Branch libreoffice-5-0-4
[LibreOffice.git] / include / vcl / event.hxx
blob085182a41d0ce0a03745a8eeefab942299e3b04c
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/cmdevt.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 TextDirectionality {
42 TextDirectionality_LeftToRight_TopToBottom,
43 TextDirectionality_RightToLeft_TopToBottom,
44 TextDirectionality_TopToBottom_RightToLeft
47 class VCL_DLLPUBLIC KeyEvent
49 private:
50 vcl::KeyCode maKeyCode;
51 sal_uInt16 mnRepeat;
52 sal_Unicode mnCharCode;
54 public:
55 KeyEvent();
56 KeyEvent( sal_Unicode nChar, const vcl::KeyCode& rKeyCode,
57 sal_uInt16 nRepeat = 0 );
59 sal_Unicode GetCharCode() const { return mnCharCode; }
60 const vcl::KeyCode& GetKeyCode() const { return maKeyCode; }
61 sal_uInt16 GetRepeat() const { return mnRepeat; }
63 KeyEvent LogicalTextDirectionality (TextDirectionality eMode) const;
64 KeyEvent (const KeyEvent& rKeyEvent);
68 inline KeyEvent::KeyEvent()
70 mnCharCode = 0;
71 mnRepeat = 0;
74 inline KeyEvent::KeyEvent( sal_Unicode nChar, const vcl::KeyCode& rKeyCode,
75 sal_uInt16 nRepeat ) :
76 maKeyCode( rKeyCode )
79 mnCharCode = nChar;
80 mnRepeat = nRepeat;
84 // - MouseEvent-Types -
87 enum class MouseEventModifiers
89 NONE = 0,
90 // mouse move modifiers
91 SIMPLEMOVE = 0x0001,
92 DRAGMOVE = 0x0002,
93 DRAGCOPY = 0x0004,
94 ENTERWINDOW = 0x0010,
95 LEAVEWINDOW = 0x0020,
96 SYNTHETIC = 0x0040,
97 MODIFIERCHANGED = 0x0080,
98 // mouse up/down-button modifiers
99 SIMPLECLICK = 0x0100,
100 SELECT = 0x0200,
101 MULTISELECT = 0x0400,
102 RANGESELECT = 0x0800
104 namespace o3tl
106 template<> struct typed_flags<MouseEventModifiers> : is_typed_flags<MouseEventModifiers, 0xff7> {};
109 // Maus-Buttons
110 #define MOUSE_LEFT ((sal_uInt16)0x0001)
111 #define MOUSE_MIDDLE ((sal_uInt16)0x0002)
112 #define MOUSE_RIGHT ((sal_uInt16)0x0004)
115 // - MouseEvent -
118 class VCL_DLLPUBLIC MouseEvent
120 private:
121 Point maPos;
122 MouseEventModifiers mnMode;
123 sal_uInt16 mnClicks;
124 sal_uInt16 mnCode;
126 public:
127 explicit MouseEvent();
128 explicit MouseEvent( const Point& rPos, sal_uInt16 nClicks = 1,
129 MouseEventModifiers nMode = MouseEventModifiers::NONE, sal_uInt16 nButtons = 0,
130 sal_uInt16 nModifier = 0 );
132 const Point& GetPosPixel() const { return maPos; }
133 MouseEventModifiers GetMode() const { return mnMode; }
134 /** inits this vcl KeyEvent with all settings from the given awt event **/
135 MouseEvent( const ::com::sun::star::awt::MouseEvent& rEvent );
137 sal_uInt16 GetClicks() const { return mnClicks; }
139 bool IsEnterWindow() const
140 { return bool(mnMode & MouseEventModifiers::ENTERWINDOW); }
141 bool IsLeaveWindow() const
142 { return bool(mnMode & MouseEventModifiers::LEAVEWINDOW); }
143 bool IsSynthetic() const
144 { return bool(mnMode & MouseEventModifiers::SYNTHETIC); }
145 bool IsModifierChanged() const
146 { return bool(mnMode & MouseEventModifiers::MODIFIERCHANGED); }
148 sal_uInt16 GetButtons() const
149 { return (mnCode & (MOUSE_LEFT | MOUSE_MIDDLE | MOUSE_RIGHT)); }
150 bool IsLeft() const
151 { return ((mnCode & MOUSE_LEFT) != 0); }
152 bool IsMiddle() const
153 { return ((mnCode & MOUSE_MIDDLE) != 0); }
154 bool IsRight() const
155 { return ((mnCode & MOUSE_RIGHT) != 0); }
157 sal_uInt16 GetModifier() const
158 { return (mnCode & (KEY_SHIFT | KEY_MOD1 | KEY_MOD2)); }
159 bool IsShift() const
160 { return ((mnCode & KEY_SHIFT) != 0); }
161 bool IsMod1() const
162 { return ((mnCode & KEY_MOD1) != 0); }
163 bool IsMod2() const
164 { return ((mnCode & KEY_MOD2) != 0); }
165 bool IsMod3() const
166 { return ((mnCode & KEY_MOD3) != 0); }
169 inline MouseEvent::MouseEvent()
171 mnMode = MouseEventModifiers::NONE;
172 mnClicks = 0;
173 mnCode = 0;
176 inline MouseEvent::MouseEvent( const Point& rPos, sal_uInt16 nClicks,
177 MouseEventModifiers nMode,
178 sal_uInt16 nButtons, sal_uInt16 nModifier ) :
179 maPos( rPos )
181 mnClicks = nClicks;
182 mnMode = nMode;
183 mnCode = nButtons | nModifier;
186 class VCL_DLLPUBLIC ZoomEvent
188 private:
189 Point maCenter;
190 float mfScale;
192 public:
193 ZoomEvent() :
194 mfScale( 1 )
198 ZoomEvent( const Point& rCenter,
199 float fScale ) :
200 maCenter( rCenter ),
201 mfScale( fScale )
205 const Point& GetCenter() const
207 return maCenter;
210 float GetScale() const
212 return mfScale;
216 class VCL_DLLPUBLIC ScrollEvent
218 private:
219 int mnXOffset;
220 int mnYOffset;
222 public:
223 ScrollEvent() :
224 mnXOffset( 0 ),
225 mnYOffset( 0 )
229 ScrollEvent( int xOffset, int yOffset ) :
230 mnXOffset( xOffset ),
231 mnYOffset( yOffset )
235 int GetXOffset() const
237 return mnXOffset;
240 int GetYOffset() const
242 return mnYOffset;
247 // - HelpEvent -
249 enum class HelpEventMode
251 NONE = 0x0000,
252 CONTEXT = 0x0001,
253 EXTENDED = 0x0002,
254 BALLOON = 0x0004,
255 QUICK = 0x0008
257 namespace o3tl
259 template<> struct typed_flags<HelpEventMode> : is_typed_flags<HelpEventMode, 0x0f> {};
262 class VCL_DLLPUBLIC HelpEvent
264 private:
265 Point maPos;
266 HelpEventMode mnMode;
267 bool mbKeyboardActivated;
269 public:
270 explicit HelpEvent();
271 explicit HelpEvent( HelpEventMode nHelpMode );
272 explicit HelpEvent( const Point& rMousePos, HelpEventMode nHelpMode );
274 const Point& GetMousePosPixel() const { return maPos; }
275 HelpEventMode GetMode() const { return mnMode; }
276 bool KeyboardActivated() const { return mbKeyboardActivated; }
277 void SetKeyboardActivated( bool bKeyboard ) { mbKeyboardActivated = bKeyboard; }
280 inline HelpEvent::HelpEvent()
282 mnMode = HelpEventMode::CONTEXT;
283 mbKeyboardActivated = true;
286 inline HelpEvent::HelpEvent( const Point& rMousePos, HelpEventMode nHelpMode ) :
287 maPos( rMousePos )
289 mnMode = nHelpMode;
290 mbKeyboardActivated = false;
293 inline HelpEvent::HelpEvent( HelpEventMode nHelpMode )
295 mnMode = nHelpMode;
296 mbKeyboardActivated = true;
299 /// Event to pass information for UserDraw() handling eg. in comboboxes.
300 class VCL_DLLPUBLIC UserDrawEvent
302 private:
303 /// Window that owns the user draw.
304 VclPtr<vcl::Window> mpWindow;
306 /// RenderContext to which we should draw - can be a VirtualDevice or anything.
307 VclPtr<vcl::RenderContext> mpRenderContext;
309 Rectangle maOutRect;
310 sal_uInt16 mnItemId;
311 sal_uInt16 mnStyle;
313 public:
314 UserDrawEvent();
315 UserDrawEvent(vcl::Window* pWindow, vcl::RenderContext* pRenderContext,
316 const Rectangle& rOutRect, sal_uInt16 nId, sal_uInt16 nStyle = 0);
318 vcl::Window* GetWindow() const { return mpWindow; }
319 vcl::RenderContext* GetRenderContext() const { return mpRenderContext; }
320 const Rectangle& GetRect() const { return maOutRect; }
321 sal_uInt16 GetItemId() const { return mnItemId; }
322 sal_uInt16 GetStyle() const { return mnStyle; }
325 inline UserDrawEvent::UserDrawEvent()
326 : mpWindow(nullptr)
327 , mpRenderContext(nullptr)
328 , mnItemId(0)
329 , mnStyle(0)
333 inline UserDrawEvent::UserDrawEvent(vcl::Window* pWindow, vcl::RenderContext* pRenderContext,
334 const Rectangle& rOutRect, sal_uInt16 nId, sal_uInt16 nStyle)
335 : mpWindow(pWindow)
336 , mpRenderContext(pRenderContext)
337 , maOutRect( rOutRect )
338 , mnItemId(nId)
339 , mnStyle(nStyle)
344 // - TrackingEvent -
347 class VCL_DLLPUBLIC TrackingEvent
349 private:
350 MouseEvent maMEvt;
351 TrackingEventFlags mnFlags;
353 public:
354 explicit TrackingEvent();
355 explicit TrackingEvent( const MouseEvent&,
356 TrackingEventFlags nTrackFlags = TrackingEventFlags::NONE );
358 const MouseEvent& GetMouseEvent() const { return maMEvt; }
360 bool IsTrackingRepeat() const
361 { return bool(mnFlags & TrackingEventFlags::Repeat); }
363 bool IsTrackingEnded() const
364 { return bool(mnFlags & TrackingEventFlags::End); }
365 bool IsTrackingCanceled() const
366 { return bool(mnFlags & TrackingEventFlags::Cancel); }
367 TrackingEventFlags GetTrackingFlags() const { return mnFlags; }
370 inline TrackingEvent::TrackingEvent()
372 mnFlags = TrackingEventFlags::NONE;
375 inline TrackingEvent::TrackingEvent( const MouseEvent& rMEvt,
376 TrackingEventFlags nTrackFlags ) :
377 maMEvt( rMEvt )
379 mnFlags = nTrackFlags;
383 // - NotifyEvent -
385 enum class MouseNotifyEvent
387 NONE = 0,
388 MOUSEBUTTONDOWN = 1,
389 MOUSEBUTTONUP = 2,
390 MOUSEMOVE = 3,
391 KEYINPUT = 4,
392 KEYUP = 5,
393 GETFOCUS = 6,
394 LOSEFOCUS = 7,
395 COMMAND = 8,
396 DESTROY = 9,
397 INPUTENABLE = 10,
398 INPUTDISABLE = 11,
399 EXECUTEDIALOG = 100,
400 ENDEXECUTEDIALOG = 101
403 class VCL_DLLPUBLIC NotifyEvent
405 private:
406 VclPtr<vcl::Window> mpWindow;
407 void* mpData;
408 MouseNotifyEvent mnEventType;
409 long mnRetValue;
411 public:
412 NotifyEvent();
413 NotifyEvent( MouseNotifyEvent nEventType,
414 vcl::Window* pWindow,
415 const void* pEvent = NULL,
416 long nRet = 0 );
418 MouseNotifyEvent GetType() const { return mnEventType; }
419 vcl::Window* GetWindow() const { return mpWindow; }
420 void* GetData() const { return mpData; }
422 void SetReturnValue( long nRet ) { mnRetValue = nRet; }
423 long GetReturnValue() const { return mnRetValue; }
425 const KeyEvent* GetKeyEvent() const;
426 const MouseEvent* GetMouseEvent() const;
427 const CommandEvent* GetCommandEvent() const;
430 inline const KeyEvent* NotifyEvent::GetKeyEvent() const
432 if ( (mnEventType == MouseNotifyEvent::KEYINPUT) || (mnEventType == MouseNotifyEvent::KEYUP) )
433 return static_cast<const KeyEvent*>(mpData);
434 else
435 return NULL;
438 inline const MouseEvent* NotifyEvent::GetMouseEvent() const
440 if ( (mnEventType >= MouseNotifyEvent::MOUSEBUTTONDOWN) && (mnEventType <= MouseNotifyEvent::MOUSEMOVE) )
441 return static_cast<const MouseEvent*>(mpData);
442 else
443 return NULL;
446 inline const CommandEvent* NotifyEvent::GetCommandEvent() const
448 if ( mnEventType == MouseNotifyEvent::COMMAND )
449 return static_cast<const CommandEvent*>(mpData);
450 else
451 return NULL;
455 // - DataChangedEvent -
458 enum class DataChangedEventType {
459 NONE = 0,
460 SETTINGS = 1,
461 DISPLAY = 2,
462 FONTS = 4,
463 PRINTER = 5,
464 FONTSUBSTITUTION = 6,
465 USER = 10000
468 class VCL_DLLPUBLIC DataChangedEvent
470 private:
471 void* mpData;
472 AllSettingsFlags mnFlags;
473 DataChangedEventType mnType;
475 public:
476 explicit DataChangedEvent();
477 explicit DataChangedEvent( DataChangedEventType nType,
478 const void* pData = NULL,
479 AllSettingsFlags nFlags = AllSettingsFlags::NONE );
481 DataChangedEventType GetType() const { return mnType; }
482 void* GetData() const { return mpData; }
483 AllSettingsFlags GetFlags() const { return mnFlags; }
485 const AllSettings* GetOldSettings() const;
488 inline DataChangedEvent::DataChangedEvent()
490 mpData = NULL;
491 mnFlags = AllSettingsFlags::NONE;
492 mnType = DataChangedEventType::NONE;
495 inline DataChangedEvent::DataChangedEvent( DataChangedEventType nType,
496 const void* pData,
497 AllSettingsFlags nChangeFlags )
499 mpData = const_cast<void*>(pData);
500 mnFlags = nChangeFlags;
501 mnType = nType;
504 inline const AllSettings* DataChangedEvent::GetOldSettings() const
506 if ( mnType == DataChangedEventType::SETTINGS )
507 return static_cast<const AllSettings*>(mpData);
508 else
509 return NULL;
512 #endif // INCLUDED_VCL_EVENT_HXX
514 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */