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>
33 enum class TextDirectionality
{
34 LeftToRight_TopToBottom
,
35 RightToLeft_TopToBottom
,
36 TopToBottom_RightToLeft
,
37 BottomToTop_LeftToRight
44 class VCL_DLLPUBLIC KeyEvent
47 vcl::KeyCode maKeyCode
;
49 sal_Unicode mnCharCode
;
53 KeyEvent( sal_Unicode nChar
, const vcl::KeyCode
& rKeyCode
,
54 sal_uInt16 nRepeat
= 0 );
56 sal_Unicode
GetCharCode() const { return mnCharCode
; }
57 const vcl::KeyCode
& GetKeyCode() const { return maKeyCode
; }
58 sal_uInt16
GetRepeat() const { return mnRepeat
; }
60 KeyEvent
LogicalTextDirectionality (TextDirectionality eMode
) const;
63 inline KeyEvent::KeyEvent()
69 inline KeyEvent::KeyEvent( sal_Unicode nChar
, const vcl::KeyCode
& rKeyCode
,
70 sal_uInt16 nRepeat
) :
79 enum class MouseEventModifiers
82 // mouse move modifiers
89 MODIFIERCHANGED
= 0x0080,
90 // mouse up/down-button modifiers
98 template<> struct typed_flags
<MouseEventModifiers
> : is_typed_flags
<MouseEventModifiers
, 0xff7> {};
102 #define MOUSE_LEFT (sal_uInt16(0x0001))
103 #define MOUSE_MIDDLE (sal_uInt16(0x0002))
104 #define MOUSE_RIGHT (sal_uInt16(0x0004))
106 class VCL_DLLPUBLIC MouseEvent
110 MouseEventModifiers mnMode
;
114 // Set, if the document relative logic position are available
115 std::optional
<Point
> maLogicPosition
;
118 explicit MouseEvent();
119 explicit MouseEvent( const Point
& rPos
, sal_uInt16 nClicks
= 1,
120 MouseEventModifiers nMode
= MouseEventModifiers::NONE
, sal_uInt16 nButtons
= 0,
121 sal_uInt16 nModifier
= 0 );
123 const Point
& GetPosPixel() const { return maPos
; }
124 MouseEventModifiers
GetMode() const { return mnMode
; }
126 sal_uInt16
GetClicks() const { return mnClicks
; }
128 void setLogicPosition(Point aLogicPosition
)
130 maLogicPosition
= aLogicPosition
;
133 const std::optional
<Point
> & getLogicPosition() const
135 return maLogicPosition
;
138 bool IsEnterWindow() const
139 { return bool(mnMode
& MouseEventModifiers::ENTERWINDOW
); }
140 bool IsLeaveWindow() const
141 { return bool(mnMode
& MouseEventModifiers::LEAVEWINDOW
); }
142 bool IsSynthetic() const
143 { return bool(mnMode
& MouseEventModifiers::SYNTHETIC
); }
144 bool IsModifierChanged() const
145 { return bool(mnMode
& MouseEventModifiers::MODIFIERCHANGED
); }
147 sal_uInt16
GetButtons() const
148 { return (mnCode
& (MOUSE_LEFT
| MOUSE_MIDDLE
| MOUSE_RIGHT
)); }
150 { return ((mnCode
& MOUSE_LEFT
) != 0); }
151 bool IsMiddle() const
152 { return ((mnCode
& MOUSE_MIDDLE
) != 0); }
154 { return ((mnCode
& MOUSE_RIGHT
) != 0); }
156 sal_uInt16
GetModifier() const
157 { return (mnCode
& (KEY_SHIFT
| KEY_MOD1
| KEY_MOD2
)); }
159 { return ((mnCode
& KEY_SHIFT
) != 0); }
161 { return ((mnCode
& KEY_MOD1
) != 0); }
163 { return ((mnCode
& KEY_MOD2
) != 0); }
165 { return ((mnCode
& KEY_MOD3
) != 0); }
168 inline MouseEvent::MouseEvent()
170 mnMode
= MouseEventModifiers::NONE
;
175 inline MouseEvent::MouseEvent( const Point
& rPos
, sal_uInt16 nClicks
,
176 MouseEventModifiers nMode
,
177 sal_uInt16 nButtons
, sal_uInt16 nModifier
) :
182 mnCode
= nButtons
| nModifier
;
185 enum class HelpEventMode
194 template<> struct typed_flags
<HelpEventMode
> : is_typed_flags
<HelpEventMode
, 0x07> {};
197 class VCL_DLLPUBLIC HelpEvent
201 HelpEventMode mnMode
;
202 bool mbKeyboardActivated
;
205 explicit HelpEvent( const Point
& rMousePos
, HelpEventMode nHelpMode
);
207 const Point
& GetMousePosPixel() const { return maPos
; }
208 HelpEventMode
GetMode() const { return mnMode
; }
209 bool KeyboardActivated() const { return mbKeyboardActivated
; }
210 void SetKeyboardActivated( bool bKeyboard
) { mbKeyboardActivated
= bKeyboard
; }
213 inline HelpEvent::HelpEvent( const Point
& rMousePos
, HelpEventMode nHelpMode
) :
217 mbKeyboardActivated
= false;
220 /// Event to pass information for UserDraw() handling eg. in comboboxes.
221 class VCL_DLLPUBLIC UserDrawEvent
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::RenderContext
* pRenderContext
,
233 const tools::Rectangle
& rOutRect
, sal_uInt16 nId
, bool bSelected
= false)
234 : mpRenderContext(pRenderContext
)
235 , maOutRect( rOutRect
)
237 , mbSelected(bSelected
)
241 vcl::RenderContext
* GetRenderContext() const { return mpRenderContext
; }
242 const tools::Rectangle
& GetRect() const { return maOutRect
; }
243 sal_uInt16
GetItemId() const { return mnItemId
; }
244 bool IsSelected() const { return mbSelected
; }
247 class VCL_DLLPUBLIC TrackingEvent
251 TrackingEventFlags mnFlags
;
254 explicit TrackingEvent( const MouseEvent
&,
255 TrackingEventFlags nTrackFlags
= TrackingEventFlags::NONE
);
257 const MouseEvent
& GetMouseEvent() const { return maMEvt
; }
259 bool IsTrackingRepeat() const
260 { return bool(mnFlags
& TrackingEventFlags::Repeat
); }
261 bool IsTrackingEnded() const
262 { return bool(mnFlags
& TrackingEventFlags::End
); }
263 bool IsTrackingCanceled() const
264 { return bool(mnFlags
& TrackingEventFlags::Cancel
); }
267 inline TrackingEvent::TrackingEvent( const MouseEvent
& rMEvt
,
268 TrackingEventFlags nTrackFlags
) :
271 mnFlags
= nTrackFlags
;
275 enum class NotifyEventType
288 class VCL_DLLPUBLIC NotifyEvent
291 VclPtr
<vcl::Window
> mpWindow
;
293 NotifyEventType mnEventType
;
296 NotifyEvent( NotifyEventType nEventType
,
297 vcl::Window
* pWindow
,
298 const void* pEvent
= nullptr );
300 // Avoid implicitly defined copy constructors/assignments for the
301 // DLLPUBLIC class (they may require forward-declared classes used
302 // internally to be defined in places using NotifyEvent)
303 NotifyEvent(const NotifyEvent
&) = delete;
304 NotifyEvent(NotifyEvent
&&) = delete;
305 NotifyEvent
& operator=(const NotifyEvent
&) = delete;
306 NotifyEvent
& operator=(NotifyEvent
&&) = delete;
308 NotifyEventType
GetType() const { return mnEventType
; }
309 vcl::Window
* GetWindow() const { return mpWindow
; }
310 void* GetData() const { return mpData
; }
311 const KeyEvent
* GetKeyEvent() const;
312 const MouseEvent
* GetMouseEvent() const;
313 const CommandEvent
* GetCommandEvent() const;
316 inline const KeyEvent
* NotifyEvent::GetKeyEvent() const
318 if ( (mnEventType
== NotifyEventType::KEYINPUT
) || (mnEventType
== NotifyEventType::KEYUP
) )
319 return static_cast<const KeyEvent
*>(mpData
);
324 inline const MouseEvent
* NotifyEvent::GetMouseEvent() const
326 if ( (mnEventType
>= NotifyEventType::MOUSEBUTTONDOWN
) && (mnEventType
<= NotifyEventType::MOUSEMOVE
) )
327 return static_cast<const MouseEvent
*>(mpData
);
332 inline const CommandEvent
* NotifyEvent::GetCommandEvent() const
334 if ( mnEventType
== NotifyEventType::COMMAND
)
335 return static_cast<const CommandEvent
*>(mpData
);
341 enum class DataChangedEventType
{
350 class VCL_DLLPUBLIC DataChangedEvent
354 AllSettingsFlags mnFlags
;
355 DataChangedEventType mnType
;
358 explicit DataChangedEvent( DataChangedEventType nType
,
359 const void* pData
= nullptr,
360 AllSettingsFlags nFlags
= AllSettingsFlags::NONE
);
362 DataChangedEventType
GetType() const { return mnType
; }
363 AllSettingsFlags
GetFlags() const { return mnFlags
; }
365 const AllSettings
* GetOldSettings() const;
368 inline DataChangedEvent::DataChangedEvent( DataChangedEventType nType
,
370 AllSettingsFlags nChangeFlags
)
372 mpData
= const_cast<void*>(pData
);
373 mnFlags
= nChangeFlags
;
377 inline const AllSettings
* DataChangedEvent::GetOldSettings() const
379 if ( mnType
== DataChangedEventType::SETTINGS
)
380 return static_cast<const AllSettings
*>(mpData
);
385 #endif // INCLUDED_VCL_EVENT_HXX
387 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */