Beispiel #1
0
        private bool SetFocusedItem(TreeNode node, bool bSelect, TreeNode oldNode, TreeViewAction action)
        {
            CMSTreeViewCancelEventArgs e = new CMSTreeViewCancelEventArgs(node, false, bSelect, action);

            OnBeforeSelect(e);
            if (e.Cancel)
            {
                return(false);
            }

            // temporary disable OnXXXSelect events
            this.bEnableSelectEvents = false;
            IntPtr hItem = SetFocusedItem(node);

            if (bSelect)
            {
                AddSelectedItem(node);
            }
            else
            {
                RemoveSelectedItem(node);
            }
            SetSelectedState(node, bSelect);

            // enable OnXXXSelect events
            this.bEnableSelectEvents = true;

            OnAfterSelect(new CMSTreeViewEventArgs(node, bSelect, action));
            return(true);
        }
 // Constructor.
 public TreeViewCancelEventArgs
     (TreeNode node, bool cancel, TreeViewAction action)
     : base(cancel)
 {
     this.node   = node;
     this.action = action;
 }
Beispiel #3
0
        public void Ctor_TreeNode_TreeViewAction(TreeNode node, TreeViewAction action)
        {
            var e = new TreeViewEventArgs(node, action);

            Assert.Equal(node, e.Node);
            Assert.Equal(action, e.Action);
        }
Beispiel #4
0
        public bool SelectNode(TreeNode node, bool select, TreeViewAction action)
        {
            if (node == null || IsNodeSelected(node) == select)
            {
                return(false);
            }

            TreeViewCancelEventArgs ce = new TreeViewCancelEventArgs(node, false, action);

            SuspendBeforeSelect = true;
            OnBeforeSelect(ce);
            SuspendBeforeSelect = false;
            if (ce.Cancel)
            {
                return(false);
            }

            if (select)
            {
                node.EnsureVisible();
                SelectedNodes.Add(node);
            }
            else
            {
                SelectedNodes.Remove(node);
            }

            OnAfterSelect(new TreeViewEventArgs(node, action));
            return(true);
        }
Beispiel #5
0
 /// <summary>
 /// Toggles the tri state check.
 /// </summary>
 /// <param name="node">The node.</param>
 /// <param name="action">The action.</param>
 private void ToggleTriStateCheck(
     TreeNode node,
     TreeViewAction action)
 {
     if (node.StateImageIndex == TriStateUncheckedStateImageIndex)
     {
         SetTriStateToNode(
             node,
             action,
             TriStateCheckedStateImageIndex,
             true);
     }
     else if (node.StateImageIndex == TriStateIndeterminateStateImageIndex &&
              indeterminateToChecked)
     {
         SetTriStateToNode(
             node,
             action,
             TriStateCheckedStateImageIndex,
             true);
     }
     else
     {
         SetTriStateToNode(
             node,
             action,
             TriStateUncheckedStateImageIndex,
             true);
     }
 }
Beispiel #6
0
 private void ClearSelectedNodes(TreeViewAction action)
 {
     for (int i = SelectedNodes.Count - 1; i >= 0; i--)
     {
         SelectNode(SelectedNodes[i], false, action);
     }
 }
	// Constructor.
	public TreeViewCancelEventArgs
				(TreeNode node, bool cancel, TreeViewAction action)
			: base(cancel)
			{
				this.node = node;
				this.action = action;
			}
Beispiel #8
0
        private void SelectTo(TreeNode node, TreeViewAction action)
        {
            if (LastSelectedNode == null)
            {
                SelectNode(node, true, action);
            }
            else if (LastSelectedNode == node)
            {
                SelectNode(node, false, action);
            }
            else
            {
                TreeNode nodeBegin = LastSelectedNode;
                TreeNode tn        = nodeBegin;
                while ((tn != null) && (tn != node))
                {
                    if (nodeBegin.Bounds.Y > node.Bounds.Y)
                    {
                        tn = tn.PrevVisibleNode;
                    }
                    else
                    {
                        tn = tn.NextVisibleNode;
                    }

                    if (tn != null)
                    {
                        SelectNode(tn, true, action);
                    }
                }
            }
        }
        public void Ctor_TreeNode_Bool_TreeViewAction(TreeNode node, bool cancel, TreeViewAction action)
        {
            var e = new TreeViewCancelEventArgs(node, cancel, action);

            Assert.Equal(node, e.Node);
            Assert.Equal(cancel, e.Cancel);
            Assert.Equal(action, e.Action);
        }
Beispiel #10
0
 public static void TreeView_AfterSelect(TreeViewAction action, TreeNode node)
 {
     // 通过鼠标或者键盘触发事件,防止修改节点的Checked状态时候再次进入
     if ((action == TreeViewAction.ByMouse || action == TreeViewAction.ByKeyboard) && node.Checked)
     {
         LogHelper.Log("select node " + node.Text + " tag " + node.Tag + " key " + OPCDAViewHelper.Key(node.FullPath.ToString()));
     }
 }
Beispiel #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TreeViewTriStateEventArgs"/> class.
 /// </summary>
 /// <param name="node">The node.</param>
 /// <param name="action">The action.</param>
 /// <param name="stateImageIndex">Index of the state image.</param>
 public TreeViewTriStateEventArgs(
     TreeNode node,
     TreeViewAction action,
     int stateImageIndex)
     :
     base(node, action)
 {
     this.stateImageIndex = stateImageIndex;
 }
Beispiel #12
0
        private void UnselectNodesRecursively(MultiSelectTreeNode tn, TreeViewAction tva)
        {
            SelectNode(tn, false, tva);

            foreach (MultiSelectTreeNode node in tn.Nodes)
            {
                UnselectNodesRecursively(node, tva);
            }
        }
Beispiel #13
0
        public static void TreeView_AfterCheck(TreeViewAction action, TreeNode node)
        {
            if (action != TreeViewAction.Unknown)
            {
                LogHelper.Log("check node " + node.Text + " tag " + node.Tag + " Level " + node.Level.ToString());

                SetChildNodeCheckedState(node, node.Checked);
                SetParentNodeCheckedState(node, node.Checked);
            }
        }
Beispiel #14
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="node">The node.</param>
 /// <param name="cancel">if set to <c>true</c> [cancel].</param>
 /// <param name="action">The action.</param>
 /// <param name="currentStateImageIndex">Index of the current state image.</param>
 /// <param name="newStateImageIndex">New index of the state image.</param>
 public TreeViewCancelTriStateEventArgs(
     TreeNode node,
     bool cancel,
     TreeViewAction action,
     int currentStateImageIndex,
     int newStateImageIndex)
     :
     base(node, cancel, action)
 {
     this.currentStateImageIndex = currentStateImageIndex;
     this.newStateImageIndex     = newStateImageIndex;
 }
Beispiel #15
0
        public void SelectNode(TreeNode[] nodes, TreeViewAction action, bool exclusive)
        {
            if (exclusive)
            {
                ClearSelectedNodes(action);
            }

            foreach (TreeNode node in nodes)
            {
                SelectNode(node, true, action);
            }
        }
Beispiel #16
0
 /// <summary>
 /// Applies a new check state to the given tree node.
 /// The UseTriStateCheckBoxes property must be set to TRUE.
 /// </summary>
 /// <param name="node">The node.</param>
 /// <param name="action">The action.</param>
 /// <param name="checkState">State of the check.</param>
 private void DoSetNodeCheckState(
     TreeNode node,
     TreeViewAction action,
     CheckState checkState)
 {
     // Use TreeViewAction.ByKeyboard here,
     // to indicate that it was called from outside.
     SetTriStateToNode(
         node,
         action,
         ConvertCheckStateToImageIndex(checkState),
         true);
 }
Beispiel #17
0
        /// <summary>
        /// Applies the given state to the given node.
        /// Raises events, too.
        /// </summary>
        /// <param name="node">The node.</param>
        /// <param name="action">The action.</param>
        /// <param name="stateImageIndex">Index of the state image.</param>
        /// <param name="raiseEvents">if set to <c>true</c> [raise events].</param>
        private void SetTriStateToNode(
            TreeNode node,
            TreeViewAction action,
            int stateImageIndex,
            bool raiseEvents)
        {
            bool canSet = true;

            if (raiseEvents)
            {
                TreeViewCancelEventArgs args =
                    new TreeViewCancelEventArgs(node, false, action);

                OnBeforeCheck(args);

                TreeViewCancelTriStateEventArgs triArgs =
                    new TreeViewCancelTriStateEventArgs(
                        node,
                        args.Cancel,
                        action,
                        node.StateImageIndex,
                        stateImageIndex);

                OnBeforeTriStateCheck(triArgs);

                canSet = !triArgs.Cancel;
            }

            if (canSet)
            {
                // Actually set.
                // THIS IS THE ONLY PLACE to set.
                node.StateImageIndex = stateImageIndex;

                if (raiseEvents)
                {
                    TreeViewEventArgs args =
                        new TreeViewEventArgs(node, action);

                    OnAfterCheck(args);

                    TreeViewTriStateEventArgs triArgs =
                        new TreeViewTriStateEventArgs(
                            node,
                            action,
                            node.StateImageIndex);

                    OnAfterTriStateCheck(triArgs);
                }
            }
        }
Beispiel #18
0
        private void UnselectAllNodesNotBelongingToLevel(int level, TreeViewAction tva)
        {
            ArrayList list = new ArrayList();

            foreach (MultiSelectTreeNode node in _selectedNodes)
            {
                if (GetNodeLevel(node) != level)
                {
                    list.Add(node);
                }
            }
            foreach (MultiSelectTreeNode node2 in list)
            {
                SelectNode(node2, false, tva);
            }
        }
Beispiel #19
0
        protected virtual void OnCustomCheck(TreeNode node, TreeViewAction action)
        {
            var e = new TreeViewCancelEventArgs(node, false, action);

            OnBeforeCheck(e);
            if (e.Cancel)
            {
                return;
            }

            if (node is IStateTreeNode)
            {
                ((IStateTreeNode)node).UpdateState(e);
            }

            OnAfterCheck(new TreeViewEventArgs(node, action));
        }
        /// <summary>Toggles the CheckState of the specified node on response of a click/keyboard event.</summary>
        /// <param name="node">The node affected by the event.</param>
        /// <param name="action">The action that caused the event.</param>
        private void ToggleNodeCheckState(TreeNode node, TreeViewAction action)
        {
            // Compute the new check box state of the node
            CheckState newState;

            switch ((CheckState)node.StateImageIndex)
            {
            case CheckState.Unchecked: newState = CheckState.Checked; break;

            case CheckState.Checked: newState = CheckState.Unchecked; break;

            case CheckState.Indeterminate: newState = CheckState.Checked; break;     // Standard behaviour

            default: throw new InvalidOperationException("Invalid TreeNode.StateImageIndex - Check your code.");
            }

            // Update the checked state of the node
            SetCheckStateImpl(node, newState, action);
        }
Beispiel #21
0
        private void ChangeNodeStateByUser(TreeNode node, TreeViewAction action)
        {
            if (this.BeforeNodeStateChangeByUser != null)
            {
                this.BeforeNodeStateChangeByUser(this, new TreeViewEventArgs(node, action));
            }
            switch (node.StateImageIndex)
            {
            case ItemState.Unchecked:
            case ItemState.Mixed:
                node.StateImageIndex = ItemState.Checked;
                break;

            case ItemState.Checked:
                node.StateImageIndex = ItemState.Unchecked;
                break;
            }
            UpdateChildren(node);
            UpdateParent(node);
        }
        private void SetCheckStateImpl(TreeNode node, CheckState newState, TreeViewAction action)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }
            if (newState != CheckState.Checked && newState != CheckState.Unchecked)
            {
                throw new ArgumentOutOfRangeException("newState", "Only checked and unchecked states can be set.");
            }

            // Set the check state and update the children and parent
            PropagateNodeCheckStateDown(node, newState);
            PropagateNodeCheckStateUp(node);

            // Trigger the AfterCheckState event on the affected node
            if (AfterCheckState != null)
            {
                AfterCheckState(this, new TreeViewEventArgs(node, action));
            }
        }
Beispiel #23
0
        private bool SelectNode(MultiSelectTreeNode node, bool select, TreeViewAction tva)
        {
            bool selected = false;

            if (node == null)
            {
                return(false);
            }
            if (select)
            {
                if (!IsNodeSelected(node))
                {
                    MultiSelectTreeViewCancelEventArgs e = new MultiSelectTreeViewCancelEventArgs(node, false, tva);
                    OnBeforeSelect(e);
                    if (e.Cancel)
                    {
                        return(false);
                    }
                    _selectedNodes.Add(node);
                    selected          = true;
                    _selectionChanged = true;
                    OnAfterSelect(new TreeViewEventArgs(node, tva));
                }
                _mostRecentSelectedNode = node;
                return(selected);
            }
            if (IsNodeSelected(node))
            {
                OnBeforeDeselect(new TreeViewEventArgs(node));
                _selectedNodes.Remove(node);
                _selectionChanged = true;

                OnAfterDeselect(new TreeViewEventArgs(node));
            }
            return(selected);
        }
 private void tvClientesServicios_BeforeCheck(object sender, TreeViewCancelEventArgs e)
 {
     action = e.Action;
 }
Beispiel #25
0
 // Constructor.
 public TreeViewEventArgs(TreeNode node, TreeViewAction action)
 {
     this.node   = node;
     this.action = action;
 }
Beispiel #26
0
        // 选中或取消选中 Dpu 时执行的操作
        private void treDpuCatalog_AfterCheck(object sender, TreeViewEventArgs e)
        {
            // 改变子节点的选中状态
            if ((e.Action == TreeViewAction.ByMouse || actionTemp == TreeViewAction.ByMouse) && e.Node.Nodes.Count > 0)
            {
                foreach (TreeNode node in e.Node.Nodes)
                {
                    actionTemp   = TreeViewAction.ByMouse;
                    node.Checked = e.Node.Checked;
                }
            }

            actionTemp = TreeViewAction.Unknown;

            // 改变父节点的选中状态
            if (e.Node.Parent != null)
            {
                if (!e.Node.Checked)
                {
                    bool hasChecked = false;

                    foreach (TreeNode node in e.Node.Parent.Nodes)
                    {
                        if (node.Checked)
                        {
                            hasChecked = true;
                            break;
                        }
                    }

                    e.Node.Parent.Checked = hasChecked;
                }
                else
                {
                    e.Node.Parent.Checked = true;
                }
            }

            if ((e.Node.Tag as NodeTag).type == NodeType.Controller)
            {
                if (e.Node.Checked)
                {
                    // 加载选中 Dpu 下的文档列表

                    BllManager bll = new BllManager(manager);

                    IList <Prj_Document> documents = bll.manager.DocumentCRUD.GetPrj_Documents_By_Prj_Controller_ID((e.Node.Tag as NodeTag).id);
                    foreach (Prj_Document doc in documents)
                    {
                        ListViewItem item = new ListViewItem(
                            new string[] {
                            doc.DocumentName.Substring(0, doc.DocumentName.IndexOf('-')).PadLeft(3, '0') + "-"
                            + doc.DocumentName.Substring(doc.DocumentName.IndexOf('-') + 1).PadLeft(3, '0'),
                            doc.DocumentCaption
                        });
                        item.Tag         = doc;
                        item.ToolTipText = doc.DocumentCaption;
                        this.lstPages.Items.Add(item);
                    }
                }
                else
                {
                    // 移除对应 Dpu 的文档列表

                    IList <int> mastLeavedId = new List <int>();

                    for (int i = 0; i < this.lstPages.Items.Count;)
                    {
                        if (((Prj_Document)this.lstPages.Items[i].Tag).Prj_Controller_ID == (((NodeTag)e.Node.Tag).id))
                        {
                            this.lstPages.Items.Remove(this.lstPages.Items[i]);
                        }
                        else
                        {
                            i++;
                        }
                    }
                }
            }
        }
Beispiel #27
0
		/// <summary>
		/// Unselects nodes outside the specified range.
		/// </summary>
		/// <param name="startNode">Start node.</param>
		/// <param name="endNode">End node.</param>
		/// <param name="tva">Specifies the action that caused the selection change.</param>
		private void UnselectNodesOutsideRange(TreeNode startNode, TreeNode endNode, TreeViewAction tva)
		{
			// Calculate start node and end node
			TreeNode firstNode = null;
			TreeNode lastNode = null;
			if (startNode.Bounds.Y < endNode.Bounds.Y)
			{
				firstNode = startNode;
				lastNode = endNode;
			}
			else
			{
				firstNode = endNode;
				lastNode = startNode;
			}

			// Unselect each node outside range
			TreeNode tnTemp = firstNode;
			while (tnTemp != null)
			{
				tnTemp = tnTemp.PrevVisibleNode;
				if (tnTemp != null)
				{
					SelectNode(tnTemp, false, tva);
				}
			}

			tnTemp = lastNode;
			while (tnTemp != null)
			{
				tnTemp = tnTemp.NextVisibleNode;
				if (tnTemp != null)
				{
					SelectNode(tnTemp, false, tva);
				}
			}
		}
Beispiel #28
0
		/// <summary>
		/// (Un)selects the specified node.
		/// </summary>
		/// <param name="tn">Node to (un)select.</param>
		/// <param name="select">True to select node, false to unselect node.</param>
		/// <param name="tva">Specifies the action that caused the selection change.</param>
		/// <returns>True if node was selected, false if not.</returns>
		private bool SelectNode(TreeNode tn, bool select, TreeViewAction tva)
		{
			bool blnSelected = false;

			if (tn == null)
				return false;

			if (select)
			{
				// Only try to select node if it was not already selected																		
				if (!IsNodeSelected(tn))
				{
					// Check if node selection is cancelled
					TreeViewCancelEventArgs tvcea = new TreeViewCancelEventArgs(tn, false, tva);
					base.OnBeforeSelect(tvcea);
					if (tvcea.Cancel)
					{
						// This node selection was cancelled!						
						return false;
					}

					PreserveNodeColors(tn);

					tn.BackColor = SelectionBackColor; // GKM moved from above
					tn.ForeColor = BackColor; // GKM moved from above									

					htblSelectedNodes.Add(tn.GetHashCode(), tn);
					blnSelected = true;
					blnSelectionChanged = true;

					base.OnAfterSelect(new TreeViewEventArgs(tn, tva));
				}

				tnMostRecentSelectedNode = tn;
			}
			else
			{
				// Only unselect node if it was selected
				if (IsNodeSelected(tn))
				{
					OnBeforeDeselect(tn);

					Color[] originalColors = (Color[])this.htblSelectedNodesOrigColors[tn.GetHashCode()];
					if (originalColors != null)
					{
						htblSelectedNodes.Remove(tn.GetHashCode());
						blnSelectionChanged = true;
						htblSelectedNodesOrigColors.Remove(tn.GetHashCode());

						// GKM - Restore original node colors
						tn.BackColor = originalColors[0]; // GKM - was BackColor;
						tn.ForeColor = originalColors[1]; // GKM - was ForeColor;
					}

					OnAfterDeselect(tn);
				}
			}

			return blnSelected;
		}
Beispiel #29
0
		/// <summary>
		/// Unselects all selected nodes that don't belong directly or indirectly to the specified parent.
		/// </summary>
		/// <param name="parent">Parent node.</param>
		/// <param name="tva">Specifies the action that caused the selection change.</param>
		private void UnselectAllNodesNotBelongingToParent(TreeNode parent, TreeViewAction tva)
		{
			// First, build list of nodes that need to be unselected
			ArrayList arrNodesToDeselect = new ArrayList();
			foreach (TreeNode selectedTreeNode in htblSelectedNodes.Values)
			{
				if (!IsChildOf(selectedTreeNode, parent))
				{
					arrNodesToDeselect.Add(selectedTreeNode);
				}
			}

			// Do the actual unselect
			foreach (TreeNode tnToDeselect in arrNodesToDeselect)
			{
				SelectNode(tnToDeselect, false, tva);
			}
		}
Beispiel #30
0
		/// <summary>
		/// Unselects all selected nodes.
		/// </summary>
		/// <param name="tva">Specifies the action that caused the selection change.</param>
		private void UnselectAllNodes(TreeViewAction tva)
		{
			UnselectAllNodesExceptNode(null, tva);
		}
Beispiel #31
0
        private static void ModifyFolderExpandedState(TreeNode Node, TreeViewAction Action)
        {
            ConfigItems.NodeDescription nodeDescr = (ConfigItems.NodeDescription)Node.Tag;

            switch (nodeDescr.TreeNodeType)
            {
                case NodeType.Folder:
                    ConfigItems.TDSQueriesTree.FoldersRow folder = (ConfigItems.TDSQueriesTree.FoldersRow)nodeDescr.NodeData;

                    folder.Expanded = (Action == TreeViewAction.Expand ? true : false);

                    break;
            }
        }
			/// <summary>
			/// Constructor.
			/// </summary>
			/// <param name="node">The node.</param>
			/// <param name="cancel">if set to <c>true</c> [cancel].</param>
			/// <param name="action">The action.</param>
			/// <param name="currentStateImageIndex">Index of the current state image.</param>
			/// <param name="newStateImageIndex">New index of the state image.</param>
			public TreeViewCancelTriStateEventArgs(
					TreeNode node,
					bool cancel,
					TreeViewAction action,
					int currentStateImageIndex,
					int newStateImageIndex )
				:
				base( node, cancel, action )
			{
				this.currentStateImageIndex = currentStateImageIndex;
				this.newStateImageIndex = newStateImageIndex;
			}
		/// <summary>
		/// Applies the given state to the given node.
		/// Raises events, too.
		/// </summary>
		/// <param name="node">The node.</param>
		/// <param name="action">The action.</param>
		/// <param name="stateImageIndex">Index of the state image.</param>
		/// <param name="raiseEvents">if set to <c>true</c> [raise events].</param>
		private void SetTriStateToNode(
			TreeNode node,
			TreeViewAction action,
			int stateImageIndex,
			bool raiseEvents )
		{
			bool canSet = true;

			if ( raiseEvents )
			{
				TreeViewCancelEventArgs args =
					new TreeViewCancelEventArgs( node, false, action );

				OnBeforeCheck( args );

				TreeViewCancelTriStateEventArgs triArgs =
					new TreeViewCancelTriStateEventArgs(
					node,
					args.Cancel,
					action,
					node.StateImageIndex,
					stateImageIndex );

				OnBeforeTriStateCheck( triArgs );

				canSet = !triArgs.Cancel;
			}

			if ( canSet )
			{
				// Actually set.
				// THIS IS THE ONLY PLACE to set.
				node.StateImageIndex = stateImageIndex;

				if ( raiseEvents )
				{
					TreeViewEventArgs args =
						new TreeViewEventArgs( node, action );

					OnAfterCheck( args );

					TreeViewTriStateEventArgs triArgs =
						new TreeViewTriStateEventArgs(
						node,
						action,
						node.StateImageIndex );

					OnAfterTriStateCheck( triArgs );
				}
			}
		}
 internal bool TreeViewBeforeCheck(TreeNode node, TreeViewAction actionTaken)
 {
     TreeViewCancelEventArgs e = new TreeViewCancelEventArgs(node, false, actionTaken);
     this.OnBeforeCheck(e);
     return e.Cancel;
 }
 public TreeViewEventArgs(TreeNode node, TreeViewAction action)
 {
     Action = action;
     Node = node;
 }
        /// <summary>
        /// Selects nodes within the specified range.
        /// </summary>
        /// <param name="startNode">Start node.</param>
        /// <param name="endNode">End Node.</param>
        /// <param name="tva">Specifies the action that caused the selection change.</param>
        private void SelectNodesInsideRange(TreeNode startNode, TreeNode endNode, TreeViewAction tva)
        {
            // Calculate start node and end node
            TreeNode firstNode = null;
            TreeNode lastNode = null;

            SortNodes(ref startNode, ref endNode);

            firstNode = startNode;
            lastNode = endNode;

            //This was a terrible idea, whoever came up with it...
            // Bounds are not updated always and it's not fixable as it's part of .NET framework.
            // Much better is to rely on a real index in a tree model
            /*

            if (startNode.Bounds.Y < endNode.Bounds.Y)
            {
                firstNode = startNode;
                lastNode = endNode;
            }
            else
            {
                firstNode = endNode;
                lastNode = startNode;
            }
            */

            // Select each node in range

            SelectNode(firstNode, true, tva);
            TreeNode tnTemp = firstNode;
            while (tnTemp != lastNode)
            {
                tnTemp = tnTemp.NextVisibleNode;
                if (tnTemp != null)
                {
                    SelectNode(tnTemp, true, tva);
                }
            }
            SelectNode(lastNode, true, tva);
        }
