[Libreoffice-commits] core.git: 5 commits - sc/source

Noel Power noel.power at suse.com
Mon May 27 11:46:23 PDT 2013


 sc/source/filter/inc/condformatbuffer.hxx  |   47 ++++++++++-
 sc/source/filter/inc/extlstcontext.hxx     |    6 -
 sc/source/filter/inc/sheetdatabuffer.hxx   |   19 ++++
 sc/source/filter/inc/stylesbuffer.hxx      |    4 
 sc/source/filter/oox/condformatbuffer.cxx  |  121 ++++++++++++++++++++++++++++
 sc/source/filter/oox/condformatcontext.cxx |    2 
 sc/source/filter/oox/extlstcontext.cxx     |   98 ++++-------------------
 sc/source/filter/oox/sheetdatabuffer.cxx   |  122 +++++++++++++++++++++++++----
 sc/source/filter/oox/stylesbuffer.cxx      |   64 +++++++++++++++
 sc/source/filter/oox/worksheethelper.cxx   |    1 
 10 files changed, 380 insertions(+), 104 deletions(-)

New commits:
commit 0c9533603392bd2646aed89b878f8761f217fb7a
Author: Noel Power <noel.power at suse.com>
Date:   Mon May 27 15:34:17 2013 +0100

    remove some  methods that are no longer used after rework
    
    Change-Id: I2772dff6297e223caed499e0e7c801970e707700

diff --git a/sc/source/filter/inc/extlstcontext.hxx b/sc/source/filter/inc/extlstcontext.hxx
index 7c26502..c982f10 100644
--- a/sc/source/filter/inc/extlstcontext.hxx
+++ b/sc/source/filter/inc/extlstcontext.hxx
@@ -21,13 +21,7 @@ public:
     virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs );
     virtual void        onStartElement( const AttributeList& rAttribs );
 
-    void finalizeImport();
-
 private:
-    void importDataBar( const AttributeList& rAttribs );
-    void importNegativeFillColor( const AttributeList& rAttribs );
-    void importAxisColor( const AttributeList& rAttribs );
-    void importCfvo( const AttributeList& rAttribs );
     void* mpTarget;
 
     bool mbFirstEntry;
diff --git a/sc/source/filter/oox/extlstcontext.cxx b/sc/source/filter/oox/extlstcontext.cxx
index 8d83845..52a9e36 100644
--- a/sc/source/filter/oox/extlstcontext.cxx
+++ b/sc/source/filter/oox/extlstcontext.cxx
@@ -65,80 +65,6 @@ void ExtCfRuleContext::onStartElement( const AttributeList& rAttribs )
     }
 }
 
-void ExtCfRuleContext::importDataBar( const AttributeList& rAttribs )
-{
-    ScDataBarFormatData* pDataBar = static_cast<ScDataBarFormatData*>(mpTarget);
-    pDataBar->mbGradient = rAttribs.getBool( XML_gradient, true );
-
-    OUString aAxisPosition = rAttribs.getString( XML_axisPosition, "automatic" );
-    if( aAxisPosition == "none" )
-        pDataBar->meAxisPosition = databar::NONE;
-    else if( aAxisPosition == "middle" )
-        pDataBar->meAxisPosition = databar::MIDDLE;
-    else
-        pDataBar->meAxisPosition = databar::AUTOMATIC;
-
-    pDataBar->mbNeg = !rAttribs.getBool( XML_negativeBarColorSameAsPositive, false );
-}
-
-namespace {
-
-::Color RgbToRgbComponents( sal_Int32 nRgb )
-{
-    sal_Int32 ornR = (nRgb >> 16) & 0xFF;
-    sal_Int32 ornG = (nRgb >> 8) & 0xFF;
-    sal_Int32 ornB = nRgb & 0xFF;
-
-    return ::Color(ornR, ornG, ornB);
-}
-
-}
-
-void ExtCfRuleContext::importAxisColor( const AttributeList& rAttribs )
-{
-    ScDataBarFormatData* pDataBar = static_cast<ScDataBarFormatData*>(mpTarget);
-
-    sal_Int32 nColor = rAttribs.getIntegerHex( XML_rgb, API_RGB_TRANSPARENT );
-    ::Color aColor = RgbToRgbComponents(nColor);
-    pDataBar->maAxisColor = aColor;
-}
-
-void ExtCfRuleContext::importNegativeFillColor( const AttributeList& rAttribs )
-{
-    sal_Int32 nColor = rAttribs.getIntegerHex( XML_rgb, API_RGB_TRANSPARENT );
-    ::Color aColor = RgbToRgbComponents(nColor);
-    ::Color* pColor = new Color(aColor.GetRed(), aColor.GetGreen(), aColor.GetBlue());
-    static_cast<ScDataBarFormatData*>(mpTarget)->mpNegativeColor.reset(pColor);
-}
-
-void ExtCfRuleContext::importCfvo( const AttributeList& rAttribs )
-{
-    ScDataBarFormatData* pDataBar = static_cast<ScDataBarFormatData*>(mpTarget);
-    ScColorScaleEntry* pEntry = NULL;
-    if(mbFirstEntry)
-        pEntry = pDataBar->mpLowerLimit.get();
-    else
-        pEntry = pDataBar->mpUpperLimit.get();
-
-    OUString aColorScaleType = rAttribs.getString( XML_type, OUString() );
-    if(aColorScaleType == "min")
-        pEntry->SetType(COLORSCALE_MIN);
-    else if (aColorScaleType == "max")
-        pEntry->SetType(COLORSCALE_MAX);
-    else if (aColorScaleType == "autoMin")
-        pEntry->SetType(COLORSCALE_AUTO);
-    else if (aColorScaleType == "autoMax")
-        pEntry->SetType(COLORSCALE_AUTO);
-    else if (aColorScaleType == "percentile")
-        pEntry->SetType(COLORSCALE_PERCENTILE);
-    else if (aColorScaleType == "percent")
-        pEntry->SetType(COLORSCALE_PERCENT);
-    else if (aColorScaleType == "formula")
-        pEntry->SetType(COLORSCALE_FORMULA);
-
-    mbFirstEntry = false;
-}
-
 ExtLstLocalContext::ExtLstLocalContext( WorksheetContextBase& rFragment, void* pTarget ):
     WorksheetContextBase(rFragment),
     mpTarget(pTarget)
