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