Beispiel #37
0
 public VirtualTreeViewEventArgs(VirtualTreeNode node, TreeViewAction action)
     : this(node)
 {
     _action = action;
 }
Beispiel #38
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;
			}
		}
Beispiel #39
0
		/// <summary>
		/// Processes a node range.
		/// </summary>
		/// <param name="startNode">Start node of range.</param>
		/// <param name="endNode">End node of range.</param>
		/// <param name="e">MouseEventArgs.</param>
		/// <param name="keys">Keys.</param>
		/// <param name="tva">TreeViewAction.</param>
		/// <param name="allowStartEdit">True if node can go to edit mode, false if not.</param>
		private void ProcessNodeRange(TreeNode startNode, TreeNode endNode, MouseEventArgs e, Keys keys, TreeViewAction tva, bool allowStartEdit)
		{
			blnSelectionChanged = false; // prepare for OnSelectionsChanged

			if (e.Button == MouseButtons.Left)
			{
				blnWasDoubleClick = (intMouseClicks == 2);

				TreeNode tnTemp = null;
				int intNodeLevelStart;

				if (((keys & Keys.Control) == 0) && ((keys & Keys.Shift) == 0))
				{
					// CTRL and SHIFT not held down							
					tnSelectionMirrorPoint = endNode;
					int intNumberOfSelectedNodes = SelectedNodes.Count;

					// If it was a double click, select node and suspend further processing					
					if (blnWasDoubleClick)
					{
						base.OnMouseDown(e);
						return;
					}

					if (!IsPlusMinusClicked(endNode, e))
					{
						bool blnNodeWasSelected = false;
						if (IsNodeSelected(endNode))
							blnNodeWasSelected = true;


						UnselectAllNodesExceptNode(endNode, tva);
						SelectNode(endNode, true, tva);


						if ((blnNodeWasSelected) && (LabelEdit) && (allowStartEdit) && (!blnWasDoubleClick) && (intNumberOfSelectedNodes <= 1))
						{
							// Node should be put in edit mode					
							tnNodeToStartEditOn = endNode;
							System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ThreadStart(StartEdit));
							t.Start();
						}
					}
				}
				else if (((keys & Keys.Control) != 0) && ((keys & Keys.Shift) == 0))
				{
					// CTRL held down
					tnSelectionMirrorPoint = null;

					if (!IsNodeSelected(endNode))
					{
						switch (selectionMode)
						{
							case TreeViewSelectionMode.SingleSelect:
								UnselectAllNodesExceptNode(endNode, tva);
								break;

							case TreeViewSelectionMode.MultiSelectSameRootBranch:
								TreeNode tnAbsoluteParent2 = GetRootParent(endNode);
								UnselectAllNodesNotBelongingToParent(tnAbsoluteParent2, tva);
								break;

							case TreeViewSelectionMode.MultiSelectSameLevel:
								UnselectAllNodesNotBelongingToLevel(GetNodeLevel(endNode), tva);
								break;

							case TreeViewSelectionMode.MultiSelectSameLevelAndRootBranch:
								TreeNode tnAbsoluteParent = GetRootParent(endNode);
								UnselectAllNodesNotBelongingToParent(tnAbsoluteParent, tva);
								UnselectAllNodesNotBelongingToLevel(GetNodeLevel(endNode), tva);
								break;

							case TreeViewSelectionMode.MultiSelectSameParent:
								TreeNode tnParent = endNode.Parent;
								UnselectAllNodesNotBelongingDirectlyToParent(tnParent, tva);
								break;
						}

						SelectNode(endNode, true, tva);
					}
					else
					{
						SelectNode(endNode, false, tva);
					}
				}
				else if (((keys & Keys.Control) == 0) && ((keys & Keys.Shift) != 0))
				{
					// SHIFT pressed
					if (tnSelectionMirrorPoint == null)
					{
						tnSelectionMirrorPoint = startNode;
					}

					switch (selectionMode)
					{
						case TreeViewSelectionMode.SingleSelect:
							UnselectAllNodesExceptNode(endNode, tva);
							SelectNode(endNode, true, tva);
							break;

						case TreeViewSelectionMode.MultiSelectSameRootBranch:
							TreeNode tnAbsoluteParentStartNode = GetRootParent(startNode);
							tnTemp = startNode;
							// Check each visible node from startNode to endNode and select it if needed
							while ((tnTemp != null) && (tnTemp != endNode))
							{
								if (startNode.Bounds.Y > endNode.Bounds.Y)
									tnTemp = tnTemp.PrevVisibleNode;
								else
									tnTemp = tnTemp.NextVisibleNode;
								if (tnTemp != null)
								{
									TreeNode tnAbsoluteParent = GetRootParent(tnTemp);
									if (tnAbsoluteParent == tnAbsoluteParentStartNode)
									{
										SelectNode(tnTemp, true, tva);
									}
								}
							}
							UnselectAllNodesNotBelongingToParent(tnAbsoluteParentStartNode, tva);
							UnselectNodesOutsideRange(tnSelectionMirrorPoint, endNode, tva);
							break;

						case TreeViewSelectionMode.MultiSelectSameLevel:
							intNodeLevelStart = GetNodeLevel(startNode);
							tnTemp = startNode;
							// Check each visible node from startNode to endNode and select it if needed
							while ((tnTemp != null) && (tnTemp != endNode))
							{
								if (startNode.Bounds.Y > endNode.Bounds.Y)
									tnTemp = tnTemp.PrevVisibleNode;
								else
									tnTemp = tnTemp.NextVisibleNode;
								if (tnTemp != null)
								{
									int intNodeLevel = GetNodeLevel(tnTemp);
									if (intNodeLevel == intNodeLevelStart)
									{
										SelectNode(tnTemp, true, tva);
									}
								}
							}
							UnselectAllNodesNotBelongingToLevel(intNodeLevelStart, tva);
							UnselectNodesOutsideRange(tnSelectionMirrorPoint, endNode, tva);
							break;

						case TreeViewSelectionMode.MultiSelectSameLevelAndRootBranch:
							TreeNode tnAbsoluteParentStart = GetRootParent(startNode);
							intNodeLevelStart = GetNodeLevel(startNode);
							tnTemp = startNode;
							// Check each visible node from startNode to endNode and select it if needed
							while ((tnTemp != null) && (tnTemp != endNode))
							{
								if (startNode.Bounds.Y > endNode.Bounds.Y)
									tnTemp = tnTemp.PrevVisibleNode;
								else
									tnTemp = tnTemp.NextVisibleNode;
								if (tnTemp != null)
								{
									int intNodeLevel = GetNodeLevel(tnTemp);
									TreeNode tnAbsoluteParent = GetRootParent(tnTemp);
									if ((intNodeLevel == intNodeLevelStart) && (tnAbsoluteParent == tnAbsoluteParentStart))
									{
										SelectNode(tnTemp, true, tva);
									}
								}
							}
							UnselectAllNodesNotBelongingToParent(tnAbsoluteParentStart, tva);
							UnselectAllNodesNotBelongingToLevel(intNodeLevelStart, tva);
							UnselectNodesOutsideRange(tnSelectionMirrorPoint, endNode, tva);
							break;

						case TreeViewSelectionMode.MultiSelect:
							SelectNodesInsideRange(tnSelectionMirrorPoint, endNode, tva);
							UnselectNodesOutsideRange(tnSelectionMirrorPoint, endNode, tva);
							break;

						case TreeViewSelectionMode.MultiSelectSameParent:
							TreeNode tnParentStartNode = startNode.Parent;
							tnTemp = startNode;
							// Check each visible node from startNode to endNode and select it if needed
							while ((tnTemp != null) && (tnTemp != endNode))
							{
								if (startNode.Bounds.Y > endNode.Bounds.Y)
									tnTemp = tnTemp.PrevVisibleNode;
								else
									tnTemp = tnTemp.NextVisibleNode;
								if (tnTemp != null)
								{
									TreeNode tnParent = tnTemp.Parent;
									if (tnParent == tnParentStartNode)
									{
										SelectNode(tnTemp, true, tva);
									}
								}
							}
							UnselectAllNodesNotBelongingDirectlyToParent(tnParentStartNode, tva);
							UnselectNodesOutsideRange(tnSelectionMirrorPoint, endNode, tva);
							break;
					}
				}
				else if (((keys & Keys.Control) != 0) && ((keys & Keys.Shift) != 0))
				{
					// SHIFT AND CTRL pressed
					switch (selectionMode)
					{
						case TreeViewSelectionMode.SingleSelect:
							UnselectAllNodesExceptNode(endNode, tva);
							SelectNode(endNode, true, tva);
							break;

						case TreeViewSelectionMode.MultiSelectSameRootBranch:
							TreeNode tnAbsoluteParentStartNode = GetRootParent(startNode);
							tnTemp = startNode;
							// Check each visible node from startNode to endNode and select it if needed
							while ((tnTemp != null) && (tnTemp != endNode))
							{
								if (startNode.Bounds.Y > endNode.Bounds.Y)
									tnTemp = tnTemp.PrevVisibleNode;
								else
									tnTemp = tnTemp.NextVisibleNode;
								if (tnTemp != null)
								{
									TreeNode tnAbsoluteParent = GetRootParent(tnTemp);
									if (tnAbsoluteParent == tnAbsoluteParentStartNode)
									{
										SelectNode(tnTemp, true, tva);
									}
								}
							}
							UnselectAllNodesNotBelongingToParent(tnAbsoluteParentStartNode, tva);
							break;

						case TreeViewSelectionMode.MultiSelectSameLevel:
							intNodeLevelStart = GetNodeLevel(startNode);
							tnTemp = startNode;
							// Check each visible node from startNode to endNode and select it if needed
							while ((tnTemp != null) && (tnTemp != endNode))
							{
								if (startNode.Bounds.Y > endNode.Bounds.Y)
									tnTemp = tnTemp.PrevVisibleNode;
								else
									tnTemp = tnTemp.NextVisibleNode;
								if (tnTemp != null)
								{
									int intNodeLevel = GetNodeLevel(tnTemp);
									if (intNodeLevel == intNodeLevelStart)
									{
										SelectNode(tnTemp, true, tva);
									}
								}
							}
							UnselectAllNodesNotBelongingToLevel(intNodeLevelStart, tva);
							break;

						case TreeViewSelectionMode.MultiSelectSameLevelAndRootBranch:
							TreeNode tnAbsoluteParentStart = GetRootParent(startNode);
							intNodeLevelStart = GetNodeLevel(startNode);
							tnTemp = startNode;
							// Check each visible node from startNode to endNode and select it if needed
							while ((tnTemp != null) && (tnTemp != endNode))
							{
								if (startNode.Bounds.Y > endNode.Bounds.Y)
									tnTemp = tnTemp.PrevVisibleNode;
								else
									tnTemp = tnTemp.NextVisibleNode;
								if (tnTemp != null)
								{
									int intNodeLevel = GetNodeLevel(tnTemp);
									TreeNode tnAbsoluteParent = GetRootParent(tnTemp);
									if ((intNodeLevel == intNodeLevelStart) && (tnAbsoluteParent == tnAbsoluteParentStart))
									{
										SelectNode(tnTemp, true, tva);
									}
								}
							}
							UnselectAllNodesNotBelongingToParent(tnAbsoluteParentStart, tva);
							UnselectAllNodesNotBelongingToLevel(intNodeLevelStart, tva);
							break;

						case TreeViewSelectionMode.MultiSelect:
							tnTemp = startNode;
							// Check each visible node from startNode to endNode and select it if needed
							while ((tnTemp != null) && (tnTemp != endNode))
							{
								if (startNode.Bounds.Y > endNode.Bounds.Y)
									tnTemp = tnTemp.PrevVisibleNode;
								else
									tnTemp = tnTemp.NextVisibleNode;
								if (tnTemp != null)
								{
									SelectNode(tnTemp, true, tva);
								}
							}
							break;

						case TreeViewSelectionMode.MultiSelectSameParent:
							TreeNode tnParentStartNode = startNode.Parent;
							tnTemp = startNode;
							// Check each visible node from startNode to endNode and select it if needed
							while ((tnTemp != null) && (tnTemp != endNode))
							{
								if (startNode.Bounds.Y > endNode.Bounds.Y)
									tnTemp = tnTemp.PrevVisibleNode;
								else
									tnTemp = tnTemp.NextVisibleNode;
								if (tnTemp != null)
								{
									TreeNode tnParent = tnTemp.Parent;
									if (tnParent == tnParentStartNode)
									{
										SelectNode(tnTemp, true, tva);
									}
								}
							}
							UnselectAllNodesNotBelongingDirectlyToParent(tnParentStartNode, tva);
							break;
					}
				}
			}
			else if (e.Button == MouseButtons.Right)
			{
				// if right mouse button clicked, clear selection and select right-clicked node
				if (!IsNodeSelected(endNode))
				{
					UnselectAllNodes(tva);
					SelectNode(endNode, true, tva);
				}
			}
			OnSelectionsChanged();
		}
		/// <summary>
		/// Toggles the tri state check.
		/// </summary>
		/// <param name="node">The node.</param>
		/// <param name="action">The action.</param>
		private void ToggleTriStateCheck(
			TreeNode node,
			TreeViewAction action )
		{
			if ( node.StateImageIndex == TriStateUncheckedStateImageIndex )
			{
				SetTriStateToNode(
				node,
				action,
				TriStateCheckedStateImageIndex,
				true );
			}
			else if ( node.StateImageIndex == TriStateIndeterminateStateImageIndex &&
				indeterminateToChecked )
			{
				SetTriStateToNode(
				node,
				action,
				TriStateCheckedStateImageIndex,
				true );
			}
			else
			{
				SetTriStateToNode(
				node,
				action,
				TriStateUncheckedStateImageIndex,
				true );
			}
		}
