1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
36 namespace com
{ namespace sun
{ namespace star
{ namespace awt
{
41 enum TextDirectionality
{
42 TextDirectionality_LeftToRight_TopToBottom
,
43 TextDirectionality_RightToLeft_TopToBottom
,
44 TextDirectionality_TopToBottom_RightToLeft
47 class VCL_DLLPUBLIC KeyEvent
50 vcl::KeyCode maKeyCode
;
52 sal_Unicode mnCharCode
;
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()
74 inline KeyEvent::KeyEvent( sal_Unicode nChar
, const vcl::KeyCode
& rKeyCode
,
75 sal_uInt16 nRepeat
) :
84 // - MouseEvent-Types -
87 enum class MouseEventModifiers
90 // mouse move modifiers
97 MODIFIERCHANGED
= 0x0080,
98 // mouse up/down-button modifiers
101 MULTISELECT
= 0x0400,
106 template<> struct typed_flags
<MouseEventModifiers
> : is_typed_flags
<MouseEventModifiers
, 0xff7> {};
110 #define MOUSE_LEFT ((sal_uInt16)0x0001)
111 #define MOUSE_MIDDLE ((sal_uInt16)0x0002)
112 #define MOUSE_RIGHT ((sal_uInt16)0x0004)
118 class VCL_DLLPUBLIC MouseEvent
122 MouseEventModifiers mnMode
;
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
)); }
151 { return ((mnCode
& MOUSE_LEFT
) != 0); }
152 bool IsMiddle() const
153 { return ((mnCode
& MOUSE_MIDDLE
) != 0); }
155 { return ((mnCode
& MOUSE_RIGHT
) != 0); }
157 sal_uInt16
GetModifier() const
158 { return (mnCode
& (KEY_SHIFT
| KEY_MOD1
| KEY_MOD2
)); }
160 { return ((mnCode
& KEY_SHIFT
) != 0); }
162 { return ((mnCode
& KEY_MOD1
) != 0); }
164 { return ((mnCode
& KEY_MOD2
) != 0); }
166 { return ((mnCode
& KEY_MOD3
) != 0); }
169 inline MouseEvent::MouseEvent()
171 mnMode
= MouseEventModifiers::NONE
;
176 inline MouseEvent::MouseEvent( const Point
& rPos
, sal_uInt16 nClicks
,
177 MouseEventModifiers nMode
,
178 sal_uInt16 nButtons
, sal_uInt16 nModifier
) :
183 mnCode
= nButtons
| nModifier
;
186 class VCL_DLLPUBLIC ZoomEvent
198 ZoomEvent( const Point
& rCenter
,
205 const Point
& GetCenter() const
210 float GetScale() const
216 class VCL_DLLPUBLIC ScrollEvent
229 ScrollEvent( int xOffset
, int yOffset
) :
230 mnXOffset( xOffset
),
235 int GetXOffset() const
240 int GetYOffset() const
249 enum class HelpEventMode
259 template<> struct typed_flags
<HelpEventMode
> : is_typed_flags
<HelpEventMode
, 0x0f> {};
262 class VCL_DLLPUBLIC HelpEvent
266 HelpEventMode mnMode
;
267 bool mbKeyboardActivated
;
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
) :
290 mbKeyboardActivated
= false;
293 inline HelpEvent::HelpEvent( HelpEventMode nHelpMode
)
296 mbKeyboardActivated
= true;
299 /// Event to pass information for UserDraw() handling eg. in comboboxes.
300 class VCL_DLLPUBLIC UserDrawEvent
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
;
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()
327 , mpRenderContext(nullptr)
333 inline UserDrawEvent::UserDrawEvent(vcl::Window
* pWindow
, vcl::RenderContext
* pRenderContext
,
334 const Rectangle
& rOutRect
, sal_uInt16 nId
, sal_uInt16 nStyle
)
336 , mpRenderContext(pRenderContext
)
337 , maOutRect( rOutRect
)
347 class VCL_DLLPUBLIC TrackingEvent
351 TrackingEventFlags mnFlags
;
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
) :
379 mnFlags
= nTrackFlags
;
385 enum class MouseNotifyEvent
400 ENDEXECUTEDIALOG
= 101
403 class VCL_DLLPUBLIC NotifyEvent
406 VclPtr
<vcl::Window
> mpWindow
;
408 MouseNotifyEvent mnEventType
;
413 NotifyEvent( MouseNotifyEvent nEventType
,
414 vcl::Window
* pWindow
,
415 const void* pEvent
= NULL
,
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
);
438 inline const MouseEvent
* NotifyEvent::GetMouseEvent() const
440 if ( (mnEventType
>= MouseNotifyEvent::MOUSEBUTTONDOWN
) && (mnEventType
<= MouseNotifyEvent::MOUSEMOVE
) )
441 return static_cast<const MouseEvent
*>(mpData
);
446 inline const CommandEvent
* NotifyEvent::GetCommandEvent() const
448 if ( mnEventType
== MouseNotifyEvent::COMMAND
)
449 return static_cast<const CommandEvent
*>(mpData
);
455 // - DataChangedEvent -
458 enum class DataChangedEventType
{
464 FONTSUBSTITUTION
= 6,
468 class VCL_DLLPUBLIC DataChangedEvent
472 AllSettingsFlags mnFlags
;
473 DataChangedEventType mnType
;
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()
491 mnFlags
= AllSettingsFlags::NONE
;
492 mnType
= DataChangedEventType::NONE
;
495 inline DataChangedEvent::DataChangedEvent( DataChangedEventType nType
,
497 AllSettingsFlags nChangeFlags
)
499 mpData
= const_cast<void*>(pData
);
500 mnFlags
= nChangeFlags
;
504 inline const AllSettings
* DataChangedEvent::GetOldSettings() const
506 if ( mnType
== DataChangedEventType::SETTINGS
)
507 return static_cast<const AllSettings
*>(mpData
);
512 #endif // INCLUDED_VCL_EVENT_HXX
514 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */