[Libreoffice-commits] core.git: Branch 'libreoffice-4-3' - sc/source

Kohei Yoshida kohei.yoshida at collabora.com
Fri May 23 09:56:31 PDT 2014


 sc/source/ui/dialogs/searchresults.cxx |   40 ++++++++++++++++++++++-----------
 1 file changed, 27 insertions(+), 13 deletions(-)

New commits:
commit 622a869be5ae7a23dee39101531b26b9353cfee8
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Fri May 23 12:54:20 2014 -0400

    fdo#76824: Proper way to parse cell address strings.
    
    Be aware of the variable address convention.
    
    Change-Id: I37ca38758f055e7799cadefafda61174ea3cbf9c
    (cherry picked from commit 653e4adddfc80aeb91c1d21c18e95b3986c85c54)

diff --git a/sc/source/ui/dialogs/searchresults.cxx b/sc/source/ui/dialogs/searchresults.cxx
index 51c5ece..73955c8 100644
--- a/sc/source/ui/dialogs/searchresults.cxx
+++ b/sc/source/ui/dialogs/searchresults.cxx
@@ -47,16 +47,20 @@ void SearchResultsDlg::FillResults( ScDocument* pDoc, const ScRangeList &rMatche
 {
     mpList->Clear();
     mpList->SetUpdateMode(false);
+    std::vector<OUString> aTabNames = pDoc->GetAllTableNames();
+    SCTAB nTabCount = aTabNames.size();
     for (size_t i = 0, n = rMatchedRanges.size(); i < n; ++i)
     {
         ScCellIterator aIter(pDoc, *rMatchedRanges[i]);
         for (bool bHas = aIter.first(); bHas; bHas = aIter.next())
         {
-            ScAddress aAddress = aIter.GetPos();
-            OUString sAddress;
-            ScRangeStringConverter::GetStringFromAddress(sAddress, aAddress,
-                    pDoc, formula::FormulaGrammar::CONV_OOO);
-            mpList->InsertEntry(sAddress.replace('.', '\t') + "\t" + pDoc->GetString(aAddress));
+            ScAddress aPos = aIter.GetPos();
+            if (aPos.Tab() >= nTabCount)
+                // Out-of-bound sheet index.
+                continue;
+
+            OUString aPosStr = aPos.Format(SCA_ABS, NULL, pDoc->GetAddressConvention());
+            mpList->InsertEntry(aTabNames[aPos.Tab()] + "\t" + aPosStr + "\t" + pDoc->GetString(aPos));
         }
     }
     mpList->SetUpdateMode(true);
@@ -86,15 +90,25 @@ IMPL_LINK_NOARG( SearchResultsDlg, ListSelectHdl )
         return 0;
 
     SvTreeListEntry *pEntry = mpList->FirstSelected();
-    ScAddress aAddress;
-    sal_Int32 nOffset = 0;
-    OUString sAddress = mpList->GetEntryText(pEntry).replaceFirst("\t", ".");
-    ScRangeStringConverter::GetAddressFromString(aAddress, sAddress,
-            mpDoc, formula::FormulaGrammar::CONV_OOO, nOffset, '\t');
+    OUString aTabStr = mpList->GetEntryText(pEntry, 0);
+    OUString aPosStr = mpList->GetEntryText(pEntry, 1);
+
+    SCTAB nTab = -1;
+    if (!mpDoc->GetTable(aTabStr, nTab))
+        // No sheet with specified name.
+        return 0;
+
+    ScAddress aPos;
+    sal_uInt16 nRes = aPos.Parse(aPosStr, mpDoc, mpDoc->GetAddressConvention());
+    if (!(nRes & SCA_VALID))
+        // Invalid address string.
+        return 0;
+
+    // Jump to the cell.
     ScTabViewShell* pScViewShell = ScTabViewShell::GetActiveViewShell();
-    pScViewShell->SetTabNo(aAddress.Tab());
-    pScViewShell->SetCursor(aAddress.Col(), aAddress.Row());
-    pScViewShell->AlignToCursor(aAddress.Col(), aAddress.Row(), SC_FOLLOW_JUMP);
+    pScViewShell->SetTabNo(nTab);
+    pScViewShell->SetCursor(aPos.Col(), aPos.Row());
+    pScViewShell->AlignToCursor(aPos.Col(), aPos.Row(), SC_FOLLOW_JUMP);
 
     return 0;
 }


More information about the Libreoffice-commits mailing list