1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
/* -*- 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 <IDocumentDrawModelAccess.hxx>
#include <IDocumentLayoutAccess.hxx>
#include <svx/svdpage.hxx>
#include <svx/svdobj.hxx>
namespace sw::search
{
void SearchResultLocator::findOne(LocationResult& rResult, SearchIndexData const& rSearchIndexData)
{
if (rSearchIndexData.meType == NodeType::WriterNode)
{
SwNodes const& rNodes = mpDocument->GetNodes();
if (rSearchIndexData.mnNodeIndex >= rNodes.Count())
return;
SwNode* pNode = rNodes[rSearchIndexData.mnNodeIndex];
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();
rResult.mbFound = true;
rResult.maRectangles.emplace_back(rArea.Left(), rArea.Top(),
rArea.Left() + rArea.Width(),
rArea.Top() + rArea.Height());
}
}
else if (rSearchIndexData.meType == 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.maObjectName)
{
auto aRect = o3tl::convert(pObject->GetLogicRect(), o3tl::Length::mm100,
o3tl::Length::twip);
rResult.mbFound = true;
rResult.maRectangles.emplace_back(aRect.Left(), aRect.Top(),
aRect.Left() + aRect.GetWidth(),
aRect.Top() + aRect.GetHeight());
}
}
}
}
}
}
LocationResult SearchResultLocator::find(std::vector<SearchIndexData> const& rSearchIndexDataVector)
{
LocationResult aResult;
for (auto const& rSearchIndexData : rSearchIndexDataVector)
findOne(aResult, rSearchIndexData);
return aResult;
}
} // end sw namespace
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|