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 
26 namespace sw {
27 
28 bool 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::unique_ptr<SwPaM> pPam(MakeRegion( fnMove, rRegion ));
36 
37  // if at beginning/end then move it out of the node
38  if( bSrchForward
39  ? pPam->GetPoint()->nContent.GetIndex() == pPam->GetContentNode()->Len()
40  : !pPam->GetPoint()->nContent.GetIndex() )
41  {
42  if( !(*fnMove.fnNds)( &pPam->GetPoint()->nNode, false ))
43  {
44  return false;
45  }
46  SwContentNode *pNd = pPam->GetPoint()->nNode.GetNode().GetContentNode();
47  pPam->GetPoint()->nContent.Assign( pNd, bSrchForward ? 0 : pNd->Len() );
48  }
49 
50  bool bFirst = true;
51  SwContentNode* pNode;
52  while (nullptr != (pNode = ::GetNode(*pPam, bFirst, fnMove, bInReadOnly, pLayout)))
53  {
54  SwTextFrame const*const pFrame(pLayout && pNode->IsTextNode()
55  ? static_cast<SwTextFrame const*>(pNode->getLayoutFrame(pLayout))
56  : nullptr);
57  assert(!pLayout || !pNode->IsTextNode() || pFrame);
58  SwContentNode const& rPropsNode(*(pFrame
59  ? pFrame->GetTextNodeForParaProps()
60  : pNode));
61 
62  if (rPropsNode.GetFormatColl() == &rFormat)
63  {
64  // if a FormatCollection is found then it is definitely a SwContentNode
65 
66  // FORWARD: SPoint at the end, GetMark at the beginning of the node
67  // BACKWARD: SPoint at the beginning, GetMark at the end of the node
68  // always: incl. start and incl. end
69  if (pFrame)
70  {
71  *rSearchPam.GetPoint() = *pPam->GetPoint();
72  rSearchPam.SetMark();
73  *rSearchPam.GetMark() = pFrame->MapViewToModelPos(
74  TextFrameIndex(bSrchForward ? pFrame->GetText().getLength() : 0));
75  }
76  else
77  {
78  *rSearchPam.GetPoint() = *pPam->GetPoint();
79  rSearchPam.SetMark();
80  pNode->MakeEndIndex( &rSearchPam.GetPoint()->nContent );
81  rSearchPam.GetMark()->nContent = 0;
82  }
83 
84  // if backward search, switch point and mark
85  if( !bSrchForward )
86  rSearchPam.Exchange();
87 
88  bFound = true;
89  break;
90  }
91  }
92  return bFound;
93 }
94 
95 }
96 
97 /* 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:1180
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:754
std::unique_ptr< SwPaM > MakeRegion(SwMoveFnCollection const &fnMove, const SwPaM &rOrigRg)
make a new region
Definition: pam.cxx:501
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:1147
Dialog to specify the properties of date form field.
const OUString & GetText() const
Returns the text portion we want to edit (for inline see underneath)
Definition: txtfrm.cxx:1290
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:28
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:1300
const SwPosition * GetPoint() const
Definition: pam.hxx:207
void Exchange()
Definition: pam.cxx:469
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:455
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:1245
void MakeEndIndex(SwIndex *pIdx)
Definition: node.hxx:392