1 /*
2    NSEvent.h
3 
4    The event class
5 
6    Copyright (C) 1996,1999 Free Software Foundation, Inc.
7 
8    Author:  Scott Christley <scottc@net-community.com>
9    Date: 1996
10 
11    This file is part of the GNUstep GUI Library.
12 
13    This library is free software; you can redistribute it and/or
14    modify it under the terms of the GNU Lesser General Public
15    License as published by the Free Software Foundation; either
16    version 2 of the License, or (at your option) any later version.
17 
18    This library is distributed in the hope that it will be useful,
19    but WITHOUT ANY WARRANTY; without even the implied warranty of
20    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
21    Lesser General Public License for more details.
22 
23    You should have received a copy of the GNU Lesser General Public
24    License along with this library; see the file COPYING.LIB.
25    If not, see <http://www.gnu.org/licenses/> or write to the
26    Free Software Foundation, 51 Franklin Street, Fifth Floor,
27    Boston, MA 02110-1301, USA.
28 */
29 
30 #ifndef _GNUstep_H_NSEvent
31 #define _GNUstep_H_NSEvent
32 #import <GNUstepBase/GSVersionMacros.h>
33 
34 #import <Foundation/NSObject.h>
35 #import <Foundation/NSGeometry.h>
36 // For NSTimeInterval
37 #import <Foundation/NSDate.h>
38 
39 @class NSString;
40 @class NSWindow;
41 @class NSGraphicsContext;
42 
43 /**
44  * Enumeration of event types recognized within GNUstep GUI.  Each type has a
45  * corresponding mask that can be used when filtering for multiple types.  For
46  * example, the <code>NSLeftMouseDown</code> type has
47  * <code>NSLeftMouseDownMask</code> for its mask.  The special mask
48  * <code>NSAnyEventMask</code> matches any event.  The complete list of types
49  * is as follows:
50  * <example>
51   NSLeftMouseDown,
52   NSLeftMouseUp,
53   NSOtherMouseDown,
54   NSOtherMouseUp,
55   NSRightMouseDown,
56   NSRightMouseUp,
57   NSMouseMoved,
58   NSLeftMouseDragged,
59   NSOtherMouseDragged,
60   NSRightMouseDragged,
61   NSMouseEntered,
62   NSMouseExited,
63   NSKeyDown,
64   NSKeyUp,
65   NSFlagsChanged,
66   NSAppKitDefined,       // reserved
67   NSSystemDefined,       // reserved
68   NSApplicationDefined,  // available for custom use by apps
69   NSPeriodic,
70   NSCursorUpdate,
71   NSScrollWheel
72  </example>
73  */
74 enum _NSEventType {
75   // Note - order IS significant as ranges of values
76   // are used for testing for valid event types.
77   NSLeftMouseDown = 1,
78   NSLeftMouseUp,
79   NSRightMouseDown,
80   NSRightMouseUp,
81   NSMouseMoved,
82   NSLeftMouseDragged,
83   NSRightMouseDragged,
84   NSMouseEntered,
85   NSMouseExited,
86   NSKeyDown,
87   NSKeyUp,
88   NSFlagsChanged,
89   NSAppKitDefined,
90   NSSystemDefined,
91   NSApplicationDefined,
92   NSPeriodic,
93   NSCursorUpdate,
94   NSScrollWheel = 22,
95 #if OS_API_VERSION(MAC_OS_X_VERSION_10_4, GS_API_LATEST)
96   NSTabletPoint,
97   NSTabletProximity,
98 #endif
99   NSOtherMouseDown = 25,
100   NSOtherMouseUp,
101   NSOtherMouseDragged
102 };
103 typedef NSUInteger NSEventType;
104 
105 enum {
106   NSLeftMouseDownMask = (1 << NSLeftMouseDown),
107   NSLeftMouseUpMask = (1 << NSLeftMouseUp),
108   NSRightMouseDownMask = (1 << NSRightMouseDown),
109   NSRightMouseUpMask = (1 << NSRightMouseUp),
110   NSMouseMovedMask = (1 << NSMouseMoved),
111   NSLeftMouseDraggedMask = (1 << NSLeftMouseDragged),
112   NSRightMouseDraggedMask = (1 << NSRightMouseDragged),
113   NSMouseEnteredMask = (1 << NSMouseEntered),
114   NSMouseExitedMask = (1 << NSMouseExited),
115   NSKeyDownMask = (1 << NSKeyDown),
116   NSKeyUpMask = (1 << NSKeyUp),
117   NSFlagsChangedMask = (1 << NSFlagsChanged),
118   NSAppKitDefinedMask = (1 << NSAppKitDefined),
119   NSSystemDefinedMask = (1 << NSSystemDefined),
120   NSApplicationDefinedMask = (1 << NSApplicationDefined),
121   NSPeriodicMask = (1 << NSPeriodic),
122   NSCursorUpdateMask = (1 << NSCursorUpdate),
123   NSScrollWheelMask = (1 << NSScrollWheel),
124 #if OS_API_VERSION(MAC_OS_X_VERSION_10_4, GS_API_LATEST)
125   NSTabletPointMask = (1 << NSTabletPoint),
126   NSTabletProximityMask = (1 << NSTabletProximity),
127 #endif
128   NSOtherMouseDownMask = (1 << NSOtherMouseDown),
129   NSOtherMouseUpMask = (1 << NSOtherMouseUp),
130   NSOtherMouseDraggedMask = (1 << NSOtherMouseDragged),
131 
132   NSAnyEventMask = 0xffffffffU,
133 
134   // key events
135   GSKeyEventMask = (NSKeyDownMask | NSKeyUpMask | NSFlagsChangedMask),
136   // mouse events
137   GSMouseEventMask = (NSLeftMouseDownMask | NSLeftMouseUpMask | NSLeftMouseDraggedMask
138                       | NSRightMouseDownMask | NSRightMouseUpMask | NSRightMouseDraggedMask
139                       | NSOtherMouseDownMask | NSOtherMouseUpMask | NSOtherMouseDraggedMask
140                       | NSMouseMovedMask | NSScrollWheelMask
141 #if OS_API_VERSION(MAC_OS_X_VERSION_10_4, GS_API_LATEST)
142                       | NSTabletPointMask | NSTabletProximityMask
143 #endif
144       ),
145   // mouse move events
146   GSMouseMovedEventMask = (NSMouseMovedMask | NSScrollWheelMask
147                            | NSLeftMouseDraggedMask | NSRightMouseDraggedMask
148                            | NSOtherMouseDraggedMask),
149   // enter/exit event
150   GSEnterExitEventMask = (NSMouseEnteredMask | NSMouseExitedMask | NSCursorUpdateMask),
151   // other events
152   GSOtherEventMask = (NSAppKitDefinedMask | NSSystemDefinedMask
153                       | NSApplicationDefinedMask | NSPeriodicMask),
154 
155   // tracking loops may need to add NSPeriodicMask
156   GSTrackingLoopMask = (NSLeftMouseDownMask | NSLeftMouseUpMask
157                         | NSLeftMouseDraggedMask | NSMouseMovedMask
158                         | NSRightMouseUpMask | NSOtherMouseUpMask)
159 };
160 typedef unsigned long long NSEventMask;
161 
162 /*
163  * Convert an NSEvent Type to it's respective Event Mask
164  */
165 // FIXME: Should we use the inline trick from NSGeometry.h here?
166 static inline NSEventMask
167 NSEventMaskFromType(NSEventType type);
168 
169 static inline NSEventMask
NSEventMaskFromType(NSEventType type)170 NSEventMaskFromType(NSEventType type)
171 {
172   return (1 << type);
173 }
174 
175 enum {
176 #if OS_API_VERSION(MAC_OS_X_VERSION_10_4, GS_API_LATEST)
177   NSDeviceIndependentModifierFlagsMask = 0xffff0000U,
178 #endif
179   NSAlphaShiftKeyMask = 1 << 16,
180   NSShiftKeyMask = 2 << 16,
181   NSControlKeyMask = 4 << 16,
182   NSAlternateKeyMask = 8 << 16,
183   NSCommandKeyMask = 16 << 16,
184   NSNumericPadKeyMask = 32 << 16,
185   NSHelpKeyMask = 64 << 16,
186   NSFunctionKeyMask = 128 << 16
187 };
188 typedef NSUInteger NSEventModifierFlags;
189 
190 
191 #if OS_API_VERSION(MAC_OS_X_VERSION_10_4, GS_API_LATEST)
192 enum
193 {
194   NSUnknownPointingDevice,
195   NSPenPointingDevice,
196   NSCursorPointingDevice,
197   NSEraserPointingDevice
198 };
199 typedef NSUInteger NSPointingDeviceType;
200 
201 enum
202 {
203   NSPenTipMask = 1,
204   NSPenLowerSideMask = 2,
205   NSPenUpperSideMask = 4
206 };
207 typedef NSUInteger NSEventButtonMask;
208 
209 enum
210 {
211   NSMouseEventSubtype,
212   NSTabletPointEventSubtype,
213   NSTabletProximityEventSubtype
214 };
215 
216 enum {
217   NSWindowExposedEventType = 0,
218   NSApplicationActivatedEventType = 1,
219   NSApplicationDeactivatedEventType = 2,
220   NSWindowMovedEventType = 4,
221   NSScreenChangedEventType = 8,
222   NSAWTEventType = 16
223 };
224 
225 enum
226 {
227   NSPowerOffEventType = 1
228 };
229 
230 #endif
231 
232 #if OS_API_VERSION(MAC_OS_X_VERSION_10_7, GS_API_LATEST)
233 enum {
234   NSEventPhaseNone = 0,
235   NSEventPhaseBegan = 1,
236   NSEventPhaseStationary = 2,
237   NSEventPhaseChanged = 4,
238   NSEventPhaseEnded = 8,
239   NSEventPhaseCancelled = 16,
240   NSEventPhaseMayBegin = 32
241 };
242 typedef NSUInteger NSEventPhase;
243 
244 enum {
245   NSEventGestureAxisNone = 0,
246   NSEventGestureAxisHorizontal,
247   NSEventGestureAxisVertical
248 };
249 typedef NSInteger NSEventGestureAxis;
250 
251 enum {
252   NSEventSwipeTrackingLockDirection = 1,
253   NSEventSwipeTrackingClampGestureAmount = 2
254 };
255 typedef NSUInteger NSEventSwipeTrackingOptions;
256 
257 #endif
258 
259 @interface NSEvent : NSObject <NSCoding, NSCopying>
260 {
261   NSEventType	event_type;
262   NSPoint	location_point;
263   NSUInteger modifier_flags;
264   NSTimeInterval event_time;
265   NSInteger window_num;
266   NSGraphicsContext *event_context;
267   union _MB_event_data
268     {
269       struct
270         {
271           NSInteger event_num;
272           NSInteger click;
273           NSInteger button;
274           float pressure;
275           CGFloat deltaX;
276           CGFloat deltaY;
277           CGFloat deltaZ;
278         } mouse;
279       struct
280         {
281           BOOL     repeat;
282           __unsafe_unretained NSString *char_keys;
283           __unsafe_unretained NSString *unmodified_keys;
284           unsigned short key_code;
285         } key;
286       struct
287         {
288           NSInteger event_num;
289           NSInteger tracking_num;
290           void *user_data;
291         } tracking;
292       struct
293         {
294           short sub_type;
295           NSInteger data1;
296           NSInteger data2;
297         } misc;
298     } event_data;
299 }
300 
301 + (NSEvent*) enterExitEventWithType: (NSEventType)type
302                            location: (NSPoint)location
303                       modifierFlags: (NSUInteger)flags
304                           timestamp: (NSTimeInterval)time
305                        windowNumber: (NSInteger)windowNum
306                             context: (NSGraphicsContext*)context
307                         eventNumber: (NSInteger)eventNum
308                      trackingNumber: (NSInteger)trackingNum
309                            userData: (void *)userData;
310 
311 + (NSEvent*) keyEventWithType: (NSEventType)type
312                      location: (NSPoint)location
313                 modifierFlags: (NSUInteger)flags
314                     timestamp: (NSTimeInterval)time
315                  windowNumber: (NSInteger)windowNum
316                       context: (NSGraphicsContext*)context
317                    characters: (NSString *)keys
318   charactersIgnoringModifiers: (NSString *)ukeys
319                     isARepeat: (BOOL)repeatKey
320                       keyCode: (unsigned short)code;
321 
322 + (NSEvent*) mouseEventWithType: (NSEventType)type
323                        location: (NSPoint)location
324                   modifierFlags: (NSUInteger)flags
325                       timestamp: (NSTimeInterval)time
326                    windowNumber: (NSInteger)windowNum
327                         context: (NSGraphicsContext*)context
328                     eventNumber: (NSInteger)eventNum
329                      clickCount: (NSInteger)clickNum
330                        pressure: (float)pressureValue;
331 
332 #if OS_API_VERSION(GS_API_NONE, GS_API_NONE)
333 + (NSEvent*) mouseEventWithType: (NSEventType)type
334                        location: (NSPoint)location
335                   modifierFlags: (NSUInteger)flags
336                       timestamp: (NSTimeInterval)time
337                    windowNumber: (NSInteger)windowNum
338                         context: (NSGraphicsContext*)context
339                     eventNumber: (NSInteger)eventNum
340                      clickCount: (NSInteger)clickNum
341                        pressure: (float)pressureValue
342                    buttonNumber: (NSInteger)buttonNum
343                          deltaX: (CGFloat)deltaX
344                          deltaY: (CGFloat)deltaY
345                          deltaZ: (CGFloat)deltaZ;
346 #endif
347 
348 + (NSPoint)mouseLocation;
349 
350 + (NSEvent*) otherEventWithType: (NSEventType)type
351                        location: (NSPoint)location
352                   modifierFlags: (NSUInteger)flags
353                       timestamp: (NSTimeInterval)time
354                    windowNumber: (NSInteger)windowNum
355                         context: (NSGraphicsContext*)context
356                         subtype: (short)subType
357                           data1: (NSInteger)data1
358                           data2: (NSInteger)data2;
359 
360 + (void) startPeriodicEventsAfterDelay: (NSTimeInterval)delaySeconds
361                             withPeriod: (NSTimeInterval)periodSeconds;
362 + (void) stopPeriodicEvents;
363 
364 
365 #if OS_API_VERSION(GS_API_MACOSX, GS_API_LATEST)
366 - (NSInteger) buttonNumber;
367 #endif
368 - (NSString *) characters;
369 - (NSString *) charactersIgnoringModifiers;
370 - (NSInteger) clickCount;
371 - (NSGraphicsContext*) context;
372 - (NSInteger) data1;
373 - (NSInteger) data2;
374 #if OS_API_VERSION(GS_API_MACOSX, GS_API_LATEST)
375 - (CGFloat)deltaX;
376 - (CGFloat)deltaY;
377 - (CGFloat)deltaZ;
378 #endif
379 - (NSInteger) eventNumber;
380 - (BOOL) isARepeat;
381 - (unsigned short) keyCode;
382 - (NSPoint) locationInWindow;
383 - (NSEventModifierFlags) modifierFlags;
384 - (float) pressure;
385 - (short) subtype;
386 - (NSTimeInterval) timestamp;
387 - (NSInteger) trackingNumber;
388 - (NSEventType) type;
389 - (void *) userData;
390 - (NSWindow *) window;
391 - (NSInteger) windowNumber;
392 
393 #if OS_API_VERSION(MAC_OS_X_VERSION_10_3, GS_API_LATEST)
394 - (NSEventMask) associatedEventsMask;
395 #endif
396 
397 #if OS_API_VERSION(MAC_OS_X_VERSION_10_4, GS_API_LATEST)
398 - (NSInteger) absoluteX;
399 - (NSInteger) absoluteY;
400 - (NSInteger) absoluteZ;
401 - (NSEventButtonMask) buttonMask;
402 - (NSUInteger) capabilityMask;
403 - (NSUInteger) deviceID;
404 - (BOOL) isEnteringProximity;
405 - (NSUInteger) pointingDeviceID;
406 - (NSUInteger) pointingDeviceSerialNumber;
407 - (NSPointingDeviceType) pointingDeviceType;
408 - (float) rotation;
409 - (NSUInteger) systemTabletID;
410 - (NSUInteger) tabletID;
411 - (float) tangentialPressure;
412 - (NSPoint) tilt;
413 - (unsigned long long) uniqueID;
414 - (id) vendorDefined;
415 - (NSUInteger) vendorID;
416 - (NSUInteger) vendorPointingDeviceType;
417 #endif
418 
419 #if OS_API_VERSION(MAC_OS_X_VERSION_10_5, GS_API_LATEST)
420 + (NSEvent*) eventWithEventRef: (const void *)eventRef;
421 //+ (NSEvent*) eventWithCGEvent: (CGEventRef)cgEvent;
422 - (const void *) eventRef;
423 //- (CGEventRef) CGEvent;
424 + (void) setMouseCoalescingEnabled: (BOOL)flag;
425 + (BOOL) isMouseCoalescingEnabled;
426 #endif
427 
428 #if OS_API_VERSION(MAC_OS_X_VERSION_10_6, GS_API_LATEST)
429 + (NSEventModifierFlags) modifierFlags;
430 + (NSTimeInterval) keyRepeatDelay;
431 + (NSTimeInterval) keyRepeatInterval;
432 + (NSUInteger) pressedMouseButtons;
433 + (NSTimeInterval) doubleClickInterval;
434 #endif
435 
436 #if OS_API_VERSION(MAC_OS_X_VERSION_10_7, GS_API_LATEST)
437 - (NSEventPhase) phase;
438 - (NSEventPhase) momentumPhase;
439 #endif
440 @end
441 
442 enum {
443   NSUpArrowFunctionKey = 0xF700,
444   NSDownArrowFunctionKey = 0xF701,
445   NSLeftArrowFunctionKey = 0xF702,
446   NSRightArrowFunctionKey = 0xF703,
447   NSF1FunctionKey  = 0xF704,
448   NSF2FunctionKey  = 0xF705,
449   NSF3FunctionKey  = 0xF706,
450   NSF4FunctionKey  = 0xF707,
451   NSF5FunctionKey  = 0xF708,
452   NSF6FunctionKey  = 0xF709,
453   NSF7FunctionKey  = 0xF70A,
454   NSF8FunctionKey  = 0xF70B,
455   NSF9FunctionKey  = 0xF70C,
456   NSF10FunctionKey = 0xF70D,
457   NSF11FunctionKey = 0xF70E,
458   NSF12FunctionKey = 0xF70F,
459   NSF13FunctionKey = 0xF710,
460   NSF14FunctionKey = 0xF711,
461   NSF15FunctionKey = 0xF712,
462   NSF16FunctionKey = 0xF713,
463   NSF17FunctionKey = 0xF714,
464   NSF18FunctionKey = 0xF715,
465   NSF19FunctionKey = 0xF716,
466   NSF20FunctionKey = 0xF717,
467   NSF21FunctionKey = 0xF718,
468   NSF22FunctionKey = 0xF719,
469   NSF23FunctionKey = 0xF71A,
470   NSF24FunctionKey = 0xF71B,
471   NSF25FunctionKey = 0xF71C,
472   NSF26FunctionKey = 0xF71D,
473   NSF27FunctionKey = 0xF71E,
474   NSF28FunctionKey = 0xF71F,
475   NSF29FunctionKey = 0xF720,
476   NSF30FunctionKey = 0xF721,
477   NSF31FunctionKey = 0xF722,
478   NSF32FunctionKey = 0xF723,
479   NSF33FunctionKey = 0xF724,
480   NSF34FunctionKey = 0xF725,
481   NSF35FunctionKey = 0xF726,
482   NSInsertFunctionKey = 0xF727,
483   NSDeleteFunctionKey = 0xF728,
484   NSHomeFunctionKey = 0xF729,
485   NSBeginFunctionKey = 0xF72A,
486   NSEndFunctionKey = 0xF72B,
487   NSPageUpFunctionKey = 0xF72C,
488   NSPageDownFunctionKey = 0xF72D,
489   NSPrintScreenFunctionKey = 0xF72E,
490   NSScrollLockFunctionKey = 0xF72F,
491   NSPauseFunctionKey = 0xF730,
492   NSSysReqFunctionKey = 0xF731,
493   NSBreakFunctionKey = 0xF732,
494   NSResetFunctionKey = 0xF733,
495   NSStopFunctionKey = 0xF734,
496   NSMenuFunctionKey = 0xF735,
497   NSUserFunctionKey = 0xF736,
498   NSSystemFunctionKey = 0xF737,
499   NSPrintFunctionKey = 0xF738,
500   NSClearLineFunctionKey = 0xF739,
501   NSClearDisplayFunctionKey = 0xF73A,
502   NSInsertLineFunctionKey = 0xF73B,
503   NSDeleteLineFunctionKey = 0xF73C,
504   NSInsertCharFunctionKey = 0xF73D,
505   NSDeleteCharFunctionKey = 0xF73E,
506   NSPrevFunctionKey = 0xF73F,
507   NSNextFunctionKey = 0xF740,
508   NSSelectFunctionKey = 0xF741,
509   NSExecuteFunctionKey = 0xF742,
510   NSUndoFunctionKey = 0xF743,
511   NSRedoFunctionKey = 0xF744,
512   NSFindFunctionKey = 0xF745,
513   NSHelpFunctionKey = 0xF746,
514   NSModeSwitchFunctionKey = 0xF747
515 };
516 
517 #if OS_API_VERSION(GS_API_NONE, GS_API_NONE)
518 typedef enum {
519   GSAppKitWindowMoved = 1,
520   GSAppKitWindowResized,
521   GSAppKitWindowClose,
522   GSAppKitWindowMiniaturize,
523   GSAppKitWindowFocusIn,
524   GSAppKitWindowFocusOut,
525   GSAppKitWindowLeave,
526   GSAppKitWindowEnter,
527   GSAppKitDraggingEnter,
528   GSAppKitDraggingUpdate,
529   GSAppKitDraggingStatus,
530   GSAppKitDraggingExit,
531   GSAppKitDraggingDrop,
532   GSAppKitDraggingFinished,
533   GSAppKitRegionExposed,
534   GSAppKitWindowDeminiaturize,
535   GSAppKitAppHide
536 } GSAppKitSubtype;
537 #endif
538 
539 #endif /* _GNUstep_H_NSEvent */
540