Пример #1
0
 public static long DoEnumeratorListTest(Tree tree, int repeatCount)
 {
     var sw = new Stopwatch();
     sw.Start();
     var nodeEnumerator = new NodeEnumerator(tree);
     for (var i = 0; i < repeatCount; i++)
     {
         var list = nodeEnumerator.ToList();
     }
     sw.Stop();
     return sw.ElapsedMilliseconds;
 }
Пример #2
0
 public int EnumPresentationNodes(uint dwFlags, out IVsEnumNavInfoNodes ppEnum)
 {
     ppEnum = new NodeEnumerator <SymbolList>(Children);
     return(VSConstants.S_OK);
 }
Пример #3
0
 public int EnumCanonicalNodes(out IVsEnumNavInfoNodes ppEnum)
 {
     ppEnum = new NodeEnumerator <SymbolList>(Children);
     return(VSConstants.S_OK);
 }
Пример #4
0
 public int Clone(out IVsEnumNavInfoNodes ppEnum)
 {
     ppEnum = new NodeEnumerator <T>(_locations);
     return(VSConstants.S_OK);
 }
Пример #5
0
 public int EnumCanonicalNodes(out IVsEnumNavInfoNodes ppEnum)
 {
     ppEnum = new NodeEnumerator <SimpleLocationInfo>(Children);
     return(VSConstants.S_OK);
 }
Пример #6
0
 public int EnumPresentationNodes(uint dwFlags, out IVsEnumNavInfoNodes ppEnum) {
     ppEnum = new NodeEnumerator<SimpleLocationInfo>(Children);
     return VSConstants.S_OK;
 }
Пример #7
0
 public ValuesEnumerator(NodeEnumerator enumerator)
 {
     this.enumerator = enumerator;
 }
Пример #8
0
 public virtual Boolean MoveNext()
 {
     return(NodeEnumerator.MoveNext());
 }
Пример #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NodeList{T}"/> class.
 /// </summary>
 /// <param name="nodes">Array of nodes.</param>
 public NodeList(INode <T>[] nodes)
 {
     this.enumerator = new NodeEnumerator(nodes);
 }
Пример #10
0
		// Returns true if we dont have vertical space to draw all the items.
		private bool GetNeedVScrollBar()
		{
			int fullNodes = VisibleCount;
			NodeEnumerator nodes = new NodeEnumerator(Nodes);
			while (nodes.MoveNext())
			{
				if (--fullNodes == 0)
				{
					return true;
				}
			}
			return false;
		}
Пример #11
0
		// Render the treeview starting from startingLine
		internal void Draw(Graphics g, TreeNode startNode)
		{
			if (updating > 0)
			{
				return;
			}

			Rectangle clientRectangle = ClientRectangle;
			int drawableHeight = clientRectangle.Height;
			int drawableWidth = clientRectangle.Width - xOffset;

			// We count the visible rows to see if we need the v scrollbar but we wait before deciding if we need the h scroll bar.
			bool needsHScrollBar = false;
			bool needsVScrollBar = GetNeedVScrollBar() && scrollable;
			bool createNewVScrollBar = false;
			bool createNewHScrollBar = false;

			if (needsVScrollBar)
			{
				// Don't allow drawing on the area that is going to be the scroll bar.
				// Create the scroll bar so we can get its width.
				if (vScrollBar == null)
				{
					vScrollBar = new VScrollBar();
					createNewVScrollBar = true;
				}
				drawableWidth -= vScrollBar.Width;
				Rectangle rect = new Rectangle(drawableWidth + xOffset, 0, vScrollBar.Width, clientRectangle.Height);
				g.ExcludeClip(rect);
			}
			else
			{
				// Check to see if the top node is not the first node and we have room for the whole tree.
				// If so, abandon the draw and redraw the whole tree from the top.
				if (topNode != null && topNode != this.nodes[0])
				{
					topNode = null;
					Invalidate();
					return;
				}
				if (vScrollBar != null)
				{
					// We don't need the scroll bar anymore.
					Controls.Remove(vScrollBar);
					vScrollBar.Dispose();
					vScrollBar = null;
				}
			}
			// Is the node being processed on the screen.
			bool drawing = false;
			// Start counting from the top.
			int nodeFromTop = -1;
			// Number of nodes.
			int nodeCount = 0;
			int topNodePosition = 0;
			// The maximum width of a displayed node.
			int maxWidth = 0;
			StringFormat format = new StringFormat(StringFormatFlags.NoWrap);
			if (topNode == null && this.nodes.Count > 0)
			{
				topNode = this.nodes[0];
			}
			Rectangle textBounds = Rectangle.Empty;

			NodeEnumerator nodes = new NodeEnumerator(this.nodes);
			using (Pen markerPen = new Pen(SystemColors.ControlLight))
			{
				markerPen.DashStyle = DashStyle.Dot;
				while (nodes.MoveNext())
				{
					// If we havnt started drawing yet, then see if we need to and if so clear the background.
					if (!drawing)
					{
						if (nodes.currentNode  == topNode)
						{
							// We are at the top node.
							nodeFromTop = 0;
							topNodePosition = nodeCount;
						}
					
						// Check to see if we must start drawing. Clear the background.
						if (nodeFromTop >= 0 && (nodes.currentNode == startNode || startNode == root))
						{
							// Clear background.
							int y = ItemHeight * nodeFromTop;
							using (SolidBrush b = new SolidBrush(BackColor))
							{
								g.FillRectangle(b, 0, y, ClientSize.Width, ClientSize.Height - y);
							}
							drawing = true;
						}
					}

					// Even if we arnt drawing nodes yet, we need to measure if the nodes are visible, for hscrollbar purposes.
					if (nodeFromTop >= 0 && drawableHeight > 0)
					{
						textBounds = GetTextBounds(g, nodes.currentNode, nodeFromTop, nodes.level);
						// Is the text too wide to fit in - if so we need an h scroll bar.
						if (textBounds.Right > drawableWidth && !needsHScrollBar && scrollable)
						{
							needsHScrollBar = true;
							if (hScrollBar == null)
							{
								hScrollBar = new HScrollBar();
								createNewHScrollBar = true;
							}
							drawableHeight -= hScrollBar.Height;
							// Don't allow drawing on the area that is going to be the scroll bar.
							Rectangle rect = new Rectangle(0, clientRectangle.Height - hScrollBar.Height, clientRectangle.Width, hScrollBar.Height);
							g.ExcludeClip(rect);
						}
						if (textBounds.Right > maxWidth)
						{
							maxWidth = textBounds.Right;
						}

					}

					// Draw the node if we still have space.
					if (drawing && drawableHeight > 0)
					{
						Rectangle bounds;
						// Draw the lines and the expander.
						DrawExpanderMarker(g, markerPen, nodes.currentNode, nodeFromTop, nodes.level);
						// Draw checkboxes.
						if (checkBoxes)
						{
							bounds = GetCheckBounds(nodeFromTop, nodes.level);
							ButtonState state;
							if (nodes.currentNode.isChecked)
							{
								state = ButtonState.Checked;
							}
							else
							{
								state = ButtonState.Normal;
							}
							ControlPaint.DrawCheckBox(g, bounds, state);
						}
						// Draw the node image.
						if (imageList != null)
						{
							bounds = GetImageBounds(nodeFromTop, nodes.level);
							int index = GetDisplayIndex(nodes.currentNode );
						
							if (index < imageList.Images.Count)
							{
								Image image = imageList.Images[index];
								g.DrawImage(image, bounds.X, bounds.Y);
							
							}
						}
						bounds = textBounds;
						// The height may be too small now.
						// If we are currently editing a node then dont draw it.
						if (drawableHeight > 0 && nodes.currentNode != editNode)
						{
							// Draw the node text.
							if (nodes.currentNode  == selectedNode && (Focused || !hideSelection))
							{
								Rectangle r;

								// **TODO**
								// Running into a chicken and egg issue here where if
								// we fill the rect here, we're overdrawing the
								// checkBoxes or ExpanderMarker of above

								// Draw FullRowSelect if we qualify
								if(fullRowSelect && !showLines)
								{
									int left = 1;
//									if(nodes.currentNode)
//									{
//										left = 10;
//									}
									g.FillRectangle(SystemBrushes.Highlight, new Rectangle(left, bounds.Y, drawableWidth - 1, bounds.Height));
								}
								else
								{
									g.FillRectangle(SystemBrushes.Highlight, bounds);
								}
								g.DrawString(nodes.currentNode.Text, Font, SystemBrushes.HighlightText, bounds, format);

								// Draw the focus rectangle.
								if(FullRowSelect && !ShowLines)
								{
									r = new Rectangle(0, bounds.Y - 1, drawableWidth, bounds.Height + 1);
								}
								else
								{
									r = new Rectangle(bounds.X - 1, bounds.Y - 1, bounds.Width + 1, bounds.Height + 1);
								}
								ControlPaint.DrawFocusRectangle(g, r);
							}
							else
							{
								g.DrawString(nodes.currentNode .Text, Font, SystemBrushes.ControlText, bounds,format);
							}
						}
						drawableHeight -= ItemHeight;
					}

					if (nodeFromTop >= 0)
					{
						nodeFromTop++;
					}
					nodeCount++;
				}
			}
			// If we need a v scroll bar, then set it up.
			if (needsVScrollBar)
			{
				SetupVScrollBar(nodeCount, needsHScrollBar, createNewVScrollBar, topNodePosition);
			}
			if (needsHScrollBar)
			{
				SetupHScrollBar(needsVScrollBar, maxWidth, createNewHScrollBar, g);
			}
			else if (hScrollBar != null)
			{
				// We dont need the scroll bar.
				// If we have scrolled then we need to reset the position.
				if (xOffset != 0)
				{
					xOffset = 0;
					Invalidate();
				}
				Controls.Remove(hScrollBar);
				hScrollBar.Dispose();
				hScrollBar = null;
			}
		}
Пример #12
0
		protected override bool ProcessDialogKey(Keys keyData)
		{
			if ((keyData & Keys.Alt) == 0)
			{
				Keys key = keyData & Keys.KeyCode;
				bool shiftKey = (keyData & Keys.Shift) != 0;
				bool controlKey = (keyData & Keys.Control) != 0;
				TreeNode selectedNode = SelectedNode;

				switch (key)
				{
					case Keys.Left:
						if (selectedNode != null)
						{
							if (selectedNode.IsExpanded)
							{
								selectedNode.Collapse();
							}
							else if (selectedNode.Parent != null)
							{
								SelectedNode = selectedNode.Parent;
							}
						}
						return true;
					case Keys.Right:
						if (selectedNode != null && selectedNode.Nodes.Count != 0)
						{
							if (selectedNode.IsExpanded)
							{
								SelectedNode = selectedNode.NextVisibleNode;
							}
							else
							{
								selectedNode.Expand();
							}
						}
						return true;
					case Keys.Up:
						if (selectedNode != null)
						{
							selectedNode = selectedNode.PrevVisibleNode;
							if (selectedNode != null)
							{
								SelectedNode = selectedNode;
							}
						}
						return true;
					case Keys.Down:
						if (selectedNode != null)
						{
							selectedNode = selectedNode.NextVisibleNode;
							if (selectedNode != null)
							{
								SelectedNode = selectedNode;
							}
						}	
						return true;
					case Keys.Home:
						if (Nodes[0] != null)
						{
							SelectedNode = Nodes[0];
						}
						return true;
					case Keys.End:
					{
						NodeEnumerator nodes = new NodeEnumerator(this.nodes);
						while (nodes.MoveNext())
						{
						}
						SelectedNode = nodes.currentNode;
						return true;
					}
					case Keys.Prior:
					{
						int nodePosition = 0;
						// Get the position of the current selected node.
						NodeEnumerator nodes = new NodeEnumerator(this.nodes);
						while (nodes.MoveNext())
						{
							if (nodes.currentNode == selectedNode)
							{
								break;
							}
							nodePosition++;
						}

						nodePosition -= VisibleCountActual - 1;
						if (nodePosition < 0)
						{
							nodePosition = 0;
						}

						// Get the node that corresponds to the position.
						nodes.Reset();
						while (nodes.MoveNext())
						{
							if (nodePosition-- == 0)
							{
								break;
							}
						}

						// Set the selectedNode.
						SelectedNode = nodes.currentNode;

					}
						return true;
					case Keys.Next:
					{
						int rows = 0;
						int rowsPerPage = VisibleCountActual;
						NodeEnumerator nodes = new NodeEnumerator(this.nodes);
						while (nodes.MoveNext())
						{
							if (nodes.currentNode == selectedNode || rows > 0)
							{
								rows++;
								if (rows >= rowsPerPage)
								{
									break;
								}
							}
						}
						SelectedNode = nodes.currentNode;
						
						return true;
					}
				}
	
			}
			return base.ProcessDialogKey(keyData);
		}
Пример #13
0
        protected override bool MoveNextCore()
        {
            if (Stack == null)
            {
                if (ProceedNextRootItem() == false)
                {
                    return(false);
                }

                if (HasCurrentNode)
                {
                    return(true);
                }
            }

            while (true)
            {
                while (Stack.Count > 0)
                {
                    var tmp = Stack.Peek();

                    if (tmp.IsVisited == false)
                    {
                        CurrentNode = Stack.Peek().Node;
                        Stack.VisitPeakNode();
                        HasCurrentNode = true;

                        return(true);
                    }

                    if (tmp.HasCurrent == false)
                    {
                        Stack.MoveNextPeakNode(out tmp);
                    }

                    if (tmp.HasNext == false && tmp.HasCurrent == false)
                    {
                        while (Stack.Count > 0 && Stack.MoveNextPeakNode(out tmp) == false)
                        {
                            Stack.Pop();
                        }

                        if (Stack.Count == 0)
                        {
                            break;
                        }
                    }

                    Stack.Push(NodeEnumerator.Create(tmp.CurrentChild, TreeAdvisor));
                }

                if (ProceedNextRootItem() == false)
                {
                    return(false);
                }

                if (HasCurrentNode)
                {
                    return(true);
                }
            }
        }