Esempio n. 1
0
        private int CountToNext()
        {
            bool expanded = is_expanded;

            is_expanded = false;
            OpenTreeNodeEnumerator walk = new OpenTreeNodeEnumerator(this);

            TreeNode next = null;

            if (walk.MoveNext() && walk.MoveNext())
            {
                next = walk.CurrentNode;
            }

            is_expanded = expanded;
            walk.Reset();
            walk.MoveNext();

            int count = 0;

            while (walk.MoveNext() && walk.CurrentNode != next)
            {
                count++;
            }

            return(count);
        }
Esempio n. 2
0
        private void RemoveAt(int index, bool update)
        {
            TreeNode removed         = nodes [index];
            TreeNode prev            = GetPrevNode(removed);
            TreeNode new_selected    = null;
            bool     re_set_selected = false;
            bool     visible         = removed.IsVisible;

            TreeView tree_view = TreeView;

            if (tree_view != null)
            {
                tree_view.RecalculateVisibleOrder(prev);

                if (removed == tree_view.SelectedNode)
                {
                    if (removed.IsExpanded)
                    {
                        removed.Collapse();                             // Fix Xamarin Bugzilla 5010.
                    }
                    re_set_selected = true;
                    OpenTreeNodeEnumerator oe = new OpenTreeNodeEnumerator(removed);
                    if (oe.MoveNext() && oe.MoveNext())
                    {
                        new_selected = oe.CurrentNode;
                    }
                    else
                    {
                        oe = new OpenTreeNodeEnumerator(removed);
                        oe.MovePrevious();
                        new_selected = oe.CurrentNode == removed ? null : oe.CurrentNode;
                    }
                }
            }

            Array.Copy(nodes, index + 1, nodes, index, count - index - 1);
            count--;

            nodes[count] = null;

            if (nodes.Length > OrigSize && nodes.Length > (count * 2))
            {
                Shrink();
            }

            if (tree_view != null && re_set_selected)
            {
                tree_view.SelectedNode = new_selected;
            }

            TreeNode parent = removed.parent;

            removed.parent = null;

            if (update && tree_view != null && visible)
            {
                tree_view.RecalculateVisibleOrder(prev);
                tree_view.UpdateScrollBars(false);
                tree_view.UpdateBelow(parent);
            }

            OnUIACollectionChanged(CollectionChangeAction.Remove, removed);
        }
Esempio n. 3
0
		protected override void OnKeyDown (KeyEventArgs e)
		{
			OpenTreeNodeEnumerator ne;

			switch (e.KeyData & Keys.KeyCode) {
			case Keys.Add:
				if (selected_node != null && selected_node.IsExpanded)
					selected_node.Expand ();
				break;
			case Keys.Subtract:
				if (selected_node != null && selected_node.IsExpanded)
					selected_node.Collapse ();
				break;
			case Keys.Left:
				if (selected_node != null) {
					if (selected_node.IsExpanded && selected_node.Nodes.Count > 0)
						selected_node.Collapse ();
					else {
						TreeNode parent = selected_node.Parent;
						if (parent != null) {
							selection_action = TreeViewAction.ByKeyboard;
							SelectedNode = parent;
						}
					}
				}
				break;
			case Keys.Right:
				if (selected_node != null) {
					if (!selected_node.IsExpanded)
						selected_node.Expand ();
					else {
						TreeNode child = selected_node.FirstNode;
						if (child != null)
							SelectedNode = child;
					}
				}
				break;
			case Keys.Up:
				if (selected_node != null) {
					ne = new OpenTreeNodeEnumerator (selected_node);
					if (ne.MovePrevious () && ne.MovePrevious ()) {
						selection_action = TreeViewAction.ByKeyboard;
						SelectedNode = ne.CurrentNode;
					}
				}
				break;
			case Keys.Down:
				if (selected_node != null) {
					ne = new OpenTreeNodeEnumerator (selected_node);
					if (ne.MoveNext () && ne.MoveNext ()) {
						selection_action = TreeViewAction.ByKeyboard;
						SelectedNode = ne.CurrentNode;
					}
				}
				break;
			case Keys.Home:
				if (root_node.Nodes.Count > 0) {
					ne = new OpenTreeNodeEnumerator (root_node.Nodes [0]);
					if (ne.MoveNext ()) {
						selection_action = TreeViewAction.ByKeyboard;
						SelectedNode = ne.CurrentNode;
					}
				}
				break;
			case Keys.End:
				if (root_node.Nodes.Count > 0) {
					ne = new OpenTreeNodeEnumerator (root_node.Nodes [0]);
					while (ne.MoveNext ())
					{ }
					selection_action = TreeViewAction.ByKeyboard;
					SelectedNode = ne.CurrentNode;
				}
				break;
			case Keys.PageDown:
				if (selected_node != null) {
					ne = new OpenTreeNodeEnumerator (selected_node);
					int move = VisibleCount;
					for (int i = 0; i < move && ne.MoveNext (); i++) {
						
					}
					selection_action = TreeViewAction.ByKeyboard;
					SelectedNode = ne.CurrentNode;
				}
				break;
			case Keys.PageUp:
				if (selected_node != null) {
					ne = new OpenTreeNodeEnumerator (selected_node);
					int move = VisibleCount;
					for (int i = 0; i < move && ne.MovePrevious (); i++)
					{ }
					selection_action = TreeViewAction.ByKeyboard;
					SelectedNode = ne.CurrentNode;
				}
				break;
			case Keys.Multiply:
				if (selected_node != null)
					selected_node.ExpandAll ();
				break;
			}
			base.OnKeyDown (e);

			if (!e.Handled && checkboxes &&
           		     selected_node != null &&
			    (e.KeyData & Keys.KeyCode) == Keys.Space) {
				selected_node.check_reason = TreeViewAction.ByKeyboard;
				selected_node.Checked = !selected_node.Checked;		
				e.Handled = true;
			}
		}
