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

Eike Rathke (via logerrit) logerrit at kemper.freedesktop.org
Tue Nov 12 16:04:47 UTC 2019


 sc/inc/address.hxx               |    1 
 sc/inc/document.hxx              |    3 -
 sc/inc/table.hxx                 |    2 
 sc/source/core/data/document.cxx |    4 -
 sc/source/core/data/table1.cxx   |   97 +++++++++++++++++++++++++--------------
 sc/source/ui/inc/viewdata.hxx    |    1 
 sc/source/ui/view/tabview3.cxx   |   14 +----
 7 files changed, 72 insertions(+), 50 deletions(-)

New commits:
commit 25160a56f4fd8a18c27eaa77b0539ab267b80294
Author:     Eike Rathke <erack at redhat.com>
AuthorDate: Tue Nov 12 14:15:13 2019 +0100
Commit:     Eike Rathke <erack at redhat.com>
CommitDate: Tue Nov 12 17:03:26 2019 +0100

    Resolves: tdf#122232 Move TabStartCol logic to ScTable::GetNextPos()
    
    ... instead of blindly applying it to every move if set.
    
    Change-Id: Ief2efb4eb2288cd479852d5a250c2523715de38b
    Reviewed-on: https://gerrit.libreoffice.org/82513
    Reviewed-by: Eike Rathke <erack at redhat.com>
    Tested-by: Jenkins

diff --git a/sc/inc/address.hxx b/sc/inc/address.hxx
index 9af77284a986..c879cdc6a6d0 100644
--- a/sc/inc/address.hxx
+++ b/sc/inc/address.hxx
@@ -84,6 +84,7 @@ const SCTAB TABLEID_DOC       = SCTAB_MAX;  // entire document, e.g. protect
 const SCROW SCROWS32K         = 32000; // for fuzzing
 const SCCOL SCCOL_REPEAT_NONE = SCCOL_MAX;
 const SCROW SCROW_REPEAT_NONE = SCROW_MAX;
+const SCCOL SC_TABSTART_NONE  = SCCOL_MAX;
 
 const SCROW MAXROW_30         = 8191;
 
diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index 171ec8c1624a..6b3f8f6ecbb3 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -1454,7 +1454,8 @@ public:
 
     void               FindAreaPos( SCCOL& rCol, SCROW& rRow, SCTAB nTab, ScMoveDirection eDirection ) const;
     SC_DLLPUBLIC void  GetNextPos( SCCOL& rCol, SCROW& rRow, SCTAB nTab, SCCOL nMovX, SCROW nMovY,
-                                   bool bMarked, bool bUnprotected, const ScMarkData& rMark ) const;
+                                   bool bMarked, bool bUnprotected, const ScMarkData& rMark,
+                                   SCCOL nTabStartCol = SC_TABSTART_NONE ) const;
 
     bool               GetNextMarkedCell( SCCOL& rCol, SCROW& rRow, SCTAB nTab,
                                           const ScMarkData& rMark );
diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx
index 823b3f7bafde..91063a82481e 100644
--- a/sc/inc/table.hxx
+++ b/sc/inc/table.hxx
@@ -588,7 +588,7 @@ public:
 
     void        FindAreaPos( SCCOL& rCol, SCROW& rRow, ScMoveDirection eDirection ) const;
     void        GetNextPos( SCCOL& rCol, SCROW& rRow, SCCOL nMovX, SCROW nMovY,
-                                bool bMarked, bool bUnprotected, const ScMarkData& rMark ) const;
+                            bool bMarked, bool bUnprotected, const ScMarkData& rMark, SCCOL nTabStartCol ) const;
 
     bool        SkipRow( const SCCOL rCol, SCROW& rRow, const SCROW nMovY, const ScMarkData& rMark,
                          const bool bUp, const SCROW nUsedY, const bool bMarked, const bool bSheetProtected ) const;
diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index f6414450b55d..ec4a0e3e610a 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -6073,7 +6073,7 @@ void ScDocument::FindAreaPos( SCCOL& rCol, SCROW& rRow, SCTAB nTab, ScMoveDirect
 }
 
 void ScDocument::GetNextPos( SCCOL& rCol, SCROW& rRow, SCTAB nTab, SCCOL nMovX, SCROW nMovY,
-                                bool bMarked, bool bUnprotected, const ScMarkData& rMark ) const
+        bool bMarked, bool bUnprotected, const ScMarkData& rMark, SCCOL nTabStartCol ) const
 {
     OSL_ENSURE( !nMovX || !nMovY, "GetNextPos: only X or Y" );
 
@@ -6082,7 +6082,7 @@ void ScDocument::GetNextPos( SCCOL& rCol, SCROW& rRow, SCTAB nTab, SCCOL nMovX,
     aCopyMark.MarkToMulti();
 
     if (ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab])
-        maTabs[nTab]->GetNextPos( rCol, rRow, nMovX, nMovY, bMarked, bUnprotected, aCopyMark );
+        maTabs[nTab]->GetNextPos( rCol, rRow, nMovX, nMovY, bMarked, bUnprotected, aCopyMark, nTabStartCol );
 }
 
 //  Data operations
diff --git a/sc/source/core/data/table1.cxx b/sc/source/core/data/table1.cxx
index a7f8991c0276..7a2e740bb721 100644
--- a/sc/source/core/data/table1.cxx
+++ b/sc/source/core/data/table1.cxx
@@ -1386,7 +1386,7 @@ bool ScTable::SkipRow( const SCCOL nCol, SCROW& rRow, const SCROW nMovY,
 }
 
 void ScTable::GetNextPos( SCCOL& rCol, SCROW& rRow, SCCOL nMovX, SCROW nMovY,
-                                bool bMarked, bool bUnprotected, const ScMarkData& rMark ) const
+        bool bMarked, bool bUnprotected, const ScMarkData& rMark, SCCOL nTabStartCol ) const
 {
     // Ensure bMarked is set only if there is a mark.
     assert( !bMarked || rMark.IsMarked() || rMark.IsMultiMarked());
@@ -1447,53 +1447,82 @@ void ScTable::GetNextPos( SCCOL& rCol, SCROW& rRow, SCCOL nMovX, SCROW nMovY,
             rCol = nCol;
             rRow = nRow;
         }
+
+        // Caller ensures actually moving nMovY to jump to prev/next row's
+        // start col.
+        if (nTabStartCol != SC_TABSTART_NONE)
+            rCol = nTabStartCol;
+
         return;
     }
 
     if ( nMovY && (bMarked || bUnprotected))
     {
-        bool bUp = (nMovY < 0);
-        const SCCOL nColAdd = (bUp ? -1 : 1);
-        sal_uInt16 nWrap = 0;
-
-        if (bMarked)
-            nRow = rMark.GetNextMarked( nCol, nRow, bUp );
-
-        while ( SkipRow( nCol, nRow, nMovY, rMark, bUp, nEndRow, bMarked, bSheetProtected ))
-            ;
-
-        while ( nRow < nStartRow || nRow > nEndRow )
+        do
         {
-            nCol += nColAdd;
+            const bool bUp = (nMovY < 0);
+            const SCCOL nColAdd = (bUp ? -1 : 1);
 
-            while (nStartCol <= nCol && nCol <= nEndCol && ValidCol(nCol) && ColHidden(nCol))
-                nCol += nColAdd;    //  skip hidden cols
+            if (bMarked)
+                nRow = rMark.GetNextMarked( nCol, nRow, bUp );
 
-            if (nCol < nStartCol)
+            if (nTabStartCol != SC_TABSTART_NONE)
             {
-                nCol = nEndCol;
-
-                if (++nWrap >= 2)
-                    return;
+                /* NOTE: If current rCol < nTabStartCol when going down, there
+                 * is no way to detect if the previous Tab wrapped around to
+                 * the next row or if it was a Shift+Tab going backwards. The
+                 * result after a wrap is an odd jump to the next row's
+                 * nTabStartCol, which is logical though and always has been
+                 * the case. Similar for rCol > nTabStartCol when going up.
+                 * Related, it would be nice to limit advancing the position
+                 * within bounds even if another wrap would occur, but again we
+                 * can't tell if previously Tab or Shift+Tab was used, so we
+                 * don't know if it would be nTabStartCol to nEndCol (for Tab)
+                 * or nStartCol to nTabStartCol (for Shift+Tab). */
+
+                // Continue moving horizontally.
+                nMovX = nColAdd;
+                nCol = nTabStartCol;
+                break;  // do
             }
-            else if (nCol > nEndCol)
+
+            while ( SkipRow( nCol, nRow, nMovY, rMark, bUp, nEndRow, bMarked, bSheetProtected ))
+                ;
+
+            sal_uInt16 nWrap = 0;
+            while ( nRow < nStartRow || nRow > nEndRow )
             {
-                nCol = nStartCol;
+                nCol += nColAdd;
 
-                if (++nWrap >= 2)
-                    return;
-            }
-            if (nRow < nStartRow)
-                nRow = nEndRow;
-            else if (nRow > nEndRow)
-                nRow = nStartRow;
+                while (nStartCol <= nCol && nCol <= nEndCol && ValidCol(nCol) && ColHidden(nCol))
+                    nCol += nColAdd;    //  skip hidden cols
 
-            if (bMarked)
-                nRow = rMark.GetNextMarked( nCol, nRow, bUp );
+                if (nCol < nStartCol)
+                {
+                    nCol = nEndCol;
 
-            while ( SkipRow( nCol, nRow, nMovY, rMark, bUp, nEndRow, bMarked, bSheetProtected ))
-                ;
-        }
+                    if (++nWrap >= 2)
+                        return;
+                }
+                else if (nCol > nEndCol)
+                {
+                    nCol = nStartCol;
+
+                    if (++nWrap >= 2)
+                        return;
+                }
+                if (nRow < nStartRow)
+                    nRow = nEndRow;
+                else if (nRow > nEndRow)
+                    nRow = nStartRow;
+
+                if (bMarked)
+                    nRow = rMark.GetNextMarked( nCol, nRow, bUp );
+
+                while ( SkipRow( nCol, nRow, nMovY, rMark, bUp, nEndRow, bMarked, bSheetProtected ))
+                    ;
+            }
+        } while (false);
     }
 
     if ( nMovX && ( bMarked || bUnprotected ) )
diff --git a/sc/source/ui/inc/viewdata.hxx b/sc/source/ui/inc/viewdata.hxx
index 24dd5e69a275..1edfdeebd222 100644
--- a/sc/source/ui/inc/viewdata.hxx
+++ b/sc/source/ui/inc/viewdata.hxx
@@ -30,7 +30,6 @@
 #include <o3tl/typed_flags_set.hxx>
 
 #define SC_SIZE_NONE        65535
-const SCCOL SC_TABSTART_NONE = SCCOL_MAX;
 
 enum class ScFillMode
 {
diff --git a/sc/source/ui/view/tabview3.cxx b/sc/source/ui/view/tabview3.cxx
index dbe93c9e9f18..f512e8dd9127 100644
--- a/sc/source/ui/view/tabview3.cxx
+++ b/sc/source/ui/view/tabview3.cxx
@@ -1429,17 +1429,9 @@ void ScTabView::MoveCursorEnter( bool bShift )          // bShift -> up/down
     }
     else
     {
-        pDoc->GetNextPos( nNewX, nNewY, nTab, nMoveX, nMoveY, false, true, rMark );
-
-        if ( nMoveY != 0 && !nMoveX )
-        {
-            // after Tab and Enter back to the starting column again
-            SCCOL nTabCol = aViewData.GetTabStartCol();
-            if (nTabCol != SC_TABSTART_NONE)
-            {
-                nNewX = nTabCol;
-            }
-        }
+        // After Tab and Enter back to the starting column again.
+        const SCCOL nTabStartCol = ((nMoveY != 0 && !nMoveX) ? aViewData.GetTabStartCol() : SC_TABSTART_NONE);
+        pDoc->GetNextPos( nNewX, nNewY, nTab, nMoveX, nMoveY, false, true, rMark, nTabStartCol );
 
         MoveCursorRel( nNewX - nCurX, nNewY - nCurY, SC_FOLLOW_LINE, false);
     }


More information about the Libreoffice-commits mailing list