LibreOffice Module vcl (master) 1
event.hxx
Go to the documentation of this file.
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
31class CommandEvent;
32
38};
39
40namespace vcl {
41 class Window;
42}
43
45{
46private:
48 sal_uInt16 mnRepeat;
50
51public:
52 KeyEvent();
53 KeyEvent( sal_Unicode nChar, const vcl::KeyCode& rKeyCode,
54 sal_uInt16 nRepeat = 0 );
55
56 sal_Unicode GetCharCode() const { return mnCharCode; }
57 const vcl::KeyCode& GetKeyCode() const { return maKeyCode; }
58 sal_uInt16 GetRepeat() const { return mnRepeat; }
59
60 KeyEvent LogicalTextDirectionality (TextDirectionality eMode) const;
61};
62
64{
65 mnCharCode = 0;
66 mnRepeat = 0;
67}
68
69inline KeyEvent::KeyEvent( sal_Unicode nChar, const vcl::KeyCode& rKeyCode,
70 sal_uInt16 nRepeat ) :
71 maKeyCode( rKeyCode )
72
73{
74 mnCharCode = nChar;
75 mnRepeat = nRepeat;
76}
77
78
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};
96namespace o3tl
97{
98 template<> struct typed_flags<MouseEventModifiers> : is_typed_flags<MouseEventModifiers, 0xff7> {};
99}
100
101// Mouse buttons
102#define MOUSE_LEFT (sal_uInt16(0x0001))
103#define MOUSE_MIDDLE (sal_uInt16(0x0002))
104#define MOUSE_RIGHT (sal_uInt16(0x0004))
105
107{
108private:
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
117public:
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 const Point& GetPosPixel() const { return maPos; }
125
126 sal_uInt16 GetClicks() const { return mnClicks; }
127
128 void setLogicPosition(Point aLogicPosition)
129 {
130 maLogicPosition = aLogicPosition;
131 }
132
133 const std::optional<Point> & getLogicPosition() const
134 {
135 return maLogicPosition;
136 }
137
138 bool IsEnterWindow() const
139 { return bool(mnMode & MouseEventModifiers::ENTERWINDOW); }
140 bool IsLeaveWindow() const
141 { return bool(mnMode & MouseEventModifiers::LEAVEWINDOW); }
142 bool IsSynthetic() const
143 { return bool(mnMode & MouseEventModifiers::SYNTHETIC); }
144 bool IsModifierChanged() const
146
147 sal_uInt16 GetButtons() const
148 { return (mnCode & (MOUSE_LEFT | MOUSE_MIDDLE | MOUSE_RIGHT)); }
149 bool IsLeft() const
150 { return ((mnCode & MOUSE_LEFT) != 0); }
151 bool IsMiddle() const
152 { return ((mnCode & MOUSE_MIDDLE) != 0); }
153 bool IsRight() const
154 { return ((mnCode & MOUSE_RIGHT) != 0); }
155
156 sal_uInt16 GetModifier() const
157 { return (mnCode & (KEY_SHIFT | KEY_MOD1 | KEY_MOD2)); }
158 bool IsShift() const
159 { return ((mnCode & KEY_SHIFT) != 0); }
160 bool IsMod1() const
161 { return ((mnCode & KEY_MOD1) != 0); }
162 bool IsMod2() const
163 { return ((mnCode & KEY_MOD2) != 0); }
164 bool IsMod3() const
165 { return ((mnCode & KEY_MOD3) != 0); }
166};
167
169{
171 mnClicks = 0;
172 mnCode = 0;
173}
174
175inline MouseEvent::MouseEvent( const Point& rPos, sal_uInt16 nClicks,
177 sal_uInt16 nButtons, sal_uInt16 nModifier ) :
178 maPos( rPos )
179{
180 mnClicks = nClicks;
181 mnMode = nMode;
182 mnCode = nButtons | nModifier;
183}
184
186{
187 NONE = 0x0000,
188 CONTEXT = 0x0001,
189 BALLOON = 0x0002,
190 QUICK = 0x0004
191};
192namespace o3tl
193{
194 template<> struct typed_flags<HelpEventMode> : is_typed_flags<HelpEventMode, 0x07> {};
195}
196
198{
199private:
203
204public:
205 explicit HelpEvent( const Point& rMousePos, HelpEventMode nHelpMode );
206
207 const Point& GetMousePosPixel() const { return maPos; }
208 HelpEventMode GetMode() const { return mnMode; }
209 bool KeyboardActivated() const { return mbKeyboardActivated; }
210 void SetKeyboardActivated( bool bKeyboard ) { mbKeyboardActivated = bKeyboard; }
211};
212
213inline HelpEvent::HelpEvent( const Point& rMousePos, HelpEventMode nHelpMode ) :
214 maPos( rMousePos )
215{
216 mnMode = nHelpMode;
217 mbKeyboardActivated = false;
218}
219
222{
223private:
226
228 sal_uInt16 mnItemId;
230
231public:
233 const tools::Rectangle& rOutRect, sal_uInt16 nId, bool bSelected = false)
234 : mpRenderContext(pRenderContext)
235 , maOutRect( rOutRect )
236 , mnItemId(nId)
237 , mbSelected(bSelected)
238 {
239 }
240
241 vcl::RenderContext* GetRenderContext() const { return mpRenderContext; }
242 const tools::Rectangle& GetRect() const { return maOutRect; }
243 sal_uInt16 GetItemId() const { return mnItemId; }
244 bool IsSelected() const { return mbSelected; }
245};
246
248{
249private:
252
253public:
254 explicit TrackingEvent( const MouseEvent&,
256
257 const MouseEvent& GetMouseEvent() const { return maMEvt; }
258
259 bool IsTrackingRepeat() const
260 { return bool(mnFlags & TrackingEventFlags::Repeat); }
261 bool IsTrackingEnded() const
262 { return bool(mnFlags & TrackingEventFlags::End); }
264 { return bool(mnFlags & TrackingEventFlags::Cancel); }
265};
266
268 TrackingEventFlags nTrackFlags ) :
269 maMEvt( rMEvt )
270{
271 mnFlags = nTrackFlags;
272}
273
274
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
289{
290private:
292 void* mpData;
294
295public:
296 NotifyEvent( NotifyEventType nEventType,
297 vcl::Window* pWindow,
298 const void* pEvent = nullptr );
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;
307
308 NotifyEventType GetType() const { return mnEventType; }
309 vcl::Window* GetWindow() const { return mpWindow; }
310 void* GetData() const { return mpData; }
311 const KeyEvent* GetKeyEvent() const;
312 const MouseEvent* GetMouseEvent() const;
313 const CommandEvent* GetCommandEvent() const;
314};
315
317{
319 return static_cast<const KeyEvent*>(mpData);
320 else
321 return nullptr;
322}
323
325{
327 return static_cast<const MouseEvent*>(mpData);
328 else
329 return nullptr;
330}
331
333{
335 return static_cast<const CommandEvent*>(mpData);
336 else
337 return nullptr;
338}
339
340
342 NONE = 0,
343 SETTINGS = 1,
344 DISPLAY = 2,
345 FONTS = 4,
346 PRINTER = 5,
348};
349
351{
352private:
353 void* mpData;
356
357public:
359 const void* pData = nullptr,
361
364
365 const AllSettings* GetOldSettings() const;
366};
367
369 const void* pData,
370 AllSettingsFlags nChangeFlags )
371{
372 mpData = const_cast<void*>(pData);
373 mnFlags = nChangeFlags;
374 mnType = nType;
375}
376
378{
380 return static_cast<const AllSettings*>(mpData);
381 else
382 return nullptr;
383}
384
385#endif // INCLUDED_VCL_EVENT_HXX
386
387/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
AllSettingsFlags mnFlags
Definition: event.hxx:354
DataChangedEventType GetType() const
Definition: event.hxx:362
DataChangedEvent(DataChangedEventType nType, const void *pData=nullptr, AllSettingsFlags nFlags=AllSettingsFlags::NONE)
Definition: event.hxx:368
AllSettingsFlags GetFlags() const
Definition: event.hxx:363
void * mpData
Definition: event.hxx:353
DataChangedEventType mnType
Definition: event.hxx:355
const AllSettings * GetOldSettings() const
Definition: event.hxx:377
HelpEvent(const Point &rMousePos, HelpEventMode nHelpMode)
Definition: event.hxx:213
bool mbKeyboardActivated
Definition: event.hxx:202
HelpEventMode mnMode
Definition: event.hxx:201
Point maPos
Definition: event.hxx:200
void SetKeyboardActivated(bool bKeyboard)
Definition: event.hxx:210
HelpEventMode GetMode() const
Definition: event.hxx:208
bool KeyboardActivated() const
Definition: event.hxx:209
const Point & GetMousePosPixel() const
Definition: event.hxx:207
vcl::KeyCode maKeyCode
Definition: event.hxx:47
sal_Unicode GetCharCode() const
Definition: event.hxx:56
sal_uInt16 mnRepeat
Definition: event.hxx:48
const vcl::KeyCode & GetKeyCode() const
Definition: event.hxx:57
sal_uInt16 GetRepeat() const
Definition: event.hxx:58
KeyEvent()
Definition: event.hxx:63
sal_Unicode mnCharCode
Definition: event.hxx:49
bool IsMod1() const
Definition: event.hxx:160
bool IsEnterWindow() const
Definition: event.hxx:138
MouseEventModifiers GetMode() const
Definition: event.hxx:124
sal_uInt16 mnCode
Definition: event.hxx:112
MouseEventModifiers mnMode
Definition: event.hxx:110
std::optional< Point > maLogicPosition
Definition: event.hxx:115
bool IsMod3() const
Definition: event.hxx:164
const std::optional< Point > & getLogicPosition() const
Definition: event.hxx:133
bool IsSynthetic() const
Definition: event.hxx:142
bool IsMod2() const
Definition: event.hxx:162
bool IsLeaveWindow() const
Definition: event.hxx:140
sal_uInt16 GetModifier() const
Definition: event.hxx:156
sal_uInt16 GetClicks() const
Definition: event.hxx:126
bool IsRight() const
Definition: event.hxx:153
Point maPos
Definition: event.hxx:109
sal_uInt16 GetButtons() const
Definition: event.hxx:147
sal_uInt16 mnClicks
Definition: event.hxx:111
MouseEvent()
Definition: event.hxx:168
const Point & GetPosPixel() const
Definition: event.hxx:123
bool IsMiddle() const
Definition: event.hxx:151
bool IsModifierChanged() const
Definition: event.hxx:144
bool IsLeft() const
Definition: event.hxx:149
void setLogicPosition(Point aLogicPosition)
Definition: event.hxx:128
bool IsShift() const
Definition: event.hxx:158
const KeyEvent * GetKeyEvent() const
Definition: event.hxx:316
vcl::Window * GetWindow() const
Definition: event.hxx:309
const CommandEvent * GetCommandEvent() const
Definition: event.hxx:332
void * GetData() const
Definition: event.hxx:310
const MouseEvent * GetMouseEvent() const
Definition: event.hxx:324
NotifyEvent(const NotifyEvent &)=delete
NotifyEventType mnEventType
Definition: event.hxx:293
NotifyEvent & operator=(NotifyEvent &&)=delete
NotifyEvent & operator=(const NotifyEvent &)=delete
void * mpData
Definition: event.hxx:292
NotifyEvent(NotifyEvent &&)=delete
VclPtr< vcl::Window > mpWindow
Definition: event.hxx:291
NotifyEventType GetType() const
Definition: event.hxx:308
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:170
bool IsTrackingEnded() const
Definition: event.hxx:261
TrackingEvent(const MouseEvent &, TrackingEventFlags nTrackFlags=TrackingEventFlags::NONE)
Definition: event.hxx:267
TrackingEventFlags mnFlags
Definition: event.hxx:251
bool IsTrackingRepeat() const
Definition: event.hxx:259
MouseEvent maMEvt
Definition: event.hxx:250
bool IsTrackingCanceled() const
Definition: event.hxx:263
const MouseEvent & GetMouseEvent() const
Definition: event.hxx:257
Event to pass information for UserDraw() handling eg. in comboboxes.
Definition: event.hxx:222
tools::Rectangle maOutRect
Definition: event.hxx:227
UserDrawEvent(vcl::RenderContext *pRenderContext, const tools::Rectangle &rOutRect, sal_uInt16 nId, bool bSelected=false)
Definition: event.hxx:232
bool mbSelected
Definition: event.hxx:229
vcl::RenderContext * GetRenderContext() const
Definition: event.hxx:241
sal_uInt16 mnItemId
Definition: event.hxx:228
bool IsSelected() const
Definition: event.hxx:244
const tools::Rectangle & GetRect() const
Definition: event.hxx:242
VclPtr< vcl::RenderContext > mpRenderContext
RenderContext to which we should draw - can be a VirtualDevice or anything.
Definition: event.hxx:225
sal_uInt16 GetItemId() const
Definition: event.hxx:243
A thin wrapper around rtl::Reference to implement the acquire and dispose semantics we want for refer...
Definition: vclptr.hxx:58
sal_Int16 mnMode
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
#define MOUSE_LEFT
Definition: event.hxx:102
#define MOUSE_MIDDLE
Definition: event.hxx:103
#define MOUSE_RIGHT
Definition: event.hxx:104
NotifyEventType
Definition: event.hxx:276
DataChangedEventType
Definition: event.hxx:341
TextDirectionality
Definition: event.hxx:33
MouseEventModifiers
Definition: event.hxx:80
HelpEventMode
Definition: event.hxx:186
FuncFlags mnFlags
constexpr sal_uInt16 KEY_MOD2
Definition: keycodes.hxx:32
constexpr sal_uInt16 KEY_MOD1
Definition: keycodes.hxx:31
constexpr sal_uInt16 KEY_MOD3
Definition: keycodes.hxx:33
constexpr sal_uInt16 KEY_SHIFT
Definition: keycodes.hxx:30
std::unique_ptr< sal_Int32[]> pData
NONE
sal_Int16 nId
QPRO_FUNC_TYPE nType
sal_Int32 mnType
AllSettingsFlags
Definition: settings.hxx:682
SELECT
sal_uInt16 sal_Unicode
TrackingEventFlags
Definition: vclenum.hxx:358
VclPtr< vcl::Window > mpWindow