/// <summary> /// 可见状态改变方法 /// </summary> public override void onVisibleChanged() { base.onVisibleChanged(); if (Visible) { if (m_popup) { FCHScrollBar hScrollBar = HScrollBar; FCVScrollBar vScrollBar = VScrollBar; if (hScrollBar != null) { hScrollBar.Pos = 0; } if (vScrollBar != null) { vScrollBar.Pos = 0; } focus(); //修正显示位置 adjust(this); } startTimer(m_timerID, 10); } else { stopTimer(m_timerID); bool close = closeMenus(m_items); FCNative native = Native; if (native != null) { native.invalidate(); } } }
/// <summary> /// 重置列头布局 /// </summary> public virtual void resetHeaderLayout() { int bandsSize = m_bands.size(); FCRect bounds = Bounds; int left = bounds.left; int width = Width; if (bandsSize == 0) { int scrollH = 0; FCHScrollBar hScrollBar = Grid.HScrollBar; if (hScrollBar != null && hScrollBar.Visible) { scrollH = -hScrollBar.Pos; } int columnsSize = m_columns.size(); for (int i = 0; i < columnsSize; i++) { FCBandedFCGridColumn column = m_columns.get(i); if (column.Visible) { int columnWidth = column.Width; if (i == columnsSize - 1 || left + columnWidth > width + bounds.left) { columnWidth = width + bounds.left - left; } FCRect cellRect = new FCRect(left, bounds.bottom, left + columnWidth, bounds.bottom + column.Height); column.Bounds = cellRect; cellRect.left -= scrollH; cellRect.right -= scrollH; column.HeaderRect = cellRect; left += columnWidth; } } } else { for (int i = 0; i < bandsSize; i++) { FCGridBand band = m_bands.get(i); if (band.Visible) { int bandWidth = band.Width; if (i == bandsSize - 1 || left + bandWidth > width + bounds.left) { bandWidth = width + bounds.left - left; } FCRect cellRect = new FCRect(left, bounds.bottom, left + bandWidth, bounds.bottom + band.Height); band.Bounds = cellRect; band.resetHeaderLayout(); left += bandWidth; } } } }
/// <summary> /// 单元格触摸按下方法 /// </summary> /// <param name="cell">单元格</param> /// <param name="touchInfo">触摸信息</param> public override void onCellTouchDown(FCGridCell cell, FCTouchInfo touchInfo) { base.onCellTouchDown(cell, touchInfo); FCPoint mp = touchInfo.m_firstPoint; FCTreeNode node = cell as FCTreeNode; if (node != null) { int scrollH = 0; FCHScrollBar hscrollBar = HScrollBar; if (hscrollBar != null && hscrollBar.Visible) { scrollH = hscrollBar.Pos; } FCRect headerRect = node.TargetColumn.Bounds; headerRect.left += HorizontalOffset - scrollH; headerRect.top += VerticalOffset - scrollH; int left = headerRect.left; //复选框 if (m_checkBoxes) { int cw = m_checkBoxSize.cx; if (mp.x >= left && mp.x <= left + cw) { node.Checked = !node.Checked; return; } left += cw + 10; } //折叠节点 ArrayList <FCTreeNode> childNodes = node.getChildNodes(); if (childNodes != null && childNodes.size() > 0) { int nw = m_nodeSize.cx; if (mp.x >= left && mp.x <= left + nw) { if (node.Expended) { node.collapse(); } else { node.expend(); } update(); return; } } //移动 if (node.AllowDragOut) { m_movingNode = node; } } }
/// <summary> /// 重置列头布局 /// </summary> public override void resetHeaderLayout() { int left = 0, top = 0, scrollH = 0; FCHScrollBar hScrollBar = HScrollBar; if (hScrollBar != null && hScrollBar.Visible) { scrollH = -hScrollBar.Pos; } int headerHeight = HeaderVisible ? HeaderHeight : 0; int horizontalOffset = HorizontalOffset; int verticalOffset = VerticalOffset; int bandsSize = m_bands.size(); for (int i = 0; i < bandsSize; i++) { FCGridBand band = m_bands.get(i); if (band.Visible) { int bandHeight = headerHeight < band.Height ? headerHeight : band.Height; FCRect bandRect = new FCRect(left + horizontalOffset, top + verticalOffset, left + horizontalOffset + band.Width, top + bandHeight + verticalOffset); bool hasFrozenColumn = false; ArrayList <FCBandedFCGridColumn> childColumns = band.getAllChildColumns(); int childColumnsSize = childColumns.size(); for (int j = 0; j < childColumnsSize; j++) { if (childColumns.get(j).Frozen) { hasFrozenColumn = true; break; } } if (!hasFrozenColumn) { bandRect.left += scrollH; bandRect.right += scrollH; } band.Bounds = bandRect; band.resetHeaderLayout(); left += band.Width; } } }
/// <summary> /// 获取内容的宽度 /// </summary> /// <returns>宽度</returns> public virtual int getContentWidth() { FCHScrollBar hScrollBar = HScrollBar; FCVScrollBar vScrollBar = VScrollBar; int wmax = 0; ArrayList <FCView> controls = m_controls; int controlSize = controls.size(); for (int i = 0; i < controlSize; i++) { FCView control = controls[i]; if (control.Visible && control != hScrollBar && control != vScrollBar) { int right = control.Right; if (right > wmax) { wmax = right; } } } return(wmax); }
/// <summary> /// 获取内容的高度 /// </summary> /// <returns>高度</returns> public virtual int getContentHeight() { FCHScrollBar hScrollBar = HScrollBar; FCVScrollBar vScrollBar = VScrollBar; int hmax = 0; ArrayList <FCView> controls = m_controls; int controlSize = controls.size(); for (int i = 0; i < controlSize; i++) { FCView control = controls[i]; if (control.Visible && control != hScrollBar && control != vScrollBar) { int bottom = control.Bottom; if (bottom > hmax) { hmax = bottom; } } } return(hmax); }
/// <summary> /// 获取内容的宽度 /// </summary> /// <returns>宽度</returns> public override int getContentWidth() { FCHScrollBar hScrollBar = HScrollBar; FCVScrollBar vScrollBar = VScrollBar; int wmax = 0; ArrayList <FCView> controls = m_controls; int controlSize = controls.size(); for (int i = 0; i < controlSize; i++) { FCView control = controls.get(i); if (control.Visible && control != hScrollBar && control != vScrollBar) { int right = control.Right; if (right > wmax) { wmax = right; } } } int allVisibleBandsWidth = AllVisibleBandsWidth; return(wmax > allVisibleBandsWidth ? wmax : allVisibleBandsWidth); }
/// <summary> /// 重绘方法 /// </summary> /// <param name="paint">绘图对象</param> /// <param name="rect">矩形</param> /// <param name="clipRect">裁剪矩形</param> /// <param name="isAlternate">是否交替行</param> public override void onPaint(FCPaint paint, FCRect rect, FCRect clipRect, bool isAlternate) { int clipW = clipRect.right - clipRect.left; int clipH = clipRect.bottom - clipRect.top; FCGrid grid = Grid; FCGridRow row = Row; if (clipW > 0 && clipH > 0 && grid != null && Column != null && row != null && TargetColumn != null) { int width = rect.right - rect.left; int height = rect.bottom - rect.top; int scrollH = 0; FCHScrollBar hscrollBar = grid.HScrollBar; if (hscrollBar != null && hscrollBar.Visible) { scrollH = hscrollBar.Pos; } FCFont font = null; long backColor = FCColor.None; long textColor = FCColor.None; bool autoEllipsis = m_tree.AutoEllipsis; FCGridCellStyle style = Style; if (style != null) { if (style.AutoEllipsis) { autoEllipsis = style.AutoEllipsis; } backColor = style.BackColor; if (style.Font != null) { font = style.Font; } textColor = style.TextColor; } FCGridRowStyle rowStyle = grid.RowStyle; if (isAlternate) { FCGridRowStyle alternateRowStyle = grid.AlternateRowStyle; if (alternateRowStyle != null) { rowStyle = alternateRowStyle; } } if (rowStyle != null) { bool selected = false; ArrayList <FCGridRow> selectedRows = grid.SelectedRows; int selectedRowsSize = selectedRows.size(); for (int i = 0; i < selectedRowsSize; i++) { if (selectedRows[i] == row) { selected = true; break; } } if (backColor == FCColor.None) { //选中 if (selected) { backColor = rowStyle.SelectedBackColor; } //悬停 else if (Row == Grid.HoveredRow) { backColor = rowStyle.HoveredBackColor; } //普通 else { backColor = rowStyle.BackColor; } } if (font == null) { font = rowStyle.Font; } if (textColor == FCColor.None) { //选中 if (selected) { textColor = rowStyle.SelectedTextColor; } //悬停 else if (Row == Grid.HoveredRow) { textColor = rowStyle.HoveredTextColor; } //普通 else { textColor = rowStyle.TextColor; } } } //绘制背景 paint.fillRect(backColor, rect); FCRect headerRect = TargetColumn.Bounds; headerRect.left += Grid.HorizontalOffset - scrollH; headerRect.top += Grid.VerticalOffset - scrollH; int left = headerRect.left; //绘制复选框 if (m_tree.CheckBoxes) { int cw = m_tree.CheckBoxSize.cx; int ch = m_tree.CheckBoxSize.cy; FCRect checkBoxRect = new FCRect(); checkBoxRect.left = left; checkBoxRect.top = rect.top + (height - ch) / 2; checkBoxRect.right = checkBoxRect.left + cw; checkBoxRect.bottom = checkBoxRect.top + ch; onPaintCheckBox(paint, checkBoxRect); left += cw + 10; } //绘制折叠展开的标志 int nw = m_tree.NodeSize.cx; int nh = m_tree.NodeSize.cy; if (m_nodes.size() > 0) { FCRect nodeRect = new FCRect(); nodeRect.left = left; nodeRect.top = rect.top + (height - nh) / 2; nodeRect.right = nodeRect.left + nw; nodeRect.bottom = nodeRect.top + nh; onPaintNode(paint, nodeRect); } left += nw + 10; m_indent = left; String text = getPaintText(); //绘制文字 if (text != null) { FCSize tSize = paint.textSize(text, font); FCRect tRect = new FCRect(); tRect.left = left; tRect.top = rect.top + (row.Height - tSize.cy) / 2; tRect.right = tRect.left + tSize.cx; tRect.bottom = tRect.top + tSize.cy; if (autoEllipsis && (tRect.right < clipRect.right || tRect.bottom < clipRect.bottom)) { if (tRect.right < clipRect.right) { tRect.right = clipRect.right; } if (tRect.bottom < clipRect.bottom) { tRect.bottom = clipRect.bottom; } paint.drawTextAutoEllipsis(text, textColor, font, tRect); } else { paint.drawText(text, textColor, font, tRect); } } } onPaintControl(paint, rect, clipRect); }
/// <summary> /// 更新滚动条的布局 /// </summary> public virtual void updateScrollBar() { if (Native != null) { FCHScrollBar hScrollBar = HScrollBar; FCVScrollBar vScrollBar = VScrollBar; if (Visible) { int width = Width, height = Height; //滚动条尺寸 int hBarHeight = (hScrollBar != null) ? hScrollBar.Height : 0; int vBarWidth = (vScrollBar != null) ? vScrollBar.Width : 0; int wmax = getContentWidth(), hmax = getContentHeight(); if (hScrollBar != null) { hScrollBar.ContentSize = wmax; hScrollBar.Size = new FCSize(width - vBarWidth, hBarHeight); hScrollBar.PageSize = width - vBarWidth; hScrollBar.Location = new FCPoint(0, height - hBarHeight); if (wmax <= width) { hScrollBar.Visible = false; } else { hScrollBar.Visible = true; } } if (vScrollBar != null) { vScrollBar.ContentSize = hmax; vScrollBar.Size = new FCSize(vBarWidth, height - hBarHeight); vScrollBar.PageSize = height - hBarHeight; vScrollBar.Location = new FCPoint(width - vBarWidth, 0); int vh = (hScrollBar != null && hScrollBar.Visible) ? height - hBarHeight : height; if (hmax <= vh) { vScrollBar.Visible = false; } else { vScrollBar.Visible = true; } } //修改尺寸 if (hScrollBar != null && vScrollBar != null) { if (hScrollBar.Visible && !vScrollBar.Visible) { hScrollBar.Width = width; hScrollBar.PageSize = width; } else if (!hScrollBar.Visible && vScrollBar.Visible) { vScrollBar.Height = height; vScrollBar.PageSize = height; } } if (hScrollBar != null && hScrollBar.Visible) { hScrollBar.update(); } if (vScrollBar != null && vScrollBar.Visible) { vScrollBar.update(); } } } }
/// <summary> /// 创建内部控件 /// </summary> /// <param name="parent">父控件</param> /// <param name="clsid">控件标识</param> /// <returns>内部控件</returns> public override FCView createInternalControl(FCView parent, String clsid) { //日历控件 FCCalendar calendar = parent as FCCalendar; if (calendar != null) { if (clsid == "datetitle") { return(new DateTitle(calendar)); } else if (clsid == "headdiv") { HeadDiv headDiv = new HeadDiv(calendar); headDiv.Width = parent.Width; headDiv.Dock = FCDockStyle.Top; return(headDiv); } else if (clsid == "lastbutton") { return(new ArrowButton(calendar)); } else if (clsid == "nextbutton") { ArrowButton nextBtn = new ArrowButton(calendar); nextBtn.ToLast = false; return(nextBtn); } } //分割层 FCSplitLayoutDiv splitLayoutDiv = parent as FCSplitLayoutDiv; if (splitLayoutDiv != null) { if (clsid == "splitter") { FCButton splitter = new FCButton(); splitter.BackColor = FCColor.Border; splitter.BorderColor = FCColor.Border; splitter.Size = new FCSize(5, 5); return(splitter); } } //滚动条 FCScrollBar scrollBar = parent as FCScrollBar; if (scrollBar != null) { scrollBar.BorderColor = FCColor.None; scrollBar.BackColor = FCColor.None; if (clsid == "addbutton") { RibbonButton addButton = new RibbonButton(); addButton.Size = new FCSize(10, 10); if (scrollBar is FCHScrollBar) { addButton.ArrowType = 2; } else if (scrollBar is FCVScrollBar) { addButton.ArrowType = 4; } return(addButton); } else if (clsid == "backbutton") { FCButton backButton = new FCButton(); backButton.BorderColor = FCColor.None; backButton.BackColor = FCColor.None; return(backButton); } else if (clsid == "scrollbutton") { RibbonButton scrollButton = new RibbonButton(); scrollButton.AllowDrag = true; if (scrollBar is FCVScrollBar) { scrollButton.Angle = 0; } return(scrollButton); } else if (clsid == "reducebutton") { RibbonButton reduceButton = new RibbonButton(); reduceButton.Size = new FCSize(10, 10); if (scrollBar is FCHScrollBar) { reduceButton.ArrowType = 1; } else if (scrollBar is FCVScrollBar) { reduceButton.ArrowType = 3; } return(reduceButton); } } //页夹 FCTabPage tabPage = parent as FCTabPage; if (tabPage != null) { if (clsid == "headerbutton") { RibbonButton button = new RibbonButton(); button.AllowDrag = true; FCSize size = new FCSize(100, 20); button.Size = size; return(button); } } //下拉列表 FCComboBox comboBox = parent as FCComboBox; if (comboBox != null) { if (clsid == "dropdownbutton") { RibbonButton dropDownButton = new RibbonButton(); dropDownButton.ArrowType = 4; dropDownButton.DisplayOffset = false; int width = comboBox.Width; int height = comboBox.Height; FCPoint location = new FCPoint(width - 20, 0); dropDownButton.Location = location; FCSize size = new FCSize(20, height); dropDownButton.Size = size; return(dropDownButton); } else if (clsid == "dropdownmenu") { FCComboBoxMenu comboBoxMenu = new FCComboBoxMenu(); comboBoxMenu.ComboBox = comboBox; comboBoxMenu.Popup = true; FCSize size = new FCSize(100, 200); comboBoxMenu.Size = size; return(comboBoxMenu); } } //日期选择 FCDateTimePicker datePicker = parent as FCDateTimePicker; if (datePicker != null) { if (clsid == "dropdownbutton") { RibbonButton dropDownButton = new RibbonButton(); dropDownButton.ArrowType = 4; dropDownButton.DisplayOffset = false; int width = datePicker.Width; int height = datePicker.Height; FCPoint location = new FCPoint(width - 16, 0); dropDownButton.Location = location; FCSize size = new FCSize(16, height); dropDownButton.Size = size; return(dropDownButton); } else if (clsid == "dropdownmenu") { FCMenu dropDownMenu = new FCMenu(); dropDownMenu.Padding = new FCPadding(1); dropDownMenu.Popup = true; FCSize size = new FCSize(200, 200); dropDownMenu.Size = size; return(dropDownMenu); } } //数字选择 FCSpin spin = parent as FCSpin; if (spin != null) { if (clsid == "downbutton") { RibbonButton downButton = new RibbonButton(); downButton.DisplayOffset = false; downButton.ArrowType = 4; FCSize size = new FCSize(16, 16); downButton.Size = size; return(downButton); } else if (clsid == "upbutton") { RibbonButton upButton = new RibbonButton(); upButton.DisplayOffset = false; upButton.ArrowType = 3; FCSize size = new FCSize(16, 16); upButton.Size = size; return(upButton); } } //容器层 FCDiv div = parent as FCDiv; if (div != null) { if (clsid == "hscrollbar") { FCHScrollBar hScrollBar = new FCHScrollBar(); hScrollBar.Visible = false; hScrollBar.Size = new FCSize(10, 10); return(hScrollBar); } else if (clsid == "vscrollbar") { FCVScrollBar vScrollBar = new FCVScrollBar(); vScrollBar.Visible = false; vScrollBar.Size = new FCSize(10, 10); return(vScrollBar); } } //表格 FCGrid grid = parent as FCGrid; if (grid != null) { if (clsid == "edittextbox") { return(new FCTextBox()); } } return(base.createInternalControl(parent, clsid)); }