cool#6580 sw: fix infinite loop when changing document language
[LibreOffice.git] / include / vcl / event.hxx
blobbd0b5589f375f30cf47249218a0915b30a9dc8cf
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>
31 class CommandEvent;
33 enum class TextDirectionality {
34 LeftToRight_TopToBottom,
35 RightToLeft_TopToBottom,
36 TopToBottom_RightToLeft,
37 BottomToTop_LeftToRight
40 class VCL_DLLPUBLIC KeyEvent
42 private:
43 vcl::KeyCode maKeyCode;
44 sal_uInt16 mnRepeat;
45 sal_Unicode mnCharCode;
47 public:
48 KeyEvent();
49 KeyEvent( sal_Unicode nChar, const vcl::KeyCode& rKeyCode,
50 sal_uInt16 nRepeat = 0 );
52 sal_Unicode GetCharCode() const { return mnCharCode; }
53 const vcl::KeyCode& GetKeyCode() const { return maKeyCode; }
54 sal_uInt16 GetRepeat() const { return mnRepeat; }
56 KeyEvent LogicalTextDirectionality (TextDirectionality eMode) const;
59 inline KeyEvent::KeyEvent()
61 mnCharCode = 0;
62 mnRepeat = 0;
65 inline KeyEvent::KeyEvent( sal_Unicode nChar, const vcl::KeyCode& rKeyCode,
66 sal_uInt16 nRepeat ) :
67 maKeyCode( rKeyCode )
70 mnCharCode = nChar;
71 mnRepeat = nRepeat;
75 enum class MouseEventModifiers
77 NONE = 0,
78 // mouse move modifiers
79 SIMPLEMOVE = 0x0001,
80 DRAGMOVE = 0x0002,
81 DRAGCOPY = 0x0004,
82 ENTERWINDOW = 0x0010,
83 LEAVEWINDOW = 0x0020,
84 SYNTHETIC = 0x0040,
85 MODIFIERCHANGED = 0x0080,
86 // mouse up/down-button modifiers
87 SIMPLECLICK = 0x0100,
88 SELECT = 0x0200,
89 MULTISELECT = 0x0400,
90 RANGESELECT = 0x0800
92 namespace o3tl
94 template<> struct typed_flags<MouseEventModifiers> : is_typed_flags<MouseEventModifiers, 0xff7> {};
97 // Mouse buttons
98 #define MOUSE_LEFT (sal_uInt16(0x0001))
99 #define MOUSE_MIDDLE (sal_uInt16(0x0002))
100 #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 public:
112 explicit MouseEvent();
113 explicit MouseEvent( const Point& rPos, sal_uInt16 nClicks = 1,
114 MouseEventModifiers nMode = MouseEventModifiers::NONE, sal_uInt16 nButtons = 0,
115 sal_uInt16 nModifier = 0 );
117 const Point& GetPosPixel() const { return maPos; }
118 MouseEventModifiers GetMode() const { return mnMode; }
120 sal_uInt16 GetClicks() const { return mnClicks; }
122 bool IsEnterWindow() const
123 { return bool(mnMode & MouseEventModifiers::ENTERWINDOW); }
124 bool IsLeaveWindow() const
125 { return bool(mnMode & MouseEventModifiers::LEAVEWINDOW); }
126 bool IsSynthetic() const
127 { return bool(mnMode & MouseEventModifiers::SYNTHETIC); }
128 bool IsModifierChanged() const
129 { return bool(mnMode & MouseEventModifiers::MODIFIERCHANGED); }
131 sal_uInt16 GetButtons() const
132 { return (mnCode & (MOUSE_LEFT | MOUSE_MIDDLE | MOUSE_RIGHT)); }
133 bool IsLeft() const
134 { return ((mnCode & MOUSE_LEFT) != 0); }
135 bool IsMiddle() const
136 { return ((mnCode & MOUSE_MIDDLE) != 0); }
137 bool IsRight() const
138 { return ((mnCode & MOUSE_RIGHT) != 0); }
140 sal_uInt16 GetModifier() const
141 { return (mnCode & (KEY_SHIFT | KEY_MOD1 | KEY_MOD2)); }
142 bool IsShift() const
143 { return ((mnCode & KEY_SHIFT) != 0); }
144 bool IsMod1() const
145 { return ((mnCode & KEY_MOD1) != 0); }
146 bool IsMod2() const
147 { return ((mnCode & KEY_MOD2) != 0); }
148 bool IsMod3() const
149 { return ((mnCode & KEY_MOD3) != 0); }
152 inline MouseEvent::MouseEvent()
154 mnMode = MouseEventModifiers::NONE;
155 mnClicks = 0;
156 mnCode = 0;
159 inline MouseEvent::MouseEvent( const Point& rPos, sal_uInt16 nClicks,
160 MouseEventModifiers nMode,
161 sal_uInt16 nButtons, sal_uInt16 nModifier ) :
162 maPos( rPos )
164 mnClicks = nClicks;
165 mnMode = nMode;
166 mnCode = nButtons | nModifier;
169 enum class HelpEventMode
171 NONE = 0x0000,
172 CONTEXT = 0x0001,
173 BALLOON = 0x0002,
174 QUICK = 0x0004
176 namespace o3tl
178 template<> struct typed_flags<HelpEventMode> : is_typed_flags<HelpEventMode, 0x07> {};
181 class VCL_DLLPUBLIC HelpEvent
183 private:
184 Point const maPos;
185 HelpEventMode mnMode;
186 bool mbKeyboardActivated;
188 public:
189 explicit HelpEvent( const Point& rMousePos, HelpEventMode nHelpMode );
191 const Point& GetMousePosPixel() const { return maPos; }
192 HelpEventMode GetMode() const { return mnMode; }
193 bool KeyboardActivated() const { return mbKeyboardActivated; }
194 void SetKeyboardActivated( bool bKeyboard ) { mbKeyboardActivated = bKeyboard; }
197 inline HelpEvent::HelpEvent( const Point& rMousePos, HelpEventMode nHelpMode ) :
198 maPos( rMousePos )
200 mnMode = nHelpMode;
201 mbKeyboardActivated = false;
204 /// Event to pass information for UserDraw() handling eg. in comboboxes.
205 class VCL_DLLPUBLIC UserDrawEvent
207 private:
208 /// Window that owns the user draw.
209 VclPtr<vcl::Window> mpWindow;
211 /// RenderContext to which we should draw - can be a VirtualDevice or anything.
212 VclPtr<vcl::RenderContext> mpRenderContext;
214 tools::Rectangle const maOutRect;
215 sal_uInt16 const mnItemId;
216 sal_uInt16 const mnStyle;
218 public:
219 UserDrawEvent(vcl::Window* pWindow, vcl::RenderContext* pRenderContext,
220 const tools::Rectangle& rOutRect, sal_uInt16 nId, sal_uInt16 nStyle = 0);
222 vcl::Window* GetWindow() const { return mpWindow; }
223 vcl::RenderContext* GetRenderContext() const { return mpRenderContext; }
224 const tools::Rectangle& GetRect() const { return maOutRect; }
225 sal_uInt16 GetItemId() const { return mnItemId; }
226 sal_uInt16 GetStyle() const { return mnStyle; }
229 inline UserDrawEvent::UserDrawEvent(vcl::Window* pWindow, vcl::RenderContext* pRenderContext,
230 const tools::Rectangle& rOutRect, sal_uInt16 nId, sal_uInt16 nStyle)
231 : mpWindow(pWindow)
232 , mpRenderContext(pRenderContext)
233 , maOutRect( rOutRect )
234 , mnItemId(nId)
235 , mnStyle(nStyle)
240 class VCL_DLLPUBLIC TrackingEvent
242 private:
243 MouseEvent const maMEvt;
244 TrackingEventFlags mnFlags;
246 public:
247 explicit TrackingEvent( const MouseEvent&,
248 TrackingEventFlags nTrackFlags = TrackingEventFlags::NONE );
250 const MouseEvent& GetMouseEvent() const { return maMEvt; }
252 bool IsTrackingRepeat() const
253 { return bool(mnFlags & TrackingEventFlags::Repeat); }
254 bool IsTrackingEnded() const
255 { return bool(mnFlags & TrackingEventFlags::End); }
256 bool IsTrackingCanceled() const
257 { return bool(mnFlags & TrackingEventFlags::Cancel); }
260 inline TrackingEvent::TrackingEvent( const MouseEvent& rMEvt,
261 TrackingEventFlags nTrackFlags ) :
262 maMEvt( rMEvt )
264 mnFlags = nTrackFlags;
268 enum class MouseNotifyEvent
270 NONE = 0,
271 MOUSEBUTTONDOWN = 1,
272 MOUSEBUTTONUP = 2,
273 MOUSEMOVE = 3,
274 KEYINPUT = 4,
275 KEYUP = 5,
276 GETFOCUS = 6,
277 LOSEFOCUS = 7,
278 COMMAND = 8,
279 INPUTENABLE = 10
282 class VCL_DLLPUBLIC NotifyEvent
284 private:
285 VclPtr<vcl::Window> mpWindow;
286 void* mpData;
287 MouseNotifyEvent mnEventType;
289 public:
290 NotifyEvent( MouseNotifyEvent nEventType,
291 vcl::Window* pWindow,
292 const void* pEvent = nullptr );
294 MouseNotifyEvent GetType() const { return mnEventType; }
295 vcl::Window* GetWindow() const { return mpWindow; }
296 void* GetData() const { return mpData; }
297 const KeyEvent* GetKeyEvent() const;
298 const MouseEvent* GetMouseEvent() const;
299 const CommandEvent* GetCommandEvent() const;
302 inline const KeyEvent* NotifyEvent::GetKeyEvent() const
304 if ( (mnEventType == MouseNotifyEvent::KEYINPUT) || (mnEventType == MouseNotifyEvent::KEYUP) )
305 return static_cast<const KeyEvent*>(mpData);
306 else
307 return nullptr;
310 inline const MouseEvent* NotifyEvent::GetMouseEvent() const
312 if ( (mnEventType >= MouseNotifyEvent::MOUSEBUTTONDOWN) && (mnEventType <= MouseNotifyEvent::MOUSEMOVE) )
313 return static_cast<const MouseEvent*>(mpData);
314 else
315 return nullptr;
318 inline const CommandEvent* NotifyEvent::GetCommandEvent() const
320 if ( mnEventType == MouseNotifyEvent::COMMAND )
321 return static_cast<const CommandEvent*>(mpData);
322 else
323 return nullptr;
327 enum class DataChangedEventType {
328 NONE = 0,
329 SETTINGS = 1,
330 DISPLAY = 2,
331 FONTS = 4,
332 PRINTER = 5,
333 FONTSUBSTITUTION = 6
336 class VCL_DLLPUBLIC DataChangedEvent
338 private:
339 void* mpData;
340 AllSettingsFlags mnFlags;
341 DataChangedEventType mnType;
343 public:
344 explicit DataChangedEvent( DataChangedEventType nType,
345 const void* pData = nullptr,
346 AllSettingsFlags nFlags = AllSettingsFlags::NONE );
348 DataChangedEventType GetType() const { return mnType; }
349 AllSettingsFlags GetFlags() const { return mnFlags; }
351 const AllSettings* GetOldSettings() const;
354 inline DataChangedEvent::DataChangedEvent( DataChangedEventType nType,
355 const void* pData,
356 AllSettingsFlags nChangeFlags )
358 mpData = const_cast<void*>(pData);
359 mnFlags = nChangeFlags;
360 mnType = nType;
363 inline const AllSettings* DataChangedEvent::GetOldSettings() const
365 if ( mnType == DataChangedEventType::SETTINGS )
366 return static_cast<const AllSettings*>(mpData);
367 else
368 return nullptr;
371 #endif // INCLUDED_VCL_EVENT_HXX
373 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */