Пример #1
0
		/// <summary>
		/// Paint the node in the expanded mode
		/// </summary>
		/// <param name="oNode"></param>
		/// <param name="nX"></param>
		/// <param name="nY"></param>
		/// <param name="oGraphics"></param>
		private void PaintNodeExpanded(Node oNode, Graphics oGraphics, ref int nX, ref int nY, int Width, 
			ref Hashtable m_mapSubItemToRect, ref Hashtable m_mapRectToSubItem, ref Hashtable m_mapRectToItemBox, 
			ref Hashtable m_mapItemBoxToRect, ref Hashtable m_mapRectToItemCheck, ref Hashtable m_mapItemCheckToRect, 
			ref Hashtable m_mapRectToItemFlag, ref Hashtable m_mapItemFlagToRect)
		{
			int nXAdd = 0;
			//if (oNode.GetShowPlusMinus() == false)
			//	nXAdd = 15;
			
			if (oNode.GetCheckBoxes() == true && oNode.CheckBoxVisible == true)
				nXAdd -= 18;
			
			int nodeSpace = 0;

			if (oNode.IndentLevel != 0)
				nodeSpace = m_oTreeView.Style.NodeSpaceHorizontal;

			int height = oNode.GetHeight(oGraphics);

			Rectangle oNodeRect = new Rectangle(nX - nXAdd +nodeSpace, nY, 
				Width - nX - 5 + nXAdd - nodeSpace, height);
			
			if (m_oTreeView.Style.FullRowSelect == false && oNode.Panel == null)
			{
				oNodeRect = new Rectangle(nX - nXAdd + nodeSpace, nY, 
					oNode.GetWidth(oGraphics), height);
			}

			// render the background
			if (oNode.BackgroundStyle != null && oNode.BackgroundStyle.Visible == true)
			{
				int width = oNode.GetTreeView().Width - oNodeRect.Left - nXAdd 
					- m_oTreeView.GetScrollBarWidth() - oNode.IndentLevel - 4;

				AreaPainter.PaintRectangle(oGraphics, oNodeRect.Left + 1 + nXAdd, oNodeRect.Top - 1,
					width, oNode.GetFullHeight(oGraphics) - 1, 
					oNode.BackgroundStyle.FillStyle,
					oNode.BackgroundStyle.BackColor, oNode.BackgroundStyle.FadeColor,
					BorderStyle.None, Color.White);
			}			

			oNode.NodeOrder = m_nNodeOrder;
			m_nNodeOrder ++;

			// get the order of the actual group. calculate the bottom nY of the group, if the current nY is bigger than
			// this calculated nY, then skip the drawing and donot draw the object		
			int nMaxY = oNode.TreeView.Height;
			int nGroupY = -height;

			// create the item rect and add it to maps
			try {m_mapSubItemToRect.Add(oNode, oNodeRect);}	catch{}
			try {m_mapRectToSubItem.Add(oNodeRect, oNode);}	catch{}

			oNode.Top = oNodeRect.Top + oNodeRect.Height + 1;
			oNode.Left = oNodeRect.Left;		
			oNode.Width = oNodeRect.Width - m_oTreeView.GetScrollBarWidth();

			SizeF oTextSize = oGraphics.MeasureString(oNode.GetText(), oNode.GetFont(), oNode.GetTreeView().GetDrawWidth() - nX - 8);
			if (m_oTreeView.Multiline == false)
				oTextSize = oGraphics.MeasureString(oNode.GetText(), oNode.GetFont());

			oNode.Top = nY + (int)oTextSize.Height + 2;

			if ((nY >= nGroupY && nY < nMaxY) || oNode.TreeView.IsDesignMode == true)
			{
				// draw flag
				PaintNodeFlag(oNode, oGraphics, oNodeRect, ref m_mapRectToItemFlag, ref m_mapItemFlagToRect);

				// draw selected background
				PaintNodeBackground(oNode, oGraphics, oNodeRect);

				// draw design selection
				PaintNodeBackgroundDesignSelection(oNode, oGraphics, oNodeRect);

				// draw expand/collapse boxes
				if (oNode.GetShowPlusMinus() == true)
					PaintExpandBox(oNode, oGraphics, nX + nodeSpace, nY, ref m_mapRectToItemBox, ref m_mapItemBoxToRect);

				// draw lines between nodes
				PaintNodeLines(oNode, oGraphics, nX + nodeSpace, nY, m_mapItemBoxToRect, m_mapSubItemToRect);
					
				// draw item header
				PaintNodeText(oNode, oGraphics, nX + nodeSpace, nY, ref m_mapRectToItemCheck, ref m_mapItemCheckToRect);				

				// check the design time highlight			
				if (oNode.DesignHighlighted)
				{
					if (oNode.GetCheckBoxes() == false)
					{					
						if (m_oTreeView.Style.FullRowSelect == true || oNode.Panel != null)
						{
							oGraphics.DrawRectangle(Pens.Black, oNodeRect.Left + 2, oNodeRect.Top - 1, 
								Width - oNodeRect.Left - 7 - m_oTreeView.GetScrollBarWidth(), oNodeRect.Height - 2);
						}
						else
						{
							oGraphics.DrawRectangle(Pens.Black, oNodeRect.Left + 2, oNodeRect.Top - 1, 
								(int)oNodeRect.Width, oNodeRect.Height - 2);
						}
					}
					else
					{
						if (oNode.CheckBoxVisible == true)
						{
							if (m_oTreeView.Style.FullRowSelect == true || oNode.Panel != null)
							{
								oGraphics.DrawRectangle(Pens.Black, oNodeRect.Left, oNodeRect.Top - 1, 
									Width - oNodeRect.Left - 7 - m_oTreeView.GetScrollBarWidth() + 2, oNodeRect.Height - 2);
							}
							else
							{
								oGraphics.DrawRectangle(Pens.Black, oNodeRect.Left, oNodeRect.Top - 1, 
									(int)oNodeRect.Width, oNodeRect.Height - 2);
							}
						}
					}
				}
			}	
		
			// for the nodes being drawn before the visible area, but still needed for the 
			// lines painting
			if (nY < nGroupY && oNode.TreeView.IsDesignMode == false)
			{
				// draw expand/collapse boxes
				PaintExpandBox(oNode, oGraphics, nX + nodeSpace, nY, ref m_mapRectToItemBox, ref m_mapItemBoxToRect);
			}

			// for the nodes being at the position under the drawing visible area, draw the lines
			// so it is visible that there are some other child nodes even they are not visible
			if (nY > nMaxY && oNode.TreeView.IsDesignMode == false)
			{
				// draw expand/collapse boxes
				PaintExpandBox(oNode, oGraphics, nX + nodeSpace, nY, ref m_mapRectToItemBox, ref m_mapItemBoxToRect);

				// draw lines between nodes
				PaintNodeLines(oNode, oGraphics, nX + nodeSpace, nY, m_mapItemBoxToRect, m_mapSubItemToRect);
			}

			nY += height;	
	
			nY += m_oTreeView.Style.NodeSpaceVertical;

			// draw all subitems
			if (oNode.TreeView.Sorted == true)
			{
				ArrayList aList = new ArrayList();

				foreach (Node oSubNode in oNode.Nodes)
					aList.Add(oSubNode);

				aList.Sort();

				for (int nNode = 0; nNode < aList.Count; nNode ++)
				{
					Node oSubNode = aList[nNode] as Node;

					if (oSubNode == null || oSubNode.Visible == false)
						continue;

					int nOldNX = nX;
					nX += 12;					

					nX += nodeSpace;

					PaintNode(oSubNode, oGraphics, ref nX, ref nY, Width, ref m_mapSubItemToRect, 
						ref m_mapRectToSubItem, ref m_mapRectToItemBox, ref m_mapItemBoxToRect,
						ref m_mapRectToItemCheck, ref m_mapItemCheckToRect, 
						ref m_mapRectToItemFlag, ref m_mapItemFlagToRect);

					nX = nOldNX;
				}
			}
			else			
			{
				// sort the nodes by the m_nCollectionOrder
//				SortedList aList = new SortedList();

				foreach (Node oSubNode in oNode.Nodes)
				{
					if (oSubNode.m_nCollectionOrder == -1)
						oSubNode.m_nCollectionOrder = oSubNode.Index;

//					try
//					{
//						aList.Add(oSubNode.m_nCollectionOrder, oSubNode);
//					}
//					catch
//					{
//						aList.Add(oSubNode.Index, oSubNode);
//					}
				}

//				for (int nNode = 0; nNode < aList.Count; nNode ++)
				Node [] aList = oNode.Nodes.GetNodesCollectionSorted();
				for (int nNode = 0; nNode < aList.Length; nNode ++)
				{
					//Node oSubNode = aList.GetByIndex(nNode) as Node;
					Node oSubNode = aList[nNode] as Node;

					if (oSubNode.Visible == false)
						continue;

					int nOldNX = nX;
					nX += 12;		
			
					nX += nodeSpace;

					PaintNode(oSubNode, oGraphics, ref nX, ref nY, Width, ref m_mapSubItemToRect, 
						ref m_mapRectToSubItem, ref m_mapRectToItemBox, ref m_mapItemBoxToRect,
						ref m_mapRectToItemCheck, ref m_mapItemCheckToRect, ref m_mapRectToItemFlag, ref m_mapItemFlagToRect);

					nX = nOldNX;
				}
			}
		}
