diff src/macfns.c @ 59384:a1edc5959dcf

* macfns.c: Include sys/param.h. [TARGET_API_MAC_CARBON] (mac_nav_event_callback): New declaration and function. [TARGET_API_MAC_CARBON] (Fx_file_dialog): Use MAXPATHLEN for size of filename string. Set event callback function when creating dialog boxes. Add code conversions for filenames. Don't dispose apple event descriptor record if failed to create it. * macterm.c: Include sys/param.h. [USE_CARBON_EVENTS] (mac_handle_window_event): Add handler for kEventWindowUpdate. (install_window_handler) [USE_CARBON_EVENTS]: Register it. (do_ae_open_documents) [TARGET_API_MAC_CARBON]: Get FSRef instead of FSSpec from apple event descriptor record. (do_ae_open_documents) [TARGET_API_MAC_CARBON]: Use MAXPATHLEN for size of filename string. [TARGET_API_MAC_CARBON] (mac_do_receive_drag): Likewise. [TARGET_API_MAC_CARBON] (mac_do_receive_drag): Return error when a file dialog is in action. [TARGET_API_MAC_CARBON] (mac_do_track_drag): Likewise. Reject only when there are no filename items. Set background color before (un)highlighting the window below the dragged items. (XTread_socket) [!USE_CARBON_EVENTS]: Don't call do_window_update.
author Steven Tamm <steventamm@mac.com>
date Thu, 06 Jan 2005 02:53:39 +0000
parents 60ffced08532
children 011a0c55c1f2
line wrap: on
line diff
--- a/src/macfns.c	Thu Jan 06 00:58:07 2005 +0000
+++ b/src/macfns.c	Thu Jan 06 02:53:39 2005 +0000
@@ -55,6 +55,7 @@
 #include <ctype.h>
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <sys/param.h>
 
 #include <stdlib.h>
 #include <string.h>
@@ -4237,6 +4238,9 @@
 			File selection dialog
  ***********************************************************************/
 
+static pascal void mac_nav_event_callback P_ ((NavEventCallbackMessage,
+					       NavCBRecPtr, void *));
+
 /**
    There is a relatively standard way to do this using applescript to run
    a (choose file) method.  However, this doesn't do "the right thing"
@@ -4261,8 +4265,9 @@
   Lisp_Object file = Qnil;
   int count = SPECPDL_INDEX ();
   struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5, gcpro6;
-  char filename[1001];
+  char filename[MAXPATHLEN];
   int default_filter_index = 1; /* 1: All Files, 2: Directories only  */
+  static NavEventUPP mac_nav_event_callbackUPP = NULL;
 
   GCPRO6 (prompt, dir, default_filename, mustmatch, file, only_dir_p);
   CHECK_STRING (prompt);
@@ -4290,16 +4295,20 @@
     options.optionFlags |= kNavSelectAllReadableItem;
     if (!NILP(prompt))
       {
-	message = cfstring_create_with_utf8_cstring (SDATA (prompt));
+	message =
+	  cfstring_create_with_utf8_cstring (SDATA (ENCODE_UTF_8 (prompt)));
 	options.message = message;
       }
     /* Don't set the application, let it use default.
     options.clientName = CFSTR ("Emacs");
     */
 
+    if (mac_nav_event_callbackUPP == NULL)
+      mac_nav_event_callbackUPP = NewNavEventUPP (mac_nav_event_callback);
+
     if (!NILP (only_dir_p))
-      status = NavCreateChooseFolderDialog(&options, NULL, NULL, NULL,
-					   &dialogRef);
+      status = NavCreateChooseFolderDialog(&options, mac_nav_event_callbackUPP,
+					   NULL, NULL, &dialogRef);
     else if (NILP (mustmatch)) 
       { 
 	/* This is a save dialog */
@@ -4310,20 +4319,22 @@
 	if (!NILP(default_filename))
 	  {
 	    saveName =
-	      cfstring_create_with_utf8_cstring (SDATA (default_filename));
+	      cfstring_create_with_utf8_cstring (SDATA (ENCODE_UTF_8
+							(default_filename)));
 	    options.saveFileName = saveName;
 	    options.optionFlags |= kNavSelectDefaultLocation;
 	  }
 	  status = NavCreatePutFileDialog(&options, 
 					  'TEXT', kNavGenericSignature,
-					  NULL, NULL, &dialogRef);
+					  mac_nav_event_callbackUPP, NULL,
+					  &dialogRef);
 	}
     else
       {
 	/* This is an open dialog*/
 	status = NavCreateChooseFileDialog(&options, fileTypes,
-					   NULL, NULL, NULL, NULL, 
-					   &dialogRef);
+					   mac_nav_event_callbackUPP, NULL,
+					   NULL, NULL, &dialogRef);
       }
     
     /* Set the default location and continue*/
@@ -4331,13 +4342,13 @@
       if (!NILP(dir)) {
 	FSRef defLoc;
 	AEDesc defLocAed;
-	status = FSPathMakeRef(SDATA(dir), &defLoc, NULL);
+	status = FSPathMakeRef(SDATA(ENCODE_FILE(dir)), &defLoc, NULL);
 	if (status == noErr) 
 	  {
 	    AECreateDesc(typeFSRef, &defLoc, sizeof(FSRef), &defLocAed);
 	    NavCustomControl(dialogRef, kNavCtlSetLocation, (void*) &defLocAed);
+	    AEDisposeDesc(&defLocAed);
 	  }
-	AEDisposeDesc(&defLocAed);
       }
 
       status = NavDialogRun(dialogRef);
@@ -4363,7 +4374,7 @@
 	    status = NavDialogGetReply(dialogRef, &reply);
 	    AECoerceDesc(&reply.selection, typeFSRef, &aed);
 	    AEGetDescData(&aed, (void *) &fsRef, sizeof (FSRef));
-	    FSRefMakePath(&fsRef, (UInt8 *) filename, 1000);
+	    FSRefMakePath(&fsRef, (UInt8 *) filename, sizeof (filename));
 	    AEDisposeDesc(&aed);
 	    if (reply.saveFileName)
 	      {
@@ -4372,9 +4383,11 @@
 		if (len && filename[len-1] != '/')
 		  filename[len++] = '/';
 		CFStringGetCString(reply.saveFileName, filename+len, 
-				   1000-len, kCFStringEncodingUTF8);
+				   sizeof (filename) - len,
+				   kCFStringEncodingUTF8);
 	      }
-	    file = DECODE_FILE(build_string (filename));
+	    file = DECODE_FILE (make_unibyte_string (filename,
+						     strlen (filename)));
 	    NavDisposeReply(&reply);
 	  }
 	  break;
@@ -4400,6 +4413,15 @@
 }
 
 
+/* Need to register some event callback function for enabling drag and
+   drop in Navigation Service dialogs.  */
+static pascal void
+mac_nav_event_callback (selector, parms, data)
+     NavEventCallbackMessage selector;
+     NavCBRecPtr parms;
+     void *data ;
+{
+}
 #endif
 
 /***********************************************************************