Пример #1
0
        /// <summary>
        /// Updates the node at the specified index, with the specified item
        /// </summary>
        /// <param name="index"></param>
        /// <param name="item"></param>
        private void UpdateNode(int index, object item)
        {
            BindingTreeNode node = (BindingTreeNode)_nodeCollection[index];

            node.DataBoundItem = item;
            node.UpdateDisplay();   // force update, even if it is the same item, because its properties may have changed
        }
Пример #2
0
        /// <summary>
        /// Removes the node at the specified index
        /// </summary>
        /// <param name="index"></param>
        private void RemoveNode(int index)
        {
            BindingTreeNode node = (BindingTreeNode)_nodeCollection[index];

            _nodeCollection.RemoveAt(index);
            node.Dispose();
        }
Пример #3
0
        /// <summary>
        /// Adds a node for the specified item
        /// </summary>
        /// <param name="item"></param>
        private void AddNode(object item)
        {
            var node = new BindingTreeNode(_tree, item, _bindingTreeView);

            _nodeCollection.Add(node);
            node.UpdateDisplay();
        }
Пример #4
0
        /// <summary>
        /// Notify that the <see cref="Selection"/> property has changed
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void _treeCtrl_AfterSelect(object sender, TreeViewEventArgs e)
        {
            BindingTreeNode selNode = (BindingTreeNode)_treeCtrl.SelectedNode;

            _treeCtrl.LabelEdit = selNode != null && selNode.CanSetNodeText();

            EventsHelper.Fire(_selectionChanged, this, EventArgs.Empty);
        }
Пример #5
0
        private void _treeCtrl_AfterCollapse(object sender, TreeViewEventArgs e)
        {
            BindingTreeNode node = e.Node as BindingTreeNode;

            if (node != null)
            {
                node.OnExpandCollapse();
            }
        }
Пример #6
0
        /// <summary>
        /// Called when an object is first dragged into this control
        /// </summary>
        /// <param name="e"></param>
        protected override void OnDragEnter(DragEventArgs e)
        {
            // clear any record of a previous drop target node
            _dropTargetNode = null;
            _dropEffect     = DragDropEffects.None;
            _dropPosition   = DragDropPosition.Default;

            base.OnDragEnter(e);
        }
Пример #7
0
        /// <summary>
        /// When the user is about to expand a node, need to build the level beneath it
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void _treeCtrl_BeforeExpand(object sender, TreeViewCancelEventArgs e)
        {
            BindingTreeNode expandingNode = (BindingTreeNode)e.Node;

            if (!expandingNode.IsSubTreeBuilt)
            {
                expandingNode.BuildSubTree();
            }
        }
Пример #8
0
        private void _treeCtrl_ItemDrag(object sender, ItemDragEventArgs e)
        {
            // the item being dragged should be selected as well.
            BindingTreeNode node = (BindingTreeNode)e.Item;

            _treeCtrl.SelectedNode = node;

            ItemDragEventArgs args = new ItemDragEventArgs(e.Button, this.GetSelectionHelper());

            EventsHelper.Fire(_itemDrag, this, args);
        }
Пример #9
0
        private void _contextMenu_Opening(object sender, CancelEventArgs e)
        {
            // Find the node we're on
            Point           pt   = _treeCtrl.PointToClient(TreeView.MousePosition);
            BindingTreeNode node = (BindingTreeNode)_treeCtrl.GetNodeAt(pt.X, pt.Y);

            _treeCtrl.SelectedNode = node;
            if (node == null)
            {
                EventsHelper.Fire(_selectionChanged, this, EventArgs.Empty);
            }
        }
Пример #10
0
        private void _treeCtrl_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            if (CheckBoxes && _treeCtrl.HitTest(e.Location).Location == TreeViewHitTestLocations.StateImage)
            {
                BindingTreeNode node = e.Node as BindingTreeNode;
                if (node != null)
                {
                    node.OnChecked();
                }
            }

            EventsHelper.Fire(_nodeMouseClicked, this, e);
        }
Пример #11
0
 private void _treeCtrl_AfterLabelEdit(object sender, NodeLabelEditEventArgs e)
 {
     if (string.IsNullOrEmpty(e.Label))
     {
         // user cancel the edit, stop editing
         e.CancelEdit = true;
     }
     else
     {
         BindingTreeNode node = e.Node as BindingTreeNode;
         if (node != null)
         {
             node.AfterLabelEdit(e.Label);
         }
     }
 }
Пример #12
0
        protected override void OnDragLeave(EventArgs e)
        {
            // is there a current drop-target node?
            if (_dropTargetNode != null)
            {
                // remove highlighting from drop target node
                HighlightNode(_dropTargetNode, false);
                SetInsertMark(_dropTargetNode, DragDropPosition.Default);
            }

            // clear the drop target node
            _dropTargetNode = null;
            _dropEffect     = DragDropEffects.None;
            _dropPosition   = DragDropPosition.Default;

            base.OnDragLeave(e);
        }
Пример #13
0
        /// <summary>
        /// Builds or rebuilds the entire level
        /// </summary>
        private void BuildLevel()
        {
            // dispose of all existing tree nodes before clearing the collection
            foreach (TreeNode node in _nodeCollection)
            {
                if (node is IDisposable)
                {
                    (node as IDisposable).Dispose();
                }
            }

            _nodeCollection.Clear();

            // create new node for each item
            foreach (object item in _tree.Items)
            {
                BindingTreeNode node = new BindingTreeNode(_tree, item, _bindingTreeView);
                _nodeCollection.Add(node);
                node.UpdateDisplay();
            }
        }
Пример #14
0
        /// <summary>
        /// Called when an object is dropped onto this control
        /// </summary>
        /// <param name="e"></param>
        protected override void OnDragDrop(DragEventArgs e)
        {
            // is there a current drop-target node?
            if (_dropTargetNode != null)
            {
                try
                {
                    object dragDropData = GetDragDropData(e);

                    // ask the node to accept the drop
                    DragDropKind result = _dropTargetNode.AcceptDrop(dragDropData, GetDragDropKind(e.Effect), _dropPosition);

                    // be sure to set the resulting effect in the event args, so that it gets communicated
                    // back to the initiator of the drag drop operation
                    e.Effect = GetDragDropEffect(result);

                    // Fire the item dropped event
                    if (e.Effect != DragDropEffects.None)
                    {
                        ItemDroppedEventArgs args = new ItemDroppedEventArgs(dragDropData, result);
                        EventsHelper.Fire(_itemDropped, this, args);
                    }
                }
                catch (Exception ex)
                {
                    Platform.Log(LogLevel.Error, ex);
                }

                // remove highlighting from drop target node
                HighlightNode(_dropTargetNode, false);
                SetInsertMark(_dropTargetNode, DragDropPosition.Default);
            }

            // clear the drop target node
            _dropTargetNode = null;
            _dropEffect     = DragDropEffects.None;
            _dropPosition   = DragDropPosition.Default;

            base.OnDragDrop(e);
        }
Пример #15
0
        /// <summary>
        /// Searches the tree depth-first for a node matching the specified criteria
        /// </summary>
        /// <param name="nodeCollection"></param>
        /// <param name="criteria"></param>
        /// <returns></returns>
        private BindingTreeNode FindNodeRecursive(TreeNodeCollection nodeCollection, Predicate <BindingTreeNode> criteria)
        {
            foreach (TreeNode node in nodeCollection)
            {
                //  Bug #871
                //  See BindingTreeNode.UpdateDisplay():
                //  the Nodes property may contain a "dummy" TreeNode, so ensure each iterated TreeNode is actually a BindingTreeNode
                BindingTreeNode bindingTreeNode = node as BindingTreeNode;

                if (bindingTreeNode != null && criteria(bindingTreeNode))
                {
                    return(bindingTreeNode);
                }
                else
                {
                    BindingTreeNode nodeFound = FindNodeRecursive(node.Nodes, criteria);
                    if (nodeFound != null)
                    {
                        return(nodeFound);
                    }
                }
            }
            return(null);
        }
Пример #16
0
		private void InsertNode(int index, object item)
		{
			BindingTreeNode node = new BindingTreeNode(_tree, item, _bindingTreeView);
			_nodeCollection.Insert(index, node);
		}
Пример #17
0
 /// <summary>
 /// Adds a node for the specified item
 /// </summary>
 /// <param name="item"></param>
 private void AddNode(object item)
 {
     var node = new BindingTreeNode(_tree, item, _bindingTreeView);
     _nodeCollection.Add(node);
     node.UpdateDisplay();
 }
Пример #18
0
        private void InsertNode(int index, object item)
        {
            BindingTreeNode node = new BindingTreeNode(_tree, item, _bindingTreeView);

            _nodeCollection.Insert(index, node);
        }
Пример #19
0
        /// <summary>
        /// Obtains the current selection
        /// </summary>
        /// <returns></returns>
        private ISelection GetSelectionHelper()
        {
            BindingTreeNode selNode = (BindingTreeNode)_treeCtrl.SelectedNode;

            return(selNode == null ? new Selection() : new Selection(selNode.DataBoundItem));
        }
