summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2020-05-27 14:07:10 +0200
committerTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2020-07-30 13:35:36 +0200
commit6ee21e14fe548954e784c4d50566b04c641df51e (patch)
treef8118efb84a1264034e88bf55c537a4c42ebda26
parentb8c7fdfb00858d16db4796c23c77a33211f7244c (diff)
sd: move LOK search result logic to it's own method
Change-Id: I67cbe4d3d63bffdab72c09b3a956f67806588348 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95306 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com> (cherry picked from commit e9dbdc9fc6ff943650e6e18986ed1cce913971ef) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95917 Tested-by: Tomaž Vajngerl <quikee@gmail.com> (cherry picked from commit 6eec4e40f6f8ea88d3136295d5485ee73ef7bf2c)
-rw-r--r--sd/inc/Outliner.hxx4
-rw-r--r--sd/source/ui/view/Outliner.cxx110
2 files changed, 65 insertions, 49 deletions
diff --git a/sd/inc/Outliner.hxx b/sd/inc/Outliner.hxx
index 78a32cbb1e83..b368f03dab1f 100644
--- a/sd/inc/Outliner.hxx
+++ b/sd/inc/Outliner.hxx
@@ -353,6 +353,10 @@ private:
*/
bool SearchAndReplaceOnce(std::vector<::sd::SearchSelection>* pSelections = nullptr);
+ void sendLOKSearchResultCallback(std::shared_ptr<sd::ViewShell>& pViewShell,
+ OutlinerView* pOutlinerView,
+ std::vector<sd::SearchSelection>* pSelections);
+
/** Detect changes of the document or view and react accordingly. Such
changes may occur because different calls to
<member>SearchAndReplace()</member> there usually is user
diff --git a/sd/source/ui/view/Outliner.cxx b/sd/source/ui/view/Outliner.cxx
index 20c248a78fd0..21ea70fbb0d9 100644
--- a/sd/source/ui/view/Outliner.cxx
+++ b/sd/source/ui/view/Outliner.cxx
@@ -690,6 +690,66 @@ bool SdOutliner::SearchAndReplaceAll()
return bRet;
}
+void SdOutliner::sendLOKSearchResultCallback(std::shared_ptr<sd::ViewShell> & pViewShell,
+ OutlinerView* pOutlinerView,
+ std::vector<sd::SearchSelection>* pSelections)
+{
+ std::vector<::tools::Rectangle> aLogicRects;
+ pOutlinerView->GetSelectionRectangles(aLogicRects);
+
+ // convert to twips if in 100thmm (seems as if LibreOfficeKit is based on twips?). Do this
+ // here where we have the only place needing this, *not* in ImpEditView::GetSelectionRectangles
+ // which makes that method unusable for others
+ if (pOutlinerView->GetWindow() && MapUnit::Map100thMM == pOutlinerView->GetWindow()->GetMapMode().GetMapUnit())
+ {
+ for (tools::Rectangle& rRectangle : aLogicRects)
+ {
+ rRectangle = OutputDevice::LogicToLogic(rRectangle, MapMode(MapUnit::Map100thMM), MapMode(MapUnit::MapTwip));
+ }
+ }
+
+ std::vector<OString> aLogicRectStrings;
+ std::transform(aLogicRects.begin(), aLogicRects.end(), std::back_inserter(aLogicRectStrings),
+ [](const ::tools::Rectangle& rRectangle)
+ {
+ return rRectangle.toString();
+ });
+
+ OString sRectangles = comphelper::string::join("; ", aLogicRectStrings);
+
+ if (!pSelections)
+ {
+ // notify LibreOfficeKit about changed page
+ OString aPayload = OString::number(maCurrentPosition.mnPageIndex);
+ SfxViewShell& rSfxViewShell = pViewShell->GetViewShellBase();
+ rSfxViewShell.libreOfficeKitViewCallback(LOK_CALLBACK_SET_PART, aPayload.getStr());
+
+ // also about search result selections
+ boost::property_tree::ptree aTree;
+ aTree.put("searchString", mpSearchItem->GetSearchString().toUtf8().getStr());
+ aTree.put("highlightAll", false);
+
+ boost::property_tree::ptree aChildren;
+ boost::property_tree::ptree aChild;
+ aChild.put("part", OString::number(maCurrentPosition.mnPageIndex).getStr());
+ aChild.put("rectangles", sRectangles.getStr());
+ aChildren.push_back(std::make_pair("", aChild));
+ aTree.add_child("searchResultSelection", aChildren);
+
+ std::stringstream aStream;
+ boost::property_tree::write_json(aStream, aTree);
+ aPayload = aStream.str().c_str();
+ rSfxViewShell.libreOfficeKitViewCallback(LOK_CALLBACK_SEARCH_RESULT_SELECTION, aPayload.getStr());
+ }
+ else
+ {
+ sd::SearchSelection aSelection(maCurrentPosition.mnPageIndex, sRectangles);
+ bool bDuplicate = !pSelections->empty() && pSelections->back() == aSelection;
+ if (!bDuplicate)
+ pSelections->push_back(aSelection);
+ }
+}
+
bool SdOutliner::SearchAndReplaceOnce(std::vector<sd::SearchSelection>* pSelections)
{
DetectChange ();
@@ -781,55 +841,7 @@ bool SdOutliner::SearchAndReplaceOnce(std::vector<sd::SearchSelection>* pSelecti
if (pViewShell && comphelper::LibreOfficeKit::isActive() && mbStringFound)
{
- std::vector<::tools::Rectangle> aLogicRects;
- pOutlinerView->GetSelectionRectangles(aLogicRects);
-
- // convert to twips if in 100thmm (seems as if LibreOfficeKit is based on twips?). Do this
- // here where we have the only place needing this, *not* in ImpEditView::GetSelectionRectangles
- // which makes that method unusable for others
- if (pOutlinerView->GetWindow() && MapUnit::Map100thMM == pOutlinerView->GetWindow()->GetMapMode().GetMapUnit())
- {
- for (tools::Rectangle& rRectangle : aLogicRects)
- {
- rRectangle = OutputDevice::LogicToLogic(rRectangle, MapMode(MapUnit::Map100thMM), MapMode(MapUnit::MapTwip));
- }
- }
-
- std::vector<OString> aLogicRectStrings;
- std::transform(aLogicRects.begin(), aLogicRects.end(), std::back_inserter(aLogicRectStrings), [](const ::tools::Rectangle& rRectangle) { return rRectangle.toString(); });
- OString sRectangles = comphelper::string::join("; ", aLogicRectStrings);
-
- if (!pSelections)
- {
- // notify LibreOfficeKit about changed page
- OString aPayload = OString::number(maCurrentPosition.mnPageIndex);
- SfxViewShell& rSfxViewShell = pViewShell->GetViewShellBase();
- rSfxViewShell.libreOfficeKitViewCallback(LOK_CALLBACK_SET_PART, aPayload.getStr());
-
- // also about search result selections
- boost::property_tree::ptree aTree;
- aTree.put("searchString", mpSearchItem->GetSearchString().toUtf8().getStr());
- aTree.put("highlightAll", false);
-
- boost::property_tree::ptree aChildren;
- boost::property_tree::ptree aChild;
- aChild.put("part", OString::number(maCurrentPosition.mnPageIndex).getStr());
- aChild.put("rectangles", sRectangles.getStr());
- aChildren.push_back(std::make_pair("", aChild));
- aTree.add_child("searchResultSelection", aChildren);
-
- std::stringstream aStream;
- boost::property_tree::write_json(aStream, aTree);
- aPayload = aStream.str().c_str();
- rSfxViewShell.libreOfficeKitViewCallback(LOK_CALLBACK_SEARCH_RESULT_SELECTION, aPayload.getStr());
- }
- else
- {
- sd::SearchSelection aSelection(maCurrentPosition.mnPageIndex, sRectangles);
- bool bDuplicate = !pSelections->empty() && pSelections->back() == aSelection;
- if (!bDuplicate)
- pSelections->push_back(aSelection);
- }
+ sendLOKSearchResultCallback(pViewShell, pOutlinerView, pSelections);
}
return mbEndOfSearch;