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#include "nodeoffset.hxx"
28
29#include <iostream>
30
31class SwDoc;
32class SwPaM;
33class Point;
34
37{
40
41 SwPosition( const SwNodeIndex &rNode, const SwIndex &rContent );
42 explicit SwPosition( const SwNodeIndex &rNode );
43 explicit SwPosition( const SwNode& rNode );
44 explicit SwPosition( SwContentNode& rNode, const sal_Int32 nOffset = 0 );
45
51 SwDoc& GetDoc() const;
52
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 bool operator !=(const SwPosition &) const;
59 void dumpAsXml(xmlTextWriterPtr pWriter) const;
60};
61
62SW_DLLPUBLIC std::ostream &operator <<(std::ostream& s, const SwPosition& position);
63
64// Result of comparing positions.
66 Before,
67 Behind,
68 Inside,
69 Outside,
70 Equal,
75};
76
77template<typename T>
79 const T& rStt1, const T& rEnd1,
80 const T& rStt2, const T& rEnd2 )
81{
83 if( rStt1 < rStt2 )
84 {
85 if( rEnd1 > rStt2 )
86 {
87 if( rEnd1 >= rEnd2 )
89 else
91
92 }
93 else if( rEnd1 == rStt2 )
95 else
97 }
98 else if( rEnd2 > rStt1 )
99 {
100 if( rEnd2 >= rEnd1 )
101 {
102 if( rEnd2 == rEnd1 && rStt2 == rStt1 )
104 else
106 }
107 else
108 {
109 if (rStt1 == rStt2)
111 else
113 }
114 }
115 else if( rEnd2 == rStt1 )
117 else
119 return nRet;
120}
121
123struct SwMoveFnCollection;
126
127using SwGoInDoc = auto (*)(SwPaM& rPam, SwMoveFnCollection const & fnMove) -> bool;
129bool GoInSection( SwPaM&, SwMoveFnCollection const &);
135
138{
144
145 SwPaM(SwPaM const& rPaM) = delete;
146
147public:
148 explicit SwPaM( const SwPosition& rPos, SwPaM* pRing = nullptr );
149 SwPaM( const SwPosition& rMk, const SwPosition& rPt, SwPaM* pRing = nullptr );
150 SwPaM( const SwNodeIndex& rMk, const SwNodeIndex& rPt,
151 SwNodeOffset nMkOffset = SwNodeOffset(0), SwNodeOffset nPtOffset = SwNodeOffset(0), SwPaM* pRing = nullptr );
152 SwPaM( const SwNode& rMk, const SwNode& rPt,
153 SwNodeOffset nMkOffset = SwNodeOffset(0), SwNodeOffset nPtOffset = SwNodeOffset(0), SwPaM* pRing = nullptr );
154 SwPaM( const SwNodeIndex& rMk, sal_Int32 nMkContent,
155 const SwNodeIndex& rPt, sal_Int32 nPtContent, SwPaM* pRing = nullptr );
156 SwPaM( const SwNode& rMk, sal_Int32 nMkContent,
157 const SwNode& rPt, sal_Int32 nPtContent, SwPaM* pRing = nullptr );
158 SwPaM( const SwNode& rNd, sal_Int32 nContent = 0, SwPaM* pRing = nullptr );
159 SwPaM( const SwNodeIndex& rNd, sal_Int32 nContent = 0, SwPaM* pRing = nullptr );
160 virtual ~SwPaM() override;
161
164 SwPaM(SwPaM const& rPaM, SwPaM * pRing);
166 SwPaM& operator=( const SwPaM & );
167
169 bool Move( SwMoveFnCollection const & fnMove = fnMoveForward,
170 SwGoInDoc fnGo = GoInContent );
171
172 bool IsInFrontOfLabel() const { return m_bIsInFrontOfLabel; }
173 void SetInFrontOfLabel_( bool bNew ) { m_bIsInFrontOfLabel = bNew; }
174
176 virtual void SetMark();
177
179 {
180 if (m_pMark != m_pPoint)
181 {
184 *m_pMark = SwPosition( SwNodeIndex( GetNode().GetNodes() ) );
185 m_pMark = m_pPoint;
186 }
187 }
188#ifdef DBG_UTIL
189 void Exchange();
190
191#else
192 void Exchange()
193 {
194 if (m_pPoint != m_pMark)
195 {
196 SwPosition *pTmp = m_pPoint;
197 m_pPoint = m_pMark;
198 m_pMark = pTmp;
199 }
200 }
201#endif
202
206 bool HasMark() const { return m_pPoint != m_pMark; }
207
208 const SwPosition *GetPoint() const { return m_pPoint; }
209 SwPosition *GetPoint() { return m_pPoint; }
210 const SwPosition *GetMark() const { return m_pMark; }
211 SwPosition *GetMark() { return m_pMark; }
212
213 const SwPosition *Start() const
214 { return (*m_pPoint) <= (*m_pMark) ? m_pPoint : m_pMark; }
216 { return (*m_pPoint) <= (*m_pMark) ? m_pPoint : m_pMark; }
217
218 const SwPosition *End() const
219 { return (*m_pPoint) > (*m_pMark) ? m_pPoint : m_pMark; }
221 { return (*m_pPoint) > (*m_pMark) ? m_pPoint : m_pMark; }
222
224 SwNode & GetNode ( bool bPoint = true ) const
225 {
226 return ( bPoint ? m_pPoint->nNode : m_pMark->nNode ).GetNode();
227 }
228
230 SwContentNode* GetContentNode( bool bPoint = true ) const
231 {
232 return GetNode(bPoint).GetContentNode();
233 }
234
241 void Normalize(bool bPointFirst = true);
242
244 SwDoc& GetDoc() const { return m_pPoint->nNode.GetNode().GetDoc(); }
245
246 SwPosition& GetBound( bool bOne = true )
247 { return bOne ? m_Bound1 : m_Bound2; }
248 const SwPosition& GetBound( bool bOne = true ) const
249 { return bOne ? m_Bound1 : m_Bound2; }
250
252 sal_uInt16 GetPageNum( bool bAtPoint = true, const Point* pLayPos = nullptr );
253
256 bool HasReadonlySel( bool bFormView ) const;
257
258 bool ContainsPosition(const SwPosition & rPos) const
259 {
260 return *Start() <= rPos && rPos <= *End();
261 }
262
263 OUString GetText() const;
264 void InvalidatePaM();
266 { return GetNextInRing(); }
267 const SwPaM* GetNext() const
268 { return GetNextInRing(); }
270 { return GetPrevInRing(); }
271 const SwPaM* GetPrev() const
272 { return GetPrevInRing(); }
273 bool IsMultiSelection() const
274 { return !unique(); }
275
276 void dumpAsXml(xmlTextWriterPtr pWriter) const;
277};
278
279SW_DLLPUBLIC std::ostream &operator <<(std::ostream& s, const SwPaM& pam);
280
281bool CheckNodesRange(const SwNodeIndex&, const SwNodeIndex&, bool bChkSection);
282
283#endif // INCLUDED_SW_INC_PAM_HXX
284
285/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
struct _xmlTextWriter * xmlTextWriterPtr
Definition: doc.hxx:188
Marks a character position inside a document model node.
Definition: index.hxx:34
Marks a node in the document model.
Definition: ndindex.hxx:31
SwNode & GetNode() const
Definition: ndindex.hxx:128
Base class of the Writer document model elements.
Definition: node.hxx:83
SwDoc & GetDoc()
Definition: node.hxx:213
SwContentNode * GetContentNode()
Definition: node.hxx:627
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:138
const SwPosition * GetMark() const
Definition: pam.hxx:210
SwPosition * Start()
Definition: pam.hxx:215
SwContentNode * GetContentNode(bool bPoint=true) const
Definition: pam.hxx:230
void SetInFrontOfLabel_(bool bNew)
Definition: pam.hxx:173
SwPosition m_Bound1
Definition: pam.hxx:139
SwPosition * GetMark()
Definition: pam.hxx:211
SwPosition * m_pMark
points at either m_Bound1 or m_Bound2
Definition: pam.hxx:142
bool ContainsPosition(const SwPosition &rPos) const
Definition: pam.hxx:258
bool IsInFrontOfLabel() const
Definition: pam.hxx:172
SwNode & GetNode(bool bPoint=true) const
Definition: pam.hxx:224
SwPaM * GetPrev()
Definition: pam.hxx:269
SwPosition * GetPoint()
Definition: pam.hxx:209
SwPosition * End()
Definition: pam.hxx:220
SwPosition * m_pPoint
points at either m_Bound1 or m_Bound2
Definition: pam.hxx:141
bool IsMultiSelection() const
Definition: pam.hxx:273
const SwPosition * End() const
Definition: pam.hxx:218
SwPaM(SwPaM const &rPaM)=delete
SwPaM * GetNext()
Definition: pam.hxx:265
SwDoc & GetDoc() const
Definition: pam.hxx:244
SwPosition m_Bound2
Definition: pam.hxx:140
bool m_bIsInFrontOfLabel
Definition: pam.hxx:143
const SwPaM * GetPrev() const
Definition: pam.hxx:271
SwPosition & GetBound(bool bOne=true)
Definition: pam.hxx:246
void DeleteMark()
Definition: pam.hxx:178
const SwPosition * GetPoint() const
Definition: pam.hxx:208
const SwPaM * GetNext() const
Definition: pam.hxx:267
const SwPosition * Start() const
Definition: pam.hxx:213
const SwPosition & GetBound(bool bOne=true) const
Definition: pam.hxx:248
bool HasMark() const
A PaM marks a selection if Point and Mark are distinct positions.
Definition: pam.hxx:206
o3tl::strong_int< sal_Int32, struct Tag_SwNodeOffset > SwNodeOffset
Definition: nodeoffset.hxx:16
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:847
SwComparePosition ComparePosition(const T &rStt1, const T &rEnd1, const T &rStt2, const T &rEnd2)
Definition: pam.hxx:78
auto(*)(SwPaM &rPam, SwMoveFnCollection const &fnMove) -> bool SwGoInDoc
Definition: pam.hxx:127
bool GoInContentSkipHidden(SwPaM &, SwMoveFnCollection const &)
Definition: pam.cxx:1010
SW_DLLPUBLIC SwMoveFnCollection const & fnMoveForward
SwPam::Move()/Find() default argument.
Definition: paminit.cxx:59
SW_DLLPUBLIC bool GoInDoc(SwPaM &, SwMoveFnCollection const &)
Definition: pam.cxx:973
SW_DLLPUBLIC bool GoInNode(SwPaM &, SwMoveFnCollection const &)
Definition: pam.cxx:985
SW_DLLPUBLIC std::ostream & operator<<(std::ostream &s, const SwPosition &position)
Definition: pam.cxx:193
bool GoInContentCells(SwPaM &, SwMoveFnCollection const &)
Definition: pam.cxx:1002
bool GoInSection(SwPaM &, SwMoveFnCollection const &)
Definition: pam.cxx:979
SwComparePosition
Definition: pam.hxx:65
@ 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:994
SW_DLLPUBLIC SwMoveFnCollection const & fnMoveBackward
Definition: paminit.cxx:58
bool GoInContentCellsSkipHidden(SwPaM &, SwMoveFnCollection const &)
Definition: pam.cxx:1018
bool CheckNodesRange(const SwNodeIndex &, const SwNodeIndex &, bool bChkSection)
Check if the given range is inside one of the defined top-level sections.
Definition: pam.cxx:258
Marks a position in the document model.
Definition: pam.hxx:37
SwNodeIndex nNode
Definition: pam.hxx:38
SwIndex 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:841