Example #1
0
        private VirtualTreeItemInfo GetItemInfo(ref ITEMPOSITION pos, int column, bool setFlags, bool ignoreMultiColumn, bool lastSubItem)
        {
            var info = new VirtualTreeItemInfo(pos.ParentNode.Branch, pos.Index, column, pos.Level);
            var blankItem = ignoreMultiColumn ? false : pos.IsBlank(column);
            info.Blank = blankItem;

            if (setFlags)
            {
                if (!ignoreMultiColumn && MultiColumnSupport)
                {
                    TREENODE tnChild;
                    if (blankItem)
                    {
                        if (column >= pos.ParentNode.GetColumnCount(pos.Index))
                        {
                            // If the item is after all supported columns then
                            // just let it draw blank by leaving all flags clear.
                            info.ClearLevel();
                        }
                        else
                        {
                            Debug.Assert(pos.SubItemOffset > 0);
                            tnChild = pos.ParentNode.GetChildNode(pos.Index);
                            Debug.Assert(tnChild != null); // Can't get a subitem offset without a node
                            if (column == 0)
                            {
                                // A blank item in the first column
                                info.TrailingItem = pos.SubItemOffset == tnChild.ImmedSubItemGain;
                                info.LastBranchItem = (pos.Index + 1) == pos.ParentNode.ImmedCount;
                                info.FirstBranchItem = pos.Index == 0;
                                info.Expanded = tnChild.Expanded && (tnChild.ImmedCount > 0);
                                    // Required information to draw lines down to expanded item
                            }
                            else
                            {
                                // A blank item in subitem column
                                info.ClearLevel();
                                info.TrailingItem = pos.SubItemOffset == tnChild.ImmedSubItemGain;
                            }
                        }
                    } // if (blankItem)
                    else if (!pos.ParentNode.MultiColumn)
                    {
                        info.Expanded = pos.IsExpanded(column);
                        info.Expandable = info.Expanded || pos.IsExpandable(column);
                        info.FirstBranchItem = pos.Index == 0;
                        info.LastBranchItem = pos.ParentNode.Branch.VisibleItemCount == (pos.Index + 1);
                        if (pos.ParentNode.InSubItemColumn)
                        {
                            info.LeadingItem = info.FirstBranchItem && pos.ParentNode.ComplexSubItem;
                            info.TrailingItem = lastSubItem;
                            info.SimpleCell = info.Level == 0 && pos.ParentNode.NoChildExpansion;
                        }
                        else
                        {
                            info.TrailingItem = info.LeadingItem = true;
                        }
                    }
                    else if (column == 0)
                    {
                        info.LeadingItem = true;
                        info.FirstBranchItem = pos.Index == 0;
                        info.LastBranchItem = (pos.Index + 1) == pos.ParentNode.ImmedCount;
                        tnChild = pos.ParentNode.GetChildNode(pos.Index);
                        if (tnChild == null)
                        {
                            info.TrailingItem = true;
                            info.Expandable = pos.IsExpandable(0); //column == 0
                        }
                        else
                        {
                            info.TrailingItem = tnChild.ImmedSubItemGain == 0;
                            info.Expanded = pos.IsExpanded(0); // column == 0
                            info.Expandable = info.Expanded || pos.IsExpandable(0);
                        }
                        info.SimpleCell = info.Level == 0 && pos.ParentNode.NoChildExpansion;
                    } // else if (column == 0)
                    else
                    {
                        info.LeadingItem = info.FirstBranchItem = true;
                        info.LastBranchItem = true;
                        tnChild = pos.ParentNode.GetChildNode(pos.Index);
                        if (tnChild != null)
                        {
                            info.TrailingItem = tnChild.ImmedSubItemGain == 0;
                        }
                        else
                        {
                            info.TrailingItem = true;
                        }
                        info.Expanded = pos.IsExpanded(column);
                        info.Expandable = info.Expanded || pos.IsExpandable(column);
                        info.SimpleCell = info.Level == 0 && !info.Expandable;
                    } // else
                } // if (MultiColumnSupport)
                else
                {
                    Debug.Assert(column == 0);
                    if (!blankItem)
                    {
                        info.Expanded = pos.IsExpanded(column);
                        info.Expandable = info.Expanded ? true : pos.IsExpandable(column);
                    }
                    info.FirstBranchItem = pos.Index == 0;
                    info.LastBranchItem = pos.ParentNode.Branch.VisibleItemCount == (pos.Index + 1);
                    info.LeadingItem = info.TrailingItem = true;
                } // else
            }
            return info;
        }