bump product version to 7.6.3.2-android
[LibreOffice.git] / include / vcl / event.hxx
blob58a90b2a764a88f4f6931d11b34ffeb3b784f993
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 <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 <optional>
31 class CommandEvent;
33 enum class TextDirectionality {
34 LeftToRight_TopToBottom,
35 RightToLeft_TopToBottom,
36 TopToBottom_RightToLeft,
37 BottomToTop_LeftToRight
40 namespace vcl {
41 class Window;
44 class VCL_DLLPUBLIC KeyEvent
46 private:
47 vcl::KeyCode maKeyCode;
48 sal_uInt16 mnRepeat;
49 sal_Unicode mnCharCode;
51 public:
52 KeyEvent();
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()
65 mnCharCode = 0;
66 mnRepeat = 0;
69 inline KeyEvent::KeyEvent( sal_Unicode nChar, const vcl::KeyCode& rKeyCode,
70 sal_uInt16 nRepeat ) :
71 maKeyCode( rKeyCode )
74 mnCharCode = nChar;
75 mnRepeat = nRepeat;
79 enum class MouseEventModifiers
81 NONE = 0,
82 // mouse move modifiers
83 SIMPLEMOVE = 0x0001,
84 DRAGMOVE = 0x0002,
85 DRAGCOPY = 0x0004,
86 ENTERWINDOW = 0x0010,
87 LEAVEWINDOW = 0x0020,
88 SYNTHETIC = 0x0040,
89 MODIFIERCHANGED = 0x0080,
90 // mouse up/down-button modifiers
91 SIMPLECLICK = 0x0100,
92 SELECT = 0x0200,
93 MULTISELECT = 0x0400,
94 RANGESELECT = 0x0800
96 namespace o3tl
98 template<> struct typed_flags<MouseEventModifiers> : is_typed_flags<MouseEventModifiers, 0xff7> {};
101 // Mouse buttons
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
108 private:
109 Point maPos;
110 MouseEventModifiers mnMode;
111 sal_uInt16 mnClicks;
112 sal_uInt16 mnCode;
114 // Set, if the document relative logic position are available
115 std::optional<Point> maLogicPosition;
117 public:
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)); }
149 bool IsLeft() const
150 { return ((mnCode & MOUSE_LEFT) != 0); }
151 bool IsMiddle() const
152 { return ((mnCode & MOUSE_MIDDLE) != 0); }
153 bool IsRight() const
154 { return ((mnCode & MOUSE_RIGHT) != 0); }
156 sal_uInt16 GetModifier() const
157 { return (mnCode & (KEY_SHIFT | KEY_MOD1 | KEY_MOD2)); }
158 bool IsShift() const
159 { return ((mnCode & KEY_SHIFT) != 0); }
160 bool IsMod1() const
161 { return ((mnCode & KEY_MOD1) != 0); }
162 bool IsMod2() const
163 { return ((mnCode & KEY_MOD2) != 0); }
164 bool IsMod3() const
165 { return ((mnCode & KEY_MOD3) != 0); }
168 inline MouseEvent::MouseEvent()
170 mnMode = MouseEventModifiers::NONE;
171 mnClicks = 0;
172 mnCode = 0;
175 inline MouseEvent::MouseEvent( const Point& rPos, sal_uInt16 nClicks,
176 MouseEventModifiers nMode,
177 sal_uInt16 nButtons, sal_uInt16 nModifier ) :
178 maPos( rPos )
180 mnClicks = nClicks;
181 mnMode = nMode;
182 mnCode = nButtons | nModifier;
185 enum class HelpEventMode
187 NONE = 0x0000,
188 CONTEXT = 0x0001,
189 BALLOON = 0x0002,
190 QUICK = 0x0004
192 namespace o3tl
194 template<> struct typed_flags<HelpEventMode> : is_typed_flags<HelpEventMode, 0x07> {};
197 class VCL_DLLPUBLIC HelpEvent
199 private:
200 Point maPos;
201 HelpEventMode mnMode;
202 bool mbKeyboardActivated;
204 public:
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 ) :
214 maPos( rMousePos )
216 mnMode = nHelpMode;
217 mbKeyboardActivated = false;
220 /// Event to pass information for UserDraw() handling eg. in comboboxes.
221 class VCL_DLLPUBLIC UserDrawEvent
223 private:
224 /// RenderContext to which we should draw - can be a VirtualDevice or anything.
225 VclPtr<vcl::RenderContext> mpRenderContext;
227 tools::Rectangle maOutRect;
228 sal_uInt16 mnItemId;
229 bool mbSelected;
231 public:
232 UserDrawEvent(vcl::RenderContext* pRenderContext,
233 const tools::Rectangle& rOutRect, sal_uInt16 nId, bool bSelected = false)
234 : mpRenderContext(pRenderContext)
235 , maOutRect( rOutRect )
236 , mnItemId(nId)
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
249 private:
250 MouseEvent maMEvt;
251 TrackingEventFlags mnFlags;
253 public:
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 ) :
269 maMEvt( rMEvt )
271 mnFlags = nTrackFlags;
275 enum class NotifyEventType
277 NONE = 0,
278 MOUSEBUTTONDOWN = 1,
279 MOUSEBUTTONUP = 2,
280 MOUSEMOVE = 3,
281 KEYINPUT = 4,
282 KEYUP = 5,
283 GETFOCUS = 6,
284 LOSEFOCUS = 7,
285 COMMAND = 8
288 class VCL_DLLPUBLIC NotifyEvent
290 private:
291 VclPtr<vcl::Window> mpWindow;
292 void* mpData;
293 NotifyEventType mnEventType;
295 public:
296 NotifyEvent( NotifyEventType nEventType,
297 vcl::Window* pWindow,
298 const void* pEvent = nullptr );
299 ~NotifyEvent();
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);
320 else
321 return nullptr;
324 inline const MouseEvent* NotifyEvent::GetMouseEvent() const
326 if ( (mnEventType >= NotifyEventType::MOUSEBUTTONDOWN) && (mnEventType <= NotifyEventType::MOUSEMOVE) )
327 return static_cast<const MouseEvent*>(mpData);
328 else
329 return nullptr;
332 inline const CommandEvent* NotifyEvent::GetCommandEvent() const
334 if ( mnEventType == NotifyEventType::COMMAND )
335 return static_cast<const CommandEvent*>(mpData);
336 else
337 return nullptr;
341 enum class DataChangedEventType {
342 NONE = 0,
343 SETTINGS = 1,
344 DISPLAY = 2,
345 FONTS = 4,
346 PRINTER = 5,
347 FONTSUBSTITUTION = 6
350 class VCL_DLLPUBLIC DataChangedEvent
352 private:
353 void* mpData;
354 AllSettingsFlags mnFlags;
355 DataChangedEventType mnType;
357 public:
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,
369 const void* pData,
370 AllSettingsFlags nChangeFlags )
372 mpData = const_cast<void*>(pData);
373 mnFlags = nChangeFlags;
374 mnType = nType;
377 inline const AllSettings* DataChangedEvent::GetOldSettings() const
379 if ( mnType == DataChangedEventType::SETTINGS )
380 return static_cast<const AllSettings*>(mpData);
381 else
382 return nullptr;
385 #endif // INCLUDED_VCL_EVENT_HXX
387 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */