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 <doc.hxx>
21 #include <pamtyp.hxx>
22 #include <pam.hxx>
23 #include <txtfrm.hxx>
24 #include <ndtxt.hxx>
25 #include <memory>
26 
27 namespace sw {
28 
29 bool FindFormatImpl(SwPaM & rSearchPam,
30  const SwFormat& rFormat, SwMoveFnCollection const & fnMove,
31  const SwPaM &rRegion, bool bInReadOnly,
32  SwRootFrame const*const pLayout)
33 {
34  bool bFound = false;
35  const bool bSrchForward = &fnMove == &fnMoveForward;
36  std::unique_ptr<SwPaM> pPam(MakeRegion( fnMove, rRegion ));
37 
38  // if at beginning/end then move it out of the node
39  if( bSrchForward
40  ? pPam->GetPoint()->nContent.GetIndex() == pPam->GetContentNode()->Len()
41  : !pPam->GetPoint()->nContent.GetIndex() )
42  {
43  if( !(*fnMove.fnNds)( &pPam->GetPoint()->nNode, false ))
44  {
45  return false;
46  }
47  SwContentNode *pNd = pPam->GetPoint()->nNode.GetNode().GetContentNode();
48  pPam->GetPoint()->nContent.Assign( pNd, bSrchForward ? 0 : pNd->Len() );
49  }
50 
51  bool bFirst = true;
52  SwContentNode* pNode;
53  while (nullptr != (pNode = ::GetNode(*pPam, 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() = *pPam->GetPoint();
73  rSearchPam.SetMark();
74  *rSearchPam.GetMark() = pFrame->MapViewToModelPos(
75  TextFrameIndex(bSrchForward ? pFrame->GetText().getLength() : 0));
76  }
77  else
78  {
79  *rSearchPam.GetPoint() = *pPam->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: */
Represents the visualization of a paragraph.
Definition: txtfrm.hxx:149
virtual sal_Int32 Len() const
Definition: node.cxx:1183
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:756
std::unique_ptr< SwPaM > MakeRegion(SwMoveFnCollection const &fnMove, const SwPaM &rOrigRg)
make a new region
Definition: pam.cxx:503
const SwPosition * GetMark() const
Definition: pam.hxx:209
SwContentFrame * getLayoutFrame(const SwRootFrame *, const SwPosition *pPos=nullptr, std::pair< Point, bool > const *pViewPosAndCalcFrame=nullptr) const
Definition: node.cxx:1150
Dialog to specify the properties of date form field.
Definition: accfrmobj.cxx:40
const OUString & GetText() const
Returns the text portion we want to edit (for inline see underneath)
Definition: txtfrm.cxx:1282
The root element of a Writer document layout.
Definition: rootfrm.hxx:79
SwIndex nContent
Definition: pam.hxx:38
bool FindFormatImpl(SwPaM &rSearchPam, const SwFormat &rFormat, SwMoveFnCollection const &fnMove, const SwPaM &rRegion, bool bInReadOnly, SwRootFrame const *const pLayout)
Definition: findfmt.cxx:29
Base class for various Writer styles.
Definition: format.hxx:43
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:136
SwTextNode const * GetTextNodeForParaProps() const
Definition: txtfrm.cxx:1292
const SwPosition * GetPoint() const
Definition: pam.hxx:207
void Exchange()
Definition: pam.cxx:471
SwContentNode * GetContentNode()
Definition: node.hxx:615
SwMoveFnCollection const & fnMoveForward
SwPam::Move()/Find() default argument.
Definition: paminit.cxx:59
virtual void SetMark()
Unless this is called, the getter method of Mark will return Point.
Definition: pam.cxx:457
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...
bool IsTextNode() const
Definition: node.hxx:636
SwPosition MapViewToModelPos(TextFrameIndex nIndex) const
Definition: txtfrm.cxx:1237
void MakeEndIndex(SwIndex *pIdx)
Definition: node.hxx:392