Пример #1
0
        private void ProcessViewNodeRemoving(JetListViewNode node)
        {
            if (node.Level == 0)
            {
                string          nodeGroup       = _groupProvider.GetGroupName(node.Data);
                GroupHeaderNode nodeGroupHeader = (GroupHeaderNode)_groupMap [nodeGroup];
                if (nodeGroupHeader != null)
                {
                    bool haveSameGroup = false;
                    int  index         = _nodeCollection.Root.IndexOf(node);
                    if (index > 0)
                    {
                        JetListViewNode prevNode = _nodeCollection.Root.Nodes [index - 1];
                        if (_groupProvider.GetGroupName(prevNode.Data) == nodeGroup)
                        {
                            haveSameGroup = true;
                        }
                    }
                    if (!haveSameGroup && index < _nodeCollection.Root.ChildCount - 1)
                    {
                        JetListViewNode nextNode = _nodeCollection.Root.Nodes [index + 1];
                        if (_groupProvider.GetGroupName(nextNode.Data) == nodeGroup)
                        {
                            haveSameGroup = true;
                        }
                    }

                    if (!haveSameGroup)
                    {
                        RemoveGroup(nodeGroupHeader);
                    }
                }
            }
        }
Пример #2
0
        public IVisibleNodeEnumerator GetDirectionalEnumerator(IViewNode startNode, MoveDirection direction)
        {
            Guard.NullArgument(startNode, "startNode");
            JetListViewNode startLvNode = startNode as JetListViewNode;

            if (startLvNode != null)
            {
                return(new GroupedItemEnumerator(this,
                                                 _nodeCollection.GetDirectionalEnumerator(startLvNode, direction), direction,
                                                 (direction == MoveDirection.Down)));
            }

            GroupHeaderNode startHeaderNode = startNode as GroupHeaderNode;

            Debug.Assert(startHeaderNode.TopNode != null);
            if (startHeaderNode.TopNode == null)
            {
                return(new GroupedItemEnumerator(this, new EmptyEnumerator(), direction, false));
            }

            GroupedItemEnumerator enumerator = new GroupedItemEnumerator(this,
                                                                         _nodeCollection.GetDirectionalEnumerator(startHeaderNode.TopNode, direction),
                                                                         direction, false);

            if (direction == MoveDirection.Up)
            {
                // move from first node of current group to last node of previous group
                enumerator.MoveNext();
            }
            return(enumerator);
        }
Пример #3
0
        private void DrawGroupRow(Graphics g, Rectangle rectangle, GroupHeaderNode node, ref int curY)
        {
            Rectangle rcHeader = new Rectangle(rectangle.Left, curY, rectangle.Width, _groupRenderer.GroupHeaderHeight);

            _groupRenderer.DrawGroupHeader(g, rcHeader, node, GetRowState(node));
            curY += rcHeader.Height;
        }
Пример #4
0
 private void HandleNodeChanged(object sender, JetListViewNodeEventArgs e)
 {
     if (e.Node.Level == 0)
     {
         GroupHeaderNode groupHeader = GetNodeGroupHeader(e.Node);
         int             headerIndex = _groupMap.IndexOfValue(groupHeader);
         if (headerIndex > 0)
         {
             GroupHeaderNode prevGroup = (GroupHeaderNode)_groupMap.GetByIndex(headerIndex - 1);
             if (prevGroup.TopNode == e.Node)
             {
                 RemoveGroup(prevGroup);
                 return;
             }
         }
         if (headerIndex < _groupMap.Count - 1)
         {
             GroupHeaderNode nextGroup = (GroupHeaderNode)_groupMap.GetByIndex(headerIndex + 1);
             if (nextGroup.TopNode == e.Node)
             {
                 RemoveGroup(nextGroup);
                 return;
             }
         }
     }
 }
Пример #5
0
        public MoveDirection GetMoveDirection(IViewNode startNode, IViewNode endNode)
        {
            JetListViewNode startLvNode = startNode as JetListViewNode;

            if (startLvNode == null)
            {
                GroupHeaderNode startHeaderNode = (GroupHeaderNode)startNode;
                startLvNode = startHeaderNode.TopNode;
            }

            JetListViewNode endLvNode = endNode as JetListViewNode;

            if (endLvNode == null)
            {
                GroupHeaderNode endHeaderNode = (GroupHeaderNode)endNode;
                endLvNode = endHeaderNode.TopNode;
            }

            int orderDiff = _nodeCollection.CompareVisibleOrder(startLvNode, endLvNode);

            if (orderDiff == 0 && startNode is GroupHeaderNode && !(endNode is GroupHeaderNode))
            {
                return(MoveDirection.Down);
            }
            return((orderDiff < 0)
                    ? MoveDirection.Down
                    : MoveDirection.Up);
        }
