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 <config_feature_desktop.h>
23 #include <vcl/cursor.hxx>
26 #include "swregion.hxx"
31 namespace sdr::overlay
{ class OverlaySelection
; }
35 class SwContentControlButton
;
37 // From here classes/methods for non-text cursor.
39 class SW_DLLPUBLIC SwVisibleCursor
41 friend void InitCore();
42 friend void FinitCore();
44 const SwCursorShell
* m_pCursorShell
;
45 vcl::Cursor m_aTextCursor
;
47 /// For LibreOfficeKit only - remember what page we were at the last time.
48 sal_uInt16 m_nPageLastTime
;
49 SwRect m_aLastLOKRect
;
55 SwVisibleCursor( const SwCursorShell
* pCShell
);
61 bool IsVisible() const { return m_bIsVisible
; }
62 void SetDragCursor( bool bFlag
= true ) { m_bIsDragCursor
= bFlag
; }
63 void SetPosAndShow(SfxViewShell
const * pViewShell
);
64 const vcl::Cursor
& GetTextCursor() const;
66 std::optional
<OString
> getLOKPayload(int nType
, int nViewId
) const;
69 // From here classes/methods for selections.
71 namespace sw::overlay
{ class OverlayRangesOutline
; }
75 * SwSelPaintRects is a base class of SwShellCursor, which stores the overlay for the
76 * cursor/selection: a list of rectangles to be painted as an overlay. It is also capable of
77 * painting other overlays as needed (text input, content control).
79 class SwSelPaintRects
: public SwRects
81 friend void InitCore();
82 friend void FinitCore();
84 static tools::Long s_nPixPtX
, s_nPixPtY
;
85 static MapMode
*s_pMapMode
;
87 const SwCursorShell
* m_pCursorShell
;
89 #if HAVE_FEATURE_DESKTOP || defined(ANDROID)
90 std::unique_ptr
<sdr::overlay::OverlaySelection
> m_pCursorOverlay
;
93 bool m_bShowTextInputFieldOverlay
;
94 std::unique_ptr
<sw::overlay::OverlayRangesOutline
> m_pTextInputFieldOverlay
;
95 bool m_bShowContentControlOverlay
;
96 std::unique_ptr
<sw::overlay::OverlayRangesOutline
> m_pContentControlOverlay
;
97 VclPtr
<SwContentControlButton
> m_pContentControlButton
;
99 void HighlightInputField();
100 void HighlightContentControl();
103 SwSelPaintRects( const SwCursorShell
& rCSh
);
104 virtual ~SwSelPaintRects();
106 virtual void FillRects() = 0;
107 /// Fill rStart and rEnd with a rectangle that represents the start and end for selection handles.
108 virtual void FillStartEnd(SwRect
& rStart
, SwRect
& rEnd
) const = 0;
110 // #i75172# in SwCursorShell::CreateCursor() the content of SwSelPaintRects is exchanged. To
111 // make a complete swap access to m_pCursorOverlay is needed there
112 void swapContent(SwSelPaintRects
& rSwap
);
114 void Show(std::vector
<OString
>* pSelectionRectangles
= nullptr);
116 void Invalidate( const SwRect
& rRect
);
118 void SetShowTextInputFieldOverlay( const bool bShow
)
120 m_bShowTextInputFieldOverlay
= bShow
;
123 void SetShowContentControlOverlay(const bool bShow
) { m_bShowContentControlOverlay
= bShow
; }
125 const VclPtr
<SwContentControlButton
>& GetContentControlButton() const;
127 const SwCursorShell
* GetShell() const { return m_pCursorShell
; }
128 // check current MapMode of the shell and set possibly the static members.
129 // Optional set the parameters pX, pY
130 static void Get1PixelInLogic( const SwViewShell
& rSh
,
131 tools::Long
* pX
= nullptr, tools::Long
* pY
= nullptr );
133 std::optional
<OString
> getLOKPayload(int nType
, int nViewId
) const;
136 /// Represents the current text cursor of one opened edit window.
138 /// See SwShellTableCursor for a table cursor that extends this class.
139 class SW_DLLPUBLIC SwShellCursor
: public virtual SwCursor
, public SwSelPaintRects
142 // Document positions of start/end characters of a SSelection.
145 const SwPosition
* m_pInitialPoint
; // For assignment of GetPoint() to m_PointPt.
147 using SwCursor::UpDown
;
150 SwShellCursor( const SwCursorShell
& rCursorSh
, const SwPosition
&rPos
);
151 SwShellCursor( const SwCursorShell
& rCursorSh
, const SwPosition
&rPos
,
152 const Point
& rPtPos
, SwPaM
* pRing
);
153 // note: *intentionally* links the new shell cursor into the old one's Ring
154 SwShellCursor( SwShellCursor
& );
155 virtual ~SwShellCursor() override
;
157 virtual void FillRects() override
; // For Table- and normal cursors.
158 /// @see SwSelPaintRects::FillStartEnd(), override for text selections.
159 virtual void FillStartEnd(SwRect
& rStart
, SwRect
& rEnd
) const override
;
161 void Show(SfxViewShell
const * pViewShell
); // Update and display all selections.
162 void Hide(); // Hide all selections.
163 void Invalidate( const SwRect
& rRect
);
165 const Point
& GetPtPos() const { return (SwPaM::GetPoint() == m_pInitialPoint
) ? m_PointPt
: m_MarkPt
; }
166 Point
& GetPtPos() { return (SwPaM::GetPoint() == m_pInitialPoint
) ? m_PointPt
: m_MarkPt
; }
167 const Point
& GetMkPos() const { return (SwPaM::GetMark() == m_pInitialPoint
) ? m_PointPt
: m_MarkPt
; }
168 Point
& GetMkPos() { return (SwPaM::GetMark() == m_pInitialPoint
) ? m_PointPt
: m_MarkPt
; }
169 const Point
& GetSttPos() const { return (SwPaM::Start() == m_pInitialPoint
) ? m_PointPt
: m_MarkPt
; }
170 Point
& GetSttPos() { return (SwPaM::Start() == m_pInitialPoint
) ? m_PointPt
: m_MarkPt
; }
171 const Point
& GetEndPos() const { return (SwPaM::End() == m_pInitialPoint
) ? m_PointPt
: m_MarkPt
; }
172 Point
& GetEndPos() { return (SwPaM::End() == m_pInitialPoint
) ? m_PointPt
: m_MarkPt
; }
174 virtual void SetMark() override
;
176 virtual SwCursor
* Create( SwPaM
* pRing
= nullptr ) const override
;
178 virtual short MaxReplaceArived() override
; //returns RET_YES/RET_CANCEL/RET_NO
179 virtual void SaveTableBoxContent( const SwPosition
* pPos
) override
;
181 bool UpDown( bool bUp
, sal_uInt16 nCnt
);
183 // true: Cursor can be set to this position.
184 virtual bool IsAtValidPos( bool bPoint
= true ) const override
;
186 virtual bool IsReadOnlyAvailable() const override
;
188 SwShellCursor
* GetNext() { return dynamic_cast<SwShellCursor
*>(GetNextInRing()); }
189 const SwShellCursor
* GetNext() const { return dynamic_cast<SwShellCursor
const *>(GetNextInRing()); }
190 SwShellCursor
* GetPrev() { return dynamic_cast<SwShellCursor
*>(GetPrevInRing()); }
191 const SwShellCursor
* GetPrev() const { return dynamic_cast<SwShellCursor
const *>(GetPrevInRing()); }
194 class SwShellTableCursor final
: public virtual SwShellCursor
, public virtual SwTableCursor
196 /// Left edge of the selection start (top left cell).
198 /// Right edge of the selection end (bottom right cell).
200 // The Selection has the same order as the table boxes, i.e.
201 // if something is deleted from the one array at a certain position
202 // it has to be deleted from the other one as well!!
205 SwShellTableCursor( const SwCursorShell
& rCursorSh
, const SwPosition
& rPos
);
206 SwShellTableCursor( const SwCursorShell
& rCursorSh
,
207 const SwPosition
&rMkPos
, const Point
& rMkPt
,
208 const SwPosition
&rPtPos
, const Point
& rPtPt
);
209 virtual ~SwShellTableCursor() override
;
211 virtual void FillRects() override
; // For table and normal cursor.
212 /// @see SwSelPaintRects::FillStartEnd(), override for table selections.
213 virtual void FillStartEnd(SwRect
& rStart
, SwRect
& rEnd
) const override
;
215 // Check if SPoint is within table SSelection.
216 bool Contains( const Point
& rPt
) const;
218 virtual void SetMark() override
;
219 virtual SwCursor
* Create( SwPaM
* pRing
= nullptr ) const override
;
221 virtual short MaxReplaceArived() override
; //returns RET_YES/RET_CANCEL/RET_NO
222 virtual void SaveTableBoxContent( const SwPosition
* pPos
) override
;
224 // true: Cursor can be set to this position.
225 virtual bool IsAtValidPos( bool bPoint
= true ) const override
;
227 SwShellTableCursor
* GetNext() { return dynamic_cast<SwShellTableCursor
*>(GetNextInRing()); }
228 const SwShellTableCursor
* GetNext() const { return dynamic_cast<SwShellTableCursor
const *>(GetNextInRing()); }
229 SwShellTableCursor
* GetPrev() { return dynamic_cast<SwShellTableCursor
*>(GetPrevInRing()); }
230 const SwShellTableCursor
* GetPrev() const { return dynamic_cast<SwShellTableCursor
const *>(GetPrevInRing()); }
234 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */