Example #1
0
        private void HighlightNode(KTreeNode newHighlight, KTreeNodeMeasurements.Part?newPart)
        {
            if (newHighlight != _highlightNode || _highlightPart != newPart)
            {
                bool oldFocused = Focused;

                KTreeNode old = _highlightNode;

                if (newHighlight != null && !newHighlight.IsSelectable)
                {
                    _highlightNode = null;
                    _highlightPart = null;
                }
                else
                {
                    _highlightNode = newHighlight;
                    _highlightPart = newPart;
                }

                // Update the border if required
                if (oldFocused != Focused)
                {
                    RedrawBorder();
                }

                // Render old node without highlight
                if (old != null)
                {
                    Rerender(old);
                }

                // Render new node
                if (_highlightNode != null)
                {
                    Rerender(_highlightNode);
                }
            }
        }
Example #2
0
        private HitTestResult?HitTest(Point location, params KTreeNodeMeasurements.Part[] wanted)
        {
            if (location.X < 0 || location.X >= ViewRectangle.Width)
            {
                return(null);
            }

            KTreeNode node = NodeAtY(location.Y);

            if (node == null)
            {
                return(null);
            }

            KTreeNodeMeasurements.Part?part = node.EffectiveDimension.HitTest(location.X + _horizontalScrollBar.Value);
            if (part != null)
            {
                // Check if it's the part we're interested in
                if (wanted.Length > 0 && !wanted.Contains(part.Value))
                {
                    return(null);
                }

                // Part.None is valid only if full row selection is enabled
                if (!FullRowSelect && part.Value == KTreeNodeMeasurements.Part.None)
                {
                    return(null);
                }

                // Success
                return(new HitTestResult()
                {
                    Node = node, Part = part.Value
                });
            }

            return(null);
        }
 private VisualStyleRenderer GetStyle(KTreeNode node, KTreeNodeMeasurements.Part?highlight)
 {
     if (!_tree.Enabled)
     {
         return(_treeViewItemDisabled);
     }
     else if (highlight != null)
     {
         if (node.IsSelected)
         {
             return(_treeViewItemHotSelected);
         }
         else
         {
             return(_treeViewItemHot);
         }
     }
     else
     {
         if (node.IsSelected)
         {
             if (_tree.Focused)
             {
                 return(_treeViewItemSelected);
             }
             else
             {
                 return(_treeViewItemSelectedNotFocus);
             }
         }
         else
         {
             return(_treeViewItemNormal);
         }
     }
 }
        protected override void RenderNodeText(Graphics graphics, KTreeNode node, Rectangle rect, KTreeNodeMeasurements.Part?highlight)
        {
            Color foreColor = GetStyle(node, highlight).GetColor(ColorProperty.TextColor);

            TextRenderer.DrawText(graphics, node.Text, _tree.Font, rect, foreColor, Color.Transparent, TEXT_FLAGS);
        }
Example #5
0
 public override void ToggleCheck(KTreeNode node)
 {
     node.CheckState = node.CheckState == CheckState.Checked ? CheckState.Unchecked : CheckState.Checked;
 }
Example #6
0
 abstract public void ToggleCheck(KTreeNode node);
Example #7
0
 protected virtual CheckState NextCheckState(KTreeNode node)
 {
     return((node.CheckState == CheckState.Checked) ? CheckState.Unchecked : CheckState.Checked);
 }
Example #8
0
 protected override void RenderNodeText(Graphics graphics, KTreeNode node, Rectangle rect, KTreeNodeMeasurements.Part?highlight)
 {
     TextRenderer.DrawText(graphics, node.Text, _tree.Font, rect, GetColor(node, highlight), Color.Transparent, TEXT_FLAGS);
 }
Example #9
0
 internal void OnNodeRemoved(KTreeNode parent, KTreeNode node)
 {
     throw new NotImplementedException();
 }
Example #10
0
 protected abstract void RenderNodeText(Graphics graphics, KTreeNode node, Rectangle rect, KTreeNodeMeasurements.Part?highlight);
 public override void Add(KTreeNode node)
 {
     _selectedNode = node;
 }
 public override void Clear()
 {
     _selectedNode = null;
 }
 abstract public void Toggle(KTreeNode node);
 abstract public void Add(KTreeNode node);
Example #15
0
        private void DoSelectNode(KTreeNode node, SelectAction action, ScrollMode scroll)
        {
            if (action == SelectAction.Set || action == SelectAction.Range)
            {
                _selectionManager.Clear();
            }

            if (node != null)
            {
                switch (action)
                {
                case SelectAction.Range:
                case SelectAction.AddRange:
                    if (_selectRangeAnchor == null)
                    {
                        _selectRangeAnchor = node;
                        _selectionManager.Add(node);
                        break;
                    }

                    // Select any nodes from the anchor to the current node
                    int activeIndex = Math.Max(0, _presentNodes.IndexOf(_selectRangeAnchor));
                    int nodeIndex   = _presentNodes.IndexOf(node);
                    // Keep to order just in case the selection manager wants it
                    if (activeIndex > nodeIndex)
                    {
                        for (int i = nodeIndex; i <= activeIndex; ++i)
                        {
                            if (_presentNodes[i].IsSelectable)
                            {
                                _selectionManager.Add(_presentNodes[i]);
                            }
                        }
                    }
                    else
                    {
                        for (int i = activeIndex; i <= nodeIndex; ++i)
                        {
                            if (_presentNodes[i].IsSelectable)
                            {
                                _selectionManager.Add(_presentNodes[i]);
                            }
                        }
                    }
                    break;

                case SelectAction.Set:
                    _selectRangeAnchor = node;
                    _selectionManager.Add(node);
                    break;

                case SelectAction.Toggle:
                    _selectRangeAnchor = node;
                    _selectionManager.Toggle(node);
                    break;
                }

                if (scroll != ScrollMode.None)
                {
                    ScrollIntoView(node, scroll);
                }
            }

            ActiveNode = node;

            // Must rerender
            // TODO: affected nodes only
            Rerender();

            // Raise event if needed
            CheckSelectionChanged();
        }
