comparison dwt/internal/cocoa/NSEvent.d @ 45:d8635bb48c7c

Merge with SWT 3.5
author Jacob Carlborg <doob@me.com>
date Mon, 01 Dec 2008 17:07:00 +0100
parents f565d3a95c0a
children cfa563df4fdd
comparison
equal deleted inserted replaced
44:ca5e494f2bbf 45:d8635bb48c7c
1 /******************************************************************************* 1 /*******************************************************************************
2 * Copyright (c) 2007 IBM Corporation and others. 2 * Copyright (c) 2000, 2008 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials 3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0 4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at 5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html 6 * http://www.eclipse.org/legal/epl-v10.html
7 * 7 *
8 * Contributors: 8 * Contributors:
9 * IBM Corporation - initial API and implementation 9 * IBM Corporation - initial API and implementation
10 * 10 *
11 * Port to the D programming language: 11 * Port to the D programming language:
12 * Jacob Carlborg <jacob.carlborg@gmail.com> 12 * Jacob Carlborg <doob@me.com>
13 *******************************************************************************/ 13 *******************************************************************************/
14 module dwt.internal.cocoa.NSEvent; 14 module dwt.internal.cocoa.NSEvent;
15 15
16 import dwt.internal.cocoa.CGEventTypes; 16 import dwt.dwthelper.utils;
17 import dwt.internal.cocoa.CGFloat; 17 import dwt.internal.c.Carbon;
18 import dwt.internal.cocoa.id; 18 import cocoa = dwt.internal.cocoa.id;
19 import dwt.internal.cocoa.IOLLEvent; 19 import dwt.internal.cocoa.NSDate;
20 import dwt.internal.cocoa.NSDate : NSTimeInterval;
21 import dwt.internal.cocoa.NSGraphicsContext; 20 import dwt.internal.cocoa.NSGraphicsContext;
22 import dwt.internal.cocoa.NSInteger;
23 import dwt.internal.cocoa.NSObject; 21 import dwt.internal.cocoa.NSObject;
24 import dwt.internal.cocoa.NSPoint; 22 import dwt.internal.cocoa.NSPoint;
25 import dwt.internal.cocoa.NSString; 23 import dwt.internal.cocoa.NSString;
26 import dwt.internal.cocoa.NSTrackingArea;
27 import dwt.internal.cocoa.NSWindow; 24 import dwt.internal.cocoa.NSWindow;
28 import dwt.internal.cocoa.OS; 25 import dwt.internal.cocoa.OS;
26 import dwt.internal.objc.cocoa.Cocoa;
29 import objc = dwt.internal.objc.runtime; 27 import objc = dwt.internal.objc.runtime;
30 28
31 enum NSEventType 29 enum NSEventType
32 { 30 {
33 NSLeftMouseDown = 1, 31 NSLeftMouseDown = 1,
34 NSLeftMouseUp = 2, 32 NSLeftMouseUp = 2,
35 NSRightMouseDown = 3, 33 NSRightMouseDown = 3,
36 NSRightMouseUp = 4, 34 NSRightMouseUp = 4,
37 NSMouseMoved = 5, 35 NSMouseMoved = 5,
38 NSLeftMouseDragged = 6, 36 NSLeftMouseDragged = 6,
39 NSRightMouseDragged = 7, 37 NSRightMouseDragged = 7,
40 NSMouseEntered = 8, 38 NSMouseEntered = 8,
41 NSMouseExited = 9, 39 NSMouseExited = 9,
42 NSKeyDown = 10, 40 NSKeyDown = 10,
43 NSKeyUp = 11, 41 NSKeyUp = 11,
44 NSFlagsChanged = 12, 42 NSFlagsChanged = 12,
45 NSAppKitDefined = 13, 43 NSAppKitDefined = 13,
46 NSSystemDefined = 14, 44 NSSystemDefined = 14,
47 NSApplicationDefined = 15, 45 NSApplicationDefined = 15,
48 NSPeriodic = 16, 46 NSPeriodic = 16,
49 NSCursorUpdate = 17, 47 NSCursorUpdate = 17,
50 NSScrollWheel = 22, 48 NSScrollWheel = 22,
51 NSTabletPoint = 23, 49 NSTabletPoint = 23,
52 NSTabletProximity = 24, 50 NSTabletProximity = 24,
53 NSOtherMouseDown = 25, 51 NSOtherMouseDown = 25,
54 NSOtherMouseUp = 26, 52 NSOtherMouseUp = 26,
55 NSOtherMouseDragged = 27 53 NSOtherMouseDragged = 27
56 } 54 }
57 55
58 alias NSEventType.NSLeftMouseDown NSLeftMouseDown; 56 public class NSEvent : NSObject {
59 alias NSEventType.NSLeftMouseUp NSLeftMouseUp;
60 alias NSEventType.NSRightMouseDown NSRightMouseDown;
61 alias NSEventType.NSRightMouseUp NSRightMouseUp;
62 alias NSEventType.NSMouseMoved NSMouseMoved;
63 alias NSEventType.NSLeftMouseDragged NSLeftMouseDragged;
64 alias NSEventType.NSRightMouseDragged NSRightMouseDragged;
65 alias NSEventType.NSMouseEntered NSMouseEntered;
66 alias NSEventType.NSMouseExited NSMouseExited;
67 alias NSEventType.NSKeyDown NSKeyDown;
68 alias NSEventType.NSKeyUp NSKeyUp;
69 alias NSEventType.NSFlagsChanged NSFlagsChanged;
70 alias NSEventType.NSAppKitDefined NSAppKitDefined;
71 alias NSEventType.NSSystemDefined NSSystemDefined;
72 alias NSEventType.NSApplicationDefined NSApplicationDefined;
73 alias NSEventType.NSPeriodic NSPeriodic;
74 alias NSEventType.NSCursorUpdate NSCursorUpdate;
75 alias NSEventType.NSScrollWheel NSScrollWheel;
76 alias NSEventType.NSTabletPoint NSTabletPoint;
77 alias NSEventType.NSTabletProximity NSTabletProximity;
78 alias NSEventType.NSOtherMouseDown NSOtherMouseDown;
79 alias NSEventType.NSOtherMouseUp NSOtherMouseUp;
80 alias NSEventType.NSOtherMouseDragged NSOtherMouseDragged;
81 57
82 enum NSPointingDeviceType 58 public this() {
83 { 59 super();
84 NSUnknownPointingDevice = NX_TABLET_POINTER_UNKNOWN,
85 NSPenPointingDevice = NX_TABLET_POINTER_PEN,
86 NSCursorPointingDevice = NX_TABLET_POINTER_CURSOR,
87 NSEraserPointingDevice = NX_TABLET_POINTER_ERASER
88 } 60 }
89 61
90 alias NSPointingDeviceType.NSUnknownPointingDevice NSUnknownPointingDevice; 62 public this(objc.id id) {
91 alias NSPointingDeviceType.NSPenPointingDevice NSPenPointingDevice; 63 super(id);
92 alias NSPointingDeviceType.NSCursorPointingDevice NSCursorPointingDevice; 64 }
93 alias NSPointingDeviceType.NSEraserPointingDevice NSEraserPointingDevice;
94 65
95 public class NSEvent : NSObject 66 public this(cocoa.id id) {
96 { 67 super(id);
97 public this () 68 }
98 {
99 super();
100 }
101 69
102 public this (objc.id id) 70 public NSInteger buttonNumber() {
103 { 71 return OS.objc_msgSend(this.id, OS.sel_buttonNumber);
104 super(id); 72 }
105 }
106 73
107 public CGEventRef CGEvent () 74 public NSString characters() {
108 { 75 objc.id result = OS.objc_msgSend(this.id, OS.sel_characters);
109 return cast(CGEventRef) OS.objc_msgSend(this.id_, OS.sel_CGEvent); 76 return result !is null ? new NSString(result) : null;
110 } 77 }
111 78
112 public NSInteger absoluteX () 79 public NSString charactersIgnoringModifiers() {
113 { 80 objc.id result = OS.objc_msgSend(this.id, OS.sel_charactersIgnoringModifiers);
114 return cast(NSInteger) OS.objc_msgSend(this.id_, OS.sel_absoluteX); 81 return result !is null ? new NSString(result) : null;
115 } 82 }
116 83
117 public NSInteger absoluteY () 84 public NSInteger clickCount() {
118 { 85 return cast(NSInteger) OS.objc_msgSend(this.id, OS.sel_clickCount);
119 return cast(NSInteger) OS.objc_msgSend(this.id_, OS.sel_absoluteY); 86 }
120 }
121 87
122 public NSInteger absoluteZ () 88 public CGFloat deltaX() {
123 { 89 return cast(CGFloat) OS.objc_msgSend_fpret(this.id, OS.sel_deltaX);
124 return cast(NSInteger) OS.objc_msgSend(this.id_, OS.sel_absoluteZ); 90 }
125 }
126 91
127 public NSUInteger buttonMask () 92 public CGFloat deltaY() {
128 { 93 return cast(CGFloat) OS.objc_msgSend_fpret(this.id, OS.sel_deltaY);
129 return cast(NSUInteger) OS.objc_msgSend(this.id_, OS.sel_buttonMask); 94 }
130 }
131 95
132 public NSInteger buttonNumber () 96 public ushort keyCode() {
133 { 97 return cast(ushort) OS.objc_msgSend(this.id, OS.sel_keyCode);
134 return cast(NSInteger) OS.objc_msgSend(this.id_, OS.sel_buttonNumber); 98 }
135 }
136 99
137 public NSUInteger capabilityMask () 100 public NSPoint locationInWindow() {
138 { 101 NSPoint result = NSPoint();
139 return cast(NSUInteger) OS.objc_msgSend(this.id_, OS.sel_capabilityMask); 102 OS.objc_msgSend_stret(result, this.id, OS.sel_locationInWindow);
140 } 103 return result;
104 }
141 105
142 public NSString characters () 106 public int /*long*/ modifierFlags() {
143 { 107 return OS.objc_msgSend(this.id, OS.sel_modifierFlags);
144 objc.id result = OS.objc_msgSend(this.id_, OS.sel_characters); 108 }
145 return result !is null ? new NSString(result) : null;
146 }
147 109
148 public NSString charactersIgnoringModifiers () 110 public static NSPoint mouseLocation() {
149 { 111 NSPoint result = NSPoint();
150 objc.id result = OS.objc_msgSend(this.id_, OS.sel_charactersIgnoringModifiers); 112 OS.objc_msgSend_stret(result, OS.class_NSEvent, OS.sel_mouseLocation);
151 return result !is null ? new NSString(result) : null; 113 return result;
152 } 114 }
153 115
154 public NSInteger clickCount () 116 public static NSEvent otherEventWithType(NSEventType type, NSPoint location, NSUInteger flags, double time, NSTimeInterval wNum, NSGraphicsContext context, short subtype, NSInteger d1, NSInteger d2) {
155 { 117 objc.id result = OS.objc_msgSend(OS.class_NSEvent, OS.sel_otherEventWithType_location_modifierFlags_timestamp_windowNumber_context_subtype_data1_data2_, type, location, flags, time, wNum, context !is null ? context.id : null, subtype, d1, d2);
156 return cast(NSInteger) OS.objc_msgSend(this.id_, OS.sel_clickCount); 118 return result !is null ? new NSEvent(result) : null;
157 } 119 }
158 120
159 public NSGraphicsContext context () 121 public NSEventType type() {
160 { 122 return OS.objc_msgSend(this.id, OS.sel_type);
161 objc.id result = OS.objc_msgSend(this.id_, OS.sel_context); 123 }
162 return result !is null ? new NSGraphicsContext(result) : null;
163 }
164 124
165 public NSInteger data1 () 125 public NSWindow window() {
166 { 126 objc.id result = OS.objc_msgSend(this.id, OS.sel_window);
167 return cast(NSInteger) OS.objc_msgSend(this.id_, OS.sel_data1); 127 return result !is null ? new NSWindow(result) : null;
168 } 128 }
169
170 public NSInteger data2 ()
171 {
172 return cast(NSInteger) OS.objc_msgSend(this.id_, OS.sel_data2);
173 }
174
175 public CGFloat deltaX ()
176 {
177 return cast(CGFloat) OS.objc_msgSend_fpret(this.id_, OS.sel_deltaX);
178 }
179
180 public CGFloat deltaY ()
181 {
182 return cast(CGFloat) OS.objc_msgSend_fpret(this.id_, OS.sel_deltaY);
183 }
184
185 public CGFloat deltaZ ()
186 {
187 return cast(CGFloat) OS.objc_msgSend_fpret(this.id_, OS.sel_deltaZ);
188 }
189
190 public NSUInteger deviceID ()
191 {
192 return cast(NSUInteger) OS.objc_msgSend(this.id_, OS.sel_deviceID);
193 }
194
195 public static NSEvent enterExitEventWithType (objc.id type, NSPoint location, NSUInteger flags, NSTimeInterval time, NSInteger wNum,
196 NSGraphicsContext context, NSInteger eNum, NSInteger tNum, void* data)
197 {
198 objc.id result = OS.objc_msgSend(OS.class_NSEvent,
199 OS.sel_enterExitEventWithType_1location_1modifierFlags_1timestamp_1windowNumber_1context_1eventNumber_1trackingNumber_1userData_1,
200 type, location, flags, time, wNum, context !is null ? context.id_ : null, eNum, tNum, data);
201 return result !is null ? new NSEvent(result) : null;
202 }
203
204 public NSInteger eventNumber ()
205 {
206 return cast(NSInteger) OS.objc_msgSend(this.id_, OS.sel_eventNumber);
207 }
208
209 public /*const*/void* eventRef ()
210 {
211 return OS.objc_msgSend(this.id_, OS.sel_eventRef);
212 }
213
214 public static NSEvent eventWithCGEvent (CGEventRef cgEvent)
215 {
216 objc.id result = OS.objc_msgSend(OS.class_NSEvent, OS.sel_eventWithCGEvent_1, cgEvent);
217 return result !is null ? new NSEvent(result) : null;
218 }
219
220 public static NSEvent eventWithEventRef (/*const*/void* eventRef)
221 {
222 objc.id result = OS.objc_msgSend(OS.class_NSEvent, OS.sel_eventWithEventRef_1, eventRef);
223 return result !is null ? new NSEvent(result) : null;
224 }
225
226 public bool isARepeat ()
227 {
228 return OS.objc_msgSend(this.id_, OS.sel_isARepeat) !is null;
229 }
230
231 public bool isEnteringProximity ()
232 {
233 return OS.objc_msgSend(this.id_, OS.sel_isEnteringProximity) !is null;
234 }
235
236 public static bool isMouseCoalescingEnabled ()
237 {
238 return OS.objc_msgSend(OS.class_NSEvent, OS.sel_isMouseCoalescingEnabled) !is null;
239 }
240
241 public short keyCode ()
242 {
243 return cast(short) OS.objc_msgSend(this.id_, OS.sel_keyCode);
244 }
245
246 public static NSEvent keyEventWithType (NSEventType type, NSPoint location, NSUInteger flags, NSTimeInterval time, NSInteger wNum,
247 NSGraphicsContext context, NSString keys, NSString ukeys, bool flag, short code)
248 {
249 objc.id
250 result = OS.objc_msgSend(
251 OS.class_NSEvent,
252 OS.sel_keyEventWithType_1location_1modifierFlags_1timestamp_1windowNumber_1context_1characters_1charactersIgnoringModifiers_1isARepeat_1keyCode_1,
253 type, location, flags, time, wNum, context !is null ? context.id_ : null, keys !is null ? keys.id_ : null,
254 ukeys !is null ? ukeys.id_ : null, flag, code);
255 return result !is null ? new NSEvent(result) : null;
256 }
257
258 public NSPoint locationInWindow ()
259 {
260 NSPoint result;
261 OS.objc_msgSend_struct(&result, this.id_, OS.sel_locationInWindow);
262 return result;
263 }
264
265 public NSUInteger modifierFlags ()
266 {
267 return cast(NSUInteger) OS.objc_msgSend(this.id_, OS.sel_modifierFlags);
268 }
269
270 public static NSEvent mouseEventWithType (NSEventType type, NSPoint location, NSUInteger flags, NSTimeInterval time, NSInteger wNum,
271 NSGraphicsContext context, NSInteger eNum, NSInteger cNum, float pressure)
272 {
273 objc.id result = OS.objc_msgSend(OS.class_NSEvent,
274 OS.sel_mouseEventWithType_1location_1modifierFlags_1timestamp_1windowNumber_1context_1eventNumber_1clickCount_1pressure_1, type,
275 location, flags, time, wNum, context !is null ? context.id_ : null, eNum, cNum, pressure);
276 return result !is null ? new NSEvent(result) : null;
277 }
278
279 public static NSPoint mouseLocation ()
280 {
281 NSPoint result;
282 OS.objc_msgSend_struct(&result, OS.class_NSEvent, OS.sel_mouseLocation);
283 return result;
284 }
285
286 public static NSEvent otherEventWithType (NSEventType type, NSPoint location, NSUInteger flags, NSTimeInterval time, NSInteger wNum, NSGraphicsContext context,
287 short subtype, NSInteger d1, NSInteger d2)
288 {
289 objc.id result = OS.objc_msgSend(OS.class_NSEvent,
290 OS.sel_otherEventWithType_1location_1modifierFlags_1timestamp_1windowNumber_1context_1subtype_1data1_1data2_1, type, location, flags,
291 time, wNum, context !is null ? context.id_ : null, subtype, d1, d2);
292 return result !is null ? new NSEvent(result) : null;
293 }
294
295 public NSUInteger pointingDeviceID ()
296 {
297 return cast(NSUInteger) OS.objc_msgSend(this.id_, OS.sel_pointingDeviceID);
298 }
299
300 public NSUInteger pointingDeviceSerialNumber ()
301 {
302 return cast(NSUInteger) OS.objc_msgSend(this.id_, OS.sel_pointingDeviceSerialNumber);
303 }
304
305 public NSPointingDeviceType pointingDeviceType ()
306 {
307 return cast(NSPointingDeviceType) OS.objc_msgSend(this.id_, OS.sel_pointingDeviceType);
308 }
309
310 public float pressure ()
311 {
312 return cast(float) OS.objc_msgSend_fpret(this.id_, OS.sel_pressure);
313 }
314
315 public float rotation ()
316 {
317 return cast(float) OS.objc_msgSend_fpret(this.id_, OS.sel_rotation);
318 }
319
320 public static void setMouseCoalescingEnabled (bool flag)
321 {
322 OS.objc_msgSend(OS.class_NSEvent, OS.sel_setMouseCoalescingEnabled_1, flag);
323 }
324
325 public static void startPeriodicEventsAfterDelay (double delay, double period)
326 {
327 OS.objc_msgSend(OS.class_NSEvent, OS.sel_startPeriodicEventsAfterDelay_1withPeriod_1, delay, period);
328 }
329
330 public static void stopPeriodicEvents ()
331 {
332 OS.objc_msgSend(OS.class_NSEvent, OS.sel_stopPeriodicEvents);
333 }
334
335 public short subtype ()
336 {
337 return cast(short) OS.objc_msgSend(this.id_, OS.sel_subtype);
338 }
339
340 public NSUInteger systemTabletID ()
341 {
342 return cast(NSUInteger) OS.objc_msgSend(this.id_, OS.sel_systemTabletID);
343 }
344
345 public NSUInteger tabletID ()
346 {
347 return cast(NSUInteger) OS.objc_msgSend(this.id_, OS.sel_tabletID);
348 }
349
350 public float tangentialPressure ()
351 {
352 return cast(float) OS.objc_msgSend_fpret(this.id_, OS.sel_tangentialPressure);
353 }
354
355 public NSPoint tilt ()
356 {
357 NSPoint result;
358 OS.objc_msgSend_stret(&result, this.id_, OS.sel_tilt);
359 return result;
360 }
361
362 public NSTimeInterval timestamp ()
363 {
364 return OS.objc_msgSend_fpret(this.id_, OS.sel_timestamp);
365 }
366
367 public NSTrackingArea trackingArea ()
368 {
369 objc.id result = OS.objc_msgSend(this.id_, OS.sel_trackingArea);
370 return result !is null ? new NSTrackingArea(result) : null;
371 }
372
373 public NSInteger trackingNumber ()
374 {
375 return cast(NSInteger) OS.objc_msgSend(this.id_, OS.sel_trackingNumber);
376 }
377
378 public NSEventType type ()
379 {
380 return cast(NSEventType) OS.objc_msgSend(this.id_, OS.sel_type);
381 }
382
383 public long uniqueID ()
384 {
385 return cast(long) OS.objc_msgSend(this.id_, OS.sel_uniqueID);
386 }
387
388 public void* userData ()
389 {
390 return OS.objc_msgSend(this.id_, OS.sel_userData);
391 }
392
393 public id vendorDefined ()
394 {
395 objc.id result = OS.objc_msgSend(this.id_, OS.sel_vendorDefined);
396 return result !is null ? new id(result) : null;
397 }
398
399 public NSUInteger vendorID ()
400 {
401 return cast(NSUInteger) OS.objc_msgSend(this.id_, OS.sel_vendorID);
402 }
403
404 public NSUInteger vendorPointingDeviceType ()
405 {
406 return cast(NSUInteger) OS.objc_msgSend(this.id_, OS.sel_vendorPointingDeviceType);
407 }
408
409 public NSWindow window ()
410 {
411 objc.id result = OS.objc_msgSend(this.id_, OS.sel_window);
412 return result !is null ? new NSWindow(result) : null;
413 }
414
415 public NSInteger windowNumber ()
416 {
417 return cast(NSInteger) OS.objc_msgSend(this.id_, OS.sel_windowNumber);
418 }
419 129
420 } 130 }