Branch libreoffice-5-0-4
[LibreOffice.git] / sw / inc / swcrsr.hxx
blob7e55f59a8cae8a5abaa9704f2a0d6878e24824e4
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 INCLUDED_SW_INC_SWCRSR_HXX
20 #define INCLUDED_SW_INC_SWCRSR_HXX
22 #include <com/sun/star/i18n/WordType.hpp>
24 #include <pam.hxx>
25 #include <tblsel.hxx>
26 #include <cshtyp.hxx>
28 struct _SwCursor_SavePos;
30 namespace com { namespace sun { namespace star { namespace util {
31 struct SearchOptions;
32 } } } }
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;
40 struct SwFindParas
42 virtual int Find( SwPaM*, SwMoveFn, const SwPaM*, bool ) = 0;
43 virtual bool IsReplaceMode() const = 0;
45 protected:
46 ~SwFindParas() {}
49 typedef sal_uInt16 SwCursorSelOverFlags;
50 namespace nsSwCursorSelOverFlags
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;
59 class SW_DLLPUBLIC SwCursor : public SwPaM
61 friend class SwCrsrSaveState;
63 _SwCursor_SavePos* m_pSavePos;
64 long m_nRowSpanOffset; // required for travelling in tabs with rowspans
65 sal_uInt8 m_nCursorBidiLevel; // bidi level of the cursor
66 bool m_bColumnSelection; // true: cursor is aprt of a column selection
68 sal_uLong FindAll( SwFindParas& , SwDocPositions, SwDocPositions, FindRanges, bool& bCancel );
70 using SwPaM::Find;
72 SwCursor(SwCursor const& rPaM) SAL_DELETED_FUNCTION;
74 protected:
75 _SwCursor_SavePos* CreateNewSavePos() const;
76 void SaveState();
77 void RestoreState();
79 const _SwCursor_SavePos* GetSavePos() const { return m_pSavePos; }
81 virtual const SwContentFrm* DoSetBidiLevelLeftRight(
82 bool & io_rbLeft, bool bVisualAllowed, 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 /// this takes a second parameter, which indicates the Ring that
92 /// the new cursor should be part of (may be null)
93 SwCursor(SwCursor const& rCursor, SwPaM* pRing);
95 public:
97 virtual SwCursor* Create( SwPaM* pRing = 0 ) const;
99 virtual short MaxReplaceArived(); //returns RET_YES/RET_CANCEL/RET_NO
100 virtual void SaveTableBoxContent( const SwPosition* pPos = 0 );
102 void FillFindPos( SwDocPositions ePos, SwPosition& rPos ) const;
103 SwMoveFnCollection* MakeFindRange( SwDocPositions, SwDocPositions,
104 SwPaM* ) const;
106 sal_uLong Find( const com::sun::star::util::SearchOptions& rSearchOpt,
107 bool bSearchInNotes,
108 SwDocPositions nStart, SwDocPositions nEnde,
109 bool& bCancel,
110 FindRanges = FND_IN_BODY,
111 bool bReplace = false );
112 sal_uLong Find( const SwTextFormatColl& rFormatColl,
113 SwDocPositions nStart, SwDocPositions nEnde,
114 bool& bCancel,
115 FindRanges = FND_IN_BODY,
116 const SwTextFormatColl* pReplFormat = 0 );
117 sal_uLong Find( const SfxItemSet& rSet, bool bNoCollections,
118 SwDocPositions nStart, SwDocPositions nEnde,
119 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 bool IsStartWord( sal_Int16 nWordType = com::sun::star::i18n::WordType::ANYWORD_IGNOREWHITESPACES ) const;
126 bool IsEndWord( sal_Int16 nWordType = com::sun::star::i18n::WordType::ANYWORD_IGNOREWHITESPACES ) const;
127 bool IsInWord( sal_Int16 nWordType = com::sun::star::i18n::WordType::ANYWORD_IGNOREWHITESPACES ) const;
128 bool IsStartEndSentence( bool bEnd ) const;
129 bool GoStartWord();
130 bool GoEndWord();
131 bool GoNextWord();
132 bool GoPrevWord();
133 bool SelectWord( SwViewShell* pViewShell, const Point* pPt = 0 );
135 // API versions of above functions (will be used with a different
136 // WordType for the break iterator)
137 bool IsStartWordWT( sal_Int16 nWordType ) const;
138 bool IsEndWordWT( sal_Int16 nWordType ) const;
139 bool IsInWordWT( sal_Int16 nWordType ) const;
140 bool GoStartWordWT( sal_Int16 nWordType );
141 bool GoEndWordWT( sal_Int16 nWordType );
142 bool GoNextWordWT( sal_Int16 nWordType );
143 bool GoPrevWordWT( sal_Int16 nWordType );
144 bool SelectWordWT( SwViewShell* pViewShell, sal_Int16 nWordType, const Point* pPt = 0 );
146 enum SentenceMoveType
148 NEXT_SENT,
149 PREV_SENT,
150 START_SENT,
151 END_SENT
153 bool GoSentence(SentenceMoveType eMoveType);
154 bool GoNextSentence(){return GoSentence(NEXT_SENT);}
155 bool GoEndSentence(){return GoSentence(END_SENT);}
156 bool GoPrevSentence(){return GoSentence(PREV_SENT);}
157 bool GoStartSentence(){return GoSentence(START_SENT);}
158 bool ExpandToSentenceBorders();
160 virtual bool LeftRight( bool bLeft, sal_uInt16 nCnt, sal_uInt16 nMode,
161 bool bAllowVisual, bool bSkipHidden, bool bInsertCrsr );
162 bool UpDown( bool bUp, sal_uInt16 nCnt, Point* pPt, long nUpDownX );
163 bool LeftRightMargin( bool bLeftMargin, bool bAPI = false );
164 bool IsAtLeftRightMargin( bool bLeftMargin, bool bAPI = false ) const;
165 bool SttEndDoc( bool bSttDoc );
166 bool GoPrevNextCell( bool bNext, sal_uInt16 nCnt );
168 bool Left( sal_uInt16 nCnt, sal_uInt16 nMode, bool bAllowVisual, bool bSkipHidden )
169 { return LeftRight( true, nCnt, nMode, bAllowVisual, bSkipHidden, false ); }
170 bool Right( sal_uInt16 nCnt, sal_uInt16 nMode, bool bAllowVisual, bool bSkipHidden )
171 { return LeftRight( false, nCnt, nMode, bAllowVisual, bSkipHidden, false ); }
172 bool GoNextCell( sal_uInt16 nCnt = 1 ) { return GoPrevNextCell( true, nCnt ); }
173 bool GoPrevCell( sal_uInt16 nCnt = 1 ) { return GoPrevNextCell( false, nCnt ); }
174 virtual bool GotoTable( const OUString& rName );
175 bool GotoTableBox( const OUString& rName );
176 bool GotoRegion( const OUString& rName );
177 bool GotoFootnoteAnchor();
178 bool GotoFootnoteText();
179 bool GotoNextFootnoteAnchor();
180 bool GotoPrevFootnoteAnchor();
181 bool GotoNextFootnoteContent();
182 bool GotoPrevFootnoteContent();
184 bool MovePara( SwWhichPara, SwPosPara );
185 bool MoveSection( SwWhichSection, SwPosSection );
186 bool MoveTable( SwWhichTable, SwPosTable );
187 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 bool IsSelOvr( int eFlags =
192 ( nsSwCursorSelOverFlags::SELOVER_CHECKNODESSECTION |
193 nsSwCursorSelOverFlags::SELOVER_TOGGLE |
194 nsSwCursorSelOverFlags::SELOVER_CHANGEPOS ));
195 bool IsInProtectTable( bool bMove = false,
196 bool bChgCrsr = true );
197 bool IsNoContent() const;
199 /** Restore cursor state to the one saved by SwCrsrSaveState **/
200 void RestoreSavePos();
202 // true: cursor can be set at this position.
203 virtual bool IsAtValidPos( bool bPoint = true ) const;
205 // Is cursor allowed in ready only ranges?
206 virtual bool IsReadOnlyAvailable() const;
208 virtual bool IsSkipOverProtectSections() const;
209 virtual bool IsSkipOverHiddenSections() const;
211 sal_uInt8 GetCrsrBidiLevel() const { return m_nCursorBidiLevel; }
212 void SetCrsrBidiLevel( sal_uInt8 nNewLevel ) { m_nCursorBidiLevel = nNewLevel; }
214 bool IsColumnSelection() const { return m_bColumnSelection; }
215 void SetColumnSelection( bool bNew ) { m_bColumnSelection = bNew; }
217 long GetCrsrRowSpanOffset() const { return m_nRowSpanOffset; }
218 void SetCrsrRowSpanOffset( long nNew ) { m_nRowSpanOffset = nNew; }
220 DECL_FIXEDMEMPOOL_NEWDEL( SwCursor )
224 A helper class to save cursor state (position). Create SwCrsrSaveState
225 object to save current state, use SwCursor::RestoreSavePos() to actually
226 restore cursor state to the saved state (SwCrsrSaveState destructor only
227 removes the saved state from an internal stack). It is possible to stack
228 several SwCrsrSaveState objects.
230 class SwCrsrSaveState
232 private:
233 SwCursor& m_rCrsr;
234 public:
235 SwCrsrSaveState( SwCursor& rC ) : m_rCrsr( rC ) { rC.SaveState(); }
236 ~SwCrsrSaveState() { m_rCrsr.RestoreState(); }
239 // internal, used by SwCursor::SaveState() etc.
240 struct _SwCursor_SavePos
242 sal_uLong nNode;
243 sal_Int32 nContent;
244 _SwCursor_SavePos* pNext;
246 _SwCursor_SavePos( const SwCursor& rCrsr )
247 : nNode( rCrsr.GetPoint()->nNode.GetIndex() ),
248 nContent( rCrsr.GetPoint()->nContent.GetIndex() ),
249 pNext( 0 )
251 virtual ~_SwCursor_SavePos() {}
253 DECL_FIXEDMEMPOOL_NEWDEL( _SwCursor_SavePos )
256 class SwTableCursor : public virtual SwCursor
259 protected:
260 sal_uLong m_nTablePtNd;
261 sal_uLong m_nTableMkNd;
262 sal_Int32 m_nTablePtCnt;
263 sal_Int32 m_nTableMkCnt;
264 SwSelBoxes m_SelectedBoxes;
265 bool m_bChanged : 1;
266 bool m_bParked : 1; // Table-cursor was parked.
268 virtual bool IsSelOvrCheck(int eFlags) SAL_OVERRIDE;
270 public:
271 SwTableCursor( const SwPosition &rPos, SwPaM* pRing = 0 );
272 SwTableCursor( SwTableCursor& );
273 virtual ~SwTableCursor();
275 virtual bool LeftRight( bool bLeft, sal_uInt16 nCnt, sal_uInt16 nMode,
276 bool bAllowVisual, bool bSkipHidden, bool bInsertCrsr ) SAL_OVERRIDE;
277 virtual bool GotoTable( const OUString& rName ) SAL_OVERRIDE;
279 void InsertBox( const SwTableBox& rTableBox );
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 bool HasReadOnlyBoxSel() const;
289 // Has table cursor been changed? If so, save new values immediately.
290 bool IsCrsrMovedUpdate();
291 // Has table cursor been changed?
292 bool IsCrsrMoved() const
294 return m_nTableMkNd != GetMark()->nNode.GetIndex() ||
295 m_nTablePtNd != GetPoint()->nNode.GetIndex() ||
296 m_nTableMkCnt != GetMark()->nContent.GetIndex() ||
297 m_nTablePtCnt != GetPoint()->nContent.GetIndex();
300 bool IsChgd() const { return m_bChanged; }
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: */