xref: /AOO41X/main/sw/inc/pam.hxx (revision 23d8f725f835233b771f2c90cead7f17182414a9)
11d2dbeb0SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
31d2dbeb0SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
41d2dbeb0SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
51d2dbeb0SAndrew Rist  * distributed with this work for additional information
61d2dbeb0SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
71d2dbeb0SAndrew Rist  * to you under the Apache License, Version 2.0 (the
81d2dbeb0SAndrew Rist  * "License"); you may not use this file except in compliance
91d2dbeb0SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
111d2dbeb0SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
131d2dbeb0SAndrew Rist  * Unless required by applicable law or agreed to in writing,
141d2dbeb0SAndrew Rist  * software distributed under the License is distributed on an
151d2dbeb0SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
161d2dbeb0SAndrew Rist  * KIND, either express or implied.  See the License for the
171d2dbeb0SAndrew Rist  * specific language governing permissions and limitations
181d2dbeb0SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
201d2dbeb0SAndrew Rist  *************************************************************/
211d2dbeb0SAndrew Rist 
221d2dbeb0SAndrew Rist 
23cdf0e10cSrcweir #ifndef _PAM_HXX
24cdf0e10cSrcweir #define _PAM_HXX
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include <stddef.h>			// fuer MemPool
27cdf0e10cSrcweir #include <tools/gen.hxx>
28cdf0e10cSrcweir #include <tools/mempool.hxx>
29cdf0e10cSrcweir #include <cshtyp.hxx>		// fuer die Funktions-Definitionen
30cdf0e10cSrcweir #include <ring.hxx>			// Superklasse
31cdf0e10cSrcweir #include <index.hxx>		// fuer SwIndex
32cdf0e10cSrcweir #include <ndindex.hxx>		// fuer SwNodeIndex
33cdf0e10cSrcweir #include "swdllapi.h"
34cdf0e10cSrcweir 
35cdf0e10cSrcweir class SwFmt;
36cdf0e10cSrcweir class SfxPoolItem;
37cdf0e10cSrcweir class SfxItemSet;
38cdf0e10cSrcweir class SwDoc;
39cdf0e10cSrcweir class SwNode;
40cdf0e10cSrcweir class SwCntntNode;
41cdf0e10cSrcweir class SwPaM;
42cdf0e10cSrcweir 
43cdf0e10cSrcweir namespace com { namespace sun { namespace star { namespace util {
44cdf0e10cSrcweir 	struct SearchOptions;
45cdf0e10cSrcweir } } } }
46cdf0e10cSrcweir 
47cdf0e10cSrcweir namespace utl {
48cdf0e10cSrcweir 	class TextSearch;
49cdf0e10cSrcweir }
50cdf0e10cSrcweir 
51cdf0e10cSrcweir struct SW_DLLPUBLIC SwPosition
52cdf0e10cSrcweir {
53cdf0e10cSrcweir 	SwNodeIndex nNode;
54cdf0e10cSrcweir 	SwIndex nContent;
55cdf0e10cSrcweir 
56cdf0e10cSrcweir     SwPosition( const SwNodeIndex &rNode, const SwIndex &rCntnt );
57cdf0e10cSrcweir     explicit SwPosition( const SwNodeIndex &rNode );
58cdf0e10cSrcweir     explicit SwPosition( const SwNode& rNode );
59cdf0e10cSrcweir     explicit SwPosition( SwCntntNode& rNode, const xub_StrLen nOffset = 0 );
60cdf0e10cSrcweir 
61cdf0e10cSrcweir 	SwPosition( const SwPosition & );
62cdf0e10cSrcweir 	SwPosition &operator=(const SwPosition &);
63cdf0e10cSrcweir 
64cdf0e10cSrcweir     // #111827#
65cdf0e10cSrcweir     /**
66cdf0e10cSrcweir        Returns the document this position is in.
67cdf0e10cSrcweir 
68cdf0e10cSrcweir        @return the document this position is in.
69cdf0e10cSrcweir     */
70cdf0e10cSrcweir     SwDoc * GetDoc() const;
71cdf0e10cSrcweir 
72cdf0e10cSrcweir 	sal_Bool operator < (const SwPosition &) const;
73cdf0e10cSrcweir 	sal_Bool operator >	(const SwPosition &) const;
74cdf0e10cSrcweir 	sal_Bool operator <=(const SwPosition &) const;
75cdf0e10cSrcweir 	sal_Bool operator >=(const SwPosition &) const;
76cdf0e10cSrcweir 	sal_Bool operator ==(const SwPosition &) const;
77cdf0e10cSrcweir 	sal_Bool operator !=(const SwPosition &) const;
78cdf0e10cSrcweir };
79cdf0e10cSrcweir 
80cdf0e10cSrcweir 
81cdf0e10cSrcweir // das Ergebnis eines Positions Vergleiches
82cdf0e10cSrcweir enum SwComparePosition {
83cdf0e10cSrcweir 	POS_BEFORE,				// Pos1 liegt vor Pos2
84cdf0e10cSrcweir 	POS_BEHIND,				// Pos1 liegt hinter Pos2
85cdf0e10cSrcweir 	POS_INSIDE,				// Pos1 liegt vollstaendig in Pos2
86cdf0e10cSrcweir 	POS_OUTSIDE,			// Pos2 liegt vollstaendig in Pos1
87cdf0e10cSrcweir 	POS_EQUAL,				// Pos1 ist genauso gross wie Pos2
88cdf0e10cSrcweir 	POS_OVERLAP_BEFORE,		// Pos1 ueberlappt Pos2 am Anfang
89cdf0e10cSrcweir 	POS_OVERLAP_BEHIND,		// Pos1 ueberlappt Pos2 am Ende
90cdf0e10cSrcweir 	POS_COLLIDE_START,		// Pos1 Start stoesst an Pos2 Ende
91cdf0e10cSrcweir 	POS_COLLIDE_END			// Pos1 End stoesst an Pos2 Start
92cdf0e10cSrcweir };
93cdf0e10cSrcweir SwComparePosition ComparePosition(
94cdf0e10cSrcweir 			const SwPosition& rStt1, const SwPosition& rEnd1,
95cdf0e10cSrcweir 			const SwPosition& rStt2, const SwPosition& rEnd2 );
96cdf0e10cSrcweir 
97cdf0e10cSrcweir SwComparePosition ComparePosition(
98cdf0e10cSrcweir 			const unsigned long nStt1, const unsigned long nEnd1,
99cdf0e10cSrcweir 			const unsigned long nStt2, const unsigned long nEnd2 );
100cdf0e10cSrcweir 
101cdf0e10cSrcweir 
102cdf0e10cSrcweir // SwPointAndMark / SwPaM
103cdf0e10cSrcweir struct SwMoveFnCollection;
104cdf0e10cSrcweir typedef SwMoveFnCollection* SwMoveFn;
105cdf0e10cSrcweir SW_DLLPUBLIC extern SwMoveFn fnMoveForward; // SwPam::Move()/Find() default argument.
106cdf0e10cSrcweir SW_DLLPUBLIC extern SwMoveFn fnMoveBackward;
107cdf0e10cSrcweir 
108cdf0e10cSrcweir typedef sal_Bool (*SwGoInDoc)( SwPaM& rPam, SwMoveFn fnMove );
109cdf0e10cSrcweir SW_DLLPUBLIC extern SwGoInDoc fnGoDoc;
110cdf0e10cSrcweir extern SwGoInDoc fnGoSection;
111cdf0e10cSrcweir SW_DLLPUBLIC extern SwGoInDoc fnGoNode;
112cdf0e10cSrcweir SW_DLLPUBLIC extern SwGoInDoc fnGoCntnt; // SwPam::Move() default argument.
113cdf0e10cSrcweir extern SwGoInDoc fnGoCntntCells;
114cdf0e10cSrcweir extern SwGoInDoc fnGoCntntSkipHidden;
115cdf0e10cSrcweir extern SwGoInDoc fnGoCntntCellsSkipHidden;
116cdf0e10cSrcweir 
117cdf0e10cSrcweir void _InitPam();
118cdf0e10cSrcweir 
119cdf0e10cSrcweir class SW_DLLPUBLIC SwPaM : public Ring
120cdf0e10cSrcweir {
121cdf0e10cSrcweir     SwPosition   m_Bound1;
122cdf0e10cSrcweir     SwPosition   m_Bound2;
123cdf0e10cSrcweir     SwPosition * m_pPoint; // points at either m_Bound1 or m_Bound2
124cdf0e10cSrcweir     SwPosition * m_pMark;  // points at either m_Bound1 or m_Bound2
125cdf0e10cSrcweir     bool m_bIsInFrontOfLabel;
126cdf0e10cSrcweir 
127cdf0e10cSrcweir 	SwPaM* MakeRegion( SwMoveFn fnMove, const SwPaM * pOrigRg = 0 );
128cdf0e10cSrcweir 
129cdf0e10cSrcweir public:
130cdf0e10cSrcweir 	SwPaM( const SwPosition& rPos, SwPaM* pRing = 0 );
131cdf0e10cSrcweir 	SwPaM( const SwPosition& rMk, const SwPosition& rPt, SwPaM* pRing = 0 );
132cdf0e10cSrcweir 	SwPaM( const SwNodeIndex& rMk, const SwNodeIndex& rPt,
133cdf0e10cSrcweir 		   long nMkOffset = 0, long nPtOffset = 0, SwPaM* pRing = 0 );
134cdf0e10cSrcweir 	SwPaM( const SwNode& rMk, const SwNode& rPt,
135cdf0e10cSrcweir 		   long nMkOffset = 0, long nPtOffset = 0, SwPaM* pRing = 0 );
136cdf0e10cSrcweir 	SwPaM(	const SwNodeIndex& rMk, xub_StrLen nMkCntnt,
137cdf0e10cSrcweir 			const SwNodeIndex& rPt, xub_StrLen nPtCntnt, SwPaM* pRing = 0 );
138cdf0e10cSrcweir 	SwPaM(	const SwNode& rMk, xub_StrLen nMkCntnt,
139cdf0e10cSrcweir 			const SwNode& rPt, xub_StrLen nPtCntnt, SwPaM* pRing = 0 );
140cdf0e10cSrcweir 	SwPaM( const SwNode& rNd, xub_StrLen nCntnt = 0, SwPaM* pRing = 0 );
141cdf0e10cSrcweir 	SwPaM( const SwNodeIndex& rNd, xub_StrLen nCntnt = 0, SwPaM* pRing = 0 );
142cdf0e10cSrcweir 	virtual ~SwPaM();
143cdf0e10cSrcweir 
144cdf0e10cSrcweir 	// @@@ semantic: no copy ctor.
145cdf0e10cSrcweir 	SwPaM( SwPaM & );
146cdf0e10cSrcweir 	// @@@ semantic: no copy assignment for super class Ring.
147cdf0e10cSrcweir 	SwPaM& operator=( const SwPaM & );
148cdf0e10cSrcweir 
149cdf0e10cSrcweir 	// Bewegen des Cursors
150cdf0e10cSrcweir 	sal_Bool Move( SwMoveFn fnMove = fnMoveForward,
151cdf0e10cSrcweir 					SwGoInDoc fnGo = fnGoCntnt );
152cdf0e10cSrcweir 
153cdf0e10cSrcweir 	// Suchen
154cdf0e10cSrcweir 	sal_uInt8 Find(	const com::sun::star::util::SearchOptions& rSearchOpt,
155cdf0e10cSrcweir 				sal_Bool bSearchInNotes,
156cdf0e10cSrcweir 				utl::TextSearch& rSTxt,
157cdf0e10cSrcweir 				SwMoveFn fnMove = fnMoveForward,
158cdf0e10cSrcweir 				const SwPaM *pPam =0, sal_Bool bInReadOnly = sal_False);
159cdf0e10cSrcweir 	sal_Bool Find(	const SwFmt& rFmt,
160cdf0e10cSrcweir 				SwMoveFn fnMove = fnMoveForward,
161cdf0e10cSrcweir 				const SwPaM *pPam =0, sal_Bool bInReadOnly = sal_False);
162cdf0e10cSrcweir 	sal_Bool Find(	const SfxPoolItem& rAttr, sal_Bool bValue = sal_True,
163cdf0e10cSrcweir 				SwMoveFn fnMove = fnMoveForward,
164cdf0e10cSrcweir 				const SwPaM *pPam =0, sal_Bool bInReadOnly = sal_False );
165cdf0e10cSrcweir 	sal_Bool Find(	const SfxItemSet& rAttr, sal_Bool bNoColls,
166cdf0e10cSrcweir 				SwMoveFn fnMove,
167cdf0e10cSrcweir 				const SwPaM *pPam, sal_Bool bInReadOnly, sal_Bool bMoveFirst );
168cdf0e10cSrcweir 
169cdf0e10cSrcweir 	bool DoSearch( const com::sun::star::util::SearchOptions& rSearchOpt, utl::TextSearch& rSTxt,
170cdf0e10cSrcweir 					SwMoveFn fnMove, sal_Bool bSrchForward, sal_Bool bRegSearch, sal_Bool bChkEmptyPara, sal_Bool bChkParaEnd,
171cdf0e10cSrcweir 					xub_StrLen &nStart, xub_StrLen &nEnde,xub_StrLen nTxtLen,SwNode* pNode, SwPaM* pPam);
172cdf0e10cSrcweir 
IsInFrontOfLabel() const173cdf0e10cSrcweir     inline bool IsInFrontOfLabel() const        { return m_bIsInFrontOfLabel; }
_SetInFrontOfLabel(bool bNew)174cdf0e10cSrcweir     inline void _SetInFrontOfLabel( bool bNew ) { m_bIsInFrontOfLabel = bNew; }
175cdf0e10cSrcweir 
176cdf0e10cSrcweir     virtual void SetMark();
177cdf0e10cSrcweir 
DeleteMark()178cdf0e10cSrcweir     void DeleteMark()
179cdf0e10cSrcweir     {
180cdf0e10cSrcweir         if (m_pMark != m_pPoint)
181cdf0e10cSrcweir         {
182cdf0e10cSrcweir             // clear the mark position; this helps if mark's SwIndex is
183cdf0e10cSrcweir             // registered at some node, and that node is then deleted
184cdf0e10cSrcweir             *m_pMark = SwPosition( SwNodeIndex( GetNode()->GetNodes() ) );
185cdf0e10cSrcweir             m_pMark = m_pPoint;
186cdf0e10cSrcweir         }
187cdf0e10cSrcweir     }
188cdf0e10cSrcweir #ifndef DBG_UTIL
189cdf0e10cSrcweir 
Exchange()190cdf0e10cSrcweir     void Exchange()
191cdf0e10cSrcweir     {
192cdf0e10cSrcweir         if (m_pPoint != m_pMark)
193cdf0e10cSrcweir         {
194cdf0e10cSrcweir             SwPosition *pTmp = m_pPoint;
195cdf0e10cSrcweir             m_pPoint = m_pMark;
196cdf0e10cSrcweir             m_pMark = pTmp;
197cdf0e10cSrcweir         }
198cdf0e10cSrcweir     }
199cdf0e10cSrcweir #else
200cdf0e10cSrcweir     void Exchange();
201cdf0e10cSrcweir #endif
202cdf0e10cSrcweir 
203cdf0e10cSrcweir     /** A PaM marks a selection if Point and Mark are distinct positions.
204cdf0e10cSrcweir         @return     true iff the PaM spans a selection
205cdf0e10cSrcweir      */
HasMark() const206cdf0e10cSrcweir     bool HasMark() const { return m_pPoint == m_pMark ? false : true; }
207cdf0e10cSrcweir 
GetPoint() const208cdf0e10cSrcweir     const SwPosition *GetPoint() const { return m_pPoint; }
GetPoint()209cdf0e10cSrcweir           SwPosition *GetPoint()       { return m_pPoint; }
GetMark() const210cdf0e10cSrcweir     const SwPosition *GetMark()  const { return m_pMark; }
GetMark()211cdf0e10cSrcweir           SwPosition *GetMark()        { return m_pMark; }
212cdf0e10cSrcweir 
Start() const213cdf0e10cSrcweir     const SwPosition *Start() const
214cdf0e10cSrcweir                 { return (*m_pPoint) <= (*m_pMark) ? m_pPoint : m_pMark; }
Start()215cdf0e10cSrcweir           SwPosition *Start()
216cdf0e10cSrcweir                 { return (*m_pPoint) <= (*m_pMark) ? m_pPoint : m_pMark; }
217cdf0e10cSrcweir 
End() const218cdf0e10cSrcweir     const SwPosition *End()   const
219cdf0e10cSrcweir                 { return (*m_pPoint) >  (*m_pMark) ? m_pPoint : m_pMark; }
End()220cdf0e10cSrcweir           SwPosition *End()
221cdf0e10cSrcweir                 { return (*m_pPoint) >  (*m_pMark) ? m_pPoint : m_pMark; }
222cdf0e10cSrcweir 
223cdf0e10cSrcweir     /// @return current Node at Point/Mark
GetNode(bool bPoint=true) const224cdf0e10cSrcweir     SwNode    * GetNode      ( bool bPoint = true ) const
225cdf0e10cSrcweir     {
226cdf0e10cSrcweir         return &( bPoint ? m_pPoint->nNode : m_pMark->nNode ).GetNode();
227cdf0e10cSrcweir     }
228cdf0e10cSrcweir 
229cdf0e10cSrcweir     /// @return current ContentNode at Point/Mark
GetCntntNode(bool bPoint=true) const230cdf0e10cSrcweir     SwCntntNode* GetCntntNode( bool bPoint = true ) const
231cdf0e10cSrcweir     {
232cdf0e10cSrcweir         return GetNode(bPoint)->GetCntntNode();
233cdf0e10cSrcweir     }
234cdf0e10cSrcweir 
235cdf0e10cSrcweir     /**
236cdf0e10cSrcweir        Normalizes PaM, i.e. sort point and mark.
237cdf0e10cSrcweir 
238cdf0e10cSrcweir        @param bPointFirst sal_True: If the point is behind the mark then swap.
239cdf0e10cSrcweir                           sal_False: If the mark is behind the point then swap.
240cdf0e10cSrcweir     */
241cdf0e10cSrcweir     SwPaM & Normalize(sal_Bool bPointFirst = sal_True);
242cdf0e10cSrcweir 
243cdf0e10cSrcweir     /// @return the document (SwDoc) at which the PaM is registered
GetDoc() const244cdf0e10cSrcweir     SwDoc* GetDoc() const   { return m_pPoint->nNode.GetNode().GetDoc(); }
245cdf0e10cSrcweir 
GetBound(bool bOne=true)246cdf0e10cSrcweir           SwPosition& GetBound( bool bOne = true )
247cdf0e10cSrcweir                             { return bOne ? m_Bound1 : m_Bound2; }
GetBound(bool bOne=true) const248cdf0e10cSrcweir     const SwPosition& GetBound( bool bOne = true ) const
249cdf0e10cSrcweir                             { return bOne ? m_Bound1 : m_Bound2; }
250cdf0e10cSrcweir 
251cdf0e10cSrcweir 	// erfrage die Seitennummer auf der der Cursor steht
252cdf0e10cSrcweir 	sal_uInt16 GetPageNum( sal_Bool bAtPoint = sal_True, const Point* pLayPos = 0 );
253cdf0e10cSrcweir 
254cdf0e10cSrcweir 	// steht in etwas geschuetztem oder in die Selektion umspannt
255cdf0e10cSrcweir 	// etwas geschuetztes.
256*23d8f725SOliver-Rainer Wittmann     sal_Bool HasReadonlySel( const bool bFormView ) const;
257cdf0e10cSrcweir 
ContainsPosition(const SwPosition & rPos)258cdf0e10cSrcweir     sal_Bool ContainsPosition(const SwPosition & rPos)
259cdf0e10cSrcweir     { return *Start() <= rPos && rPos <= *End(); }
260cdf0e10cSrcweir 
261cdf0e10cSrcweir     static sal_Bool Overlap(const SwPaM & a, const SwPaM & b);
262cdf0e10cSrcweir 
263cdf0e10cSrcweir     static sal_Bool LessThan(const SwPaM & a, const SwPaM & b);
264cdf0e10cSrcweir 
265cdf0e10cSrcweir 	DECL_FIXEDMEMPOOL_NEWDEL(SwPaM);
266cdf0e10cSrcweir 
267cdf0e10cSrcweir     String GetTxt() const;
268cdf0e10cSrcweir     void InvalidatePaM();
269cdf0e10cSrcweir };
270cdf0e10cSrcweir 
271cdf0e10cSrcweir 
272cdf0e10cSrcweir sal_Bool CheckNodesRange( const SwNodeIndex&, const SwNodeIndex&, sal_Bool );
273cdf0e10cSrcweir sal_Bool GoInCntnt( SwPaM & rPam, SwMoveFn fnMove );
274cdf0e10cSrcweir 
275cdf0e10cSrcweir 
276cdf0e10cSrcweir #endif	// _PAM_HXX
277