aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSteven Tamm2004-12-29 17:25:02 +0000
committerSteven Tamm2004-12-29 17:25:02 +0000
commit30c92fab793df102666fff234d59377003a79462 (patch)
tree00e78822e7949e23a8d5ad92ef0b08bf52504724 /src
parent2f7717f601c768019ee2a73a7f3535c5de74512b (diff)
downloademacs-30c92fab793df102666fff234d59377003a79462.tar.gz
emacs-30c92fab793df102666fff234d59377003a79462.zip
* term/mac-win.el: Require x-dnd.
(mac-drag-n-drop): Sync with W32 version. Use x-dnd.el functions. * macfns.c (install_window_handler): Modify extern to return OSErr value. (mac_window): Handle return value of install_window_handler. * macterm.c (reflect_byte): Remove function. (mac_create_bitmap_from_bitmap_data): Don't call it. Lookup table instead. (mac_do_font_lists): Simplify calculation of the longest nonspecial string. [TARGET_API_MAC_CARBON] (init_mac_drag_n_drop): Remove function and declaration. (mac_initialize) [TARGET_API_MAC_CARBON]: Don't call it. [TARGET_API_MAC_CARBON] (mac_do_track_drag): New function and declaration. (install_window_handler): Return OSErr value. (install_window_handler) [TARGET_API_MAC_CARBON]: Register handlers for tracking/receiving drag-and-drop items. (do_ae_open_documents): Generate unibyte strings for filenames. [TARGET_API_MAC_CARBON] (mac_do_receive_drag): Likewise. Reject only non-filename items. Set event modifiers. Set return value.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog22
-rw-r--r--src/macfns.c10
-rw-r--r--src/macterm.c169
3 files changed, 142 insertions, 59 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 08d14cb67e8..fa6e2280cbf 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,25 @@
12004-12-29 YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
2
3 * macfns.c (install_window_handler): Modify extern to return OSErr
4 value.
5 (mac_window): Handle return value of install_window_handler.
6
7 * macterm.c (reflect_byte): Remove function.
8 (mac_create_bitmap_from_bitmap_data): Don't call reflect_byte.
9 Lookup table instead.
10 (mac_do_font_lists): Simplify calculation of the longest
11 nonspecial string.
12 (init_mac_drag_n_drop): Remove function and declaration.
13 (mac_initialize) [TARGET_API_MAC_CARBON]: Don't call
14 init_mac_drag_n_drop.
15 (mac_do_track_drag): New function and declaration.
16 (install_window_handler): Return OSErr value.
17 (install_window_handler) [TARGET_API_MAC_CARBON]: Register
18 handlers for tracking/receiving drag-and-drop items.
19 (do_ae_open_documents): Generate unibyte strings for filenames.
20 (mac_do_receive_drag) [TARGET_API_MAC_CARBON] : Likewise. Reject
21 only non-filename items. Set event modifiers. Set return value.
22
12004-12-28 Dan Nicolaescu <dann@ics.uci.edu> 232004-12-28 Dan Nicolaescu <dann@ics.uci.edu>
2 24
3 * coding.c (decode_coding): Fix previous change. 25 * coding.c (decode_coding): Fix previous change.
diff --git a/src/macfns.c b/src/macfns.c
index dfbc5dacd5e..f40e8354f35 100644
--- a/src/macfns.c
+++ b/src/macfns.c
@@ -158,7 +158,7 @@ Lisp_Object Qshift;
158 158
159extern Lisp_Object Vwindow_system_version; 159extern Lisp_Object Vwindow_system_version;
160 160
161#if 0 /* Use xstricmp instead. */ 161#if 0 /* Use xstricmp instead. */
162/* compare two strings ignoring case */ 162/* compare two strings ignoring case */
163 163
164static int 164static int
@@ -2261,7 +2261,7 @@ XParseGeometry (string, x, y, width, height)
2261 2261
2262/* Create and set up the Mac window for frame F. */ 2262/* Create and set up the Mac window for frame F. */
2263 2263
2264extern install_window_handler (WindowPtr); 2264extern OSErr install_window_handler (WindowPtr);
2265 2265
2266static void 2266static void
2267mac_window (f) 2267mac_window (f)
@@ -2282,7 +2282,11 @@ mac_window (f)
2282 if (FRAME_MAC_WINDOW (f)) 2282 if (FRAME_MAC_WINDOW (f))
2283 { 2283 {
2284 SetWRefCon (FRAME_MAC_WINDOW (f), (long) f->output_data.mac); 2284 SetWRefCon (FRAME_MAC_WINDOW (f), (long) f->output_data.mac);
2285 install_window_handler (FRAME_MAC_WINDOW (f)); 2285 if (install_window_handler (FRAME_MAC_WINDOW (f)) != noErr)
2286 {
2287 DisposeWindow (FRAME_MAC_WINDOW (f));
2288 FRAME_MAC_WINDOW (f) = NULL;
2289 }
2286 } 2290 }
2287#else 2291#else
2288 FRAME_MAC_WINDOW (f) 2292 FRAME_MAC_WINDOW (f)
diff --git a/src/macterm.c b/src/macterm.c
index 3f1fb1642f1..745457f0ff3 100644
--- a/src/macterm.c
+++ b/src/macterm.c
@@ -511,23 +511,6 @@ mac_reset_clipping (display, w)
511} 511}
512 512
513 513
514/* XBM bits seem to be backward within bytes compared with how
515 Mac does things. */
516static unsigned char
517reflect_byte (orig)
518 unsigned char orig;
519{
520 int i;
521 unsigned char reflected = 0x00;
522 for (i = 0; i < 8; i++)
523 {
524 if (orig & (0x01 << i))
525 reflected |= 0x80 >> i;
526 }
527 return reflected;
528}
529
530
531/* Mac replacement for XCreateBitmapFromBitmapData. */ 514/* Mac replacement for XCreateBitmapFromBitmapData. */
532 515
533static void 516static void
@@ -536,6 +519,11 @@ mac_create_bitmap_from_bitmap_data (bitmap, bits, w, h)
536 char *bits; 519 char *bits;
537 int w, h; 520 int w, h;
538{ 521{
522 static unsigned char swap_nibble[16]
523 = { 0x0, 0x8, 0x4, 0xc, /* 0000 1000 0100 1100 */
524 0x2, 0xa, 0x6, 0xe, /* 0010 1010 0110 1110 */
525 0x1, 0x9, 0x5, 0xd, /* 0001 1001 0101 1101 */
526 0x3, 0xb, 0x7, 0xf }; /* 0011 1011 0111 1111 */
539 int i, j, w1; 527 int i, j, w1;
540 char *p; 528 char *p;
541 529
@@ -547,7 +535,12 @@ mac_create_bitmap_from_bitmap_data (bitmap, bits, w, h)
547 { 535 {
548 p = bitmap->baseAddr + i * bitmap->rowBytes; 536 p = bitmap->baseAddr + i * bitmap->rowBytes;
549 for (j = 0; j < w1; j++) 537 for (j = 0; j < w1; j++)
550 *p++ = reflect_byte (*bits++); 538 {
539 /* Bitswap XBM bytes to match how Mac does things. */
540 unsigned char c = *bits++;
541 *p++ = (unsigned char)((swap_nibble[c & 0xf] << 4)
542 | (swap_nibble[(c>>4) & 0xf]));;
543 }
551 } 544 }
552 545
553 SetRect (&(bitmap->bounds), 0, 0, w, h); 546 SetRect (&(bitmap->bounds), 0, 0, w, h);
@@ -6256,7 +6249,7 @@ mac_do_list_fonts (pattern, maxnames)
6256 char *ptr; 6249 char *ptr;
6257 int scl_val[XLFD_SCL_LAST], *field, *val; 6250 int scl_val[XLFD_SCL_LAST], *field, *val;
6258 char *longest_start, *cur_start, *nonspecial; 6251 char *longest_start, *cur_start, *nonspecial;
6259 int longest_len, cur_len, exact; 6252 int longest_len, exact;
6260 6253
6261 if (font_name_table == NULL) /* Initialize when first used. */ 6254 if (font_name_table == NULL) /* Initialize when first used. */
6262 init_font_name_table (); 6255 init_font_name_table ();
@@ -6318,7 +6311,7 @@ mac_do_list_fonts (pattern, maxnames)
6318 *ptr++ = '^'; 6311 *ptr++ = '^';
6319 6312
6320 longest_start = cur_start = ptr; 6313 longest_start = cur_start = ptr;
6321 longest_len = cur_len = 0; 6314 longest_len = 0;
6322 exact = 1; 6315 exact = 1;
6323 6316
6324 /* Turn pattern into a regexp and do a regexp match. Also find the 6317 /* Turn pattern into a regexp and do a regexp match. Also find the
@@ -6327,12 +6320,11 @@ mac_do_list_fonts (pattern, maxnames)
6327 { 6320 {
6328 if (*pattern == '?' || *pattern == '*') 6321 if (*pattern == '?' || *pattern == '*')
6329 { 6322 {
6330 if (cur_len > longest_len) 6323 if (ptr - cur_start > longest_len)
6331 { 6324 {
6332 longest_start = cur_start; 6325 longest_start = cur_start;
6333 longest_len = cur_len; 6326 longest_len = ptr - cur_start;
6334 } 6327 }
6335 cur_len = 0;
6336 exact = 0; 6328 exact = 0;
6337 6329
6338 if (*pattern == '?') 6330 if (*pattern == '?')
@@ -6342,21 +6334,16 @@ mac_do_list_fonts (pattern, maxnames)
6342 *ptr++ = '.'; 6334 *ptr++ = '.';
6343 *ptr++ = '*'; 6335 *ptr++ = '*';
6344 } 6336 }
6337 cur_start = ptr;
6345 } 6338 }
6346 else 6339 else
6347 { 6340 *ptr++ = tolower (*pattern);
6348 if (cur_len == 0)
6349 cur_start = ptr;
6350 cur_len++;
6351
6352 *ptr++ = tolower (*pattern);
6353 }
6354 } 6341 }
6355 6342
6356 if (cur_len > longest_len) 6343 if (ptr - cur_start > longest_len)
6357 { 6344 {
6358 longest_start = cur_start; 6345 longest_start = cur_start;
6359 longest_len = cur_len; 6346 longest_len = ptr - cur_start;
6360 } 6347 }
6361 6348
6362 *ptr = '$'; 6349 *ptr = '$';
@@ -7086,7 +7073,7 @@ static pascal OSErr do_ae_quit_application (AppleEvent *, AppleEvent *, long);
7086 7073
7087#if TARGET_API_MAC_CARBON 7074#if TARGET_API_MAC_CARBON
7088/* Drag and Drop */ 7075/* Drag and Drop */
7089static OSErr init_mac_drag_n_drop (); 7076static pascal OSErr mac_do_track_drag (DragTrackingMessage, WindowPtr, void*, DragReference);
7090static pascal OSErr mac_do_receive_drag (WindowPtr, void*, DragReference); 7077static pascal OSErr mac_do_receive_drag (WindowPtr, void*, DragReference);
7091#endif 7078#endif
7092 7079
@@ -7098,7 +7085,7 @@ static void init_service_handler ();
7098static pascal OSStatus mac_handle_window_event (EventHandlerCallRef, 7085static pascal OSStatus mac_handle_window_event (EventHandlerCallRef,
7099 EventRef, void *); 7086 EventRef, void *);
7100#endif 7087#endif
7101void install_window_handler (WindowPtr); 7088OSErr install_window_handler (WindowPtr);
7102 7089
7103extern void init_emacs_passwd_dir (); 7090extern void init_emacs_passwd_dir ();
7104extern int emacs_main (int, char **, char **); 7091extern int emacs_main (int, char **, char **);
@@ -7659,16 +7646,6 @@ do_zoom_window (WindowPtr w, int zoom_in_or_out)
7659 x_real_positions (f, &f->left_pos, &f->top_pos); 7646 x_real_positions (f, &f->left_pos, &f->top_pos);
7660} 7647}
7661 7648
7662#if TARGET_API_MAC_CARBON
7663/* Initialize Drag And Drop to allow files to be dropped onto emacs frames */
7664static OSErr
7665init_mac_drag_n_drop ()
7666{
7667 OSErr result = InstallReceiveHandler (mac_do_receive_drag, 0L, NULL);
7668 return result;
7669}
7670#endif
7671
7672/* Intialize AppleEvent dispatcher table for the required events. */ 7649/* Intialize AppleEvent dispatcher table for the required events. */
7673void 7650void
7674init_required_apple_events () 7651init_required_apple_events ()
@@ -7909,10 +7886,11 @@ mac_handle_window_event (next_handler, event, data)
7909#endif /* USE_CARBON_EVENTS */ 7886#endif /* USE_CARBON_EVENTS */
7910 7887
7911 7888
7912void 7889OSErr
7913install_window_handler (window) 7890install_window_handler (window)
7914 WindowPtr window; 7891 WindowPtr window;
7915{ 7892{
7893 OSErr err = noErr;
7916#if USE_CARBON_EVENTS 7894#if USE_CARBON_EVENTS
7917 EventTypeSpec specs[] = {{kEventClassWindow, kEventWindowBoundsChanging}}; 7895 EventTypeSpec specs[] = {{kEventClassWindow, kEventWindowBoundsChanging}};
7918 static EventHandlerUPP handle_window_event_UPP = NULL; 7896 static EventHandlerUPP handle_window_event_UPP = NULL;
@@ -7920,9 +7898,17 @@ install_window_handler (window)
7920 if (handle_window_event_UPP == NULL) 7898 if (handle_window_event_UPP == NULL)
7921 handle_window_event_UPP = NewEventHandlerUPP (mac_handle_window_event); 7899 handle_window_event_UPP = NewEventHandlerUPP (mac_handle_window_event);
7922 7900
7923 InstallWindowEventHandler (window, handle_window_event_UPP, 7901 err = InstallWindowEventHandler (window, handle_window_event_UPP,
7924 GetEventTypeCount (specs), specs, NULL, NULL); 7902 GetEventTypeCount (specs), specs,
7903 NULL, NULL);
7904#endif
7905#if TARGET_API_MAC_CARBON
7906 if (err == noErr)
7907 err = InstallTrackingHandler (mac_do_track_drag, window, NULL);
7908 if (err == noErr)
7909 err = InstallReceiveHandler (mac_do_receive_drag, window, NULL);
7925#endif 7910#endif
7911 return err;
7926} 7912}
7927 7913
7928 7914
@@ -8004,8 +7990,11 @@ do_ae_open_documents(AppleEvent *message, AppleEvent *reply, long refcon)
8004 fs.name) && 7990 fs.name) &&
8005 mac_to_posix_pathname (path_name, unix_path_name, 255)) 7991 mac_to_posix_pathname (path_name, unix_path_name, 255))
8006#endif 7992#endif
8007 drag_and_drop_file_list = Fcons (build_string (unix_path_name), 7993 /* x-dnd functions expect undecoded filenames. */
8008 drag_and_drop_file_list); 7994 drag_and_drop_file_list =
7995 Fcons (make_unibyte_string (unix_path_name,
7996 strlen (unix_path_name)),
7997 drag_and_drop_file_list);
8009 } 7998 }
8010 } 7999 }
8011 } 8000 }
@@ -8022,6 +8011,67 @@ descriptor_error_exit:
8022 8011
8023#if TARGET_API_MAC_CARBON 8012#if TARGET_API_MAC_CARBON
8024static pascal OSErr 8013static pascal OSErr
8014mac_do_track_drag (DragTrackingMessage message, WindowPtr window,
8015 void *handlerRefCon, DragReference theDrag)
8016{
8017 static int can_accept;
8018 short items;
8019 short index;
8020 ItemReference theItem;
8021 FlavorFlags theFlags;
8022 OSErr result;
8023
8024 switch (message)
8025 {
8026 case kDragTrackingEnterHandler:
8027 CountDragItems (theDrag, &items);
8028 can_accept = 1;
8029 for (index = 1; index <= items; index++)
8030 {
8031 GetDragItemReferenceNumber (theDrag, index, &theItem);
8032 result = GetFlavorFlags (theDrag, theItem, flavorTypeHFS, &theFlags);
8033 if (result != noErr)
8034 {
8035 can_accept = 0;
8036 break;
8037 }
8038 }
8039 break;
8040
8041 case kDragTrackingEnterWindow:
8042 if (can_accept)
8043 {
8044 RgnHandle hilite_rgn = NewRgn ();
8045 Rect r;
8046
8047 GetWindowPortBounds (window, &r);
8048 OffsetRect (&r, -r.left, -r.top);
8049 RectRgn (hilite_rgn, &r);
8050 ShowDragHilite (theDrag, hilite_rgn, true);
8051 DisposeRgn (hilite_rgn);
8052 SetThemeCursor (kThemeCopyArrowCursor);
8053 }
8054 break;
8055
8056 case kDragTrackingInWindow:
8057 break;
8058
8059 case kDragTrackingLeaveWindow:
8060 if (can_accept)
8061 {
8062 HideDragHilite (theDrag);
8063 SetThemeCursor (kThemeArrowCursor);
8064 }
8065 break;
8066
8067 case kDragTrackingLeaveHandler:
8068 break;
8069 }
8070
8071 return noErr;
8072}
8073
8074static pascal OSErr
8025mac_do_receive_drag (WindowPtr window, void *handlerRefCon, 8075mac_do_receive_drag (WindowPtr window, void *handlerRefCon,
8026 DragReference theDrag) 8076 DragReference theDrag)
8027{ 8077{
@@ -8062,11 +8112,14 @@ mac_do_receive_drag (WindowPtr window, void *handlerRefCon,
8062 data.fileSpec.parID, data.fileSpec.name) && 8112 data.fileSpec.parID, data.fileSpec.name) &&
8063 mac_to_posix_pathname (path_name, unix_path_name, 255)) 8113 mac_to_posix_pathname (path_name, unix_path_name, 255))
8064#endif 8114#endif
8065 drag_and_drop_file_list = Fcons (build_string (unix_path_name), 8115 /* x-dnd functions expect undecoded filenames. */
8066 drag_and_drop_file_list); 8116 drag_and_drop_file_list =
8117 Fcons (make_unibyte_string (unix_path_name,
8118 strlen (unix_path_name)),
8119 drag_and_drop_file_list);
8067 } 8120 }
8068 else 8121 else
8069 return; 8122 continue;
8070 } 8123 }
8071 /* If there are items in the list, construct an event and post it to 8124 /* If there are items in the list, construct an event and post it to
8072 the queue like an interrupt using kbd_buffer_store_event. */ 8125 the queue like an interrupt using kbd_buffer_store_event. */
@@ -8075,12 +8128,14 @@ mac_do_receive_drag (WindowPtr window, void *handlerRefCon,
8075 struct input_event event; 8128 struct input_event event;
8076 Lisp_Object frame; 8129 Lisp_Object frame;
8077 struct frame *f = mac_window_to_frame (window); 8130 struct frame *f = mac_window_to_frame (window);
8078 SetPortWindowPort (window); 8131 SInt16 modifiers;
8132
8079 GlobalToLocal (&mouse); 8133 GlobalToLocal (&mouse);
8134 GetDragModifiers (theDrag, NULL, NULL, &modifiers);
8080 8135
8081 event.kind = DRAG_N_DROP_EVENT; 8136 event.kind = DRAG_N_DROP_EVENT;
8082 event.code = 0; 8137 event.code = 0;
8083 event.modifiers = 0; 8138 event.modifiers = mac_to_emacs_modifiers (modifiers);
8084 event.timestamp = TickCount () * (1000 / 60); 8139 event.timestamp = TickCount () * (1000 / 60);
8085 XSETINT (event.x, mouse.h); 8140 XSETINT (event.x, mouse.h);
8086 XSETINT (event.y, mouse.v); 8141 XSETINT (event.y, mouse.v);
@@ -8095,7 +8150,11 @@ mac_do_receive_drag (WindowPtr window, void *handlerRefCon,
8095 GetCurrentProcess (&psn); 8150 GetCurrentProcess (&psn);
8096 SetFrontProcess (&psn); 8151 SetFrontProcess (&psn);
8097 } 8152 }
8153
8154 return noErr;
8098 } 8155 }
8156 else
8157 return dragNotAcceptedErr;
8099} 8158}
8100#endif 8159#endif
8101 8160
@@ -9580,8 +9639,6 @@ mac_initialize ()
9580#if TARGET_API_MAC_CARBON 9639#if TARGET_API_MAC_CARBON
9581 init_required_apple_events (); 9640 init_required_apple_events ();
9582 9641
9583 init_mac_drag_n_drop ();
9584
9585#if USE_CARBON_EVENTS 9642#if USE_CARBON_EVENTS
9586 init_service_handler (); 9643 init_service_handler ();
9587 9644