src/Misc/EFTools/DesignXmlCore/VirtualTreeGrid/Provider/VirtualTree.cs
/// <summary>
///     Attempt to expand complex sub items in a multi-column branch. Called
///     immediately after a new node is created.
/// </summary>
/// <param name="tn">The node for the parent branch</param>
/// <param name="totalIncrease">The cumulative subitem gain</param>
Attempt to expand complex sub items in a multi-column branch. Called
immediately after a new node is created.
Attempt to expand complex sub items in a multi - column branch . Called immediately after a new node is created .
private void ExpandInitialComplexSubItems(TREENODE_Multi tn, out int totalIncrease)
        {
            Debug.Assert(tn.FirstChild == null);
            Debug.Assert(tn.ComplexColumns); 
            var mcBranch = tn.Branch as IMultiColumnBranch;
            var columnCount = (mcBranch == null) ? 1 : mcBranch.ColumnCount;
            totalIncrease = 0;
            if (columnCount > 1)
            {
                int iCol;
                var complexColumnCount = 0;
                for (iCol = 1; iCol < columnCount; ++iCol)
                {
                    if (0 != (tn.SubItemStyle(iCol) & SubItemCellStyles.Complex))
                    {
                        ++complexColumnCount;
                    }
                }
                if (complexColumnCount > 0)
                {
                    var complexColumns = new int[complexColumnCount];
                    var jaggedColumns = tn.JaggedColumns;
                    var maxRow = tn.FullCount;
                    var maxColumn = columnCount - 1;
                    int iRow;
                    int itemIncr;
                    int subItemIncr;
                    TREENODE tnSubItemAnchor;
                    TREENODE tnSubItem;
                    TREENODE tnPrevHint;
                    SUBITEMNODE snPrev;
                    SUBITEMNODE sn;
                    complexColumnCount = 0;
                    ExpansionOptions options;
                    for (iCol = 1; iCol < columnCount; ++iCol)
                    {
                        if (0 != (tn.SubItemStyle(iCol) & SubItemCellStyles.Complex))
                        {
                            complexColumns[complexColumnCount] = iCol;
                            ++complexColumnCount;
                        }
                    }
                    tnPrevHint = null;
                    Debug.Assert(tn.FirstChild == null); 
                    for (iRow = 0; iRow < maxRow; ++iRow)
                    {
                        snPrev = null;
                        tnSubItemAnchor = null;
                        if (jaggedColumns)
                        {
                            maxColumn = mcBranch.GetJaggedColumnCount(iRow) - 1;
                        }
                        for (iCol = 0; iCol < complexColumnCount; ++iCol)
                        {
                            if (jaggedColumns && complexColumns[iCol] > maxColumn)
                            {
                                break;
                            }
                            options = 0;
                            tnSubItem = ExpandTreeNode(
                                tn,
                                null,
                                iRow,
                                complexColumns[iCol],
                                ObjectStyle.SubItemRootBranch,
                                false,
                                out options,
                                out itemIncr,
                                out subItemIncr);
                            if (tnSubItem != null)
                            {
                                if (snPrev == null)
                                {
                                    tnSubItemAnchor = new TREENODE_Complex();
                                    tnSubItemAnchor.Index = iRow;
                                    InsertIndexedNode(tn, tnSubItemAnchor, ref tnPrevHint);
                                }
                                tnSubItem.SubItemRoot = true;
                                if (0 == (options & ExpansionOptions.UseAsSubItemExpansion))
                                {
                                    tnSubItem.ComplexSubItem = true;
                                }
                                tnSubItem.Index = VirtualTreeConstant.NullIndex;
                                tnSubItem.Parent = tnSubItemAnchor;
                                sn = new SUBITEMNODE();
                                sn.Column = complexColumns[iCol];
                                sn.RootNode = tnSubItem;
                                if (snPrev == null)
                                {
                                    sn.NextSibling = tnSubItemAnchor.FirstSubItem;
                                    tnSubItemAnchor.FirstSubItem = sn;
                                }
                                else
                                {
                                    sn.NextSibling = snPrev.NextSibling;
                                    snPrev.NextSibling = sn;
                                }
                                snPrev = sn;
                            }
                            if (tnSubItemAnchor != null)
                            {
                                var adjustment = tnSubItemAnchor.AdjustSubItemGain();
                                tnSubItemAnchor.FullSubItemGain += adjustment;
                                totalIncrease += adjustment;
                            }
                        }
                    }
                }
            }
        }
