Index: inc/patattr.hxx =================================================================== --- inc/patattr.hxx (revision 1515688) +++ inc/patattr.hxx (working copy) @@ -19,8 +19,6 @@ * *************************************************************/ - - #ifndef SC_SCPATATR_HXX #define SC_SCPATATR_HXX @@ -38,7 +36,6 @@ class SvNumberFormatter; class ScDocument; - // how to treat COL_AUTO in GetFont: enum ScAutoFontColorMode @@ -125,6 +122,7 @@ sal_Bool IsVisible() const; sal_Bool IsVisibleEqual( const ScPatternAttr& rOther ) const; + sal_Bool IsEqual( const ScPatternAttr& rOther ) const; /** If font is an old symbol font StarBats/StarMath with text encoding RTL_TEXTENC_SYMBOL */ Index: source/core/data/attarray.cxx =================================================================== --- source/core/data/attarray.cxx (revision 1515688) +++ source/core/data/attarray.cxx (working copy) @@ -1927,21 +1927,38 @@ rLastRow = MAXROW; return sal_True; } - sal_Bool bFound = sal_False; - SCSIZE nEndPos = nCount - 1; - SCSIZE nStartPos = nEndPos; - while ( nStartPos > 0 && pData[nStartPos-1].nRow > nLastData && - !pData[nStartPos].pPattern->IsVisible() ) - --nStartPos; - if(nStartPos == 0 && !pData[nStartPos].pPattern->IsVisible()) // add this condition for handle only default pattern in one colume - rLastRow = nLastData; - else if(nStartPos >= 0 && pData[nStartPos].nRow > nLastData) - { - bFound = sal_True; - rLastRow = pData[nStartPos].nRow; - } - else - rLastRow = nLastData; + + sal_Bool bFound = sal_False; + + // Loop backwards from the end instead of using Search, assuming that + // there usually aren't many attributes below the last cell. + SCSIZE nPos = nCount; + while ( nPos > 0 && pData[nPos - 1].nRow > nLastData ) + { + SCSIZE nEndPos = nPos - 1; + SCSIZE nStartPos = nEndPos; + while ( nStartPos > 0 && pData[nStartPos - 1].nRow > nLastData && + pData[nStartPos - 1].pPattern->IsEqual( *pData[nStartPos].pPattern ) ) + --nStartPos; + + SCROW nAttrStartRow = ( nStartPos > 0 ) ? ( pData[nStartPos - 1].nRow + 1 ) : 0; + if ( nAttrStartRow <= nLastData ) + nAttrStartRow = nLastData + 1; + SCROW nAttrSize = pData[nEndPos].nRow + 1 - nAttrStartRow; + if ( nAttrSize >= SC_VISATTR_STOP ) + { + bFound = sal_False; + } + else if ( !bFound ) + { + rLastRow = pData[nEndPos].nRow; + bFound = sal_True; + } + + // look further from the top of the range. + nPos = nStartPos; + } + return bFound; } Index: source/core/data/patattr.cxx =================================================================== --- source/core/data/patattr.cxx (revision 1515688) +++ source/core/data/patattr.cxx (working copy) @@ -1144,6 +1144,19 @@ //! auch hier nur wirklich sichtbare Werte testen !!! } +sal_Bool ScPatternAttr::IsEqual( const ScPatternAttr& rOther ) const +{ + const SfxItemSet& rThisSet = GetItemSet(); + const SfxItemSet& rOtherSet = rOther.GetItemSet(); + + return OneEqual( rThisSet, rOtherSet, ATTR_BACKGROUND ) && + OneEqual( rThisSet, rOtherSet, ATTR_BORDER ) && + OneEqual( rThisSet, rOtherSet, ATTR_BORDER_TLBR ) && + OneEqual( rThisSet, rOtherSet, ATTR_BORDER_BLTR ) && + OneEqual( rThisSet, rOtherSet, ATTR_VALUE_FORMAT ) && + OneEqual( rThisSet, rOtherSet, ATTR_SHADOW ); +} + const String* ScPatternAttr::GetStyleName() const { return pName ? pName : ( pStyle ? &pStyle->GetName() : NULL );