summaryrefslogtreecommitdiff
path: root/sw/source/core/model
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2021-07-09 19:36:58 +0900
committerTomaž Vajngerl <quikee@gmail.com>2021-08-10 07:54:06 +0200
commitea1818b8ba34378b777b8706069d28fade2cc924 (patch)
treed2f7d506e3f84502b93533fe560de1bfa5009572 /sw/source/core/model
parentfc4c0747e97bb997cc37263b3e86b07dab21fe25 (diff)
indexing: add support for SdrObjects in SearchResultLocator
Also add (node) "type" parameter because we need to differentiate between Writer nodes and SdrObject nodes. Change-Id: I590695ae71781f64c22bdd7e1df01d69e3376e67 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118671 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'sw/source/core/model')
-rw-r--r--sw/source/core/model/SearchResultLocator.cxx62
1 files changed, 48 insertions, 14 deletions
diff --git a/sw/source/core/model/SearchResultLocator.cxx b/sw/source/core/model/SearchResultLocator.cxx
index 09aa12ffeb85..9b22c61fa441 100644
--- a/sw/source/core/model/SearchResultLocator.cxx
+++ b/sw/source/core/model/SearchResultLocator.cxx
@@ -14,29 +14,63 @@
#include <frame.hxx>
#include <cntfrm.hxx>
#include <viewsh.hxx>
+#include <IDocumentDrawModelAccess.hxx>
#include <IDocumentLayoutAccess.hxx>
-namespace sw
+#include <svx/svdpage.hxx>
+#include <svx/svdobj.hxx>
+
+namespace sw::search
{
LocationResult SearchResultLocator::find(SearchIndexData const& rSearchIndexData)
{
LocationResult aResult;
- SwNodes const& rNodes = mpDocument->GetNodes();
- if (rSearchIndexData.nNodeIndex >= rNodes.Count())
- return aResult;
- SwNode* pNode = rNodes[rSearchIndexData.nNodeIndex];
+ if (rSearchIndexData.eType == NodeType::WriterNode)
+ {
+ SwNodes const& rNodes = mpDocument->GetNodes();
+ if (rSearchIndexData.nNodeIndex >= rNodes.Count())
+ return aResult;
+ SwNode* pNode = rNodes[rSearchIndexData.nNodeIndex];
- auto* pContentNode = pNode->GetContentNode();
- auto* pShell = mpDocument->getIDocumentLayoutAccess().GetCurrentViewShell();
+ auto* pContentNode = pNode->GetContentNode();
+ auto* pShell = mpDocument->getIDocumentLayoutAccess().GetCurrentViewShell();
- if (pContentNode && pShell)
- {
- const SwFrame* pFrame = pContentNode->getLayoutFrame(pShell->GetLayout(), nullptr, nullptr);
- SwRect const& rArea = pFrame->getFrameArea();
+ if (pContentNode && pShell)
+ {
+ const SwFrame* pFrame
+ = pContentNode->getLayoutFrame(pShell->GetLayout(), nullptr, nullptr);
+ SwRect const& rArea = pFrame->getFrameArea();
- aResult.mbFound = true;
- aResult.maRectangles.emplace_back(rArea.Left(), rArea.Top(), rArea.Left() + rArea.Width(),
- rArea.Top() + rArea.Height());
+ aResult.mbFound = true;
+ aResult.maRectangles.emplace_back(rArea.Left(), rArea.Top(),
+ rArea.Left() + rArea.Width(),
+ rArea.Top() + rArea.Height());
+ }
+ }
+ else if (rSearchIndexData.eType == NodeType::SdrObject)
+ {
+ IDocumentDrawModelAccess& rDrawModelAccess = mpDocument->getIDocumentDrawModelAccess();
+ auto* pModel = rDrawModelAccess.GetDrawModel();
+ for (sal_uInt16 nPage = 0; nPage < pModel->GetPageCount(); ++nPage)
+ {
+ SdrPage* pPage = pModel->GetPage(nPage);
+ for (size_t nObject = 0; nObject < pPage->GetObjCount(); ++nObject)
+ {
+ SdrObject* pObject = pPage->GetObj(nObject);
+ if (pObject)
+ {
+ if (pObject->GetName() == rSearchIndexData.aObjectName)
+ {
+ auto aRect = o3tl::convert(pObject->GetLogicRect(), o3tl::Length::mm100,
+ o3tl::Length::twip);
+ aResult.mbFound = true;
+ aResult.maRectangles.emplace_back(aRect.Left(), aRect.Top(),
+ aRect.Left() + aRect.GetWidth(),
+ aRect.Top() + aRect.GetHeight());
+ }
+ }
+ }
+ }
}
return aResult;