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