Пример #6
0
 private void OnGroupRemoved(GroupHeaderNode header)
 {
     if (GroupRemoved != null)
     {
         GroupRemoved(this, new GroupEventArgs(header));
     }
 }
Пример #7
0
        public void EnsureNodeVisible(IViewNode node)
        {
            JetListViewNode lvNode = node as JetListViewNode;

            if (lvNode != null)
            {
                _nodeCollection.ExpandParents(lvNode);
                GroupHeaderNode group = GetNodeGroupHeader(lvNode);
                group.Expanded = true;
            }
        }
Пример #8
0
 private IViewNode GetNodeOrCollapsedHeader(JetListViewNode viewNode)
 {
     if (viewNode != null)
     {
         GroupHeaderNode headerNode = GetNodeGroupHeader(viewNode);
         if (!headerNode.Expanded)
         {
             return(headerNode);
         }
     }
     return(viewNode);
 }
Пример #9
0
        public GroupHeaderNode GetGroupHeader(string group)
        {
            GroupHeaderNode node = (GroupHeaderNode)_groupMap [group];

            if (node == null)
            {
                node = new GroupHeaderNode(this, group);
                _groupMap [group] = node;
                OnGroupAdded(node);
            }
            return(node);
        }
Пример #10
0
        public bool HandleMouseDown(GroupHeaderNode node, int x, int y, MouseButtons button, Keys modifiers)
        {
            Rectangle rcIcon = new Rectangle(0, 0, GroupHeaderHeight, GroupHeaderHeight);

            rcIcon.Inflate(-2, -2);
            if (rcIcon.Contains(x, y))
            {
                node.Expanded = !node.Expanded;
                return(true);
            }
            return(false);
        }
Пример #11
0
 public bool HandleGroupKeyDown(GroupHeaderNode node, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.Add || e.KeyCode == Keys.Right)
     {
         node.Expanded = true;
         return(true);
     }
     if (e.KeyCode == Keys.Subtract || e.KeyCode == Keys.Left)
     {
         node.Expanded = false;
         return(true);
     }
     return(false);
 }
Пример #12
0
 internal void OnGroupExpandChanged(GroupHeaderNode headerNode)
 {
     if (GroupExpandChanged != null)
     {
         GroupExpandChanged(this, new GroupEventArgs(headerNode));
     }
     if (!headerNode.Expanded)
     {
         if (NodesCollapsed != null)
         {
             NodesCollapsed(this, EventArgs.Empty);
         }
     }
 }
Пример #13
0
        public IViewNode GetVisibleParent(IViewNode node)
        {
            if (node is GroupHeaderNode)
            {
                return(node);
            }
            JetListViewNode lvNode     = node as JetListViewNode;
            GroupHeaderNode headerNode = GetNodeGroupHeader(lvNode);

            if (!headerNode.Expanded)
            {
                return(headerNode);
            }
            return(_nodeCollection.GetVisibleParent(lvNode));
        }
Пример #14
0
        private int GetRowHeight(IViewNode node)
        {
            GroupHeaderNode headerNode = node as GroupHeaderNode;

            if (headerNode != null)
            {
                return(_groupRenderer.GroupHeaderHeight);
            }
            else
            {
                int height = _rowRenderer.GetRowHeight((JetListViewNode)node);
                if (_rowDelimiters)
                {
                    height++;
                }
                return(height);
            }
        }
Пример #15
0
        public void DrawGroupHeader(Graphics g, Rectangle rc, GroupHeaderNode node, RowState rowState)
        {
            Rectangle rcFill = rc;

            rcFill.Height--;
            Color textColor;

            if ((rowState & RowState.ActiveSelected) != 0)
            {
                g.FillRectangle(SystemBrushes.Highlight, rcFill);
                textColor = SystemColors.HighlightText;
            }
            else
            {
                using (Brush b = new SolidBrush(_groupHeaderColor))
                {
                    g.FillRectangle(b, rcFill);
                }
                textColor = SystemColors.ControlText;
            }

            Rectangle rcIcon = new Rectangle(0, rc.Top, GroupHeaderHeight, GroupHeaderHeight);

            rcIcon.Inflate(-2, -2);
            _controlPainter.DrawTreeIcon(g, rcIcon, node.Expanded);

            Rectangle rcText = new Rectangle(20, rc.Top, _visibleWidth - 20, rc.Height);

            StringFormat fmt = new StringFormat();

            fmt.FormatFlags   = StringFormatFlags.NoWrap;
            fmt.LineAlignment = StringAlignment.Center;
            _controlPainter.DrawText(g, node.Text, _headerFont, textColor, rcText, fmt);

            if ((rowState & RowState.Focused) != 0)
            {
                _controlPainter.DrawFocusRect(g, new Rectangle(0, rc.Top, _visibleWidth, rc.Height));
            }
        }
