src/Misc/EFTools/DesignXmlCore/VirtualTreeGrid/Provider/VirtualTree.cs
/// <summary>
///     Remove all occurrences of branch from the tree. Note that removing all
///     items from a branch is not the same as removing the branch itself.
/// </summary>
/// <param name="branch">The branch to remove</param>
Remove all occurrences of branch from the tree. Note that removing all
items from a branch is not the same as removing the branch itself.
Remove all occurrences of branch from the tree . Note that removing all items from a branch is not the same as removing the branch itself .
[SuppressMessage("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily")]
        protected void RemoveBranch(IBranch branch)
        {
            var tnNextNode = LocateTrackedNode(branch);
            TREENODE tn;
            Debug.Assert(tnNextNode != null); 
            int killCount;
            int subItemKillCount;
            var enableSingleColumnEvent = GetStateFlag(TreeStateFlags.FireSingleColumnItemCountChanged)
                                          | GetStateFlag(TreeStateFlags.FireSingleColumnOnDisplayDataChanged);
            var enableNormalEvent = ItemCountChanged != null || OnDisplayDataChanged != null;
            var notify = enableNormalEvent || enableSingleColumnEvent;
            while (null != (tn = tnNextNode))
            {
                Debug.Assert(!tn.ComplexSubItem); 
                var absIndex = -1;
                var singleColumnAbsIndex = -1;
                var notifyColumn = 0;
                tnNextNode = tn.NextNode;
                if (notify)
                {
                    var tnNext = tn;
                    var coord = EnumAbsoluteIndices(VirtualTreeConstant.NullIndex, ref tnNext, out singleColumnAbsIndex);
                    if (coord.IsValid)
                    {
                        absIndex = coord.Row;
                        notifyColumn = coord.Column;
                    }
                }
                killCount = subItemKillCount = 0;
                if (tn.Expanded)
                {
                    killCount = tn.FullCount;
                    subItemKillCount = tn.ExpandedSubItemGain;
                    if ((killCount + subItemKillCount) > 0)
                    {
                        ChangeFullCountRecursive(tn, -killCount, -subItemKillCount);
                    }
                }
                var tnTemp = tn.Parent;
                if (tnTemp != null)
                {
                    if (tn.FirstSubItem == null)
                    {
                        if (tn == tnTemp.FirstChild)
                        {
                            tnTemp.FirstChild = tn.NextSibling;
                        }
                        else
                        {
                            tnTemp = tnTemp.FirstChild;
                            while (tnTemp.NextSibling != tn)
                            {
                                tnTemp = tnTemp.NextSibling;
                            }
                            tnTemp.NextSibling = tn.NextSibling;
                        }
                        FreeRecursive(ref tn);
                    }
                    else
                    {
                        var tnNext = tn.FirstChild;
                        while (null != (tnTemp = tnNext))
                        {
                            tnNext = tnTemp.NextSibling;
                            FreeRecursive(ref tnTemp);
                        }
                        tn.FirstChild = null;
                        tn.Expanded = false;
                    }
                }
                else
                {
                    Debug.Assert(myRootNode != null && myRootNode.Branch == branch);
                    (this as ITree).Root = null;
                    break;
                }
                if (notify)
                {
                    if (enableNormalEvent && absIndex != -1)
                    {
                        if ((killCount + subItemKillCount) == 0)
                        {
                            if (OnDisplayDataChanged != null)
                            {
                                OnDisplayDataChanged(
                                    this,
                                    new DisplayDataChangedEventArgs(
                                        this, VirtualTreeDisplayDataChanges.VisibleElements, absIndex, notifyColumn, 1));
                            }
                        }
                        else if (ItemCountChanged != null)
                        {
                            DelayTurnOffRedraw();
                            ItemCountChanged(
                                this,
                                new ItemCountChangedEventArgs(
                                    this, absIndex, notifyColumn, -killCount - subItemKillCount, absIndex, 0, null, true));
                        }
                    }
                    if (enableSingleColumnEvent && singleColumnAbsIndex != -1)
                    {
                        var singleTree = SingleColumnTree;
                        if (killCount == 0)
                        {
                            if (GetStateFlag(TreeStateFlags.FireSingleColumnOnDisplayDataChanged))
                            {
                                (singleTree as SingleColumnView).myOnDisplayDataChanged(
                                    singleTree,
                                    new DisplayDataChangedEventArgs(
                                        singleTree, VirtualTreeDisplayDataChanges.VisibleElements, singleColumnAbsIndex, 0, 1));
                            }
                        }
                        else if (GetStateFlag(TreeStateFlags.FireSingleColumnItemCountChanged))
                        {
                            DelayTurnOffSingleColumnRedraw();
                            (singleTree as SingleColumnView).myItemCountChanged(
                                singleTree,
                                new ItemCountChangedEventArgs(
                                    singleTree, singleColumnAbsIndex, 0, -killCount, singleColumnAbsIndex, 0, null, true));
                        }
                    }
                }
            }
            ClearPositionCache(); 
        }
