update credits
[LibreOffice.git] / sw / inc / swcrsr.hxx
blobfbbeb78c5cb3e62ec15179a1f72b3eecb1b14295
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef _SWCRSR_HXX
20 #define _SWCRSR_HXX
22 #include <com/sun/star/i18n/WordType.hpp>
24 #include <pam.hxx>
25 #include <tblsel.hxx>
26 #include <cshtyp.hxx>
29 struct _SwCursor_SavePos;
31 namespace com { namespace sun { namespace star { namespace util {
32 struct SearchOptions;
33 } } } }
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;
42 struct SwFindParas
44 virtual int Find( SwPaM*, SwMoveFn, const SwPaM*, sal_Bool ) = 0;
45 virtual int IsReplaceMode() const = 0;
47 protected:
48 ~SwFindParas() {}
51 typedef sal_uInt16 SwCursorSelOverFlags;
52 namespace nsSwCursorSelOverFlags
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;
61 class SW_DLLPUBLIC SwCursor : public SwPaM
63 friend class SwCrsrSaveState;
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
70 sal_uLong FindAll( SwFindParas& , SwDocPositions, SwDocPositions, FindRanges, sal_Bool& bCancel );
72 using SwPaM::Find;
74 protected:
75 virtual _SwCursor_SavePos* CreateNewSavePos() const;
76 void SaveState();
77 void RestoreState();
79 const _SwCursor_SavePos* GetSavePos() const { return pSavePos; }
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);
86 public:
87 // single argument ctors shall be explicit.
88 SwCursor( const SwPosition &rPos, SwPaM* pRing, bool bColumnSel );
89 virtual ~SwCursor();
91 // @@@ semantic: no copy ctor.
92 SwCursor( SwCursor& rCpy);
94 public:
96 virtual SwCursor* Create( SwPaM* pRing = 0 ) const;
98 virtual short MaxReplaceArived(); //returns RET_YES/RET_CANCEL/RET_NO
99 virtual void SaveTblBoxCntnt( const SwPosition* pPos = 0 );
101 void FillFindPos( SwDocPositions ePos, SwPosition& rPos ) const;
102 SwMoveFnCollection* MakeFindRange( SwDocPositions, SwDocPositions,
103 SwPaM* ) const;
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 );
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 );
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 );
146 enum SentenceMoveType
148 NEXT_SENT,
149 PREV_SENT,
150 START_SENT,
151 END_SENT
153 sal_Bool GoSentence(SentenceMoveType eMoveType);
154 sal_Bool GoNextSentence(){return GoSentence(NEXT_SENT);}
155 sal_Bool GoEndSentence(){return GoSentence(END_SENT);}
156 sal_Bool GoPrevSentence(){return GoSentence(PREV_SENT);}
157 sal_Bool GoStartSentence(){return GoSentence(START_SENT);}
158 sal_Bool ExpandToSentenceBorders();
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 );
168 sal_Bool Left( sal_uInt16 nCnt, sal_uInt16 nMode, sal_Bool bAllowVisual, sal_Bool bSkipHidden )
169 { return LeftRight( sal_True, nCnt, nMode, bAllowVisual, bSkipHidden, sal_False ); }
170 sal_Bool Right( sal_uInt16 nCnt, sal_uInt16 nMode, sal_Bool bAllowVisual, sal_Bool bSkipHidden )
171 { return LeftRight( sal_False, nCnt, nMode, bAllowVisual, bSkipHidden, sal_False ); }
172 sal_Bool GoNextCell( sal_uInt16 nCnt = 1 ) { return GoPrevNextCell( sal_True, nCnt ); }
173 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();
184 sal_Bool MovePara( SwWhichPara, SwPosPara );
185 sal_Bool MoveSection( SwWhichSection, SwPosSection );
186 sal_Bool MoveTable( SwWhichTable, SwPosTable );
187 sal_Bool MoveRegion( SwWhichRegion, SwPosRegion );
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;
199 /** Restore cursor state to the one saved by SwCrsrSaveState **/
200 void RestoreSavePos();
202 // sal_True: cursor can be set at this position.
203 virtual sal_Bool IsAtValidPos( sal_Bool bPoint = sal_True ) const;
205 // Is cursor allowed in ready only ranges?
206 virtual bool IsReadOnlyAvailable() const;
208 virtual sal_Bool IsSkipOverProtectSections() const;
209 virtual sal_Bool IsSkipOverHiddenSections() const;
211 sal_uInt8 GetCrsrBidiLevel() const { return nCursorBidiLevel; }
212 void SetCrsrBidiLevel( sal_uInt8 nNewLevel ) { nCursorBidiLevel = nNewLevel; }
214 bool IsColumnSelection() const { return mbColumnSelection; }
215 void SetColumnSelection( bool bNew ) { mbColumnSelection = bNew; }
217 long GetCrsrRowSpanOffset() const { return mnRowSpanOffset; }
218 void SetCrsrRowSpanOffset( long nNew ) { mnRowSpanOffset = nNew; }
220 DECL_FIXEDMEMPOOL_NEWDEL( SwCursor )
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.
231 class SwCrsrSaveState
233 SwCursor& rCrsr;
234 public:
235 SwCrsrSaveState( SwCursor& rC ) : rCrsr( rC ) { rC.SaveState(); }
236 ~SwCrsrSaveState() { rCrsr.RestoreState(); }
239 // internal, used by SwCursor::SaveState() etc.
240 struct _SwCursor_SavePos
242 sal_uLong nNode;
243 xub_StrLen nCntnt;
244 _SwCursor_SavePos* pNext;
246 _SwCursor_SavePos( const SwCursor& rCrsr )
247 : nNode( rCrsr.GetPoint()->nNode.GetIndex() ),
248 nCntnt( rCrsr.GetPoint()->nContent.GetIndex() ),
249 pNext( 0 )
251 virtual ~_SwCursor_SavePos() {}
253 DECL_FIXEDMEMPOOL_NEWDEL( _SwCursor_SavePos )
258 class SwTableCursor : public virtual SwCursor
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.
268 virtual bool IsSelOvrCheck(int eFlags);
270 public:
271 SwTableCursor( const SwPosition &rPos, SwPaM* pRing = 0 );
272 SwTableCursor( SwTableCursor& );
273 virtual ~SwTableCursor();
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 );
279 void InsertBox( const SwTableBox& rTblBox );
280 void DeleteBox(size_t nPos);
281 size_t GetSelectedBoxesCount() const { return m_SelectedBoxes.size(); }
282 const SwSelBoxes& GetSelectedBoxes() const { return m_SelectedBoxes; }
284 // Creates cursor for all boxes.
285 SwCursor* MakeBoxSels( SwCursor* pAktCrsr );
286 // Any boxes protected?
287 sal_Bool HasReadOnlyBoxSel() const;
289 // Has table cursor been changed? If so, save new values immediately.
290 sal_Bool IsCrsrMovedUpdt();
291 // Has table cursor been changed?
292 sal_Bool IsCrsrMoved() const
294 return nTblMkNd != GetMark()->nNode.GetIndex() ||
295 nTblPtNd != GetPoint()->nNode.GetIndex() ||
296 nTblMkCnt != GetMark()->nContent.GetIndex() ||
297 nTblPtCnt != GetPoint()->nContent.GetIndex();
300 sal_Bool IsChgd() const { return bChg; }
302 // Park table cursor at start node of boxes.
303 void ParkCrsr();
305 bool NewTableSelection();
306 void ActualizeSelection( const SwSelBoxes &rBoxes );
309 #endif
311 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */