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