summaryrefslogtreecommitdiff
path: root/sw/source/core/model
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2021-07-05 10:57:41 +0900
committerTomaž Vajngerl <quikee@gmail.com>2021-07-26 05:55:58 +0200
commit6e155959de6f46afbe0b68057200c3da822d81f9 (patch)
tree1b5d069b4026c5afa18e5aa1646eed9b90bd6de2 /sw/source/core/model
parent2a151d1d5bc055d5e0011460b6ec42ea9f34f880 (diff)
indexing: search result locator to return the rect of the result
Returns the rectangle(s) where the search result is located in the document. Change-Id: Ib2333584fbc460cc16b1bf205fc3d674a1c06957 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118668 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.cxx47
1 files changed, 47 insertions, 0 deletions
diff --git a/sw/source/core/model/SearchResultLocator.cxx b/sw/source/core/model/SearchResultLocator.cxx
new file mode 100644
index 000000000000..09aa12ffeb85
--- /dev/null
+++ b/sw/source/core/model/SearchResultLocator.cxx
@@ -0,0 +1,47 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ */
+
+#include <SearchResultLocator.hxx>
+#include <node.hxx>
+#include <drawdoc.hxx>
+#include <frame.hxx>
+#include <cntfrm.hxx>
+#include <viewsh.hxx>
+#include <IDocumentLayoutAccess.hxx>
+
+namespace sw
+{
+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];
+
+ 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();
+
+ aResult.mbFound = true;
+ aResult.maRectangles.emplace_back(rArea.Left(), rArea.Top(), rArea.Left() + rArea.Width(),
+ rArea.Top() + rArea.Height());
+ }
+
+ return aResult;
+}
+
+} // end sw namespace
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */