/// <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> /// removes dummy item /// </summary> internal void removeDummyItem() { if (_treeNode.Nodes.Count > 0) { TreeNode firstItem = _treeNode.Nodes[0]; if (isDummyItem(firstItem)) { _treeNode.TreeView.BeforeSelect -= TreeHandler.getInstance().TreeNodeBeforeSelect; firstItem.Remove(); _treeNode.TreeView.BeforeSelect += TreeHandler.getInstance().TreeNodeBeforeSelect; } } }
/// <summary> /// set node expand /// </summary> /// <param name = "expand"></param> internal void setExpand(bool expand) { if (expand) { _treeNode.TreeView.BeforeExpand -= TreeHandler.getInstance().BeforeExpandHandler; removeDummyItem(); _treeNode.Expand(); _treeNode.TreeView.BeforeExpand += TreeHandler.getInstance().BeforeExpandHandler; } else { _treeNode.TreeView.BeforeCollapse -= TreeHandler.getInstance().BeforeCollapseHandler; _treeNode.Collapse(true); _treeNode.TreeView.BeforeCollapse += TreeHandler.getInstance().BeforeCollapseHandler; } updateImages(); }
/// <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); }