merge the formfield patch from ooo-build
[ooovba.git] / sw / inc / pam.hxx
blob30427864a9009d19c185288da63e8f1a0c4d16f7
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: pam.hxx,v $
10 * $Revision: 1.19.172.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #ifndef _PAM_HXX
31 #define _PAM_HXX
33 #include <stddef.h> // fuer MemPool
34 #include <tools/gen.hxx>
35 #include <tools/mempool.hxx>
36 #include <cshtyp.hxx> // fuer die Funktions-Definitionen
37 #include <ring.hxx> // Superklasse
38 #include <index.hxx> // fuer SwIndex
39 #include <ndindex.hxx> // fuer SwNodeIndex
40 #include "swdllapi.h"
42 class SwFmt;
43 class SfxPoolItem;
44 class SfxItemSet;
45 class SwDoc;
46 class SwNode;
47 class SwCntntNode;
48 class SwPaM;
50 namespace com { namespace sun { namespace star { namespace util {
51 struct SearchOptions;
52 } } } }
54 namespace utl {
55 class TextSearch;
58 struct SW_DLLPUBLIC SwPosition
60 SwNodeIndex nNode;
61 SwIndex nContent;
63 SwPosition( const SwNodeIndex &rNode, const SwIndex &rCntnt );
64 explicit SwPosition( const SwNodeIndex &rNode );
65 explicit SwPosition( const SwNode& rNode );
66 explicit SwPosition( SwCntntNode& rNode, const xub_StrLen nOffset = 0 );
68 SwPosition( const SwPosition & );
69 SwPosition &operator=(const SwPosition &);
71 // #111827#
72 /**
73 Returns the document this position is in.
75 @return the document this position is in.
77 SwDoc * GetDoc() const;
79 BOOL operator < (const SwPosition &) const;
80 BOOL operator > (const SwPosition &) const;
81 BOOL operator <=(const SwPosition &) const;
82 BOOL operator >=(const SwPosition &) const;
83 BOOL operator ==(const SwPosition &) const;
84 BOOL operator !=(const SwPosition &) const;
88 // das Ergebnis eines Positions Vergleiches
89 enum SwComparePosition {
90 POS_BEFORE, // Pos1 liegt vor Pos2
91 POS_BEHIND, // Pos1 liegt hinter Pos2
92 POS_INSIDE, // Pos1 liegt vollstaendig in Pos2
93 POS_OUTSIDE, // Pos2 liegt vollstaendig in Pos1
94 POS_EQUAL, // Pos1 ist genauso gross wie Pos2
95 POS_OVERLAP_BEFORE, // Pos1 ueberlappt Pos2 am Anfang
96 POS_OVERLAP_BEHIND, // Pos1 ueberlappt Pos2 am Ende
97 POS_COLLIDE_START, // Pos1 Start stoesst an Pos2 Ende
98 POS_COLLIDE_END // Pos1 End stoesst an Pos2 Start
100 SwComparePosition ComparePosition(
101 const SwPosition& rStt1, const SwPosition& rEnd1,
102 const SwPosition& rStt2, const SwPosition& rEnd2 );
104 SwComparePosition ComparePosition(
105 const unsigned long nStt1, const unsigned long nEnd1,
106 const unsigned long nStt2, const unsigned long nEnd2 );
109 // SwPointAndMark / SwPaM
110 struct SwMoveFnCollection;
111 typedef SwMoveFnCollection* SwMoveFn;
112 SW_DLLPUBLIC extern SwMoveFn fnMoveForward; // SwPam::Move()/Find() default argument.
113 SW_DLLPUBLIC extern SwMoveFn fnMoveBackward;
115 typedef BOOL (*SwGoInDoc)( SwPaM& rPam, SwMoveFn fnMove );
116 SW_DLLPUBLIC extern SwGoInDoc fnGoDoc;
117 extern SwGoInDoc fnGoSection;
118 SW_DLLPUBLIC extern SwGoInDoc fnGoNode;
119 SW_DLLPUBLIC extern SwGoInDoc fnGoCntnt; // SwPam::Move() default argument.
120 extern SwGoInDoc fnGoCntntCells;
121 extern SwGoInDoc fnGoCntntSkipHidden;
122 extern SwGoInDoc fnGoCntntCellsSkipHidden;
124 void _InitPam();
126 class SW_DLLPUBLIC SwPaM : public Ring
128 SwPosition m_Bound1;
129 SwPosition m_Bound2;
130 SwPosition * m_pPoint; // points at either m_Bound1 or m_Bound2
131 SwPosition * m_pMark; // points at either m_Bound1 or m_Bound2
132 bool m_bIsInFrontOfLabel;
134 SwPaM* MakeRegion( SwMoveFn fnMove, const SwPaM * pOrigRg = 0 );
136 public:
137 SwPaM( const SwPosition& rPos, SwPaM* pRing = 0 );
138 SwPaM( const SwPosition& rMk, const SwPosition& rPt, SwPaM* pRing = 0 );
139 SwPaM( const SwNodeIndex& rMk, const SwNodeIndex& rPt,
140 long nMkOffset = 0, long nPtOffset = 0, SwPaM* pRing = 0 );
141 SwPaM( const SwNode& rMk, const SwNode& rPt,
142 long nMkOffset = 0, long nPtOffset = 0, SwPaM* pRing = 0 );
143 SwPaM( const SwNodeIndex& rMk, xub_StrLen nMkCntnt,
144 const SwNodeIndex& rPt, xub_StrLen nPtCntnt, SwPaM* pRing = 0 );
145 SwPaM( const SwNode& rMk, xub_StrLen nMkCntnt,
146 const SwNode& rPt, xub_StrLen nPtCntnt, SwPaM* pRing = 0 );
147 SwPaM( const SwNode& rNd, xub_StrLen nCntnt = 0, SwPaM* pRing = 0 );
148 SwPaM( const SwNodeIndex& rNd, xub_StrLen nCntnt = 0, SwPaM* pRing = 0 );
149 virtual ~SwPaM();
151 // @@@ semantic: no copy ctor.
152 SwPaM( SwPaM & );
153 // @@@ semantic: no copy assignment for super class Ring.
154 SwPaM& operator=( const SwPaM & );
156 // Bewegen des Cursors
157 BOOL Move( SwMoveFn fnMove = fnMoveForward,
158 SwGoInDoc fnGo = fnGoCntnt );
160 // Suchen
161 BYTE Find( const com::sun::star::util::SearchOptions& rSearchOpt,
162 BOOL bSearchInNotes,
163 utl::TextSearch& rSTxt,
164 SwMoveFn fnMove = fnMoveForward,
165 const SwPaM *pPam =0, BOOL bInReadOnly = FALSE);
166 BOOL Find( const SwFmt& rFmt,
167 SwMoveFn fnMove = fnMoveForward,
168 const SwPaM *pPam =0, BOOL bInReadOnly = FALSE);
169 BOOL Find( const SfxPoolItem& rAttr, BOOL bValue = TRUE,
170 SwMoveFn fnMove = fnMoveForward,
171 const SwPaM *pPam =0, BOOL bInReadOnly = FALSE );
172 BOOL Find( const SfxItemSet& rAttr, BOOL bNoColls,
173 SwMoveFn fnMove,
174 const SwPaM *pPam, BOOL bInReadOnly, BOOL bMoveFirst );
176 bool DoSearch( const com::sun::star::util::SearchOptions& rSearchOpt, utl::TextSearch& rSTxt,
177 SwMoveFn fnMove, BOOL bSrchForward, BOOL bRegSearch, BOOL bChkEmptyPara, BOOL bChkParaEnd,
178 xub_StrLen &nStart, xub_StrLen &nEnde,xub_StrLen nTxtLen,SwNode* pNode, SwPaM* pPam);
180 inline bool IsInFrontOfLabel() const { return m_bIsInFrontOfLabel; }
181 inline void _SetInFrontOfLabel( bool bNew ) { m_bIsInFrontOfLabel = bNew; }
183 virtual void SetMark();
185 void DeleteMark()
187 if (m_pMark != m_pPoint)
189 // clear the mark position; this helps if mark's SwIndex is
190 // registered at some node, and that node is then deleted
191 *m_pMark = SwPosition( SwNodeIndex( GetNode()->GetNodes() ) );
192 m_pMark = m_pPoint;
196 #ifdef PRODUCT
197 void Exchange()
199 if (m_pPoint != m_pMark)
201 SwPosition *pTmp = m_pPoint;
202 m_pPoint = m_pMark;
203 m_pMark = pTmp;
206 #else
207 void Exchange();
208 #endif
210 /** A PaM marks a selection if Point and Mark are distinct positions.
211 @return true iff the PaM spans a selection
213 bool HasMark() const { return m_pPoint == m_pMark ? false : true; }
215 const SwPosition *GetPoint() const { return m_pPoint; }
216 SwPosition *GetPoint() { return m_pPoint; }
217 const SwPosition *GetMark() const { return m_pMark; }
218 SwPosition *GetMark() { return m_pMark; }
220 const SwPosition *Start() const
221 { return (*m_pPoint) <= (*m_pMark) ? m_pPoint : m_pMark; }
222 SwPosition *Start()
223 { return (*m_pPoint) <= (*m_pMark) ? m_pPoint : m_pMark; }
225 const SwPosition *End() const
226 { return (*m_pPoint) > (*m_pMark) ? m_pPoint : m_pMark; }
227 SwPosition *End()
228 { return (*m_pPoint) > (*m_pMark) ? m_pPoint : m_pMark; }
230 /// @return current Node at Point/Mark
231 SwNode * GetNode ( bool bPoint = true ) const
233 return &( bPoint ? m_pPoint->nNode : m_pMark->nNode ).GetNode();
236 /// @return current ContentNode at Point/Mark
237 SwCntntNode* GetCntntNode( bool bPoint = true ) const
239 return GetNode(bPoint)->GetCntntNode();
243 Normalizes PaM, i.e. sort point and mark.
245 @param bPointFirst TRUE: If the point is behind the mark then swap.
246 FALSE: If the mark is behind the point then swap.
248 SwPaM & Normalize(BOOL bPointFirst = TRUE);
250 /// @return the document (SwDoc) at which the PaM is registered
251 SwDoc* GetDoc() const { return m_pPoint->nNode.GetNode().GetDoc(); }
253 SwPosition& GetBound( bool bOne = true )
254 { return bOne ? m_Bound1 : m_Bound2; }
255 const SwPosition& GetBound( bool bOne = true ) const
256 { return bOne ? m_Bound1 : m_Bound2; }
258 // erfrage die Seitennummer auf der der Cursor steht
259 USHORT GetPageNum( BOOL bAtPoint = TRUE, const Point* pLayPos = 0 );
261 // steht in etwas geschuetztem oder in die Selektion umspannt
262 // etwas geschuetztes.
263 BOOL HasReadonlySel( bool bFormView ) const;
265 BOOL ContainsPosition(const SwPosition & rPos)
266 { return *Start() <= rPos && rPos <= *End(); }
268 static BOOL Overlap(const SwPaM & a, const SwPaM & b);
270 static BOOL LessThan(const SwPaM & a, const SwPaM & b);
272 DECL_FIXEDMEMPOOL_NEWDEL(SwPaM);
274 String GetTxt() const;
275 void Invalidate();
279 BOOL CheckNodesRange( const SwNodeIndex&, const SwNodeIndex&, BOOL );
280 BOOL GoInCntnt( SwPaM & rPam, SwMoveFn fnMove );
283 #endif // _PAM_HXX