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
26class SfxItemSet;
27struct SwCursor_SavePos;
28class SvxSearchItem;
29namespace i18nutil {
30 struct SearchOptions2;
31}
32
33// Base structure for parameters of the find-methods.
34// Returns values of found-call.
35const int FIND_NOT_FOUND = 0;
36const int FIND_FOUND = 1;
37const 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
45protected:
47};
48
49enum class SwCursorSelOverFlags : sal_uInt16
50{
51 NONE = 0x00,
52 CheckNodeSection = 0x01,
53 Toggle = 0x02,
54 EnableRevDirection = 0x04,
55 ChangePos = 0x08
56};
57namespace 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.
65enum class SwCursorSkipMode { Chars = 0, Cells = 1, Hidden = 2 };
66namespace o3tl {
67 template<> struct typed_flags<SwCursorSkipMode> : is_typed_flags<SwCursorSkipMode, 0x3> {};
68}
69
71{
72 friend class SwCursorSaveState;
73
74 std::vector<SwCursor_SavePos> m_vSavePos; // the current entry is the last element
75 sal_Int32 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_Int32 FindAll( SwFindParas& , SwDocPositions, SwDocPositions, FindRanges, bool& bCancel );
80
81 SwCursor(SwCursor const& rPaM) = delete;
82
83protected:
84 void SaveState();
85 void RestoreState();
86
87 inline const SwCursor_SavePos* GetSavePos() const;
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
94public:
95 // single argument ctors shall be explicit.
96 SwCursor( const SwPosition &rPos, SwPaM* pRing );
97 virtual ~SwCursor() override;
98
99 inline SwCursor & operator =(SwCursor const &);
100
103 SwCursor(SwCursor const& rCursor, SwPaM* pRing);
104
105public:
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_Int32 Find_Text( const i18nutil::SearchOptions2& rSearchOpt,
118 bool bSearchInNotes,
119 SwDocPositions nStart, SwDocPositions nEnd,
120 bool& bCancel,
122 bool bReplace = false,
123 SwRootFrame const*const pLayout = nullptr);
124 sal_Int32 FindFormat( const SwTextFormatColl& rFormatColl,
125 SwDocPositions nStart, SwDocPositions nEnd,
126 bool& bCancel,
128 const SwTextFormatColl* pReplFormat,
129 SwRootFrame const*const pLayout = nullptr);
130 sal_Int32 FindAttrs( const SfxItemSet& rSet, bool bNoCollections,
131 SwDocPositions nStart, SwDocPositions nEnd,
132 bool& bCancel,
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 void ExpandToSentenceBorders(SwRootFrame const* pLayout);
162
163 virtual bool LeftRight( bool bLeft, sal_uInt16 nCnt, SwCursorSkipMode 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, SwCursorSkipMode::Chars, false/*bAllowVisual*/, false/*bSkipHidden*/, false, nullptr, false); }
173 bool Right( sal_uInt16 nCnt ) { return LeftRight(false, nCnt, SwCursorSkipMode::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( std::u16string_view 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 sal_Int32 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{
234private:
236public:
239};
240
241// internal, used by SwCursor::SaveState() etc.
243{
245 sal_Int32 nContent;
246
247 SwCursor_SavePos( const SwCursor& rCursor )
248 : nNode( rCursor.GetPoint()->GetNodeIndex() ),
249 nContent( rCursor.GetPoint()->GetContentIndex() )
250 {}
251};
252
253class SwTableCursor : public virtual SwCursor
254{
255
256protected:
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
267public:
268 SwTableCursor( const SwPosition &rPos );
270 virtual ~SwTableCursor() override;
271
272 virtual bool LeftRight( bool bLeft, sal_uInt16 nCnt, SwCursorSkipMode 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 // Any boxes hidden?
287 bool HasHiddenBoxSel() const;
288
289 // Has table cursor been changed? If so, save new values immediately.
290 bool IsCursorMovedUpdate();
291 // Has table cursor been changed?
292 bool IsCursorMoved() const
293 {
294 return m_nTableMkNd != GetMark()->GetNodeIndex() ||
298 }
299
300 bool IsChgd() const { return m_bChanged; }
301 void SetChgd() { m_bChanged = true; }
302
303 // Park table cursor at start node of boxes.
304 void ParkCursor();
305
306 bool NewTableSelection();
307 void ActualizeSelection( const SwSelBoxes &rBoxes );
308
309 SwTableCursor* GetNext() { return dynamic_cast<SwTableCursor *>(GetNextInRing()); }
310 const SwTableCursor* GetNext() const { return dynamic_cast<SwTableCursor const *>(GetNextInRing()); }
311 SwTableCursor* GetPrev() { return dynamic_cast<SwTableCursor *>(GetPrevInRing()); }
312 const SwTableCursor* GetPrev() const { return dynamic_cast<SwTableCursor const *>(GetPrevInRing()); }
313};
314
315const SwCursor_SavePos* SwCursor::GetSavePos() const { return m_vSavePos.empty() ? nullptr : &m_vSavePos.back(); }
316
317SwCursor & SwCursor::operator =(SwCursor const &) = default;
318
319#endif
320
321/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SwContentFrame is the layout for content nodes: a common base class for text (paragraph) and non-text...
Definition: cntfrm.hxx:59
A helper class to save cursor state (position).
Definition: swcrsr.hxx:233
SwCursorSaveState(SwCursor &rC)
Definition: swcrsr.hxx:237
SwCursor & m_rCursor
Definition: swcrsr.hxx:235
sal_Int32 GetCursorRowSpanOffset() const
Definition: swcrsr.hxx:217
void RestoreState()
Definition: swcrsr.cxx:172
bool Left(sal_uInt16 nCnt)
Definition: swcrsr.hxx:172
sal_uInt8 GetCursorBidiLevel() const
Definition: swcrsr.hxx:211
std::vector< SwCursor_SavePos > m_vSavePos
Definition: swcrsr.hxx:74
bool GoNextCell(sal_uInt16 nCnt=1)
Definition: swcrsr.hxx:174
SwCursor & operator=(SwCursor const &)
SwCursor * GetNext()
Definition: swcrsr.hxx:219
SwCursor(SwCursor const &rPaM)=delete
bool IsColumnSelection() const
Definition: swcrsr.hxx:214
bool Right(sal_uInt16 nCnt)
Definition: swcrsr.hxx:173
const SwCursor * GetNext() const
Definition: swcrsr.hxx:220
void SaveState()
Definition: swcrsr.cxx:167
bool GoPrevCell(sal_uInt16 nCnt=1)
Definition: swcrsr.hxx:175
void SetCursorBidiLevel(sal_uInt8 nNewLevel)
Definition: swcrsr.hxx:212
bool m_bColumnSelection
Definition: swcrsr.hxx:77
SentenceMoveType
Definition: swcrsr.hxx:154
@ NEXT_SENT
Definition: swcrsr.hxx:155
@ START_SENT
Definition: swcrsr.hxx:157
@ PREV_SENT
Definition: swcrsr.hxx:156
sal_Int32 m_nRowSpanOffset
Definition: swcrsr.hxx:75
sal_uInt8 m_nCursorBidiLevel
Definition: swcrsr.hxx:76
const SwCursor * GetPrev() const
Definition: swcrsr.hxx:222
void SetColumnSelection(bool bNew)
Definition: swcrsr.hxx:215
SwCursor * GetPrev()
Definition: swcrsr.hxx:221
const SwCursor_SavePos * GetSavePos() const
Definition: swcrsr.hxx:315
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:188
const SwPosition * GetMark() const
Definition: pam.hxx:255
SwPaM & operator=(const SwPaM &)
@@ semantic: no copy assignment for super class Ring.
Definition: pam.cxx:625
const SwPosition * GetPoint() const
Definition: pam.hxx:253
The root element of a Writer document layout.
Definition: rootfrm.hxx:85
SwTableBox is one table cell in the document model.
Definition: swtable.hxx:443
bool HasReadOnlyBoxSel() const
Definition: swcrsr.cxx:2610
void SetChgd()
Definition: swcrsr.hxx:301
bool HasHiddenBoxSel() const
Definition: swcrsr.cxx:2624
const SwTableCursor * GetNext() const
Definition: swcrsr.hxx:310
bool IsCursorMovedUpdate()
Definition: swcrsr.cxx:2580
void DeleteBox(size_t nPos)
Definition: swcrsr.cxx:2518
bool NewTableSelection()
Definition: swcrsr.cxx:2524
virtual bool LeftRight(bool bLeft, sal_uInt16 nCnt, SwCursorSkipMode nMode, bool bAllowVisual, bool bSkipHidden, bool bInsertCursor, SwRootFrame const *, bool) override
Definition: swcrsr.cxx:1667
SwTableCursor * GetNext()
Definition: swcrsr.hxx:309
SwTableCursor * GetPrev()
Definition: swcrsr.hxx:311
SwSelBoxes m_SelectedBoxes
Definition: swcrsr.hxx:261
SwCursor * MakeBoxSels(SwCursor *pCurrentCursor)
Definition: swcrsr.cxx:2409
virtual bool IsSelOvrCheck(SwCursorSelOverFlags eFlags) override
Definition: swcrsr.cxx:193
SwNodeOffset m_nTableMkNd
Definition: swcrsr.hxx:258
bool m_bParked
Definition: swcrsr.hxx:263
SwTableCursor(const SwPosition &rPos)
Definition: swcrsr.cxx:2366
void ActualizeSelection(const SwSelBoxes &rBoxes)
Definition: swcrsr.cxx:2545
bool IsChgd() const
Definition: swcrsr.hxx:300
bool IsCursorMoved() const
Definition: swcrsr.hxx:292
sal_Int32 m_nTablePtCnt
Definition: swcrsr.hxx:259
const SwSelBoxes & GetSelectedBoxes() const
Definition: swcrsr.hxx:280
bool m_bChanged
Definition: swcrsr.hxx:262
size_t GetSelectedBoxesCount() const
Definition: swcrsr.hxx:279
SwNodeOffset m_nTablePtNd
Definition: swcrsr.hxx:257
void InsertBox(const SwTableBox &rTableBox)
Definition: swcrsr.cxx:2511
virtual bool GotoTable(const OUString &rName) override
Definition: swcrsr.cxx:2245
const SwTableCursor * GetPrev() const
Definition: swcrsr.hxx:312
SwTableCursor(SwTableCursor &)
void ParkCursor()
park table cursor on the boxes' start node
Definition: swcrsr.cxx:2593
virtual ~SwTableCursor() override
Definition: swcrsr.cxx:2377
sal_Int32 m_nTableMkCnt
Definition: swcrsr.hxx:260
Represents the style of a paragraph.
Definition: fmtcol.hxx:61
size_type size() const
SwPaM * GetPrevInRing()
Definition: ring.hxx:87
SwPaM * GetNextInRing()
Definition: ring.hxx:84
bool(* SwWhichTable)(SwPaM &, SwMoveFnCollection const &, bool bInReadOnly)
Definition: cshtyp.hxx:58
bool(* SwWhichPara)(SwPaM &, SwMoveFnCollection const &)
Definition: cshtyp.hxx:43
SwDocPositions
Definition: cshtyp.hxx:104
FindRanges
Definition: cshtyp.hxx:91
bool(* SwWhichRegion)(SwPaM &, SwMoveFnCollection const &, bool bInReadOnly)
Definition: cshtyp.hxx:75
bool(* SwWhichSection)(SwPaM &, SwMoveFnCollection const &)
Definition: cshtyp.hxx:51
NONE
void Create(SvxOrientationItem &rItem, SvStream &rStrm, sal_uInt16)
long Long
SwNodeOffset nNode
Definition: swcrsr.hxx:244
SwCursor_SavePos(const SwCursor &rCursor)
Definition: swcrsr.hxx:247
sal_Int32 nContent
Definition: swcrsr.hxx:245
virtual bool IsReplaceMode() const =0
~SwFindParas()
Definition: swcrsr.hxx:46
virtual int DoFind(SwPaM &, SwMoveFnCollection const &, const SwPaM &, bool, std::unique_ptr< SvxSearchItem > &xSearchItem)=0
Marks a position in the document model.
Definition: pam.hxx:38
SwNodeOffset GetNodeIndex() const
Definition: pam.hxx:78
sal_Int32 GetContentIndex() const
Definition: pam.hxx:85
SwCursorSkipMode
Definition: swcrsr.hxx:65
SwCursorSelOverFlags
Definition: swcrsr.hxx:50
const int FIND_NOT_FOUND
Definition: swcrsr.hxx:35
const int FIND_FOUND
Definition: swcrsr.hxx:36
const int FIND_NO_RING
Definition: swcrsr.hxx:37
#define SW_DLLPUBLIC
Definition: swdllapi.h:28
unsigned char sal_uInt8