Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : : #ifndef _SWCRSR_HXX
29 : : #define _SWCRSR_HXX
30 : :
31 : : #include <com/sun/star/i18n/WordType.hpp>
32 : :
33 : : #include <pam.hxx>
34 : : #include <tblsel.hxx>
35 : : #include <cshtyp.hxx>
36 : :
37 : :
38 : : struct _SwCursor_SavePos;
39 : :
40 : : namespace com { namespace sun { namespace star { namespace util {
41 : : struct SearchOptions;
42 : : } } } }
43 : :
44 : :
45 : : // Base structure for parameters of the find-methods.
46 : : // Returns values of found-call.
47 : : const int FIND_NOT_FOUND = 0;
48 : : const int FIND_FOUND = 1;
49 : : const int FIND_NO_RING = 2;
50 : :
51 : 18 : struct SwFindParas
52 : : {
53 : : virtual int Find( SwPaM*, SwMoveFn, const SwPaM*, sal_Bool ) = 0;
54 : : virtual int IsReplaceMode() const = 0;
55 : :
56 : : protected:
57 : 18 : ~SwFindParas() {}
58 : : };
59 : :
60 : : typedef sal_uInt16 SwCursorSelOverFlags;
61 : : namespace nsSwCursorSelOverFlags
62 : : {
63 : : const SwCursorSelOverFlags SELOVER_NONE = 0x00;
64 : : const SwCursorSelOverFlags SELOVER_CHECKNODESSECTION = 0x01;
65 : : const SwCursorSelOverFlags SELOVER_TOGGLE = 0x02;
66 : : const SwCursorSelOverFlags SELOVER_ENABLEREVDIREKTION = 0x04;
67 : : const SwCursorSelOverFlags SELOVER_CHANGEPOS = 0x08;
68 : : }
69 : :
70 : 0 : class SW_DLLPUBLIC SwCursor : public SwPaM
71 : : {
72 : : friend class SwCrsrSaveState;
73 : :
74 : : _SwCursor_SavePos* pSavePos;
75 : : long mnRowSpanOffset; // required for travelling in tabs with rowspans
76 : : sal_uInt8 nCursorBidiLevel; // bidi level of the cursor
77 : : bool mbColumnSelection; // true: cursor is aprt of a column selection
78 : :
79 : : sal_uLong FindAll( SwFindParas& , SwDocPositions, SwDocPositions, FindRanges, sal_Bool& bCancel );
80 : :
81 : : using SwPaM::Find;
82 : :
83 : : protected:
84 : : virtual _SwCursor_SavePos* CreateNewSavePos() const;
85 : : void SaveState();
86 : : void RestoreState();
87 : :
88 : 14130 : const _SwCursor_SavePos* GetSavePos() const { return pSavePos; }
89 : :
90 : : virtual const SwCntntFrm* DoSetBidiLevelLeftRight(
91 : : sal_Bool & io_rbLeft, sal_Bool bVisualAllowed, sal_Bool bInsertCrsr);
92 : : virtual void DoSetBidiLevelUpDown();
93 : : virtual bool IsSelOvrCheck(int eFlags);
94 : :
95 : : public:
96 : : // single argument ctors shall be explicit.
97 : : SwCursor( const SwPosition &rPos, SwPaM* pRing, bool bColumnSel );
98 : : virtual ~SwCursor();
99 : :
100 : : // @@@ semantic: no copy ctor.
101 : : SwCursor( SwCursor& rCpy);
102 : :
103 : : public:
104 : :
105 : : virtual SwCursor* Create( SwPaM* pRing = 0 ) const;
106 : :
107 : : virtual short MaxReplaceArived(); //returns RET_YES/RET_CANCEL/RET_NO
108 : : virtual void SaveTblBoxCntnt( const SwPosition* pPos = 0 );
109 : :
110 : : void FillFindPos( SwDocPositions ePos, SwPosition& rPos ) const;
111 : : SwMoveFnCollection* MakeFindRange( SwDocPositions, SwDocPositions,
112 : : SwPaM* ) const;
113 : :
114 : :
115 : : sal_uLong Find( const com::sun::star::util::SearchOptions& rSearchOpt,
116 : : sal_Bool bSearchInNotes,
117 : : SwDocPositions nStart, SwDocPositions nEnde,
118 : : sal_Bool& bCancel,
119 : : FindRanges = FND_IN_BODY,
120 : : int bReplace = sal_False );
121 : : sal_uLong Find( const SwTxtFmtColl& rFmtColl,
122 : : SwDocPositions nStart, SwDocPositions nEnde,
123 : : sal_Bool& bCancel,
124 : : FindRanges = FND_IN_BODY,
125 : : const SwTxtFmtColl* pReplFmt = 0 );
126 : : sal_uLong Find( const SfxItemSet& rSet, sal_Bool bNoCollections,
127 : : SwDocPositions nStart, SwDocPositions nEnde,
128 : : sal_Bool& bCancel,
129 : : FindRanges = FND_IN_BODY,
130 : : const com::sun::star::util::SearchOptions* pSearchOpt = 0,
131 : : const SfxItemSet* rReplSet = 0 );
132 : :
133 : : // UI versions
134 : : sal_Bool IsStartWord( sal_Int16 nWordType = com::sun::star::i18n::WordType::ANYWORD_IGNOREWHITESPACES ) const;
135 : : sal_Bool IsEndWord( sal_Int16 nWordType = com::sun::star::i18n::WordType::ANYWORD_IGNOREWHITESPACES ) const;
136 : : sal_Bool IsInWord( sal_Int16 nWordType = com::sun::star::i18n::WordType::ANYWORD_IGNOREWHITESPACES ) const;
137 : : sal_Bool IsStartEndSentence( bool bEnd ) const;
138 : : sal_Bool GoStartWord();
139 : : sal_Bool GoEndWord();
140 : : sal_Bool GoNextWord();
141 : : sal_Bool GoPrevWord();
142 : : sal_Bool SelectWord( ViewShell* pViewShell, const Point* pPt = 0 );
143 : :
144 : : // API versions of above functions (will be used with a different
145 : : // WordType for the break iterator)
146 : : sal_Bool IsStartWordWT( sal_Int16 nWordType ) const;
147 : : sal_Bool IsEndWordWT( sal_Int16 nWordType ) const;
148 : : sal_Bool IsInWordWT( sal_Int16 nWordType ) const;
149 : : sal_Bool GoStartWordWT( sal_Int16 nWordType );
150 : : sal_Bool GoEndWordWT( sal_Int16 nWordType );
151 : : sal_Bool GoNextWordWT( sal_Int16 nWordType );
152 : : sal_Bool GoPrevWordWT( sal_Int16 nWordType );
153 : : sal_Bool SelectWordWT( ViewShell* pViewShell, sal_Int16 nWordType, const Point* pPt = 0 );
154 : :
155 : : enum SentenceMoveType
156 : : {
157 : : NEXT_SENT,
158 : : PREV_SENT,
159 : : START_SENT,
160 : : END_SENT
161 : : };
162 : : sal_Bool GoSentence(SentenceMoveType eMoveType);
163 : 0 : sal_Bool GoNextSentence(){return GoSentence(NEXT_SENT);}
164 : 0 : sal_Bool GoEndSentence(){return GoSentence(END_SENT);}
165 : : sal_Bool GoPrevSentence(){return GoSentence(PREV_SENT);}
166 : 0 : sal_Bool GoStartSentence(){return GoSentence(START_SENT);}
167 : : sal_Bool ExpandToSentenceBorders();
168 : :
169 : : virtual sal_Bool LeftRight( sal_Bool bLeft, sal_uInt16 nCnt, sal_uInt16 nMode,
170 : : sal_Bool bAllowVisual, sal_Bool bSkipHidden, sal_Bool bInsertCrsr );
171 : : sal_Bool UpDown( sal_Bool bUp, sal_uInt16 nCnt, Point* pPt, long nUpDownX );
172 : : sal_Bool LeftRightMargin( sal_Bool bLeftMargin, sal_Bool bAPI = sal_False );
173 : : sal_Bool IsAtLeftRightMargin( sal_Bool bLeftMargin, sal_Bool bAPI = sal_False ) const;
174 : : sal_Bool SttEndDoc( sal_Bool bSttDoc );
175 : : sal_Bool GoPrevNextCell( sal_Bool bNext, sal_uInt16 nCnt );
176 : :
177 : 7822 : sal_Bool Left( sal_uInt16 nCnt, sal_uInt16 nMode, sal_Bool bAllowVisual, sal_Bool bSkipHidden )
178 : 7822 : { return LeftRight( sal_True, nCnt, nMode, bAllowVisual, bSkipHidden, sal_False ); }
179 : 5558 : sal_Bool Right( sal_uInt16 nCnt, sal_uInt16 nMode, sal_Bool bAllowVisual, sal_Bool bSkipHidden )
180 : 5558 : { return LeftRight( sal_False, nCnt, nMode, bAllowVisual, bSkipHidden, sal_False ); }
181 : 4 : sal_Bool GoNextCell( sal_uInt16 nCnt = 1 ) { return GoPrevNextCell( sal_True, nCnt ); }
182 : 4 : sal_Bool GoPrevCell( sal_uInt16 nCnt = 1 ) { return GoPrevNextCell( sal_False, nCnt ); }
183 : : virtual sal_Bool GotoTable( const String& rName );
184 : : sal_Bool GotoTblBox( const String& rName );
185 : : sal_Bool GotoRegion( const String& rName );
186 : : sal_Bool GotoFtnAnchor();
187 : : sal_Bool GotoFtnTxt();
188 : : sal_Bool GotoNextFtnAnchor();
189 : : sal_Bool GotoPrevFtnAnchor();
190 : : sal_Bool GotoNextFtnCntnt();
191 : : sal_Bool GotoPrevFtnCntnt();
192 : :
193 : : sal_Bool MovePara( SwWhichPara, SwPosPara );
194 : : sal_Bool MoveSection( SwWhichSection, SwPosSection );
195 : : sal_Bool MoveTable( SwWhichTable, SwPosTable );
196 : : sal_Bool MoveRegion( SwWhichRegion, SwPosRegion );
197 : :
198 : : // Is there a selection of content in table?
199 : : // Return value indicates if cursor remains at its old position.
200 : : virtual sal_Bool IsSelOvr( int eFlags =
201 : : ( nsSwCursorSelOverFlags::SELOVER_CHECKNODESSECTION |
202 : : nsSwCursorSelOverFlags::SELOVER_TOGGLE |
203 : : nsSwCursorSelOverFlags::SELOVER_CHANGEPOS ));
204 : : virtual sal_Bool IsInProtectTable( sal_Bool bMove = sal_False,
205 : : sal_Bool bChgCrsr = sal_True );
206 : : sal_Bool IsNoCntnt() const;
207 : :
208 : : /** Restore cursor state to the one saved by SwCrsrSaveState **/
209 : : void RestoreSavePos();
210 : :
211 : : // sal_True: cursor can be set at this position.
212 : : virtual sal_Bool IsAtValidPos( sal_Bool bPoint = sal_True ) const;
213 : :
214 : : // Is cursor allowed in ready only ranges?
215 : : virtual bool IsReadOnlyAvailable() const;
216 : :
217 : : virtual sal_Bool IsSkipOverProtectSections() const;
218 : : virtual sal_Bool IsSkipOverHiddenSections() const;
219 : :
220 : 69345 : sal_uInt8 GetCrsrBidiLevel() const { return nCursorBidiLevel; }
221 : 44 : void SetCrsrBidiLevel( sal_uInt8 nNewLevel ) { nCursorBidiLevel = nNewLevel; }
222 : :
223 : 0 : bool IsColumnSelection() const { return mbColumnSelection; }
224 : 6 : void SetColumnSelection( bool bNew ) { mbColumnSelection = bNew; }
225 : :
226 : 0 : long GetCrsrRowSpanOffset() const { return mnRowSpanOffset; }
227 : : void SetCrsrRowSpanOffset( long nNew ) { mnRowSpanOffset = nNew; }
228 : :
229 [ + - ][ + - ]: 744 : DECL_FIXEDMEMPOOL_NEWDEL( SwCursor )
230 : : };
231 : :
232 : :
233 : : /**
234 : : A helper class to save cursor state (position). Create SwCrsrSaveState
235 : : object to save current state, use SwCursor::RestoreSavePos() to actually
236 : : restore cursor state to the saved state (SwCrsrSaveState destructor only
237 : : removes the saved state from an internal stack). It is possible to stack
238 : : several SwCrsrSaveState objects.
239 : : **/
240 : : class SwCrsrSaveState
241 : : {
242 : : SwCursor& rCrsr;
243 : : public:
244 : 18042 : SwCrsrSaveState( SwCursor& rC ) : rCrsr( rC ) { rC.SaveState(); }
245 : 18042 : ~SwCrsrSaveState() { rCrsr.RestoreState(); }
246 : : };
247 : :
248 : : // internal, used by SwCursor::SaveState() etc.
249 : : struct _SwCursor_SavePos
250 : : {
251 : : sal_uLong nNode;
252 : : xub_StrLen nCntnt;
253 : : _SwCursor_SavePos* pNext;
254 : :
255 : 18042 : _SwCursor_SavePos( const SwCursor& rCrsr )
256 : 18042 : : nNode( rCrsr.GetPoint()->nNode.GetIndex() ),
257 : 18042 : nCntnt( rCrsr.GetPoint()->nContent.GetIndex() ),
258 : 54126 : pNext( 0 )
259 : 18042 : {}
260 [ - + ]: 36084 : virtual ~_SwCursor_SavePos() {}
261 : :
262 [ + - ][ + - ]: 36084 : DECL_FIXEDMEMPOOL_NEWDEL( _SwCursor_SavePos )
263 : : };
264 : :
265 : :
266 : :
267 : : class SwTableCursor : public virtual SwCursor
268 : : {
269 : :
270 : : protected:
271 : : sal_uLong nTblPtNd, nTblMkNd;
272 : : xub_StrLen nTblPtCnt, nTblMkCnt;
273 : : SwSelBoxes aSelBoxes;
274 : : sal_Bool bChg : 1;
275 : : sal_Bool bParked : 1; // Table-cursor was parked.
276 : :
277 : : virtual bool IsSelOvrCheck(int eFlags);
278 : :
279 : : public:
280 : : SwTableCursor( const SwPosition &rPos, SwPaM* pRing = 0 );
281 : : SwTableCursor( SwTableCursor& );
282 : : virtual ~SwTableCursor();
283 : :
284 : : virtual sal_Bool LeftRight( sal_Bool bLeft, sal_uInt16 nCnt, sal_uInt16 nMode,
285 : : sal_Bool bAllowVisual, sal_Bool bSkipHidden, sal_Bool bInsertCrsr );
286 : : virtual sal_Bool GotoTable( const String& rName );
287 : :
288 : : void InsertBox( const SwTableBox& rTblBox );
289 [ + - ][ + - ]: 32 : void DeleteBox( sal_uInt16 nPos ) { aSelBoxes.erase( aSelBoxes.begin() + nPos ); bChg = sal_True; }
290 : 111 : sal_uInt16 GetBoxesCount() const { return aSelBoxes.size(); }
291 : 104 : const SwSelBoxes& GetBoxes() const { return aSelBoxes; }
292 : :
293 : : // Creates cursor for all boxes.
294 : : SwCursor* MakeBoxSels( SwCursor* pAktCrsr );
295 : : // Any boxes protected?
296 : : sal_Bool HasReadOnlyBoxSel() const;
297 : :
298 : : // Has table cursor been changed? If so, save new values immediately.
299 : : sal_Bool IsCrsrMovedUpdt();
300 : : // Has table cursor been changed?
301 : 226 : sal_Bool IsCrsrMoved() const
302 : : {
303 : 226 : return nTblMkNd != GetMark()->nNode.GetIndex() ||
304 : 218 : nTblPtNd != GetPoint()->nNode.GetIndex() ||
305 : 214 : nTblMkCnt != GetMark()->nContent.GetIndex() ||
306 [ - + ][ + + : 658 : nTblPtCnt != GetPoint()->nContent.GetIndex();
+ + + - ]
307 : : }
308 : :
309 : 913 : sal_Bool IsChgd() const { return bChg; }
310 : :
311 : : // Park table cursor at start node of boxes.
312 : : void ParkCrsr();
313 : :
314 : : bool NewTableSelection();
315 : : void ActualizeSelection( const SwSelBoxes &rBoxes );
316 : : };
317 : :
318 : : #endif
319 : :
320 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|