summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael R Sweet <michael.r.sweet@gmail.com>2003-05-30 07:03:09 +0000
committerMichael R Sweet <michael.r.sweet@gmail.com>2003-05-30 07:03:09 +0000
commit0aa85c540cc0b440d6ae46720f3496ce3733d4db (patch)
treef60e044982d9d08abc0c0325874822be14d7f490
parent47426f0b3fe6cddea8cca421d0c905edb4834bfa (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
-rw-r--r--CHANGES3
-rw-r--r--FL/mac.H7
-rw-r--r--src/Fl_mac.cxx89
3 files changed, 95 insertions, 4 deletions
diff --git a/CHANGES b/CHANGES
index fa882f6e6..c05032f0a 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,5 +1,8 @@
CHANGES IN FLTK 1.1.4
+ - Added the OSX-specific fl_open_callback() function to
+ handle Open Documents messages from the Finder (STR
+ #pending)
- The configure script contained erroneous whitespace in
various tests which caused errors on some platforms
(STR #60)
diff --git a/FL/mac.H b/FL/mac.H
index 6c32ac65c..dd36536a8 100644
--- a/FL/mac.H
+++ b/FL/mac.H
@@ -1,5 +1,5 @@
//
-// "$Id: mac.H,v 1.1.2.9 2003/01/30 21:40:53 easysw Exp $"
+// "$Id: mac.H,v 1.1.2.10 2003/05/30 07:03:08 easysw Exp $"
//
// Mac header file for the Fast Light Tool Kit (FLTK).
//
@@ -112,9 +112,12 @@ extern FL_EXPORT void fl_delete_bitmask(Fl_Bitmask bm);
extern void fl_open_display();
+// Register a function for opening files via the finder...
+extern void fl_open_callback(void (*cb)(const char *));
+
extern FL_EXPORT int fl_parse_color(const char* p, uchar& r, uchar& g, uchar& b);
//
-// End of "$Id: mac.H,v 1.1.2.9 2003/01/30 21:40:53 easysw Exp $".
+// End of "$Id: mac.H,v 1.1.2.10 2003/05/30 07:03:08 easysw Exp $".
//
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 $".
//