Пример #2
0
		/// <summary>
		/// Paint the node in the closed mode
		/// </summary>
		/// <param name="oNode"></param>
		/// <param name="nX"></param>
		/// <param name="nY"></param>
		/// <param name="oGraphics"></param>
		internal void PaintNode(Node oNode, Graphics oGraphics, ref int nX, ref int nY, int nWidth,
			ref Hashtable m_mapSubItemToRect, ref Hashtable m_mapRectToSubItem, ref Hashtable m_mapRectToItemBox, 
			ref Hashtable m_mapItemBoxToRect, ref Hashtable m_mapRectToItemCheck, ref Hashtable m_mapItemCheckToRect,
			ref Hashtable m_mapRectToItemFlag, ref Hashtable m_mapItemFlagToRect)
		{
			if (oNode == null)
				return;

			oNode._TreeView = m_oTreeView;
			
			if (oNode.NodeStyle != null)
			{
				oNode.NodeStyle.TreeView = this.m_oTreeView;
				oNode.NodeStyle.CheckBoxStyle.TreeView = this.m_oTreeView;
				oNode.NodeStyle.ExpandBoxStyle.TreeView = this.m_oTreeView;
			}
			
			Width = nWidth;

			if (oNode.IsExpanded == true)
			{
				PaintNodeExpanded(oNode, oGraphics, ref nX, ref nY, Width, ref m_mapSubItemToRect, ref m_mapRectToSubItem, 
					ref m_mapRectToItemBox, ref m_mapItemBoxToRect, ref m_mapRectToItemCheck, ref m_mapItemCheckToRect, 
					ref m_mapRectToItemFlag, ref m_mapItemFlagToRect);

				return;
			}			

			int nXAdd = 0;
			//if (oNode.GetShowPlusMinus() == false)
			//	nXAdd = 15;

			if (oNode.GetCheckBoxes() == true && oNode.CheckBoxVisible == true)
				nXAdd -= 18;	
		
			int nodeSpace = 0;

			if (oNode.IndentLevel != 0)
				nodeSpace = m_oTreeView.Style.NodeSpaceHorizontal;

			int height = oNode.GetHeight(oGraphics);

			Rectangle oNodeRect = new Rectangle(nX - nXAdd + nodeSpace, nY, 
				Width - nX - 5 + nXAdd - nodeSpace, height);
			
			if (m_oTreeView.Style.FullRowSelect == false && oNode.Panel == null)
			{
				oNodeRect = new Rectangle(nX - nXAdd + nodeSpace, nY, 
					oNode.GetWidth(oGraphics), height);
			}

			oNode.NodeOrder = m_nNodeOrder;
			m_nNodeOrder ++;
			
			// get the order of the actual group. calculate the bottom nY of the group, if the current nY is bigger than
			// this calculated nY, then skip the drawing and donot draw the object
			int nMaxY = oNode.TreeView.Height;
			int nGroupY = -height;

			// render the background
			if (oNode.BackgroundStyle != null && oNode.BackgroundStyle.Visible == true)
			{
				int width = oNode.GetTreeView().Width - oNodeRect.Left - nXAdd 
					- m_oTreeView.GetScrollBarWidth() - oNode.IndentLevel - 4;

				AreaPainter.PaintRectangle(oGraphics, oNodeRect.Left + 1 + nXAdd, oNodeRect.Top - 1,
					width, oNode.GetFullHeight(oGraphics) - 1, 
					oNode.BackgroundStyle.FillStyle,
					oNode.BackgroundStyle.BackColor, oNode.BackgroundStyle.FadeColor,
					BorderStyle.None, Color.White);
			}

			if (nY > nGroupY && nY < nMaxY)
			{			
				// draw flag
				PaintNodeFlag(oNode, oGraphics, oNodeRect, ref m_mapRectToItemFlag, ref m_mapItemFlagToRect);

				// render selected background
				PaintNodeBackground(oNode, oGraphics, oNodeRect);

				// draw design selection
				PaintNodeBackgroundDesignSelection(oNode, oGraphics, oNodeRect);

				// draw expand/collapse boxes
				if (oNode.GetShowPlusMinus() == true)
					PaintExpandBox(oNode, oGraphics, nX + nodeSpace, nY, ref m_mapRectToItemBox, ref m_mapItemBoxToRect);

				// draw lines between nodes
				PaintNodeLines(oNode, oGraphics, nX + nodeSpace, nY, m_mapItemBoxToRect, m_mapSubItemToRect);

				// draw item header and the subitems indicator
				PaintNodeText(oNode, oGraphics, nX + nodeSpace, nY, ref m_mapRectToItemCheck, ref m_mapItemCheckToRect);			

				// check the design time highlight			
				if (oNode.DesignHighlighted)
				{
					if (oNode.GetCheckBoxes() == false)
					{					
						if (m_oTreeView.Style.FullRowSelect == true || oNode.Panel != null)
						{
							oGraphics.DrawRectangle(Pens.Black, oNodeRect.Left + 2, oNodeRect.Top - 1, 
								Width - oNodeRect.Left - 7 - m_oTreeView.GetScrollBarWidth(), oNodeRect.Height - 2);
						}
						else
						{
							oGraphics.DrawRectangle(Pens.Black, oNodeRect.Left + 2, oNodeRect.Top - 1, 
								(int)oNodeRect.Width, oNodeRect.Height - 2);
						}
					}
					else
					{
						if (oNode.CheckBoxVisible == true)
						{
							if (m_oTreeView.Style.FullRowSelect == true || oNode.Panel != null)
							{
								oGraphics.DrawRectangle(Pens.Black, oNodeRect.Left, oNodeRect.Top - 1, 
									Width - oNodeRect.Left - 7 - m_oTreeView.GetScrollBarWidth() + 2, oNodeRect.Height - 2);
							}
							else
							{
								oGraphics.DrawRectangle(Pens.Black, oNodeRect.Left, oNodeRect.Top - 1, 
									(int)oNodeRect.Width, oNodeRect.Height - 2);
							}
						}
					}					
				}

				// create the item rect and add it to maps
				try{m_mapSubItemToRect.Add(oNode, oNodeRect);}catch{}
				try{m_mapRectToSubItem.Add(oNodeRect, oNode);}catch{}

				oNode.Top = oNodeRect.Top + oNodeRect.Height;
				oNode.Left = oNodeRect.Left;
				oNode.Width = oNodeRect.Width - m_oTreeView.GetScrollBarWidth();
			}

			// for the nodes being drawn before the visible area, but still needed for the 
			// lines painting
			if (nY <= nGroupY)
			{
				// draw expand/collapse boxes
				PaintExpandBox(oNode, oGraphics, nX + nodeSpace, nY, ref m_mapRectToItemBox, ref m_mapItemBoxToRect);
			}

			// for the nodes being at the position under the drawing visible area, draw the lines
			// so it is visible that there are some other child nodes even they are not visible
			if (nY >= nMaxY)
			{
				// draw expand/collapse boxes
				PaintExpandBox(oNode, oGraphics, nX + nodeSpace, nY, ref m_mapRectToItemBox, ref m_mapItemBoxToRect);

				// draw lines between nodes
				PaintNodeLines(oNode, oGraphics, nX + nodeSpace, nY, m_mapItemBoxToRect, m_mapSubItemToRect);
			}

			nY += height;

			nY += m_oTreeView.Style.NodeSpaceVertical;
		}