示例#1
0
		/// <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();
		}
示例#2
0
		protected override void OnMouseLeave(EventArgs e)
		{
			base.OnMouseLeave(e);

			if (m_oDragDropPop != null)
			{
				m_oDragDropPop.Hide();
				m_oDragDropPop.Dispose();
			}

			ClearDesignHighlight();

			ClearHover();

			m_bFocus = false;

			if (MouseOverNode != null)
				InvokeNodeMouseLeave(MouseOverNode);
			
			MouseOverNode = null;
			HighlightedNode = null;
			m_oDragOverNode = null;
			m_bDragDropNode = false;
			m_oDragNode = null;			
			DragDropNode = null;
			m_oButtonClicked = System.Windows.Forms.MouseButtons.None;

			Invalidate();
		}
示例#3
0
		protected override void OnMouseUp(MouseEventArgs e)
		{
			base.OnMouseUp(e);

			if (m_oDragDropPop != null)
			{
				m_oDragDropPop.Hide();
				m_oDragDropPop.Dispose();
			}

			// check the place, get the object, its popup menu and show it
			Component oComponent = this.GetSubObjectAtPoint(new Point(e.X, e.Y));

			if (oComponent is Node)
				InvokeNodeMouseUp(e, oComponent as Node);

			// flag object
			if (this.Flags == true && IsNodeFlag(new Point(e.X, e.Y)) == true)
			{
				Node oNode = GetNodeByItemFlag(GetNodeFlagRect(new Point(e.X, e.Y)));
				InvokeNodeFlagMouseUp(e, oNode);
			}

			#region droping at node

			Node oDropNode = oComponent as Node;
			string key = null;

			if (m_oDragNode != null)
				key = m_oDragNode.Key;

			if (oDropNode != null && oDropNode.AllowDrop == true)
			{
				// perform the drop of the node
				if (m_bDragDropNode == true && oDropNode != null && oDropNode != m_oDragNode)
				{
					Node oCopyNode = m_oDragNode;

					// check where we are dropping, we can test the TreeView's nodedrop variables							
					if (DragDropNode != null
						&& DragDropNode.NodeDropMode == NodeDropMode.DropUnder)
					{
						// drop at the node
						// add the node to the new parent holder							
						oCopyNode.TreeView = oDropNode.TreeView;

						oCopyNode.NodeMoving = true;

						if (oCopyNode.IsSomeParent(oDropNode) == false)
						{
							InvokeBeforeNodePositionChange(oCopyNode);
							m_oDragNode.Remove();
							oCopyNode.SetParent(oDropNode);
							oDropNode.Nodes.Insert(0, oCopyNode);
							InvokeAfterNodePositionChange(oCopyNode);

							oDropNode.IsExpanded = true;
						}

						oCopyNode.NodeMoving = false;

						foreach (Node oSubNode in oCopyNode.Nodes)
							oSubNode.m_nCollectionOrder = oSubNode.YOrder;
					}
					else if (DragDropNode != null
						&& DragDropNode.NodeDropMode == NodeDropMode.DropAfter)
					{
						// we are droping the node behind the drop node selected
						Node oNode = DragDropNode.DropNode;

						if (oNode.Collection.Count - 1 == oNode.Index)
						{
							// add the node to the new parent holder							
							oCopyNode.TreeView = oNode.TreeView;
							oCopyNode.NodeMoving = true;

							if (oCopyNode.IsSomeParent(oNode) == false)
							{
								InvokeBeforeNodePositionChange(oCopyNode);
								m_oDragNode.Remove();
								oCopyNode.SetParent(oNode.Parent);
								oNode.Collection.Add(oCopyNode);
								InvokeAfterNodePositionChange(oCopyNode);

								oDropNode.IsExpanded = true;
							}

							oCopyNode.NodeMoving = false;
						}
						else
						{
							// add the node to the new parent holder							
							oCopyNode.TreeView = oNode.TreeView;
							oCopyNode.NodeMoving = true;

							if (oCopyNode.IsSomeParent(oNode) == false)
							{
								InvokeBeforeNodePositionChange(oCopyNode);
								m_oDragNode.Remove();
								oCopyNode.SetParent(oNode.Parent);
								oNode.Collection.Insert(oNode.Index + 1, oCopyNode);
								InvokeAfterNodePositionChange(oCopyNode);

								oDropNode.IsExpanded = true;
							}

							oCopyNode.NodeMoving = false;
						}
					}
					else if (DragDropNode != null
						&& DragDropNode.NodeDropMode == NodeDropMode.DropInfront)
					{
						// we are droping the node infront the drop node selected
						Node oNode = DragDropNode.DropNode;

						// add the node to the new parent holder							
						oCopyNode.TreeView = oNode.TreeView;
						oCopyNode.NodeMoving = true;

						if (oCopyNode.IsSomeParent(oNode) == false)
						{
							InvokeBeforeNodePositionChange(oCopyNode);
							m_oDragNode.Remove();
							oCopyNode.SetParent(oNode.Parent);
							oNode.Collection.Insert(oNode.Index, oCopyNode);
							InvokeAfterNodePositionChange(oCopyNode);

							oDropNode.IsExpanded = true;
						}

						oCopyNode.NodeMoving = false;
					}

					foreach (Node oCollectionNode in oCopyNode.Collection)
						oCollectionNode.m_nCollectionOrder = oCollectionNode.Index;
				}
			}

			if (m_oDragNode != null)
			{
				ClearNodeKey(key);
				m_oDragNode.Key = key;
			}

			#endregion	

			m_oButtonClicked = MouseButtons.None;
			m_bDragDropNode = false;
			DragDropNode = null;
			m_oDragNode = null;

			Invalidate();
		}