1 /*----------------------------------------------------------------------------
5 TabletEvents.m - Implamentation file for TabletEvent Category.
6 This is an extension to the NSEvent class.
10 Copyright WACOM Technology, Inc. 2001.
14 ----------------------------------------------------------------------------*/
16 #import "TabletEvents.h"
18 NSString *kProximityNotification = @"Proximity Event Notification";
20 NSString *kVendorID = @"vendorID";
21 NSString *kTabletID = @"tabletID";
22 NSString *kPointerID = @"pointerID";
23 NSString *kDeviceID = @"deviceID";
24 NSString *kSystemTabletID = @"systemTabletID";
25 NSString *kVendorPointerType = @"vendorPointerType";
26 NSString *kPointerSerialNumber = @"pointerSerialNumber";
27 NSString *kUniqueID = @"uniqueID";
28 NSString *kCapabilityMask = @"capabilityMask";
29 NSString *kPointerType = @"pointerType";
30 NSString *kEnterProximity = @"enterProximity";
32 @implementation NSEvent (TabletEvents)
33 //////////////////////////////////////////////////////////////////////////////
41 //////////////////////////////////////////////////////////////////////////////
42 - (BOOL) isTabletPointerEvent
47 switch (GetEventClass((EventRef)_eventRef))
49 case kEventClassMouse:
50 result = GetEventParameter((EventRef)_eventRef,
51 kEventParamTabletEventType,
53 sizeof( eventType ), NULL,
56 if ( result == noErr )
58 if ( eventType == kEventTabletPoint )
65 case kEventClassTablet:
66 if(GetEventKind((EventRef)_eventRef) == kEventTabletPoint)
81 //////////////////////////////////////////////////////////////////////////////
82 - (BOOL) isTabletProximityEvent
87 switch (GetEventClass((EventRef)_eventRef))
89 case kEventClassMouse:
90 result = GetEventParameter((EventRef)_eventRef,
91 kEventParamTabletEventType,
93 sizeof( eventType ), NULL,
96 if ( result == noErr )
98 if ( eventType == kEventTabletProximity )
105 case kEventClassTablet:
106 if(GetEventKind((EventRef)_eventRef) == kEventTabletProximity)
121 //////////////////////////////////////////////////////////////////////////////
122 - (TabletPointerRec) tabletRec
125 TabletPointerRec tabletData;
127 result = GetEventParameter((EventRef)_eventRef, kEventParamTabletPointerRec,
128 typeTabletPointerRec, NULL,
129 sizeof( TabletPointerRec ), NULL, &tabletData );
136 //////////////////////////////////////////////////////////////////////////////
137 - (void) setLocation:(NSPoint)loc
144 //////////////////////////////////////////////////////////////////////////////
145 - (unsigned int) deviceID
148 TabletPointerRec tabletData;
149 UInt16 theDeviceID = 0;
151 result = GetEventParameter((EventRef)_eventRef, kEventParamTabletPointerRec,
152 typeTabletPointerRec, NULL,
153 sizeof( TabletPointerRec ), NULL, &tabletData );
157 theDeviceID = tabletData.deviceID;
165 //////////////////////////////////////////////////////////////////////////////
169 TabletPointerRec tabletData;
172 result = GetEventParameter((EventRef)_eventRef, kEventParamTabletPointerRec,
173 typeTabletPointerRec, NULL,
174 sizeof( TabletPointerRec ), NULL, &tabletData );
178 absX = tabletData.absX;
186 //////////////////////////////////////////////////////////////////////////////
190 TabletPointerRec tabletData;
193 result = GetEventParameter((EventRef)_eventRef, kEventParamTabletPointerRec,
194 typeTabletPointerRec, NULL,
195 sizeof( TabletPointerRec ), NULL, &tabletData );
199 absY = tabletData.absX;
207 //////////////////////////////////////////////////////////////////////////////
211 TabletPointerRec tabletData;
214 result = GetEventParameter((EventRef)_eventRef, kEventParamTabletPointerRec,
215 typeTabletPointerRec, NULL,
216 sizeof( TabletPointerRec ), NULL, &tabletData );
220 absZ = tabletData.absZ;
228 //////////////////////////////////////////////////////////////////////////////
229 - (void) getAbsoluteX:(SInt32*)absX Y:(SInt32*)absY Z:(SInt32*)absZ
232 TabletPointerRec tabletData;
234 result = GetEventParameter((EventRef)_eventRef, kEventParamTabletPointerRec,
235 typeTabletPointerRec, NULL,
236 sizeof( TabletPointerRec ), NULL, &tabletData );
242 *absX = tabletData.absX;
247 *absY = tabletData.absY;
252 *absZ = tabletData.absZ;
259 //////////////////////////////////////////////////////////////////////////////
263 TabletPointerRec tabletData;
264 NSPoint theTilt = {0.0, 0.0};
266 result = GetEventParameter((EventRef)_eventRef, kEventParamTabletPointerRec,
267 typeTabletPointerRec, NULL,
268 sizeof( TabletPointerRec ), NULL, &tabletData );
272 theTilt.x = tabletData.tiltX/32767.0;
273 theTilt.y = tabletData.tiltY/32767.0;
282 //////////////////////////////////////////////////////////////////////////////
283 - (UInt16) rawTabletPressure
286 TabletPointerRec tabletData;
289 result = GetEventParameter((EventRef)_eventRef, kEventParamTabletPointerRec,
290 typeTabletPointerRec, NULL,
291 sizeof( TabletPointerRec ), NULL, &tabletData );
295 pressure = tabletData.pressure;
303 //////////////////////////////////////////////////////////////////////////////
304 - (float) scaledTabletPressure
307 TabletPointerRec tabletData;
308 float pressure = 0.0;
310 result = GetEventParameter((EventRef)_eventRef, kEventParamTabletPointerRec,
311 typeTabletPointerRec, NULL,
312 sizeof( TabletPointerRec ), NULL, &tabletData );
316 pressure = (float)tabletData.pressure/65535.0;
324 //////////////////////////////////////////////////////////////////////////////
325 - (float) rotationInDegrees; /* 0.0¡ <-> +359.99999¡ */
328 TabletPointerRec tabletData;
332 result = GetEventParameter((EventRef)_eventRef, kEventParamTabletPointerRec,
333 typeTabletPointerRec, NULL,
334 sizeof( TabletPointerRec ), NULL, &tabletData );
338 rotation = tabletData.rotation;
339 rotDeg = (float)rotation/64.0;
347 //////////////////////////////////////////////////////////////////////////////
348 - (float) rotationInRadians; /* 0 <-> 2¹ */
351 TabletPointerRec tabletData;
355 result = GetEventParameter((EventRef)_eventRef, kEventParamTabletPointerRec,
356 typeTabletPointerRec, NULL,
357 sizeof( TabletPointerRec ), NULL, &tabletData );
361 rotation = tabletData.rotation;
362 rotRad = (float)rotation/64.0;
363 rotRad = (rotRad * pi) / 180.0;