xref: /aoo42x/main/sw/inc/swcrsr.hxx (revision 1d2dbeb0)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #ifndef _SWCRSR_HXX
24 #define _SWCRSR_HXX
25 
26 #include <com/sun/star/i18n/WordType.hpp>
27 
28 #include <pam.hxx>
29 #include <tblsel.hxx>
30 #include <cshtyp.hxx>
31 
32 
33 struct _SwCursor_SavePos;
34 
35 namespace com { namespace sun { namespace star { namespace util {
36 	struct SearchOptions;
37 } } } }
38 
39 
40 // ein Basis-Struktur fuer die Parameter der Find-Methoden
41 // return - Werte vom Found-Aufruf.
42 const int FIND_NOT_FOUND	= 0;
43 const int FIND_FOUND		= 1;
44 const int FIND_NO_RING		= 2;
45 
46 struct SwFindParas
47 {
48 	virtual int Find( SwPaM*, SwMoveFn, const SwPaM*, sal_Bool ) = 0;
49 	virtual int IsReplaceMode() const = 0;
50 };
51 
52 typedef sal_uInt16 SwCursorSelOverFlags;
53 namespace nsSwCursorSelOverFlags
54 {
55     const SwCursorSelOverFlags SELOVER_NONE                = 0x00;
56     const SwCursorSelOverFlags SELOVER_CHECKNODESSECTION   = 0x01;
57     const SwCursorSelOverFlags SELOVER_TOGGLE              = 0x02;
58     const SwCursorSelOverFlags SELOVER_ENABLEREVDIREKTION  = 0x04;
59     const SwCursorSelOverFlags SELOVER_CHANGEPOS           = 0x08;
60 }
61 
62 class SwCursor : public SwPaM
63 {
64 	friend class SwCrsrSaveState;
65 
66 	_SwCursor_SavePos* pSavePos;
67     long mnRowSpanOffset;        // required for travelling in tabs with rowspans
68     sal_uInt8 nCursorBidiLevel;       // bidi level of the cursor
69     bool mbColumnSelection;      // true: cursor is aprt of a column selection
70 
71     sal_uLong FindAll( SwFindParas& , SwDocPositions, SwDocPositions, FindRanges, sal_Bool& bCancel );
72 
73     using SwPaM::Find;
74 
75 protected:
76 	virtual _SwCursor_SavePos* CreateNewSavePos() const;
77 	void SaveState();
78 	void RestoreState();
79 
GetSavePos() const80 	const _SwCursor_SavePos* GetSavePos() const { return pSavePos; }
81 
82     virtual const SwCntntFrm* DoSetBidiLevelLeftRight(
83         sal_Bool & io_rbLeft, sal_Bool bVisualAllowed, sal_Bool bInsertCrsr);
84     virtual void DoSetBidiLevelUpDown();
85     virtual bool IsSelOvrCheck(int eFlags);
86 
87 public:
88 	// single argument ctors shall be explicit.
89 	SwCursor( const SwPosition &rPos, SwPaM* pRing, bool bColumnSel );
90 	virtual ~SwCursor();
91 
92 	// @@@ semantic: no copy ctor.
93 	SwCursor( SwCursor& rCpy);
94 
95 public:
96 
97 	virtual SwCursor* Create( SwPaM* pRing = 0 ) const;
98 
99     virtual short MaxReplaceArived(); //returns RET_YES/RET_CANCEL/RET_NO
100     virtual void SaveTblBoxCntnt( const SwPosition* pPos = 0 );
101 
102 	void FillFindPos( SwDocPositions ePos, SwPosition& rPos ) const;
103 	SwMoveFnCollection* MakeFindRange( SwDocPositions, SwDocPositions,
104 										SwPaM* ) const;
105 
106 
107 	sal_uLong Find( const com::sun::star::util::SearchOptions& rSearchOpt,
108 				sal_Bool bSearchInNotes,
109 				SwDocPositions nStart, SwDocPositions nEnde,
110                 sal_Bool& bCancel,
111                 FindRanges = FND_IN_BODY,
112 				int bReplace = sal_False );
113 	sal_uLong Find( const SwTxtFmtColl& rFmtColl,
114 				SwDocPositions nStart, SwDocPositions nEnde,
115                 sal_Bool& bCancel,
116                 FindRanges = FND_IN_BODY,
117 				const SwTxtFmtColl* pReplFmt = 0 );
118 	sal_uLong Find( const SfxItemSet& rSet, sal_Bool bNoCollections,
119 				SwDocPositions nStart, SwDocPositions nEnde,
120                 sal_Bool& bCancel,
121                 FindRanges = FND_IN_BODY,
122 				const com::sun::star::util::SearchOptions* pSearchOpt = 0,
123 				const SfxItemSet* rReplSet = 0 );
124 
125     // UI versions
126     sal_Bool IsStartWord( sal_Int16 nWordType = com::sun::star::i18n::WordType::ANYWORD_IGNOREWHITESPACES ) const;
127     sal_Bool IsEndWord( sal_Int16 nWordType = com::sun::star::i18n::WordType::ANYWORD_IGNOREWHITESPACES ) const;
128     sal_Bool IsInWord( sal_Int16 nWordType = com::sun::star::i18n::WordType::ANYWORD_IGNOREWHITESPACES ) const;
129     sal_Bool IsStartEndSentence( bool bEnd ) const;
130     sal_Bool GoStartWord();
131     sal_Bool GoEndWord();
132     sal_Bool GoNextWord();
133     sal_Bool GoPrevWord();
134     sal_Bool SelectWord( ViewShell* pViewShell, const Point* pPt = 0 );
135 
136     // API versions of above functions (will be used with a different
137     // WordType for the break iterator)
138     sal_Bool IsStartWordWT( sal_Int16 nWordType ) const;
139     sal_Bool IsEndWordWT( sal_Int16 nWordType ) const;
140     sal_Bool IsInWordWT( sal_Int16 nWordType ) const;
141     sal_Bool GoStartWordWT( sal_Int16 nWordType );
142     sal_Bool GoEndWordWT( sal_Int16 nWordType );
143     sal_Bool GoNextWordWT( sal_Int16 nWordType );
144     sal_Bool GoPrevWordWT( sal_Int16 nWordType );
145     sal_Bool SelectWordWT( ViewShell* pViewShell, sal_Int16 nWordType, const Point* pPt = 0 );
146 
147 	enum SentenceMoveType
148 	{
149 		NEXT_SENT,
150 		PREV_SENT,
151 		START_SENT,
152 		END_SENT
153 	};
154     sal_Bool GoSentence(SentenceMoveType eMoveType);
GoNextSentence()155 	sal_Bool GoNextSentence(){return GoSentence(NEXT_SENT);}
GoEndSentence()156     sal_Bool GoEndSentence(){return GoSentence(END_SENT);}
GoPrevSentence()157     sal_Bool GoPrevSentence(){return GoSentence(PREV_SENT);}
GoStartSentence()158     sal_Bool GoStartSentence(){return GoSentence(START_SENT);}
159     sal_Bool ExpandToSentenceBorders();
160 
161     virtual sal_Bool LeftRight( sal_Bool bLeft, sal_uInt16 nCnt, sal_uInt16 nMode,
162         sal_Bool bAllowVisual, sal_Bool bSkipHidden, sal_Bool bInsertCrsr );
163 	sal_Bool UpDown( sal_Bool bUp, sal_uInt16 nCnt, Point* pPt, long nUpDownX );
164 	sal_Bool LeftRightMargin( sal_Bool bLeftMargin, sal_Bool bAPI = sal_False );
165 	sal_Bool IsAtLeftRightMargin( sal_Bool bLeftMargin, sal_Bool bAPI = sal_False ) const;
166 	sal_Bool SttEndDoc( sal_Bool bSttDoc );
167 	sal_Bool GoPrevNextCell( sal_Bool bNext, sal_uInt16 nCnt );
168 
Left(sal_uInt16 nCnt,sal_uInt16 nMode,sal_Bool bAllowVisual,sal_Bool bSkipHidden)169     sal_Bool Left( sal_uInt16 nCnt, sal_uInt16 nMode, sal_Bool bAllowVisual, sal_Bool bSkipHidden )
170                                     { return LeftRight( sal_True, nCnt, nMode, bAllowVisual, bSkipHidden, sal_False ); }
Right(sal_uInt16 nCnt,sal_uInt16 nMode,sal_Bool bAllowVisual,sal_Bool bSkipHidden)171     sal_Bool Right( sal_uInt16 nCnt, sal_uInt16 nMode, sal_Bool bAllowVisual, sal_Bool bSkipHidden )
172                                     { return LeftRight( sal_False, nCnt, nMode, bAllowVisual, bSkipHidden, sal_False ); }
GoNextCell(sal_uInt16 nCnt=1)173     sal_Bool GoNextCell( sal_uInt16 nCnt = 1 )  { return GoPrevNextCell( sal_True, nCnt ); }
GoPrevCell(sal_uInt16 nCnt=1)174 	sal_Bool GoPrevCell( sal_uInt16 nCnt = 1 )	{ return GoPrevNextCell( sal_False, nCnt ); }
175     virtual sal_Bool GotoTable( const String& rName );
176 	sal_Bool GotoTblBox( const String& rName );
177 	sal_Bool GotoRegion( const String& rName );
178 	sal_Bool GotoFtnAnchor();
179 	sal_Bool GotoFtnTxt();
180 	sal_Bool GotoNextFtnAnchor();
181 	sal_Bool GotoPrevFtnAnchor();
182 	sal_Bool GotoNextFtnCntnt();
183 	sal_Bool GotoPrevFtnCntnt();
184 
185 	sal_Bool MovePara( SwWhichPara, SwPosPara );
186 	sal_Bool MoveSection( SwWhichSection, SwPosSection );
187 	sal_Bool MoveTable( SwWhichTable, SwPosTable );
188 	sal_Bool MoveRegion( SwWhichRegion, SwPosRegion );
189 
190 
191 	// gibt es eine Selection vom Content in die Tabelle
192 	// Return Wert gibt an, ob der Crsr auf der alten Position verbleibt
193 	virtual sal_Bool IsSelOvr( int eFlags =
194                                 ( nsSwCursorSelOverFlags::SELOVER_CHECKNODESSECTION |
195                                   nsSwCursorSelOverFlags::SELOVER_TOGGLE |
196                                   nsSwCursorSelOverFlags::SELOVER_CHANGEPOS ));
197 	virtual sal_Bool IsInProtectTable( sal_Bool bMove = sal_False,
198 										sal_Bool bChgCrsr = sal_True );
199 	sal_Bool IsNoCntnt() const;
200 
201 	void RestoreSavePos();		// Point auf die SavePos setzen
202 
203 	// sal_True: an die Position kann der Cursor gesetzt werden
204 	virtual sal_Bool IsAtValidPos( sal_Bool bPoint = sal_True ) const;
205 
206 	// darf der Cursor in ReadOnlyBereiche?
207     virtual bool IsReadOnlyAvailable() const;
208 
209     virtual sal_Bool IsSkipOverProtectSections() const;
210     virtual sal_Bool IsSkipOverHiddenSections() const;
211 
GetCrsrBidiLevel() const212     sal_uInt8 GetCrsrBidiLevel() const { return nCursorBidiLevel; }
SetCrsrBidiLevel(sal_uInt8 nNewLevel)213     void SetCrsrBidiLevel( sal_uInt8 nNewLevel ) { nCursorBidiLevel = nNewLevel; }
214 
IsColumnSelection() const215     bool IsColumnSelection() const { return mbColumnSelection; }
SetColumnSelection(bool bNew)216     void SetColumnSelection( bool bNew ) { mbColumnSelection = bNew; }
217 
GetCrsrRowSpanOffset() const218     long GetCrsrRowSpanOffset() const { return mnRowSpanOffset; }
SetCrsrRowSpanOffset(long nNew)219     void SetCrsrRowSpanOffset( long nNew ) { mnRowSpanOffset = nNew; }
220 
221     DECL_FIXEDMEMPOOL_NEWDEL( SwCursor )
222 };
223 
224 
225 class SwCrsrSaveState
226 {
227 	SwCursor& rCrsr;
228 public:
SwCrsrSaveState(SwCursor & rC)229 	SwCrsrSaveState( SwCursor& rC ) : rCrsr( rC ) { rC.SaveState(); }
~SwCrsrSaveState()230 	~SwCrsrSaveState() { rCrsr.RestoreState(); }
231 };
232 
233 struct _SwCursor_SavePos
234 {
235 	sal_uLong nNode;
236 	xub_StrLen nCntnt;
237 	_SwCursor_SavePos* pNext;
238 
_SwCursor_SavePos_SwCursor_SavePos239 	_SwCursor_SavePos( const SwCursor& rCrsr )
240 		: nNode( rCrsr.GetPoint()->nNode.GetIndex() ),
241 		nCntnt( rCrsr.GetPoint()->nContent.GetIndex() ),
242 		pNext( 0 )
243 	{}
~_SwCursor_SavePos_SwCursor_SavePos244 	virtual ~_SwCursor_SavePos() {}
245 
246 	DECL_FIXEDMEMPOOL_NEWDEL( _SwCursor_SavePos )
247 };
248 
249 
250 
251 class SwTableCursor : public virtual SwCursor
252 {
253 
254 protected:
255 	sal_uLong nTblPtNd, nTblMkNd;
256 	xub_StrLen nTblPtCnt, nTblMkCnt;
257 	SwSelBoxes aSelBoxes;
258 	sal_Bool bChg : 1;
259 	sal_Bool bParked : 1;		// Tabellen-Cursor wurde geparkt
260 
261     virtual bool IsSelOvrCheck(int eFlags);
262 
263 public:
264 	SwTableCursor( const SwPosition &rPos, SwPaM* pRing = 0 );
265 	SwTableCursor( SwTableCursor& );
266 	virtual ~SwTableCursor();
267 
268     virtual sal_Bool LeftRight( sal_Bool bLeft, sal_uInt16 nCnt, sal_uInt16 nMode,
269         sal_Bool bAllowVisual, sal_Bool bSkipHidden, sal_Bool bInsertCrsr );
270     virtual sal_Bool GotoTable( const String& rName );
271 
272 	void InsertBox( const SwTableBox& rTblBox );
DeleteBox(sal_uInt16 nPos)273 	void DeleteBox( sal_uInt16 nPos ) { aSelBoxes.Remove( nPos ); bChg = sal_True; }
GetBoxesCount() const274 	sal_uInt16 GetBoxesCount() const { return aSelBoxes.Count(); }
GetBoxes() const275 	const SwSelBoxes& GetBoxes() const { return aSelBoxes; }
276 
277 		// Baut fuer alle Boxen die Cursor auf
278 	SwCursor* MakeBoxSels( SwCursor* pAktCrsr );
279 		// sind irgendwelche Boxen mit einem Schutz versehen?
280 	sal_Bool HasReadOnlyBoxSel() const;
281 
282 		// wurde der TabelleCursor veraendert ? Wenn ja speicher gleich
283 		// die neuen Werte.
284 	sal_Bool IsCrsrMovedUpdt();
285 		// wurde der TabelleCursor veraendert ?
IsCrsrMoved() const286 	sal_Bool IsCrsrMoved() const
287 	{
288 		return	nTblMkNd != GetMark()->nNode.GetIndex() ||
289 				nTblPtNd != GetPoint()->nNode.GetIndex() ||
290 				nTblMkCnt != GetMark()->nContent.GetIndex() ||
291 				nTblPtCnt != GetPoint()->nContent.GetIndex();
292 	}
293 
IsChgd() const294 	sal_Bool IsChgd() const { return bChg; }
295 
296 	// Parke den Tabellen-Cursor auf dem StartNode der Boxen.
297 	void ParkCrsr();
298 
299     bool NewTableSelection();
300     void ActualizeSelection( const SwSelBoxes &rBoxes );
301 };
302 
303 #endif
304 
305