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;
230 
231 public:
232  UserDrawEvent(vcl::Window* pWindow, vcl::RenderContext* pRenderContext,
233  const tools::Rectangle& rOutRect, sal_uInt16 nId, bool bSelected = false)
234  : mpWindow(pWindow)
235  , mpRenderContext(pRenderContext)
236  , maOutRect( rOutRect )
237  , mnItemId(nId)
238  , mbSelected(bSelected)
239  {
240  }
241 
242  vcl::Window* GetWindow() const { return mpWindow; }
243  vcl::RenderContext* GetRenderContext() const { return mpRenderContext; }
244  const tools::Rectangle& GetRect() const { return maOutRect; }
245  sal_uInt16 GetItemId() const { return mnItemId; }
246  bool IsSelected() const { return mbSelected; }
247 };
248 
250 {
251 private:
254 
255 public:
256  explicit TrackingEvent( const MouseEvent&,
258 
259  const MouseEvent& GetMouseEvent() const { return maMEvt; }
260 
261  bool IsTrackingRepeat() const
262  { return bool(mnFlags & TrackingEventFlags::Repeat); }
263  bool IsTrackingEnded() const
264  { return bool(mnFlags & TrackingEventFlags::End); }
265  bool IsTrackingCanceled() const
266  { return bool(mnFlags & TrackingEventFlags::Cancel); }
267 };
268 
270  TrackingEventFlags nTrackFlags ) :
271  maMEvt( rMEvt )
272 {
273  mnFlags = nTrackFlags;
274 }
275 
276 
278 {
279  NONE = 0,
280  MOUSEBUTTONDOWN = 1,
281  MOUSEBUTTONUP = 2,
282  MOUSEMOVE = 3,
283  KEYINPUT = 4,
284  KEYUP = 5,
285  GETFOCUS = 6,
286  LOSEFOCUS = 7,
287  COMMAND = 8,
288  INPUTENABLE = 10
289 };
290 
292 {
293 private:
295  void* mpData;
297 
298 public:
299  NotifyEvent( MouseNotifyEvent nEventType,
300  vcl::Window* pWindow,
301  const void* pEvent = nullptr );
302 
303  MouseNotifyEvent GetType() const { return mnEventType; }
304  vcl::Window* GetWindow() const { return mpWindow; }
305  void* GetData() const { return mpData; }
306  const KeyEvent* GetKeyEvent() const;
307  const MouseEvent* GetMouseEvent() const;
308  const CommandEvent* GetCommandEvent() const;
309 };
310 
311 inline const KeyEvent* NotifyEvent::GetKeyEvent() const
312 {
314  return static_cast<const KeyEvent*>(mpData);
315  else
316  return nullptr;
317 }
318 
320 {
322  return static_cast<const MouseEvent*>(mpData);
323  else
324  return nullptr;
325 }
326 
328 {
330  return static_cast<const CommandEvent*>(mpData);
331  else
332  return nullptr;
333 }
334 
335 
337  NONE = 0,
338  SETTINGS = 1,
339  DISPLAY = 2,
340  FONTS = 4,
341  PRINTER = 5,
342  FONTSUBSTITUTION = 6
343 };
344 
346 {
347 private:
348  void* mpData;
351 
352 public:
353  explicit DataChangedEvent( DataChangedEventType nType,
354  const void* pData = nullptr,
356 
357  DataChangedEventType GetType() const { return mnType; }
358  AllSettingsFlags GetFlags() const { return mnFlags; }
359 
360  const AllSettings* GetOldSettings() const;
361 };
362 
364  const void* pData,
365  AllSettingsFlags nChangeFlags )
366 {
367  mpData = const_cast<void*>(pData);
368  mnFlags = nChangeFlags;
369  mnType = nType;
370 }
371 
373 {
375  return static_cast<const AllSettings*>(mpData);
376  else
377  return nullptr;
378 }
379 
380 #endif // INCLUDED_VCL_EVENT_HXX
381 
382 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
DataChangedEvent(DataChangedEventType nType, const void *pData=nullptr, AllSettingsFlags nFlags=AllSettingsFlags::NONE)
Definition: event.hxx:363
constexpr sal_uInt16 KEY_MOD1
Definition: keycodes.hxx:31
DataChangedEventType mnType
Definition: event.hxx:350
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:327
const tools::Rectangle & GetRect() const
Definition: event.hxx:244
const AllSettings * GetOldSettings() const
Definition: event.hxx:372
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
bool IsShift() const
Definition: event.hxx:155
DataChangedEventType GetType() const
Definition: event.hxx:357
const KeyEvent * GetKeyEvent() const
Definition: event.hxx:311
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:296
HelpEventMode GetMode() const
Definition: event.hxx:205
void * mpData
Definition: event.hxx:295
MouseEvent maMEvt
Definition: event.hxx:252
MouseEventModifiers
Definition: event.hxx:76
bool IsTrackingRepeat() const
Definition: event.hxx:261
AllSettingsFlags
Definition: settings.hxx:668
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:304
HelpEventMode
Definition: event.hxx:182
bool mbSelected
Definition: event.hxx:229
sal_uInt16 GetButtons() const
Definition: event.hxx:144
Point maPos
Definition: event.hxx:106
bool IsEnterWindow() const
Definition: event.hxx:135
TrackingEvent(const MouseEvent &, TrackingEventFlags nTrackFlags=TrackingEventFlags::NONE)
Definition: event.hxx:269
AllSettingsFlags GetFlags() const
Definition: event.hxx:358
TrackingEventFlags
Definition: window.hxx:104
DataChangedEventType
Definition: event.hxx:336
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
vcl::RenderContext * GetRenderContext() const
Definition: event.hxx:243
bool IsLeaveWindow() const
Definition: event.hxx:137
bool IsMod2() const
Definition: event.hxx:159
AllSettingsFlags mnFlags
Definition: event.hxx:349
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:302
bool mbKeyboardActivated
Definition: event.hxx:199
MouseNotifyEvent GetType() const
Definition: event.hxx:303
UserDrawEvent(vcl::Window *pWindow, vcl::RenderContext *pRenderContext, const tools::Rectangle &rOutRect, sal_uInt16 nId, bool bSelected=false)
Definition: event.hxx:232
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:263
void * GetData() const
Definition: event.hxx:305
sal_uInt16 GetItemId() const
Definition: event.hxx:245
KeyEvent()
Definition: event.hxx:60
sal_uInt16 mnRepeat
Definition: event.hxx:45
bool IsModifierChanged() const
Definition: event.hxx:141
void * mpData
Definition: event.hxx:348
const vcl::KeyCode & GetKeyCode() const
Definition: event.hxx:54
VclPtr< vcl::Window > mpWindow
Definition: event.hxx:294
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:319
bool IsLeft() const
Definition: event.hxx:146
sal_Unicode GetCharCode() const
Definition: event.hxx:53
TrackingEventFlags mnFlags
Definition: event.hxx:253
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:265
bool IsRight() const
Definition: event.hxx:150
bool IsSelected() const
Definition: event.hxx:246
#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:259
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:277
vcl::Window * GetWindow() const
Definition: event.hxx:242
bool IsMod1() const
Definition: event.hxx:157
void SetKeyboardActivated(bool bKeyboard)
Definition: event.hxx:207