diff options
Diffstat (limited to 'sw/source/core/model')
-rw-r--r-- | sw/source/core/model/SearchResultLocator.cxx | 62 |
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; |