1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 #ifndef _SV_EVENT_HXX
25 #define _SV_EVENT_HXX
26
27 #include <vcl/sv.h>
28 #include <vcl/dllapi.h>
29 #include <tools/gen.hxx>
30 #include <vcl/keycod.hxx>
31 #include <vcl/cmdevt.hxx>
32
33 class AllSettings;
34 class OutputDevice;
35 class Window;
36 struct IDataObject;
37
38 namespace com { namespace sun { namespace star { namespace awt {
39 struct KeyEvent;
40 struct MouseEvent;
41 } } } }
42
43 enum TextDirectionality {
44 TextDirectionality_LeftToRight_TopToBottom,
45 TextDirectionality_RightToLeft_TopToBottom,
46 TextDirectionality_TopToBottom_RightToLeft
47 };
48
49 // ------------
50 // - KeyEvent -
51 // ------------
52 class VCL_DLLPUBLIC KeyEvent
53 {
54 private:
55 KeyCode maKeyCode;
56 sal_uInt16 mnRepeat;
57 xub_Unicode mnCharCode;
58
59 public:
60 KeyEvent();
61 KeyEvent( xub_Unicode nChar, const KeyCode& rKeyCode,
62 sal_uInt16 nRepeat = 0 );
63
64 /** inits this vcl KeyEvent with all settings from the given awt event **/
65 KeyEvent( const ::com::sun::star::awt::KeyEvent& rEvent );
66
67 /** fills out the given awt KeyEvent with all settings from this vcl event **/
68 void InitKeyEvent( ::com::sun::star::awt::KeyEvent& rEvent ) const;
69
GetCharCode() const70 xub_Unicode GetCharCode() const { return mnCharCode; }
GetKeyCode() const71 const KeyCode& GetKeyCode() const { return maKeyCode; }
GetRepeat() const72 sal_uInt16 GetRepeat() const { return mnRepeat; }
73
74 KeyEvent LogicalTextDirectionality (TextDirectionality eMode) const;
75 KeyEvent (const KeyEvent& rKeyEvent);
76
77 };
78
KeyEvent()79 inline KeyEvent::KeyEvent()
80 {
81 mnCharCode = 0;
82 mnRepeat = 0;
83 }
84
KeyEvent(xub_Unicode nChar,const KeyCode & rKeyCode,sal_uInt16 nRepeat)85 inline KeyEvent::KeyEvent( xub_Unicode nChar, const KeyCode& rKeyCode,
86 sal_uInt16 nRepeat ) :
87 maKeyCode( rKeyCode )
88
89 {
90 mnCharCode = nChar;
91 mnRepeat = nRepeat;
92 }
93
94 // --------------------
95 // - MouseEvent-Types -
96 // --------------------
97
98 // Maus-Move-Modi
99 #define MOUSE_SIMPLEMOVE ((sal_uInt16)0x0001)
100 #define MOUSE_DRAGMOVE ((sal_uInt16)0x0002)
101 #define MOUSE_DRAGCOPY ((sal_uInt16)0x0004)
102 #define MOUSE_ENTERWINDOW ((sal_uInt16)0x0010)
103 #define MOUSE_LEAVEWINDOW ((sal_uInt16)0x0020)
104 #define MOUSE_SYNTHETIC ((sal_uInt16)0x0040)
105 #define MOUSE_MODIFIERCHANGED ((sal_uInt16)0x0080)
106
107 // Maus-Button-Down/Up-Modi
108 #define MOUSE_SIMPLECLICK ((sal_uInt16)0x0001)
109 #define MOUSE_SELECT ((sal_uInt16)0x0002)
110 #define MOUSE_MULTISELECT ((sal_uInt16)0x0004)
111 #define MOUSE_RANGESELECT ((sal_uInt16)0x0008)
112
113 // Maus-Buttons
114 #define MOUSE_LEFT ((sal_uInt16)0x0001)
115 #define MOUSE_MIDDLE ((sal_uInt16)0x0002)
116 #define MOUSE_RIGHT ((sal_uInt16)0x0004)
117
118 // --------------
119 // - MouseEvent -
120 // --------------
121
122 class VCL_DLLPUBLIC MouseEvent
123 {
124 private:
125 Point maPos;
126 sal_uInt16 mnMode;
127 sal_uInt16 mnClicks;
128 sal_uInt16 mnCode;
129
130 public:
131 explicit MouseEvent();
132 explicit MouseEvent( const Point& rPos, sal_uInt16 nClicks = 1,
133 sal_uInt16 nMode = 0, sal_uInt16 nButtons = 0,
134 sal_uInt16 nModifier = 0 );
135
GetPosPixel() const136 const Point& GetPosPixel() const { return maPos; }
GetMode() const137 sal_uInt16 GetMode() const { return mnMode; }
138 /** inits this vcl KeyEvent with all settings from the given awt event **/
139 MouseEvent( const ::com::sun::star::awt::MouseEvent& rEvent );
140
141 /** fills out the given awt KeyEvent with all settings from this vcl event **/
142 void InitMouseEvent( ::com::sun::star::awt::MouseEvent& rEvent ) const;
143
GetClicks() const144 sal_uInt16 GetClicks() const { return mnClicks; }
145
IsEnterWindow() const146 sal_Bool IsEnterWindow() const
147 { return ((mnMode & MOUSE_ENTERWINDOW) != 0); }
IsLeaveWindow() const148 sal_Bool IsLeaveWindow() const
149 { return ((mnMode & MOUSE_LEAVEWINDOW) != 0); }
IsSynthetic() const150 sal_Bool IsSynthetic() const
151 { return ((mnMode & MOUSE_SYNTHETIC) != 0); }
IsModifierChanged() const152 sal_Bool IsModifierChanged() const
153 { return ((mnMode & MOUSE_MODIFIERCHANGED) != 0); }
154
GetButtons() const155 sal_uInt16 GetButtons() const
156 { return (mnCode & (MOUSE_LEFT | MOUSE_MIDDLE | MOUSE_RIGHT)); }
IsLeft() const157 sal_Bool IsLeft() const
158 { return ((mnCode & MOUSE_LEFT) != 0); }
IsMiddle() const159 sal_Bool IsMiddle() const
160 { return ((mnCode & MOUSE_MIDDLE) != 0); }
IsRight() const161 sal_Bool IsRight() const
162 { return ((mnCode & MOUSE_RIGHT) != 0); }
163
GetModifier() const164 sal_uInt16 GetModifier() const
165 { return (mnCode & (KEY_SHIFT | KEY_MOD1 | KEY_MOD2)); }
IsShift() const166 sal_Bool IsShift() const
167 { return ((mnCode & KEY_SHIFT) != 0); }
IsMod1() const168 sal_Bool IsMod1() const
169 { return ((mnCode & KEY_MOD1) != 0); }
IsMod2() const170 sal_Bool IsMod2() const
171 { return ((mnCode & KEY_MOD2) != 0); }
IsMod3() const172 sal_Bool IsMod3() const
173 { return ((mnCode & KEY_MOD3) != 0); }
174 };
175
MouseEvent()176 inline MouseEvent::MouseEvent()
177 {
178 mnMode = 0;
179 mnClicks = 0;
180 mnCode = 0;
181 }
182
MouseEvent(const Point & rPos,sal_uInt16 nClicks,sal_uInt16 nMode,sal_uInt16 nButtons,sal_uInt16 nModifier)183 inline MouseEvent::MouseEvent( const Point& rPos, sal_uInt16 nClicks,
184 sal_uInt16 nMode,
185 sal_uInt16 nButtons, sal_uInt16 nModifier ) :
186 maPos( rPos )
187 {
188 mnClicks = nClicks;
189 mnMode = nMode;
190 mnCode = nButtons | nModifier;
191 }
192
193 // -------------
194 // - HelpEvent -
195 // -------------
196
197 #define HELPMODE_CONTEXT ((sal_uInt16)0x0001)
198 #define HELPMODE_EXTENDED ((sal_uInt16)0x0002)
199 #define HELPMODE_BALLOON ((sal_uInt16)0x0004)
200 #define HELPMODE_QUICK ((sal_uInt16)0x0008)
201
202 class VCL_DLLPUBLIC HelpEvent
203 {
204 private:
205 Point maPos;
206 sal_uInt16 mnMode;
207 sal_Bool mbKeyboardActivated;
208
209 public:
210 explicit HelpEvent();
211 explicit HelpEvent( sal_uInt16 nHelpMode );
212 explicit HelpEvent( const Point& rMousePos, sal_uInt16 nHelpMode );
213
214 const Point& GetMousePosPixel() const;
GetMode() const215 sal_uInt16 GetMode() const { return mnMode; }
KeyboardActivated() const216 sal_Bool KeyboardActivated() const { return mbKeyboardActivated; }
SetKeyboardActivated(sal_Bool bKeyboard)217 void SetKeyboardActivated( sal_Bool bKeyboard ) { mbKeyboardActivated = bKeyboard; }
218 };
219
HelpEvent()220 inline HelpEvent::HelpEvent()
221 {
222 mnMode = HELPMODE_CONTEXT;
223 mbKeyboardActivated = sal_True;
224 }
225
HelpEvent(const Point & rMousePos,sal_uInt16 nHelpMode)226 inline HelpEvent::HelpEvent( const Point& rMousePos, sal_uInt16 nHelpMode ) :
227 maPos( rMousePos )
228 {
229 mnMode = nHelpMode;
230 mbKeyboardActivated = sal_False;
231 }
232
HelpEvent(sal_uInt16 nHelpMode)233 inline HelpEvent::HelpEvent( sal_uInt16 nHelpMode )
234 {
235 mnMode = nHelpMode;
236 mbKeyboardActivated = sal_True;
237 }
238
239 // -----------------
240 // - UserDrawEvent -
241 // -----------------
242
243 class VCL_DLLPUBLIC UserDrawEvent
244 {
245 private:
246 OutputDevice* mpOutDev;
247 Rectangle maOutRect;
248 sal_uInt16 mnItemId;
249 sal_uInt16 mnStyle;
250
251 public:
252 UserDrawEvent();
253 UserDrawEvent( OutputDevice* pOut,
254 const Rectangle& rOutRect,
255 sal_uInt16 nId, sal_uInt16 nStyle = 0 );
256
GetDevice() const257 OutputDevice* GetDevice() const { return mpOutDev; }
GetRect() const258 const Rectangle& GetRect() const { return maOutRect; }
GetItemId() const259 sal_uInt16 GetItemId() const { return mnItemId; }
GetStyle() const260 sal_uInt16 GetStyle() const { return mnStyle; }
261 };
262
UserDrawEvent()263 inline UserDrawEvent::UserDrawEvent()
264 {
265 mpOutDev = NULL;
266 mnItemId = 0;
267 mnStyle = 0;
268 }
269
UserDrawEvent(OutputDevice * pOut,const Rectangle & rOutRect,sal_uInt16 nId,sal_uInt16 nStyle)270 inline UserDrawEvent::UserDrawEvent( OutputDevice* pOut,
271 const Rectangle& rOutRect,
272 sal_uInt16 nId, sal_uInt16 nStyle ) :
273 maOutRect( rOutRect )
274 {
275 mpOutDev = pOut;
276 mnItemId = nId;
277 mnStyle = nStyle;
278 }
279
280 // ------------------
281 // - Tracking-Types -
282 // ------------------
283
284 #define ENDTRACK_CANCEL ((sal_uInt16)0x0001)
285 #define ENDTRACK_KEY ((sal_uInt16)0x0002)
286 #define ENDTRACK_FOCUS ((sal_uInt16)0x0004)
287 #define ENDTRACK_END ((sal_uInt16)0x1000)
288 #define ENDTRACK_DONTCALLHDL ((sal_uInt16)0x8000)
289
290 #define TRACKING_REPEAT ((sal_uInt16)0x0100)
291
292 // -----------------
293 // - TrackingEvent -
294 // -----------------
295
296 class VCL_DLLPUBLIC TrackingEvent
297 {
298 private:
299 MouseEvent maMEvt;
300 sal_uInt16 mnFlags;
301
302 public:
303 explicit TrackingEvent();
304 explicit TrackingEvent( const MouseEvent&,
305 sal_uInt16 nTrackFlags = 0 );
306
GetMouseEvent() const307 const MouseEvent& GetMouseEvent() const { return maMEvt; }
308
IsTrackingRepeat() const309 sal_Bool IsTrackingRepeat() const
310 { return ((mnFlags & TRACKING_REPEAT) != 0); }
311
IsTrackingEnded() const312 sal_Bool IsTrackingEnded() const
313 { return ((mnFlags & ENDTRACK_END) != 0); }
IsTrackingCanceled() const314 sal_Bool IsTrackingCanceled() const
315 { return ((mnFlags & ENDTRACK_CANCEL) != 0); }
GetTrackingFlags() const316 sal_uInt16 GetTrackingFlags() const { return mnFlags; }
317 };
318
TrackingEvent()319 inline TrackingEvent::TrackingEvent()
320 {
321 mnFlags = 0;
322 }
323
TrackingEvent(const MouseEvent & rMEvt,sal_uInt16 nTrackFlags)324 inline TrackingEvent::TrackingEvent( const MouseEvent& rMEvt,
325 sal_uInt16 nTrackFlags ) :
326 maMEvt( rMEvt )
327 {
328 mnFlags = nTrackFlags;
329 }
330
331 // ---------------
332 // - NotifyEvent -
333 // ---------------
334
335 #define EVENT_MOUSEBUTTONDOWN 1
336 #define EVENT_MOUSEBUTTONUP 2
337 #define EVENT_MOUSEMOVE 3
338 #define EVENT_KEYINPUT 4
339 #define EVENT_KEYUP 5
340 #define EVENT_GETFOCUS 6
341 #define EVENT_LOSEFOCUS 7
342 #define EVENT_COMMAND 8
343 #define EVENT_DESTROY 9
344 #define EVENT_INPUTENABLE 10
345 #define EVENT_INPUTDISABLE 11
346 #define EVENT_EXECUTEDIALOG 100
347 #define EVENT_ENDEXECUTEDIALOG 101
348 #define EVENT_USER 10000
349
350 class VCL_DLLPUBLIC NotifyEvent
351 {
352 private:
353 Window* mpWindow;
354 void* mpData;
355 sal_uInt16 mnType;
356 long mnRetValue;
357
358 public:
359 NotifyEvent();
360 NotifyEvent( sal_uInt16 nType,
361 Window* pWindow,
362 const void* pEvent = NULL,
363 long nRet = 0 );
364
GetType() const365 sal_uInt16 GetType() const { return mnType; }
GetWindow() const366 Window* GetWindow() const { return mpWindow; }
GetData() const367 void* GetData() const { return mpData; }
368
SetReturnValue(long nRet)369 void SetReturnValue( long nRet ) { mnRetValue = nRet; }
GetReturnValue() const370 long GetReturnValue() const { return mnRetValue; }
371
372 const KeyEvent* GetKeyEvent() const;
373 const MouseEvent* GetMouseEvent() const;
374 const CommandEvent* GetCommandEvent() const;
375 };
376
NotifyEvent()377 inline NotifyEvent::NotifyEvent()
378 {
379 mpWindow = NULL;
380 mpData = NULL;
381 mnType = 0;
382 mnRetValue = 0;
383 }
384
NotifyEvent(sal_uInt16 nType,Window * pWindow,const void * pEvent,long nRet)385 inline NotifyEvent::NotifyEvent( sal_uInt16 nType, Window* pWindow,
386 const void* pEvent, long nRet )
387 {
388 mpWindow = pWindow;
389 mpData = (void*)pEvent;
390 mnType = nType;
391 mnRetValue = nRet;
392 }
393
GetKeyEvent() const394 inline const KeyEvent* NotifyEvent::GetKeyEvent() const
395 {
396 if ( (mnType == EVENT_KEYINPUT) || (mnType == EVENT_KEYUP) )
397 return (const KeyEvent*)mpData;
398 else
399 return NULL;
400 }
401
GetMouseEvent() const402 inline const MouseEvent* NotifyEvent::GetMouseEvent() const
403 {
404 if ( (mnType >= EVENT_MOUSEBUTTONDOWN) && (mnType <= EVENT_MOUSEMOVE) )
405 return (const MouseEvent*)mpData;
406 else
407 return NULL;
408 }
409
GetCommandEvent() const410 inline const CommandEvent* NotifyEvent::GetCommandEvent() const
411 {
412 if ( mnType == EVENT_COMMAND )
413 return (const CommandEvent*)mpData;
414 else
415 return NULL;
416 }
417
418 // --------------------
419 // - DataChangedEvent -
420 // --------------------
421
422 #define DATACHANGED_SETTINGS ((sal_uInt16)1)
423 #define DATACHANGED_DISPLAY ((sal_uInt16)2)
424 #define DATACHANGED_DATETIME ((sal_uInt16)3)
425 #define DATACHANGED_FONTS ((sal_uInt16)4)
426 #define DATACHANGED_PRINTER ((sal_uInt16)5)
427 #define DATACHANGED_FONTSUBSTITUTION ((sal_uInt16)6)
428 #define DATACHANGED_USER ((sal_uInt16)10000)
429
430 class VCL_DLLPUBLIC DataChangedEvent
431 {
432 private:
433 void* mpData;
434 sal_uLong mnFlags;
435 sal_uInt16 mnType;
436
437 public:
438 explicit DataChangedEvent();
439 explicit DataChangedEvent( sal_uInt16 nType,
440 const void* pData = NULL,
441 sal_uLong nFlags = 0 );
442
GetType() const443 sal_uInt16 GetType() const { return mnType; }
GetData() const444 void* GetData() const { return mpData; }
GetFlags() const445 sal_uLong GetFlags() const { return mnFlags; }
446
447 const AllSettings* GetOldSettings() const;
448 };
449
DataChangedEvent()450 inline DataChangedEvent::DataChangedEvent()
451 {
452 mpData = NULL;
453 mnFlags = 0;
454 mnType = 0;
455 }
456
DataChangedEvent(sal_uInt16 nType,const void * pData,sal_uLong nChangeFlags)457 inline DataChangedEvent::DataChangedEvent( sal_uInt16 nType,
458 const void* pData,
459 sal_uLong nChangeFlags )
460 {
461 mpData = (void*)pData;
462 mnFlags = nChangeFlags;
463 mnType = nType;
464 }
465
GetOldSettings() const466 inline const AllSettings* DataChangedEvent::GetOldSettings() const
467 {
468 if ( mnType == DATACHANGED_SETTINGS )
469 return (const AllSettings*)mpData;
470 else
471 return NULL;
472 }
473
474 #endif // _SV_EVENT_HXX
475
476