public int appleEventProc(int nextHandler, int theEvent, int userData) { if(!this.isEnabled()){ return OS.noErr; } int eventClass = OS.GetEventClass(theEvent); if (eventClass == OS.kEventClassAppleEvent) { int[] aeEventID = new int[1]; if (OS.GetEventParameter(theEvent, OS.kEventParamAEEventID, OS.typeType, null, 4, null, aeEventID) != OS.noErr) { return OS.eventNotHandledErr; } if (aeEventID[0] != kAEOpenDocuments && aeEventID[0] != kURLEventClass) { return OS.eventNotHandledErr; } EventRecord eventRecord = new EventRecord(); OS.ConvertEventRefToEventRecord(theEvent, eventRecord); OS.AEProcessAppleEvent(eventRecord); return OS.noErr; } return OS.eventNotHandledErr; }
public int openDocProc(int theAppleEvent, int reply, int handlerRefcon) { if(!this.isEnabled()){ return OS.noErr; } AEDesc aeDesc = new AEDesc(); EventRecord eventRecord = new EventRecord(); OS.ConvertEventRefToEventRecord(theAppleEvent, eventRecord); try { int result = OpenDocJNI.AEGetParamDesc(theAppleEvent,OS.kEventParamDirectObject, typeAEList, aeDesc); if (result != OS.noErr) { System.err.println("OSX: Could call AEGetParamDesc. Error: " + result); return OS.noErr; } } catch (java.lang.UnsatisfiedLinkError e) { System.err.println("OSX: AEGetParamDesc not available. Can't open sent file"); return OS.noErr; } int[] count = new int[1]; OS.AECountItems(aeDesc, count); if (count[0] > 0) { String[] fileNames = new String[count[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]]; C.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); } if (OS.AEGetNthPtr(aeDesc, i + 1, typeText, aeKeyword,typeCode, dataPtr, maximumSize, actualSize) == OS.noErr) { byte[] urlRef = new byte[actualSize[0]]; C.memmove(urlRef, dataPtr, actualSize[0]); fileNames[i] = new String(urlRef); } } if( fileNames.length > 0 ){ OpenDocAction.saveAndOpen( fileNames[0] ); } } return OS.noErr; }