1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
21 #include <com/sun/star/i18n/WordType.hpp>
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>
29 #ifdef SW_DLLIMPLEMENTATION
30 #include <TextFrameIndex.hxx>
32 #include "IShellCursorSupplier.hxx"
38 #include "crstate.hxx"
44 #include "IDocumentMarkAccess.hxx"
53 class SwTextFormatColl
;
54 class SwTextINetFormat
;
55 class SwFormatINetFormat
;
64 class SwTextContentControl
;
67 struct SearchOptions2
;
69 namespace com::sun::star::text
{ class XTextRange
; }
70 namespace com::sun::star::container
{ class XStringKeyMap
; }
72 // enum and struct to get information via the Doc-Position
74 enum class IsAttrAtPos
87 ContentCheck
= 0x0400,
90 TableRedline
= 0x2000,
91 TableColRedline
= 0x4000,
93 CurrAttrs
= 0x8000, ///< only for debugging
94 TableBoxValue
= 0x10000, ///< only for debugging
96 ContentControl
= 0x20000,
97 AllowContaining
= 0x40000, // With Outline, finds an outline node for non-outline position
100 template<> struct typed_flags
<IsAttrAtPos
> : is_typed_flags
<IsAttrAtPos
, 0x7ffff> {};
103 struct SwContentAtPos
106 const SwField
* pField
;
107 const SfxPoolItem
* pAttr
;
108 const SwRangeRedline
* pRedl
;
109 SwContentNode
* pNode
;
110 const sw::mark::Fieldmark
* pFieldmark
;
112 IsAttrAtPos eContentAtPos
;
115 const SwTextAttr
* pFndTextAttr
;
117 SwContentAtPos( IsAttrAtPos eGetAtPos
)
118 : eContentAtPos( eGetAtPos
)
120 aFnd
.pField
= nullptr;
121 pFndTextAttr
= nullptr;
122 nDist
= 0; // #i23726#
125 bool IsInProtectSect() const;
126 bool IsInRTLText() const;
129 // return values of SetCursor (can be combined via ||)
130 const int CRSR_POSOLD
= 0x01, // cursor stays at old position
131 CRSR_POSCHG
= 0x02; // position changed by the layout
135 bool ReplaceImpl(SwPaM
& rCursor
, OUString
const& rReplacement
,
136 bool const bRegExp
, SwDoc
& rDoc
, SwRootFrame
const*const pLayout
);
138 /// Helperfunction to resolve backward references in regular expressions
139 std::optional
<OUString
> ReplaceBackReferences(const i18nutil::SearchOptions2
& rSearchOpt
,
140 SwPaM
* pPam
, SwRootFrame
const* pLayout
);
142 bool GetRanges(std::vector
<std::shared_ptr
<SwUnoCursor
>> & rRanges
,
143 SwDoc
& rDoc
, SwPaM
const& rDelPam
);
147 class SAL_DLLPUBLIC_RTTI SwCursorShell
149 , public sw::BroadcastingModify
150 , public ::sw::IShellCursorSupplier
152 friend class SwCallLink
;
153 friend class SwVisibleCursor
;
154 friend class SwSelPaintRects
;
156 // requires the Cursor as InternalCursor
157 friend bool GetAutoSumSel( const SwCursorShell
&, SwCellFrames
& );
161 /** for calling UpdateCursor */
163 UPDOWN
= (1 << 0), ///< keep Up/Down on columns
164 SCROLLWIN
= (1 << 1), ///< scroll window
165 CHKRANGE
= (1 << 2), ///< check overlapping PaMs
166 READONLY
= (1 << 3) ///< make visible in spite of Readonly
169 SW_DLLPUBLIC
void UpdateCursor(
170 sal_uInt16 eFlags
= SwCursorShell::SCROLLWIN
|SwCursorShell::CHKRANGE
,
171 bool bIdleEnd
= false );
175 SwRect m_aCharRect
; ///< Char-SRectangle on which the cursor is located
176 Point m_aCursorHeight
; ///< height & offset from visible Cursor
177 Point m_aOldRBPos
; ///< Right/Bottom of last VisArea
178 // (used in Invalidate by Cursor)
180 Link
<const SwFlyFrameFormat
*,void> m_aFlyMacroLnk
; /**< Link will be called, if the Cursor is set
181 into a fly. A macro can then be called */
182 Link
<LinkParamNone
*,void> m_aChgLnk
; /**< link will be called by every attribute/
183 format changes at cursor position.*/
184 Link
<SwCursorShell
&,void> m_aGrfArrivedLnk
; ///< Link calls to UI if a graphic is arrived
186 SwShellCursor
* m_pCurrentCursor
; ///< current cursor
187 SwShellCursor
* m_pStackCursor
; ///< stack for the cursor
188 SwVisibleCursor
*m_pVisibleCursor
; ///< the visible cursor
190 SwBlockCursor
*m_pBlockCursor
; ///< interface of cursor for block (=rectangular) selection
192 SwShellTableCursor
* m_pTableCursor
; /**< table Cursor; only in tables when the
193 selection lays over 2 columns */
195 SwNodeIndex
* m_pBoxIdx
; ///< for recognizing of the changed
196 SwTableBox
* m_pBoxPtr
; ///< table row
198 tools::Long m_nUpDownX
; /**< try to move the cursor on up/down always
199 in the same column */
200 tools::Long m_nLeftFramePos
;
201 SwNodeOffset m_nCurrentNode
; // save CursorPos at Start-Action
202 sal_Int32 m_nCurrentContent
;
203 SwNodeType m_nCurrentNdTyp
;
206 * Via the Method SttCursorMove and EndCursorMove this counter gets
207 * incremented/decremented. As long as the counter is inequal to 0, the
208 * current Cursor gets no update. This way, "complicated" cursor movements
209 * (via Find()) can be realised.
211 sal_uInt16 m_nCursorMove
;
212 CursorMoveState m_eMvState
; ///< Status for Cursor-Travelling - GetModelPositionForViewPoint
213 SwTable::SearchType m_eEnhancedTableSel
; /// table rows or columns selected by not cell by cell
215 OUString m_sMarkedListId
;
216 int m_nMarkedListLevel
;
218 bool m_bHasFocus
: 1; ///< Shell is "active" in a window
219 bool m_bSVCursorVis
: 1; ///< SV-Cursor visible/invisible
220 bool m_bChgCallFlag
: 1; ///< attribute change inside Start- and EndAction
221 bool m_bVisPortChgd
: 1; ///< in VisPortChg-Call
222 // (used in Invalidate by the Cursor)
224 bool m_bCallChgLnk
: 1; ///< flag for derived classes
225 // true -> call ChgLnk
226 // access only via SwChgLinkFlag
227 bool m_bAllProtect
: 1; ///< Flag for areas
228 // true -> everything protected / hidden
229 bool m_bInCMvVisportChgd
: 1; ///< Flag for CursorMoves
230 // true -> view was moved
231 bool m_bGCAttr
: 1; // true -> non expanded attributes exist.
232 bool m_bIgnoreReadonly
: 1; // true -> make the cursor visible on next
233 // EndAction in spite of Readonly
234 bool m_bSelTableCells
: 1; // true -> select cells over the InputWin
235 bool m_bAutoUpdateCells
: 1; // true -> autoformat cells
236 bool m_bBasicHideCursor
: 1; // true -> HideCursor from Basic
237 bool m_bSetCursorInReadOnly
: 1;// true -> Cursor is allowed in ReadOnly-Areas
238 bool m_bOverwriteCursor
: 1; // true -> show Overwrite Cursor
239 bool m_bIsCursorPosChanged
: 1; // true -> if the cursor position is changed last cursor update
241 // true -> send accessible events when cursor changes
242 // (set to false when using internal-only helper cursor)
243 bool m_bSendAccessibleCursorEvents
: 1;
245 bool m_bMacroExecAllowed
: 1;
247 // SwViewShell::LayoutIdle needs to be called on cursor update to repeat a spell check,
248 // because previous attempt marked a word as pending, because the word had cursor
249 bool m_bNeedLayoutOnCursorUpdate
: 1 = false;
251 SwFrame
* m_oldColFrame
;
253 Idle m_aLayoutIdle
; // An idle to schedule another SwViewShell::LayoutIdle call
255 void MoveCursorToNum();
257 void ParkPams( SwPaM
* pDelRg
, SwShellCursor
** ppDelRing
);
259 /** Mark a certain list level of a certain list
261 levels of a certain lists are marked now
263 @param sListId list Id of the list whose level is marked
264 @param nLevel to be marked list level
266 An empty sListId denotes that no level of a list is marked.
268 void MarkListLevel( const OUString
& sListId
,
271 // private method(s) accessed from public inline method(s) must be exported.
272 SW_DLLPUBLIC
bool LeftRight( bool, sal_uInt16
, SwCursorSkipMode
, bool );
273 bool UpDown( bool, sal_uInt16
);
274 bool LRMargin( bool, bool bAPI
= false );
275 bool IsAtLRMargin( bool, bool bAPI
= false ) const;
277 bool isInHiddenFrame(SwShellCursor
* pShellCursor
);
279 bool GoStartWordImpl();
280 bool GoEndWordImpl();
281 bool GoNextWordImpl();
282 bool GoPrevWordImpl();
283 bool GoNextSentenceImpl();
284 bool GoEndSentenceImpl();
285 bool GoStartSentenceImpl();
287 typedef bool (SwCursor::*FNCursor
)();
288 typedef bool (SwCursorShell::*FNCursorShell
)();
289 bool CallCursorFN( FNCursor
);
290 bool CallCursorShellFN( FNCursorShell
);
292 const SwRangeRedline
* GotoRedline_( SwRedlineTable::size_type nArrPos
, bool bSelect
);
294 void sendLOKCursorUpdates();
296 DECL_LINK(DoLayoutIdle
, Timer
*, void); // calls SwViewShell::LayoutIdle
300 inline SwMoveFnCollection
const & MakeFindRange( SwDocPositions
, SwDocPositions
, SwPaM
* ) const;
303 * Compare-Method for the StackCursor and the current Cursor.
304 * The Methods return -1, 0, 1 for lower, equal, greater.
306 int CompareCursorStackMkCurrPt() const;
308 SW_DLLPUBLIC
bool SelTableRowOrCol( bool bRow
, bool bRowSimple
= false );
310 bool SetInFrontOfLabel( bool bNew
);
312 void RefreshBlockCursor();
314 /** Updates the marked list level according to the cursor.
316 void UpdateMarkedListLevel();
319 virtual void SwClientNotify(const SwModify
&, const SfxHint
&) override
;
321 virtual void OnSpellWrongStatePending() override
{ m_bNeedLayoutOnCursorUpdate
= true; }
324 SwCursorShell( SwDoc
& rDoc
, vcl::Window
*pWin
, const SwViewOption
*pOpt
);
325 // disguised copy constructor
326 SwCursorShell( SwCursorShell
& rShell
, vcl::Window
*pWin
);
327 virtual ~SwCursorShell() override
;
329 // create new cursor and append the old one
330 virtual SwCursor
& CreateNewShellCursor() override
;
331 SW_DLLPUBLIC
virtual SwCursor
& GetCurrentShellCursor() override
;
333 SW_DLLPUBLIC SwPaM
* CreateCursor();
334 ///< delete the current cursor and make the following into the current
335 SW_DLLPUBLIC
void DestroyCursor();
336 ///< transform TableCursor to normal cursor, nullify Tablemode
337 void TableCursorToCursor();
338 ///< enter block mode, change normal cursor into block cursor
339 void CursorToBlockCursor();
340 ///< leave block mode, change block cursor into normal cursor
341 void BlockCursorToCursor();
343 // SelAll() selects the document body content
344 // if ExtendedSelect() is called afterwards, the whole nodes array is selected
345 // only for usage in special cases allowed!
346 void ExtendedSelectAll(bool bFootnotes
= true);
347 /// If ExtendedSelectAll() was called and selection didn't change since then.
348 typedef std::optional
<std::pair
<SwNode
const*, std::vector
<SwTableNode
*>>> ExtendedSelection
;
349 ExtendedSelection
ExtendedSelectedAll() const;
350 enum class StartsWith
{ None
, Table
, HiddenPara
, HiddenSection
};
351 /// If document body starts with a table or starts/ends with hidden paragraph.
352 StartsWith
StartsWith_();
354 SW_DLLPUBLIC SwCursor
* GetCursor( bool bMakeTableCursor
= true ) const;
355 // return only the current cursor
356 SwShellCursor
* GetCursor_() { return m_pCurrentCursor
; }
357 const SwShellCursor
* GetCursor_() const { return m_pCurrentCursor
; }
359 // show passed cursor - for UNO
360 void SetSelection(const SwPaM
& rCursor
);
362 // remove all cursors from ContentNodes and set to 0
363 void ParkCursor( const SwNode
&rIdx
);
365 // return the current cursor stack
366 // (required in EditShell when deleting contents)
367 inline SwPaM
* GetStackCursor() const;
369 // start parenthesing, hide SV-Cursor and selected areas
370 SW_DLLPUBLIC
void StartAction();
371 // end parenthesing, show SV-Cursor and selected areas
372 SW_DLLPUBLIC
void EndAction( const bool bIdleEnd
= false );
374 // basic cursor travelling
375 tools::Long
GetUpDownX() const { return m_nUpDownX
; }
377 bool Left( sal_uInt16 nCnt
, SwCursorSkipMode nMode
, bool bAllowVisual
= false )
378 { return LeftRight( true, nCnt
, nMode
, bAllowVisual
); }
379 bool Right( sal_uInt16 nCnt
, SwCursorSkipMode nMode
, bool bAllowVisual
= false )
380 { return LeftRight( false, nCnt
, nMode
, bAllowVisual
); }
381 bool Up( sal_uInt16 nCnt
= 1 ) { return UpDown( true, nCnt
); }
382 bool Down( sal_uInt16 nCnt
= 1 ) { return UpDown( false, nCnt
); }
383 bool LeftMargin() { return LRMargin( true ); }
384 bool RightMargin(bool bAPI
= false) { return LRMargin( false, bAPI
); }
385 SW_DLLPUBLIC
bool SttEndDoc( bool bStt
);
387 bool MovePage( SwWhichPage
, SwPosPage
);
388 SW_DLLPUBLIC
bool MovePara( SwWhichPara
, SwMoveFnCollection
const & );
389 SW_DLLPUBLIC
bool MoveSection( SwWhichSection
, SwMoveFnCollection
const & );
390 SW_DLLPUBLIC
bool MoveTable( SwWhichTable
, SwMoveFnCollection
const & );
391 void MoveColumn( SwWhichColumn
, SwPosColumn
);
392 bool MoveRegion( SwWhichRegion
, SwMoveFnCollection
const & );
394 // note: DO NOT call it FindText because windows.h
395 SW_DLLPUBLIC sal_Int32
Find_Text( const i18nutil::SearchOptions2
& rSearchOpt
,
397 SwDocPositions eStart
, SwDocPositions eEnd
,
399 FindRanges eRng
, bool bReplace
= false );
401 sal_Int32
FindFormat( const SwTextFormatColl
& rFormatColl
,
402 SwDocPositions eStart
, SwDocPositions eEnd
,
404 FindRanges eRng
, const SwTextFormatColl
* pReplFormat
);
406 sal_Int32
FindAttrs( const SfxItemSet
& rSet
, bool bNoCollections
,
407 SwDocPositions eStart
, SwDocPositions eEnd
,
410 const i18nutil::SearchOptions2
* pSearchOpt
,
411 const SfxItemSet
* rReplSet
);
413 // Position the Cursor
415 // CRSR_POSCHG: when cursor was corrected from SPoint by the layout
416 // CRSR_POSOLD: when the cursor was not changed
419 * false: Over the last half of the character, place cursor behind it. This is used when
420 * the cursor is actually being moved by the user to the closest valid point.
421 * true: Place the cursor at the start of the character/field. This is used when setting
422 * the cursor is done in order to get at the properties under the mouse pointer.
424 SW_DLLPUBLIC
int SetCursor(const Point
& rPt
, bool bOnlyText
= false, bool bBlock
= true,
425 bool bFieldInfo
= false);
428 * Notification that the visible area was changed. m_aVisArea is reset, then
429 * scrolling is done. The passed Rectangle lays on pixel borders to avoid
432 virtual void VisPortChgd( const SwRect
& ) override
;
435 * virtual paint method to make selection visible again after Paint
437 void Paint(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& rRect
) override
;
440 inline void SetMark();
441 inline bool HasMark() const;
443 SW_DLLPUBLIC
void ClearMark();
446 Ensure point and mark of the current PaM are in a specific order.
448 @param bPointFirst true: If the point is behind the mark then
449 swap the PaM. false: If the mark is behind the point then swap
452 SW_DLLPUBLIC
void NormalizePam(bool bPointFirst
= true);
454 SW_DLLPUBLIC
void SwapPam();
455 SW_DLLPUBLIC
bool TestCurrPam( const Point
& rPt
,
456 bool bTstHit
= false); // only exact matches
459 /// store a copy of the current cursor on the cursor stack
460 SW_DLLPUBLIC
void Push();
461 enum class PopMode
{ DeleteCurrent
, DeleteStack
};
464 * - either from the top of the stack
465 * - or delete the current one and replace it with the cursor from the
467 * @return <true> if there was one on the stack, <false> otherwise
469 bool Pop(PopMode
, ::std::optional
<SwCallLink
>& roLink
);
470 SW_DLLPUBLIC
bool Pop(PopMode
);
473 * Delete the topmost from the stack and move its Mark into the current.
477 SW_DLLPUBLIC
void SttCursorMove();
478 SW_DLLPUBLIC
void EndCursorMove( const bool bIdleEnd
= false );
481 * When the focus is lost the selected ranges are not displayed anymore.
482 * On the other hand, on receiving the focus all selected ranges are displayed again
483 * (ranges must be recalculated!).
485 bool HasShellFocus() const { return m_bHasFocus
; }
486 void ShellLoseFocus();
487 void ShellGetFocus();
489 // Methods for displaying or hiding the visible text cursor.
490 SW_DLLPUBLIC
void ShowCursor();
491 SW_DLLPUBLIC
void HideCursor();
492 // Methods for displaying or hiding the selected ranges with visible cursor.
493 void ShowCursors( bool bCursorVis
);
496 bool IsOverwriteCursor() const { return m_bOverwriteCursor
; }
497 void SetOverwriteCursor( bool bFlag
) { m_bOverwriteCursor
= bFlag
; }
499 bool IsSendAccessibleCursorEvents() const { return m_bSendAccessibleCursorEvents
; };
500 void SetSendAccessibleCursorEvents(bool bEnable
) { m_bSendAccessibleCursorEvents
= bEnable
; };
502 // Return current frame in which the cursor is placed.
503 SW_DLLPUBLIC SwContentFrame
*GetCurrFrame( const bool bCalcFrame
= true ) const;
505 //true if cursor is hidden because of readonly.
506 //false if it is working despite readonly.
507 SW_DLLPUBLIC
bool IsCursorReadonly() const;
509 // Cursor is placed in something that is protected or selection contains
510 // something that is protected.
511 SW_DLLPUBLIC
bool HasReadonlySel(bool isReplace
= false) const;
512 bool HasHiddenSections() const;
514 // Can the cursor be set to read only ranges?
515 bool IsReadOnlyAvailable() const { return m_bSetCursorInReadOnly
; }
516 void SetReadOnlyAvailable( bool bFlag
);
517 bool IsOverReadOnlyPos( const Point
& rPt
) const;
519 // Methods for aFlyMacroLnk.
520 void SetFlyMacroLnk( const Link
<const SwFlyFrameFormat
*,void>& rLnk
) { m_aFlyMacroLnk
= rLnk
; }
521 const Link
<const SwFlyFrameFormat
*,void>& GetFlyMacroLnk() const { return m_aFlyMacroLnk
; }
523 // Methods returning/altering link for changes of attributes/formats.
524 void SetChgLnk( const Link
<LinkParamNone
*,void> &rLnk
) { m_aChgLnk
= rLnk
; }
525 const Link
<LinkParamNone
*,void>& GetChgLnk() const { return m_aChgLnk
; }
527 // Methods returning/altering link for "graphic completely loaded".
528 void SetGrfArrivedLnk( const Link
<SwCursorShell
&,void> &rLnk
) { m_aGrfArrivedLnk
= rLnk
; }
529 const Link
<SwCursorShell
&,void>& GetGrfArrivedLnk() const { return m_aGrfArrivedLnk
; }
531 //Call ChgLink. When within an action calling will be delayed.
534 // Check if the current cursor contains a selection, i.e.
535 // if Mark is set and SPoint and Mark are different.
536 SW_DLLPUBLIC
bool HasSelection() const;
538 // Check if a selection exists, i.e. if the current cursor comprises a selection.
539 inline bool IsSelection() const;
540 // returns if multiple cursors are available
541 inline bool IsMultiSelection() const;
543 // Check if a complete paragraph was selected.
544 bool IsSelFullPara() const;
546 // Check if selection is within one paragraph.
548 //Should WaitPtr be activated for Clipboard.
549 bool ShouldWait() const;
551 // Check if selection is within one paragraph.
552 bool IsSelOnePara() const;
554 // Check if selection starts a paragraph.
555 bool IsSelStartPara() const;
558 * Returns SRectangle, at which the cursor is located.
560 const SwRect
&GetCharRect() const { return m_aCharRect
; }
562 * Returns if cursor is wholly or partly within visible range.
564 bool IsCursorVisible() const { return VisArea().Overlaps( GetCharRect() ); }
566 * Returns SwRect, at which the character is located.
568 void GetCharRectAt(SwRect
& rRect
, const SwPosition
* pPos
);
570 // Return current page number:
571 // true: in which cursor is located.
572 // false: which is visible at the upper margin.
573 SW_DLLPUBLIC
void GetPageNum( sal_uInt16
&rnPhyNum
, sal_uInt16
&rnVirtNum
,
574 bool bAtCursorPos
= true, const bool bCalcFrame
= true );
575 // Returns current page's sequential number (1-based),in which cursor is located, ignoring autoinserted empty pages.
576 // Returns 0 on error
577 SW_DLLPUBLIC sal_uInt16
GetPageNumSeqNonEmpty();
578 // Determine how "empty pages" are handled
579 // (used in PhyPage).
580 sal_uInt16
GetNextPrevPageNum( bool bNext
= true );
582 // Move cursor at the beginning of page "nPage".
583 bool GotoPage( sal_uInt16 nPage
);
585 SW_DLLPUBLIC sal_uInt16
GetPageCnt();
591 void GoNextPrevCursorSetSearchLabel(const bool bNext
);
593 // at CurrentCursor.SPoint
594 SW_DLLPUBLIC ::sw::mark::MarkBase
* SetBookmark(
596 const OUString
& rName
,
597 IDocumentMarkAccess::MarkType eMark
= IDocumentMarkAccess::MarkType::BOOKMARK
);
598 SW_DLLPUBLIC ::sw::mark::MarkBase
* SetBookmark2(
600 const OUString
& rName
,
602 const OUString
& rCondition
);
603 SW_DLLPUBLIC
bool GotoMark( const ::sw::mark::MarkBase
* const pMark
); // sets CurrentCursor.SPoint
604 bool GotoMark( const ::sw::mark::MarkBase
* const pMark
, bool bAtStart
);
605 bool GoNextBookmark(); // true, if there was one
606 bool GoPrevBookmark();
608 bool IsFormProtected();
609 ::sw::mark::Fieldmark
* GetCurrentFieldmark();
610 sw::mark::Fieldmark
* GetFieldmarkAfter();
611 sw::mark::Fieldmark
* GetFieldmarkBefore();
612 bool GotoFieldmark(const ::sw::mark::Fieldmark
* const pMark
);
614 // update Cursr, i.e. reset it into content should only be called when the
615 // cursor was set to a random position e.g. when deleting frames
616 void UpdateCursorPos();
618 // get the selected text at the current cursor. It will be filled with
620 SW_DLLPUBLIC OUString
GetSelText() const;
622 /// Check if Point of current cursor is placed within a table.
623 SW_DLLPUBLIC
const SwTableNode
* IsCursorInTable() const;
624 bool MoveOutOfTable();
625 bool TrySelectOuterTable();
626 bool MoveStartText();
628 SW_DLLPUBLIC
bool IsCursorInFootnote() const;
630 inline Point
& GetCursorDocPos() const;
631 // get cursor position relative to the page it is in
632 Point
GetCursorPagePos() const;
633 inline bool IsCursorPtAtEnd() const;
635 inline const SwPaM
* GetTableCrs() const;
636 inline SwPaM
* GetTableCrs();
638 bool IsTableComplexForChart();
639 // get current table selection as text
640 OUString
GetBoxNms() const;
642 // set Cursor to the next/previous cell
643 SW_DLLPUBLIC
bool GoNextCell( bool bAppendLine
= true );
644 SW_DLLPUBLIC
bool GoPrevCell();
645 // go to this box (if available and inside of table)
646 bool GotoTable( const OUString
& rName
);
648 // select a table row, column or box (based on the current cursor)
649 bool SelTableRow() { return SelTableRowOrCol( true ); }
650 bool SelTableCol() { return SelTableRowOrCol( false ); }
653 SW_DLLPUBLIC
bool SelTable();
658 bool GotoOutline( const OUString
& rName
);
659 // to the next/previous or the given OutlineNode
660 void GotoOutline( SwOutlineNodes::size_type nIdx
);
661 // find the "outline position" in the nodes array of the current chapter
662 SW_DLLPUBLIC
SwOutlineNodes::size_type
GetOutlinePos(sal_uInt8 nLevel
= UCHAR_MAX
, SwPaM
* pPaM
= nullptr);
663 // select the given range of OutlineNodes. Optionally including the children
664 // the sal_uInt16s are the positions in OutlineNodes-Array (EditShell)
665 void MakeOutlineSel(SwOutlineNodes::size_type nSttPos
, SwOutlineNodes::size_type nEndPos
,
666 bool bWithChildren
, bool bKillPams
= true, SwOutlineNodesInline
* pOutlNdsInline
= nullptr);
668 bool GotoNextOutline();
669 bool GotoPrevOutline();
671 /** Delivers the current shell cursor
673 Some operations have to run on the current cursor ring,
674 some on the m_pTableCursor (if exist) or the current cursor ring and
675 some on the m_pTableCursor or m_pBlockCursor or the current cursor ring.
676 This small function checks the existence and delivers the wished cursor.
679 if the block cursor is of interest or not
681 @return m_pTableCursor if exist,
682 m_pBlockCursor if exist and of interest (param bBlock)
683 otherwise m_pCurrentCursor
685 SW_DLLPUBLIC SwShellCursor
* getShellCursor( bool bBlock
);
686 const SwShellCursor
* getShellCursor( bool bBlock
) const
687 { return const_cast<SwCursorShell
*>(this)->getShellCursor( bBlock
); }
689 bool IsBlockMode() const { return nullptr != m_pBlockCursor
; }
691 // is the Cursor in a table and is the selection over 2 columns
692 bool IsTableMode() const { return nullptr != m_pTableCursor
; }
694 const SwShellTableCursor
* GetTableCursor() const { return m_pTableCursor
; }
695 SwShellTableCursor
* GetTableCursor() { return m_pTableCursor
; }
696 size_t UpdateTableSelBoxes();
698 SW_DLLPUBLIC
bool GotoFootnoteText(); ///< jump from content to footnote
699 bool GotoFootnoteAnchor(); ///< jump from footnote to anchor
700 SW_DLLPUBLIC
bool GotoPrevFootnoteAnchor();
701 SW_DLLPUBLIC
bool GotoNextFootnoteAnchor();
703 void GotoFlyAnchor(); ///< jump from the frame to the anchor
704 SW_DLLPUBLIC
bool GotoHeaderText(); ///< jump from the content to the header
705 bool GotoFooterText(); ///< jump from the content to the footer
706 // jump to the header/footer of the given or current PageDesc
707 bool SetCursorInHdFt(size_t nDescNo
, bool bInHeader
, bool bEven
= false, bool bFirst
= false);
708 // is point of cursor in header/footer. pbInHeader return true if it is
709 // in a headerframe otherwise in a footerframe
710 SW_DLLPUBLIC
bool IsInHeaderFooter( bool* pbInHeader
= nullptr ) const;
712 bool GotoNextTOXBase( const OUString
* = nullptr );
713 bool GotoPrevTOXBase( const OUString
* = nullptr );
714 void GotoTOXMarkBase();
715 // jump to the next or previous index entry
716 bool GotoNxtPrvTOXMark( bool bNext
= true );
717 // jump to the next/previous index mark of this type
718 SW_DLLPUBLIC
const SwTOXMark
& GotoTOXMark( const SwTOXMark
& rStart
, SwTOXSearch eDir
);
720 // jump to the next or previous table formula
721 // optionally only to broken formulas
722 bool GotoNxtPrvTableFormula( bool bNext
= true,
723 bool bOnlyErrors
= false );
724 // jump to the next / previous hyperlink - inside text and also
726 bool SelectNxtPrvHyperlink( bool bNext
);
728 bool GotoRefMark( const OUString
& rRefMark
, sal_uInt16 nSubType
,
729 sal_uInt16 nSeqNo
, sal_uInt16 nFlags
);
731 // get the nth character from the start or end of the current selection
732 sal_Unicode
GetChar( bool bEnd
= true, tools::Long nOffset
= 0 );
733 bool ExtendSelection( bool bEnd
= true, sal_Int32 nCount
= 1 );
735 // Place only the visible cursor at the given position in the document.
736 // Return false if SPoint was corrected by layout.
737 // (This is needed for displaying the Drag&Drop/Copy-Cursor.)
738 bool SetVisibleCursor( const Point
&rPt
);
739 inline void UnSetVisibleCursor();
740 SW_DLLPUBLIC SwVisibleCursor
* GetVisibleCursor() const;
742 // jump to the next or previous field of the corresponding type
744 const SwFieldType
* pFieldType
,
746 const SwFieldIds nResType
= SwFieldIds::Unknown
,
747 const bool bAddSetExpressionFieldsToInputFields
= true );
749 bool GotoFormatField( const SwFormatField
& rField
);
751 bool GotoFormatContentControl(const SwFormatContentControl
& rContentControl
);
753 SW_DLLPUBLIC
void GotoFormControl(bool bNext
);
755 static SwTextField
* GetTextFieldAtPos(
756 const SwPosition
* pPos
,
757 ::sw::GetTextAttrMode eMode
);
758 static SwTextField
* GetTextFieldAtCursor(
759 const SwPaM
* pCursor
,
760 ::sw::GetTextAttrMode eMode
);
761 SW_DLLPUBLIC
static SwField
* GetFieldAtCursor(
762 const SwPaM
* pCursor
,
763 const bool bIncludeInputFieldAtStart
);
764 SW_DLLPUBLIC SwField
* GetCurField( const bool bIncludeInputFieldAtStart
= false ) const;
765 SW_DLLPUBLIC
bool CursorInsideInputField() const;
766 SW_DLLPUBLIC SwTextContentControl
* CursorInsideContentControl() const;
767 SW_DLLPUBLIC
static bool PosInsideInputField( const SwPosition
& rPos
);
768 bool DocPtInsideInputField( const Point
& rDocPt
) const;
769 static sal_Int32
StartOfInputFieldAtPos( const SwPosition
& rPos
);
770 static sal_Int32
EndOfInputFieldAtPos( const SwPosition
& rPos
);
772 // Return number of cursors in ring (The flag indicates whether
773 // only cursors containing selections are requested).
774 SW_DLLPUBLIC sal_uInt16
GetCursorCnt( bool bAll
= true ) const;
776 // Char Travelling - methods (in crstrvl1.cxx)
780 SW_DLLPUBLIC
bool GoPrevWord();
781 bool GoNextSentence();
782 SW_DLLPUBLIC
bool GoStartSentence();
783 SW_DLLPUBLIC
bool GoEndSentence();
784 bool SelectWord( const Point
* pPt
);
785 bool SelectWordWT( const Point
* pt
, sal_Int16 nWordType
);
786 void ExpandToSentenceBorders();
788 // get position from current cursor
789 bool IsStartWord( sal_Int16 nWordType
= css::i18n::WordType::ANYWORD_IGNOREWHITESPACES
)const;
790 bool IsEndWord( sal_Int16 nWordType
= css::i18n::WordType::ANYWORD_IGNOREWHITESPACES
) const;
791 bool IsInWord( sal_Int16 nWordType
= css::i18n::WordType::ANYWORD_IGNOREWHITESPACES
) const;
792 bool IsStartSentence() const;
793 bool IsEndSentence() const;
794 SW_DLLPUBLIC
bool IsSttPara() const;
795 SW_DLLPUBLIC
bool IsEndPara() const;
796 bool IsEndOfTable() const; ///< at the very last SwPosition inside a table
797 bool IsStartOfDoc() const;
798 SW_DLLPUBLIC
bool IsEndOfDoc() const;
799 bool IsInFrontOfLabel() const;
800 bool IsAtLeftMargin() const { return IsAtLRMargin( true ); }
801 bool IsAtRightMargin() const { return IsAtLRMargin( false, true/*bAPI*/ ); }
803 // delete all created cursors, set the table cursor and the last cursor to
804 // its TextNode (or StartNode?)
805 // They all get created on the next ::GetCursor again
806 // Used for Drag&Drop/Clipboard-Paste in tables
807 bool ParkTableCursor();
809 // Non expanded attributes?
810 bool IsGCAttr() const { return m_bGCAttr
; }
811 void ClearGCAttr() { m_bGCAttr
= false; }
812 void UpdateAttr() { m_bGCAttr
= true; }
814 // is the whole document protected/hidden (for UI...)
815 bool IsAllProtect() const { return m_bAllProtect
; }
817 bool GotoRegion( std::u16string_view rName
);
819 // show the current selection
820 virtual void MakeSelVisible();
822 // set the cursor to a NOT protected/hidden node
823 bool FindValidContentNode( bool bOnlyText
);
825 SW_DLLPUBLIC
bool GetContentAtPos( const Point
& rPt
,
826 SwContentAtPos
& rContentAtPos
,
827 bool bSetCursor
= false,
828 SwRect
* pFieldRect
= nullptr );
830 const SwPostItField
* GetPostItFieldAtCursor() const;
832 // get smart tags rectangle for the given point
833 void GetSmartTagRect( const Point
& rPt
, SwRect
& rSelectRect
);
835 // get smart tags at current cursor position
836 void GetSmartTagTerm( std::vector
< OUString
>& rSmartTagTypes
,
837 css::uno::Sequence
< css::uno::Reference
< css::container::XStringKeyMap
> >& rStringKeyMaps
,
838 css::uno::Reference
<css::text::XTextRange
>& rRange
) const;
840 bool IsPageAtPos( const Point
&rPt
) const;
842 bool SelectTextAttr( sal_uInt16 nWhich
, bool bExpand
, const SwTextAttr
* pAttr
= nullptr );
843 bool GotoINetAttr( const SwTextINetFormat
& rAttr
);
844 const SwFormatINetFormat
* FindINetAttr( std::u16string_view rName
) const;
846 SW_DLLPUBLIC
bool SelectTextModel(sal_Int32 nStart
, sal_Int32 nEnd
);
847 #ifdef SW_DLLIMPLEMENTATION
848 bool SelectTextView(TextFrameIndex nStart
, TextFrameIndex nEnd
);
849 // result is only valid while cursor isn't moved!
850 TextFrameIndex
GetCursorPointAsViewIndex() const;
853 bool CheckTableBoxContent( const SwPosition
* pPos
= nullptr );
854 void SaveTableBoxContent( const SwPosition
* pPos
= nullptr );
855 void ClearTableBoxContent();
856 bool EndAllTableBoxEdit();
858 void SetSelTableCells( bool bFlag
) { m_bSelTableCells
= bFlag
; }
859 bool IsSelTableCells() const { return m_bSelTableCells
; }
861 void UnsetEnhancedTableSelection() { m_eEnhancedTableSel
= SwTable::SEARCH_NONE
; }
862 SwTable::SearchType
GetEnhancedTableSelection() const { return m_eEnhancedTableSel
; }
864 bool IsAutoUpdateCells() const { return m_bAutoUpdateCells
; }
865 void SetAutoUpdateCells( bool bFlag
) { m_bAutoUpdateCells
= bFlag
; }
867 bool GetShadowCursorPos( const Point
& rPt
, SwFillMode eFillMode
,
868 SwRect
& rRect
, sal_Int16
& rOrient
);
869 SW_DLLPUBLIC
bool SetShadowCursorPos( const Point
& rPt
, SwFillMode eFillMode
);
871 const SwRangeRedline
* SelNextRedline();
872 const SwRangeRedline
* SelPrevRedline();
873 SW_DLLPUBLIC
const SwRangeRedline
* GotoRedline( SwRedlineTable::size_type nArrPos
, bool bSelect
);
875 bool GotoFootnoteAnchor(const SwTextFootnote
& rTextFootnote
);
877 SvxFrameDirection
GetTextDirection( const Point
* pPt
= nullptr ) const;
878 // is cursor or the point in/over a vertical formatted text?
879 bool IsInVerticalText( const Point
* pPt
= nullptr ) const;
880 // is cursor or the point in/over a right to left formatted text?
881 bool IsInRightToLeftText() const;
883 static void FirePageChangeEvent(sal_uInt16 nOldPage
, sal_uInt16 nNewPage
);
884 bool bColumnChange();
885 static void FireSectionChangeEvent(sal_uInt16 nOldSection
, sal_uInt16 nNewSection
);
886 static void FireColumnChangeEvent(sal_uInt16 nOldColumn
, sal_uInt16 nNewColumn
);
887 // If the current cursor position is inside a hidden range true is returned. If bSelect is
888 // true, the hidden range is selected. If bSelect is false, the hidden range is not selected.
889 bool IsInHiddenRange(const bool bSelect
);
891 // remove all invalid cursors
892 void ClearUpCursors();
894 void SetMacroExecAllowed( const bool _bMacroExecAllowed
)
896 m_bMacroExecAllowed
= _bMacroExecAllowed
;
898 bool IsMacroExecAllowed() const
900 return m_bMacroExecAllowed
;
904 Returns textual description of the current selection.
906 - If the current selection is a multi-selection the result is
908 - Else the result is the text of the selection.
910 @return the textual description of the current selection
912 OUString
GetCursorDescr() const;
914 virtual void dumpAsXml(xmlTextWriterPtr pWriter
) const override
;
915 /// Implementation of lok::Document::getPartPageRectangles() for Writer.
916 OUString
getPageRectangles();
918 /// See SwView::NotifyCursor().
919 void NotifyCursor(SfxViewShell
* pViewShell
) const;
923 inline SwMoveFnCollection
const & SwCursorShell::MakeFindRange(
924 SwDocPositions nStt
, SwDocPositions nEnd
, SwPaM
* pPam
) const
926 return m_pCurrentCursor
->MakeFindRange( nStt
, nEnd
, pPam
);
929 inline SwPaM
* SwCursorShell::GetStackCursor() const { return m_pStackCursor
; }
931 inline void SwCursorShell::SetMark() { m_pCurrentCursor
->SetMark(); }
933 inline bool SwCursorShell::HasMark() const { return m_pCurrentCursor
->HasMark(); }
935 inline bool SwCursorShell::IsSelection() const
937 return IsTableMode() || m_pCurrentCursor
->HasMark() ||
938 m_pCurrentCursor
->GetNext() != m_pCurrentCursor
;
940 inline bool SwCursorShell::IsMultiSelection() const
942 return m_pCurrentCursor
->GetNext() != m_pCurrentCursor
;
945 inline bool SwCursorShell::IsCursorPtAtEnd() const
947 return m_pCurrentCursor
->End() == m_pCurrentCursor
->GetPoint();
950 inline Point
& SwCursorShell::GetCursorDocPos() const
952 return m_pCurrentCursor
->GetPtPos();
955 inline const SwPaM
* SwCursorShell::GetTableCrs() const
957 return m_pTableCursor
;
960 inline SwPaM
* SwCursorShell::GetTableCrs()
962 return m_pTableCursor
;
965 inline void SwCursorShell::UnSetVisibleCursor()
967 m_pVisibleCursor
->Hide();
968 m_pVisibleCursor
->SetDragCursor( false );
971 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */