Debian Codegraph @

sw/inc/crsrsh.hxx

raw symbols SCIP
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 #pragma once
20
21 #include <com/sun/star/i18n/WordType.hpp>
22
23 #include <rtl/ustring.hxx>
24 #include <tools/link.hxx>
25 #include <vcl/idle.hxx>
26 #include <vcl/keycod.hxx>
27 #include <o3tl/typed_flags_set.hxx>
28
29 #ifdef SW_DLLIMPLEMENTATION
30 #include <TextFrameIndex.hxx>
31 #endif
32 #include "IShellCursorSupplier.hxx"
33 #include "swdllapi.h"
34 #include "docary.hxx"
35 #include "viewsh.hxx"
36 #include "calbck.hxx"
37 #include "cshtyp.hxx"
38 #include "crstate.hxx"
39 #include "toxe.hxx"
40 #include "tblsel.hxx"
41 #include "viscrs.hxx"
42 #include "node.hxx"
43 #include "fldbas.hxx"
44 #include "IDocumentMarkAccess.hxx"
45 #include <optional>
46
47 class SfxItemSet;
48 class SfxPoolItem;
49 class SwCallLink;
50 class SwContentFrame;
51 class SwUnoCursor;
52 class SwFormatField;
53 class SwTextFormatColl;
54 class SwTextINetFormat;
55 class SwFormatINetFormat;
56 class SwTextAttr;
57 class SwTOXMark;
58 class SwRangeRedline;
59 class SwBlockCursor;
60 class SwPostItField;
61 class SwTextField;
62 class SwTextFootnote;
63 class SwTextContentControl;
64 class SwMarkName;
65 enum class ReferencesSubtype : sal_uInt16;
66
67 namespace i18nutil {
68 struct SearchOptions2;
69 }
70 namespace com::sun::star::text { class XTextRange; }
71 namespace com::sun::star::container { class XStringKeyMap; }
72
73 // enum and struct to get information via the Doc-Position
74
75 enum class IsAttrAtPos
76 {
77 NONE = 0x0000,
78 Field = 0x0001,
79 ClickField = 0x0002,
80 Footnote = 0x0004,
81 InetAttr = 0x0008,
82 TableBoxFml = 0x0010,
83 Redline = 0x0020,
84 Outline = 0x0040,
85 ToxMark = 0x0080,
86 RefMark = 0x0100,
87 NumLabel = 0x0200,
88 ContentCheck = 0x0400,
89 SmartTag = 0x0800,
90 FormControl = 0x1000,
91 TableRedline = 0x2000,
92 TableColRedline = 0x4000,
93 #ifdef DBG_UTIL
94 CurrAttrs = 0x8000, ///< only for debugging
95 TableBoxValue = 0x10000, ///< only for debugging
96 #endif
97 ContentControl = 0x20000,
98 AllowContaining = 0x40000, // With Outline, finds an outline node for non-outline position
99 };
100 namespace o3tl {
101 template<> struct typed_flags<IsAttrAtPos> : is_typed_flags<IsAttrAtPos, 0x7ffff> {};
102 }
103
104 struct SwContentAtPos
105 {
106 union {
107 const SwField* pField;
108 const SfxPoolItem* pAttr;
109 const SwRangeRedline* pRedl;
110 SwContentNode * pNode;
111 const sw::mark::Fieldmark* pFieldmark;
112 } aFnd;
113 IsAttrAtPos eContentAtPos;
114 int nDist;
115 OUString sStr;
116 const SwTextAttr* pFndTextAttr;
117
118 SwContentAtPos( IsAttrAtPos eGetAtPos )
119 : eContentAtPos( eGetAtPos )
120 {
121 aFnd.pField = nullptr;
122 pFndTextAttr = nullptr;
123 nDist = 0; // #i23726#
124 }
125
126 bool IsInProtectSect() const;
127 bool IsInRTLText() const;
128 };
129
130 // return values of SetCursor (can be combined via ||)
131 const int CRSR_POSOLD = 0x01, // cursor stays at old position
132 CRSR_POSCHG = 0x02; // position changed by the layout
133
134 namespace sw {
135
136 bool ReplaceImpl(SwPaM & rCursor, OUString const& rReplacement,
137 bool const bRegExp, SwDoc & rDoc, SwRootFrame const*const pLayout);
138
139 /// Helperfunction to resolve backward references in regular expressions
140 std::optional<OUString> ReplaceBackReferences(const i18nutil::SearchOptions2& rSearchOpt,
141 SwPaM* pPam, SwRootFrame const* pLayout );
142
143 bool GetRanges(std::vector<std::shared_ptr<SwUnoCursor>> & rRanges,
144 SwDoc & rDoc, SwPaM const& rDelPam);
145
146 struct VisibleCursorState
147 {
148 SwRect m_aCharRect; ///< Char-SRectangle on which the cursor is located
149 Point m_aCursorHeight; ///< height & offset from visible Cursor
150
151 SwShellCursor* m_pCurrentCursor; ///< currently active cursor
152 SwVisibleCursor *m_pVisibleCursor; ///< cursor displayed in view
153 bool m_bSVCursorVis : 1; ///< SV-Cursor visible/invisible
154 bool m_bOverwriteCursor : 1; ///< true -> show Overwrite Cursor
155
156 bool IsOverwriteCursor() const { return m_bOverwriteCursor; }
157 void SetOverwriteCursor( bool bFlag ) { m_bOverwriteCursor = bFlag; }
158 };
159
160 } // namespace sw
161
162 class SAL_DLLPUBLIC_RTTI SwCursorShell
163 : public SwViewShell
164 , public sw::BroadcastingModify
165 , public ::sw::IShellCursorSupplier
166 , protected ::sw::VisibleCursorState
167 {
168 friend class SwCallLink;
169 friend class SwVisibleCursor;
170 friend class SwSelPaintRects;
171
172 // requires the Cursor as InternalCursor
173 friend bool GetAutoSumSel( const SwCursorShell&, SwCellFrames& );
174
175 public:
176
177 /** for calling UpdateCursor */
178 enum CursorFlag {
179 UPDOWN = (1 << 0), ///< keep Up/Down on columns
180 SCROLLWIN = (1 << 1), ///< scroll window
181 CHKRANGE = (1 << 2), ///< check overlapping PaMs
182 READONLY = (1 << 3) ///< make visible in spite of Readonly
183 };
184
185 SW_DLLPUBLIC void UpdateCursor(
186 sal_uInt16 eFlags = SwCursorShell::SCROLLWIN|SwCursorShell::CHKRANGE,
187 bool bIdleEnd = false, ScrollSizeMode eScrollSizeMode = ScrollSizeMode::ScrollSizeDefault );
188
189 private:
190
191 Point m_aOldRBPos; ///< Right/Bottom of last VisArea
192 // (used in Invalidate by Cursor)
193
194 Link<const SwFlyFrameFormat*,void> m_aFlyMacroLnk; /**< Link will be called, if the Cursor is set
195 into a fly. A macro can then be called */
196 Link<LinkParamNone*,void> m_aChgLnk; /**< link will be called by every attribute/
197 format changes at cursor position.*/
198 Link<SwCursorShell&,void> m_aGrfArrivedLnk; ///< Link calls to UI if a graphic is arrived
199
200 SwShellCursor* m_pStackCursor; ///< stack for the cursor
201
202 SwBlockCursor *m_pBlockCursor; ///< interface of cursor for block (=rectangular) selection
203
204 SwShellTableCursor* m_pTableCursor; /**< table Cursor; only in tables when the
205 selection lays over 2 columns */
206
207 #if ENABLE_YRS
208 public:
209 ::std::unordered_map<OString, ::std::unique_ptr<VisibleCursorState>> m_PeerCursors;
210 SwVisibleCursor * FindVisibleCursorForPeer(SwSelPaintRects const& rCursor) const;
211 void YrsAddCursor(OString const& rId, ::std::optional<SwPosition> const& roPoint, ::std::optional<SwPosition> const& roMark, OUString const& rAuthor);
212 void YrsSetCursor(OString const& rId, ::std::optional<SwPosition> const& roPoint, ::std::optional<SwPosition> const& roMark);
213 void YrsDelCursor(OString const& rId);
214 private:
215 #endif
216
217 SwNodeIndex* m_pBoxIdx; ///< for recognizing of the changed
218 SwTableBox* m_pBoxPtr; ///< table row
219
220 tools::Long m_nUpDownX; /**< try to move the cursor on up/down always
221 in the same column */
222 tools::Long m_nLeftFramePos;
223 SwNodeOffset m_nCurrentNode; // save CursorPos at Start-Action
224 sal_Int32 m_nCurrentContent;
225 SwNodeType m_nCurrentNdTyp;
226
227 /*
228 * Via the Method SttCursorMove and EndCursorMove this counter gets
229 * incremented/decremented. As long as the counter is inequal to 0, the
230 * current Cursor gets no update. This way, "complicated" cursor movements
231 * (via Find()) can be realised.
232 */
233 sal_uInt16 m_nCursorMove;
234 CursorMoveState m_eMvState; ///< Status for Cursor-Travelling - GetModelPositionForViewPoint
235 SwTable::SearchType m_eEnhancedTableSel; /// table rows or columns selected by not cell by cell
236
237 OUString m_sMarkedListId;
238 int m_nMarkedListLevel;
239
240 bool m_bHasFocus : 1; ///< Shell is "active" in a window
241 bool m_bChgCallFlag : 1; ///< attribute change inside Start- and EndAction
242 bool m_bVisPortChgd : 1; ///< in VisPortChg-Call
243 // (used in Invalidate by the Cursor)
244
245 bool m_bCallChgLnk : 1; ///< flag for derived classes
246 // true -> call ChgLnk
247 // access only via SwChgLinkFlag
248 bool m_bAllProtect : 1; ///< Flag for areas
249 // true -> everything protected / hidden
250 bool m_bInCMvVisportChgd : 1; ///< Flag for CursorMoves
251 // true -> view was moved
252 bool m_bGCAttr : 1; // true -> non expanded attributes exist.
253 bool m_bIgnoreReadonly : 1; // true -> make the cursor visible on next
254 // EndAction in spite of Readonly
255 bool m_bSelTableCells : 1; // true -> select cells over the InputWin
256 bool m_bAutoUpdateCells : 1; // true -> autoformat cells
257 bool m_bBasicHideCursor : 1; // true -> HideCursor from Basic
258 bool m_bSetCursorInReadOnly : 1;// true -> Cursor is allowed in ReadOnly-Areas
259
260 // true -> send accessible events when cursor changes
261 // (set to false when using internal-only helper cursor)
262 bool m_bSendAccessibleCursorEvents : 1;
263
264 bool m_bMacroExecAllowed : 1;
265
266 // SwViewShell::LayoutIdle needs to be called on cursor update to repeat a spell check,
267 // because previous attempt marked a word as pending, because the word had cursor
268 bool m_bNeedLayoutOnCursorUpdate : 1 = false;
269
270 SwFrame* m_oldColFrame;
271
272 Idle m_aLayoutIdle; // An idle to schedule another SwViewShell::LayoutIdle call
273
274 void MoveCursorToNum();
275
276 void ParkPams( SwPaM* pDelRg, SwShellCursor** ppDelRing );
277
278 /** Mark a certain list level of a certain list
279
280 levels of a certain lists are marked now
281
282 @param sListId list Id of the list whose level is marked
283 @param nLevel to be marked list level
284
285 An empty sListId denotes that no level of a list is marked.
286 */
287 void MarkListLevel( const OUString& sListId,
288 const int nLevel );
289
290 // private method(s) accessed from public inline method(s) must be exported.
291 SW_DLLPUBLIC bool LeftRight( bool, sal_uInt16, SwCursorSkipMode, bool );
292 bool UpDown( bool, sal_uInt16 );
293 bool LRMargin( bool, bool bAPI = false );
294 bool IsAtLRMargin( bool, bool bAPI = false ) const;
295
296 bool isInHiddenFrame(SwShellCursor* pShellCursor);
297
298 bool GoStartWordImpl();
299 bool GoEndWordImpl();
300 bool GoNextWordImpl();
301 bool GoPrevWordImpl();
302 bool GoNextSentenceImpl();
303 bool GoEndSentenceImpl();
304 bool GoStartSentenceImpl();
305
306 typedef bool (SwCursor::*FNCursor)();
307 typedef bool (SwCursorShell::*FNCursorShell)();
308 bool CallCursorFN( FNCursor );
309 bool CallCursorShellFN( FNCursorShell );
310
311 const SwRangeRedline* GotoRedline_( SwRedlineTable::size_type nArrPos, bool bSelect );
312
313 void sendLOKCursorUpdates();
314
315 DECL_LINK(DoLayoutIdle, Timer*, void); // calls SwViewShell::LayoutIdle
316
317 protected:
318
319 inline SwMoveFnCollection const & MakeFindRange( SwDocPositions, SwDocPositions, SwPaM* ) const;
320
321 /*
322 * Compare-Method for the StackCursor and the current Cursor.
323 * The Methods return -1, 0, 1 for lower, equal, greater.
324 */
325 int CompareCursorStackMkCurrPt() const;
326
327 SW_DLLPUBLIC bool SelTableRowOrCol( bool bRow, bool bRowSimple = false );
328
329 bool SetInFrontOfLabel( bool bNew );
330
331 void RefreshBlockCursor();
332
333 /** Updates the marked list level according to the cursor.
334 */
335 void UpdateMarkedListLevel();
336
337 protected:
338 virtual void SwClientNotify(const SwModify&, const SfxHint&) override;
339
340 virtual void OnSpellWrongStatePending() override { m_bNeedLayoutOnCursorUpdate = true; }
341
342 public:
343 SwCursorShell( SwDoc& rDoc, vcl::Window *pWin, const SwViewOption *pOpt );
344 // disguised copy constructor
345 SwCursorShell( SwCursorShell& rShell, vcl::Window *pWin );
346 virtual ~SwCursorShell() override;
347
348 // create new cursor and append the old one
349 virtual SwCursor & CreateNewShellCursor() override;
350 SW_DLLPUBLIC virtual SwCursor & GetCurrentShellCursor() override;
351
352 SW_DLLPUBLIC SwPaM * CreateCursor();
353 ///< delete the current cursor and make the following into the current
354 SW_DLLPUBLIC void DestroyCursor();
355 ///< transform TableCursor to normal cursor, nullify Tablemode
356 void TableCursorToCursor();
357 ///< enter block mode, change normal cursor into block cursor
358 void CursorToBlockCursor();
359 ///< leave block mode, change block cursor into normal cursor
360 void BlockCursorToCursor();
361
362 // SelAll() selects the document body content
363 // if ExtendedSelect() is called afterwards, the whole nodes array is selected
364 // only for usage in special cases allowed!
365 void ExtendedSelectAll(bool bFootnotes = true);
366 /// If ExtendedSelectAll() was called and selection didn't change since then.
367 typedef std::optional<std::pair<SwNode const*, std::vector<SwTableNode*>>> ExtendedSelection;
368 ExtendedSelection ExtendedSelectedAll() const;
369 enum class StartsWith { None, Table, HiddenPara, HiddenSection };
370 /// If document body starts with a table or starts/ends with hidden paragraph.
371 StartsWith StartsWith_();
372
373 SW_DLLPUBLIC SwCursor* GetCursor( bool bMakeTableCursor = true ) const;
374 // return only the current cursor
375 SwShellCursor* GetCursor_() { return m_pCurrentCursor; }
376 const SwShellCursor* GetCursor_() const { return m_pCurrentCursor; }
377
378 // show passed cursor - for UNO
379 void SetSelection(const SwPaM& rCursor);
380
381 // remove all cursors from ContentNodes and set to 0
382 void ParkCursor( const SwNode &rIdx );
383
384 // return the current cursor stack
385 // (required in EditShell when deleting contents)
386 inline SwPaM* GetStackCursor() const;
387
388 // start parenthesing, hide SV-Cursor and selected areas
389 SW_DLLPUBLIC virtual void StartAction() override;
390 // end parenthesing, show SV-Cursor and selected areas
391 SW_DLLPUBLIC virtual void EndAction(const bool bIdleEnd = false) override;
392
393 // basic cursor travelling
394 tools::Long GetUpDownX() const { return m_nUpDownX; }
395
396 bool Left( sal_uInt16 nCnt, SwCursorSkipMode nMode, bool bAllowVisual = false )
397 { return LeftRight( true, nCnt, nMode, bAllowVisual ); }
398 bool Right( sal_uInt16 nCnt, SwCursorSkipMode nMode, bool bAllowVisual = false )
399 { return LeftRight( false, nCnt, nMode, bAllowVisual ); }
400 bool Up( sal_uInt16 nCnt = 1 ) { return UpDown( true, nCnt ); }
401 bool Down( sal_uInt16 nCnt = 1 ) { return UpDown( false, nCnt ); }
402 bool LeftMargin() { return LRMargin( true ); }
403 bool RightMargin(bool bAPI = false) { return LRMargin( false, bAPI ); }
404 SW_DLLPUBLIC bool SttEndDoc( bool bStt );
405
406 bool MovePage( SwWhichPage, SwPosPage );
407 SW_DLLPUBLIC bool MovePara( SwWhichPara, SwMoveFnCollection const & );
408 SW_DLLPUBLIC bool MoveSection( SwWhichSection, SwMoveFnCollection const & );
409 SW_DLLPUBLIC bool MoveTable( SwWhichTable, SwMoveFnCollection const & );
410 void MoveColumn( SwWhichColumn, SwPosColumn );
411 bool MoveRegion( SwWhichRegion, SwMoveFnCollection const & );
412
413 // note: DO NOT call it FindText because windows.h
414 SW_DLLPUBLIC sal_Int32 Find_Text( const i18nutil::SearchOptions2& rSearchOpt,
415 bool bSearchInNotes,
416 SwDocPositions eStart, SwDocPositions eEnd,
417 bool& bCancel,
418 FindRanges eRng, bool bReplace = false );
419
420 sal_Int32 FindFormat( const SwTextFormatColl& rFormatColl,
421 SwDocPositions eStart, SwDocPositions eEnd,
422 bool& bCancel,
423 FindRanges eRng, const SwTextFormatColl* pReplFormat );
424
425 sal_Int32 FindAttrs( const SfxItemSet& rSet, bool bNoCollections,
426 SwDocPositions eStart, SwDocPositions eEnd,
427 bool& bCancel,
428 FindRanges eRng,
429 const i18nutil::SearchOptions2* pSearchOpt,
430 const SfxItemSet* rReplSet );
431
432 // Position the Cursor
433 // return values:
434 // CRSR_POSCHG: when cursor was corrected from SPoint by the layout
435 // CRSR_POSOLD: when the cursor was not changed
436 /**
437 * @param bFieldInfo
438 * false: Over the last half of the character, place cursor behind it. This is used when
439 * the cursor is actually being moved by the user to the closest valid point.
440 * true: Place the cursor at the start of the character/field. This is used when setting
441 * the cursor is done in order to get at the properties under the mouse pointer.
442 */
443 SW_DLLPUBLIC int SetCursor(const Point& rPt, bool bOnlyText = false, bool bBlock = true,
444 bool bFieldInfo = false, ScrollSizeMode eScrollSizeMode = ScrollSizeMode::ScrollSizeDefault);
445
446 /*
447 * Notification that the visible area was changed. m_aVisArea is reset, then
448 * scrolling is done. The passed Rectangle lays on pixel borders to avoid
449 * pixel errors.
450 */
451 virtual void VisPortChgd( const SwRect & ) override;
452
453 /*
454 * virtual paint method to make selection visible again after Paint
455 */
456 void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle & rRect) override;
457
458 // Areas
459 inline void SetMark();
460 inline bool HasMark() const;
461
462 SW_DLLPUBLIC void ClearMark();
463
464 /**
465 Ensure point and mark of the current PaM are in a specific order.
466
467 @param bPointFirst true: If the point is behind the mark then
468 swap the PaM. false: If the mark is behind the point then swap
469 the PaM.
470 */
471 SW_DLLPUBLIC void NormalizePam(bool bPointFirst = true);
472
473 SW_DLLPUBLIC void SwapPam();
474 SW_DLLPUBLIC bool TestCurrPam( const Point & rPt,
475 bool bTstHit = false); // only exact matches
476 SW_DLLPUBLIC void KillPams();
477
478 /// store a copy of the current cursor on the cursor stack
479 SW_DLLPUBLIC void Push();
480 enum class PopMode { DeleteCurrent, DeleteStack };
481 /*
482 * Delete a cursor
483 * - either from the top of the stack
484 * - or delete the current one and replace it with the cursor from the
485 * stack
486 * @return <true> if there was one on the stack, <false> otherwise
487 */
488 bool Pop(PopMode, ::std::optional<SwCallLink>& roLink);
489 SW_DLLPUBLIC bool Pop(PopMode);
490 /*
491 * Combine 2 Cursors.
492 * Delete the topmost from the stack and move its Mark into the current.
493 */
494 void Combine();
495
496 SW_DLLPUBLIC void SttCursorMove();
497 SW_DLLPUBLIC void EndCursorMove( const bool bIdleEnd = false );
498
499 /*
500 * When the focus is lost the selected ranges are not displayed anymore.
501 * On the other hand, on receiving the focus all selected ranges are displayed again
502 * (ranges must be recalculated!).
503 */
504 bool HasShellFocus() const { return m_bHasFocus; }
505 void ShellLoseFocus();
506 void ShellGetFocus();
507
508 // Methods for displaying or hiding the visible text cursor.
509 SW_DLLPUBLIC void ShowCursor();
510 SW_DLLPUBLIC void HideCursor();
511 // Methods for displaying or hiding the selected ranges with visible cursor.
512 void ShowCursors( bool bCursorVis );
513 void HideCursors();
514
515 bool IsSendAccessibleCursorEvents() const { return m_bSendAccessibleCursorEvents; };
516 void SetSendAccessibleCursorEvents(bool bEnable) { m_bSendAccessibleCursorEvents = bEnable; };
517
518 // Return current frame in which the cursor is placed.
519 SW_DLLPUBLIC SwContentFrame *GetCurrFrame( const bool bCalcFrame = true ) const;
520
521 //true if cursor is hidden because of readonly.
522 //false if it is working despite readonly.
523 SW_DLLPUBLIC bool IsCursorReadonly() const;
524
525 // Cursor is placed in something that is protected or selection contains
526 // something that is protected.
527 SW_DLLPUBLIC bool HasReadonlySel(bool isReplace = false) const;
528 bool HasHiddenSections() const;
529
530 // Can the cursor be set to read only ranges?
531 bool IsReadOnlyAvailable() const { return m_bSetCursorInReadOnly; }
532 void SetReadOnlyAvailable( bool bFlag );
533 bool IsOverReadOnlyPos( const Point& rPt ) const;
534
535 // Methods for aFlyMacroLnk.
536 void SetFlyMacroLnk( const Link<const SwFlyFrameFormat*,void>& rLnk ) { m_aFlyMacroLnk = rLnk; }
537 const Link<const SwFlyFrameFormat*,void>& GetFlyMacroLnk() const { return m_aFlyMacroLnk; }
538
539 // Methods returning/altering link for changes of attributes/formats.
540 void SetChgLnk( const Link<LinkParamNone*,void> &rLnk ) { m_aChgLnk = rLnk; }
541 const Link<LinkParamNone*,void>& GetChgLnk() const { return m_aChgLnk; }
542
543 // Methods returning/altering link for "graphic completely loaded".
544 void SetGrfArrivedLnk( const Link<SwCursorShell&,void> &rLnk ) { m_aGrfArrivedLnk = rLnk; }
545 const Link<SwCursorShell&,void>& GetGrfArrivedLnk() const { return m_aGrfArrivedLnk; }
546
547 //Call ChgLink. When within an action calling will be delayed.
548 void CallChgLnk();
549
550 // Check if the current cursor contains a selection, i.e.
551 // if Mark is set and SPoint and Mark are different.
552 SW_DLLPUBLIC bool HasSelection() const;
553
554 // Check if a selection exists, i.e. if the current cursor comprises a selection.
555 inline bool IsSelection() const;
556 // returns if multiple cursors are available
557 inline bool IsMultiSelection() const;
558
559 // Check if a complete paragraph was selected.
560 bool IsSelFullPara() const;
561
562 // Check if selection is within one paragraph.
563
564 //Should WaitPtr be activated for Clipboard.
565 bool ShouldWait() const;
566
567 // Check if selection is within one paragraph.
568 bool IsSelOnePara() const;
569
570 // Check if selection starts a paragraph.
571 bool IsSelStartPara() const;
572
573 /*
574 * Returns SRectangle, at which the cursor is located.
575 */
576 const SwRect &GetCharRect() const { return m_aCharRect; }
577 /*
578 * Returns if cursor is wholly or partly within visible range.
579 */
580 bool IsCursorVisible() const { return VisArea().Overlaps( GetCharRect() ); }
581 /*
582 * Returns SwRect, at which the character is located.
583 */
584 void GetCharRectAt(SwRect& rRect, const SwPosition* pPos);
585
586 // Return current page number:
587 // true: in which cursor is located.
588 // false: which is visible at the upper margin.
589 SW_DLLPUBLIC void GetPageNum( sal_uInt16 &rnPhyNum, sal_uInt16 &rnVirtNum,
590 bool bAtCursorPos = true, const bool bCalcFrame = true );
591 // Returns current page's sequential number (1-based),in which cursor is located, ignoring autoinserted empty pages.
592 // Returns 0 on error
593 SW_DLLPUBLIC sal_uInt16 GetPageNumSeqNonEmpty();
594 // Determine how "empty pages" are handled
595 // (used in PhyPage).
596 sal_uInt16 GetNextPrevPageNum( bool bNext = true );
597
598 // Move cursor at the beginning of page "nPage".
599 bool GotoPage( sal_uInt16 nPage );
600
601 SW_DLLPUBLIC sal_uInt16 GetPageCnt();
602
603 bool GoNextCursor();
604
605 bool GoPrevCursor();
606
607 void GoNextPrevCursorSetSearchLabel(const bool bNext);
608
609 // at CurrentCursor.SPoint
610 SW_DLLPUBLIC ::sw::mark::MarkBase* SetBookmark(
611 const vcl::KeyCode&,
612 const SwMarkName& rName,
613 IDocumentMarkAccess::MarkType eMark = IDocumentMarkAccess::MarkType::BOOKMARK);
614 SW_DLLPUBLIC ::sw::mark::MarkBase* SetBookmark2(
615 const vcl::KeyCode&,
616 const SwMarkName& rName,
617 bool bHide,
618 const OUString& rCondition);
619 SW_DLLPUBLIC bool GotoMark( const ::sw::mark::MarkBase* const pMark ); // sets CurrentCursor.SPoint
620 bool GotoMark( const ::sw::mark::MarkBase* const pMark, bool bAtStart );
621 bool GoNextBookmark(); // true, if there was one
622 bool GoPrevBookmark();
623
624 bool IsFormProtected();
625 ::sw::mark::Fieldmark* GetCurrentFieldmark();
626 sw::mark::Fieldmark* GetFieldmarkAfter();
627 sw::mark::Fieldmark* GetFieldmarkBefore();
628 bool GotoFieldmark(const ::sw::mark::Fieldmark* const pMark);
629
630 // update Cursr, i.e. reset it into content should only be called when the
631 // cursor was set to a random position e.g. when deleting frames
632 void UpdateCursorPos();
633
634 // get the selected text at the current cursor. It will be filled with
635 // fields etc.
636 SW_DLLPUBLIC OUString GetSelText() const;
637
638 /// Check if Point of current cursor is placed within a table.
639 SW_DLLPUBLIC const SwTableNode* IsCursorInTable() const;
640 bool MoveOutOfTable();
641 bool TrySelectOuterTable();
642 bool MoveStartText();
643
644 SW_DLLPUBLIC bool IsCursorInFootnote() const;
645
646 inline Point& GetCursorDocPos() const;
647 // get cursor position relative to the page it is in
648 Point GetCursorPagePos() const;
649 inline bool IsCursorPtAtEnd() const;
650
651 inline const SwPaM* GetTableCrs() const;
652 inline SwPaM* GetTableCrs();
653
654 bool IsTableComplexForChart();
655 // get current table selection as text
656 OUString GetBoxNms() const;
657
658 // set Cursor to the next/previous cell
659 SW_DLLPUBLIC bool GoNextCell( bool bAppendLine = true );
660 SW_DLLPUBLIC bool GoPrevCell();
661 // go to this box (if available and inside of table)
662 bool GotoTable( const UIName& rName );
663
664 // select a table row, column or box (based on the current cursor)
665 bool SelTableRow() { return SelTableRowOrCol( true ); }
666 bool SelTableCol() { return SelTableRowOrCol( false ); }
667 bool SelTableBox();
668
669 SW_DLLPUBLIC bool SelTable();
670
671 void GotoNextNum();
672 void GotoPrevNum();
673
674 bool GotoOutline( const OUString& rName );
675 // to the next/previous or the given OutlineNode
676 void GotoOutline( SwOutlineNodes::size_type nIdx );
677 // find the "outline position" in the nodes array of the current chapter
678 SW_DLLPUBLIC SwOutlineNodes::size_type GetOutlinePos(sal_uInt8 nLevel = UCHAR_MAX, SwPaM* pPaM = nullptr);
679 // select the given range of OutlineNodes. Optionally including the children
680 // the sal_uInt16s are the positions in OutlineNodes-Array (EditShell)
681 void MakeOutlineSel(SwOutlineNodes::size_type nSttPos, SwOutlineNodes::size_type nEndPos,
682 bool bWithChildren, bool bKillPams = true, const SwOutlineNodesInline* pOutlNdsInline = nullptr);
683
684 bool GotoNextOutline();
685 bool GotoPrevOutline();
686
687 /** Delivers the current shell cursor
688
689 Some operations have to run on the current cursor ring,
690 some on the m_pTableCursor (if exist) or the current cursor ring and
691 some on the m_pTableCursor or m_pBlockCursor or the current cursor ring.
692 This small function checks the existence and delivers the wished cursor.
693
694 @param bBlock [bool]
695 if the block cursor is of interest or not
696
697 @return m_pTableCursor if exist,
698 m_pBlockCursor if exist and of interest (param bBlock)
699 otherwise m_pCurrentCursor
700 */
701 SW_DLLPUBLIC SwShellCursor* getShellCursor( bool bBlock );
702 const SwShellCursor* getShellCursor( bool bBlock ) const
703 { return const_cast<SwCursorShell*>(this)->getShellCursor( bBlock ); }
704
705 bool IsBlockMode() const { return nullptr != m_pBlockCursor; }
706
707 // is the Cursor in a table and is the selection over 2 columns
708 bool IsTableMode() const { return nullptr != m_pTableCursor; }
709
710 const SwShellTableCursor* GetTableCursor() const { return m_pTableCursor; }
711 SwShellTableCursor* GetTableCursor() { return m_pTableCursor; }
712 size_t UpdateTableSelBoxes();
713
714 SW_DLLPUBLIC bool GotoFootnoteText(); ///< jump from content to footnote
715 bool GotoFootnoteAnchor(); ///< jump from footnote to anchor
716 SW_DLLPUBLIC bool GotoPrevFootnoteAnchor();
717 SW_DLLPUBLIC bool GotoNextFootnoteAnchor();
718
719 void GotoFlyAnchor(); ///< jump from the frame to the anchor
720 SW_DLLPUBLIC bool GotoHeaderText(); ///< jump from the content to the header
721 bool GotoFooterText(); ///< jump from the content to the footer
722 // jump to the header/footer of the given or current PageDesc
723 bool SetCursorInHdFt(size_t nDescNo, bool bInHeader, bool bEven = false, bool bFirst = false);
724 // is point of cursor in header/footer. pbInHeader return true if it is
725 // in a headerframe otherwise in a footerframe
726 SW_DLLPUBLIC bool IsInHeaderFooter( bool* pbInHeader = nullptr ) const;
727
728 bool GotoNextTOXBase( const UIName* = nullptr );
729 bool GotoPrevTOXBase( const UIName* = nullptr );
730 void GotoTOXMarkBase();
731 // jump to the next or previous index entry
732 bool GotoNxtPrvTOXMark( bool bNext = true );
733 // jump to the next/previous index mark of this type
734 SW_DLLPUBLIC const SwTOXMark& GotoTOXMark( const SwTOXMark& rStart, SwTOXSearch eDir );
735
736 // jump to the next or previous table formula
737 // optionally only to broken formulas
738 bool GotoNxtPrvTableFormula( bool bNext = true,
739 bool bOnlyErrors = false );
740 // jump to the next / previous hyperlink - inside text and also
741 // on graphics
742 bool SelectNxtPrvHyperlink( bool bNext );
743
744 bool GotoRefMark( const SwMarkName& rRefMark, ReferencesSubtype nSubType,
745 sal_uInt16 nSeqNo, sal_uInt16 nFlags );
746
747 // get the nth character from the start or end of the current selection
748 sal_Unicode GetChar( bool bEnd = true, tools::Long nOffset = 0 );
749 bool ExtendSelection( bool bEnd = true, sal_Int32 nCount = 1 );
750
751 // Place only the visible cursor at the given position in the document.
752 // Return false if SPoint was corrected by layout.
753 // (This is needed for displaying the Drag&Drop/Copy-Cursor.)
754 bool SetVisibleCursor( const Point &rPt, ScrollSizeMode eScrollSizeMode = ScrollSizeMode::ScrollSizeDefault );
755 inline void UnSetVisibleCursor();
756 SW_DLLPUBLIC SwVisibleCursor* GetVisibleCursor() const;
757
758 // jump to the next or previous field of the corresponding type
759 bool MoveFieldType(
760 const SwFieldType* pFieldType,
761 const bool bNext,
762 const SwFieldIds nResType = SwFieldIds::Unknown,
763 const bool bAddSetExpressionFieldsToInputFields = true );
764
765 bool GotoFormatField( const SwFormatField& rField );
766
767 bool GotoFormatContentControl(const SwFormatContentControl& rContentControl);
768
769 SW_DLLPUBLIC void GotoFormControl(bool bNext);
770
771 static SwTextField* GetTextFieldAtPos(
772 const SwPosition* pPos,
773 ::sw::GetTextAttrMode eMode);
774 static SwTextField* GetTextFieldAtCursor(
775 const SwPaM* pCursor,
776 ::sw::GetTextAttrMode eMode);
777 SW_DLLPUBLIC static SwField* GetFieldAtCursor(
778 const SwPaM* pCursor,
779 const bool bIncludeInputFieldAtStart );
780 SW_DLLPUBLIC SwField* GetCurField( const bool bIncludeInputFieldAtStart = false ) const;
781 SW_DLLPUBLIC bool CursorInsideInputField() const;
782 SW_DLLPUBLIC SwTextContentControl* CursorInsideContentControl() const;
783 SW_DLLPUBLIC static bool PosInsideInputField( const SwPosition& rPos );
784 bool DocPtInsideInputField( const Point& rDocPt ) const;
785 static sal_Int32 StartOfInputFieldAtPos( const SwPosition& rPos );
786 static sal_Int32 EndOfInputFieldAtPos( const SwPosition& rPos );
787
788 // Return number of cursors in ring (The flag indicates whether
789 // only cursors containing selections are requested).
790 SW_DLLPUBLIC sal_uInt16 GetCursorCnt( bool bAll = true ) const;
791
792 // Char Travelling - methods (in crstrvl1.cxx)
793 bool GoStartWord();
794 bool GoEndWord();
795 bool GoNextWord();
796 SW_DLLPUBLIC bool GoPrevWord();
797 bool GoNextSentence();
798 SW_DLLPUBLIC bool GoStartSentence();
799 SW_DLLPUBLIC bool GoEndSentence();
800 bool SelectWord( const Point* pPt );
801 bool SelectWordWT( const Point* pt, sal_Int16 nWordType );
802 void ExpandToSentenceBorders();
803
804 // get position from current cursor
805 bool IsStartWord( sal_Int16 nWordType = css::i18n::WordType::ANYWORD_IGNOREWHITESPACES )const;
806 bool IsEndWord( sal_Int16 nWordType = css::i18n::WordType::ANYWORD_IGNOREWHITESPACES ) const;
807 bool IsInWord( sal_Int16 nWordType = css::i18n::WordType::ANYWORD_IGNOREWHITESPACES ) const;
808 bool IsStartSentence() const;
809 bool IsEndSentence() const;
810 SW_DLLPUBLIC bool IsSttPara() const;
811 SW_DLLPUBLIC bool IsEndPara() const;
812 bool IsEndOfTable() const; ///< at the very last SwPosition inside a table
813 bool IsStartOfDoc() const;
814 SW_DLLPUBLIC bool IsEndOfDoc() const;
815 bool IsInFrontOfLabel() const;
816 bool IsAtLeftMargin() const { return IsAtLRMargin( true ); }
817 bool IsAtRightMargin() const { return IsAtLRMargin( false, true/*bAPI*/ ); }
818
819 // delete all created cursors, set the table cursor and the last cursor to
820 // its TextNode (or StartNode?)
821 // They all get created on the next ::GetCursor again
822 // Used for Drag&Drop/Clipboard-Paste in tables
823 bool ParkTableCursor();
824
825 // Non expanded attributes?
826 bool IsGCAttr() const { return m_bGCAttr; }
827 void ClearGCAttr() { m_bGCAttr = false; }
828 void UpdateAttr() { m_bGCAttr = true; }
829
830 // is the whole document protected/hidden (for UI...)
831 bool IsAllProtect() const { return m_bAllProtect; }
832
833 bool GotoRegion( std::u16string_view rName );
834
835 // show the current selection
836 virtual void MakeSelVisible(ScrollSizeMode eScrollSizeMode = ScrollSizeMode::ScrollSizeDefault);
837
838 // set the cursor to a NOT protected/hidden node
839 bool FindValidContentNode( bool bOnlyText );
840
841 SW_DLLPUBLIC bool GetContentAtPos( const Point& rPt,
842 SwContentAtPos& rContentAtPos,
843 bool bSetCursor = false,
844 SwRect* pFieldRect = nullptr );
845
846 const SwPostItField* GetPostItFieldAtCursor() const;
847
848 // get smart tags rectangle for the given point
849 void GetSmartTagRect( const Point& rPt, SwRect& rSelectRect );
850
851 // get smart tags at current cursor position
852 void GetSmartTagTerm( std::vector< OUString >& rSmartTagTypes,
853 css::uno::Sequence< css::uno::Reference< css::container::XStringKeyMap > >& rStringKeyMaps,
854 css::uno::Reference<css::text::XTextRange>& rRange ) const;
855
856 bool IsPageAtPos( const Point &rPt ) const;
857
858 bool SelectTextAttr( sal_uInt16 nWhich, bool bExpand, const SwTextAttr* pAttr = nullptr );
859 bool GotoINetAttr( const SwTextINetFormat& rAttr );
860 const SwFormatINetFormat* FindINetAttr( std::u16string_view rName ) const;
861
862 SW_DLLPUBLIC bool SelectTextModel(sal_Int32 nStart, sal_Int32 nEnd);
863 #ifdef SW_DLLIMPLEMENTATION
864 bool SelectTextView(TextFrameIndex nStart, TextFrameIndex nEnd);
865 // result is only valid while cursor isn't moved!
866 TextFrameIndex GetCursorPointAsViewIndex() const;
867 #endif
868
869 bool CheckTableBoxContent( const SwPosition* pPos = nullptr );
870 void SaveTableBoxContent( const SwPosition* pPos = nullptr );
871 void ClearTableBoxContent();
872 bool EndAllTableBoxEdit();
873
874 void SetSelTableCells( bool bFlag ) { m_bSelTableCells = bFlag; }
875 bool IsSelTableCells() const { return m_bSelTableCells; }
876
877 void UnsetEnhancedTableSelection() { m_eEnhancedTableSel = SwTable::SEARCH_NONE; }
878 SwTable::SearchType GetEnhancedTableSelection() const { return m_eEnhancedTableSel; }
879
880 bool IsAutoUpdateCells() const { return m_bAutoUpdateCells; }
881 void SetAutoUpdateCells( bool bFlag ) { m_bAutoUpdateCells = bFlag; }
882
883 bool GetShadowCursorPos( const Point& rPt, SwFillMode eFillMode,
884 SwRect& rRect, sal_Int16& rOrient );
885 SW_DLLPUBLIC bool SetShadowCursorPos( const Point& rPt, SwFillMode eFillMode );
886
887 const SwRangeRedline* SelNextRedline();
888 const SwRangeRedline* SelPrevRedline();
889 SW_DLLPUBLIC const SwRangeRedline* GotoRedline( SwRedlineTable::size_type nArrPos, bool bSelect );
890
891 bool GotoFootnoteAnchor(const SwTextFootnote& rTextFootnote);
892
893 SvxFrameDirection GetTextDirection( const Point* pPt = nullptr ) const;
894 // is cursor or the point in/over a vertical formatted text?
895 bool IsInVerticalText( const Point* pPt = nullptr ) const;
896 // is cursor or the point in/over a right to left formatted text?
897 bool IsInRightToLeftText() const;
898
899 static void FirePageChangeEvent(sal_uInt16 nOldPage, sal_uInt16 nNewPage);
900 bool bColumnChange();
901 static void FireSectionChangeEvent(sal_uInt16 nOldSection, sal_uInt16 nNewSection);
902 static void FireColumnChangeEvent(sal_uInt16 nOldColumn, sal_uInt16 nNewColumn);
903 // If the current cursor position is inside a hidden range true is returned. If bSelect is
904 // true, the hidden range is selected. If bSelect is false, the hidden range is not selected.
905 bool IsInHiddenRange(const bool bSelect);
906
907 // remove all invalid cursors
908 void ClearUpCursors();
909
910 void SetMacroExecAllowed( const bool _bMacroExecAllowed )
911 {
912 m_bMacroExecAllowed = _bMacroExecAllowed;
913 }
914 bool IsMacroExecAllowed() const
915 {
916 return m_bMacroExecAllowed;
917 }
918
919 /**
920 Returns textual description of the current selection.
921
922 - If the current selection is a multi-selection the result is
923 STR_MULTISEL.
924 - Else the result is the text of the selection.
925
926 @return the textual description of the current selection
927 */
928 OUString GetCursorDescr() const;
929
930 virtual void dumpAsXml(xmlTextWriterPtr pWriter) const override;
931 /// Implementation of lok::Document::getPartPageRectangles() for Writer.
932 OUString getPageRectangles();
933
934 /// See SwView::NotifyCursor().
935 void NotifyCursor(SfxViewShell* pViewShell) const;
936 };
937
938 // Cursor Inlines:
939 inline SwMoveFnCollection const & SwCursorShell::MakeFindRange(
940 SwDocPositions nStt, SwDocPositions nEnd, SwPaM* pPam ) const
941 {
942 return m_pCurrentCursor->MakeFindRange( nStt, nEnd, pPam );
943 }
944
945 inline SwPaM* SwCursorShell::GetStackCursor() const { return m_pStackCursor; }
946
947 inline void SwCursorShell::SetMark() { m_pCurrentCursor->SetMark(); }
948
949 inline bool SwCursorShell::HasMark() const { return m_pCurrentCursor->HasMark(); }
950
951 inline bool SwCursorShell::IsSelection() const
952 {
953 return IsTableMode() || m_pCurrentCursor->HasMark() ||
954 m_pCurrentCursor->GetNext() != m_pCurrentCursor;
955 }
956 inline bool SwCursorShell::IsMultiSelection() const
957 {
958 return m_pCurrentCursor->GetNext() != m_pCurrentCursor;
959 }
960
961 inline bool SwCursorShell::IsCursorPtAtEnd() const
962 {
963 return m_pCurrentCursor->End() == m_pCurrentCursor->GetPoint();
964 }
965
966 inline Point& SwCursorShell::GetCursorDocPos() const
967 {
968 return m_pCurrentCursor->GetPtPos();
969 }
970
971 inline const SwPaM* SwCursorShell::GetTableCrs() const
972 {
973 return m_pTableCursor;
974 }
975
976 inline SwPaM* SwCursorShell::GetTableCrs()
977 {
978 return m_pTableCursor;
979 }
980
981 inline void SwCursorShell::UnSetVisibleCursor()
982 {
983 m_pVisibleCursor->Hide();
984 m_pVisibleCursor->SetDragCursor( false );
985 }
986
987 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */