Coverage Report

Created: 2025-12-08 09:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/include/vcl/event.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
20
#ifndef INCLUDED_VCL_EVENT_HXX
21
#define INCLUDED_VCL_EVENT_HXX
22
23
#include <vcl/dllapi.h>
24
#include <tools/gen.hxx>
25
#include <vcl/keycod.hxx>
26
#include <vcl/settings.hxx>
27
#include <vcl/vclptr.hxx>
28
#include <vcl/outdev.hxx>
29
#include <optional>
30
31
class CommandEvent;
32
33
enum class TextDirectionality {
34
    LeftToRight_TopToBottom,
35
    RightToLeft_TopToBottom,
36
    TopToBottom_RightToLeft,
37
    BottomToTop_LeftToRight
38
};
39
40
namespace vcl {
41
    class Window;
42
}
43
44
class VCL_DLLPUBLIC KeyEvent
45
{
46
private:
47
    vcl::KeyCode    maKeyCode;
48
    sal_uInt16      mnRepeat;
49
    sal_Unicode     mnCharCode;
50
51
public:
52
                    KeyEvent();
53
                    KeyEvent( sal_Unicode nChar, const vcl::KeyCode& rKeyCode,
54
                              sal_uInt16 nRepeat = 0 );
55
56
0
    sal_Unicode         GetCharCode() const     { return mnCharCode; }
57
0
    const vcl::KeyCode& GetKeyCode() const      { return maKeyCode;  }
58
0
    sal_uInt16          GetRepeat() const       { return mnRepeat;   }
59
60
    KeyEvent        LogicalTextDirectionality (TextDirectionality eMode) const;
61
};
62
63
inline KeyEvent::KeyEvent()
64
0
{
65
0
    mnCharCode  = 0;
66
0
    mnRepeat    = 0;
67
0
}
68
69
inline KeyEvent::KeyEvent( sal_Unicode nChar, const vcl::KeyCode& rKeyCode,
70
                           sal_uInt16 nRepeat ) :
71
0
            maKeyCode( rKeyCode )
72
73
0
{
74
0
    mnCharCode  = nChar;
75
0
    mnRepeat    = nRepeat;
76
0
}
77
78
79
enum class MouseEventModifiers
80
{
81
   NONE              = 0,
82
   // mouse move modifiers
83
   SIMPLEMOVE        = 0x0001,
84
   DRAGMOVE          = 0x0002,
85
   DRAGCOPY          = 0x0004,
86
   ENTERWINDOW       = 0x0010,
87
   LEAVEWINDOW       = 0x0020,
88
   SYNTHETIC         = 0x0040,
89
   MODIFIERCHANGED   = 0x0080,
90
   // mouse up/down-button modifiers
91
   SIMPLECLICK       = 0x0100,
92
   SELECT            = 0x0200,
93
   MULTISELECT       = 0x0400,
94
   RANGESELECT       = 0x0800
95
};
96
namespace o3tl
97
{
98
    template<> struct typed_flags<MouseEventModifiers> : is_typed_flags<MouseEventModifiers, 0xff7> {};
99
}
100
101
// Mouse buttons
102
0
#define MOUSE_LEFT              (sal_uInt16(0x0001))
103
0
#define MOUSE_MIDDLE            (sal_uInt16(0x0002))
104
0
#define MOUSE_RIGHT             (sal_uInt16(0x0004))
105
106
class VCL_DLLPUBLIC MouseEvent
107
{
108
private:
109
    Point               maPos;
110
    MouseEventModifiers mnMode;
111
    sal_uInt16          mnClicks;
112
    sal_uInt16          mnCode;
113
114
    // Set, if the document relative logic position are available
115
    std::optional<Point> maLogicPosition;
116
117
public:
118
    explicit        MouseEvent();
119
    explicit        MouseEvent( const Point& rPos, sal_uInt16 nClicks = 1,
120
                                MouseEventModifiers nMode = MouseEventModifiers::NONE, sal_uInt16 nButtons = 0,
121
                                sal_uInt16 nModifier = 0 );
122
123
0
    const Point&    GetPosPixel() const     { return maPos; }
124
0
    MouseEventModifiers GetMode() const         { return mnMode; }
125
126
0
    sal_uInt16      GetClicks() const       { return mnClicks; }
127
128
    void setLogicPosition(Point aLogicPosition)
129
0
    {
130
0
        maLogicPosition = aLogicPosition;
131
0
    }
132
133
    const std::optional<Point> & getLogicPosition() const
134
0
    {
135
0
        return maLogicPosition;
136
0
    }
137
138
    bool            IsEnterWindow() const
139
0
                        { return bool(mnMode & MouseEventModifiers::ENTERWINDOW); }
140
    bool            IsLeaveWindow() const
141
0
                        { return bool(mnMode & MouseEventModifiers::LEAVEWINDOW); }
142
    bool            IsSynthetic() const
143
0
                        { return bool(mnMode & MouseEventModifiers::SYNTHETIC); }
144
    bool            IsModifierChanged() const
145
0
                        { return bool(mnMode & MouseEventModifiers::MODIFIERCHANGED); }
146
147
    sal_uInt16      GetButtons() const
148
0
                        { return (mnCode & (MOUSE_LEFT | MOUSE_MIDDLE | MOUSE_RIGHT)); }
149
    bool            IsLeft() const
150
0
                        { return ((mnCode & MOUSE_LEFT) != 0); }
151
    bool            IsMiddle() const
152
0
                        { return ((mnCode & MOUSE_MIDDLE) != 0); }
153
    bool            IsRight() const
154
0
                        { return ((mnCode & MOUSE_RIGHT) != 0); }
155
156
    sal_uInt16      GetModifier() const
157
0
                        { return (mnCode & (KEY_SHIFT | KEY_MOD1 | KEY_MOD2)); }
158
    bool            IsShift() const
159
0
                        { return ((mnCode & KEY_SHIFT) != 0); }
160
    bool            IsMod1() const
161
0
                        { return ((mnCode & KEY_MOD1) != 0); }
162
    bool            IsMod2() const
163
0
                        { return ((mnCode & KEY_MOD2) != 0); }
164
    bool            IsMod3() const
165
0
                        { return ((mnCode & KEY_MOD3) != 0); }
166
};
167
168
inline MouseEvent::MouseEvent()
169
1.29M
{
170
1.29M
    mnMode      = MouseEventModifiers::NONE;
171
1.29M
    mnClicks    = 0;
172
1.29M
    mnCode      = 0;
173
1.29M
}
174
175
inline MouseEvent::MouseEvent( const Point& rPos, sal_uInt16 nClicks,
176
                               MouseEventModifiers nMode,
177
                               sal_uInt16 nButtons, sal_uInt16 nModifier ) :