Example #16
0
 public CheckStateChangedEventArgs(KTreeNode node)
 {
     this.Node = node;
 }
Example #17
0
 protected abstract Size GetExpanderSize(Graphics graphics, KTreeNode node);
Example #18
0
 internal void OnNodeChildrenChanged(KTreeNode node)
 {
     Rerender(node);
 }
Example #19
0
 virtual protected object DoLoadChildren(KTreeNode node)
 {
     return(LoadChildren(node));
 }
Example #20
0
 protected override Size GetExpanderSize(Graphics graphics, KTreeNode node)
 {
     return(_expanderBoxSize);
 }
Example #21
0
 virtual protected void DoRenderChildren(KTreeNode node, object loaded, KTreeNodes children)
 {
     RenderChildren(node, loaded, children);
 }
Example #22
0
 public override void ToggleCheck(KTreeNode node)
 {
     node.CheckState = (CheckState)(((int)node.CheckState + 1) % 3);
 }
Example #23
0
 public KTreeNodeLoaderStatic(KTreeNode owner)
     :
     base(owner)
 {
     State = LoadingState.Loaded;
 }
Example #24
0
 abstract public void SetCheck(KTreeNode node, CheckState state);
Example #25
0
 public KTreeNodeLoader(KTreeNode parent)
 {
     Children = new KTreeNodes(parent);
 }
Example #26
0
 public override void SetCheck(KTreeNode node, CheckState state)
 {
     node.CheckStateDirect = state == CheckState.Checked ? CheckState.Checked : CheckState.Unchecked;
 }
Example #27
0
        public void ScrollIntoView(KTreeNode node, ScrollMode mode)
        {
            if (mode == ScrollMode.None)
            {
                return;
            }

            if (!node.IsVisible)
            {
                //return;
                foreach (KTreeNode parent in node.Ancestors)
                {
                    if (!parent.IsExpanded)
                    {
                        parent.IsExpanded = true;
                    }
                    else
                    {
                        break;
                    }
                }
            }

            // Number of pixels from edge to keep node in Y direction.
            // TODO: this assumes all nodes are the same height
            int scrollBorderY = node.EffectiveDimension.NodeRect.Height;

            // Vertical
            // Do nothing if the node is already fully visible
            if (!ScrolledRectangle.ContainsY(node.EffectiveDimension.NodeRect.Top - scrollBorderY) ||
                !ScrolledRectangle.ContainsY(node.EffectiveDimension.NodeRect.Bottom + scrollBorderY))
            {
                if (mode == ScrollMode.Auto)
                {
                    if (node.EffectiveDimension.NodeRect.Top + scrollBorderY < ScrolledRectangle.Y)
                    {
                        mode = ScrollMode.Top;
                    }
                    else
                    {
                        mode = ScrollMode.Bottom;
                    }
                }

                switch (mode)
                {
                case ScrollMode.Top:
                    SetVScroll(node.EffectiveDimension.NodeRect.Top - ViewRectangle.Top - scrollBorderY);
                    break;

                case ScrollMode.Middle:
                    SetVScroll((node.EffectiveDimension.NodeRect.Top + node.EffectiveDimension.NodeRect.Height / 2) - (ViewRectangle.Top + ViewRectangle.Height / 2));
                    break;

                case ScrollMode.Bottom:
                    SetVScroll(node.EffectiveDimension.NodeRect.Bottom - ViewRectangle.Bottom + scrollBorderY);
                    break;
                }
            }

            // Horizontal
            if (!ScrolledRectangle.ContainsX(node.EffectiveDimension.NodeRect.Left) || !ScrolledRectangle.ContainsX(node.EffectiveDimension.NodeRect.Right))
            {
                // Align left or right, depending on which is the smallest change
                int alignLeft  = node.EffectiveDimension.NodeRect.Left - ViewRectangle.Left;
                int alignRight = node.EffectiveDimension.NodeRect.Right - ViewRectangle.Right;
                if (Math.Abs(alignLeft - _horizontalScrollBar.Value) < Math.Abs(alignRight - _horizontalScrollBar.Value))
                {
                    SetHScroll(alignLeft);
                }
                else
                {
                    SetHScroll(alignRight);
                }
            }

            // Check current highlight
            CheckMouseHighlight();
        }
Example #28
0
 public override void SetCheck(KTreeNode node, CheckState state)
 {
     node.CheckStateDirect = state;
 }
Example #29
0
 /// <summary>
 /// Selects a single node and makes it the active node.
 /// </summary>
 /// <param name="node">The node. Pass null to deselect any nodes</param>
 /// <param name="scroll">Set to a specific mode to scroll the node into view</param>
 public void SelectNode(KTreeNode node, ScrollMode scroll = ScrollMode.None)
 {
     DoSelectNode(node, SelectAction.Set, scroll);
 }