/// <summary> open temporary editor for tree child create a text control for the editor /// </summary> /// <param name="child"></param> /// <returns></returns> internal Control showTmpEditor(TreeChild child) { Debug.Assert(Misc.IsGuiThread()); if (_form == null) { _form = GuiUtils.FindForm(_treeControl); } GuiUtils.SetTmpEditorOnTagData(_form, _tmpEditor); TextBox text = (_tmpEditor.Control == null ? (TextBox)toControl(_mgTreeControl, CommandType.CREATE_EDIT) : (TextBox)_tmpEditor.Control); text.Show(); //fixed bug #:310473, control is created as hiden we need to show the created editor. ControlUtils.SetBGColor(text, Color.White); text.BorderStyle = BorderStyle.FixedSingle; ControlsMap.getInstance().setMapData(_mgTreeControl, child._mgRow, text); if (CultureInfo.CurrentCulture.TwoLetterISOLanguageName == "ja") // JPN: IME support { child.Modifable = true; } child.setProperties(text); _tmpEditor.Control = text; _tmpEditor.Node = child.getTreeNode(); _tmpEditor.Layout(); ((TagData)_form.Tag).LastFocusedControl = text; GuiUtils.setFocus(text, true, false); return(text); }
/// <summary> /// see ItemsManager#setSelectionIndex(int) /// </summary> /// <param name="number"></param> internal override void setSelectionIndex(int number) { Debug.Assert(Misc.IsGuiThread()); if (number != GuiConstants.NO_ROW_SELECTED) { TreeChild treeChild = (TreeChild)controlsMap.object2Widget(_mgTreeControl, number); if (_prevSelectedTreeNode != null && _prevSelectedTreeNode.TreeView != null /* isDisposed()*/) { // workaround for SWT bug. QCR #729438 Rectangle rect = _prevSelectedTreeNode.Bounds; _treeControl.Invalidate(new Rectangle(rect.X, rect.Y, rect.Width + 10, rect.Height), true); } _treeControl.BeforeSelect -= TreeHandler.getInstance().TreeNodeBeforeSelect; _treeControl.SelectedNode = treeChild.getTreeNode(); _selectedTreeNode = treeChild.getTreeNode(); _prevSelectedTreeNode = _selectedTreeNode; showSelection(); _treeControl.BeforeSelect += TreeHandler.getInstance().TreeNodeBeforeSelect; } else { _treeControl.SelectedNode = null; _prevSelectedTreeNode = null; } }
/// <summary> /// dispose treeItrm /// </summary> internal override void Dispose() { Object parentItem = _treeNode.Parent; TreeView treeview = _treeNode.TreeView; base.Dispose(); TreeEditor treeEditor = _treeManager.getTmpEditor(); if (treeEditor.Node == _treeNode) { treeEditor.Node = null; } // remove might change selection. we dont want to catch it. treeview.BeforeSelect -= TreeHandler.getInstance().TreeNodeBeforeSelect; _treeNode.Remove(); treeview.BeforeSelect += TreeHandler.getInstance().TreeNodeBeforeSelect; if (parentItem is TreeNode) { TreeChild parent = TreeManager.getTreeChild((TreeNode)parentItem); parent.checkAndAddDummyItem(); } }
//<summary> get tree child from tree item</summary> //<param name="treeNode"></param> //<returns></returns> internal static TreeChild getTreeChild(TreeNode treeNode) { Debug.Assert(Misc.IsGuiThread()); ControlsMap controlsMap = ControlsMap.getInstance(); MapData mapdata = controlsMap.getMapData(treeNode); TreeChild child = (TreeChild)controlsMap.object2Widget(mapdata.getControl(), mapdata.getIdx()); return(child); }
/// <summary> /// create parent row /// </summary> /// <param name="parentIdx">index of parent</param> /// <param name="afterSibling">add new node after this sibling, if equals 0, add node as first child</param> /// <param name="mgRow">idx of new node</param> internal void createNode(int parentIdx, int afterSiblingIdx, int mgRow) { Debug.Assert(Misc.IsGuiThread()); TreeNode item = null; Object parent = controlsMap.object2Widget(_mgTreeControl, parentIdx); Debug.Assert(parent != null); int idx = 0; TreeChild afterSibling = null; if (afterSiblingIdx > 0) { afterSibling = (TreeChild)controlsMap.object2Widget(_mgTreeControl, afterSiblingIdx); idx = afterSibling.getIndex() + 1; } if (parent is TreeView) { item = ((TreeView)parent).Nodes.Insert(idx, ""); // ensure that the root is visible even if the tree is not visible. // if not ensured, set expand might not work on nodes and when tree is visible // it will be collapsed. item.EnsureVisible(); } else if (parent is TreeChild) { ((TreeChild)parent).removeDummyItem(); item = (((TreeChild)parent).getTreeNode()).Nodes.Insert(idx, ""); } else { Debug.Assert(false); } TreeChild treeChild = new TreeChild(this, _mgTreeControl, 0, mgRow, item); // check that we do not add node twice Debug.Assert(controlsMap.object2Widget(_mgTreeControl, mgRow) == null); // add treechild to madding controlsMap.add(_mgTreeControl, mgRow, treeChild); // set map data on tree item item.Tag = new TagData(); controlsMap.setMapData(_mgTreeControl, mgRow, item); }
/// <summary> /// move node under parent to a location after 'afterSiblingIdx'. /// </summary> /// <param name="parentIdx">The parent node under which we are moving the node</param> /// <param name="afterSiblingIdx">The new location is after that sibling</param> /// <param name="nodeId">The node to move</param> internal void moveNode(int parentIdx, int afterSiblingIdx, int nodeId) { Debug.Assert(Misc.IsGuiThread()); Object parent = controlsMap.object2Widget(_mgTreeControl, parentIdx); Debug.Assert(parent != null); int idx = 0; TreeChild afterSibling = null; TreeChild nodeToMove = null; //get the treeChild of the node to move nodeToMove = (TreeChild)controlsMap.object2Widget(_mgTreeControl, nodeId); // get the new index under the parent if (afterSiblingIdx > 0) { afterSibling = (TreeChild)controlsMap.object2Widget(_mgTreeControl, afterSiblingIdx); idx = afterSibling.getIndex() + 1; } //inserting an open node, raises the before expand. avoid it. _treeControl.BeforeExpand -= TreeHandler.getInstance().BeforeExpandHandler; // remove from the nodes collection and add at the new location. if (parent is TreeView) { //remove and insert of a root (The parent is the tree itself) ((TreeView)parent).Nodes.Remove(nodeToMove.getTreeNode()); ((TreeView)parent).Nodes.Insert(idx, nodeToMove.getTreeNode()); } else if (parent is TreeChild) { //remove and insert of a node with another node as a parent. (((TreeChild)parent).getTreeNode()).Nodes.Remove(nodeToMove.getTreeNode()); (((TreeChild)parent).getTreeNode()).Nodes.Insert(idx, nodeToMove.getTreeNode()); } else { Debug.Assert(false); } // resume handling 'Before expand'. _treeControl.BeforeExpand += TreeHandler.getInstance().BeforeExpandHandler; }
/// <summary> /// /// </summary> /// <param name="type"></param> /// <param name="sender"></param> /// <param name="e"></param> internal override void handleEvent(EventType type, Object sender, EventArgs e) { ControlsMap controlsMap = ControlsMap.getInstance(); TreeView tree = (TreeView)sender; TreeManager treeManager = GuiUtils.getTreeManager(tree); Point location = new Point(); MapData mapData = null; Point pt; if (e is MouseEventArgs) { location = ((MouseEventArgs)e).Location; } if (tree.IsDisposed) { return; } switch (type) { case EventType.GOT_FOCUS: treeManager.setFocusTime(); break; case EventType.NODE_MOUSE_HOVER: mapData = controlsMap.getMapData(((TreeNodeMouseHoverEventArgs)e).Node); break; case EventType.MOUSE_LEAVE: //workaround for .NET problem mouseleave is sent too much times for every tree node //we must check if the tooltip left tree pt = tree.PointToClient(Control.MousePosition); if (tree.ClientRectangle.Contains(pt)) { return; } break; case EventType.MOUSE_UP: tree.MouseMove += TreeHandler.getInstance().MouseMoveHandler; treeManager.InExpand = false; break; case EventType.MOUSE_DOWN: treeManager.setMouseDownTime(); break; case EventType.MOUSE_MOVE: // Mouse move only to decide, whether we should start drag operation or not. // Should not handle MouseMove further : Need to handle NodeMouseHover is instead of mousemove Control control = (Control)sender; if (!treeManager.InExpand && GuiUtils.ShouldPerformBeginDrag(control, (MouseEventArgs)e)) { mapData = GuiUtils.getContainerManager(control).HitTest(new Point(((MouseEventArgs)e).X, ((MouseEventArgs)e).Y), true, false); // mapData == null means we are on the node's sign. if (mapData != null) { //Before starting to drag, if we are dragging from a different node //the selected node, move the selected node before starting to drag. // (* it will actually do something only for RTE not RC). if (tree.SelectedNode != null) { MapData oldNodmapDataDrag = controlsMap.getMapData(tree.SelectedNode); int oldLineDrag = oldNodmapDataDrag.getIdx(); if (mapData.getIdx() != oldLineDrag) { Events.OnTreeNodeSelectChange(mapData.getControl(), oldLineDrag, mapData.getIdx()); } } GuiUtils.BeginDrag(control, (MouseEventArgs)e, mapData); } } return; case EventType.DRAG_DROP: control = (Control)sender; pt = new Point(((DragEventArgs)e).X, ((DragEventArgs)e).Y); Point screen = control.PointToClient(pt); mapData = GuiUtils.getContainerManager(control).HitTest(screen, true, false); // mapData == null means we are on the node's sign. if (mapData != null) { //Before starting to drop, if we are dropping on a different node //the selected node, move the selected node before starting to drop. // (* it will actually do something only for RTE not RC). if (tree.SelectedNode != null) { MapData oldNodmapDataDrop = controlsMap.getMapData(tree.SelectedNode); int oldLineDrop = oldNodmapDataDrop.getIdx(); if (mapData.getIdx() != oldLineDrop) { Events.OnTreeNodeSelectChange(mapData.getControl(), oldLineDrop, mapData.getIdx()); } } } break; case EventType.LABEL_EDIT: if (!treeManager.IsLabelEditAllowed) { ((NodeLabelEditEventArgs)e).CancelEdit = true; } else { mapData = controlsMap.getMapData(((NodeLabelEditEventArgs)e).Node); Events.OnEditNode(mapData.getControl(), mapData.getIdx()); } return; case EventType.KEY_DOWN: KeyEventArgs keyEventArgs = (KeyEventArgs)e; // check if we should handle the key down (in default handler) or let the // tree continue with its default behavior. if (!Events.ShouldHandleTreeKeyDown(keyEventArgs.KeyCode)) { return; // let tree send default expand collapse event } break; case EventType.RESIZE: treeManager.resize(); return; case EventType.SCROLL: case EventType.MOUSE_WHEEL: GuiUtils.checkAndCloseTreeEditorOnClick(tree); return; case EventType.BEFOR_EXPAND: treeManager.InExpand = true; mapData = controlsMap.getMapData(((TreeViewCancelEventArgs)e).Node); TreeChild treeChild = (TreeChild)controlsMap.object2Widget(mapData.getControl(), mapData.getIdx()); Events.OnExpand(mapData.getControl(), mapData.getIdx()); ((TreeViewCancelEventArgs)e).Cancel = true; return; case EventType.BEFOR_COLLAPSE: mapData = controlsMap.getMapData(((TreeViewCancelEventArgs)e).Node); Events.OnCollapse(mapData.getControl(), mapData.getIdx()); ((TreeViewCancelEventArgs)e).Cancel = true; return; case EventType.BEFORE_SELECT: MapData oldNodmapData = null; int oldLine = 0; mapData = controlsMap.getMapData(((TreeViewCancelEventArgs)e).Node); if (mapData != null) { GuiMgControl mgControl = mapData.getControl(); int newLine = mapData.getIdx(); if (tree.SelectedNode != null) { oldNodmapData = controlsMap.getMapData(tree.SelectedNode); oldLine = oldNodmapData.getIdx(); } // if true, cancel the change (true for online, false for RC) // in online there is handling for the select change and we don't want it to // happen here. if (Events.OnTreeNodeSelectChange(mgControl, oldLine, newLine)) { ((TreeViewCancelEventArgs)e).Cancel = true; } } else { ((TreeViewCancelEventArgs)e).Cancel = true; } return; } DefaultContainerHandler.getInstance().handleEvent(type, (Control)sender, e, mapData); }