178
0
            maPos( rPos )
179
0
{
180
0
    mnClicks    = nClicks;
181
0
    mnMode      = nMode;
182
0
    mnCode      = nButtons | nModifier;
183
0
}
184
185
enum class HelpEventMode
186
{
187
    NONE           = 0x0000,
188
    CONTEXT        = 0x0001,
189
    BALLOON        = 0x0002,
190
    QUICK          = 0x0004
191
};
192
namespace o3tl
193
{
194
    template<> struct typed_flags<HelpEventMode> : is_typed_flags<HelpEventMode, 0x07> {};
195
}
196
197
class VCL_DLLPUBLIC HelpEvent
198
{
199
private:
200
    Point           maPos;
201
    HelpEventMode   mnMode;
202
    bool            mbKeyboardActivated;
203
204
public:
205
    explicit        HelpEvent( const Point& rMousePos, HelpEventMode nHelpMode );
206
207
0
    const Point&    GetMousePosPixel() const { return maPos; }
208
0
    HelpEventMode   GetMode() const { return mnMode; }
209
0
    bool            KeyboardActivated() const { return mbKeyboardActivated; }
210
0
    void            SetKeyboardActivated( bool bKeyboard ) { mbKeyboardActivated = bKeyboard; }
211
};
212
213
inline HelpEvent::HelpEvent( const Point& rMousePos, HelpEventMode nHelpMode ) :
214
0
            maPos( rMousePos )
215
0
{
216
0
    mnMode  = nHelpMode;
217
0
    mbKeyboardActivated = false;
218
0
}
219
220
/// Event to pass information for UserDraw() handling eg. in comboboxes.
221
class VCL_DLLPUBLIC UserDrawEvent
222
{
223
private:
224
    /// RenderContext to which we should draw - can be a VirtualDevice or anything.
225
    VclPtr<vcl::RenderContext> mpRenderContext;
226
227
    tools::Rectangle    maOutRect;
228
    sal_uInt16          mnItemId;
229
    bool                mbSelected;
230
231
public:
232
    UserDrawEvent(vcl::RenderContext* pRenderContext,
233
                  const tools::Rectangle& rOutRect, sal_uInt16 nId, bool bSelected = false)
234
0
        : mpRenderContext(pRenderContext)
235
0
        , maOutRect( rOutRect )
236
0
        , mnItemId(nId)
237
0
        , mbSelected(bSelected)
238
0
    {
239
0
    }
240
241
0
    vcl::RenderContext* GetRenderContext() const { return mpRenderContext; }
242
0
    const tools::Rectangle&    GetRect() const { return maOutRect; }
243
0
    sal_uInt16          GetItemId() const { return mnItemId; }
244
0
    bool                IsSelected() const { return mbSelected; }
245
};
246
247
class VCL_DLLPUBLIC TrackingEvent
248
{
249
private:
250
    MouseEvent          maMEvt;
251
    TrackingEventFlags  mnFlags;
252
253
public:
254
    explicit            TrackingEvent( const MouseEvent&,
255
                                       TrackingEventFlags nTrackFlags = TrackingEventFlags::NONE );
256
257
0
    const MouseEvent&   GetMouseEvent() const { return maMEvt; }
258
259
    bool                IsTrackingRepeat() const
260
0
                            { return bool(mnFlags & TrackingEventFlags::Repeat); }
261
    bool                IsTrackingEnded() const
262
0
                            { return bool(mnFlags & TrackingEventFlags::End); }
263
    bool                IsTrackingCanceled() const
264
0
                            { return bool(mnFlags & TrackingEventFlags::Cancel); }
265
};
266
267
inline TrackingEvent::TrackingEvent( const MouseEvent& rMEvt,
268
                                     TrackingEventFlags nTrackFlags ) :
269
0
            maMEvt( rMEvt )
270
0
{
271
0
    mnFlags = nTrackFlags;
272
0
}
273
274
275
enum class NotifyEventType
276
{
277
    NONE             = 0,
278
    MOUSEBUTTONDOWN  = 1,
279
    MOUSEBUTTONUP    = 2,
280
    MOUSEMOVE        = 3,
281
    KEYINPUT         = 4,
282
    KEYUP            = 5,
283
    GETFOCUS         = 6,
284
    LOSEFOCUS        = 7,
285
    COMMAND          = 8
286
};
287
288
class VCL_DLLPUBLIC NotifyEvent
289
{
290
private:
291
    VclPtr<vcl::Window>     mpWindow;
292
    void*                   mpData;
293
    NotifyEventType        mnEventType;
294
295
public:
296
                            NotifyEvent( NotifyEventType nEventType,
297
                                         vcl::Window* pWindow,
298
                                         const void* pEvent = nullptr );
299
                            ~NotifyEvent();
300
                            // Avoid implicitly defined copy constructors/assignments for the
301
                            // DLLPUBLIC class (they may require forward-declared classes used
302
                            // internally to be defined in places using NotifyEvent)
303
                            NotifyEvent(const NotifyEvent&) = delete;
304
                            NotifyEvent(NotifyEvent&&) = delete;
305
                            NotifyEvent& operator=(const NotifyEvent&) = delete;
306
                            NotifyEvent& operator=(NotifyEvent&&) = delete;
307
308
0
    NotifyEventType        GetType() const { return mnEventType; }
309
0
    vcl::Window*            GetWindow() const { return mpWindow; }
310
0
    void*                   GetData() const { return mpData; }
311
    const KeyEvent*         GetKeyEvent() const;
312
    const MouseEvent*       GetMouseEvent() const;
313
    const CommandEvent*     GetCommandEvent() const;
314
};
315
316
inline const KeyEvent* NotifyEvent::GetKeyEvent() const
317
0
{
318
0
    if ( (mnEventType == NotifyEventType::KEYINPUT) || (mnEventType == NotifyEventType::KEYUP) )
319
0
        return static_cast<const KeyEvent*>(mpData);
320
0
    else
321
0
        return nullptr;
322
0
}
323
324
inline const MouseEvent* NotifyEvent::GetMouseEvent() const
325
0
{
326
0
    if ( (mnEventType >= NotifyEventType::MOUSEBUTTONDOWN) && (mnEventType <= NotifyEventType::MOUSEMOVE) )
327
0
        return static_cast<const MouseEvent*>(mpData);
328
0
    else
329
0
        return nullptr;
330
0
}
331
332
inline const CommandEvent* NotifyEvent::GetCommandEvent() const
333
0
{
334
0
    if ( mnEventType == NotifyEventType::COMMAND )
335
0
        return static_cast<const CommandEvent*>(mpData);
336
0
    else
337
0
        return nullptr;
338
0
}
339
340
341
enum class DataChangedEventType {
342
    NONE               = 0,
343
    SETTINGS           = 1,
344
    DISPLAY            = 2,
345
    FONTS              = 4,
346
    PRINTER            = 5,
347
    FONTSUBSTITUTION   = 6
348
};
349
350
class VCL_DLLPUBLIC DataChangedEvent
351
{
352
private:
353
    const AllSettings*      mpData;
354
    AllSettingsFlags        mnFlags;
355
    DataChangedEventType    mnType;
356
357
public:
358
    explicit                DataChangedEvent( DataChangedEventType nType,
359
                                              const AllSettings* pData = nullptr,
360
                                              AllSettingsFlags nFlags = AllSettingsFlags::NONE );
361
362
6
    DataChangedEventType    GetType() const { return mnType; }
363
2
    AllSettingsFlags        GetFlags() const { return mnFlags; }
364
365
    const AllSettings*      GetOldSettings() const;
366
};
367
368
inline DataChangedEvent::DataChangedEvent( DataChangedEventType nType,
369
                                           const AllSettings* pData,
370
                                           AllSettingsFlags nChangeFlags )
371
2
{
372
2
    mpData  = pData;
373
2
    mnFlags = nChangeFlags;
374
2
    mnType  = nType;
375
2
}
376
377
inline const AllSettings* DataChangedEvent::GetOldSettings() const
378
0
{
379
0
    if ( mnType == DataChangedEventType::SETTINGS )
380
0
        return mpData;
381
0
    else
382
0
        return nullptr;
383
0
}
384
385
#endif // INCLUDED_VCL_EVENT_HXX
386
387
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */