diff options
author | Kohei Yoshida <kohei.yoshida@collabora.com> | 2014-05-23 12:54:20 -0400 |
---|---|---|
committer | Andras Timar <andras.timar@collabora.com> | 2014-06-02 19:01:53 +0200 |
commit | 5366335e6b6296bcdf5a50c2dec85c15259e8800 (patch) | |
tree | d132827fcce4823a194599422353d81304d95c23 /sc | |
parent | 3247e21e30a363c4b7e0f105597d95191c053694 (diff) |
fdo#76824: Proper way to parse cell address strings.
Be aware of the variable address convention.
Change-Id: I37ca38758f055e7799cadefafda61174ea3cbf9c
(cherry picked from commit 653e4adddfc80aeb91c1d21c18e95b3986c85c54)
Reviewed-on: https://gerrit.libreoffice.org/9454
Reviewed-by: Eike Rathke <erack@redhat.com>
Tested-by: Eike Rathke <erack@redhat.com>
Diffstat (limited to 'sc')
-rw-r--r-- | sc/source/ui/dialogs/searchresults.cxx | 40 |
1 files changed, 27 insertions, 13 deletions
diff --git a/sc/source/ui/dialogs/searchresults.cxx b/sc/source/ui/dialogs/searchresults.cxx index 1f8ee016d292..2de6ab676a72 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; } |