Esempio n. 4
0
		internal void UpdateScrollBars (bool force)
		{
			if (!force && (IsDisposed || update_stack > 0 || !IsHandleCreated || !Visible))
				return;

			bool vert = false;
			bool horz = false;
			int height = 0;
			int width = -1;

			int item_height = ActualItemHeight;
			if (scrollable) {
				OpenTreeNodeEnumerator walk = new OpenTreeNodeEnumerator (root_node);
				
				while (walk.MoveNext ()) {
					int r = walk.CurrentNode.Bounds.Right;
					if (r > width)
						width = r;

					height += item_height;
				}

				height -= item_height; // root_node adjustment
				width += hbar_offset;

				if (height > ClientRectangle.Height) {
					vert = true;

					if (width > ClientRectangle.Width - SystemInformation.VerticalScrollBarWidth)
						horz = true;
				} else if (width > ClientRectangle.Width) {
					horz = true;
				}

				if (!vert && horz && height > ClientRectangle.Height - SystemInformation.HorizontalScrollBarHeight)
					vert = true;
			}

			if (vert) {
				int visible_height = horz ? ClientRectangle.Height - hbar.Height : ClientRectangle.Height;
				vbar.SetValues (Math.Max (0, max_visible_order - 2), visible_height / ActualItemHeight);
				/*
				vbar.Maximum = max_visible_order;
				vbar.LargeChange = ClientRectangle.Height / ItemHeight;
				*/

				if (!vbar_bounds_set) {
					vbar.Bounds = new Rectangle (ClientRectangle.Width - vbar.Width, 0, vbar.Width,
							ClientRectangle.Height -
							(horz ? SystemInformation.VerticalScrollBarWidth : 0));
					vbar_bounds_set = true;

					// We need to recalc the hbar if the vbar is now visible
					hbar_bounds_set = false;
				}

				
				vbar.Visible = true;
				if (skipped_nodes > 0) {
					int skip = Math.Min (skipped_nodes, vbar.Maximum - VisibleCount + 1);
					skipped_nodes = 0;
					vbar.SafeValueSet (skip);
					skipped_nodes = skip;
				}
			} else {
				skipped_nodes = 0;
				RecalculateVisibleOrder (root_node);
				vbar.Visible = false;
				SetVScrollValue (0);
				vbar_bounds_set = false;
			}

			if (horz) {
				hbar.SetValues (width + 1, ClientRectangle.Width - (vert ? SystemInformation.VerticalScrollBarWidth : 0));
				/*
				hbar.LargeChange = ClientRectangle.Width;
				hbar.Maximum = width + 1;
				*/

				if (!hbar_bounds_set) {
					hbar.Bounds = new Rectangle (0, ClientRectangle.Height - hbar.Height,
							ClientRectangle.Width - (vert ? SystemInformation.VerticalScrollBarWidth : 0),
							hbar.Height);
					hbar_bounds_set = true;
				}
				hbar.Visible = true;
			} else {
				hbar_offset = 0;
				hbar.Visible = false;
				hbar_bounds_set = false;
			}
		}
Esempio n. 5
0
		private void Draw (Rectangle clip, Graphics dc)
		{
			dc.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (BackColor), clip);

			if (dash == null)
				CreateDashPen ();

			Rectangle viewport = ViewportRectangle;
			Rectangle original_clip = clip;
			if (clip.Bottom > viewport.Bottom)
				clip.Height = viewport.Bottom - clip.Top;

			OpenTreeNodeEnumerator walk = new OpenTreeNodeEnumerator (TopNode);
			while (walk.MoveNext ()) {
				TreeNode current = walk.CurrentNode;

				// Haven't gotten to visible nodes yet
				if (current.GetY () + ActualItemHeight < clip.Top)
					continue;

				// Past the visible nodes
				if (current.GetY () > clip.Bottom)
					break;

				DrawTreeNode (current, dc, clip);
			}

			if (hbar.Visible && vbar.Visible) {
				Rectangle corner = new Rectangle (hbar.Right, vbar.Bottom, vbar.Width, hbar.Height);
				if (original_clip.IntersectsWith (corner))
					dc.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (ThemeEngine.Current.ColorControl),
							corner);
			}
		}
