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 <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>
34 enum class TextDirectionality
{
35 LeftToRight_TopToBottom
,
36 RightToLeft_TopToBottom
,
37 TopToBottom_RightToLeft
,
38 BottomToTop_LeftToRight
41 class VCL_DLLPUBLIC KeyEvent
44 vcl::KeyCode maKeyCode
;
46 sal_Unicode mnCharCode
;
50 KeyEvent( sal_Unicode nChar
, const vcl::KeyCode
& rKeyCode
,
51 sal_uInt16 nRepeat
= 0 );
53 sal_Unicode
GetCharCode() const { return mnCharCode
; }
54 const vcl::KeyCode
& GetKeyCode() const { return maKeyCode
; }
55 sal_uInt16
GetRepeat() const { return mnRepeat
; }
57 KeyEvent
LogicalTextDirectionality (TextDirectionality eMode
) const;
60 inline KeyEvent::KeyEvent()
66 inline KeyEvent::KeyEvent( sal_Unicode nChar
, const vcl::KeyCode
& rKeyCode
,
67 sal_uInt16 nRepeat
) :
76 enum class MouseEventModifiers
79 // mouse move modifiers
86 MODIFIERCHANGED
= 0x0080,
87 // mouse up/down-button modifiers
95 template<> struct typed_flags
<MouseEventModifiers
> : is_typed_flags
<MouseEventModifiers
, 0xff7> {};
99 #define MOUSE_LEFT (sal_uInt16(0x0001))
100 #define MOUSE_MIDDLE (sal_uInt16(0x0002))
101 #define MOUSE_RIGHT (sal_uInt16(0x0004))
103 class VCL_DLLPUBLIC MouseEvent
107 MouseEventModifiers mnMode
;
111 // Set, if the document relative logic position are available
112 std::optional
<Point
> maLogicPosition
;
115 explicit MouseEvent();
116 explicit MouseEvent( const Point
& rPos
, sal_uInt16 nClicks
= 1,
117 MouseEventModifiers nMode
= MouseEventModifiers::NONE
, sal_uInt16 nButtons
= 0,
118 sal_uInt16 nModifier
= 0 );
120 const Point
& GetPosPixel() const { return maPos
; }
121 MouseEventModifiers
GetMode() const { return mnMode
; }
123 sal_uInt16
GetClicks() const { return mnClicks
; }
125 void setLogicPosition(Point aLogicPosition
)
127 maLogicPosition
= aLogicPosition
;
130 std::optional
<Point
> getLogicPosition() const
132 return maLogicPosition
;
135 bool IsEnterWindow() const
136 { return bool(mnMode
& MouseEventModifiers::ENTERWINDOW
); }
137 bool IsLeaveWindow() const
138 { return bool(mnMode
& MouseEventModifiers::LEAVEWINDOW
); }
139 bool IsSynthetic() const
140 { return bool(mnMode
& MouseEventModifiers::SYNTHETIC
); }
141 bool IsModifierChanged() const
142 { return bool(mnMode
& MouseEventModifiers::MODIFIERCHANGED
); }
144 sal_uInt16
GetButtons() const
145 { return (mnCode
& (MOUSE_LEFT
| MOUSE_MIDDLE
| MOUSE_RIGHT
)); }
147 { return ((mnCode
& MOUSE_LEFT
) != 0); }
148 bool IsMiddle() const
149 { return ((mnCode
& MOUSE_MIDDLE
) != 0); }
151 { return ((mnCode
& MOUSE_RIGHT
) != 0); }
153 sal_uInt16
GetModifier() const
154 { return (mnCode
& (KEY_SHIFT
| KEY_MOD1
| KEY_MOD2
)); }
156 { return ((mnCode
& KEY_SHIFT
) != 0); }
158 { return ((mnCode
& KEY_MOD1
) != 0); }
160 { return ((mnCode
& KEY_MOD2
) != 0); }
162 { return ((mnCode
& KEY_MOD3
) != 0); }
165 inline MouseEvent::MouseEvent()
167 mnMode
= MouseEventModifiers::NONE
;
172 inline MouseEvent::MouseEvent( const Point
& rPos
, sal_uInt16 nClicks
,
173 MouseEventModifiers nMode
,
174 sal_uInt16 nButtons
, sal_uInt16 nModifier
) :
179 mnCode
= nButtons
| nModifier
;
182 enum class HelpEventMode
191 template<> struct typed_flags
<HelpEventMode
> : is_typed_flags
<HelpEventMode
, 0x07> {};
194 class VCL_DLLPUBLIC HelpEvent
198 HelpEventMode mnMode
;
199 bool mbKeyboardActivated
;
202 explicit HelpEvent( const Point
& rMousePos
, HelpEventMode nHelpMode
);
204 const Point
& GetMousePosPixel() const { return maPos
; }
205 HelpEventMode
GetMode() const { return mnMode
; }
206 bool KeyboardActivated() const { return mbKeyboardActivated
; }
207 void SetKeyboardActivated( bool bKeyboard
) { mbKeyboardActivated
= bKeyboard
; }
210 inline HelpEvent::HelpEvent( const Point
& rMousePos
, HelpEventMode nHelpMode
) :
214 mbKeyboardActivated
= false;
217 /// Event to pass information for UserDraw() handling eg. in comboboxes.
218 class VCL_DLLPUBLIC UserDrawEvent
221 /// Window that owns the user draw.
222 VclPtr
<vcl::Window
> mpWindow
;
224 /// RenderContext to which we should draw - can be a VirtualDevice or anything.
225 VclPtr
<vcl::RenderContext
> mpRenderContext
;
227 tools::Rectangle maOutRect
;
232 UserDrawEvent(vcl::Window
* pWindow
, vcl::RenderContext
* pRenderContext
,
233 const tools::Rectangle
& rOutRect
, sal_uInt16 nId
, bool bSelected
= false)
235 , mpRenderContext(pRenderContext
)
236 , maOutRect( rOutRect
)
238 , mbSelected(bSelected
)
242 vcl::Window
* GetWindow() const { return mpWindow
; }
243 vcl::RenderContext
* GetRenderContext() const { return mpRenderContext
; }
244 const tools::Rectangle
& GetRect() const { return maOutRect
; }
245 sal_uInt16
GetItemId() const { return mnItemId
; }
246 bool IsSelected() const { return mbSelected
; }
249 class VCL_DLLPUBLIC TrackingEvent
253 TrackingEventFlags mnFlags
;
256 explicit TrackingEvent( const MouseEvent
&,
257 TrackingEventFlags nTrackFlags
= TrackingEventFlags::NONE
);
259 const MouseEvent
& GetMouseEvent() const { return maMEvt
; }
261 bool IsTrackingRepeat() const
262 { return bool(mnFlags
& TrackingEventFlags::Repeat
); }
263 bool IsTrackingEnded() const
264 { return bool(mnFlags
& TrackingEventFlags::End
); }
265 bool IsTrackingCanceled() const
266 { return bool(mnFlags
& TrackingEventFlags::Cancel
); }
269 inline TrackingEvent::TrackingEvent( const MouseEvent
& rMEvt
,
270 TrackingEventFlags nTrackFlags
) :
273 mnFlags
= nTrackFlags
;
277 enum class MouseNotifyEvent
290 class VCL_DLLPUBLIC NotifyEvent
293 VclPtr
<vcl::Window
> mpWindow
;
295 MouseNotifyEvent mnEventType
;
298 NotifyEvent( MouseNotifyEvent nEventType
,
299 vcl::Window
* pWindow
,
300 const void* pEvent
= nullptr );
302 MouseNotifyEvent
GetType() const { return mnEventType
; }
303 vcl::Window
* GetWindow() const { return mpWindow
; }
304 void* GetData() const { return mpData
; }
305 const KeyEvent
* GetKeyEvent() const;
306 const MouseEvent
* GetMouseEvent() const;
307 const CommandEvent
* GetCommandEvent() const;
310 inline const KeyEvent
* NotifyEvent::GetKeyEvent() const
312 if ( (mnEventType
== MouseNotifyEvent::KEYINPUT
) || (mnEventType
== MouseNotifyEvent::KEYUP
) )
313 return static_cast<const KeyEvent
*>(mpData
);
318 inline const MouseEvent
* NotifyEvent::GetMouseEvent() const
320 if ( (mnEventType
>= MouseNotifyEvent::MOUSEBUTTONDOWN
) && (mnEventType
<= MouseNotifyEvent::MOUSEMOVE
) )
321 return static_cast<const MouseEvent
*>(mpData
);
326 inline const CommandEvent
* NotifyEvent::GetCommandEvent() const
328 if ( mnEventType
== MouseNotifyEvent::COMMAND
)
329 return static_cast<const CommandEvent
*>(mpData
);
335 enum class DataChangedEventType
{
344 class VCL_DLLPUBLIC DataChangedEvent
348 AllSettingsFlags mnFlags
;
349 DataChangedEventType mnType
;
352 explicit DataChangedEvent( DataChangedEventType nType
,
353 const void* pData
= nullptr,
354 AllSettingsFlags nFlags
= AllSettingsFlags::NONE
);
356 DataChangedEventType
GetType() const { return mnType
; }
357 AllSettingsFlags
GetFlags() const { return mnFlags
; }
359 const AllSettings
* GetOldSettings() const;
362 inline DataChangedEvent::DataChangedEvent( DataChangedEventType nType
,
364 AllSettingsFlags nChangeFlags
)
366 mpData
= const_cast<void*>(pData
);
367 mnFlags
= nChangeFlags
;
371 inline const AllSettings
* DataChangedEvent::GetOldSettings() const
373 if ( mnType
== DataChangedEventType::SETTINGS
)
374 return static_cast<const AllSettings
*>(mpData
);
379 #endif // INCLUDED_VCL_EVENT_HXX
381 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */