src/Misc/EFTools/DesignXmlCore/VirtualTreeGrid/UI/ColumnHeader.cs
/// <summary>
///     Move changes from the current (permuted) header back into the full header array
/// </summary>
/// <param name="permutation">The current column permutation</param>
/// <param name="autoFillApplied">true if the current headers are variable size because the AutoFillFixedColumns property is true</param>
/// <param name="fullHeaders">The full header array</param>
Move changes from the current (permuted) header back into the full header array
Move changes from the current ( permuted ) header back into the full header array
public void ReverseIntegratePermutedSettings(
                ColumnPermutation permutation, bool autoFillApplied, VirtualTreeColumnHeader[] fullHeaders)
            {
                if ((permutation == null && !autoFillApplied)
                    || ReferenceEquals(myHeaders, fullHeaders))
                {
                    return;
                }
                var headersCount = myHeaders.Length;
                if (HasVariableBounds && !autoFillApplied)
                {
                    var fullCount = fullHeaders.Length;
                    var lastFullPercentage = 0f;
                    var lastPercentageColumn = -1;
                    var basePercentage = 0f;
                    int i;
                    int permutedColumn;
                    float currentPercentage;
                    float incrementalPercentage;
                    for (i = 0; i < fullCount; ++i)
                    {
                        currentPercentage = fullHeaders[i].Percentage;
                        if (currentPercentage != 0f)
                        {
                            incrementalPercentage = currentPercentage - lastFullPercentage;
                            if (permutation.GetPermutedColumn(i) != -1)
                            {
                                basePercentage += incrementalPercentage;
                            }
                            fullHeaders[i].SetPercentage(incrementalPercentage);
                            lastFullPercentage = currentPercentage;
                            lastPercentageColumn = i;
                        }
                        else
                        {
                            permutedColumn = permutation.GetPermutedColumn(i);
                            if (permutedColumn != -1)
                            {
                                fullHeaders[i].SetWidth(myHeaders[permutedColumn].Width);
                            }
                        }
                    }
                    if (basePercentage != 0f)
                    {
                        for (i = 0; i <= lastPercentageColumn; ++i)
                        {
                            if (fullHeaders[i].Percentage != 0f)
                            {
                                permutedColumn = permutation.GetPermutedColumn(i);
                                if (permutedColumn != -1)
                                {
                                    currentPercentage = myHeaders[permutedColumn].Percentage;
                                    lastFullPercentage = 0f;
                                    for (var j = permutedColumn - 1; j >= 0; --j)
                                    {
                                        lastFullPercentage = myHeaders[j].Percentage;
                                        if (lastFullPercentage != 0f)
                                        {
                                            break;
                                        }
                                    }
                                    fullHeaders[i].SetPercentage((currentPercentage - lastFullPercentage) * basePercentage);
                                }
                            }
                        }
                    }
                    if (lastPercentageColumn != -1)
                    {
                        var newPercentage = 0f;
                        for (i = 0; i < lastPercentageColumn; ++i)
                        {
                            currentPercentage = fullHeaders[i].Percentage;
                            if (currentPercentage != 0f)
                            {
                                newPercentage += currentPercentage;
                                fullHeaders[i].SetPercentage(newPercentage);
                            }
                        }
                        fullHeaders[lastPercentageColumn].SetPercentage(1f);
                    }
                }
                else
                {
                    for (var i = 0; i < headersCount; ++i)
                    {
                        fullHeaders[permutation.GetNativeColumn(i)].SetWidth(myHeaders[i].Width);
                    }
                }
            }
public void ReverseIntegratePermutedSettings ( ColumnPermutation permutation , bool autoFillApplied , VirtualTreeColumnHeader [ ] fullHeaders ) { if ( ( permutation == null && ! autoFillApplied ) || ReferenceEquals ( myHeaders , fullHeaders ) ) { return ; } var headersCount = myHeaders . Length ; if ( HasVariableBounds && ! autoFillApplied ) { var fullCount = fullHeaders . Length ; var lastFullPercentage = 0f ; var lastPercentageColumn = - 1 ; var basePercentage = 0f ; int i ; int permutedColumn ; float currentPercentage ; float incrementalPercentage ; for ( i = 0 ; i < fullCount ; ++ i ) { currentPercentage = fullHeaders [ i ] . Percentage ; if ( currentPercentage != 0f ) { incrementalPercentage = currentPercentage - lastFullPercentage ; if ( permutation . GetPermutedColumn ( i ) != - 1 ) { basePercentage += incrementalPercentage ; } fullHeaders [ i ] . SetPercentage ( incrementalPercentage ) ; lastFullPercentage = currentPercentage ; lastPercentageColumn = i ; } else { permutedColumn = permutation . GetPermutedColumn ( i ) ; if ( permutedColumn != - 1 ) { fullHeaders [ i ] . SetWidth ( myHeaders [ permutedColumn ] . Width ) ; } } } if ( basePercentage != 0f ) { for ( i = 0 ; i <= lastPercentageColumn ; ++ i ) { if ( fullHeaders [ i ] . Percentage != 0f ) { permutedColumn = permutation . GetPermutedColumn ( i ) ; if ( permutedColumn != - 1 ) { currentPercentage = myHeaders [ permutedColumn ] . Percentage ; lastFullPercentage = 0f ; for ( var j = permutedColumn - 1 ; j >= 0 ; -- j ) { lastFullPercentage = myHeaders [ j ] . Percentage ; if ( lastFullPercentage != 0f ) { break ; } } fullHeaders [ i ] . SetPercentage ( ( currentPercentage - lastFullPercentage ) * basePercentage ) ; } } } } if ( lastPercentageColumn != - 1 ) { var newPercentage = 0f ; for ( i = 0 ; i < lastPercentageColumn ; ++ i ) { currentPercentage = fullHeaders [ i ] . Percentage ; if ( currentPercentage != 0f ) { newPercentage += currentPercentage ; fullHeaders [ i ] . SetPercentage ( newPercentage ) ; } } fullHeaders [ lastPercentageColumn ] . SetPercentage ( 1f ) ; } } else { for ( var i = 0 ; i < headersCount ; ++ i ) { fullHeaders [ permutation . GetNativeColumn ( i ) ] . SetWidth ( myHeaders [ i ] . Width ) ; } } }
Move changes from the current (permuted) header back into the full header array
Move changes from the current ( permuted ) header back into the full header array
// This is the complicated case. We need to get the current percentages of // the visible proportional columns from the full headers and then use the sum // of those as the base percentage for integrating the other items back in. // To facilitate this effort, we also switch the full header percentages to // an incremental percentage instead of an ascending percentage and then switch // them back later on. // Switch the full headers to incremental. Update the fixed width columns while // we're going through the loop. // Fixed width column, need to update at some point, might as well do it now // Integrate the new settings into the full headers // See if the column is displayed // Grab the current percentage // Find the previous proportional column, if any. // Set the new incremental percentage in the full headers array // Switch the full headers back to ascending percentages // The header percentages now contain an incremental percentage, not the total // percentage they should hold. Walk down the list and fix this. // Just set all of them. This will be a noop for the proportional columns, // it isn't worth detecting the case.
permutation
ColumnPermutation
The current column permutation
The current column permutation
autoFillApplied
bool
true if the current headers are variable size because the AutoFillFixedColumns property is true
true if the current headers are variable size because the AutoFillFixedColumns property is true
fullHeaders
VirtualTreeColumnHeader[]
The full header array
The full header array