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