LibreOffice Module sw (master)  1
swcrsr.hxx
Go to the documentation of this file.
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 "pam.hxx"
23 #include "tblsel.hxx"
24 #include "cshtyp.hxx"
25 
26 class SfxItemSet;
27 struct SwCursor_SavePos;
28 namespace i18nutil {
29  struct SearchOptions2;
30 }
31 
32 // Base structure for parameters of the find-methods.
33 // Returns values of found-call.
34 const int FIND_NOT_FOUND = 0;
35 const int FIND_FOUND = 1;
36 const int FIND_NO_RING = 2;
37 
39 {
40  virtual int DoFind(SwPaM &, SwMoveFnCollection const &, const SwPaM&, bool) = 0;
41  virtual bool IsReplaceMode() const = 0;
42 
43 protected:
45 };
46 
47 enum class SwCursorSelOverFlags : sal_uInt16
48 {
49  NONE = 0x00,
50  CheckNodeSection = 0x01,
51  Toggle = 0x02,
52  EnableRevDirection = 0x04,
53  ChangePos = 0x08
54 };
55 namespace o3tl {
56  template<> struct typed_flags<SwCursorSelOverFlags> : is_typed_flags<SwCursorSelOverFlags, 0x0f> {};
57 }
58 
59 // define for cursor travelling normally in western text cells and chars do
60 // the same, but in complex text cell skip over ligatures and char skip
61 // into it.
62 // These defines exist only to cut off the dependencies to I18N project.
63 const sal_uInt16 CRSR_SKIP_CHARS = 0;
64 const sal_uInt16 CRSR_SKIP_CELLS = 1;
65 const sal_uInt16 CRSR_SKIP_HIDDEN = 2;
66 
67 
68 class SW_DLLPUBLIC SwCursor : public SwPaM
69 {
70  friend class SwCursorSaveState;
71 
72  std::vector<SwCursor_SavePos> m_vSavePos; // the current entry is the last element
73  long m_nRowSpanOffset; // required for travelling in tabs with rowspans
74  sal_uInt8 m_nCursorBidiLevel; // bidi level of the cursor
75  bool m_bColumnSelection; // true: cursor is aprt of a column selection
76 
77  sal_uLong FindAll( SwFindParas& , SwDocPositions, SwDocPositions, FindRanges, bool& bCancel );
78 
79  SwCursor(SwCursor const& rPaM) = delete;
80 
81 protected:
82  void SaveState();
83  void RestoreState();
84 
85  const SwCursor_SavePos* GetSavePos() const { return m_vSavePos.empty() ? nullptr : &m_vSavePos.back(); }
86 
87  virtual const SwContentFrame* DoSetBidiLevelLeftRight(
88  bool & io_rbLeft, bool bVisualAllowed, bool bInsertCursor);
89  virtual void DoSetBidiLevelUpDown();
90  virtual bool IsSelOvrCheck(SwCursorSelOverFlags eFlags);
91 
92 public:
93  // single argument ctors shall be explicit.
94  SwCursor( const SwPosition &rPos, SwPaM* pRing );
95  virtual ~SwCursor() override;
96 
97  SwCursor & operator =(SwCursor const &) = default;
98 
101  SwCursor(SwCursor const& rCursor, SwPaM* pRing);
102 
103 public:
104 
105  virtual SwCursor* Create( SwPaM* pRing = nullptr ) const;
106 
107  virtual short MaxReplaceArived(); //returns RET_YES/RET_CANCEL/RET_NO
108  virtual void SaveTableBoxContent( const SwPosition* pPos );
109 
110  void FillFindPos( SwDocPositions ePos, SwPosition& rPos ) const;
111  SwMoveFnCollection const & MakeFindRange( SwDocPositions, SwDocPositions,
112  SwPaM* ) const;
113 
114  // note: DO NOT call it FindText because windows.h
115  sal_uLong Find_Text( const i18nutil::SearchOptions2& rSearchOpt,
116  bool bSearchInNotes,
117  SwDocPositions nStart, SwDocPositions nEnde,
118  bool& bCancel,
119  FindRanges,
120  bool bReplace = false,
121  SwRootFrame const*const pLayout = nullptr);
122  sal_uLong FindFormat( const SwTextFormatColl& rFormatColl,
123  SwDocPositions nStart, SwDocPositions nEnde,
124  bool& bCancel,
125  FindRanges,
126  const SwTextFormatColl* pReplFormat,
127  SwRootFrame const*const pLayout = nullptr);
128  sal_uLong FindAttrs( const SfxItemSet& rSet, bool bNoCollections,
129  SwDocPositions nStart, SwDocPositions nEnde,
130  bool& bCancel,
131  FindRanges,
132  const i18nutil::SearchOptions2* pSearchOpt,
133  const SfxItemSet* rReplSet = nullptr,
134  SwRootFrame const*const pLayout = nullptr);
135 
136  // UI versions
137  bool IsStartEndSentence(bool bEnd, SwRootFrame const* pLayout) const;
138  bool SelectWord( SwViewShell const * pViewShell, const Point* pPt );
139 
140  // API versions of above functions (will be used with a different
141  // WordType for the break iterator)
142  bool IsStartWordWT(sal_Int16 nWordType, SwRootFrame const* pLayout = nullptr) const;
143  bool IsEndWordWT(sal_Int16 nWordType, SwRootFrame const* pLayout = nullptr) const;
144  bool IsInWordWT(sal_Int16 nWordType, SwRootFrame const* pLayout = nullptr) const;
145  bool GoStartWordWT(sal_Int16 nWordType, SwRootFrame const* pLayout = nullptr);
146  bool GoEndWordWT(sal_Int16 nWordType, SwRootFrame const* pLayout = nullptr);
147  bool GoNextWordWT(sal_Int16 nWordType, SwRootFrame const* pLayout = nullptr);
148  bool GoPrevWordWT(sal_Int16 nWordType, SwRootFrame const* pLayout = nullptr);
149  bool SelectWordWT( SwViewShell const * pViewShell, sal_Int16 nWordType, const Point* pPt );
150 
152  {
156  END_SENT
157  };
158  bool GoSentence(SentenceMoveType eMoveType, SwRootFrame const*pLayout = nullptr);
159  bool ExpandToSentenceBorders(SwRootFrame const* pLayout);
160 
161  virtual bool LeftRight( bool bLeft, sal_uInt16 nCnt, sal_uInt16 nMode,
162  bool bAllowVisual, bool bSkipHidden, bool bInsertCursor,
163  SwRootFrame const* pLayout);
164  bool UpDown(bool bUp, sal_uInt16 nCnt, Point const * pPt, long nUpDownX, SwRootFrame & rLayout);
165  bool LeftRightMargin(SwRootFrame const& rLayout, bool bLeftMargin, bool bAPI);
166  bool IsAtLeftRightMargin(SwRootFrame const& rLayout, bool bLeftMargin, bool bAPI) const;
167  bool SttEndDoc( bool bSttDoc );
168  bool GoPrevNextCell( bool bNext, sal_uInt16 nCnt );
169 
170  bool Left( sal_uInt16 nCnt ) { return LeftRight( true, nCnt, CRSR_SKIP_CHARS, false/*bAllowVisual*/, false/*bSkipHidden*/, false, nullptr ); }
171  bool Right( sal_uInt16 nCnt ) { return LeftRight( false, nCnt, CRSR_SKIP_CHARS, false/*bAllowVisual*/, false/*bSkipHidden*/, false, nullptr ); }
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 
182  bool MovePara( SwWhichPara, SwMoveFnCollection const & );
183  bool MoveSection( SwWhichSection, SwMoveFnCollection const & );
184  bool MoveTable( SwWhichTable, SwMoveFnCollection const & );
185  bool MoveRegion( SwWhichRegion, SwMoveFnCollection const & );
186 
187  // Is there a selection of content in table?
188  // Return value indicates if cursor remains at its old position.
189  virtual bool IsSelOvr( SwCursorSelOverFlags eFlags =
193  bool IsInProtectTable( bool bMove = false,
194  bool bChgCursor = true );
195  bool IsNoContent() const;
196 
198  void RestoreSavePos();
199 
200  // true: cursor can be set at this position.
201  virtual bool IsAtValidPos( bool bPoint = true ) const;
202 
203  // Is cursor allowed in ready only ranges?
204  virtual bool IsReadOnlyAvailable() const;
205 
206  virtual bool IsSkipOverProtectSections() const;
207  virtual bool IsSkipOverHiddenSections() const;
208 
209  sal_uInt8 GetCursorBidiLevel() const { return m_nCursorBidiLevel; }
210  void SetCursorBidiLevel( sal_uInt8 nNewLevel ) { m_nCursorBidiLevel = nNewLevel; }
211 
212  bool IsColumnSelection() const { return m_bColumnSelection; }
213  void SetColumnSelection( bool bNew ) { m_bColumnSelection = bNew; }
214 
215  long GetCursorRowSpanOffset() const { return m_nRowSpanOffset; }
216 
217  SwCursor* GetNext() { return dynamic_cast<SwCursor *>(GetNextInRing()); }
218  const SwCursor* GetNext() const { return dynamic_cast<SwCursor const *>(GetNextInRing()); }
219  SwCursor* GetPrev() { return dynamic_cast<SwCursor *>(GetPrevInRing()); }
220  const SwCursor* GetPrev() const { return dynamic_cast<SwCursor const *>(GetPrevInRing()); }
221 };
222 
231 {
232 private:
234 public:
235  SwCursorSaveState( SwCursor& rC ) : m_rCursor( rC ) { rC.SaveState(); }
236  ~SwCursorSaveState() { m_rCursor.RestoreState(); }
237 };
238 
239 // internal, used by SwCursor::SaveState() etc.
240 struct SwCursor_SavePos final
241 {
243  sal_Int32 nContent;
244 
245  SwCursor_SavePos( const SwCursor& rCursor )
246  : nNode( rCursor.GetPoint()->nNode.GetIndex() ),
247  nContent( rCursor.GetPoint()->nContent.GetIndex() )
248  {}
249 };
250 
251 class SwTableCursor : public virtual SwCursor
252 {
253 
254 protected:
257  sal_Int32 m_nTablePtCnt;
258  sal_Int32 m_nTableMkCnt;
260  bool m_bChanged : 1;
261  bool m_bParked : 1; // Table-cursor was parked.
262 
263  virtual bool IsSelOvrCheck(SwCursorSelOverFlags eFlags) override;
264 
265 public:
266  SwTableCursor( const SwPosition &rPos );
268  virtual ~SwTableCursor() override;
269 
270  virtual bool LeftRight( bool bLeft, sal_uInt16 nCnt, sal_uInt16 nMode,
271  bool bAllowVisual, bool bSkipHidden, bool bInsertCursor,
272  SwRootFrame const*) override;
273  virtual bool GotoTable( const OUString& rName ) override;
274 
275  void InsertBox( const SwTableBox& rTableBox );
276  void DeleteBox(size_t nPos);
277  size_t GetSelectedBoxesCount() const { return m_SelectedBoxes.size(); }
278  const SwSelBoxes& GetSelectedBoxes() const { return m_SelectedBoxes; }
279 
280  // Creates cursor for all boxes.
281  SwCursor* MakeBoxSels( SwCursor* pCurrentCursor );
282  // Any boxes protected?
283  bool HasReadOnlyBoxSel() const;
284 
285  // Has table cursor been changed? If so, save new values immediately.
286  bool IsCursorMovedUpdate();
287  // Has table cursor been changed?
288  bool IsCursorMoved() const
289  {
290  return m_nTableMkNd != GetMark()->nNode.GetIndex() ||
291  m_nTablePtNd != GetPoint()->nNode.GetIndex() ||
292  m_nTableMkCnt != GetMark()->nContent.GetIndex() ||
293  m_nTablePtCnt != GetPoint()->nContent.GetIndex();
294  }
295 
296  bool IsChgd() const { return m_bChanged; }
297  void SetChgd() { m_bChanged = true; }
298 
299  // Park table cursor at start node of boxes.
300  void ParkCursor();
301 
302  bool NewTableSelection();
303  void ActualizeSelection( const SwSelBoxes &rBoxes );
304 
305  SwTableCursor* GetNext() { return dynamic_cast<SwTableCursor *>(GetNextInRing()); }
306  const SwTableCursor* GetNext() const { return dynamic_cast<SwTableCursor const *>(GetNextInRing()); }
307  SwTableCursor* GetPrev() { return dynamic_cast<SwTableCursor *>(GetPrevInRing()); }
308  const SwTableCursor* GetPrev() const { return dynamic_cast<SwTableCursor const *>(GetPrevInRing()); }
309 };
310 
311 #endif
312 
313 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool IsCursorMoved() const
Definition: swcrsr.hxx:288
bool IsColumnSelection() const
Definition: swcrsr.hxx:212
void InsertBox(const SwTableBox &rTableBox)
Definition: swcrsr.cxx:2415
SwCursorSelOverFlags
Definition: swcrsr.hxx:47
SwTableCursor(const SwPosition &rPos)
Definition: swcrsr.cxx:2273
const SwSelBoxes & GetSelectedBoxes() const
Definition: swcrsr.hxx:278
Represents the style of a paragraph.
Definition: fmtcol.hxx:55
Marks a position in the document model.
Definition: pam.hxx:35
void SetColumnSelection(bool bNew)
Definition: swcrsr.hxx:213
bool GoPrevCell(sal_uInt16 nCnt=1)
Definition: swcrsr.hxx:173
const SwCursor * GetPrev() const
Definition: swcrsr.hxx:220
SwNodeIndex nNode
Definition: pam.hxx:37
const SwTableCursor * GetPrev() const
Definition: swcrsr.hxx:308
long GetCursorRowSpanOffset() const
Definition: swcrsr.hxx:215
sal_uIntPtr sal_uLong
const SwPosition * GetMark() const
Definition: pam.hxx:209
bool Left(sal_uInt16 nCnt)
Definition: swcrsr.hxx:170
SentenceMoveType
Definition: swcrsr.hxx:151
sal_uLong m_nTableMkNd
Definition: swcrsr.hxx:256
sal_uInt8 GetCursorBidiLevel() const
Definition: swcrsr.hxx:209
SwCursor * MakeBoxSels(SwCursor *pCurrentCursor)
Definition: swcrsr.cxx:2316
long m_nRowSpanOffset
Definition: swcrsr.hxx:73
SwCursor_SavePos(const SwCursor &rCursor)
Definition: swcrsr.hxx:245
void Create(SvxOrientationItem &rItem, SvStream &rStrm, sal_uInt16)
The root element of a Writer document layout.
Definition: rootfrm.hxx:79
const SwCursor * GetNext() const
Definition: swcrsr.hxx:218
SwDocPositions
Definition: cshtyp.hxx:103
sal_uLong m_nTablePtNd
Definition: swcrsr.hxx:255
SwIndex nContent
Definition: pam.hxx:38
SwCursor & m_rCursor
Definition: swcrsr.hxx:233
sal_uLong GetIndex() const
Definition: ndindex.hxx:152
virtual bool GotoTable(const OUString &rName) override
Definition: swcrsr.cxx:2152
FindRanges
Definition: cshtyp.hxx:90
bool IsCursorMovedUpdate()
Definition: swcrsr.cxx:2484
std::vector< SwCursor_SavePos > m_vSavePos
Definition: swcrsr.hxx:72
size_type size() const
SwPaM * GetPrevInRing()
Definition: ring.hxx:87
void SaveState()
Definition: swcrsr.cxx:161
bool(* SwWhichRegion)(SwPaM &, SwMoveFnCollection const &, bool bInReadOnly)
Definition: cshtyp.hxx:75
bool GoNextCell(sal_uInt16 nCnt=1)
Definition: swcrsr.hxx:172
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:136
bool(* SwWhichTable)(SwPaM &, SwMoveFnCollection const &, bool bInReadOnly)
Definition: cshtyp.hxx:58
sal_Int32 m_nTablePtCnt
Definition: swcrsr.hxx:257
virtual bool IsReplaceMode() const =0
bool m_bChanged
Definition: swcrsr.hxx:260
A helper class to save cursor state (position).
Definition: swcrsr.hxx:230
bool(* SwWhichPara)(SwPaM &, SwMoveFnCollection const &)
Definition: cshtyp.hxx:43
sal_uInt8 m_nCursorBidiLevel
Definition: swcrsr.hxx:74
SwCursor * GetNext()
Definition: swcrsr.hxx:217
const SwPosition * GetPoint() const
Definition: pam.hxx:207
sal_Int32 nContent
Definition: swcrsr.hxx:243
SwTableCursor * GetNext()
Definition: swcrsr.hxx:305
bool IsChgd() const
Definition: swcrsr.hxx:296
SwCursorSaveState(SwCursor &rC)
Definition: swcrsr.hxx:235
SwPaM * GetNextInRing()
Definition: ring.hxx:84
const sal_uInt16 CRSR_SKIP_HIDDEN
Definition: swcrsr.hxx:65
sal_uLong nNode
Definition: swcrsr.hxx:242
#define SW_DLLPUBLIC
Definition: swdllapi.h:28
const int FIND_NO_RING
Definition: swcrsr.hxx:36
void RestoreState()
Definition: swcrsr.cxx:166
const sal_uInt16 CRSR_SKIP_CELLS
Definition: swcrsr.hxx:64
SwSelBoxes m_SelectedBoxes
Definition: swcrsr.hxx:259
virtual int DoFind(SwPaM &, SwMoveFnCollection const &, const SwPaM &, bool)=0
virtual bool LeftRight(bool bLeft, sal_uInt16 nCnt, sal_uInt16 nMode, bool bAllowVisual, bool bSkipHidden, bool bInsertCursor, SwRootFrame const *) override
Definition: swcrsr.cxx:1651
unsigned char sal_uInt8
bool Right(sal_uInt16 nCnt)
Definition: swcrsr.hxx:171
const int FIND_FOUND
Definition: swcrsr.hxx:35
sal_Int32 GetIndex() const
Definition: index.hxx:95
void SetChgd()
Definition: swcrsr.hxx:297
~SwFindParas()
Definition: swcrsr.hxx:44
bool m_bParked
Definition: swcrsr.hxx:261
size_t GetSelectedBoxesCount() const
Definition: swcrsr.hxx:277
void SetCursorBidiLevel(sal_uInt8 nNewLevel)
Definition: swcrsr.hxx:210
SwTableBox is one table cell in the document model.
Definition: swtable.hxx:386
virtual ~SwTableCursor() override
Definition: swcrsr.cxx:2284
const SwTableCursor * GetNext() const
Definition: swcrsr.hxx:306
SwPaM & operator=(const SwPaM &)
@@ semantic: no copy assignment for super class Ring.
Definition: pam.cxx:441
void ParkCursor()
park table cursor on the boxes' start node
Definition: swcrsr.cxx:2497
virtual bool IsSelOvrCheck(SwCursorSelOverFlags eFlags) override
Definition: swcrsr.cxx:187
const sal_uInt16 CRSR_SKIP_CHARS
Definition: swcrsr.hxx:63
sal_Int32 m_nTableMkCnt
Definition: swcrsr.hxx:258
void ActualizeSelection(const SwSelBoxes &rBoxes)
Definition: swcrsr.cxx:2449
const int FIND_NOT_FOUND
Definition: swcrsr.hxx:34
void DeleteBox(size_t nPos)
Definition: swcrsr.cxx:2422
bool NewTableSelection()
Definition: swcrsr.cxx:2428
bool HasReadOnlyBoxSel() const
Definition: swcrsr.cxx:2516
bool(* SwWhichSection)(SwPaM &, SwMoveFnCollection const &)
Definition: cshtyp.hxx:51
bool m_bColumnSelection
Definition: swcrsr.hxx:75
SwTableCursor * GetPrev()
Definition: swcrsr.hxx:307
SwCursor * GetPrev()
Definition: swcrsr.hxx:219
const SwCursor_SavePos * GetSavePos() const
Definition: swcrsr.hxx:85