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 "contentindex.hxx"
25#include "ndindex.hxx"
26#include "swdllapi.h"
27#include "nodeoffset.hxx"
28
29#include <iostream>
30
31class SwDoc;
32class SwPaM;
33class Point;
34
37{
40
41 SwPosition( const SwNodeIndex &rNode, const SwContentIndex &rContent );
42 SwPosition( const SwNode &rNode, const SwContentIndex &rContent );
43 explicit SwPosition( SwNodes& rNodes, SwNodeOffset nIndex = SwNodeOffset(0) );
44 explicit SwPosition( const SwNodeIndex &rNode, SwNodeOffset nDiff = SwNodeOffset(0) );
45 explicit SwPosition( const SwNode& rNode, SwNodeOffset nDiff = SwNodeOffset(0) );
46 explicit SwPosition( const SwContentNode& rNode, sal_Int32 nContentOffset = 0 );
47 SwPosition( const SwNodeIndex &rNode, const SwContentNode*, sal_Int32 nContentOffset );
48 SwPosition( const SwNode &rNode, const SwContentNode*, sal_Int32 nContentOffset );
49 SwPosition( const SwNodeIndex &rNode, SwNodeOffset nDiff, const SwContentNode*, sal_Int32 nContentOffset );
50 SwPosition( const SwNode &rNode, SwNodeOffset nDiff, const SwContentNode*, sal_Int32 nContentOffset );
51 SwPosition( const SwContentIndex &, short nDiff );
52
53 // callers should be using one of the other constructors to avoid creating a temporary
54 SwPosition( SwNodeIndex && ) = delete;
55 SwPosition( const SwNodeIndex &, SwContentIndex && ) = delete;
57 SwPosition( SwNodeIndex &&, const SwContentNode*, sal_Int32 ) = delete;
59 SwPosition( SwContentIndex &&, short ) = delete;
60
66 SwDoc& GetDoc() const;
67
68 bool operator < (const SwPosition &) const;
69 bool operator > (const SwPosition &) const;
70 bool operator <=(const SwPosition &) const;
71 bool operator >=(const SwPosition &) const;
72 bool operator ==(const SwPosition &) const;
73 bool operator !=(const SwPosition &) const;
74 void dumpAsXml(xmlTextWriterPtr pWriter) const;
75
76
77 SwNodeOffset GetNodeIndex() const { return nNode.GetIndex(); }
78 const SwNodes& GetNodes() const { return nNode.GetNodes(); }
79 SwNodes& GetNodes() { return nNode.GetNodes(); }
80 SwNode& GetNode() const { return nNode.GetNode(); }
81
82
83 const SwContentNode* GetContentNode() const { return nContent.GetContentNode(); }
84 sal_Int32 GetContentIndex() const { return nContent.GetIndex(); }
85 void SetMark(const sw::mark::IMark* pMark) { nContent.SetMark(pMark); }
86 void SetRedline(SwRangeRedline* pRangeRedline) { nContent.SetRedline(pRangeRedline); }
87
89 void Assign( const SwNode& rNd, SwNodeOffset nDelta, sal_Int32 nContentOffset = 0 );
90 void Assign( SwNodeOffset nNodeOffset, sal_Int32 nContentOffset = 0 );
91 void Assign( const SwContentNode& rNode, sal_Int32 nContentOffset = 0 );
92 void Assign( const SwNode& rNd, sal_Int32 nContentOffset = 0 );
93 void Assign( const SwNodeIndex& rNdIdx, sal_Int32 nContentOffset = 0 );
95 void AssignStartIndex( const SwContentNode& rNd );
97 void AssignEndIndex( const SwContentNode& rNd );
99 void Adjust( SwNodeOffset nDelta );
101 void AdjustContent( sal_Int32 nDelta );
103 void SetContent( sal_Int32 nContentIndex );
104};
105
106SW_DLLPUBLIC std::ostream &operator <<(std::ostream& s, const SwPosition& position);
107
108// Result of comparing positions.
110 Before,
111 Behind,
112 Inside,
113 Outside,
114 Equal,
119};
120
121template<typename T>
123 const T& rStt1, const T& rEnd1,
124 const T& rStt2, const T& rEnd2 )
125{
127 if( rStt1 < rStt2 )
128 {
129 if( rEnd1 > rStt2 )
130 {
131 if( rEnd1 >= rEnd2 )
133 else
135
136 }
137 else if( rEnd1 == rStt2 )
139 else
141 }
142 else if( rEnd2 > rStt1 )
143 {
144 if( rEnd2 >= rEnd1 )
145 {
146 if( rEnd2 == rEnd1 && rStt2 == rStt1 )
148 else
150 }
151 else
152 {
153 if (rStt1 == rStt2)
155 else
157 }
158 }
159 else if( rEnd2 == rStt1 )
161 else
163 return nRet;
164}
165
167struct SwMoveFnCollection;
170
171using SwGoInDoc = auto (*)(SwPaM& rPam, SwMoveFnCollection const & fnMove) -> bool;
173bool GoInSection( SwPaM&, SwMoveFnCollection const &);
179
187{
193
194 SwPaM(SwPaM const& rPaM) = delete;
195
196public:
197 explicit SwPaM( const SwPosition& rPos, SwPaM* pRing = nullptr );
198 SwPaM( const SwPosition& rMk, const SwPosition& rPt, SwPaM* pRing = nullptr );
199 SwPaM( const SwNodeIndex& rMk, const SwNodeIndex& rPt,
200 SwNodeOffset nMkOffset = SwNodeOffset(0), SwNodeOffset nPtOffset = SwNodeOffset(0), SwPaM* pRing = nullptr );
201 SwPaM( const SwNode& rMk, const SwNode& rPt,
202 SwNodeOffset nMkOffset = SwNodeOffset(0), SwNodeOffset nPtOffset = SwNodeOffset(0), SwPaM* pRing = nullptr );
203 SwPaM( const SwNodeIndex& rMk, sal_Int32 nMkContent,
204 const SwNodeIndex& rPt, sal_Int32 nPtContent, SwPaM* pRing = nullptr );
205 SwPaM( const SwNode& rMk, sal_Int32 nMkContent,
206 const SwNode& rPt, sal_Int32 nPtContent, SwPaM* pRing = nullptr );
207 SwPaM( const SwNode& rMk, SwNodeOffset nMkOffset, sal_Int32 nMkContent,
208 const SwNode& rPt, SwNodeOffset nPtOffset, sal_Int32 nPtContent, SwPaM* pRing = nullptr );
209 SwPaM( const SwNode& rNd, SwNodeOffset nNdOffset, sal_Int32 nContent = 0, SwPaM* pRing = nullptr );
210 explicit SwPaM( const SwNode& rNd, sal_Int32 nContent = 0, SwPaM* pRing = nullptr );
211 explicit SwPaM( const SwNodeIndex& rNd, sal_Int32 nContent = 0, SwPaM* pRing = nullptr );
212 explicit SwPaM( SwNodes& rNds, SwNodeOffset nMkOffset = SwNodeOffset(0), SwPaM* pRing = nullptr );
213 virtual ~SwPaM() override;
214
217 SwPaM(SwPaM const& rPaM, SwPaM * pRing);
219 SwPaM& operator=( const SwPaM & );
220
222 bool Move( SwMoveFnCollection const & fnMove = fnMoveForward,
223 SwGoInDoc fnGo = GoInContent );
224
225 bool IsInFrontOfLabel() const { return m_bIsInFrontOfLabel; }
226 void SetInFrontOfLabel_( bool bNew ) { m_bIsInFrontOfLabel = bNew; }
227
229 virtual void SetMark();
230
232 {
233 if (m_pMark != m_pPoint)
234 {
237 m_pMark->Assign( *GetPointNode().GetNodes()[SwNodeOffset(0)] );
238 m_pMark = m_pPoint;
239 }
240 }
241#ifdef DBG_UTIL
242 void Exchange();
243
244#else
245 void Exchange()
246 {
247 if (m_pPoint != m_pMark)
248 {
249 SwPosition *pTmp = m_pPoint;
250 m_pPoint = m_pMark;
251 m_pMark = pTmp;
252 }
253 }
254#endif
255
259 bool HasMark() const { return m_pPoint != m_pMark; }
260
261 const SwPosition *GetPoint() const { return m_pPoint; }
262 SwPosition *GetPoint() { return m_pPoint; }
263 const SwPosition *GetMark() const { return m_pMark; }
264 SwPosition *GetMark() { return m_pMark; }
265
266 const SwPosition *Start() const
267 { return (*m_pPoint) <= (*m_pMark) ? m_pPoint : m_pMark; }
269 { return (*m_pPoint) <= (*m_pMark) ? m_pPoint : m_pMark; }
270
271 const SwPosition *End() const
272 { return (*m_pPoint) > (*m_pMark) ? m_pPoint : m_pMark; }
274 { return (*m_pPoint) > (*m_pMark) ? m_pPoint : m_pMark; }
275
277 std::pair<const SwPosition *, const SwPosition *> StartEnd() const
278 { if ((*m_pPoint) <= (*m_pMark)) return { m_pPoint, m_pMark }; else return { m_pMark, m_pPoint }; }
279 std::pair<SwPosition *, SwPosition *> StartEnd()
280 { if ((*m_pPoint) <= (*m_pMark)) return { m_pPoint, m_pMark }; else return { m_pMark, m_pPoint }; }
281
283 SwNode& GetPointNode() const { return m_pPoint->nNode.GetNode(); }
284 SwNode& GetMarkNode() const { return m_pMark->nNode.GetNode(); }
285
289
296 void Normalize(bool bPointFirst = true);
297
299 SwDoc& GetDoc() const { return m_pPoint->nNode.GetNode().GetDoc(); }
300
301 SwPosition& GetBound( bool bOne = true )
302 { return bOne ? m_Bound1 : m_Bound2; }
303 const SwPosition& GetBound( bool bOne = true ) const
304 { return bOne ? m_Bound1 : m_Bound2; }
305
307 sal_uInt16 GetPageNum( bool bAtPoint = true, const Point* pLayPos = nullptr );
308
311 bool HasReadonlySel(bool bFormView, bool isReplace) const;
312
313 bool ContainsPosition(const SwPosition & rPos) const
314 {
315 return *Start() <= rPos && rPos <= *End();
316 }
317
318 OUString GetText() const;
319 void InvalidatePaM();
321 { return GetNextInRing(); }
322 const SwPaM* GetNext() const
323 { return GetNextInRing(); }
325 { return GetPrevInRing(); }
326 const SwPaM* GetPrev() const
327 { return GetPrevInRing(); }
328 bool IsMultiSelection() const
329 { return !unique(); }
330
331 void dumpAsXml(xmlTextWriterPtr pWriter) const;
332};
333
334SW_DLLPUBLIC std::ostream &operator <<(std::ostream& s, const SwPaM& pam);
335
336bool CheckNodesRange(const SwNode&, const SwNode&, bool bChkSection);
337
338#endif // INCLUDED_SW_INC_PAM_HXX
339
340/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Marks a character position inside a document model content node (SwContentNode)
void SetMark(const sw::mark::IMark *pMark)
Definition: index.cxx:222
sal_Int32 GetIndex() const
const SwContentNode * GetContentNode() const
void SetRedline(SwRangeRedline *pRangeRedline)
Definition: doc.hxx:195
Marks a node in the document model.
Definition: ndindex.hxx:31
const SwNodes & GetNodes() const
Definition: ndindex.hxx:119
SwNode & GetNode() const
Definition: ndindex.hxx:123
SwNodeOffset GetIndex() const
Definition: ndindex.hxx:111
Base class of the Writer document model elements.
Definition: node.hxx:98
SwDoc & GetDoc()
Definition: node.hxx:233
SwContentNode * GetContentNode()
Definition: node.hxx:666
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:187
const SwPosition * GetMark() const
Definition: pam.hxx:263
SwPosition * Start()
Definition: pam.hxx:268
void SetInFrontOfLabel_(bool bNew)
Definition: pam.hxx:226
SwNode & GetPointNode() const
Definition: pam.hxx:283
SwPosition m_Bound1
Definition: pam.hxx:188
SwPosition * GetMark()
Definition: pam.hxx:264
SwPosition * m_pMark
points at either m_Bound1 or m_Bound2
Definition: pam.hxx:191
bool ContainsPosition(const SwPosition &rPos) const
Definition: pam.hxx:313
bool IsInFrontOfLabel() const
Definition: pam.hxx:225
SwPaM * GetPrev()
Definition: pam.hxx:324
std::pair< const SwPosition *, const SwPosition * > StartEnd() const
Because sometimes the cost of the operator<= can add up.
Definition: pam.hxx:277
SwPosition * GetPoint()
Definition: pam.hxx:262
SwPosition * End()
Definition: pam.hxx:273
SwPosition * m_pPoint
points at either m_Bound1 or m_Bound2
Definition: pam.hxx:190
bool IsMultiSelection() const
Definition: pam.hxx:328
SwContentNode * GetPointContentNode() const
Definition: pam.hxx:287
const SwPosition * End() const
Definition: pam.hxx:271
SwPaM(SwPaM const &rPaM)=delete
SwPaM * GetNext()
Definition: pam.hxx:320
SwContentNode * GetMarkContentNode() const
Definition: pam.hxx:288
SwDoc & GetDoc() const
Definition: pam.hxx:299
SwPosition m_Bound2
Definition: pam.hxx:189
std::pair< SwPosition *, SwPosition * > StartEnd()
Definition: pam.hxx:279
bool m_bIsInFrontOfLabel
Definition: pam.hxx:192
const SwPaM * GetPrev() const
Definition: pam.hxx:326
SwPosition & GetBound(bool bOne=true)
Definition: pam.hxx:301
void DeleteMark()
Definition: pam.hxx:231
SwNode & GetMarkNode() const
Definition: pam.hxx:284
const SwPosition * GetPoint() const
Definition: pam.hxx:261
const SwPaM * GetNext() const
Definition: pam.hxx:322
const SwPosition * Start() const
Definition: pam.hxx:266
const SwPosition & GetBound(bool bOne=true) const
Definition: pam.hxx:303
bool HasMark() const
A PaM marks a selection if Point and Mark are distinct positions.
Definition: pam.hxx:259
struct _xmlTextWriter * xmlTextWriterPtr
o3tl::strong_int< sal_Int32, struct Tag_SwNodeOffset > SwNodeOffset
Definition: nodeoffset.hxx:16
SwComparePosition ComparePosition(const T &rStt1, const T &rEnd1, const T &rStt2, const T &rEnd2)
Definition: pam.hxx:122
auto(*)(SwPaM &rPam, SwMoveFnCollection const &fnMove) -> bool SwGoInDoc
Definition: pam.hxx:171
bool GoInContentSkipHidden(SwPaM &, SwMoveFnCollection const &)
Definition: pam.cxx:1196
SW_DLLPUBLIC SwMoveFnCollection const & fnMoveForward
SwPam::Move()/Find() default argument.
Definition: paminit.cxx:61
SW_DLLPUBLIC bool GoInDoc(SwPaM &, SwMoveFnCollection const &)
Definition: pam.cxx:1159
SW_DLLPUBLIC bool GoInNode(SwPaM &, SwMoveFnCollection const &)
Definition: pam.cxx:1171
bool CheckNodesRange(const SwNode &, const SwNode &, bool bChkSection)
Check if the given range is inside one of the defined top-level sections.
Definition: pam.cxx:348
SW_DLLPUBLIC std::ostream & operator<<(std::ostream &s, const SwPosition &position)
Definition: pam.cxx:283
bool GoInContentCells(SwPaM &, SwMoveFnCollection const &)
Definition: pam.cxx:1188
bool GoInSection(SwPaM &, SwMoveFnCollection const &)
Definition: pam.cxx:1165
SwComparePosition
Definition: pam.hxx:109
@ OverlapBehind
Pos1 overlaps Pos2 at the end.
@ CollideEnd
Pos1 end touches at Pos2 start.
@ Behind
Pos1 behind Pos2.
@ OverlapBefore
Pos1 overlaps Pos2 at the beginning.
@ Outside
Pos2 completely contained in Pos1.
@ Before
Pos1 before Pos2.
@ Inside
Pos1 completely contained in Pos2.
@ CollideStart
Pos1 start touches at Pos2 end.
@ Equal
Pos1 is as large as Pos2.
SW_DLLPUBLIC bool GoInContent(SwPaM &, SwMoveFnCollection const &)
Definition: pam.cxx:1180
SW_DLLPUBLIC SwMoveFnCollection const & fnMoveBackward
Definition: paminit.cxx:60
bool GoInContentCellsSkipHidden(SwPaM &, SwMoveFnCollection const &)
Definition: pam.cxx:1204
Marks a position in the document model.
Definition: pam.hxx:37
SwNode & GetNode() const
Definition: pam.hxx:80
SwPosition(SwNodeIndex &&, const SwContentNode *, sal_Int32)=delete
void SetMark(const sw::mark::IMark *pMark)
Definition: pam.hxx:85
SwPosition(const SwNode &rNode, SwNodeOffset nDiff, const SwContentNode *, sal_Int32 nContentOffset)
void Assign(const SwNode &rNd, SwNodeOffset nDelta, sal_Int32 nContentOffset=0)
These all set both nNode and nContent.
Definition: pam.cxx:230
SwNodeIndex nNode
Definition: pam.hxx:38
SwPosition(SwNodeIndex &&, SwNodeOffset)=delete
SwPosition(SwNodeIndex &&, SwContentIndex &&)=delete
SwPosition(SwNodeIndex &&)=delete
SwPosition(const SwNodeIndex &, SwContentIndex &&)=delete
const SwContentNode * GetContentNode() const
Definition: pam.hxx:83
SwNodeOffset GetNodeIndex() const
Definition: pam.hxx:77
const SwNodes & GetNodes() const
Definition: pam.hxx:78
void SetRedline(SwRangeRedline *pRangeRedline)
Definition: pam.hxx:86
sal_Int32 GetContentIndex() const
Definition: pam.hxx:84
SwPosition(SwContentIndex &&, short)=delete
SwNodes & GetNodes()
Definition: pam.hxx:79
SwContentIndex nContent
Definition: pam.hxx:39
#define SW_DLLPUBLIC
Definition: swdllapi.h:28
#define SAL_WARN_UNUSED
bool operator<(const wwFont &r1, const wwFont &r2)
Definition: wrtw8sty.cxx:885