Coverage Report

Created: 2026-07-10 11:04

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