LibreOffice Module sw (master) 1
findfmt.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <pamtyp.hxx>
21#include <pam.hxx>
22#include <txtfrm.hxx>
23#include <ndtxt.hxx>
24#include <memory>
25
26namespace sw {
27
28bool FindFormatImpl(SwPaM & rSearchPam,
29 const SwFormat& rFormat, SwMoveFnCollection const & fnMove,
30 const SwPaM &rRegion, bool bInReadOnly,
31 SwRootFrame const*const pLayout)
32{
33 bool bFound = false;
34 const bool bSrchForward = &fnMove == &fnMoveForward;
35 std::optional<SwPaM> oPam;
36 MakeRegion( fnMove, rRegion, oPam );
37
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() )
42 {
43 if( !(*fnMove.fnPos)( oPam->GetPoint(), false ))
44 {
45 return false;
46 }
47 SwContentNode *pNd = oPam->GetPoint()->GetNode().GetContentNode();
48 oPam->GetPoint()->SetContent( bSrchForward ? 0 : pNd->Len() );
49 }
50
51 bool bFirst = true;
52 SwContentNode* pNode;
53 while (nullptr != (pNode = ::GetNode(*oPam, bFirst, fnMove, bInReadOnly, pLayout)))
54 {
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));
62
63 if (rPropsNode.GetFormatColl() == &rFormat)
64 {
65 // if a FormatCollection is found then it is definitely a SwContentNode
66
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)
71 {
72 *rSearchPam.GetPoint() = *oPam->GetPoint();
73 rSearchPam.SetMark();
74 *rSearchPam.GetMark() = pFrame->MapViewToModelPos(
75 TextFrameIndex(bSrchForward ? pFrame->GetText().getLength() : 0));
76 }
77 else
78 {
79 *rSearchPam.GetPoint() = *oPam->GetPoint();
80 rSearchPam.SetMark();
81 pNode->MakeEndIndex( &rSearchPam.GetPoint()->nContent );
82 rSearchPam.GetMark()->nContent = 0;
83 }
84
85 // if backward search, switch point and mark
86 if( !bSrchForward )
87 rSearchPam.Exchange();
88
89 bFound = true;
90 break;
91 }
92 }
93 return bFound;
94}
95
96}
97
98/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
o3tl::strong_int< sal_Int32, struct Tag_TextFrameIndex > TextFrameIndex
Denotes a character index in a text frame at a layout level, after extent mapping from a text node at...
SwFormatColl * GetFormatColl() const
Definition: node.hxx:477
SwContentFrame * getLayoutFrame(const SwRootFrame *, const SwPosition *pPos=nullptr, std::pair< Point, bool > const *pViewPosAndCalcFrame=nullptr) const
Definition: node.cxx:1224
void MakeEndIndex(SwContentIndex *pIdx)
Definition: node.hxx:415
virtual sal_Int32 Len() const
Definition: node.cxx:1257
Base class for various Writer styles.
Definition: format.hxx:47
bool IsTextNode() const
Definition: node.hxx:665
SwContentNode * GetContentNode()
Definition: node.hxx:644
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:187
const SwPosition * GetMark() const
Definition: pam.hxx:263
virtual void SetMark()
Unless this is called, the getter method of Mark will return Point.
Definition: pam.cxx:642
void Exchange()
Definition: pam.cxx:656
const SwPosition * GetPoint() const
Definition: pam.hxx:261
The root element of a Writer document layout.
Definition: rootfrm.hxx:82
Represents the visualization of a paragraph.
Definition: txtfrm.hxx:165
SwPosition MapViewToModelPos(TextFrameIndex nIndex) const
Definition: txtfrm.cxx:1246
const OUString & GetText() const
Returns the text portion we want to edit (for inline see underneath)
Definition: txtfrm.cxx:1293
SwTextNode const * GetTextNodeForParaProps() const
Definition: txtfrm.cxx:1303
Dialog to specify the properties of date form field.
void MakeRegion(SwMoveFnCollection const &fnMove, const SwPaM &rOrigRg, std::optional< SwPaM > &rPam)
make a new region
Definition: pam.cxx:687
bool FindFormatImpl(SwPaM &rSearchPam, const SwFormat &rFormat, SwMoveFnCollection const &fnMove, const SwPaM &rRegion, bool bInReadOnly, SwRootFrame const *const pLayout)
Definition: findfmt.cxx:28
SwContentNode * GetNode(SwPaM &rPam, bool &rbFirst, SwMoveFnCollection const &fnMove, bool const bInReadOnly, SwRootFrame const *const i_pLayout)
This function returns the next node in direction of search.
Definition: pam.cxx:1012
SwMoveFnCollection const & fnMoveForward
SwPam::Move()/Find() default argument.
Definition: paminit.cxx:61
SwContentIndex nContent
Definition: pam.hxx:39