LibreOffice Module sw (master)  1
pam.hxx
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 #ifndef INCLUDED_SW_INC_PAM_HXX
20 #define INCLUDED_SW_INC_PAM_HXX
21 
22 #include <sal/types.h>
23 #include "ring.hxx"
24 #include "index.hxx"
25 #include "ndindex.hxx"
26 #include "swdllapi.h"
27 
28 #include <iostream>
29 
30 class SwDoc;
31 class SwPaM;
32 class Point;
33 
36 {
39 
40  SwPosition( const SwNodeIndex &rNode, const SwIndex &rContent );
41  explicit SwPosition( const SwNodeIndex &rNode );
42  explicit SwPosition( const SwNode& rNode );
43  explicit SwPosition( SwContentNode& rNode, const sal_Int32 nOffset = 0 );
44 
50  SwDoc * GetDoc() const;
51 
52  bool operator < (const SwPosition &) const;
53  bool operator > (const SwPosition &) const;
54  bool operator <=(const SwPosition &) const;
55  bool operator >=(const SwPosition &) const;
56  bool operator ==(const SwPosition &) const;
57  bool operator !=(const SwPosition &) const;
58  void dumpAsXml(xmlTextWriterPtr pWriter) const;
59 };
60 
61 SW_DLLPUBLIC std::ostream &operator <<(std::ostream& s, const SwPosition& position);
62 
63 // Result of comparing positions.
64 enum class SwComparePosition {
65  Before,
66  Behind,
67  Inside,
68  Outside,
69  Equal,
72  CollideStart,
73  CollideEnd
74 };
75 
76 template<typename T>
78  const T& rStt1, const T& rEnd1,
79  const T& rStt2, const T& rEnd2 )
80 {
81  SwComparePosition nRet;
82  if( rStt1 < rStt2 )
83  {
84  if( rEnd1 > rStt2 )
85  {
86  if( rEnd1 >= rEnd2 )
88  else
90 
91  }
92  else if( rEnd1 == rStt2 )
94  else
96  }
97  else if( rEnd2 > rStt1 )
98  {
99  if( rEnd2 >= rEnd1 )
100  {
101  if( rEnd2 == rEnd1 && rStt2 == rStt1 )
103  else
105  }
106  else
107  {
108  if (rStt1 == rStt2)
110  else
112  }
113  }
114  else if( rEnd2 == rStt1 )
116  else
118  return nRet;
119 }
120 
122 struct SwMoveFnCollection;
125 
126 using SwGoInDoc = auto (*)(SwPaM& rPam, SwMoveFnCollection const & fnMove) -> bool;
134 
137 {
143 
144  SwPaM(SwPaM const& rPaM) = delete;
145 
146 public:
147  explicit SwPaM( const SwPosition& rPos, SwPaM* pRing = nullptr );
148  SwPaM( const SwPosition& rMk, const SwPosition& rPt, SwPaM* pRing = nullptr );
149  SwPaM( const SwNodeIndex& rMk, const SwNodeIndex& rPt,
150  long nMkOffset = 0, long nPtOffset = 0, SwPaM* pRing = nullptr );
151  SwPaM( const SwNode& rMk, const SwNode& rPt,
152  long nMkOffset = 0, long nPtOffset = 0, SwPaM* pRing = nullptr );
153  SwPaM( const SwNodeIndex& rMk, sal_Int32 nMkContent,
154  const SwNodeIndex& rPt, sal_Int32 nPtContent, SwPaM* pRing = nullptr );
155  SwPaM( const SwNode& rMk, sal_Int32 nMkContent,
156  const SwNode& rPt, sal_Int32 nPtContent, SwPaM* pRing = nullptr );
157  SwPaM( const SwNode& rNd, sal_Int32 nContent = 0, SwPaM* pRing = nullptr );
158  SwPaM( const SwNodeIndex& rNd, sal_Int32 nContent = 0, SwPaM* pRing = nullptr );
159  virtual ~SwPaM() override;
160 
163  SwPaM(SwPaM const& rPaM, SwPaM * pRing);
165  SwPaM& operator=( const SwPaM & );
166 
168  bool Move( SwMoveFnCollection const & fnMove = fnMoveForward,
169  SwGoInDoc fnGo = GoInContent );
170 
171  bool IsInFrontOfLabel() const { return m_bIsInFrontOfLabel; }
172  void SetInFrontOfLabel_( bool bNew ) { m_bIsInFrontOfLabel = bNew; }
173 
175  virtual void SetMark();
176 
177  void DeleteMark()
178  {
179  if (m_pMark != m_pPoint)
180  {
183  *m_pMark = SwPosition( SwNodeIndex( GetNode().GetNodes() ) );
184  m_pMark = m_pPoint;
185  }
186  }
187 #ifdef DBG_UTIL
188  void Exchange();
189 
190 #else
191  void Exchange()
192  {
193  if (m_pPoint != m_pMark)
194  {
195  SwPosition *pTmp = m_pPoint;
196  m_pPoint = m_pMark;
197  m_pMark = pTmp;
198  }
199  }
200 #endif
201 
205  bool HasMark() const { return m_pPoint != m_pMark; }
206 
207  const SwPosition *GetPoint() const { return m_pPoint; }
208  SwPosition *GetPoint() { return m_pPoint; }
209  const SwPosition *GetMark() const { return m_pMark; }
210  SwPosition *GetMark() { return m_pMark; }
211 
212  const SwPosition *Start() const
213  { return (*m_pPoint) <= (*m_pMark) ? m_pPoint : m_pMark; }
215  { return (*m_pPoint) <= (*m_pMark) ? m_pPoint : m_pMark; }
216 
217  const SwPosition *End() const
218  { return (*m_pPoint) > (*m_pMark) ? m_pPoint : m_pMark; }
220  { return (*m_pPoint) > (*m_pMark) ? m_pPoint : m_pMark; }
221 
223  SwNode & GetNode ( bool bPoint = true ) const
224  {
225  return ( bPoint ? m_pPoint->nNode : m_pMark->nNode ).GetNode();
226  }
227 
229  SwContentNode* GetContentNode( bool bPoint = true ) const
230  {
231  return GetNode(bPoint).GetContentNode();
232  }
233 
240  void Normalize(bool bPointFirst = true);
241 
243  SwDoc* GetDoc() const { return m_pPoint->nNode.GetNode().GetDoc(); }
244 
245  SwPosition& GetBound( bool bOne = true )
246  { return bOne ? m_Bound1 : m_Bound2; }
247  const SwPosition& GetBound( bool bOne = true ) const
248  { return bOne ? m_Bound1 : m_Bound2; }
249 
251  sal_uInt16 GetPageNum( bool bAtPoint = true, const Point* pLayPos = nullptr );
252 
255  bool HasReadonlySel( bool bFormView ) const;
256 
257  bool ContainsPosition(const SwPosition & rPos) const
258  {
259  return *Start() <= rPos && rPos <= *End();
260  }
261 
262  OUString GetText() const;
263  void InvalidatePaM();
265  { return GetNextInRing(); }
266  const SwPaM* GetNext() const
267  { return GetNextInRing(); }
269  { return GetPrevInRing(); }
270  const SwPaM* GetPrev() const
271  { return GetPrevInRing(); }
272  bool IsMultiSelection() const
273  { return !unique(); }
274 
275  void dumpAsXml(xmlTextWriterPtr pWriter) const;
276 };
277 
278 SW_DLLPUBLIC std::ostream &operator <<(std::ostream& s, const SwPaM& pam);
279 
280 bool CheckNodesRange( const SwNodeIndex&, const SwNodeIndex&, bool bChkSection );
281 
282 #endif // INCLUDED_SW_INC_PAM_HXX
283 
284 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SwPosition m_Bound1
Definition: pam.hxx:138
SwPosition * GetPoint()
Definition: pam.hxx:208
void DeleteMark()
Definition: pam.hxx:177
bool operator<(const SwTextGlyphsKey &l, const SwTextGlyphsKey &r)
Definition: fntcache.cxx:132
SwNode & GetNode(bool bPoint=true) const
Definition: pam.hxx:223
Marks a position in the document model.
Definition: pam.hxx:35
bool IsMultiSelection() const
Definition: pam.hxx:272
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
SW_DLLPUBLIC bool GoInNode(SwPaM &, SwMoveFnCollection const &)
Definition: pam.cxx:894
SwComparePosition ComparePosition(const T &rStt1, const T &rEnd1, const T &rStt2, const T &rEnd2)
Definition: pam.hxx:77
SwNodeIndex nNode
Definition: pam.hxx:37
Pos1 is as large as Pos2.
const SwPosition * GetMark() const
Definition: pam.hxx:209
const SwPaM * GetPrev() const
Definition: pam.hxx:270
Pos1 completely contained in Pos2.
SwPosition * GetMark()
Definition: pam.hxx:210
Definition: doc.hxx:185
SW_DLLPUBLIC SwMoveFnCollection const & fnMoveForward
SwPam::Move()/Find() default argument.
Definition: paminit.cxx:59
SwPosition * m_pPoint
points at either m_Bound1 or m_Bound2
Definition: pam.hxx:140
SwNode & GetNode() const
Definition: ndindex.hxx:118
SW_DLLPUBLIC bool GoInDoc(SwPaM &, SwMoveFnCollection const &)
Definition: pam.cxx:882
SwPosition & GetBound(bool bOne=true)
Definition: pam.hxx:245
SW_DLLPUBLIC bool GoInContentSkipHidden(SwPaM &, SwMoveFnCollection const &)
Definition: pam.cxx:919
SW_DLLPUBLIC bool GoInContent(SwPaM &, SwMoveFnCollection const &)
Definition: pam.cxx:903
SwPosition * m_pMark
points at either m_Bound1 or m_Bound2
Definition: pam.hxx:141
SwContentNode * GetContentNode(bool bPoint=true) const
Definition: pam.hxx:229
Pos1 end touches at Pos2 start.
SwIndex nContent
Definition: pam.hxx:38
SW_DLLPUBLIC bool GoInSection(SwPaM &, SwMoveFnCollection const &)
Definition: pam.cxx:888
auto(*)(SwPaM &rPam, SwMoveFnCollection const &fnMove) -> bool SwGoInDoc
Definition: pam.hxx:126
bool m_bIsInFrontOfLabel
Definition: pam.hxx:142
Pos2 completely contained in Pos1.
Pos1 before Pos2.
value_type * GetPrevInRing()
Definition: ring.hxx:87
SwPaM * GetNext()
Definition: pam.hxx:264
const SwPaM * GetNext() const
Definition: pam.hxx:266
bool ContainsPosition(const SwPosition &rPos) const
Definition: pam.hxx:257
bool CheckNodesRange(const SwNodeIndex &, const SwNodeIndex &, bool bChkSection)
Definition: pam.cxx:238
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:136
struct _xmlTextWriter * xmlTextWriterPtr
SW_DLLPUBLIC bool GoInContentCells(SwPaM &, SwMoveFnCollection const &)
Definition: pam.cxx:911
const SwPosition * GetPoint() const
Definition: pam.hxx:207
Pos1 start touches at Pos2 end.
bool unique() const
Definition: ring.hxx:96
const SwPosition & GetBound(bool bOne=true) const
Definition: pam.hxx:247
SwContentNode * GetContentNode()
Definition: node.hxx:615
SwPosition m_Bound2
Definition: pam.hxx:139
bool HasMark() const
A PaM marks a selection if Point and Mark are distinct positions.
Definition: pam.hxx:205
value_type * GetNextInRing()
Definition: ring.hxx:84
SwDoc * GetDoc()
Definition: node.hxx:702
SwDoc * GetDoc() const
Definition: pam.hxx:243
Marks a character position inside a document model node.
Definition: index.hxx:37
Marks a node in the document model.
Definition: ndindex.hxx:31
#define SW_DLLPUBLIC
Definition: swdllapi.h:28
const SwPosition * Start() const
Definition: pam.hxx:212
SwPaM * GetPrev()
Definition: pam.hxx:268
#define SAL_WARN_UNUSED
SwPosition * End()
Definition: pam.hxx:219
SW_DLLPUBLIC std::ostream & operator<<(std::ostream &s, const SwPosition &position)
Definition: pam.cxx:191
Pos1 overlaps Pos2 at the end.
const SwPosition * End() const
Definition: pam.hxx:217
SW_DLLPUBLIC bool GoInContentCellsSkipHidden(SwPaM &, SwMoveFnCollection const &)
Definition: pam.cxx:927
SW_DLLPUBLIC SwMoveFnCollection const & fnMoveBackward
Definition: paminit.cxx:58
void SetInFrontOfLabel_(bool bNew)
Definition: pam.hxx:172
Pos1 behind Pos2.
Pos1 overlaps Pos2 at the beginning.
SwComparePosition
Definition: pam.hxx:64
SwPosition * Start()
Definition: pam.hxx:214
bool IsInFrontOfLabel() const
Definition: pam.hxx:171
Base class of the Writer document model elements.
Definition: node.hxx:79