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 rSearchPam.GetPoint()->SetContent(pNode->Len());
82 rSearchPam.GetMark()->SetContent(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:497
SwContentFrame * getLayoutFrame(const SwRootFrame *, const SwPosition *pPos=nullptr, std::pair< Point, bool > const *pViewPosAndCalcFrame=nullptr) const
Definition: node.cxx:1223
virtual sal_Int32 Len() const
Definition: node.cxx:1256
Base class for various Writer styles.
Definition: format.hxx:47
bool IsTextNode() const
Definition: node.hxx:190
SwContentNode * GetContentNode()
Definition: node.hxx:666
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:188
const SwPosition * GetMark() const
Definition: pam.hxx:255
virtual void SetMark()
Unless this is called, the getter method of Mark will return Point.
Definition: pam.cxx:643
void Exchange()
Definition: pam.hxx:242
const SwPosition * GetPoint() const
Definition: pam.hxx:253
The root element of a Writer document layout.
Definition: rootfrm.hxx:85
Represents the visualization of a paragraph.
Definition: txtfrm.hxx:168
SwPosition MapViewToModelPos(TextFrameIndex nIndex) const
Definition: txtfrm.cxx:1333
const OUString & GetText() const
Returns the text portion we want to edit (for inline see underneath)
Definition: txtfrm.cxx:1380
SwTextNode const * GetTextNodeForParaProps() const
Definition: txtfrm.cxx:1390
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:676
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:1043
SwMoveFnCollection const & fnMoveForward
SwPam::Move()/Find() default argument.
Definition: paminit.cxx:61
void SetContent(sal_Int32 nContentIndex)
Set content index, only valid to call this if the position points to a SwContentNode subclass.
Definition: pam.cxx:267