Exemple #1
0
		// Collapse the children recursively but don't redraw.
		private void CollapseInternal()
		{
			bool selected = false;
			// Recursively collapse, if a child was selected, mark to select the parent.
			if (childCount > 0)
			{
				for (int i = 0; i < childCount; i++)
				{
					if (treeView.SelectedNode == children[i])
						selected = true;
					children[i].CollapseInternal();
				}
			}
			// Do the events.
			TreeViewExCancelEventArgs eventArgs = new TreeViewExCancelEventArgs(this, false, TreeViewExAction.Collapse);
			treeView.OnBeforeCollapse(eventArgs);
			if (!eventArgs.Cancel)
			{
				treeView.OnAfterCollapse(new TreeViewExEventArgs(this));
				// The node is now collapsed.
				expanded = false;
			}
			if (selected)
			{
				treeView.SelectedNode = this;
			}
		}
Exemple #2
0
        void ProcessClick(int x, int y, bool rightMouse)
        {
            int nodeFromTop = -1;
            int height = ItemHeight;
            using (Graphics g = CreateGraphics())
            {
                // Iterate through all the nodes, looking for the bounds that match.
                NodeEnumeratorEx nodes = new NodeEnumeratorEx(this.nodes);
                while (nodes.MoveNext())
                {
                    if (nodes.currentNode == topNode)
                    {
                        // We are now at the top of the control.
                        nodeFromTop = 0;
                    }
                    if (nodeFromTop > -1)
                    {
                        // Check if the y matches this node.
                        if (y < height * (nodeFromTop + 1))
                        {
                            bool allowEdit = false;
                            bool allowSelect = true;
                            // Clicking the image can be used to select.
                            if (imageList == null || !GetImageBounds(nodeFromTop, nodes.level).Contains(x, y))
                            {
                                // Clicking the text can be used to edit and select.
                                // if false then the hierarchy marker must have been clicked.
                                if (GetTextBounds(g, nodes.currentNode, nodeFromTop, nodes.level).Contains(x, y))
                                {
                                    allowEdit = true;
                                }
                                else
                                {
                                    allowSelect = false;
                                }
                            }
                            if (SelectedNode == nodes.Current && mouseClickTimer != null && mouseClickTimer.Enabled && (allowEdit || allowSelect))
                            {
                                mouseClickTimer.Stop();
                                nodeToEdit = null;
                                nodes.currentNode.Toggle();
                                return;
                            }
                            if (allowSelect || rightMouse)
                            {
                                if (selectedNode == nodes.Current)
                                {
                                    if (labelEdit && allowEdit && !rightMouse)
                                    {
                                        if (selectedNode.CanRename())
                                            nodeToEdit = nodes.currentNode;
                                    }
                                    Focus();
                                }
                                else
                                {
                                    nodeToEdit = null;
                                    // Do the events.
                                    TreeViewExCancelEventArgs eventArgs = new TreeViewExCancelEventArgs(nodes.currentNode, false, TreeViewExAction.ByMouse);
                                    OnBeforeSelect(eventArgs);
                                    if (!eventArgs.Cancel)
                                    {
                                        SelectedNode = nodes.currentNode;
                                        Focus();
                                    }
                                }
                                if (rightMouse)
                                {
                                    return;
                                }
                                if (mouseClickTimer == null)
                                {
                                    mouseClickTimer = new Forms.Timer();
                                    mouseClickTimer.Tick +=new EventHandler(mouseClickTimer_Tick);
                                    mouseClickTimer.Interval = mouseEditTimeout;
                                }

                                mouseClickTimer.Start();
                                break;
                            }
                        }
                        nodeFromTop++;
                    }
                }
            }
        }
Exemple #3
0
        // Non Microsoft member.
        protected override void OnMouseDown(Forms.MouseEventArgs e)
        {
            nodeToEdit = null;
            if (e.Button == Forms.MouseButtons.Left)
            {
                int nodeFromTop = -1;
                // Iterate through all the nodes, looking for the bounds that match.
                NodeEnumeratorEx nodes = new NodeEnumeratorEx(this.nodes);
                bool _clicked = false;

                while (nodes.MoveNext())
                {
                    if (nodes.currentNode == topNode)
                    {
                        // We are now at the top of the control.
                        nodeFromTop = 0;
                    }
                    if (nodeFromTop > -1)
                    {
                        if (GetExpanderBounds(nodeFromTop, nodes.level).Contains(e.X, e.Y))
                        {
                            nodes.currentNode.Toggle();
                            _clicked = true;
                            break;
                        }
                        else if (GetCheckBounds(nodeFromTop, nodes.level).Contains(e.X, e.Y))
                        {
                            TreeViewExCancelEventArgs args = new TreeViewExCancelEventArgs(nodes.currentNode, false, TreeViewExAction.ByMouse);
                            OnBeforeCheck(args);
                            if (!args.Cancel)
                            {
                                nodes.currentNode.isChecked = !nodes.currentNode.isChecked;
                                OnAfterCheck(new TreeViewExEventArgs(nodes.currentNode, TreeViewExAction.ByMouse));
                            }

                            Invalidate(GetCheckBounds(nodeFromTop, nodes.level));
                            _clicked = true;
                            break;

                        }
                        nodeFromTop++;
                    }
                }

                if (!_clicked)
                {
                    var pt = new Point(e.X, e.Y);
                    var node = GetNodeAt(e.X, e.Y);

                    if (node != null && node.Bounds.Contains(pt))
                    {
                        Focus();
                        nodeToBeDropped = node;

                        if (selectedNode != null)
                            selectedNode.Invalidate();
                        nodeToBeDropped.Invalidate();
                    }
                }
            }
            else
            {
                ProcessClick(e.X, e.Y, true);
            }
            base.OnMouseDown(e);
        }
Exemple #4
0
 protected override void OnKeyDown(Forms.KeyEventArgs e)
 {
     base.OnKeyDown(e);
     if (!e.Handled && checkBoxes && selectedNode != null && (e.KeyData & Forms.Keys.KeyCode) == Forms.Keys.Space)
     {
         TreeViewExCancelEventArgs args = new TreeViewExCancelEventArgs(selectedNode, false, TreeViewExAction.ByKeyboard);
         this.OnBeforeCheck(args);
         if (!args.Cancel)
         {
             selectedNode.isChecked = !selectedNode.isChecked;
             selectedNode.Invalidate();
             this.OnAfterCheck(new TreeViewExEventArgs(selectedNode, TreeViewExAction.ByKeyboard));
         }
         e.Handled = true;
     }
 }
Exemple #5
0
 protected virtual void OnBeforeSelect(TreeViewExCancelEventArgs e)
 {
     if (BeforeSelect != null)
         BeforeSelect(this, e);
 }
Exemple #6
0
 protected virtual void OnBeforeExpand(TreeViewExCancelEventArgs e)
 {
     if (BeforeExpand != null)
         BeforeExpand(this, e);
 }
Exemple #7
0
 protected internal virtual void OnBeforeCollapse(TreeViewExCancelEventArgs e)
 {
     if (BeforeCollapse != null)
         BeforeCollapse(this, e);
 }
Exemple #8
0
 protected internal virtual void OnBeforeCheck(TreeViewExCancelEventArgs e)
 {
     if (BeforeCheck != null)
         BeforeCheck(this, e);
 }