Coverage Report

Created: 2026-10-14 09:33

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sw/inc/viscrs.hxx
Line
Count
Source
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 <config_collab.h>
22
#include <config_feature_desktop.h>
23
24
#include <vcl/cursor.hxx>
25
#include "swcrsr.hxx"
26
#include "swrect.hxx"
27
#include "swregion.hxx"
28
#include "swdllapi.h"
29
30
#include <optional>
31
32
namespace sdr::overlay { class OverlaySelection; }
33
34
namespace sw { struct VisibleCursorState; }
35
class SwCursorShell;
36
class SfxViewShell;
37
class SwContentControlButton;
38
39
// From here classes/methods for non-text cursor.
40
41
class SW_DLLPUBLIC SwVisibleCursor
42
{
43
    friend void InitCore();
44
    friend void FinitCore();
45
46
    ::sw::VisibleCursorState const& m_rState;
47
    const SwCursorShell* m_pCursorShell;
48
    vcl::Cursor m_aTextCursor;
49
50
    /// For LibreOfficeKit only - remember what page we were at the last time.
51
    sal_uInt16 m_nPageLastTime;
52
    SwRect m_aLastLOKRect;
53
54
    bool m_bIsVisible;
55
    bool m_bIsDragCursor;
56
57
public:
58
    SwVisibleCursor(::sw::VisibleCursorState const& rState, const SwCursorShell * pCShell);
59
    ~SwVisibleCursor();
60
61
    void Show();
62
    void Hide();
63
64
9.04k
    bool IsVisible() const { return m_bIsVisible; }
65
0
    void SetDragCursor( bool bFlag = true ) { m_bIsDragCursor = bFlag; }
66
    SwRect SetPos();
67
    void SetPosAndShow(SfxViewShell const * pViewShell);
68
    const vcl::Cursor& GetTextCursor() const;
69
70
    std::optional<OString> getLOKPayload(int nType, int nViewId) const;
71
72
#if ENABLE_YRS
73
    ::std::optional<OUString> m_Author;
74
#endif
75
};
76
77
// From here classes/methods for selections.
78
79
namespace sw::overlay { class OverlayRangesOutline; }
80
class MapMode;
81
82
/**
83
 * SwSelPaintRects is a base class of SwShellCursor, which stores the overlay for the
84
 * cursor/selection: a list of rectangles to be painted as an overlay. It is also capable of
85
 * painting other overlays as needed (text input, content control).
86
 */
87
class SwSelPaintRects : public SwRects
88
{
89
    friend void InitCore();
90
    friend void FinitCore();
91
92
    static tools::Long s_nPixPtX, s_nPixPtY;
93
    static MapMode *s_pMapMode;
94
95
    const SwCursorShell* m_pCursorShell;
96
97
#if HAVE_FEATURE_DESKTOP || defined(ANDROID)
98
    std::unique_ptr<sdr::overlay::OverlaySelection> m_pCursorOverlay;
99
#endif
100
101
    bool m_bShowTextInputFieldOverlay;
102
    std::unique_ptr<sw::overlay::OverlayRangesOutline> m_pTextInputFieldOverlay;
103
    bool m_bShowContentControlOverlay;
104
    std::unique_ptr<sw::overlay::OverlayRangesOutline> m_pContentControlOverlay;
105
    VclPtr<SwContentControlButton> m_pContentControlButton;
106
107
    void HighlightInputField();
108
    void HighlightContentControl();
109
110
public:
111
    SwSelPaintRects( const SwCursorShell& rCSh );
112
    virtual ~SwSelPaintRects();
113
114
    virtual void FillRects() = 0;
115
    /// Fill rStart and rEnd with a rectangle that represents the start and end for selection handles.
116
    virtual void FillStartEnd(SwRect& rStart, SwRect& rEnd) const = 0;
117
118
    // #i75172# in SwCursorShell::CreateCursor() the content of SwSelPaintRects is exchanged. To
119
    // make a complete swap access to m_pCursorOverlay is needed there
120
    void swapContent(SwSelPaintRects& rSwap);
121
122
    void Show(std::vector<OString>* pSelectionRectangles = nullptr);
123
    void Hide();
124
    void Invalidate( const SwRect& rRect );
125
126
    void SetShowTextInputFieldOverlay( const bool bShow )
127
0
    {
128
0
        m_bShowTextInputFieldOverlay = bShow;
129
0
    }
130
131
0
    void SetShowContentControlOverlay(const bool bShow) { m_bShowContentControlOverlay = bShow; }
132
133
    const VclPtr<SwContentControlButton>& GetContentControlButton() const;
134
135
52.8k
    const SwCursorShell* GetShell() const { return m_pCursorShell; }
136
    // check current MapMode of the shell and set possibly the static members.
137
    // Optional set the parameters pX, pY
138
    static void Get1PixelInLogic( const SwViewShell& rSh,
139
                                    tools::Long* pX = nullptr, tools::Long* pY = nullptr );
140
141
    std::optional<OString> getLOKPayload(int nType) const;
142
};
143
144
/// Represents the current text cursor of one opened edit window.
145
///
146
/// See SwShellTableCursor for a table cursor that extends this class.
147
class SW_DLLPUBLIC SwShellCursor : public virtual SwCursor, public SwSelPaintRects
148
{
149
private:
150
    // Document positions of start/end characters of a SSelection.
151
    Point m_MarkPt;
152
    Point m_PointPt;
153
    const SwPosition* m_pInitialPoint; // For assignment of GetPoint() to m_PointPt.
154
155
    using SwCursor::UpDown;
156
157
public:
158
    SwShellCursor( const SwCursorShell& rCursorSh, const SwPosition &rPos );
159
    SwShellCursor( const SwCursorShell& rCursorSh, const SwPosition &rPos,
160
                    const Point& rPtPos, SwPaM* pRing );
161
    // note: *intentionally* links the new shell cursor into the old one's Ring
162
    SwShellCursor( SwShellCursor& );
163
    virtual ~SwShellCursor() override;
164
165
    virtual void FillRects() override;   // For Table- and normal cursors.
166
    /// @see SwSelPaintRects::FillStartEnd(), override for text selections.
167
    virtual void FillStartEnd(SwRect& rStart, SwRect& rEnd) const override;
168
169
    void Show(SfxViewShell const * pViewShell); // Update and display all selections.
170
    void Hide();            // Hide all selections.
171
    void Invalidate( const SwRect& rRect );
172
173
0
    const Point& GetPtPos() const   { return (SwPaM::GetPoint() == m_pInitialPoint) ? m_PointPt : m_MarkPt; }
174
536k
          Point& GetPtPos()         { return (SwPaM::GetPoint() == m_pInitialPoint) ? m_PointPt : m_MarkPt; }
175
0
    const Point& GetMkPos() const   { return (SwPaM::GetMark() == m_pInitialPoint) ? m_PointPt : m_MarkPt; }
176
771
          Point& GetMkPos()         { return (SwPaM::GetMark() == m_pInitialPoint) ? m_PointPt : m_MarkPt; }
177
2.32k
    const Point& GetSttPos() const  { return (SwPaM::Start() == m_pInitialPoint) ? m_PointPt : m_MarkPt; }
178
4
          Point& GetSttPos()        { return (SwPaM::Start() == m_pInitialPoint) ? m_PointPt : m_MarkPt; }
179
2.32k
    const Point& GetEndPos() const  { return (SwPaM::End() == m_pInitialPoint) ? m_PointPt : m_MarkPt; }
180
0
          Point& GetEndPos()        { return (SwPaM::End() == m_pInitialPoint) ? m_PointPt : m_MarkPt; }
181
182
    virtual void SetMark() override;
183
184
    virtual SwCursor* Create( SwPaM* pRing = nullptr ) const override;
185
186
    virtual short MaxReplaceArived() override; //returns RET_YES/RET_CANCEL/RET_NO
187
    virtual void SaveTableBoxContent( const SwPosition* pPos ) override;
188
189
    bool UpDown( bool bUp, sal_uInt16 nCnt );
190
191
    // true: Cursor can be set to this position.
192
    virtual bool IsAtValidPos( bool bPoint = true ) const override;
193
194
    virtual bool IsReadOnlyAvailable() const override;
195
196
35.4k
    SwShellCursor* GetNext()             { return dynamic_cast<SwShellCursor *>(GetNextInRing()); }
197
0
    const SwShellCursor* GetNext() const { return dynamic_cast<SwShellCursor const *>(GetNextInRing()); }
198
0
    SwShellCursor* GetPrev()             { return dynamic_cast<SwShellCursor *>(GetPrevInRing()); }
199
0
    const SwShellCursor* GetPrev() const { return dynamic_cast<SwShellCursor const *>(GetPrevInRing()); }
200
};
201
202
class SwShellTableCursor final : public virtual SwShellCursor, public virtual SwTableCursor
203
{
204
    /// Left edge of the selection start (top left cell).
205
    SwRect m_aStart;
206
    /// Right edge of the selection end (bottom right cell).
207
    SwRect m_aEnd;
208
    // The Selection has the same order as the table boxes, i.e.
209
    // if something is deleted from the one array at a certain position
210
    // it has to be deleted from the other one as well!!
211
212
public:
213
    SwShellTableCursor( const SwCursorShell& rCursorSh, const SwPosition& rPos );
214
    SwShellTableCursor( const SwCursorShell& rCursorSh,
215
                    const SwPosition &rMkPos, const Point& rMkPt,
216
                    const SwPosition &rPtPos, const Point& rPtPt );
217
    virtual ~SwShellTableCursor() override;
218
219
    virtual void FillRects() override;   // For table and normal cursor.
220
    /// @see SwSelPaintRects::FillStartEnd(), override for table selections.
221
    virtual void FillStartEnd(SwRect& rStart, SwRect& rEnd) const override;
222
223
    // Check if SPoint is within table SSelection.
224
    bool Contains( const Point& rPt ) const;
225
226
    virtual void SetMark() override;
227
    virtual SwCursor* Create( SwPaM* pRing = nullptr ) const override;
228
229
    virtual short MaxReplaceArived() override; //returns RET_YES/RET_CANCEL/RET_NO
230
    virtual void SaveTableBoxContent( const SwPosition* pPos ) override;
231
232
    // true: Cursor can be set to this position.
233
    virtual bool IsAtValidPos( bool bPoint = true ) const override;
234
235
0
    SwShellTableCursor* GetNext()             { return dynamic_cast<SwShellTableCursor *>(GetNextInRing()); }
236
0
    const SwShellTableCursor* GetNext() const { return dynamic_cast<SwShellTableCursor const *>(GetNextInRing()); }
237
0
    SwShellTableCursor* GetPrev()             { return dynamic_cast<SwShellTableCursor *>(GetPrevInRing()); }
238
0
    const SwShellTableCursor* GetPrev() const { return dynamic_cast<SwShellTableCursor const *>(GetPrevInRing()); }
239
};
240
241
242
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */