1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
28 bool FindFormatImpl(SwPaM
& rSearchPam
,
29 const SwFormat
& rFormat
, SwMoveFnCollection
const & fnMove
,
30 const SwPaM
&rRegion
, bool bInReadOnly
,
31 SwRootFrame
const*const pLayout
)
34 const bool bSrchForward
= &fnMove
== &fnMoveForward
;
35 std::optional
<SwPaM
> oPam
;
36 MakeRegion( fnMove
, rRegion
, oPam
);
38 // if at beginning/end then move it out of the node
40 ? oPam
->GetPoint()->GetContentIndex() == oPam
->GetPointContentNode()->Len()
41 : !oPam
->GetPoint()->GetContentIndex() )
43 if( !(*fnMove
.fnPos
)( oPam
->GetPoint(), false ))
47 SwContentNode
*pNd
= oPam
->GetPoint()->GetNode().GetContentNode();
48 oPam
->GetPoint()->SetContent( bSrchForward
? 0 : pNd
->Len() );
53 while (nullptr != (pNode
= ::GetNode(*oPam
, bFirst
, fnMove
, bInReadOnly
, pLayout
)))
55 SwTextFrame
const*const pFrame(pLayout
&& pNode
->IsTextNode()
56 ? static_cast<SwTextFrame
const*>(pNode
->getLayoutFrame(pLayout
))
58 assert(!pLayout
|| !pNode
->IsTextNode() || pFrame
);
59 SwContentNode
const& rPropsNode(*(pFrame
60 ? pFrame
->GetTextNodeForParaProps()
63 if (rPropsNode
.GetFormatColl() == &rFormat
)
65 // if a FormatCollection is found then it is definitely a SwContentNode
67 // FORWARD: SPoint at the end, GetMark at the beginning of the node
68 // BACKWARD: SPoint at the beginning, GetMark at the end of the node
69 // always: incl. start and incl. end
72 *rSearchPam
.GetPoint() = *oPam
->GetPoint();
74 *rSearchPam
.GetMark() = pFrame
->MapViewToModelPos(
75 TextFrameIndex(bSrchForward
? pFrame
->GetText().getLength() : 0));
79 *rSearchPam
.GetPoint() = *oPam
->GetPoint();
81 rSearchPam
.GetPoint()->SetContent(pNode
->Len());
82 rSearchPam
.GetMark()->SetContent(0);
85 // if backward search, switch point and mark
87 rSearchPam
.Exchange();
98 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */