/// <summary> /// Initialise default values /// </summary> private void Init() { this.key = ""; this.dataMember = ""; this.dictionary = null; this.caption = ""; this.width = I3Column.DefaultWidth_Const; this.columnState = I3ColumnState.Normal; this.headerAlignment = I3ColumnAlignment.Center; this.cellAlignment = I3ColumnAlignment.Left; this.image = null; this.imageOnRight = false; this.columnModel = null; this.x = 0; this.tooltipText = null; this.format = ""; this.sortOrder = SortOrder.None; this.renderer = null; this.editor = null; this.comparer = null; this.isSelected = false; this.cellTextAutoWarp = false; this.state = (byte)(STATE_ENABLED_Const | STATE_EDITABLE_Const | STATE_VISIBLE_Const | STATE_SELECTABLE_Const | STATE_SORTABLE_Const); }
/// <summary> /// 设置编辑器的大小和位置 /// Sets the location and size of the CellEditor /// </summary> /// <param name="cellRect">A Rectangle that represents the size and location /// of the Cell being edited</param> protected override void SetEditLocation(Rectangle cellRect) { // calc the size of the textbox II3CellRenderer renderer = this.EditingTable.ColumnModel.GetCellRenderer(this.EditingCellPos.Column); int buttonWidth = ((I3PopupCellRenderer)renderer).ButtonWidth; this.TextBox.Size = new Size(cellRect.Width - 1 - buttonWidth, cellRect.Height - 1); this.TextBox.Location = cellRect.Location; this.TextBox.Width = 0; }
/// <summary> /// 设置编辑器的大小和位置 /// Sets the location and size of the CellEditor /// </summary> /// <param name="cellRect">A Rectangle that represents the size and location /// of the Cell being edited</param> protected override void SetEditLocation(Rectangle cellRect) { // calc the size of the textbox II3CellRenderer renderer = this.EditingTable.ColumnModel.GetCellRenderer(this.EditingCellPos.Column); int buttonWidth = ((I3DateTimeCellRenderer)renderer).ButtonWidth; this.TextBox.Size = new Size(cellRect.Width - 1 - buttonWidth, cellRect.Height - 1); this.TextBox.Location = cellRect.Location; this.TextBox.Width = 0; this.dateTimePicker.Width = this.EditingTable.ColumnModel.Columns[this.EditingCellPos.Column].Width; this.DropDown.Height = this.EditingCell.Row.Height; this.DropDown.Width = this.dateTimePicker.Width - 1; }
/// <summary> /// 显示下拉容器 /// Displays the drop down portion to the user /// </summary> protected virtual void ShowDropDown() { //TextBox.Location在准备编辑方法中被赋值 Point p = this.EditingTable.PointToScreen(this.TextBox.Location); //p.Y += this.TextBox.Height + 1; p.Y = GetDropDownContainerTop(p); Rectangle screenBounds = Screen.GetBounds(p); if (p.Y + this.dropDownContainer.Height > screenBounds.Bottom) { p.Y -= this.TextBox.Height + this.dropDownContainer.Height + 1; } if (p.X + this.dropDownContainer.Width > screenBounds.Right) { II3CellRenderer renderer = this.EditingTable.ColumnModel.GetCellRenderer(this.EditingCellPos.Column); int buttonWidth = ((I3DropDownCellRenderer)renderer).ButtonWidth; p.X = p.X + this.TextBox.Width + buttonWidth - this.dropDownContainer.Width; } this.dropDownContainer.Location = p; this.parentForm.AddOwnedForm(this.dropDownContainer); this.activationListener.AssignHandle(this.parentForm.Handle); this.dropDownContainer.ShowDropDown(); this.dropDownContainer.Activate(); // A little bit of fun. We've shown the popup, // but because we've kept the main window's // title bar in focus the tab sequence isn't quite // right. This can be fixed by sending a tab, // but that on its own would shift focus to the // second control in the form. So send a tab, // followed by a reverse-tab. // Send a Tab command: I3NativeMethods.keybd_event((byte)Keys.Tab, 0, 0, 0); I3NativeMethods.keybd_event((byte)Keys.Tab, 0, I3KeyEventFFlags.KEYEVENTF_KEYUP, 0); // Send a reverse Tab command: I3NativeMethods.keybd_event((byte)Keys.ShiftKey, 0, 0, 0); I3NativeMethods.keybd_event((byte)Keys.Tab, 0, 0, 0); I3NativeMethods.keybd_event((byte)Keys.Tab, 0, I3KeyEventFFlags.KEYEVENTF_KEYUP, 0); I3NativeMethods.keybd_event((byte)Keys.ShiftKey, 0, I3KeyEventFFlags.KEYEVENTF_KEYUP, 0); }
/// <summary> /// 从缓存中获取Renderer /// </summary> /// <param name="type"></param> /// <returns></returns> public static II3CellRenderer GetRenderer(Type type) { if (type == null) { return(null); } if (rendererDic.ContainsKey(type)) { return(rendererDic[type]); } II3CellRenderer result = BuildRenderer(type); rendererDic.Add(type, result); return(result); }
/// <summary> /// 重新计算单元格的大小,借以调整行、列的大小 /// prepareNarrow:是否处理内容缩放 /// </summary> /// <param name="reportData"></param> /// <param name="row"></param> /// <param name="col"></param> private static void ReCalCellSize(I3ReportData reportData, int row, int col, bool prepareNarrow) { #region 获取单元格、样式、合并区域对象 I3ReportCell cell = reportData.GetCellItem(row, col); if (cell == null || cell.MergState == I3MergeState.Merged) //单元格为空,或者是被合并的,不需要重新计算 { return; } I3ReportCellStyle style = reportData.GetCellStyle(cell.StyleName); //没有样式设置,不用重新计算 if (style == null) { return; } I3MergeRange range = cell.MergState == I3MergeState.FirstCell ? reportData.GetMergeRange(row, col) : null; if (range == null) { range = new I3MergeRange((short)row, (short)col, (short)row, (short)col); } #endregion #region 得到默认宽度、高度 int width = 0; int height = 0; for (int i = range.StartRow; i <= range.EndRow; i++) { height += reportData[i].Height; } for (int i = range.StartCol; i <= range.EndCol; i++) { width += reportData.Cols[i].Width; } if (width == 0 || height == 0) { return; } #endregion II3CellRenderer renderer = I3CellRendererBuilder.GetRenderer(reportData[row][col]); SizeF needSize = renderer.CalCellNeedSize(width, height, style, cell); if (needSize != SizeF.Empty) { renderer.AdjustCellSize(width, height, needSize, style, cell, range, reportData, prepareNarrow); } }
/// <summary> /// Sets the location and size of the CellEditor /// </summary> /// <param name="cellRect">A Rectangle that represents the size and location /// of the Cell being edited</param> protected override void SetEditLocation(Rectangle cellRect) { // calc the size of the textbox II3CellRenderer renderer = this.EditingTable.ColumnModel.GetCellRenderer(this.EditingCellPos.Column); int buttonWidth = ((I3NumberCellRenderer)renderer).ButtonWidth; this.TextBox.Size = new Size(cellRect.Width - 2 - buttonWidth, cellRect.Height - 2); // calc the location of the textbox this.TextBox.Location = cellRect.Location; this.TextBox.Left++; this.TextBox.Top++; this.buttonBounds = new Rectangle(this.TextBox.Left + 1, this.TextBox.Top, buttonWidth, this.TextBox.Height); if (((I3NumberColumn)this.EditingTable.ColumnModel.Columns[this.EditingCellPos.Column]).UpDownAlign == LeftRightAlignment.Left) { this.TextBox.Location = new Point(cellRect.Left + buttonWidth, cellRect.Top); this.buttonBounds.Location = new Point(cellRect.Left, cellRect.Top); } }
/// <summary> /// Associates the specified ICellRenderer with the specified name /// </summary> /// <param name="name">The name to be associated with the specified ICellRenderer</param> /// <param name="renderer">The ICellRenderer to be added to the ColumnModel</param> public void SetCellRenderer(string name, II3CellRenderer renderer) { if (name == null || renderer == null) { return; } name = name.ToUpper(); if (this._cellRenderers.ContainsKey(name)) { this._cellRenderers.Remove(name); this._cellRenderers[name] = renderer; } else { this._cellRenderers.Add(name, renderer); } }
/// <summary> /// 测试单元格 /// </summary> /// <param name="pageIndex"></param> /// <param name="x"></param> /// <param name="y"></param> /// <returns></returns> private I3ReportCell TestCell(int pageIndex, int x, int y) { if (reportDatas == null || CellItemEventMode == ReportPrint.I3CellItemEventMode.None) { return(null); } I3ReportData reportData = reportDatas.GetReportDataByAreaIndex(pageIndex); int row = TestRow(pageIndex, x, y); int col = TestCol(pageIndex, x, y); if (row < 0 || col < 0) { return(null); } I3ReportCell cell = reportData[row][col]; cell = cell.MergState == I3MergeState.Merged ? reportData.GetMergedStartedCell(row, col) : cell; switch (CellItemEventMode) { case I3CellItemEventMode.CellRect: return(cell); case I3CellItemEventMode.ContentRect: I3PrintArea area = reportDatas.PrintAreas.Dic[pageIndex]; RectangleF fullRect = GetAreaPaperRect(area); RectangleF dataRect = GetAreaContentRect(area); RectangleF rect = I3ReportPrintController.CalCellDrawRect_Scale(reportDatas, cell, area, Scale, dataRect, null); II3CellRenderer renderer = I3CellRendererBuilder.GetRenderer(cell); RectangleF contentRect = renderer.DrawContent(this.CreateGraphics(), Scale, reportData, cell, rect, reportData.GetCellStyle(cell.StyleName), area, false); RectangleF testRect = new RectangleF(x, y, 1, 1); return(contentRect.IntersectsWith(testRect) ? cell : null); default: return(null); } }
/// <summary> /// 将单元格输出到画布上 /// </summary> /// <param name="reportData"></param> /// <param name="row"></param> /// <param name="col"></param> private static void DrawCell(Graphics g, RectangleF fullRect, RectangleF dataRect, RectangleF areaRect, float scale, I3ReportDatas reportDatas, I3ReportCell cell, I3PrintArea area, I3ReportCell mergedCell, bool drawBackground, bool drawBorder, bool drawContect) { #region 合并单元格中的格子处理 if (cell != null && cell.MergState == I3MergeState.Merged) { //2017.04.26 为加快绘制速度,合并单元格不处理 return; //I3ReportCell firstCell = reportData.GetMergedStartedCell(cell.Row, cell.Col); //if (firstCell != null) //{ // DrawCell(g, fullRect, dataRect, areaRect, scale, reportData, firstCell, area, cell, drawBackground, drawBorder, drawContect); //} //return; } #endregion #region 绘制区域、剪切区域 RectangleF cellDrawRect = CalCellDrawRect_Scale(reportDatas, cell, area, scale, dataRect, mergedCell); if (cellDrawRect.IsEmpty) { return; } //2017.04.26 为加快绘制速度,不做单元格剪切区域计算,直接使用原始的剪切区域 //I3ReportCell destCell = mergedCell == null ? cell : mergedCell; //计算剪切区域使用真实单元格 //RectangleF clipRect = CalCellClipRect_Scale(reportData, destCell, area, scale, dataRect, fullRect, areaRect); ////destCell.SetCellRect(graphicsKey, clipRect); //clipRect.Intersect(g.ClipBounds); //if (clipRect.IsEmpty) //{ // return; //} //g.SetClip(clipRect); #endregion #region 样式 I3ReportCellStyle style = area.ReportData.GetCellStyle(cell.StyleName); if (style == null) { return; } #endregion II3CellRenderer renderer = I3CellRendererBuilder.GetRenderer(cell); RectangleF oldClip = g.ClipBounds; //背景 if (drawBackground) { g.SetClip(oldClip); g.FillRectangle(Brushes.White, cellDrawRect); renderer.DrawBackground(g, scale, area.ReportData, cell, cellDrawRect, style); } //边框 if (drawBorder) { RectangleF borderClipRect = oldClip; //扩大避免边框画不全 borderClipRect.Inflate(1, 1); g.SetClip(borderClipRect); renderer.DrawCellBorder(g, scale, area.ReportData, cell, cellDrawRect, style); } //内容 if (drawContect) { g.SetClip(oldClip); renderer.DrawContent(g, scale, area.ReportData, cell, cellDrawRect, style, area, true); } }