tdf#149529 crash on deref deleted ScDocument*
[LibreOffice.git] / include / vcl / commandevent.hxx
blob883147fad491b00cb42aff3e4f82350e93ab7a87
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_COMMANDEVENT_HXX
21 #define INCLUDED_VCL_COMMANDEVENT_HXX
23 #include <memory>
24 #include <tools/gen.hxx>
25 #include <tools/solar.h>
26 #include <vcl/dllapi.h>
27 #include <vcl/keycodes.hxx>
28 #include <o3tl/typed_flags_set.hxx>
29 #include <rtl/ustring.hxx>
30 #include <vcl/GestureEvent.hxx>
32 class CommandExtTextInputData;
33 class CommandWheelData;
34 class CommandScrollData;
35 class CommandModKeyData;
36 class CommandDialogData;
37 class CommandMediaData;
38 class CommandSelectionChangeData;
39 class CommandSwipeData;
40 class CommandLongPressData;
41 class CommandGestureData;
43 enum class CommandEventId;
45 enum class ExtTextInputAttr {
46 NONE = 0x0000,
47 GrayWaveline = 0x0100,
48 Underline = 0x0200,
49 BoldUnderline = 0x0400,
50 DottedUnderline = 0x0800,
51 DashDotUnderline = 0x1000,
52 Highlight = 0x2000,
53 RedText = 0x4000,
54 HalfToneText = 0x8000
56 namespace o3tl
58 template<> struct typed_flags<ExtTextInputAttr> : is_typed_flags<ExtTextInputAttr, 0xff00> {};
61 #define EXTTEXTINPUT_CURSOR_INVISIBLE (sal_uInt16(0x0001))
62 #define EXTTEXTINPUT_CURSOR_OVERWRITE (sal_uInt16(0x0002))
65 class VCL_DLLPUBLIC CommandEvent
67 private:
68 Point maPos;
69 void* mpData;
70 CommandEventId mnCommand;
71 bool mbMouseEvent;
73 public:
74 CommandEvent();
75 CommandEvent( const Point& rMousePos, CommandEventId nCmd,
76 bool bMEvt = false, const void* pCmdData = nullptr );
78 CommandEventId GetCommand() const { return mnCommand; }
79 const Point& GetMousePosPixel() const { return maPos; }
80 bool IsMouseEvent() const { return mbMouseEvent; }
81 void* GetEventData() const { return mpData; }
83 const CommandExtTextInputData* GetExtTextInputData() const;
84 const CommandWheelData* GetWheelData() const;
85 const CommandScrollData* GetAutoScrollData() const;
86 const CommandModKeyData* GetModKeyData() const;
87 const CommandDialogData* GetDialogData() const;
88 CommandMediaData* GetMediaData() const;
89 const CommandSelectionChangeData* GetSelectionChangeData() const;
90 const CommandSwipeData* GetSwipeData() const;
91 const CommandLongPressData* GetLongPressData() const;
92 const CommandGestureData* GetGestureData() const;
95 class VCL_DLLPUBLIC CommandExtTextInputData
97 private:
98 OUString maText;
99 std::unique_ptr<ExtTextInputAttr[]> mpTextAttr;
100 sal_Int32 mnCursorPos;
101 sal_uInt16 mnCursorFlags;
102 bool mbOnlyCursor;
104 public:
105 CommandExtTextInputData( const OUString& rText,
106 const ExtTextInputAttr* pTextAttr,
107 sal_Int32 nCursorPos,
108 sal_uInt16 nCursorFlags,
109 bool bOnlyCursor );
110 CommandExtTextInputData( const CommandExtTextInputData& rData );
111 ~CommandExtTextInputData();
113 const OUString& GetText() const { return maText; }
114 const ExtTextInputAttr* GetTextAttr() const { return mpTextAttr.get(); }
116 sal_Int32 GetCursorPos() const { return mnCursorPos; }
117 bool IsCursorVisible() const { return (mnCursorFlags & EXTTEXTINPUT_CURSOR_INVISIBLE) == 0; }
118 bool IsCursorOverwrite() const { return (mnCursorFlags & EXTTEXTINPUT_CURSOR_OVERWRITE) != 0; }
119 bool IsOnlyCursorChanged() const { return mbOnlyCursor; }
122 class VCL_DLLPUBLIC CommandInputContextData
126 enum class CommandWheelMode
128 NONE = 0,
129 SCROLL = 1,
130 ZOOM = 2,
131 DATAZOOM = 3
134 // Magic value used in mnLines field in CommandWheelData
135 #define COMMAND_WHEEL_PAGESCROLL (sal_uLong(0xFFFFFFFF))
137 class VCL_DLLPUBLIC CommandWheelData
139 private:
140 tools::Long mnDelta;
141 tools::Long mnNotchDelta;
142 double mnLines;
143 CommandWheelMode mnWheelMode;
144 sal_uInt16 mnCode;
145 bool mbHorz;
146 bool mbDeltaIsPixel;
148 public:
149 CommandWheelData();
150 CommandWheelData( tools::Long nWheelDelta, tools::Long nWheelNotchDelta,
151 double nScrollLines,
152 CommandWheelMode nWheelMode, sal_uInt16 nKeyModifier,
153 bool bHorz, bool bDeltaIsPixel = false );
155 tools::Long GetDelta() const { return mnDelta; }
156 tools::Long GetNotchDelta() const { return mnNotchDelta; }
157 double GetScrollLines() const { return mnLines; }
158 bool IsHorz() const { return mbHorz; }
159 bool IsDeltaPixel() const { return mbDeltaIsPixel; }
161 CommandWheelMode GetMode() const { return mnWheelMode; }
163 sal_uInt16 GetModifier() const
164 { return (mnCode & (KEY_SHIFT | KEY_MOD1 | KEY_MOD2)); }
165 bool IsShift() const
166 { return ((mnCode & KEY_SHIFT) != 0); }
167 bool IsMod1() const
168 { return ((mnCode & KEY_MOD1) != 0); }
169 bool IsMod2() const
170 { return ((mnCode & KEY_MOD2) != 0); }
173 class CommandScrollData
175 private:
176 tools::Long mnDeltaX;
177 tools::Long mnDeltaY;
179 public:
180 CommandScrollData( tools::Long nDeltaX, tools::Long nDeltaY );
182 tools::Long GetDeltaX() const { return mnDeltaX; }
183 tools::Long GetDeltaY() const { return mnDeltaY; }
186 class CommandModKeyData
188 private:
189 bool mbDown;
190 ModKeyFlags mnCode;
192 public:
193 CommandModKeyData( ModKeyFlags nCode, bool bDown );
195 bool IsDown() const { return mbDown; }
196 bool IsMod1() const { return bool(mnCode & ModKeyFlags::Mod1Msk); }
197 bool IsMod2() const { return bool(mnCode & ModKeyFlags::Mod2Msk); }
198 bool IsLeftShift() const { return bool(mnCode & ModKeyFlags::LeftShift); }
199 bool IsRightShift() const { return bool(mnCode & ModKeyFlags::RightShift); }
202 enum class ShowDialogId
204 Preferences = 1,
205 About = 2,
208 class VCL_DLLPUBLIC CommandDialogData
210 ShowDialogId m_nDialogId;
211 public:
212 CommandDialogData( ShowDialogId nDialogId )
213 : m_nDialogId( nDialogId )
216 ShowDialogId GetDialogId() const { return m_nDialogId; }
219 // Media Commands
220 enum class MediaCommand
222 ChannelDown = 1, // Decrement the channel value, for example, for a TV or radio tuner.
223 ChannelUp = 2, // Increment the channel value, for example, for a TV or radio tuner.
224 NextTrack = 3, // Go to next media track/slide.
225 Pause = 4, // Pause. If already paused, take no further action. This is a direct PAUSE command that has no state.
226 Play = 5, // Begin playing at the current position. If already paused, it will resume. This is a direct PLAY command that has no state.
227 PlayPause = 6, // Play or pause playback.
228 PreviousTrack = 7, // Go to previous media track/slide.
229 Record = 8, // Begin recording the current stream.
230 Rewind = 9,// Go backward in a stream at a higher rate of speed.
231 Stop = 10,// Stop playback.
232 MicOnOffToggle = 11,// Toggle the microphone.
233 MicrophoneVolumeDown = 12,// Increase microphone volume.
234 MicrophoneVolumeMute = 13,// Mute the microphone.
235 MicrophoneVolumeUp = 14,// Decrease microphone volume.
236 VolumeDown = 15,// Lower the volume.
237 VolumeMute = 16,// Mute the volume.
238 VolumeUp = 17,// Raise the volume.
239 Menu = 18,// Button Menu pressed.
240 PlayHold = 20,// Button Play (long) pressed.
241 NextTrackHold = 21,// Button Right holding pressed.
244 class VCL_DLLPUBLIC CommandMediaData
246 MediaCommand m_nMediaId;
247 bool m_bPassThroughToOS;
248 public:
249 CommandMediaData(MediaCommand nMediaId)
250 : m_nMediaId(nMediaId)
251 , m_bPassThroughToOS(true)
254 MediaCommand GetMediaId() const { return m_nMediaId; }
255 void SetPassThroughToOS(bool bPassThroughToOS) { m_bPassThroughToOS = bPassThroughToOS; }
256 bool GetPassThroughToOS() const { return m_bPassThroughToOS; }
259 class CommandSelectionChangeData
261 private:
262 sal_uLong mnStart;
263 sal_uLong mnEnd;
265 public:
266 CommandSelectionChangeData( sal_uLong nStart, sal_uLong nEnd );
268 sal_uLong GetStart() const { return mnStart; }
269 sal_uLong GetEnd() const { return mnEnd; }
272 class VCL_DLLPUBLIC CommandSwipeData
274 double mnVelocityX;
275 public:
276 CommandSwipeData()
277 : mnVelocityX(0)
280 CommandSwipeData(double nVelocityX)
281 : mnVelocityX(nVelocityX)
284 double getVelocityX() const { return mnVelocityX; }
288 class VCL_DLLPUBLIC CommandLongPressData
290 double mnX;
291 double mnY;
292 public:
293 CommandLongPressData()
294 : mnX(0)
295 , mnY(0)
298 CommandLongPressData(double nX, double nY)
299 : mnX(nX)
300 , mnY(nY)
303 double getX() const { return mnX; }
304 double getY() const { return mnY; }
307 class VCL_DLLPUBLIC CommandGestureData
309 public:
310 double const mfX;
311 double const mfY;
312 double const mfOffset;
313 GestureEventType const meEventType;
314 PanningOrientation const meOrientation;
316 CommandGestureData(double fX, double fY, GestureEventType eEventType, double fOffset, PanningOrientation eOrientation)
317 : mfX(fX)
318 , mfY(fY)
319 , mfOffset(fOffset)
320 , meEventType(eEventType)
321 , meOrientation(eOrientation)
325 enum class CommandEventId
327 NONE = 0,
328 ContextMenu = 1,
329 StartDrag = 2,
330 Wheel = 3,
331 StartAutoScroll = 4,
332 AutoScroll = 5,
333 StartExtTextInput = 7,
334 ExtTextInput = 8,
335 EndExtTextInput = 9,
336 InputContextChange = 10,
337 CursorPos = 11,
338 PasteSelection = 12,
339 ModKeyChange = 13,
340 InputLanguageChange = 15,
341 ShowDialog = 16,
342 Media = 17,
343 SelectionChange = 18,
344 PrepareReconversion = 19,
345 QueryCharPosition = 20,
346 Swipe = 21,
347 LongPress = 22,
348 Gesture = 23,
351 #endif // INCLUDED_VCL_COMMANDEVENT_HXX
353 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */