Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 150099 Details for
Bug 201154
Add support in SWT for event-based document opening
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
R351 Equinox Carbon/Cocoa patch
equinox_executable_carbon_cocoa_R351.patch (text/plain), 10.60 KB, created by
Mike Schrag
on 2009-10-21 08:16:02 EDT
(
hide
)
Description:
R351 Equinox Carbon/Cocoa patch
Filename:
MIME Type:
Creator:
Mike Schrag
Created:
2009-10-21 08:16:02 EDT
Size:
10.60 KB
patch
obsolete
>diff --git a/library/carbon/eclipseCarbon.c b/library/carbon/eclipseCarbon.c >index e5da4e6..69c4456 100755 >--- a/library/carbon/eclipseCarbon.c >+++ b/library/carbon/eclipseCarbon.c >@@ -343,8 +343,42 @@ int launchJavaVM( _TCHAR* args[] ) > return -1; > } > >+/* Externed from eclipseCarbonCommon.c */ >+extern MPSemaphoreID startupEventSemaphore; >+/* Externed from eclipseCarbonCommon.c */ >+extern _TCHAR** startupOpenedDocuments; >+ > int startJavaVM( _TCHAR* libPath, _TCHAR* vmArgs[], _TCHAR* progArgs[], _TCHAR* jarFile ) > { >+ _TCHAR** progArgsWithStartupDocuments; >+ int nProgArgs = 0; >+ int nStartupOpenedDocuments = 0; >+ >+ /* We have to do a small run of dispatch messages so we receive the openDocuments >+ * or openApplication Apple events >+ */ >+ dispatchMessages(); >+ >+ /* ... and we block on the startup event semaphore, which is flipped by the >+ * Apple Event handlers (either openDocuments or openApplication -- we are >+ * guaranteed to receive at least one of them). >+ */ >+ MPWaitOnSemaphore(startupEventSemaphore, kDurationForever); >+ >+ /* If the app was launched via openDocuments, then stuff the list of >+ * documents onto the front of the Java VM commandline >+ */ >+ if (startupOpenedDocuments != NULL) { >+ while(progArgs[nProgArgs] != NULL) { nProgArgs ++; } >+ while(startupOpenedDocuments[nStartupOpenedDocuments] != NULL) { nStartupOpenedDocuments ++; } >+ >+ progArgsWithStartupDocuments = malloc((nProgArgs + nStartupOpenedDocuments + 1) * sizeof(_TCHAR*)); >+ memset(progArgsWithStartupDocuments, 0, (nProgArgs + nStartupOpenedDocuments + 1) * sizeof(_TCHAR*)); >+ memcpy(progArgsWithStartupDocuments, startupOpenedDocuments, nStartupOpenedDocuments * sizeof(_TCHAR*)); >+ memcpy(progArgsWithStartupDocuments + nStartupOpenedDocuments, progArgs, nProgArgs * sizeof(_TCHAR*)); >+ progArgs = progArgsWithStartupDocuments; >+ } >+ > if (secondThread == 0) { > /* Set an environment variable that tells the AWT (if started) we started the JVM on the main thread. */ > char firstThreadEnvVariable[80]; >diff --git a/library/carbon/eclipseCarbonCommon.c b/library/carbon/eclipseCarbonCommon.c >index 82e9719..cc3f1d6 100755 >--- a/library/carbon/eclipseCarbonCommon.c >+++ b/library/carbon/eclipseCarbonCommon.c >@@ -31,6 +31,75 @@ static CFBundleRef javaVMBundle = NULL; > > int initialized = 0; > >+/* The semaphore that blocks until the openDocuments/openApplication >+ * Apple events have been received >+ */ >+MPSemaphoreID startupEventSemaphore; >+ >+/* The list of opened document paths from an openDocuments Apple event */ >+_TCHAR** startupOpenedDocuments = NULL; >+ >+#ifdef COCOA >+@interface EQEventDelegate : NSObject >+@end >+ >+@implementation EQEventDelegate >+/* handleOpenApplication doesn't do anything except signal the startup semaphore */ >+- (void)handleOpenApplication:(NSAppleEventDescriptor *)event withReplyEvent: (NSAppleEventDescriptor *)replyEvent { >+ MPSignalSemaphore(startupEventSemaphore); >+} >+ >+/* handleOpenDocuments parses out the list of files that triggered this application >+ * to launch, and sets them into the _TCHAR **startupOpenedDocuments which >+ * will be consumed by startJavaVM in eclipseCarbon.c as commandline >+ * paramaters. When this process is complete, the startup semaphore >+ * will be signalled. >+ */ >+- (void)handleOpenDocuments:(NSAppleEventDescriptor *)event withReplyEvent: (NSAppleEventDescriptor *)replyEvent { >+ NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; >+ NSAppleEventDescriptor *fileList = [event paramDescriptorForKeyword:keyDirectObject]; >+ if (fileList) { >+ NSInteger descriptorNum; >+ NSInteger descriptorCount = [fileList numberOfItems]; >+ startupOpenedDocuments = malloc((descriptorCount + 1) * sizeof(_TCHAR*)); >+ memset(startupOpenedDocuments, 0, (descriptorCount + 1) * sizeof(_TCHAR*)); >+ for (descriptorNum = 1; descriptorNum <= descriptorCount; descriptorNum++) { >+ NSAppleEventDescriptor *fileAliasDesc = [fileList descriptorAtIndex:descriptorNum]; >+ if (fileAliasDesc) { >+ NSAppleEventDescriptor *fileURLDesc = [fileAliasDesc coerceToDescriptorType:typeFileURL]; >+ NSData *fileURLData = [fileURLDesc data]; >+ if (fileURLData) { >+ NSString *fileURLString = [[[NSString alloc] initWithBytes:[fileURLData bytes] length:[fileURLData length] encoding:NSUTF8StringEncoding] autorelease]; >+ NSURL *fileURL = [NSURL URLWithString:fileURLString]; >+ NSString *filePath = [fileURL path]; >+ NSInteger length = [filePath maximumLengthOfBytesUsingEncoding:NSUTF8StringEncoding]; >+ char *s = malloc(length); >+ if ([filePath getCString:s maxLength:length encoding:NSUTF8StringEncoding]) { >+ startupOpenedDocuments[descriptorCount - 1] = s; >+ } >+ else { >+ free(s); >+ } >+ } >+ } >+ } >+ } >+ [pool release]; >+ >+ MPSignalSemaphore(startupEventSemaphore); >+} >+@end >+#else >+/* The Apple Event event processor */ >+static OSStatus appleEventProc(EventHandlerCallRef inCaller, EventRef inEvent, void* inRefcon); >+ >+/* The openApplication Apple Event callback */ >+static pascal OSErr openApplicationAEProc(const AppleEvent *theAppleEvent, AppleEvent *reply, long handlerRefcon); >+ >+/* The openDocuments Apple Event callback */ >+static pascal OSErr openDocumentsAEProc(const AppleEvent *theAppleEvent, AppleEvent *reply, long handlerRefcon); >+#endif >+ > static void init() { > if (!initialized) { > ProcessSerialNumber psn; >@@ -58,7 +127,37 @@ int initWindowSystem( int* pArgc, char* argv[], int showSplash ) > /*debug("install dir: %s\n", homeDir);*/ > if (homeDir != NULL) > chdir(homeDir); >- >+ >+ /* Create a semaphore and immediately lock it. This will be >+ * unlocked by the openApplication or openDocuments Apple Event. >+ * The OS guarantees that one (and only one) of these will be >+ * sent during the app startup process. The events are delivered >+ * very quickly, so this only slightly increases startup time. The >+ * startJavaVM function in eclipseCarbon.c is also blocking on this >+ * event, because startJavaVM is called prior to this initialization >+ * process. >+ */ >+ MPCreateBinarySemaphore(&startupEventSemaphore); >+ //MPWaitOnSemaphore(startupEventSemaphore, kDurationForever); >+ >+#ifdef COCOA >+ EQEventDelegate *delegate = [[EQEventDelegate alloc] init]; >+ NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; >+ [NSApplication sharedApplication]; >+ >+ [[NSAppleEventManager sharedAppleEventManager] setEventHandler:delegate andSelector:@selector(handleOpenApplication:withReplyEvent:) forEventClass:kCoreEventClass andEventID:kAEOpenApplication]; >+ [[NSAppleEventManager sharedAppleEventManager] setEventHandler:delegate andSelector:@selector(handleOpenDocuments:withReplyEvent:) forEventClass:kCoreEventClass andEventID:kAEOpenDocuments]; >+ >+ [pool release]; >+#else >+ EventTypeSpec kEvents[] = { {kEventClassAppleEvent, kEventAppleEvent} }; >+ >+ /* Install the Apple Event handlers */ >+ InstallApplicationEventHandler(NewEventHandlerUPP(appleEventProc), GetEventTypeCount(kEvents), kEvents, 0, NULL); >+ AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, NewAEEventHandlerUPP(openApplicationAEProc), 0, false); >+ AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, NewAEEventHandlerUPP(openDocumentsAEProc), 0, false); >+#endif >+ > if (showSplash) > init(); > >@@ -183,4 +282,101 @@ char * resolveSymlinks( char * path ) { > } > CFRelease(url); > return result; >-} >\ No newline at end of file >+} >+ >+#ifdef COCOA >+ >+#else >+/* This is taken from an Apple example on handling Apple Events manually */ >+static OSStatus appleEventProc(EventHandlerCallRef inCaller, EventRef inEvent, void* inRefcon) { >+ Boolean release = false; >+ EventRecord eventRecord; >+ OSErr ignoreErrForThisSample; >+ >+ // Events of type kEventAppleEvent must be removed from the queue >+ // before being passed to AEProcessAppleEvent. >+ if (IsEventInQueue(GetMainEventQueue(), inEvent)) { >+ // RemoveEventFromQueue will release the event, which will >+ // destroy it if we don't retain it first. >+ RetainEvent(inEvent); >+ release = true; >+ RemoveEventFromQueue(GetMainEventQueue(), inEvent); >+ } >+ >+ // Convert the event ref to the type AEProcessAppleEvent expects. >+ ConvertEventRefToEventRecord(inEvent, &eventRecord); >+ ignoreErrForThisSample = AEProcessAppleEvent(&eventRecord); >+ >+ if (release) { >+ ReleaseEvent(inEvent); >+ } >+ >+ // This Carbon event has been handled, even if no AppleEvent handlers >+ // were installed for the Apple event. >+ return noErr; >+} >+ >+/* openApplication doesn't do anything except signal the startup semaphore */ >+static pascal OSErr openApplicationAEProc(const AppleEvent *theAppleEvent, AppleEvent *reply, long handlerRefcon) { >+ MPSignalSemaphore(startupEventSemaphore); >+ return noErr; >+} >+ >+/* openDocuments parses out the list of files that triggered this application >+ * to launch, and sets them into the _TCHAR **startupOpenedDocuments which >+ * will be consumed by startJavaVM in eclipseCarbon.c as commandline >+ * paramaters. When this process is complete, the startup semaphore >+ * will be signalled. >+ */ >+static pascal OSErr openDocumentsAEProc(const AppleEvent *theAppleEvent, AppleEvent *reply, long handlerRefcon) { >+ AEDescList docList; >+ FSRef fsRef; >+ CFURLRef resolved; >+ Boolean isFolder, wasAliased; >+ CFStringRef string; >+ long index; >+ long count = 0; >+ OSErr err = AEGetParamDesc(theAppleEvent, keyDirectObject, typeAEList, &docList); >+ require_noerr(err, CantGetDocList); >+ >+ err = AECountItems(&docList, &count); >+ require_noerr(err, CantGetCount); >+ >+ //CFStringRef imageString = CFStringCreateWithCString(kCFAllocatorDefault, featureImage, kCFStringEncodingASCII); >+ startupOpenedDocuments = malloc((count + 1) * sizeof(_TCHAR*)); >+ memset(startupOpenedDocuments, 0, (count + 1) * sizeof(_TCHAR*)); >+ for (index = 1; index <= count; index++) { >+ err = AEGetNthPtr(&docList, index, typeFSRef, NULL, NULL, &fsRef, sizeof(FSRef), NULL); >+ require_noerr(err, CantGetDocDescPtr); >+ >+ if (FSResolveAliasFile(&fsRef, true, &isFolder, &wasAliased) == noErr) { >+ resolved = CFURLCreateFromFSRef(kCFAllocatorDefault, &fsRef); >+ if (resolved != NULL) { >+ string = CFURLCopyFileSystemPath(resolved, kCFURLPOSIXPathStyle); >+ CFIndex length = CFStringGetMaximumSizeForEncoding(CFStringGetLength(string), kCFStringEncodingUTF8); >+ char *s = malloc(length); >+ if (CFStringGetCString(string, s, length, kCFStringEncodingUTF8)) { >+ startupOpenedDocuments[index - 1] = s; >+ } >+ else { >+ free(s); >+ } >+ CFRelease(string); >+ CFRelease(resolved); >+ } >+ } >+ } >+ >+CantGetCount: >+CantGetDocDescPtr: >+ AEDisposeDesc(&docList); >+ >+CantGetDocList: >+ if (err != noErr) { >+ // For handlers that expect a reply, add error information here. >+ } >+ >+ MPSignalSemaphore(startupEventSemaphore); >+ return err; >+} >+#endif
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 201154
:
76977
|
76978
|
77255
|
83404
|
150098
|
150099
|
150100
|
150134
|
151354
|
151355
|
153400
|
156013