[Libreoffice-commits] .: Branch 'feature/gsoc-calc-perf' - sc/source

Daniel Bankston dbank at kemper.freedesktop.org
Fri May 25 00:39:25 PDT 2012


 sc/source/filter/xml/xmlcelli.cxx |   15 +++----
 sc/source/filter/xml/xmlsubti.cxx |   79 ++++++++++++++++++++++++--------------
 sc/source/filter/xml/xmlsubti.hxx |   18 ++++----
 3 files changed, 68 insertions(+), 44 deletions(-)

New commits:
commit 5069f76b553cec0b7f1816523491a0896fb6e3b5
Author: Daniel Bankston <daniel.e.bankston at gmail.com>
Date:   Fri May 25 02:36:28 2012 -0500

    Convert ScMyTables matrix methods to use direct Sc calls
    
    Change-Id: I345d938b80e5c68f9db20cf032fed9966df44936

diff --git a/sc/source/filter/xml/xmlcelli.cxx b/sc/source/filter/xml/xmlcelli.cxx
index 89bf499..e7e0bf4 100644
--- a/sc/source/filter/xml/xmlcelli.cxx
+++ b/sc/source/filter/xml/xmlcelli.cxx
@@ -334,8 +334,8 @@ SvXMLImportContext *ScXMLTableRowCellContext::CreateChildContext( sal_uInt16 nPr
             bIsEmpty = false;
             bTextP = true;
             com::sun::star::table::CellAddress aCellPos = rXMLImport.GetTables().GetRealCellPos();
-            if (((nCellType == util::NumberFormat::TEXT) || bFormulaTextResult) &&
-                !rXMLImport.GetTables().IsPartOfMatrix(aCellPos.Column, aCellPos.Row))
+            if( ((nCellType == util::NumberFormat::TEXT) || bFormulaTextResult) &&
+                !rXMLImport.GetTables().IsPartOfMatrix(static_cast<SCCOL>(aCellPos.Column), static_cast<SCROW>(aCellPos.Row)) )
             {
                 if (!bHasTextImport)
                 {
@@ -911,7 +911,7 @@ void ScXMLTableRowCellContext::EndElement()
                                     case util::NumberFormat::TEXT:
                                         {
                                             bool bDoIncrement = true;
-                                            if (rTables.IsPartOfMatrix(aCurrentPos.Column, aCurrentPos.Row))
+                                            if (rTables.IsPartOfMatrix(static_cast<SCCOL>(aCurrentPos.Column), static_cast<SCROW>(aCurrentPos.Row)))
                                             {
                                                 LockSolarMutex();
                                                 // test - bypass the API
@@ -998,7 +998,7 @@ void ScXMLTableRowCellContext::EndElement()
                                     case util::NumberFormat::DATETIME:
                                     case util::NumberFormat::LOGICAL:
                                         {
-                                            if (rTables.IsPartOfMatrix(aCurrentPos.Column, aCurrentPos.Row))
+                                            if( rTables.IsPartOfMatrix(static_cast<SCCOL>(aCurrentPos.Column), static_cast<SCROW>(aCurrentPos.Row)) )
                                             {
                                                 LockSolarMutex();
                                                 // test - bypass the API
@@ -1184,9 +1184,10 @@ void ScXMLTableRowCellContext::EndElement()
                             if (nMatrixCols > 0 && nMatrixRows > 0)
                             {
                                 rTables.AddMatrixRange(
-                                        aCellPos.Column, aCellPos.Row,
-                                        aCellPos.Column + nMatrixCols - 1,
-                                        aCellPos.Row + nMatrixRows - 1,
+                                        static_cast<SCCOL>(aCellPos.Column),
+                                        static_cast<SCROW>(aCellPos.Row),
+                                        static_cast<SCCOL>(aCellPos.Column + nMatrixCols - 1),
+                                        static_cast<SCROW>(aCellPos.Row + nMatrixRows - 1),
                                         pOUFormula->first, pOUFormula->second, eGrammar);
                             }
                         }
diff --git a/sc/source/filter/xml/xmlsubti.cxx b/sc/source/filter/xml/xmlsubti.cxx
index 5f33aca..9342961 100644
--- a/sc/source/filter/xml/xmlsubti.cxx
+++ b/sc/source/filter/xml/xmlsubti.cxx
@@ -41,6 +41,8 @@
 #include "sheetdata.hxx"
 #include "tabprotection.hxx"
 #include "convuno.hxx"
+#include "docsh.hxx"
+#include "docfunc.hxx"
 #include <svx/svdpage.hxx>
 
 #include <sax/tools/converter.hxx>
@@ -645,7 +647,7 @@ void ScMyTables::DeleteTable()
         ScMyMatrixRangeList::iterator aEndItr = aMatrixRangeList.end();
         while(aItr != aEndItr)
         {
-            SetMatrix(aItr->aRange, aItr->sFormula, aItr->sFormulaNmsp, aItr->eGrammar);
+            SetMatrix(aItr->aScRange, aItr->sFormula, aItr->sFormulaNmsp, aItr->eGrammar);
             ++aItr;
         }
         aMatrixRangeList.clear();
@@ -754,22 +756,20 @@ void ScMyTables::AddOLE(uno::Reference <drawing::XShape>& rShape,
 }
 
 void ScMyTables::AddMatrixRange(
-        sal_Int32 nStartColumn, sal_Int32 nStartRow, sal_Int32 nEndColumn, sal_Int32 nEndRow,
+        const SCCOL nStartColumn, const SCROW nStartRow, const SCCOL nEndColumn, const SCROW nEndRow,
         const rtl::OUString& rFormula, const rtl::OUString& rFormulaNmsp, const formula::FormulaGrammar::Grammar eGrammar)
 {
     OSL_ENSURE(nEndRow >= nStartRow, "wrong row order");
     OSL_ENSURE(nEndColumn >= nStartColumn, "wrong column order");
-    table::CellRangeAddress aRange;
-    aRange.StartColumn = nStartColumn;
-    aRange.StartRow = nStartRow;
-    aRange.EndColumn = nEndColumn;
-    aRange.EndRow = nEndRow;
-    aRange.Sheet = nCurrentSheet;
-    ScMatrixRange aMRange(aRange, rFormula, rFormulaNmsp, eGrammar);
+    ScRange aScRange(
+        nStartColumn, nStartRow, nCurrentSheet,
+        nEndColumn, nEndRow, nCurrentSheet
+    );
+    ScMatrixRange aMRange(aScRange, rFormula, rFormulaNmsp, eGrammar);
     aMatrixRangeList.push_back(aMRange);
 }
 
-bool ScMyTables::IsPartOfMatrix(sal_Int32 nColumn, sal_Int32 nRow)
+bool ScMyTables::IsPartOfMatrix(const SCCOL nColumn, const SCROW nRow)
 {
     bool bResult(false);
     if (!aMatrixRangeList.empty())
@@ -779,19 +779,20 @@ bool ScMyTables::IsPartOfMatrix(sal_Int32 nColumn, sal_Int32 nRow)
         bool bReady(false);
         while(!bReady && aItr != aEndItr)
         {
-            if (nCurrentSheet > aItr->aRange.Sheet)
+            if (nCurrentSheet > aItr->aScRange.aStart.Tab())
             {
                 OSL_FAIL("should never hapen, because the list should be cleared in DeleteTable");
                 aItr = aMatrixRangeList.erase(aItr);
             }
-            else if ((nRow > aItr->aRange.EndRow) && (nColumn > aItr->aRange.EndColumn))
+            else if ((nRow > aItr->aScRange.aEnd.Row()) && (nColumn > aItr->aScRange.aEnd.Col()))
             {
-                SetMatrix(aItr->aRange, aItr->sFormula, aItr->sFormulaNmsp, aItr->eGrammar);
+                SetMatrix(aItr->aScRange, aItr->sFormula, aItr->sFormulaNmsp, aItr->eGrammar);
                 aItr = aMatrixRangeList.erase(aItr);
             }
-            else if (nColumn < aItr->aRange.StartColumn)
+            else if (nColumn < aItr->aScRange.aStart.Col())
                 bReady = true;
-            else if (nColumn >= aItr->aRange.StartColumn && nColumn <= aItr->aRange.EndColumn && nRow >= aItr->aRange.StartRow && nRow <= aItr->aRange.EndRow)
+            else if ( nColumn >= aItr->aScRange.aStart.Col() && nColumn <= aItr->aScRange.aEnd.Col() &&
+                      nRow >= aItr->aScRange.aStart.Row() && nRow <= aItr->aScRange.aEnd.Row() )
             {
                 bReady = true;
                 bResult = true;
@@ -803,24 +804,46 @@ bool ScMyTables::IsPartOfMatrix(sal_Int32 nColumn, sal_Int32 nRow)
     return bResult;
 }
 
-void ScMyTables::SetMatrix(const table::CellRangeAddress& rRange, const rtl::OUString& rFormula,
-        const rtl::OUString& rFormulaNmsp, const formula::FormulaGrammar::Grammar eGrammar)
+namespace {
+
+ScRange getCellRangeByPosition( const ScRange& rScRange, const SCCOL nLeft, const SCROW nTop, const SCCOL nRight, const SCROW nBottom )
 {
-    uno::Reference <table::XCellRange> xMatrixCellRange(
-        GetCurrentXCellRange()->getCellRangeByPosition(rRange.StartColumn, rRange.StartRow,
-                    rRange.EndColumn, rRange.EndRow));
-    if (xMatrixCellRange.is())
+    if( nLeft >= 0 && nTop >= 0 && nRight >= 0 && nBottom >= 0 )
     {
-        uno::Reference <sheet::XArrayFormulaRange> xArrayFormulaRange(xMatrixCellRange, uno::UNO_QUERY);
-        if (xArrayFormulaRange.is())
+        SCCOL nStartX = rScRange.aStart.Col() + nLeft;
+        SCROW nStartY = rScRange.aStart.Row() + nTop;
+        SCCOL nEndX = rScRange.aStart.Col() + nRight;
+        SCROW nEndY = rScRange.aStart.Row() + nBottom;
+
+        if( nStartX <= nEndX && nEndX <= rScRange.aEnd.Col() &&
+            nStartY <= nEndY && nEndY <= rScRange.aEnd.Row() )
         {
-            ScCellRangeObj* pCellRangeObj =
-                static_cast<ScCellRangeObj*>(ScCellRangesBase::getImplementation(
-                            xMatrixCellRange));
-            if (pCellRangeObj)
-                pCellRangeObj->SetArrayFormulaWithGrammar( rFormula, rFormulaNmsp, eGrammar);
+            return ScRange( nStartX, nStartY, rScRange.aStart.Tab(), nEndX, nEndY, rScRange.aEnd.Tab() );
         }
     }
+    return ScRange( ScAddress::INITIALIZE_INVALID );
+}
+
+} //anonymous namespace
+
+void ScMyTables::SetMatrix(const ScRange& rScRange, const rtl::OUString& rFormula,
+        const rtl::OUString& rFormulaNmsp, const formula::FormulaGrammar::Grammar eGrammar)
+{
+    ScRange aWholeSheetRange( 0, 0, nCurrentSheet, MAXCOL, MAXROW, nCurrentSheet );  //the whole sheet
+    ScRange aMatrixRange(
+        getCellRangeByPosition( aWholeSheetRange, rScRange.aStart.Col(), rScRange.aStart.Row(), rScRange.aEnd.Col(), rScRange.aEnd.Row() )
+    );
+    ScDocShell* pDocSh = static_cast< ScDocShell* >( rImport.GetDocument()->GetDocumentShell() );
+    if ( !rFormula.isEmpty() )
+        pDocSh->GetDocFunc().EnterMatrix( aMatrixRange, NULL, NULL, rFormula, sal_True, sal_True, rFormulaNmsp, eGrammar );
+    else
+    {
+        //  empty string -> erase array formula
+        ScMarkData aMark;
+        aMark.SetMarkArea( aMatrixRange );
+        aMark.SelectTable( aMatrixRange.aStart.Tab(), sal_True );
+        pDocSh->GetDocFunc().DeleteContents( aMark, IDF_CONTENTS, sal_True, sal_True );
+    }
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/filter/xml/xmlsubti.hxx b/sc/source/filter/xml/xmlsubti.hxx
index 6fa8161..101eddd 100644
--- a/sc/source/filter/xml/xmlsubti.hxx
+++ b/sc/source/filter/xml/xmlsubti.hxx
@@ -99,12 +99,12 @@ struct ScMatrixRange
     rtl::OUString sFormula;
     rtl::OUString sFormulaNmsp;
     formula::FormulaGrammar::Grammar eGrammar;
-    com::sun::star::table::CellRangeAddress aRange;
-    ScMatrixRange(const com::sun::star::table::CellRangeAddress& rRange, const rtl::OUString& rFormula, const rtl::OUString& rFormulaNmsp, const formula::FormulaGrammar::Grammar eGrammarP) :
+    ScRange aScRange;
+    ScMatrixRange(const ScRange& rScRange, const rtl::OUString& rFormula, const rtl::OUString& rFormulaNmsp, const formula::FormulaGrammar::Grammar eGrammarP) :
         sFormula(rFormula),
         sFormulaNmsp(rFormulaNmsp),
         eGrammar(eGrammarP),
-        aRange(rRange)
+        aScRange(rScRange)
     {
     }
 };
@@ -192,16 +192,16 @@ public:
     void                                AddOLE(com::sun::star::uno::Reference <com::sun::star::drawing::XShape>& rShape,
                                                const rtl::OUString &rRangeList);
 
-    void                                AddMatrixRange( sal_Int32 nStartColumn,
-                                                sal_Int32 nStartRow,
-                                                sal_Int32 nEndColumn,
-                                                sal_Int32 nEndRow,
+    void                                AddMatrixRange( const SCCOL nStartColumn,
+                                                const SCROW nStartRow,
+                                                const SCCOL nEndColumn,
+                                                const SCROW nEndRow,
                                                 const rtl::OUString& rFormula,
                                                 const rtl::OUString& rFormulaNmsp,
                                                 const formula::FormulaGrammar::Grammar );
 
-    bool                                IsPartOfMatrix(sal_Int32 nColumn, sal_Int32 nRow);
-    void                                SetMatrix( const com::sun::star::table::CellRangeAddress& rRange,
+    bool                                IsPartOfMatrix( const SCCOL nColumn, const SCROW nRow);
+    void                                SetMatrix( const ScRange& rScRange,
                                                 const rtl::OUString& rFormula,
                                                 const rtl::OUString& rFormulaNmsp,
                                                 const formula::FormulaGrammar::Grammar );


More information about the Libreoffice-commits mailing list