### Eclipse Workspace Patch 1.0 #P org.eclipse.equinox.executable #P org.eclipse.swt Index: Eclipse SWT PI/carbon/library/os.c =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.swt/Eclipse SWT PI/carbon/library/os.c,v retrieving revision 1.137 diff -u -r1.137 os.c --- Eclipse SWT PI/carbon/library/os.c 5 Nov 2007 21:25:28 -0000 1.137 +++ Eclipse SWT PI/carbon/library/os.c 21 Nov 2007 06:46:51 -0000 @@ -15,6 +15,38 @@ #define OS_NATIVE(func) Java_org_eclipse_swt_internal_carbon_OS_##func +#ifndef NO_AEGetParamDesc +JNIEXPORT jint JNICALL OS_NATIVE(AEGetParamDesc) + (JNIEnv *env, jclass that, jint theAppleEvent, jint theAEKeyword, jint desiredType, jobject result) +{ + AEDesc _result, *lpresult=NULL; + jint rc = 0; + OS_NATIVE_ENTER(env, that, AEGetParamDesc_FUNC); + if (result) if ((lpresult = getAEDescFields(env, result, &_result)) == NULL) goto fail; + rc = (jint)AEGetParamDesc((const AppleEvent *)theAppleEvent, (AEKeyword)theAEKeyword, (DescType)desiredType, (AEDescList *)lpresult); + +fail: + if (result && lpresult) setAEDescFields(env, result, lpresult); + OS_NATIVE_EXIT(env, that, AEGetParamDesc_FUNC); + return rc; +} +#endif + +#ifndef NO_AEDisposeDesc +JNIEXPORT jint JNICALL OS_NATIVE(AEDisposeDesc) +(JNIEnv *env, jclass that, jobject theAEDesc) +{ + AEDesc _theAEDesc, *lptheAEDesc=NULL; + jint rc = 0; + OS_NATIVE_ENTER(env, that, AEDisposeDesc_FUNC); + if (theAEDesc) if ((lptheAEDesc = getAEDescFields(env, theAEDesc, &_theAEDesc)) == NULL) goto fail; + rc = AEDisposeDesc((AEDesc *)lptheAEDesc); +fail: + OS_NATIVE_EXIT(env, that, AEDisposeDesc_FUNC); + return rc; +} +#endif + #ifndef NO_AECountItems JNIEXPORT jint JNICALL OS_NATIVE(AECountItems) (JNIEnv *env, jclass that, jobject arg0, jintArray arg1) Index: Eclipse SWT PI/carbon/library/os_stats.h =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.swt/Eclipse SWT PI/carbon/library/os_stats.h,v retrieving revision 1.103 diff -u -r1.103 os_stats.h --- Eclipse SWT PI/carbon/library/os_stats.h 5 Nov 2007 21:25:28 -0000 1.103 +++ Eclipse SWT PI/carbon/library/os_stats.h 21 Nov 2007 06:46:54 -0000 @@ -25,6 +25,8 @@ #endif typedef enum { + AEGetParamDesc_FUNC, + AEDisposeDesc_FUNC, AECountItems_FUNC, AEGetNthPtr_FUNC, AEInstallEventHandler_FUNC, Index: Eclipse SWT PI/carbon/library/os_stats.c =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.swt/Eclipse SWT PI/carbon/library/os_stats.c,v retrieving revision 1.103 diff -u -r1.103 os_stats.c --- Eclipse SWT PI/carbon/library/os_stats.c 5 Nov 2007 21:25:28 -0000 1.103 +++ Eclipse SWT PI/carbon/library/os_stats.c 21 Nov 2007 06:46:52 -0000 @@ -14,9 +14,11 @@ #ifdef NATIVE_STATS -int OS_nativeFunctionCount = 943; -int OS_nativeFunctionCallCount[943]; +int OS_nativeFunctionCount = 945; +int OS_nativeFunctionCallCount[945]; char * OS_nativeFunctionNames[] = { + "AEGetParamDesc", + "AEDisposeDesc", "AECountItems", "AEGetNthPtr", "AEInstallEventHandler", Index: Eclipse SWT/common/org/eclipse/swt/SWT.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWT.java,v retrieving revision 1.144 diff -u -r1.144 SWT.java --- Eclipse SWT/common/org/eclipse/swt/SWT.java 5 Nov 2007 18:44:26 -0000 1.144 +++ Eclipse SWT/common/org/eclipse/swt/SWT.java 21 Nov 2007 06:47:20 -0000 @@ -610,6 +610,22 @@ * @since 3.2 */ public static final int PaintItem = 42; + + /** + * The external open event type (value is 43). + *