Пример #20
0
        protected override void OnDragLeave(EventArgs e)
        {
            // is there a current drop-target node?
            if (_dropTargetNode != null)
            {
                // remove highlighting from drop target node
				HighlightNode(_dropTargetNode, false);
				SetInsertMark(_dropTargetNode, DragDropPosition.Default);
            }

            // clear the drop target node
            _dropTargetNode = null;
            _dropEffect = DragDropEffects.None;
        	_dropPosition = DragDropPosition.Default;

            base.OnDragLeave(e);
        }
Пример #21
0
        /// <summary>
        /// Called when an object is dropped onto this control
        /// </summary>
        /// <param name="e"></param>
        protected override void OnDragDrop(DragEventArgs e)
        {
            // is there a current drop-target node?
            if (_dropTargetNode != null)
            {
                try
                {
					object dragDropData = GetDragDropData(e);
					
					// ask the node to accept the drop
					DragDropKind result = _dropTargetNode.AcceptDrop(dragDropData, GetDragDropKind(e.Effect), _dropPosition);

                    // be sure to set the resulting effect in the event args, so that it gets communicated
                    // back to the initiator of the drag drop operation
                    e.Effect = GetDragDropEffect(result);

					// Fire the item dropped event
					if (e.Effect != DragDropEffects.None)
					{
						ItemDroppedEventArgs args = new ItemDroppedEventArgs(dragDropData, result);
						EventsHelper.Fire(_itemDropped, this, args);
					}
				}
                catch (Exception ex)
                {
                    Platform.Log(LogLevel.Error, ex);
                }

                // remove highlighting from drop target node
                HighlightNode(_dropTargetNode, false);
            	SetInsertMark(_dropTargetNode, DragDropPosition.Default);
            }

            // clear the drop target node
            _dropTargetNode = null;
            _dropEffect = DragDropEffects.None;
        	_dropPosition = DragDropPosition.Default;

            base.OnDragDrop(e);
        }
Пример #22
0
        /// <summary>
        /// Called repeatedly as the object is dragged within this control
        /// </summary>
        /// <param name="e"></param>
        protected override void OnDragOver(DragEventArgs e)
        {
            // determine the node under the cursor
			Point cursor = _treeCtrl.PointToClient(new Point(e.X, e.Y));
            BindingTreeNode node = (BindingTreeNode)_treeCtrl.GetNodeAt(cursor);
 
            // determine what effect the user is trying to accomplish
            DragDropEffects desiredEffect = GetDragDropDesiredEffect(e);

			// determine if the user is trying to drag to the top, middle or bottom areas of the node
        	DragDropPosition position = DragDropPosition.Default;
        	if (this.AllowDropToIndex && node != null)
        	{
        		float result = 1f*(cursor.Y - node.Bounds.Y)/node.Bounds.Height;
        		if (result <= 0.2f)
        			position = DragDropPosition.Before;
        		else if (result >= 0.8f)
        			position = DragDropPosition.After;
        	}

            // optimization: only care if different than the last known drop-target node, or different desired effect, or different drop position
        	if (node != _dropTargetNode || desiredEffect != _dropEffect || position != _dropPosition)
            {
                _treeCtrl.BeginUpdate();    // suspend drawing

                // un-highlight the last known drop-target node
				HighlightNode(_dropTargetNode, false);
				SetInsertMark(_dropTargetNode, DragDropPosition.Default);

                // set the drop target node to this node
                _dropTargetNode = node;
                _dropEffect = desiredEffect;
				_dropPosition = position;

                // check if drop target node exists and what kind of operation it will accept
                DragDropKind acceptableKind = (_dropTargetNode == null) ?
                    DragDropKind.None : _dropTargetNode.CanAcceptDrop(GetDragDropData(e), GetDragDropKind(desiredEffect), _dropPosition);

                // display the appropriate effect cue based on the result
                e.Effect = GetDragDropEffect(acceptableKind);

                // if the drop target is valid and willing to accept data, highlight it
                if (acceptableKind != DragDropKind.None)
                {
					HighlightNode(_dropTargetNode, _dropPosition == DragDropPosition.Default);
					SetInsertMark(_dropTargetNode, _dropPosition);
                }

                _treeCtrl.EndUpdate(); // resume drawing
            }

			// perform drag scrolling
			if (_treeCtrl.ClientRectangle.Contains(cursor))
			{
				if (cursor.Y > _treeCtrl.Height - _treeCtrl.ItemHeight/2)
					SendMessage(_treeCtrl.Handle, (int) WindowsMessages.WM_VSCROLL, new IntPtr(1), IntPtr.Zero);
				else if (cursor.Y < _treeCtrl.ItemHeight/2)
					SendMessage(_treeCtrl.Handle, (int) WindowsMessages.WM_VSCROLL, IntPtr.Zero, IntPtr.Zero);
			}
            
            base.OnDragOver(e);
        }
