/// <summary> /// 按键抬起方法 /// </summary> /// <param name="key">按键</param> public override void onKeyUp(char key) { if (!IsDragging) { m_step = 1; base.onKeyUp(key); if (m_offsetX != 0 || m_offsetY != 0) { int targetsSize = m_targets.Count; if (targetsSize > 0) { m_designerDiv.saveUndo(); for (int i = 0; i < targetsSize; i++) { FCView target = m_targets[i]; FCPoint oldLocation = target.Location; oldLocation.x += m_offsetX; oldLocation.y += m_offsetY; m_xml.setProperty(target, "location", FCStr.convertPointToStr(oldLocation)); target.update(); } m_designerDiv.Designer.refreshProperties(); } refreshStatusBar(); Parent.invalidate(); } } m_offsetX = 0; m_offsetY = 0; }
/// <summary> /// 下拉列表控件索引改变事件 /// </summary> /// <param name="sender">调用者</param> private void comboBoxSelectedIndexChanged(object sender) { if (m_xml != null) { if (!m_settingProperty) { m_settingProperty = true; FCComboBox comboBox = sender as FCComboBox; if (comboBox != null) { m_designerDiv.saveUndo(); String name = comboBox.Tag.ToString(); String value = comboBox.SelectedText; int targetsSize = m_targets.Count; for (int i = 0; i < targetsSize; i++) { FCView target = m_targets[i]; m_xml.setProperty(target, name, value); target.update(); } Native.update(); Native.invalidate(); } m_settingProperty = false; } } }
/// <summary> /// 创建树的节点 /// </summary> /// <param name="node">节点</param> /// <param name="control">控件</param> protected virtual void createTreeNodes(XmlNode node, FCView control) { foreach (XmlNode subNode in node.ChildNodes) { createTreeNode(subNode, control, null); } control.update(); }
/// <summary> /// 拖动结束方法 /// </summary> public override void onDragEnd() { base.onDragEnd(); int targetsSize = m_targets.Count; FCView divDesigner = Parent; //判定区域 FCNative native = Native; m_designerDiv.saveUndo(); FCPoint mp = Native.TouchPoint; for (int i = 0; i < targetsSize; i++) { FCView target = m_targets[i]; FCView parent = target.Parent; bool outControl = false; FCPoint oldNativeLocation = target.pointToNative(new FCPoint(0, 0)); if (parent != null) { if (divDesigner != null) { //查找新的控件 m_acceptTouch = false; FCView newParent = native.findControl(mp, divDesigner); m_acceptTouch = true; if (newParent != null && m_xml.isContainer(newParent) && newParent != this && newParent != parent && target != newParent) { //移除控件 m_xml.removeControl(target); //添加控件 m_xml.addControl(target, newParent); parent = newParent; outControl = true; } } } if (outControl || canDragTargets()) { FCRect newRect = convertBoundsToPRect(Bounds); oldNativeLocation.x += newRect.left - m_startRect.left; oldNativeLocation.y += newRect.top - m_startRect.top; m_xml.setProperty(target, "location", FCStr.convertPointToStr(target.Parent.pointToControl(oldNativeLocation))); target.update(); } } m_designerDiv.Designer.refreshProperties(); refreshStatusBar(); divDesigner.update(); }
/// <summary> /// 读取XML /// </summary> /// <param name="node">XML节点</param> /// <param name="parent">父控件</param> public virtual FCView readNode(XmlNode node, FCView parent) { String type = node.Name.ToLower(); FCView control = createControl(node, type); if (control != null) { control.Native = m_native; if (parent != null) { parent.addControl(control); } else { m_native.addControl(control); } //前设置属性 setAttributesBefore(node, control); if (control is FCSplitLayoutDiv) { //创建分割层 createSplitLayoutSubProperty(node, control as FCSplitLayoutDiv); } else if (control is FCChart) { createChartSubProperty(node, control as FCChart); } else if (control is FCTableLayoutDiv) { createTableLayoutSubProperty(node, control as FCTableLayoutDiv); } else { //加载子节点 readChildNodes(node, control); } //后设置属性 setAttributesAfter(node, control); control.update(); onAddControl(control, node); } else { //创建子属性 createSubProperty(node, parent); } return(control); }
/// <summary> /// 单元格编辑结束 /// </summary> /// <param name="cell">单元格</param> public override void onCellEditEnd(FCGridCell cell) { base.onCellEditEnd(cell); if (cell != null) { FCGridCell nameCell = cell.Row.getCell("PROPERTYNAME"); if (nameCell != null) { m_designerDiv.saveUndo(); String name = nameCell.Name; String eventName = "on" + name.ToLower(); String value = cell.Text; int targetsSize = m_targets.Count; for (int i = 0; i < targetsSize; i++) { FCView target = m_targets[i]; if (value == null || value.Trim().Length == 0) { m_xml.removeProperty(target, eventName); } else { m_xml.setProperty(target, eventName, value); } target.update(); } //恢复正确的值 String rightValue = ""; for (int i = 0; i < targetsSize; i++) { FCView target = m_targets[i]; Dictionary <String, String> attributes = m_xml.getAttributes(m_xml.Nodes[target]); if (attributes.ContainsKey(eventName)) { rightValue = attributes[eventName]; } } cell.Text = rightValue; Native.update(); Native.invalidate(); } } }
/// <summary> /// 更新布局 /// </summary> /// <param name="var">变量</param> /// <returns>状态</returns> private double UPDATE(CVariable var) { if (m_xml != null) { int pLen = var.m_parameters != null ? var.m_parameters.Length : 0; if (pLen == 0) { m_xml.Native.update(); } else { FCView control = m_xml.findControl(m_indicator.getText(var.m_parameters[0])); if (control != null) { control.update(); } } } return(0); }
/// <summary> /// 清除目标 /// </summary> public void clearTargets() { //保存上次编辑的控件属性 FCTextBox editTextBox = EditTextBox; if (editTextBox != null) { if (editTextBox.Tag != null) { FCGridCell editingCell = EditTextBox.Tag as FCGridCell; if (editingCell != null) { FCGridCell nameCell = editingCell.Row.getCell("PROPERTYNAME"); if (nameCell != null) { String cellName = nameCell.Name; String cellValue = editTextBox.Text; String eventName = "on" + cellName.ToLower(); int targetsSize = m_targets.Count; for (int i = 0; i < targetsSize; i++) { FCView target = m_targets[i]; if (cellValue == null || cellValue.Trim().Length == 0) { m_xml.removeProperty(target, eventName); } else { m_xml.setProperty(target, eventName, cellValue); } target.update(); } } } } editTextBox.Visible = false; } m_targets.Clear(); }
/// <summary> /// 单元格编辑结束 /// </summary> /// <param name="cell">单元格</param> public override void onCellEditEnd(FCGridCell cell) { base.onCellEditEnd(cell); if (cell != null) { if (cell.Row.m_cells.Count > 0) { FCGridCell nameCell = cell.Row.getCell("PROPERTYNAME"); if (nameCell != null) { m_designerDiv.saveUndo(); String name = nameCell.Name; String value = cell.Text; int targetsSize = m_targets.Count; for (int i = 0; i < targetsSize; i++) { FCView target = m_targets[i]; m_xml.setProperty(target, name, value); if (m_collectionWindow != null) { m_collectionWindow.onPropertyChanged(name, value); } target.update(); } //恢复正确的值 String rightValue = "", type = ""; for (int i = 0; i < targetsSize; i++) { m_targets[i].getProperty(name.ToLower(), ref rightValue, ref type); } cell.Text = rightValue; Native.update(); Native.invalidate(); } } } }
/// <summary> /// 重置布局 /// </summary> /// <returns></returns> public override bool onResetLayout() { bool reset = false; if (Native != null && m_splitter != null && m_firstControl != null && m_secondControl != null) { FCRect splitRect = new FCRect(); int width = Width, height = Height; FCRect fRect = new FCRect(); FCRect sRect = new FCRect(); FCSize splitterSize = new FCSize(0, 0); if (m_splitter.Visible) { splitterSize.cx = m_splitter.Width; splitterSize.cy = m_splitter.Height; } FCLayoutStyle layoutStyle = LayoutStyle; switch (layoutStyle) { //自下而上 case FCLayoutStyle.BottomToTop: //绝对大小 if (m_splitMode == FCSizeType.AbsoluteSize || m_oldSize.cy == 0) { splitRect.left = 0; splitRect.top = height - (m_oldSize.cy - m_splitter.Top); splitRect.right = width; splitRect.bottom = splitRect.top + splitterSize.cy; } //百分比大小 else if (m_splitMode == FCSizeType.PercentSize) { splitRect.left = 0; if (m_splitPercent == -1) { m_splitPercent = (float)m_splitter.Top / m_oldSize.cy; } splitRect.top = (int)(height * m_splitPercent); splitRect.right = width; splitRect.bottom = splitRect.top + splitterSize.cy; } fRect.left = 0; fRect.top = splitRect.bottom; fRect.right = width; fRect.bottom = height; sRect.left = 0; sRect.top = 0; sRect.right = width; sRect.bottom = splitRect.top; break; //从左向右 case FCLayoutStyle.LeftToRight: //绝对大小 if (m_splitMode == FCSizeType.AbsoluteSize || m_oldSize.cx == 0) { splitRect.left = m_splitter.Left; splitRect.top = 0; splitRect.right = m_splitter.Left + splitterSize.cx; splitRect.bottom = height; } //百分比大小 else if (m_splitMode == FCSizeType.PercentSize) { if (m_splitPercent == -1) { m_splitPercent = (float)m_splitter.Left / m_oldSize.cx; } splitRect.left = (int)(width * m_splitPercent); splitRect.top = 0; splitRect.right = splitRect.left + splitterSize.cx; splitRect.bottom = height; } fRect.left = 0; fRect.top = 0; fRect.right = splitRect.left; fRect.bottom = height; sRect.left = splitRect.right; sRect.top = 0; sRect.right = width; sRect.bottom = height; break; //从右向左 case FCLayoutStyle.RightToLeft: //绝对大小 if (m_splitMode == FCSizeType.AbsoluteSize || m_oldSize.cx == 0) { splitRect.left = width - (m_oldSize.cx - m_splitter.Left); splitRect.top = 0; splitRect.right = splitRect.left + splitterSize.cx; splitRect.bottom = height; } //百分比大小 else if (m_splitMode == FCSizeType.PercentSize) { if (m_splitPercent == -1) { m_splitPercent = (float)m_splitter.Left / m_oldSize.cx; } splitRect.left = (int)(width * m_splitPercent); splitRect.top = 0; splitRect.right = splitRect.left + splitterSize.cx; splitRect.bottom = height; } fRect.left = splitRect.right; fRect.top = 0; fRect.right = width; fRect.bottom = height; sRect.left = 0; sRect.top = 0; sRect.right = splitRect.left; sRect.bottom = height; break; //自上而下 case FCLayoutStyle.TopToBottom: //绝对大小 if (m_splitMode == FCSizeType.AbsoluteSize || m_oldSize.cy == 0) { splitRect.left = 0; splitRect.top = m_splitter.Top; splitRect.right = width; splitRect.bottom = splitRect.top + splitterSize.cy; } //百分比大小 else if (m_splitMode == FCSizeType.PercentSize) { splitRect.left = 0; if (m_splitPercent == -1) { m_splitPercent = (float)m_splitter.Top / m_oldSize.cy; } splitRect.top = (int)(height * m_splitPercent); splitRect.right = width; splitRect.bottom = splitRect.top + splitterSize.cy; } fRect.left = 0; fRect.top = 0; fRect.right = width; fRect.bottom = splitRect.top; sRect.left = 0; sRect.top = splitRect.bottom; sRect.right = width; sRect.bottom = height; break; } if (m_splitter.Visible) { FCRect spRect = m_splitter.Bounds; if (spRect.left != splitRect.left || spRect.top != splitRect.top || spRect.right != splitRect.right || spRect.bottom != splitRect.bottom) { m_splitter.Bounds = splitRect; reset = true; } if (m_splitter.AllowDrag) { if (layoutStyle == FCLayoutStyle.LeftToRight || layoutStyle == FCLayoutStyle.RightToLeft) { m_splitter.Cursor = FCCursors.SizeWE; } else { m_splitter.Cursor = FCCursors.SizeNS; } m_splitter.bringToFront(); } } FCRect fcRect = m_firstControl.Bounds; if (fcRect.left != fRect.left || fcRect.top != fRect.top || fcRect.right != fRect.right || fcRect.bottom != fRect.bottom) { reset = true; m_firstControl.Bounds = fRect; m_firstControl.update(); } FCRect scRect = m_secondControl.Bounds; if (scRect.left != sRect.left || scRect.top != sRect.top || scRect.right != sRect.right || scRect.bottom != sRect.bottom) { reset = true; m_secondControl.Bounds = sRect; m_secondControl.update(); } } m_oldSize = Size; return(reset); }
/// <summary> /// 单元格点击事件 /// </summary> /// <param name="cell">单元格</param> /// <param name="mp">坐标</param> /// <param name="button">按钮</param> /// <param name="clicks">点击次数</param> /// <param name="delta">滚轮值</param> public override void onCellClick(FCGridCell cell, FCTouchInfo touchInto) { base.onCellClick(cell, touchInto); List <FCGridRow> rows = m_rows; int rowsSize = rows.Count; for (int i = 0; i < rowsSize; i++) { FCGridRow row = rows[i]; List <FCGridCell> cells = row.getCells(); int cellsSize = cells.Count; for (int j = 0; j < cellsSize; j++) { FCGridControlCell cCell = cells[j] as FCGridControlCell; if (cCell != null) { if (row == cell.Row) { cCell.Control.TextColor = FCDraw.FCCOLORS_TEXTCOLOR4; } else { cCell.Control.TextColor = FCColor.Text; } } } } if (touchInto.m_firstTouch) { if (touchInto.m_clicks == 1) { if (!cell.AllowEdit && cell is GridColorCell) { GridColorCell colorCell = cell as GridColorCell; ColorDialog colorDialog = new ColorDialog(); colorDialog.AllowFullOpen = true; colorDialog.AnyColor = true; colorDialog.SolidColorOnly = false; int a = 0, r = 0, g = 0, b = 0; FCColor.toArgb(Native.Paint, FCStr.convertStrToColor(colorCell.getString()), ref a, ref r, ref g, ref b); colorDialog.Color = Color.FromArgb(a, r, g, b); if (colorDialog.ShowDialog() == DialogResult.OK) { Color newColor = colorDialog.Color; a = newColor.A; r = newColor.R; g = newColor.G; b = newColor.B; colorCell.setString(FCStr.convertColorToStr(FCColor.argb(a, r, g, b))); FCGridCell nameCell = cell.Row.getCell("PROPERTYNAME"); if (nameCell != null) { m_designerDiv.saveUndo(); String name = nameCell.Name; String value = cell.Text; int targetsSize = m_targets.Count; for (int i = 0; i < targetsSize; i++) { FCView target = m_targets[i]; m_xml.setProperty(target, name, value); if (m_collectionWindow != null) { m_collectionWindow.onPropertyChanged(name, value); } target.update(); } //恢复正确的值 String rightValue = "", type = ""; for (int i = 0; i < targetsSize; i++) { m_targets[i].getProperty(name.ToLower(), ref rightValue, ref type); } cell.Text = rightValue; Native.update(); Native.invalidate(); } } colorDialog.Dispose(); } //字体单元格 else if (!cell.AllowEdit && cell is GridFontCell) { GridFontCell fontCell = cell as GridFontCell; FontDialog fontDialog = new FontDialog(); fontDialog.Font = getFont(FCStr.convertStrToFont(fontCell.getString())); if (fontDialog.ShowDialog() == DialogResult.OK) { Font newFont = fontDialog.Font; fontCell.setString(FCStr.convertFontToStr(new FCFont(newFont.Name, newFont.Size, newFont.Bold, newFont.Underline, newFont.Italic, newFont.Strikeout))); FCGridCell nameCell = cell.Row.getCell("PROPERTYNAME"); if (nameCell != null) { m_designerDiv.saveUndo(); String name = nameCell.Name; String value = cell.Text; int targetsSize = m_targets.Count; for (int i = 0; i < targetsSize; i++) { FCView target = m_targets[i]; m_xml.setProperty(target, name, value); if (m_collectionWindow != null) { m_collectionWindow.onPropertyChanged(name, value); } target.update(); } //恢复正确的值 String rightValue = "", type = ""; for (int i = 0; i < targetsSize; i++) { m_targets[i].getProperty(name.ToLower(), ref rightValue, ref type); } cell.Text = rightValue; Native.update(); Native.invalidate(); } } } //单击编辑框 else if (cell is FCGridButtonCell) { FCButton cButton = (cell as FCGridButtonCell).Button; if (cButton.Tag != null) { String collectionName = cButton.Tag.ToString(); int targetsSize = m_targets.Count; if (targetsSize > 0) { FCView target = m_targets[0]; CollectionWindow collectionWindow = new CollectionWindow(m_native); collectionWindow.CollectionName = collectionName; collectionWindow.DesignerDiv = m_designerDiv; collectionWindow.Target = target; collectionWindow.Xml = m_xml; collectionWindow.IsWinForm = false; collectionWindow.showDialog(); } } } } } }
/// <summary> /// 鼠标抬起方法 /// </summary> /// <param name="touchInto">触摸信息</param> public override void onTouchUp(FCTouchInfo touchInto) { m_point2 = Native.TouchPoint; base.onTouchUp(touchInto); if (!IsDragging) { FCView divDesigner = Parent; if (m_resizePoint != -1) { FCRect nowRect = convertBoundsToPRect(Bounds); //移动控件 int targetsSize = m_targets.Count; if (targetsSize > 0) { m_designerDiv.saveUndo(); for (int i = 0; i < targetsSize; i++) { FCView target = m_targets[i]; FCPoint oldLocation = target.Location; FCSize oldSize = target.Size; oldLocation.x += nowRect.left - m_startRect.left; oldLocation.y += nowRect.top - m_startRect.top; oldSize.cx += (nowRect.right - nowRect.left) - (m_startRect.right - m_startRect.left); oldSize.cy += (m_startRect.top - m_startRect.bottom) - (nowRect.top - nowRect.bottom); if (oldSize.cx < 4) { oldSize.cx = 4; } else if (oldSize.cy < 4) { oldSize.cy = 4; } m_xml.setProperty(target, "location", FCStr.convertPointToStr(oldLocation)); m_xml.setProperty(target, "size", FCStr.convertSizeToStr(oldSize)); target.update(); } } m_designerDiv.Designer.refreshProperties(); } else { if (m_targets.Count == 1) { if (Math.Abs(m_point1.x - m_point2.x) > 5 && Math.Abs(m_point1.y - m_point2.y) > 5) { //获取选中控件 FCView target = m_targets[0]; FCRect moveRect = getRectangle(pointToControl(m_point1), pointToControl(m_point2)); List <FCView> newTargets = new List <FCView>(); List <FCView> subControls = target.getControls(); int left = 0, top = 0, right = 0, bottom = 0, idx = 0; int subControlsSize = subControls.Count; for (int i = 0; i < subControlsSize; i++) { FCView subControl = subControls[i]; FCRect bounds = subControl.Bounds; FCRect tempRect = new FCRect(); if (Native.Host.getIntersectRect(ref tempRect, ref moveRect, ref bounds) > 0) { newTargets.Add(subControl); if (idx == 0) { left = bounds.left; top = bounds.top; right = bounds.right; bottom = bounds.bottom; } else { if (left > bounds.left) { left = bounds.left; } if (top > bounds.top) { top = bounds.top; } if (right < bounds.right) { right = bounds.right; } if (bottom < bounds.bottom) { bottom = bounds.bottom; } } idx++; } } if (newTargets.Count > 0) { FCPoint p1 = target.pointToNative(new FCPoint(left, top)); FCPoint p2 = target.pointToNative(new FCPoint(right, bottom)); p1 = divDesigner.pointToControl(p1); p2 = divDesigner.pointToControl(p2); Bounds = convertPRectToBounds(new FCRect(p1.x, p1.y, p2.x, p2.y)); clearTargets(); addTargets(newTargets); m_designerDiv.Designer.refreshProperties(newTargets); } } } } } refreshStatusBar(); m_resizePoint = -1; Cursor = FCCursors.Arrow; FCNative native = Native; native.Host.setCursor(FCCursors.Arrow); native.update(); native.invalidate(); }