[ SuppressMessage ( " " , " " ) ] protected void RemoveBranch ( IBranch branch ) { var tnNextNode = LocateTrackedNode ( branch ) ; TREENODE tn ; Debug . Assert ( tnNextNode != null ) ; int killCount ; int subItemKillCount ; var enableSingleColumnEvent = GetStateFlag ( TreeStateFlags . FireSingleColumnItemCountChanged ) | GetStateFlag ( TreeStateFlags . FireSingleColumnOnDisplayDataChanged ) ; var enableNormalEvent = ItemCountChanged != null || OnDisplayDataChanged != null ; var notify = enableNormalEvent || enableSingleColumnEvent ; while ( null != ( tn = tnNextNode ) ) { Debug . Assert ( ! tn . ComplexSubItem ) ; var absIndex = - 1 ; var singleColumnAbsIndex = - 1 ; var notifyColumn = 0 ; tnNextNode = tn . NextNode ; if ( notify ) { var tnNext = tn ; var coord = EnumAbsoluteIndices ( VirtualTreeConstant . NullIndex , ref tnNext , out singleColumnAbsIndex ) ; if ( coord . IsValid ) { absIndex = coord . Row ; notifyColumn = coord . Column ; } } killCount = subItemKillCount = 0 ; if ( tn . Expanded ) { killCount = tn . FullCount ; subItemKillCount = tn . ExpandedSubItemGain ; if ( ( killCount + subItemKillCount ) > 0 ) { ChangeFullCountRecursive ( tn , - killCount , - subItemKillCount ) ; } } var tnTemp = tn . Parent ; if ( tnTemp != null ) { if ( tn . FirstSubItem == null ) { if ( tn == tnTemp . FirstChild ) { tnTemp . FirstChild = tn . NextSibling ; } else { tnTemp = tnTemp . FirstChild ; while ( tnTemp . NextSibling != tn ) { tnTemp = tnTemp . NextSibling ; } tnTemp . NextSibling = tn . NextSibling ; } FreeRecursive ( ref tn ) ; } else { var tnNext = tn . FirstChild ; while ( null != ( tnTemp = tnNext ) ) { tnNext = tnTemp . NextSibling ; FreeRecursive ( ref tnTemp ) ; } tn . FirstChild = null ; tn . Expanded = false ; } } else { Debug . Assert ( myRootNode != null && myRootNode . Branch == branch ) ; ( this as ITree ) . Root = null ; break ; } if ( notify ) { if ( enableNormalEvent && absIndex != - 1 ) { if ( ( killCount + subItemKillCount ) == 0 ) { if ( OnDisplayDataChanged != null ) { OnDisplayDataChanged ( this , new DisplayDataChangedEventArgs ( this , VirtualTreeDisplayDataChanges . VisibleElements , absIndex , notifyColumn , 1 ) ) ; } } else if ( ItemCountChanged != null ) { DelayTurnOffRedraw ( ) ; ItemCountChanged ( this , new ItemCountChangedEventArgs ( this , absIndex , notifyColumn , - killCount - subItemKillCount , absIndex , 0 , null , true ) ) ; } } if ( enableSingleColumnEvent && singleColumnAbsIndex != - 1 ) { var singleTree = SingleColumnTree ; if ( killCount == 0 ) { if ( GetStateFlag ( TreeStateFlags . FireSingleColumnOnDisplayDataChanged ) ) { ( singleTree as SingleColumnView ) . myOnDisplayDataChanged ( singleTree , new DisplayDataChangedEventArgs ( singleTree , VirtualTreeDisplayDataChanges . VisibleElements , singleColumnAbsIndex , 0 , 1 ) ) ; } } else if ( GetStateFlag ( TreeStateFlags . FireSingleColumnItemCountChanged ) ) { DelayTurnOffSingleColumnRedraw ( ) ; ( singleTree as SingleColumnView ) . myItemCountChanged ( singleTree , new ItemCountChangedEventArgs ( singleTree , singleColumnAbsIndex , 0 , - killCount , singleColumnAbsIndex , 0 , null , true ) ) ; } } } } ClearPositionCache ( ) ; }
Remove all occurrences of branch from the tree.
Remove all occurrences of branch from the tree .
//Expect LocateTrackedNode to throw otherwise // Not handled, UNDONE_MC // We need to get the notification index before deleting anything // UNDONE_MC: Need broader method call to catch all subitem cases // UNDONE_MC: See comments in InsertItems. Fold the notifications // for the three size changes into one, and get enough info // back to do multi column. For example, the ComplexSubItem check // in this if statement is equivalent to the output rowIncr parameter // from the more complex ChangeFullCountRecursive call. // UNDONE_NOW: //ItemsDeleted(this, absIndex, killCount); //Cached absolute information is toast.
branch
IBranch
The branch to remove
The branch to remove