コード例 #1
0
ファイル: TreeNode.cs プロジェクト: emclient/mac-playground
        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);
        }
コード例 #2
0
        private TreeNode GetPrevNode(TreeNode node)
        {
            OpenTreeNodeEnumerator one = new OpenTreeNodeEnumerator(node);

            if (one.MovePrevious() && one.MovePrevious())
            {
                return(one.CurrentNode);
            }
            return(null);
        }
コード例 #3
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);
        }
コード例 #4
0
ファイル: TreeView.cs プロジェクト: ileonchik/mono
		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;
			}
		}
コード例 #5
0
ファイル: TreeView.cs プロジェクト: ileonchik/mono
		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;
			}
		}
コード例 #6
0
ファイル: TreeView.cs プロジェクト: ileonchik/mono
		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);
			}
		}
コード例 #7
0
ファイル: TreeView.cs プロジェクト: ileonchik/mono
		internal void SetBottom (TreeNode node)
		{
			if (!vbar.is_visible)
				return;

			OpenTreeNodeEnumerator walk = new OpenTreeNodeEnumerator (node);

			int bottom = ViewportRectangle.Bottom;
			int offset = 0;
			while (walk.MovePrevious ()) {
				if (walk.CurrentNode.Bounds.Bottom <= bottom)
					break;
				offset++;
			}

			int nv = vbar.Value + offset;
			if (vbar.Value + offset < vbar.Maximum) {
				SetVScrollValue (nv);
			} else {
#if DEBUG
				Console.Error.WriteLine ("setting bottom to value greater then maximum ({0}, {1})",
						nv, vbar.Maximum);
#endif
			}
				
		}
コード例 #8
0
ファイル: TreeView.cs プロジェクト: ileonchik/mono
		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;
		}
コード例 #9
0
ファイル: TreeView.cs プロジェクト: ileonchik/mono
		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;
		}
コード例 #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
        }
コード例 #11
0
ファイル: TreeNode.cs プロジェクト: nlhepler/mono
		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;
		}
コード例 #12
0
		private TreeNode GetPrevNode (TreeNode node)
		{
			OpenTreeNodeEnumerator one = new OpenTreeNodeEnumerator (node);

			if (one.MovePrevious () && one.MovePrevious ())
				return one.CurrentNode;
			return null;
		}
コード例 #13
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
		}