Index: Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java,v retrieving revision 1.14 diff -u -r1.14 Display.java --- Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java 3 Dec 2007 17:17:53 -0000 1.14 +++ Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java 29 Jan 2008 09:12:31 -0000 @@ -1749,6 +1749,15 @@ OS.class_addMethod(cls, OS.sel_menuForEvent_1, proc3, "@:@"); OS.class_addMethod(cls, OS.sel_textView_1clickedOnLink_1atIndex_1, proc5, "@:@@i"); OS.objc_registerClassPair(cls); + + className = "SWTApplicationDelegate"; + cls = OS.objc_allocateClassPair(OS.class_NSObject, className, 0); + OS.class_addMethod(cls, OS.sel_handleAppleEvent_1withReplyEvent_1, proc4, "@:@@"); + OS.objc_registerClassPair(cls); + + SWTApplicationDelegate applicationDelegate = (SWTApplicationDelegate) new SWTApplicationDelegate().alloc().init(); + NSAppleEventManager manager = NSAppleEventManager.sharedAppleEventManager(); + manager.setEventHandler(applicationDelegate, OS.sel_handleAppleEvent_1withReplyEvent_1, OS.kCoreEventClass, OS.kAEQuitApplication); } /** @@ -3067,8 +3076,23 @@ return 0; } +int coreEventProc (int inevent, int replyEvent) { + if(!disposing) { + Event event = new Event (); + sendEvent (SWT.Close, event); + if (event.doit) { + dispose (); + } + } + + return 0; +} int windowDelegateProc(int delegate, int sel, int arg0, int arg1) { + if(sel == OS.sel_handleAppleEvent_1withReplyEvent_1) { + return coreEventProc(arg0, arg1); + } + int jniRef = OS.objc_msgSend(delegate, OS.sel_tag); if (jniRef == 0 || jniRef == -1) return 0; Widget widget = (Widget)OS.JNIGetObject(jniRef); Index: Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/OS.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/OS.java,v retrieving revision 1.9 diff -u -r1.9 OS.java --- Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/OS.java 3 Dec 2007 17:17:53 -0000 1.9 +++ Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/OS.java 29 Jan 2008 09:04:30 -0000 @@ -33,7 +33,9 @@ public static final int kAlertCautionIcon = ('c'<<24) + ('a'<<16) + ('u'<<8) + 't'; public static final int kAlertNoteIcon = ('n'<<24) + ('o'<<16) + ('t'<<8) + 'e'; public static final int kAlertStopIcon = ('s'<<24) + ('t'<<16) + ('o'<<8) + 'p'; - + public static final int kCoreEventClass = ('a'<<24) + ('e'<<16) + ('v'<<8) + 't'; + public static final int kAEQuitApplication = ('q'<<24) + ('u'<<16) + ('i'<<8) + 't'; + public static final int sel_sendSelection = sel_registerName("sendSelection"); public static final int sel_sendDoubleSelection = sel_registerName("sendDoubleSelection"); public static final int sel_sendVerticalSelection = sel_registerName("sendVerticalSelection"); @@ -6827,6 +6829,7 @@ public static final int sel_AMSymbol = sel_registerName("AMSymbol"); public static final int sel_valueWraps = sel_registerName("valueWraps"); public static final int sel_allCredentials = sel_registerName("allCredentials"); +public static final int sel_handleAppleEvent_1withReplyEvent_1 = sel_registerName("handleAppleEvent:withReplyEvent:"); /** Constants */ public static final int NSAWTEventType = 16; Index: Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/SWTApplicationDelegate.java =================================================================== RCS file: Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/SWTApplicationDelegate.java diff -N Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/SWTApplicationDelegate.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/SWTApplicationDelegate.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,11 @@ +package org.eclipse.swt.internal.cocoa; + +public class SWTApplicationDelegate extends NSObject { + public SWTApplicationDelegate() { + super(0); + } + + public SWTApplicationDelegate(int id) { + super(id); + } +}