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

Markus Mohrhard mmohrhard at kemper.freedesktop.org
Sun Aug 5 16:00:56 PDT 2012


 sc/inc/column.hxx               |    3 
 sc/source/core/data/column2.cxx |  169 ++++++++++++++++++++++++++--------------
 2 files changed, 117 insertions(+), 55 deletions(-)

New commits:
commit 1e2964e55e6fc791b911998ca710a9f174c3d1ef
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Sun Aug 5 20:28:03 2012 +0200

    skip hidden rows when moving with the cursor, fdo#45020
    
    Change-Id: I3b12d774914599489dea2bb711b2d057111b677b

diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx
index 6f776e1..6bc8c8c 100644
--- a/sc/inc/column.hxx
+++ b/sc/inc/column.hxx
@@ -389,6 +389,9 @@ public:
 
 private:
     ScBaseCell* CloneCell(SCSIZE nIndex, sal_uInt16 nFlags, ScDocument& rDestDoc, const ScAddress& rDestPos);
+
+    SCROW FindNextVisibleRowWithContent(SCROW nRow, bool bForward) const;
+    SCROW FindNextVisibleRow(SCROW nRow, bool bForward) const;
 };
 
 
diff --git a/sc/source/core/data/column2.cxx b/sc/source/core/data/column2.cxx
index dba0fc6..f22fec0 100644
--- a/sc/source/core/data/column2.cxx
+++ b/sc/source/core/data/column2.cxx
@@ -1307,11 +1307,102 @@ bool ScColumn::GetNextDataPos(SCROW& rRow) const        // greater than rRow
     return bMore;
 }
 
+SCROW ScColumn::FindNextVisibleRow(SCROW nRow, bool bForward) const
+{
+    if(bForward)
+    {
+        nRow++;
+        SCROW nEndRow = 0;
+        bool bHidden = pDocument->RowHidden(nRow, nTab, NULL, &nEndRow);
+        if(bHidden)
+            return std::min<SCROW>(MAXROW, nEndRow + 1);
+        else
+            return nRow;
+    }
+    else
+    {
+        nRow--;
+        SCROW nStartRow = MAXROW;
+        bool bHidden = pDocument->RowHidden(nRow, nTab, &nStartRow, NULL);
+        if(bHidden)
+            return std::max<SCROW>(0, nStartRow - 1);
+        else
+            return nRow;
+    }
+}
+
+SCROW ScColumn::FindNextVisibleRowWithContent(SCROW nRow, bool bForward) const
+{
+    if(bForward)
+    {
+        bool bFound = false;
+        do
+        {
+            nRow++;
+            SCROW nEndRow = 0;
+            bool bHidden = pDocument->RowHidden(nRow, nTab, NULL, &nEndRow);
+            if(bHidden)
+            {
+                nRow = nEndRow + 1;
+                if(nRow >= MAXROW)
+                    return MAXROW;
+            }
+
+            SCSIZE nIndex;
+            bool bThere = Search( nRow, nIndex );
+            if( bThere && !maItems[nIndex].pCell->IsBlank())
+                return nRow;
+            else if(nIndex >= maItems.size())
+                return MAXROW;
+            else
+            {
+                if(bThere)
+                    nRow = maItems[nIndex+1].nRow - 1;
+                else
+                    nRow = maItems[nIndex].nRow - 1;
+            }
+        }
+        while(!bFound && nRow < MAXROW);
+
+        return MAXROW;
+    }
+    else
+    {
+        bool bFound = false;
+        do
+        {
+            nRow--;
+            SCROW nStartRow = MAXROW;
+            bool bHidden = pDocument->RowHidden(nRow, nTab, &nStartRow, NULL);
+            if(bHidden)
+            {
+                nRow = nStartRow - 1;
+                if(nRow <= 0)
+                    return 0;
+            }
+
+            SCSIZE nIndex;
+            bool bThere = Search( nRow, nIndex );
+            if(bThere && !maItems[nIndex].pCell->IsBlank())
+                return nRow;
+            else if(nIndex == 0)
+                return 0;
+            else
+                nRow = maItems[nIndex-1].nRow + 1;
+        }
+        while(!bFound && nRow > 0);
+
+        return 0;
+    }
+}
+
 void ScColumn::FindDataAreaPos(SCROW& rRow, long nMovY) const
 {
-    if (!nMovY) return;
+    if (!nMovY)
+       return;
     bool bForward = (nMovY>0);
 
+    // check if we are in a data area
     SCSIZE nIndex;
     bool bThere = Search(rRow, nIndex);
     if (bThere && maItems[nIndex].pCell->IsBlank())
@@ -1320,69 +1411,37 @@ void ScColumn::FindDataAreaPos(SCROW& rRow, long nMovY) const
     size_t nLastIndex = maItems.size() - 1;
     if (bThere)
     {
-        SCROW nLast = rRow;
-        SCSIZE nOldIndex = nIndex;
-        if (bForward)
+        SCROW nNextRow = FindNextVisibleRow(rRow, bForward);
+        SCSIZE nNewIndex;
+        bool bNextThere = Search(nNextRow, nNewIndex);
+        if(bNextThere && maItems[nNewIndex].pCell->IsBlank())
+            bNextThere = false;
+
+        if(bNextThere)
         {
-            if (nIndex<nLastIndex)
+            SCROW nLastRow;
+            nLastRow = nNextRow;
+            do
             {
-                ++nIndex;
-                while (nIndex<nLastIndex && maItems[nIndex].nRow==nLast+1
-                                        && !maItems[nIndex].pCell->IsBlank())
-                {
-                    ++nIndex;
-                    ++nLast;
-                }
-                if (nIndex==nLastIndex)
-                    if (maItems[nIndex].nRow==nLast+1 && !maItems[nIndex].pCell->IsBlank())
-                        ++nLast;
+                nNextRow = FindNextVisibleRow(nLastRow, bForward);
+                bNextThere = Search(nNextRow, nNewIndex);
+                if(!bNextThere || maItems[nNewIndex].pCell->IsBlank())
+                    bNextThere = false;
+                else
+                    nLastRow = nNextRow;
             }
+            while(bNextThere && nNewIndex < nLastIndex && nNewIndex > 0);
+
+            rRow = nLastRow;
         }
         else
         {
-            if (nIndex>0)
-            {
-                --nIndex;
-                while (nIndex>0 && maItems[nIndex].nRow+1==nLast
-                                        && !maItems[nIndex].pCell->IsBlank())
-                {
-                    --nIndex;
-                    --nLast;
-                }
-                if (nIndex==0)
-                    if (maItems[nIndex].nRow+1==nLast && !maItems[nIndex].pCell->IsBlank())
-                        --nLast;
-            }
-        }
-        if (nLast==rRow)
-        {
-            bThere = false;
-            nIndex = bForward ? nOldIndex+1 : nOldIndex;
+            rRow = FindNextVisibleRowWithContent(nNextRow, bForward);
         }
-        else
-            rRow = nLast;
     }
-
-    if (!bThere)
+    else
     {
-        if (bForward)
-        {
-            while (nIndex<nLastIndex+1 && maItems[nIndex].pCell->IsBlank())
-                ++nIndex;
-            if (nIndex<nLastIndex+1)
-                rRow = maItems[nIndex].nRow;
-            else
-                rRow = MAXROW;
-        }
-        else
-        {
-            while (nIndex>0 && maItems[nIndex-1].pCell->IsBlank())
-                --nIndex;
-            if (nIndex>0)
-                rRow = maItems[nIndex-1].nRow;
-            else
-                rRow = 0;
-        }
+        rRow = FindNextVisibleRowWithContent(rRow, bForward);
     }
 }
 


More information about the Libreoffice-commits mailing list