commit 10ceb0c3a27a9052e84582aef9e98dd2e206c195
Author: Noel Power <noel.power at suse.com>
Date:   Mon May 27 14:53:49 2013 +0100

    buffer ExtCfRuleContext startElement processing
    
    ExtCfRuleContext::onStartElement processing depends on some data now buffered
    until CondFormatBuffer::finalizeImport runs. We now need to wait for this
    data to be available. This change buffers up the processing that used happen
    in ExtCfRuleContext startElement so it is now done as part of
    CondFormatBuffer::finalizeImport
    
    Change-Id: Ifbfe12740e6c4bc9791183dba89acb79cbbb6ef6

diff --git a/sc/source/filter/inc/condformatbuffer.hxx b/sc/source/filter/inc/condformatbuffer.hxx
index 8420aaf..2ea0f93 100644
--- a/sc/source/filter/inc/condformatbuffer.hxx
+++ b/sc/source/filter/inc/condformatbuffer.hxx
@@ -231,7 +231,47 @@ private:
     bool                mbReadyForFinalize;
 };
 
+struct ExCfRuleModel
+{
+    ExCfRuleModel() : mbGradient( false ), mbNegativeBarColorSameAsPositive( false ), mnAxisColor( API_RGB_TRANSPARENT ), mnNegativeColor( API_RGB_TRANSPARENT ), mbIsLower( true ) {}
+    // DataBar
+    bool mbGradient;
+    OUString maAxisPosition;
+    bool mbNegativeBarColorSameAsPositive;
+    // AxisColor
+    sal_Int32 mnAxisColor;
+    // NegativeFillColor
+    sal_Int32 mnNegativeColor;
+    // Cfvo
+    bool mbIsLower;
+    OUString maColorScaleType;
+};
+
+class ExtCfRule
+{
+    enum RuleType
+    {
+        DATABAR,
+        NEGATIVEFILLCOLOR,
+        AXISCOLOR,
+        CFVO,
+        UNKNOWN,
+    };
+    ExCfRuleModel maModel;
+    RuleType mnRuleType;
+    void*    mpTarget;
+public:
+    ExtCfRule(void* pTarget = NULL ) : mnRuleType( ExtCfRule::RuleType::UNKNOWN ), mpTarget(pTarget) {}
+    void finalizeImport();
+    void importDataBar(  const AttributeList& rAttribs );
+    void importNegativeFillColor(  const AttributeList& rAttribs );
+    void importAxisColor(  const AttributeList& rAttribs );
+    void importCfvo(  const AttributeList& rAttribs );
+    ExCfRuleModel& getModel() { return maModel; }
+};
+
 typedef ::boost::shared_ptr< CondFormat > CondFormatRef;
+typedef ::boost::shared_ptr< ExtCfRule > ExtCfRuleRef;
 
 // ============================================================================
 
@@ -244,6 +284,7 @@ public:
     CondFormatRef       importConditionalFormatting( const AttributeList& rAttribs );
     /** Imports settings from the CONDFORMATTING record. */
     CondFormatRef       importCondFormatting( SequenceInputStream& rStrm );
+    ExtCfRuleRef        createExtCfRule( void* pTarget );
 
     /** Converts an OOXML condition operator token to the API constant. */
     static sal_Int32    convertToApiOperator( sal_Int32 nToken );
@@ -254,7 +295,9 @@ private:
 
 private:
     typedef RefVector< CondFormat > CondFormatVec;
+    typedef RefVector< ExtCfRule > ExtCfRuleVec;
     CondFormatVec       maCondFormats;      /// All conditional formatting in a sheet.
+    ExtCfRuleVec        maCfRules;          /// All external conditional formatting rules in a sheet.
 };
 
 // ============================================================================
diff --git a/sc/source/filter/oox/condformatbuffer.cxx b/sc/source/filter/oox/condformatbuffer.cxx
index 6660ac9..70a8b65 100644
--- a/sc/source/filter/oox/condformatbuffer.cxx
+++ b/sc/source/filter/oox/condformatbuffer.cxx
@@ -1023,6 +1023,13 @@ void CondFormatBuffer::finalizeImport()
         if ( (*it).get() )
             (*it).get()->finalizeImport();
     }
+    ExtCfRuleVec::iterator ext_it = maCfRules.begin();
+    ExtCfRuleVec::iterator ext_end = maCfRules.end();
+    for ( ; ext_it != ext_end; ++ext_it )
+    {
+        if ( (*ext_it).get() )
+            (*ext_it).get()->finalizeImport();
+    }
 }
 
 CondFormatRef CondFormatBuffer::importCondFormatting( SequenceInputStream& rStrm )
@@ -1032,6 +1039,13 @@ CondFormatRef CondFormatBuffer::importCondFormatting( SequenceInputStream& rStrm
     return xCondFmt;
 }
 
+ExtCfRuleRef CondFormatBuffer::createExtCfRule( void* pTarget )
+{
+    ExtCfRuleRef extRule( new ExtCfRule( pTarget ) );
+    maCfRules.push_back( extRule );
+    return extRule;
+}
+
 sal_Int32 CondFormatBuffer::convertToApiOperator( sal_Int32 nToken )
 {
     switch( nToken )
@@ -1075,7 +1089,100 @@ CondFormatRef CondFormatBuffer::createCondFormat()
     maCondFormats.push_back( xCondFmt );
     return xCondFmt;
 }
+/*
+::Color RgbToRgbComponents( sal_Int32 nRgb )
+{
+    sal_Int32 ornR = (nRgb >> 16) & 0xFF;
+    sal_Int32 ornG = (nRgb >> 8) & 0xFF;
+    sal_Int32 ornB = nRgb & 0xFF;
+
+    return ::Color(ornR, ornG, ornB);
+}
+*/
+
+void ExtCfRule::finalizeImport()
+{
+    switch ( mnRuleType )
+    {
+        case DATABAR:
+        {
+            ScDataBarFormatData* pDataBar = static_cast<ScDataBarFormatData*>(mpTarget);
+            if( maModel.maAxisPosition == "none" )
+                pDataBar->meAxisPosition = databar::NONE;
+            else if( maModel.maAxisPosition == "middle" )
+                pDataBar->meAxisPosition = databar::MIDDLE;
+            else
+                pDataBar->meAxisPosition = databar::AUTOMATIC;
+            pDataBar->mbNeg = !maModel.mbGradient;
+            break;
+        }
+        case AXISCOLOR:
+        {
+            ScDataBarFormatData* pDataBar = static_cast<ScDataBarFormatData*>(mpTarget);
+            pDataBar->maAxisColor = RgbToRgbComponents(maModel.mnAxisColor);
+            break;
+        }
+        case NEGATIVEFILLCOLOR:
+        {
+            ScDataBarFormatData* pDataBar = static_cast<ScDataBarFormatData*>(mpTarget);
+            pDataBar->mpNegativeColor.reset( new ::Color( RgbToRgbComponents(maModel.mnNegativeColor) ) );
+            break;
+        }
+        case CFVO:
+        {
+            ScDataBarFormatData* pDataBar = static_cast<ScDataBarFormatData*>(mpTarget);
+            ScColorScaleEntry* pEntry = NULL;
+            if(maModel.mbIsLower)
+                pEntry = pDataBar->mpLowerLimit.get();
+            else
+                pEntry = pDataBar->mpUpperLimit.get();
+
+            if(maModel.maColorScaleType == "min")
+                pEntry->SetType(COLORSCALE_MIN);
+            else if (maModel.maColorScaleType == "max")
+                pEntry->SetType(COLORSCALE_MAX);
+            else if (maModel.maColorScaleType == "autoMin")
+                pEntry->SetType(COLORSCALE_AUTO);
+            else if (maModel.maColorScaleType == "autoMax")
+                pEntry->SetType(COLORSCALE_AUTO);
+            else if (maModel.maColorScaleType == "percentile")
+                pEntry->SetType(COLORSCALE_PERCENTILE);
+            else if (maModel.maColorScaleType == "percent")
+                pEntry->SetType(COLORSCALE_PERCENT);
+            else if (maModel.maColorScaleType == "formula")
+                pEntry->SetType(COLORSCALE_FORMULA);
+            break;
+        }
+        case UNKNOWN: // nothing to do
+        default:
+            break;
+    };
+}
 
+void ExtCfRule::importDataBar( const AttributeList& rAttribs )
+{
+    mnRuleType = DATABAR;
+    maModel.mbGradient = rAttribs.getBool( XML_gradient, true );
+    maModel.maAxisPosition = rAttribs.getString( XML_axisPosition, "automatic" );
+}
+
+void ExtCfRule::importNegativeFillColor( const AttributeList& rAttribs )
+{
+     mnRuleType = NEGATIVEFILLCOLOR;
+     maModel.mnNegativeColor = rAttribs.getIntegerHex( XML_rgb, API_RGB_TRANSPARENT );
+}
+
+void ExtCfRule::importAxisColor( const AttributeList& rAttribs )
+{
+    mnRuleType = AXISCOLOR;
+    maModel.mnAxisColor = rAttribs.getIntegerHex( XML_rgb, API_RGB_TRANSPARENT );
+}
+
+void ExtCfRule::importCfvo( const AttributeList& rAttribs )
+{
+    mnRuleType = CFVO;
+    maModel.maColorScaleType = rAttribs.getString( XML_type, OUString() );
+}
 // ============================================================================
 
 } // namespace xls
diff --git a/sc/source/filter/oox/extlstcontext.cxx b/sc/source/filter/oox/extlstcontext.cxx
index b949288..8d83845 100644
--- a/sc/source/filter/oox/extlstcontext.cxx
+++ b/sc/source/filter/oox/extlstcontext.cxx
@@ -11,6 +11,7 @@
 #include "worksheethelper.hxx"
 #include <oox/core/contexthandler.hxx>
 #include "colorscale.hxx"
+#include "condformatbuffer.hxx"
 
 using ::oox::core::ContextHandlerRef;
 
@@ -34,18 +35,31 @@ void ExtCfRuleContext::onStartElement( const AttributeList& rAttribs )
     switch( getCurrentElement() )
     {
         case XLS_EXT_TOKEN( dataBar ):
-            importDataBar( rAttribs );
+        {
+            ExtCfRuleRef xRule = getCondFormats().createExtCfRule(mpTarget);
+            xRule->importDataBar( rAttribs );
             break;
+        }
         case XLS_EXT_TOKEN( negativeFillColor ):
-            importNegativeFillColor( rAttribs );
+        {
+            ExtCfRuleRef xRule = getCondFormats().createExtCfRule(mpTarget);
+            xRule->importNegativeFillColor( rAttribs );
             break;
+        }
         case XLS_EXT_TOKEN( axisColor ):
-            importAxisColor( rAttribs );
+        {
+            ExtCfRuleRef xRule = getCondFormats().createExtCfRule(mpTarget);
+            xRule->importAxisColor( rAttribs );
             break;
+        }
         case XLS_EXT_TOKEN( cfvo ):
-            importCfvo( rAttribs );
+        {
+            ExtCfRuleRef xRule = getCondFormats().createExtCfRule(mpTarget);
+            xRule->importCfvo( rAttribs );
+            xRule->getModel().mbIsLower = mbFirstEntry;
+            mbFirstEntry = false;
             break;
-
+        }
         default:
             break;
     }
commit 96b8aa8ed659ef0501bcbc01f01c9013dbe4bc77
Author: Noel Power <noel.power at suse.com>
Date:   Mon May 27 11:30:20 2013 +0100

    buffer conditional formatting finalization so it happens after styles import
    
    Change-Id: If28059578280536141ea966d83e4540939f6e76b

diff --git a/sc/source/filter/inc/condformatbuffer.hxx b/sc/source/filter/inc/condformatbuffer.hxx
index e81ca73..8420aaf 100644
--- a/sc/source/filter/inc/condformatbuffer.hxx
+++ b/sc/source/filter/inc/condformatbuffer.hxx
@@ -217,6 +217,7 @@ public:
     /** Returns the cell ranges this conditional formatting belongs to. */
     inline const ApiCellRangeList& getRanges() const { return maModel.maRanges; }
 
+    void                setReadyForFinalize() { mbReadyForFinalize = true; }
 private:
     CondFormatRuleRef   createRule();
     void                insertRule( CondFormatRuleRef xRule );
@@ -227,6 +228,7 @@ private:
     CondFormatModel     maModel;            /// Model of this conditional formatting.
     CondFormatRuleMap   maRules;            /// Maps formatting rules by priority.
     ScConditionalFormat* mpFormat;
+    bool                mbReadyForFinalize;
 };
 
 typedef ::boost::shared_ptr< CondFormat > CondFormatRef;
@@ -246,7 +248,7 @@ public:
     /** Converts an OOXML condition operator token to the API constant. */
     static sal_Int32    convertToApiOperator( sal_Int32 nToken );
     static sal_Int32    convertToInternalOperator( sal_Int32 nToken );
-
+    void                finalizeImport();
 private:
     CondFormatRef       createCondFormat();
 
diff --git a/sc/source/filter/oox/condformatbuffer.cxx b/sc/source/filter/oox/condformatbuffer.cxx
index 01c3edc..6660ac9 100644
--- a/sc/source/filter/oox/condformatbuffer.cxx
+++ b/sc/source/filter/oox/condformatbuffer.cxx
@@ -932,7 +932,8 @@ CondFormatModel::CondFormatModel() :
 
 CondFormat::CondFormat( const WorksheetHelper& rHelper ) :
     WorksheetHelper( rHelper ),
-    mpFormat(NULL)
+    mpFormat(NULL),
+    mbReadyForFinalize(false)
 {
 }
 
@@ -1013,6 +1014,17 @@ CondFormatRef CondFormatBuffer::importConditionalFormatting( const AttributeList
     return xCondFmt;
 }
 
+void CondFormatBuffer::finalizeImport()
+{
+    CondFormatVec::iterator it = maCondFormats.begin();
+    CondFormatVec::iterator it_end = maCondFormats.end();
+    for( ; it != it_end; ++it )
+    {
+        if ( (*it).get() )
+            (*it).get()->finalizeImport();
+    }
+}
+
 CondFormatRef CondFormatBuffer::importCondFormatting( SequenceInputStream& rStrm )
 {
     CondFormatRef xCondFmt = createCondFormat();
diff --git a/sc/source/filter/oox/condformatcontext.cxx b/sc/source/filter/oox/condformatcontext.cxx
index f4d192c..67b1ed9 100644
--- a/sc/source/filter/oox/condformatcontext.cxx
+++ b/sc/source/filter/oox/condformatcontext.cxx
@@ -178,7 +178,7 @@ void CondFormatContext::onEndElement()
     {
         case XLS_TOKEN( conditionalFormatting ):
             if(mxCondFmt.get())
-                mxCondFmt->finalizeImport();
+                mxCondFmt->setReadyForFinalize();
             break;
     }
 }
diff --git a/sc/source/filter/oox/worksheethelper.cxx b/sc/source/filter/oox/worksheethelper.cxx
index f18ee49..bd8b9ba 100644
--- a/sc/source/filter/oox/worksheethelper.cxx
+++ b/sc/source/filter/oox/worksheethelper.cxx
@@ -946,6 +946,7 @@ void WorksheetGlobals::finalizeWorksheetImport()
 {
     lclUpdateProgressBar( mxRowProgress, 1.0 );
     maSheetData.finalizeImport();
+    getCondFormats().finalizeImport();
     lclUpdateProgressBar( mxFinalProgress, 0.25 );
     finalizeHyperlinkRanges();
     finalizeValidationRanges();
commit f3611760f307949a17bfdcceadb3c6a7bfb20952
Author: Noel Power <noel.power at suse.com>
Date:   Fri May 24 09:52:12 2013 +0100

    reorg styles code slightly, process normal (and row ) style in own method
    
    Change-Id: I701d12cf8f672824d7cfca1e995f02040fdd3095

diff --git a/sc/source/filter/inc/sheetdatabuffer.hxx b/sc/source/filter/inc/sheetdatabuffer.hxx
index 103418a..563145e 100644
--- a/sc/source/filter/inc/sheetdatabuffer.hxx
+++ b/sc/source/filter/inc/sheetdatabuffer.hxx
@@ -192,7 +192,7 @@ private:
     /** Writes all cell formatting attributes to the passed cell range list. (depreciates writeXfIdRangeProperties) */
     void                writeXfIdRangeListProperties( sal_Int32 nXfId, sal_Int32 nNumFmtId, const ApiCellRangeList& rRanges ) const;
     void                applyCellMerging( const ::com::sun::star::table::CellRangeAddress& rRange );
-
+    void                addColXfStyle( sal_Int32 nXfId, sal_Int32 nFormatId, const ::com::sun::star::table::CellRangeAddress& rAddress, bool bProcessRowRange = false );
 private:
     /** Stores cell range address and formula token array of an array formula. */
     typedef ::std::pair< ::com::sun::star::table::CellRangeAddress, ApiTokenSequence > ArrayFormula;
@@ -217,6 +217,22 @@ private:
     typedef ::std::pair< sal_Int32, sal_Int32 > XfIdNumFmtKey;
     typedef ::std::map< XfIdNumFmtKey, ApiCellRangeList > XfIdRangeListMap;
 
+    typedef ::std::pair< sal_Int32, sal_Int32 > RowRange;
+    struct RowRangeStyle
+    {
+        sal_Int32 mnStartRow;
+        sal_Int32 mnEndRow;
+        XfIdNumFmtKey mnNumFmt;
+    };
+    struct StyleRowRangeComp
+    {
+        bool operator() (const RowRangeStyle& lhs, const RowRangeStyle& rhs) const
+        {
+            return lhs.mnEndRow<rhs.mnStartRow;
+        }
+    };
+    typedef ::std::set< RowRangeStyle, StyleRowRangeComp > RowStyles;
+    typedef ::std::map< sal_Int32, RowStyles > ColStyles;
     /** Stores information about a merged cell range. */
     struct MergedRange
     {
@@ -230,6 +246,7 @@ private:
     };
     typedef ::std::list< MergedRange > MergedRangeList;
 
+    ColStyles           maStylesPerColumn;      /// Stores cell styles by column ( in row ranges )
     CellBlockBuffer     maCellBlocks;           /// Manages all open cell blocks.
     ArrayFormulaList    maArrayFormulas;        /// All array formulas in the sheet.
     TableOperationList  maTableOperations;      /// All table operations in the sheet.
diff --git a/sc/source/filter/oox/sheetdatabuffer.cxx b/sc/source/filter/oox/sheetdatabuffer.cxx
index 48b5e8e..174842a 100644
--- a/sc/source/filter/oox/sheetdatabuffer.cxx
+++ b/sc/source/filter/oox/sheetdatabuffer.cxx
@@ -346,6 +346,66 @@ void addIfNotInMyMap( StylesBuffer& rStyles, std::map< std::pair< sal_Int32, sal
     }
 }
 
+void SheetDataBuffer::addColXfStyle( sal_Int32 nXfId, sal_Int32 nFormatId, const ::com::sun::star::table::CellRangeAddress& rAddress, bool bProcessRowRange )
+{
+    RowRangeStyle aStyleRows;
+    aStyleRows.mnNumFmt.first = nXfId;
+    aStyleRows.mnNumFmt.second = nFormatId;
+    aStyleRows.mnStartRow = rAddress.StartRow;
+    aStyleRows.mnEndRow = rAddress.EndRow;
+    for ( sal_Int32 nCol = rAddress.StartColumn; nCol <= rAddress.EndColumn; ++nCol )
+    {
+        if ( !bProcessRowRange )
+            maStylesPerColumn[ nCol ].insert( aStyleRows );
+        else
+        {
+            RowStyles& rRowStyles =  maStylesPerColumn[ nCol ];
+            // If the rowrange style includes rows already
+            // allocated to a style then we need to split
+            // the range style Rows into sections ( to
+            // occupy only rows that have no style definition )
+
+            // We dont want to set any rowstyle 'rows'
+            // for rows where there is an existing 'style' )
+            std::vector< RowRangeStyle > aRangeRowsSplits;
+
+            RowStyles::iterator rows_it = rRowStyles.begin();
+            RowStyles::iterator rows_end = rRowStyles.end();
+            bool bAddRange = true;
+            for ( ; rows_it != rows_end; ++rows_it )
+            {
+                const RowRangeStyle& r = *rows_it;
+                // if row is completely within existing style, discard it
+                if ( aStyleRows.mnStartRow >= r.mnStartRow && aStyleRows.mnEndRow <= r.mnEndRow )
+                    bAddRange = false;
+                else if ( aStyleRows.mnStartRow <= r.mnStartRow )
+                {
+                    // not intersecting at all?, if so finish as none left
+                    // to check ( row ranges are in ascending order
+                    if ( aStyleRows.mnEndRow < r.mnStartRow )
+                        break;
+                    else if ( aStyleRows.mnEndRow <= r.mnEndRow )
+                    {
+                        aStyleRows.mnEndRow = r.mnStartRow - 1;
+                        break;
+                    }
+                    if ( aStyleRows.mnStartRow < r.mnStartRow )
+                    {
+                        RowRangeStyle aSplit = aStyleRows;
+                        aSplit.mnEndRow = r.mnStartRow - 1;
+                        aRangeRowsSplits.push_back( aSplit );
+                    }
+                }
+            }
+            std::vector< RowRangeStyle >::iterator splits_it = aRangeRowsSplits.begin();
+            std::vector< RowRangeStyle >::iterator splits_end = aRangeRowsSplits.end();
+            for ( ; splits_it != splits_end; ++splits_it )
+                rRowStyles.insert( *splits_it );
+            if ( bAddRange )
+                rRowStyles.insert( aStyleRows );
+        }
+    }
+}
 void SheetDataBuffer::finalizeImport()
 {
     // insert all cells of all open cell blocks
@@ -362,49 +422,19 @@ void SheetDataBuffer::finalizeImport()
     // write default formatting of remaining row range
     maXfIdRowRangeList[ maXfIdRowRange.mnXfId ].push_back( maXfIdRowRange.maRowRange );
 
-    typedef ::std::pair< sal_Int32, sal_Int32 > RowRange;
-    struct RowRangeStyle
-    {
-        sal_Int32 mnStartRow;
-        sal_Int32 mnEndRow;
-        XfIdNumFmtKey mnNumFmt;
-    };
-    struct StyleRowRangeComp
-    {
-        bool operator() (const RowRangeStyle& lhs, const RowRangeStyle& rhs) const
-        {
-            return lhs.mnEndRow<rhs.mnStartRow;
-        }
-    };
-
-    typedef ::std::set< RowRangeStyle, StyleRowRangeComp > RowStyles;
-    typedef ::std::map< sal_Int32, RowStyles > ColStyles;
-
-    ColStyles aStylesPerColumn;
-    StylesBuffer& rStyles = getStyles();
-
     std::map< std::pair< sal_Int32, sal_Int32 >, ApiCellRangeList > rangeStyleListMap;
-
     for( XfIdRangeListMap::const_iterator aIt = maXfIdRangeLists.begin(), aEnd = maXfIdRangeLists.end(); aIt != aEnd; ++aIt )
+    {
         addIfNotInMyMap( getStyles(), rangeStyleListMap, aIt->first.first, aIt->first.second, aIt->second );
-
+    }
     // gather all ranges that have the same style and apply them in bulk
     for (  std::map< std::pair< sal_Int32, sal_Int32 >, ApiCellRangeList >::iterator it = rangeStyleListMap.begin(), it_end = rangeStyleListMap.end(); it != it_end; ++it )
     {
         const ApiCellRangeList& rRanges( it->second );
         for ( ApiCellRangeList::const_iterator it_range = rRanges.begin(), it_rangeend = rRanges.end(); it_range!=it_rangeend; ++it_range )
-        {
-            RowRangeStyle aStyleRows;
-            aStyleRows.mnNumFmt.first = it->first.first;
-            aStyleRows.mnNumFmt.second = it->first.second;
-            aStyleRows.mnStartRow = it_range->StartRow;
-            aStyleRows.mnEndRow = it_range->EndRow;
-            for ( sal_Int32 nCol = it_range->StartColumn; nCol <= it_range->EndColumn; ++nCol )
-                aStylesPerColumn[ nCol ].insert( aStyleRows );
-        }
+            addColXfStyle( it->first.first, it->first.second, *it_range );
     }
 
-    // process row ranges for each column, don't overwrite any existing row entries for a column
     for ( std::map< sal_Int32, std::vector< ValueRange > >::iterator it = maXfIdRowRangeList.begin(), it_end =  maXfIdRowRangeList.end(); it != it_end; ++it )
     {
         ApiCellRangeList rangeList;
@@ -412,64 +442,17 @@ void SheetDataBuffer::finalizeImport()
         // get all row ranges for id
         for ( std::vector< ValueRange >::iterator rangeIter = it->second.begin(), rangeIter_end = it->second.end(); rangeIter != rangeIter_end; ++rangeIter )
         {
-            RowRangeStyle aStyleRows;
-            aStyleRows.mnNumFmt.first = it->first;
-            if ( aStyleRows.mnNumFmt.first == -1 ) // dud
+            if ( it->first == -1 ) // it's a dud skip it
                 continue;
-            aStyleRows.mnNumFmt.second = -1;
-            aStyleRows.mnStartRow = rangeIter->mnFirst;
-            aStyleRows.mnEndRow = rangeIter->mnLast;
-            for ( sal_Int32 nCol = 0; nCol <= rAddrConv.getMaxApiAddress().Column; ++nCol )
-            {
-                RowStyles& rRowStyles =  aStylesPerColumn[ nCol ];
-                // If the rowrange style includes rows already
-                // allocated to a style then we need to split
-                // the range style Rows into sections ( to
-                // occupy only rows that have no style definition )
-
-                // We dont want to set any rowstyle 'rows'
-                // for rows where there is an existing 'style' )
-                std::vector< RowRangeStyle > aRangeRowsSplits;
-
-                RowStyles::iterator rows_it = rRowStyles.begin();
-                RowStyles::iterator rows_end = rRowStyles.end();
-                bool bAddRange = true;
-                for ( ; rows_it != rows_end; ++rows_it )
-                {
-                    const RowRangeStyle& r = *rows_it;
-                    // if row is completely within existing style, discard it
-                    if ( aStyleRows.mnStartRow >= r.mnStartRow && aStyleRows.mnEndRow <= r.mnEndRow )
-                        bAddRange = false;
-                    else if ( aStyleRows.mnStartRow <= r.mnStartRow )
-                    {
-                        // not intersecting at all?, if so finish as none left
-                        // to check ( row ranges are in ascending order
-                        if ( aStyleRows.mnEndRow < r.mnStartRow )
-                            break;
-                        else if ( aStyleRows.mnEndRow <= r.mnEndRow )
-                        {
-                            aStyleRows.mnEndRow = r.mnStartRow - 1;
-                            break;
-                        }
-                        if ( aStyleRows.mnStartRow < r.mnStartRow )
-                        {
-                            RowRangeStyle aSplit = aStyleRows;
-                            aSplit.mnEndRow = r.mnStartRow - 1;
-                            aRangeRowsSplits.push_back( aSplit );
-                        }
-                    }
-                }
-                std::vector< RowRangeStyle >::iterator splits_it = aRangeRowsSplits.begin();
-                std::vector< RowRangeStyle >::iterator splits_end = aRangeRowsSplits.end();
-                for ( ; splits_it != splits_end; ++splits_it )
-                    rRowStyles.insert( *splits_it );
-                if ( bAddRange )
-                    rRowStyles.insert( aStyleRows );
-            }
+            CellRangeAddress aRange( getSheetIndex(), 0, rangeIter->mnFirst, rAddrConv.getMaxApiAddress().Column, rangeIter->mnLast );
+
+            addColXfStyle( it->first, -1, aRange, true );
         }
     }
+
     ScDocument& rDoc = getScDocument();
-    for ( ColStyles::iterator col = aStylesPerColumn.begin(), col_end = aStylesPerColumn.end(); col != col_end; ++col )
+    StylesBuffer& rStyles = getStyles();
+    for ( ColStyles::iterator col = maStylesPerColumn.begin(), col_end = maStylesPerColumn.end(); col != col_end; ++col )
     {
         RowStyles& rRowStyles = col->second;
         std::list<ScAttrEntry> aAttrs;
@@ -497,6 +480,7 @@ void SheetDataBuffer::finalizeImport()
 
         rDoc.SetAttrEntries(nScCol, getSheetIndex(), pData, static_cast<SCSIZE>(nAttrSize));
     }
+
     // merge all cached merged ranges and update right/bottom cell borders
     for( MergedRangeList::iterator aIt = maMergedRanges.begin(), aEnd = maMergedRanges.end(); aIt != aEnd; ++aIt )
         applyCellMerging( aIt->maRange );
commit fc861c7088e9b639a1c2c80f8ba4535c798aeb34
Author: Noel Power <noel.power at suse.com>
Date:   Thu May 23 11:50:28 2013 +0100

    improve cell style xls[x|m] import performance
    
    This change reorganizes the styles by column ( and by row ranges in that column )
    so we can apply ScAttrEntry entries directly via Document.SetAttrEntries(...) this is
    what the binary filter does also.
    
    Change-Id: I7c1398c1d900e0a2b6c6ec3746b982ef60e653a0

diff --git a/sc/source/filter/inc/stylesbuffer.hxx b/sc/source/filter/inc/stylesbuffer.hxx
index 77654c7..32b439c 100644
--- a/sc/source/filter/inc/stylesbuffer.hxx
+++ b/sc/source/filter/inc/stylesbuffer.hxx
@@ -35,6 +35,8 @@
 #include "stlsheet.hxx"
 #include <editeng/svxenum.hxx>
 #include <editeng/frmdir.hxx>
+#include "attarray.hxx"
+#include <list>
 
 class ScMarkData;
 namespace com { namespace sun { namespace star {
@@ -719,6 +721,8 @@ public:
     inline const Protection& getProtection() const { return maProtection; }
 
     void  writeToMarkData( ::ScMarkData& rMarkData, sal_Int32 nNumFmtId  );
+    void  applyPatternToAttrList( ::std::list<ScAttrEntry>& rAttrs, SCROW nRow1, SCROW nRow2,
+                                  sal_Int32 nForceScNumFmt );
     /** Writes all formatting attributes to the passed property map. */
     void                writeToPropertyMap( PropertyMap& rPropMap ) const;
     /** Writes all formatting attributes to the passed property set. */
diff --git a/sc/source/filter/oox/sheetdatabuffer.cxx b/sc/source/filter/oox/sheetdatabuffer.cxx
index 11a057d..48b5e8e 100644
--- a/sc/source/filter/oox/sheetdatabuffer.cxx
+++ b/sc/source/filter/oox/sheetdatabuffer.cxx
@@ -361,6 +361,50 @@ void SheetDataBuffer::finalizeImport()
 
     // write default formatting of remaining row range
     maXfIdRowRangeList[ maXfIdRowRange.mnXfId ].push_back( maXfIdRowRange.maRowRange );
+
+    typedef ::std::pair< sal_Int32, sal_Int32 > RowRange;
+    struct RowRangeStyle
+    {
+        sal_Int32 mnStartRow;
+        sal_Int32 mnEndRow;
+        XfIdNumFmtKey mnNumFmt;
+    };
+    struct StyleRowRangeComp
+    {
+        bool operator() (const RowRangeStyle& lhs, const RowRangeStyle& rhs) const
+        {
+            return lhs.mnEndRow<rhs.mnStartRow;
+        }
+    };
+
+    typedef ::std::set< RowRangeStyle, StyleRowRangeComp > RowStyles;
+    typedef ::std::map< sal_Int32, RowStyles > ColStyles;
+
+    ColStyles aStylesPerColumn;
+    StylesBuffer& rStyles = getStyles();
+
+    std::map< std::pair< sal_Int32, sal_Int32 >, ApiCellRangeList > rangeStyleListMap;
+
+    for( XfIdRangeListMap::const_iterator aIt = maXfIdRangeLists.begin(), aEnd = maXfIdRangeLists.end(); aIt != aEnd; ++aIt )
+        addIfNotInMyMap( getStyles(), rangeStyleListMap, aIt->first.first, aIt->first.second, aIt->second );
+
+    // gather all ranges that have the same style and apply them in bulk
+    for (  std::map< std::pair< sal_Int32, sal_Int32 >, ApiCellRangeList >::iterator it = rangeStyleListMap.begin(), it_end = rangeStyleListMap.end(); it != it_end; ++it )
+    {
+        const ApiCellRangeList& rRanges( it->second );
+        for ( ApiCellRangeList::const_iterator it_range = rRanges.begin(), it_rangeend = rRanges.end(); it_range!=it_rangeend; ++it_range )
+        {
+            RowRangeStyle aStyleRows;
+            aStyleRows.mnNumFmt.first = it->first.first;
+            aStyleRows.mnNumFmt.second = it->first.second;
+            aStyleRows.mnStartRow = it_range->StartRow;
+            aStyleRows.mnEndRow = it_range->EndRow;
+            for ( sal_Int32 nCol = it_range->StartColumn; nCol <= it_range->EndColumn; ++nCol )
+                aStylesPerColumn[ nCol ].insert( aStyleRows );
+        }
+    }
+
+    // process row ranges for each column, don't overwrite any existing row entries for a column
     for ( std::map< sal_Int32, std::vector< ValueRange > >::iterator it = maXfIdRowRangeList.begin(), it_end =  maXfIdRowRangeList.end(); it != it_end; ++it )
     {
         ApiCellRangeList rangeList;
@@ -368,27 +412,91 @@ void SheetDataBuffer::finalizeImport()
         // get all row ranges for id
         for ( std::vector< ValueRange >::iterator rangeIter = it->second.begin(), rangeIter_end = it->second.end(); rangeIter != rangeIter_end; ++rangeIter )
         {
-            CellRangeAddress aRange( getSheetIndex(), 0, rangeIter->mnFirst, rAddrConv.getMaxApiAddress().Column, rangeIter->mnLast );
-            rangeList.push_back( aRange );
+            RowRangeStyle aStyleRows;
+            aStyleRows.mnNumFmt.first = it->first;
+            if ( aStyleRows.mnNumFmt.first == -1 ) // dud
+                continue;
+            aStyleRows.mnNumFmt.second = -1;
+            aStyleRows.mnStartRow = rangeIter->mnFirst;
+            aStyleRows.mnEndRow = rangeIter->mnLast;
+            for ( sal_Int32 nCol = 0; nCol <= rAddrConv.getMaxApiAddress().Column; ++nCol )
+            {
+                RowStyles& rRowStyles =  aStylesPerColumn[ nCol ];
+                // If the rowrange style includes rows already
+                // allocated to a style then we need to split
+                // the range style Rows into sections ( to
+                // occupy only rows that have no style definition )
+
+                // We dont want to set any rowstyle 'rows'
+                // for rows where there is an existing 'style' )
+                std::vector< RowRangeStyle > aRangeRowsSplits;
+
+                RowStyles::iterator rows_it = rRowStyles.begin();
+                RowStyles::iterator rows_end = rRowStyles.end();
+                bool bAddRange = true;
+                for ( ; rows_it != rows_end; ++rows_it )
+                {
+                    const RowRangeStyle& r = *rows_it;
+                    // if row is completely within existing style, discard it
+                    if ( aStyleRows.mnStartRow >= r.mnStartRow && aStyleRows.mnEndRow <= r.mnEndRow )
+                        bAddRange = false;
+                    else if ( aStyleRows.mnStartRow <= r.mnStartRow )
+                    {
+                        // not intersecting at all?, if so finish as none left
+                        // to check ( row ranges are in ascending order
+                        if ( aStyleRows.mnEndRow < r.mnStartRow )
+                            break;
+                        else if ( aStyleRows.mnEndRow <= r.mnEndRow )
+                        {
+                            aStyleRows.mnEndRow = r.mnStartRow - 1;
+                            break;
+                        }
+                        if ( aStyleRows.mnStartRow < r.mnStartRow )
+                        {
+                            RowRangeStyle aSplit = aStyleRows;
+                            aSplit.mnEndRow = r.mnStartRow - 1;
+                            aRangeRowsSplits.push_back( aSplit );
+                        }
+                    }
+                }
+                std::vector< RowRangeStyle >::iterator splits_it = aRangeRowsSplits.begin();
+                std::vector< RowRangeStyle >::iterator splits_end = aRangeRowsSplits.end();
+                for ( ; splits_it != splits_end; ++splits_it )
+                    rRowStyles.insert( *splits_it );
+                if ( bAddRange )
+                    rRowStyles.insert( aStyleRows );
+            }
+        }
+    }
+    ScDocument& rDoc = getScDocument();
+    for ( ColStyles::iterator col = aStylesPerColumn.begin(), col_end = aStylesPerColumn.end(); col != col_end; ++col )
+    {
+        RowStyles& rRowStyles = col->second;
+        std::list<ScAttrEntry> aAttrs;
+        SCCOL nScCol = static_cast< SCCOL >( col->first );
+        for ( RowStyles::iterator rRows = rRowStyles.begin(), rRows_end = rRowStyles.end(); rRows != rRows_end; ++rRows )
+        {
+             Xf* pXf = rStyles.getCellXf( rRows->mnNumFmt.first ).get();
+
+             if ( pXf )
+                 pXf->applyPatternToAttrList( aAttrs,  rRows->mnStartRow,  rRows->mnEndRow,  rRows->mnNumFmt.second );
         }
-        ScRangeList aList;
-        for ( ApiCellRangeList::const_iterator itRange = rangeList.begin(), itRange_end = rangeList.end(); itRange!=itRange_end; ++itRange )
+        if (aAttrs.empty() || aAttrs.back().nRow != MAXROW)
         {
-            ScRange* pRange = new ScRange();
-            ScUnoConversion::FillScRange( *pRange, *itRange );
-            aList.push_back( pRange );
+            ScAttrEntry aEntry;
+            aEntry.nRow = MAXROW;
+            aEntry.pPattern = rDoc.GetDefPattern();
+            aAttrs.push_back(aEntry);
         }
-        ScMarkData aMark;
-        aMark.MarkFromRangeList( aList, false );
 
-        getStyles().writeCellXfToMarkData( aMark, it->first, -1 );
+        size_t nAttrSize = aAttrs.size();
+        ScAttrEntry* pData = new ScAttrEntry[nAttrSize];
+        std::list<ScAttrEntry>::const_iterator itr = aAttrs.begin(), itrEnd = aAttrs.end();
+        for (size_t i = 0; itr != itrEnd; ++itr, ++i)
+            pData[i] = *itr;
+
+        rDoc.SetAttrEntries(nScCol, getSheetIndex(), pData, static_cast<SCSIZE>(nAttrSize));
     }
-    std::map< std::pair< sal_Int32, sal_Int32 >, ApiCellRangeList > rangeStyleListMap;
-    // gather all ranges that have the same style and apply them in bulk
-    for( XfIdRangeListMap::const_iterator aIt = maXfIdRangeLists.begin(), aEnd = maXfIdRangeLists.end(); aIt != aEnd; ++aIt )
-        addIfNotInMyMap( getStyles(), rangeStyleListMap, aIt->first.first, aIt->first.second, aIt->second );
-    for (  std::map< std::pair< sal_Int32, sal_Int32 >, ApiCellRangeList >::iterator it = rangeStyleListMap.begin(), it_end = rangeStyleListMap.end(); it != it_end; ++it )
-        writeXfIdRangeListProperties( it->first.first, it->first.second, it->second );
     // merge all cached merged ranges and update right/bottom cell borders
     for( MergedRangeList::iterator aIt = maMergedRanges.begin(), aEnd = maMergedRanges.end(); aIt != aEnd; ++aIt )
         applyCellMerging( aIt->maRange );
diff --git a/sc/source/filter/oox/stylesbuffer.cxx b/sc/source/filter/oox/stylesbuffer.cxx
index 0d0467d..cead31d 100644
--- a/sc/source/filter/oox/stylesbuffer.cxx
+++ b/sc/source/filter/oox/stylesbuffer.cxx
@@ -2281,6 +2281,70 @@ FontRef Xf::getFont() const
     return getStyles().getFont( maModel.mnFontId );
 }
 
+void Xf::applyPatternToAttrList( ::std::list<ScAttrEntry>& rAttrs, SCROW nRow1, SCROW nRow2,
+                                  sal_Int32 nNumFmtId )
+{
+    createPattern();
+    ScPatternAttr& rPat = *mpPattern;
+    ScDocument& rDoc = getScDocument();
+    if ( isCellXf() )
+    {
+        StylesBuffer& rStyles = getStyles();
+        rStyles.createCellStyle( maModel.mnStyleXfId );
+
+        mpStyleSheet = rStyles.getCellStyleSheet( maModel.mnStyleXfId );
+        if ( mpStyleSheet )
+        {
+            //rDoc.ApplySelectionStyle( static_cast<ScStyleSheet&>(*mpStyleSheet), rMarkData );
+            rPat.SetStyleSheet(mpStyleSheet, false);
+        }
+        else
+        {
+            ScStyleSheetPool* pStylePool = rDoc.GetStyleSheetPool();
+            if (pStylePool)
+            {
+                ScStyleSheet* pStyleSheet = static_cast<ScStyleSheet*>(
+                    pStylePool->Find(
+                        ScGlobal::GetRscString(STR_STYLENAME_STANDARD), SFX_STYLE_FAMILY_PARA));
+
+                if (pStyleSheet)
+                    rPat.SetStyleSheet( pStyleSheet, false );
+            }
+        }
+    }
+    if ( nNumFmtId >= 0 )
+    {
+        ScPatternAttr aNumPat(rDoc.GetPool());
+        getStyles().writeNumFmtToItemSet( aNumPat.GetItemSet(), nNumFmtId );
+        rPat.GetItemSet().Put(aNumPat.GetItemSet());
+    }
+    if (rPat.GetStyleName())
+    {
+        // Check for a gap between the last entry and this one.
+        bool bHasGap = false;
+        if (rAttrs.empty() && nRow1 > 0)
+            // First attribute range doesn't start at row 0.
+            bHasGap = true;
+
+        if (!rAttrs.empty() && rAttrs.back().nRow + 1 < nRow1)
+            bHasGap = true;
+
+        if (bHasGap)
+        {
+            // Fill this gap with the default pattern.
+            ScAttrEntry aEntry;
+            aEntry.nRow = nRow1 - 1;
+            aEntry.pPattern = rDoc.GetDefPattern();
+            rAttrs.push_back(aEntry);
+        }
+
+        ScAttrEntry aEntry;
+        aEntry.nRow = nRow2;
+        aEntry.pPattern = static_cast<const ScPatternAttr*>(&rDoc.GetPool()->Put(rPat));
+        rAttrs.push_back(aEntry);
+    }
+}
+
 void Xf::writeToMarkData( ::ScMarkData& rMarkData, sal_Int32 nNumFmtId  )
 {
     createPattern();


More information about the Libreoffice-commits mailing list