+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.
#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
+#include <sys/param.h>
#include <stdlib.h>
#include <string.h>
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"
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);
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 */
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*/
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);
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)
{
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;
}
+/* 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
\f
/***********************************************************************
#include <errno.h>
#include <setjmp.h>
#include <sys/stat.h>
+#include <sys/param.h>
#include "keyboard.h"
#include "frame.h"
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)
{
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)
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++)
{
- FSSpec fs;
- Str255 path_name, unix_path_name;
#ifdef MAC_OSX
FSRef fref;
-#endif
+ 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;
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 (err != noErr) continue;
- if (FSRefMakePath (&fref, unix_path_name, 255) == noErr)
-#else
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))
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;
}
}
{
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);
case kDragTrackingLeaveWindow:
if (can_accept)
{
+ struct frame *f = mac_window_to_frame (window);
+
+ mac_set_backcolor (FRAME_BACKGROUND_PIXEL (f));
HideDragHilite (theDrag);
SetThemeCursor (kThemeArrowCursor);
}
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);
if (result == noErr)
{
#ifdef MAC_OSX
- FSRef frref;
+ FSRef fref;
+ char unix_path_name[MAXPATHLEN];
#else
- Str255 path_name;
+ Str255 path_name, unix_path_name;
#endif
- Str255 unix_path_name;
GetFlavorData (theDrag, theItem, flavorTypeHFS, &data, &size, 0L);
#ifdef MAC_OSX
/* Use Carbon routines, otherwise it converts the file name
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. */
if (SendEventToEventTarget (eventRef, toolbox_dispatcher)
!= eventNotHandledErr)
break;
-#endif
+#else
do_window_update ((WindowPtr) er.message);
+#endif
break;
case osEvt: