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 
31 class CommandEvent;
32 
33 enum class TextDirectionality {
38 };
39 
40 namespace vcl {
41  class Window;
42 }
43 
45 {
46 private:
48  sal_uInt16 mnRepeat;
50 
51 public:
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 
69 inline 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 };
96 namespace 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 {
108 private:
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  const Point& GetPosPixel() const { return maPos; }
124  MouseEventModifiers GetMode() const { return mnMode; }
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
145  { return bool(mnMode & MouseEventModifiers::MODIFIERCHANGED); }
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 
175 inline MouseEvent::MouseEvent( const Point& rPos, sal_uInt16 nClicks,
176  MouseEventModifiers nMode,
177  sal_uInt16 nButtons, sal_uInt16 nModifier ) :
178  maPos( rPos )
179 {
180  mnClicks = nClicks;
181  mnMode = nMode;
182  mnCode = nButtons | nModifier;
183 }
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 
198 {
199 private:
203 
204 public:
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 
213 inline HelpEvent::HelpEvent( const Point& rMousePos, HelpEventMode nHelpMode ) :
214  maPos( rMousePos )
215 {
216  mnMode = nHelpMode;
217  mbKeyboardActivated = false;
218 }
219 
222 {
223 private:
226 
228  sal_uInt16 mnItemId;
230 
231 public:
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 {
249 private:
252 
253 public:
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); }
263  bool IsTrackingCanceled() const
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 {
290 private:
292  void* mpData;
294 
295 public:
296  NotifyEvent( MouseNotifyEvent 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  MouseNotifyEvent 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 
316 inline const KeyEvent* NotifyEvent::GetKeyEvent() const
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,
347  FONTSUBSTITUTION = 6
348 };
349 
351 {
352 private:
353  void* mpData;
356 
357 public:
358  explicit DataChangedEvent( DataChangedEventType nType,
359  const void* pData = nullptr,
361 
362  DataChangedEventType GetType() const { return mnType; }
363  AllSettingsFlags GetFlags() const { return mnFlags; }
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: */
UserDrawEvent(vcl::RenderContext *pRenderContext, const tools::Rectangle &rOutRect, sal_uInt16 nId, bool bSelected=false)
Definition: event.hxx:232
DataChangedEvent(DataChangedEventType nType, const void *pData=nullptr, AllSettingsFlags nFlags=AllSettingsFlags::NONE)
Definition: event.hxx:368
constexpr sal_uInt16 KEY_MOD1
Definition: keycodes.hxx:31
DataChangedEventType mnType
Definition: event.hxx:355
bool IsMod3() const
Definition: event.hxx:164
const CommandEvent * GetCommandEvent() const
Definition: event.hxx:332
const tools::Rectangle & GetRect() const
Definition: event.hxx:242
A thin wrapper around rtl::Reference to implement the acquire and dispose semantics we want for refer...
Definition: button.hxx:34
const AllSettings * GetOldSettings() const
Definition: event.hxx:377
sal_uInt16 mnCode
Definition: event.hxx:112
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
MouseEventModifiers GetMode() const
Definition: event.hxx:124
tools::Rectangle maOutRect
Definition: event.hxx:227
bool IsShift() const
Definition: event.hxx:158
DataChangedEventType GetType() const
Definition: event.hxx:362
const KeyEvent * GetKeyEvent() const
Definition: event.hxx:316
TextDirectionality
Definition: event.hxx:33
bool IsMiddle() const
Definition: event.hxx:151
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:293
HelpEventMode GetMode() const
Definition: event.hxx:208
void * mpData
Definition: event.hxx:292
MouseEvent maMEvt
Definition: event.hxx:250
MouseEventModifiers
Definition: event.hxx:79
bool IsTrackingRepeat() const
Definition: event.hxx:259
AllSettingsFlags
Definition: settings.hxx:659
sal_uInt16 GetClicks() const
Definition: event.hxx:126
std::optional< Point > maLogicPosition
Definition: event.hxx:115
sal_uInt16 sal_Unicode
HelpEventMode mnMode
Definition: event.hxx:201
vcl::Window * GetWindow() const
Definition: event.hxx:309
HelpEventMode
Definition: event.hxx:185
bool mbSelected
Definition: event.hxx:229
sal_uInt16 GetButtons() const
Definition: event.hxx:147
Point maPos
Definition: event.hxx:109
bool IsEnterWindow() const
Definition: event.hxx:138
TrackingEvent(const MouseEvent &, TrackingEventFlags nTrackFlags=TrackingEventFlags::NONE)
Definition: event.hxx:267
AllSettingsFlags GetFlags() const
Definition: event.hxx:363
DataChangedEventType
Definition: event.hxx:341
HelpEvent(const Point &rMousePos, HelpEventMode nHelpMode)
Definition: event.hxx:213
vcl::KeyCode maKeyCode
Definition: event.hxx:47
#define MOUSE_LEFT
Definition: event.hxx:102
const Point & GetMousePosPixel() const
Definition: event.hxx:207
sal_Unicode mnCharCode
Definition: event.hxx:49
vcl::RenderContext * GetRenderContext() const
Definition: event.hxx:241
bool IsLeaveWindow() const
Definition: event.hxx:140
bool IsMod2() const
Definition: event.hxx:162
AllSettingsFlags mnFlags
Definition: event.hxx:354
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:168
bool mbKeyboardActivated
Definition: event.hxx:202
MouseNotifyEvent GetType() const
Definition: event.hxx:308
TrackingEventFlags
Definition: vclenum.hxx:401
sal_uInt16 GetModifier() const
Definition: event.hxx:156
constexpr sal_uInt16 KEY_MOD2
Definition: keycodes.hxx:32
bool KeyboardActivated() const
Definition: event.hxx:209
bool IsTrackingEnded() const
Definition: event.hxx:261
void * GetData() const
Definition: event.hxx:310
const std::optional< Point > & getLogicPosition() const
Definition: event.hxx:133
sal_uInt16 GetItemId() const
Definition: event.hxx:243
KeyEvent()
Definition: event.hxx:63
sal_uInt16 mnRepeat
Definition: event.hxx:48
bool IsModifierChanged() const
Definition: event.hxx:144
void * mpData
Definition: event.hxx:353
const vcl::KeyCode & GetKeyCode() const
Definition: event.hxx:57
VclPtr< vcl::Window > mpWindow
Definition: event.hxx:291
MouseEventModifiers mnMode
Definition: event.hxx:110
bool IsSynthetic() const
Definition: event.hxx:142
sal_uInt16 mnItemId
Definition: event.hxx:228
const MouseEvent * GetMouseEvent() const
Definition: event.hxx:324
bool IsLeft() const
Definition: event.hxx:149
sal_Unicode GetCharCode() const
Definition: event.hxx:56
TrackingEventFlags mnFlags
Definition: event.hxx:251
const Point & GetPosPixel() const
Definition: event.hxx:123
sal_uInt16 GetRepeat() const
Definition: event.hxx:58
MouseEvent()
Definition: event.hxx:168
Event to pass information for UserDraw() handling eg. in comboboxes.
Definition: event.hxx:221
bool IsTrackingCanceled() const
Definition: event.hxx:263
bool IsRight() const
Definition: event.hxx:153
bool IsSelected() const
Definition: event.hxx:244
#define MOUSE_MIDDLE
Definition: event.hxx:103
sal_uInt16 mnClicks
Definition: event.hxx:111
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:257
void setLogicPosition(Point aLogicPosition)
Definition: event.hxx:128
Point maPos
Definition: event.hxx:200
#define MOUSE_RIGHT
Definition: event.hxx:104
MouseNotifyEvent
Definition: event.hxx:275
bool IsMod1() const
Definition: event.hxx:160
void SetKeyboardActivated(bool bKeyboard)
Definition: event.hxx:210