comparison src/macterm.c @ 60364:de784812b4d4

[TARGET_API_MAC_CARBON && !MAC_OSX]: Define USE_CARBON_EVENTS to 1. [__MRC__ && TARGET_API_MAC_CARBON]: Don't declare `qd'. (x_free_frame_resources): Call remove_window_handler for non-tooltip windows. [TARGET_API_MAC_CARBON]: Don't include headers that are included via Carbon.h. [TARGET_API_MAC_CARBON] (mac_do_track_dragUPP) (mac_do_receive_dragUPP): New variables. (mac_handle_service_event, init_service_handler): Put declarations and definitions in #ifdef MAC_OSX. (install_window_handler) [TARGET_API_MAC_CARBON]: Create UPPs for drag-and-drop handler functions and register them. (remove_window_handler): New function. (do_ae_open_documents, mac_do_receive_drag) [!MAC_OSX]: Use fsspec_to_posix_pathname. (main): Change #if !TARGET_API_MAC_CARBON to #ifdef MAC_OS8. (XTread_socket) [!MAC_OSX]: Don't pass keyboard events to TSM. [MAC_OS8] (make_mac_terminal_frame) [TARGET_API_MAC_CARBON]: Set default cursors. (mac_initialize) [USE_CARBON_EVENTS && !MAC_OSX] : Don't call init_service_handler or init_quit_char_handler. (mac_initialize) [!MAC_OSX]: Don't call MakeMeTheFrontProcess.
author YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
date Fri, 04 Mar 2005 11:11:16 +0000
parents 96a18b943293
children 4536f307a219 1f334cdd7020 29e773288013
comparison
equal deleted inserted replaced
60363:c4138f578114 60364:de784812b4d4
32 32
33 #ifndef MAC_OSX 33 #ifndef MAC_OSX
34 #include <alloca.h> 34 #include <alloca.h>
35 #endif 35 #endif
36 36
37 #ifdef MAC_OSX 37 #if TARGET_API_MAC_CARBON
38 /* USE_CARBON_EVENTS determines if the Carbon Event Manager is used to 38 /* USE_CARBON_EVENTS determines if the Carbon Event Manager is used to
39 obtain events from the event queue. If set to 0, WaitNextEvent is 39 obtain events from the event queue. If set to 0, WaitNextEvent is
40 used instead. */ 40 used instead. */
41 #define USE_CARBON_EVENTS 1 41 #define USE_CARBON_EVENTS 1
42 #else /* not MAC_OSX */ 42 #else /* not TARGET_API_MAC_CARBON */
43 #include <Quickdraw.h> 43 #include <Quickdraw.h>
44 #include <ToolUtils.h> 44 #include <ToolUtils.h>
45 #include <Sound.h> 45 #include <Sound.h>
46 #include <Events.h> 46 #include <Events.h>
47 #include <Script.h> 47 #include <Script.h>
56 #endif 56 #endif
57 57
58 #if __profile__ 58 #if __profile__
59 #include <profiler.h> 59 #include <profiler.h>
60 #endif 60 #endif
61 #endif /* not MAC_OSX */ 61 #endif /* not TARGET_API_MAC_CARBON */
62 62
63 #include "systty.h" 63 #include "systty.h"
64 #include "systime.h" 64 #include "systime.h"
65 #include "atimer.h" 65 #include "atimer.h"
66 #include "keymap.h" 66 #include "keymap.h"
243 extern XrmDatabase x_load_resources P_ ((Display *, char *, char *, char *)); 243 extern XrmDatabase x_load_resources P_ ((Display *, char *, char *, char *));
244 #endif 244 #endif
245 245
246 extern int inhibit_window_system; 246 extern int inhibit_window_system;
247 247
248 #if __MRC__ 248 #if __MRC__ && !TARGET_API_MAC_CARBON
249 QDGlobals qd; /* QuickDraw global information structure. */ 249 QDGlobals qd; /* QuickDraw global information structure. */
250 #endif 250 #endif
251 251
252 252
253 struct frame * x_window_to_frame (struct mac_display_info *, WindowPtr); 253 struct frame * x_window_to_frame (struct mac_display_info *, WindowPtr);
5571 { 5571 {
5572 struct mac_display_info *dpyinfo = FRAME_MAC_DISPLAY_INFO (f); 5572 struct mac_display_info *dpyinfo = FRAME_MAC_DISPLAY_INFO (f);
5573 WindowPtr wp = FRAME_MAC_WINDOW (f); 5573 WindowPtr wp = FRAME_MAC_WINDOW (f);
5574 5574
5575 BLOCK_INPUT; 5575 BLOCK_INPUT;
5576
5577 if (wp != tip_window)
5578 remove_window_handler (wp);
5576 5579
5577 DisposeWindow (wp); 5580 DisposeWindow (wp);
5578 if (wp == tip_window) 5581 if (wp == tip_window)
5579 /* Neither WaitNextEvent nor ReceiveNextEvent receives `window 5582 /* Neither WaitNextEvent nor ReceiveNextEvent receives `window
5580 closed' event. So we reset tip_window here. */ 5583 closed' event. So we reset tip_window here. */
7076 7079
7077 7080
7078 7081
7079 /* The Mac Event loop code */ 7082 /* The Mac Event loop code */
7080 7083
7081 #ifndef MAC_OSX 7084 #if !TARGET_API_MAC_CARBON
7082 #include <Events.h> 7085 #include <Events.h>
7083 #include <Quickdraw.h> 7086 #include <Quickdraw.h>
7084 #include <Balloons.h> 7087 #include <Balloons.h>
7085 #include <Devices.h> 7088 #include <Devices.h>
7086 #include <Fonts.h> 7089 #include <Fonts.h>
7097 #include <Resources.h> 7100 #include <Resources.h>
7098 7101
7099 #if __MWERKS__ 7102 #if __MWERKS__
7100 #include <unix.h> 7103 #include <unix.h>
7101 #endif 7104 #endif
7102 #endif /* ! MAC_OSX */ 7105 #endif /* ! TARGET_API_MAC_CARBON */
7103 7106
7104 #define M_APPLE 128 7107 #define M_APPLE 128
7105 #define I_ABOUT 1 7108 #define I_ABOUT 1
7106 7109
7107 #define WINDOW_RESOURCE 128 7110 #define WINDOW_RESOURCE 128
7198 7201
7199 #if TARGET_API_MAC_CARBON 7202 #if TARGET_API_MAC_CARBON
7200 /* Drag and Drop */ 7203 /* Drag and Drop */
7201 static pascal OSErr mac_do_track_drag (DragTrackingMessage, WindowPtr, void*, DragReference); 7204 static pascal OSErr mac_do_track_drag (DragTrackingMessage, WindowPtr, void*, DragReference);
7202 static pascal OSErr mac_do_receive_drag (WindowPtr, void*, DragReference); 7205 static pascal OSErr mac_do_receive_drag (WindowPtr, void*, DragReference);
7206 static DragTrackingHandlerUPP mac_do_track_dragUPP = NULL;
7207 static DragReceiveHandlerUPP mac_do_receive_dragUPP = NULL;
7203 #endif 7208 #endif
7204 7209
7205 #if USE_CARBON_EVENTS 7210 #if USE_CARBON_EVENTS
7211 #ifdef MAC_OSX
7206 /* Preliminary Support for the OSX Services Menu */ 7212 /* Preliminary Support for the OSX Services Menu */
7207 static OSStatus mac_handle_service_event (EventHandlerCallRef,EventRef,void*); 7213 static OSStatus mac_handle_service_event (EventHandlerCallRef,EventRef,void*);
7208 static void init_service_handler (); 7214 static void init_service_handler ();
7215 #endif
7209 /* Window Event Handler */ 7216 /* Window Event Handler */
7210 static pascal OSStatus mac_handle_window_event (EventHandlerCallRef, 7217 static pascal OSStatus mac_handle_window_event (EventHandlerCallRef,
7211 EventRef, void *); 7218 EventRef, void *);
7212 #endif 7219 #endif
7213 OSErr install_window_handler (WindowPtr); 7220 OSErr install_window_handler (WindowPtr);
7842 if (err != noErr) 7849 if (err != noErr)
7843 abort (); 7850 abort ();
7844 } 7851 }
7845 7852
7846 #if USE_CARBON_EVENTS 7853 #if USE_CARBON_EVENTS
7847 7854 #ifdef MAC_OSX
7848 void 7855 void
7849 init_service_handler () 7856 init_service_handler ()
7850 { 7857 {
7851 EventTypeSpec specs[] = {{kEventClassService, kEventServiceGetTypes}, 7858 EventTypeSpec specs[] = {{kEventClassService, kEventServiceGetTypes},
7852 {kEventClassService, kEventServiceCopy}, 7859 {kEventClassService, kEventServiceCopy},
7938 */ 7945 */
7939 } 7946 }
7940 } 7947 }
7941 return err; 7948 return err;
7942 } 7949 }
7943 7950 #endif
7944 7951
7945 static pascal OSStatus 7952 static pascal OSStatus
7946 mac_handle_window_event (next_handler, event, data) 7953 mac_handle_window_event (next_handler, event, data)
7947 EventHandlerCallRef next_handler; 7954 EventHandlerCallRef next_handler;
7948 EventRef event; 7955 EventRef event;
8035 err = InstallWindowEventHandler (window, handle_window_event_UPP, 8042 err = InstallWindowEventHandler (window, handle_window_event_UPP,
8036 GetEventTypeCount (specs), specs, 8043 GetEventTypeCount (specs), specs,
8037 NULL, NULL); 8044 NULL, NULL);
8038 #endif 8045 #endif
8039 #if TARGET_API_MAC_CARBON 8046 #if TARGET_API_MAC_CARBON
8047 if (mac_do_track_dragUPP == NULL)
8048 mac_do_track_dragUPP = NewDragTrackingHandlerUPP (mac_do_track_drag);
8049 if (mac_do_receive_dragUPP == NULL)
8050 mac_do_receive_dragUPP = NewDragReceiveHandlerUPP (mac_do_receive_drag);
8051
8040 if (err == noErr) 8052 if (err == noErr)
8041 err = InstallTrackingHandler (mac_do_track_drag, window, NULL); 8053 err = InstallTrackingHandler (mac_do_track_dragUPP, window, NULL);
8042 if (err == noErr) 8054 if (err == noErr)
8043 err = InstallReceiveHandler (mac_do_receive_drag, window, NULL); 8055 err = InstallReceiveHandler (mac_do_receive_dragUPP, window, NULL);
8044 #endif 8056 #endif
8045 return err; 8057 return err;
8046 } 8058 }
8047 8059
8060 void
8061 remove_window_handler (window)
8062 WindowPtr window;
8063 {
8064 #if TARGET_API_MAC_CARBON
8065 if (mac_do_track_dragUPP)
8066 RemoveTrackingHandler (mac_do_track_dragUPP, window);
8067 if (mac_do_receive_dragUPP)
8068 RemoveReceiveHandler (mac_do_receive_dragUPP, window);
8069 #endif
8070 }
8048 8071
8049 /* Open Application Apple Event */ 8072 /* Open Application Apple Event */
8050 static pascal OSErr 8073 static pascal OSErr
8051 do_ae_open_application(const AppleEvent *pae, AppleEvent *preply, long prefcon) 8074 do_ae_open_application(const AppleEvent *pae, AppleEvent *preply, long prefcon)
8052 { 8075 {
8121 int i; 8144 int i;
8122 8145
8123 /* AE file list is one based so just use that for indexing here. */ 8146 /* AE file list is one based so just use that for indexing here. */
8124 for (i = 1; i <= num_files_to_open; i++) 8147 for (i = 1; i <= num_files_to_open; i++)
8125 { 8148 {
8149 char unix_path_name[MAXPATHLEN];
8126 #ifdef MAC_OSX 8150 #ifdef MAC_OSX
8127 FSRef fref; 8151 FSRef fref;
8128 char unix_path_name[MAXPATHLEN];
8129 8152
8130 err = AEGetNthPtr (&the_desc, i, typeFSRef, &keyword, 8153 err = AEGetNthPtr (&the_desc, i, typeFSRef, &keyword,
8131 &actual_type, &fref, sizeof (FSRef), 8154 &actual_type, &fref, sizeof (FSRef),
8132 &actual_size); 8155 &actual_size);
8133 if (err != noErr || actual_type != typeFSRef) 8156 if (err != noErr || actual_type != typeFSRef)
8135 8158
8136 if (FSRefMakePath (&fref, unix_path_name, sizeof (unix_path_name)) 8159 if (FSRefMakePath (&fref, unix_path_name, sizeof (unix_path_name))
8137 == noErr) 8160 == noErr)
8138 #else 8161 #else
8139 FSSpec fs; 8162 FSSpec fs;
8140 Str255 path_name, unix_path_name;
8141 8163
8142 err = AEGetNthPtr(&the_desc, i, typeFSS, &keyword, &actual_type, 8164 err = AEGetNthPtr(&the_desc, i, typeFSS, &keyword, &actual_type,
8143 (Ptr) &fs, sizeof (fs), &actual_size); 8165 (Ptr) &fs, sizeof (fs), &actual_size);
8144 if (err != noErr) continue; 8166 if (err != noErr) continue;
8145 8167
8146 if (path_from_vol_dir_name (path_name, 255, fs.vRefNum, fs.parID, 8168 if (fsspec_to_posix_pathname (&fs, unix_path_name,
8147 fs.name) && 8169 sizeof (unix_path_name) - 1) == noErr)
8148 mac_to_posix_pathname (path_name, unix_path_name, 255))
8149 #endif 8170 #endif
8150 /* x-dnd functions expect undecoded filenames. */ 8171 /* x-dnd functions expect undecoded filenames. */
8151 drag_and_drop_file_list = 8172 drag_and_drop_file_list =
8152 Fcons (make_unibyte_string (unix_path_name, 8173 Fcons (make_unibyte_string (unix_path_name,
8153 strlen (unix_path_name)), 8174 strlen (unix_path_name)),
8262 result = GetFlavorFlags (theDrag, theItem, flavorTypeHFS, &theFlags); 8283 result = GetFlavorFlags (theDrag, theItem, flavorTypeHFS, &theFlags);
8263 if (result == noErr) 8284 if (result == noErr)
8264 { 8285 {
8265 #ifdef MAC_OSX 8286 #ifdef MAC_OSX
8266 FSRef fref; 8287 FSRef fref;
8288 #endif
8267 char unix_path_name[MAXPATHLEN]; 8289 char unix_path_name[MAXPATHLEN];
8268 #else 8290
8269 Str255 path_name, unix_path_name;
8270 #endif
8271 GetFlavorData (theDrag, theItem, flavorTypeHFS, &data, &size, 0L); 8291 GetFlavorData (theDrag, theItem, flavorTypeHFS, &data, &size, 0L);
8272 #ifdef MAC_OSX 8292 #ifdef MAC_OSX
8273 /* Use Carbon routines, otherwise it converts the file name 8293 /* Use Carbon routines, otherwise it converts the file name
8274 to /Macintosh HD/..., which is not correct. */ 8294 to /Macintosh HD/..., which is not correct. */
8275 FSpMakeFSRef (&data.fileSpec, &fref); 8295 FSpMakeFSRef (&data.fileSpec, &fref);
8276 if (! FSRefMakePath (&fref, unix_path_name, sizeof (unix_path_name))); 8296 if (! FSRefMakePath (&fref, unix_path_name, sizeof (unix_path_name)));
8277 #else 8297 #else
8278 if (path_from_vol_dir_name (path_name, 255, data.fileSpec.vRefNum, 8298 if (fsspec_to_posix_pathname (&data.fileSpec, unix_path_name,
8279 data.fileSpec.parID, data.fileSpec.name) && 8299 sizeof (unix_path_name) - 1) == noErr)
8280 mac_to_posix_pathname (path_name, unix_path_name, 255))
8281 #endif 8300 #endif
8282 /* x-dnd functions expect undecoded filenames. */ 8301 /* x-dnd functions expect undecoded filenames. */
8283 drag_and_drop_file_list = 8302 drag_and_drop_file_list =
8284 Fcons (make_unibyte_string (unix_path_name, 8303 Fcons (make_unibyte_string (unix_path_name,
8285 strlen (unix_path_name)), 8304 strlen (unix_path_name)),
8372 This makes the cursor jump back to its correct position after 8391 This makes the cursor jump back to its correct position after
8373 briefly jumping to that of the matching parenthesis, print useful 8392 briefly jumping to that of the matching parenthesis, print useful
8374 hints and prompts in the minibuffer after the user stops typing for 8393 hints and prompts in the minibuffer after the user stops typing for
8375 a wait, etc. */ 8394 a wait, etc. */
8376 8395
8377 #if !TARGET_API_MAC_CARBON 8396 #ifdef MAC_OS8
8378 #undef main 8397 #undef main
8379 int 8398 int
8380 main (void) 8399 main (void)
8381 { 8400 {
8382 #if __profile__ /* is the profiler on? */ 8401 #if __profile__ /* is the profiler on? */
8954 case autoKey: 8973 case autoKey:
8955 { 8974 {
8956 int keycode = (er.message & keyCodeMask) >> 8; 8975 int keycode = (er.message & keyCodeMask) >> 8;
8957 int xkeysym; 8976 int xkeysym;
8958 8977
8959 #if USE_CARBON_EVENTS 8978 #if USE_CARBON_EVENTS && defined (MAC_OSX)
8960 /* When using Carbon Events, we need to pass raw keyboard 8979 /* When using Carbon Events, we need to pass raw keyboard
8961 events to the TSM ourselves. If TSM handles it, it 8980 events to the TSM ourselves. If TSM handles it, it
8962 will pass back noErr, otherwise it will pass back 8981 will pass back noErr, otherwise it will pass back
8963 "eventNotHandledErr" and we can process it 8982 "eventNotHandledErr" and we can process it
8964 normally. */ 8983 normally. */
9263 f->output_data.mac->cursor_pixel = 0; 9282 f->output_data.mac->cursor_pixel = 0;
9264 f->output_data.mac->border_pixel = 0x00ff00; 9283 f->output_data.mac->border_pixel = 0x00ff00;
9265 f->output_data.mac->mouse_pixel = 0xff00ff; 9284 f->output_data.mac->mouse_pixel = 0xff00ff;
9266 f->output_data.mac->cursor_foreground_pixel = 0x0000ff; 9285 f->output_data.mac->cursor_foreground_pixel = 0x0000ff;
9267 9286
9287 #if TARGET_API_MAC_CARBON
9288 f->output_data.mac->text_cursor = kThemeIBeamCursor;
9289 f->output_data.mac->nontext_cursor = kThemeArrowCursor;
9290 f->output_data.mac->modeline_cursor = kThemeArrowCursor;
9291 f->output_data.mac->hand_cursor = kThemePointingHandCursor;
9292 f->output_data.mac->hourglass_cursor = kThemeWatchCursor;
9293 f->output_data.mac->horizontal_drag_cursor = kThemeResizeLeftRightCursor;
9294 #else
9268 f->output_data.mac->text_cursor = GetCursor (iBeamCursor); 9295 f->output_data.mac->text_cursor = GetCursor (iBeamCursor);
9269 f->output_data.mac->nontext_cursor = &arrow_cursor; 9296 f->output_data.mac->nontext_cursor = &arrow_cursor;
9270 f->output_data.mac->modeline_cursor = &arrow_cursor; 9297 f->output_data.mac->modeline_cursor = &arrow_cursor;
9271 f->output_data.mac->hand_cursor = &arrow_cursor; 9298 f->output_data.mac->hand_cursor = &arrow_cursor;
9272 f->output_data.mac->hourglass_cursor = GetCursor (watchCursor); 9299 f->output_data.mac->hourglass_cursor = GetCursor (watchCursor);
9273 f->output_data.mac->horizontal_drag_cursor = &arrow_cursor; 9300 f->output_data.mac->horizontal_drag_cursor = &arrow_cursor;
9301 #endif
9274 9302
9275 FRAME_FONTSET (f) = -1; 9303 FRAME_FONTSET (f) = -1;
9276 f->output_data.mac->explicit_parent = 0; 9304 f->output_data.mac->explicit_parent = 0;
9277 f->left_pos = 8; 9305 f->left_pos = 8;
9278 f->top_pos = 32; 9306 f->top_pos = 32;
9803 BLOCK_INPUT; 9831 BLOCK_INPUT;
9804 9832
9805 #if TARGET_API_MAC_CARBON 9833 #if TARGET_API_MAC_CARBON
9806 init_required_apple_events (); 9834 init_required_apple_events ();
9807 9835
9808 #if USE_CARBON_EVENTS 9836 #if USE_CARBON_EVENTS && defined (MAC_OSX)
9809 init_service_handler (); 9837 init_service_handler ();
9810 9838
9811 init_quit_char_handler (); 9839 init_quit_char_handler ();
9812 #endif 9840 #endif
9813 9841
9814 DisableMenuCommand (NULL, kHICommandQuit); 9842 DisableMenuCommand (NULL, kHICommandQuit);
9815 9843
9844 #ifdef MAC_OSX
9816 if (!inhibit_window_system) 9845 if (!inhibit_window_system)
9817 MakeMeTheFrontProcess (); 9846 MakeMeTheFrontProcess ();
9847 #endif
9818 #endif 9848 #endif
9819 UNBLOCK_INPUT; 9849 UNBLOCK_INPUT;
9820 } 9850 }
9821 9851
9822 9852