private void ExpandInitialComplexSubItems ( TREENODE_Multi tn , out int totalIncrease ) { Debug . Assert ( tn . FirstChild == null ) ; Debug . Assert ( tn . ComplexColumns ) ; var mcBranch = tn . Branch as IMultiColumnBranch ; var columnCount = ( mcBranch == null ) ? 1 : mcBranch . ColumnCount ; totalIncrease = 0 ; if ( columnCount > 1 ) { int iCol ; var complexColumnCount = 0 ; for ( iCol = 1 ; iCol < columnCount ; ++ iCol ) { if ( 0 != ( tn . SubItemStyle ( iCol ) & SubItemCellStyles . Complex ) ) { ++ complexColumnCount ; } } if ( complexColumnCount > 0 ) { var complexColumns = new int [ complexColumnCount ] ; var jaggedColumns = tn . JaggedColumns ; var maxRow = tn . FullCount ; var maxColumn = columnCount - 1 ; int iRow ; int itemIncr ; int subItemIncr ; TREENODE tnSubItemAnchor ; TREENODE tnSubItem ; TREENODE tnPrevHint ; SUBITEMNODE snPrev ; SUBITEMNODE sn ; complexColumnCount = 0 ; ExpansionOptions options ; for ( iCol = 1 ; iCol < columnCount ; ++ iCol ) { if ( 0 != ( tn . SubItemStyle ( iCol ) & SubItemCellStyles . Complex ) ) { complexColumns [ complexColumnCount ] = iCol ; ++ complexColumnCount ; } } tnPrevHint = null ; Debug . Assert ( tn . FirstChild == null ) ; for ( iRow = 0 ; iRow < maxRow ; ++ iRow ) { snPrev = null ; tnSubItemAnchor = null ; if ( jaggedColumns ) { maxColumn = mcBranch . GetJaggedColumnCount ( iRow ) - 1 ; } for ( iCol = 0 ; iCol < complexColumnCount ; ++ iCol ) { if ( jaggedColumns && complexColumns [ iCol ] > maxColumn ) { break ; } options = 0 ; tnSubItem = ExpandTreeNode ( tn , null , iRow , complexColumns [ iCol ] , ObjectStyle . SubItemRootBranch , false , out options , out itemIncr , out subItemIncr ) ; if ( tnSubItem != null ) { if ( snPrev == null ) { tnSubItemAnchor = new TREENODE_Complex ( ) ; tnSubItemAnchor . Index = iRow ; InsertIndexedNode ( tn , tnSubItemAnchor , ref tnPrevHint ) ; } tnSubItem . SubItemRoot = true ; if ( 0 == ( options & ExpansionOptions . UseAsSubItemExpansion ) ) { tnSubItem . ComplexSubItem = true ; } tnSubItem . Index = VirtualTreeConstant . NullIndex ; tnSubItem . Parent = tnSubItemAnchor ; sn = new SUBITEMNODE ( ) ; sn . Column = complexColumns [ iCol ] ; sn . RootNode = tnSubItem ; if ( snPrev == null ) { sn . NextSibling = tnSubItemAnchor . FirstSubItem ; tnSubItemAnchor . FirstSubItem = sn ; } else { sn . NextSibling = snPrev . NextSibling ; snPrev . NextSibling = sn ; } snPrev = sn ; } if ( tnSubItemAnchor != null ) { var adjustment = tnSubItemAnchor . AdjustSubItemGain ( ) ; tnSubItemAnchor . FullSubItemGain += adjustment ; totalIncrease += adjustment ; } } } } } }
Attempt to expand complex sub items in a multi-column branch.
Attempt to expand complex sub items in a multi - column branch .
// The algorithm will walk sequentially through the branch and // create a new tree node for each row. We walk all columns // in a given row to make it easier to build the TREENODE list // attached to the parent. // Check before calling // Get an array with the complex columns // Walk the columns that matter and link up the returned tree nodes // This is initial expansion only // First node for this row, go ahead and create a dummy node // TREENODE_Complex is the lowest common denominator // that supports multi column expansion. This node may // be upgraded later if an expansion is actually made // on this item. // UNDONE_MC: Might want to insert last so there are no lasting side effects in case of failure // UNDONE_MC: Should we store the column in the blank index field of the root // instead of in the SUBITEMNODE? This would save calculating the column with // SUBITEMNODE.ColumnOfRootNode when we need it.
tn
TREENODE_Multi
The node for the parent branch
The node for the parent branch
int
out
totalIncrease
The cumulative subitem gain
The cumulative subitem gain