xref: /trunk/main/vcl/inc/vcl/event.hxx (revision cea84f56765a2ac06f0f5a2718f45f6430edc781) !
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                     KeyEvent& operator=(const KeyEvent&) = default;
77 
78 };
79 
KeyEvent()80 inline KeyEvent::KeyEvent()
81 {
82     mnCharCode  = 0;
83     mnRepeat    = 0;
84 }
85 
KeyEvent(xub_Unicode nChar,const KeyCode & rKeyCode,sal_uInt16 nRepeat)86 inline KeyEvent::KeyEvent( xub_Unicode nChar, const KeyCode& rKeyCode,
87                            sal_uInt16 nRepeat ) :
88             maKeyCode( rKeyCode )
89 
90 {
91     mnCharCode  = nChar;
92     mnRepeat    = nRepeat;
93 }
94 
95 // --------------------
96 // - MouseEvent-Types -
97 // --------------------
98 
99 // Maus-Move-Modi
100 #define MOUSE_SIMPLEMOVE        ((sal_uInt16)0x0001)
101 #define MOUSE_DRAGMOVE          ((sal_uInt16)0x0002)
102 #define MOUSE_DRAGCOPY          ((sal_uInt16)0x0004)
103 #define MOUSE_ENTERWINDOW       ((sal_uInt16)0x0010)
104 #define MOUSE_LEAVEWINDOW       ((sal_uInt16)0x0020)
105 #define MOUSE_SYNTHETIC         ((sal_uInt16)0x0040)
106 #define MOUSE_MODIFIERCHANGED   ((sal_uInt16)0x0080)
107 
108 // Maus-Button-Down/Up-Modi
109 #define MOUSE_SIMPLECLICK       ((sal_uInt16)0x0001)
110 #define MOUSE_SELECT            ((sal_uInt16)0x0002)
111 #define MOUSE_MULTISELECT       ((sal_uInt16)0x0004)
112 #define MOUSE_RANGESELECT       ((sal_uInt16)0x0008)
113 
114 // Maus-Buttons
115 #define MOUSE_LEFT              ((sal_uInt16)0x0001)
116 #define MOUSE_MIDDLE            ((sal_uInt16)0x0002)
117 #define MOUSE_RIGHT             ((sal_uInt16)0x0004)
118 
119 // --------------
120 // - MouseEvent -
121 // --------------
122 
123 class VCL_DLLPUBLIC MouseEvent
124 {
125 private:
126     Point           maPos;
127     sal_uInt16          mnMode;
128     sal_uInt16          mnClicks;
129     sal_uInt16          mnCode;
130 
131 public:
132     explicit        MouseEvent();
133     explicit        MouseEvent( const Point& rPos, sal_uInt16 nClicks = 1,
134                                 sal_uInt16 nMode = 0, sal_uInt16 nButtons = 0,
135                                 sal_uInt16 nModifier = 0 );
136 
GetPosPixel() const137     const Point&    GetPosPixel() const     { return maPos; }
GetMode() const138     sal_uInt16          GetMode() const         { return mnMode; }
139                     /** inits this vcl KeyEvent with all settings from the given awt event **/
140                     MouseEvent( const ::com::sun::star::awt::MouseEvent& rEvent );
141 
142     /** fills out the given awt KeyEvent with all settings from this vcl event **/
143     void InitMouseEvent( ::com::sun::star::awt::MouseEvent& rEvent ) const;
144 
GetClicks() const145     sal_uInt16          GetClicks() const       { return mnClicks; }
146 
IsEnterWindow() const147     sal_Bool            IsEnterWindow() const
148                         { return ((mnMode & MOUSE_ENTERWINDOW) != 0); }
IsLeaveWindow() const149     sal_Bool            IsLeaveWindow() const
150                         { return ((mnMode & MOUSE_LEAVEWINDOW) != 0); }
IsSynthetic() const151     sal_Bool            IsSynthetic() const
152                         { return ((mnMode & MOUSE_SYNTHETIC) != 0); }
IsModifierChanged() const153     sal_Bool            IsModifierChanged() const
154                         { return ((mnMode & MOUSE_MODIFIERCHANGED) != 0); }
155 
GetButtons() const156     sal_uInt16          GetButtons() const
157                         { return (mnCode & (MOUSE_LEFT | MOUSE_MIDDLE | MOUSE_RIGHT)); }
IsLeft() const158     sal_Bool            IsLeft() const
159                         { return ((mnCode & MOUSE_LEFT) != 0); }
IsMiddle() const160     sal_Bool            IsMiddle() const
161                         { return ((mnCode & MOUSE_MIDDLE) != 0); }
IsRight() const162     sal_Bool            IsRight() const
163                         { return ((mnCode & MOUSE_RIGHT) != 0); }
164 
GetModifier() const165     sal_uInt16          GetModifier() const
166                         { return (mnCode & (KEY_SHIFT | KEY_MOD1 | KEY_MOD2)); }
IsShift() const167     sal_Bool            IsShift() const
168                         { return ((mnCode & KEY_SHIFT) != 0); }
IsMod1() const169     sal_Bool            IsMod1() const
170                         { return ((mnCode & KEY_MOD1) != 0); }
IsMod2() const171     sal_Bool            IsMod2() const
172                         { return ((mnCode & KEY_MOD2) != 0); }
IsMod3() const173     sal_Bool            IsMod3() const
174                         { return ((mnCode & KEY_MOD3) != 0); }
175 };
176 
MouseEvent()177 inline MouseEvent::MouseEvent()
178 {
179     mnMode      = 0;
180     mnClicks    = 0;
181     mnCode      = 0;
182 }
183 
MouseEvent(const Point & rPos,sal_uInt16 nClicks,sal_uInt16 nMode,sal_uInt16 nButtons,sal_uInt16 nModifier)184 inline MouseEvent::MouseEvent( const Point& rPos, sal_uInt16 nClicks,
185                                sal_uInt16 nMode,
186                                sal_uInt16 nButtons, sal_uInt16 nModifier ) :
187             maPos( rPos )
188 {
189     mnClicks    = nClicks;
190     mnMode      = nMode;
191     mnCode      = nButtons | nModifier;
192 }
193 
194 // -------------
195 // - HelpEvent -
196 // -------------
197 
198 #define HELPMODE_CONTEXT        ((sal_uInt16)0x0001)
199 #define HELPMODE_EXTENDED       ((sal_uInt16)0x0002)
200 #define HELPMODE_BALLOON        ((sal_uInt16)0x0004)
201 #define HELPMODE_QUICK          ((sal_uInt16)0x0008)
202 
203 class VCL_DLLPUBLIC HelpEvent
204 {
205 private:
206     Point           maPos;
207     sal_uInt16          mnMode;
208     sal_Bool            mbKeyboardActivated;
209 
210 public:
211     explicit        HelpEvent();
212     explicit        HelpEvent( sal_uInt16 nHelpMode );
213     explicit        HelpEvent( const Point& rMousePos, sal_uInt16 nHelpMode );
214 
215     const Point&    GetMousePosPixel() const;
GetMode() const216     sal_uInt16          GetMode() const { return mnMode; }
KeyboardActivated() const217     sal_Bool            KeyboardActivated() const { return mbKeyboardActivated; }
SetKeyboardActivated(sal_Bool bKeyboard)218     void            SetKeyboardActivated( sal_Bool bKeyboard ) { mbKeyboardActivated = bKeyboard; }
219 };
220 
HelpEvent()221 inline HelpEvent::HelpEvent()
222 {
223     mnMode  = HELPMODE_CONTEXT;
224     mbKeyboardActivated = sal_True;
225 }
226 
HelpEvent(const Point & rMousePos,sal_uInt16 nHelpMode)227 inline HelpEvent::HelpEvent( const Point& rMousePos, sal_uInt16 nHelpMode ) :
228             maPos( rMousePos )
229 {
230     mnMode  = nHelpMode;
231     mbKeyboardActivated = sal_False;
232 }
233 
HelpEvent(sal_uInt16 nHelpMode)234 inline HelpEvent::HelpEvent( sal_uInt16 nHelpMode )
235 {
236     mnMode  = nHelpMode;
237     mbKeyboardActivated = sal_True;
238 }
239 
240 // -----------------
241 // - UserDrawEvent -
242 // -----------------
243 
244 class VCL_DLLPUBLIC UserDrawEvent
245 {
246 private:
247     OutputDevice*       mpOutDev;
248     Rectangle           maOutRect;
249     sal_uInt16              mnItemId;
250     sal_uInt16              mnStyle;
251 
252 public:
253                         UserDrawEvent();
254                         UserDrawEvent( OutputDevice* pOut,
255                                        const Rectangle& rOutRect,
256                                        sal_uInt16 nId, sal_uInt16 nStyle = 0 );
257 
GetDevice() const258     OutputDevice*       GetDevice() const { return mpOutDev; }
GetRect() const259     const Rectangle&    GetRect() const { return maOutRect; }
GetItemId() const260     sal_uInt16              GetItemId() const { return mnItemId; }
GetStyle() const261     sal_uInt16              GetStyle() const { return mnStyle; }
262 };
263 
UserDrawEvent()264 inline UserDrawEvent::UserDrawEvent()
265 {
266     mpOutDev    = NULL;
267     mnItemId    = 0;
268     mnStyle     = 0;
269 }
270 
UserDrawEvent(OutputDevice * pOut,const Rectangle & rOutRect,sal_uInt16 nId,sal_uInt16 nStyle)271 inline UserDrawEvent::UserDrawEvent( OutputDevice* pOut,
272                                      const Rectangle& rOutRect,
273                                      sal_uInt16 nId, sal_uInt16 nStyle ) :
274             maOutRect( rOutRect )
275 {
276     mpOutDev    = pOut;
277     mnItemId    = nId;
278     mnStyle     = nStyle;
279 }
280 
281 // ------------------
282 // - Tracking-Types -
283 // ------------------
284 
285 #define ENDTRACK_CANCEL         ((sal_uInt16)0x0001)
286 #define ENDTRACK_KEY            ((sal_uInt16)0x0002)
287 #define ENDTRACK_FOCUS          ((sal_uInt16)0x0004)
288 #define ENDTRACK_END            ((sal_uInt16)0x1000)
289 #define ENDTRACK_DONTCALLHDL    ((sal_uInt16)0x8000)
290 
291 #define TRACKING_REPEAT         ((sal_uInt16)0x0100)
292 
293 // -----------------
294 // - TrackingEvent -
295 // -----------------
296 
297 class VCL_DLLPUBLIC TrackingEvent
298 {
299 private:
300     MouseEvent          maMEvt;
301     sal_uInt16              mnFlags;
302 
303 public:
304     explicit            TrackingEvent();
305     explicit            TrackingEvent( const MouseEvent&,
306                                        sal_uInt16 nTrackFlags = 0 );
307 
GetMouseEvent() const308     const MouseEvent&   GetMouseEvent() const { return maMEvt; }
309 
IsTrackingRepeat() const310     sal_Bool                IsTrackingRepeat() const
311                             { return ((mnFlags & TRACKING_REPEAT) != 0); }
312 
IsTrackingEnded() const313     sal_Bool                IsTrackingEnded() const
314                             { return ((mnFlags & ENDTRACK_END) != 0); }
IsTrackingCanceled() const315     sal_Bool                IsTrackingCanceled() const
316                             { return ((mnFlags & ENDTRACK_CANCEL) != 0); }
GetTrackingFlags() const317     sal_uInt16              GetTrackingFlags() const { return mnFlags; }
318 };
319 
TrackingEvent()320 inline TrackingEvent::TrackingEvent()
321 {
322     mnFlags = 0;
323 }
324 
TrackingEvent(const MouseEvent & rMEvt,sal_uInt16 nTrackFlags)325 inline TrackingEvent::TrackingEvent( const MouseEvent& rMEvt,
326                                      sal_uInt16 nTrackFlags ) :
327             maMEvt( rMEvt )
328 {
329     mnFlags = nTrackFlags;
330 }
331 
332 // ---------------
333 // - NotifyEvent -
334 // ---------------
335 
336 #define EVENT_MOUSEBUTTONDOWN   1
337 #define EVENT_MOUSEBUTTONUP     2
338 #define EVENT_MOUSEMOVE         3
339 #define EVENT_KEYINPUT          4
340 #define EVENT_KEYUP             5
341 #define EVENT_GETFOCUS          6
342 #define EVENT_LOSEFOCUS         7
343 #define EVENT_COMMAND           8
344 #define EVENT_DESTROY           9
345 #define EVENT_INPUTENABLE       10
346 #define EVENT_INPUTDISABLE      11
347 #define EVENT_EXECUTEDIALOG     100
348 #define EVENT_ENDEXECUTEDIALOG  101
349 #define EVENT_USER              10000
350 
351 class VCL_DLLPUBLIC NotifyEvent
352 {
353 private:
354     Window*                 mpWindow;
355     void*                   mpData;
356     sal_uInt16                  mnType;
357     long                    mnRetValue;
358 
359 public:
360                             NotifyEvent();
361                             NotifyEvent( sal_uInt16 nType,
362                                          Window* pWindow,
363                                          const void* pEvent = NULL,
364                                          long nRet = 0 );
365 
GetType() const366     sal_uInt16                  GetType() const { return mnType; }
GetWindow() const367     Window*                 GetWindow() const { return mpWindow; }
GetData() const368     void*                   GetData() const { return mpData; }
369 
SetReturnValue(long nRet)370     void                    SetReturnValue( long nRet ) { mnRetValue = nRet; }
GetReturnValue() const371     long                    GetReturnValue() const { return mnRetValue; }
372 
373     const KeyEvent*         GetKeyEvent() const;
374     const MouseEvent*       GetMouseEvent() const;
375     const CommandEvent*     GetCommandEvent() const;
376 };
377 
NotifyEvent()378 inline NotifyEvent::NotifyEvent()
379 {
380     mpWindow    = NULL;
381     mpData      = NULL;
382     mnType      = 0;
383     mnRetValue  = 0;
384 }
385 
NotifyEvent(sal_uInt16 nType,Window * pWindow,const void * pEvent,long nRet)386 inline NotifyEvent::NotifyEvent( sal_uInt16 nType, Window* pWindow,
387                                  const void* pEvent, long nRet )
388 {
389     mpWindow    = pWindow;
390     mpData      = (void*)pEvent;
391     mnType      = nType;
392     mnRetValue  = nRet;
393 }
394 
GetKeyEvent() const395 inline const KeyEvent* NotifyEvent::GetKeyEvent() const
396 {
397     if ( (mnType == EVENT_KEYINPUT) || (mnType == EVENT_KEYUP) )
398         return (const KeyEvent*)mpData;
399     else
400         return NULL;
401 }
402 
GetMouseEvent() const403 inline const MouseEvent* NotifyEvent::GetMouseEvent() const
404 {
405     if ( (mnType >= EVENT_MOUSEBUTTONDOWN) && (mnType <= EVENT_MOUSEMOVE) )
406         return (const MouseEvent*)mpData;
407     else
408         return NULL;
409 }
410 
GetCommandEvent() const411 inline const CommandEvent* NotifyEvent::GetCommandEvent() const
412 {
413     if ( mnType == EVENT_COMMAND )
414         return (const CommandEvent*)mpData;
415     else
416         return NULL;
417 }
418 
419 // --------------------
420 // - DataChangedEvent -
421 // --------------------
422 
423 #define DATACHANGED_SETTINGS            ((sal_uInt16)1)
424 #define DATACHANGED_DISPLAY             ((sal_uInt16)2)
425 #define DATACHANGED_DATETIME            ((sal_uInt16)3)
426 #define DATACHANGED_FONTS               ((sal_uInt16)4)
427 #define DATACHANGED_PRINTER             ((sal_uInt16)5)
428 #define DATACHANGED_FONTSUBSTITUTION    ((sal_uInt16)6)
429 #define DATACHANGED_USER                ((sal_uInt16)10000)
430 
431 class VCL_DLLPUBLIC DataChangedEvent
432 {
433 private:
434     void*                   mpData;
435     sal_uLong                   mnFlags;
436     sal_uInt16                  mnType;
437 
438 public:
439     explicit                DataChangedEvent();
440     explicit                DataChangedEvent( sal_uInt16 nType,
441                                               const void* pData = NULL,
442                                               sal_uLong nFlags = 0 );
443 
GetType() const444     sal_uInt16                  GetType() const { return mnType; }
GetData() const445     void*                   GetData() const { return mpData; }
GetFlags() const446     sal_uLong                   GetFlags() const { return mnFlags; }
447 
448     const AllSettings*      GetOldSettings() const;
449 };
450 
DataChangedEvent()451 inline DataChangedEvent::DataChangedEvent()
452 {
453     mpData  = NULL;
454     mnFlags = 0;
455     mnType  = 0;
456 }
457 
DataChangedEvent(sal_uInt16 nType,const void * pData,sal_uLong nChangeFlags)458 inline DataChangedEvent::DataChangedEvent( sal_uInt16 nType,
459                                            const void* pData,
460                                            sal_uLong nChangeFlags )
461 {
462     mpData  = (void*)pData;
463     mnFlags = nChangeFlags;
464     mnType  = nType;
465 }
466 
GetOldSettings() const467 inline const AllSettings* DataChangedEvent::GetOldSettings() const
468 {
469     if ( mnType == DATACHANGED_SETTINGS )
470         return (const AllSettings*)mpData;
471     else
472         return NULL;
473 }
474 
475 #endif // _SV_EVENT_HXX
476