### Eclipse Workspace Patch 1.0 #P org.eclipse.swt 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 19 Feb 2008 22:36:22 -0000 @@ -114,6 +114,7 @@ NSPoint cascade = new NSPoint(); + int jniRef; Callback windowDelegateCallback2, windowDelegateCallback3, windowDelegateCallback4, windowDelegateCallback5; Callback windowDelegateCallback6; Callback dialogCallback3; @@ -227,11 +228,14 @@ Runnable timerList []; NSTimer nsTimers []; SWTWindowDelegate timerDelegate = (SWTWindowDelegate)new SWTWindowDelegate().alloc().init(); + SWTApplicationDelegate applicationDelegate; /* Display Data */ Object data; String [] keys; Object [] values; + private Callback applicationDelegateCallback3; + private Callback applicationDelegateCallback2; /* * TEMPORARY CODE. Install the runnable that @@ -629,6 +633,8 @@ pool = (NSAutoreleasePool)new NSAutoreleasePool().alloc().init(); application = NSApplication.sharedApplication(); + jniRef = OS.NewGlobalRef(this); + if (jniRef == 0) error (SWT.ERROR_NO_HANDLES); } static void deregister (Display display) { @@ -659,6 +665,8 @@ if (pool != null) pool.release(); pool = null; application = null; + if (jniRef != 0) OS.DeleteGlobalRef(jniRef); + jniRef = 0; } /** @@ -1517,6 +1525,14 @@ protected void init () { super.init (); initClasses (); + initApplicationDelegate(); + application.finishLaunching(); +} + +void initApplicationDelegate() { + applicationDelegate = (SWTApplicationDelegate)new SWTApplicationDelegate().alloc().init(); + applicationDelegate.setTag(jniRef); + application.setDelegate(applicationDelegate); } void initClasses () { @@ -1524,6 +1540,13 @@ int dialogProc3 = dialogCallback3.getAddress(); if (dialogProc3 == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); + applicationDelegateCallback3 = new Callback(this, "applicationDelegateProc", 3); + int appProc3 = applicationDelegateCallback3.getAddress(); + if (appProc3 == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); + applicationDelegateCallback2 = new Callback(this, "applicationDelegateProc", 2); + int appProc2 = applicationDelegateCallback2.getAddress(); + if (appProc2 == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); + windowDelegateCallback3 = new Callback(this, "windowDelegateProc", 3); int proc3 = windowDelegateCallback3.getAddress(); if (proc3 == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); @@ -1542,13 +1565,27 @@ int drawRectProc = OS.drawRect_CALLBACK(proc3); - String className = "SWTWindowDelegate"; + String className = "SWTApplicationDelegate"; int cls = OS.objc_allocateClassPair(OS.class_NSObject, className, 0); OS.class_addIvar(cls, "tag", OS.PTR_SIZEOF, (byte)(Math.log(OS.PTR_SIZEOF) / Math.log(2)), "i"); + OS.class_addMethod(cls, OS.sel_tag, proc2, "@:"); + OS.class_addMethod(cls, OS.sel_setTag_1, proc3, "@:i"); + OS.class_addMethod(cls, OS.sel_applicationWillFinishLaunching_1, appProc3, "@:@"); + OS.class_addMethod(cls, OS.sel_terminate_1, appProc3, "@:@"); + OS.class_addMethod(cls, OS.sel_terminate, appProc2, "@:"); + OS.class_addMethod(cls, OS.sel_orderFrontStandardAboutPanel_1, appProc3, "@:@"); + OS.class_addMethod(cls, OS.sel_hideOtherApplications_1, appProc3, "@:@"); + OS.class_addMethod(cls, OS.sel_hide_1, appProc3, "@:@"); + OS.class_addMethod(cls, OS.sel_unhideAllApplications_1, appProc3, "@:@"); + OS.class_addMethod(cls, OS.sel_applicationShouldTerminate_1, appProc3, "@:@"); + OS.objc_registerClassPair(cls); + + className = "SWTWindowDelegate"; + cls = OS.objc_allocateClassPair(OS.class_NSObject, className, 0); + OS.class_addIvar(cls, "tag", OS.PTR_SIZEOF, (byte)(Math.log(OS.PTR_SIZEOF) / Math.log(2)), "i"); OS.class_addMethod(cls, OS.sel_windowDidResize_1, proc3, "@:@"); OS.class_addMethod(cls, OS.sel_windowShouldClose_1, proc3, "@:@"); OS.class_addMethod(cls, OS.sel_windowWillClose_1, proc3, "@:@"); - OS.class_addMethod(cls, OS.sel_windowWillClose_1, proc3, "@:@"); OS.class_addMethod(cls, OS.sel_windowDidResignKey_1, proc3, "@:@"); OS.class_addMethod(cls, OS.sel_windowDidBecomeKey_1, proc3, "@:@"); OS.class_addMethod(cls, OS.sel_tag, proc2, "@:"); @@ -2940,6 +2977,50 @@ object.performSelectorOnMainThread_withObject_waitUntilDone_(OS.sel_release, null, false); } +int applicationDelegateProc(int delegate, int sel) { + if (sel == OS.sel_finishLaunching) { + System.out.println("finish!"); + } + if (sel == OS.sel_terminate) { + System.out.println("terminate!"); + } + return 0; +} + +int applicationDelegateProc(int id, int sel, int arg0) { + if (sel == OS.sel_applicationWillFinishLaunching_1) { + String fileName = "/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Resources/English.lproj/DefaultApp.nib"; + int length = fileName.length(); + char[] chars = new char[length]; + fileName.getChars(0, length, chars, 0); + NSString filestr = NSString.stringWithCharacters(chars, length); + + String text = "NSOwner"; + length = text.length(); + chars = new char[length]; + text.getChars(0, length, chars, 0); + NSString str = NSString.stringWithCharacters(chars, length); + + id dict = NSDictionary.dictionaryWithObject(applicationDelegate, str); + NSBundle.loadNibFile(filestr, dict, null); + } else if (sel == OS.sel_terminate_1) { + System.out.println("sel_terminate_1"); + if ( !disposing ){ + Event event = new Event(); + sendEvent(SWT.Close, event); + if ( event.doit ) { + dispose(); + System.exit(0); + } + } + } else if (sel == OS.sel_orderFrontStandardAboutPanel_1) { + System.out.println("sel_orderFrontStandardAboutPanel_1"); + } else if (sel == OS.sel_hideOtherApplications_1) { + System.out.println("sel_hideOtherApplications_1"); + } else if (sel == OS.sel_hide_1) { + System.out.println("sel_hide_1"); + } else if (sel == OS.sel_unhideAllApplications_1) { + System.out.println("sel_unhideAllApplications_1"); + } else if (sel == OS.sel_applicationShouldTerminate_1) { + System.out.println("OS.sel_applicationShouldTerminate_1"); + } else { + System.out.println("window delegate proc sel = " + sel); + } + return 0; +} + int dialogProc(int id, int sel, int arg0) { int jniRef = OS.objc_msgSend(id, OS.sel_tag); if (jniRef == 0 || jniRef == -1) return 0; Index: Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSBundle.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSBundle.java,v retrieving revision 1.3 diff -u -r1.3 NSBundle.java --- Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSBundle.java 19 Nov 2007 15:45:20 -0000 1.3 +++ Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSBundle.java 19 Feb 2008 22:36:22 -0000 @@ -213,4 +213,8 @@ return OS.objc_msgSend(this.id, OS.sel_unload) != 0; } +public static boolean loadNibFile(id fileName, id dict, id zone) { + return OS.objc_msgSend(OS.class_NSBundle, OS.sel_loadNibFile_1externalNameTable_1withZone_1, fileName.id, dict.id, 0) != 0; +} + } 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,21 @@ +package org.eclipse.swt.internal.cocoa; + +public class SWTApplicationDelegate extends NSObject { + + public SWTApplicationDelegate() { + super(0); + } + + public SWTApplicationDelegate(int id) { + super(id); + } + + public int tag() { + return OS.objc_msgSend(id, OS.sel_tag); + } + + public void setTag(int tag) { + OS.objc_msgSend(id, OS.sel_setTag_1, tag); + } + +}