Esempio n. 6
0
		internal void RecalculateVisibleOrder (TreeNode start)
		{
			if (update_stack > 0)
				return;

			int order;
			if (start == null) {
				start = root_node;
				order = 0;
			} else
				order = start.visible_order;

			
			
			OpenTreeNodeEnumerator walk = new OpenTreeNodeEnumerator (start);
			while (walk.MoveNext ()) {
				walk.CurrentNode.visible_order = order;
				order++;
			}

			max_visible_order = order;
		}
Esempio n. 7
0
		private TreeNode GetNodeAt (int y)
		{
			if (nodes.Count <= 0)
				return null;

			OpenTreeNodeEnumerator o = new OpenTreeNodeEnumerator (TopNode);
			int move = y / ActualItemHeight;
			for (int i = -1; i < move; i++) {
				if (!o.MoveNext ())
					return null;
			}

			return o.CurrentNode;
		}
Esempio n. 8
0
        private void RemoveAt(int index, bool update)
        {
            TreeNode removed         = nodes [index];
            TreeNode prev            = GetPrevNode(removed);
            TreeNode new_selected    = null;
            bool     re_set_selected = false;
            bool     visible         = removed.IsVisible;

            TreeView tree_view = null;

            if (owner != null)
            {
                tree_view = owner.TreeView;
            }

            if (tree_view != null)
            {
                tree_view.RecalculateVisibleOrder(prev);

                if (removed == tree_view.SelectedNode)
                {
                    re_set_selected = true;
                    OpenTreeNodeEnumerator oe = new OpenTreeNodeEnumerator(removed);
                    if (oe.MoveNext() && oe.MoveNext())
                    {
                        new_selected = oe.CurrentNode;
                    }
                    else
                    {
                        oe = new OpenTreeNodeEnumerator(removed);
                        oe.MovePrevious();
                        new_selected = oe.CurrentNode == removed ? null : oe.CurrentNode;
                    }
                }
            }

            Array.Copy(nodes, index + 1, nodes, index, count - index - 1);
            count--;

            nodes[count] = null;

            if (nodes.Length > OrigSize && nodes.Length > (count * 2))
            {
                Shrink();
            }

            if (tree_view != null && re_set_selected)
            {
                tree_view.SelectedNode = new_selected;
            }

            TreeNode parent = removed.parent;

            removed.parent = null;

            if (update && tree_view != null && visible)
            {
                tree_view.RecalculateVisibleOrder(prev);
                tree_view.UpdateScrollBars(false);
                tree_view.UpdateBelow(parent);
            }
#if NET_2_0
            // UIA Framework Event: Collection Changed
            if (tree_view != null)
            {
                tree_view.OnUIACollectionChanged(owner, new CollectionChangeEventArgs(CollectionChangeAction.Remove, removed));
            }
#endif
        }
Esempio n. 9
0
		private int CountToNext ()
		{
			bool expanded = is_expanded;
			is_expanded = false;
			OpenTreeNodeEnumerator walk = new OpenTreeNodeEnumerator (this);

			TreeNode next= null;
			if (walk.MoveNext () && walk.MoveNext ())
				next = walk.CurrentNode;

			is_expanded = expanded;
			walk.Reset ();
			walk.MoveNext ();

			int count = 0;
			while (walk.MoveNext () && walk.CurrentNode != next)
				count++;

			return count;
		}
Esempio n. 10
0
		private void RemoveAt (int index, bool update)
		{
			TreeNode removed = nodes [index];
			TreeNode prev = GetPrevNode (removed);
			TreeNode new_selected = null;
			bool re_set_selected = false;
			bool visible = removed.IsVisible;

			TreeView tree_view = null;
			if (owner != null)
				tree_view = owner.TreeView;

			if (tree_view != null) {
				tree_view.RecalculateVisibleOrder (prev);

				if (removed == tree_view.SelectedNode) {
					re_set_selected = true;
					OpenTreeNodeEnumerator oe = new OpenTreeNodeEnumerator (removed);
					if (oe.MoveNext () && oe.MoveNext ()) {
						new_selected = oe.CurrentNode;
					} else {
						oe = new OpenTreeNodeEnumerator (removed);
						oe.MovePrevious ();
						new_selected = oe.CurrentNode == removed ? null : oe.CurrentNode;
					}
				}
			}

			Array.Copy (nodes, index + 1, nodes, index, count - index - 1);
			count--;
			
			nodes[count] = null;
			
			if (nodes.Length > OrigSize && nodes.Length > (count * 2))
				Shrink ();

			if (tree_view != null && re_set_selected) {
				tree_view.SelectedNode = new_selected;
			}

			TreeNode parent = removed.parent;
			removed.parent = null;

			if (update && tree_view != null && visible) {
				tree_view.RecalculateVisibleOrder (prev);
				tree_view.UpdateScrollBars (false);
				tree_view.UpdateBelow (parent);
			}
#if NET_2_0
			// UIA Framework Event: Collection Changed
			if (tree_view != null)
				tree_view.OnUIACollectionChanged (owner, new CollectionChangeEventArgs (CollectionChangeAction.Remove, removed));
#endif
		}