Пример #16
0
        public void Draw(Graphics g, Rectangle rectangle)
        {
            lock ( _nodeCollection )
            {
                IViewNode topNode = _topNode;
                if (topNode != null)
                {
                    int         curY       = -_topNodeOffset + _borderSize;
                    IEnumerator enumerator = GetRowEnumerator(topNode);
                    while (enumerator.MoveNext())
                    {
                        int             oldVer    = _nodeCollection.Version;
                        GroupHeaderNode groupNode = enumerator.Current as GroupHeaderNode;
                        if (groupNode != null)
                        {
                            DrawGroupRow(g, rectangle, groupNode, ref curY);
                        }
                        else
                        {
                            JetListViewNode itemNode = (JetListViewNode)enumerator.Current;
                            DrawNodeRow(g, rectangle, itemNode, ref curY);
                        }

                        // some column draw methods may have caused events to be pumped or modified
                        // the collection - if it has changed, abort the draw and start again
                        if (oldVer != _nodeCollection.Version)
                        {
                            InvalidateBelow(0);
                            break;
                        }
                        if (curY >= rectangle.Bottom)
                        {
                            break;
                        }
                    }
                }
            }
        }
Пример #17
0
 private void RemoveGroup(GroupHeaderNode nodeGroupHeader)
 {
     OnViewNodeRemoving(nodeGroupHeader);
     _groupMap.Remove(nodeGroupHeader.Text);
     OnGroupRemoved(nodeGroupHeader);
 }
Пример #18
0
        public bool MoveNext()
        {
            if (_onHeaderNode)
            {
                if (_moveDirection == MoveDirection.Up)
                {
                    if (_lastHeaderNode)
                    {
                        return(false);
                    }
                    JetListViewNode groupNode = (JetListViewNode)_baseEnumerator.Current;
                    string          newGroup  = _groupCollection.GroupProvider.GetGroupName(groupNode.Data);
                    if (newGroup == null)
                    {
                        throw new InvalidOperationException("Group provider returned null group name for object " + groupNode.Data);
                    }
                    _curHeaderNode = _groupCollection.GetGroupHeader(newGroup);
                }
                if (_curHeaderNode.Expanded)
                {
                    _onHeaderNode = false;
                    return(true);
                }

                if (!SkipCollapsedGroup())
                {
                    if (_moveDirection == MoveDirection.Up)
                    {
                        _lastHeaderNode = true;
                        return(true);
                    }
                    return(false);
                }
            }
            else
            {
                if (!_baseEnumerator.MoveNext())
                {
                    if (_moveDirection == MoveDirection.Up)
                    {
                        _onHeaderNode   = true;
                        _lastHeaderNode = true;
                        return(true);
                    }
                    return(false);
                }
            }

            JetListViewNode curNode       = (JetListViewNode)_baseEnumerator.Current;
            GroupHeaderNode newHeaderNode = _groupCollection.GetNodeGroupHeader(curNode);

            if (newHeaderNode != _curHeaderNode)
            {
                if (_curHeaderNode == null && _moveDirection == MoveDirection.Up)
                {
                    _curHeaderNode = newHeaderNode;
                }
                else
                {
                    if (_moveDirection == MoveDirection.Down)
                    {
                        _curHeaderNode = newHeaderNode;
                        // if we're enumerating from middle of a group, we can't overwrite topNode
                        if (!_skipFirstGroupHeader || _curHeaderNode.TopNode == null)
                        {
                            _curHeaderNode.TopNode = curNode;
                        }
                    }
                    if (_skipFirstGroupHeader)
                    {
                        _skipFirstGroupHeader = false;
                    }
                    else
                    {
                        _onHeaderNode = true;
                    }
                }
            }

            return(true);
        }
Пример #19
0
 public GroupEventArgs(GroupHeaderNode header)
 {
     _groupHeader = header;
 }