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#include <utility>
31
32class SwDoc;
33class SwPaM;
34class Point;
35
38{
41
42 SwPosition( const SwNodeIndex &rNode, const SwContentIndex &rContent );
43 SwPosition( const SwNode &rNode, const SwContentIndex &rContent );
44 explicit SwPosition( SwNodes& rNodes, SwNodeOffset nIndex = SwNodeOffset(0) );
45 explicit SwPosition( const SwNodeIndex &rNode, SwNodeOffset nDiff = SwNodeOffset(0) );
46 explicit SwPosition( const SwNode& rNode, SwNodeOffset nDiff = SwNodeOffset(0) );
47 explicit SwPosition( const SwContentNode& rNode, sal_Int32 nContentOffset = 0 );
48 SwPosition( const SwNodeIndex &rNode, const SwContentNode*, sal_Int32 nContentOffset );
49 SwPosition( const SwNode &rNode, const SwContentNode*, sal_Int32 nContentOffset );
50 SwPosition( const SwNodeIndex &rNode, SwNodeOffset nDiff, const SwContentNode*, sal_Int32 nContentOffset );
51 SwPosition( const SwNode &rNode, SwNodeOffset nDiff, const SwContentNode*, sal_Int32 nContentOffset );
52 SwPosition( const SwContentIndex &, short nDiff );
53
54 // callers should be using one of the other constructors to avoid creating a temporary
55 SwPosition( SwNodeIndex && ) = delete;
56 SwPosition( const SwNodeIndex &, SwContentIndex && ) = delete;
58 SwPosition( SwNodeIndex &&, const SwContentNode*, sal_Int32 ) = delete;
60 SwPosition( SwContentIndex &&, short ) = delete;
61
67 SwDoc& GetDoc() const;
68
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 bool operator !=(const SwPosition &) const;
75 void dumpAsXml(xmlTextWriterPtr pWriter) const;
76
77
78 SwNodeOffset GetNodeIndex() const { return nNode.GetIndex(); }
79 const SwNodes& GetNodes() const { return nNode.GetNodes(); }
80 SwNodes& GetNodes() { return nNode.GetNodes(); }
81 SwNode& GetNode() const { return nNode.GetNode(); }
82
83
84 const SwContentNode* GetContentNode() const { return nContent.GetContentNode(); }
85 sal_Int32 GetContentIndex() const { return nContent.GetIndex(); }
86 void SetMark(const sw::mark::IMark* pMark) { nContent.SetMark(pMark); }
87 void SetRedline(SwRangeRedline* pRangeRedline) { nContent.SetRedline(pRangeRedline); }
88
90 void Assign( const SwNode& rNd, SwNodeOffset nDelta, sal_Int32 nContentOffset = 0 );
91 void Assign( SwNodeOffset nNodeOffset, sal_Int32 nContentOffset = 0 );
92 void Assign( const SwContentNode& rNode, sal_Int32 nContentOffset = 0 );
93 void Assign( const SwNode& rNd, sal_Int32 nContentOffset = 0 );
94 void Assign( const SwNodeIndex& rNdIdx, sal_Int32 nContentOffset = 0 );
96 void AssignStartIndex( const SwContentNode& rNd );
98 void AssignEndIndex( const SwContentNode& rNd );
100 void Adjust( SwNodeOffset nDelta );
102 void AdjustContent( sal_Int32 nDelta );
104 void SetContent( sal_Int32 nContentIndex );
105};
106
107SW_DLLPUBLIC std::ostream &operator <<(std::ostream& s, const SwPosition& position);
108
109// Result of comparing positions.
111 Before,
112 Behind,
113 Inside,
114 Outside,
115 Equal,
120};
121
122template<typename T>
124 const T& rStt1, const T& rEnd1,
125 const T& rStt2, const T& rEnd2 )
126{
128 if( rStt1 < rStt2 )
129 {
130 if( rEnd1 > rStt2 )
131 {
132 if( rEnd1 >= rEnd2 )
134 else
136
137 }
138 else if( rEnd1 == rStt2 )
140 else
142 }
143 else if( rEnd2 > rStt1 )
144 {
145 if( rEnd2 >= rEnd1 )
146 {
147 if( rEnd2 == rEnd1 && rStt2 == rStt1 )
149 else
151 }
152 else
153 {
154 if (rStt1 == rStt2)
156 else
158 }
159 }
160 else if( rEnd2 == rStt1 )
162 else
164 return nRet;
165}
166
168struct SwMoveFnCollection;
171
172using SwGoInDoc = auto (*)(SwPaM& rPam, SwMoveFnCollection const & fnMove) -> bool;
174bool GoInSection( SwPaM&, SwMoveFnCollection const &);
180
188{
194
195 SwPaM(SwPaM const& rPaM) = delete;
196
197public:
198 explicit SwPaM( const SwPosition& rPos, SwPaM* pRing = nullptr );
199 SwPaM( const SwPosition& rMk, const SwPosition& rPt, SwPaM* pRing = nullptr );
200 SwPaM( const SwNodeIndex& rMk, const SwNodeIndex& rPt,
201 SwNodeOffset nMkOffset = SwNodeOffset(0), SwNodeOffset nPtOffset = SwNodeOffset(0), SwPaM* pRing = nullptr );
202 SwPaM( const SwNode& rMk, const SwNode& rPt,
203 SwNodeOffset nMkOffset = SwNodeOffset(0), SwNodeOffset nPtOffset = SwNodeOffset(0), SwPaM* pRing = nullptr );
204 SwPaM( const SwNodeIndex& rMk, sal_Int32 nMkContent,
205 const SwNodeIndex& rPt, sal_Int32 nPtContent, SwPaM* pRing = nullptr );
206 SwPaM( const SwNode& rMk, sal_Int32 nMkContent,
207 const SwNode& rPt, sal_Int32 nPtContent, SwPaM* pRing = nullptr );
208 SwPaM( const SwNode& rMk, SwNodeOffset nMkOffset, sal_Int32 nMkContent,
209 const SwNode& rPt, SwNodeOffset nPtOffset, sal_Int32 nPtContent, SwPaM* pRing = nullptr );
210 SwPaM( const SwNode& rNd, SwNodeOffset nNdOffset, sal_Int32 nContent = 0, SwPaM* pRing = nullptr );
211 explicit SwPaM( const SwNode& rNd, sal_Int32 nContent = 0, SwPaM* pRing = nullptr );
212 explicit SwPaM( const SwNodeIndex& rNd, sal_Int32 nContent = 0, SwPaM* pRing = nullptr );
213 explicit SwPaM( SwNodes& rNds, SwNodeOffset nMkOffset = SwNodeOffset(0), SwPaM* pRing = nullptr );
214 virtual ~SwPaM() override;
215
218 SwPaM(SwPaM const& rPaM, SwPaM * pRing);
220 SwPaM& operator=( const SwPaM & );
221
223 bool Move( SwMoveFnCollection const & fnMove = fnMoveForward,
224 SwGoInDoc fnGo = GoInContent );
225
226 bool IsInFrontOfLabel() const { return m_bIsInFrontOfLabel; }
227 void SetInFrontOfLabel_( bool bNew ) { m_bIsInFrontOfLabel = bNew; }
228
230 virtual void SetMark();
231
233 {
234 if (HasMark())
235 {
238 m_pMark->Assign( *GetPointNode().GetNodes()[SwNodeOffset(0)] );
239 m_pMark = m_pPoint;
240 }
241 }
242 void Exchange()
243 {
244 if (HasMark())
245 std::swap(m_pPoint, m_pMark);
246 }
247
251 bool HasMark() const { return m_pPoint != m_pMark; }
252
253 const SwPosition *GetPoint() const { return m_pPoint; }
254 SwPosition *GetPoint() { return m_pPoint; }
255 const SwPosition *GetMark() const { return m_pMark; }
256 SwPosition *GetMark() { return m_pMark; }
257
258 const SwPosition *Start() const
259 { return (*m_pPoint) <= (*m_pMark) ? m_pPoint : m_pMark; }
261 { return (*m_pPoint) <= (*m_pMark) ? m_pPoint : m_pMark; }
262
263 const SwPosition *End() const
264 { return (*m_pPoint) > (*m_pMark) ? m_pPoint : m_pMark; }
266 { return (*m_pPoint) > (*m_pMark) ? m_pPoint : m_pMark; }
267
269 std::pair<const SwPosition *, const SwPosition *> StartEnd() const
270 { if ((*m_pPoint) <= (*m_pMark)) return { m_pPoint, m_pMark }; else return { m_pMark, m_pPoint }; }
271 std::pair<SwPosition *, SwPosition *> StartEnd()
272 { if ((*m_pPoint) <= (*m_pMark)) return { m_pPoint, m_pMark }; else return { m_pMark, m_pPoint }; }
273
275 SwNode& GetPointNode() const { return m_pPoint->nNode.GetNode(); }
276 SwNode& GetMarkNode() const { return m_pMark->nNode.GetNode(); }
277
281
288 void Normalize(bool bPointFirst = true);
289
291 SwDoc& GetDoc() const { return m_pPoint->nNode.GetNode().GetDoc(); }
292
293 SwPosition& GetBound( bool bOne = true )
294 { return bOne ? m_Bound1 : m_Bound2; }
295 const SwPosition& GetBound( bool bOne = true ) const
296 { return bOne ? m_Bound1 : m_Bound2; }
297
299 sal_uInt16 GetPageNum( bool bAtPoint = true, const Point* pLayPos = nullptr );
300
303 bool HasReadonlySel(bool bFormView, bool isReplace) const;
305 bool HasHiddenSections() const;
306
307 bool ContainsPosition(const SwPosition & rPos) const
308 {
309 return *Start() <= rPos && rPos <= *End();
310 }
311
312 OUString GetText() const;
313 void InvalidatePaM();
315 { return GetNextInRing(); }
316 const SwPaM* GetNext() const
317 { return GetNextInRing(); }
319 { return GetPrevInRing(); }
320 const SwPaM* GetPrev() const
321 { return GetPrevInRing(); }
322 bool IsMultiSelection() const
323 { return !unique(); }
324
325 void dumpAsXml(xmlTextWriterPtr pWriter) const;
326};
327
328SW_DLLPUBLIC std::ostream &operator <<(std::ostream& s, const SwPaM& pam);
329
330bool CheckNodesRange(const SwNode&, const SwNode&, bool bChkSection);
331
332#endif // INCLUDED_SW_INC_PAM_HXX
333
334/* 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:197
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:188
const SwPosition * GetMark() const
Definition: pam.hxx:255
SwPosition * Start()
Definition: pam.hxx:260
void SetInFrontOfLabel_(bool bNew)
Definition: pam.hxx:227
SwNode & GetPointNode() const
Definition: pam.hxx:275
SwPosition m_Bound1
Definition: pam.hxx:189
SwPosition * GetMark()
Definition: pam.hxx:256
void Exchange()
Definition: pam.hxx:242
SwPosition * m_pMark
points at either m_Bound1 or m_Bound2
Definition: pam.hxx:192
bool ContainsPosition(const SwPosition &rPos) const
Definition: pam.hxx:307
bool IsInFrontOfLabel() const
Definition: pam.hxx:226
SwPaM * GetPrev()
Definition: pam.hxx:318
std::pair< const SwPosition *, const SwPosition * > StartEnd() const
Because sometimes the cost of the operator<= can add up.
Definition: pam.hxx:269
SwPosition * GetPoint()
Definition: pam.hxx:254
SwPosition * End()
Definition: pam.hxx:265
SwPosition * m_pPoint
points at either m_Bound1 or m_Bound2
Definition: pam.hxx:191
bool IsMultiSelection() const
Definition: pam.hxx:322
SwContentNode * GetPointContentNode() const
Definition: pam.hxx:279
const SwPosition * End() const
Definition: pam.hxx:263
SwPaM(SwPaM const &rPaM)=delete
SwPaM * GetNext()
Definition: pam.hxx:314
SwContentNode * GetMarkContentNode() const
Definition: pam.hxx:280
SwDoc & GetDoc() const
Definition: pam.hxx:291
SwPosition m_Bound2
Definition: pam.hxx:190
std::pair< SwPosition *, SwPosition * > StartEnd()
Definition: pam.hxx:271
bool m_bIsInFrontOfLabel
Definition: pam.hxx:193
const SwPaM * GetPrev() const
Definition: pam.hxx:320
SwPosition & GetBound(bool bOne=true)
Definition: pam.hxx:293
void DeleteMark()
Definition: pam.hxx:232
SwNode & GetMarkNode() const
Definition: pam.hxx:276
const SwPosition * GetPoint() const
Definition: pam.hxx:253
const SwPaM * GetNext() const
Definition: pam.hxx:316
const SwPosition * Start() const
Definition: pam.hxx:258
const SwPosition & GetBound(bool bOne=true) const
Definition: pam.hxx:295
bool HasMark() const
A PaM marks a selection if Point and Mark are distinct positions.
Definition: pam.hxx:251
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:123
auto(*)(SwPaM &rPam, SwMoveFnCollection const &fnMove) -> bool SwGoInDoc
Definition: pam.hxx:172
bool GoInContentSkipHidden(SwPaM &, SwMoveFnCollection const &)
Definition: pam.cxx:1219
SW_DLLPUBLIC SwMoveFnCollection const & fnMoveForward
SwPam::Move()/Find() default argument.
Definition: paminit.cxx:61
SW_DLLPUBLIC bool GoInDoc(SwPaM &, SwMoveFnCollection const &)
Definition: pam.cxx:1182
SW_DLLPUBLIC bool GoInNode(SwPaM &, SwMoveFnCollection const &)
Definition: pam.cxx:1194
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:349
SW_DLLPUBLIC std::ostream & operator<<(std::ostream &s, const SwPosition &position)
Definition: pam.cxx:284
bool GoInContentCells(SwPaM &, SwMoveFnCollection const &)
Definition: pam.cxx:1211
bool GoInSection(SwPaM &, SwMoveFnCollection const &)
Definition: pam.cxx:1188
SwComparePosition
Definition: pam.hxx:110
@ 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:1203
SW_DLLPUBLIC SwMoveFnCollection const & fnMoveBackward
Definition: paminit.cxx:60
bool GoInContentCellsSkipHidden(SwPaM &, SwMoveFnCollection const &)
Definition: pam.cxx:1227
Marks a position in the document model.
Definition: pam.hxx:38
SwNode & GetNode() const
Definition: pam.hxx:81
SwPosition(SwNodeIndex &&, const SwContentNode *, sal_Int32)=delete
void SetMark(const sw::mark::IMark *pMark)
Definition: pam.hxx:86
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:231
SwNodeIndex nNode
Definition: pam.hxx:39
SwPosition(SwNodeIndex &&, SwNodeOffset)=delete
SwPosition(SwNodeIndex &&, SwContentIndex &&)=delete
SwPosition(SwNodeIndex &&)=delete
SwPosition(const SwNodeIndex &, SwContentIndex &&)=delete
const SwContentNode * GetContentNode() const
Definition: pam.hxx:84
SwNodeOffset GetNodeIndex() const
Definition: pam.hxx:78
const SwNodes & GetNodes() const
Definition: pam.hxx:79
void SetRedline(SwRangeRedline *pRangeRedline)
Definition: pam.hxx:87
sal_Int32 GetContentIndex() const
Definition: pam.hxx:85
SwPosition(SwContentIndex &&, short)=delete
SwNodes & GetNodes()
Definition: pam.hxx:80
SwContentIndex nContent
Definition: pam.hxx:40
#define SW_DLLPUBLIC
Definition: swdllapi.h:28
#define SAL_WARN_UNUSED
bool operator<(const wwFont &r1, const wwFont &r2)
Definition: wrtw8sty.cxx:885