diff options
| author | Michael R Sweet <michael.r.sweet@gmail.com> | 2003-05-30 07:03:09 +0000 |
|---|---|---|
| committer | Michael R Sweet <michael.r.sweet@gmail.com> | 2003-05-30 07:03:09 +0000 |
| commit | 0aa85c540cc0b440d6ae46720f3496ce3733d4db (patch) | |
| tree | f60e044982d9d08abc0c0325874822be14d7f490 /src | |
| parent | 47426f0b3fe6cddea8cca421d0c905edb4834bfa (diff) | |
Add preliminary support for Apple Open Documents event callback interface
on OSX (to allow FLUID and other apps to register a callback to open files)
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@3016 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src')
| -rw-r--r-- | src/Fl_mac.cxx | 89 |
1 files changed, 87 insertions, 2 deletions
diff --git a/src/Fl_mac.cxx b/src/Fl_mac.cxx index f2ee20c16..779d20112 100644 --- a/src/Fl_mac.cxx +++ b/src/Fl_mac.cxx @@ -1,5 +1,5 @@ // -// "$Id: Fl_mac.cxx,v 1.1.2.43 2003/05/28 05:10:05 matthiaswm Exp $" +// "$Id: Fl_mac.cxx,v 1.1.2.44 2003/05/30 07:03:09 easysw Exp $" // // MacOS specific code for the Fast Light Tool Kit (FLTK). // @@ -70,6 +70,7 @@ extern void fl_fix_focus(); // forward definition of functions in this file static void handleUpdateEvent( WindowPtr xid ); //+ int fl_handle(const EventRecord &event); +static int FSSpec2UnixPath( FSSpec *fs, char *dst ); // public variables int fl_screen; @@ -984,6 +985,90 @@ pascal OSStatus carbonKeyboardHandler( EventHandlerCallRef nextHandler, EventRef } + +/** + * Open callback function to call... + */ + +static void (*open_cb)(const char *) = 0; + + +/** + * Event handler for Apple-O key combination and also for file opens + * via the finder... + */ + +static OSErr OpenAppleEventHandler(const AppleEvent *appleEvt, + AppleEvent *reply, + UInt32 refcon) { + OSErr err; + AEDescList documents; + long i, n; + FSSpec fileSpec; + AEKeyword keyWd; + DescType typeCd; + Size actSz; + char filename[1024]; + + if (!open_cb) return noErr; + + // Initialize the document list... + AECreateDesc(typeNull, NULL, 0, &documents); + + // Get the open parameter(s)... + err = AEGetParamDesc(appleEvt, keyDirectObject, typeAEList, &documents); + if (err != noErr) { + AEDisposeDesc(&documents); + return err; + } + + // Lock access to FLTK in this thread... + fl_lock_function(); + + // Open the documents via the callback... + if (AECountItems(theDocuments, &n) == noErr) { + for (i = 1; i <= n; i ++) { + // Get the next FSSpec record... + AEGetNthPtr(theDocuments, i, typeFSS, &keyWd, &typeCd, + (Ptr)&fileSpec, sizeof(fileSpec), + (actSz = sizeof(fileSpec), &actSz)); + + // Convert to a UNIX path... + FSSpec2UnixPath(&fileSpec, filename); + + // Call the callback with the filename... + (*open_cb)(filename); + } + } + + // Unlock access to FLTK for all threads... + fl_unlock_function(); + + // Get rid of the document list... + AEDisposeDesc(&documents); + + return noErr; +} + + +/** + * Install an open documents event handler... + */ + +void fl_open_callback(void (*cb)(const char *)) { + open_cb = cb; + if (cb) { + AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, + NewAEEventHandlerUPP((AEEventHandlerProcPtr) + OpenAppleEventHandler), 0, false); + } else { + AERemoveEventHandler(kCoreEventClass, kAEOpenDocuments, + NewAEEventHandlerUPP((AEEventHandlerProcPtr) + OpenAppleEventHandler), false); + } +} + + /** * initialize the Mac toolboxes and set the default menubar */ @@ -1776,6 +1861,6 @@ void Fl::paste(Fl_Widget &receiver, int clipboard) { // -// End of "$Id: Fl_mac.cxx,v 1.1.2.43 2003/05/28 05:10:05 matthiaswm Exp $". +// End of "$Id: Fl_mac.cxx,v 1.1.2.44 2003/05/30 07:03:09 easysw Exp $". // |
