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 .
19 #ifndef INCLUDED_SW_INC_VISCRS_HXX
20 #define INCLUDED_SW_INC_VISCRS_HXX
22 #include <config_feature_desktop.h>
24 #include <vcl/cursor.hxx>
27 #include "swregion.hxx"
30 namespace sdr::overlay
{ class OverlayObject
; }
35 // From here classes/methods for non-text cursor.
37 class SW_DLLPUBLIC SwVisibleCursor
39 friend void InitCore();
40 friend void FinitCore();
45 vcl::Cursor m_aTextCursor
;
46 const SwCursorShell
* m_pCursorShell
;
48 /// For LibreOfficeKit only - remember what page we were at the last time.
49 sal_uInt16 m_nPageLastTime
;
50 SwRect m_aLastLOKRect
;
53 SwVisibleCursor( const SwCursorShell
* pCShell
);
59 bool IsVisible() const { return m_bIsVisible
; }
60 void SetDragCursor( bool bFlag
= true ) { m_bIsDragCursor
= bFlag
; }
61 void SetPosAndShow(SfxViewShell
const * pViewShell
);
62 const vcl::Cursor
& GetTextCursor() const;
64 OString
getLOKPayload(int nType
, int nViewId
, bool* ignore
) const;
67 // From here classes/methods for selections.
69 namespace sw::overlay
{ class OverlayRangesOutline
; }
72 class SwSelPaintRects
: public SwRects
74 friend void InitCore();
75 friend void FinitCore();
77 static tools::Long s_nPixPtX
, s_nPixPtY
;
78 static MapMode
*s_pMapMode
;
80 const SwCursorShell
* m_pCursorShell
;
82 #if HAVE_FEATURE_DESKTOP || defined(ANDROID)
83 std::unique_ptr
<sdr::overlay::OverlayObject
> m_pCursorOverlay
;
86 bool m_bShowTextInputFieldOverlay
;
87 std::unique_ptr
<sw::overlay::OverlayRangesOutline
> m_pTextInputFieldOverlay
;
89 void HighlightInputField();
92 SwSelPaintRects( const SwCursorShell
& rCSh
);
93 virtual ~SwSelPaintRects();
95 virtual void FillRects() = 0;
96 /// Fill rStart and rEnd with a rectangle that represents the start and end for selection handles.
97 virtual void FillStartEnd(SwRect
& rStart
, SwRect
& rEnd
) const = 0;
99 // #i75172# in SwCursorShell::CreateCursor() the content of SwSelPaintRects is exchanged. To
100 // make a complete swap access to m_pCursorOverlay is needed there
101 void swapContent(SwSelPaintRects
& rSwap
);
103 void Show(std::vector
<OString
>* pSelectionRectangles
= nullptr);
105 void Invalidate( const SwRect
& rRect
);
107 void SetShowTextInputFieldOverlay( const bool bShow
)
109 m_bShowTextInputFieldOverlay
= bShow
;
112 const SwCursorShell
* GetShell() const { return m_pCursorShell
; }
113 // check current MapMode of the shell and set possibly the static members.
114 // Optional set the parameters pX, pY
115 static void Get1PixelInLogic( const SwViewShell
& rSh
,
116 tools::Long
* pX
= nullptr, tools::Long
* pY
= nullptr );
118 OString
getLOKPayload(int nType
, int nViewId
, bool* ignore
) const;
121 class SW_DLLPUBLIC SwShellCursor
: public virtual SwCursor
, public SwSelPaintRects
124 // Document positions of start/end characters of a SSelection.
127 const SwPosition
* m_pInitialPoint
; // For assignment of GetPoint() to m_PointPt.
129 using SwCursor::UpDown
;
132 SwShellCursor( const SwCursorShell
& rCursorSh
, const SwPosition
&rPos
);
133 SwShellCursor( const SwCursorShell
& rCursorSh
, const SwPosition
&rPos
,
134 const Point
& rPtPos
, SwPaM
* pRing
);
135 // note: *intentionally* links the new shell cursor into the old one's Ring
136 SwShellCursor( SwShellCursor
& );
137 virtual ~SwShellCursor() override
;
139 virtual void FillRects() override
; // For Table- and normal cursors.
140 /// @see SwSelPaintRects::FillStartEnd(), override for text selections.
141 virtual void FillStartEnd(SwRect
& rStart
, SwRect
& rEnd
) const override
;
143 void Show(SfxViewShell
const * pViewShell
); // Update and display all selections.
144 void Hide(); // Hide all selections.
145 void Invalidate( const SwRect
& rRect
);
147 const Point
& GetPtPos() const { return (SwPaM::GetPoint() == m_pInitialPoint
) ? m_PointPt
: m_MarkPt
; }
148 Point
& GetPtPos() { return (SwPaM::GetPoint() == m_pInitialPoint
) ? m_PointPt
: m_MarkPt
; }
149 const Point
& GetMkPos() const { return (SwPaM::GetMark() == m_pInitialPoint
) ? m_PointPt
: m_MarkPt
; }
150 Point
& GetMkPos() { return (SwPaM::GetMark() == m_pInitialPoint
) ? m_PointPt
: m_MarkPt
; }
151 const Point
& GetSttPos() const { return (SwPaM::Start() == m_pInitialPoint
) ? m_PointPt
: m_MarkPt
; }
152 Point
& GetSttPos() { return (SwPaM::Start() == m_pInitialPoint
) ? m_PointPt
: m_MarkPt
; }
153 const Point
& GetEndPos() const { return (SwPaM::End() == m_pInitialPoint
) ? m_PointPt
: m_MarkPt
; }
154 Point
& GetEndPos() { return (SwPaM::End() == m_pInitialPoint
) ? m_PointPt
: m_MarkPt
; }
156 virtual void SetMark() override
;
158 virtual SwCursor
* Create( SwPaM
* pRing
= nullptr ) const override
;
160 virtual short MaxReplaceArived() override
; //returns RET_YES/RET_CANCEL/RET_NO
161 virtual void SaveTableBoxContent( const SwPosition
* pPos
) override
;
163 bool UpDown( bool bUp
, sal_uInt16 nCnt
);
165 // true: Cursor can be set to this position.
166 virtual bool IsAtValidPos( bool bPoint
= true ) const override
;
168 virtual bool IsReadOnlyAvailable() const override
;
170 SwShellCursor
* GetNext() { return dynamic_cast<SwShellCursor
*>(GetNextInRing()); }
171 const SwShellCursor
* GetNext() const { return dynamic_cast<SwShellCursor
const *>(GetNextInRing()); }
172 SwShellCursor
* GetPrev() { return dynamic_cast<SwShellCursor
*>(GetPrevInRing()); }
173 const SwShellCursor
* GetPrev() const { return dynamic_cast<SwShellCursor
const *>(GetPrevInRing()); }
176 class SwShellTableCursor final
: public virtual SwShellCursor
, public virtual SwTableCursor
178 /// Left edge of the selection start (top left cell).
180 /// Right edge of the selection end (bottom right cell).
182 // The Selection has the same order as the table boxes, i.e.
183 // if something is deleted from the one array at a certain position
184 // it has to be deleted from the other one as well!!
187 SwShellTableCursor( const SwCursorShell
& rCursorSh
, const SwPosition
& rPos
);
188 SwShellTableCursor( const SwCursorShell
& rCursorSh
,
189 const SwPosition
&rMkPos
, const Point
& rMkPt
,
190 const SwPosition
&rPtPos
, const Point
& rPtPt
);
191 virtual ~SwShellTableCursor() override
;
193 virtual void FillRects() override
; // For table and normal cursor.
194 /// @see SwSelPaintRects::FillStartEnd(), override for table selections.
195 virtual void FillStartEnd(SwRect
& rStart
, SwRect
& rEnd
) const override
;
197 // Check if SPoint is within table SSelection.
198 bool IsInside( const Point
& rPt
) const;
200 virtual void SetMark() override
;
201 virtual SwCursor
* Create( SwPaM
* pRing
= nullptr ) const override
;
203 virtual short MaxReplaceArived() override
; //returns RET_YES/RET_CANCEL/RET_NO
204 virtual void SaveTableBoxContent( const SwPosition
* pPos
) override
;
206 // true: Cursor can be set to this position.
207 virtual bool IsAtValidPos( bool bPoint
= true ) const override
;
209 SwShellTableCursor
* GetNext() { return dynamic_cast<SwShellTableCursor
*>(GetNextInRing()); }
210 const SwShellTableCursor
* GetNext() const { return dynamic_cast<SwShellTableCursor
const *>(GetNextInRing()); }
211 SwShellTableCursor
* GetPrev() { return dynamic_cast<SwShellTableCursor
*>(GetPrevInRing()); }
212 const SwShellTableCursor
* GetPrev() const { return dynamic_cast<SwShellTableCursor
const *>(GetPrevInRing()); }
215 #endif // INCLUDED_SW_INC_VISCRS_HXX
217 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */