From e0e76ab914bc4d9e4933e11c622a43981be2a141 Mon Sep 17 00:00:00 2001 From: Steven Tamm Date: Thu, 6 Jan 2005 02:53:39 +0000 Subject: [PATCH] * 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. --- src/ChangeLog | 26 ++++++++++++++++++++ src/macfns.c | 48 ++++++++++++++++++++++++++---------- src/macterm.c | 67 ++++++++++++++++++++++++++++++++++----------------- 3 files changed, 106 insertions(+), 35 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 977b239287f..d12787c92a3 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,29 @@ +2005-01-05 YAMAMOTO Mitsuharu + + * 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 * term.c (encode_terminal_code): Fix buffer size computation. diff --git a/src/macfns.c b/src/macfns.c index f40e8354f35..9a8382e413c 100644 --- a/src/macfns.c +++ b/src/macfns.c @@ -55,6 +55,7 @@ static unsigned char gray_bits[] = { #include #include #include +#include #include #include @@ -4237,6 +4238,9 @@ Value is t if tooltip was open, nil otherwise. */) 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 @@ If ONLY-DIR-P is non-nil, the user can only select directories. */) 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 @@ If ONLY-DIR-P is non-nil, the user can only select directories. */) 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 ONLY-DIR-P is non-nil, the user can only select directories. */) 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 ONLY-DIR-P is non-nil, the user can only select directories. */) 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 @@ If ONLY-DIR-P is non-nil, the user can only select directories. */) 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 ONLY-DIR-P is non-nil, the user can only select directories. */) 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 @@ If ONLY-DIR-P is non-nil, the user can only select directories. */) } +/* 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 /*********************************************************************** diff --git a/src/macterm.c b/src/macterm.c index dda0cc8311f..4d80fbac5fa 100644 --- a/src/macterm.c +++ b/src/macterm.c @@ -69,6 +69,7 @@ Boston, MA 02111-1307, USA. */ #include #include #include +#include #include "keyboard.h" #include "frame.h" @@ -7867,6 +7868,14 @@ mac_handle_window_event (next_handler, event, data) 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 @@ install_window_handler (window) { 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 @@ do_ae_open_documents(AppleEvent *message, AppleEvent *reply, long refcon) 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)) @@ -8072,18 +8086,21 @@ mac_do_track_drag (DragTrackingMessage message, WindowPtr window, 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 @@ mac_do_track_drag (DragTrackingMessage message, WindowPtr window, { 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 @@ mac_do_track_drag (DragTrackingMessage message, WindowPtr window, 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 @@ mac_do_receive_drag (WindowPtr window, void *handlerRefCon, 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 @@ mac_do_receive_drag (WindowPtr window, void *handlerRefCon, 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 @@ -8169,8 +8193,6 @@ mac_do_receive_drag (WindowPtr window, void *handlerRefCon, 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 @@ XTread_socket (sd, expected, hold_quit) if (SendEventToEventTarget (eventRef, toolbox_dispatcher) != eventNotHandledErr) break; -#endif +#else do_window_update ((WindowPtr) er.message); +#endif break; case osEvt: -- 2.39.5