+ * The external open event is sent when an operating system + * notifies the application that the user would like to open + * a set of files (for instance, by double-clicking on the + * files in the operating system's file management app). + *

+ * + * @see org.eclipse.swt.widgets.Display#addListener + * @see org.eclipse.swt.widgets.Event + * + * @since 3.4 + */ + public static final int ExternalOpen = 43; /** * The IME composition event type (value is 43). Index: Eclipse SWT PI/carbon/org/eclipse/swt/internal/carbon/OS.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.swt/Eclipse SWT PI/carbon/org/eclipse/swt/internal/carbon/OS.java,v retrieving revision 1.281 diff -u -r1.281 OS.java --- Eclipse SWT PI/carbon/org/eclipse/swt/internal/carbon/OS.java 20 Nov 2007 15:32:54 -0000 1.281 +++ Eclipse SWT PI/carbon/org/eclipse/swt/internal/carbon/OS.java 21 Nov 2007 06:47:07 -0000 @@ -13,7 +13,8 @@ package org.eclipse.swt.internal.carbon; -import org.eclipse.swt.internal.*; +import org.eclipse.swt.internal.C; +import org.eclipse.swt.internal.Library; public class OS extends C { static { @@ -57,11 +58,15 @@ public static final int kActivateAndHandleClick = 3; public static final int kAppearanceEventClass = ('a'<<24) + ('p'<<16) + ('p'<<8) + 'r'; public static final int kAEAppearanceChanged = ('t'<<24) + ('h'<<16) + ('m'<<8) + 'e'; + public static final int kAEOpenApplication = ('o' << 24) + ('a' << 16) + ('p' << 8) + 'p'; + public static final int kAEOpenDocuments = ('o' << 24) + ('d' << 16) + ('o' << 8) + 'c'; + public static final int kAEReopenApplication = ('r' << 24) + ('a' << 16) + ('p' << 8) + 'p'; public static final int kAESystemFontChanged = ('s'<<24) + ('y'<<16) + ('s'<<8) + 'f'; public static final int kAESmallSystemFontChanged = ('s'<<24) + ('s'<<16) + ('f'<<8) + 'n'; public static final int kAEViewsFontChanged = ('v'<<24) + ('f'<<16) + ('n'<<8) + 't'; public static final int kAEQuitApplication = ('q'<<24) + ('u'<<16) + ('i'<<8) + 't'; public static final int kCoreEventClass = ('a'<<24) + ('e'<<16) + ('v'<<8) + 't'; + public static final int kURLEventClass = ('G'<<24) + ('U'<<16) + ('R'<<8) + 'L'; public static final int kAlertCautionAlert = 2; public static final int kAlertCautionIcon = ('c'<<24) + ('a'<<16) + ('u'<<8) + 't'; public static final int kAlertNoteAlert = 1; @@ -959,6 +964,7 @@ public static final int teJustLeft = 0; public static final int teJustCenter = 1; public static final int teJustRight = -1; + public static final int typeAEList = ('l'<<24) + ('i'<<16) + ('s'<<8) + 't'; public static final int typeBoolean = ('b'<<24) + ('o'<<16) + ('o'<<8) + 'l'; public static final int typeCFDictionaryRef = ('c'<<24) + ('f'<<16) + ('d'<<8) + 'c'; public static final int typeCFMutableArrayRef = ('c'<<24) + ('f'<<16) + ('m'<<8) + 'a'; @@ -1023,6 +1029,8 @@ public static final native int kPMGraphicsContextCoreGraphics(); public static final native int ActiveNonFloatingWindow(); public static final native int ActivateTSMDocument(int idocID); +public static final native int AEGetParamDesc(int theAppleEvent, int theAEKeyword, int desiredType, AEDesc result); +public static final native int AEDisposeDesc(AEDesc theAEDesc); public static final native int AECountItems(AEDesc theAEDescList, int[] theCount); public static final native int AEGetNthPtr(AEDesc theAEDescList, int index, int desiredType, int[] theAEKeyword, int[] typeCode, int dataPtr, int maximumSize, int[] actualSize); public static final native int AEInstallEventHandler(int theAEEventClass, int theAEEventID, int handler, int handlerRefcon, boolean isSysHandler); Index: Eclipse SWT/carbon/org/eclipse/swt/widgets/Display.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Display.java,v retrieving revision 1.295 diff -u -r1.295 Display.java --- Eclipse SWT/carbon/org/eclipse/swt/widgets/Display.java 12 Nov 2007 20:25:52 -0000 1.295 +++ Eclipse SWT/carbon/org/eclipse/swt/widgets/Display.java 21 Nov 2007 06:47:14 -0000 @@ -11,6 +11,7 @@ package org.eclipse.swt.widgets; import org.eclipse.swt.internal.*; +import org.eclipse.swt.internal.carbon.AEDesc; import org.eclipse.swt.internal.carbon.CFRange; import org.eclipse.swt.internal.carbon.CFRunLoopSourceContext; import org.eclipse.swt.internal.carbon.EventRecord; @@ -109,11 +110,11 @@ Callback actionCallback, appleEventCallback, clockCallback, commandCallback, controlCallback, accessibilityCallback, appearanceCallback; Callback drawItemCallback, itemDataCallback, itemNotificationCallback, itemCompareCallback, searchCallback, trayItemCallback; Callback hitTestCallback, keyboardCallback, menuCallback, mouseHoverCallback, helpCallback, observerCallback, sourceCallback; - Callback mouseCallback, trackingCallback, windowCallback, colorCallback, textInputCallback, releaseCallback, coreEventCallback; + Callback mouseCallback, trackingCallback, windowCallback, colorCallback, textInputCallback, releaseCallback, coreEventCallback, openDocumentsCallback; int actionProc, appleEventProc, clockProc, commandProc, controlProc, appearanceProc, accessibilityProc; int drawItemProc, itemDataProc, itemNotificationProc, itemCompareProc, helpProc, searchProc, trayItemProc; int hitTestProc, keyboardProc, menuProc, mouseHoverProc, observerProc, sourceProc; - int mouseProc, trackingProc, windowProc, colorProc, textInputProc, releaseProc, coreEventProc; + int mouseProc, trackingProc, windowProc, colorProc, textInputProc, releaseProc, coreEventProc, openDocumentsProc; EventTable eventTable, filterTable; int queue, runLoop, runLoopSource, runLoopObserver, lastModifiers, lastState, lastX, lastY; boolean disposing; @@ -2111,6 +2112,9 @@ coreEventCallback = new Callback (this, "coreEventProc", 3); coreEventProc = coreEventCallback.getAddress (); if (coreEventProc == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS); + openDocumentsCallback = new Callback(this, "openDocumentsProc", 3); + openDocumentsProc = openDocumentsCallback.getAddress(); + if (openDocumentsProc == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS); /* Install Event Handlers */ int[] mask1 = new int[] { @@ -2134,6 +2138,8 @@ }; OS.InstallEventHandler (appTarget, appleEventProc, mask3.length / 2, mask3, 0, null); OS.AEInstallEventHandler(OS.kCoreEventClass, OS.kAEQuitApplication, coreEventProc, 0, false); + OS.AEInstallEventHandler(OS.kCoreEventClass, OS.kAEOpenDocuments, openDocumentsProc, 0, false); + OS.AEInstallEventHandler(OS.kURLEventClass, OS.kURLEventClass, openDocumentsProc, 0, false); int [] mask4 = new int[] { OS.kEventClassKeyboard, OS.kEventRawKeyDown, @@ -3146,7 +3152,7 @@ actionProc = appleEventProc = caretProc = commandProc = appearanceProc = searchProc = trayItemProc = 0; accessibilityProc = clockProc = controlProc = drawItemProc = itemDataProc = itemNotificationProc = itemCompareProc = 0; helpProc = hitTestProc = keyboardProc = menuProc = observerProc = sourceProc = releaseProc = 0; - mouseHoverProc = mouseProc = trackingProc = windowProc = colorProc = coreEventProc = 0; + mouseHoverProc = mouseProc = trackingProc = windowProc = colorProc = coreEventProc = openDocumentsProc = 0; textInputProc = 0; timerCallback.dispose (); timerCallback = null; @@ -4070,4 +4076,53 @@ return OS.eventNotHandledErr; } +int openDocumentsProc(int theAppleEvent, int reply, int handlerRefcon) { + System.out.println("Display.openDocumentsProc: " + theAppleEvent + ", " + reply + ", " + handlerRefcon); + AEDesc aeDesc = new AEDesc(); + EventRecord eventRecord = new EventRecord(); + OS.ConvertEventRefToEventRecord(theAppleEvent, eventRecord); + int result = OS.AEGetParamDesc(theAppleEvent, OS.kEventParamDirectObject, OS.typeAEList, aeDesc); + if (result != OS.noErr) { + return OS.noErr; + } + + int[] count = new int[1]; + OS.AECountItems(aeDesc, count); + String[] fileNames = new String[count[0]]; + if (count[0] > 0) { + int maximumSize = 80; // size of FSRef + int dataPtr = OS.NewPtr(maximumSize); + int[] aeKeyword = new int[1]; + int[] typeCode = new int[1]; + int[] actualSize = new int[1]; + for (int i = 0; i < count[0]; i++) { + if (OS.AEGetNthPtr(aeDesc, i + 1, OS.typeFSRef, aeKeyword, typeCode, dataPtr, maximumSize, actualSize) == OS.noErr) { + byte[] fsRef = new byte[actualSize[0]]; + OS.memmove(fsRef, dataPtr, actualSize [0]); + int dirUrl = OS.CFURLCreateFromFSRef(OS.kCFAllocatorDefault, fsRef); + int dirString = OS.CFURLCopyFileSystemPath(dirUrl, OS.kCFURLPOSIXPathStyle); + OS.CFRelease(dirUrl); + int length = OS.CFStringGetLength(dirString); + char[] buffer = new char[length]; + CFRange range = new CFRange(); + range.length = length; + OS.CFStringGetCharacters(dirString, range, buffer); + OS.CFRelease(dirString); + fileNames[i] = new String(buffer); + } + else if (OS.AEGetNthPtr(aeDesc, i + 1, OS.typeChar, aeKeyword, typeCode, dataPtr, maximumSize, actualSize) == OS.noErr) { + byte[] urlRef = new byte[actualSize[0]]; + OS.memmove(urlRef, dataPtr, actualSize[0]); + fileNames[i] = new String(urlRef); + } + } + } + OS.AEDisposeDesc(aeDesc); + + Event event = new Event (); + event.data = fileNames; + sendEvent (SWT.ExternalOpen, event); + return OS.noErr; +} + }