changeset 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 b2ee40a51736
children 24b54016dd51
files src/ChangeLog src/macfns.c src/macterm.c
diffstat 3 files changed, 109 insertions(+), 38 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Thu Jan 06 00:58:07 2005 +0000
+++ b/src/ChangeLog	Thu Jan 06 02:53:39 2005 +0000
@@ -1,3 +1,29 @@
+2005-01-05  YAMAMOTO Mitsuharu  <mituharu@math.s.chiba-u.ac.jp>
+
+	* 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.
+
 2005-01-05  Romain Francoise  <romain@orebokech.com>
 
 	* term.c (encode_terminal_code): Fix buffer size computation.
--- 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
 
 /***********************************************************************
--- a/src/macterm.c	Thu Jan 06 00:58:07 2005 +0000
+++ b/src/macterm.c	Thu Jan 06 02:53:39 2005 +0000
@@ -69,6 +69,7 @@
 #include <errno.h>
 #include <setjmp.h>
 #include <sys/stat.h>
+#include <sys/param.h>
 
 #include "keyboard.h"
 #include "frame.h"
@@ -7867,6 +7868,14 @@
 
   switch (GetEventKind (event))
     {
+    case kEventWindowUpdate:
+      result = CallNextEventHandler (next_handler, event);
+      if (result != eventNotHandledErr)
+	return result;
+
+      do_window_update (wp);
+      break;
+
     case kEventWindowBoundsChanging:
       result = CallNextEventHandler (next_handler, event);
       if (result != eventNotHandledErr)
@@ -7924,7 +7933,8 @@
 {
   OSErr err = noErr;
 #if USE_CARBON_EVENTS
-  EventTypeSpec specs[] = {{kEventClassWindow, kEventWindowBoundsChanging}};
+  EventTypeSpec specs[] = {{kEventClassWindow, kEventWindowUpdate},
+			   {kEventClassWindow, kEventWindowBoundsChanging}};
   static EventHandlerUPP handle_window_event_UPP = NULL;
 
   if (handle_window_event_UPP == NULL)
@@ -8019,24 +8029,28 @@
         int i;
 
         /* AE file list is one based so just use that for indexing here.  */
-        for (i = 1; (err == noErr) && (i <= num_files_to_open); i++)
+        for (i = 1; i <= num_files_to_open; i++)
 	  {
+#ifdef MAC_OSX
+	    FSRef fref;
+	    char unix_path_name[MAXPATHLEN];
+
+	    err = AEGetNthPtr (&the_desc, i, typeFSRef, &keyword,
+			       &actual_type, &fref, sizeof (FSRef),
+			       &actual_size);
+	    if (err != noErr || actual_type != typeFSRef)
+	      continue;
+
+	    if (FSRefMakePath (&fref, unix_path_name, sizeof (unix_path_name))
+		== noErr)
+#else
 	    FSSpec fs;
 	    Str255 path_name, unix_path_name;
-#ifdef MAC_OSX
-	    FSRef fref;
-#endif
 
 	    err = AEGetNthPtr(&the_desc, i, typeFSS, &keyword, &actual_type,
 			      (Ptr) &fs, sizeof (fs), &actual_size);
-	    if (err != noErr) break;
-
-#ifdef MAC_OSX
-	    err = FSpMakeFSRef (&fs, &fref);
-	    if (err != noErr) break;
-
-	    if (FSRefMakePath (&fref, unix_path_name, 255) == noErr)
-#else
+	    if (err != noErr) continue;
+
 	    if (path_from_vol_dir_name (path_name, 255, fs.vRefNum, fs.parID,
 					fs.name) &&
 		mac_to_posix_pathname (path_name, unix_path_name, 255))
@@ -8072,18 +8086,21 @@
   FlavorFlags theFlags;
   OSErr result;
 
+  if (GetFrontWindowOfClass (kMovableModalWindowClass, false))
+    return dragNotAcceptedErr;
+
   switch (message)
     {
     case kDragTrackingEnterHandler:
       CountDragItems (theDrag, &items);
-      can_accept = 1;
+      can_accept = 0;
       for (index = 1; index <= items; index++)
 	{
 	  GetDragItemReferenceNumber (theDrag, index, &theItem);
 	  result = GetFlavorFlags (theDrag, theItem, flavorTypeHFS, &theFlags);
-	  if (result != noErr)
+	  if (result == noErr)
 	    {
-	      can_accept = 0;
+	      can_accept = 1;
 	      break;
 	    }
 	}
@@ -8094,7 +8111,9 @@
 	{
 	  RgnHandle hilite_rgn = NewRgn ();
 	  Rect r;
-
+	  struct frame *f = mac_window_to_frame (window);
+
+	  mac_set_backcolor (FRAME_BACKGROUND_PIXEL (f));
 	  GetWindowPortBounds (window, &r);
 	  OffsetRect (&r, -r.left, -r.top);
 	  RectRgn (hilite_rgn, &r);
@@ -8110,6 +8129,9 @@
     case kDragTrackingLeaveWindow:
       if (can_accept)
 	{
+	  struct frame *f = mac_window_to_frame (window);
+
+	  mac_set_backcolor (FRAME_BACKGROUND_PIXEL (f));
 	  HideDragHilite (theDrag);
 	  SetThemeCursor (kThemeArrowCursor);
 	}
@@ -8133,9 +8155,11 @@
   OSErr result;
   ItemReference theItem;
   HFSFlavor data;
-  FSRef fref;
   Size size = sizeof (HFSFlavor);
 
+  if (GetFrontWindowOfClass (kMovableModalWindowClass, false))
+    return dragNotAcceptedErr;
+
   drag_and_drop_file_list = Qnil;
   GetDragMouse (theDrag, &mouse, 0L);
   CountDragItems (theDrag, &items);
@@ -8147,11 +8171,11 @@
       if (result == noErr)
 	{
 #ifdef MAC_OSX
-	  FSRef frref;
+	  FSRef fref;
+	  char unix_path_name[MAXPATHLEN];
 #else
-	  Str255 path_name;
-#endif
-	  Str255 unix_path_name;
+	  Str255 path_name, unix_path_name;
+#endif
 	  GetFlavorData (theDrag, theItem, flavorTypeHFS, &data, &size, 0L);
 #ifdef MAC_OSX
 	  /* Use Carbon routines, otherwise it converts the file name
@@ -8169,8 +8193,6 @@
 					  strlen (unix_path_name)),
 		     drag_and_drop_file_list);
 	}
-      else
-	continue;
     }
   /* If there are items in the list, construct an event and post it to
      the queue like an interrupt using kbd_buffer_store_event.  */
@@ -8730,8 +8752,9 @@
 	  if (SendEventToEventTarget (eventRef, toolbox_dispatcher)
 	      != eventNotHandledErr)
 	    break;
-#endif
+#else
 	  do_window_update ((WindowPtr) er.message);
+#endif
 	  break;
 
 	case osEvt: