Mercurial > emacs
comparison src/macterm.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 | 68eaccfa130a |
children | b0b469611a56 |
comparison
equal
deleted
inserted
replaced
59383:b2ee40a51736 | 59384:a1edc5959dcf |
---|---|
67 | 67 |
68 #include <ctype.h> | 68 #include <ctype.h> |
69 #include <errno.h> | 69 #include <errno.h> |
70 #include <setjmp.h> | 70 #include <setjmp.h> |
71 #include <sys/stat.h> | 71 #include <sys/stat.h> |
72 #include <sys/param.h> | |
72 | 73 |
73 #include "keyboard.h" | 74 #include "keyboard.h" |
74 #include "frame.h" | 75 #include "frame.h" |
75 #include "dispextern.h" | 76 #include "dispextern.h" |
76 #include "fontset.h" | 77 #include "fontset.h" |
7865 GetEventParameter (event, kEventParamDirectObject, typeWindowRef, | 7866 GetEventParameter (event, kEventParamDirectObject, typeWindowRef, |
7866 NULL, sizeof (WindowPtr), NULL, &wp); | 7867 NULL, sizeof (WindowPtr), NULL, &wp); |
7867 | 7868 |
7868 switch (GetEventKind (event)) | 7869 switch (GetEventKind (event)) |
7869 { | 7870 { |
7871 case kEventWindowUpdate: | |
7872 result = CallNextEventHandler (next_handler, event); | |
7873 if (result != eventNotHandledErr) | |
7874 return result; | |
7875 | |
7876 do_window_update (wp); | |
7877 break; | |
7878 | |
7870 case kEventWindowBoundsChanging: | 7879 case kEventWindowBoundsChanging: |
7871 result = CallNextEventHandler (next_handler, event); | 7880 result = CallNextEventHandler (next_handler, event); |
7872 if (result != eventNotHandledErr) | 7881 if (result != eventNotHandledErr) |
7873 return result; | 7882 return result; |
7874 | 7883 |
7922 install_window_handler (window) | 7931 install_window_handler (window) |
7923 WindowPtr window; | 7932 WindowPtr window; |
7924 { | 7933 { |
7925 OSErr err = noErr; | 7934 OSErr err = noErr; |
7926 #if USE_CARBON_EVENTS | 7935 #if USE_CARBON_EVENTS |
7927 EventTypeSpec specs[] = {{kEventClassWindow, kEventWindowBoundsChanging}}; | 7936 EventTypeSpec specs[] = {{kEventClassWindow, kEventWindowUpdate}, |
7937 {kEventClassWindow, kEventWindowBoundsChanging}}; | |
7928 static EventHandlerUPP handle_window_event_UPP = NULL; | 7938 static EventHandlerUPP handle_window_event_UPP = NULL; |
7929 | 7939 |
7930 if (handle_window_event_UPP == NULL) | 7940 if (handle_window_event_UPP == NULL) |
7931 handle_window_event_UPP = NewEventHandlerUPP (mac_handle_window_event); | 7941 handle_window_event_UPP = NewEventHandlerUPP (mac_handle_window_event); |
7932 | 7942 |
8017 if (err == noErr) | 8027 if (err == noErr) |
8018 { | 8028 { |
8019 int i; | 8029 int i; |
8020 | 8030 |
8021 /* AE file list is one based so just use that for indexing here. */ | 8031 /* AE file list is one based so just use that for indexing here. */ |
8022 for (i = 1; (err == noErr) && (i <= num_files_to_open); i++) | 8032 for (i = 1; i <= num_files_to_open; i++) |
8023 { | 8033 { |
8034 #ifdef MAC_OSX | |
8035 FSRef fref; | |
8036 char unix_path_name[MAXPATHLEN]; | |
8037 | |
8038 err = AEGetNthPtr (&the_desc, i, typeFSRef, &keyword, | |
8039 &actual_type, &fref, sizeof (FSRef), | |
8040 &actual_size); | |
8041 if (err != noErr || actual_type != typeFSRef) | |
8042 continue; | |
8043 | |
8044 if (FSRefMakePath (&fref, unix_path_name, sizeof (unix_path_name)) | |
8045 == noErr) | |
8046 #else | |
8024 FSSpec fs; | 8047 FSSpec fs; |
8025 Str255 path_name, unix_path_name; | 8048 Str255 path_name, unix_path_name; |
8026 #ifdef MAC_OSX | |
8027 FSRef fref; | |
8028 #endif | |
8029 | 8049 |
8030 err = AEGetNthPtr(&the_desc, i, typeFSS, &keyword, &actual_type, | 8050 err = AEGetNthPtr(&the_desc, i, typeFSS, &keyword, &actual_type, |
8031 (Ptr) &fs, sizeof (fs), &actual_size); | 8051 (Ptr) &fs, sizeof (fs), &actual_size); |
8032 if (err != noErr) break; | 8052 if (err != noErr) continue; |
8033 | 8053 |
8034 #ifdef MAC_OSX | |
8035 err = FSpMakeFSRef (&fs, &fref); | |
8036 if (err != noErr) break; | |
8037 | |
8038 if (FSRefMakePath (&fref, unix_path_name, 255) == noErr) | |
8039 #else | |
8040 if (path_from_vol_dir_name (path_name, 255, fs.vRefNum, fs.parID, | 8054 if (path_from_vol_dir_name (path_name, 255, fs.vRefNum, fs.parID, |
8041 fs.name) && | 8055 fs.name) && |
8042 mac_to_posix_pathname (path_name, unix_path_name, 255)) | 8056 mac_to_posix_pathname (path_name, unix_path_name, 255)) |
8043 #endif | 8057 #endif |
8044 /* x-dnd functions expect undecoded filenames. */ | 8058 /* x-dnd functions expect undecoded filenames. */ |
8070 short index; | 8084 short index; |
8071 ItemReference theItem; | 8085 ItemReference theItem; |
8072 FlavorFlags theFlags; | 8086 FlavorFlags theFlags; |
8073 OSErr result; | 8087 OSErr result; |
8074 | 8088 |
8089 if (GetFrontWindowOfClass (kMovableModalWindowClass, false)) | |
8090 return dragNotAcceptedErr; | |
8091 | |
8075 switch (message) | 8092 switch (message) |
8076 { | 8093 { |
8077 case kDragTrackingEnterHandler: | 8094 case kDragTrackingEnterHandler: |
8078 CountDragItems (theDrag, &items); | 8095 CountDragItems (theDrag, &items); |
8079 can_accept = 1; | 8096 can_accept = 0; |
8080 for (index = 1; index <= items; index++) | 8097 for (index = 1; index <= items; index++) |
8081 { | 8098 { |
8082 GetDragItemReferenceNumber (theDrag, index, &theItem); | 8099 GetDragItemReferenceNumber (theDrag, index, &theItem); |
8083 result = GetFlavorFlags (theDrag, theItem, flavorTypeHFS, &theFlags); | 8100 result = GetFlavorFlags (theDrag, theItem, flavorTypeHFS, &theFlags); |
8084 if (result != noErr) | 8101 if (result == noErr) |
8085 { | 8102 { |
8086 can_accept = 0; | 8103 can_accept = 1; |
8087 break; | 8104 break; |
8088 } | 8105 } |
8089 } | 8106 } |
8090 break; | 8107 break; |
8091 | 8108 |
8092 case kDragTrackingEnterWindow: | 8109 case kDragTrackingEnterWindow: |
8093 if (can_accept) | 8110 if (can_accept) |
8094 { | 8111 { |
8095 RgnHandle hilite_rgn = NewRgn (); | 8112 RgnHandle hilite_rgn = NewRgn (); |
8096 Rect r; | 8113 Rect r; |
8097 | 8114 struct frame *f = mac_window_to_frame (window); |
8115 | |
8116 mac_set_backcolor (FRAME_BACKGROUND_PIXEL (f)); | |
8098 GetWindowPortBounds (window, &r); | 8117 GetWindowPortBounds (window, &r); |
8099 OffsetRect (&r, -r.left, -r.top); | 8118 OffsetRect (&r, -r.left, -r.top); |
8100 RectRgn (hilite_rgn, &r); | 8119 RectRgn (hilite_rgn, &r); |
8101 ShowDragHilite (theDrag, hilite_rgn, true); | 8120 ShowDragHilite (theDrag, hilite_rgn, true); |
8102 DisposeRgn (hilite_rgn); | 8121 DisposeRgn (hilite_rgn); |
8108 break; | 8127 break; |
8109 | 8128 |
8110 case kDragTrackingLeaveWindow: | 8129 case kDragTrackingLeaveWindow: |
8111 if (can_accept) | 8130 if (can_accept) |
8112 { | 8131 { |
8132 struct frame *f = mac_window_to_frame (window); | |
8133 | |
8134 mac_set_backcolor (FRAME_BACKGROUND_PIXEL (f)); | |
8113 HideDragHilite (theDrag); | 8135 HideDragHilite (theDrag); |
8114 SetThemeCursor (kThemeArrowCursor); | 8136 SetThemeCursor (kThemeArrowCursor); |
8115 } | 8137 } |
8116 break; | 8138 break; |
8117 | 8139 |
8131 FlavorFlags theFlags; | 8153 FlavorFlags theFlags; |
8132 Point mouse; | 8154 Point mouse; |
8133 OSErr result; | 8155 OSErr result; |
8134 ItemReference theItem; | 8156 ItemReference theItem; |
8135 HFSFlavor data; | 8157 HFSFlavor data; |
8136 FSRef fref; | |
8137 Size size = sizeof (HFSFlavor); | 8158 Size size = sizeof (HFSFlavor); |
8159 | |
8160 if (GetFrontWindowOfClass (kMovableModalWindowClass, false)) | |
8161 return dragNotAcceptedErr; | |
8138 | 8162 |
8139 drag_and_drop_file_list = Qnil; | 8163 drag_and_drop_file_list = Qnil; |
8140 GetDragMouse (theDrag, &mouse, 0L); | 8164 GetDragMouse (theDrag, &mouse, 0L); |
8141 CountDragItems (theDrag, &items); | 8165 CountDragItems (theDrag, &items); |
8142 for (index = 1; index <= items; index++) | 8166 for (index = 1; index <= items; index++) |
8145 GetDragItemReferenceNumber (theDrag, index, &theItem); | 8169 GetDragItemReferenceNumber (theDrag, index, &theItem); |
8146 result = GetFlavorFlags (theDrag, theItem, flavorTypeHFS, &theFlags); | 8170 result = GetFlavorFlags (theDrag, theItem, flavorTypeHFS, &theFlags); |
8147 if (result == noErr) | 8171 if (result == noErr) |
8148 { | 8172 { |
8149 #ifdef MAC_OSX | 8173 #ifdef MAC_OSX |
8150 FSRef frref; | 8174 FSRef fref; |
8175 char unix_path_name[MAXPATHLEN]; | |
8151 #else | 8176 #else |
8152 Str255 path_name; | 8177 Str255 path_name, unix_path_name; |
8153 #endif | 8178 #endif |
8154 Str255 unix_path_name; | |
8155 GetFlavorData (theDrag, theItem, flavorTypeHFS, &data, &size, 0L); | 8179 GetFlavorData (theDrag, theItem, flavorTypeHFS, &data, &size, 0L); |
8156 #ifdef MAC_OSX | 8180 #ifdef MAC_OSX |
8157 /* Use Carbon routines, otherwise it converts the file name | 8181 /* Use Carbon routines, otherwise it converts the file name |
8158 to /Macintosh HD/..., which is not correct. */ | 8182 to /Macintosh HD/..., which is not correct. */ |
8159 FSpMakeFSRef (&data.fileSpec, &fref); | 8183 FSpMakeFSRef (&data.fileSpec, &fref); |
8167 drag_and_drop_file_list = | 8191 drag_and_drop_file_list = |
8168 Fcons (make_unibyte_string (unix_path_name, | 8192 Fcons (make_unibyte_string (unix_path_name, |
8169 strlen (unix_path_name)), | 8193 strlen (unix_path_name)), |
8170 drag_and_drop_file_list); | 8194 drag_and_drop_file_list); |
8171 } | 8195 } |
8172 else | |
8173 continue; | |
8174 } | 8196 } |
8175 /* If there are items in the list, construct an event and post it to | 8197 /* If there are items in the list, construct an event and post it to |
8176 the queue like an interrupt using kbd_buffer_store_event. */ | 8198 the queue like an interrupt using kbd_buffer_store_event. */ |
8177 if (!NILP (drag_and_drop_file_list)) | 8199 if (!NILP (drag_and_drop_file_list)) |
8178 { | 8200 { |
8728 case updateEvt: | 8750 case updateEvt: |
8729 #if USE_CARBON_EVENTS | 8751 #if USE_CARBON_EVENTS |
8730 if (SendEventToEventTarget (eventRef, toolbox_dispatcher) | 8752 if (SendEventToEventTarget (eventRef, toolbox_dispatcher) |
8731 != eventNotHandledErr) | 8753 != eventNotHandledErr) |
8732 break; | 8754 break; |
8733 #endif | 8755 #else |
8734 do_window_update ((WindowPtr) er.message); | 8756 do_window_update ((WindowPtr) er.message); |
8757 #endif | |
8735 break; | 8758 break; |
8736 | 8759 |
8737 case osEvt: | 8760 case osEvt: |
8738 #if USE_CARBON_EVENTS | 8761 #if USE_CARBON_EVENTS |
8739 if (SendEventToEventTarget (eventRef, toolbox_dispatcher) | 8762 if (SendEventToEventTarget (eventRef, toolbox_dispatcher) |