Beispiel #41
0
		/// <summary>
		/// Unselects all selected nodes that don't belong to the specified level.
		/// </summary>
		/// <param name="level">Node level.</param>
		/// <param name="tva">Specifies the action that caused the selection change.</param>
		private void UnselectAllNodesNotBelongingToLevel(int level, TreeViewAction tva)
		{
			// First, build list of nodes that need to be unselected
			ArrayList arrNodesToDeselect = new ArrayList();
			foreach (TreeNode selectedTreeNode in htblSelectedNodes.Values)
			{
				if (GetNodeLevel(selectedTreeNode) != level)
				{
					arrNodesToDeselect.Add(selectedTreeNode);
				}
			}

			// Do the actual unselect
			foreach (TreeNode tnToDeselect in arrNodesToDeselect)
			{
				SelectNode(tnToDeselect, false, tva);
			}
		}
		/// <summary>
		/// Applies a new check state to the given tree node.
		/// The UseTriStateCheckBoxes property must be set to TRUE.
		/// </summary>
		/// <param name="node">The node.</param>
		/// <param name="action">The action.</param>
		/// <param name="checkState">State of the check.</param>
		private void DoSetNodeCheckState(
			TreeNode node,
			TreeViewAction action,
			CheckState checkState )
		{
			// Use TreeViewAction.ByKeyboard here, 
			// to indicate that it was called from outside.
			SetTriStateToNode(
				node,
				action,
				ConvertCheckStateToImageIndex( checkState ),
				true );
		}
Beispiel #43
0
		/// <summary>
		/// Unselects all selected nodes, except for the specified node which should not be touched.
		/// </summary>
		/// <param name="nodeKeepSelected">Node not to touch.</param>
		/// <param name="tva">Specifies the action that caused the selection change.</param>
		private void UnselectAllNodesExceptNode(TreeNode nodeKeepSelected, TreeViewAction tva)
		{
			// First, build list of nodes that need to be unselected
			ArrayList arrNodesToDeselect = new ArrayList();
			foreach (TreeNode selectedTreeNode in htblSelectedNodes.Values)
			{
				if (nodeKeepSelected == null)
				{
					arrNodesToDeselect.Add(selectedTreeNode);
				}
				else if ((nodeKeepSelected != null) && (selectedTreeNode != nodeKeepSelected))
				{
					arrNodesToDeselect.Add(selectedTreeNode);
				}
			}

			// Do the actual unselect
			foreach (TreeNode tnToDeselect in arrNodesToDeselect)
			{
				SelectNode(tnToDeselect, false, tva);
			}
		}
Beispiel #44
0
 public EasyTreeViewEventArgs(object node, TreeViewAction action)
 {
     this.node   = node;
     this.action = action;
 }
Beispiel #45
0
		/// <summary>
		/// Selects nodes within the specified range.
		/// </summary>
		/// <param name="startNode">Start node.</param>
		/// <param name="endNode">End Node.</param>
		/// <param name="tva">Specifies the action that caused the selection change.</param>
		private void SelectNodesInsideRange(TreeNode startNode, TreeNode endNode, TreeViewAction tva)
		{
			// Calculate start node and end node
			TreeNode firstNode = null;
			TreeNode lastNode = null;
			if (startNode.Bounds.Y < endNode.Bounds.Y)
			{
				firstNode = startNode;
				lastNode = endNode;
			}
			else
			{
				firstNode = endNode;
				lastNode = startNode;
			}

			// Select each node in range
			SelectNode(firstNode, true, tva);
			TreeNode tnTemp = firstNode;
			while (tnTemp != lastNode)
			{
				tnTemp = tnTemp.NextVisibleNode;
				if (tnTemp != null)
				{
					SelectNode(tnTemp, true, tva);
				}
			}
			SelectNode(lastNode, true, tva);
		}
        /// <include file='doc\TreeView.uex' path='docs/doc[@for="TreeView.TreeViewBeforeAfterCheck"]/*' />
        /// <devdoc>
        ///     Defined so that a  tree node can use it
        ///
        /// </devdoc>
        /// <internalonly/>

        internal bool TreeViewBeforeCheck(TreeNode node, TreeViewAction actionTaken) {
            TreeViewCancelEventArgs tvce = new TreeViewCancelEventArgs(node, false, actionTaken);
            OnBeforeCheck(tvce);
            return (tvce.Cancel);
        }
