1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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 ************************************************************************/
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
50 namespace com
{ namespace sun
{ namespace star
{ namespace util
{
58 struct SW_DLLPUBLIC SwPosition
63 SwPosition( const SwNode
& rNode
);
64 SwPosition( const SwNodeIndex
&rNode
);
65 SwPosition( const SwNodeIndex
&rNode
, const SwIndex
&rCntnt
);
66 /* @@@MAINTAINABILITY-HORROR@@@
67 SwPosition desperately needs a constructor
68 SwPosition( const SwNode& rNode, xub_StrLen nOffset );
71 SwPosition( const SwPosition
& );
72 SwPosition
&operator=(const SwPosition
&);
76 Returns the document this position is in.
78 @return the document this position is in.
80 SwDoc
* GetDoc() const;
82 BOOL
operator < (const SwPosition
&) const;
83 BOOL
operator > (const SwPosition
&) const;
84 BOOL
operator <=(const SwPosition
&) const;
85 BOOL
operator >=(const SwPosition
&) const;
86 BOOL
operator ==(const SwPosition
&) const;
87 BOOL
operator !=(const SwPosition
&) const;
91 // das Ergebnis eines Positions Vergleiches
92 enum SwComparePosition
{
93 POS_BEFORE
, // Pos1 liegt vor Pos2
94 POS_BEHIND
, // Pos1 liegt hinter Pos2
95 POS_INSIDE
, // Pos1 liegt vollstaendig in Pos2
96 POS_OUTSIDE
, // Pos2 liegt vollstaendig in Pos1
97 POS_EQUAL
, // Pos1 ist genauso gross wie Pos2
98 POS_OVERLAP_BEFORE
, // Pos1 ueberlappt Pos2 am Anfang
99 POS_OVERLAP_BEHIND
, // Pos1 ueberlappt Pos2 am Ende
100 POS_COLLIDE_START
, // Pos1 Start stoesst an Pos2 Ende
101 POS_COLLIDE_END
// Pos1 End stoesst an Pos2 Start
103 SwComparePosition
ComparePosition(
104 const SwPosition
& rStt1
, const SwPosition
& rEnd1
,
105 const SwPosition
& rStt2
, const SwPosition
& rEnd2
);
107 SwComparePosition
ComparePosition(
108 const unsigned long nStt1
, const unsigned long nEnd1
,
109 const unsigned long nStt2
, const unsigned long nEnd2
);
112 // SwPointAndMark / SwPaM
113 struct SwMoveFnCollection
;
114 typedef SwMoveFnCollection
* SwMoveFn
;
115 SW_DLLPUBLIC
extern SwMoveFn fnMoveForward
; // SwPam::Move()/Find() default argument.
116 SW_DLLPUBLIC
extern SwMoveFn fnMoveBackward
;
118 typedef BOOL (*SwGoInDoc
)( SwPaM
& rPam
, SwMoveFn fnMove
);
119 SW_DLLPUBLIC
extern SwGoInDoc fnGoDoc
;
120 extern SwGoInDoc fnGoSection
;
121 SW_DLLPUBLIC
extern SwGoInDoc fnGoNode
;
122 SW_DLLPUBLIC
extern SwGoInDoc fnGoCntnt
; // SwPam::Move() default argument.
123 extern SwGoInDoc fnGoCntntCells
;
124 extern SwGoInDoc fnGoCntntSkipHidden
;
125 extern SwGoInDoc fnGoCntntCellsSkipHidden
;
129 class SW_DLLPUBLIC SwPaM
: public Ring
135 BOOL bIsInFrontOfLabel
;
137 SwPaM
* MakeRegion( SwMoveFn fnMove
, const SwPaM
* pOrigRg
= 0 );
140 SwPaM( const SwPosition
& rPos
, SwPaM
* pRing
= 0 );
141 SwPaM( const SwPosition
& rMk
, const SwPosition
& rPt
, SwPaM
* pRing
= 0 );
142 SwPaM( const SwNodeIndex
& rMk
, const SwNodeIndex
& rPt
,
143 long nMkOffset
= 0, long nPtOffset
= 0, SwPaM
* pRing
= 0 );
144 SwPaM( const SwNode
& rMk
, const SwNode
& rPt
,
145 long nMkOffset
= 0, long nPtOffset
= 0, SwPaM
* pRing
= 0 );
146 SwPaM( const SwNodeIndex
& rMk
, xub_StrLen nMkCntnt
,
147 const SwNodeIndex
& rPt
, xub_StrLen nPtCntnt
, SwPaM
* pRing
= 0 );
148 SwPaM( const SwNode
& rMk
, xub_StrLen nMkCntnt
,
149 const SwNode
& rPt
, xub_StrLen nPtCntnt
, SwPaM
* pRing
= 0 );
150 SwPaM( const SwNode
& rNd
, xub_StrLen nCntnt
= 0, SwPaM
* pRing
= 0 );
151 SwPaM( const SwNodeIndex
& rNd
, xub_StrLen nCntnt
= 0, SwPaM
* pRing
= 0 );
154 // @@@ semantic: no copy ctor.
156 // @@@ semantic: no copy assignment for super class Ring.
157 SwPaM
& operator=( const SwPaM
& );
159 // Bewegen des Cursors
160 BOOL
Move( SwMoveFn fnMove
= fnMoveForward
,
161 SwGoInDoc fnGo
= fnGoCntnt
);
164 BYTE
Find( const com::sun::star::util::SearchOptions
& rSearchOpt
,
166 utl::TextSearch
& rSTxt
,
167 SwMoveFn fnMove
= fnMoveForward
,
168 const SwPaM
*pPam
=0, BOOL bInReadOnly
= FALSE
);
169 BOOL
Find( const SwFmt
& rFmt
,
170 SwMoveFn fnMove
= fnMoveForward
,
171 const SwPaM
*pPam
=0, BOOL bInReadOnly
= FALSE
);
172 BOOL
Find( const SfxPoolItem
& rAttr
, BOOL bValue
= TRUE
,
173 SwMoveFn fnMove
= fnMoveForward
,
174 const SwPaM
*pPam
=0, BOOL bInReadOnly
= FALSE
);
175 BOOL
Find( const SfxItemSet
& rAttr
, BOOL bNoColls
,
177 const SwPaM
*pPam
, BOOL bInReadOnly
, BOOL bMoveFirst
);
179 bool DoSearch( const com::sun::star::util::SearchOptions
& rSearchOpt
, utl::TextSearch
& rSTxt
,
180 SwMoveFn fnMove
, BOOL bSrchForward
, BOOL bRegSearch
, BOOL bChkEmptyPara
, BOOL bChkParaEnd
,
181 xub_StrLen
&nStart
, xub_StrLen
&nEnde
,xub_StrLen nTxtLen
,SwNode
* pNode
, SwPaM
* pPam
);
183 inline BOOL
IsInFrontOfLabel() const { return bIsInFrontOfLabel
; }
184 inline void _SetInFrontOfLabel( BOOL bNew
) { bIsInFrontOfLabel
= bNew
; }
186 virtual void SetMark();
187 void DeleteMark() { pMark
= pPoint
; }
193 SwPosition
*pTmp
= pPoint
;
202 * Undocumented Feature: Liefert zurueck, ob das Pam ueber
203 * eine Selektion verfuegt oder nicht. Definition einer
204 * Selektion: Point und Mark zeigen auf unterschiedliche
207 BOOL
HasMark() const { return pPoint
== pMark
? FALSE
: TRUE
; }
209 const SwPosition
*GetPoint() const { return pPoint
; }
210 SwPosition
*GetPoint() { return pPoint
; }
211 const SwPosition
*GetMark() const { return pMark
; }
212 SwPosition
*GetMark() { return pMark
; }
214 const SwPosition
*Start() const
215 { return (*pPoint
) <= (*pMark
)? pPoint
: pMark
; }
217 { return (*pPoint
) <= (*pMark
)? pPoint
: pMark
; }
218 const SwPosition
*End() const
219 { return (*pPoint
) > (*pMark
)? pPoint
: pMark
; }
221 { return (*pPoint
) > (*pMark
)? pPoint
: pMark
; }
223 // erfrage vom SwPaM den aktuellen Node/ContentNode am SPoint / Mark
224 SwNode
* GetNode( BOOL bPoint
= TRUE
) const
226 return &( bPoint
? pPoint
->nNode
: pMark
->nNode
).GetNode();
228 SwCntntNode
* GetCntntNode( BOOL bPoint
= TRUE
) const
230 return ( bPoint
? pPoint
->nNode
: pMark
->nNode
).GetNode().GetCntntNode();
234 Normalizes PaM, i.e. sort point and mark.
236 @param bPointFirst TRUE: If the point is behind the mark then swap.
237 FALSE: If the mark is behind the point then swap.
239 SwPaM
& Normalize(BOOL bPointFirst
= TRUE
);
241 // erfrage vom SwPaM das Dokument, in dem er angemeldet ist
242 SwDoc
* GetDoc() const { return pPoint
->nNode
.GetNode().GetDoc(); }
243 SwPosition
& GetBound( BOOL bOne
= TRUE
)
244 { return bOne
? aBound1
: aBound2
; }
245 const SwPosition
& GetBound( BOOL bOne
= TRUE
) const
246 { return bOne
? aBound1
: aBound2
; }
248 // erfrage die Seitennummer auf der der Cursor steht
249 USHORT
GetPageNum( BOOL bAtPoint
= TRUE
, const Point
* pLayPos
= 0 );
251 // steht in etwas geschuetztem oder in die Selektion umspannt
252 // etwas geschuetztes.
253 BOOL
HasReadonlySel( bool bFormView
) const;
255 BOOL
ContainsPosition(const SwPosition
& rPos
)
256 { return *Start() <= rPos
&& rPos
<= *End(); }
258 static BOOL
Overlap(const SwPaM
& a
, const SwPaM
& b
);
260 static BOOL
LessThan(const SwPaM
& a
, const SwPaM
& b
);
262 DECL_FIXEDMEMPOOL_NEWDEL(SwPaM
);
264 String
GetTxt() const;
269 BOOL
CheckNodesRange( const SwNodeIndex
&, const SwNodeIndex
&, BOOL
);
270 BOOL
GoInCntnt( SwPaM
& rPam
, SwMoveFn fnMove
);