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