Beispiel #47
0
		/// <summary>
		/// Recursively unselect node.
		/// </summary>
		/// <param name="tn">Node to recursively unselect.</param>
		/// <param name="tva">Specifies the action that caused the selection change.</param>
		private void UnselectNodesRecursively(TreeNode tn, TreeViewAction tva)
		{
			SelectNode(tn, false, tva);
			foreach (TreeNode child in tn.Nodes)
			{
				UnselectNodesRecursively(child, tva);
			}
		}
 internal void TreeViewAfterCheck(TreeNode node, TreeViewAction actionTaken) {
     OnAfterCheck(new TreeViewEventArgs(node, actionTaken));
 }
 public TreeViewSelectedNodeChangedArgs(TreeNode beforeNode, TreeNode afterNode, TreeViewAction action)
 {
     BeforeNode = beforeNode;
     AfterNode = afterNode;
     Action = action;
 }
 public TreeViewEventArgs(TreeNode node, TreeViewAction action)
 {
 }
Beispiel #51
0
 public TreeViewEventArgs(TreeNode node)
 {
     this.node   = node;
     this.action = TreeViewAction.Unknown;
 }
Beispiel #52
0
 private void tsResults_AfterExpand(object sender, TreeViewEventArgs e)
 {
     TreeViewAction action = e.Action;
 }
			/// <summary>
			/// Initializes a new instance of the <see cref="TreeViewTriStateEventArgs"/> class.
			/// </summary>
			/// <param name="node">The node.</param>
			/// <param name="action">The action.</param>
			/// <param name="stateImageIndex">Index of the state image.</param>
			public TreeViewTriStateEventArgs(
				TreeNode node,
				TreeViewAction action,
				int stateImageIndex )
				:
				base( node, action )
			{
				this.stateImageIndex = stateImageIndex;
			}
Beispiel #54
0
 public TreeViewEventArgs(TreeNode?node, TreeViewAction action)
 {
     Node   = node;
     Action = action;
 }
Beispiel #55
0
 public VirtualTreeViewCancelEventArgs(VirtualTreeNode node, bool cancel, TreeViewAction action)
     : base(cancel)
 {
     _node = node;
     _action = action;
 }
 public MultiSelectTreeViewCancelEventArgs(MultiSelectTreeNode node, bool cancel, TreeViewAction action)
     : base(cancel)
 {
     _node = node;
     _action = action;
 }
 public TreeViewEventArgs(TreeNode node, TreeViewAction action)
 {
     this.node = node;
     this.action = action;
 }
 private void ChangeNodeStateByUser(TreeNode node, TreeViewAction action)
 {
     if (this.BeforeNodeStateChangeByUser != null)
     {
         this.BeforeNodeStateChangeByUser(this, new TreeViewEventArgs(node, action));
     }
     switch (node.StateImageIndex)
     {
         case ItemState.Unchecked:
         case ItemState.Mixed:
             node.StateImageIndex = ItemState.Checked;
             break;
         case ItemState.Checked:
             node.StateImageIndex = ItemState.Unchecked;
             break;
     }
     UpdateChildren(node);
     UpdateParent(node);
 }
 public TreeViewEventArgs(TreeNode node, TreeViewAction action) : this(node)
 {
     this.action = action;
 }
Beispiel #60
0
 public TreeViewEventArgs(TreeNode node, TreeViewAction action)
 {
     Action = action;
     Node   = node;
 }