sc/source/filter/xml/xmlcelli.cxx |  119 +++++++++++++++++---------------------
 sc/source/filter/xml/xmlsubti.cxx |    3 
 sc/source/filter/xml/xmlsubti.hxx |    2 
 3 files changed, 56 insertions(+), 68 deletions(-)

New commits:
commit 1ddcc44190a690a3ac221a8c4b38d830046f03ef
Author: Daniel Bankston <daniel.e.banks...@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 9d1c7c0..89bf499 100644
--- a/sc/source/filter/xml/xmlcelli.cxx
+++ b/sc/source/filter/xml/xmlcelli.cxx
@@ -455,64 +455,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();
@@ -527,38 +524,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; }
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to