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