Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / include / vcl / event.hxx
blob26ce846ed9f479c7923df78ad8b5b4ea2c58473f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_VCL_EVENT_HXX
21 #define INCLUDED_VCL_EVENT_HXX
23 #include <tools/solar.h>
24 #include <vcl/dllapi.h>
25 #include <tools/gen.hxx>
26 #include <vcl/keycod.hxx>
27 #include <vcl/commandevent.hxx>
28 #include <vcl/settings.hxx>
29 #include <vcl/vclptr.hxx>
30 #include <vcl/outdev.hxx>
31 #include <vcl/window.hxx>
33 class AllSettings;
34 struct IDataObject;
36 namespace com { namespace sun { namespace star { namespace awt {
37 struct KeyEvent;
38 struct MouseEvent;
39 } } } }
41 enum class TextDirectionality {
42 LeftToRight_TopToBottom,
43 RightToLeft_TopToBottom,
44 TopToBottom_RightToLeft,
45 BottomToTop_LeftToRight
48 class VCL_DLLPUBLIC KeyEvent
50 private:
51 vcl::KeyCode maKeyCode;
52 sal_uInt16 mnRepeat;
53 sal_Unicode mnCharCode;
55 public:
56 KeyEvent();
57 KeyEvent( sal_Unicode nChar, const vcl::KeyCode& rKeyCode,
58 sal_uInt16 nRepeat = 0 );
60 sal_Unicode GetCharCode() const { return mnCharCode; }
61 const vcl::KeyCode& GetKeyCode() const { return maKeyCode; }
62 sal_uInt16 GetRepeat() const { return mnRepeat; }
64 KeyEvent LogicalTextDirectionality (TextDirectionality eMode) const;
65 KeyEvent (const KeyEvent& rKeyEvent);
69 inline KeyEvent::KeyEvent()
71 mnCharCode = 0;
72 mnRepeat = 0;
75 inline KeyEvent::KeyEvent( sal_Unicode nChar, const vcl::KeyCode& rKeyCode,
76 sal_uInt16 nRepeat ) :
77 maKeyCode( rKeyCode )
80 mnCharCode = nChar;
81 mnRepeat = nRepeat;
85 enum class MouseEventModifiers
87 NONE = 0,
88 // mouse move modifiers
89 SIMPLEMOVE = 0x0001,
90 DRAGMOVE = 0x0002,
91 DRAGCOPY = 0x0004,
92 ENTERWINDOW = 0x0010,
93 LEAVEWINDOW = 0x0020,
94 SYNTHETIC = 0x0040,
95 MODIFIERCHANGED = 0x0080,
96 // mouse up/down-button modifiers
97 SIMPLECLICK = 0x0100,
98 SELECT = 0x0200,
99 MULTISELECT = 0x0400,
100 RANGESELECT = 0x0800
102 namespace o3tl
104 template<> struct typed_flags<MouseEventModifiers> : is_typed_flags<MouseEventModifiers, 0xff7> {};
107 // Maus-Buttons
108 #define MOUSE_LEFT ((sal_uInt16)0x0001)
109 #define MOUSE_MIDDLE ((sal_uInt16)0x0002)
110 #define MOUSE_RIGHT ((sal_uInt16)0x0004)
113 class VCL_DLLPUBLIC MouseEvent
115 private:
116 Point maPos;
117 MouseEventModifiers mnMode;
118 sal_uInt16 mnClicks;
119 sal_uInt16 mnCode;
121 public:
122 explicit MouseEvent();
123 explicit MouseEvent( const Point& rPos, sal_uInt16 nClicks = 1,
124 MouseEventModifiers nMode = MouseEventModifiers::NONE, sal_uInt16 nButtons = 0,
125 sal_uInt16 nModifier = 0 );
127 const Point& GetPosPixel() const { return maPos; }
128 MouseEventModifiers GetMode() const { return mnMode; }
130 sal_uInt16 GetClicks() const { return mnClicks; }
132 bool IsEnterWindow() const
133 { return bool(mnMode & MouseEventModifiers::ENTERWINDOW); }
134 bool IsLeaveWindow() const
135 { return bool(mnMode & MouseEventModifiers::LEAVEWINDOW); }
136 bool IsSynthetic() const
137 { return bool(mnMode & MouseEventModifiers::SYNTHETIC); }
138 bool IsModifierChanged() const
139 { return bool(mnMode & MouseEventModifiers::MODIFIERCHANGED); }
141 sal_uInt16 GetButtons() const
142 { return (mnCode & (MOUSE_LEFT | MOUSE_MIDDLE | MOUSE_RIGHT)); }
143 bool IsLeft() const
144 { return ((mnCode & MOUSE_LEFT) != 0); }
145 bool IsMiddle() const
146 { return ((mnCode & MOUSE_MIDDLE) != 0); }
147 bool IsRight() const
148 { return ((mnCode & MOUSE_RIGHT) != 0); }
150 sal_uInt16 GetModifier() const
151 { return (mnCode & (KEY_SHIFT | KEY_MOD1 | KEY_MOD2)); }
152 bool IsShift() const
153 { return ((mnCode & KEY_SHIFT) != 0); }
154 bool IsMod1() const
155 { return ((mnCode & KEY_MOD1) != 0); }
156 bool IsMod2() const
157 { return ((mnCode & KEY_MOD2) != 0); }
158 bool IsMod3() const
159 { return ((mnCode & KEY_MOD3) != 0); }
162 inline MouseEvent::MouseEvent()
164 mnMode = MouseEventModifiers::NONE;
165 mnClicks = 0;
166 mnCode = 0;
169 inline MouseEvent::MouseEvent( const Point& rPos, sal_uInt16 nClicks,
170 MouseEventModifiers nMode,
171 sal_uInt16 nButtons, sal_uInt16 nModifier ) :
172 maPos( rPos )
174 mnClicks = nClicks;
175 mnMode = nMode;
176 mnCode = nButtons | nModifier;
179 enum class HelpEventMode
181 NONE = 0x0000,
182 CONTEXT = 0x0001,
183 EXTENDED = 0x0002,
184 BALLOON = 0x0004,
185 QUICK = 0x0008
187 namespace o3tl
189 template<> struct typed_flags<HelpEventMode> : is_typed_flags<HelpEventMode, 0x0f> {};
192 class VCL_DLLPUBLIC HelpEvent
194 private:
195 Point maPos;
196 HelpEventMode mnMode;
197 bool mbKeyboardActivated;
199 public:
200 explicit HelpEvent( const Point& rMousePos, HelpEventMode nHelpMode );
202 const Point& GetMousePosPixel() const { return maPos; }
203 HelpEventMode GetMode() const { return mnMode; }
204 bool KeyboardActivated() const { return mbKeyboardActivated; }
205 void SetKeyboardActivated( bool bKeyboard ) { mbKeyboardActivated = bKeyboard; }
208 inline HelpEvent::HelpEvent( const Point& rMousePos, HelpEventMode nHelpMode ) :
209 maPos( rMousePos )
211 mnMode = nHelpMode;
212 mbKeyboardActivated = false;
215 /// Event to pass information for UserDraw() handling eg. in comboboxes.
216 class VCL_DLLPUBLIC UserDrawEvent
218 private:
219 /// Window that owns the user draw.
220 VclPtr<vcl::Window> mpWindow;
222 /// RenderContext to which we should draw - can be a VirtualDevice or anything.
223 VclPtr<vcl::RenderContext> mpRenderContext;
225 tools::Rectangle maOutRect;
226 sal_uInt16 mnItemId;
227 sal_uInt16 mnStyle;
229 public:
230 UserDrawEvent(vcl::Window* pWindow, vcl::RenderContext* pRenderContext,
231 const tools::Rectangle& rOutRect, sal_uInt16 nId, sal_uInt16 nStyle = 0);
233 vcl::Window* GetWindow() const { return mpWindow; }
234 vcl::RenderContext* GetRenderContext() const { return mpRenderContext; }
235 const tools::Rectangle& GetRect() const { return maOutRect; }
236 sal_uInt16 GetItemId() const { return mnItemId; }
237 sal_uInt16 GetStyle() const { return mnStyle; }
240 inline UserDrawEvent::UserDrawEvent(vcl::Window* pWindow, vcl::RenderContext* pRenderContext,
241 const tools::Rectangle& rOutRect, sal_uInt16 nId, sal_uInt16 nStyle)
242 : mpWindow(pWindow)
243 , mpRenderContext(pRenderContext)
244 , maOutRect( rOutRect )
245 , mnItemId(nId)
246 , mnStyle(nStyle)
251 class VCL_DLLPUBLIC TrackingEvent
253 private:
254 MouseEvent maMEvt;
255 TrackingEventFlags mnFlags;
257 public:
258 explicit TrackingEvent( const MouseEvent&,
259 TrackingEventFlags nTrackFlags = TrackingEventFlags::NONE );
261 const MouseEvent& GetMouseEvent() const { return maMEvt; }
263 bool IsTrackingRepeat() const
264 { return bool(mnFlags & TrackingEventFlags::Repeat); }
265 bool IsTrackingEnded() const
266 { return bool(mnFlags & TrackingEventFlags::End); }
267 bool IsTrackingCanceled() const
268 { return bool(mnFlags & TrackingEventFlags::Cancel); }
271 inline TrackingEvent::TrackingEvent( const MouseEvent& rMEvt,
272 TrackingEventFlags nTrackFlags ) :
273 maMEvt( rMEvt )
275 mnFlags = nTrackFlags;
279 enum class MouseNotifyEvent
281 NONE = 0,
282 MOUSEBUTTONDOWN = 1,
283 MOUSEBUTTONUP = 2,
284 MOUSEMOVE = 3,
285 KEYINPUT = 4,
286 KEYUP = 5,
287 GETFOCUS = 6,
288 LOSEFOCUS = 7,
289 COMMAND = 8,
290 DESTROY = 9,
291 INPUTENABLE = 10,
292 INPUTDISABLE = 11,
293 EXECUTEDIALOG = 100,
294 ENDEXECUTEDIALOG = 101
297 class VCL_DLLPUBLIC NotifyEvent
299 private:
300 VclPtr<vcl::Window> mpWindow;
301 void* mpData;
302 MouseNotifyEvent mnEventType;
304 public:
305 NotifyEvent( MouseNotifyEvent nEventType,
306 vcl::Window* pWindow,
307 const void* pEvent = nullptr );
309 MouseNotifyEvent GetType() const { return mnEventType; }
310 vcl::Window* GetWindow() const { return mpWindow; }
311 void* GetData() const { return mpData; }
312 const KeyEvent* GetKeyEvent() const;
313 const MouseEvent* GetMouseEvent() const;
314 const CommandEvent* GetCommandEvent() const;
317 inline const KeyEvent* NotifyEvent::GetKeyEvent() const
319 if ( (mnEventType == MouseNotifyEvent::KEYINPUT) || (mnEventType == MouseNotifyEvent::KEYUP) )
320 return static_cast<const KeyEvent*>(mpData);
321 else
322 return nullptr;
325 inline const MouseEvent* NotifyEvent::GetMouseEvent() const
327 if ( (mnEventType >= MouseNotifyEvent::MOUSEBUTTONDOWN) && (mnEventType <= MouseNotifyEvent::MOUSEMOVE) )
328 return static_cast<const MouseEvent*>(mpData);
329 else
330 return nullptr;
333 inline const CommandEvent* NotifyEvent::GetCommandEvent() const
335 if ( mnEventType == MouseNotifyEvent::COMMAND )
336 return static_cast<const CommandEvent*>(mpData);
337 else
338 return nullptr;
342 enum class DataChangedEventType {
343 NONE = 0,
344 SETTINGS = 1,
345 DISPLAY = 2,
346 FONTS = 4,
347 PRINTER = 5,
348 FONTSUBSTITUTION = 6,
349 USER = 10000
352 class VCL_DLLPUBLIC DataChangedEvent
354 private:
355 void* mpData;
356 AllSettingsFlags mnFlags;
357 DataChangedEventType mnType;
359 public:
360 explicit DataChangedEvent( DataChangedEventType nType,
361 const void* pData = nullptr,
362 AllSettingsFlags nFlags = AllSettingsFlags::NONE );
364 DataChangedEventType GetType() const { return mnType; }
365 AllSettingsFlags GetFlags() const { return mnFlags; }
367 const AllSettings* GetOldSettings() const;
370 inline DataChangedEvent::DataChangedEvent( DataChangedEventType nType,
371 const void* pData,
372 AllSettingsFlags nChangeFlags )
374 mpData = const_cast<void*>(pData);
375 mnFlags = nChangeFlags;
376 mnType = nType;
379 inline const AllSettings* DataChangedEvent::GetOldSettings() const
381 if ( mnType == DataChangedEventType::SETTINGS )
382 return static_cast<const AllSettings*>(mpData);
383 else
384 return nullptr;
387 #endif // INCLUDED_VCL_EVENT_HXX
389 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */