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"
29 namespace sdr::overlay
{ class OverlayObject
; }
34 // From here classes/methods for non-text cursor.
36 class SW_DLLPUBLIC SwVisibleCursor
38 friend void InitCore();
39 friend void FinitCore();
41 const SwCursorShell
* m_pCursorShell
;
42 vcl::Cursor m_aTextCursor
;
44 /// For LibreOfficeKit only - remember what page we were at the last time.
45 sal_uInt16 m_nPageLastTime
;
46 SwRect m_aLastLOKRect
;
52 SwVisibleCursor( const SwCursorShell
* pCShell
);
58 bool IsVisible() const { return m_bIsVisible
; }
59 void SetDragCursor( bool bFlag
= true ) { m_bIsDragCursor
= bFlag
; }
60 void SetPosAndShow(SfxViewShell
const * pViewShell
);
61 const vcl::Cursor
& GetTextCursor() const;
63 OString
getLOKPayload(int nType
, int nViewId
, bool* ignore
) const;
66 // From here classes/methods for selections.
68 namespace sw::overlay
{ class OverlayRangesOutline
; }
71 class SwSelPaintRects
: public SwRects
73 friend void InitCore();
74 friend void FinitCore();
76 static tools::Long s_nPixPtX
, s_nPixPtY
;
77 static MapMode
*s_pMapMode
;
79 const SwCursorShell
* m_pCursorShell
;
81 #if HAVE_FEATURE_DESKTOP || defined(ANDROID)
82 std::unique_ptr
<sdr::overlay::OverlayObject
> m_pCursorOverlay
;
85 bool m_bShowTextInputFieldOverlay
;
86 std::unique_ptr
<sw::overlay::OverlayRangesOutline
> m_pTextInputFieldOverlay
;
88 void HighlightInputField();
91 SwSelPaintRects( const SwCursorShell
& rCSh
);
92 virtual ~SwSelPaintRects();
94 virtual void FillRects() = 0;
95 /// Fill rStart and rEnd with a rectangle that represents the start and end for selection handles.
96 virtual void FillStartEnd(SwRect
& rStart
, SwRect
& rEnd
) const = 0;
98 // #i75172# in SwCursorShell::CreateCursor() the content of SwSelPaintRects is exchanged. To
99 // make a complete swap access to m_pCursorOverlay is needed there
100 void swapContent(SwSelPaintRects
& rSwap
);
102 void Show(std::vector
<OString
>* pSelectionRectangles
= nullptr);
104 void Invalidate( const SwRect
& rRect
);
106 void SetShowTextInputFieldOverlay( const bool bShow
)
108 m_bShowTextInputFieldOverlay
= bShow
;
111 const SwCursorShell
* GetShell() const { return m_pCursorShell
; }
112 // check current MapMode of the shell and set possibly the static members.
113 // Optional set the parameters pX, pY
114 static void Get1PixelInLogic( const SwViewShell
& rSh
,
115 tools::Long
* pX
= nullptr, tools::Long
* pY
= nullptr );
117 OString
getLOKPayload(int nType
, int nViewId
, bool* ignore
) const;
120 class SW_DLLPUBLIC SwShellCursor
: public virtual SwCursor
, public SwSelPaintRects
123 // Document positions of start/end characters of a SSelection.
126 const SwPosition
* m_pInitialPoint
; // For assignment of GetPoint() to m_PointPt.
128 using SwCursor::UpDown
;
131 SwShellCursor( const SwCursorShell
& rCursorSh
, const SwPosition
&rPos
);
132 SwShellCursor( const SwCursorShell
& rCursorSh
, const SwPosition
&rPos
,
133 const Point
& rPtPos
, SwPaM
* pRing
);
134 // note: *intentionally* links the new shell cursor into the old one's Ring
135 SwShellCursor( SwShellCursor
& );
136 virtual ~SwShellCursor() override
;
138 virtual void FillRects() override
; // For Table- and normal cursors.
139 /// @see SwSelPaintRects::FillStartEnd(), override for text selections.
140 virtual void FillStartEnd(SwRect
& rStart
, SwRect
& rEnd
) const override
;
142 void Show(SfxViewShell
const * pViewShell
); // Update and display all selections.
143 void Hide(); // Hide all selections.
144 void Invalidate( const SwRect
& rRect
);
146 const Point
& GetPtPos() const { return (SwPaM::GetPoint() == m_pInitialPoint
) ? m_PointPt
: m_MarkPt
; }
147 Point
& GetPtPos() { return (SwPaM::GetPoint() == m_pInitialPoint
) ? m_PointPt
: m_MarkPt
; }
148 const Point
& GetMkPos() const { return (SwPaM::GetMark() == m_pInitialPoint
) ? m_PointPt
: m_MarkPt
; }
149 Point
& GetMkPos() { return (SwPaM::GetMark() == m_pInitialPoint
) ? m_PointPt
: m_MarkPt
; }
150 const Point
& GetSttPos() const { return (SwPaM::Start() == m_pInitialPoint
) ? m_PointPt
: m_MarkPt
; }
151 Point
& GetSttPos() { return (SwPaM::Start() == m_pInitialPoint
) ? m_PointPt
: m_MarkPt
; }
152 const Point
& GetEndPos() const { return (SwPaM::End() == m_pInitialPoint
) ? m_PointPt
: m_MarkPt
; }
153 Point
& GetEndPos() { return (SwPaM::End() == m_pInitialPoint
) ? m_PointPt
: m_MarkPt
; }
155 virtual void SetMark() override
;
157 virtual SwCursor
* Create( SwPaM
* pRing
= nullptr ) const override
;
159 virtual short MaxReplaceArived() override
; //returns RET_YES/RET_CANCEL/RET_NO
160 virtual void SaveTableBoxContent( const SwPosition
* pPos
) override
;
162 bool UpDown( bool bUp
, sal_uInt16 nCnt
);
164 // true: Cursor can be set to this position.
165 virtual bool IsAtValidPos( bool bPoint
= true ) const override
;
167 virtual bool IsReadOnlyAvailable() const override
;
169 SwShellCursor
* GetNext() { return dynamic_cast<SwShellCursor
*>(GetNextInRing()); }
170 const SwShellCursor
* GetNext() const { return dynamic_cast<SwShellCursor
const *>(GetNextInRing()); }
171 SwShellCursor
* GetPrev() { return dynamic_cast<SwShellCursor
*>(GetPrevInRing()); }
172 const SwShellCursor
* GetPrev() const { return dynamic_cast<SwShellCursor
const *>(GetPrevInRing()); }
175 class SwShellTableCursor final
: public virtual SwShellCursor
, public virtual SwTableCursor
177 /// Left edge of the selection start (top left cell).
179 /// Right edge of the selection end (bottom right cell).
181 // The Selection has the same order as the table boxes, i.e.
182 // if something is deleted from the one array at a certain position
183 // it has to be deleted from the other one as well!!
186 SwShellTableCursor( const SwCursorShell
& rCursorSh
, const SwPosition
& rPos
);
187 SwShellTableCursor( const SwCursorShell
& rCursorSh
,
188 const SwPosition
&rMkPos
, const Point
& rMkPt
,
189 const SwPosition
&rPtPos
, const Point
& rPtPt
);
190 virtual ~SwShellTableCursor() override
;
192 virtual void FillRects() override
; // For table and normal cursor.
193 /// @see SwSelPaintRects::FillStartEnd(), override for table selections.
194 virtual void FillStartEnd(SwRect
& rStart
, SwRect
& rEnd
) const override
;
196 // Check if SPoint is within table SSelection.
197 bool Contains( const Point
& rPt
) const;
199 virtual void SetMark() override
;
200 virtual SwCursor
* Create( SwPaM
* pRing
= nullptr ) const override
;
202 virtual short MaxReplaceArived() override
; //returns RET_YES/RET_CANCEL/RET_NO
203 virtual void SaveTableBoxContent( const SwPosition
* pPos
) override
;
205 // true: Cursor can be set to this position.
206 virtual bool IsAtValidPos( bool bPoint
= true ) const override
;
208 SwShellTableCursor
* GetNext() { return dynamic_cast<SwShellTableCursor
*>(GetNextInRing()); }
209 const SwShellTableCursor
* GetNext() const { return dynamic_cast<SwShellTableCursor
const *>(GetNextInRing()); }
210 SwShellTableCursor
* GetPrev() { return dynamic_cast<SwShellTableCursor
*>(GetPrevInRing()); }
211 const SwShellTableCursor
* GetPrev() const { return dynamic_cast<SwShellTableCursor
const *>(GetPrevInRing()); }
215 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */