[Libreoffice-commits] .: 8 commits - sc/source

Markus Mohrhard mmohrhard at kemper.freedesktop.org
Fri Jun 1 10:52:36 PDT 2012


 sc/source/filter/xml/xmlcelli.cxx |   93 +++++++++-----------------------------
 sc/source/filter/xml/xmlcelli.hxx |    6 --
 sc/source/filter/xml/xmlsubti.cxx |   75 +++++++++++++++++-------------
 sc/source/filter/xml/xmlsubti.hxx |   19 ++++---
 4 files changed, 79 insertions(+), 114 deletions(-)

New commits:
commit ba1951f3d0ab18f38d71896480bf62312895327d
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Fri Jun 1 19:50:46 2012 +0200

    use isEmpty instead of getLength == 0
    
    Change-Id: I755711cabae8e9a7b6f3d60658580a49fdebab8e

diff --git a/sc/source/filter/xml/xmlsubti.cxx b/sc/source/filter/xml/xmlsubti.cxx
index 7c48ad1..4d93a21 100644
--- a/sc/source/filter/xml/xmlsubti.cxx
+++ b/sc/source/filter/xml/xmlsubti.cxx
@@ -811,7 +811,7 @@ void ScMyTables::SetMatrix(const ScRange& rScRange, const rtl::OUString& rFormul
     aMark.SelectTable( rScRange.aStart.Tab(), sal_True );
     ScTokenArray* pCode = new ScTokenArray;
     pCode->AddStringXML( rFormula );
-    if( (eGrammar == formula::FormulaGrammar::GRAM_EXTERNAL) && (rFormulaNmsp.getLength() > 0) )
+    if( (eGrammar == formula::FormulaGrammar::GRAM_EXTERNAL) && (!rFormulaNmsp.isEmpty() > 0) )
         pCode->AddStringXML( rFormulaNmsp );
     pDoc->InsertMatrixFormula(
         rScRange.aStart.Col(), rScRange.aStart.Row(),
commit 57f7595fef2d5626eb26680a4f102ac548743541
Author: Daniel Bankston <daniel.e.bankston at gmail.com>
Date:   Sat May 26 02:54:41 2012 -0500

    Remove ScDocFunc calls and unnecessary checks from ODS import for merged cells
    
    It seems only one line was actually needed from ScDocFunc::MergeCells() during
    ODS import, which was the call to ScDocument::DoMerge().  Also, IsMerged()
    and unmerging is not needed during ODS import.
    
    Change-Id: Ieec5abf8c4c8ce52df16cece77ffe1a1574e6397

diff --git a/sc/source/filter/xml/xmlcelli.cxx b/sc/source/filter/xml/xmlcelli.cxx
index 1261c04..6305774 100644
--- a/sc/source/filter/xml/xmlcelli.cxx
+++ b/sc/source/filter/xml/xmlcelli.cxx
@@ -41,9 +41,7 @@
 #include "unonames.hxx"
 #include "postit.hxx"
 #include "sheetdata.hxx"
-#include "cellmergeoption.hxx"
 #include "docsh.hxx"
-#include "docfunc.hxx"
 
 #include "XMLTableShapeImportHelper.hxx"
 #include "XMLTextPContext.hxx"
@@ -453,69 +451,16 @@ SvXMLImportContext *ScXMLTableRowCellContext::CreateChildContext( sal_uInt16 nPr
     return pContext;
 }
 
-namespace {
-
-static bool ScCellExists( const ScAddress& rScAddress )
-{
-    return( rScAddress.Col() <= MAXCOL && rScAddress.Row() <= MAXROW );
-}
-
-void merge( ScDocShell* pDocSh, const ScRange& rScRange, const bool bMerge )
-{
-    if( pDocSh )
-    {
-        ScCellMergeOption aMergeOption(
-            rScRange.aStart.Col(), rScRange.aStart.Row(),
-            rScRange.aEnd.Col(), rScRange.aEnd.Row(), false
-        );
-        aMergeOption.maTabs.insert( rScRange.aStart.Tab() );
-        if ( bMerge )
-            pDocSh->GetDocFunc().MergeCells( aMergeOption, false, true, true );
-        else
-            pDocSh->GetDocFunc().UnmergeCells( aMergeOption, true, true );
-    }
-}
-
-} //anonymous namespace
-
-bool ScXMLTableRowCellContext::IsMerged( ScRange& rScRange, const ScAddress& rScCell ) const
+void ScXMLTableRowCellContext::DoMerge( const ScAddress& rScAddress, const SCCOL nCols, const SCROW nRows )
 {
-    if( ScCellExists(rScCell) )
+    SCCOL mergeToCol = rScAddress.Col() + nCols;
+    SCROW mergeToRow = rScAddress.Row() + nRows;
+    bool bInBounds = rScAddress.Col() <= MAXCOL && rScAddress.Row() <= MAXROW &&
+                       mergeToCol <= MAXCOL && mergeToRow <= MAXROW;
+    if( bInBounds )
     {
-        ScDocument* pDoc = rXMLImport.GetDocument();
-        pDoc->ExtendOverlapped( rScRange );
-        pDoc->ExtendMerge( rScRange );
-        rScRange.Justify();
-        if( rScRange.aStart.Col() == rScCell.Col() && rScRange.aEnd.Col() == rScCell.Col() &&
-            rScRange.aStart.Row() == rScCell.Row() && rScRange.aEnd.Row() == rScCell.Row() )
-            return false;
-        else
-            return true;
-    }
-    return false;
-}
-
-void ScXMLTableRowCellContext::DoMerge( const ScAddress& rScCellPos, const SCCOL nCols, const SCROW nRows )
-{
-    if( ScCellExists(rScCellPos) )
-    {
-        SCTAB nCurrentSheet = GetScImport().GetTables().GetCurrentSheet();
-        ScRange aScRange(
-            rScCellPos.Col(), rScCellPos.Row(), nCurrentSheet,
-            rScCellPos.Col(), rScCellPos.Row(), nCurrentSheet
-        );
-        ScDocShell* pDocSh = static_cast< ScDocShell* >( rXMLImport.GetDocument()->GetDocumentShell() );
-        if( IsMerged(aScRange, rScCellPos) )
-        {
-            //unmerge
-            merge( pDocSh, aScRange, false );
-        }
-        //merge
-        SCCOL newEndCol = aScRange.aStart.Col() + nCols;
-        SCROW newEndRow = aScRange.aStart.Row() + nRows;
-        aScRange.aEnd.SetCol( newEndCol );
-        aScRange.aEnd.SetRow( newEndRow );
-        merge( pDocSh, aScRange, true );
+        rXMLImport.GetDocument()->DoMerge( rScAddress.Tab(),
+            rScAddress.Col(), rScAddress.Row(), mergeToCol, mergeToRow );
     }
 }
 
diff --git a/sc/source/filter/xml/xmlcelli.hxx b/sc/source/filter/xml/xmlcelli.hxx
index 9cdcac5..70137f0 100644
--- a/sc/source/filter/xml/xmlcelli.hxx
+++ b/sc/source/filter/xml/xmlcelli.hxx
@@ -82,7 +82,6 @@ class ScXMLTableRowCellContext : public SvXMLImportContext
 
     sal_Int16 GetCellType(const rtl::OUString& sOUValue) const;
 
-    bool IsMerged(ScRange& rScRange, const ScAddress& rScCell) const;
     void DoMerge(const ScAddress& rScCellPos, const SCCOL nCols, const SCROW nRows);
 
     void SetContentValidation(com::sun::star::uno::Reference<com::sun::star::beans::XPropertySet>& xPropSet);
commit 369089180d724720b6c296d8a79db54a0d35e8c2
Author: Daniel Bankston <daniel.e.bankston at gmail.com>
Date:   Fri May 25 21:39:24 2012 -0500

    Remove header includes that are no longer used.
    
    Change-Id: I7096ab8f3b90a6235ae6efe7c42676f167d2d39b

diff --git a/sc/source/filter/xml/xmlsubti.cxx b/sc/source/filter/xml/xmlsubti.cxx
index 16d2b00..7c48ad1 100644
--- a/sc/source/filter/xml/xmlsubti.cxx
+++ b/sc/source/filter/xml/xmlsubti.cxx
@@ -40,9 +40,6 @@
 #include "XMLStylesImportHelper.hxx"
 #include "sheetdata.hxx"
 #include "tabprotection.hxx"
-#include "convuno.hxx"
-#include "docsh.hxx"
-#include "docfunc.hxx"
 #include "tokenarray.hxx"
 #include <svx/svdpage.hxx>
 
commit 07bfdbaa2d57403a7136079f4221ab2ed8f7c0b2
Author: Daniel Bankston <daniel.e.bankston at gmail.com>
Date:   Fri May 25 21:07:41 2012 -0500

    Remove ScDocFunc layer on ODS import for matrices
    
    Also, since it is unnecessary during import, removed code path where
    ScDocFunc::DeleteContents is called.
    
    Change-Id: Iafe2e261d27d674be6d5ec7f26edccc218879598

diff --git a/sc/source/filter/xml/xmlsubti.cxx b/sc/source/filter/xml/xmlsubti.cxx
index b830a6f..16d2b00 100644
--- a/sc/source/filter/xml/xmlsubti.cxx
+++ b/sc/source/filter/xml/xmlsubti.cxx
@@ -43,6 +43,7 @@
 #include "convuno.hxx"
 #include "docsh.hxx"
 #include "docfunc.hxx"
+#include "tokenarray.hxx"
 #include <svx/svdpage.hxx>
 
 #include <sax/tools/converter.hxx>
@@ -807,17 +808,20 @@ bool ScMyTables::IsPartOfMatrix(const SCCOL nColumn, const SCROW nRow)
 void ScMyTables::SetMatrix(const ScRange& rScRange, const rtl::OUString& rFormula,
         const rtl::OUString& rFormulaNmsp, const formula::FormulaGrammar::Grammar eGrammar)
 {
-    ScDocShell* pDocSh = static_cast< ScDocShell* >( rImport.GetDocument()->GetDocumentShell() );
-    if ( !rFormula.isEmpty() )
-        pDocSh->GetDocFunc().EnterMatrix( rScRange, NULL, NULL, rFormula, sal_True, sal_True, rFormulaNmsp, eGrammar );
-    else
-    {
-        //  empty string -> erase array formula
-        ScMarkData aMark;
-        aMark.SetMarkArea( rScRange );
-        aMark.SelectTable( rScRange.aStart.Tab(), sal_True );
-        pDocSh->GetDocFunc().DeleteContents( aMark, IDF_CONTENTS, sal_True, sal_True );
-    }
+    ScDocument* pDoc = rImport.GetDocument();
+    ScMarkData aMark;
+    aMark.SetMarkArea( rScRange );
+    aMark.SelectTable( rScRange.aStart.Tab(), sal_True );
+    ScTokenArray* pCode = new ScTokenArray;
+    pCode->AddStringXML( rFormula );
+    if( (eGrammar == formula::FormulaGrammar::GRAM_EXTERNAL) && (rFormulaNmsp.getLength() > 0) )
+        pCode->AddStringXML( rFormulaNmsp );
+    pDoc->InsertMatrixFormula(
+        rScRange.aStart.Col(), rScRange.aStart.Row(),
+        rScRange.aEnd.Col(), rScRange.aEnd.Row(),
+        aMark, EMPTY_STRING, pCode, eGrammar );
+    delete pCode;
+    pDoc->IncXMLImportedFormulaCount( rFormula.getLength() );
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit 66ff25666ddb390e5c4bddaaa7d706991297a975
Author: Daniel Bankston <daniel.e.bankston at gmail.com>
Date:   Fri May 25 17:22:21 2012 -0500

    Remove unnecessary code in ODS import for matrix and merge
    
    MyScTables matrix methods and ScXMLTableRowCellContext merge methods used
    getCellRangePosition() (that was adopted from ScCellRangeObj) which contains
    logic that is no longer necessary since since the UNO calls have been converted
    to direct Sc calls.
    
    Change-Id: Ibfa335860d142effb120d3e4f28a36d3d3c58666

diff --git a/sc/source/filter/xml/xmlcelli.cxx b/sc/source/filter/xml/xmlcelli.cxx
index a75cd7f..1261c04 100644
--- a/sc/source/filter/xml/xmlcelli.cxx
+++ b/sc/source/filter/xml/xmlcelli.cxx
@@ -460,29 +460,6 @@ static bool ScCellExists( const ScAddress& rScAddress )
     return( rScAddress.Col() <= MAXCOL && rScAddress.Row() <= MAXROW );
 }
 
-ScRange getCellRangeByPosition( const ScRange& rScRange, const SCCOL nLeft, const SCROW nTop, const SCCOL nRight, const SCROW nBottom )
-{
-    if( nLeft >= 0 && nTop >= 0 && nRight >= 0 && nBottom >= 0 )
-    {
-        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() )
-        {
-            return ScRange( nStartX, nStartY, rScRange.aStart.Tab(), nEndX, nEndY, rScRange.aEnd.Tab() );
-        }
-    }
-    return ScRange( ScAddress::INITIALIZE_INVALID );
-}
-
-ScRange getCellRangeByPosition( const ScRange& rScRange, const ScAddress& rScCell )
-{
-    return getCellRangeByPosition( rScRange, rScCell.Col(), rScCell.Row(), rScCell.Col(), rScCell.Row() );
-}
-
 void merge( ScDocShell* pDocSh, const ScRange& rScRange, const bool bMerge )
 {
     if( pDocSh )
@@ -501,18 +478,16 @@ void merge( ScDocShell* pDocSh, const ScRange& rScRange, const bool bMerge )
 
 } //anonymous namespace
 
-bool ScXMLTableRowCellContext::IsMerged( const ScRange& rScRange, const ScAddress& rScCell, ScRange& rScCellRange ) const
+bool ScXMLTableRowCellContext::IsMerged( ScRange& rScRange, const ScAddress& rScCell ) const
 {
     if( ScCellExists(rScCell) )
     {
         ScDocument* pDoc = rXMLImport.GetDocument();
-        rScCellRange = getCellRangeByPosition( rScRange, rScCell );
-        if( !rScRange.IsValid() ) return false;
-        pDoc->ExtendOverlapped( rScCellRange );
-        pDoc->ExtendMerge( rScCellRange );
-        rScCellRange.Justify();
-        if( rScCellRange.aStart.Col() == rScCell.Col() && rScCellRange.aEnd.Col() == rScCell.Col() &&
-            rScCellRange.aStart.Row() == rScCell.Row() && rScCellRange.aEnd.Row() == rScCell.Row() )
+        pDoc->ExtendOverlapped( rScRange );
+        pDoc->ExtendMerge( rScRange );
+        rScRange.Justify();
+        if( rScRange.aStart.Col() == rScCell.Col() && rScRange.aEnd.Col() == rScCell.Col() &&
+            rScRange.aStart.Row() == rScCell.Row() && rScRange.aEnd.Row() == rScCell.Row() )
             return false;
         else
             return true;
@@ -520,32 +495,27 @@ bool ScXMLTableRowCellContext::IsMerged( const ScRange& rScRange, const ScAddres
     return false;
 }
 
-void ScXMLTableRowCellContext::DoMerge( const ScAddress& rScCellPos, const sal_Int32 nCols, const sal_Int32 nRows )
+void ScXMLTableRowCellContext::DoMerge( const ScAddress& rScCellPos, const SCCOL nCols, const SCROW nRows )
 {
     if( ScCellExists(rScCellPos) )
     {
-        ScRange aScCellRange;
         SCTAB nCurrentSheet = GetScImport().GetTables().GetCurrentSheet();
-        ScRange aScRange( 0, 0, nCurrentSheet, MAXCOL, MAXROW, nCurrentSheet );  //the whole sheet
+        ScRange aScRange(
+            rScCellPos.Col(), rScCellPos.Row(), nCurrentSheet,
+            rScCellPos.Col(), rScCellPos.Row(), nCurrentSheet
+        );
         ScDocShell* pDocSh = static_cast< ScDocShell* >( rXMLImport.GetDocument()->GetDocumentShell() );
-        if( IsMerged(aScRange, rScCellPos, aScCellRange) )
+        if( IsMerged(aScRange, rScCellPos) )
         {
             //unmerge
-            ScRange aScMergeRange(
-                getCellRangeByPosition( aScRange, aScCellRange.aStart.Col(), aScCellRange.aStart.Row(),
-                    aScCellRange.aEnd.Col(), aScCellRange.aEnd.Row() )
-            );
-            if( aScMergeRange.IsValid() )
-                merge( pDocSh, aScMergeRange, false );
+            merge( pDocSh, aScRange, false );
         }
-
         //merge
-        ScRange aScMergeRange(
-            getCellRangeByPosition( aScRange, aScCellRange.aStart.Col(), aScCellRange.aStart.Row(),
-                aScCellRange.aEnd.Col() + nCols,  aScCellRange.aEnd.Row() + nRows )
-        );
-        if( aScMergeRange.IsValid() )
-            merge( pDocSh, aScMergeRange, true );
+        SCCOL newEndCol = aScRange.aStart.Col() + nCols;
+        SCROW newEndRow = aScRange.aStart.Row() + nRows;
+        aScRange.aEnd.SetCol( newEndCol );
+        aScRange.aEnd.SetRow( newEndRow );
+        merge( pDocSh, aScRange, true );
     }
 }
 
@@ -826,7 +796,7 @@ void ScXMLTableRowCellContext::EndElement()
         if (xCellRange.is())
         {
             if (bIsMerged)
-                DoMerge(aScCellPos, nMergedCols - 1, nMergedRows - 1);
+                DoMerge(aScCellPos, static_cast<SCCOL>(nMergedCols - 1), static_cast<SCROW>(nMergedRows - 1));
             if ( !pOUFormula )
             {
                 ::boost::optional< rtl::OUString > pOUText;
diff --git a/sc/source/filter/xml/xmlcelli.hxx b/sc/source/filter/xml/xmlcelli.hxx
index 4f8b4f9..9cdcac5 100644
--- a/sc/source/filter/xml/xmlcelli.hxx
+++ b/sc/source/filter/xml/xmlcelli.hxx
@@ -82,8 +82,8 @@ class ScXMLTableRowCellContext : public SvXMLImportContext
 
     sal_Int16 GetCellType(const rtl::OUString& sOUValue) const;
 
-    bool IsMerged(const ScRange& rScRange, const ScAddress& rScCell, ScRange& rScCellAddress) const;
-    void DoMerge(const ScAddress& rScCellPos, const sal_Int32 nCols, const sal_Int32 nRows);
+    bool IsMerged(ScRange& rScRange, const ScAddress& rScCell) const;
+    void DoMerge(const ScAddress& rScCellPos, const SCCOL nCols, const SCROW nRows);
 
     void SetContentValidation(com::sun::star::uno::Reference<com::sun::star::beans::XPropertySet>& xPropSet);
     void SetCellProperties(const com::sun::star::uno::Reference<com::sun::star::table::XCellRange>& xCellRange,
diff --git a/sc/source/filter/xml/xmlsubti.cxx b/sc/source/filter/xml/xmlsubti.cxx
index 9342961..b830a6f 100644
--- a/sc/source/filter/xml/xmlsubti.cxx
+++ b/sc/source/filter/xml/xmlsubti.cxx
@@ -804,44 +804,18 @@ bool ScMyTables::IsPartOfMatrix(const SCCOL nColumn, const SCROW nRow)
     return bResult;
 }
 
-namespace {
-
-ScRange getCellRangeByPosition( const ScRange& rScRange, const SCCOL nLeft, const SCROW nTop, const SCCOL nRight, const SCROW nBottom )
-{
-    if( nLeft >= 0 && nTop >= 0 && nRight >= 0 && nBottom >= 0 )
-    {
-        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() )
-        {
-            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 );
+        pDocSh->GetDocFunc().EnterMatrix( rScRange, 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 );
+        aMark.SetMarkArea( rScRange );
+        aMark.SelectTable( rScRange.aStart.Tab(), sal_True );
         pDocSh->GetDocFunc().DeleteContents( aMark, IDF_CONTENTS, sal_True, sal_True );
     }
 }
commit 2b47dd55a3ee886806277b5636517d3d97417bad
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 08be576..a75cd7f 100644
--- a/sc/source/filter/xml/xmlcelli.cxx
+++ b/sc/source/filter/xml/xmlcelli.cxx
@@ -332,8 +332,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)
                 {
@@ -909,7 +909,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
@@ -996,7 +996,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
@@ -1182,9 +1182,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 );
commit 60f8cef7df244b0e9219e770a8d9ae9d02fe237f
Author: Daniel Bankston <daniel.e.bankston at gmail.com>
Date:   Thu May 24 16:31:34 2012 -0500

    Make suggested code style changes
    
    Change-Id: I9cd71b78098adc6b0fee1139ffb1a1202d9981dc

diff --git a/sc/source/filter/xml/xmlcelli.cxx b/sc/source/filter/xml/xmlcelli.cxx
index cd74d73..08be576 100644
--- a/sc/source/filter/xml/xmlcelli.cxx
+++ b/sc/source/filter/xml/xmlcelli.cxx
@@ -453,64 +453,61 @@ SvXMLImportContext *ScXMLTableRowCellContext::CreateChildContext( sal_uInt16 nPr
     return pContext;
 }
 
-namespace
+namespace {
+
+static bool ScCellExists( const ScAddress& rScAddress )
 {
-    static bool lcl_ScCellExists( const ScAddress& rScAddress )
-    {
-        return( rScAddress.Col() <= MAXCOL && rScAddress.Row() <= MAXROW );
-    }
+    return( rScAddress.Col() <= MAXCOL && rScAddress.Row() <= MAXROW );
+}
 
-    static ScRange lcl_ScGetCellRangeByPosition( const ScRange& rScRange, const SCCOL nLeft, const SCROW nTop, const SCCOL nRight, const SCROW nBottom )
-        throw( lang::IndexOutOfBoundsException )
+ScRange getCellRangeByPosition( const ScRange& rScRange, const SCCOL nLeft, const SCROW nTop, const SCCOL nRight, const SCROW nBottom )
+{
+    if( nLeft >= 0 && nTop >= 0 && nRight >= 0 && nBottom >= 0 )
     {
-        if( nLeft >= 0 && nTop >= 0 && nRight >= 0 && nBottom >= 0 )
-        {
-            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() )
-            {
-                return ScRange( nStartX, nStartY, rScRange.aStart.Tab(), nEndX, nEndY, rScRange.aEnd.Tab() );
-            }
-        }
-        throw lang::IndexOutOfBoundsException();
-    }
+        SCCOL nStartX = rScRange.aStart.Col() + nLeft;
+        SCROW nStartY = rScRange.aStart.Row() + nTop;
+        SCCOL nEndX = rScRange.aStart.Col() + nRight;
+        SCROW nEndY = rScRange.aStart.Row() + nBottom;
 
-    static ScRange lcl_ScGetCellRangeByPosition( const ScRange& rScRange, const ScAddress& rScCell ) throw( lang::IndexOutOfBoundsException )
-    {
-        try
+        if( nStartX <= nEndX && nEndX <= rScRange.aEnd.Col() &&
+            nStartY <= nEndY && nEndY <= rScRange.aEnd.Row() )
         {
-            return lcl_ScGetCellRangeByPosition( rScRange, rScCell.Col(), rScCell.Row(), rScCell.Col(), rScCell.Row() );
+            return ScRange( nStartX, nStartY, rScRange.aStart.Tab(), nEndX, nEndY, rScRange.aEnd.Tab() );
         }
-        catch( lang::IndexOutOfBoundsException & ) { throw; }
     }
+    return ScRange( ScAddress::INITIALIZE_INVALID );
+}
+
+ScRange getCellRangeByPosition( const ScRange& rScRange, const ScAddress& rScCell )
+{
+    return getCellRangeByPosition( rScRange, rScCell.Col(), rScCell.Row(), rScCell.Col(), rScCell.Row() );
+}
 
-    static void lcl_ScMerge( ScDocShell* pDocSh, const ScRange& rScRange, const bool bMerge )
+void merge( ScDocShell* pDocSh, const ScRange& rScRange, const bool bMerge )
+{
+    if( pDocSh )
     {
-        if( pDocSh )
-        {
-            ScCellMergeOption aMergeOption(
-                rScRange.aStart.Col(), rScRange.aStart.Row(),
-                rScRange.aEnd.Col(), rScRange.aEnd.Row(), false
-            );
-            aMergeOption.maTabs.insert( rScRange.aStart.Tab() );
-            if ( bMerge )
-                pDocSh->GetDocFunc().MergeCells( aMergeOption, false, true, true );
-            else
-                pDocSh->GetDocFunc().UnmergeCells( aMergeOption, true, true );
-        }
+        ScCellMergeOption aMergeOption(
+            rScRange.aStart.Col(), rScRange.aStart.Row(),
+            rScRange.aEnd.Col(), rScRange.aEnd.Row(), false
+        );
+        aMergeOption.maTabs.insert( rScRange.aStart.Tab() );
+        if ( bMerge )
+            pDocSh->GetDocFunc().MergeCells( aMergeOption, false, true, true );
+        else
+            pDocSh->GetDocFunc().UnmergeCells( aMergeOption, true, true );
     }
 }
 
+} //anonymous namespace
+
 bool ScXMLTableRowCellContext::IsMerged( const ScRange& rScRange, const ScAddress& rScCell, ScRange& rScCellRange ) const
 {
-    if( lcl_ScCellExists(rScCell) )
+    if( ScCellExists(rScCell) )
     {
         ScDocument* pDoc = rXMLImport.GetDocument();
-        rScCellRange = lcl_ScGetCellRangeByPosition( rScRange, rScCell );
+        rScCellRange = getCellRangeByPosition( rScRange, rScCell );
+        if( !rScRange.IsValid() ) return false;
         pDoc->ExtendOverlapped( rScCellRange );
         pDoc->ExtendMerge( rScCellRange );
         rScCellRange.Justify();
@@ -525,38 +522,30 @@ bool ScXMLTableRowCellContext::IsMerged( const ScRange& rScRange, const ScAddres
 
 void ScXMLTableRowCellContext::DoMerge( const ScAddress& rScCellPos, const sal_Int32 nCols, const sal_Int32 nRows )
 {
-    if( lcl_ScCellExists(rScCellPos) )
+    if( ScCellExists(rScCellPos) )
     {
         ScRange aScCellRange;
         SCTAB nCurrentSheet = GetScImport().GetTables().GetCurrentSheet();
         ScRange aScRange( 0, 0, nCurrentSheet, MAXCOL, MAXROW, nCurrentSheet );  //the whole sheet
         ScDocShell* pDocSh = static_cast< ScDocShell* >( rXMLImport.GetDocument()->GetDocumentShell() );
-        // Stored merge range may actually be of a larger extend than what
-        // we support, in which case getCellRangeByPosition() throws
-        // IndexOutOfBoundsException. Do nothing then.        ???
-        try
+        if( IsMerged(aScRange, rScCellPos, aScCellRange) )
         {
-            if( IsMerged(aScRange, rScCellPos, aScCellRange) )
-            {
-                //unmerge
-                ScRange aScMergeRange(
-                    lcl_ScGetCellRangeByPosition( aScRange, aScCellRange.aStart.Col(), aScCellRange.aStart.Row(),
-                        aScCellRange.aEnd.Col(), aScCellRange.aEnd.Row() )
-                );
-                lcl_ScMerge( pDocSh, aScMergeRange, false );
-            }
-
-            //merge
+            //unmerge
             ScRange aScMergeRange(
-                lcl_ScGetCellRangeByPosition( aScRange, aScCellRange.aStart.Col(), aScCellRange.aStart.Row(),
-                    aScCellRange.aEnd.Col() + nCols,  aScCellRange.aEnd.Row() + nRows )
+                getCellRangeByPosition( aScRange, aScCellRange.aStart.Col(), aScCellRange.aStart.Row(),
+                    aScCellRange.aEnd.Col(), aScCellRange.aEnd.Row() )
             );
-            lcl_ScMerge( pDocSh, aScMergeRange, true );
-        }
-        catch( lang::IndexOutOfBoundsException & )
-        {
-            OSL_FAIL("ScXMLTableRowCellContext::DoMerge: range to be merged larger than what we support");
+            if( aScMergeRange.IsValid() )
+                merge( pDocSh, aScMergeRange, false );
         }
+
+        //merge
+        ScRange aScMergeRange(
+            getCellRangeByPosition( aScRange, aScCellRange.aStart.Col(), aScCellRange.aStart.Row(),
+                aScCellRange.aEnd.Col() + nCols,  aScCellRange.aEnd.Row() + nRows )
+        );
+        if( aScMergeRange.IsValid() )
+            merge( pDocSh, aScMergeRange, true );
     }
 }
 
diff --git a/sc/source/filter/xml/xmlsubti.cxx b/sc/source/filter/xml/xmlsubti.cxx
index ec633bf..5f33aca 100644
--- a/sc/source/filter/xml/xmlsubti.cxx
+++ b/sc/source/filter/xml/xmlsubti.cxx
@@ -685,8 +685,7 @@ table::CellAddress ScMyTables::GetRealCellPos()
     return aRealCellPos;
 }
 
-//placeholder; needs more work
-const ScAddress ScMyTables::GetRealScCellPos() const
+ScAddress ScMyTables::GetRealScCellPos() const
 {
     sal_Int32 nRow = 0;
     sal_Int32 nCol = 0;
diff --git a/sc/source/filter/xml/xmlsubti.hxx b/sc/source/filter/xml/xmlsubti.hxx
index 4fa41cb..6fa8161 100644
--- a/sc/source/filter/xml/xmlsubti.hxx
+++ b/sc/source/filter/xml/xmlsubti.hxx
@@ -171,7 +171,7 @@ public:
         { return ScMyOLEFixer::IsOLE(rShape); }
     void                                DeleteTable();
     com::sun::star::table::CellAddress  GetRealCellPos();
-    const ScAddress                     GetRealScCellPos() const;
+    ScAddress                           GetRealScCellPos() const;
     void                                AddColCount(sal_Int32 nTempColCount);
     void                                AddColStyle(const sal_Int32 nRepeat, const rtl::OUString& rCellStyleName);
     ScXMLTabProtectionData&             GetCurrentProtectionData() { return maProtectionData; }
commit 119b7085ee77c7bd033059332766e66cdcc81fec
Author: Daniel Bankston <daniel.e.bankston at gmail.com>
Date:   Thu May 24 06:05:15 2012 -0500

    Convert ODS import merge methods to use direct Sc calls
    
    During ODS import, ScXMLTableRowCellContext::DoMerge() and
    ScXMLTableRowCellContext::IsMerged() are used to handle merged cells.
    These methods now use direct Sc calls instead of UNO calls.
    
    Change-Id: Ie9a0cd743aca67ee8bc841c2c2133ad67444efca

diff --git a/sc/source/filter/xml/xmlcelli.cxx b/sc/source/filter/xml/xmlcelli.cxx
index dcab782..cd74d73 100644
--- a/sc/source/filter/xml/xmlcelli.cxx
+++ b/sc/source/filter/xml/xmlcelli.cxx
@@ -41,6 +41,9 @@
 #include "unonames.hxx"
 #include "postit.hxx"
 #include "sheetdata.hxx"
+#include "cellmergeoption.hxx"
+#include "docsh.hxx"
+#include "docfunc.hxx"
 
 #include "XMLTableShapeImportHelper.hxx"
 #include "XMLTextPContext.hxx"
@@ -450,68 +453,109 @@ SvXMLImportContext *ScXMLTableRowCellContext::CreateChildContext( sal_uInt16 nPr
     return pContext;
 }
 
-bool ScXMLTableRowCellContext::IsMerged (const uno::Reference <table::XCellRange>& xCellRange, const sal_Int32 nCol, const sal_Int32 nRow,
-                            table::CellRangeAddress& aCellAddress) const
+namespace
 {
-    table::CellAddress aCell; // don't need to set the sheet, because every sheet can contain the same count of cells.
-    aCell.Column = nCol;
-    aCell.Row = nRow;
-    if (CellExists(aCell))
+    static bool lcl_ScCellExists( const ScAddress& rScAddress )
     {
-        uno::Reference<sheet::XSheetCellRange> xMergeSheetCellRange (xCellRange->getCellRangeByPosition(nCol,nRow,nCol,nRow), uno::UNO_QUERY);
-        uno::Reference<sheet::XSpreadsheet> xTable (xMergeSheetCellRange->getSpreadsheet());
-        uno::Reference<sheet::XSheetCellCursor> xMergeSheetCursor (xTable->createCursorByRange(xMergeSheetCellRange));
-        if (xMergeSheetCursor.is())
+        return( rScAddress.Col() <= MAXCOL && rScAddress.Row() <= MAXROW );
+    }
+
+    static ScRange lcl_ScGetCellRangeByPosition( const ScRange& rScRange, const SCCOL nLeft, const SCROW nTop, const SCCOL nRight, const SCROW nBottom )
+        throw( lang::IndexOutOfBoundsException )
+    {
+        if( nLeft >= 0 && nTop >= 0 && nRight >= 0 && nBottom >= 0 )
         {
-            xMergeSheetCursor->collapseToMergedArea();
-            uno::Reference<sheet::XCellRangeAddressable> xMergeCellAddress (xMergeSheetCursor, uno::UNO_QUERY);
-            if (xMergeCellAddress.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() )
             {
-                aCellAddress = xMergeCellAddress->getRangeAddress();
-                if (aCellAddress.StartColumn == nCol && aCellAddress.EndColumn == nCol &&
-                    aCellAddress.StartRow == nRow && aCellAddress.EndRow == nRow)
-                    return false;
-                else
-                    return true;
+                return ScRange( nStartX, nStartY, rScRange.aStart.Tab(), nEndX, nEndY, rScRange.aEnd.Tab() );
             }
         }
+        throw lang::IndexOutOfBoundsException();
+    }
+
+    static ScRange lcl_ScGetCellRangeByPosition( const ScRange& rScRange, const ScAddress& rScCell ) throw( lang::IndexOutOfBoundsException )
+    {
+        try
+        {
+            return lcl_ScGetCellRangeByPosition( rScRange, rScCell.Col(), rScCell.Row(), rScCell.Col(), rScCell.Row() );
+        }
+        catch( lang::IndexOutOfBoundsException & ) { throw; }
+    }
+
+    static void lcl_ScMerge( ScDocShell* pDocSh, const ScRange& rScRange, const bool bMerge )
+    {
+        if( pDocSh )
+        {
+            ScCellMergeOption aMergeOption(
+                rScRange.aStart.Col(), rScRange.aStart.Row(),
+                rScRange.aEnd.Col(), rScRange.aEnd.Row(), false
+            );
+            aMergeOption.maTabs.insert( rScRange.aStart.Tab() );
+            if ( bMerge )
+                pDocSh->GetDocFunc().MergeCells( aMergeOption, false, true, true );
+            else
+                pDocSh->GetDocFunc().UnmergeCells( aMergeOption, true, true );
+        }
+    }
+}
+
+bool ScXMLTableRowCellContext::IsMerged( const ScRange& rScRange, const ScAddress& rScCell, ScRange& rScCellRange ) const
+{
+    if( lcl_ScCellExists(rScCell) )
+    {
+        ScDocument* pDoc = rXMLImport.GetDocument();
+        rScCellRange = lcl_ScGetCellRangeByPosition( rScRange, rScCell );
+        pDoc->ExtendOverlapped( rScCellRange );
+        pDoc->ExtendMerge( rScCellRange );
+        rScCellRange.Justify();
+        if( rScCellRange.aStart.Col() == rScCell.Col() && rScCellRange.aEnd.Col() == rScCell.Col() &&
+            rScCellRange.aStart.Row() == rScCell.Row() && rScCellRange.aEnd.Row() == rScCell.Row() )
+            return false;
+        else
+            return true;
     }
     return false;
 }
 
-void ScXMLTableRowCellContext::DoMerge(const com::sun::star::table::CellAddress& aCellPos,
-                 const sal_Int32 nCols, const sal_Int32 nRows)
+void ScXMLTableRowCellContext::DoMerge( const ScAddress& rScCellPos, const sal_Int32 nCols, const sal_Int32 nRows )
 {
-    if (CellExists(aCellPos))
+    if( lcl_ScCellExists(rScCellPos) )
     {
-        uno::Reference<table::XCellRange> xCellRange(rXMLImport.GetTables().GetCurrentXCellRange());
-        if ( xCellRange.is() )
+        ScRange aScCellRange;
+        SCTAB nCurrentSheet = GetScImport().GetTables().GetCurrentSheet();
+        ScRange aScRange( 0, 0, nCurrentSheet, MAXCOL, MAXROW, nCurrentSheet );  //the whole sheet
+        ScDocShell* pDocSh = static_cast< ScDocShell* >( rXMLImport.GetDocument()->GetDocumentShell() );
+        // Stored merge range may actually be of a larger extend than what
+        // we support, in which case getCellRangeByPosition() throws
+        // IndexOutOfBoundsException. Do nothing then.        ???
+        try
         {
-            // Stored merge range may actually be of a larger extend than what
-            // we support, in which case getCellRangeByPosition() throws
-            // IndexOutOfBoundsException. Do nothing then.
-            try
-            {
-                table::CellRangeAddress aCellAddress;
-                if (IsMerged(xCellRange, aCellPos.Column, aCellPos.Row, aCellAddress))
-                {
-                    //unmerge
-                    uno::Reference <util::XMergeable> xMergeable (xCellRange->getCellRangeByPosition(aCellAddress.StartColumn, aCellAddress.StartRow,
-                                aCellAddress.EndColumn, aCellAddress.EndRow), uno::UNO_QUERY);
-                    if (xMergeable.is())
-                        xMergeable->merge(false);
-                }
-
-                //merge
-                uno::Reference <util::XMergeable> xMergeable (xCellRange->getCellRangeByPosition(aCellAddress.StartColumn, aCellAddress.StartRow,
-                            aCellAddress.EndColumn + nCols, aCellAddress.EndRow + nRows), uno::UNO_QUERY);
-                if (xMergeable.is())
-                    xMergeable->merge(true);
-            }
-            catch ( lang::IndexOutOfBoundsException & )
+            if( IsMerged(aScRange, rScCellPos, aScCellRange) )
             {
-                OSL_FAIL("ScXMLTableRowCellContext::DoMerge: range to be merged larger than what we support");
+                //unmerge
+                ScRange aScMergeRange(
+                    lcl_ScGetCellRangeByPosition( aScRange, aScCellRange.aStart.Col(), aScCellRange.aStart.Row(),
+                        aScCellRange.aEnd.Col(), aScCellRange.aEnd.Row() )
+                );
+                lcl_ScMerge( pDocSh, aScMergeRange, false );
             }
+
+            //merge
+            ScRange aScMergeRange(
+                lcl_ScGetCellRangeByPosition( aScRange, aScCellRange.aStart.Col(), aScCellRange.aStart.Row(),
+                    aScCellRange.aEnd.Col() + nCols,  aScCellRange.aEnd.Row() + nRows )
+            );
+            lcl_ScMerge( pDocSh, aScMergeRange, true );
+        }
+        catch( lang::IndexOutOfBoundsException & )
+        {
+            OSL_FAIL("ScXMLTableRowCellContext::DoMerge: range to be merged larger than what we support");
         }
     }
 }
@@ -783,11 +827,17 @@ void ScXMLTableRowCellContext::EndElement()
         table::CellAddress aCellPos = rTables.GetRealCellPos();
         if (aCellPos.Column > 0 && nRepeatedRows > 1)
             aCellPos.Row -= (nRepeatedRows - 1);
+
+        //duplicated for now
+        ScAddress aScCellPos = rTables.GetRealScCellPos();
+        if (aScCellPos.Col() > 0 && nRepeatedRows > 1)
+            aScCellPos.SetRow( aScCellPos.Row() - (nRepeatedRows - 1) );
+
         uno::Reference<table::XCellRange> xCellRange(rTables.GetCurrentXCellRange());
         if (xCellRange.is())
         {
             if (bIsMerged)
-                DoMerge(aCellPos, nMergedCols - 1, nMergedRows - 1);
+                DoMerge(aScCellPos, nMergedCols - 1, nMergedRows - 1);
             if ( !pOUFormula )
             {
                 ::boost::optional< rtl::OUString > pOUText;
diff --git a/sc/source/filter/xml/xmlcelli.hxx b/sc/source/filter/xml/xmlcelli.hxx
index 7a518ea..4f8b4f9 100644
--- a/sc/source/filter/xml/xmlcelli.hxx
+++ b/sc/source/filter/xml/xmlcelli.hxx
@@ -82,11 +82,8 @@ class ScXMLTableRowCellContext : public SvXMLImportContext
 
     sal_Int16 GetCellType(const rtl::OUString& sOUValue) const;
 
-    bool IsMerged (const com::sun::star::uno::Reference <com::sun::star::table::XCellRange>& xCellRange,
-                const sal_Int32 nCol, const sal_Int32 nRow,
-                com::sun::star::table::CellRangeAddress& aCellAddress) const;
-    void DoMerge(const com::sun::star::table::CellAddress& aCellPos,
-                 const sal_Int32 nCols, const sal_Int32 nRows);
+    bool IsMerged(const ScRange& rScRange, const ScAddress& rScCell, ScRange& rScCellAddress) const;
+    void DoMerge(const ScAddress& rScCellPos, const sal_Int32 nCols, const sal_Int32 nRows);
 
     void SetContentValidation(com::sun::star::uno::Reference<com::sun::star::beans::XPropertySet>& xPropSet);
     void SetCellProperties(const com::sun::star::uno::Reference<com::sun::star::table::XCellRange>& xCellRange,
diff --git a/sc/source/filter/xml/xmlsubti.cxx b/sc/source/filter/xml/xmlsubti.cxx
index aead6b7..ec633bf 100644
--- a/sc/source/filter/xml/xmlsubti.cxx
+++ b/sc/source/filter/xml/xmlsubti.cxx
@@ -40,6 +40,7 @@
 #include "XMLStylesImportHelper.hxx"
 #include "sheetdata.hxx"
 #include "tabprotection.hxx"
+#include "convuno.hxx"
 #include <svx/svdpage.hxx>
 
 #include <sax/tools/converter.hxx>
@@ -684,6 +685,21 @@ table::CellAddress ScMyTables::GetRealCellPos()
     return aRealCellPos;
 }
 
+//placeholder; needs more work
+const ScAddress ScMyTables::GetRealScCellPos() const
+{
+    sal_Int32 nRow = 0;
+    sal_Int32 nCol = 0;
+    size_t n = maTables.size();
+    for (size_t i = 0; i < n; ++i)
+    {
+        const ScMyTableData& rTab = maTables[i];
+        nCol += rTab.GetRealCols(rTab.GetColumn());
+        nRow += rTab.GetRealRows(rTab.GetRow());
+    }
+    return ScAddress( static_cast<SCCOL>(nCol), static_cast<SCCOL>(nRow), nCurrentSheet );
+}
+
 void ScMyTables::AddColCount(sal_Int32 nTempColCount)
 {
     pCurrentTab->SetColCount(pCurrentTab->GetColCount() + nTempColCount);
diff --git a/sc/source/filter/xml/xmlsubti.hxx b/sc/source/filter/xml/xmlsubti.hxx
index cf37bcf..4fa41cb 100644
--- a/sc/source/filter/xml/xmlsubti.hxx
+++ b/sc/source/filter/xml/xmlsubti.hxx
@@ -171,6 +171,7 @@ public:
         { return ScMyOLEFixer::IsOLE(rShape); }
     void                                DeleteTable();
     com::sun::star::table::CellAddress  GetRealCellPos();
+    const ScAddress                     GetRealScCellPos() const;
     void                                AddColCount(sal_Int32 nTempColCount);
     void                                AddColStyle(const sal_Int32 nRepeat, const rtl::OUString& rCellStyleName);
     ScXMLTabProtectionData&             GetCurrentProtectionData() { return maProtectionData; }


More information about the Libreoffice-commits mailing list