Example #1
0
		public static TreeAreaInfo GetTreeAreaInfo(TreeGX tree, int x, int y)
		{
			TreeAreaInfo areaInfo=new TreeAreaInfo();

            if (tree.Nodes.Count == 0 || !tree.DisplayRectangle.Contains(x, y) && tree.Zoom == 1)
				return null;

			Node node=tree.Nodes[0];
			if(tree.DisplayRootNode!=null)
				node = tree.DisplayRootNode;
			
			Node dragNode = tree.GetDragNode();
			Rectangle dragNodeBounds=NodeDisplay.GetNodeRectangle(eNodeRectanglePart.NodeBounds,dragNode,tree.NodeDisplay.Offset);
			if(dragNodeBounds.Contains(x,y))
			{
				areaInfo.NodeAt=dragNode;
				return areaInfo;
			}

			int dragNodeWidth = dragNode.BoundsRelative.Width;
			Node previousNode = null;
			Rectangle previousRect=Rectangle.Empty;
			
			if(tree.DisplayRootNode!=null)
				node=tree.DisplayRootNode;
			while(node!=null)
			{
				if(!node.IsDisplayed)
				{
					node = node.NextVisibleNode;
					continue;
				}
				Rectangle r=NodeDisplay.GetNodeRectangle(eNodeRectanglePart.NodeBounds,node,tree.NodeDisplay.Offset);
				if(r.Contains(x,y))
				{
					areaInfo.NodeAt = node;
					break;
				}
				
				if(previousNode!=null && node.Parent==previousNode.Parent)
				{
					Rectangle totalArea;
					if(r.Width<dragNodeWidth || previousRect.Width<dragNodeWidth)
					{
						totalArea =
							Rectangle.Union(new Rectangle(r.Location, new Size(dragNodeWidth, r.Height)),
							                new Rectangle(previousRect.Location, new Size(dragNodeWidth, previousRect.Height)));
					}
					else
						totalArea=Rectangle.Union(r,previousRect);
					if(totalArea.Contains(x,y))
					{
						Rectangle r1 = r;
						Rectangle r2 = previousRect;
						if(totalArea.Width>r1.Width) r1.Width = totalArea.Width;
						if(totalArea.Width>r2.Width) r2.Width = totalArea.Width;
						if(!r1.Contains(x,y) && !r2.Contains(x,y))
						{
							areaInfo.PreviousNode = previousNode;
							areaInfo.NextNode = node;
							areaInfo.NodeAt = null;
							areaInfo.ParentAreaNode = node.Parent;
							break;
						}
					}
				}
				
				previousNode = node;
				previousRect = r;
				
                //r=NodeDisplay.GetNodeRectangle(eNodeRectanglePart.ChildNodeBounds,node,tree.NodeDisplay.Offset);

                //if (!r.Contains(x, y))
                //    node = GetNextVisibleSibling(node);
                //else
				node = node.NextVisibleNode;
			}
			return areaInfo;
		}