Resolves tdf#142513 - Order of ZoomIn and ZoomOut at Print Preview
[LibreOffice.git] / sw / inc / swcrsr.hxx
blob234b0196d68ea5d08253ea51a02d41d25cf3d6eb
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 "pam.hxx"
23 #include "tblsel.hxx"
24 #include "cshtyp.hxx"
26 class SfxItemSet;
27 struct SwCursor_SavePos;
28 class SvxSearchItem;
29 namespace i18nutil {
30 struct SearchOptions2;
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;
39 struct SwFindParas
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;
45 protected:
46 ~SwFindParas() {}
49 enum class SwCursorSelOverFlags : sal_uInt16
51 NONE = 0x00,
52 CheckNodeSection = 0x01,
53 Toggle = 0x02,
54 EnableRevDirection = 0x04,
55 ChangePos = 0x08
57 namespace o3tl {
58 template<> struct typed_flags<SwCursorSelOverFlags> : is_typed_flags<SwCursorSelOverFlags, 0x0f> {};
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;
70 class SW_DLLPUBLIC SwCursor : public SwPaM
72 friend class SwCursorSaveState;
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
79 sal_uLong FindAll( SwFindParas& , SwDocPositions, SwDocPositions, FindRanges, bool& bCancel );
81 SwCursor(SwCursor const& rPaM) = delete;
83 protected:
84 void SaveState();
85 void RestoreState();
87 const SwCursor_SavePos* GetSavePos() const { return m_vSavePos.empty() ? nullptr : &m_vSavePos.back(); }
89 virtual const SwContentFrame* DoSetBidiLevelLeftRight(
90 bool & io_rbLeft, bool bVisualAllowed, bool bInsertCursor);
91 virtual void DoSetBidiLevelUpDown();
92 virtual bool IsSelOvrCheck(SwCursorSelOverFlags eFlags);
94 public:
95 // single argument ctors shall be explicit.
96 SwCursor( const SwPosition &rPos, SwPaM* pRing );
97 virtual ~SwCursor() override;
99 SwCursor & operator =(SwCursor const &) = default;
101 /// this takes a second parameter, which indicates the Ring that
102 /// the new cursor should be part of (may be null)
103 SwCursor(SwCursor const& rCursor, SwPaM* pRing);
105 public:
107 virtual SwCursor* Create( SwPaM* pRing = nullptr ) const;
109 virtual short MaxReplaceArived(); //returns RET_YES/RET_CANCEL/RET_NO
110 virtual void SaveTableBoxContent( const SwPosition* pPos );
112 void FillFindPos( SwDocPositions ePos, SwPosition& rPos ) const;
113 SwMoveFnCollection const & MakeFindRange( SwDocPositions, SwDocPositions,
114 SwPaM* ) const;
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);
138 // UI versions
139 bool IsStartEndSentence(bool bEnd, SwRootFrame const* pLayout) const;
140 bool SelectWord( SwViewShell const * pViewShell, const Point* pPt );
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 );
153 enum SentenceMoveType
155 NEXT_SENT,
156 PREV_SENT,
157 START_SENT,
158 END_SENT
160 bool GoSentence(SentenceMoveType eMoveType, SwRootFrame const*pLayout = nullptr);
161 bool ExpandToSentenceBorders(SwRootFrame const* pLayout);
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 );
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( std::u16string_view rName );
179 bool GotoFootnoteAnchor();
180 bool GotoFootnoteText();
181 bool GotoNextFootnoteAnchor();
182 bool GotoPrevFootnoteAnchor();
184 bool MovePara( SwWhichPara, SwMoveFnCollection const & );
185 bool MoveSection( SwWhichSection, SwMoveFnCollection const & );
186 bool MoveTable( SwWhichTable, SwMoveFnCollection const & );
187 bool MoveRegion( SwWhichRegion, SwMoveFnCollection const & );
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 =
192 SwCursorSelOverFlags::CheckNodeSection |
193 SwCursorSelOverFlags::Toggle |
194 SwCursorSelOverFlags::ChangePos );
195 bool IsInProtectTable( bool bMove = false,
196 bool bChgCursor = true );
197 bool IsNoContent() const;
199 /** Restore cursor state to the one saved by SwCursorSaveState **/
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 GetCursorBidiLevel() const { return m_nCursorBidiLevel; }
212 void SetCursorBidiLevel( sal_uInt8 nNewLevel ) { m_nCursorBidiLevel = nNewLevel; }
214 bool IsColumnSelection() const { return m_bColumnSelection; }
215 void SetColumnSelection( bool bNew ) { m_bColumnSelection = bNew; }
217 tools::Long GetCursorRowSpanOffset() const { return m_nRowSpanOffset; }
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()); }
226 A helper class to save cursor state (position). Create SwCursorSaveState
227 object to save current state, use SwCursor::RestoreSavePos() to actually
228 restore cursor state to the saved state (SwCursorSaveState destructor only
229 removes the saved state from an internal stack). It is possible to stack
230 several SwCursorSaveState objects.
232 class SwCursorSaveState
234 private:
235 SwCursor& m_rCursor;
236 public:
237 SwCursorSaveState( SwCursor& rC ) : m_rCursor( rC ) { rC.SaveState(); }
238 ~SwCursorSaveState() { m_rCursor.RestoreState(); }
241 // internal, used by SwCursor::SaveState() etc.
242 struct SwCursor_SavePos final
244 sal_uLong nNode;
245 sal_Int32 nContent;
247 SwCursor_SavePos( const SwCursor& rCursor )
248 : nNode( rCursor.GetPoint()->nNode.GetIndex() ),
249 nContent( rCursor.GetPoint()->nContent.GetIndex() )
253 class SwTableCursor : public virtual SwCursor
256 protected:
257 sal_uLong m_nTablePtNd;
258 sal_uLong m_nTableMkNd;
259 sal_Int32 m_nTablePtCnt;
260 sal_Int32 m_nTableMkCnt;
261 SwSelBoxes m_SelectedBoxes;
262 bool m_bChanged : 1;
263 bool m_bParked : 1; // Table-cursor was parked.
265 virtual bool IsSelOvrCheck(SwCursorSelOverFlags eFlags) override;
267 public:
268 SwTableCursor( const SwPosition &rPos );
269 SwTableCursor( SwTableCursor& );
270 virtual ~SwTableCursor() override;
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;
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; }
282 // Creates cursor for all boxes.
283 SwCursor* MakeBoxSels( SwCursor* pCurrentCursor );
284 // Any boxes protected?
285 bool HasReadOnlyBoxSel() const;
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
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();
298 bool IsChgd() const { return m_bChanged; }
299 void SetChgd() { m_bChanged = true; }
301 // Park table cursor at start node of boxes.
302 void ParkCursor();
304 bool NewTableSelection();
305 void ActualizeSelection( const SwSelBoxes &rBoxes );
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()); }
313 #endif
315 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */