vcl: 'horizontically'
[LibreOffice.git] / include / vcl / event.hxx
blob9173ce0e7d00f48206d0229bbb38daf61c6fd863
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 <vcl/window.hxx>
30 #include <optional>
32 class CommandEvent;
34 enum class TextDirectionality {
35 LeftToRight_TopToBottom,
36 RightToLeft_TopToBottom,
37 TopToBottom_RightToLeft,
38 BottomToTop_LeftToRight
41 class VCL_DLLPUBLIC KeyEvent
43 private:
44 vcl::KeyCode maKeyCode;
45 sal_uInt16 mnRepeat;
46 sal_Unicode mnCharCode;
48 public:
49 KeyEvent();
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()
62 mnCharCode = 0;
63 mnRepeat = 0;
66 inline KeyEvent::KeyEvent( sal_Unicode nChar, const vcl::KeyCode& rKeyCode,
67 sal_uInt16 nRepeat ) :
68 maKeyCode( rKeyCode )
71 mnCharCode = nChar;
72 mnRepeat = nRepeat;
76 enum class MouseEventModifiers
78 NONE = 0,
79 // mouse move modifiers
80 SIMPLEMOVE = 0x0001,
81 DRAGMOVE = 0x0002,
82 DRAGCOPY = 0x0004,
83 ENTERWINDOW = 0x0010,
84 LEAVEWINDOW = 0x0020,
85 SYNTHETIC = 0x0040,
86 MODIFIERCHANGED = 0x0080,
87 // mouse up/down-button modifiers
88 SIMPLECLICK = 0x0100,
89 SELECT = 0x0200,
90 MULTISELECT = 0x0400,
91 RANGESELECT = 0x0800
93 namespace o3tl
95 template<> struct typed_flags<MouseEventModifiers> : is_typed_flags<MouseEventModifiers, 0xff7> {};
98 // Mouse buttons
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
105 private:
106 Point maPos;
107 MouseEventModifiers mnMode;
108 sal_uInt16 mnClicks;
109 sal_uInt16 mnCode;
111 // Set, if the document relative logic position are available
112 std::optional<Point> maLogicPosition;
114 public:
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)); }
146 bool IsLeft() const
147 { return ((mnCode & MOUSE_LEFT) != 0); }
148 bool IsMiddle() const
149 { return ((mnCode & MOUSE_MIDDLE) != 0); }
150 bool IsRight() const
151 { return ((mnCode & MOUSE_RIGHT) != 0); }
153 sal_uInt16 GetModifier() const
154 { return (mnCode & (KEY_SHIFT | KEY_MOD1 | KEY_MOD2)); }
155 bool IsShift() const
156 { return ((mnCode & KEY_SHIFT) != 0); }
157 bool IsMod1() const
158 { return ((mnCode & KEY_MOD1) != 0); }
159 bool IsMod2() const
160 { return ((mnCode & KEY_MOD2) != 0); }
161 bool IsMod3() const
162 { return ((mnCode & KEY_MOD3) != 0); }
165 inline MouseEvent::MouseEvent()
167 mnMode = MouseEventModifiers::NONE;
168 mnClicks = 0;
169 mnCode = 0;
172 inline MouseEvent::MouseEvent( const Point& rPos, sal_uInt16 nClicks,
173 MouseEventModifiers nMode,
174 sal_uInt16 nButtons, sal_uInt16 nModifier ) :
175 maPos( rPos )
177 mnClicks = nClicks;
178 mnMode = nMode;
179 mnCode = nButtons | nModifier;
182 enum class HelpEventMode
184 NONE = 0x0000,
185 CONTEXT = 0x0001,
186 BALLOON = 0x0002,
187 QUICK = 0x0004
189 namespace o3tl
191 template<> struct typed_flags<HelpEventMode> : is_typed_flags<HelpEventMode, 0x07> {};
194 class VCL_DLLPUBLIC HelpEvent
196 private:
197 Point maPos;
198 HelpEventMode mnMode;
199 bool mbKeyboardActivated;
201 public:
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 ) :
211 maPos( rMousePos )
213 mnMode = nHelpMode;
214 mbKeyboardActivated = false;
217 /// Event to pass information for UserDraw() handling eg. in comboboxes.
218 class VCL_DLLPUBLIC UserDrawEvent
220 private:
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;
228 sal_uInt16 mnItemId;
229 bool mbSelected;
231 public:
232 UserDrawEvent(vcl::Window* pWindow, vcl::RenderContext* pRenderContext,
233 const tools::Rectangle& rOutRect, sal_uInt16 nId, bool bSelected = false)
234 : mpWindow(pWindow)
235 , mpRenderContext(pRenderContext)
236 , maOutRect( rOutRect )
237 , mnItemId(nId)
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
251 private:
252 MouseEvent maMEvt;
253 TrackingEventFlags mnFlags;
255 public:
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 ) :
271 maMEvt( rMEvt )
273 mnFlags = nTrackFlags;
277 enum class MouseNotifyEvent
279 NONE = 0,
280 MOUSEBUTTONDOWN = 1,
281 MOUSEBUTTONUP = 2,
282 MOUSEMOVE = 3,
283 KEYINPUT = 4,
284 KEYUP = 5,
285 GETFOCUS = 6,
286 LOSEFOCUS = 7,
287 COMMAND = 8
290 class VCL_DLLPUBLIC NotifyEvent
292 private:
293 VclPtr<vcl::Window> mpWindow;
294 void* mpData;
295 MouseNotifyEvent mnEventType;
297 public:
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);
314 else
315 return nullptr;
318 inline const MouseEvent* NotifyEvent::GetMouseEvent() const
320 if ( (mnEventType >= MouseNotifyEvent::MOUSEBUTTONDOWN) && (mnEventType <= MouseNotifyEvent::MOUSEMOVE) )
321 return static_cast<const MouseEvent*>(mpData);
322 else
323 return nullptr;
326 inline const CommandEvent* NotifyEvent::GetCommandEvent() const
328 if ( mnEventType == MouseNotifyEvent::COMMAND )
329 return static_cast<const CommandEvent*>(mpData);
330 else
331 return nullptr;
335 enum class DataChangedEventType {
336 NONE = 0,
337 SETTINGS = 1,
338 DISPLAY = 2,
339 FONTS = 4,
340 PRINTER = 5,
341 FONTSUBSTITUTION = 6
344 class VCL_DLLPUBLIC DataChangedEvent
346 private:
347 void* mpData;
348 AllSettingsFlags mnFlags;
349 DataChangedEventType mnType;
351 public:
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,
363 const void* pData,
364 AllSettingsFlags nChangeFlags )
366 mpData = const_cast<void*>(pData);
367 mnFlags = nChangeFlags;
368 mnType = nType;
371 inline const AllSettings* DataChangedEvent::GetOldSettings() const
373 if ( mnType == DataChangedEventType::SETTINGS )
374 return static_cast<const AllSettings*>(mpData);
375 else
376 return nullptr;
379 #endif // INCLUDED_VCL_EVENT_HXX
381 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */