comparison dwt/widgets/Display.d @ 61:c74ba20de292

Fix: The application responds to events now
author Jacob Carlborg <doob@me.com>
date Tue, 23 Dec 2008 00:35:24 +0100
parents 62202ce0039f
children 10eaa644646f
comparison
equal deleted inserted replaced
60:62202ce0039f 61:c74ba20de292
65 import dwt.internal.cocoa.NSWindow; 65 import dwt.internal.cocoa.NSWindow;
66 import dwt.internal.cocoa.NSWorkspace; 66 import dwt.internal.cocoa.NSWorkspace;
67 import dwt.internal.cocoa.OS; 67 import dwt.internal.cocoa.OS;
68 import dwt.internal.cocoa.SWTApplicationDelegate; 68 import dwt.internal.cocoa.SWTApplicationDelegate;
69 import dwt.internal.cocoa.SWTWindowDelegate; 69 import dwt.internal.cocoa.SWTWindowDelegate;
70 import dwt.internal.cocoa.id; 70 import cocoa = dwt.internal.cocoa.id;
71 import dwt.internal.cocoa.objc_super; 71 import dwt.internal.cocoa.objc_super;
72 72
73 import tango.core.Thread; 73 import tango.core.Thread;
74 import tango.stdc.stringz; 74 import tango.stdc.stringz;
75 75
179 179
180 /* Windows and Events */ 180 /* Windows and Events */
181 Event [] eventQueue; 181 Event [] eventQueue;
182 EventTable eventTable, filterTable; 182 EventTable eventTable, filterTable;
183 bool disposing; 183 bool disposing;
184 184
185 /* Sync/Async Widget Communication */ 185 /* Sync/Async Widget Communication */
186 Synchronizer synchronizer; 186 Synchronizer synchronizer;
187 Thread thread; 187 Thread thread;
188 bool allowTimers, runAsyncMessages_; 188 bool allowTimers, runAsyncMessages_;
189 189
190 NSGraphicsContext[] contexts; 190 NSGraphicsContext[] contexts;
191 191
192 Caret currentCaret; 192 Caret currentCaret;
193 193
194 bool dragging; 194 bool dragging;
195 Control currentControl, grabControl, trackingControl; 195 Control currentControl, grabControl, trackingControl;
196 196
197 NSDictionary markedAttributes; 197 NSDictionary markedAttributes;
198 198
199 Shell [] modalShells; 199 Shell [] modalShells;
200 200
201 Menu menuBar; 201 Menu menuBar;
202 Menu[] menus, popups; 202 Menu[] menus, popups;
203 203
204 NSApplication application; 204 NSApplication application;
205 objc.Class applicationClass; 205 objc.Class applicationClass;
206 NSImage dockImage; 206 NSImage dockImage;
207 bool isEmbedded; 207 bool isEmbedded;
208 208
211 NSWindow screenWindow; 211 NSWindow screenWindow;
212 NSAutoreleasePool pool; 212 NSAutoreleasePool pool;
213 int loopCounter = 0; 213 int loopCounter = 0;
214 bool idle; 214 bool idle;
215 static const short SWT_IDLE_TYPE = 1; 215 static const short SWT_IDLE_TYPE = 1;
216 216
217 int[] screenID; 217 int[] screenID;
218 NSPoint[] screenCascade; 218 NSPoint[] screenCascade;
219 219
220 /* Menus */ 220 /* Menus */
221 // Menu menuBar; 221 // Menu menuBar;
222 // static final int ID_TEMPORARY = 1000; 222 // static final int ID_TEMPORARY = 1000;
223 // static final int ID_START = 1001; 223 // static final int ID_START = 1001;
224 224
225 /* Display Shutdown */ 225 /* Display Shutdown */
226 Runnable [] disposeList; 226 Runnable [] disposeList;
227 227
228 /* System Tray */ 228 /* System Tray */
229 Tray tray; 229 Tray tray;
230 230
231 /* System Resources */ 231 /* System Resources */
232 Image errorImage, infoImage, warningImage; 232 Image errorImage, infoImage, warningImage;
233 Cursor [] cursors; 233 Cursor [] cursors;
234 234
235 /* Key Mappings. */ 235 /* Key Mappings. */
236 static int [] [] KeyTable = [ 236 static int [] [] KeyTable = [
237 237
238 /* Keyboard and Mouse Masks */ 238 /* Keyboard and Mouse Masks */
239 [58, DWT.ALT], 239 [58, DWT.ALT],
240 [56, DWT.SHIFT], 240 [56, DWT.SHIFT],
241 [59, DWT.CONTROL], 241 [59, DWT.CONTROL],
242 [55, DWT.COMMAND], 242 [55, DWT.COMMAND],
243 [61, DWT.ALT], 243 [61, DWT.ALT],
244 [62, DWT.CONTROL], 244 [62, DWT.CONTROL],
245 [60, DWT.SHIFT], 245 [60, DWT.SHIFT],
246 [54, DWT.COMMAND], 246 [54, DWT.COMMAND],
247 247
248 /* Non-Numeric Keypad Keys */ 248 /* Non-Numeric Keypad Keys */
249 [126, DWT.ARROW_UP], 249 [126, DWT.ARROW_UP],
250 [125, DWT.ARROW_DOWN], 250 [125, DWT.ARROW_DOWN],
251 [123, DWT.ARROW_LEFT], 251 [123, DWT.ARROW_LEFT],
252 [124, DWT.ARROW_RIGHT], 252 [124, DWT.ARROW_RIGHT],
253 [116, DWT.PAGE_UP], 253 [116, DWT.PAGE_UP],
254 [121, DWT.PAGE_DOWN], 254 [121, DWT.PAGE_DOWN],
255 [115, DWT.HOME], 255 [115, DWT.HOME],
256 [119, DWT.END], 256 [119, DWT.END],
257 // [??, DWT.INSERT], 257 // [??, DWT.INSERT],
258 258
259 /* Virtual and Ascii Keys */ 259 /* Virtual and Ascii Keys */
260 [51, DWT.BS], 260 [51, DWT.BS],
261 [36, DWT.CR], 261 [36, DWT.CR],
262 [117, DWT.DEL], 262 [117, DWT.DEL],
263 [53, DWT.ESC], 263 [53, DWT.ESC],
264 [76, DWT.LF], 264 [76, DWT.LF],
265 [48, DWT.TAB], 265 [48, DWT.TAB],
266 266
267 /* Functions Keys */ 267 /* Functions Keys */
268 [122, DWT.F1], 268 [122, DWT.F1],
269 [120, DWT.F2], 269 [120, DWT.F2],
270 [99, DWT.F3], 270 [99, DWT.F3],
271 [118, DWT.F4], 271 [118, DWT.F4],
272 [96, DWT.F5], 272 [96, DWT.F5],
273 [97, DWT.F6], 273 [97, DWT.F6],
274 [98, DWT.F7], 274 [98, DWT.F7],
275 [100, DWT.F8], 275 [100, DWT.F8],
276 [101, DWT.F9], 276 [101, DWT.F9],
277 [109, DWT.F10], 277 [109, DWT.F10],
278 [103, DWT.F11], 278 [103, DWT.F11],
279 [111, DWT.F12], 279 [111, DWT.F12],
280 [105, DWT.F13], 280 [105, DWT.F13],
281 [107, DWT.F14], 281 [107, DWT.F14],
282 [113, DWT.F15], 282 [113, DWT.F15],
283 283
284 /* Numeric Keypad Keys */ 284 /* Numeric Keypad Keys */
285 [67, DWT.KEYPAD_MULTIPLY], 285 [67, DWT.KEYPAD_MULTIPLY],
286 [69, DWT.KEYPAD_ADD], 286 [69, DWT.KEYPAD_ADD],
287 [76, DWT.KEYPAD_CR], 287 [76, DWT.KEYPAD_CR],
288 [78, DWT.KEYPAD_SUBTRACT], 288 [78, DWT.KEYPAD_SUBTRACT],
289 [65, DWT.KEYPAD_DECIMAL], 289 [65, DWT.KEYPAD_DECIMAL],
290 [75, DWT.KEYPAD_DIVIDE], 290 [75, DWT.KEYPAD_DIVIDE],
291 [82, DWT.KEYPAD_0], 291 [82, DWT.KEYPAD_0],
292 [83, DWT.KEYPAD_1], 292 [83, DWT.KEYPAD_1],
293 [84, DWT.KEYPAD_2], 293 [84, DWT.KEYPAD_2],
294 [85, DWT.KEYPAD_3], 294 [85, DWT.KEYPAD_3],
295 [86, DWT.KEYPAD_4], 295 [86, DWT.KEYPAD_4],
296 [87, DWT.KEYPAD_5], 296 [87, DWT.KEYPAD_5],
297 [88, DWT.KEYPAD_6], 297 [88, DWT.KEYPAD_6],
298 [89, DWT.KEYPAD_7], 298 [89, DWT.KEYPAD_7],
299 [91, DWT.KEYPAD_8], 299 [91, DWT.KEYPAD_8],
300 [92, DWT.KEYPAD_9], 300 [92, DWT.KEYPAD_9],
301 [81, DWT.KEYPAD_EQUAL], 301 [81, DWT.KEYPAD_EQUAL],
302 302
303 /* Other keys */ 303 /* Other keys */
304 [57, DWT.CAPS_LOCK], 304 [57, DWT.CAPS_LOCK],
305 [71, DWT.NUM_LOCK], 305 [71, DWT.NUM_LOCK],
306 // [??, DWT.SCROLL_LOCK], 306 // [??, DWT.SCROLL_LOCK],
307 // [??, DWT.PAUSE], 307 // [??, DWT.PAUSE],
308 // [??, DWT.BREAK], 308 // [??, DWT.BREAK],
309 // [??, DWT.PRINT_SCREEN], 309 // [??, DWT.PRINT_SCREEN],
310 [114, DWT.HELP], 310 [114, DWT.HELP],
311 311
312 ]; 312 ];
313 313
314 static String APP_NAME = "DWT"; 314 static String APP_NAME = "DWT";
315 static const String ADD_WIDGET_KEY = "dwt.internal.addWidget"; 315 static const String ADD_WIDGET_KEY = "dwt.internal.addWidget";
316 static const String SWT_OBJECT = "SWT_OBJECT"; //$NON-NLS-1$ 316 static const String SWT_OBJECT = "SWT_OBJECT"; //$NON-NLS-1$
317 317
318 /* Multiple Displays. */ 318 /* Multiple Displays. */
319 static Display Default; 319 static Display Default;
320 static Display [] Displays; 320 static Display [] Displays;
321 321
322 /* Package Name */ 322 /* Package Name */
323 static const String PACKAGE_PREFIX = "dwt.widgets."; 323 static const String PACKAGE_PREFIX = "dwt.widgets.";
324 324
325 /* Timer */ 325 /* Timer */
326 Runnable timerList []; 326 Runnable timerList [];
327 NSTimer nsTimers []; 327 NSTimer nsTimers [];
328 SWTWindowDelegate timerDelegate; 328 SWTWindowDelegate timerDelegate;
329 SWTApplicationDelegate applicationDelegate; 329 SWTApplicationDelegate applicationDelegate;
332 Object data; 332 Object data;
333 String [] keys; 333 String [] keys;
334 Object [] values; 334 Object [] values;
335 335
336 /* 336 /*
337 * TEMPORARY CODE. Install the runnable that 337 * TEMPORARY CODE. Install the runnable that
338 * gets the current display. This code will 338 * gets the current display. This code will
339 * be removed in the future. 339 * be removed in the future.
340 */ 340 */
341 static this () { 341 static this () {
342 Displays = new Display [4];
342 DeviceFinder = new class Runnable { 343 DeviceFinder = new class Runnable {
343 public void run () { 344 public void run () {
344 Device device = getCurrent (); 345 Device device = getCurrent ();
345 if (device is null) { 346 if (device is null) {
346 device = getDefault (); 347 device = getDefault ();
347 } 348 }
348 setDevice (device); 349 setDevice (device);
349 } 350 }
351 };
352 }
353
354 /*
355 * TEMPORARY CODE.
356 */
357 static void setDevice (Device device) {
358 CurrentDevice = device;
359 }
360
361 static char* ascii (String name) {
362 /*int length = name.length ();
363 char [] chars = new char [length];
364 name.getChars (0, length, chars, 0);
365 byte [] buffer = new byte [length + 1];
366 for (int i=0; i<length; i++) {
367 buffer [i] = cast(byte) chars [i];
368 }
369 return buffer;*/
370 return name.toStringz();
371 }
372
373 static int translateKey (int key) {
374 for (int i=0; i<KeyTable.length; i++) {
375 if (KeyTable [i] [0] is key) return KeyTable [i] [1];
376 }
377 return 0;
378 }
379
380 static int untranslateKey (int key) {
381 for (int i=0; i<KeyTable.length; i++) {
382 if (KeyTable [i] [1] is key) return KeyTable [i] [0];
383 }
384 return 0;
385 }
386
387 void addContext (NSGraphicsContext context) {
388 if (contexts is null) contexts = new NSGraphicsContext [12];
389 for (int i=0; i<contexts.length; i++) {
390 if (contexts[i] !is null && contexts [i].id is context.id) {
391 contexts [i] = context;
392 return;
393 }
394 }
395 NSGraphicsContext [] newContexts = new NSGraphicsContext [contexts.length + 12];
396 newContexts [contexts.length] = context;
397 System.arraycopy (contexts, 0, newContexts, 0, contexts.length);
398 contexts = newContexts;
399 }
400
401 /**
402 * Adds the listener to the collection of listeners who will
403 * be notified when an event of the given type occurs anywhere
404 * in a widget. The event type is one of the event constants
405 * defined in class <code>DWT</code>. When the event does occur,
406 * the listener is notified by sending it the <code>handleEvent()</code>
407 * message.
408 * <p>
409 * Setting the type of an event to <code>DWT.None</code> from
410 * within the <code>handleEvent()</code> method can be used to
411 * change the event type and stop subsequent Java listeners
412 * from running. Because event filters run before other listeners,
413 * event filters can both block other listeners and set arbitrary
414 * fields within an event. For this reason, event filters are both
415 * powerful and dangerous. They should generally be avoided for
416 * performance, debugging and code maintenance reasons.
417 * </p>
418 *
419 * @param eventType the type of event to listen for
420 * @param listener the listener which should be notified when the event occurs
421 *
422 * @exception IllegalArgumentException <ul>
423 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
424 * </ul>
425 * @exception DWTException <ul>
426 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
427 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
428 * </ul>
429 *
430 * @see Listener
431 * @see DWT
432 * @see #removeFilter
433 * @see #removeListener
434 *
435 * @since 3.0
436 */
437 public void addFilter (int eventType, Listener listener) {
438 checkDevice ();
439 if (listener is null) error (DWT.ERROR_NULL_ARGUMENT);
440 if (filterTable is null) filterTable = new EventTable ();
441 filterTable.hook (eventType, listener);
442 }
443
444 /**
445 * Adds the listener to the collection of listeners who will
446 * be notified when an event of the given type occurs. The event
447 * type is one of the event constants defined in class <code>DWT</code>.
448 * When the event does occur in the display, the listener is notified by
449 * sending it the <code>handleEvent()</code> message.
450 *
451 * @param eventType the type of event to listen for
452 * @param listener the listener which should be notified when the event occurs
453 *
454 * @exception IllegalArgumentException <ul>
455 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
456 * </ul>
457 * @exception DWTException <ul>
458 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
459 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
460 * </ul>
461 *
462 * @see Listener
463 * @see DWT
464 * @see #removeListener
465 *
466 * @since 2.0
467 */
468 public void addListener (int eventType, Listener listener) {
469 checkDevice ();
470 if (listener is null) error (DWT.ERROR_NULL_ARGUMENT);
471 if (eventTable is null) eventTable = new EventTable ();
472 eventTable.hook (eventType, listener);
473 }
474
475 void addMenu (Menu menu) {
476 if (menus is null) menus = new Menu [12];
477 for (int i=0; i<menus.length; i++) {
478 if (menus [i] is null) {
479 menus [i] = menu;
480 return;
481 }
482 }
483 Menu [] newMenus = new Menu [menus.length + 12];
484 newMenus [menus.length] = menu;
485 System.arraycopy (menus, 0, newMenus, 0, menus.length);
486 menus = newMenus;
487 }
488
489 void addPopup (Menu menu) {
490 if (popups is null) popups = new Menu [4];
491 int length = popups.length;
492 for (int i=0; i<length; i++) {
493 if (popups [i] is menu) return;
494 }
495 int index = 0;
496 while (index < length) {
497 if (popups [index] is null) break;
498 index++;
499 }
500 if (index is length) {
501 Menu [] newPopups = new Menu [length + 4];
502 System.arraycopy (popups, 0, newPopups, 0, length);
503 popups = newPopups;
504 }
505 popups [index] = menu;
506 }
507
508 void addWidget (NSObject view, Widget widget) {
509 if (view is null) return;
510 OS.object_setInstanceVariable (view.id, SWT_OBJECT, widget.jniRef);
511 }
512
513 /**
514 * Causes the <code>run()</code> method of the runnable to
515 * be invoked by the user-interface thread at the next
516 * reasonable opportunity. The caller of this method continues
517 * to run in parallel, and is not notified when the
518 * runnable has completed. Specifying <code>null</code> as the
519 * runnable simply wakes the user-interface thread when run.
520 * <p>
521 * Note that at the time the runnable is invoked, widgets
522 * that have the receiver as their display may have been
523 * disposed. Therefore, it is necessary to check for this
524 * case inside the runnable before accessing the widget.
525 * </p>
526 *
527 * @param runnable code to run on the user-interface thread or <code>null</code>
528 *
529 * @exception DWTException <ul>
530 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
531 * </ul>
532 *
533 * @see #syncExec
534 */
535 public void asyncExec (Runnable runnable) {
536 synchronized (Device.classinfo) {
537 if (isDisposed ()) error (DWT.ERROR_DEVICE_DISPOSED);
538 synchronizer.asyncExec (runnable);
539 }
540 }
541
542 /**
543 * Causes the system hardware to emit a short sound
544 * (if it supports this capability).
545 *
546 * @exception DWTException <ul>
547 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
548 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
549 * </ul>
550 */
551 public void beep () {
552 checkDevice ();
553 OS.NSBeep ();
554 }
555
556 void cascadeWindow (NSWindow window, NSScreen screen) {
557 NSDictionary dictionary = screen.deviceDescription();
558 int screenNumber = (new NSNumber(dictionary.objectForKey(NSString.stringWith("NSScreenNumber")).id)).intValue();
559 int index = 0;
560 while (screenID[index] !is 0 && screenID[index] !is screenNumber) index++;
561 screenID[index] = screenNumber;
562 NSPoint cascade = screenCascade[index];
563 //FIXME Jacob Carlborg
564 /*if (cascade is null) {
565 NSRect frame = screen.frame();
566 cascade = NSPoint();
567 cascade.x = frame.x;
568 cascade.y = frame.y + frame.height;
569 }*/
570 screenCascade[index] = window.cascadeTopLeftFromPoint(cascade);
571 }
572
573 protected void checkDevice () {
574 if (thread is null) error (DWT.ERROR_WIDGET_DISPOSED);
575 if (thread !is Thread.getThis ()) error (DWT.ERROR_THREAD_INVALID_ACCESS);
576 if (isDisposed ()) error (DWT.ERROR_DEVICE_DISPOSED);
577 }
578
579 /**
580 * Checks that this class can be subclassed.
581 * <p>
582 * IMPORTANT: See the comment in <code>Widget.checkSubclass()</code>.
583 * </p>
584 *
585 * @exception DWTException <ul>
586 * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
587 * </ul>
588 *
589 * @see Widget#checkSubclass
590 */
591 protected void checkSubclass () {
592 if (!Display.isValidClass (this.classinfo)) error (DWT.ERROR_INVALID_SUBCLASS);
593 }
594
595 /**
596 * Constructs a new instance of this class.
597 * <p>
598 * Note: The resulting display is marked as the <em>current</em>
599 * display. If this is the first display which has been
600 * constructed since the application started, it is also
601 * marked as the <em>default</em> display.
602 * </p>
603 *
604 * @exception DWTException <ul>
605 * <li>ERROR_THREAD_INVALID_ACCESS - if called from a thread that already created an existing display</li>
606 * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
607 * </ul>
608 *
609 * @see #getCurrent
610 * @see #getDefault
611 * @see Widget#checkSubclass
612 * @see Shell
613 */
614 public this () {
615 this (null);
616 }
617
618 /**
619 * Constructs a new instance of this class using the parameter.
620 *
621 * @param data the device data
622 */
623 public this (DeviceData data) {
624 super (data);
625 screenID = new int[32];
626 screenCascade = new NSPoint[32];
627 cursors = new Cursor [DWT.CURSOR_HAND + 1];
628 timerDelegate = cast(SWTWindowDelegate)(new SWTWindowDelegate()).alloc().init();
629
630 caretTimer = new class(currentCaret) Runnable {
631 Caret currentCaret;
632
633 this (Caret currentCaret)
634 {
635 this.currentCaret = currentCaret;
636 }
637
638 public void run () {
639 if (currentCaret !is null) {
640 if (currentCaret is null || currentCaret.isDisposed()) return;
641 if (currentCaret.blinkCaret ()) {
642 int blinkRate = currentCaret.blinkRate;
643 if (blinkRate !is 0) timerExec (blinkRate, this);
644 } else {
645 currentCaret = null;
646 }
647 }
648
649 }
350 }; 650 };
351 } 651
352 652 hoverTimer = new class(currentControl) Runnable {
353 /* 653 Control currentControl;
354 * TEMPORARY CODE. 654
355 */ 655 this (Control currentControl)
356 static void setDevice (Device device) { 656 {
357 CurrentDevice = device; 657 this.currentControl = currentControl;
358 } 658 }
359 659
360 static char* ascii (String name) { 660 public void run () {
361 /*int length = name.length (); 661 if (currentControl !is null && !currentControl.isDisposed()) {
362 char [] chars = new char [length]; 662 currentControl.sendMouseEvent (null, DWT.MouseHover, trackingControl !is null);
363 name.getChars (0, length, chars, 0); 663 }
364 byte [] buffer = new byte [length + 1]; 664 }
365 for (int i=0; i<length; i++) { 665 };
366 buffer [i] = cast(byte) chars [i]; 666 }
367 } 667
368 return buffer;*/ 668 static void checkDisplay (Thread thread, bool multiple) {
369 return name.toStringz(); 669 synchronized (Device.classinfo) {
370 } 670 for (int i=0; i<Displays.length; i++) {
371 671 if (Displays [i] !is null) {
372 static int translateKey (int key) { 672 if (!multiple) DWT.error (DWT.ERROR_NOT_IMPLEMENTED, null, " [multiple displays]");
373 for (int i=0; i<KeyTable.length; i++) { 673 if (Displays [i].thread is thread) DWT.error (DWT.ERROR_THREAD_INVALID_ACCESS);
374 if (KeyTable [i] [0] is key) return KeyTable [i] [1]; 674 }
375 } 675 }
376 return 0; 676 }
377 } 677 }
378 678
379 static int untranslateKey (int key) { 679 static String convertToLf(String text) {
380 for (int i=0; i<KeyTable.length; i++) { 680 char Cr = '\r';
381 if (KeyTable [i] [1] is key) return KeyTable [i] [0]; 681 char Lf = '\n';
382 } 682 int length = text.length ();
383 return 0; 683 if (length is 0) return text;
384 } 684
385 685 /* Check for an LF or CR/LF. Assume the rest of the string
386 void addContext (NSGraphicsContext context) { 686 * is formated that way. This will not work if the string
387 if (contexts is null) contexts = new NSGraphicsContext [12]; 687 * contains mixed delimiters. */
388 for (int i=0; i<contexts.length; i++) { 688 int i = text.indexOf (Lf, 0);
389 if (contexts[i] !is null && contexts [i].id is context.id) { 689 if (i is -1 || i is 0) return text;
390 contexts [i] = context; 690 if (text.charAt (i - 1) !is Cr) return text;
391 return; 691
392 } 692 /* The string is formatted with CR/LF.
393 } 693 * Create a new string with the LF line delimiter. */
394 NSGraphicsContext [] newContexts = new NSGraphicsContext [contexts.length + 12]; 694 i = 0;
395 newContexts [contexts.length] = context; 695 StringBuffer result = new StringBuffer ();
396 System.arraycopy (contexts, 0, newContexts, 0, contexts.length); 696 while (i < length) {
397 contexts = newContexts; 697 int j = text.indexOf (Cr, i);
398 } 698 if (j is -1) j = length;
399 699 String s = text.substring (i, j);
400 /** 700 result.append (s);
401 * Adds the listener to the collection of listeners who will 701 i = j + 2;
402 * be notified when an event of the given type occurs anywhere 702 result.append (Lf);
403 * in a widget. The event type is one of the event constants 703 }
404 * defined in class <code>DWT</code>. When the event does occur, 704 return result.toString ();
405 * the listener is notified by sending it the <code>handleEvent()</code> 705 }
406 * message. 706
407 * <p> 707 void clearModal (Shell shell) {
408 * Setting the type of an event to <code>DWT.None</code> from 708 if (modalShells is null) return;
409 * within the <code>handleEvent()</code> method can be used to 709 int index = 0, length_ = modalShells.length;
410 * change the event type and stop subsequent Java listeners 710 while (index < length_) {
411 * from running. Because event filters run before other listeners, 711 if (modalShells [index] is shell) break;
412 * event filters can both block other listeners and set arbitrary 712 if (modalShells [index] is null) return;
413 * fields within an event. For this reason, event filters are both 713 index++;
414 * powerful and dangerous. They should generally be avoided for 714 }
415 * performance, debugging and code maintenance reasons. 715 if (index is length_) return;
416 * </p> 716 System.arraycopy (modalShells, index + 1, modalShells, index, --length_ - index);
417 * 717 modalShells [length_] = null;
418 * @param eventType the type of event to listen for 718 if (index is 0 && modalShells [0] is null) modalShells = null;
419 * @param listener the listener which should be notified when the event occurs 719 Shell [] shells = getShells ();
420 * 720 for (int i=0; i<shells.length; i++) shells [i].updateModal ();
421 * @exception IllegalArgumentException <ul> 721 }
422 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> 722
423 * </ul> 723 /**
424 * @exception DWTException <ul> 724 * Requests that the connection between DWT and the underlying
425 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 725 * operating system be closed.
426 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> 726 *
427 * </ul> 727 * @exception DWTException <ul>
428 * 728 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
429 * @see Listener 729 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
430 * @see DWT 730 * </ul>
431 * @see #removeFilter 731 *
432 * @see #removeListener 732 * @see Device#dispose
433 * 733 *
434 * @since 3.0 734 * @since 2.0
435 */ 735 */
436 public void addFilter (int eventType, Listener listener) { 736 public void close () {
437 checkDevice (); 737 checkDevice ();
438 if (listener is null) error (DWT.ERROR_NULL_ARGUMENT); 738 Event event = new Event ();
439 if (filterTable is null) filterTable = new EventTable (); 739 sendEvent (DWT.Close, event);
440 filterTable.hook (eventType, listener); 740 if (event.doit) dispose ();
441 } 741 }
442 742
443 /** 743 /**
444 * Adds the listener to the collection of listeners who will 744 * Creates the device in the operating system. If the device
445 * be notified when an event of the given type occurs. The event 745 * does not have a handle, this method may do nothing depending
446 * type is one of the event constants defined in class <code>DWT</code>. 746 * on the device.
447 * When the event does occur in the display, the listener is notified by 747 * <p>
448 * sending it the <code>handleEvent()</code> message. 748 * This method is called before <code>init</code>.
449 * 749 * </p>
450 * @param eventType the type of event to listen for 750 *
451 * @param listener the listener which should be notified when the event occurs 751 * @param data the DeviceData which describes the receiver
452 * 752 *
453 * @exception IllegalArgumentException <ul> 753 * @see #init
454 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> 754 */
455 * </ul> 755 protected void create (DeviceData data) {
456 * @exception DWTException <ul> 756 checkSubclass ();
457 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 757 checkDisplay (thread = Thread.getThis (), false);
458 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> 758 createDisplay (data);
459 * </ul> 759 register (this);
460 * 760 synchronizer = new Synchronizer (this);
461 * @see Listener 761 if (Default is null) Default = this;
462 * @see DWT 762 }
463 * @see #removeListener 763
464 * 764 void createDisplay (DeviceData data) {
465 * @since 2.0 765 if (OS.VERSION < 0x1050) {
466 */ 766 System.out_.println ("***WARNING: DWT requires MacOS X version {}{}{}{}" , 10 , "." , 5 , " or greater"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
467 public void addListener (int eventType, Listener listener) { 767 System.out_.println ("***WARNING: Detected: {}{}{}{}{}" , Integer.toHexString((OS.VERSION & 0xFF00) >> 8) , "." , Integer.toHexString((OS.VERSION & 0xF0) >> 4) , "." , Integer.toHexString(OS.VERSION & 0xF)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
468 checkDevice (); 768 error(DWT.ERROR_NOT_IMPLEMENTED);
469 if (listener is null) error (DWT.ERROR_NULL_ARGUMENT); 769 }
470 if (eventTable is null) eventTable = new EventTable (); 770
471 eventTable.hook (eventType, listener); 771 NSThread nsthread = NSThread.currentThread();
472 } 772 NSMutableDictionary dictionary = nsthread.threadDictionary();
473 773 NSString key = NSString.stringWith("SWT_NSAutoreleasePool");
474 void addMenu (Menu menu) { 774 pool = new NSAutoreleasePool(dictionary.objectForKey(key));
475 if (menus is null) menus = new Menu [12]; 775
476 for (int i=0; i<menus.length; i++) { 776 application = NSApplication.sharedApplication();
477 if (menus [i] is null) { 777
478 menus [i] = menu; 778 /*
479 return; 779 * TODO: If an NSApplication is already running we don't want to create another NSApplication.
480 } 780 * But if we don't we won't get mouse events, since we currently need to subclass NSApplication and intercept sendEvent to
481 } 781 * deliver mouse events correctly to widgets.
482 Menu [] newMenus = new Menu [menus.length + 12]; 782 */
483 newMenus [menus.length] = menu; 783 if (!application.isRunning()) {
484 System.arraycopy (menus, 0, newMenus, 0, menus.length); 784 /*
485 menus = newMenus; 785 * Feature in the Macintosh. On OS 10.2, it is necessary
486 } 786 * to explicitly check in with the Process Manager and set
487 787 * the current process to be the front process in order for
488 void addPopup (Menu menu) { 788 * windows to come to the front by default. The fix is call
489 if (popups is null) popups = new Menu [4]; 789 * both GetCurrentProcess() and SetFrontProcess().
490 int length = popups.length; 790 *
491 for (int i=0; i<length; i++) { 791 * NOTE: It is not actually necessary to use the process
492 if (popups [i] is menu) return; 792 * serial number returned by GetCurrentProcess() in the
493 } 793 * call to SetFrontProcess() (ie. kCurrentProcess can be
494 int index = 0; 794 * used) but both functions must be called in order for
495 while (index < length) { 795 * windows to come to the front.
496 if (popups [index] is null) break; 796 */
497 index++; 797 Carbon.ProcessSerialNumber psn;
498 } 798 if (OS.GetCurrentProcess (&psn) is OS.noErr) {
499 if (index is length) { 799 int pid = OS.getpid ();
500 Menu [] newPopups = new Menu [length + 4]; 800 char* ptr = OS.getenv (ascii ("APP_NAME_" ~ Integer.toString(pid)));
501 System.arraycopy (popups, 0, newPopups, 0, length); 801 if (ptr is null && APP_NAME !is null) {
502 popups = newPopups; 802 ptr = NSString.stringWith(APP_NAME).UTF8String();
503 } 803 }
504 popups [index] = menu; 804 if (ptr !is null) OS.CPSSetProcessName (&psn, ptr);
505 } 805 OS.TransformProcessType (&psn, OS.kProcessTransformToForegroundApplication);
506 806 OS.SetFrontProcess (&psn);
507 void addWidget (NSObject view, Widget widget) { 807 ptr = OS.getenv (ascii ("APP_ICON_" ~ Integer.toString(pid)));
508 if (view is null) return; 808 if (ptr !is null) {
509 OS.object_setInstanceVariable (view.id, SWT_OBJECT, widget.jniRef); 809 NSString path = NSString.stringWithUTF8String (ptr);
510 } 810 NSImage image = cast(NSImage) (new NSImage()).alloc();
511 811 image = image.initByReferencingFile(path);
512 /** 812 dockImage = image;
513 * Causes the <code>run()</code> method of the runnable to 813 application.setApplicationIconImage(image);
514 * be invoked by the user-interface thread at the next 814 }
515 * reasonable opportunity. The caller of this method continues 815 }
516 * to run in parallel, and is not notified when the 816
517 * runnable has completed. Specifying <code>null</code> as the 817 String className = "SWTApplication";
518 * runnable simply wakes the user-interface thread when run. 818 objc.Class cls;
519 * <p> 819 if ((cls = cast(objc.Class) OS.objc_lookUpClass (className)) is null) {
520 * Note that at the time the runnable is invoked, widgets 820 objc.IMP proc2 = cast(objc.IMP) &applicationProc2;
521 * that have the receiver as their display may have been 821 objc.IMP proc3 = cast(objc.IMP) &applicationProc3;
522 * disposed. Therefore, it is necessary to check for this 822 objc.IMP proc6 = cast(objc.IMP) &applicationProc6;
523 * case inside the runnable before accessing the widget. 823 cls = OS.objc_allocateClassPair(cast(objc.Class) OS.class_NSApplication, className, 0);
524 * </p> 824 OS.class_addMethod(cls, OS.sel_registerName("sendEvent:"), proc3, "@:@");
525 * 825
526 * @param runnable code to run on the user-interface thread or <code>null</code> 826 static if ((void*).sizeof > int.sizeof) // 64bit target
527 * 827 OS.class_addMethod(cls, OS.sel_nextEventMatchingMask_untilDate_inMode_dequeue_, proc6, "@:Q@@B");
528 * @exception DWTException <ul> 828 else
529 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> 829 OS.class_addMethod(cls, OS.sel_nextEventMatchingMask_untilDate_inMode_dequeue_, proc6, "@:I@@B");
530 * </ul> 830
531 * 831 OS.class_addMethod(cls, OS.sel_isRunning, proc2, "@:");
532 * @see #syncExec 832 OS.objc_registerClassPair(cls);
533 */ 833 }
534 public void asyncExec (Runnable runnable) { 834 applicationClass = OS.object_setClass(application.id, cls);
535 synchronized (Device.classinfo) { 835 } else {
536 if (isDisposed ()) error (DWT.ERROR_DEVICE_DISPOSED); 836 isEmbedded = true;
537 synchronizer.asyncExec (runnable); 837 }
538 } 838
539 } 839 // application = new NSApplication(OS.objc_msgSend(cls, OS.sel_sharedApplication));
540 840 }
541 /** 841
542 * Causes the system hardware to emit a short sound 842 static void deregister (Display display) {
543 * (if it supports this capability). 843 synchronized (Device.classinfo) {
544 * 844 for (int i=0; i<Displays.length; i++) {
545 * @exception DWTException <ul> 845 if (display is Displays [i]) Displays [i] = null;
546 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 846 }
547 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> 847 }
548 * </ul> 848 }
549 */ 849
550 public void beep () { 850 /**
551 checkDevice (); 851 * Destroys the device in the operating system and releases
552 OS.NSBeep (); 852 * the device's handle. If the device does not have a handle,
553 } 853 * this method may do nothing depending on the device.
554 854 * <p>
555 void cascadeWindow (NSWindow window, NSScreen screen) { 855 * This method is called after <code>release</code>.
556 NSDictionary dictionary = screen.deviceDescription(); 856 * </p>
557 int screenNumber = (new NSNumber(dictionary.objectForKey(NSString.stringWith("NSScreenNumber")).id)).intValue(); 857 * @see Device#dispose
558 int index = 0; 858 * @see #release
559 while (screenID[index] !is 0 && screenID[index] !is screenNumber) index++; 859 */
560 screenID[index] = screenNumber; 860 protected void destroy () {
561 NSPoint cascade = screenCascade[index]; 861 if (this is Default) Default = null;
562 //FIXME Jacob Carlborg 862 deregister (this);
563 /*if (cascade is null) { 863 destroyDisplay ();
864 }
865
866 void destroyDisplay () {
867 application = null;
868 }
869
870 /**
871 * Causes the <code>run()</code> method of the runnable to
872 * be invoked by the user-interface thread just before the
873 * receiver is disposed. Specifying a <code>null</code> runnable
874 * is ignored.
875 *
876 * @param runnable code to run at dispose time.
877 *
878 * @exception DWTException <ul>
879 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
880 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
881 * </ul>
882 */
883 public void disposeExec (Runnable runnable) {
884 checkDevice ();
885 if (disposeList is null) disposeList = new Runnable [4];
886 for (int i=0; i<disposeList.length; i++) {
887 if (disposeList [i] is null) {
888 disposeList [i] = runnable;
889 return;
890 }
891 }
892 Runnable [] newDisposeList = new Runnable [disposeList.length + 4];
893 SimpleType!(Runnable).arraycopy (disposeList, 0, newDisposeList, 0, disposeList.length);
894 newDisposeList [disposeList.length] = runnable;
895 disposeList = newDisposeList;
896 }
897
898 void error (int code) {
899 DWT.error(code);
900 }
901
902 bool filterEvent (Event event) {
903 if (filterTable !is null) filterTable.sendEvent (event);
904 return false;
905 }
906
907 bool filters (int eventType) {
908 if (filterTable is null) return false;
909 return filterTable.hooks (eventType);
910 }
911
912 /**
913 * Given the operating system handle for a widget, returns
914 * the instance of the <code>Widget</code> subclass which
915 * represents it in the currently running application, if
916 * such exists, or null if no matching widget can be found.
917 * <p>
918 * <b>IMPORTANT:</b> This method should not be called from
919 * application code. The arguments are platform-specific.
920 * </p>
921 *
922 * @param handle the handle for the widget
923 * @return the DWT widget that the handle represents
924 *
925 * @exception DWTException <ul>
926 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
927 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
928 * </ul>
929 */
930 public Widget findWidget (objc.id handle) {
931 checkDevice ();
932 return getWidget (handle);
933 }
934
935 /**
936 * Given the operating system handle for a widget,
937 * and widget-specific id, returns the instance of
938 * the <code>Widget</code> subclass which represents
939 * the handle/id pair in the currently running application,
940 * if such exists, or null if no matching widget can be found.
941 * <p>
942 * <b>IMPORTANT:</b> This method should not be called from
943 * application code. The arguments are platform-specific.
944 * </p>
945 *
946 * @param handle the handle for the widget
947 * @param id the id for the subwidget (usually an item)
948 * @return the DWT widget that the handle/id pair represents
949 *
950 * @exception DWTException <ul>
951 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
952 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
953 * </ul>
954 *
955 * @since 3.1
956 */
957 public Widget findWidget (objc.id handle, int id) {
958 checkDevice ();
959 return getWidget (handle);
960 }
961
962 /**
963 * Given a widget and a widget-specific id, returns the
964 * instance of the <code>Widget</code> subclass which represents
965 * the widget/id pair in the currently running application,
966 * if such exists, or null if no matching widget can be found.
967 *
968 * @param widget the widget
969 * @param id the id for the subwidget (usually an item)
970 * @return the DWT subwidget (usually an item) that the widget/id pair represents
971 *
972 * @exception DWTException <ul>
973 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
974 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
975 * </ul>
976 *
977 * @since 3.3
978 */
979 public Widget findWidget (Widget widget, int id) {
980 checkDevice ();
981 return null;
982 }
983
984 /**
985 * Returns the display which the given thread is the
986 * user-interface thread for, or null if the given thread
987 * is not a user-interface thread for any display. Specifying
988 * <code>null</code> as the thread will return <code>null</code>
989 * for the display.
990 *
991 * @param thread the user-interface thread
992 * @return the display for the given thread
993 */
994 public static Display findDisplay (Thread thread) {
995 synchronized (Device.classinfo) {
996 for (int i=0; i<Displays.length; i++) {
997 Display display = Displays [i];
998 if (display !is null && display.thread is thread) {
999 return display;
1000 }
1001 }
1002 return null;
1003 }
1004 }
1005
1006 /**
1007 * Returns the currently active <code>Shell</code>, or null
1008 * if no shell belonging to the currently running application
1009 * is active.
1010 *
1011 * @return the active shell or null
1012 *
1013 * @exception DWTException <ul>
1014 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1015 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
1016 * </ul>
1017 */
1018 public Shell getActiveShell () {
1019 checkDevice ();
1020 NSArray windows = application.windows();
1021 int count = cast(int)/*64*/windows.count();
1022 for (int i = 0; i < count; i++) {
1023 NSWindow win = new NSWindow(windows.objectAtIndex(i));
1024 if (win.isKeyWindow()) {
1025 Widget widget = getWidget(win.contentView());
1026 if (cast(Shell) widget) {
1027 return cast(Shell)widget;
1028 }
1029 }
1030 }
1031 return null;
1032 }
1033
1034 /**
1035 * Returns a rectangle describing the receiver's size and location. Note that
1036 * on multi-monitor systems the origin can be negative.
1037 *
1038 * @return the bounding rectangle
1039 *
1040 * @exception DWTException <ul>
1041 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1042 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
1043 * </ul>
1044 */
1045 public Rectangle getBounds () {
1046 checkDevice ();
1047 NSArray screens = NSScreen.screens();
1048 return getBounds (screens);
1049 }
1050
1051 Rectangle getBounds (NSArray screens) {
1052 NSRect primaryFrame = (new NSScreen(screens.objectAtIndex(0))).frame();
1053 CGFloat minX = CGFloat.max, maxX = CGFloat.min;
1054 CGFloat minY = CGFloat.max, maxY = CGFloat.min;
1055 NSUInteger count = screens.count();
1056 for (NSUInteger i = 0; i < count; i++) {
1057 NSScreen screen = new NSScreen(screens.objectAtIndex(i));
1058 NSRect frame = screen.frame();
1059 CGFloat x1 = frame.x, x2 = frame.x + frame.width;
1060 CGFloat y1 = primaryFrame.height - frame.y, y2 = primaryFrame.height - (frame.y + frame.height);
1061 if (x1 < minX) minX = x1;
1062 if (x2 < minX) minX = x2;
1063 if (x1 > maxX) maxX = x1;
1064 if (x2 > maxX) maxX = x2;
1065 if (y1 < minY) minY = y1;
1066 if (y2 < minY) minY = y2;
1067 if (y1 > maxY) maxY = y1;
1068 if (y2 > maxY) maxY = y2;
1069 }
1070 return new Rectangle (cast(int)minX, cast(int)minY, cast(int)(maxX - minX), cast(int)(maxY - minY));
1071 }
1072
1073 /**
1074 * Returns the display which the currently running thread is
1075 * the user-interface thread for, or null if the currently
1076 * running thread is not a user-interface thread for any display.
1077 *
1078 * @return the current display
1079 */
1080 public static Display getCurrent () {
1081 return findDisplay (Thread.getThis ());
1082 }
1083
1084 int getCaretBlinkTime () {
1085 checkDevice ();
1086 return 560;
1087 }
1088
1089 /**
1090 * Returns a rectangle which describes the area of the
1091 * receiver which is capable of displaying data.
1092 *
1093 * @return the client area
1094 *
1095 * @exception DWTException <ul>
1096 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1097 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
1098 * </ul>
1099 *
1100 * @see #getBounds
1101 */
1102 public Rectangle getClientArea () {
1103 checkDevice ();
1104 NSArray screens = NSScreen.screens();
1105 if (screens.count() !is 1) return getBounds (screens);
1106 NSScreen screen = new NSScreen(screens.objectAtIndex(0));
564 NSRect frame = screen.frame(); 1107 NSRect frame = screen.frame();
565 cascade = NSPoint(); 1108 NSRect visibleFrame = screen.visibleFrame();
566 cascade.x = frame.x; 1109 CGFloat y = frame.height - (visibleFrame.y + visibleFrame.height);
567 cascade.y = frame.y + frame.height; 1110 return new Rectangle(cast(int)visibleFrame.x, cast(int)y, cast(int)visibleFrame.width, cast(int)visibleFrame.height);
568 }*/ 1111 }
569 screenCascade[index] = window.cascadeTopLeftFromPoint(cascade); 1112
570 } 1113 /**
571 1114 * Returns the control which the on-screen pointer is currently
572 protected void checkDevice () { 1115 * over top of, or null if it is not currently over one of the
573 if (thread is null) error (DWT.ERROR_WIDGET_DISPOSED); 1116 * controls built by the currently running application.
574 if (thread !is Thread.getThis ()) error (DWT.ERROR_THREAD_INVALID_ACCESS); 1117 *
575 if (isDisposed ()) error (DWT.ERROR_DEVICE_DISPOSED); 1118 * @return the control under the cursor
576 } 1119 *
577 1120 * @exception DWTException <ul>
578 /** 1121 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
579 * Checks that this class can be subclassed. 1122 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
580 * <p> 1123 * </ul>
581 * IMPORTANT: See the comment in <code>Widget.checkSubclass()</code>. 1124 */
582 * </p> 1125 public Control getCursorControl () {
583 * 1126 checkDevice();
584 * @exception DWTException <ul> 1127 return findControl(null, false, false, true);
585 * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> 1128 }
586 * </ul> 1129
587 * 1130 /**
588 * @see Widget#checkSubclass 1131 * Returns the location of the on-screen pointer relative
589 */ 1132 * to the top left corner of the screen.
590 protected void checkSubclass () { 1133 *
591 if (!Display.isValidClass (this.classinfo)) error (DWT.ERROR_INVALID_SUBCLASS); 1134 * @return the cursor location
592 } 1135 *
593 1136 * @exception DWTException <ul>
594 /** 1137 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
595 * Constructs a new instance of this class. 1138 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
596 * <p> 1139 * </ul>
597 * Note: The resulting display is marked as the <em>current</em> 1140 */
598 * display. If this is the first display which has been 1141 public Point getCursorLocation () {
599 * constructed since the application started, it is also 1142 checkDevice ();
600 * marked as the <em>default</em> display. 1143 NSPoint location = NSEvent.mouseLocation();
601 * </p> 1144 NSRect primaryFrame = getPrimaryFrame();
602 * 1145 return new Point (cast(int) location.x, cast(int) (primaryFrame.height - location.y));
603 * @exception DWTException <ul> 1146 }
604 * <li>ERROR_THREAD_INVALID_ACCESS - if called from a thread that already created an existing display</li> 1147
605 * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> 1148 /**
606 * </ul> 1149 * Returns an array containing the recommended cursor sizes.
607 * 1150 *
608 * @see #getCurrent 1151 * @return the array of cursor sizes
609 * @see #getDefault 1152 *
610 * @see Widget#checkSubclass 1153 * @exception DWTException <ul>
611 * @see Shell 1154 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
612 */ 1155 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
613 public this () { 1156 * </ul>
614 this (null); 1157 *
615 } 1158 * @since 3.0
616 1159 */
617 /** 1160 public Point [] getCursorSizes () {
618 * Constructs a new instance of this class using the parameter. 1161 checkDevice ();
619 * 1162 return [new Point (16, 16)];
620 * @param data the device data 1163 }
621 */ 1164
622 public this (DeviceData data) { 1165 /**
623 super (data); 1166 * Returns the default display. One is created (making the
624 screenID = new int[32]; 1167 * thread that invokes this method its user-interface thread)
625 screenCascade = new NSPoint[32]; 1168 * if it did not already exist.
626 cursors = new Cursor [DWT.CURSOR_HAND + 1]; 1169 *
627 Displays = new Display [4]; 1170 * @return the default display
628 timerDelegate = cast(SWTWindowDelegate)(new SWTWindowDelegate()).alloc().init(); 1171 */
629 1172 public static Display getDefault () {
630 caretTimer = new class(currentCaret) Runnable { 1173 synchronized (Device.classinfo) {
631 Caret currentCaret; 1174 if (Default is null) Default = new Display ();
632 1175 return Default;
633 this (Caret currentCaret) 1176 }
634 { 1177 }
635 this.currentCaret = currentCaret; 1178
636 } 1179 /**
637 1180 * Returns the application defined property of the receiver
638 public void run () { 1181 * with the specified name, or null if it has not been set.
639 if (currentCaret !is null) { 1182 * <p>
640 if (currentCaret is null || currentCaret.isDisposed()) return; 1183 * Applications may have associated arbitrary objects with the
641 if (currentCaret.blinkCaret ()) { 1184 * receiver in this fashion. If the objects stored in the
642 int blinkRate = currentCaret.blinkRate; 1185 * properties need to be notified when the display is disposed
643 if (blinkRate !is 0) timerExec (blinkRate, this); 1186 * of, it is the application's responsibility to provide a
644 } else { 1187 * <code>disposeExec()</code> handler which does so.
645 currentCaret = null; 1188 * </p>
646 } 1189 *
647 } 1190 * @param key the name of the property
648 1191 * @return the value of the property or null if it has not been set
649 } 1192 *
650 }; 1193 * @exception IllegalArgumentException <ul>
651 1194 * <li>ERROR_NULL_ARGUMENT - if the key is null</li>
652 hoverTimer = new class(currentControl) Runnable { 1195 * </ul>
653 Control currentControl; 1196 * @exception DWTException <ul>
654 1197 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
655 this (Control currentControl) 1198 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
656 { 1199 * </ul>
657 this.currentControl = currentControl; 1200 *
658 } 1201 * @see #setData(String, Object)
659 1202 * @see #disposeExec(Runnable)
660 public void run () { 1203 */
661 if (currentControl !is null && !currentControl.isDisposed()) { 1204 public Object getData (String key) {
662 currentControl.sendMouseEvent (null, DWT.MouseHover, trackingControl !is null); 1205 checkDevice ();
663 } 1206 //if (key is null) error (DWT.ERROR_NULL_ARGUMENT);
664 } 1207 if (keys is null) return null;
665 }; 1208 for (int i=0; i<keys.length; i++) {
666 } 1209 if (keys [i].equals (key)) return values [i];
667 1210 }
668 static void checkDisplay (Thread thread, bool multiple) { 1211 return null;
669 synchronized (Device.classinfo) { 1212 }
670 for (int i=0; i<Displays.length; i++) { 1213
671 if (Displays [i] !is null) { 1214 /**
672 if (!multiple) DWT.error (DWT.ERROR_NOT_IMPLEMENTED, null, " [multiple displays]"); 1215 * Returns the application defined, display specific data
673 if (Displays [i].thread is thread) DWT.error (DWT.ERROR_THREAD_INVALID_ACCESS); 1216 * associated with the receiver, or null if it has not been
674 } 1217 * set. The <em>display specific data</em> is a single,
675 } 1218 * unnamed field that is stored with every display.
676 } 1219 * <p>
677 } 1220 * Applications may put arbitrary objects in this field. If
678 1221 * the object stored in the display specific data needs to
679 static String convertToLf(String text) { 1222 * be notified when the display is disposed of, it is the
680 char Cr = '\r'; 1223 * application's responsibility to provide a
681 char Lf = '\n'; 1224 * <code>disposeExec()</code> handler which does so.
682 int length = text.length (); 1225 * </p>
683 if (length is 0) return text; 1226 *
684 1227 * @return the display specific data
685 /* Check for an LF or CR/LF. Assume the rest of the string 1228 *
686 * is formated that way. This will not work if the string 1229 * @exception DWTException <ul>
687 * contains mixed delimiters. */ 1230 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
688 int i = text.indexOf (Lf, 0); 1231 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
689 if (i is -1 || i is 0) return text; 1232 * </ul>
690 if (text.charAt (i - 1) !is Cr) return text; 1233 *
691 1234 * @see #setData(Object)
692 /* The string is formatted with CR/LF. 1235 * @see #disposeExec(Runnable)
693 * Create a new string with the LF line delimiter. */ 1236 */
694 i = 0; 1237 public Object getData () {
695 StringBuffer result = new StringBuffer (); 1238 checkDevice ();
696 while (i < length) { 1239 return data;
697 int j = text.indexOf (Cr, i); 1240 }
698 if (j is -1) j = length; 1241
699 String s = text.substring (i, j); 1242 /**
700 result.append (s); 1243 * Returns the button dismissal align_ment, one of <code>LEFT</code> or <code>RIGHT</code>.
701 i = j + 2; 1244 * The button dismissal align_ment is the ordering that should be used when positioning the
702 result.append (Lf); 1245 * default dismissal button for a dialog. For example, in a dialog that contains an OK and
703 } 1246 * CANCEL button, on platforms where the button dismissal align_ment is <code>LEFT</code>, the
704 return result.toString (); 1247 * button ordering should be OK/CANCEL. When button dismissal align_ment is <code>RIGHT</code>,
705 } 1248 * the button ordering should be CANCEL/OK.
706 1249 *
707 void clearModal (Shell shell) { 1250 * @return the button dismissal order
708 if (modalShells is null) return; 1251 *
709 int index = 0, length_ = modalShells.length; 1252 * @exception DWTException <ul>
710 while (index < length_) { 1253 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
711 if (modalShells [index] is shell) break; 1254 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
712 if (modalShells [index] is null) return; 1255 * </ul>
713 index++; 1256 *
714 } 1257 * @since 2.1
715 if (index is length_) return; 1258 */
716 System.arraycopy (modalShells, index + 1, modalShells, index, --length_ - index); 1259 public int getDismissalAlignment () {
717 modalShells [length_] = null; 1260 checkDevice ();
718 if (index is 0 && modalShells [0] is null) modalShells = null; 1261 return DWT.RIGHT;
719 Shell [] shells = getShells (); 1262 }
720 for (int i=0; i<shells.length; i++) shells [i].updateModal (); 1263
721 } 1264 /**
722 1265 * Returns the longest duration, in milliseconds, between
723 /** 1266 * two mouse button clicks that will be considered a
724 * Requests that the connection between DWT and the underlying 1267 * <em>double click</em> by the underlying operating system.
725 * operating system be closed. 1268 *
726 * 1269 * @return the double click time
727 * @exception DWTException <ul> 1270 *
728 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 1271 * @exception DWTException <ul>
729 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> 1272 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
730 * </ul> 1273 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
731 * 1274 * </ul>
732 * @see Device#dispose 1275 */
733 * 1276 public int getDoubleClickTime () {
734 * @since 2.0 1277 checkDevice ();
735 */ 1278 return 0;
736 public void close () { 1279 // return OS.GetDblTime () * 1000 / 60;
737 checkDevice (); 1280 }
738 Event event = new Event (); 1281
739 sendEvent (DWT.Close, event); 1282 /**
740 if (event.doit) dispose (); 1283 * Returns the control which currently has keyboard focus,
741 } 1284 * or null if keyboard events are not currently going to
742 1285 * any of the controls built by the currently running
743 /** 1286 * application.
744 * Creates the device in the operating system. If the device 1287 *
745 * does not have a handle, this method may do nothing depending 1288 * @return the control under the cursor
746 * on the device. 1289 *
747 * <p> 1290 * @exception DWTException <ul>
748 * This method is called before <code>init</code>. 1291 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
749 * </p> 1292 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
750 * 1293 * </ul>
751 * @param data the DeviceData which describes the receiver 1294 */
752 * 1295 public Control getFocusControl () {
753 * @see #init 1296 checkDevice ();
754 */ 1297 NSWindow window = application.keyWindow();
755 protected void create (DeviceData data) { 1298 return GetFocusControl(window);
756 checkSubclass (); 1299 }
757 checkDisplay (thread = Thread.getThis (), false); 1300
758 createDisplay (data); 1301 static Control GetFocusControl(NSWindow window) {
759 register (this); 1302 if (window !is null) {
760 synchronizer = new Synchronizer (this); 1303 NSResponder responder = window.firstResponder();
761 if (Default is null) Default = this; 1304 if (responder !is null && !responder.respondsToSelector(OS.sel_superview)) {
762 } 1305 return null;
763 1306 }
764 void createDisplay (DeviceData data) { 1307 NSView view = new NSView(responder.id);
765 if (OS.VERSION < 0x1050) { 1308 if (view !is null) {
766 System.Out.println ("***WARNING: DWT requires MacOS X version {}{}{}{}" , 10 , "." , 5 , " or greater"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 1309 do {
767 System.Out.println ("***WARNING: Detected: {}{}{}{}{}" , Integer.toHexString((OS.VERSION & 0xFF00) >> 8) , "." , Integer.toHexString((OS.VERSION & 0xF0) >> 4) , "." , Integer.toHexString(OS.VERSION & 0xF)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 1310 Widget widget = GetWidget (view.id);
768 error(DWT.ERROR_NOT_IMPLEMENTED); 1311 if (cast(Control)widget) {
769 } 1312 return cast(Control)widget;
770 1313 }
771 NSThread nsthread = NSThread.currentThread(); 1314 view = view.superview();
772 NSMutableDictionary dictionary = nsthread.threadDictionary(); 1315 } while (view !is null);
773 NSString key = NSString.stringWith("SWT_NSAutoreleasePool"); 1316 }
774 pool = new NSAutoreleasePool(dictionary.objectForKey(key)); 1317 }
775 1318 return null;
776 application = NSApplication.sharedApplication(); 1319 }
777 1320
778 /* 1321 /**
779 * TODO: If an NSApplication is already running we don't want to create another NSApplication. 1322 * Returns true when the high contrast mode is enabled.
780 * But if we don't we won't get mouse events, since we currently need to subclass NSApplication and intercept sendEvent to 1323 * Otherwise, false is returned.
781 * deliver mouse events correctly to widgets. 1324 * <p>
782 */ 1325 * Note: This operation is a hint and is not supported on
783 if (!application.isRunning()) { 1326 * platforms that do not have this concept.
1327 * </p>
1328 *
1329 * @return the high contrast mode
1330 *
1331 * @exception DWTException <ul>
1332 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1333 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
1334 * </ul>
1335 *
1336 * @since 3.0
1337 */
1338 public bool getHighContrast () {
1339 checkDevice ();
1340 return false;
1341 }
1342
1343 /**
1344 * Returns the maximum allowed depth of icons on this display, in bits per pixel.
1345 * On some platforms, this may be different than the actual depth of the display.
1346 *
1347 * @return the maximum icon depth
1348 *
1349 * @exception DWTException <ul>
1350 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1351 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
1352 * </ul>
1353 *
1354 * @see Device#getDepth
1355 */
1356 public int getIconDepth () {
1357 return getDepth ();
1358 }
1359
1360 /**
1361 * Returns an array containing the recommended icon sizes.
1362 *
1363 * @return the array of icon sizes
1364 *
1365 * @exception DWTException <ul>
1366 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1367 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
1368 * </ul>
1369 *
1370 * @see Decorations#setImages(Image[])
1371 *
1372 * @since 3.0
1373 */
1374 public Point [] getIconSizes () {
1375 checkDevice ();
1376 return [
1377 new Point (16, 16), new Point (32, 32),
1378 new Point (64, 64), new Point (128, 128)];
1379 }
1380
1381 int getLastEventTime () {
784 /* 1382 /*
785 * Feature in the Macintosh. On OS 10.2, it is necessary 1383 * This code is intentionally commented. Event time is
786 * to explicitly check in with the Process Manager and set 1384 * in seconds and we need an accurate time in milliseconds.
787 * the current process to be the front process in order for
788 * windows to come to the front by default. The fix is call
789 * both GetCurrentProcess() and SetFrontProcess().
790 *
791 * NOTE: It is not actually necessary to use the process
792 * serial number returned by GetCurrentProcess() in the
793 * call to SetFrontProcess() (ie. kCurrentProcess can be
794 * used) but both functions must be called in order for
795 * windows to come to the front.
796 */ 1385 */
797 Carbon.ProcessSerialNumber psn; 1386 // return (int) (OS.GetLastUserEventTime () * 1000.0);
798 if (OS.GetCurrentProcess (&psn) is OS.noErr) { 1387 return cast(int) System.currentTimeMillis ();
799 int pid = OS.getpid (); 1388 }
800 char* ptr = OS.getenv (ascii ("APP_NAME_" ~ Integer.toString(pid))); 1389
801 if (ptr is null && APP_NAME !is null) { 1390 Menu [] getMenus (Decorations shell) {
802 ptr = NSString.stringWith(APP_NAME).UTF8String(); 1391 if (menus is null) return new Menu [0];
803 } 1392 int count = 0;
804 if (ptr !is null) OS.CPSSetProcessName (&psn, ptr); 1393 for (int i = 0; i < menus.length; i++) {
805 OS.TransformProcessType (&psn, OS.kProcessTransformToForegroundApplication); 1394 Menu menu = menus[i];
806 OS.SetFrontProcess (&psn); 1395 if (menu !is null && menu.parent is shell) count++;
807 ptr = OS.getenv (ascii ("APP_ICON_" ~ Integer.toString(pid))); 1396 }
808 if (ptr !is null) { 1397 int index = 0;
809 NSString path = NSString.stringWithUTF8String (ptr); 1398 Menu[] result = new Menu[count];
810 NSImage image = cast(NSImage) (new NSImage()).alloc(); 1399 for (int i = 0; i < menus.length; i++) {
811 image = image.initByReferencingFile(path); 1400 Menu menu = menus[i];
812 dockImage = image; 1401 if (menu !is null && menu.parent is shell) {
813 application.setApplicationIconImage(image); 1402 result[index++] = menu;
814 } 1403 }
815 } 1404 }
816 1405 return result;
817 String className = "SWTApplication"; 1406 }
818 objc.Class cls; 1407
819 if ((cls = cast(objc.Class) OS.objc_lookUpClass (className)) is null) { 1408 int getMessageCount () {
820 objc.IMP proc2 = cast(objc.IMP) &applicationProc2; 1409 return synchronizer.getMessageCount ();
821 objc.IMP proc3 = cast(objc.IMP) &applicationProc3; 1410 }
822 objc.IMP proc6 = cast(objc.IMP) &applicationProc6; 1411
823 cls = OS.objc_allocateClassPair(cast(objc.Class) OS.class_NSApplication, className, 0); 1412 /**
824 OS.class_addMethod(cls, OS.sel_sendEvent_, proc3, "@:@"); 1413 * Returns an array of monitors attached to the device.
825 1414 *
826 static if ((void*).sizeof > int.sizeof) // 64bit target 1415 * @return the array of monitors
827 OS.class_addMethod(cls, OS.sel_nextEventMatchingMask_untilDate_inMode_dequeue_, proc6, "@:Q@@B"); 1416 *
828 else 1417 * @since 3.0
829 OS.class_addMethod(cls, OS.sel_nextEventMatchingMask_untilDate_inMode_dequeue_, proc6, "@:I@@B"); 1418 */
830 1419 public dwt.widgets.Monitor.Monitor [] getMonitors () {
831 OS.class_addMethod(cls, OS.sel_isRunning, proc2, "@:"); 1420 checkDevice ();
832 OS.objc_registerClassPair(cls); 1421 NSArray screens = NSScreen.screens();
833 } 1422 NSRect primaryFrame = (new NSScreen(screens.objectAtIndex(0))).frame();
834 applicationClass = OS.object_setClass(application.id, cls); 1423 NSUInteger count = screens.count();
835 } else { 1424 dwt.widgets.Monitor.Monitor [] monitors = new dwt.widgets.Monitor.Monitor [count];
836 isEmbedded = true; 1425 for (NSUInteger i=0; i<count; i++) {
837 } 1426 dwt.widgets.Monitor.Monitor monitor = new dwt.widgets.Monitor.Monitor ();
838 1427 NSScreen screen = new NSScreen(screens.objectAtIndex(i));
839 // application = new NSApplication(OS.objc_msgSend(cls, OS.sel_sharedApplication)); 1428 NSRect frame = screen.frame();
840 } 1429 monitor.x = cast(int)frame.x;
841 1430 monitor.y = cast(int)(primaryFrame.height - (frame.y + frame.height));
842 static void deregister (Display display) { 1431 monitor.width = cast(int)frame.width;
843 synchronized (Device.classinfo) { 1432 monitor.height = cast(int)frame.height;
844 for (int i=0; i<Displays.length; i++) { 1433 NSRect visibleFrame = screen.visibleFrame();
845 if (display is Displays [i]) Displays [i] = null; 1434 monitor.clientX = cast(int)visibleFrame.x;
846 } 1435 monitor.clientY = cast(int)(primaryFrame.height - (visibleFrame.y + visibleFrame.height));
847 } 1436 monitor.clientWidth = cast(int)visibleFrame.width;
848 } 1437 monitor.clientHeight = cast(int)visibleFrame.height;
849 1438 monitors [i] = monitor;
850 /** 1439 }
851 * Destroys the device in the operating system and releases 1440 return monitors;
852 * the device's handle. If the device does not have a handle, 1441 }
853 * this method may do nothing depending on the device. 1442
854 * <p> 1443 NSRect getPrimaryFrame () {
855 * This method is called after <code>release</code>. 1444 NSArray screens = NSScreen.screens();
856 * </p> 1445 return (new NSScreen(screens.objectAtIndex(0))).frame();
857 * @see Device#dispose 1446 }
858 * @see #release 1447
859 */ 1448 /**
860 protected void destroy () { 1449 * Returns the primary monitor for that device.
861 if (this is Default) Default = null; 1450 *
862 deregister (this); 1451 * @return the primary monitor
863 destroyDisplay (); 1452 *
864 } 1453 * @since 3.0
865 1454 */
866 void destroyDisplay () { 1455 public dwt.widgets.Monitor.Monitor getPrimaryMonitor () {
867 application = null; 1456 checkDevice ();
868 }
869
870 /**
871 * Causes the <code>run()</code> method of the runnable to
872 * be invoked by the user-interface thread just before the
873 * receiver is disposed. Specifying a <code>null</code> runnable
874 * is ignored.
875 *
876 * @param runnable code to run at dispose time.
877 *
878 * @exception DWTException <ul>
879 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
880 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
881 * </ul>
882 */
883 public void disposeExec (Runnable runnable) {
884 checkDevice ();
885 if (disposeList is null) disposeList = new Runnable [4];
886 for (int i=0; i<disposeList.length; i++) {
887 if (disposeList [i] is null) {
888 disposeList [i] = runnable;
889 return;
890 }
891 }
892 Runnable [] newDisposeList = new Runnable [disposeList.length + 4];
893 SimpleType!(Runnable).arraycopy (disposeList, 0, newDisposeList, 0, disposeList.length);
894 newDisposeList [disposeList.length] = runnable;
895 disposeList = newDisposeList;
896 }
897
898 void error (int code) {
899 DWT.error(code);
900 }
901
902 bool filterEvent (Event event) {
903 if (filterTable !is null) filterTable.sendEvent (event);
904 return false;
905 }
906
907 bool filters (int eventType) {
908 if (filterTable is null) return false;
909 return filterTable.hooks (eventType);
910 }
911
912 /**
913 * Given the operating system handle for a widget, returns
914 * the instance of the <code>Widget</code> subclass which
915 * represents it in the currently running application, if
916 * such exists, or null if no matching widget can be found.
917 * <p>
918 * <b>IMPORTANT:</b> This method should not be called from
919 * application code. The arguments are platform-specific.
920 * </p>
921 *
922 * @param handle the handle for the widget
923 * @return the DWT widget that the handle represents
924 *
925 * @exception DWTException <ul>
926 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
927 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
928 * </ul>
929 */
930 public Widget findWidget (objc.id handle) {
931 checkDevice ();
932 return getWidget (handle);
933 }
934
935 /**
936 * Given the operating system handle for a widget,
937 * and widget-specific id, returns the instance of
938 * the <code>Widget</code> subclass which represents
939 * the handle/id pair in the currently running application,
940 * if such exists, or null if no matching widget can be found.
941 * <p>
942 * <b>IMPORTANT:</b> This method should not be called from
943 * application code. The arguments are platform-specific.
944 * </p>
945 *
946 * @param handle the handle for the widget
947 * @param id the id for the subwidget (usually an item)
948 * @return the DWT widget that the handle/id pair represents
949 *
950 * @exception DWTException <ul>
951 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
952 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
953 * </ul>
954 *
955 * @since 3.1
956 */
957 public Widget findWidget (objc.id handle, int id) {
958 checkDevice ();
959 return getWidget (handle);
960 }
961
962 /**
963 * Given a widget and a widget-specific id, returns the
964 * instance of the <code>Widget</code> subclass which represents
965 * the widget/id pair in the currently running application,
966 * if such exists, or null if no matching widget can be found.
967 *
968 * @param widget the widget
969 * @param id the id for the subwidget (usually an item)
970 * @return the DWT subwidget (usually an item) that the widget/id pair represents
971 *
972 * @exception DWTException <ul>
973 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
974 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
975 * </ul>
976 *
977 * @since 3.3
978 */
979 public Widget findWidget (Widget widget, int id) {
980 checkDevice ();
981 return null;
982 }
983
984 /**
985 * Returns the display which the given thread is the
986 * user-interface thread for, or null if the given thread
987 * is not a user-interface thread for any display. Specifying
988 * <code>null</code> as the thread will return <code>null</code>
989 * for the display.
990 *
991 * @param thread the user-interface thread
992 * @return the display for the given thread
993 */
994 public static Display findDisplay (Thread thread) {
995 synchronized (Device.classinfo) {
996 for (int i=0; i<Displays.length; i++) {
997 Display display = Displays [i];
998 if (display !is null && display.thread is thread) {
999 return display;
1000 }
1001 }
1002 return null;
1003 }
1004 }
1005
1006 /**
1007 * Returns the currently active <code>Shell</code>, or null
1008 * if no shell belonging to the currently running application
1009 * is active.
1010 *
1011 * @return the active shell or null
1012 *
1013 * @exception DWTException <ul>
1014 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1015 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
1016 * </ul>
1017 */
1018 public Shell getActiveShell () {
1019 checkDevice ();
1020 NSArray windows = application.windows();
1021 int count = cast(int)/*64*/windows.count();
1022 for (int i = 0; i < count; i++) {
1023 NSWindow win = new NSWindow(windows.objectAtIndex(i));
1024 if (win.isKeyWindow()) {
1025 Widget widget = getWidget(win.contentView());
1026 if (cast(Shell) widget) {
1027 return cast(Shell)widget;
1028 }
1029 }
1030 }
1031 return null;
1032 }
1033
1034 /**
1035 * Returns a rectangle describing the receiver's size and location. Note that
1036 * on multi-monitor systems the origin can be negative.
1037 *
1038 * @return the bounding rectangle
1039 *
1040 * @exception DWTException <ul>
1041 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1042 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
1043 * </ul>
1044 */
1045 public Rectangle getBounds () {
1046 checkDevice ();
1047 NSArray screens = NSScreen.screens();
1048 return getBounds (screens);
1049 }
1050
1051 Rectangle getBounds (NSArray screens) {
1052 NSRect primaryFrame = (new NSScreen(screens.objectAtIndex(0))).frame();
1053 CGFloat minX = CGFloat.max, maxX = CGFloat.min;
1054 CGFloat minY = CGFloat.max, maxY = CGFloat.min;
1055 NSUInteger count = screens.count();
1056 for (NSUInteger i = 0; i < count; i++) {
1057 NSScreen screen = new NSScreen(screens.objectAtIndex(i));
1058 NSRect frame = screen.frame();
1059 CGFloat x1 = frame.x, x2 = frame.x + frame.width;
1060 CGFloat y1 = primaryFrame.height - frame.y, y2 = primaryFrame.height - (frame.y + frame.height);
1061 if (x1 < minX) minX = x1;
1062 if (x2 < minX) minX = x2;
1063 if (x1 > maxX) maxX = x1;
1064 if (x2 > maxX) maxX = x2;
1065 if (y1 < minY) minY = y1;
1066 if (y2 < minY) minY = y2;
1067 if (y1 > maxY) maxY = y1;
1068 if (y2 > maxY) maxY = y2;
1069 }
1070 return new Rectangle (cast(int)minX, cast(int)minY, cast(int)(maxX - minX), cast(int)(maxY - minY));
1071 }
1072
1073 /**
1074 * Returns the display which the currently running thread is
1075 * the user-interface thread for, or null if the currently
1076 * running thread is not a user-interface thread for any display.
1077 *
1078 * @return the current display
1079 */
1080 public static Display getCurrent () {
1081 return findDisplay (Thread.getThis ());
1082 }
1083
1084 int getCaretBlinkTime () {
1085 checkDevice ();
1086 return 560;
1087 }
1088
1089 /**
1090 * Returns a rectangle which describes the area of the
1091 * receiver which is capable of displaying data.
1092 *
1093 * @return the client area
1094 *
1095 * @exception DWTException <ul>
1096 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1097 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
1098 * </ul>
1099 *
1100 * @see #getBounds
1101 */
1102 public Rectangle getClientArea () {
1103 checkDevice ();
1104 NSArray screens = NSScreen.screens();
1105 if (screens.count() !is 1) return getBounds (screens);
1106 NSScreen screen = new NSScreen(screens.objectAtIndex(0));
1107 NSRect frame = screen.frame();
1108 NSRect visibleFrame = screen.visibleFrame();
1109 CGFloat y = frame.height - (visibleFrame.y + visibleFrame.height);
1110 return new Rectangle(cast(int)visibleFrame.x, cast(int)y, cast(int)visibleFrame.width, cast(int)visibleFrame.height);
1111 }
1112
1113 /**
1114 * Returns the control which the on-screen pointer is currently
1115 * over top of, or null if it is not currently over one of the
1116 * controls built by the currently running application.
1117 *
1118 * @return the control under the cursor
1119 *
1120 * @exception DWTException <ul>
1121 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1122 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
1123 * </ul>
1124 */
1125 public Control getCursorControl () {
1126 checkDevice();
1127 return findControl(null, false, false, true);
1128 }
1129
1130 /**
1131 * Returns the location of the on-screen pointer relative
1132 * to the top left corner of the screen.
1133 *
1134 * @return the cursor location
1135 *
1136 * @exception DWTException <ul>
1137 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1138 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
1139 * </ul>
1140 */
1141 public Point getCursorLocation () {
1142 checkDevice ();
1143 NSPoint location = NSEvent.mouseLocation();
1144 NSRect primaryFrame = getPrimaryFrame();
1145 return new Point (cast(int) location.x, cast(int) (primaryFrame.height - location.y));
1146 }
1147
1148 /**
1149 * Returns an array containing the recommended cursor sizes.
1150 *
1151 * @return the array of cursor sizes
1152 *
1153 * @exception DWTException <ul>
1154 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1155 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
1156 * </ul>
1157 *
1158 * @since 3.0
1159 */
1160 public Point [] getCursorSizes () {
1161 checkDevice ();
1162 return [new Point (16, 16)];
1163 }
1164
1165 /**
1166 * Returns the default display. One is created (making the
1167 * thread that invokes this method its user-interface thread)
1168 * if it did not already exist.
1169 *
1170 * @return the default display
1171 */
1172 public static Display getDefault () {
1173 synchronized (Device.classinfo) {
1174 if (Default is null) Default = new Display ();
1175 return Default;
1176 }
1177 }
1178
1179 /**
1180 * Returns the application defined property of the receiver
1181 * with the specified name, or null if it has not been set.
1182 * <p>
1183 * Applications may have associated arbitrary objects with the
1184 * receiver in this fashion. If the objects stored in the
1185 * properties need to be notified when the display is disposed
1186 * of, it is the application's responsibility to provide a
1187 * <code>disposeExec()</code> handler which does so.
1188 * </p>
1189 *
1190 * @param key the name of the property
1191 * @return the value of the property or null if it has not been set
1192 *
1193 * @exception IllegalArgumentException <ul>
1194 * <li>ERROR_NULL_ARGUMENT - if the key is null</li>
1195 * </ul>
1196 * @exception DWTException <ul>
1197 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1198 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
1199 * </ul>
1200 *
1201 * @see #setData(String, Object)
1202 * @see #disposeExec(Runnable)
1203 */
1204 public Object getData (String key) {
1205 checkDevice ();
1206 //if (key is null) error (DWT.ERROR_NULL_ARGUMENT);
1207 if (keys is null) return null;
1208 for (int i=0; i<keys.length; i++) {
1209 if (keys [i].equals (key)) return values [i];
1210 }
1211 return null;
1212 }
1213
1214 /**
1215 * Returns the application defined, display specific data
1216 * associated with the receiver, or null if it has not been
1217 * set. The <em>display specific data</em> is a single,
1218 * unnamed field that is stored with every display.
1219 * <p>
1220 * Applications may put arbitrary objects in this field. If
1221 * the object stored in the display specific data needs to
1222 * be notified when the display is disposed of, it is the
1223 * application's responsibility to provide a
1224 * <code>disposeExec()</code> handler which does so.
1225 * </p>
1226 *
1227 * @return the display specific data
1228 *
1229 * @exception DWTException <ul>
1230 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1231 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
1232 * </ul>
1233 *
1234 * @see #setData(Object)
1235 * @see #disposeExec(Runnable)
1236 */
1237 public Object getData () {
1238 checkDevice ();
1239 return data;
1240 }
1241
1242 /**
1243 * Returns the button dismissal align_ment, one of <code>LEFT</code> or <code>RIGHT</code>.
1244 * The button dismissal align_ment is the ordering that should be used when positioning the
1245 * default dismissal button for a dialog. For example, in a dialog that contains an OK and
1246 * CANCEL button, on platforms where the button dismissal align_ment is <code>LEFT</code>, the
1247 * button ordering should be OK/CANCEL. When button dismissal align_ment is <code>RIGHT</code>,
1248 * the button ordering should be CANCEL/OK.
1249 *
1250 * @return the button dismissal order
1251 *
1252 * @exception DWTException <ul>
1253 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1254 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
1255 * </ul>
1256 *
1257 * @since 2.1
1258 */
1259 public int getDismissalAlignment () {
1260 checkDevice ();
1261 return DWT.RIGHT;
1262 }
1263
1264 /**
1265 * Returns the longest duration, in milliseconds, between
1266 * two mouse button clicks that will be considered a
1267 * <em>double click</em> by the underlying operating system.
1268 *
1269 * @return the double click time
1270 *
1271 * @exception DWTException <ul>
1272 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1273 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
1274 * </ul>
1275 */
1276 public int getDoubleClickTime () {
1277 checkDevice ();
1278 return 0;
1279 // return OS.GetDblTime () * 1000 / 60;
1280 }
1281
1282 /**
1283 * Returns the control which currently has keyboard focus,
1284 * or null if keyboard events are not currently going to
1285 * any of the controls built by the currently running
1286 * application.
1287 *
1288 * @return the control under the cursor
1289 *
1290 * @exception DWTException <ul>
1291 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1292 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
1293 * </ul>
1294 */
1295 public Control getFocusControl () {
1296 checkDevice ();
1297 NSWindow window = application.keyWindow();
1298 return GetFocusControl(window);
1299 }
1300
1301 static Control GetFocusControl(NSWindow window) {
1302 if (window !is null) {
1303 NSResponder responder = window.firstResponder();
1304 if (responder !is null && !responder.respondsToSelector(OS.sel_superview)) {
1305 return null;
1306 }
1307 NSView view = new NSView(responder.id);
1308 if (view !is null) {
1309 do {
1310 Widget widget = GetWidget (view.id);
1311 if (cast(Control)widget) {
1312 return cast(Control)widget;
1313 }
1314 view = view.superview();
1315 } while (view !is null);
1316 }
1317 }
1318 return null;
1319 }
1320
1321 /**
1322 * Returns true when the high contrast mode is enabled.
1323 * Otherwise, false is returned.
1324 * <p>
1325 * Note: This operation is a hint and is not supported on
1326 * platforms that do not have this concept.
1327 * </p>
1328 *
1329 * @return the high contrast mode
1330 *
1331 * @exception DWTException <ul>
1332 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1333 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
1334 * </ul>
1335 *
1336 * @since 3.0
1337 */
1338 public bool getHighContrast () {
1339 checkDevice ();
1340 return false;
1341 }
1342
1343 /**
1344 * Returns the maximum allowed depth of icons on this display, in bits per pixel.
1345 * On some platforms, this may be different than the actual depth of the display.
1346 *
1347 * @return the maximum icon depth
1348 *
1349 * @exception DWTException <ul>
1350 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1351 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
1352 * </ul>
1353 *
1354 * @see Device#getDepth
1355 */
1356 public int getIconDepth () {
1357 return getDepth ();
1358 }
1359
1360 /**
1361 * Returns an array containing the recommended icon sizes.
1362 *
1363 * @return the array of icon sizes
1364 *
1365 * @exception DWTException <ul>
1366 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1367 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
1368 * </ul>
1369 *
1370 * @see Decorations#setImages(Image[])
1371 *
1372 * @since 3.0
1373 */
1374 public Point [] getIconSizes () {
1375 checkDevice ();
1376 return [
1377 new Point (16, 16), new Point (32, 32),
1378 new Point (64, 64), new Point (128, 128)];
1379 }
1380
1381 int getLastEventTime () {
1382 /*
1383 * This code is intentionally commented. Event time is
1384 * in seconds and we need an accurate time in milliseconds.
1385 */
1386 // return (int) (OS.GetLastUserEventTime () * 1000.0);
1387 return cast(int) System.currentTimeMillis ();
1388 }
1389
1390 Menu [] getMenus (Decorations shell) {
1391 if (menus is null) return new Menu [0];
1392 int count = 0;
1393 for (int i = 0; i < menus.length; i++) {
1394 Menu menu = menus[i];
1395 if (menu !is null && menu.parent is shell) count++;
1396 }
1397 int index = 0;
1398 Menu[] result = new Menu[count];
1399 for (int i = 0; i < menus.length; i++) {
1400 Menu menu = menus[i];
1401 if (menu !is null && menu.parent is shell) {
1402 result[index++] = menu;
1403 }
1404 }
1405 return result;
1406 }
1407
1408 int getMessageCount () {
1409 return synchronizer.getMessageCount ();
1410 }
1411
1412 /**
1413 * Returns an array of monitors attached to the device.
1414 *
1415 * @return the array of monitors
1416 *
1417 * @since 3.0
1418 */
1419 public dwt.widgets.Monitor.Monitor [] getMonitors () {
1420 checkDevice ();
1421 NSArray screens = NSScreen.screens();
1422 NSRect primaryFrame = (new NSScreen(screens.objectAtIndex(0))).frame();
1423 NSUInteger count = screens.count();
1424 dwt.widgets.Monitor.Monitor [] monitors = new dwt.widgets.Monitor.Monitor [count];
1425 for (NSUInteger i=0; i<count; i++) {
1426 dwt.widgets.Monitor.Monitor monitor = new dwt.widgets.Monitor.Monitor (); 1457 dwt.widgets.Monitor.Monitor monitor = new dwt.widgets.Monitor.Monitor ();
1427 NSScreen screen = new NSScreen(screens.objectAtIndex(i)); 1458 NSArray screens = NSScreen.screens();
1459 NSScreen screen = new NSScreen(screens.objectAtIndex(0));
1428 NSRect frame = screen.frame(); 1460 NSRect frame = screen.frame();
1429 monitor.x = cast(int)frame.x; 1461 monitor.x = cast(int)frame.x;
1430 monitor.y = cast(int)(primaryFrame.height - (frame.y + frame.height)); 1462 monitor.y = cast(int)(frame.height - (frame.y + frame.height));
1431 monitor.width = cast(int)frame.width; 1463 monitor.width = cast(int)frame.width;
1432 monitor.height = cast(int)frame.height; 1464 monitor.height = cast(int)frame.height;
1433 NSRect visibleFrame = screen.visibleFrame(); 1465 NSRect visibleFrame = screen.visibleFrame();
1434 monitor.clientX = cast(int)visibleFrame.x; 1466 monitor.clientX = cast(int)visibleFrame.x;
1435 monitor.clientY = cast(int)(primaryFrame.height - (visibleFrame.y + visibleFrame.height)); 1467 monitor.clientY = cast(int)(frame.height - (visibleFrame.y + visibleFrame.height));
1436 monitor.clientWidth = cast(int)visibleFrame.width; 1468 monitor.clientWidth = cast(int)visibleFrame.width;
1437 monitor.clientHeight = cast(int)visibleFrame.height; 1469 monitor.clientHeight = cast(int)visibleFrame.height;
1438 monitors [i] = monitor; 1470 return monitor;
1439 } 1471 }
1440 return monitors; 1472
1441 } 1473 /**
1442 1474 * Returns a (possibly empty) array containing all shells which have
1443 NSRect getPrimaryFrame () { 1475 * not been disposed and have the receiver as their display.
1444 NSArray screens = NSScreen.screens(); 1476 *
1445 return (new NSScreen(screens.objectAtIndex(0))).frame(); 1477 * @return the receiver's shells
1446 } 1478 *
1447 1479 * @exception DWTException <ul>
1448 /** 1480 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1449 * Returns the primary monitor for that device. 1481 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
1450 * 1482 * </ul>
1451 * @return the primary monitor 1483 */
1452 * 1484 public Shell [] getShells () {
1453 * @since 3.0 1485 checkDevice ();
1454 */ 1486 NSArray windows = application.windows();
1455 public dwt.widgets.Monitor.Monitor getPrimaryMonitor () { 1487 int index = 0;
1456 checkDevice (); 1488 Shell [] result = new Shell [windows.count()];
1457 dwt.widgets.Monitor.Monitor monitor = new dwt.widgets.Monitor.Monitor (); 1489 for (int i = 0; i < result.length; i++) {
1458 NSArray screens = NSScreen.screens(); 1490 NSWindow window = new NSWindow(windows.objectAtIndex(i));
1459 NSScreen screen = new NSScreen(screens.objectAtIndex(0)); 1491 Widget widget = getWidget(window.contentView());
1460 NSRect frame = screen.frame(); 1492 if (cast(Shell) widget) {
1461 monitor.x = cast(int)frame.x; 1493 result[index++] = cast(Shell)widget;
1462 monitor.y = cast(int)(frame.height - (frame.y + frame.height)); 1494 }
1463 monitor.width = cast(int)frame.width; 1495 }
1464 monitor.height = cast(int)frame.height; 1496 if (index is result.length) return result;
1465 NSRect visibleFrame = screen.visibleFrame(); 1497 Shell [] newResult = new Shell [index];
1466 monitor.clientX = cast(int)visibleFrame.x; 1498 System.arraycopy (result, 0, newResult, 0, index);
1467 monitor.clientY = cast(int)(frame.height - (visibleFrame.y + visibleFrame.height)); 1499 return newResult;
1468 monitor.clientWidth = cast(int)visibleFrame.width; 1500 }
1469 monitor.clientHeight = cast(int)visibleFrame.height; 1501
1470 return monitor; 1502 /**
1471 } 1503 * Gets the synchronizer used by the display.
1472 1504 *
1473 /** 1505 * @return the receiver's synchronizer
1474 * Returns a (possibly empty) array containing all shells which have 1506 *
1475 * not been disposed and have the receiver as their display. 1507 * @exception DWTException <ul>
1476 * 1508 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1477 * @return the receiver's shells 1509 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
1478 * 1510 * </ul>
1479 * @exception DWTException <ul> 1511 *
1480 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 1512 * @since 3.4
1481 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> 1513 */
1482 * </ul> 1514 public Synchronizer getSynchronizer () {
1483 */ 1515 checkDevice ();
1484 public Shell [] getShells () { 1516 return synchronizer;
1485 checkDevice (); 1517 }
1486 NSArray windows = application.windows(); 1518
1487 int index = 0; 1519 /**
1488 Shell [] result = new Shell [windows.count()]; 1520 * Returns the thread that has invoked <code>syncExec</code>
1489 for (int i = 0; i < result.length; i++) { 1521 * or null if no such runnable is currently being invoked by
1490 NSWindow window = new NSWindow(windows.objectAtIndex(i)); 1522 * the user-interface thread.
1491 Widget widget = getWidget(window.contentView()); 1523 * <p>
1492 if (cast(Shell) widget) { 1524 * Note: If a runnable invoked by asyncExec is currently
1493 result[index++] = cast(Shell)widget; 1525 * running, this method will return null.
1494 } 1526 * </p>
1495 } 1527 *
1496 if (index is result.length) return result; 1528 * @return the receiver's sync-interface thread
1497 Shell [] newResult = new Shell [index]; 1529 *
1498 System.arraycopy (result, 0, newResult, 0, index); 1530 * @exception DWTException <ul>
1499 return newResult; 1531 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
1500 } 1532 * </ul>
1501 1533 */
1502 /** 1534 public Thread getSyncThread () {
1503 * Gets the synchronizer used by the display. 1535 synchronized (Device.classinfo) {
1504 * 1536 if (isDisposed ()) error (DWT.ERROR_DEVICE_DISPOSED);
1505 * @return the receiver's synchronizer 1537 return synchronizer.syncThread;
1506 * 1538 }
1507 * @exception DWTException <ul> 1539 }
1508 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 1540
1509 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> 1541 /**
1510 * </ul> 1542 * Returns the matching standard color for the given
1511 * 1543 * constant, which should be one of the color constants
1512 * @since 3.4 1544 * specified in class <code>DWT</code>. Any value other
1513 */ 1545 * than one of the DWT color constants which is passed
1514 public Synchronizer getSynchronizer () { 1546 * in will result in the color black. This color should
1515 checkDevice (); 1547 * not be free'd because it was allocated by the system,
1516 return synchronizer; 1548 * not the application.
1517 } 1549 *
1518 1550 * @param id the color constant
1519 /** 1551 * @return the matching color
1520 * Returns the thread that has invoked <code>syncExec</code> 1552 *
1521 * or null if no such runnable is currently being invoked by 1553 * @exception DWTException <ul>
1522 * the user-interface thread. 1554 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1523 * <p> 1555 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
1524 * Note: If a runnable invoked by asyncExec is currently 1556 * </ul>
1525 * running, this method will return null. 1557 *
1526 * </p> 1558 * @see DWT
1527 * 1559 */
1528 * @return the receiver's sync-interface thread 1560 public Color getSystemColor (int id) {
1529 * 1561 checkDevice ();
1530 * @exception DWTException <ul> 1562 NSColor color = null;
1531 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> 1563 switch (id) {
1532 * </ul> 1564 case DWT.COLOR_INFO_FOREGROUND: return super.getSystemColor (DWT.COLOR_BLACK);
1533 */ 1565 case DWT.COLOR_INFO_BACKGROUND: return Color.cocoa_new (this, [0xFF / 255f, 0xFF / 255f, 0xE1 / 255f, 1]);
1534 public Thread getSyncThread () { 1566 case DWT.COLOR_TITLE_FOREGROUND: color = NSColor.windowFrameTextColor(); break;
1535 synchronized (Device.classinfo) { 1567 case DWT.COLOR_TITLE_BACKGROUND: color = NSColor.secondarySelectedControlColor(); break;
1536 if (isDisposed ()) error (DWT.ERROR_DEVICE_DISPOSED); 1568 case DWT.COLOR_TITLE_BACKGROUND_GRADIENT: color = NSColor.windowFrameColor(); break;
1537 return synchronizer.syncThread; 1569 case DWT.COLOR_TITLE_INACTIVE_FOREGROUND: color = NSColor.disabledControlTextColor(); break;
1538 } 1570 case DWT.COLOR_TITLE_INACTIVE_BACKGROUND: color = NSColor.secondarySelectedControlColor(); break;
1539 } 1571 case DWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT: color = NSColor.secondarySelectedControlColor(); break;
1540 1572 case DWT.COLOR_WIDGET_DARK_SHADOW: color = NSColor.controlDarkShadowColor(); break;
1541 /** 1573 case DWT.COLOR_WIDGET_NORMAL_SHADOW: color = NSColor.controlShadowColor(); break;
1542 * Returns the matching standard color for the given 1574 case DWT.COLOR_WIDGET_LIGHT_SHADOW: color = NSColor.controlHighlightColor(); break;
1543 * constant, which should be one of the color constants 1575 case DWT.COLOR_WIDGET_HIGHLIGHT_SHADOW: color = NSColor.controlLightHighlightColor(); break;
1544 * specified in class <code>DWT</code>. Any value other 1576 case DWT.COLOR_WIDGET_BACKGROUND: color = NSColor.controlHighlightColor(); break;
1545 * than one of the DWT color constants which is passed 1577 case DWT.COLOR_WIDGET_FOREGROUND: color = NSColor.controlTextColor(); break;
1546 * in will result in the color black. This color should 1578 case DWT.COLOR_WIDGET_BORDER: return super.getSystemColor (DWT.COLOR_BLACK);
1547 * not be free'd because it was allocated by the system, 1579 case DWT.COLOR_LIST_FOREGROUND: color = NSColor.textColor(); break;
1548 * not the application. 1580 case DWT.COLOR_LIST_BACKGROUND: color = NSColor.textBackgroundColor(); break;
1549 * 1581 case DWT.COLOR_LIST_SELECTION_TEXT: color = NSColor.selectedTextColor(); break;
1550 * @param id the color constant 1582 case DWT.COLOR_LIST_SELECTION: color = NSColor.selectedTextBackgroundColor(); break;
1551 * @return the matching color 1583 default:
1552 * 1584 return super.getSystemColor (id);
1553 * @exception DWTException <ul> 1585 }
1554 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 1586 if (color is null) return super.getSystemColor(id);
1555 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> 1587 color = color.colorUsingColorSpace(NSColorSpace.deviceRGBColorSpace());
1556 * </ul> 1588 if (color is null) return super.getSystemColor(id);
1557 * 1589 CGFloat[] components = new CGFloat[color.numberOfComponents()];
1558 * @see DWT 1590 color.getComponents(components.ptr);
1559 */ 1591 return Color.cocoa_new (this, [components[0], components[1], components[2], components[3]]);
1560 public Color getSystemColor (int id) { 1592 }
1561 checkDevice (); 1593
1562 NSColor color = null; 1594 /**
1563 switch (id) { 1595 * Returns the matching standard platform cursor for the given
1564 case DWT.COLOR_INFO_FOREGROUND: return super.getSystemColor (DWT.COLOR_BLACK); 1596 * constant, which should be one of the cursor constants
1565 case DWT.COLOR_INFO_BACKGROUND: return Color.cocoa_new (this, [0xFF / 255f, 0xFF / 255f, 0xE1 / 255f, 1]); 1597 * specified in class <code>DWT</code>. This cursor should
1566 case DWT.COLOR_TITLE_FOREGROUND: color = NSColor.windowFrameTextColor(); break; 1598 * not be free'd because it was allocated by the system,
1567 case DWT.COLOR_TITLE_BACKGROUND: color = NSColor.secondarySelectedControlColor(); break; 1599 * not the application. A value of <code>null</code> will
1568 case DWT.COLOR_TITLE_BACKGROUND_GRADIENT: color = NSColor.windowFrameColor(); break; 1600 * be returned if the supplied constant is not an DWT cursor
1569 case DWT.COLOR_TITLE_INACTIVE_FOREGROUND: color = NSColor.disabledControlTextColor(); break; 1601 * constant.
1570 case DWT.COLOR_TITLE_INACTIVE_BACKGROUND: color = NSColor.secondarySelectedControlColor(); break; 1602 *
1571 case DWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT: color = NSColor.secondarySelectedControlColor(); break; 1603 * @param id the DWT cursor constant
1572 case DWT.COLOR_WIDGET_DARK_SHADOW: color = NSColor.controlDarkShadowColor(); break; 1604 * @return the corresponding cursor or <code>null</code>
1573 case DWT.COLOR_WIDGET_NORMAL_SHADOW: color = NSColor.controlShadowColor(); break; 1605 *
1574 case DWT.COLOR_WIDGET_LIGHT_SHADOW: color = NSColor.controlHighlightColor(); break; 1606 * @exception DWTException <ul>
1575 case DWT.COLOR_WIDGET_HIGHLIGHT_SHADOW: color = NSColor.controlLightHighlightColor(); break; 1607 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1576 case DWT.COLOR_WIDGET_BACKGROUND: color = NSColor.controlHighlightColor(); break; 1608 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
1577 case DWT.COLOR_WIDGET_FOREGROUND: color = NSColor.controlTextColor(); break; 1609 * </ul>
1578 case DWT.COLOR_WIDGET_BORDER: return super.getSystemColor (DWT.COLOR_BLACK); 1610 *
1579 case DWT.COLOR_LIST_FOREGROUND: color = NSColor.textColor(); break; 1611 * @see DWT#CURSOR_ARROW
1580 case DWT.COLOR_LIST_BACKGROUND: color = NSColor.textBackgroundColor(); break; 1612 * @see DWT#CURSOR_WAIT
1581 case DWT.COLOR_LIST_SELECTION_TEXT: color = NSColor.selectedTextColor(); break; 1613 * @see DWT#CURSOR_CROSS
1582 case DWT.COLOR_LIST_SELECTION: color = NSColor.selectedTextBackgroundColor(); break; 1614 * @see DWT#CURSOR_APPSTARTING
1583 default: 1615 * @see DWT#CURSOR_HELP
1584 return super.getSystemColor (id); 1616 * @see DWT#CURSOR_SIZEALL
1585 } 1617 * @see DWT#CURSOR_SIZENESW
1586 if (color is null) return super.getSystemColor(id); 1618 * @see DWT#CURSOR_SIZENS
1587 color = color.colorUsingColorSpace(NSColorSpace.deviceRGBColorSpace()); 1619 * @see DWT#CURSOR_SIZENWSE
1588 if (color is null) return super.getSystemColor(id); 1620 * @see DWT#CURSOR_SIZEWE
1589 CGFloat[] components = new CGFloat[color.numberOfComponents()]; 1621 * @see DWT#CURSOR_SIZEN
1590 color.getComponents(components.ptr); 1622 * @see DWT#CURSOR_SIZES
1591 return Color.cocoa_new (this, [components[0], components[1], components[2], components[3]]); 1623 * @see DWT#CURSOR_SIZEE
1592 } 1624 * @see DWT#CURSOR_SIZEW
1593 1625 * @see DWT#CURSOR_SIZENE
1594 /** 1626 * @see DWT#CURSOR_SIZESE
1595 * Returns the matching standard platform cursor for the given 1627 * @see DWT#CURSOR_SIZESW
1596 * constant, which should be one of the cursor constants 1628 * @see DWT#CURSOR_SIZENW
1597 * specified in class <code>DWT</code>. This cursor should 1629 * @see DWT#CURSOR_UPARROW
1598 * not be free'd because it was allocated by the system, 1630 * @see DWT#CURSOR_IBEAM
1599 * not the application. A value of <code>null</code> will 1631 * @see DWT#CURSOR_NO
1600 * be returned if the supplied constant is not an DWT cursor 1632 * @see DWT#CURSOR_HAND
1601 * constant. 1633 *
1602 * 1634 * @since 3.0
1603 * @param id the DWT cursor constant 1635 */
1604 * @return the corresponding cursor or <code>null</code> 1636 public Cursor getSystemCursor (int id) {
1605 * 1637 checkDevice ();
1606 * @exception DWTException <ul> 1638 if (!(0 <= id && id < cursors.length)) return null;
1607 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 1639 if (cursors [id] is null) {
1608 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> 1640 cursors [id] = new Cursor (this, id);
1609 * </ul> 1641 }
1610 * 1642 return cursors [id];
1611 * @see DWT#CURSOR_ARROW 1643 }
1612 * @see DWT#CURSOR_WAIT 1644
1613 * @see DWT#CURSOR_CROSS 1645 /**
1614 * @see DWT#CURSOR_APPSTARTING 1646 * Returns the matching standard platform image for the given
1615 * @see DWT#CURSOR_HELP 1647 * constant, which should be one of the icon constants
1616 * @see DWT#CURSOR_SIZEALL 1648 * specified in class <code>DWT</code>. This image should
1617 * @see DWT#CURSOR_SIZENESW 1649 * not be free'd because it was allocated by the system,
1618 * @see DWT#CURSOR_SIZENS 1650 * not the application. A value of <code>null</code> will
1619 * @see DWT#CURSOR_SIZENWSE 1651 * be returned either if the supplied constant is not an
1620 * @see DWT#CURSOR_SIZEWE 1652 * DWT icon constant or if the platform does not define an
1621 * @see DWT#CURSOR_SIZEN 1653 * image that corresponds to the constant.
1622 * @see DWT#CURSOR_SIZES 1654 *
1623 * @see DWT#CURSOR_SIZEE 1655 * @param id the DWT icon constant
1624 * @see DWT#CURSOR_SIZEW 1656 * @return the corresponding image or <code>null</code>
1625 * @see DWT#CURSOR_SIZENE 1657 *
1626 * @see DWT#CURSOR_SIZESE 1658 * @exception DWTException <ul>
1627 * @see DWT#CURSOR_SIZESW 1659 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1628 * @see DWT#CURSOR_SIZENW 1660 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
1629 * @see DWT#CURSOR_UPARROW 1661 * </ul>
1630 * @see DWT#CURSOR_IBEAM 1662 *
1631 * @see DWT#CURSOR_NO 1663 * @see DWT#ICON_ERROR
1632 * @see DWT#CURSOR_HAND 1664 * @see DWT#ICON_INFORMATION
1633 * 1665 * @see DWT#ICON_QUESTION
1634 * @since 3.0 1666 * @see DWT#ICON_WARNING
1635 */ 1667 * @see DWT#ICON_WORKING
1636 public Cursor getSystemCursor (int id) { 1668 *
1637 checkDevice (); 1669 * @since 3.0
1638 if (!(0 <= id && id < cursors.length)) return null; 1670 */
1639 if (cursors [id] is null) { 1671 public Image getSystemImage (int id) {
1640 cursors [id] = new Cursor (this, id); 1672 checkDevice ();
1641 } 1673 switch(id) {
1642 return cursors [id]; 1674 case DWT.ICON_ERROR: {
1643 } 1675 if (errorImage !is null) return errorImage;
1644 1676 NSImage nsImage = NSWorkspace.sharedWorkspace ().iconForFileType (new NSString (OS.NSFileTypeForHFSTypeCode (OS.kAlertStopIcon)));
1645 /** 1677 if (nsImage is null) return null;
1646 * Returns the matching standard platform image for the given 1678 nsImage.retain ();
1647 * constant, which should be one of the icon constants 1679 return errorImage = Image.cocoa_new (this, DWT.ICON, nsImage);
1648 * specified in class <code>DWT</code>. This image should 1680 }
1649 * not be free'd because it was allocated by the system, 1681 case DWT.ICON_INFORMATION:
1650 * not the application. A value of <code>null</code> will 1682 case DWT.ICON_QUESTION:
1651 * be returned either if the supplied constant is not an 1683 case DWT.ICON_WORKING: {
1652 * DWT icon constant or if the platform does not define an 1684 if (infoImage !is null) return infoImage;
1653 * image that corresponds to the constant. 1685 NSImage nsImage = NSWorkspace.sharedWorkspace ().iconForFileType (new NSString (OS.NSFileTypeForHFSTypeCode (OS.kAlertNoteIcon)));
1654 * 1686 if (nsImage is null) return null;
1655 * @param id the DWT icon constant 1687 nsImage.retain ();
1656 * @return the corresponding image or <code>null</code> 1688 return infoImage = Image.cocoa_new (this, DWT.ICON, nsImage);
1657 * 1689 }
1658 * @exception DWTException <ul> 1690 case DWT.ICON_WARNING: {
1659 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 1691 if (warningImage !is null) return warningImage;
1660 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> 1692 NSImage nsImage = NSWorkspace.sharedWorkspace ().iconForFileType (new NSString (OS.NSFileTypeForHFSTypeCode (OS.kAlertCautionIcon)));
1661 * </ul> 1693 if (nsImage is null) return null;
1662 * 1694 nsImage.retain ();
1663 * @see DWT#ICON_ERROR 1695 return warningImage = Image.cocoa_new (this, DWT.ICON, nsImage);
1664 * @see DWT#ICON_INFORMATION 1696 }
1665 * @see DWT#ICON_QUESTION 1697
1666 * @see DWT#ICON_WARNING 1698 default:
1667 * @see DWT#ICON_WORKING 1699 }
1668 * 1700 return null;
1669 * @since 3.0 1701 }
1670 */ 1702
1671 public Image getSystemImage (int id) { 1703 /**
1672 checkDevice (); 1704 * Returns the single instance of the system tray or null
1673 switch(id) { 1705 * when there is no system tray available for the platform.
1674 case DWT.ICON_ERROR: { 1706 *
1675 if (errorImage !is null) return errorImage; 1707 * @return the system tray or <code>null</code>
1676 NSImage nsImage = NSWorkspace.sharedWorkspace ().iconForFileType (new NSString (OS.NSFileTypeForHFSTypeCode (OS.kAlertStopIcon))); 1708 *
1677 if (nsImage is null) return null; 1709 * @exception DWTException <ul>
1678 nsImage.retain (); 1710 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
1679 return errorImage = Image.cocoa_new (this, DWT.ICON, nsImage); 1711 * </ul>
1680 } 1712 *
1681 case DWT.ICON_INFORMATION: 1713 * @since 3.0
1682 case DWT.ICON_QUESTION: 1714 */
1683 case DWT.ICON_WORKING: { 1715 public Tray getSystemTray () {
1684 if (infoImage !is null) return infoImage; 1716 checkDevice ();
1685 NSImage nsImage = NSWorkspace.sharedWorkspace ().iconForFileType (new NSString (OS.NSFileTypeForHFSTypeCode (OS.kAlertNoteIcon))); 1717 if (tray !is null) return tray;
1686 if (nsImage is null) return null; 1718 return tray = new Tray (this, DWT.NONE);
1687 nsImage.retain (); 1719 }
1688 return infoImage = Image.cocoa_new (this, DWT.ICON, nsImage); 1720
1689 } 1721 /**
1690 case DWT.ICON_WARNING: { 1722 * Returns the user-interface thread for the receiver.
1691 if (warningImage !is null) return warningImage; 1723 *
1692 NSImage nsImage = NSWorkspace.sharedWorkspace ().iconForFileType (new NSString (OS.NSFileTypeForHFSTypeCode (OS.kAlertCautionIcon))); 1724 * @return the receiver's user-interface thread
1693 if (nsImage is null) return null; 1725 *
1694 nsImage.retain (); 1726 * @exception DWTException <ul>
1695 return warningImage = Image.cocoa_new (this, DWT.ICON, nsImage); 1727 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
1696 } 1728 * </ul>
1697 } 1729 */
1698 return null; 1730 public Thread getThread () {
1699 } 1731 synchronized (Device.classinfo) {
1700 1732 if (isDisposed ()) error (DWT.ERROR_DEVICE_DISPOSED);
1701 /** 1733 return thread;
1702 * Returns the single instance of the system tray or null 1734 }
1703 * when there is no system tray available for the platform. 1735 }
1704 * 1736
1705 * @return the system tray or <code>null</code> 1737 int getToolTipTime () {
1706 * 1738 checkDevice ();
1707 * @exception DWTException <ul> 1739 //TODO get OS value (NSTooltipManager?)
1708 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> 1740 return 560;
1709 * </ul> 1741 }
1710 * 1742
1711 * @since 3.0 1743 Widget getWidget (objc.id id) {
1712 */ 1744 return GetWidget (id);
1713 public Tray getSystemTray () { 1745 }
1714 checkDevice (); 1746
1715 if (tray !is null) return tray; 1747 static Widget GetWidget (objc.id id) {
1716 return tray = new Tray (this, DWT.NONE); 1748 if (id is null) return null;
1717 } 1749 void* jniRef;
1718 1750 OS.object_getInstanceVariable(id, SWT_OBJECT, jniRef);
1719 /** 1751 if (jniRef is null) return null;
1720 * Returns the user-interface thread for the receiver. 1752 return cast(Widget)OS.JNIGetObject(jniRef);
1721 * 1753 }
1722 * @return the receiver's user-interface thread 1754
1723 * 1755 Widget getWidget (NSView view) {
1724 * @exception DWTException <ul> 1756 if (view is null) return null;
1725 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> 1757 return getWidget(view.id);
1726 * </ul> 1758 }
1727 */ 1759
1728 public Thread getThread () { 1760 /**
1729 synchronized (Device.classinfo) { 1761 * Initializes any internal resources needed by the
1730 if (isDisposed ()) error (DWT.ERROR_DEVICE_DISPOSED); 1762 * device.
1731 return thread; 1763 * <p>
1732 } 1764 * This method is called after <code>create</code>.
1733 } 1765 * </p>
1734 1766 *
1735 int getToolTipTime () { 1767 * @see #create
1736 checkDevice (); 1768 */
1737 //TODO get OS value (NSTooltipManager?) 1769 protected void init_ () {
1738 return 560; 1770 super.init_ ();
1739 } 1771 initClasses ();
1740 1772
1741 Widget getWidget (objc.id id) { 1773 /*if (!isEmbedded) {
1742 return GetWidget (id); 1774 initApplicationDelegate();
1743 } 1775 application.finishLaunching();
1744 1776 }
1745 static Widget GetWidget (objc.id id) { 1777
1746 if (id is null) return null; 1778 timerDelegate = cast(SWTWindowDelegate)(new SWTWindowDelegate()).alloc().init();
1747 void* jniRef; 1779
1748 OS.object_getInstanceVariable(id, SWT_OBJECT, jniRef); 1780 NSTextView textView = cast(NSTextView)(new NSTextView()).alloc();
1749 if (jniRef is null) return null; 1781 textView.initWithFrame (NSRect ());
1750 return cast(Widget)OS.JNIGetObject(jniRef); 1782 markedAttributes = textView.markedTextAttributes ();
1751 } 1783 markedAttributes.retain ();
1752 1784 textView.release ();*/
1753 Widget getWidget (NSView view) { 1785 }
1754 if (view is null) return null; 1786
1755 return getWidget(view.id); 1787 void initApplicationDelegate() {
1756 } 1788 String className = "SWTApplicationDelegate";
1757 1789 if (OS.objc_lookUpClass (className) is null) {
1758 /** 1790 objc.IMP appProc3 = cast(objc.IMP) &applicationDelegateProc;
1759 * Initializes any internal resources needed by the 1791 objc.Class cls = OS.objc_allocateClassPair(cast(objc.Class) OS.class_NSObject, className, 0);
1760 * device. 1792 OS.class_addMethod(cls, OS.sel_applicationWillFinishLaunching_, appProc3, "@:@");
1761 * <p> 1793 OS.class_addMethod(cls, OS.sel_terminate_, appProc3, "@:@");
1762 * This method is called after <code>create</code>. 1794 OS.class_addMethod(cls, OS.sel_orderFrontStandardAboutPanel_, appProc3, "@:@");
1763 * </p> 1795 OS.class_addMethod(cls, OS.sel_hideOtherApplications_, appProc3, "@:@");
1764 * 1796 OS.class_addMethod(cls, OS.sel_hide_, appProc3, "@:@");
1765 * @see #create 1797 OS.class_addMethod(cls, OS.sel_unhideAllApplications_, appProc3, "@:@");
1766 */ 1798 OS.class_addMethod(cls, OS.sel_applicationShouldTerminate_, appProc3, "@:@");
1767 protected void init_ () { 1799 OS.class_addMethod(cls, OS.sel_applicationWillTerminate_, appProc3, "@:@");
1768 super.init_ (); 1800 OS.class_addMethod(cls, OS.sel_applicationWillResignActive_, appProc3, "@:@");
1769 initClasses (); 1801 OS.objc_registerClassPair(cls);
1770 1802 }
1771 if (!isEmbedded) { 1803 applicationDelegate = cast(SWTApplicationDelegate)(new SWTApplicationDelegate()).alloc().init();
1772 initApplicationDelegate(); 1804 application.setDelegate(applicationDelegate);
1773 application.finishLaunching(); 1805 }
1774 } 1806
1775 1807 void addEventMethods (objc.Class cls, objc.IMP proc2, objc.IMP proc3, objc.IMP drawRectProc) {
1776 timerDelegate = cast(SWTWindowDelegate)(new SWTWindowDelegate()).alloc().init(); 1808 OS.class_addMethod(cls, OS.sel_mouseDown_, proc3, "@:@");
1777 1809 OS.class_addMethod(cls, OS.sel_mouseUp_, proc3, "@:@");
1778 NSTextView textView = cast(NSTextView)(new NSTextView()).alloc(); 1810 OS.class_addMethod(cls, OS.sel_scrollWheel_, proc3, "@:@");
1779 textView.initWithFrame (NSRect ()); 1811 OS.class_addMethod(cls, OS.sel_rightMouseDown_, proc3, "@:@");
1780 markedAttributes = textView.markedTextAttributes (); 1812 OS.class_addMethod(cls, OS.sel_rightMouseUp_, proc3, "@:@");
1781 markedAttributes.retain (); 1813 OS.class_addMethod(cls, OS.sel_otherMouseDown_, proc3, "@:@");
1782 textView.release (); 1814 OS.class_addMethod(cls, OS.sel_otherMouseUp_, proc3, "@:@");
1783 } 1815 OS.class_addMethod(cls, OS.sel_mouseDragged_, proc3, "@:@");
1784 1816 OS.class_addMethod(cls, OS.sel_mouseMoved_, proc3, "@:@");
1785 void initApplicationDelegate() { 1817 OS.class_addMethod(cls, OS.sel_mouseEntered_, proc3, "@:@");
1786 String className = "SWTApplicationDelegate"; 1818 OS.class_addMethod(cls, OS.sel_mouseExited_, proc3, "@:@");
1787 if (OS.objc_lookUpClass (className) is null) { 1819 OS.class_addMethod(cls, OS.sel_menuForEvent_, proc3, "@:@");
1788 objc.IMP appProc3 = cast(objc.IMP) &applicationDelegateProc; 1820 OS.class_addMethod(cls, OS.sel_resignFirstResponder, proc2, "@:");
1821 OS.class_addMethod(cls, OS.sel_becomeFirstResponder, proc2, "@:");
1822 OS.class_addMethod(cls, OS.sel_keyDown_, proc3, "@:@");
1823 OS.class_addMethod(cls, OS.sel_keyUp_, proc3, "@:@");
1824 OS.class_addMethod(cls, OS.sel_flagsChanged_, proc3, "@:@");
1825 OS.class_addMethod(cls, OS.sel_drawRect_, drawRectProc, "@:{NSRect}");
1826 }
1827
1828 void addFrameMethods(objc.Class cls, objc.IMP setFrameOriginProc, objc.IMP setFrameSizeProc) {
1829 OS.class_addMethod(cls, OS.sel_setFrameOrigin_, setFrameOriginProc, "@:{NSPoint}");
1830 OS.class_addMethod(cls, OS.sel_setFrameSize_, setFrameSizeProc, "@:{NSSize}");
1831 }
1832
1833 void addAccessibilityMethods(objc.Class cls, objc.IMP proc2, objc.IMP proc3, objc.IMP proc4, objc.IMP accessibilityHitTestProc) {
1834 OS.class_addMethod(cls, OS.sel_accessibilityActionNames, proc2, "@:");
1835 OS.class_addMethod(cls, OS.sel_accessibilityAttributeNames, proc2, "@:");
1836 OS.class_addMethod(cls, OS.sel_accessibilityParameterizedAttributeNames, proc2, "@:");
1837 OS.class_addMethod(cls, OS.sel_accessibilityFocusedUIElement, proc2, "@:");
1838 OS.class_addMethod(cls, OS.sel_accessibilityIsIgnored, proc2, "@:");
1839 OS.class_addMethod(cls, OS.sel_accessibilityAttributeValue_, proc3, "@:@");
1840 OS.class_addMethod(cls, OS.sel_accessibilityIsAttributeSettable_, proc3, "@:@");
1841 OS.class_addMethod(cls, OS.sel_accessibilityHitTest_, accessibilityHitTestProc, "@:{NSPoint}");
1842 OS.class_addMethod(cls, OS.sel_accessibilityAttributeValue_forParameter_, proc4, "@:@@");
1843 OS.class_addMethod(cls, OS.sel_accessibilityPerformAction_, proc3, "@:@");
1844 OS.class_addMethod(cls, OS.sel_accessibilityActionDescription_, proc3, "@:@");
1845 }
1846
1847 objc.Class registerCellSubclass(objc.Class cellClass, int size, int align_, String types) {
1848 String cellClassName = OS.class_getName(cellClass);
1849 objc.Class cls = OS.objc_allocateClassPair(cellClass, "SWT" ~ cellClassName, 0);
1850 OS.class_addIvar(cls, SWT_OBJECT, size, cast(byte)align_, types);
1851 OS.objc_registerClassPair(cls);
1852 return cls;
1853 }
1854
1855 void initClasses () {
1856 if (OS.objc_lookUpClass ("SWTView") !is null) return;
1857
1858 objc.IMP dialogProc3 = cast(objc.IMP) &dialogProc;
1859 objc.IMP proc3 = cast(objc.IMP) &windowDelegateProc3;
1860 objc.IMP proc2 = cast(objc.IMP) &windowDelegateProc2;
1861 objc.IMP proc4 = cast(objc.IMP) &windowDelegateProc4;
1862 objc.IMP proc5 = cast(objc.IMP) &windowDelegateProc5;
1863 objc.IMP proc6 = cast(objc.IMP) &windowDelegateProc6;
1864
1865 objc.IMP drawRectProc = OS.drawRect_CALLBACK(proc3);
1866 objc.IMP drawInteriorWithFrameInViewProc = OS.drawInteriorWithFrame_inView_CALLBACK (proc4);
1867 objc.IMP setFrameOriginProc = OS.setFrameOrigin_CALLBACK(proc3);
1868 objc.IMP setFrameSizeProc = OS.setFrameSize_CALLBACK(proc3);
1869 objc.IMP hitTestProc = OS.hitTest_CALLBACK(proc3);
1870 objc.IMP markedRangeProc = OS.markedRange_CALLBACK(proc2);
1871 objc.IMP selectedRangeProc = OS.selectedRange_CALLBACK(proc2);
1872 objc.IMP highlightSelectionInClipRectProc = OS.highlightSelectionInClipRect_CALLBACK(proc3);
1873 objc.IMP setMarkedText_selectedRangeProc = OS.setMarkedText_selectedRange_CALLBACK(proc4);
1874 objc.IMP attributedSubstringFromRangeProc = OS.attributedSubstringFromRange_CALLBACK(proc3);
1875 objc.IMP characterIndexForPointProc = OS.characterIndexForPoint_CALLBACK(proc3);
1876 objc.IMP firstRectForCharacterRangeProc = OS.firstRectForCharacterRange_CALLBACK(proc3);
1877 objc.IMP textWillChangeSelectionProc = OS.textView_willChangeSelectionFromCharacterRange_toCharacterRange_CALLBACK(proc5);
1878 objc.IMP accessibilityHitTestProc = OS.accessibilityHitTest_CALLBACK(proc3);
1879
1880 String types = "*";
1881 size_t size = C.PTR_SIZEOF, align_ = C.PTR_SIZEOF is 4 ? 2 : 3;
1882
1883 String className = "SWTWindowDelegate";
1789 objc.Class cls = OS.objc_allocateClassPair(cast(objc.Class) OS.class_NSObject, className, 0); 1884 objc.Class cls = OS.objc_allocateClassPair(cast(objc.Class) OS.class_NSObject, className, 0);
1790 OS.class_addMethod(cls, OS.sel_applicationWillFinishLaunching_, appProc3, "@:@"); 1885 OS.class_addIvar(cls, SWT_OBJECT, size, cast(byte)align_, types);
1791 OS.class_addMethod(cls, OS.sel_terminate_, appProc3, "@:@"); 1886 OS.class_addMethod(cls, OS.sel_windowDidResize_, proc3, "@:@");
1792 OS.class_addMethod(cls, OS.sel_orderFrontStandardAboutPanel_, appProc3, "@:@"); 1887 OS.class_addMethod(cls, OS.sel_windowDidMove_, proc3, "@:@");
1793 OS.class_addMethod(cls, OS.sel_hideOtherApplications_, appProc3, "@:@"); 1888 OS.class_addMethod(cls, OS.sel_windowShouldClose_, proc3, "@:@");
1794 OS.class_addMethod(cls, OS.sel_hide_, appProc3, "@:@"); 1889 OS.class_addMethod(cls, OS.sel_windowWillClose_, proc3, "@:@");
1795 OS.class_addMethod(cls, OS.sel_unhideAllApplications_, appProc3, "@:@"); 1890 OS.class_addMethod(cls, OS.sel_windowDidResignKey_, proc3, "@:@");
1796 OS.class_addMethod(cls, OS.sel_applicationShouldTerminate_, appProc3, "@:@"); 1891 OS.class_addMethod(cls, OS.sel_windowDidBecomeKey_, proc3, "@:@");
1797 OS.class_addMethod(cls, OS.sel_applicationWillTerminate_, appProc3, "@:@"); 1892 OS.class_addMethod(cls, OS.sel_timerProc_, proc3, "@:@");
1798 OS.class_addMethod(cls, OS.sel_applicationWillResignActive_, appProc3, "@:@");
1799 OS.objc_registerClassPair(cls); 1893 OS.objc_registerClassPair(cls);
1800 } 1894
1801 applicationDelegate = cast(SWTApplicationDelegate)(new SWTApplicationDelegate()).alloc().init(); 1895 className = "SWTPanelDelegate";
1802 application.setDelegate(applicationDelegate); 1896 cls = OS.objc_allocateClassPair(cast(objc.Class) OS.class_NSObject, className, 0);
1803 } 1897 OS.class_addIvar(cls, SWT_OBJECT, size, cast(byte)align_, types);
1804 1898 OS.class_addMethod(cls, OS.sel_windowWillClose_, dialogProc3, "@:@");
1805 void addEventMethods (objc.Class cls, objc.IMP proc2, objc.IMP proc3, objc.IMP drawRectProc) { 1899 OS.class_addMethod(cls, OS.sel_changeColor_, dialogProc3, "@:@");
1806 OS.class_addMethod(cls, OS.sel_mouseDown_, proc3, "@:@"); 1900 OS.class_addMethod(cls, OS.sel_changeFont_, dialogProc3, "@:@");
1807 OS.class_addMethod(cls, OS.sel_mouseUp_, proc3, "@:@"); 1901 OS.objc_registerClassPair(cls);
1808 OS.class_addMethod(cls, OS.sel_scrollWheel_, proc3, "@:@"); 1902
1809 OS.class_addMethod(cls, OS.sel_rightMouseDown_, proc3, "@:@"); 1903 className = "SWTMenu";
1810 OS.class_addMethod(cls, OS.sel_rightMouseUp_, proc3, "@:@"); 1904 cls = OS.objc_allocateClassPair(cast(objc.Class) OS.class_NSMenu, className, 0);
1811 OS.class_addMethod(cls, OS.sel_otherMouseDown_, proc3, "@:@"); 1905 OS.class_addIvar(cls, SWT_OBJECT, size, cast(byte)align_, types);
1812 OS.class_addMethod(cls, OS.sel_otherMouseUp_, proc3, "@:@"); 1906 OS.class_addMethod(cls, OS.sel_menuWillOpen_, proc3, "@:@");
1813 OS.class_addMethod(cls, OS.sel_mouseDragged_, proc3, "@:@"); 1907 OS.class_addMethod(cls, OS.sel_menuDidClose_, proc3, "@:@");
1814 OS.class_addMethod(cls, OS.sel_mouseMoved_, proc3, "@:@"); 1908 OS.class_addMethod(cls, OS.sel_menu_willHighlightItem_, proc4, "@:@@");
1815 OS.class_addMethod(cls, OS.sel_mouseEntered_, proc3, "@:@"); 1909 OS.class_addMethod(cls, OS.sel_menuNeedsUpdate_, proc3, "@:@");
1816 OS.class_addMethod(cls, OS.sel_mouseExited_, proc3, "@:@"); 1910 OS.objc_registerClassPair(cls);
1817 OS.class_addMethod(cls, OS.sel_menuForEvent_, proc3, "@:@"); 1911
1818 OS.class_addMethod(cls, OS.sel_resignFirstResponder, proc2, "@:"); 1912 className = "SWTView";
1819 OS.class_addMethod(cls, OS.sel_becomeFirstResponder, proc2, "@:"); 1913 cls = OS.objc_allocateClassPair(cast(objc.Class) OS.class_NSView, className, 0);
1820 OS.class_addMethod(cls, OS.sel_keyDown_, proc3, "@:@"); 1914 OS.class_addProtocol(cls, OS.objc_getProtocol("NSTextInput"));
1821 OS.class_addMethod(cls, OS.sel_keyUp_, proc3, "@:@"); 1915 OS.class_addIvar(cls, SWT_OBJECT, size, cast(byte)align_, types);
1822 OS.class_addMethod(cls, OS.sel_flagsChanged_, proc3, "@:@"); 1916 OS.class_addMethod(cls, OS.sel_isFlipped, proc2, "@:");
1823 OS.class_addMethod(cls, OS.sel_drawRect_, drawRectProc, "@:{NSRect}"); 1917 OS.class_addMethod(cls, OS.sel_acceptsFirstResponder, proc2, "@:");
1824 } 1918 OS.class_addMethod(cls, OS.sel_isOpaque, proc2, "@:");
1825 1919 OS.class_addMethod(cls, OS.sel_hitTest_, hitTestProc, "@:{NSPoint}");
1826 void addFrameMethods(objc.Class cls, objc.IMP setFrameOriginProc, objc.IMP setFrameSizeProc) { 1920
1827 OS.class_addMethod(cls, OS.sel_setFrameOrigin_, setFrameOriginProc, "@:{NSPoint}"); 1921 //NSTextInput protocol
1828 OS.class_addMethod(cls, OS.sel_setFrameSize_, setFrameSizeProc, "@:{NSSize}"); 1922 OS.class_addMethod(cls, OS.sel_hasMarkedText, proc2, "@:");
1829 } 1923 OS.class_addMethod(cls, OS.sel_markedRange, markedRangeProc, "@:");
1830 1924 OS.class_addMethod(cls, OS.sel_selectedRange, selectedRangeProc, "@:");
1831 void addAccessibilityMethods(objc.Class cls, objc.IMP proc2, objc.IMP proc3, objc.IMP proc4, objc.IMP accessibilityHitTestProc) { 1925 OS.class_addMethod(cls, OS.sel_setMarkedText_selectedRange_, setMarkedText_selectedRangeProc, "@:@{NSRange}");
1832 OS.class_addMethod(cls, OS.sel_accessibilityActionNames, proc2, "@:"); 1926 OS.class_addMethod(cls, OS.sel_unmarkText, proc2, "@:");
1833 OS.class_addMethod(cls, OS.sel_accessibilityAttributeNames, proc2, "@:"); 1927 OS.class_addMethod(cls, OS.sel_validAttributesForMarkedText, proc2, "@:");
1834 OS.class_addMethod(cls, OS.sel_accessibilityParameterizedAttributeNames, proc2, "@:"); 1928 OS.class_addMethod(cls, OS.sel_attributedSubstringFromRange_, attributedSubstringFromRangeProc, "@:{NSRange}");
1835 OS.class_addMethod(cls, OS.sel_accessibilityFocusedUIElement, proc2, "@:"); 1929 OS.class_addMethod(cls, OS.sel_insertText_, proc3, "@:@");
1836 OS.class_addMethod(cls, OS.sel_accessibilityIsIgnored, proc2, "@:"); 1930 OS.class_addMethod(cls, OS.sel_characterIndexForPoint_, characterIndexForPointProc, "@:{NSPoint}");
1837 OS.class_addMethod(cls, OS.sel_accessibilityAttributeValue_, proc3, "@:@"); 1931 OS.class_addMethod(cls, OS.sel_firstRectForCharacterRange_, firstRectForCharacterRangeProc, "@:{NSRange}");
1838 OS.class_addMethod(cls, OS.sel_accessibilityIsAttributeSettable_, proc3, "@:@"); 1932 OS.class_addMethod(cls, OS.sel_doCommandBySelector_, proc3, "@::");
1839 OS.class_addMethod(cls, OS.sel_accessibilityHitTest_, accessibilityHitTestProc, "@:{NSPoint}"); 1933
1840 OS.class_addMethod(cls, OS.sel_accessibilityAttributeValue_forParameter_, proc4, "@:@@"); 1934 addEventMethods(cls, proc2, proc3, drawRectProc);
1841 OS.class_addMethod(cls, OS.sel_accessibilityPerformAction_, proc3, "@:@"); 1935 addFrameMethods(cls, setFrameOriginProc, setFrameSizeProc);
1842 OS.class_addMethod(cls, OS.sel_accessibilityActionDescription_, proc3, "@:@"); 1936 addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc);
1843 } 1937 OS.objc_registerClassPair(cls);
1844 1938
1845 objc.Class registerCellSubclass(objc.Class cellClass, int size, int align_, String types) { 1939 className = "SWTScrollView";
1846 String cellClassName = OS.class_getName(cellClass); 1940 cls = OS.objc_allocateClassPair(cast(objc.Class) OS.class_NSScrollView, className, 0);
1847 objc.Class cls = OS.objc_allocateClassPair(cellClass, "SWT" ~ cellClassName, 0); 1941 OS.class_addIvar(cls, SWT_OBJECT, size, cast(byte)align_, types);
1848 OS.class_addIvar(cls, SWT_OBJECT, size, cast(byte)align_, types); 1942 OS.class_addMethod(cls, OS.sel_sendVerticalSelection, proc2, "@:");
1849 OS.objc_registerClassPair(cls); 1943 OS.class_addMethod(cls, OS.sel_sendHorizontalSelection, proc2, "@:");
1850 return cls; 1944 OS.class_addMethod(cls, OS.sel_pageDown_, proc3, "@:@");
1851 } 1945 OS.class_addMethod(cls, OS.sel_pageUp_, proc3, "@:@");
1852 1946 OS.class_addMethod(cls, OS.sel_reflectScrolledClipView_, proc3, "@:@");
1853 void initClasses () { 1947 addEventMethods(cls, proc2, proc3, drawRectProc);
1854 if (OS.objc_lookUpClass ("SWTView") !is null) return; 1948 addFrameMethods(cls, setFrameOriginProc, setFrameSizeProc);
1855 1949 addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc);
1856 objc.IMP dialogProc3 = cast(objc.IMP) &dialogProc; 1950 OS.objc_registerClassPair(cls);
1857 objc.IMP proc3 = cast(objc.IMP) &windowDelegateProc3; 1951
1858 objc.IMP proc2 = cast(objc.IMP) &windowDelegateProc2; 1952 className = "SWTButton";
1859 objc.IMP proc4 = cast(objc.IMP) &windowDelegateProc4; 1953 cls = OS.objc_allocateClassPair(cast(objc.Class) OS.class_NSButton, className, 0);
1860 objc.IMP proc5 = cast(objc.IMP) &windowDelegateProc5; 1954 OS.class_addIvar(cls, SWT_OBJECT, size, cast(byte)align_, types);
1861 objc.IMP proc6 = cast(objc.IMP) &windowDelegateProc6; 1955 OS.class_addMethod(cls, OS.sel_sendSelection, proc2, "@:");
1862 1956 addEventMethods(cls, proc2, proc3, drawRectProc);
1863 objc.IMP drawRectProc = OS.drawRect_CALLBACK(proc3); 1957 addFrameMethods(cls, setFrameOriginProc, setFrameSizeProc);
1864 objc.IMP drawInteriorWithFrameInViewProc = OS.drawInteriorWithFrame_inView_CALLBACK (proc4); 1958 addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc);
1865 objc.IMP setFrameOriginProc = OS.setFrameOrigin_CALLBACK(proc3); 1959 OS.objc_registerClassPair(cls);
1866 objc.IMP setFrameSizeProc = OS.setFrameSize_CALLBACK(proc3); 1960
1867 objc.IMP hitTestProc = OS.hitTest_CALLBACK(proc3); 1961 cls = registerCellSubclass(NSButton.cellClass(), size, align_, types);
1868 objc.IMP markedRangeProc = OS.markedRange_CALLBACK(proc2); 1962 addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc);
1869 objc.IMP selectedRangeProc = OS.selectedRange_CALLBACK(proc2); 1963 NSButton.setCellClass(cls);
1870 objc.IMP highlightSelectionInClipRectProc = OS.highlightSelectionInClipRect_CALLBACK(proc3); 1964
1871 objc.IMP setMarkedText_selectedRangeProc = OS.setMarkedText_selectedRange_CALLBACK(proc4); 1965 className = "SWTTableView";
1872 objc.IMP attributedSubstringFromRangeProc = OS.attributedSubstringFromRange_CALLBACK(proc3); 1966 cls = OS.objc_allocateClassPair(cast(objc.Class) OS.class_NSTableView, className, 0);
1873 objc.IMP characterIndexForPointProc = OS.characterIndexForPoint_CALLBACK(proc3); 1967 OS.class_addIvar(cls, SWT_OBJECT, size, cast(byte)align_, types);
1874 objc.IMP firstRectForCharacterRangeProc = OS.firstRectForCharacterRange_CALLBACK(proc3); 1968 OS.class_addMethod(cls, OS.sel_highlightSelectionInClipRect_, highlightSelectionInClipRectProc, "@:{NSRect}");
1875 objc.IMP textWillChangeSelectionProc = OS.textView_willChangeSelectionFromCharacterRange_toCharacterRange_CALLBACK(proc5); 1969 OS.class_addMethod(cls, OS.sel_sendDoubleSelection, proc2, "@:");
1876 objc.IMP accessibilityHitTestProc = OS.accessibilityHitTest_CALLBACK(proc3); 1970 OS.class_addMethod(cls, OS.sel_numberOfRowsInTableView_, proc3, "@:@");
1877 1971 OS.class_addMethod(cls, OS.sel_tableView_objectValueForTableColumn_row_, proc5, "@:@:@:@");
1878 String types = "*"; 1972 OS.class_addMethod(cls, OS.sel_tableView_shouldEditTableColumn_row_, proc5, "@:@:@:@");
1879 size_t size = C.PTR_SIZEOF, align_ = C.PTR_SIZEOF is 4 ? 2 : 3; 1973 OS.class_addMethod(cls, OS.sel_tableViewSelectionDidChange_, proc3, "@:@");
1880 1974 static if ((void*).sizeof > int.sizeof) /* 64bit target*/ OS.class_addMethod(cls, OS.sel_tableView_willDisplayCell_forTableColumn_row_, proc6, "@:@@@q");
1881 String className = "SWTWindowDelegate"; 1975 else OS.class_addMethod(cls, OS.sel_tableView_willDisplayCell_forTableColumn_row_, proc6, "@:@@@i");
1882 objc.Class cls = OS.objc_allocateClassPair(cast(objc.Class) OS.class_NSObject, className, 0); 1976 static if ((void*).sizeof > int.sizeof) /* 64bit target*/ OS.class_addMethod(cls, OS.sel_tableView_setObjectValue_forTableColumn_row_, proc6, "@:@@@q");
1883 OS.class_addIvar(cls, SWT_OBJECT, size, cast(byte)align_, types); 1977 else OS.class_addMethod(cls, OS.sel_tableView_setObjectValue_forTableColumn_row_, proc6, "@:@@@i");
1884 OS.class_addMethod(cls, OS.sel_windowDidResize_, proc3, "@:@"); 1978 OS.class_addMethod(cls, OS.sel_tableViewColumnDidMove_, proc3, "@:@");
1885 OS.class_addMethod(cls, OS.sel_windowDidMove_, proc3, "@:@"); 1979 OS.class_addMethod(cls, OS.sel_tableViewColumnDidResize_, proc3, "@:@");
1886 OS.class_addMethod(cls, OS.sel_windowShouldClose_, proc3, "@:@"); 1980 OS.class_addMethod(cls, OS.sel_tableView_didClickTableColumn_, proc4, "@:@");
1887 OS.class_addMethod(cls, OS.sel_windowWillClose_, proc3, "@:@"); 1981 addEventMethods(cls, proc2, proc3, drawRectProc);
1888 OS.class_addMethod(cls, OS.sel_windowDidResignKey_, proc3, "@:@"); 1982 addFrameMethods(cls, setFrameOriginProc, setFrameSizeProc);
1889 OS.class_addMethod(cls, OS.sel_windowDidBecomeKey_, proc3, "@:@"); 1983 addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc);
1890 OS.class_addMethod(cls, OS.sel_timerProc_, proc3, "@:@"); 1984 OS.objc_registerClassPair(cls);
1891 OS.objc_registerClassPair(cls); 1985
1892 1986 className = "SWTTableHeaderCell";
1893 className = "SWTPanelDelegate"; 1987 cls = OS.objc_allocateClassPair (cast(objc.Class) OS.class_NSTableHeaderCell, className, 0);
1894 cls = OS.objc_allocateClassPair(cast(objc.Class) OS.class_NSObject, className, 0); 1988 OS.class_addIvar (cls, SWT_OBJECT, size, cast(byte)align_, types);
1895 OS.class_addIvar(cls, SWT_OBJECT, size, cast(byte)align_, types); 1989 OS.class_addMethod (cls, OS.sel_drawInteriorWithFrame_inView_, drawInteriorWithFrameInViewProc, "@:{NSRect}@");
1896 OS.class_addMethod(cls, OS.sel_windowWillClose_, dialogProc3, "@:@"); 1990 OS.objc_registerClassPair (cls);
1897 OS.class_addMethod(cls, OS.sel_changeColor_, dialogProc3, "@:@"); 1991
1898 OS.class_addMethod(cls, OS.sel_changeFont_, dialogProc3, "@:@"); 1992 className = "SWTBrowserCell";
1899 OS.objc_registerClassPair(cls); 1993 cls = OS.objc_allocateClassPair (cast(objc.Class) OS.class_NSBrowserCell, className, 0);
1900 1994 OS.class_addIvar (cls, SWT_OBJECT, size, cast(byte)align_, types);
1901 className = "SWTMenu"; 1995 OS.class_addMethod (cls, OS.sel_drawInteriorWithFrame_inView_, drawInteriorWithFrameInViewProc, "@:{NSRect}@");
1902 cls = OS.objc_allocateClassPair(cast(objc.Class) OS.class_NSMenu, className, 0); 1996 OS.objc_registerClassPair (cls);
1903 OS.class_addIvar(cls, SWT_OBJECT, size, cast(byte)align_, types); 1997
1904 OS.class_addMethod(cls, OS.sel_menuWillOpen_, proc3, "@:@"); 1998 className = "SWTTableHeaderView";
1905 OS.class_addMethod(cls, OS.sel_menuDidClose_, proc3, "@:@"); 1999 cls = OS.objc_allocateClassPair(cast(objc.Class) OS.class_NSTableHeaderView, className, 0);
1906 OS.class_addMethod(cls, OS.sel_menu_willHighlightItem_, proc4, "@:@@"); 2000 OS.class_addIvar(cls, SWT_OBJECT, size, cast(byte)align_, types);
1907 OS.class_addMethod(cls, OS.sel_menuNeedsUpdate_, proc3, "@:@"); 2001 OS.class_addMethod(cls, OS.sel_mouseDown_, proc3, "@:@");
1908 OS.objc_registerClassPair(cls); 2002 OS.objc_registerClassPair(cls);
1909 2003
1910 className = "SWTView"; 2004 className = "SWTOutlineView";
1911 cls = OS.objc_allocateClassPair(cast(objc.Class) OS.class_NSView, className, 0); 2005 cls = OS.objc_allocateClassPair(cast(objc.Class) OS.class_NSOutlineView, className, 0);
1912 OS.class_addProtocol(cls, OS.objc_getProtocol("NSTextInput")); 2006 OS.class_addIvar(cls, SWT_OBJECT, size, cast(byte)align_, types);
1913 OS.class_addIvar(cls, SWT_OBJECT, size, cast(byte)align_, types); 2007 OS.class_addMethod(cls, OS.sel_highlightSelectionInClipRect_, highlightSelectionInClipRectProc, "@:{NSRect}");
1914 OS.class_addMethod(cls, OS.sel_isFlipped, proc2, "@:"); 2008 OS.class_addMethod(cls, OS.sel_sendDoubleSelection, proc2, "@:");
1915 OS.class_addMethod(cls, OS.sel_acceptsFirstResponder, proc2, "@:"); 2009 OS.class_addMethod(cls, OS.sel_outlineViewSelectionDidChange_, proc3, "@:@");
1916 OS.class_addMethod(cls, OS.sel_isOpaque, proc2, "@:"); 2010 OS.class_addMethod(cls, OS.sel_outlineViewItemDidExpand_, proc3, "@:@");
1917 OS.class_addMethod(cls, OS.sel_hitTest_, hitTestProc, "@:{NSPoint}"); 2011 OS.class_addMethod(cls, OS.sel_outlineView_shouldCollapseItem_, proc4, "@:@@");
1918 2012 OS.class_addMethod(cls, OS.sel_outlineView_shouldExpandItem_, proc4, "@:@@");
1919 //NSTextInput protocol 2013 OS.class_addMethod(cls, OS.sel_outlineView_child_ofItem_, proc5, "@:@i@");
1920 OS.class_addMethod(cls, OS.sel_hasMarkedText, proc2, "@:"); 2014 OS.class_addMethod(cls, OS.sel_outlineView_isItemExpandable_, proc4, "@:@@");
1921 OS.class_addMethod(cls, OS.sel_markedRange, markedRangeProc, "@:"); 2015 OS.class_addMethod(cls, OS.sel_outlineView_numberOfChildrenOfItem_, proc4, "@:@@");
1922 OS.class_addMethod(cls, OS.sel_selectedRange, selectedRangeProc, "@:"); 2016 OS.class_addMethod(cls, OS.sel_outlineView_objectValueForTableColumn_byItem_, proc5, "@:@@@");
1923 OS.class_addMethod(cls, OS.sel_setMarkedText_selectedRange_, setMarkedText_selectedRangeProc, "@:@{NSRange}"); 2017 OS.class_addMethod(cls, OS.sel_outlineView_willDisplayCell_forTableColumn_item_, proc6, "@:@@@@");
1924 OS.class_addMethod(cls, OS.sel_unmarkText, proc2, "@:"); 2018 OS.class_addMethod(cls, OS.sel_outlineView_setObjectValue_forTableColumn_byItem_, proc6, "@:@@@@");
1925 OS.class_addMethod(cls, OS.sel_validAttributesForMarkedText, proc2, "@:"); 2019 OS.class_addMethod(cls, OS.sel_outlineViewColumnDidMove_, proc3, "@:@");
1926 OS.class_addMethod(cls, OS.sel_attributedSubstringFromRange_, attributedSubstringFromRangeProc, "@:{NSRange}"); 2020 OS.class_addMethod(cls, OS.sel_outlineViewColumnDidResize_, proc3, "@:@");
1927 OS.class_addMethod(cls, OS.sel_insertText_, proc3, "@:@"); 2021 OS.class_addMethod(cls, OS.sel_outlineView_didClickTableColumn_, proc4, "@:@");
1928 OS.class_addMethod(cls, OS.sel_characterIndexForPoint_, characterIndexForPointProc, "@:{NSPoint}"); 2022 addEventMethods(cls, proc2, proc3, drawRectProc);
1929 OS.class_addMethod(cls, OS.sel_firstRectForCharacterRange_, firstRectForCharacterRangeProc, "@:{NSRange}"); 2023 addFrameMethods(cls, setFrameOriginProc, setFrameSizeProc);
1930 OS.class_addMethod(cls, OS.sel_doCommandBySelector_, proc3, "@::"); 2024 addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc);
1931 2025 OS.objc_registerClassPair(cls);
1932 addEventMethods(cls, proc2, proc3, drawRectProc); 2026
1933 addFrameMethods(cls, setFrameOriginProc, setFrameSizeProc); 2027 className = "SWTTreeItem";
1934 addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc); 2028 cls = OS.objc_allocateClassPair(cast(objc.Class) OS.class_NSObject, className, 0);
1935 OS.objc_registerClassPair(cls); 2029 OS.class_addIvar(cls, SWT_OBJECT, size, cast(byte)align_, types);
1936 2030 OS.objc_registerClassPair(cls);
1937 className = "SWTScrollView"; 2031
1938 cls = OS.objc_allocateClassPair(cast(objc.Class) OS.class_NSScrollView, className, 0); 2032 className = "SWTTabView";
1939 OS.class_addIvar(cls, SWT_OBJECT, size, cast(byte)align_, types); 2033 cls = OS.objc_allocateClassPair(cast(objc.Class) OS.class_NSTabView, className, 0);
1940 OS.class_addMethod(cls, OS.sel_sendVerticalSelection, proc2, "@:"); 2034 OS.class_addIvar(cls, SWT_OBJECT, size, cast(byte)align_, types);
1941 OS.class_addMethod(cls, OS.sel_sendHorizontalSelection, proc2, "@:"); 2035 OS.class_addMethod(cls, OS.sel_tabView_willSelectTabViewItem_, proc4, "@:@@");
1942 OS.class_addMethod(cls, OS.sel_pageDown_, proc3, "@:@"); 2036 OS.class_addMethod(cls, OS.sel_tabView_didSelectTabViewItem_, proc4, "@:@@");
1943 OS.class_addMethod(cls, OS.sel_pageUp_, proc3, "@:@"); 2037 addEventMethods(cls, proc2, proc3, drawRectProc);
1944 OS.class_addMethod(cls, OS.sel_reflectScrolledClipView_, proc3, "@:@"); 2038 addFrameMethods(cls, setFrameOriginProc, setFrameSizeProc);
1945 addEventMethods(cls, proc2, proc3, drawRectProc); 2039 addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc);
1946 addFrameMethods(cls, setFrameOriginProc, setFrameSizeProc); 2040 OS.objc_registerClassPair(cls);
1947 addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc); 2041
1948 OS.objc_registerClassPair(cls); 2042 className = "SWTBox";
1949 2043 cls = OS.objc_allocateClassPair(cast(objc.Class) OS.class_NSBox, className, 0);
1950 className = "SWTButton"; 2044 OS.class_addIvar(cls, SWT_OBJECT, size, cast(byte)align_, types);
1951 cls = OS.objc_allocateClassPair(cast(objc.Class) OS.class_NSButton, className, 0); 2045 addEventMethods(cls, proc2, proc3, drawRectProc);
1952 OS.class_addIvar(cls, SWT_OBJECT, size, cast(byte)align_, types); 2046 addFrameMethods(cls, setFrameOriginProc, setFrameSizeProc);
1953 OS.class_addMethod(cls, OS.sel_sendSelection, proc2, "@:"); 2047 addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc);
1954 addEventMethods(cls, proc2, proc3, drawRectProc); 2048 OS.objc_registerClassPair(cls);
1955 addFrameMethods(cls, setFrameOriginProc, setFrameSizeProc); 2049
1956 addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc); 2050 className = "SWTProgressIndicator";
1957 OS.objc_registerClassPair(cls); 2051 cls = OS.objc_allocateClassPair(cast(objc.Class) OS.class_NSProgressIndicator, className, 0);
1958 2052 OS.class_addIvar(cls, SWT_OBJECT, size, cast(byte)align_, types);
1959 cls = registerCellSubclass(NSButton.cellClass(), size, align_, types); 2053 addEventMethods(cls, proc2, proc3, drawRectProc);
1960 addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc); 2054 addFrameMethods(cls, setFrameOriginProc, setFrameSizeProc);
1961 NSButton.setCellClass(cls); 2055 addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc);
1962 2056 OS.objc_registerClassPair(cls);
1963 className = "SWTTableView"; 2057
1964 cls = OS.objc_allocateClassPair(cast(objc.Class) OS.class_NSTableView, className, 0); 2058 className = "SWTSlider";
1965 OS.class_addIvar(cls, SWT_OBJECT, size, cast(byte)align_, types); 2059 cls = OS.objc_allocateClassPair(cast(objc.Class) OS.class_NSSlider, className, 0);
1966 OS.class_addMethod(cls, OS.sel_highlightSelectionInClipRect_, highlightSelectionInClipRectProc, "@:{NSRect}"); 2060 OS.class_addIvar(cls, SWT_OBJECT, size, cast(byte)align_, types);
1967 OS.class_addMethod(cls, OS.sel_sendDoubleSelection, proc2, "@:"); 2061 addEventMethods(cls, proc2, proc3, drawRectProc);
1968 OS.class_addMethod(cls, OS.sel_numberOfRowsInTableView_, proc3, "@:@"); 2062 addFrameMethods(cls, setFrameOriginProc, setFrameSizeProc);
1969 OS.class_addMethod(cls, OS.sel_tableView_objectValueForTableColumn_row_, proc5, "@:@:@:@"); 2063 addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc);
1970 OS.class_addMethod(cls, OS.sel_tableView_shouldEditTableColumn_row_, proc5, "@:@:@:@"); 2064 OS.objc_registerClassPair(cls);
1971 OS.class_addMethod(cls, OS.sel_tableViewSelectionDidChange_, proc3, "@:@"); 2065
1972 OS.class_addMethod(cls, OS.sel_tableView_willDisplayCell_forTableColumn_row_, proc6, "@:@@@i"); 2066 cls = registerCellSubclass(NSSlider.cellClass(), size, align_, types);
1973 OS.class_addMethod(cls, OS.sel_tableView_setObjectValue_forTableColumn_row_, proc6, "@:@@@i"); 2067 addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc);
1974 OS.class_addMethod(cls, OS.sel_tableViewColumnDidMove_, proc3, "@:@"); 2068 NSSlider.setCellClass(cls);
1975 OS.class_addMethod(cls, OS.sel_tableViewColumnDidResize_, proc3, "@:@"); 2069
1976 OS.class_addMethod(cls, OS.sel_tableView_didClickTableColumn_, proc4, "@:@"); 2070 className = "SWTPopUpButton";
1977 addEventMethods(cls, proc2, proc3, drawRectProc); 2071 cls = OS.objc_allocateClassPair(cast(objc.Class) OS.class_NSPopUpButton, className, 0);
1978 addFrameMethods(cls, setFrameOriginProc, setFrameSizeProc); 2072 OS.class_addIvar(cls, SWT_OBJECT, size, cast(byte)align_, types);
1979 addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc); 2073 OS.class_addMethod(cls, OS.sel_sendSelection, proc2, "@:");
1980 OS.objc_registerClassPair(cls); 2074 addEventMethods(cls, proc2, proc3, drawRectProc);
1981 2075 addFrameMethods(cls, setFrameOriginProc, setFrameSizeProc);
1982 className = "SWTTableHeaderCell"; 2076 addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc);
1983 cls = OS.objc_allocateClassPair (cast(objc.Class) OS.class_NSTableHeaderCell, className, 0); 2077 OS.objc_registerClassPair(cls);
1984 OS.class_addIvar (cls, SWT_OBJECT, size, cast(byte)align_, types); 2078
1985 OS.class_addMethod (cls, OS.sel_drawInteriorWithFrame_inView_, drawInteriorWithFrameInViewProc, "@:{NSRect}@"); 2079 cls = registerCellSubclass(NSPopUpButton.cellClass(), size, align_, types);
1986 OS.objc_registerClassPair (cls); 2080 addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc);
1987 2081 NSPopUpButton.setCellClass(cls);
1988 className = "SWTBrowserCell"; 2082
1989 cls = OS.objc_allocateClassPair (cast(objc.Class) OS.class_NSBrowserCell, className, 0); 2083 className = "SWTComboBox";
1990 OS.class_addIvar (cls, SWT_OBJECT, size, cast(byte)align_, types); 2084 cls = OS.objc_allocateClassPair(cast(objc.Class) OS.class_NSComboBox, className, 0);
1991 OS.class_addMethod (cls, OS.sel_drawInteriorWithFrame_inView_, drawInteriorWithFrameInViewProc, "@:{NSRect}@"); 2085 OS.class_addIvar(cls, SWT_OBJECT, size, cast(byte)align_, types);
1992 OS.objc_registerClassPair (cls); 2086 OS.class_addMethod(cls, OS.sel_comboBoxSelectionDidChange_, proc3, "@:@");
1993 2087 OS.class_addMethod(cls, OS.sel_sendSelection, proc2, "@:");
1994 className = "SWTTableHeaderView"; 2088 OS.class_addMethod(cls, OS.sel_textDidChange_, proc3, "@:@");
1995 cls = OS.objc_allocateClassPair(cast(objc.Class) OS.class_NSTableHeaderView, className, 0); 2089 OS.class_addMethod(cls, OS.sel_textViewDidChangeSelection_, proc3, "@:@");
1996 OS.class_addIvar(cls, SWT_OBJECT, size, cast(byte)align_, types); 2090 OS.class_addMethod(cls, OS.sel_textView_willChangeSelectionFromCharacterRange_toCharacterRange_, textWillChangeSelectionProc, "@:@{NSRange}{NSRange}");
1997 OS.class_addMethod(cls, OS.sel_mouseDown_, proc3, "@:@"); 2091 addEventMethods(cls, proc2, proc3, drawRectProc);
1998 OS.objc_registerClassPair(cls); 2092 addFrameMethods(cls, setFrameOriginProc, setFrameSizeProc);
1999 2093 addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc);
2000 className = "SWTOutlineView"; 2094 OS.objc_registerClassPair(cls);
2001 cls = OS.objc_allocateClassPair(cast(objc.Class) OS.class_NSOutlineView, className, 0); 2095
2002 OS.class_addIvar(cls, SWT_OBJECT, size, cast(byte)align_, types); 2096 cls = registerCellSubclass(NSComboBox.cellClass(), size, align_, types);
2003 OS.class_addMethod(cls, OS.sel_highlightSelectionInClipRect_, highlightSelectionInClipRectProc, "@:{NSRect}"); 2097 addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc);
2004 OS.class_addMethod(cls, OS.sel_sendDoubleSelection, proc2, "@:"); 2098 NSComboBox.setCellClass(cls);
2005 OS.class_addMethod(cls, OS.sel_outlineViewSelectionDidChange_, proc3, "@:@"); 2099
2006 OS.class_addMethod(cls, OS.sel_outlineViewItemDidExpand_, proc3, "@:@"); 2100 className = "SWTDatePicker";
2007 OS.class_addMethod(cls, OS.sel_outlineView_shouldCollapseItem_, proc4, "@:@@"); 2101 cls = OS.objc_allocateClassPair(cast(objc.Class) OS.class_NSDatePicker, className, 0);
2008 OS.class_addMethod(cls, OS.sel_outlineView_shouldExpandItem_, proc4, "@:@@"); 2102 OS.class_addIvar(cls, SWT_OBJECT, size, cast(byte)align_, types);
2009 OS.class_addMethod(cls, OS.sel_outlineView_child_ofItem_, proc5, "@:@i@"); 2103 OS.class_addMethod(cls, OS.sel_sendSelection, proc2, "@:");
2010 OS.class_addMethod(cls, OS.sel_outlineView_isItemExpandable_, proc4, "@:@@"); 2104 addEventMethods(cls, proc2, proc3, drawRectProc);
2011 OS.class_addMethod(cls, OS.sel_outlineView_numberOfChildrenOfItem_, proc4, "@:@@"); 2105 addFrameMethods(cls, setFrameOriginProc, setFrameSizeProc);
2012 OS.class_addMethod(cls, OS.sel_outlineView_objectValueForTableColumn_byItem_, proc5, "@:@@@"); 2106 addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc);
2013 OS.class_addMethod(cls, OS.sel_outlineView_willDisplayCell_forTableColumn_item_, proc6, "@:@@@@"); 2107 OS.objc_registerClassPair(cls);
2014 OS.class_addMethod(cls, OS.sel_outlineView_setObjectValue_forTableColumn_byItem_, proc6, "@:@@@@"); 2108
2015 OS.class_addMethod(cls, OS.sel_outlineViewColumnDidMove_, proc3, "@:@"); 2109 className = "SWTImageView";
2016 OS.class_addMethod(cls, OS.sel_outlineViewColumnDidResize_, proc3, "@:@"); 2110 cls = OS.objc_allocateClassPair(cast(objc.Class) OS.class_NSImageView, className, 0);
2017 OS.class_addMethod(cls, OS.sel_outlineView_didClickTableColumn_, proc4, "@:@"); 2111 OS.class_addIvar(cls, SWT_OBJECT, size, cast(byte)align_, types);
2018 addEventMethods(cls, proc2, proc3, drawRectProc); 2112 addEventMethods(cls, proc2, proc3, drawRectProc);
2019 addFrameMethods(cls, setFrameOriginProc, setFrameSizeProc); 2113 addFrameMethods(cls, setFrameOriginProc, setFrameSizeProc);
2020 addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc); 2114 addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc);
2021 OS.objc_registerClassPair(cls); 2115 OS.objc_registerClassPair(cls);
2022 2116
2023 className = "SWTTreeItem"; 2117 cls = registerCellSubclass(NSImageView.cellClass(), size, align_, types);
2024 cls = OS.objc_allocateClassPair(cast(objc.Class) OS.class_NSObject, className, 0); 2118 addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc);
2025 OS.class_addIvar(cls, SWT_OBJECT, size, cast(byte)align_, types); 2119 NSImageView.setCellClass(cls);
2026 OS.objc_registerClassPair(cls); 2120
2027 2121 className = "SWTStepper";
2028 className = "SWTTabView"; 2122 cls = OS.objc_allocateClassPair(cast(objc.Class) OS.class_NSStepper, className, 0);
2029 cls = OS.objc_allocateClassPair(cast(objc.Class) OS.class_NSTabView, className, 0); 2123 OS.class_addIvar(cls, SWT_OBJECT, size, cast(byte)align_, types);
2030 OS.class_addIvar(cls, SWT_OBJECT, size, cast(byte)align_, types); 2124 OS.class_addMethod(cls, OS.sel_sendSelection, proc2, "@:");
2031 OS.class_addMethod(cls, OS.sel_tabView_willSelectTabViewItem_, proc4, "@:@@"); 2125 addEventMethods(cls, proc2, proc3, drawRectProc);
2032 OS.class_addMethod(cls, OS.sel_tabView_didSelectTabViewItem_, proc4, "@:@@"); 2126 addFrameMethods(cls, setFrameOriginProc, setFrameSizeProc);
2033 addEventMethods(cls, proc2, proc3, drawRectProc); 2127 addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc);
2034 addFrameMethods(cls, setFrameOriginProc, setFrameSizeProc); 2128 OS.objc_registerClassPair(cls);
2035 addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc); 2129
2036 OS.objc_registerClassPair(cls); 2130 cls = registerCellSubclass(NSStepper.cellClass(), size, align_, types);
2037 2131 addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc);
2038 className = "SWTBox"; 2132 NSStepper.setCellClass(cls);
2039 cls = OS.objc_allocateClassPair(cast(objc.Class) OS.class_NSBox, className, 0); 2133
2040 OS.class_addIvar(cls, SWT_OBJECT, size, cast(byte)align_, types); 2134 className = "SWTScroller";
2041 addEventMethods(cls, proc2, proc3, drawRectProc); 2135 cls = OS.objc_allocateClassPair(cast(objc.Class) OS.class_NSScroller, className, 0);
2042 addFrameMethods(cls, setFrameOriginProc, setFrameSizeProc); 2136 OS.class_addIvar(cls, SWT_OBJECT, size, cast(byte)align_, types);
2043 addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc); 2137 OS.class_addMethod(cls, OS.sel_sendSelection, proc2, "@:");
2044 OS.objc_registerClassPair(cls); 2138 addEventMethods(cls, proc2, proc3, drawRectProc);
2045 2139 addFrameMethods(cls, setFrameOriginProc, setFrameSizeProc);
2046 className = "SWTProgressIndicator"; 2140 addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc);
2047 cls = OS.objc_allocateClassPair(cast(objc.Class) OS.class_NSProgressIndicator, className, 0); 2141 OS.objc_registerClassPair(cls);
2048 OS.class_addIvar(cls, SWT_OBJECT, size, cast(byte)align_, types); 2142
2049 addEventMethods(cls, proc2, proc3, drawRectProc); 2143 className = "SWTMenuItem";
2050 addFrameMethods(cls, setFrameOriginProc, setFrameSizeProc); 2144 cls = OS.objc_allocateClassPair(cast(objc.Class) OS.class_NSMenuItem, className, 0);
2051 addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc); 2145 OS.class_addIvar(cls, SWT_OBJECT, size, cast(byte)align_, types);
2052 OS.objc_registerClassPair(cls); 2146 OS.class_addMethod(cls, OS.sel_sendSelection, proc2, "@:");
2053 2147 OS.objc_registerClassPair(cls);
2054 className = "SWTSlider"; 2148
2055 cls = OS.objc_allocateClassPair(cast(objc.Class) OS.class_NSSlider, className, 0); 2149 className = "SWTTextView";
2056 OS.class_addIvar(cls, SWT_OBJECT, size, cast(byte)align_, types); 2150 cls = OS.objc_allocateClassPair(cast(objc.Class) OS.class_NSTextView, className, 0);
2057 addEventMethods(cls, proc2, proc3, drawRectProc); 2151 OS.class_addIvar(cls, SWT_OBJECT, size, cast(byte)align_, types);
2058 addFrameMethods(cls, setFrameOriginProc, setFrameSizeProc); 2152 addEventMethods(cls, proc2, proc3, drawRectProc);
2059 addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc); 2153 addFrameMethods(cls, setFrameOriginProc, setFrameSizeProc);
2060 OS.objc_registerClassPair(cls); 2154 addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc);
2061 2155 OS.class_addMethod(cls, OS.sel_insertText_, proc3, "@:@");
2062 cls = registerCellSubclass(NSSlider.cellClass(), size, align_, types); 2156 OS.class_addMethod(cls, OS.sel_doCommandBySelector_, proc3, "@::");
2063 addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc); 2157 OS.class_addMethod(cls, OS.sel_textDidChange_, proc3, "@:@");
2064 NSSlider.setCellClass(cls); 2158 OS.class_addMethod(cls, OS.sel_textView_clickedOnLink_atIndex_, proc5, "@:@@@");
2065 2159 OS.objc_registerClassPair(cls);
2066 className = "SWTPopUpButton"; 2160
2067 cls = OS.objc_allocateClassPair(cast(objc.Class) OS.class_NSPopUpButton, className, 0); 2161 className = "SWTEditorView";
2068 OS.class_addIvar(cls, SWT_OBJECT, size, cast(byte)align_, types); 2162 cls = OS.objc_allocateClassPair(cast(objc.Class) OS.class_NSTextView, className, 0);
2069 OS.class_addMethod(cls, OS.sel_sendSelection, proc2, "@:"); 2163 OS.class_addMethod(cls, OS.sel_keyDown_, proc3, "@:@");
2070 addEventMethods(cls, proc2, proc3, drawRectProc); 2164 OS.class_addMethod(cls, OS.sel_keyUp_, proc3, "@:@");
2071 addFrameMethods(cls, setFrameOriginProc, setFrameSizeProc); 2165 OS.class_addMethod(cls, OS.sel_insertText_, proc3, "@:@");
2072 addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc); 2166 OS.class_addMethod(cls, OS.sel_doCommandBySelector_, proc3, "@::");
2073 OS.objc_registerClassPair(cls); 2167 OS.objc_registerClassPair(cls);
2074 2168
2075 cls = registerCellSubclass(NSPopUpButton.cellClass(), size, align_, types); 2169 className = "SWTTextField";
2076 addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc); 2170 cls = OS.objc_allocateClassPair(cast(objc.Class) OS.class_NSTextField, className, 0);
2077 NSPopUpButton.setCellClass(cls); 2171 OS.class_addIvar(cls, SWT_OBJECT, size, cast(byte)align_, types);
2078 2172 addEventMethods(cls, proc2, proc3, drawRectProc);
2079 className = "SWTComboBox"; 2173 addFrameMethods(cls, setFrameOriginProc, setFrameSizeProc);
2080 cls = OS.objc_allocateClassPair(cast(objc.Class) OS.class_NSComboBox, className, 0); 2174 addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc);
2081 OS.class_addIvar(cls, SWT_OBJECT, size, cast(byte)align_, types); 2175 OS.class_addMethod(cls, OS.sel_textDidChange_, proc3, "@:@");
2082 OS.class_addMethod(cls, OS.sel_comboBoxSelectionDidChange_, proc3, "@:@"); 2176 OS.class_addMethod(cls, OS.sel_textViewDidChangeSelection_, proc3, "@:@");
2083 OS.class_addMethod(cls, OS.sel_sendSelection, proc2, "@:"); 2177 OS.class_addMethod(cls, OS.sel_textView_willChangeSelectionFromCharacterRange_toCharacterRange_, textWillChangeSelectionProc, "@:@{NSRange}{NSRange}");
2084 OS.class_addMethod(cls, OS.sel_textDidChange_, proc3, "@:@"); 2178 OS.objc_registerClassPair(cls);
2085 OS.class_addMethod(cls, OS.sel_textViewDidChangeSelection_, proc3, "@:@"); 2179
2086 OS.class_addMethod(cls, OS.sel_textView_willChangeSelectionFromCharacterRange_toCharacterRange_, textWillChangeSelectionProc, "@:@{NSRange}{NSRange}"); 2180 cls = registerCellSubclass(NSTextField.cellClass(), size, align_, types);
2087 addEventMethods(cls, proc2, proc3, drawRectProc); 2181 addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc);
2088 addFrameMethods(cls, setFrameOriginProc, setFrameSizeProc); 2182 NSTextField.setCellClass(cls);
2089 addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc); 2183
2090 OS.objc_registerClassPair(cls); 2184 className = "SWTSearchField";
2091 2185 cls = OS.objc_allocateClassPair(cast(objc.Class) OS.class_NSSearchField, className, 0);
2092 cls = registerCellSubclass(NSComboBox.cellClass(), size, align_, types); 2186 OS.class_addIvar(cls, SWT_OBJECT, size, cast(byte)align_, types);
2093 addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc); 2187 addEventMethods(cls, proc2, proc3, drawRectProc);
2094 NSComboBox.setCellClass(cls); 2188 addFrameMethods(cls, setFrameOriginProc, setFrameSizeProc);
2095 2189 addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc);
2096 className = "SWTDatePicker"; 2190 OS.class_addMethod(cls, OS.sel_textDidChange_, proc3, "@:@");
2097 cls = OS.objc_allocateClassPair(cast(objc.Class) OS.class_NSDatePicker, className, 0); 2191 OS.class_addMethod(cls, OS.sel_textViewDidChangeSelection_, proc3, "@:@");
2098 OS.class_addIvar(cls, SWT_OBJECT, size, cast(byte)align_, types); 2192 OS.class_addMethod(cls, OS.sel_textView_willChangeSelectionFromCharacterRange_toCharacterRange_, textWillChangeSelectionProc, "@:@{NSRange}{NSRange}");
2099 OS.class_addMethod(cls, OS.sel_sendSelection, proc2, "@:"); 2193 OS.objc_registerClassPair(cls);
2100 addEventMethods(cls, proc2, proc3, drawRectProc); 2194
2101 addFrameMethods(cls, setFrameOriginProc, setFrameSizeProc); 2195 cls = registerCellSubclass(NSSearchField.cellClass(), size, align_, types);
2102 addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc); 2196 addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc);
2103 OS.objc_registerClassPair(cls); 2197 NSSearchField.setCellClass(cls);
2104 2198
2105 className = "SWTImageView"; 2199 className = "SWTSecureTextField";
2106 cls = OS.objc_allocateClassPair(cast(objc.Class) OS.class_NSImageView, className, 0); 2200 cls = OS.objc_allocateClassPair(cast(objc.Class) OS.class_NSSecureTextField, className, 0);
2107 OS.class_addIvar(cls, SWT_OBJECT, size, cast(byte)align_, types); 2201 OS.class_addIvar(cls, SWT_OBJECT, size, cast(byte)align_, types);
2108 addEventMethods(cls, proc2, proc3, drawRectProc); 2202 addEventMethods(cls, proc2, proc3, drawRectProc);
2109 addFrameMethods(cls, setFrameOriginProc, setFrameSizeProc); 2203 addFrameMethods(cls, setFrameOriginProc, setFrameSizeProc);
2110 addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc); 2204 addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc);
2111 OS.objc_registerClassPair(cls); 2205 OS.class_addMethod(cls, OS.sel_textDidChange_, proc3, "@:@");
2112 2206 OS.class_addMethod(cls, OS.sel_textViewDidChangeSelection_, proc3, "@:@");
2113 cls = registerCellSubclass(NSImageView.cellClass(), size, align_, types); 2207 OS.class_addMethod(cls, OS.sel_textView_willChangeSelectionFromCharacterRange_toCharacterRange_, textWillChangeSelectionProc, "@:@{NSRange}{NSRange}");
2114 addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc); 2208 OS.objc_registerClassPair(cls);
2115 NSImageView.setCellClass(cls); 2209
2116 2210 // Don't subclass NSSecureTextFieldCell -- you'll get an NSException from [NSSecureTextField setCellClass:]!
2117 className = "SWTStepper"; 2211
2118 cls = OS.objc_allocateClassPair(cast(objc.Class) OS.class_NSStepper, className, 0); 2212 className = "SWTWindow";
2119 OS.class_addIvar(cls, SWT_OBJECT, size, cast(byte)align_, types); 2213 cls = OS.objc_allocateClassPair(cast(objc.Class) OS.class_NSWindow, className, 0);
2120 OS.class_addMethod(cls, OS.sel_sendSelection, proc2, "@:"); 2214 OS.class_addIvar(cls, SWT_OBJECT, size, cast(byte)align_, types);
2121 addEventMethods(cls, proc2, proc3, drawRectProc); 2215 OS.class_addMethod(cls, OS.sel_sendEvent_, proc3, "@:@");
2122 addFrameMethods(cls, setFrameOriginProc, setFrameSizeProc); 2216 OS.class_addMethod(cls, OS.sel_helpRequested_, proc3, "@:@");
2123 addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc); 2217 OS.class_addMethod(cls, OS.sel_canBecomeKeyWindow, proc2, "@:");
2124 OS.objc_registerClassPair(cls); 2218 OS.class_addMethod(cls, OS.sel_makeFirstResponder_, proc3, "@:@");
2125 2219 addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc);
2126 cls = registerCellSubclass(NSStepper.cellClass(), size, align_, types); 2220 OS.objc_registerClassPair(cls);
2127 addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc); 2221 }
2128 NSStepper.setCellClass(cls); 2222
2129 2223 /**
2130 className = "SWTScroller"; 2224 * Invokes platform specific functionality to allocate a new GC handle.
2131 cls = OS.objc_allocateClassPair(cast(objc.Class) OS.class_NSScroller, className, 0); 2225 * <p>
2132 OS.class_addIvar(cls, SWT_OBJECT, size, cast(byte)align_, types); 2226 * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
2133 OS.class_addMethod(cls, OS.sel_sendSelection, proc2, "@:"); 2227 * API for <code>Display</code>. It is marked public only so that it
2134 addEventMethods(cls, proc2, proc3, drawRectProc); 2228 * can be shared within the packages provided by DWT. It is not
2135 addFrameMethods(cls, setFrameOriginProc, setFrameSizeProc); 2229 * available on all platforms, and should never be called from
2136 addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc); 2230 * application code.
2137 OS.objc_registerClassPair(cls); 2231 * </p>
2138 2232 *
2139 className = "SWTMenuItem"; 2233 * @param data the platform specific GC data
2140 cls = OS.objc_allocateClassPair(cast(objc.Class) OS.class_NSMenuItem, className, 0); 2234 * @return the platform specific GC handle
2141 OS.class_addIvar(cls, SWT_OBJECT, size, cast(byte)align_, types); 2235 *
2142 OS.class_addMethod(cls, OS.sel_sendSelection, proc2, "@:"); 2236 * @exception DWTException <ul>
2143 OS.objc_registerClassPair(cls); 2237 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
2144 2238 * </ul>
2145 className = "SWTTextView"; 2239 * @exception DWTError <ul>
2146 cls = OS.objc_allocateClassPair(cast(objc.Class) OS.class_NSTextView, className, 0); 2240 * <li>ERROR_NO_HANDLES if a handle could not be obtained for gc creation</li>
2147 OS.class_addIvar(cls, SWT_OBJECT, size, cast(byte)align_, types); 2241 * </ul>
2148 addEventMethods(cls, proc2, proc3, drawRectProc); 2242 */
2149 addFrameMethods(cls, setFrameOriginProc, setFrameSizeProc); 2243 public objc.id internal_new_GC (GCData data) {
2150 addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc); 2244 if (isDisposed()) DWT.error(DWT.ERROR_DEVICE_DISPOSED);
2151 OS.class_addMethod(cls, OS.sel_insertText_, proc3, "@:@"); 2245 if (screenWindow is null) {
2152 OS.class_addMethod(cls, OS.sel_doCommandBySelector_, proc3, "@::"); 2246 NSWindow window = cast(NSWindow) (new NSWindow ()).alloc ();
2153 OS.class_addMethod(cls, OS.sel_textDidChange_, proc3, "@:@"); 2247 NSRect rect = NSRect();
2154 OS.class_addMethod(cls, OS.sel_textView_clickedOnLink_atIndex_, proc5, "@:@@@"); 2248 window = window.initWithContentRect(rect, OS.NSBorderlessWindowMask, OS.NSBackingStoreBuffered, false);
2155 OS.objc_registerClassPair(cls); 2249 window.setReleasedWhenClosed(false);
2156 2250 screenWindow = window;
2157 className = "SWTEditorView"; 2251 }
2158 cls = OS.objc_allocateClassPair(cast(objc.Class) OS.class_NSTextView, className, 0); 2252 NSGraphicsContext context = screenWindow.graphicsContext();
2159 OS.class_addMethod(cls, OS.sel_keyDown_, proc3, "@:@"); 2253 // NSAffineTransform transform = NSAffineTransform.transform();
2160 OS.class_addMethod(cls, OS.sel_keyUp_, proc3, "@:@"); 2254 // NSSize size = handle.size();
2161 OS.class_addMethod(cls, OS.sel_insertText_, proc3, "@:@"); 2255 // transform.translateXBy(0, size.height);
2162 OS.class_addMethod(cls, OS.sel_doCommandBySelector_, proc3, "@::"); 2256 // transform.scaleXBy(1, -1);
2163 OS.objc_registerClassPair(cls); 2257 // transform.set();
2164 2258 if (data !is null) {
2165 className = "SWTTextField"; 2259 int mask = DWT.LEFT_TO_RIGHT | DWT.RIGHT_TO_LEFT;
2166 cls = OS.objc_allocateClassPair(cast(objc.Class) OS.class_NSTextField, className, 0); 2260 if ((data.style & mask) is 0) {
2167 OS.class_addIvar(cls, SWT_OBJECT, size, cast(byte)align_, types); 2261 data.style |= DWT.LEFT_TO_RIGHT;
2168 addEventMethods(cls, proc2, proc3, drawRectProc); 2262 }
2169 addFrameMethods(cls, setFrameOriginProc, setFrameSizeProc); 2263 data.device = this;
2170 addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc); 2264 data.background = getSystemColor(DWT.COLOR_WHITE).handle;
2171 OS.class_addMethod(cls, OS.sel_textDidChange_, proc3, "@:@"); 2265 data.foreground = getSystemColor(DWT.COLOR_BLACK).handle;
2172 OS.class_addMethod(cls, OS.sel_textViewDidChangeSelection_, proc3, "@:@"); 2266 data.font = getSystemFont();
2173 OS.class_addMethod(cls, OS.sel_textView_willChangeSelectionFromCharacterRange_toCharacterRange_, textWillChangeSelectionProc, "@:@{NSRange}{NSRange}"); 2267 }
2174 OS.objc_registerClassPair(cls); 2268 return context.id;
2175 2269 }
2176 cls = registerCellSubclass(NSTextField.cellClass(), size, align_, types); 2270
2177 addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc); 2271 /**
2178 NSTextField.setCellClass(cls); 2272 * Invokes platform specific functionality to dispose a GC handle.
2179 2273 * <p>
2180 className = "SWTSearchField"; 2274 * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
2181 cls = OS.objc_allocateClassPair(cast(objc.Class) OS.class_NSSearchField, className, 0); 2275 * API for <code>Display</code>. It is marked public only so that it
2182 OS.class_addIvar(cls, SWT_OBJECT, size, cast(byte)align_, types); 2276 * can be shared within the packages provided by DWT. It is not
2183 addEventMethods(cls, proc2, proc3, drawRectProc); 2277 * available on all platforms, and should never be called from
2184 addFrameMethods(cls, setFrameOriginProc, setFrameSizeProc); 2278 * application code.
2185 addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc); 2279 * </p>
2186 OS.class_addMethod(cls, OS.sel_textDidChange_, proc3, "@:@"); 2280 *
2187 OS.class_addMethod(cls, OS.sel_textViewDidChangeSelection_, proc3, "@:@"); 2281 * @param hDC the platform specific GC handle
2188 OS.class_addMethod(cls, OS.sel_textView_willChangeSelectionFromCharacterRange_toCharacterRange_, textWillChangeSelectionProc, "@:@{NSRange}{NSRange}"); 2282 * @param data the platform specific GC data
2189 OS.objc_registerClassPair(cls); 2283 */
2190 2284 public void internal_dispose_GC (objc.id context, GCData data) {
2191 cls = registerCellSubclass(NSSearchField.cellClass(), size, align_, types); 2285 if (isDisposed()) DWT.error(DWT.ERROR_DEVICE_DISPOSED);
2192 addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc); 2286
2193 NSSearchField.setCellClass(cls); 2287 }
2194 2288
2195 className = "SWTSecureTextField"; 2289 static bool isValidClass (ClassInfo clazz) {
2196 cls = OS.objc_allocateClassPair(cast(objc.Class) OS.class_NSSecureTextField, className, 0); 2290 String name = clazz.name;
2197 OS.class_addIvar(cls, SWT_OBJECT, size, cast(byte)align_, types); 2291 int index = name.lastIndexOf ('.');
2198 addEventMethods(cls, proc2, proc3, drawRectProc); 2292 name = name[0 .. index];
2199 addFrameMethods(cls, setFrameOriginProc, setFrameSizeProc); 2293 index = name.lastIndexOf ('.');
2200 addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc); 2294 return name.substring (0, index + 1).equals (PACKAGE_PREFIX);
2201 OS.class_addMethod(cls, OS.sel_textDidChange_, proc3, "@:@"); 2295 }
2202 OS.class_addMethod(cls, OS.sel_textViewDidChangeSelection_, proc3, "@:@"); 2296
2203 OS.class_addMethod(cls, OS.sel_textView_willChangeSelectionFromCharacterRange_toCharacterRange_, textWillChangeSelectionProc, "@:@{NSRange}{NSRange}"); 2297 bool isValidThread () {
2204 OS.objc_registerClassPair(cls); 2298 return thread is Thread.getThis ();
2205 2299 }
2206 // Don't subclass NSSecureTextFieldCell -- you'll get an NSException from [NSSecureTextField setCellClass:]! 2300
2207 2301 /**
2208 className = "SWTWindow"; 2302 * Generate a low level system event.
2209 cls = OS.objc_allocateClassPair(cast(objc.Class) OS.class_NSWindow, className, 0); 2303 *
2210 OS.class_addIvar(cls, SWT_OBJECT, size, cast(byte)align_, types); 2304 * <code>post</code> is used to generate low level keyboard
2211 OS.class_addMethod(cls, OS.sel_sendEvent_, proc3, "@:@"); 2305 * and mouse events. The intent is to enable automated UI
2212 OS.class_addMethod(cls, OS.sel_helpRequested_, proc3, "@:@"); 2306 * testing by simulating the input from the user. Most
2213 OS.class_addMethod(cls, OS.sel_canBecomeKeyWindow, proc2, "@:"); 2307 * DWT applications should never need to call this method.
2214 OS.class_addMethod(cls, OS.sel_makeFirstResponder_, proc3, "@:@"); 2308 * <p>
2215 addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc); 2309 * Note that this operation can fail when the operating system
2216 OS.objc_registerClassPair(cls); 2310 * fails to generate the event for any reason. For example,
2217 } 2311 * this can happen when there is no such key or mouse button
2218 2312 * or when the system event queue is full.
2219 /** 2313 * </p>
2220 * Invokes platform specific functionality to allocate a new GC handle. 2314 * <p>
2221 * <p> 2315 * <b>Event Types:</b>
2222 * <b>IMPORTANT:</b> This method is <em>not</em> part of the public 2316 * <p>KeyDown, KeyUp
2223 * API for <code>Display</code>. It is marked public only so that it 2317 * <p>The following fields in the <code>Event</code> apply:
2224 * can be shared within the packages provided by DWT. It is not 2318 * <ul>
2225 * available on all platforms, and should never be called from 2319 * <li>(in) type KeyDown or KeyUp</li>
2226 * application code. 2320 * <p> Either one of:
2227 * </p> 2321 * <li>(in) character a character that corresponds to a keyboard key</li>
2228 * 2322 * <li>(in) keyCode the key code of the key that was typed,
2229 * @param data the platform specific GC data 2323 * as defined by the key code constants in class <code>DWT</code></li>
2230 * @return the platform specific GC handle 2324 * </ul>
2231 * 2325 * <p>MouseDown, MouseUp</p>
2232 * @exception DWTException <ul> 2326 * <p>The following fields in the <code>Event</code> apply:
2233 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> 2327 * <ul>
2234 * </ul> 2328 * <li>(in) type MouseDown or MouseUp
2235 * @exception DWTError <ul> 2329 * <li>(in) button the button that is pressed or released
2236 * <li>ERROR_NO_HANDLES if a handle could not be obtained for gc creation</li> 2330 * </ul>
2237 * </ul> 2331 * <p>MouseMove</p>
2238 */ 2332 * <p>The following fields in the <code>Event</code> apply:
2239 public objc.id internal_new_GC (GCData data) { 2333 * <ul>
2240 if (isDisposed()) DWT.error(DWT.ERROR_DEVICE_DISPOSED); 2334 * <li>(in) type MouseMove
2241 if (screenWindow is null) { 2335 * <li>(in) x the x coordinate to move the mouse pointer to in screen coordinates
2242 NSWindow window = cast(NSWindow) (new NSWindow ()).alloc (); 2336 * <li>(in) y the y coordinate to move the mouse pointer to in screen coordinates
2243 NSRect rect = NSRect(); 2337 * </ul>
2244 window = window.initWithContentRect(rect, OS.NSBorderlessWindowMask, OS.NSBackingStoreBuffered, false); 2338 * </dl>
2245 window.setReleasedWhenClosed(false); 2339 *
2246 screenWindow = window; 2340 * @param event the event to be generated
2247 } 2341 *
2248 NSGraphicsContext context = screenWindow.graphicsContext(); 2342 * @return true if the event was generated or false otherwise
2249 // NSAffineTransform transform = NSAffineTransform.transform(); 2343 *
2250 // NSSize size = handle.size(); 2344 * @exception IllegalArgumentException <ul>
2251 // transform.translateXBy(0, size.height); 2345 * <li>ERROR_NULL_ARGUMENT - if the event is null</li>
2252 // transform.scaleXBy(1, -1); 2346 * </ul>
2253 // transform.set(); 2347 * @exception DWTException <ul>
2254 if (data !is null) { 2348 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
2255 int mask = DWT.LEFT_TO_RIGHT | DWT.RIGHT_TO_LEFT; 2349 * </ul>
2256 if ((data.style & mask) is 0) { 2350 *
2257 data.style |= DWT.LEFT_TO_RIGHT; 2351 * @since 3.0
2258 } 2352 *
2259 data.device = this; 2353 */
2260 data.background = getSystemColor(DWT.COLOR_WHITE).handle; 2354 public bool post(Event event) {
2261 data.foreground = getSystemColor(DWT.COLOR_BLACK).handle; 2355 synchronized (Device.classinfo) {
2262 data.font = getSystemFont(); 2356 if (isDisposed ()) error (DWT.ERROR_DEVICE_DISPOSED);
2263 } 2357 if (event is null) error (DWT.ERROR_NULL_ARGUMENT);
2264 return context.id; 2358 // int type = event.type;
2265 } 2359 // switch (type) {
2266 2360 // case DWT.KeyDown:
2267 /** 2361 // case DWT.KeyUp: {
2268 * Invokes platform specific functionality to dispose a GC handle. 2362 // int vKey = Display.untranslateKey (event.keyCode);
2269 * <p> 2363 // if (vKey !is 0) {
2270 * <b>IMPORTANT:</b> This method is <em>not</em> part of the public 2364 // return OS.CGPostKeyboardEvent (0, vKey, type is DWT.KeyDown) is 0;
2271 * API for <code>Display</code>. It is marked public only so that it 2365 // } else {
2272 * can be shared within the packages provided by DWT. It is not 2366 // vKey = -1;
2273 * available on all platforms, and should never be called from 2367 // int kchrPtr = OS.GetScriptManagerVariable (cast(short) OS.smKCHRCache);
2274 * application code. 2368 // int key = -1;
2275 * </p> 2369 // int [] state = new int [1];
2276 * 2370 // int [] encoding = new int [1];
2277 * @param hDC the platform specific GC handle 2371 // short keyScript = cast(short) OS.GetScriptManagerVariable (cast(short) OS.smKeyScript);
2278 * @param data the platform specific GC data 2372 // short regionCode = cast(short) OS.GetScriptManagerVariable (cast(short) OS.smRegionCode);
2279 */ 2373 // if (OS.UpgradeScriptInfoToTextEncoding (keyScript, cast(short) OS.kTextLanguageDontCare, regionCode, null, encoding) is OS.paramErr) {
2280 public void internal_dispose_GC (objc.id context, GCData data) { 2374 // if (OS.UpgradeScriptInfoToTextEncoding (keyScript, cast(short) OS.kTextLanguageDontCare, cast(short) OS.kTextRegionDontCare, null, encoding) is OS.paramErr) {
2281 if (isDisposed()) DWT.error(DWT.ERROR_DEVICE_DISPOSED); 2375 // encoding [0] = OS.kTextEncodingMacRoman;
2282 2376 // }
2283 } 2377 // }
2284 2378 // int [] encodingInfo = new int [1];
2285 static bool isValidClass (ClassInfo clazz) { 2379 // OS.CreateUnicodeToTextInfoByEncoding (encoding [0], encodingInfo);
2286 String name = clazz.name; 2380 // if (encodingInfo [0] !is 0) {
2287 int index = name.lastIndexOf ('.'); 2381 // char [] input = {event.character};
2288 name = name[0 .. index]; 2382 // byte [] buffer = new byte [2];
2289 index = name.lastIndexOf ('.'); 2383 // OS.ConvertFromUnicodeToPString (encodingInfo [0], 2, input, buffer);
2290 return name.substring (0, index + 1).equals (PACKAGE_PREFIX); 2384 // OS.DisposeUnicodeToTextInfo (encodingInfo);
2291 } 2385 // key = buffer [1] & 0x7f;
2292 2386 // }
2293 bool isValidThread () { 2387 // if (key is -1) return false;
2294 return thread is Thread.getThis (); 2388 // for (int i = 0 ; i <= 0x7F ; i++) {
2295 } 2389 // int result1 = OS.KeyTranslate (kchrPtr, cast(short) (i | 512), state);
2296 2390 // int result2 = OS.KeyTranslate (kchrPtr, cast(short) i, state);
2297 /** 2391 // if ((result1 & 0x7f) is key || (result2 & 0x7f) is key) {
2298 * Generate a low level system event. 2392 // vKey = i;
2299 * 2393 // break;
2300 * <code>post</code> is used to generate low level keyboard 2394 // }
2301 * and mouse events. The intent is to enable automated UI 2395 // }
2302 * testing by simulating the input from the user. Most 2396 // if (vKey is -1) return false;
2303 * DWT applications should never need to call this method. 2397 // return OS.CGPostKeyboardEvent (key, vKey, type is DWT.KeyDown) is 0;
2304 * <p> 2398 // }
2305 * Note that this operation can fail when the operating system 2399 // }
2306 * fails to generate the event for any reason. For example, 2400 // case DWT.MouseDown:
2307 * this can happen when there is no such key or mouse button 2401 // case DWT.MouseMove:
2308 * or when the system event queue is full. 2402 // case DWT.MouseUp: {
2309 * </p> 2403 // CGPoint mouseCursorPosition = new CGPoint ();
2310 * <p> 2404 // int chord = OS.GetCurrentEventButtonState ();
2311 * <b>Event Types:</b> 2405 // if (type is DWT.MouseMove) {
2312 * <p>KeyDown, KeyUp 2406 // mouseCursorPosition.x = event.x;
2313 * <p>The following fields in the <code>Event</code> apply: 2407 // mouseCursorPosition.y = event.y;
2314 * <ul> 2408 // return OS.CGPostMouseEvent (mouseCursorPosition, true, 5, (chord & 0x1) !is 0, (chord & 0x2) !is 0, (chord & 0x4) !is 0, (chord & 0x8) !is 0, (chord & 0x10) !is 0) is 0;
2315 * <li>(in) type KeyDown or KeyUp</li> 2409 // } else {
2316 * <p> Either one of: 2410 // int button = event.button;
2317 * <li>(in) character a character that corresponds to a keyboard key</li> 2411 // if (button < 1 || button > 5) return false;
2318 * <li>(in) keyCode the key code of the key that was typed, 2412 // bool button1 = false, button2 = false, button3 = false, button4 = false, button5 = false;
2319 * as defined by the key code constants in class <code>DWT</code></li> 2413 // switch (button) {
2320 * </ul> 2414 // case 1: {
2321 * <p>MouseDown, MouseUp</p> 2415 // button1 = type is DWT.MouseDown;
2322 * <p>The following fields in the <code>Event</code> apply: 2416 // button2 = (chord & 0x4) !is 0;
2323 * <ul> 2417 // button3 = (chord & 0x2) !is 0;
2324 * <li>(in) type MouseDown or MouseUp 2418 // button4 = (chord & 0x8) !is 0;
2325 * <li>(in) button the button that is pressed or released 2419 // button5 = (chord & 0x10) !is 0;
2326 * </ul> 2420 // break;
2327 * <p>MouseMove</p> 2421 // }
2328 * <p>The following fields in the <code>Event</code> apply: 2422 // case 2: {
2329 * <ul> 2423 // button1 = (chord & 0x1) !is 0;
2330 * <li>(in) type MouseMove 2424 // button2 = type is DWT.MouseDown;
2331 * <li>(in) x the x coordinate to move the mouse pointer to in screen coordinates 2425 // button3 = (chord & 0x2) !is 0;
2332 * <li>(in) y the y coordinate to move the mouse pointer to in screen coordinates 2426 // button4 = (chord & 0x8) !is 0;
2333 * </ul> 2427 // button5 = (chord & 0x10) !is 0;
2334 * </dl> 2428 // break;
2335 * 2429 // }
2336 * @param event the event to be generated 2430 // case 3: {
2337 * 2431 // button1 = (chord & 0x1) !is 0;
2338 * @return true if the event was generated or false otherwise 2432 // button2 = (chord & 0x4) !is 0;
2339 * 2433 // button3 = type is DWT.MouseDown;
2340 * @exception IllegalArgumentException <ul> 2434 // button4 = (chord & 0x8) !is 0;
2341 * <li>ERROR_NULL_ARGUMENT - if the event is null</li> 2435 // button5 = (chord & 0x10) !is 0;
2342 * </ul> 2436 // break;
2343 * @exception DWTException <ul> 2437 // }
2344 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> 2438 // case 4: {
2345 * </ul> 2439 // button1 = (chord & 0x1) !is 0;
2346 * 2440 // button2 = (chord & 0x4) !is 0;
2347 * @since 3.0 2441 // button3 = (chord & 0x2) !is 0;
2348 * 2442 // button4 = type is DWT.MouseDown;
2349 */ 2443 // button5 = (chord & 0x10) !is 0;
2350 public bool post(Event event) { 2444 // break;
2351 synchronized (Device.classinfo) { 2445 // }
2352 if (isDisposed ()) error (DWT.ERROR_DEVICE_DISPOSED); 2446 // case 5: {
2353 if (event is null) error (DWT.ERROR_NULL_ARGUMENT); 2447 // button1 = (chord & 0x1) !is 0;
2354 // int type = event.type; 2448 // button2 = (chord & 0x4) !is 0;
2355 // switch (type) { 2449 // button3 = (chord & 0x2) !is 0;
2356 // case DWT.KeyDown: 2450 // button4 = (chord & 0x8) !is 0;
2357 // case DWT.KeyUp: { 2451 // button5 = type is DWT.MouseDown;
2358 // int vKey = Display.untranslateKey (event.keyCode); 2452 // break;
2359 // if (vKey !is 0) { 2453 // }
2360 // return OS.CGPostKeyboardEvent (0, vKey, type is DWT.KeyDown) is 0; 2454 // }
2361 // } else { 2455 // dwt.internal.carbon.Point pt = new dwt.internal.carbon.Point ();
2362 // vKey = -1; 2456 // OS.GetGlobalMouse (pt);
2363 // int kchrPtr = OS.GetScriptManagerVariable (cast(short) OS.smKCHRCache); 2457 // mouseCursorPosition.x = pt.h;
2364 // int key = -1; 2458 // mouseCursorPosition.y = pt.v;
2365 // int [] state = new int [1]; 2459 // return OS.CGPostMouseEvent (mouseCursorPosition, true, 5, button1, button3, button2, button4, button5) is 0;
2366 // int [] encoding = new int [1]; 2460 // }
2367 // short keyScript = cast(short) OS.GetScriptManagerVariable (cast(short) OS.smKeyScript); 2461 // }
2368 // short regionCode = cast(short) OS.GetScriptManagerVariable (cast(short) OS.smRegionCode); 2462 // case DWT.MouseWheel: {
2369 // if (OS.UpgradeScriptInfoToTextEncoding (keyScript, cast(short) OS.kTextLanguageDontCare, regionCode, null, encoding) is OS.paramErr) { 2463 // return OS.CGPostScrollWheelEvent (1, event.count) is 0;
2370 // if (OS.UpgradeScriptInfoToTextEncoding (keyScript, cast(short) OS.kTextLanguageDontCare, cast(short) OS.kTextRegionDontCare, null, encoding) is OS.paramErr) { 2464 // }
2371 // encoding [0] = OS.kTextEncodingMacRoman; 2465 // }
2372 // } 2466 return false;
2373 // } 2467 }
2374 // int [] encodingInfo = new int [1]; 2468 }
2375 // OS.CreateUnicodeToTextInfoByEncoding (encoding [0], encodingInfo); 2469
2376 // if (encodingInfo [0] !is 0) { 2470 void postEvent (Event event) {
2377 // char [] input = {event.character}; 2471 /*
2378 // byte [] buffer = new byte [2]; 2472 * Place the event at the end of the event queue.
2379 // OS.ConvertFromUnicodeToPString (encodingInfo [0], 2, input, buffer); 2473 * This code is always called in the Display's
2380 // OS.DisposeUnicodeToTextInfo (encodingInfo); 2474 * thread so it must be re-enterant but does not
2381 // key = buffer [1] & 0x7f; 2475 * need to be synchronized.
2382 // } 2476 */
2383 // if (key is -1) return false; 2477 if (eventQueue is null) eventQueue = new Event [4];
2384 // for (int i = 0 ; i <= 0x7F ; i++) { 2478 int index = 0;
2385 // int result1 = OS.KeyTranslate (kchrPtr, cast(short) (i | 512), state); 2479 int length = eventQueue.length;
2386 // int result2 = OS.KeyTranslate (kchrPtr, cast(short) i, state); 2480 while (index < length) {
2387 // if ((result1 & 0x7f) is key || (result2 & 0x7f) is key) { 2481 if (eventQueue [index] is null) break;
2388 // vKey = i; 2482 index++;
2389 // break; 2483 }
2390 // } 2484 if (index is length) {
2391 // } 2485 Event [] newQueue = new Event [length + 4];
2392 // if (vKey is -1) return false; 2486 System.arraycopy (eventQueue, 0, newQueue, 0, length);
2393 // return OS.CGPostKeyboardEvent (key, vKey, type is DWT.KeyDown) is 0; 2487 eventQueue = newQueue;
2394 // } 2488 }
2395 // } 2489 eventQueue [index] = event;
2396 // case DWT.MouseDown: 2490 }
2397 // case DWT.MouseMove: 2491
2398 // case DWT.MouseUp: { 2492 /**
2399 // CGPoint mouseCursorPosition = new CGPoint (); 2493 * Maps a point from one coordinate system to another.
2400 // int chord = OS.GetCurrentEventButtonState (); 2494 * When the control is null, coordinates are mapped to
2401 // if (type is DWT.MouseMove) { 2495 * the display.
2402 // mouseCursorPosition.x = event.x; 2496 * <p>
2403 // mouseCursorPosition.y = event.y; 2497 * NOTE: On right-to-left platforms where the coordinate
2404 // return OS.CGPostMouseEvent (mouseCursorPosition, true, 5, (chord & 0x1) !is 0, (chord & 0x2) !is 0, (chord & 0x4) !is 0, (chord & 0x8) !is 0, (chord & 0x10) !is 0) is 0; 2498 * systems are mirrored, special care needs to be taken
2405 // } else { 2499 * when mapping coordinates from one control to another
2406 // int button = event.button; 2500 * to ensure the result is correctly mirrored.
2407 // if (button < 1 || button > 5) return false; 2501 *
2408 // bool button1 = false, button2 = false, button3 = false, button4 = false, button5 = false; 2502 * Mapping a point that is the origin of a rectangle and
2409 // switch (button) { 2503 * then adding the width and height is not equivalent to
2410 // case 1: { 2504 * mapping the rectangle. When one control is mirrored
2411 // button1 = type is DWT.MouseDown; 2505 * and the other is not, adding the width and height to a
2412 // button2 = (chord & 0x4) !is 0; 2506 * point that was mapped causes the rectangle to extend
2413 // button3 = (chord & 0x2) !is 0; 2507 * in the wrong direction. Mapping the entire rectangle
2414 // button4 = (chord & 0x8) !is 0; 2508 * instead of just one point causes both the origin and
2415 // button5 = (chord & 0x10) !is 0; 2509 * the corner of the rectangle to be mapped.
2416 // break; 2510 * </p>
2417 // } 2511 *
2418 // case 2: { 2512 * @param from the source <code>Control</code> or <code>null</code>
2419 // button1 = (chord & 0x1) !is 0; 2513 * @param to the destination <code>Control</code> or <code>null</code>
2420 // button2 = type is DWT.MouseDown; 2514 * @param point to be mapped
2421 // button3 = (chord & 0x2) !is 0; 2515 * @return point with mapped coordinates
2422 // button4 = (chord & 0x8) !is 0; 2516 *
2423 // button5 = (chord & 0x10) !is 0; 2517 * @exception IllegalArgumentException <ul>
2424 // break; 2518 * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
2425 // } 2519 * <li>ERROR_INVALID_ARGUMENT - if the Control from or the Control to have been disposed</li>
2426 // case 3: { 2520 * </ul>
2427 // button1 = (chord & 0x1) !is 0; 2521 * @exception DWTException <ul>
2428 // button2 = (chord & 0x4) !is 0; 2522 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
2429 // button3 = type is DWT.MouseDown; 2523 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
2430 // button4 = (chord & 0x8) !is 0; 2524 * </ul>
2431 // button5 = (chord & 0x10) !is 0; 2525 *
2432 // break; 2526 * @since 2.1.2
2433 // } 2527 */
2434 // case 4: { 2528 public Point map (Control from, Control to, Point point) {
2435 // button1 = (chord & 0x1) !is 0; 2529 checkDevice ();
2436 // button2 = (chord & 0x4) !is 0; 2530 if (point is null) error (DWT.ERROR_NULL_ARGUMENT);
2437 // button3 = (chord & 0x2) !is 0; 2531 return map (from, to, point.x, point.y);
2438 // button4 = type is DWT.MouseDown; 2532 }
2439 // button5 = (chord & 0x10) !is 0; 2533
2440 // break; 2534 /**
2441 // } 2535 * Maps a point from one coordinate system to another.
2442 // case 5: { 2536 * When the control is null, coordinates are mapped to
2443 // button1 = (chord & 0x1) !is 0; 2537 * the display.
2444 // button2 = (chord & 0x4) !is 0; 2538 * <p>
2445 // button3 = (chord & 0x2) !is 0; 2539 * NOTE: On right-to-left platforms where the coordinate
2446 // button4 = (chord & 0x8) !is 0; 2540 * systems are mirrored, special care needs to be taken
2447 // button5 = type is DWT.MouseDown; 2541 * when mapping coordinates from one control to another
2448 // break; 2542 * to ensure the result is correctly mirrored.
2449 // } 2543 *
2450 // } 2544 * Mapping a point that is the origin of a rectangle and
2451 // dwt.internal.carbon.Point pt = new dwt.internal.carbon.Point (); 2545 * then adding the width and height is not equivalent to
2452 // OS.GetGlobalMouse (pt); 2546 * mapping the rectangle. When one control is mirrored
2453 // mouseCursorPosition.x = pt.h; 2547 * and the other is not, adding the width and height to a
2454 // mouseCursorPosition.y = pt.v; 2548 * point that was mapped causes the rectangle to extend
2455 // return OS.CGPostMouseEvent (mouseCursorPosition, true, 5, button1, button3, button2, button4, button5) is 0; 2549 * in the wrong direction. Mapping the entire rectangle
2456 // } 2550 * instead of just one point causes both the origin and
2457 // } 2551 * the corner of the rectangle to be mapped.
2458 // case DWT.MouseWheel: { 2552 * </p>
2459 // return OS.CGPostScrollWheelEvent (1, event.count) is 0; 2553 *
2460 // } 2554 * @param from the source <code>Control</code> or <code>null</code>
2461 // } 2555 * @param to the destination <code>Control</code> or <code>null</code>
2556 * @param x coordinates to be mapped
2557 * @param y coordinates to be mapped
2558 * @return point with mapped coordinates
2559 *
2560 * @exception IllegalArgumentException <ul>
2561 * <li>ERROR_INVALID_ARGUMENT - if the Control from or the Control to have been disposed</li>
2562 * </ul>
2563 * @exception DWTException <ul>
2564 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
2565 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
2566 * </ul>
2567 *
2568 * @since 2.1.2
2569 */
2570 public Point map (Control from, Control to, int x, int y) {
2571 checkDevice ();
2572 if (from !is null && from.isDisposed()) error (DWT.ERROR_INVALID_ARGUMENT);
2573 if (to !is null && to.isDisposed()) error (DWT.ERROR_INVALID_ARGUMENT);
2574 Point point = new Point (x, y);
2575 if (from is to) return point;
2576 NSPoint pt = NSPoint();
2577 pt.x = x;
2578 pt.y = y;
2579 NSWindow fromWindow = from !is null ? from.view.window() : null;
2580 NSWindow toWindow = to !is null ? to.view.window() : null;
2581 if (toWindow !is null && fromWindow !is null && toWindow.id is fromWindow.id) {
2582 pt = from.view.convertPoint_toView_(pt, to.view);
2583 } else {
2584 NSRect primaryFrame = getPrimaryFrame();
2585 if (from !is null) {
2586 NSView view = from.contentView ();
2587 pt = view.convertPoint_toView_(pt, null);
2588 pt = fromWindow.convertBaseToScreen(pt);
2589 pt.y = primaryFrame.height - pt.y;
2590 }
2591 if (to !is null) {
2592 NSView view = to.contentView ();
2593 pt.y = primaryFrame.height - pt.y;
2594 pt = toWindow.convertScreenToBase(pt);
2595 pt = view.convertPoint_fromView_(pt, null);
2596 }
2597 }
2598 point.x = cast(int)pt.x;
2599 point.y = cast(int)pt.y;
2600 return point;
2601 }
2602
2603 /**
2604 * Maps a point from one coordinate system to another.
2605 * When the control is null, coordinates are mapped to
2606 * the display.
2607 * <p>
2608 * NOTE: On right-to-left platforms where the coordinate
2609 * systems are mirrored, special care needs to be taken
2610 * when mapping coordinates from one control to another
2611 * to ensure the result is correctly mirrored.
2612 *
2613 * Mapping a point that is the origin of a rectangle and
2614 * then adding the width and height is not equivalent to
2615 * mapping the rectangle. When one control is mirrored
2616 * and the other is not, adding the width and height to a
2617 * point that was mapped causes the rectangle to extend
2618 * in the wrong direction. Mapping the entire rectangle
2619 * instead of just one point causes both the origin and
2620 * the corner of the rectangle to be mapped.
2621 * </p>
2622 *
2623 * @param from the source <code>Control</code> or <code>null</code>
2624 * @param to the destination <code>Control</code> or <code>null</code>
2625 * @param rectangle to be mapped
2626 * @return rectangle with mapped coordinates
2627 *
2628 * @exception IllegalArgumentException <ul>
2629 * <li>ERROR_NULL_ARGUMENT - if the rectangle is null</li>
2630 * <li>ERROR_INVALID_ARGUMENT - if the Control from or the Control to have been disposed</li>
2631 * </ul>
2632 * @exception DWTException <ul>
2633 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
2634 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
2635 * </ul>
2636 *
2637 * @since 2.1.2
2638 */
2639 public Rectangle map (Control from, Control to, Rectangle rectangle) {
2640 checkDevice ();
2641 if (rectangle is null) error (DWT.ERROR_NULL_ARGUMENT);
2642 return map (from, to, rectangle.x, rectangle.y, rectangle.width, rectangle.height);
2643 }
2644
2645 /**
2646 * Maps a point from one coordinate system to another.
2647 * When the control is null, coordinates are mapped to
2648 * the display.
2649 * <p>
2650 * NOTE: On right-to-left platforms where the coordinate
2651 * systems are mirrored, special care needs to be taken
2652 * when mapping coordinates from one control to another
2653 * to ensure the result is correctly mirrored.
2654 *
2655 * Mapping a point that is the origin of a rectangle and
2656 * then adding the width and height is not equivalent to
2657 * mapping the rectangle. When one control is mirrored
2658 * and the other is not, adding the width and height to a
2659 * point that was mapped causes the rectangle to extend
2660 * in the wrong direction. Mapping the entire rectangle
2661 * instead of just one point causes both the origin and
2662 * the corner of the rectangle to be mapped.
2663 * </p>
2664 *
2665 * @param from the source <code>Control</code> or <code>null</code>
2666 * @param to the destination <code>Control</code> or <code>null</code>
2667 * @param x coordinates to be mapped
2668 * @param y coordinates to be mapped
2669 * @param width coordinates to be mapped
2670 * @param height coordinates to be mapped
2671 * @return rectangle with mapped coordinates
2672 *
2673 * @exception IllegalArgumentException <ul>
2674 * <li>ERROR_INVALID_ARGUMENT - if the Control from or the Control to have been disposed</li>
2675 * </ul>
2676 * @exception DWTException <ul>
2677 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
2678 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
2679 * </ul>
2680 *
2681 * @since 2.1.2
2682 */
2683 public Rectangle map (Control from, Control to, int x, int y, int width, int height) {
2684 checkDevice ();
2685 if (from !is null && from.isDisposed()) error (DWT.ERROR_INVALID_ARGUMENT);
2686 if (to !is null && to.isDisposed()) error (DWT.ERROR_INVALID_ARGUMENT);
2687 Rectangle rectangle = new Rectangle (x, y, width, height);
2688 if (from is to) return rectangle;
2689 NSPoint pt = NSPoint();
2690 pt.x = x;
2691 pt.y = y;
2692 NSWindow fromWindow = from !is null ? from.view.window() : null;
2693 NSWindow toWindow = to !is null ? to.view.window() : null;
2694 if (toWindow !is null && fromWindow !is null && toWindow.id is fromWindow.id) {
2695 pt = from.view.convertPoint_toView_(pt, to.view);
2696 } else {
2697 NSRect primaryFrame = getPrimaryFrame();
2698 if (from !is null) {
2699 NSView view = from.contentView ();
2700 pt = view.convertPoint_toView_(pt, null);
2701 pt = fromWindow.convertBaseToScreen(pt);
2702 pt.y = primaryFrame.height - pt.y;
2703 }
2704 if (to !is null) {
2705 NSView view = to.contentView ();
2706 pt.y = primaryFrame.height - pt.y;
2707 pt = toWindow.convertScreenToBase(pt);
2708 pt = view.convertPoint_fromView_(pt, null);
2709 }
2710 }
2711 rectangle.x = cast(int)pt.x;
2712 rectangle.y = cast(int)pt.y;
2713 return rectangle;
2714 }
2715
2716 /**
2717 * Reads an event from the operating system's event queue,
2718 * dispatches it appropriately, and returns <code>true</code>
2719 * if there is potentially more work to do, or <code>false</code>
2720 * if the caller can sleep until another event is placed on
2721 * the event queue.
2722 * <p>
2723 * In addition to checking the system event queue, this method also
2724 * checks if any inter-thread messages (created by <code>syncExec()</code>
2725 * or <code>asyncExec()</code>) are waiting to be processed, and if
2726 * so handles them before returning.
2727 * </p>
2728 *
2729 * @return <code>false</code> if the caller can sleep upon return from this method
2730 *
2731 * @exception DWTException <ul>
2732 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
2733 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
2734 * <li>ERROR_FAILED_EXEC - if an exception occurred while running an inter-thread message</li>
2735 * </ul>
2736 *
2737 * @see #sleep
2738 * @see #wake
2739 */
2740 public bool readAndDispatch () {
2741 checkDevice ();
2742 if (loopCounter is 0) {
2743 pool.release();
2744 pool = cast(NSAutoreleasePool)(new NSAutoreleasePool()).alloc().init();
2745 }
2746 loopCounter ++;
2747 bool events = false;
2748 events |= runTimers ();
2749 events |= runContexts ();
2750 events |= runPopups ();
2751 NSEvent event = application.nextEventMatchingMask(0, null, OS.NSDefaultRunLoopMode, true);
2752
2753 try {
2754 if (event !is null) {
2755 events = true;
2756 application.sendEvent(event);
2757 }
2758 // NSEvent event = NSEvent.otherEventWithType(OS.NSApplicationDefined, NSPoint(), 0, 0, 0, null, SWT_IDLE_TYPE, 0, 0);
2759 // application.postEvent(event, false);
2760 // idle = true;
2761 // application.run();
2762 // events |= !idle;
2763 if (events) {
2764 runDeferredEvents ();
2765 return true;
2766 }
2767 return runAsyncMessages (false);
2768 } finally {
2769 loopCounter --;
2770 }
2771
2772 }
2773
2774 static void register (Display display) {
2775 synchronized (Device.classinfo) {
2776 for (int i=0; i<Displays.length; i++) {
2777 if (Displays [i] is null) {
2778 Displays [i] = display;
2779 return;
2780 }
2781 }
2782 Display [] newDisplays = new Display [Displays.length + 4];
2783 System.arraycopy (Displays, 0, newDisplays, 0, Displays.length);
2784 newDisplays [Displays.length] = display;
2785 Displays = newDisplays;
2786 }
2787 }
2788
2789 /**
2790 * Releases any internal resources back to the operating
2791 * system and clears all fields except the device handle.
2792 * <p>
2793 * Disposes all shells which are currently open on the display.
2794 * After this method has been invoked, all related related shells
2795 * will answer <code>true</code> when sent the message
2796 * <code>isDisposed()</code>.
2797 * </p><p>
2798 * When a device is destroyed, resources that were acquired
2799 * on behalf of the programmer need to be returned to the
2800 * operating system. For example, if the device allocated a
2801 * font to be used as the system font, this font would be
2802 * freed in <code>release</code>. Also,to assist the garbage
2803 * collector and minimize the amount of memory that is not
2804 * reclaimed when the programmer keeps a reference to a
2805 * disposed device, all fields except the handle are zero'd.
2806 * The handle is needed by <code>destroy</code>.
2807 * </p>
2808 * This method is called before <code>destroy</code>.
2809 *
2810 * @see Device#dispose
2811 * @see #destroy
2812 */
2813 protected void release () {
2814 disposing = true;
2815 sendEvent (DWT.Dispose, new Event ());
2816 Shell [] shells = getShells ();
2817 for (int i=0; i<shells.length; i++) {
2818 Shell shell = shells [i];
2819 if (!shell.isDisposed ()) shell.dispose ();
2820 }
2821 if (tray !is null) tray.dispose ();
2822 tray = null;
2823 while (readAndDispatch ()) {}
2824 if (disposeList !is null) {
2825 for (int i=0; i<disposeList.length; i++) {
2826 if (disposeList [i] !is null) disposeList [i].run ();
2827 }
2828 }
2829 disposeList = null;
2830 synchronizer.releaseSynchronizer ();
2831 synchronizer = null;
2832 releaseDisplay ();
2833 super.release ();
2834 }
2835
2836 void releaseDisplay () {
2837 /* Release the System Images */
2838 if (errorImage !is null) errorImage.dispose ();
2839 if (infoImage !is null) infoImage.dispose ();
2840 if (warningImage !is null) warningImage.dispose ();
2841 errorImage = infoImage = warningImage = null;
2842
2843 currentCaret = null;
2844
2845 /* Release Timers */
2846 if (hoverTimer !is null) timerExec(-1, hoverTimer);
2847 hoverTimer = null;
2848 if (caretTimer !is null) timerExec(-1, caretTimer);
2849 caretTimer = null;
2850 if (nsTimers !is null) {
2851 for (int i=0; i<nsTimers.length; i++) {
2852 if (nsTimers [i] !is null) {
2853 nsTimers [i].invalidate();
2854 nsTimers [i].release();
2855 }
2856 }
2857 }
2858 nsTimers = null;
2859 if (timerDelegate !is null) timerDelegate.release();
2860 timerDelegate = null;
2861
2862 /* Release the System Cursors */
2863 for (int i = 0; i < cursors.length; i++) {
2864 if (cursors [i] !is null) cursors [i].dispose ();
2865 }
2866 cursors = null;
2867
2868 /* Release Dock image */
2869 if (dockImage !is null) dockImage.release();
2870 dockImage = null;
2871
2872 if (screenWindow !is null) screenWindow.release();
2873 screenWindow = null;
2874
2875 modalShells = null;
2876 menuBar = null;
2877 menus = null;
2878
2879 if (markedAttributes !is null) markedAttributes.release();
2880 markedAttributes = null;
2881
2882 /* The release pool needs to be released before the call backs. */
2883 if (pool !is null) pool.release();
2884 pool = null;
2885
2886 if (application !is null && applicationClass !is null) {
2887 OS.object_setClass (application.id, applicationClass);
2888 }
2889 application = null;
2890 applicationClass = null;
2891 }
2892
2893 void removeContext (NSGraphicsContext context) {
2894 if (contexts is null) return;
2895 int count = 0;
2896 for (int i = 0; i < contexts.length; i++) {
2897 if (contexts[i] !is null) {
2898 if (contexts [i].id is context.id) {
2899 contexts[i] = null;
2900 } else {
2901 count++;
2902 }
2903 }
2904 }
2905 if (count is 0) contexts = null;
2906 }
2907
2908 /**
2909 * Removes the listener from the collection of listeners who will
2910 * be notified when an event of the given type occurs anywhere in
2911 * a widget. The event type is one of the event constants defined
2912 * in class <code>DWT</code>.
2913 *
2914 * @param eventType the type of event to listen for
2915 * @param listener the listener which should no longer be notified when the event occurs
2916 *
2917 * @exception IllegalArgumentException <ul>
2918 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
2919 * </ul>
2920 * @exception DWTException <ul>
2921 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
2922 * </ul>
2923 *
2924 * @see Listener
2925 * @see DWT
2926 * @see #addFilter
2927 * @see #addListener
2928 *
2929 * @since 3.0
2930 */
2931 public void removeFilter (int eventType, Listener listener) {
2932 checkDevice ();
2933 if (listener is null) error (DWT.ERROR_NULL_ARGUMENT);
2934 if (filterTable is null) return;
2935 filterTable.unhook (eventType, listener);
2936 if (filterTable.size () is 0) filterTable = null;
2937 }
2938
2939 /**
2940 * Removes the listener from the collection of listeners who will
2941 * be notified when an event of the given type occurs. The event type
2942 * is one of the event constants defined in class <code>DWT</code>.
2943 *
2944 * @param eventType the type of event to listen for
2945 * @param listener the listener which should no longer be notified
2946 *
2947 * @exception IllegalArgumentException <ul>
2948 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
2949 * </ul>
2950 * @exception DWTException <ul>
2951 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
2952 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
2953 * </ul>
2954 *
2955 * @see Listener
2956 * @see DWT
2957 * @see #addListener
2958 *
2959 * @since 2.0
2960 */
2961 public void removeListener (int eventType, Listener listener) {
2962 checkDevice ();
2963 if (listener is null) error (DWT.ERROR_NULL_ARGUMENT);
2964 if (eventTable is null) return;
2965 eventTable.unhook (eventType, listener);
2966 }
2967
2968 Widget removeWidget (NSObject view) {
2969 if (view is null) return null;
2970 void* jniRef;
2971 OS.object_getInstanceVariable(view.id, SWT_OBJECT, jniRef);
2972 if (jniRef is null) return null;
2973 Widget widget = cast(Widget)OS.JNIGetObject(jniRef);
2974 OS.object_setInstanceVariable(view.id, SWT_OBJECT, null);
2975 return widget;
2976 }
2977
2978 void removeMenu (Menu menu) {
2979 if (menus is null) return;
2980 for (int i = 0; i < menus.length; i++) {
2981 if (menus [i] is menu) {
2982 menus[i] = null;
2983 break;
2984 }
2985 }
2986 }
2987
2988 void removePopup (Menu menu) {
2989 if (popups is null) return;
2990 for (int i=0; i<popups.length; i++) {
2991 if (popups [i] is menu) {
2992 popups [i] = null;
2993 return;
2994 }
2995 }
2996 }
2997
2998 bool runAsyncMessages (bool all) {
2999 return synchronizer.runAsyncMessages (all);
3000 }
3001
3002 bool runContexts () {
3003 if (contexts !is null) {
3004 for (int i = 0; i < contexts.length; i++) {
3005 if (contexts[i] !is null) contexts[i].flushGraphics();
3006 }
3007 }
2462 return false; 3008 return false;
2463 } 3009 }
2464 } 3010
2465 3011 bool runDeferredEvents () {
2466 void postEvent (Event event) { 3012 /*
2467 /* 3013 * Run deferred events. This code is always
2468 * Place the event at the end of the event queue. 3014 * called in the Display's thread so it must
2469 * This code is always called in the Display's 3015 * be re-enterant need not be synchronized.
2470 * thread so it must be re-enterant but does not 3016 */
2471 * need to be synchronized. 3017 while (eventQueue !is null) {
2472 */ 3018
2473 if (eventQueue is null) eventQueue = new Event [4]; 3019 /* Take an event off the queue */
2474 int index = 0; 3020 Event event = eventQueue [0];
2475 int length = eventQueue.length; 3021 if (event is null) break;
2476 while (index < length) { 3022 int length_ = eventQueue.length;
2477 if (eventQueue [index] is null) break; 3023 System.arraycopy (eventQueue, 1, eventQueue, 0, --length_);
2478 index++; 3024 eventQueue [length_] = null;
2479 } 3025
2480 if (index is length) { 3026 /* Run the event */
2481 Event [] newQueue = new Event [length + 4]; 3027 Widget widget = event.widget;
2482 System.arraycopy (eventQueue, 0, newQueue, 0, length); 3028 if (widget !is null && !widget.isDisposed ()) {
2483 eventQueue = newQueue; 3029 Widget item = event.item;
2484 } 3030 if (item is null || !item.isDisposed ()) {
2485 eventQueue [index] = event; 3031 widget.notifyListeners (event.type, event);
2486 } 3032 }
2487 3033 }
2488 /** 3034
2489 * Maps a point from one coordinate system to another. 3035 /*
2490 * When the control is null, coordinates are mapped to 3036 * At this point, the event queue could
2491 * the display. 3037 * be null due to a recursive invokation
2492 * <p> 3038 * when running the event.
2493 * NOTE: On right-to-left platforms where the coordinate 3039 */
2494 * systems are mirrored, special care needs to be taken 3040 }
2495 * when mapping coordinates from one control to another 3041
2496 * to ensure the result is correctly mirrored. 3042 /* Clear the queue */
2497 * 3043 eventQueue = null;
2498 * Mapping a point that is the origin of a rectangle and 3044 return true;
2499 * then adding the width and height is not equivalent to 3045 }
2500 * mapping the rectangle. When one control is mirrored 3046
2501 * and the other is not, adding the width and height to a 3047 bool runPopups () {
2502 * point that was mapped causes the rectangle to extend 3048 if (popups is null) return false;
2503 * in the wrong direction. Mapping the entire rectangle 3049 bool result = false;
2504 * instead of just one point causes both the origin and 3050 while (popups !is null) {
2505 * the corner of the rectangle to be mapped. 3051 Menu menu = popups [0];
2506 * </p> 3052 if (menu is null) break;
2507 * 3053 int length_ = popups.length;
2508 * @param from the source <code>Control</code> or <code>null</code> 3054 System.arraycopy (popups, 1, popups, 0, --length_);
2509 * @param to the destination <code>Control</code> or <code>null</code> 3055 popups [length_] = null;
2510 * @param point to be mapped 3056 // clearMenuFlags ();
2511 * @return point with mapped coordinates
2512 *
2513 * @exception IllegalArgumentException <ul>
2514 * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
2515 * <li>ERROR_INVALID_ARGUMENT - if the Control from or the Control to have been disposed</li>
2516 * </ul>
2517 * @exception DWTException <ul>
2518 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
2519 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
2520 * </ul>
2521 *
2522 * @since 2.1.2
2523 */
2524 public Point map (Control from, Control to, Point point) {
2525 checkDevice ();
2526 if (point is null) error (DWT.ERROR_NULL_ARGUMENT);
2527 return map (from, to, point.x, point.y);
2528 }
2529
2530 /**
2531 * Maps a point from one coordinate system to another.
2532 * When the control is null, coordinates are mapped to
2533 * the display.
2534 * <p>
2535 * NOTE: On right-to-left platforms where the coordinate
2536 * systems are mirrored, special care needs to be taken
2537 * when mapping coordinates from one control to another
2538 * to ensure the result is correctly mirrored.
2539 *
2540 * Mapping a point that is the origin of a rectangle and
2541 * then adding the width and height is not equivalent to
2542 * mapping the rectangle. When one control is mirrored
2543 * and the other is not, adding the width and height to a
2544 * point that was mapped causes the rectangle to extend
2545 * in the wrong direction. Mapping the entire rectangle
2546 * instead of just one point causes both the origin and
2547 * the corner of the rectangle to be mapped.
2548 * </p>
2549 *
2550 * @param from the source <code>Control</code> or <code>null</code>
2551 * @param to the destination <code>Control</code> or <code>null</code>
2552 * @param x coordinates to be mapped
2553 * @param y coordinates to be mapped
2554 * @return point with mapped coordinates
2555 *
2556 * @exception IllegalArgumentException <ul>
2557 * <li>ERROR_INVALID_ARGUMENT - if the Control from or the Control to have been disposed</li>
2558 * </ul>
2559 * @exception DWTException <ul>
2560 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
2561 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
2562 * </ul>
2563 *
2564 * @since 2.1.2
2565 */
2566 public Point map (Control from, Control to, int x, int y) {
2567 checkDevice ();
2568 if (from !is null && from.isDisposed()) error (DWT.ERROR_INVALID_ARGUMENT);
2569 if (to !is null && to.isDisposed()) error (DWT.ERROR_INVALID_ARGUMENT);
2570 Point point = new Point (x, y);
2571 if (from is to) return point;
2572 NSPoint pt = NSPoint();
2573 pt.x = x;
2574 pt.y = y;
2575 NSWindow fromWindow = from !is null ? from.view.window() : null;
2576 NSWindow toWindow = to !is null ? to.view.window() : null;
2577 if (toWindow !is null && fromWindow !is null && toWindow.id is fromWindow.id) {
2578 pt = from.view.convertPoint_toView_(pt, to.view);
2579 } else {
2580 NSRect primaryFrame = getPrimaryFrame();
2581 if (from !is null) {
2582 NSView view = from.contentView ();
2583 pt = view.convertPoint_toView_(pt, null);
2584 pt = fromWindow.convertBaseToScreen(pt);
2585 pt.y = primaryFrame.height - pt.y;
2586 }
2587 if (to !is null) {
2588 NSView view = to.contentView ();
2589 pt.y = primaryFrame.height - pt.y;
2590 pt = toWindow.convertScreenToBase(pt);
2591 pt = view.convertPoint_fromView_(pt, null);
2592 }
2593 }
2594 point.x = cast(int)pt.x;
2595 point.y = cast(int)pt.y;
2596 return point;
2597 }
2598
2599 /**
2600 * Maps a point from one coordinate system to another.
2601 * When the control is null, coordinates are mapped to
2602 * the display.
2603 * <p>
2604 * NOTE: On right-to-left platforms where the coordinate
2605 * systems are mirrored, special care needs to be taken
2606 * when mapping coordinates from one control to another
2607 * to ensure the result is correctly mirrored.
2608 *
2609 * Mapping a point that is the origin of a rectangle and
2610 * then adding the width and height is not equivalent to
2611 * mapping the rectangle. When one control is mirrored
2612 * and the other is not, adding the width and height to a
2613 * point that was mapped causes the rectangle to extend
2614 * in the wrong direction. Mapping the entire rectangle
2615 * instead of just one point causes both the origin and
2616 * the corner of the rectangle to be mapped.
2617 * </p>
2618 *
2619 * @param from the source <code>Control</code> or <code>null</code>
2620 * @param to the destination <code>Control</code> or <code>null</code>
2621 * @param rectangle to be mapped
2622 * @return rectangle with mapped coordinates
2623 *
2624 * @exception IllegalArgumentException <ul>
2625 * <li>ERROR_NULL_ARGUMENT - if the rectangle is null</li>
2626 * <li>ERROR_INVALID_ARGUMENT - if the Control from or the Control to have been disposed</li>
2627 * </ul>
2628 * @exception DWTException <ul>
2629 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
2630 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
2631 * </ul>
2632 *
2633 * @since 2.1.2
2634 */
2635 public Rectangle map (Control from, Control to, Rectangle rectangle) {
2636 checkDevice ();
2637 if (rectangle is null) error (DWT.ERROR_NULL_ARGUMENT);
2638 return map (from, to, rectangle.x, rectangle.y, rectangle.width, rectangle.height);
2639 }
2640
2641 /**
2642 * Maps a point from one coordinate system to another.
2643 * When the control is null, coordinates are mapped to
2644 * the display.
2645 * <p>
2646 * NOTE: On right-to-left platforms where the coordinate
2647 * systems are mirrored, special care needs to be taken
2648 * when mapping coordinates from one control to another
2649 * to ensure the result is correctly mirrored.
2650 *
2651 * Mapping a point that is the origin of a rectangle and
2652 * then adding the width and height is not equivalent to
2653 * mapping the rectangle. When one control is mirrored
2654 * and the other is not, adding the width and height to a
2655 * point that was mapped causes the rectangle to extend
2656 * in the wrong direction. Mapping the entire rectangle
2657 * instead of just one point causes both the origin and
2658 * the corner of the rectangle to be mapped.
2659 * </p>
2660 *
2661 * @param from the source <code>Control</code> or <code>null</code>
2662 * @param to the destination <code>Control</code> or <code>null</code>
2663 * @param x coordinates to be mapped
2664 * @param y coordinates to be mapped
2665 * @param width coordinates to be mapped
2666 * @param height coordinates to be mapped
2667 * @return rectangle with mapped coordinates
2668 *
2669 * @exception IllegalArgumentException <ul>
2670 * <li>ERROR_INVALID_ARGUMENT - if the Control from or the Control to have been disposed</li>
2671 * </ul>
2672 * @exception DWTException <ul>
2673 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
2674 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
2675 * </ul>
2676 *
2677 * @since 2.1.2
2678 */
2679 public Rectangle map (Control from, Control to, int x, int y, int width, int height) {
2680 checkDevice ();
2681 if (from !is null && from.isDisposed()) error (DWT.ERROR_INVALID_ARGUMENT);
2682 if (to !is null && to.isDisposed()) error (DWT.ERROR_INVALID_ARGUMENT);
2683 Rectangle rectangle = new Rectangle (x, y, width, height);
2684 if (from is to) return rectangle;
2685 NSPoint pt = NSPoint();
2686 pt.x = x;
2687 pt.y = y;
2688 NSWindow fromWindow = from !is null ? from.view.window() : null;
2689 NSWindow toWindow = to !is null ? to.view.window() : null;
2690 if (toWindow !is null && fromWindow !is null && toWindow.id is fromWindow.id) {
2691 pt = from.view.convertPoint_toView_(pt, to.view);
2692 } else {
2693 NSRect primaryFrame = getPrimaryFrame();
2694 if (from !is null) {
2695 NSView view = from.contentView ();
2696 pt = view.convertPoint_toView_(pt, null);
2697 pt = fromWindow.convertBaseToScreen(pt);
2698 pt.y = primaryFrame.height - pt.y;
2699 }
2700 if (to !is null) {
2701 NSView view = to.contentView ();
2702 pt.y = primaryFrame.height - pt.y;
2703 pt = toWindow.convertScreenToBase(pt);
2704 pt = view.convertPoint_fromView_(pt, null);
2705 }
2706 }
2707 rectangle.x = cast(int)pt.x;
2708 rectangle.y = cast(int)pt.y;
2709 return rectangle;
2710 }
2711
2712 /**
2713 * Reads an event from the operating system's event queue,
2714 * dispatches it appropriately, and returns <code>true</code>
2715 * if there is potentially more work to do, or <code>false</code>
2716 * if the caller can sleep until another event is placed on
2717 * the event queue.
2718 * <p>
2719 * In addition to checking the system event queue, this method also
2720 * checks if any inter-thread messages (created by <code>syncExec()</code>
2721 * or <code>asyncExec()</code>) are waiting to be processed, and if
2722 * so handles them before returning.
2723 * </p>
2724 *
2725 * @return <code>false</code> if the caller can sleep upon return from this method
2726 *
2727 * @exception DWTException <ul>
2728 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
2729 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
2730 * <li>ERROR_FAILED_EXEC - if an exception occurred while running an inter-thread message</li>
2731 * </ul>
2732 *
2733 * @see #sleep
2734 * @see #wake
2735 */
2736 public bool readAndDispatch () {
2737 checkDevice ();
2738 if (loopCounter is 0) {
2739 pool.release();
2740 pool = cast(NSAutoreleasePool)(new NSAutoreleasePool()).alloc().init();
2741 }
2742 loopCounter ++;
2743 bool events = false;
2744 events |= runTimers ();
2745 events |= runContexts ();
2746 events |= runPopups ();
2747 NSEvent event = application.nextEventMatchingMask(0, null, OS.NSDefaultRunLoopMode, true);
2748
2749 try {
2750 if (event !is null) {
2751 events = true;
2752 application.sendEvent(event);
2753 }
2754 // NSEvent event = NSEvent.otherEventWithType(OS.NSApplicationDefined, NSPoint(), 0, 0, 0, null, SWT_IDLE_TYPE, 0, 0);
2755 // application.postEvent(event, false);
2756 // idle = true;
2757 // application.run();
2758 // events |= !idle;
2759 if (events) {
2760 runDeferredEvents (); 3057 runDeferredEvents ();
2761 return true; 3058 if (!menu.isDisposed ()) menu._setVisible (true);
2762 } 3059 // clearMenuFlags ();
2763 return runAsyncMessages (false); 3060 result = true;
2764 } finally { 3061 }
2765 loopCounter --; 3062 popups = null;
2766 } 3063 return result;
2767 3064 }
2768 } 3065
2769 3066 bool runTimers () {
2770 static void register (Display display) { 3067 if (timerList is null) return false;
2771 synchronized (Device.classinfo) { 3068 bool result = false;
2772 for (int i=0; i<Displays.length; i++) { 3069 for (int i=0; i<timerList.length; i++) {
2773 if (Displays [i] is null) { 3070 if (nsTimers [i] is null && timerList [i] !is null) {
2774 Displays [i] = display; 3071 Runnable runnable = timerList [i];
3072 timerList [i] = null;
3073 if (runnable !is null) {
3074 result = true;
3075 runnable.run ();
3076 }
3077 }
3078 }
3079 return result;
3080 }
3081
3082 void sendEvent (int eventType, Event event) {
3083 if (eventTable is null && filterTable is null) {
3084 return;
3085 }
3086 if (event is null) event = new Event ();
3087 event.display = this;
3088 event.type = eventType;
3089 if (event.time is 0) event.time = getLastEventTime ();
3090 if (!filterEvent (event)) {
3091 if (eventTable !is null) eventTable.sendEvent (event);
3092 }
3093 }
3094
3095 /**
3096 * On platforms which support it, sets the application name
3097 * to be the argument. On Motif, for example, this can be used
3098 * to set the name used for resource lookup. Specifying
3099 * <code>null</code> for the name clears it.
3100 *
3101 * @param name the new app name or <code>null</code>
3102 */
3103 public static void setAppName (String name) {
3104 APP_NAME = name;
3105 }
3106
3107 //TODO use custom timer instead of timerExec
3108 Runnable hoverTimer;
3109
3110 //TODO - use custom timer instead of timerExec
3111 Runnable caretTimer;
3112
3113 void setCurrentCaret (Caret caret) {
3114 // if (caretID !is 0) OS.RemoveEventLoopTimer (caretID);
3115 // caretID = 0;
3116 currentCaret = caret;
3117 if (currentCaret !is null) {
3118 int blinkRate = currentCaret.blinkRate;
3119 timerExec (blinkRate, caretTimer);
3120 }
3121 }
3122
3123 void setCursor (Control control) {
3124 Cursor cursor = null;
3125 if (control !is null) cursor = control.findCursor ();
3126 if (cursor is null) cursor = getSystemCursor (DWT.CURSOR_ARROW);
3127 cursor.handle.set ();
3128 }
3129
3130 /**
3131 * Sets the location of the on-screen pointer relative to the top left corner
3132 * of the screen. <b>Note: It is typically considered bad practice for a
3133 * program to move the on-screen pointer location.</b>
3134 *
3135 * @param x the new x coordinate for the cursor
3136 * @param y the new y coordinate for the cursor
3137 *
3138 * @exception DWTException <ul>
3139 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
3140 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
3141 * </ul>
3142 *
3143 * @since 2.1
3144 */
3145 public void setCursorLocation (int x, int y) {
3146 checkDevice ();
3147 CGPoint pt = CGPoint ();
3148 pt.x = x; pt.y = y;
3149 OS.CGWarpMouseCursorPosition (pt);
3150 }
3151
3152 /**
3153 * Sets the location of the on-screen pointer relative to the top left corner
3154 * of the screen. <b>Note: It is typically considered bad practice for a
3155 * program to move the on-screen pointer location.</b>
3156 *
3157 * @param point new position
3158 *
3159 * @exception DWTException <ul>
3160 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
3161 * <li>ERROR_NULL_ARGUMENT - if the point is null
3162 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
3163 * </ul>
3164 *
3165 * @since 2.0
3166 */
3167 public void setCursorLocation (Point point) {
3168 checkDevice ();
3169 if (point is null) error (DWT.ERROR_NULL_ARGUMENT);
3170 setCursorLocation (point.x, point.y);
3171 }
3172
3173 /**
3174 * Sets the application defined property of the receiver
3175 * with the specified name to the given argument.
3176 * <p>
3177 * Applications may have associated arbitrary objects with the
3178 * receiver in this fashion. If the objects stored in the
3179 * properties need to be notified when the display is disposed
3180 * of, it is the application's responsibility provide a
3181 * <code>disposeExec()</code> handler which does so.
3182 * </p>
3183 *
3184 * @param key the name of the property
3185 * @param value the new value for the property
3186 *
3187 * @exception IllegalArgumentException <ul>
3188 * <li>ERROR_NULL_ARGUMENT - if the key is null</li>
3189 * </ul>
3190 * @exception DWTException <ul>
3191 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
3192 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
3193 * </ul>
3194 *
3195 * @see #getData(String)
3196 * @see #disposeExec(Runnable)
3197 */
3198 public void setData (String key, Object value) {
3199 checkDevice ();
3200 //if (key is null) error (DWT.ERROR_NULL_ARGUMENT);
3201
3202 if (key.equals (ADD_WIDGET_KEY)) {
3203 auto wrap = cast(ArrayWrapperObject) value;
3204
3205 if (wrap is null)
3206 DWT.error(DWT.ERROR_INVALID_ARGUMENT, null, " []");
3207
3208 Object [] data = wrap.array;
3209 NSObject object = cast(NSObject)data [0];
3210 Widget widget = cast(Widget)data [1];
3211 if (widget is null) {
3212 removeWidget (object);
3213 } else {
3214 addWidget (object, widget);
3215 }
3216 }
3217
3218 /* Remove the key/value pair */
3219 if (value is null) {
3220 if (keys is null) return;
3221 int index = 0;
3222 while (index < keys.length && !keys [index].equals (key)) index++;
3223 if (index is keys.length) return;
3224 if (keys.length is 1) {
3225 keys = null;
3226 values = null;
3227 } else {
3228 String [] newKeys = new String [keys.length - 1];
3229 Object [] newValues = new Object [values.length - 1];
3230 System.arraycopy (keys, 0, newKeys, 0, index);
3231 System.arraycopy (keys, index + 1, newKeys, index, newKeys.length - index);
3232 System.arraycopy (values, 0, newValues, 0, index);
3233 System.arraycopy (values, index + 1, newValues, index, newValues.length - index);
3234 keys = newKeys;
3235 values = newValues;
3236 }
3237 return;
3238 }
3239
3240 /* Add the key/value pair */
3241 if (keys is null) {
3242 keys = [key];
3243 values = [value];
3244 return;
3245 }
3246 for (int i=0; i<keys.length; i++) {
3247 if (keys [i].equals (key)) {
3248 values [i] = value;
2775 return; 3249 return;
2776 } 3250 }
2777 } 3251 }
2778 Display [] newDisplays = new Display [Displays.length + 4]; 3252 String [] newKeys = new String [keys.length + 1];
2779 System.arraycopy (Displays, 0, newDisplays, 0, Displays.length); 3253 Object [] newValues = new Object [values.length + 1];
2780 newDisplays [Displays.length] = display; 3254 System.arraycopy (keys, 0, newKeys, 0, keys.length);
2781 Displays = newDisplays; 3255 System.arraycopy (values, 0, newValues, 0, values.length);
2782 } 3256 newKeys [keys.length] = key;
2783 } 3257 newValues [values.length] = value;
2784 3258 keys = newKeys;
2785 /** 3259 values = newValues;
2786 * Releases any internal resources back to the operating 3260 }
2787 * system and clears all fields except the device handle. 3261
2788 * <p> 3262 void setMenuBar (Menu menu) {
2789 * Disposes all shells which are currently open on the display. 3263 if (menu is menuBar) return;
2790 * After this method has been invoked, all related related shells 3264 menuBar = menu;
2791 * will answer <code>true</code> when sent the message 3265 //remove all existing menu items except the application menu
2792 * <code>isDisposed()</code>. 3266 NSMenu menubar = application.mainMenu();
2793 * </p><p> 3267 NSInteger count = menubar.numberOfItems();
2794 * When a device is destroyed, resources that were acquired 3268 while (count > 1) {
2795 * on behalf of the programmer need to be returned to the 3269 menubar.removeItemAtIndex(count - 1);
2796 * operating system. For example, if the device allocated a 3270 count--;
2797 * font to be used as the system font, this font would be 3271 }
2798 * freed in <code>release</code>. Also,to assist the garbage 3272 //set parent of each item to NULL and add them to menubar
2799 * collector and minimize the amount of memory that is not 3273 if (menu !is null) {
2800 * reclaimed when the programmer keeps a reference to a 3274 MenuItem[] items = menu.getItems();
2801 * disposed device, all fields except the handle are zero'd. 3275 for (int i = 0; i < items.length; i++) {
2802 * The handle is needed by <code>destroy</code>. 3276 items[i].nsItem.setMenu(null);
2803 * </p> 3277 menubar.addItem(items[i].nsItem);
2804 * This method is called before <code>destroy</code>. 3278 }
2805 * 3279 }
2806 * @see Device#dispose 3280 }
2807 * @see #destroy 3281
2808 */ 3282 void setModalShell (Shell shell) {
2809 protected void release () { 3283 if (modalShells is null) modalShells = new Shell [4];
2810 disposing = true; 3284 int index = 0, length = modalShells.length;
2811 sendEvent (DWT.Dispose, new Event ()); 3285 while (index < length) {
2812 Shell [] shells = getShells (); 3286 if (modalShells [index] is shell) return;
2813 for (int i=0; i<shells.length; i++) { 3287 if (modalShells [index] is null) break;
2814 Shell shell = shells [i]; 3288 index++;
2815 if (!shell.isDisposed ()) shell.dispose (); 3289 }
2816 } 3290 if (index is length) {
2817 if (tray !is null) tray.dispose (); 3291 Shell [] newModalShells = new Shell [length + 4];
2818 tray = null; 3292 System.arraycopy (modalShells, 0, newModalShells, 0, length);
2819 while (readAndDispatch ()) {} 3293 modalShells = newModalShells;
2820 if (disposeList !is null) { 3294 }
2821 for (int i=0; i<disposeList.length; i++) { 3295 modalShells [index] = shell;
2822 if (disposeList [i] !is null) disposeList [i].run (); 3296 Shell [] shells = getShells ();
2823 } 3297 for (int i=0; i<shells.length; i++) shells [i].updateModal ();
2824 } 3298 }
2825 disposeList = null; 3299
2826 synchronizer.releaseSynchronizer (); 3300 /**
2827 synchronizer = null; 3301 * Sets the application defined, display specific data
2828 releaseDisplay (); 3302 * associated with the receiver, to the argument.
2829 super.release (); 3303 * The <em>display specific data</em> is a single,
2830 } 3304 * unnamed field that is stored with every display.
2831 3305 * <p>
2832 void releaseDisplay () { 3306 * Applications may put arbitrary objects in this field. If
2833 /* Release the System Images */ 3307 * the object stored in the display specific data needs to
2834 if (errorImage !is null) errorImage.dispose (); 3308 * be notified when the display is disposed of, it is the
2835 if (infoImage !is null) infoImage.dispose (); 3309 * application's responsibility provide a
2836 if (warningImage !is null) warningImage.dispose (); 3310 * <code>disposeExec()</code> handler which does so.
2837 errorImage = infoImage = warningImage = null; 3311 * </p>
2838 3312 *
2839 currentCaret = null; 3313 * @param data the new display specific data
2840 3314 *
2841 /* Release Timers */ 3315 * @exception DWTException <ul>
2842 if (hoverTimer !is null) timerExec(-1, hoverTimer); 3316 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
2843 hoverTimer = null; 3317 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
2844 if (caretTimer !is null) timerExec(-1, caretTimer); 3318 * </ul>
2845 caretTimer = null; 3319 *
2846 if (nsTimers !is null) { 3320 * @see #getData()
2847 for (int i=0; i<nsTimers.length; i++) { 3321 * @see #disposeExec(Runnable)
2848 if (nsTimers [i] !is null) { 3322 */
2849 nsTimers [i].invalidate(); 3323 public void setData (Object data) {
2850 nsTimers [i].release(); 3324 checkDevice ();
2851 } 3325 this.data = data;
2852 } 3326 }
2853 } 3327
2854 nsTimers = null; 3328 /**
2855 if (timerDelegate !is null) timerDelegate.release(); 3329 * Sets the synchronizer used by the display to be
2856 timerDelegate = null; 3330 * the argument, which can not be null.
2857 3331 *
2858 /* Release the System Cursors */ 3332 * @param synchronizer the new synchronizer for the display (must not be null)
2859 for (int i = 0; i < cursors.length; i++) { 3333 *
2860 if (cursors [i] !is null) cursors [i].dispose (); 3334 * @exception IllegalArgumentException <ul>
2861 } 3335 * <li>ERROR_NULL_ARGUMENT - if the synchronizer is null</li>
2862 cursors = null; 3336 * </ul>
2863 3337 * @exception DWTException <ul>
2864 /* Release Dock image */ 3338 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
2865 if (dockImage !is null) dockImage.release(); 3339 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
2866 dockImage = null; 3340 * <li>ERROR_FAILED_EXEC - if an exception occurred while running an inter-thread message</li>
2867 3341 * </ul>
2868 if (screenWindow !is null) screenWindow.release(); 3342 */
2869 screenWindow = null; 3343 public void setSynchronizer (Synchronizer synchronizer) {
2870 3344 checkDevice ();
2871 modalShells = null; 3345 if (synchronizer is null) error (DWT.ERROR_NULL_ARGUMENT);
2872 menuBar = null; 3346 if (synchronizer is this.synchronizer) return;
2873 menus = null; 3347 Synchronizer oldSynchronizer;
2874 3348 synchronized (Device.classinfo) {
2875 if (markedAttributes !is null) markedAttributes.release(); 3349 oldSynchronizer = this.synchronizer;
2876 markedAttributes = null; 3350 this.synchronizer = synchronizer;
2877 3351 }
2878 /* The release pool needs to be released before the call backs. */ 3352 if (oldSynchronizer !is null) {
2879 if (pool !is null) pool.release(); 3353 oldSynchronizer.runAsyncMessages(true);
2880 pool = null; 3354 }
2881 3355 }
2882 if (application !is null && applicationClass !is null) { 3356
2883 OS.object_setClass (application.id, applicationClass); 3357 /**
2884 } 3358 * Causes the user-interface thread to <em>sleep</em> (that is,
2885 application = null; 3359 * to be put in a state where it does not consume CPU cycles)
2886 applicationClass = null; 3360 * until an event is received or it is otherwise awakened.
2887 } 3361 *
2888 3362 * @return <code>true</code> if an event requiring dispatching was placed on the queue.
2889 void removeContext (NSGraphicsContext context) { 3363 *
2890 if (contexts is null) return; 3364 * @exception DWTException <ul>
2891 int count = 0; 3365 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
2892 for (int i = 0; i < contexts.length; i++) { 3366 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
2893 if (contexts[i] !is null) { 3367 * </ul>
2894 if (contexts [i].id is context.id) { 3368 *
2895 contexts[i] = null; 3369 * @see #wake
3370 */
3371 public bool sleep () {
3372 checkDevice ();
3373 if (getMessageCount () !is 0) return true;
3374 if (loopCounter is 0) {
3375 pool.release();
3376 pool = cast(NSAutoreleasePool)(new NSAutoreleasePool()).alloc().init();
3377 }
3378 allowTimers = runAsyncMessages = false;
3379 NSRunLoop.currentRunLoop().runMode(OS.NSDefaultRunLoopMode, NSDate.distantFuture());
3380 allowTimers = runAsyncMessages = true;
3381 return true;
3382 }
3383
3384 int sourceProc (int info) {
3385 return 0;
3386 }
3387
3388 /**
3389 * Causes the <code>run()</code> method of the runnable to
3390 * be invoked by the user-interface thread at the next
3391 * reasonable opportunity. The thread which calls this method
3392 * is suspended until the runnable completes. Specifying <code>null</code>
3393 * as the runnable simply wakes the user-interface thread.
3394 * <p>
3395 * Note that at the time the runnable is invoked, widgets
3396 * that have the receiver as their display may have been
3397 * disposed. Therefore, it is necessary to check for this
3398 * case inside the runnable before accessing the widget.
3399 * </p>
3400 *
3401 * @param runnable code to run on the user-interface thread or <code>null</code>
3402 *
3403 * @exception DWTException <ul>
3404 * <li>ERROR_FAILED_EXEC - if an exception occurred when executing the runnable</li>
3405 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
3406 * </ul>
3407 *
3408 * @see #asyncExec
3409 */
3410 public void syncExec (Runnable runnable) {
3411 Synchronizer synchronizer;
3412 synchronized (Device.classinfo) {
3413 if (isDisposed ()) error (DWT.ERROR_DEVICE_DISPOSED);
3414 synchronizer = this.synchronizer;
3415 }
3416 synchronizer.syncExec (runnable);
3417 }
3418
3419 /**
3420 * Causes the <code>run()</code> method of the runnable to
3421 * be invoked by the user-interface thread after the specified
3422 * number of milliseconds have elapsed. If milliseconds is less
3423 * than zero, the runnable is not executed.
3424 * <p>
3425 * Note that at the time the runnable is invoked, widgets
3426 * that have the receiver as their display may have been
3427 * disposed. Therefore, it is necessary to check for this
3428 * case inside the runnable before accessing the widget.
3429 * </p>
3430 *
3431 * @param milliseconds the delay before running the runnable
3432 * @param runnable code to run on the user-interface thread
3433 *
3434 * @exception IllegalArgumentException <ul>
3435 * <li>ERROR_NULL_ARGUMENT - if the runnable is null</li>
3436 * </ul>
3437 * @exception DWTException <ul>
3438 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
3439 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
3440 * </ul>
3441 *
3442 * @see #asyncExec
3443 */
3444 public void timerExec (int milliseconds, Runnable runnable) {
3445 checkDevice ();
3446 //TODO - remove a timer, reschedule a timer not tested
3447 if (runnable is null) error (DWT.ERROR_NULL_ARGUMENT);
3448 if (timerList is null) timerList = new Runnable [4];
3449 if (nsTimers is null) nsTimers = new NSTimer [4];
3450 int index = 0;
3451 while (index < timerList.length) {
3452 if (timerList [index] is runnable) break;
3453 index++;
3454 }
3455 if (index !is timerList.length) {
3456 NSTimer timer = nsTimers [index];
3457 if (timer is null) {
3458 timerList [index] = null;
2896 } else { 3459 } else {
2897 count++; 3460 if (milliseconds < 0) {
2898 } 3461 timer.invalidate();
2899 } 3462 timerList [index] = null;
2900 } 3463 nsTimers [index] = null;
2901 if (count is 0) contexts = null; 3464 } else {
2902 } 3465 timer.setFireDate(NSDate.dateWithTimeIntervalSinceNow (milliseconds / 1000.0));
2903 3466 }
2904 /** 3467 return;
2905 * Removes the listener from the collection of listeners who will 3468 }
2906 * be notified when an event of the given type occurs anywhere in 3469 }
2907 * a widget. The event type is one of the event constants defined 3470 if (milliseconds < 0) return;
2908 * in class <code>DWT</code>. 3471 index = 0;
2909 * 3472 while (index < timerList.length) {
2910 * @param eventType the type of event to listen for 3473 if (timerList [index] is null) break;
2911 * @param listener the listener which should no longer be notified when the event occurs 3474 index++;
2912 * 3475 }
2913 * @exception IllegalArgumentException <ul> 3476 if (index is timerList.length) {
2914 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> 3477 Runnable [] newTimerList = new Runnable [timerList.length + 4];
2915 * </ul> 3478 SimpleType!(Runnable).arraycopy (timerList, 0, newTimerList, 0, timerList.length);
2916 * @exception DWTException <ul> 3479 timerList = newTimerList;
2917 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 3480 NSTimer [] newTimerIds = new NSTimer [nsTimers.length + 4];
2918 * </ul> 3481 System.arraycopy (nsTimers, 0, newTimerIds, 0, nsTimers.length);
2919 * 3482 nsTimers = newTimerIds;
2920 * @see Listener 3483 }
2921 * @see DWT 3484 NSNumber userInfo = NSNumber.numberWithInt(index);
2922 * @see #addFilter 3485 NSTimer timer = NSTimer.scheduledTimerWithTimeInterval(milliseconds / 1000.0, timerDelegate, OS.sel_timerProc_, userInfo, false);
2923 * @see #addListener 3486 timer.retain();
2924 * 3487 if (timer !is null) {
2925 * @since 3.0 3488 nsTimers [index] = timer;
2926 */ 3489 timerList [index] = runnable;
2927 public void removeFilter (int eventType, Listener listener) { 3490 }
2928 checkDevice (); 3491 }
2929 if (listener is null) error (DWT.ERROR_NULL_ARGUMENT); 3492
2930 if (filterTable is null) return; 3493 objc.id timerProc (objc.id id, objc.SEL sel, objc.id timerID) {
2931 filterTable.unhook (eventType, listener); 3494 NSTimer timer = new NSTimer (timerID);
2932 if (filterTable.size () is 0) filterTable = null; 3495 NSNumber number = new NSNumber(timer.userInfo());
2933 } 3496 int index = number.intValue();
2934 3497 if (timerList is null) return null;
2935 /** 3498 if (0 <= index && index < timerList.length) {
2936 * Removes the listener from the collection of listeners who will 3499 if (allowTimers) {
2937 * be notified when an event of the given type occurs. The event type 3500 Runnable runnable = timerList [index];
2938 * is one of the event constants defined in class <code>DWT</code>.
2939 *
2940 * @param eventType the type of event to listen for
2941 * @param listener the listener which should no longer be notified
2942 *
2943 * @exception IllegalArgumentException <ul>
2944 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
2945 * </ul>
2946 * @exception DWTException <ul>
2947 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
2948 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
2949 * </ul>
2950 *
2951 * @see Listener
2952 * @see DWT
2953 * @see #addListener
2954 *
2955 * @since 2.0
2956 */
2957 public void removeListener (int eventType, Listener listener) {
2958 checkDevice ();
2959 if (listener is null) error (DWT.ERROR_NULL_ARGUMENT);
2960 if (eventTable is null) return;
2961 eventTable.unhook (eventType, listener);
2962 }
2963
2964 Widget removeWidget (NSObject view) {
2965 if (view is null) return null;
2966 void* jniRef;
2967 OS.object_getInstanceVariable(view.id, SWT_OBJECT, jniRef);
2968 if (jniRef is null) return null;
2969 Widget widget = cast(Widget)OS.JNIGetObject(jniRef);
2970 OS.object_setInstanceVariable(view.id, SWT_OBJECT, null);
2971 return widget;
2972 }
2973
2974 void removeMenu (Menu menu) {
2975 if (menus is null) return;
2976 for (int i = 0; i < menus.length; i++) {
2977 if (menus [i] is menu) {
2978 menus[i] = null;
2979 break;
2980 }
2981 }
2982 }
2983
2984 void removePopup (Menu menu) {
2985 if (popups is null) return;
2986 for (int i=0; i<popups.length; i++) {
2987 if (popups [i] is menu) {
2988 popups [i] = null;
2989 return;
2990 }
2991 }
2992 }
2993
2994 bool runAsyncMessages (bool all) {
2995 return synchronizer.runAsyncMessages (all);
2996 }
2997
2998 bool runContexts () {
2999 if (contexts !is null) {
3000 for (int i = 0; i < contexts.length; i++) {
3001 if (contexts[i] !is null) contexts[i].flushGraphics();
3002 }
3003 }
3004 return false;
3005 }
3006
3007 bool runDeferredEvents () {
3008 /*
3009 * Run deferred events. This code is always
3010 * called in the Display's thread so it must
3011 * be re-enterant need not be synchronized.
3012 */
3013 while (eventQueue !is null) {
3014
3015 /* Take an event off the queue */
3016 Event event = eventQueue [0];
3017 if (event is null) break;
3018 int length_ = eventQueue.length;
3019 System.arraycopy (eventQueue, 1, eventQueue, 0, --length_);
3020 eventQueue [length_] = null;
3021
3022 /* Run the event */
3023 Widget widget = event.widget;
3024 if (widget !is null && !widget.isDisposed ()) {
3025 Widget item = event.item;
3026 if (item is null || !item.isDisposed ()) {
3027 widget.notifyListeners (event.type, event);
3028 }
3029 }
3030
3031 /*
3032 * At this point, the event queue could
3033 * be null due to a recursive invokation
3034 * when running the event.
3035 */
3036 }
3037
3038 /* Clear the queue */
3039 eventQueue = null;
3040 return true;
3041 }
3042
3043 bool runPopups () {
3044 if (popups is null) return false;
3045 bool result = false;
3046 while (popups !is null) {
3047 Menu menu = popups [0];
3048 if (menu is null) break;
3049 int length_ = popups.length;
3050 System.arraycopy (popups, 1, popups, 0, --length_);
3051 popups [length_] = null;
3052 // clearMenuFlags ();
3053 runDeferredEvents ();
3054 if (!menu.isDisposed ()) menu._setVisible (true);
3055 // clearMenuFlags ();
3056 result = true;
3057 }
3058 popups = null;
3059 return result;
3060 }
3061
3062 bool runTimers () {
3063 if (timerList is null) return false;
3064 bool result = false;
3065 for (int i=0; i<timerList.length; i++) {
3066 if (nsTimers [i] is null && timerList [i] !is null) {
3067 Runnable runnable = timerList [i];
3068 timerList [i] = null;
3069 if (runnable !is null) {
3070 result = true;
3071 runnable.run ();
3072 }
3073 }
3074 }
3075 return result;
3076 }
3077
3078 void sendEvent (int eventType, Event event) {
3079 if (eventTable is null && filterTable is null) {
3080 return;
3081 }
3082 if (event is null) event = new Event ();
3083 event.display = this;
3084 event.type = eventType;
3085 if (event.time is 0) event.time = getLastEventTime ();
3086 if (!filterEvent (event)) {
3087 if (eventTable !is null) eventTable.sendEvent (event);
3088 }
3089 }
3090
3091 /**
3092 * On platforms which support it, sets the application name
3093 * to be the argument. On Motif, for example, this can be used
3094 * to set the name used for resource lookup. Specifying
3095 * <code>null</code> for the name clears it.
3096 *
3097 * @param name the new app name or <code>null</code>
3098 */
3099 public static void setAppName (String name) {
3100 APP_NAME = name;
3101 }
3102
3103 //TODO use custom timer instead of timerExec
3104 Runnable hoverTimer;
3105
3106 //TODO - use custom timer instead of timerExec
3107 Runnable caretTimer;
3108
3109 void setCurrentCaret (Caret caret) {
3110 // if (caretID !is 0) OS.RemoveEventLoopTimer (caretID);
3111 // caretID = 0;
3112 currentCaret = caret;
3113 if (currentCaret !is null) {
3114 int blinkRate = currentCaret.blinkRate;
3115 timerExec (blinkRate, caretTimer);
3116 }
3117 }
3118
3119 void setCursor (Control control) {
3120 Cursor cursor = null;
3121 if (control !is null) cursor = control.findCursor ();
3122 if (cursor is null) cursor = getSystemCursor (DWT.CURSOR_ARROW);
3123 cursor.handle.set ();
3124 }
3125
3126 /**
3127 * Sets the location of the on-screen pointer relative to the top left corner
3128 * of the screen. <b>Note: It is typically considered bad practice for a
3129 * program to move the on-screen pointer location.</b>
3130 *
3131 * @param x the new x coordinate for the cursor
3132 * @param y the new y coordinate for the cursor
3133 *
3134 * @exception DWTException <ul>
3135 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
3136 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
3137 * </ul>
3138 *
3139 * @since 2.1
3140 */
3141 public void setCursorLocation (int x, int y) {
3142 checkDevice ();
3143 CGPoint pt = CGPoint ();
3144 pt.x = x; pt.y = y;
3145 OS.CGWarpMouseCursorPosition (pt);
3146 }
3147
3148 /**
3149 * Sets the location of the on-screen pointer relative to the top left corner
3150 * of the screen. <b>Note: It is typically considered bad practice for a
3151 * program to move the on-screen pointer location.</b>
3152 *
3153 * @param point new position
3154 *
3155 * @exception DWTException <ul>
3156 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
3157 * <li>ERROR_NULL_ARGUMENT - if the point is null
3158 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
3159 * </ul>
3160 *
3161 * @since 2.0
3162 */
3163 public void setCursorLocation (Point point) {
3164 checkDevice ();
3165 if (point is null) error (DWT.ERROR_NULL_ARGUMENT);
3166 setCursorLocation (point.x, point.y);
3167 }
3168
3169 /**
3170 * Sets the application defined property of the receiver
3171 * with the specified name to the given argument.
3172 * <p>
3173 * Applications may have associated arbitrary objects with the
3174 * receiver in this fashion. If the objects stored in the
3175 * properties need to be notified when the display is disposed
3176 * of, it is the application's responsibility provide a
3177 * <code>disposeExec()</code> handler which does so.
3178 * </p>
3179 *
3180 * @param key the name of the property
3181 * @param value the new value for the property
3182 *
3183 * @exception IllegalArgumentException <ul>
3184 * <li>ERROR_NULL_ARGUMENT - if the key is null</li>
3185 * </ul>
3186 * @exception DWTException <ul>
3187 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
3188 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
3189 * </ul>
3190 *
3191 * @see #getData(String)
3192 * @see #disposeExec(Runnable)
3193 */
3194 public void setData (String key, Object value) {
3195 checkDevice ();
3196 //if (key is null) error (DWT.ERROR_NULL_ARGUMENT);
3197
3198 if (key.equals (ADD_WIDGET_KEY)) {
3199 auto wrap = cast(ArrayWrapperObject) value;
3200
3201 if (wrap is null)
3202 DWT.error(DWT.ERROR_INVALID_ARGUMENT, null, " []");
3203
3204 Object [] data = wrap.array;
3205 NSObject object = cast(NSObject)data [0];
3206 Widget widget = cast(Widget)data [1];
3207 if (widget is null) {
3208 removeWidget (object);
3209 } else {
3210 addWidget (object, widget);
3211 }
3212 }
3213
3214 /* Remove the key/value pair */
3215 if (value is null) {
3216 if (keys is null) return;
3217 int index = 0;
3218 while (index < keys.length && !keys [index].equals (key)) index++;
3219 if (index is keys.length) return;
3220 if (keys.length is 1) {
3221 keys = null;
3222 values = null;
3223 } else {
3224 String [] newKeys = new String [keys.length - 1];
3225 Object [] newValues = new Object [values.length - 1];
3226 System.arraycopy (keys, 0, newKeys, 0, index);
3227 System.arraycopy (keys, index + 1, newKeys, index, newKeys.length - index);
3228 System.arraycopy (values, 0, newValues, 0, index);
3229 System.arraycopy (values, index + 1, newValues, index, newValues.length - index);
3230 keys = newKeys;
3231 values = newValues;
3232 }
3233 return;
3234 }
3235
3236 /* Add the key/value pair */
3237 if (keys is null) {
3238 keys = [key];
3239 values = [value];
3240 return;
3241 }
3242 for (int i=0; i<keys.length; i++) {
3243 if (keys [i].equals (key)) {
3244 values [i] = value;
3245 return;
3246 }
3247 }
3248 String [] newKeys = new String [keys.length + 1];
3249 Object [] newValues = new Object [values.length + 1];
3250 System.arraycopy (keys, 0, newKeys, 0, keys.length);
3251 System.arraycopy (values, 0, newValues, 0, values.length);
3252 newKeys [keys.length] = key;
3253 newValues [values.length] = value;
3254 keys = newKeys;
3255 values = newValues;
3256 }
3257
3258 void setMenuBar (Menu menu) {
3259 if (menu is menuBar) return;
3260 menuBar = menu;
3261 //remove all existing menu items except the application menu
3262 NSMenu menubar = application.mainMenu();
3263 NSInteger count = menubar.numberOfItems();
3264 while (count > 1) {
3265 menubar.removeItemAtIndex(count - 1);
3266 count--;
3267 }
3268 //set parent of each item to NULL and add them to menubar
3269 if (menu !is null) {
3270 MenuItem[] items = menu.getItems();
3271 for (int i = 0; i < items.length; i++) {
3272 items[i].nsItem.setMenu(null);
3273 menubar.addItem(items[i].nsItem);
3274 }
3275 }
3276 }
3277
3278 void setModalShell (Shell shell) {
3279 if (modalShells is null) modalShells = new Shell [4];
3280 int index = 0, length = modalShells.length;
3281 while (index < length) {
3282 if (modalShells [index] is shell) return;
3283 if (modalShells [index] is null) break;
3284 index++;
3285 }
3286 if (index is length) {
3287 Shell [] newModalShells = new Shell [length + 4];
3288 System.arraycopy (modalShells, 0, newModalShells, 0, length);
3289 modalShells = newModalShells;
3290 }
3291 modalShells [index] = shell;
3292 Shell [] shells = getShells ();
3293 for (int i=0; i<shells.length; i++) shells [i].updateModal ();
3294 }
3295
3296 /**
3297 * Sets the application defined, display specific data
3298 * associated with the receiver, to the argument.
3299 * The <em>display specific data</em> is a single,
3300 * unnamed field that is stored with every display.
3301 * <p>
3302 * Applications may put arbitrary objects in this field. If
3303 * the object stored in the display specific data needs to
3304 * be notified when the display is disposed of, it is the
3305 * application's responsibility provide a
3306 * <code>disposeExec()</code> handler which does so.
3307 * </p>
3308 *
3309 * @param data the new display specific data
3310 *
3311 * @exception DWTException <ul>
3312 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
3313 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
3314 * </ul>
3315 *
3316 * @see #getData()
3317 * @see #disposeExec(Runnable)
3318 */
3319 public void setData (Object data) {
3320 checkDevice ();
3321 this.data = data;
3322 }
3323
3324 /**
3325 * Sets the synchronizer used by the display to be
3326 * the argument, which can not be null.
3327 *
3328 * @param synchronizer the new synchronizer for the display (must not be null)
3329 *
3330 * @exception IllegalArgumentException <ul>
3331 * <li>ERROR_NULL_ARGUMENT - if the synchronizer is null</li>
3332 * </ul>
3333 * @exception DWTException <ul>
3334 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
3335 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
3336 * <li>ERROR_FAILED_EXEC - if an exception occurred while running an inter-thread message</li>
3337 * </ul>
3338 */
3339 public void setSynchronizer (Synchronizer synchronizer) {
3340 checkDevice ();
3341 if (synchronizer is null) error (DWT.ERROR_NULL_ARGUMENT);
3342 if (synchronizer is this.synchronizer) return;
3343 Synchronizer oldSynchronizer;
3344 synchronized (Device.classinfo) {
3345 oldSynchronizer = this.synchronizer;
3346 this.synchronizer = synchronizer;
3347 }
3348 if (oldSynchronizer !is null) {
3349 oldSynchronizer.runAsyncMessages(true);
3350 }
3351 }
3352
3353 /**
3354 * Causes the user-interface thread to <em>sleep</em> (that is,
3355 * to be put in a state where it does not consume CPU cycles)
3356 * until an event is received or it is otherwise awakened.
3357 *
3358 * @return <code>true</code> if an event requiring dispatching was placed on the queue.
3359 *
3360 * @exception DWTException <ul>
3361 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
3362 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
3363 * </ul>
3364 *
3365 * @see #wake
3366 */
3367 public bool sleep () {
3368 checkDevice ();
3369 if (getMessageCount () !is 0) return true;
3370 if (loopCounter is 0) {
3371 pool.release();
3372 pool = cast(NSAutoreleasePool)(new NSAutoreleasePool()).alloc().init();
3373 }
3374 allowTimers = runAsyncMessages = false;
3375 NSRunLoop.currentRunLoop().runMode(OS.NSDefaultRunLoopMode, NSDate.distantFuture());
3376 allowTimers = runAsyncMessages = true;
3377 return true;
3378 }
3379
3380 int sourceProc (int info) {
3381 return 0;
3382 }
3383
3384 /**
3385 * Causes the <code>run()</code> method of the runnable to
3386 * be invoked by the user-interface thread at the next
3387 * reasonable opportunity. The thread which calls this method
3388 * is suspended until the runnable completes. Specifying <code>null</code>
3389 * as the runnable simply wakes the user-interface thread.
3390 * <p>
3391 * Note that at the time the runnable is invoked, widgets
3392 * that have the receiver as their display may have been
3393 * disposed. Therefore, it is necessary to check for this
3394 * case inside the runnable before accessing the widget.
3395 * </p>
3396 *
3397 * @param runnable code to run on the user-interface thread or <code>null</code>
3398 *
3399 * @exception DWTException <ul>
3400 * <li>ERROR_FAILED_EXEC - if an exception occurred when executing the runnable</li>
3401 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
3402 * </ul>
3403 *
3404 * @see #asyncExec
3405 */
3406 public void syncExec (Runnable runnable) {
3407 Synchronizer synchronizer;
3408 synchronized (Device.classinfo) {
3409 if (isDisposed ()) error (DWT.ERROR_DEVICE_DISPOSED);
3410 synchronizer = this.synchronizer;
3411 }
3412 synchronizer.syncExec (runnable);
3413 }
3414
3415 /**
3416 * Causes the <code>run()</code> method of the runnable to
3417 * be invoked by the user-interface thread after the specified
3418 * number of milliseconds have elapsed. If milliseconds is less
3419 * than zero, the runnable is not executed.
3420 * <p>
3421 * Note that at the time the runnable is invoked, widgets
3422 * that have the receiver as their display may have been
3423 * disposed. Therefore, it is necessary to check for this
3424 * case inside the runnable before accessing the widget.
3425 * </p>
3426 *
3427 * @param milliseconds the delay before running the runnable
3428 * @param runnable code to run on the user-interface thread
3429 *
3430 * @exception IllegalArgumentException <ul>
3431 * <li>ERROR_NULL_ARGUMENT - if the runnable is null</li>
3432 * </ul>
3433 * @exception DWTException <ul>
3434 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
3435 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
3436 * </ul>
3437 *
3438 * @see #asyncExec
3439 */
3440 public void timerExec (int milliseconds, Runnable runnable) {
3441 checkDevice ();
3442 //TODO - remove a timer, reschedule a timer not tested
3443 if (runnable is null) error (DWT.ERROR_NULL_ARGUMENT);
3444 if (timerList is null) timerList = new Runnable [4];
3445 if (nsTimers is null) nsTimers = new NSTimer [4];
3446 int index = 0;
3447 while (index < timerList.length) {
3448 if (timerList [index] is runnable) break;
3449 index++;
3450 }
3451 if (index !is timerList.length) {
3452 NSTimer timer = nsTimers [index];
3453 if (timer is null) {
3454 timerList [index] = null;
3455 } else {
3456 if (milliseconds < 0) {
3457 timer.invalidate();
3458 timerList [index] = null; 3501 timerList [index] = null;
3459 nsTimers [index] = null; 3502 nsTimers [index] = null;
3503 if (runnable !is null) runnable.run ();
3460 } else { 3504 } else {
3461 timer.setFireDate(NSDate.dateWithTimeIntervalSinceNow (milliseconds / 1000.0)); 3505 nsTimers [index] = null;
3462 } 3506 wakeThread ();
3463 return; 3507 }
3464 } 3508 }
3465 } 3509 timer.release();
3466 if (milliseconds < 0) return; 3510 return null;
3467 index = 0; 3511 }
3468 while (index < timerList.length) { 3512
3469 if (timerList [index] is null) break; 3513 /**
3470 index++; 3514 * Forces all outstanding paint requests for the display
3471 } 3515 * to be processed before this method returns.
3472 if (index is timerList.length) { 3516 *
3473 Runnable [] newTimerList = new Runnable [timerList.length + 4]; 3517 * @exception DWTException <ul>
3474 SimpleType!(Runnable).arraycopy (timerList, 0, newTimerList, 0, timerList.length); 3518 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
3475 timerList = newTimerList; 3519 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
3476 NSTimer [] newTimerIds = new NSTimer [nsTimers.length + 4]; 3520 * </ul>
3477 System.arraycopy (nsTimers, 0, newTimerIds, 0, nsTimers.length); 3521 *
3478 nsTimers = newTimerIds; 3522 * @see Control#update()
3479 } 3523 */
3480 NSNumber userInfo = NSNumber.numberWithInt(index); 3524 public void update () {
3481 NSTimer timer = NSTimer.scheduledTimerWithTimeInterval(milliseconds / 1000.0, timerDelegate, OS.sel_timerProc_, userInfo, false); 3525 checkDevice ();
3482 timer.retain(); 3526 // Shell [] shells = getShells ();
3483 if (timer !is null) { 3527 // for (int i=0; i<shells.length; i++) {
3484 nsTimers [index] = timer; 3528 // Shell shell = shells [i];
3485 timerList [index] = runnable; 3529 // if (!shell.isDisposed ()) shell.update (true);
3486 } 3530 // }
3487 } 3531
3488 3532 }
3489 objc.id timerProc (objc.id id, objc.SEL sel, objc.id timerID) { 3533
3490 NSTimer timer = new NSTimer (timerID); 3534 /**
3491 NSNumber number = new NSNumber(timer.userInfo()); 3535 * If the receiver's user-interface thread was <code>sleep</code>ing,
3492 int index = number.intValue(); 3536 * causes it to be awakened and start running again. Note that this
3493 if (timerList is null) return null; 3537 * method may be called from any thread.
3494 if (0 <= index && index < timerList.length) { 3538 *
3495 if (allowTimers) { 3539 * @exception DWTException <ul>
3496 Runnable runnable = timerList [index]; 3540 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
3497 timerList [index] = null; 3541 * </ul>
3498 nsTimers [index] = null; 3542 *
3499 if (runnable !is null) runnable.run (); 3543 * @see #sleep
3500 } else { 3544 */
3501 nsTimers [index] = null; 3545 public void wake () {
3546 synchronized (Device.classinfo) {
3547 if (isDisposed ()) error (DWT.ERROR_DEVICE_DISPOSED);
3548 if (thread is Thread.getThis ()) return;
3502 wakeThread (); 3549 wakeThread ();
3503 } 3550 }
3504 } 3551 }
3505 timer.release(); 3552
3506 return null; 3553 void wakeThread () {
3507 } 3554 NSObject object = (new NSObject()).alloc().init();
3508 3555 object.performSelectorOnMainThread(OS.sel_release, null, false);
3509 /** 3556 }
3510 * Forces all outstanding paint requests for the display 3557
3511 * to be processed before this method returns. 3558 Control findControl (NSEvent nsEvent, bool checkGrab, bool checkTrim, bool checkWindows) {
3512 * 3559 if (checkGrab && grabControl !is null && !grabControl.isDisposed()) return grabControl;
3513 * @exception DWTException <ul> 3560 NSPoint point = NSEvent.mouseLocation();
3514 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 3561 NSView view = null;
3515 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> 3562 NSWindow window = nsEvent !is null ? nsEvent.window() : null;
3516 * </ul> 3563 if (window !is null) {
3517 * 3564 view = window.contentView().hitTest (window.convertScreenToBase(point));
3518 * @see Control#update() 3565 }
3519 */ 3566 if (view is null && checkWindows) {
3520 public void update () { 3567 NSArray windows = application.orderedWindows();
3521 checkDevice (); 3568 for (int i = 0; i < windows.count() && view is null; i++) {
3522 // Shell [] shells = getShells (); 3569 window = new NSWindow(windows.objectAtIndex(i));
3523 // for (int i=0; i<shells.length; i++) { 3570 NSView contentView = window.contentView();
3524 // Shell shell = shells [i]; 3571 if (contentView !is null) view = contentView.hitTest (window.convertScreenToBase(point));
3525 // if (!shell.isDisposed ()) shell.update (true); 3572 }
3526 // } 3573 }
3527 3574 Control control = null;
3528 } 3575 if (view !is null) {
3529 3576 do {
3530 /** 3577 Widget widget = getWidget (view);
3531 * If the receiver's user-interface thread was <code>sleep</code>ing, 3578 if (cast(Control) widget) {
3532 * causes it to be awakened and start running again. Note that this 3579 control = cast(Control)widget;
3533 * method may be called from any thread. 3580 break;
3534 * 3581 }
3535 * @exception DWTException <ul> 3582 view = view.superview();
3536 * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> 3583 } while (view !is null);
3537 * </ul> 3584 }
3538 * 3585 if (checkTrim) {
3539 * @see #sleep 3586 if (control !is null && control.isTrim (view)) control = null;
3540 */ 3587 }
3541 public void wake () { 3588 return control;
3542 synchronized (Device.classinfo) { 3589 }
3543 if (isDisposed ()) error (DWT.ERROR_DEVICE_DISPOSED); 3590
3544 if (thread is Thread.getThis ()) return; 3591 objc.id applicationNextEventMatchingMask (objc.id id, objc.SEL sel, objc.id mask, objc.id expiration, objc.id mode, objc.id dequeue) {
3545 wakeThread (); 3592 objc_super super_struct = objc_super();
3546 } 3593 super_struct.receiver = id;
3547 } 3594 super_struct.super_class = cast(objc.Class) OS.objc_msgSend(id, OS.sel_superclass);
3548 3595 objc.id result = OS.objc_msgSendSuper(&super_struct, sel, mask, expiration, mode, dequeue !is null);
3549 void wakeThread () { 3596 if (result !is null) {
3550 NSObject object = (new NSObject()).alloc().init(); 3597 if (trackingControl !is null && dequeue !is null) {
3551 object.performSelectorOnMainThread(OS.sel_release, null, false); 3598 NSEvent nsEvent = new NSEvent(result);
3552 } 3599 applicationSendMouseEvent(nsEvent, true);
3553 3600 }
3554 Control findControl (NSEvent nsEvent, bool checkGrab, bool checkTrim, bool checkWindows) { 3601 }
3555 if (checkGrab && grabControl !is null && !grabControl.isDisposed()) return grabControl; 3602 return result;
3556 NSPoint point = NSEvent.mouseLocation(); 3603 }
3557 NSView view = null; 3604
3558 NSWindow window = nsEvent !is null ? nsEvent.window() : null; 3605 void applicationSendMouseEvent (NSEvent nsEvent, bool send) {
3559 if (window !is null) { 3606 if (send) runDeferredEvents();
3560 view = window.contentView().hitTest (window.convertScreenToBase(point)); 3607 bool up = false;
3561 } 3608 NSEventType type = nsEvent.type();
3562 if (view is null && checkWindows) { 3609 switch (type) {
3563 NSArray windows = application.orderedWindows(); 3610 case OS.NSLeftMouseDown:
3564 for (int i = 0; i < windows.count() && view is null; i++) { 3611 case OS.NSRightMouseDown:
3565 window = new NSWindow(windows.objectAtIndex(i)); 3612 case OS.NSOtherMouseDown: {
3566 NSView contentView = window.contentView(); 3613 Control control = grabControl = findControl(nsEvent, false, true, false);
3567 if (contentView !is null) view = contentView.hitTest (window.convertScreenToBase(point)); 3614 if (control !is null) {
3568 } 3615 if (nsEvent.clickCount() is 1 && (control.state & Widget.DRAG_DETECT) !is 0 && control.hooks (DWT.DragDetect) && control.dragDetect()) {
3569 } 3616 dragging = true;
3570 Control control = null; 3617 }
3571 if (view !is null) { 3618 control.sendMouseEvent (nsEvent, DWT.MouseDown, send);
3572 do { 3619 if (nsEvent.clickCount() is 2) {
3573 Widget widget = getWidget (view); 3620 control.sendMouseEvent (nsEvent, DWT.MouseDoubleClick, send);
3574 if (cast(Control) widget) { 3621 }
3575 control = cast(Control)widget; 3622 }
3576 break; 3623 break;
3577 } 3624 }
3578 view = view.superview(); 3625 case OS.NSLeftMouseUp:
3579 } while (view !is null); 3626 case OS.NSRightMouseUp:
3580 } 3627 case OS.NSOtherMouseUp: {
3581 if (checkTrim) { 3628 Control control = findControl(nsEvent, true, true, false);
3582 if (control !is null && control.isTrim (view)) control = null; 3629 if (control !is null) {
3583 } 3630 control.sendMouseEvent (nsEvent, DWT.MouseUp, send);
3584 return control;
3585 }
3586
3587 objc.id applicationNextEventMatchingMask (objc.id id, objc.SEL sel, objc.id mask, objc.id expiration, objc.id mode, objc.id dequeue) {
3588 objc_super super_struct = objc_super();
3589 super_struct.receiver = id;
3590 super_struct.super_class = cast(objc.Class) OS.objc_msgSend(id, OS.sel_superclass);
3591 objc.id result = OS.objc_msgSendSuper(&super_struct, sel, mask, expiration, mode, dequeue !is null);
3592 if (result !is null) {
3593 if (trackingControl !is null && dequeue !is null) {
3594 NSEvent nsEvent = new NSEvent(result);
3595 applicationSendMouseEvent(nsEvent, true);
3596 }
3597 }
3598 return result;
3599 }
3600
3601 void applicationSendMouseEvent (NSEvent nsEvent, bool send) {
3602 if (send) runDeferredEvents();
3603 bool up = false;
3604 int type = cast(int)/*64*/nsEvent.type();
3605 switch (type) {
3606 case OS.NSLeftMouseDown:
3607 case OS.NSRightMouseDown:
3608 case OS.NSOtherMouseDown: {
3609 Control control = grabControl = findControl(nsEvent, false, true, false);
3610 if (control !is null) {
3611 if (nsEvent.clickCount() is 1 && (control.state & Widget.DRAG_DETECT) !is 0 && control.hooks (DWT.DragDetect) && control.dragDetect()) {
3612 dragging = true;
3613 } 3631 }
3614 control.sendMouseEvent (nsEvent, DWT.MouseDown, send); 3632 grabControl = null;
3615 if (nsEvent.clickCount() is 2) { 3633 up = true;
3616 control.sendMouseEvent (nsEvent, DWT.MouseDoubleClick, send); 3634 //FALL THROUGH
3635 }
3636 case OS.NSLeftMouseDragged:
3637 case OS.NSRightMouseDragged:
3638 case OS.NSOtherMouseDragged:
3639 case OS.NSMouseMoved: {
3640 Control control = findControl(nsEvent, true, true, type is OS.NSMouseMoved);
3641 if (dragging) {
3642 dragging = false;
3643 control.sendDragEvent(nsEvent);
3617 } 3644 }
3618 } 3645 if (control !is currentControl) {
3619 break; 3646 if (currentControl !is null) {
3620 } 3647 currentControl.sendMouseEvent (nsEvent, DWT.MouseExit, send);
3621 case OS.NSLeftMouseUp: 3648 }
3622 case OS.NSRightMouseUp: 3649 currentControl = control;
3623 case OS.NSOtherMouseUp: { 3650 if (control !is null) {
3624 Control control = findControl(nsEvent, true, true, false); 3651 control.sendMouseEvent (nsEvent, DWT.MouseEnter, send);
3625 if (control !is null) { 3652 if (up) timerExec (getToolTipTime (), hoverTimer);
3626 control.sendMouseEvent (nsEvent, DWT.MouseUp, send); 3653 }
3627 } 3654 setCursor (control);
3628 grabControl = null;
3629 up = true;
3630 //FALL THROUGH
3631 }
3632 case OS.NSLeftMouseDragged:
3633 case OS.NSRightMouseDragged:
3634 case OS.NSOtherMouseDragged:
3635 case OS.NSMouseMoved: {
3636 Control control = findControl(nsEvent, true, true, type is OS.NSMouseMoved);
3637 if (dragging) {
3638 dragging = false;
3639 control.sendDragEvent(nsEvent);
3640 }
3641 if (control !is currentControl) {
3642 if (currentControl !is null) {
3643 currentControl.sendMouseEvent (nsEvent, DWT.MouseExit, send);
3644 } 3655 }
3645 currentControl = control; 3656 if (!up && control !is null) {
3646 if (control !is null) { 3657 timerExec (getToolTipTime (), hoverTimer);
3647 control.sendMouseEvent (nsEvent, DWT.MouseEnter, send); 3658 control.sendMouseEvent (nsEvent, DWT.MouseMove, send);
3648 if (up) timerExec (getToolTipTime (), hoverTimer);
3649 } 3659 }
3650 setCursor (control); 3660 break;
3651 } 3661 }
3652 if (!up && control !is null) { 3662 default:
3653 timerExec (getToolTipTime (), hoverTimer); 3663 }
3654 control.sendMouseEvent (nsEvent, DWT.MouseMove, send); 3664 }
3655 } 3665
3656 break; 3666 void applicationSendEvent (objc.id id, objc.SEL sel, objc.id event) {
3657 } 3667 NSEvent nsEvent = new NSEvent(event);
3658 } 3668 NSEventType type = nsEvent.type ();
3659 } 3669 bool beep_ = false;
3660 3670 switch (type) {
3661 void applicationSendEvent (objc.id id, objc.SEL sel, objc.id event) { 3671 case OS.NSLeftMouseDown:
3662 NSEvent nsEvent = new NSEvent(event); 3672 case OS.NSRightMouseDown:
3663 int type = nsEvent.type (); 3673 case OS.NSOtherMouseDown:
3664 bool beep_ = false; 3674 beep_ = true;
3665 switch (type) { 3675 case OS.NSLeftMouseUp:
3666 case OS.NSLeftMouseDown: 3676 case OS.NSRightMouseUp:
3667 case OS.NSRightMouseDown: 3677 case OS.NSMouseMoved:
3668 case OS.NSOtherMouseDown: 3678 case OS.NSLeftMouseDragged:
3669 beep_ = true; 3679 case OS.NSRightMouseDragged:
3670 case OS.NSLeftMouseUp: 3680 case OS.NSMouseEntered:
3671 case OS.NSRightMouseUp: 3681 case OS.NSMouseExited:
3672 case OS.NSMouseMoved: 3682 case OS.NSKeyDown:
3673 case OS.NSLeftMouseDragged: 3683 case OS.NSKeyUp:
3674 case OS.NSRightMouseDragged: 3684 case OS.NSOtherMouseUp:
3675 case OS.NSMouseEntered: 3685 case OS.NSOtherMouseDragged:
3676 case OS.NSMouseExited: 3686 case OS.NSScrollWheel:
3677 case OS.NSKeyDown: 3687 NSWindow window = nsEvent.window ();
3678 case OS.NSKeyUp: 3688 if (window !is null) {
3679 case OS.NSOtherMouseUp: 3689 Shell shell = cast(Shell) getWidget (window.id);
3680 case OS.NSOtherMouseDragged: 3690 if (shell !is null && shell.getModalShell () !is null) {
3681 case OS.NSScrollWheel: 3691 if (beep_) beep ();
3682 NSWindow window = nsEvent.window (); 3692 return;
3683 if (window !is null) { 3693 }
3684 Shell shell = cast(Shell) getWidget (window.id);
3685 if (shell !is null && shell.getModalShell () !is null) {
3686 if (beep_) beep ();
3687 return;
3688 } 3694 }
3689 } 3695 break;
3690 break; 3696 default:
3691 } 3697 }
3692 applicationSendMouseEvent (nsEvent, false); 3698 applicationSendMouseEvent (nsEvent, false);
3693 objc_super super_struct = objc_super (); 3699 objc_super super_struct = objc_super ();
3694 super_struct.receiver = id; 3700 super_struct.receiver = id;
3695 super_struct.super_class = cast(objc.Class) OS.objc_msgSend (id, OS.sel_superclass); 3701 super_struct.super_class = cast(objc.Class) OS.objc_msgSend (id, OS.sel_superclass);
3696 OS.objc_msgSendSuper (&super_struct, sel, event); 3702 OS.objc_msgSendSuper (&super_struct, sel, event);
3697 // if (nsEvent.type() is OS.NSApplicationDefined && nsEvent.subtype() is SWT_IDLE_TYPE) { 3703 // if (nsEvent.type() is OS.NSApplicationDefined && nsEvent.subtype() is SWT_IDLE_TYPE) {
3698 // idle = true; 3704 // idle = true;
3699 // } else { 3705 // } else {
3700 // idle = false; 3706 // idle = false;
3701 // } 3707 // }
3702 // application.stop(null); 3708 // application.stop(null);
3703 } 3709 }
3704 3710
3705 extern (C): 3711 extern (C):
3706 3712
3707 // #245724: [NSApplication isRunning] must return true to allow the AWT to load correctly. 3713 // #245724: [NSApplication isRunning] must return true to allow the AWT to load correctly.
3708 static objc.id applicationProc2(objc.id id, objc.SEL sel) {println("applicationProc2"); 3714 static objc.id applicationProc2(objc.id id, objc.SEL sel) {
3709 //TODO optimize getting the display
3710 Display display = getCurrent ();
3711 if (display is null) return null;
3712 if (sel is OS.sel_isRunning) {
3713 return cast(objc.id) (display.isDisposed() ? null : cast(objc.id) 1);
3714 }
3715 return null;
3716 }
3717
3718 static objc.id applicationProc3(objc.id id, objc.SEL sel, objc.id event) {println("applicationProc3");
3719 //TODO optimize getting the display
3720 Display display = getCurrent ();
3721 if (display is null) return null;
3722 if (sel is OS.sel_sendEvent_) {
3723 display.applicationSendEvent (id, sel, event);
3724 return null;
3725 }
3726 return null;
3727 }
3728
3729 static objc.id applicationProc6(objc.id id, objc.SEL sel, objc.id arg0, objc.id arg1, objc.id arg2, objc.id arg3) {println("applicationProc6");
3730 //TODO optimize getting the display
3731 Display display = getCurrent ();
3732 if (display is null) return null;
3733 if (sel is OS.sel_nextEventMatchingMask_untilDate_inMode_dequeue_) {
3734 return display.applicationNextEventMatchingMask(id, sel, arg0, arg1, arg2, arg3);
3735 }
3736 return null;
3737 }
3738
3739 static objc.id applicationDelegateProc(objc.id id, objc.SEL sel, objc.id arg0) {
3740 //TODO optimize getting the display
3741 Display display = getCurrent ();
3742 if (display is null) return null;
3743 cocoa.id applicationDelegate = display.applicationDelegate;
3744 NSApplication application = display.application;
3745 if (sel is OS.sel_applicationWillFinishLaunching_) {
3746 NSDictionary dict = NSDictionary.dictionaryWithObject(applicationDelegate, NSString.stringWith("NSOwner"));
3747 NSString nibFile = NSString.stringWith("/System/Library/Frameworks/JavaVM.framework/Resources/English.lproj/DefaultApp.nib");
3748 if (!NSBundle.loadNibFile(nibFile, dict, null)) {
3749 nibFile = NSString.stringWith("/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Resources/English.lproj/DefaultApp.nib");
3750 NSBundle.loadNibFile(nibFile, dict, null);
3751 }
3752 //replace %@ with application name
3753 NSMenu mainmenu = application.mainMenu();
3754 NSMenuItem appitem = mainmenu.itemAtIndex(0);
3755 if (appitem !is null) {
3756 NSMenu sm = appitem.submenu();
3757 NSArray ia = sm.itemArray();
3758 for(int i = 0; i < ia.count(); i++) {
3759 NSMenuItem ni = new NSMenuItem(ia.objectAtIndex(i));
3760 NSString title = ni.title().stringByReplacingOccurrencesOfString(NSString.stringWith("%@"), NSString.stringWith(APP_NAME));
3761 ni.setTitle(title);
3762 }
3763 }
3764 } else if (sel is OS.sel_terminate_) {
3765 application.terminate(application);
3766 } else if (sel is OS.sel_orderFrontStandardAboutPanel_) {
3767 // Event event = new Event ();
3768 // sendEvent (DWT.ABORT, event);
3769 } else if (sel is OS.sel_hideOtherApplications_) {
3770 application.hideOtherApplications(application);
3771 } else if (sel is OS.sel_hide_) {
3772 application.hide(application);
3773 } else if (sel is OS.sel_unhideAllApplications_) {
3774 application.unhideAllApplications(application);
3775 } else if (sel is OS.sel_applicationShouldTerminate_) {
3776 if (!display.disposing) {
3777 Event event = new Event ();
3778 display.sendEvent (DWT.Close, event);
3779 if (event.doit) {
3780 return cast(objc.id) OS.NSTerminateNow;
3781 }
3782 }
3783 return cast(objc.id) OS.NSTerminateCancel;
3784 } else if (sel is OS.sel_applicationWillTerminate_) {
3785 display.dispose();
3786 } else if (sel is OS.sel_applicationWillResignActive_) {
3787 Shell[] shells = display.getShells();
3788 for (int i = 0; i < shells.length; i++) {
3789 shells[i].clearLevel();
3790 }
3791 }
3792 return null;
3793 }
3794
3795 static objc.id dialogProc(objc.id id, objc.SEL sel, objc.id arg0) {
3796 void* jniRef;
3797 OS.object_getInstanceVariable(id, SWT_OBJECT, jniRef);
3798 if (jniRef is null) return null;
3799 if (sel is OS.sel_changeColor_) {
3800 ColorDialog dialog = cast(ColorDialog)OS.JNIGetObject(jniRef);
3801 if (jniRef is null) return null;
3802 dialog.changeColor(id, sel, arg0);
3803 } else if (sel is OS.sel_changeFont_) {
3804 FontDialog dialog = cast(FontDialog)OS.JNIGetObject(jniRef);
3805 if (dialog is null) return null;
3806 dialog.changeFont(id, sel, arg0);
3807 } else if (sel is OS.sel_windowWillClose_) {
3808 Object object = OS.JNIGetObject(jniRef);
3809 if (cast(FontDialog) object) {
3810 (cast(FontDialog)object).windowWillClose(id, sel, arg0);
3811 } else if (cast(ColorDialog) object) {
3812 (cast(ColorDialog)object).windowWillClose(id, sel, arg0);
3813 }
3814 }
3815 return null;
3816 }
3817
3818 static objc.id windowDelegateProc2(objc.id id, objc.SEL sel) {
3819 Widget widget = GetWidget(id);
3820 if (widget is null) return null;
3821 if (sel is OS.sel_sendSelection) {
3822 widget.sendSelection();
3823 } else if (sel is OS.sel_sendDoubleSelection) {
3824 widget.sendDoubleSelection();
3825 } else if (sel is OS.sel_sendVerticalSelection) {
3826 widget.sendVerticalSelection();
3827 } else if (sel is OS.sel_sendHorizontalSelection) {
3828 widget.sendHorizontalSelection();
3829 } else if (sel is OS.sel_acceptsFirstResponder) {
3830 return widget.acceptsFirstResponder(id, sel) ? cast(objc.id) 1 : null;
3831 } else if (sel is OS.sel_becomeFirstResponder) {
3832 return widget.becomeFirstResponder(id, sel) ? cast(objc.id) 1 : null;
3833 } else if (sel is OS.sel_resignFirstResponder) {
3834 return widget.resignFirstResponder(id, sel) ? cast(objc.id) 1 : null;
3835 } else if (sel is OS.sel_isFlipped) {
3836 return widget.isFlipped(id, sel) ? cast(objc.id) 1 : null;
3837 } else if (sel is OS.sel_isOpaque) {
3838 return widget.isOpaque(id, sel) ? cast(objc.id) 1 : null;
3839 } else if (sel is OS.sel_unmarkText) {
3840 //TODO not called?
3841 } else if (sel is OS.sel_validAttributesForMarkedText) {
3842 return widget.validAttributesForMarkedText (id, sel);
3843 } else if (sel is OS.sel_markedRange) {
3844 NSRange range = widget.markedRange (id, sel);
3845 /* NOTE that this is freed in C */
3846 objc.id result = cast(objc.id) OS.malloc (NSRange.sizeof);
3847 OS.memmove (result, &range, NSRange.sizeof);
3848 return result;
3849 } else if (sel is OS.sel_selectedRange) {
3850 NSRange range = widget.selectedRange (id, sel);
3851 /* NOTE that this is freed in C */
3852 objc.id result = cast(objc.id) OS.malloc (NSRange.sizeof);
3853 OS.memmove (result, &range, NSRange.sizeof);
3854 return result;
3855 } else if (sel is OS.sel_hasMarkedText) {
3856 return widget.hasMarkedText (id, sel) ? cast(objc.id) 1 : null;
3857 } else if (sel is OS.sel_canBecomeKeyWindow) {
3858 return widget.canBecomeKeyWindow (id, sel) ? cast(objc.id) 1 : null;
3859 } else if (sel is OS.sel_accessibilityActionNames) {
3860 return widget.accessibilityActionNames(id, sel);
3861 } else if (sel is OS.sel_accessibilityAttributeNames) {
3862 return widget.accessibilityAttributeNames(id, sel);
3863 } else if (sel is OS.sel_accessibilityParameterizedAttributeNames) {
3864 return widget.accessibilityParameterizedAttributeNames(id, sel);
3865 } else if (sel is OS.sel_accessibilityFocusedUIElement) {
3866 return widget.accessibilityFocusedUIElement(id, sel);
3867 } else if (sel is OS.sel_accessibilityIsIgnored) {
3868 return (widget.accessibilityIsIgnored(id, sel) ? cast(objc.id) 1 : null);
3869 }
3870 return null;
3871 }
3872
3873 static objc.id windowDelegateProc3(objc.id id, objc.SEL sel, objc.id arg0) {
3874 if (sel is OS.sel_timerProc_) {
3875 //TODO optimize getting the display 3715 //TODO optimize getting the display
3876 Display display = getCurrent (); 3716 Display display = getCurrent ();
3877 if (display is null) return null; 3717 if (display is null) return null;
3878 return display.timerProc (id, sel, arg0); 3718 if (sel is OS.sel_isRunning) {
3879 } 3719 return cast(objc.id) (display.isDisposed() ? null : cast(objc.id) 1);
3880 Widget widget = GetWidget(id); 3720 }
3881 if (widget is null && (sel is OS.sel_keyDown_ ||sel is OS.sel_keyUp_ ||sel is OS.sel_insertText_ ||sel is OS.sel_doCommandBySelector_)) { 3721 return null;
3882 widget = GetFocusControl ((new NSView (id)).window ()); 3722 }
3883 } 3723
3884 if (widget is null) return null; 3724 static objc.id applicationProc3(objc.id id, objc.SEL sel, objc.id event) {
3885 if (sel is OS.sel_windowWillClose_) { 3725 //TODO optimize getting the display
3886 widget.windowWillClose(id, sel, arg0); 3726 Display display = getCurrent ();
3887 } else if (sel is OS.sel_drawRect_) { 3727 if (display is null) return null;
3888 NSRect rect = NSRect(); 3728 if (sel is OS.sel_sendEvent_) {
3889 OS.memmove(&rect, arg0, NSRect.sizeof); 3729 display.applicationSendEvent (id, sel, event);
3890 widget.drawRect(id, sel, rect); 3730 return null;
3891 } else if (sel is OS.sel_setFrameOrigin_) { 3731 }
3892 NSPoint point = NSPoint(); 3732 return null;
3893 OS.memmove(&point, arg0, NSPoint.sizeof); 3733 }
3894 widget.setFrameOrigin(id, sel, point); 3734
3895 } else if (sel is OS.sel_setFrameSize_) { 3735 static objc.id applicationProc6(objc.id id, objc.SEL sel, objc.id arg0, objc.id arg1, objc.id arg2, objc.id arg3) {
3896 NSSize size = NSSize(); 3736 //TODO optimize getting the display
3897 OS.memmove(&size, arg0, NSSize.sizeof); 3737 Display display = getCurrent ();
3898 widget.setFrameSize(id, sel, size); 3738 if (display is null) return null;
3899 } else if (sel is OS.sel_hitTest_) { 3739 if (sel is OS.sel_nextEventMatchingMask_untilDate_inMode_dequeue_) {
3900 NSPoint point = NSPoint(); 3740 return display.applicationNextEventMatchingMask(id, sel, arg0, arg1, arg2, arg3);
3901 OS.memmove(&point, arg0, NSPoint.sizeof); 3741 }
3902 return widget.hitTest(id, sel, point); 3742 return null;
3903 } else if (sel is OS.sel_windowShouldClose_) { 3743 }
3904 return widget.windowShouldClose(id, sel, arg0) ? cast(objc.id) 1 : null; 3744
3905 } else if (sel is OS.sel_mouseDown_) { 3745 static objc.id applicationDelegateProc(objc.id id, objc.SEL sel, objc.id arg0) {
3906 widget.mouseDown(id, sel, arg0); 3746 //TODO optimize getting the display
3907 } else if (sel is OS.sel_keyDown_) { 3747 Display display = getCurrent ();
3908 widget.keyDown(id, sel, arg0); 3748 if (display is null) return null;
3909 } else if (sel is OS.sel_keyUp_) { 3749 cocoa.id applicationDelegate = display.applicationDelegate;
3910 widget.keyUp(id, sel, arg0); 3750 NSApplication application = display.application;
3911 } else if (sel is OS.sel_flagsChanged_) { 3751 if (sel is OS.sel_applicationWillFinishLaunching_) {
3912 widget.flagsChanged(id, sel, arg0); 3752 NSDictionary dict = NSDictionary.dictionaryWithObject(applicationDelegate, NSString.stringWith("NSOwner"));
3913 } else if (sel is OS.sel_mouseUp_) { 3753 NSString nibFile = NSString.stringWith("/System/Library/Frameworks/JavaVM.framework/Resources/English.lproj/DefaultApp.nib");
3914 widget.mouseUp(id, sel, arg0); 3754 if (!NSBundle.loadNibFile(nibFile, dict, null)) {
3915 } else if (sel is OS.sel_rightMouseDown_) { 3755 nibFile = NSString.stringWith("/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Resources/English.lproj/DefaultApp.nib");
3916 widget.rightMouseDown(id, sel, arg0); 3756 NSBundle.loadNibFile(nibFile, dict, null);
3917 } else if (sel is OS.sel_rightMouseUp_) { 3757 }
3918 widget.rightMouseUp(id, sel, arg0); 3758 //replace %@ with application name
3919 } else if (sel is OS.sel_otherMouseDown_) { 3759 NSMenu mainmenu = application.mainMenu();
3920 widget.otherMouseDown(id, sel, arg0); 3760 NSMenuItem appitem = mainmenu.itemAtIndex(0);
3921 } else if (sel is OS.sel_otherMouseUp_) { 3761 if (appitem !is null) {
3922 widget.otherMouseUp(id, sel, arg0); 3762 NSMenu sm = appitem.submenu();
3923 } else if (sel is OS.sel_mouseMoved_) { 3763 NSArray ia = sm.itemArray();
3924 widget.mouseMoved(id, sel, arg0); 3764 for(int i = 0; i < ia.count(); i++) {
3925 } else if (sel is OS.sel_mouseDragged_) { 3765 NSMenuItem ni = new NSMenuItem(ia.objectAtIndex(i));
3926 widget.mouseDragged(id, sel, arg0); 3766 NSString title = ni.title().stringByReplacingOccurrencesOfString(NSString.stringWith("%@"), NSString.stringWith(APP_NAME));
3927 } else if (sel is OS.sel_mouseEntered_) { 3767 ni.setTitle(title);
3928 widget.mouseEntered(id, sel, arg0); 3768 }
3929 } else if (sel is OS.sel_mouseExited_) { 3769 }
3930 widget.mouseExited(id, sel, arg0); 3770 } else if (sel is OS.sel_terminate_) {
3931 } else if (sel is OS.sel_menuForEvent_) { 3771 application.terminate(application);
3932 return widget.menuForEvent(id, sel, arg0); 3772 } else if (sel is OS.sel_orderFrontStandardAboutPanel_) {
3933 } else if (sel is OS.sel_numberOfRowsInTableView_) { 3773 // Event event = new Event ();
3934 return cast(objc.id) widget.numberOfRowsInTableView(id, sel, arg0); 3774 // sendEvent (DWT.ABORT, event);
3935 } else if (sel is OS.sel_comboBoxSelectionDidChange_) { 3775 } else if (sel is OS.sel_hideOtherApplications_) {
3936 widget.comboBoxSelectionDidChange(id, sel, arg0); 3776 application.hideOtherApplications(application);
3937 } else if (sel is OS.sel_tableViewSelectionDidChange_) { 3777 } else if (sel is OS.sel_hide_) {
3938 widget.tableViewSelectionDidChange(id, sel, arg0); 3778 application.hide(application);
3939 } else if (sel is OS.sel_windowDidResignKey_) { 3779 } else if (sel is OS.sel_unhideAllApplications_) {
3940 widget.windowDidResignKey(id, sel, arg0); 3780 application.unhideAllApplications(application);
3941 } else if (sel is OS.sel_windowDidBecomeKey_) { 3781 } else if (sel is OS.sel_applicationShouldTerminate_) {
3942 widget.windowDidBecomeKey(id, sel, arg0); 3782 if (!display.disposing) {
3943 } else if (sel is OS.sel_windowDidResize_) { 3783 Event event = new Event ();
3944 widget.windowDidResize(id, sel, arg0); 3784 display.sendEvent (DWT.Close, event);
3945 } else if (sel is OS.sel_windowDidMove_) { 3785 if (event.doit) {
3946 widget.windowDidMove(id, sel, arg0); 3786 return cast(objc.id) OS.NSTerminateNow;
3947 } else if (sel is OS.sel_menuWillOpen_) { 3787 }
3948 widget.menuWillOpen(id, sel, arg0); 3788 }
3949 } else if (sel is OS.sel_menuDidClose_) { 3789 return cast(objc.id) OS.NSTerminateCancel;
3950 widget.menuDidClose(id, sel, arg0); 3790 } else if (sel is OS.sel_applicationWillTerminate_) {
3951 } else if (sel is OS.sel_menuNeedsUpdate_) { 3791 display.dispose();
3952 widget.menuNeedsUpdate(id, sel, arg0); 3792 } else if (sel is OS.sel_applicationWillResignActive_) {
3953 } else if (sel is OS.sel_outlineViewSelectionDidChange_) { 3793 Shell[] shells = display.getShells();
3954 widget.outlineViewSelectionDidChange(id, sel, arg0); 3794 for (int i = 0; i < shells.length; i++) {
3955 } else if (sel is OS.sel_outlineViewItemDidExpand_) { 3795 shells[i].clearLevel();
3956 widget.outlineViewItemDidExpand(id, sel, arg0); 3796 }
3957 } else if (sel is OS.sel_sendEvent_) { 3797 }
3958 widget.windowSendEvent(id, sel, arg0); 3798 return null;
3959 } else if (sel is OS.sel_helpRequested_) { 3799 }
3960 widget.helpRequested(id, sel, arg0); 3800
3961 } else if (sel is OS.sel_scrollWheel_) { 3801 static objc.id dialogProc(objc.id id, objc.SEL sel, objc.id arg0) {
3962 widget.scrollWheel(id, sel, arg0); 3802 void* jniRef;
3963 } else if (sel is OS.sel_pageDown_) { 3803 OS.object_getInstanceVariable(id, SWT_OBJECT, jniRef);
3964 widget.pageDown(id, sel, arg0); 3804 if (jniRef is null) return null;
3965 } else if (sel is OS.sel_pageUp_) { 3805 if (sel is OS.sel_changeColor_) {
3966 widget.pageUp(id, sel, arg0); 3806 ColorDialog dialog = cast(ColorDialog)OS.JNIGetObject(jniRef);
3967 } else if (sel is OS.sel_textViewDidChangeSelection_) { 3807 if (jniRef is null) return null;
3968 widget.textViewDidChangeSelection(id, sel, arg0); 3808 dialog.changeColor(id, sel, arg0);
3969 } else if (sel is OS.sel_textDidChange_) { 3809 } else if (sel is OS.sel_changeFont_) {
3970 widget.textDidChange(id, sel, arg0); 3810 FontDialog dialog = cast(FontDialog)OS.JNIGetObject(jniRef);
3971 } else if (sel is OS.sel_attributedSubstringFromRange_) { 3811 if (dialog is null) return null;
3972 return widget.attributedSubstringFromRange (id, sel, arg0); 3812 dialog.changeFont(id, sel, arg0);
3973 } else if (sel is OS.sel_characterIndexForPoint_) { 3813 } else if (sel is OS.sel_windowWillClose_) {
3974 return cast(objc.id) widget.characterIndexForPoint (id, sel, arg0); 3814 Object object = OS.JNIGetObject(jniRef);
3975 } else if (sel is OS.sel_firstRectForCharacterRange_) { 3815 if (cast(FontDialog) object) {
3976 NSRect rect = widget.firstRectForCharacterRange (id, sel, arg0); 3816 (cast(FontDialog)object).windowWillClose(id, sel, arg0);
3977 /* NOTE that this is freed in C */ 3817 } else if (cast(ColorDialog) object) {
3978 objc.id result = cast(objc.id) OS.malloc (NSRect.sizeof); 3818 (cast(ColorDialog)object).windowWillClose(id, sel, arg0);
3979 OS.memmove (result, &rect, NSRect.sizeof); 3819 }
3980 return result; 3820 }
3981 } else if (sel is OS.sel_insertText_) { 3821 return null;
3982 widget.insertText (id, sel, arg0); 3822 }
3983 } else if (sel is OS.sel_doCommandBySelector_) { 3823
3984 widget.doCommandBySelector (id, sel, cast(char*) arg0); 3824 static objc.id windowDelegateProc2(objc.id id, objc.SEL sel) {
3985 } else if (sel is OS.sel_highlightSelectionInClipRect_) { 3825 Widget widget = GetWidget(id);
3986 widget.highlightSelectionInClipRect (id, sel, arg0); 3826 if (widget is null) return null;
3987 } else if (sel is OS.sel_reflectScrolledClipView_) { 3827 if (sel is OS.sel_sendSelection) {
3988 widget.reflectScrolledClipView (id, sel, arg0); 3828 widget.sendSelection();
3989 } else if (sel is OS.sel_accessibilityHitTest_) { 3829 } else if (sel is OS.sel_sendDoubleSelection) {
3990 NSPoint point = NSPoint(); 3830 widget.sendDoubleSelection();
3991 OS.memmove(&point, arg0, NSPoint.sizeof); 3831 } else if (sel is OS.sel_sendVerticalSelection) {
3992 return widget.accessibilityHitTest(id, sel, point); 3832 widget.sendVerticalSelection();
3993 } else if (sel is OS.sel_accessibilityAttributeValue_) { 3833 } else if (sel is OS.sel_sendHorizontalSelection) {
3994 return widget.accessibilityAttributeValue(id, sel, arg0); 3834 widget.sendHorizontalSelection();
3995 } else if (sel is OS.sel_accessibilityIsAttributeSettable_) { 3835 } else if (sel is OS.sel_acceptsFirstResponder) {
3996 return (widget.accessibilityIsAttributeSettable(id, sel, arg0) ? cast(objc.id) 1 : null); 3836 return widget.acceptsFirstResponder(id, sel) ? cast(objc.id) 1 : null;
3997 } else if (sel is OS.sel_accessibilityPerformAction_) { 3837 } else if (sel is OS.sel_becomeFirstResponder) {
3998 widget.accessibilityPerformAction(id, sel, arg0); 3838 return widget.becomeFirstResponder(id, sel) ? cast(objc.id) 1 : null;
3999 } else if (sel is OS.sel_accessibilityActionDescription_) { 3839 } else if (sel is OS.sel_resignFirstResponder) {
4000 widget.accessibilityActionDescription(id, sel, arg0); 3840 return widget.resignFirstResponder(id, sel) ? cast(objc.id) 1 : null;
4001 } else if (sel is OS.sel_makeFirstResponder_) { 3841 } else if (sel is OS.sel_isFlipped) {
4002 return widget.makeFirstResponder(id, sel, arg0) ? cast(objc.id) 1 : null; 3842 return widget.isFlipped(id, sel) ? cast(objc.id) 1 : null;
4003 } else if (sel is OS.sel_tableViewColumnDidMove_) { 3843 } else if (sel is OS.sel_isOpaque) {
4004 widget.tableViewColumnDidMove(id, sel, arg0); 3844 return widget.isOpaque(id, sel) ? cast(objc.id) 1 : null;
4005 } else if (sel is OS.sel_tableViewColumnDidResize_) { 3845 } else if (sel is OS.sel_unmarkText) {
4006 widget.tableViewColumnDidResize(id, sel, arg0); 3846 //TODO not called?
4007 } else if (sel is OS.sel_outlineViewColumnDidMove_) { 3847 } else if (sel is OS.sel_validAttributesForMarkedText) {
4008 widget.outlineViewColumnDidMove(id, sel, arg0); 3848 return widget.validAttributesForMarkedText (id, sel);
4009 } else if (sel is OS.sel_outlineViewColumnDidResize_) { 3849 } else if (sel is OS.sel_markedRange) {
4010 widget.outlineViewColumnDidResize(id, sel, arg0); 3850 NSRange range = widget.markedRange (id, sel);
4011 } 3851 /* NOTE that this is freed in C */
4012 return null; 3852 objc.id result = cast(objc.id) OS.malloc (NSRange.sizeof);
4013 } 3853 OS.memmove (result, &range, NSRange.sizeof);
4014 3854 return result;
4015 static objc.id windowDelegateProc4(objc.id id, objc.SEL sel, objc.id arg0, objc.id arg1) { 3855 } else if (sel is OS.sel_selectedRange) {
4016 Widget widget = GetWidget(id); 3856 NSRange range = widget.selectedRange (id, sel);
4017 if (widget is null) return null; 3857 /* NOTE that this is freed in C */
4018 if (sel is OS.sel_tabView_willSelectTabViewItem_) { 3858 objc.id result = cast(objc.id) OS.malloc (NSRange.sizeof);
4019 widget.tabView_willSelectTabViewItem(id, sel, arg0, arg1); 3859 OS.memmove (result, &range, NSRange.sizeof);
4020 } else if (sel is OS.sel_tabView_didSelectTabViewItem_) { 3860 return result;
4021 widget.tabView_didSelectTabViewItem(id, sel, arg0, arg1); 3861 } else if (sel is OS.sel_hasMarkedText) {
4022 } else if (sel is OS.sel_outlineView_isItemExpandable_) { 3862 return widget.hasMarkedText (id, sel) ? cast(objc.id) 1 : null;
4023 return widget.outlineView_isItemExpandable(id, sel, arg0, arg1) ? cast(objc.id) 1 : null; 3863 } else if (sel is OS.sel_canBecomeKeyWindow) {
4024 } else if (sel is OS.sel_outlineView_numberOfChildrenOfItem_) { 3864 return widget.canBecomeKeyWindow (id, sel) ? cast(objc.id) 1 : null;
4025 return cast(objc.id) widget.outlineView_numberOfChildrenOfItem(id, sel, arg0, arg1); 3865 } else if (sel is OS.sel_accessibilityActionNames) {
4026 } else if (sel is OS.sel_outlineView_shouldCollapseItem_) { 3866 return widget.accessibilityActionNames(id, sel);
4027 return widget.outlineView_shouldCollapseItem(id, sel, arg0, arg1) ? cast(objc.id) 1 : null; 3867 } else if (sel is OS.sel_accessibilityAttributeNames) {
4028 } else if (sel is OS.sel_outlineView_shouldExpandItem_) { 3868 return widget.accessibilityAttributeNames(id, sel);
4029 return widget.outlineView_shouldExpandItem(id, sel, arg0, arg1) ? cast(objc.id) 1 : null; 3869 } else if (sel is OS.sel_accessibilityParameterizedAttributeNames) {
4030 } else if (sel is OS.sel_menu_willHighlightItem_) { 3870 return widget.accessibilityParameterizedAttributeNames(id, sel);
4031 widget.menu_willHighlightItem(id, sel, arg0, arg1); 3871 } else if (sel is OS.sel_accessibilityFocusedUIElement) {
4032 } else if (sel is OS.sel_setMarkedText_selectedRange_) { 3872 return widget.accessibilityFocusedUIElement(id, sel);
4033 widget.setMarkedText_selectedRange (id, sel, arg0, arg1); 3873 } else if (sel is OS.sel_accessibilityIsIgnored) {
4034 } else if (sel is OS.sel_drawInteriorWithFrame_inView_) { 3874 return (widget.accessibilityIsIgnored(id, sel) ? cast(objc.id) 1 : null);
4035 widget.drawInteriorWithFrame_inView (id, sel, arg0, arg1); 3875 }
4036 } else if (sel is OS.sel_accessibilityAttributeValue_forParameter_) { 3876 return null;
4037 return widget.accessibilityAttributeValue_forParameter(id, sel, arg0, arg1); 3877 }
4038 } else if (sel is OS.sel_tableView_didClickTableColumn_) { 3878
4039 widget.tableView_didClickTableColumn (id, sel, arg0, arg1); 3879 static objc.id windowDelegateProc3(objc.id id, objc.SEL sel, objc.id arg0) {
4040 } else if (sel is OS.sel_outlineView_didClickTableColumn_) { 3880 if (sel is OS.sel_timerProc_) {
4041 widget.outlineView_didClickTableColumn (id, sel, arg0, arg1); 3881 //TODO optimize getting the display
4042 } 3882 Display display = getCurrent ();
4043 return null; 3883 if (display is null) return null;
4044 } 3884 return display.timerProc (id, sel, arg0);
4045 3885 }
4046 static objc.id windowDelegateProc5(objc.id id, objc.SEL sel, objc.id arg0, objc.id arg1, objc.id arg2) { 3886 Widget widget = GetWidget(id);
4047 Widget widget = GetWidget(id); 3887 if (widget is null && (sel is OS.sel_keyDown_ ||sel is OS.sel_keyUp_ ||sel is OS.sel_insertText_ ||sel is OS.sel_doCommandBySelector_)) {
4048 if (widget is null) return null; 3888 widget = GetFocusControl ((new NSView (id)).window ());
4049 if (sel is OS.sel_tableView_objectValueForTableColumn_row_) { 3889 }
4050 return widget.tableView_objectValueForTableColumn_row(id, sel, arg0, arg1, arg2); 3890 if (widget is null) return null;
4051 } else if (sel is OS.sel_tableView_shouldEditTableColumn_row_) { 3891 if (sel is OS.sel_windowWillClose_) {
4052 return widget.tableView_shouldEditTableColumn_row(id, sel, arg0, arg1, arg2) ? cast(objc.id) 1 : null; 3892 widget.windowWillClose(id, sel, arg0);
4053 } else if (sel is OS.sel_textView_clickedOnLink_atIndex_) { 3893 } else if (sel is OS.sel_drawRect_) {
4054 return widget.textView_clickOnLink_atIndex(id, sel, arg0, arg1, arg2) ? cast(objc.id) 1 : null; 3894 NSRect rect = NSRect();
4055 } else if (sel is OS.sel_outlineView_child_ofItem_) { 3895 OS.memmove(&rect, arg0, NSRect.sizeof);
4056 return widget.outlineView_child_ofItem(id, sel, arg0, arg1, arg2); 3896 widget.drawRect(id, sel, rect);
4057 } else if (sel is OS.sel_outlineView_objectValueForTableColumn_byItem_) { 3897 } else if (sel is OS.sel_setFrameOrigin_) {
4058 return widget.outlineView_objectValueForTableColumn_byItem(id, sel, arg0, arg1, arg2); 3898 NSPoint point = NSPoint();
4059 } else if (sel is OS.sel_textView_willChangeSelectionFromCharacterRange_toCharacterRange_) { 3899 OS.memmove(&point, arg0, NSPoint.sizeof);
4060 NSRange range = widget.textView_willChangeSelectionFromCharacterRange_toCharacterRange(id, sel, arg0, arg1, arg2); 3900 widget.setFrameOrigin(id, sel, point);
4061 /* NOTE that this is freed in C */ 3901 } else if (sel is OS.sel_setFrameSize_) {
4062 objc.id result = cast(objc.id) OS.malloc (NSRange.sizeof); 3902 NSSize size = NSSize();
4063 OS.memmove (result, &range, NSRange.sizeof); 3903 OS.memmove(&size, arg0, NSSize.sizeof);
4064 return result; 3904 widget.setFrameSize(id, sel, size);
4065 } 3905 } else if (sel is OS.sel_hitTest_) {
4066 return null; 3906 NSPoint point = NSPoint();
4067 } 3907 OS.memmove(&point, arg0, NSPoint.sizeof);
4068 3908 return widget.hitTest(id, sel, point);
4069 static objc.id windowDelegateProc6(objc.id id, objc.SEL sel, objc.id arg0, objc.id arg1, objc.id arg2, objc.id arg3) { 3909 } else if (sel is OS.sel_windowShouldClose_) {
4070 Widget widget = GetWidget(id); 3910 return widget.windowShouldClose(id, sel, arg0) ? cast(objc.id) 1 : null;
4071 if (widget is null) return null; 3911 } else if (sel is OS.sel_mouseDown_) {
4072 if (sel is OS.sel_tableView_willDisplayCell_forTableColumn_row_) { 3912 widget.mouseDown(id, sel, arg0);
4073 widget.tableView_willDisplayCell_forTableColumn_row(id, sel, arg0, arg1, arg2, arg3); 3913 } else if (sel is OS.sel_keyDown_) {
4074 } else if (sel is OS.sel_outlineView_willDisplayCell_forTableColumn_item_) { 3914 widget.keyDown(id, sel, arg0);
4075 widget.outlineView_willDisplayCell_forTableColumn_item(id, sel, arg0, arg1, arg2, arg3); 3915 } else if (sel is OS.sel_keyUp_) {
4076 } else if (sel is OS.sel_outlineView_setObjectValue_forTableColumn_byItem_) { 3916 widget.keyUp(id, sel, arg0);
4077 widget.outlineView_setObjectValue_forTableColumn_byItem(id, sel, arg0, arg1, arg2, arg3); 3917 } else if (sel is OS.sel_flagsChanged_) {
4078 } else if (sel is OS.sel_tableView_setObjectValue_forTableColumn_row_) { 3918 widget.flagsChanged(id, sel, arg0);
4079 widget.tableView_setObjectValue_forTableColumn_row(id, sel, arg0, arg1, arg2, arg3); 3919 } else if (sel is OS.sel_mouseUp_) {
4080 } 3920 widget.mouseUp(id, sel, arg0);
4081 return null; 3921 } else if (sel is OS.sel_rightMouseDown_) {
4082 } 3922 widget.rightMouseDown(id, sel, arg0);
4083 } 3923 } else if (sel is OS.sel_rightMouseUp_) {
3924 widget.rightMouseUp(id, sel, arg0);
3925 } else if (sel is OS.sel_otherMouseDown_) {
3926 widget.otherMouseDown(id, sel, arg0);
3927 } else if (sel is OS.sel_otherMouseUp_) {
3928 widget.otherMouseUp(id, sel, arg0);
3929 } else if (sel is OS.sel_mouseMoved_) {
3930 widget.mouseMoved(id, sel, arg0);
3931 } else if (sel is OS.sel_mouseDragged_) {
3932 widget.mouseDragged(id, sel, arg0);
3933 } else if (sel is OS.sel_mouseEntered_) {
3934 widget.mouseEntered(id, sel, arg0);
3935 } else if (sel is OS.sel_mouseExited_) {
3936 widget.mouseExited(id, sel, arg0);
3937 } else if (sel is OS.sel_menuForEvent_) {
3938 return widget.menuForEvent(id, sel, arg0);
3939 } else if (sel is OS.sel_numberOfRowsInTableView_) {
3940 return cast(objc.id) widget.numberOfRowsInTableView(id, sel, arg0);
3941 } else if (sel is OS.sel_comboBoxSelectionDidChange_) {
3942 widget.comboBoxSelectionDidChange(id, sel, arg0);
3943 } else if (sel is OS.sel_tableViewSelectionDidChange_) {
3944 widget.tableViewSelectionDidChange(id, sel, arg0);
3945 } else if (sel is OS.sel_windowDidResignKey_) {
3946 widget.windowDidResignKey(id, sel, arg0);
3947 } else if (sel is OS.sel_windowDidBecomeKey_) {
3948 widget.windowDidBecomeKey(id, sel, arg0);
3949 } else if (sel is OS.sel_windowDidResize_) {
3950 widget.windowDidResize(id, sel, arg0);
3951 } else if (sel is OS.sel_windowDidMove_) {
3952 widget.windowDidMove(id, sel, arg0);
3953 } else if (sel is OS.sel_menuWillOpen_) {
3954 widget.menuWillOpen(id, sel, arg0);
3955 } else if (sel is OS.sel_menuDidClose_) {
3956 widget.menuDidClose(id, sel, arg0);
3957 } else if (sel is OS.sel_menuNeedsUpdate_) {
3958 widget.menuNeedsUpdate(id, sel, arg0);
3959 } else if (sel is OS.sel_outlineViewSelectionDidChange_) {
3960 widget.outlineViewSelectionDidChange(id, sel, arg0);
3961 } else if (sel is OS.sel_outlineViewItemDidExpand_) {
3962 widget.outlineViewItemDidExpand(id, sel, arg0);
3963 } else if (sel is OS.sel_sendEvent_) {
3964 widget.windowSendEvent(id, sel, arg0);
3965 } else if (sel is OS.sel_helpRequested_) {
3966 widget.helpRequested(id, sel, arg0);
3967 } else if (sel is OS.sel_scrollWheel_) {
3968 widget.scrollWheel(id, sel, arg0);
3969 } else if (sel is OS.sel_pageDown_) {
3970 widget.pageDown(id, sel, arg0);
3971 } else if (sel is OS.sel_pageUp_) {
3972 widget.pageUp(id, sel, arg0);
3973 } else if (sel is OS.sel_textViewDidChangeSelection_) {
3974 widget.textViewDidChangeSelection(id, sel, arg0);
3975 } else if (sel is OS.sel_textDidChange_) {
3976 widget.textDidChange(id, sel, arg0);
3977 } else if (sel is OS.sel_attributedSubstringFromRange_) {
3978 return widget.attributedSubstringFromRange (id, sel, arg0);
3979 } else if (sel is OS.sel_characterIndexForPoint_) {
3980 return cast(objc.id) widget.characterIndexForPoint (id, sel, arg0);
3981 } else if (sel is OS.sel_firstRectForCharacterRange_) {
3982 NSRect rect = widget.firstRectForCharacterRange (id, sel, arg0);
3983 /* NOTE that this is freed in C */
3984 objc.id result = cast(objc.id) OS.malloc (NSRect.sizeof);
3985 OS.memmove (result, &rect, NSRect.sizeof);
3986 return result;
3987 } else if (sel is OS.sel_insertText_) {
3988 widget.insertText (id, sel, arg0);
3989 } else if (sel is OS.sel_doCommandBySelector_) {
3990 widget.doCommandBySelector (id, sel, cast(char*) arg0);
3991 } else if (sel is OS.sel_highlightSelectionInClipRect_) {
3992 widget.highlightSelectionInClipRect (id, sel, arg0);
3993 } else if (sel is OS.sel_reflectScrolledClipView_) {
3994 widget.reflectScrolledClipView (id, sel, arg0);
3995 } else if (sel is OS.sel_accessibilityHitTest_) {
3996 NSPoint point = NSPoint();
3997 OS.memmove(&point, arg0, NSPoint.sizeof);
3998 return widget.accessibilityHitTest(id, sel, point);
3999 } else if (sel is OS.sel_accessibilityAttributeValue_) {
4000 return widget.accessibilityAttributeValue(id, sel, arg0);
4001 } else if (sel is OS.sel_accessibilityIsAttributeSettable_) {
4002 return (widget.accessibilityIsAttributeSettable(id, sel, arg0) ? cast(objc.id) 1 : null);
4003 } else if (sel is OS.sel_accessibilityPerformAction_) {
4004 widget.accessibilityPerformAction(id, sel, arg0);
4005 } else if (sel is OS.sel_accessibilityActionDescription_) {
4006 widget.accessibilityActionDescription(id, sel, arg0);
4007 } else if (sel is OS.sel_makeFirstResponder_) {
4008 return widget.makeFirstResponder(id, sel, arg0) ? cast(objc.id) 1 : null;
4009 } else if (sel is OS.sel_tableViewColumnDidMove_) {
4010 widget.tableViewColumnDidMove(id, sel, arg0);
4011 } else if (sel is OS.sel_tableViewColumnDidResize_) {
4012 widget.tableViewColumnDidResize(id, sel, arg0);
4013 } else if (sel is OS.sel_outlineViewColumnDidMove_) {
4014 widget.outlineViewColumnDidMove(id, sel, arg0);
4015 } else if (sel is OS.sel_outlineViewColumnDidResize_) {
4016 widget.outlineViewColumnDidResize(id, sel, arg0);
4017 }
4018 return null;
4019 }
4020
4021 static objc.id windowDelegateProc4(objc.id id, objc.SEL sel, objc.id arg0, objc.id arg1) {
4022 Widget widget = GetWidget(id);
4023 if (widget is null) return null;
4024 if (sel is OS.sel_tabView_willSelectTabViewItem_) {
4025 widget.tabView_willSelectTabViewItem(id, sel, arg0, arg1);
4026 } else if (sel is OS.sel_tabView_didSelectTabViewItem_) {
4027 widget.tabView_didSelectTabViewItem(id, sel, arg0, arg1);
4028 } else if (sel is OS.sel_outlineView_isItemExpandable_) {
4029 return widget.outlineView_isItemExpandable(id, sel, arg0, arg1) ? cast(objc.id) 1 : null;
4030 } else if (sel is OS.sel_outlineView_numberOfChildrenOfItem_) {
4031 return cast(objc.id) widget.outlineView_numberOfChildrenOfItem(id, sel, arg0, arg1);
4032 } else if (sel is OS.sel_outlineView_shouldCollapseItem_) {
4033 return widget.outlineView_shouldCollapseItem(id, sel, arg0, arg1) ? cast(objc.id) 1 : null;
4034 } else if (sel is OS.sel_outlineView_shouldExpandItem_) {
4035 return widget.outlineView_shouldExpandItem(id, sel, arg0, arg1) ? cast(objc.id) 1 : null;
4036 } else if (sel is OS.sel_menu_willHighlightItem_) {
4037 widget.menu_willHighlightItem(id, sel, arg0, arg1);
4038 } else if (sel is OS.sel_setMarkedText_selectedRange_) {
4039 widget.setMarkedText_selectedRange (id, sel, arg0, arg1);
4040 } else if (sel is OS.sel_drawInteriorWithFrame_inView_) {
4041 widget.drawInteriorWithFrame_inView (id, sel, arg0, arg1);
4042 } else if (sel is OS.sel_accessibilityAttributeValue_forParameter_) {
4043 return widget.accessibilityAttributeValue_forParameter(id, sel, arg0, arg1);
4044 } else if (sel is OS.sel_tableView_didClickTableColumn_) {
4045 widget.tableView_didClickTableColumn (id, sel, arg0, arg1);
4046 } else if (sel is OS.sel_outlineView_didClickTableColumn_) {
4047 widget.outlineView_didClickTableColumn (id, sel, arg0, arg1);
4048 }
4049 return null;
4050 }
4051
4052 static objc.id windowDelegateProc5(objc.id id, objc.SEL sel, objc.id arg0, objc.id arg1, objc.id arg2) {
4053 Widget widget = GetWidget(id);
4054 if (widget is null) return null;
4055 if (sel is OS.sel_tableView_objectValueForTableColumn_row_) {
4056 return widget.tableView_objectValueForTableColumn_row(id, sel, arg0, arg1, arg2);
4057 } else if (sel is OS.sel_tableView_shouldEditTableColumn_row_) {
4058 return widget.tableView_shouldEditTableColumn_row(id, sel, arg0, arg1, arg2) ? cast(objc.id) 1 : null;
4059 } else if (sel is OS.sel_textView_clickedOnLink_atIndex_) {
4060 return widget.textView_clickOnLink_atIndex(id, sel, arg0, arg1, arg2) ? cast(objc.id) 1 : null;
4061 } else if (sel is OS.sel_outlineView_child_ofItem_) {
4062 return widget.outlineView_child_ofItem(id, sel, arg0, arg1, arg2);
4063 } else if (sel is OS.sel_outlineView_objectValueForTableColumn_byItem_) {
4064 return widget.outlineView_objectValueForTableColumn_byItem(id, sel, arg0, arg1, arg2);
4065 } else if (sel is OS.sel_textView_willChangeSelectionFromCharacterRange_toCharacterRange_) {
4066 NSRange range = widget.textView_willChangeSelectionFromCharacterRange_toCharacterRange(id, sel, arg0, arg1, arg2);
4067 /* NOTE that this is freed in C */
4068 objc.id result = cast(objc.id) OS.malloc (NSRange.sizeof);
4069 OS.memmove (result, &range, NSRange.sizeof);
4070 return result;
4071 }
4072 return null;
4073 }
4074
4075 static objc.id windowDelegateProc6(objc.id id, objc.SEL sel, objc.id arg0, objc.id arg1, objc.id arg2, objc.id arg3) {
4076 Widget widget = GetWidget(id);
4077 if (widget is null) return null;
4078 if (sel is OS.sel_tableView_willDisplayCell_forTableColumn_row_) {
4079 widget.tableView_willDisplayCell_forTableColumn_row(id, sel, arg0, arg1, arg2, arg3);
4080 } else if (sel is OS.sel_outlineView_willDisplayCell_forTableColumn_item_) {
4081 widget.outlineView_willDisplayCell_forTableColumn_item(id, sel, arg0, arg1, arg2, arg3);
4082 } else if (sel is OS.sel_outlineView_setObjectValue_forTableColumn_byItem_) {
4083 widget.outlineView_setObjectValue_forTableColumn_byItem(id, sel, arg0, arg1, arg2, arg3);
4084 } else if (sel is OS.sel_tableView_setObjectValue_forTableColumn_row_) {
4085 widget.tableView_setObjectValue_forTableColumn_row(id, sel, arg0, arg1, arg2, arg3);
4086 }
4087 return null;
4088 }
4089 }