/// <summary> /// Overrides the default message/event handler to perform our design time magic editing /// </summary> /// <param name="m"></param> protected override void WndProc(ref Message m) { // if the message is not or TreeView, just skip it if (m.HWnd != m_oTreeView.Handle) { // but if it is a TreeView's scrollbar, let the control handle the event if (m.HWnd == m_oTreeView.m_oScrollBar.Handle) { DefWndProc(ref m); return; } base.WndProc(ref m); return; } try { Point p = new Point(m.LParam.ToInt32()); bool bControl = ((m.WParam.ToInt32() & MK_CONTROL) != 0); bool bShift = ((m.WParam.ToInt32() & MK_SHIFT) != 0); bool lButton = ((m.WParam.ToInt32() & MK_LBUTTON) != 0); if (m.Msg == WM_MOUSEWHEEL) { base.WndProc(ref m); } switch (m.Msg) { case WM_MOVE: case WM_SIZE: base.WndProc(ref m); break; case WM_LBUTTONDBLCLK: if (m_oSelectedNode == null) break; if (m_oSelectedNode.IsExpanded == true) { // inplace editing m_InplaceEdit = new InplaceEditForm(m_oSelectedNode, this); Rectangle nodeRect = m_oTreeView.GetNodeRect(m_oSelectedNode); m_InplaceEdit.BackColor = m_oSelectedNode.GetSelectedBackColor(); m_InplaceEdit.Location = m_oTreeView.Parent.PointToScreen(m_oTreeView.Location); m_InplaceEdit.Left += nodeRect.Left + 1; m_InplaceEdit.Top += nodeRect.Top - 3; m_InplaceEdit.Width = nodeRect.Width + 2; m_InplaceEdit.Height = nodeRect.Height + 3; m_InplaceEdit.Show(); m_InplaceEdit.FocusTextBox(); break; } m_oSelectedNode.IsExpanded = !m_oSelectedNode.IsExpanded; break; case WM_LBUTTONDOWN: Cursor.Current = System.Windows.Forms.Cursors.Arrow; #region Lbutton down m_bMouseDown = true; m_oMouseDown = p; m_oTreeView.ClearDesignHighlight(); m_oSelectedNode = null; // check if have not clicked the right corner when scrollbars are in place if (m_oTreeView.Controls.Contains(m_oTreeView.m_oHScrollBar) && m_oTreeView.Controls.Contains(m_oTreeView.m_oScrollBar)) { if (p.X > m_oTreeView.m_oHScrollBar.Right && p.Y > m_oTreeView.m_oScrollBar.Bottom) { m_oTreeView.ClearAllSelection(); m_oTreeView.ClearDesignSelection(); m_oTreeView.ClearDesignHighlight(); m_bSkipSelectionChange = true; m_oSelectionService.SetSelectedComponents(new Component[] {m_oTreeView}, SelectionTypes.Replace); m_bSkipSelectionChange = false; break; } } // try to find the group or node object and set the object to the property window Component oComponent = m_oTreeView.GetSubObjectAtPoint(p); if (oComponent != null) { if (oComponent is Node) { Node oNode = oComponent as Node; m_oTreeView.ClearDesignSelection(); if (bControl == false && bShift == false) { m_oTreeView.ClearDesignSelection(); m_oTreeView.ClearDesignHighlight(); m_oTreeView.ClearAllSelection(); } if (bShift == true) { ArrayList selection = new ArrayList(); // for every node between selected node and the clicked node, alter the selection int startOrder = 0; if (m_oTreeView.SelectedNode != null) startOrder = m_oTreeView.SelectedNode.NodeOrder; int endOrder = oNode.NodeOrder; if (startOrder <= endOrder) { for (int order = startOrder; order <= endOrder; order++) { Node node = m_oTreeView.GetNodeByOrder(order); if (node == null) continue; node.TreeView = m_oTreeView; node.SelectInternal(true); selection.Add(node); } } else { for (int order = endOrder; order <= startOrder; order++) { Node node = m_oTreeView.GetNodeByOrder(order); if (node == null) continue; node.TreeView = m_oTreeView; node.SelectInternal(true); selection.Add(node); } } m_bSkipSelectionChange = true; m_oSelectionService.SetSelectedComponents(selection, SelectionTypes.Replace); m_bSkipSelectionChange = false; oNode.DesignSelected = true; m_oTreeView.Invalidate(); } else { if (oNode.IsSelected == true) { oNode.TreeView = m_oTreeView; oNode.IsSelected = false; oNode.DesignSelected = false; m_bSkipSelectionChange = true; if (bControl == true) m_oSelectionService.SetSelectedComponents(new Component[] {oNode}, SelectionTypes.Auto); m_oTreeView.Invalidate(); m_bSkipSelectionChange = false; } else { oNode.TreeView = m_oTreeView; oNode.SelectInternal(true); oNode.DesignSelected = true; m_oDragNode = oNode; m_oSelectedNode = oNode; m_bSkipSelectionChange = true; if (bControl == false) m_oSelectionService.SetSelectedComponents(new Component[] {oNode}, SelectionTypes.Replace); else m_oSelectionService.SetSelectedComponents(new Component[] {oNode}, SelectionTypes.Auto); m_oTreeView.Invalidate(); m_bSkipSelectionChange = false; } } } break; } if (m_oTreeView.Style.ShowPlusMinus == true && m_oTreeView.IsExpandBox(p) == true) { Node oNode = m_oTreeView.GetNodeByItemBox(m_oTreeView.GetExpandBoxRect(p)); if (oNode != null) { if (oNode.IsExpanded == true && oNode.CanCollapse == true) oNode.IsExpanded = false; else if (oNode.IsExpanded == false) oNode.IsExpanded = true; } try { RaiseComponentChanging(TypeDescriptor.GetProperties(oNode)["IsExpanded"]); } catch { } try { RaiseComponentChanged(TypeDescriptor.GetProperties(oNode)["IsExpanded"], null, null); } catch { } break; } if (m_oTreeView.IsNodeCheckBox(p) == true) { Node oNode = m_oTreeView.GetNodeByItemCheckBox(m_oTreeView.GetNodeCheckBoxRect(p)); oNode.ToggleChecked(); try { RaiseComponentChanging(TypeDescriptor.GetProperties(oNode)["Checked"]); } catch { } try { RaiseComponentChanged(TypeDescriptor.GetProperties(oNode)["Checked"], null, null); } catch { } break; } m_oTreeView.ClearAllSelection(); m_oTreeView.ClearDesignSelection(); m_oTreeView.ClearDesignHighlight(); m_bSkipSelectionChange = true; m_oSelectionService.SetSelectedComponents(new Component[] {m_oTreeView}, SelectionTypes.Replace); m_bSkipSelectionChange = false; #endregion break; case WM_MOUSEMOVE: #region mouse move if (m_oSelector.Visible == false) { POINT screenPoint = new POINT(); screenPoint.x = m_oTreeView.Location.X - 8; screenPoint.y = m_oTreeView.Location.Y - 8; User32.ClientToScreen(m_oTreeView.Parent.Handle, ref screenPoint); // m_oSelector.Show(screenPoint.x, screenPoint.y); } // try to find the group or node object and set the object to the property window oComponent = m_oTreeView.GetSubObjectAtPoint(p); Cursor.Current = System.Windows.Forms.Cursors.Arrow; // if we are dragging and the button is not pressed, then skip the dragging if (m_bIsDragging == true && lButton == false) { m_oTreeView.DragDropNode = null; m_bMouseDown = false; m_bIsDragging = false; m_oDragNode = null; if (m_oDragDropPop != null) { m_oDragDropPop.Close(); m_oDragDropPop.Dispose(); m_oDragDropPop = null; } m_oTreeView.ClearDesignHighlight(); m_oTreeView.Invalidate(); //Cursor.Current = m_oLastCursor; break; } // Test the dragging at the border area if (p.X <= 4 || p.Y <= 4 || p.X >= m_oTreeView.Width - 8 || p.Y >= m_oTreeView.Height - 3) { m_oTreeView.DragDropNode = null; m_bMouseDown = false; m_bIsDragging = false; m_oDragNode = null; if (m_oDragDropPop != null) { m_oDragDropPop.Close(); m_oDragDropPop.Dispose(); m_oDragDropPop = null; } m_oTreeView.ClearDesignHighlight(); m_oTreeView.Invalidate(); //Cursor.Current = m_oLastCursor; break; } if (oComponent != null || m_oTreeView.IsExpandBox(p) == true || m_oTreeView.IsNodeCheckBox(p)) { m_oLastCursor = Cursor.Current; Cursor.Current = System.Windows.Forms.Cursors.Arrow; } //else //Cursor.Current = m_oLastCursor; // start the dragging of the mouse is moving and the mouse button is still at its down state #region dragdrop start test if (m_bIsDragging == false && m_bMouseDown == true && (oComponent is Node) && m_oMouseDown != p && (m_oDragDropPop == null || m_oDragDropPop.Visible == false)) { if (Math.Abs(m_oMouseDown.X - p.X) > 3 || Math.Abs(m_oMouseDown.Y - p.Y) > 3) { m_bIsDragging = true; m_oDragNode = oComponent as Node; if (m_oDragNode != null) { m_oDragDropPop = new DragDropPopup(m_oDragNode); m_oDragDropPop.Show(); m_oTreeView.Focus(); } } } #endregion // test the moving if the moving is at some drop node allow the drop and if it is at something // not allowed, then draw the dragdrop node control in red background #region dragdrop node drop test if (m_bIsDragging == true && m_bMouseDown == true && m_oMouseDown != p && m_oDragDropPop != null) { m_oDragDropPop.CanDrop = false; m_oDragDropPop.IsCopy = bControl; m_oDragDropPop.Left = m_oTreeView.PointToScreen(p).X + 10; m_oDragDropPop.Top = m_oTreeView.PointToScreen(p).Y + 10; // get the drop object and check if we can drop it here // try to find the group or node object and set the object to the property window Node oCanDropNode = m_oTreeView.GetSubObjectAtPoint(p) as Node; if (oCanDropNode != null) { if (m_oDragNode != null && m_oDragNode.IsSomeParent(oCanDropNode) == false) m_oDragDropPop.CanDrop = true; } if (oCanDropNode != null && oCanDropNode.IsExpanded == false) { // start the expand timer m_oTimerExpandNode = oCanDropNode; Timer timer = new Timer(); timer.Interval = 800; timer.Tick += new EventHandler(this.ExpandTimerTick); timer.Enabled = true; } m_oDragDropPop.Refresh(); } #endregion // test the dragdrop while moving, if the scroller is used in the nodes area, then start the scrolling thread // and if the scrolling thread is running and the mouse has left the autoscroll area, then stop the scrolling #region dragdrop nodes autoscroll if (m_bIsDragging == true && m_oTreeView.Controls.Contains(m_oTreeView.m_oScrollBar) == true && m_oDragNode != null) { int nAdd = 10; if (m_oTreeView.Controls.Contains(m_oTreeView.m_oHScrollBar)) nAdd += m_oTreeView.m_oHScrollBar.Height; if (p.Y < 10) { if (m_oDragScrollThread != null) try { m_oDragScrollThread.Abort(); } catch { } m_oDragScrollThread = new System.Threading.Thread(new System.Threading.ThreadStart(this.OnDragScrollDown)); m_oDragScrollThread.Start(); } else if (p.Y > m_oTreeView.Height - nAdd) { if (m_oDragScrollThread != null) try { m_oDragScrollThread.Abort(); } catch { } m_oDragScrollThread = new System.Threading.Thread(new System.Threading.ThreadStart(this.OnDragScrollUp)); m_oDragScrollThread.Start(); } else { // if the mouse is outside the scrolling area and the scrolling thread is running stop the scrolling if (m_oDragScrollThread != null) try { m_oDragScrollThread.Abort(); } catch { } } } #endregion // create the highlighting while mouse draging if (oComponent != null) { m_oTreeView.ClearDesignHighlight(); // check for the node, if we are moving above the node, check if we are not in the dragging mode #region Node dragdrop structure creation and dragdrop check if (oComponent is Node && m_oDragNode != null) { Node oNode = oComponent as Node; if (oNode == m_oDragNode) break; // we are not dragging, just hightlight the node if (m_bIsDragging == false) { oNode.DesignHighlighted = true; m_oTreeView.Invalidate(); } else { // we are in the dragging mode, get the node's rectangle and do some more calculations and // operations here Rectangle oRect = m_oTreeView.GetNodeRect(oNode); // test the area where we are with the actual point of drag. if (p.Y >= oRect.Top && p.Y < oRect.Top + ((float) oRect.Height/2.0)) { if (p.X > m_oMouseDown.X + 3) // we are in the upper part of the node, but in the right side, drop under m_oTreeView.DragDropNode = new NodeDragDrop(m_oDragNode, oNode, NodeDropMode.DropUnder); else // we are in the upper part of the node m_oTreeView.DragDropNode = new NodeDragDrop(m_oDragNode, oNode, NodeDropMode.DropInfront); } else if (p.Y >= oRect.Top + ((float) oRect.Height/2.0) && p.Y <= oRect.Bottom) { // we are in the lower part of the node if (p.X > m_oMouseDown.X + 3) // test the X coordinate, if we are in the right from the pop, then behave in that way m_oTreeView.DragDropNode = new NodeDragDrop(m_oDragNode, oNode, NodeDropMode.DropUnder); else // test the X coordinate, if we are in the right from the pop, then behave in that way m_oTreeView.DragDropNode = new NodeDragDrop(m_oDragNode, oNode, NodeDropMode.DropAfter); } } } #endregion // node design highlight check if (oComponent is Node && m_oDragNode == null) { Node oNode = oComponent as Node; oNode.DesignHighlighted = true; m_oTreeView.Invalidate(); if (oNode != m_oHighlightedNode) { OnNodeMouseLeave(m_oHighlightedNode); OnNodeMouseEnter(oNode); m_oHighlightedNode = oNode; } } break; } OnNodeMouseLeave(m_oHighlightedNode); m_oHighlightedNode = null; m_oTreeView.ClearDesignHighlight(); m_oTreeView.Invalidate(); #endregion break; case WM_LBUTTONUP: Cursor.Current = System.Windows.Forms.Cursors.Arrow; #region button up // stop the drag drop scrolling thread if (m_oDragScrollThread != null) try { m_oDragScrollThread.Abort(); } catch { } if (m_oDragNode == null || m_bIsDragging == false) { m_bMouseDown = false; m_bIsDragging = false; m_oDragNode = null; if (m_oDragDropPop != null) { m_oDragDropPop.Close(); m_oDragDropPop.Dispose(); m_oDragDropPop = null; } m_oTreeView.DragDropNode = null; m_oTreeView.Invalidate(); break; } if (m_bIsDragging == true && m_oDragDropPop.CanDrop == false) { m_bMouseDown = false; m_bIsDragging = false; m_oDragNode = null; m_oTreeView.DragDropNode = null; m_oDragDropPop.Close(); m_oDragDropPop.Dispose(); m_oDragDropPop = null; m_oTreeView.Invalidate(); break; } // try to find the group or node object and set the object to the property window Node oDropNode = m_oTreeView.GetSubObjectAtPoint(p) as Node; // test the drop target if we are not droping at the same place if (oDropNode != null && m_oDragNode != null && oDropNode == m_oDragNode) { m_bMouseDown = false; m_bIsDragging = false; if (m_oDragDropPop != null) { m_oDragDropPop.Close(); m_oDragDropPop.Dispose(); m_oDragDropPop = null; } m_oTreeView.DragDropNode = null; m_oTreeView.Invalidate(); break; } #region droping at node // perform the drop of the node if (oDropNode != null) { // remove the node from its parent collection if (bControl == false) m_oDragNode.Collection.Remove(m_oDragNode); Node oCopyNode = m_oDragNode; if (bControl == true) oCopyNode = CloneNode(m_oDragNode); // check where we are dropping, we can test the TreeView's nodedrop variables if (m_oTreeView.DragDropNode != null && m_oTreeView.DragDropNode.NodeDropMode == NodeDropMode.DropUnder) { // drop at the node // add the node to the new parent holder oCopyNode.TreeView = oDropNode.TreeView; oCopyNode.SetParent(oDropNode); oCopyNode.YOrder = 0; oDropNode.Nodes.Insert(0, oCopyNode); foreach (Node oSubNode in oCopyNode.Nodes) oSubNode.m_nCollectionOrder = oSubNode.YOrder; } else if (m_oTreeView.DragDropNode != null && m_oTreeView.DragDropNode.NodeDropMode == NodeDropMode.DropAfter) { // we are droping the node behind the drop node selected Node oNode = m_oTreeView.DragDropNode.DropNode; if (oNode.Collection.Count - 1 == oNode.Index) { // add the node to the new parent holder oCopyNode.TreeView = oNode.TreeView; oCopyNode.NodeMoving = true; oCopyNode.Parent = oNode.Parent; oNode.Collection.Add(oCopyNode); oCopyNode.NodeMoving = false; } else { // add the node to the new parent holder oCopyNode.TreeView = oNode.TreeView; oCopyNode.NodeMoving = true; oCopyNode.Parent = oNode.Parent; oNode.Collection.Insert(oNode.Index + 1, oCopyNode); oCopyNode.NodeMoving = false; } } else if (m_oTreeView.DragDropNode != null && m_oTreeView.DragDropNode.NodeDropMode == NodeDropMode.DropInfront) { // we are droping the node infront the drop node selected Node oNode = m_oTreeView.DragDropNode.DropNode; // add the node to the new parent holder oCopyNode.TreeView = oNode.TreeView; oCopyNode.NodeMoving = true; oCopyNode.Parent = oNode.Parent; oNode.Collection.Insert(oNode.Index, oCopyNode); oCopyNode.NodeMoving = false; } foreach (Node oCollectionNode in oCopyNode.Collection) oCollectionNode.m_nCollectionOrder = oCollectionNode.Index; // call the update of the properties try { RaiseComponentChanging(TypeDescriptor.GetProperties(oCopyNode)["Parent"]); } catch { } try { RaiseComponentChanged(TypeDescriptor.GetProperties(oCopyNode)["Parent"], null, null); } catch { } try { RaiseComponentChanging(TypeDescriptor.GetProperties(oDropNode)["Nodes"]); } catch { } try { RaiseComponentChanged(TypeDescriptor.GetProperties(oDropNode)["Nodes"], null, null); } catch { } try { RaiseComponentChanging(TypeDescriptor.GetProperties(typeof (Node))["NodeStyle"]); } catch { } try { RaiseComponentChanged(TypeDescriptor.GetProperties(typeof (Node))["NodeStyle"], null, null); } catch { } try { RaiseComponentChanging(TypeDescriptor.GetProperties(typeof (Node))["NodeStyleSource"]); } catch { } try { RaiseComponentChanged(TypeDescriptor.GetProperties(typeof (Node))["NodeStyleSource"], null, null); } catch { } try { RaiseComponentChanging(TypeDescriptor.GetProperties(typeof (Node))["Text"]); } catch { } try { RaiseComponentChanged(TypeDescriptor.GetProperties(typeof (Node))["Text"], null, null); } catch { } try { RaiseComponentChanging(TypeDescriptor.GetProperties(typeof (Node))["ContextMenu"]); } catch { } try { RaiseComponentChanged(TypeDescriptor.GetProperties(typeof (Node))["ContextMenu"], null, null); } catch { } try { RaiseComponentChanging(TypeDescriptor.GetProperties(typeof (Node))["ContextMenuSource"]); } catch { } try { RaiseComponentChanged(TypeDescriptor.GetProperties(typeof (Node))["ContextMenuSource"], null, null); } catch { } try { RaiseComponentChanging(TypeDescriptor.GetProperties(typeof (Node))["Image"]); } catch { } try { RaiseComponentChanged(TypeDescriptor.GetProperties(typeof (Node))["Image"], null, null); } catch { } try { RaiseComponentChanging(TypeDescriptor.GetProperties(typeof (Node))["Imageindex"]); } catch { } try { RaiseComponentChanged(TypeDescriptor.GetProperties(typeof (Node))["ImageIndex"], null, null); } catch { } //oDropNode.ExpandAll(); } #endregion // clear the dragdrop properties m_bMouseDown = false; m_bIsDragging = false; m_oDragNode = null; m_oTreeView.DragDropNode = null; m_oTreeView.Invalidate(); if (m_oDragDropPop != null) { m_oDragDropPop.Close(); m_oDragDropPop.Dispose(); m_oDragDropPop = null; } #endregion break; case WM_MOUSELEAVE: m_oTreeView.DragDropNode = null; m_bMouseDown = false; m_bIsDragging = false; m_oDragNode = null; if (m_oDragDropPop != null) { m_oDragDropPop.Close(); m_oDragDropPop.Dispose(); m_oDragDropPop = null; } m_oTreeView.ClearDesignHighlight(); m_oTreeView.Invalidate(); OnNodeMouseLeave(m_oHighlightedNode); m_oHighlightedNode = null; //m_oSelector.Hide(); break; case WM_PAINT: // when there are some node to be destroyed from the clipboard action, then do it // we have to do it here beacuse there is not an event that we can handle once the // clipboard action is finished foreach (Node node in NodeComponentToDestroy.ToArray()) { node.DestroyComponent(m_oDesignerHost); node.Remove(); } NodeComponentToDestroy.Clear(); base.WndProc(ref m); break; default: base.WndProc(ref m); break; } } catch (Exception e) { MessageBox.Show(e.ToString()); } }
/// <summary> /// /// </summary> /// <param name="e"></param> protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); // if (m_bMouseMoveLocked == true) // return; Point p = new Point(e.X, e.Y); Node oMouseMoveNode = GetSubObjectAtPoint(p) as Node; // get the mouse down info and the coordinates, if we are starting to move mouse over the clicked node // then start the drag drop operation if (AutoDragDrop == true) { if (m_oButtonClicked == MouseButtons.Left && m_oDragNode == null && oMouseMoveNode != null && m_bDragDropNode == false) { if (Math.Abs(m_oMouseClickPoint.X - p.X) > 3 || Math.Abs(m_oMouseClickPoint.Y - p.Y) > 3) { if (oMouseMoveNode.AllowDrag == true) { m_bDragDropNode = true; m_oDragNode = oMouseMoveNode; if (m_oDragNode != null) { m_oDragDropPop = new DragDropPopup(m_oDragNode); m_oDragDropPop.Show(); this.Focus(); } } } } } #region dragdrop node drop test if (m_bDragDropNode == true && m_oDragDropPop != null) { m_oDragDropPop.CanDrop = false; m_oDragDropPop.Left = this.PointToScreen(p).X + 10; m_oDragDropPop.Top = this.PointToScreen(p).Y + 10; // get the drop object and check if we can drop it here // try to find the group or node object and set the object to the property window Node oCanDropNode = this.GetSubObjectAtPoint(p) as Node; if (oCanDropNode != null) { if (oCanDropNode.AllowDrop == true) { if (m_oDragNode != null && m_oDragNode.IsSomeParent(oCanDropNode) == false) m_oDragDropPop.CanDrop = true; } else m_oDragDropPop.CanDrop = false; } if (oCanDropNode != null && oCanDropNode.IsExpanded == false) { // start the expand timer m_oTimerExpandNode = oCanDropNode; System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer(); timer.Interval = 800; timer.Tick += new EventHandler(this.ExpandTimerTick); timer.Enabled = true; } m_oDragDropPop.Refresh(); } #endregion #region dragdrop autoscroll if (Controls.Contains(m_oScrollBar) == true && m_oDragNode != null) { if (p.Y < 10 && m_bDragScrollDownRunning == false) { if (m_oDragScrollThread != null) try { m_oDragScrollThread.Abort(); } catch { } m_oDragScrollThread = new Thread(new ThreadStart(this.OnDragScrollDown)); m_oDragScrollThread.Start(); } else if (p.Y > this.Height - 10 && m_bDragScrollUpRunning == false) { if (m_oDragScrollThread != null) try { m_oDragScrollThread.Abort(); } catch { } m_oDragScrollThread = new Thread(new ThreadStart(this.OnDragScrollUp)); m_oDragScrollThread.Start(); } else { // if the mouse is outside the scrolling area and the scrolling thread is running stop the scrolling if (m_oDragScrollThread != null) try { m_oDragScrollThread.Abort(); } catch { } m_bDragScrollDownRunning = false; m_bDragScrollUpRunning = false; } } #endregion #region Node dragdrop structure creation and dragdrop check if (AutoDragDrop == true) { if (oMouseMoveNode != null) { if (m_oDragNode != null && oMouseMoveNode != m_oDragNode) { // we are not dragging, just hightlight the node if (m_bDragDropNode == true) { // we are in the dragging mode, get the node's rectangle and do some more calculations and // operations here Rectangle oRect = GetNodeRect(oMouseMoveNode); // test the area where we are with the actual point of drag. if (p.Y >= oRect.Top && p.Y < oRect.Top + ((float) oRect.Height / 2.0)) { if (p.X > m_oMouseClickPoint.X + 3) // we are in the upper part of the node, but in the right side, drop under DragDropNode = new NodeDragDrop(m_oDragNode, oMouseMoveNode, NodeDropMode.DropUnder); else // we are in the upper part of the node DragDropNode = new NodeDragDrop(m_oDragNode, oMouseMoveNode, NodeDropMode.DropInfront); } else if (p.Y >= oRect.Top + ((float) oRect.Height / 2.0) && p.Y <= oRect.Bottom) { // we are in the lower part of the node if (p.X > m_oMouseClickPoint.X + 3) // test the X coordinate, if we are in the right from the pop, then behave in that way DragDropNode = new NodeDragDrop(m_oDragNode, oMouseMoveNode, NodeDropMode.DropUnder); else // test the X coordinate, if we are in the right from the pop, then behave in that way DragDropNode = new NodeDragDrop(m_oDragNode, oMouseMoveNode, NodeDropMode.DropAfter); } } } } } #endregion HighlightedNode = null; #region search for the node, if node found, highlight it if (this.Style.TrackNodeHover == true) { foreach (Rectangle r in m_mapRectToSubItem.Keys) { if (r.Contains(e.X, e.Y) == false) continue; Node oNode = m_mapRectToSubItem[r] as Node; if (oNode == null) { base.OnMouseMove(e); return; } if (this.HighlightedNode == oNode) { base.OnMouseMove(e); InvokeNodeMouseMove(e, oNode); return; } this.HighlightedNode = oNode; Invalidate(); if (this.MouseOverNode != null && this.MouseOverNode != oNode) InvokeNodeMouseLeave(MouseOverNode); if (this.MouseOverNode != oNode) { this.MouseOverNode = oNode; InvokeNodeMouseEnter(MouseOverNode); } base.OnMouseMove(e); InvokeNodeMouseMove(e, oNode); return; } } else { foreach (Rectangle r in m_mapRectToSubItem.Keys) { if (r.Contains(e.X, e.Y) == false) continue; Node oNode = m_mapRectToSubItem[r] as Node; if (oNode == null) { base.OnMouseMove(e); return; } if (this.MouseOverNode != null && this.MouseOverNode != oNode) InvokeNodeMouseLeave(MouseOverNode); if (this.MouseOverNode != oNode) { this.MouseOverNode = oNode; InvokeNodeMouseEnter(MouseOverNode); } base.OnMouseMove(e); InvokeNodeMouseMove(e, oNode); Invalidate(); return; } } #endregion bool bInvalidate = false; HighlightedNode = null; if (MouseOverNode != null) { InvokeNodeMouseLeave(MouseOverNode); bInvalidate = true; } MouseOverNode = null; if (bInvalidate == true) Invalidate(); }
/// <summary> /// Called by the framework when the context menu is being shown /// </summary> /// <param name="x"></param> /// <param name="y"></param> protected override void OnContextMenu(int x, int y) { try { m_oTreeView.DragDropNode = null; m_bMouseDown = false; m_bIsDragging = false; m_oDragNode = null; if (m_oDragDropPop != null) { m_oDragDropPop.Close(); m_oDragDropPop.Dispose(); m_oDragDropPop = null; } m_oTreeView.ClearDesignHighlight(); m_oTreeView.Invalidate(); Component oComponent = m_oTreeView.GetSubObjectAtPoint(m_oTreeView.PointToClient(new Point(x, y))); m_oContextMenuPoint = new Point(x, y); if (oComponent is Node) { m_oTreeView.ClearNodeSelection(); m_oTreeView.ClearDesignSelection(); m_oTreeView.ClearDesignHighlight(); Node oNode = oComponent as Node; oNode.TreeView = m_oTreeView; oNode.DesignSelected = true; oNode.Select(); m_oSelectedNode = oNode; m_bSkipSelectionChange = true; m_oSelectionService.SetSelectedComponents(new Component[] {oComponent}, SelectionTypes.Replace); m_bSkipSelectionChange = false; m_oTreeView.ClearDesignHighlight(); m_oTreeView.Invalidate(); m_oActionMenuTreeView.Hide(); m_oActionMenuNode.Show(x - 21, y); return; } m_oTreeView.ClearNodeSelection(); m_oTreeView.ClearDesignSelection(); m_oTreeView.ClearDesignHighlight(); m_oSelectedNode = null; m_bSkipSelectionChange = true; m_oSelectionService.SetSelectedComponents(new Component[] {m_oTreeView}, SelectionTypes.Replace); m_bSkipSelectionChange = false; m_oTreeView.ClearDesignHighlight(); m_oTreeView.Invalidate(); m_oActionMenuNode.Hide(); m_oActionMenuTreeView.Show(x - 21, y); } catch (Exception ex) { System.Console.Out.WriteLine(ex.ToString()); } }