Пример #23
0
        /// <summary>
        /// Called when an object is first dragged into this control
        /// </summary>
        /// <param name="e"></param>
        protected override void OnDragEnter(DragEventArgs e)
        {
            // clear any record of a previous drop target node
            _dropTargetNode = null;
            _dropEffect = DragDropEffects.None;
			_dropPosition = DragDropPosition.Default;

            base.OnDragEnter(e);
        }
Пример #24
0
        /// <summary>
        /// Called repeatedly as the object is dragged within this control
        /// </summary>
        /// <param name="e"></param>
        protected override void OnDragOver(DragEventArgs e)
        {
            // determine the node under the cursor
            Point           cursor = _treeCtrl.PointToClient(new Point(e.X, e.Y));
            BindingTreeNode node   = (BindingTreeNode)_treeCtrl.GetNodeAt(cursor);

            // determine what effect the user is trying to accomplish
            DragDropEffects desiredEffect = GetDragDropDesiredEffect(e);

            // determine if the user is trying to drag to the top, middle or bottom areas of the node
            DragDropPosition position = DragDropPosition.Default;

            if (this.AllowDropToIndex && node != null)
            {
                float result = 1f * (cursor.Y - node.Bounds.Y) / node.Bounds.Height;
                if (result <= 0.2f)
                {
                    position = DragDropPosition.Before;
                }
                else if (result >= 0.8f)
                {
                    position = DragDropPosition.After;
                }
            }

            // optimization: only care if different than the last known drop-target node, or different desired effect, or different drop position
            if (node != _dropTargetNode || desiredEffect != _dropEffect || position != _dropPosition)
            {
                _treeCtrl.BeginUpdate();    // suspend drawing

                // un-highlight the last known drop-target node
                HighlightNode(_dropTargetNode, false);
                SetInsertMark(_dropTargetNode, DragDropPosition.Default);

                // set the drop target node to this node
                _dropTargetNode = node;
                _dropEffect     = desiredEffect;
                _dropPosition   = position;

                // check if drop target node exists and what kind of operation it will accept
                DragDropKind acceptableKind = (_dropTargetNode == null) ?
                                              DragDropKind.None : _dropTargetNode.CanAcceptDrop(GetDragDropData(e), GetDragDropKind(desiredEffect), _dropPosition);

                // display the appropriate effect cue based on the result
                e.Effect = GetDragDropEffect(acceptableKind);

                // if the drop target is valid and willing to accept data, highlight it
                if (acceptableKind != DragDropKind.None)
                {
                    HighlightNode(_dropTargetNode, _dropPosition == DragDropPosition.Default);
                    SetInsertMark(_dropTargetNode, _dropPosition);
                }

                _treeCtrl.EndUpdate(); // resume drawing
            }

            // perform drag scrolling
            if (_treeCtrl.ClientRectangle.Contains(cursor))
            {
                if (cursor.Y > _treeCtrl.Height - _treeCtrl.ItemHeight / 2)
                {
                    SendMessage(_treeCtrl.Handle, (int)WindowsMessages.WM_VSCROLL, new IntPtr(1), IntPtr.Zero);
                }
                else if (cursor.Y < _treeCtrl.ItemHeight / 2)
                {
                    SendMessage(_treeCtrl.Handle, (int)WindowsMessages.WM_VSCROLL, IntPtr.Zero, IntPtr.Zero);
                }
            }

            base.OnDragOver(e);
        }
Пример #25
0
        /// <summary>
        /// Builds or rebuilds the entire level
        /// </summary>
        private void BuildLevel()
        {
			// dispose of all existing tree nodes before clearing the collection
        	foreach (TreeNode node in _nodeCollection)
        	{
        		if(node is IDisposable)
					(node as IDisposable).Dispose();
        	}

            _nodeCollection.Clear();

			// create new node for each item
            foreach (object item in _tree.Items)
            {
				BindingTreeNode node = new BindingTreeNode(_tree, item, _bindingTreeView);
                _nodeCollection.Add(node);
                node.UpdateDisplay();
            }
        }