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

Eike Rathke erack at redhat.com
Fri Jun 16 14:27:19 UTC 2017


 sc/source/ui/view/viewfun2.cxx |   34 +++++++++++++++++++++-------------
 1 file changed, 21 insertions(+), 13 deletions(-)

New commits:
commit b3947785202ac263671113d6c9fd57d3ce6208d5
Author: Eike Rathke <erack at redhat.com>
Date:   Fri Jun 16 16:26:13 2017 +0200

    But not empty top/left in AutoSum of SUMs final selection, tdf#71339
    
    This was even more confusing than previously..
    
    Change-Id: I9cbdd05e9b59662dfde4a08422d0d2846849719f

diff --git a/sc/source/ui/view/viewfun2.cxx b/sc/source/ui/view/viewfun2.cxx
index 3d67909bc3b7..2d5338dfa5c4 100644
--- a/sc/source/ui/view/viewfun2.cxx
+++ b/sc/source/ui/view/viewfun2.cxx
@@ -291,13 +291,13 @@ static bool lcl_FindNextSumEntryInRow( ScDocument* pDoc, SCCOL& nCol, SCROW nRow
     return eSkip == ScAutoSumSum && nCol < nTmp;
 }
 
-static bool lcl_GetAutoSumForColumnRange( ScDocument* pDoc, ScRangeList& rRangeList, const ScRange& rRange )
+static ScAutoSum lcl_GetAutoSumForColumnRange( ScDocument* pDoc, ScRangeList& rRangeList, const ScRange& rRange )
 {
     const ScAddress aStart = rRange.aStart;
     const ScAddress aEnd = rRange.aEnd;
     if ( aStart.Col() != aEnd.Col() )
     {
-        return false;
+        return ScAutoSumNone;
     }
 
     const SCTAB nTab = aEnd.Tab();
@@ -305,7 +305,7 @@ static bool lcl_GetAutoSumForColumnRange( ScDocument* pDoc, ScRangeList& rRangeL
     SCROW nEndRow = aEnd.Row();
     SCROW nStartRow = nEndRow;
     SCCOLROW nExtend = 0;
-    const ScAutoSum eSum = lcl_IsAutoSumData( pDoc, nCol, nEndRow, nTab, DIR_TOP, nExtend /*out*/ );
+    ScAutoSum eSum = lcl_IsAutoSumData( pDoc, nCol, nEndRow, nTab, DIR_TOP, nExtend /*out*/ );
 
     if ( eSum == ScAutoSumSum )
     {
@@ -324,23 +324,25 @@ static bool lcl_GetAutoSumForColumnRange( ScDocument* pDoc, ScRangeList& rRangeL
     else
     {
         while ( nStartRow > aStart.Row() &&
-                lcl_IsAutoSumData( pDoc, nCol, nStartRow-1, nTab, DIR_TOP, nExtend /*out*/ ) != ScAutoSumSum )
+                (eSum = lcl_IsAutoSumData( pDoc, nCol, nStartRow-1, nTab, DIR_TOP, nExtend /*out*/ )) != ScAutoSumSum )
         {
             --nStartRow;
         }
         rRangeList.Append( ScRange( nCol, nStartRow, nTab, nCol, nEndRow, nTab ) );
+        if (eSum == ScAutoSumNone)
+            eSum = ScAutoSumData;
     }
 
-    return true;
+    return eSum;
 }
 
-static bool lcl_GetAutoSumForRowRange( ScDocument* pDoc, ScRangeList& rRangeList, const ScRange& rRange )
+static ScAutoSum lcl_GetAutoSumForRowRange( ScDocument* pDoc, ScRangeList& rRangeList, const ScRange& rRange )
 {
     const ScAddress aStart = rRange.aStart;
     const ScAddress aEnd = rRange.aEnd;
     if ( aStart.Row() != aEnd.Row() )
     {
-        return false;
+        return ScAutoSumNone;
     }
 
     const SCTAB nTab = aEnd.Tab();
@@ -348,7 +350,7 @@ static bool lcl_GetAutoSumForRowRange( ScDocument* pDoc, ScRangeList& rRangeList
     SCCOL nEndCol = aEnd.Col();
     SCCOL nStartCol = nEndCol;
     SCCOLROW nExtend = 0;
-    const ScAutoSum eSum = lcl_IsAutoSumData( pDoc, nEndCol, nRow, nTab, DIR_LEFT, nExtend /*out*/ );
+    ScAutoSum eSum = lcl_IsAutoSumData( pDoc, nEndCol, nRow, nTab, DIR_LEFT, nExtend /*out*/ );
 
     if ( eSum == ScAutoSumSum )
     {
@@ -367,14 +369,16 @@ static bool lcl_GetAutoSumForRowRange( ScDocument* pDoc, ScRangeList& rRangeList
     else
     {
         while ( nStartCol > aStart.Col() &&
-                lcl_IsAutoSumData( pDoc, nStartCol-1, nRow, nTab, DIR_LEFT, nExtend /*out*/ ) != ScAutoSumSum )
+                (eSum = lcl_IsAutoSumData( pDoc, nStartCol-1, nRow, nTab, DIR_LEFT, nExtend /*out*/ )) != ScAutoSumSum )
         {
             --nStartCol;
         }
         rRangeList.Append( ScRange( nStartCol, nRow, nTab, nEndCol, nRow, nTab ) );
+        if (eSum == ScAutoSumNone)
+            eSum = ScAutoSumData;
     }
 
-    return true;
+    return eSum;
 }
 
 bool ScViewFunc::GetAutoSumArea( ScRangeList& rRangeList )
@@ -609,6 +613,7 @@ bool ScViewFunc::AutoSum( const ScRange& rRange, bool bSubTotal, bool bSetCursor
 
     SCCOL nMarkEndCol = nEndCol;
     SCROW nMarkEndRow = nEndRow;
+    ScAutoSum eSum = ScAutoSumNone;
 
     if ( bRow )
     {
@@ -635,7 +640,7 @@ bool ScViewFunc::AutoSum( const ScRange& rRange, bool bSubTotal, bool bSetCursor
                 ScRangeList aRangeList;
                 // Include the originally selected start row.
                 const ScRange aRange( nCol, rRange.aStart.Row(), nTab, nCol, nSumEndRow, nTab );
-                if ( lcl_GetAutoSumForColumnRange( pDoc, aRangeList, aRange ) )
+                if ( (eSum = lcl_GetAutoSumForColumnRange( pDoc, aRangeList, aRange )) != ScAutoSumNone )
                 {
                     const OUString aFormula = GetAutoSumFormula(
                         aRangeList, bSubTotal, ScAddress(nCol, nInsRow, nTab));
@@ -670,7 +675,7 @@ bool ScViewFunc::AutoSum( const ScRange& rRange, bool bSubTotal, bool bSetCursor
                 ScRangeList aRangeList;
                 // Include the originally selected start column.
                 const ScRange aRange( rRange.aStart.Col(), nRow, nTab, nSumEndCol, nRow, nTab );
-                if ( lcl_GetAutoSumForRowRange( pDoc, aRangeList, aRange ) )
+                if ( (eSum = lcl_GetAutoSumForRowRange( pDoc, aRangeList, aRange )) != ScAutoSumNone )
                 {
                     const OUString aFormula = GetAutoSumFormula( aRangeList, bSubTotal, ScAddress(nInsCol, nRow, nTab) );
                     EnterData( nInsCol, nRow, nTab, aFormula );
@@ -680,7 +685,10 @@ bool ScViewFunc::AutoSum( const ScRange& rRange, bool bSubTotal, bool bSetCursor
     }
 
     // set new mark range and cursor position
-    const ScRange aMarkRange( rRange.aStart.Col(), rRange.aStart.Row(), nTab, nMarkEndCol, nMarkEndRow, nTab );
+    const ScRange aMarkRange(
+            (eSum == ScAutoSumSum ? nStartCol : rRange.aStart.Col()),
+            (eSum == ScAutoSumSum ? nStartRow : rRange.aStart.Row()),
+            nTab, nMarkEndCol, nMarkEndRow, nTab );
     MarkRange( aMarkRange, false, bContinue );
     if ( bSetCursor )
     {


More information about the Libreoffice-commits mailing list