Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / source / core / crsr / findfmt.cxx
blobba8ab83828040f16b2e15c7c4b16e683ab907b7d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #include <pamtyp.hxx>
21 #include <pam.hxx>
22 #include <txtfrm.hxx>
23 #include <ndtxt.hxx>
24 #include <memory>
26 namespace sw {
28 bool FindFormatImpl(SwPaM & rSearchPam,
29 const SwFormat& rFormat, SwMoveFnCollection const & fnMove,
30 const SwPaM &rRegion, bool bInReadOnly,
31 SwRootFrame const*const pLayout)
33 bool bFound = false;
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
39 if( bSrchForward
40 ? oPam->GetPoint()->GetContentIndex() == oPam->GetPointContentNode()->Len()
41 : !oPam->GetPoint()->GetContentIndex() )
43 if( !(*fnMove.fnPos)( oPam->GetPoint(), false ))
45 return false;
47 SwContentNode *pNd = oPam->GetPoint()->GetNode().GetContentNode();
48 oPam->GetPoint()->SetContent( bSrchForward ? 0 : pNd->Len() );
51 bool bFirst = true;
52 SwContentNode* pNode;
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))
57 : nullptr);
58 assert(!pLayout || !pNode->IsTextNode() || pFrame);
59 SwContentNode const& rPropsNode(*(pFrame
60 ? pFrame->GetTextNodeForParaProps()
61 : pNode));
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
70 if (pFrame)
72 *rSearchPam.GetPoint() = *oPam->GetPoint();
73 rSearchPam.SetMark();
74 *rSearchPam.GetMark() = pFrame->MapViewToModelPos(
75 TextFrameIndex(bSrchForward ? pFrame->GetText().getLength() : 0));
77 else
79 *rSearchPam.GetPoint() = *oPam->GetPoint();
80 rSearchPam.SetMark();
81 rSearchPam.GetPoint()->SetContent(pNode->Len());
82 rSearchPam.GetMark()->SetContent(0);
85 // if backward search, switch point and mark
86 if( !bSrchForward )
87 rSearchPam.Exchange();
89 bFound = true;
90 break;
93 return bFound;
98 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */