aboutsummaryrefslogtreecommitdiffstats
path: root/src/macterm.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/macterm.c')
-rw-r--r--src/macterm.c1542
1 files changed, 797 insertions, 745 deletions
diff --git a/src/macterm.c b/src/macterm.c
index 44029032bbd..360dccd4f16 100644
--- a/src/macterm.c
+++ b/src/macterm.c
@@ -53,7 +53,6 @@ Boston, MA 02111-1307, USA. */
53#if defined (__MRC__) || (__MSL__ >= 0x6000) 53#if defined (__MRC__) || (__MSL__ >= 0x6000)
54#include <ControlDefinitions.h> 54#include <ControlDefinitions.h>
55#endif 55#endif
56#include <Gestalt.h>
57 56
58#if __profile__ 57#if __profile__
59#include <profiler.h> 58#include <profiler.h>
@@ -196,14 +195,6 @@ static Lisp_Object last_mouse_scroll_bar;
196 195
197static Time last_mouse_movement_time; 196static Time last_mouse_movement_time;
198 197
199enum mouse_tracking_type {
200 mouse_tracking_none,
201 mouse_tracking_mouse_movement,
202 mouse_tracking_scroll_bar
203};
204
205enum mouse_tracking_type mouse_tracking_in_progress = mouse_tracking_none;
206
207struct scroll_bar *tracked_scroll_bar = NULL; 198struct scroll_bar *tracked_scroll_bar = NULL;
208 199
209/* Incremented by XTread_socket whenever it really tries to read 200/* Incremented by XTread_socket whenever it really tries to read
@@ -294,7 +285,6 @@ void deactivate_scroll_bars (FRAME_PTR);
294 285
295static int is_emacs_window (WindowPtr); 286static int is_emacs_window (WindowPtr);
296 287
297extern int image_ascent (struct image *, struct face *);
298int x_bitmap_icon (struct frame *, Lisp_Object); 288int x_bitmap_icon (struct frame *, Lisp_Object);
299void x_make_frame_visible (struct frame *); 289void x_make_frame_visible (struct frame *);
300 290
@@ -311,7 +301,7 @@ XFreePixmap (display, pixmap)
311 Display *display; /* not used */ 301 Display *display; /* not used */
312 Pixmap pixmap; 302 Pixmap pixmap;
313{ 303{
314 DisposeGWorld (pixmap); 304 DisposeGWorld (pixmap);
315} 305}
316 306
317 307
@@ -365,11 +355,7 @@ XDrawLine (display, w, gc, x1, y1, x2, y2)
365 GC gc; 355 GC gc;
366 int x1, y1, x2, y2; 356 int x1, y1, x2, y2;
367{ 357{
368#if TARGET_API_MAC_CARBON 358 SetPortWindowPort (w);
369 SetPort (GetWindowPort (w));
370#else
371 SetPort (w);
372#endif
373 359
374 mac_set_colors (gc); 360 mac_set_colors (gc);
375 361
@@ -384,6 +370,10 @@ mac_draw_line_to_pixmap (display, p, gc, x1, y1, x2, y2)
384 GC gc; 370 GC gc;
385 int x1, y1, x2, y2; 371 int x1, y1, x2, y2;
386{ 372{
373 CGrafPtr old_port;
374 GDHandle old_gdh;
375
376 GetGWorld (&old_port, &old_gdh);
387 SetGWorld (p, NULL); 377 SetGWorld (p, NULL);
388 378
389 mac_set_colors (gc); 379 mac_set_colors (gc);
@@ -392,6 +382,8 @@ mac_draw_line_to_pixmap (display, p, gc, x1, y1, x2, y2)
392 MoveTo (x1, y1); 382 MoveTo (x1, y1);
393 LineTo (x2, y2); 383 LineTo (x2, y2);
394 UnlockPixels (GetGWorldPixMap (p)); 384 UnlockPixels (GetGWorldPixMap (p));
385
386 SetGWorld (old_port, old_gdh);
395} 387}
396 388
397/* Mac version of XClearArea. */ 389/* Mac version of XClearArea. */
@@ -411,11 +403,7 @@ XClearArea (display, w, x, y, width, height, exposures)
411 xgc.foreground = mwp->x_compatible.foreground_pixel; 403 xgc.foreground = mwp->x_compatible.foreground_pixel;
412 xgc.background = mwp->x_compatible.background_pixel; 404 xgc.background = mwp->x_compatible.background_pixel;
413 405
414#if TARGET_API_MAC_CARBON 406 SetPortWindowPort (w);
415 SetPort (GetWindowPort (w));
416#else
417 SetPort (w);
418#endif
419 407
420 mac_set_colors (&xgc); 408 mac_set_colors (&xgc);
421 SetRect (&r, x, y, x + width, y + height); 409 SetRect (&r, x, y, x + width, y + height);
@@ -436,11 +424,7 @@ XClearWindow (display, w)
436 xgc.foreground = mwp->x_compatible.foreground_pixel; 424 xgc.foreground = mwp->x_compatible.foreground_pixel;
437 xgc.background = mwp->x_compatible.background_pixel; 425 xgc.background = mwp->x_compatible.background_pixel;
438 426
439#if TARGET_API_MAC_CARBON 427 SetPortWindowPort (w);
440 SetPort (GetWindowPort (w));
441#else
442 SetPort (w);
443#endif
444 428
445 mac_set_colors (&xgc); 429 mac_set_colors (&xgc);
446 430
@@ -475,11 +459,7 @@ mac_draw_bitmap (display, w, gc, x, y, width, height, bits, overlay_p)
475 bitmap.baseAddr = (char *)bits; 459 bitmap.baseAddr = (char *)bits;
476 SetRect (&(bitmap.bounds), 0, 0, width, height); 460 SetRect (&(bitmap.bounds), 0, 0, width, height);
477 461
478#if TARGET_API_MAC_CARBON 462 SetPortWindowPort (w);
479 SetPort (GetWindowPort (w));
480#else
481 SetPort (w);
482#endif
483 463
484 mac_set_colors (gc); 464 mac_set_colors (gc);
485 SetRect (&r, x, y, x + width, y + height); 465 SetRect (&r, x, y, x + width, y + height);
@@ -504,11 +484,7 @@ mac_set_clip_rectangle (display, w, r)
504 WindowPtr w; 484 WindowPtr w;
505 Rect *r; 485 Rect *r;
506{ 486{
507#if TARGET_API_MAC_CARBON 487 SetPortWindowPort (w);
508 SetPort (GetWindowPort (w));
509#else
510 SetPort (w);
511#endif
512 488
513 ClipRect (r); 489 ClipRect (r);
514} 490}
@@ -523,11 +499,7 @@ mac_reset_clipping (display, w)
523{ 499{
524 Rect r; 500 Rect r;
525 501
526#if TARGET_API_MAC_CARBON 502 SetPortWindowPort (w);
527 SetPort (GetWindowPort (w));
528#else
529 SetPort (w);
530#endif
531 503
532 SetRect (&r, -32767, -32767, 32767, 32767); 504 SetRect (&r, -32767, -32767, 32767, 32767);
533 ClipRect (&r); 505 ClipRect (&r);
@@ -596,11 +568,7 @@ XCreatePixmap (display, w, width, height, depth)
596 Rect r; 568 Rect r;
597 QDErr err; 569 QDErr err;
598 570
599#if TARGET_API_MAC_CARBON 571 SetPortWindowPort (w);
600 SetPort (GetWindowPort (w));
601#else
602 SetPort (w);
603#endif
604 572
605 SetRect (&r, 0, 0, width, height); 573 SetRect (&r, 0, 0, width, height);
606 err = NewGWorld (&pixmap, depth, &r, NULL, NULL, 0); 574 err = NewGWorld (&pixmap, depth, &r, NULL, NULL, 0);
@@ -621,11 +589,14 @@ XCreatePixmapFromBitmapData (display, w, data, width, height, fg, bg, depth)
621{ 589{
622 Pixmap pixmap; 590 Pixmap pixmap;
623 BitMap bitmap; 591 BitMap bitmap;
592 CGrafPtr old_port;
593 GDHandle old_gdh;
624 594
625 pixmap = XCreatePixmap (display, w, width, height, depth); 595 pixmap = XCreatePixmap (display, w, width, height, depth);
626 if (pixmap == NULL) 596 if (pixmap == NULL)
627 return NULL; 597 return NULL;
628 598
599 GetGWorld (&old_port, &old_gdh);
629 SetGWorld (pixmap, NULL); 600 SetGWorld (pixmap, NULL);
630 mac_create_bitmap_from_bitmap_data (&bitmap, data, width, height); 601 mac_create_bitmap_from_bitmap_data (&bitmap, data, width, height);
631 mac_set_forecolor (fg); 602 mac_set_forecolor (fg);
@@ -639,6 +610,7 @@ XCreatePixmapFromBitmapData (display, w, data, width, height, fg, bg, depth)
639 &bitmap.bounds, &bitmap.bounds, srcCopy, 0); 610 &bitmap.bounds, &bitmap.bounds, srcCopy, 0);
640#endif /* not TARGET_API_MAC_CARBON */ 611#endif /* not TARGET_API_MAC_CARBON */
641 UnlockPixels (GetGWorldPixMap (pixmap)); 612 UnlockPixels (GetGWorldPixMap (pixmap));
613 SetGWorld (old_port, old_gdh);
642 mac_free_bitmap (&bitmap); 614 mac_free_bitmap (&bitmap);
643 615
644 return pixmap; 616 return pixmap;
@@ -657,11 +629,7 @@ XFillRectangle (display, w, gc, x, y, width, height)
657{ 629{
658 Rect r; 630 Rect r;
659 631
660#if TARGET_API_MAC_CARBON 632 SetPortWindowPort (w);
661 SetPort (GetWindowPort (w));
662#else
663 SetPort (w);
664#endif
665 633
666 mac_set_colors (gc); 634 mac_set_colors (gc);
667 SetRect (&r, x, y, x + width, y + height); 635 SetRect (&r, x, y, x + width, y + height);
@@ -678,8 +646,11 @@ mac_fill_rectangle_to_pixmap (display, p, gc, x, y, width, height)
678 int x, y; 646 int x, y;
679 unsigned int width, height; 647 unsigned int width, height;
680{ 648{
649 CGrafPtr old_port;
650 GDHandle old_gdh;
681 Rect r; 651 Rect r;
682 652
653 GetGWorld (&old_port, &old_gdh);
683 SetGWorld (p, NULL); 654 SetGWorld (p, NULL);
684 mac_set_colors (gc); 655 mac_set_colors (gc);
685 SetRect (&r, x, y, x + width, y + height); 656 SetRect (&r, x, y, x + width, y + height);
@@ -687,6 +658,8 @@ mac_fill_rectangle_to_pixmap (display, p, gc, x, y, width, height)
687 LockPixels (GetGWorldPixMap (p)); 658 LockPixels (GetGWorldPixMap (p));
688 PaintRect (&r); /* using foreground color of gc */ 659 PaintRect (&r); /* using foreground color of gc */
689 UnlockPixels (GetGWorldPixMap (p)); 660 UnlockPixels (GetGWorldPixMap (p));
661
662 SetGWorld (old_port, old_gdh);
690} 663}
691 664
692 665
@@ -702,11 +675,7 @@ mac_draw_rectangle (display, w, gc, x, y, width, height)
702{ 675{
703 Rect r; 676 Rect r;
704 677
705#if TARGET_API_MAC_CARBON 678 SetPortWindowPort (w);
706 SetPort (GetWindowPort (w));
707#else
708 SetPort (w);
709#endif
710 679
711 mac_set_colors (gc); 680 mac_set_colors (gc);
712 SetRect (&r, x, y, x + width + 1, y + height + 1); 681 SetRect (&r, x, y, x + width + 1, y + height + 1);
@@ -725,8 +694,11 @@ mac_draw_rectangle_to_pixmap (display, p, gc, x, y, width, height)
725 int x, y; 694 int x, y;
726 unsigned int width, height; 695 unsigned int width, height;
727{ 696{
697 CGrafPtr old_port;
698 GDHandle old_gdh;
728 Rect r; 699 Rect r;
729 700
701 GetGWorld (&old_port, &old_gdh);
730 SetGWorld (p, NULL); 702 SetGWorld (p, NULL);
731 mac_set_colors (gc); 703 mac_set_colors (gc);
732 SetRect (&r, x, y, x + width + 1, y + height + 1); 704 SetRect (&r, x, y, x + width + 1, y + height + 1);
@@ -734,6 +706,8 @@ mac_draw_rectangle_to_pixmap (display, p, gc, x, y, width, height)
734 LockPixels (GetGWorldPixMap (p)); 706 LockPixels (GetGWorldPixMap (p));
735 FrameRect (&r); /* using foreground color of gc */ 707 FrameRect (&r); /* using foreground color of gc */
736 UnlockPixels (GetGWorldPixMap (p)); 708 UnlockPixels (GetGWorldPixMap (p));
709
710 SetGWorld (old_port, old_gdh);
737} 711}
738 712
739 713
@@ -747,11 +721,7 @@ mac_draw_string_common (display, w, gc, x, y, buf, nchars, mode,
747 char *buf; 721 char *buf;
748 int nchars, mode, bytes_per_char; 722 int nchars, mode, bytes_per_char;
749{ 723{
750#if TARGET_API_MAC_CARBON 724 SetPortWindowPort (w);
751 SetPort (GetWindowPort (w));
752#else
753 SetPort (w);
754#endif
755 725
756 mac_set_colors (gc); 726 mac_set_colors (gc);
757 727
@@ -842,11 +812,7 @@ mac_copy_area (display, src, dest, gc, src_x, src_y, width, height, dest_x,
842{ 812{
843 Rect src_r, dest_r; 813 Rect src_r, dest_r;
844 814
845#if TARGET_API_MAC_CARBON 815 SetPortWindowPort (dest);
846 SetPort (GetWindowPort (dest));
847#else
848 SetPort (dest);
849#endif
850 816
851 SetRect (&src_r, src_x, src_y, src_x + width, src_y + height); 817 SetRect (&src_r, src_x, src_y, src_x + width, src_y + height);
852 SetRect (&dest_r, dest_x, dest_y, dest_x + width, dest_y + height); 818 SetRect (&dest_r, dest_x, dest_y, dest_x + width, dest_y + height);
@@ -882,11 +848,7 @@ mac_copy_area_with_mask (display, src, mask, dest, gc, src_x, src_y,
882{ 848{
883 Rect src_r, dest_r; 849 Rect src_r, dest_r;
884 850
885#if TARGET_API_MAC_CARBON 851 SetPortWindowPort (dest);
886 SetPort (GetWindowPort (dest));
887#else
888 SetPort (dest);
889#endif
890 852
891 SetRect (&src_r, src_x, src_y, src_x + width, src_y + height); 853 SetRect (&src_r, src_x, src_y, src_x + width, src_y + height);
892 SetRect (&dest_r, dest_x, dest_y, dest_x + width, dest_y + height); 854 SetRect (&dest_r, dest_x, dest_y, dest_x + width, dest_y + height);
@@ -946,7 +908,7 @@ mac_scroll_area (display, w, gc, src_x, src_y, width, height, dest_x, dest_y)
946 SetRect (&src_r, src_x, src_y, src_x + width, src_y + height); 908 SetRect (&src_r, src_x, src_y, src_x + width, src_y + height);
947 SetRect (&dest_r, dest_x, dest_y, dest_x + width, dest_y + height); 909 SetRect (&dest_r, dest_x, dest_y, dest_x + width, dest_y + height);
948 910
949 SetPort (GetWindowPort (w)); 911 SetPortWindowPort (w);
950 912
951 ForeColor (blackColor); 913 ForeColor (blackColor);
952 BackColor (whiteColor); 914 BackColor (whiteColor);
@@ -1004,8 +966,11 @@ mac_copy_area_to_pixmap (display, src, dest, gc, src_x, src_y, width, height,
1004 unsigned int width, height; 966 unsigned int width, height;
1005 int dest_x, dest_y; 967 int dest_x, dest_y;
1006{ 968{
969 CGrafPtr old_port;
970 GDHandle old_gdh;
1007 Rect src_r, dest_r; 971 Rect src_r, dest_r;
1008 972
973 GetGWorld (&old_port, &old_gdh);
1009 SetGWorld (dest, NULL); 974 SetGWorld (dest, NULL);
1010 ForeColor (blackColor); 975 ForeColor (blackColor);
1011 BackColor (whiteColor); 976 BackColor (whiteColor);
@@ -1024,6 +989,8 @@ mac_copy_area_to_pixmap (display, src, dest, gc, src_x, src_y, width, height,
1024#endif /* not TARGET_API_MAC_CARBON */ 989#endif /* not TARGET_API_MAC_CARBON */
1025 UnlockPixels (GetGWorldPixMap (dest)); 990 UnlockPixels (GetGWorldPixMap (dest));
1026 UnlockPixels (GetGWorldPixMap (src)); 991 UnlockPixels (GetGWorldPixMap (src));
992
993 SetGWorld (old_port, old_gdh);
1027} 994}
1028 995
1029 996
@@ -1037,8 +1004,11 @@ mac_copy_area_with_mask_to_pixmap (display, src, mask, dest, gc, src_x, src_y,
1037 unsigned int width, height; 1004 unsigned int width, height;
1038 int dest_x, dest_y; 1005 int dest_x, dest_y;
1039{ 1006{
1007 CGrafPtr old_port;
1008 GDHandle old_gdh;
1040 Rect src_r, dest_r; 1009 Rect src_r, dest_r;
1041 1010
1011 GetGWorld (&old_port, &old_gdh);
1042 SetGWorld (dest, NULL); 1012 SetGWorld (dest, NULL);
1043 ForeColor (blackColor); 1013 ForeColor (blackColor);
1044 BackColor (whiteColor); 1014 BackColor (whiteColor);
@@ -1059,6 +1029,8 @@ mac_copy_area_with_mask_to_pixmap (display, src, mask, dest, gc, src_x, src_y,
1059 UnlockPixels (GetGWorldPixMap (dest)); 1029 UnlockPixels (GetGWorldPixMap (dest));
1060 UnlockPixels (GetGWorldPixMap (mask)); 1030 UnlockPixels (GetGWorldPixMap (mask));
1061 UnlockPixels (GetGWorldPixMap (src)); 1031 UnlockPixels (GetGWorldPixMap (src));
1032
1033 SetGWorld (old_port, old_gdh);
1062} 1034}
1063 1035
1064 1036
@@ -1181,7 +1153,7 @@ x_flush (f)
1181 FOR_EACH_FRAME (rest, frame) 1153 FOR_EACH_FRAME (rest, frame)
1182 x_flush (XFRAME (frame)); 1154 x_flush (XFRAME (frame));
1183 } 1155 }
1184 else if (FRAME_X_P (f)) 1156 else if (FRAME_MAC_P (f))
1185 XFlush (FRAME_MAC_DISPLAY (f)); 1157 XFlush (FRAME_MAC_DISPLAY (f));
1186 UNBLOCK_INPUT; 1158 UNBLOCK_INPUT;
1187#endif /* TARGET_API_MAC_CARBON */ 1159#endif /* TARGET_API_MAC_CARBON */
@@ -1261,7 +1233,7 @@ x_update_window_begin (w)
1261 { 1233 {
1262 int i; 1234 int i;
1263 1235
1264 for (i = 0; i < w->desired_matrix->nrows; ++i) 1236 for (i = 0; i < w->desired_matrix->nrows; ++i)
1265 if (MATRIX_ROW_ENABLED_P (w->desired_matrix, i)) 1237 if (MATRIX_ROW_ENABLED_P (w->desired_matrix, i))
1266 break; 1238 break;
1267 1239
@@ -1283,7 +1255,7 @@ mac_draw_vertical_window_border (w, x, y0, y1)
1283 int x, y0, y1; 1255 int x, y0, y1;
1284{ 1256{
1285 struct frame *f = XFRAME (WINDOW_FRAME (w)); 1257 struct frame *f = XFRAME (WINDOW_FRAME (w));
1286 1258
1287 XDrawLine (FRAME_MAC_DISPLAY (f), FRAME_MAC_WINDOW (f), 1259 XDrawLine (FRAME_MAC_DISPLAY (f), FRAME_MAC_WINDOW (f),
1288 f->output_data.mac->normal_gc, x, y0, x, y1); 1260 f->output_data.mac->normal_gc, x, y0, x, y1);
1289} 1261}
@@ -1356,11 +1328,7 @@ x_update_end (f)
1356 /* Reset the background color of Mac OS Window to that of the frame after 1328 /* Reset the background color of Mac OS Window to that of the frame after
1357 update so that it is used by Mac Toolbox to clear the update region before 1329 update so that it is used by Mac Toolbox to clear the update region before
1358 an update event is generated. */ 1330 an update event is generated. */
1359#if TARGET_API_MAC_CARBON 1331 SetPortWindowPort (FRAME_MAC_WINDOW (f));
1360 SetPort (GetWindowPort (FRAME_MAC_WINDOW (f)));
1361#else
1362 SetPort (FRAME_MAC_WINDOW (f));
1363#endif
1364 1332
1365 mac_set_backcolor (FRAME_BACKGROUND_PIXEL (f)); 1333 mac_set_backcolor (FRAME_BACKGROUND_PIXEL (f));
1366 1334
@@ -1381,7 +1349,7 @@ static void
1381XTframe_up_to_date (f) 1349XTframe_up_to_date (f)
1382 struct frame *f; 1350 struct frame *f;
1383{ 1351{
1384 if (FRAME_X_P (f)) 1352 if (FRAME_MAC_P (f))
1385 { 1353 {
1386 struct mac_display_info *dpyinfo = FRAME_MAC_DISPLAY_INFO (f); 1354 struct mac_display_info *dpyinfo = FRAME_MAC_DISPLAY_INFO (f);
1387 1355
@@ -1525,7 +1493,7 @@ x_draw_fringe_bitmap (w, row, p)
1525 : face->foreground); 1493 : face->foreground);
1526 gcv.background = face->background; 1494 gcv.background = face->background;
1527 1495
1528 mac_draw_bitmap (display, window, &gcv, p->x, p->y, 1496 mac_draw_bitmap (display, window, &gcv, p->x, p->y,
1529 p->wd, p->h, bits, p->overlay_p); 1497 p->wd, p->h, bits, p->overlay_p);
1530 } 1498 }
1531 1499
@@ -1759,7 +1727,8 @@ static void x_draw_image_foreground_1 P_ ((struct glyph_string *, Pixmap));
1759static void x_clear_glyph_string_rect P_ ((struct glyph_string *, int, 1727static void x_clear_glyph_string_rect P_ ((struct glyph_string *, int,
1760 int, int, int)); 1728 int, int, int));
1761static void x_draw_relief_rect P_ ((struct frame *, int, int, int, int, 1729static void x_draw_relief_rect P_ ((struct frame *, int, int, int, int,
1762 int, int, int, int, Rect *)); 1730 int, int, int, int, int, int,
1731 Rect *));
1763static void x_draw_box_rect P_ ((struct glyph_string *, int, int, int, int, 1732static void x_draw_box_rect P_ ((struct glyph_string *, int, int, int, int,
1764 int, int, int, Rect *)); 1733 int, int, int, Rect *));
1765 1734
@@ -2483,9 +2452,10 @@ x_setup_relief_colors (s)
2483 2452
2484static void 2453static void
2485x_draw_relief_rect (f, left_x, top_y, right_x, bottom_y, width, 2454x_draw_relief_rect (f, left_x, top_y, right_x, bottom_y, width,
2486 raised_p, left_p, right_p, clip_rect) 2455 raised_p, top_p, bot_p, left_p, right_p, clip_rect)
2487 struct frame *f; 2456 struct frame *f;
2488 int left_x, top_y, right_x, bottom_y, width, left_p, right_p, raised_p; 2457 int left_x, top_y, right_x, bottom_y, width;
2458 int top_p, bot_p, left_p, right_p, raised_p;
2489 Rect *clip_rect; 2459 Rect *clip_rect;
2490{ 2460{
2491 Display *dpy = FRAME_MAC_DISPLAY (f); 2461 Display *dpy = FRAME_MAC_DISPLAY (f);
@@ -2500,10 +2470,11 @@ x_draw_relief_rect (f, left_x, top_y, right_x, bottom_y, width,
2500 mac_set_clip_rectangle (dpy, window, clip_rect); 2470 mac_set_clip_rectangle (dpy, window, clip_rect);
2501 2471
2502 /* Top. */ 2472 /* Top. */
2503 for (i = 0; i < width; ++i) 2473 if (top_p)
2504 XDrawLine (dpy, window, gc, 2474 for (i = 0; i < width; ++i)
2505 left_x + i * left_p, top_y + i, 2475 XDrawLine (dpy, window, gc,
2506 right_x - i * right_p, top_y + i); 2476 left_x + i * left_p, top_y + i,
2477 right_x - i * right_p, top_y + i);
2507 2478
2508 /* Left. */ 2479 /* Left. */
2509 if (left_p) 2480 if (left_p)
@@ -2520,10 +2491,11 @@ x_draw_relief_rect (f, left_x, top_y, right_x, bottom_y, width,
2520 clip_rect); 2491 clip_rect);
2521 2492
2522 /* Bottom. */ 2493 /* Bottom. */
2523 for (i = 0; i < width; ++i) 2494 if (bot_p)
2524 XDrawLine (dpy, window, gc, 2495 for (i = 0; i < width; ++i)
2525 left_x + i * left_p, bottom_y - i, 2496 XDrawLine (dpy, window, gc,
2526 right_x - i * right_p, bottom_y - i); 2497 left_x + i * left_p, bottom_y - i,
2498 right_x - i * right_p, bottom_y - i);
2527 2499
2528 /* Right. */ 2500 /* Right. */
2529 if (right_p) 2501 if (right_p)
@@ -2629,7 +2601,7 @@ x_draw_glyph_string_box (s)
2629 { 2601 {
2630 x_setup_relief_colors (s); 2602 x_setup_relief_colors (s);
2631 x_draw_relief_rect (s->f, left_x, top_y, right_x, bottom_y, 2603 x_draw_relief_rect (s->f, left_x, top_y, right_x, bottom_y,
2632 width, raised_p, left_p, right_p, &clip_rect); 2604 width, raised_p, 1, 1, left_p, right_p, &clip_rect);
2633 } 2605 }
2634} 2606}
2635 2607
@@ -2640,21 +2612,22 @@ static void
2640x_draw_image_foreground (s) 2612x_draw_image_foreground (s)
2641 struct glyph_string *s; 2613 struct glyph_string *s;
2642{ 2614{
2643 int x; 2615 int x = s->x;
2644 int y = s->ybase - image_ascent (s->img, s->face); 2616 int y = s->ybase - image_ascent (s->img, s->face, &s->slice);
2645 2617
2646 /* If first glyph of S has a left box line, start drawing it to the 2618 /* If first glyph of S has a left box line, start drawing it to the
2647 right of that line. */ 2619 right of that line. */
2648 if (s->face->box != FACE_NO_BOX 2620 if (s->face->box != FACE_NO_BOX
2649 && s->first_glyph->left_box_line_p) 2621 && s->first_glyph->left_box_line_p
2650 x = s->x + abs (s->face->box_line_width); 2622 && s->slice.x == 0)
2651 else 2623 x += abs (s->face->box_line_width);
2652 x = s->x;
2653 2624
2654 /* If there is a margin around the image, adjust x- and y-position 2625 /* If there is a margin around the image, adjust x- and y-position
2655 by that margin. */ 2626 by that margin. */
2656 x += s->img->hmargin; 2627 if (s->slice.x == 0)
2657 y += s->img->vmargin; 2628 x += s->img->hmargin;
2629 if (s->slice.y == 0)
2630 y += s->img->vmargin;
2658 2631
2659 if (s->img->pixmap) 2632 if (s->img->pixmap)
2660 { 2633 {
@@ -2667,11 +2640,12 @@ x_draw_image_foreground (s)
2667 CONVERT_TO_XRECT (clip_rect, nr); 2640 CONVERT_TO_XRECT (clip_rect, nr);
2668 image_rect.x = x; 2641 image_rect.x = x;
2669 image_rect.y = y; 2642 image_rect.y = y;
2670 image_rect.width = s->img->width; 2643 image_rect.width = s->slice.width;
2671 image_rect.height = s->img->height; 2644 image_rect.height = s->slice.height;
2672 if (x_intersect_rectangles (&clip_rect, &image_rect, &r)) 2645 if (x_intersect_rectangles (&clip_rect, &image_rect, &r))
2673 mac_copy_area_with_mask (s->display, s->img->pixmap, s->img->mask, 2646 mac_copy_area_with_mask (s->display, s->img->pixmap, s->img->mask,
2674 s->window, s->gc, r.x - x, r.y - y, 2647 s->window, s->gc,
2648 s->slice.x + r.x - x, s->slice.y + r.y - y,
2675 r.width, r.height, r.x, r.y); 2649 r.width, r.height, r.x, r.y);
2676 } 2650 }
2677 else 2651 else
@@ -2683,11 +2657,12 @@ x_draw_image_foreground (s)
2683 CONVERT_TO_XRECT (clip_rect, nr); 2657 CONVERT_TO_XRECT (clip_rect, nr);
2684 image_rect.x = x; 2658 image_rect.x = x;
2685 image_rect.y = y; 2659 image_rect.y = y;
2686 image_rect.width = s->img->width; 2660 image_rect.width = s->slice.width;
2687 image_rect.height = s->img->height; 2661 image_rect.height = s->slice.height;
2688 if (x_intersect_rectangles (&clip_rect, &image_rect, &r)) 2662 if (x_intersect_rectangles (&clip_rect, &image_rect, &r))
2689 mac_copy_area (s->display, s->img->pixmap, s->window, s->gc, 2663 mac_copy_area (s->display, s->img->pixmap, s->window, s->gc,
2690 r.x - x, r.y - y, r.width, r.height, r.x, r.y); 2664 s->slice.x + r.x - x, s->slice.y + r.y - y,
2665 r.width, r.height, r.x, r.y);
2691 2666
2692 /* When the image has a mask, we can expect that at 2667 /* When the image has a mask, we can expect that at
2693 least part of a mouse highlight or a block cursor will 2668 least part of a mouse highlight or a block cursor will
@@ -2699,15 +2674,17 @@ x_draw_image_foreground (s)
2699 { 2674 {
2700 int r = s->img->relief; 2675 int r = s->img->relief;
2701 if (r < 0) r = -r; 2676 if (r < 0) r = -r;
2702 mac_draw_rectangle (s->display, s->window, s->gc, x - r, y - r, 2677 mac_draw_rectangle (s->display, s->window, s->gc,
2703 s->img->width + r*2 - 1, s->img->height + r*2 - 1); 2678 x - r, y - r,
2679 s->slice.width + r*2 - 1,
2680 s->slice.height + r*2 - 1);
2704 } 2681 }
2705 } 2682 }
2706 } 2683 }
2707 else 2684 else
2708 /* Draw a rectangle if image could not be loaded. */ 2685 /* Draw a rectangle if image could not be loaded. */
2709 mac_draw_rectangle (s->display, s->window, s->gc, x, y, 2686 mac_draw_rectangle (s->display, s->window, s->gc, x, y,
2710 s->img->width - 1, s->img->height - 1); 2687 s->slice.width - 1, s->slice.height - 1);
2711} 2688}
2712 2689
2713 2690
@@ -2719,21 +2696,22 @@ x_draw_image_relief (s)
2719{ 2696{
2720 int x0, y0, x1, y1, thick, raised_p; 2697 int x0, y0, x1, y1, thick, raised_p;
2721 Rect r; 2698 Rect r;
2722 int x; 2699 int x = s->x;
2723 int y = s->ybase - image_ascent (s->img, s->face); 2700 int y = s->ybase - image_ascent (s->img, s->face, &s->slice);
2724 2701
2725 /* If first glyph of S has a left box line, start drawing it to the 2702 /* If first glyph of S has a left box line, start drawing it to the
2726 right of that line. */ 2703 right of that line. */
2727 if (s->face->box != FACE_NO_BOX 2704 if (s->face->box != FACE_NO_BOX
2728 && s->first_glyph->left_box_line_p) 2705 && s->first_glyph->left_box_line_p
2729 x = s->x + abs (s->face->box_line_width); 2706 && s->slice.x == 0)
2730 else 2707 x += abs (s->face->box_line_width);
2731 x = s->x;
2732 2708
2733 /* If there is a margin around the image, adjust x- and y-position 2709 /* If there is a margin around the image, adjust x- and y-position
2734 by that margin. */ 2710 by that margin. */
2735 x += s->img->hmargin; 2711 if (s->slice.x == 0)
2736 y += s->img->vmargin; 2712 x += s->img->hmargin;
2713 if (s->slice.y == 0)
2714 y += s->img->vmargin;
2737 2715
2738 if (s->hl == DRAW_IMAGE_SUNKEN 2716 if (s->hl == DRAW_IMAGE_SUNKEN
2739 || s->hl == DRAW_IMAGE_RAISED) 2717 || s->hl == DRAW_IMAGE_RAISED)
@@ -2749,12 +2727,17 @@ x_draw_image_relief (s)
2749 2727
2750 x0 = x - thick; 2728 x0 = x - thick;
2751 y0 = y - thick; 2729 y0 = y - thick;
2752 x1 = x + s->img->width + thick - 1; 2730 x1 = x + s->slice.width + thick - 1;
2753 y1 = y + s->img->height + thick - 1; 2731 y1 = y + s->slice.height + thick - 1;
2754 2732
2755 x_setup_relief_colors (s); 2733 x_setup_relief_colors (s);
2756 get_glyph_string_clip_rect (s, &r); 2734 get_glyph_string_clip_rect (s, &r);
2757 x_draw_relief_rect (s->f, x0, y0, x1, y1, thick, raised_p, 1, 1, &r); 2735 x_draw_relief_rect (s->f, x0, y0, x1, y1, thick, raised_p,
2736 s->slice.y == 0,
2737 s->slice.y + s->slice.height == s->img->height,
2738 s->slice.x == 0,
2739 s->slice.x + s->slice.width == s->img->width,
2740 &r);
2758} 2741}
2759 2742
2760 2743
@@ -2765,33 +2748,37 @@ x_draw_image_foreground_1 (s, pixmap)
2765 struct glyph_string *s; 2748 struct glyph_string *s;
2766 Pixmap pixmap; 2749 Pixmap pixmap;
2767{ 2750{
2768 int x; 2751 int x = 0;
2769 int y = s->ybase - s->y - image_ascent (s->img, s->face); 2752 int y = s->ybase - s->y - image_ascent (s->img, s->face, &s->slice);
2770 2753
2771 /* If first glyph of S has a left box line, start drawing it to the 2754 /* If first glyph of S has a left box line, start drawing it to the
2772 right of that line. */ 2755 right of that line. */
2773 if (s->face->box != FACE_NO_BOX 2756 if (s->face->box != FACE_NO_BOX
2774 && s->first_glyph->left_box_line_p) 2757 && s->first_glyph->left_box_line_p
2775 x = abs (s->face->box_line_width); 2758 && s->slice.x == 0)
2776 else 2759 x += abs (s->face->box_line_width);
2777 x = 0;
2778 2760
2779 /* If there is a margin around the image, adjust x- and y-position 2761 /* If there is a margin around the image, adjust x- and y-position
2780 by that margin. */ 2762 by that margin. */
2781 x += s->img->hmargin; 2763 if (s->slice.x == 0)
2782 y += s->img->vmargin; 2764 x += s->img->hmargin;
2765 if (s->slice.y == 0)
2766 y += s->img->vmargin;
2783 2767
2784 if (s->img->pixmap) 2768 if (s->img->pixmap)
2785 { 2769 {
2786 if (s->img->mask) 2770 if (s->img->mask)
2787 mac_copy_area_with_mask_to_pixmap (s->display, s->img->pixmap, 2771 mac_copy_area_with_mask_to_pixmap (s->display, s->img->pixmap,
2788 s->img->mask, pixmap, s->gc, 2772 s->img->mask, pixmap, s->gc,
2789 0, 0, s->img->width, s->img->height, 2773 s->slice.x, s->slice.y,
2774 s->slice.width, s->slice.height,
2790 x, y); 2775 x, y);
2791 else 2776 else
2792 { 2777 {
2793 mac_copy_area_to_pixmap (s->display, s->img->pixmap, pixmap, s->gc, 2778 mac_copy_area_to_pixmap (s->display, s->img->pixmap, pixmap, s->gc,
2794 0, 0, s->img->width, s->img->height, x, y); 2779 s->slice.x, s->slice.y,
2780 s->slice.width, s->slice.height,
2781 x, y);
2795 2782
2796 /* When the image has a mask, we can expect that at 2783 /* When the image has a mask, we can expect that at
2797 least part of a mouse highlight or a block cursor will 2784 least part of a mouse highlight or a block cursor will
@@ -2804,15 +2791,15 @@ x_draw_image_foreground_1 (s, pixmap)
2804 int r = s->img->relief; 2791 int r = s->img->relief;
2805 if (r < 0) r = -r; 2792 if (r < 0) r = -r;
2806 mac_draw_rectangle (s->display, s->window, s->gc, x - r, y - r, 2793 mac_draw_rectangle (s->display, s->window, s->gc, x - r, y - r,
2807 s->img->width + r*2 - 1, 2794 s->slice.width + r*2 - 1,
2808 s->img->height + r*2 - 1); 2795 s->slice.height + r*2 - 1);
2809 } 2796 }
2810 } 2797 }
2811 } 2798 }
2812 else 2799 else
2813 /* Draw a rectangle if image could not be loaded. */ 2800 /* Draw a rectangle if image could not be loaded. */
2814 mac_draw_rectangle_to_pixmap (s->display, pixmap, s->gc, x, y, 2801 mac_draw_rectangle_to_pixmap (s->display, pixmap, s->gc, x, y,
2815 s->img->width - 1, s->img->height - 1); 2802 s->slice.width - 1, s->slice.height - 1);
2816} 2803}
2817 2804
2818 2805
@@ -2869,19 +2856,21 @@ x_draw_image_glyph_string (s)
2869 taller than image or if image has a clip mask to reduce 2856 taller than image or if image has a clip mask to reduce
2870 flickering. */ 2857 flickering. */
2871 s->stippled_p = s->face->stipple != 0; 2858 s->stippled_p = s->face->stipple != 0;
2872 if (height > s->img->height 2859 if (height > s->slice.height
2873 || s->img->hmargin 2860 || s->img->hmargin
2874 || s->img->vmargin 2861 || s->img->vmargin
2875 || s->img->mask 2862 || s->img->mask
2876 || s->img->pixmap == 0 2863 || s->img->pixmap == 0
2877 || s->width != s->background_width) 2864 || s->width != s->background_width)
2878 { 2865 {
2879 if (box_line_hwidth && s->first_glyph->left_box_line_p) 2866 x = s->x;
2880 x = s->x + box_line_hwidth; 2867 if (s->first_glyph->left_box_line_p
2881 else 2868 && s->slice.x == 0)
2882 x = s->x; 2869 x += box_line_hwidth;
2883 2870
2884 y = s->y + box_line_vwidth; 2871 y = s->y;
2872 if (s->slice.y == 0)
2873 y += box_line_vwidth;
2885 2874
2886 if (s->img->mask) 2875 if (s->img->mask)
2887 { 2876 {
@@ -3695,11 +3684,7 @@ construct_mouse_click (result, event, f)
3695 3684
3696 mouseLoc = event->where; 3685 mouseLoc = event->where;
3697 3686
3698#if TARGET_API_MAC_CARBON 3687 SetPortWindowPort (FRAME_MAC_WINDOW (f));
3699 SetPort (GetWindowPort (FRAME_MAC_WINDOW (f)));
3700#else
3701 SetPort (FRAME_MAC_WINDOW (f));
3702#endif
3703 3688
3704 GlobalToLocal (&mouseLoc); 3689 GlobalToLocal (&mouseLoc);
3705 XSETINT (result->x, mouseLoc.h); 3690 XSETINT (result->x, mouseLoc.h);
@@ -3728,6 +3713,7 @@ note_mouse_movement (frame, pos)
3728 FRAME_PTR frame; 3713 FRAME_PTR frame;
3729 Point *pos; 3714 Point *pos;
3730{ 3715{
3716 struct mac_display_info *dpyinfo = FRAME_MAC_DISPLAY_INFO (frame);
3731#if TARGET_API_MAC_CARBON 3717#if TARGET_API_MAC_CARBON
3732 Rect r; 3718 Rect r;
3733#endif 3719#endif
@@ -3742,9 +3728,17 @@ note_mouse_movement (frame, pos)
3742 if (!PtInRect (*pos, &FRAME_MAC_WINDOW (frame)->portRect)) 3728 if (!PtInRect (*pos, &FRAME_MAC_WINDOW (frame)->portRect))
3743#endif 3729#endif
3744 { 3730 {
3745 frame->mouse_moved = 1; 3731 if (frame == dpyinfo->mouse_face_mouse_frame)
3746 last_mouse_scroll_bar = Qnil; 3732 /* This case corresponds to LeaveNotify in X11. */
3747 note_mouse_highlight (frame, -1, -1); 3733 {
3734 /* If we move outside the frame, then we're certainly no
3735 longer on any text in the frame. */
3736 clear_mouse_face (dpyinfo);
3737 dpyinfo->mouse_face_mouse_frame = 0;
3738 if (!dpyinfo->grabbed)
3739 rif->define_frame_cursor (frame,
3740 frame->output_data.mac->nontext_cursor);
3741 }
3748 } 3742 }
3749 /* Has the mouse moved off the glyph it was on at the last sighting? */ 3743 /* Has the mouse moved off the glyph it was on at the last sighting? */
3750 else if (pos->h < last_mouse_glyph.left 3744 else if (pos->h < last_mouse_glyph.left
@@ -3842,7 +3836,7 @@ glyph_rect (f, x, y, rect)
3842 3836
3843 /* x is to the right of the last glyph in the row. */ 3837 /* x is to the right of the last glyph in the row. */
3844 rect->left = WINDOW_TO_FRAME_PIXEL_X (w, gx); 3838 rect->left = WINDOW_TO_FRAME_PIXEL_X (w, gx);
3845 /* Shouldn't this be a pixel value? 3839 /* Shouldn't this be a pixel value?
3846 WINDOW_RIGHT_EDGE_X (w) seems to be the right value. 3840 WINDOW_RIGHT_EDGE_X (w) seems to be the right value.
3847 ++KFS */ 3841 ++KFS */
3848 rect->right = WINDOW_RIGHT_EDGE_COL (w); 3842 rect->right = WINDOW_RIGHT_EDGE_COL (w);
@@ -3892,6 +3886,23 @@ remember_mouse_glyph (f1, gx, gy)
3892} 3886}
3893 3887
3894 3888
3889static WindowPtr
3890mac_front_window ()
3891{
3892#if TARGET_API_MAC_CARBON
3893 return GetFrontWindowOfClass (kDocumentWindowClass, true);
3894#else
3895 WindowPtr front_window = FrontWindow ();
3896
3897 if (tip_window && front_window == tip_window)
3898 return GetNextWindow (front_window);
3899 else
3900 return front_window;
3901#endif
3902}
3903
3904#define mac_window_to_frame(wp) (((mac_output *) GetWRefCon (wp))->mFP)
3905
3895/* Return the current position of the mouse. 3906/* Return the current position of the mouse.
3896 *fp should be a frame which indicates which display to ask about. 3907 *fp should be a frame which indicates which display to ask about.
3897 3908
@@ -3923,12 +3934,12 @@ XTmouse_position (fp, insist, bar_window, part, x, y, time)
3923{ 3934{
3924 Point mouse_pos; 3935 Point mouse_pos;
3925 int ignore1, ignore2; 3936 int ignore1, ignore2;
3926 WindowPtr wp = FrontWindow (); 3937 WindowPtr wp = mac_front_window ();
3927 struct frame *f; 3938 struct frame *f;
3928 Lisp_Object frame, tail; 3939 Lisp_Object frame, tail;
3929 3940
3930 if (is_emacs_window(wp)) 3941 if (is_emacs_window(wp))
3931 f = ((mac_output *) GetWRefCon (wp))->mFP; 3942 f = mac_window_to_frame (wp);
3932 3943
3933 BLOCK_INPUT; 3944 BLOCK_INPUT;
3934 3945
@@ -3942,11 +3953,7 @@ XTmouse_position (fp, insist, bar_window, part, x, y, time)
3942 3953
3943 last_mouse_scroll_bar = Qnil; 3954 last_mouse_scroll_bar = Qnil;
3944 3955
3945#if TARGET_API_MAC_CARBON 3956 SetPortWindowPort (wp);
3946 SetPort (GetWindowPort (wp));
3947#else
3948 SetPort (wp);
3949#endif
3950 3957
3951 GetMouse (&mouse_pos); 3958 GetMouse (&mouse_pos);
3952 3959
@@ -3984,7 +3991,7 @@ mac_handle_tool_bar_click (f, button_event)
3984 if (button_event->what == mouseDown) 3991 if (button_event->what == mouseDown)
3985 handle_tool_bar_click (f, x, y, 1, 0); 3992 handle_tool_bar_click (f, x, y, 1, 0);
3986 else 3993 else
3987 handle_tool_bar_click (f, x, y, 0, 3994 handle_tool_bar_click (f, x, y, 0,
3988 x_mac_to_emacs_modifiers (FRAME_MAC_DISPLAY_INFO (f), 3995 x_mac_to_emacs_modifiers (FRAME_MAC_DISPLAY_INFO (f),
3989 button_event->modifiers)); 3996 button_event->modifiers));
3990} 3997}
@@ -4441,6 +4448,8 @@ x_scroll_bar_handle_click (bar, part_code, er, bufp)
4441 EventRecord *er; 4448 EventRecord *er;
4442 struct input_event *bufp; 4449 struct input_event *bufp;
4443{ 4450{
4451 int win_y, top_range;
4452
4444 if (! GC_WINDOWP (bar->window)) 4453 if (! GC_WINDOWP (bar->window))
4445 abort (); 4454 abort ();
4446 4455
@@ -4475,6 +4484,24 @@ x_scroll_bar_handle_click (bar, part_code, er, bufp)
4475 bufp->part = scroll_bar_handle; 4484 bufp->part = scroll_bar_handle;
4476 break; 4485 break;
4477 } 4486 }
4487
4488 win_y = XINT (bufp->y) - XINT (bar->top);
4489 top_range = VERTICAL_SCROLL_BAR_TOP_RANGE (0/*dummy*/, XINT (bar->height));
4490
4491 win_y -= VERTICAL_SCROLL_BAR_TOP_BORDER;
4492
4493 win_y -= 24;
4494
4495 if (! NILP (bar->dragging))
4496 win_y -= XINT (bar->dragging);
4497
4498 if (win_y < 0)
4499 win_y = 0;
4500 if (win_y > top_range)
4501 win_y = top_range;
4502
4503 XSETINT (bufp->x, win_y);
4504 XSETINT (bufp->y, top_range);
4478} 4505}
4479 4506
4480 4507
@@ -4524,16 +4551,12 @@ x_scroll_bar_report_motion (fp, bar_window, part, x, y, time)
4524 unsigned long *time; 4551 unsigned long *time;
4525{ 4552{
4526 struct scroll_bar *bar = XSCROLL_BAR (last_mouse_scroll_bar); 4553 struct scroll_bar *bar = XSCROLL_BAR (last_mouse_scroll_bar);
4527 WindowPtr wp = FrontWindow (); 4554 WindowPtr wp = mac_front_window ();
4528 Point mouse_pos; 4555 Point mouse_pos;
4529 struct frame *f = ((mac_output *) GetWRefCon (wp))->mFP; 4556 struct frame *f = mac_window_to_frame (wp);
4530 int win_y, top_range; 4557 int win_y, top_range;
4531 4558
4532#if TARGET_API_MAC_CARBON 4559 SetPortWindowPort (wp);
4533 SetPort (GetWindowPort (wp));
4534#else
4535 SetPort (wp);
4536#endif
4537 4560
4538 GetMouse (&mouse_pos); 4561 GetMouse (&mouse_pos);
4539 4562
@@ -4645,7 +4668,8 @@ x_draw_hollow_cursor (w, row)
4645 /* Compute the proper height and ascent of the rectangle, based 4668 /* Compute the proper height and ascent of the rectangle, based
4646 on the actual glyph. Using the full height of the row looks 4669 on the actual glyph. Using the full height of the row looks
4647 bad when there are tall images on that row. */ 4670 bad when there are tall images on that row. */
4648 h = max (FRAME_LINE_HEIGHT (f), cursor_glyph->ascent + cursor_glyph->descent); 4671 h = max (min (FRAME_LINE_HEIGHT (f), row->height),
4672 cursor_glyph->ascent + cursor_glyph->descent);
4649 if (h < row->height) 4673 if (h < row->height)
4650 y += row->ascent /* - w->phys_cursor_ascent */ + cursor_glyph->descent - h; 4674 y += row->ascent /* - w->phys_cursor_ascent */ + cursor_glyph->descent - h;
4651 h--; 4675 h--;
@@ -4759,7 +4783,11 @@ mac_define_frame_cursor (f, cursor)
4759 struct frame *f; 4783 struct frame *f;
4760 Cursor cursor; 4784 Cursor cursor;
4761{ 4785{
4762 /* MAC TODO */ 4786#if TARGET_API_MAC_CARBON
4787 SetThemeCursor (cursor);
4788#else
4789 SetCursor (*cursor);
4790#endif
4763} 4791}
4764 4792
4765 4793
@@ -4933,7 +4961,7 @@ x_new_font (f, fontname)
4933 if (FRAME_CONFIG_SCROLL_BAR_WIDTH (f) > 0) 4961 if (FRAME_CONFIG_SCROLL_BAR_WIDTH (f) > 0)
4934 { 4962 {
4935 int wid = FRAME_COLUMN_WIDTH (f); 4963 int wid = FRAME_COLUMN_WIDTH (f);
4936 FRAME_CONFIG_SCROLL_BAR_COLS (f) 4964 FRAME_CONFIG_SCROLL_BAR_COLS (f)
4937 = (FRAME_CONFIG_SCROLL_BAR_WIDTH (f) + wid-1) / wid; 4965 = (FRAME_CONFIG_SCROLL_BAR_WIDTH (f) + wid-1) / wid;
4938 } 4966 }
4939 else 4967 else
@@ -5027,11 +5055,7 @@ x_calc_absolute_position (f)
5027 GrafPtr savePort; 5055 GrafPtr savePort;
5028 GetPort (&savePort); 5056 GetPort (&savePort);
5029 5057
5030#if TARGET_API_MAC_CARBON 5058 SetPortWindowPort (FRAME_MAC_WINDOW (f));
5031 SetPort (GetWindowPort (FRAME_MAC_WINDOW (f)));
5032#else
5033 SetPort (FRAME_MAC_WINDOW (f));
5034#endif
5035 5059
5036#if TARGET_API_MAC_CARBON 5060#if TARGET_API_MAC_CARBON
5037 { 5061 {
@@ -5406,10 +5430,15 @@ x_free_frame_resources (f)
5406 struct frame *f; 5430 struct frame *f;
5407{ 5431{
5408 struct mac_display_info *dpyinfo = FRAME_MAC_DISPLAY_INFO (f); 5432 struct mac_display_info *dpyinfo = FRAME_MAC_DISPLAY_INFO (f);
5433 WindowPtr wp = FRAME_MAC_WINDOW (f);
5409 5434
5410 BLOCK_INPUT; 5435 BLOCK_INPUT;
5411 5436
5412 DisposeWindow (FRAME_MAC_WINDOW (f)); 5437 DisposeWindow (wp);
5438 if (wp == tip_window)
5439 /* Neither WaitNextEvent nor ReceiveNextEvent receives `window
5440 closed' event. So we reset tip_window here. */
5441 tip_window = NULL;
5413 5442
5414 free_frame_menubar (f); 5443 free_frame_menubar (f);
5415 5444
@@ -5826,7 +5855,7 @@ decode_mac_font_name (char *name, int size, short scriptcode)
5826 break; 5855 break;
5827 case smKorean: 5856 case smKorean:
5828 coding_system = Qeuc_kr; 5857 coding_system = Qeuc_kr;
5829 break; 5858 break;
5830 default: 5859 default:
5831 return; 5860 return;
5832 } 5861 }
@@ -6277,7 +6306,7 @@ mac_do_list_fonts (pattern, maxnames)
6277 if (fast_string_match (pattern_regex, fontname) >= 0) 6306 if (fast_string_match (pattern_regex, fontname) >= 0)
6278 { 6307 {
6279 font_list = Fcons (fontname, font_list); 6308 font_list = Fcons (fontname, font_list);
6280 6309
6281 n_fonts++; 6310 n_fonts++;
6282 if (maxnames > 0 && n_fonts >= maxnames) 6311 if (maxnames > 0 && n_fonts >= maxnames)
6283 break; 6312 break;
@@ -6933,6 +6962,11 @@ Lisp_Object drag_and_drop_file_list;
6933 6962
6934Point saved_menu_event_location; 6963Point saved_menu_event_location;
6935 6964
6965#if !TARGET_API_MAC_CARBON
6966/* Place holder for the default arrow cursor. */
6967CursPtr arrow_cursor;
6968#endif
6969
6936/* Apple Events */ 6970/* Apple Events */
6937static void init_required_apple_events (void); 6971static void init_required_apple_events (void);
6938static pascal OSErr 6972static pascal OSErr
@@ -6982,12 +7016,12 @@ static int
6982mac_get_emulated_btn ( UInt32 modifiers ) 7016mac_get_emulated_btn ( UInt32 modifiers )
6983{ 7017{
6984 int result = 0; 7018 int result = 0;
6985 if (Vmac_emulate_three_button_mouse != Qnil) { 7019 if (!NILP (Vmac_emulate_three_button_mouse)) {
6986 int cmdIs3 = (Vmac_emulate_three_button_mouse != Qreverse); 7020 int cmdIs3 = !EQ (Vmac_emulate_three_button_mouse, Qreverse);
6987 if (modifiers & controlKey) 7021 if (modifiers & controlKey)
6988 result = cmdIs3 ? 2 : 1; 7022 result = cmdIs3 ? 2 : 1;
6989 else if (modifiers & optionKey) 7023 else if (modifiers & optionKey)
6990 result = cmdIs3 ? 1 : 2; 7024 result = cmdIs3 ? 1 : 2;
6991 } 7025 }
6992 return result; 7026 return result;
6993} 7027}
@@ -7001,7 +7035,7 @@ mac_event_to_emacs_modifiers (EventRef eventRef)
7001 UInt32 mods = 0; 7035 UInt32 mods = 0;
7002 GetEventParameter (eventRef, kEventParamKeyModifiers, typeUInt32, NULL, 7036 GetEventParameter (eventRef, kEventParamKeyModifiers, typeUInt32, NULL,
7003 sizeof (UInt32), NULL, &mods); 7037 sizeof (UInt32), NULL, &mods);
7004 if (Vmac_emulate_three_button_mouse != Qnil && 7038 if (!NILP (Vmac_emulate_three_button_mouse) &&
7005 GetEventClass(eventRef) == kEventClassMouse) 7039 GetEventClass(eventRef) == kEventClassMouse)
7006 { 7040 {
7007 mods &= ~(optionKey & cmdKey); 7041 mods &= ~(optionKey & cmdKey);
@@ -7020,7 +7054,7 @@ mac_get_mouse_btn (EventRef ref)
7020 switch (result) 7054 switch (result)
7021 { 7055 {
7022 case kEventMouseButtonPrimary: 7056 case kEventMouseButtonPrimary:
7023 if (Vmac_emulate_three_button_mouse == Qnil) 7057 if (NILP (Vmac_emulate_three_button_mouse))
7024 return 0; 7058 return 0;
7025 else { 7059 else {
7026 UInt32 mods = 0; 7060 UInt32 mods = 0;
@@ -7119,6 +7153,8 @@ do_init_managers (void)
7119 InitCursor (); 7153 InitCursor ();
7120 7154
7121#if !TARGET_API_MAC_CARBON 7155#if !TARGET_API_MAC_CARBON
7156 arrow_cursor = &qd.arrow;
7157
7122 /* set up some extra stack space for use by emacs */ 7158 /* set up some extra stack space for use by emacs */
7123 SetApplLimit ((Ptr) ((long) GetApplLimit () - EXTRA_STACK_ALLOC)); 7159 SetApplLimit ((Ptr) ((long) GetApplLimit () - EXTRA_STACK_ALLOC));
7124 7160
@@ -7147,8 +7183,12 @@ do_check_ram_size (void)
7147static void 7183static void
7148do_window_update (WindowPtr win) 7184do_window_update (WindowPtr win)
7149{ 7185{
7150 struct mac_output *mwp = (mac_output *) GetWRefCon (win); 7186 struct frame *f = mac_window_to_frame (win);
7151 struct frame *f = mwp->mFP; 7187
7188 if (win == tip_window)
7189 /* The tooltip has been drawn already. Avoid the
7190 SET_FRAME_GARBAGED below. */
7191 return;
7152 7192
7153 if (f) 7193 if (f)
7154 { 7194 {
@@ -7199,13 +7239,11 @@ is_emacs_window (WindowPtr win)
7199static void 7239static void
7200do_window_activate (WindowPtr win) 7240do_window_activate (WindowPtr win)
7201{ 7241{
7202 mac_output *mwp;
7203 struct frame *f; 7242 struct frame *f;
7204 7243
7205 if (is_emacs_window (win)) 7244 if (is_emacs_window (win))
7206 { 7245 {
7207 mwp = (mac_output *) GetWRefCon (win); 7246 f = mac_window_to_frame (win);
7208 f = mwp->mFP;
7209 7247
7210 if (f) 7248 if (f)
7211 { 7249 {
@@ -7218,13 +7256,11 @@ do_window_activate (WindowPtr win)
7218static void 7256static void
7219do_window_deactivate (WindowPtr win) 7257do_window_deactivate (WindowPtr win)
7220{ 7258{
7221 mac_output *mwp;
7222 struct frame *f; 7259 struct frame *f;
7223 7260
7224 if (is_emacs_window (win)) 7261 if (is_emacs_window (win))
7225 { 7262 {
7226 mwp = (mac_output *) GetWRefCon (win); 7263 f = mac_window_to_frame (win);
7227 f = mwp->mFP;
7228 7264
7229 if (f == FRAME_MAC_DISPLAY_INFO (f)->x_focus_frame) 7265 if (f == FRAME_MAC_DISPLAY_INFO (f)->x_focus_frame)
7230 { 7266 {
@@ -7238,14 +7274,12 @@ static void
7238do_app_resume () 7274do_app_resume ()
7239{ 7275{
7240 WindowPtr wp; 7276 WindowPtr wp;
7241 mac_output *mwp;
7242 struct frame *f; 7277 struct frame *f;
7243 7278
7244 wp = FrontWindow(); 7279 wp = mac_front_window ();
7245 if (is_emacs_window (wp)) 7280 if (is_emacs_window (wp))
7246 { 7281 {
7247 mwp = (mac_output *) GetWRefCon (wp); 7282 f = mac_window_to_frame (wp);
7248 f = mwp->mFP;
7249 7283
7250 if (f) 7284 if (f)
7251 { 7285 {
@@ -7262,14 +7296,12 @@ static void
7262do_app_suspend () 7296do_app_suspend ()
7263{ 7297{
7264 WindowPtr wp; 7298 WindowPtr wp;
7265 mac_output *mwp;
7266 struct frame *f; 7299 struct frame *f;
7267 7300
7268 wp = FrontWindow(); 7301 wp = mac_front_window ();
7269 if (is_emacs_window (wp)) 7302 if (is_emacs_window (wp))
7270 { 7303 {
7271 mwp = (mac_output *) GetWRefCon (wp); 7304 f = mac_window_to_frame (wp);
7272 f = mwp->mFP;
7273 7305
7274 if (f == FRAME_MAC_DISPLAY_INFO (f)->x_focus_frame) 7306 if (f == FRAME_MAC_DISPLAY_INFO (f)->x_focus_frame)
7275 { 7307 {
@@ -7284,67 +7316,38 @@ do_app_suspend ()
7284 7316
7285 7317
7286static void 7318static void
7287do_mouse_moved (Point mouse_pos) 7319do_mouse_moved (mouse_pos, f)
7320 Point mouse_pos;
7321 FRAME_PTR *f;
7288{ 7322{
7289 WindowPtr wp = FrontWindow (); 7323 WindowPtr wp = mac_front_window ();
7290 struct frame *f; 7324 struct x_display_info *dpyinfo;
7291 7325
7292 if (is_emacs_window (wp)) 7326 if (is_emacs_window (wp))
7293 { 7327 {
7294 f = ((mac_output *) GetWRefCon (wp))->mFP; 7328 *f = mac_window_to_frame (wp);
7329 dpyinfo = FRAME_MAC_DISPLAY_INFO (*f);
7295 7330
7296#if TARGET_API_MAC_CARBON 7331 if (dpyinfo->mouse_face_hidden)
7297 SetPort (GetWindowPort (wp)); 7332 {
7298#else 7333 dpyinfo->mouse_face_hidden = 0;
7299 SetPort (wp); 7334 clear_mouse_face (dpyinfo);
7300#endif 7335 }
7301 7336
7302 GlobalToLocal (&mouse_pos); 7337 SetPortWindowPort (wp);
7303
7304 note_mouse_movement (f, &mouse_pos);
7305 }
7306}
7307 7338
7339 GlobalToLocal (&mouse_pos);
7308 7340
7309static void 7341 if (dpyinfo->grabbed && tracked_scroll_bar)
7310do_os_event (EventRecord *erp) 7342 x_scroll_bar_note_movement (tracked_scroll_bar,
7311{ 7343 mouse_pos.v
7312 switch((erp->message >> 24) & 0x000000FF) 7344 - XINT (tracked_scroll_bar->top),
7313 { 7345 TickCount() * (1000 / 60));
7314 case suspendResumeMessage:
7315 if((erp->message & resumeFlag) == 1)
7316 do_app_resume ();
7317 else 7346 else
7318 do_app_suspend (); 7347 note_mouse_movement (*f, &mouse_pos);
7319 break;
7320
7321 case mouseMovedMessage:
7322 do_mouse_moved (erp->where);
7323 break;
7324 } 7348 }
7325} 7349}
7326 7350
7327static void
7328do_events (EventRecord *erp)
7329{
7330 switch (erp->what)
7331 {
7332 case updateEvt:
7333 do_window_update ((WindowPtr) erp->message);
7334 break;
7335
7336 case osEvt:
7337 do_os_event (erp);
7338 break;
7339
7340 case activateEvt:
7341 if ((erp->modifiers & activeFlag) != 0)
7342 do_window_activate ((WindowPtr) erp->message);
7343 else
7344 do_window_deactivate ((WindowPtr) erp->message);
7345 break;
7346 }
7347}
7348 7351
7349static void 7352static void
7350do_apple_menu (SInt16 menu_item) 7353do_apple_menu (SInt16 menu_item)
@@ -7382,8 +7385,7 @@ do_menu_choice (SInt32 menu_choice)
7382 7385
7383 default: 7386 default:
7384 { 7387 {
7385 WindowPtr wp = FrontWindow (); 7388 struct frame *f = mac_window_to_frame (mac_front_window ());
7386 struct frame *f = ((mac_output *) GetWRefCon (wp))->mFP;
7387 MenuHandle menu = GetMenuHandle (menu_id); 7389 MenuHandle menu = GetMenuHandle (menu_id);
7388 if (menu) 7390 if (menu)
7389 { 7391 {
@@ -7408,8 +7410,7 @@ do_grow_window (WindowPtr w, EventRecord *e)
7408 long grow_size; 7410 long grow_size;
7409 Rect limit_rect; 7411 Rect limit_rect;
7410 int rows, columns; 7412 int rows, columns;
7411 mac_output *mwp = (mac_output *) GetWRefCon (w); 7413 struct frame *f = mac_window_to_frame (w);
7412 struct frame *f = mwp->mFP;
7413 7414
7414 SetRect(&limit_rect, MIN_DOC_SIZE, MIN_DOC_SIZE, MAX_DOC_SIZE, MAX_DOC_SIZE); 7415 SetRect(&limit_rect, MIN_DOC_SIZE, MIN_DOC_SIZE, MAX_DOC_SIZE, MAX_DOC_SIZE);
7415 7416
@@ -7438,16 +7439,11 @@ do_zoom_window (WindowPtr w, int zoom_in_or_out)
7438 Rect zoom_rect, port_rect; 7439 Rect zoom_rect, port_rect;
7439 Point top_left; 7440 Point top_left;
7440 int w_title_height, columns, rows, width, height, dummy, x, y; 7441 int w_title_height, columns, rows, width, height, dummy, x, y;
7441 mac_output *mwp = (mac_output *) GetWRefCon (w); 7442 struct frame *f = mac_window_to_frame (w);
7442 struct frame *f = mwp->mFP;
7443 7443
7444 GetPort (&save_port); 7444 GetPort (&save_port);
7445 7445
7446#if TARGET_API_MAC_CARBON 7446 SetPortWindowPort (w);
7447 SetPort (GetWindowPort (w));
7448#else
7449 SetPort (w);
7450#endif
7451 7447
7452 /* Clear window to avoid flicker. */ 7448 /* Clear window to avoid flicker. */
7453#if TARGET_API_MAC_CARBON 7449#if TARGET_API_MAC_CARBON
@@ -7500,7 +7496,7 @@ do_zoom_window (WindowPtr w, int zoom_in_or_out)
7500 } 7496 }
7501#endif /* not TARGET_API_MAC_CARBON */ 7497#endif /* not TARGET_API_MAC_CARBON */
7502 7498
7503 ZoomWindow (w, zoom_in_or_out, w == FrontWindow ()); 7499 ZoomWindow (w, zoom_in_or_out, w == mac_front_window ());
7504 7500
7505 /* retrieve window size and update application values */ 7501 /* retrieve window size and update application values */
7506#if TARGET_API_MAC_CARBON 7502#if TARGET_API_MAC_CARBON
@@ -7510,7 +7506,7 @@ do_zoom_window (WindowPtr w, int zoom_in_or_out)
7510#endif 7506#endif
7511 rows = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, port_rect.bottom - port_rect.top); 7507 rows = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, port_rect.bottom - port_rect.top);
7512 columns = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, port_rect.right - port_rect.left); 7508 columns = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, port_rect.right - port_rect.left);
7513 x_set_window_size (mwp->mFP, 0, columns, rows); 7509 x_set_window_size (f, 0, columns, rows);
7514 7510
7515 SetPort (save_port); 7511 SetPort (save_port);
7516} 7512}
@@ -7841,8 +7837,8 @@ mac_do_receive_drag (WindowPtr window, void *handlerRefCon,
7841 { 7837 {
7842 struct input_event event; 7838 struct input_event event;
7843 Lisp_Object frame; 7839 Lisp_Object frame;
7844 struct frame *f = ((mac_output *) GetWRefCon(window))->mFP; 7840 struct frame *f = mac_window_to_frame (window);
7845 SetPort (GetWindowPort (window)); 7841 SetPortWindowPort (window);
7846 GlobalToLocal (&mouse); 7842 GlobalToLocal (&mouse);
7847 7843
7848 event.kind = DRAG_N_DROP_EVENT; 7844 event.kind = DRAG_N_DROP_EVENT;
@@ -8016,26 +8012,26 @@ keycode_to_xkeysym (int keyCode, int *xKeySym)
8016/* Emacs calls this whenever it wants to read an input event from the 8012/* Emacs calls this whenever it wants to read an input event from the
8017 user. */ 8013 user. */
8018int 8014int
8019XTread_socket (int sd, int expected, struct input_event *hold_quit) 8015XTread_socket (sd, expected, hold_quit)
8016 int sd, expected;
8017 struct input_event *hold_quit;
8020{ 8018{
8021 struct input_event inev; 8019 struct input_event inev;
8022 int count = 0; 8020 int count = 0;
8023#if USE_CARBON_EVENTS 8021#if USE_CARBON_EVENTS
8024 OSStatus rneResult;
8025 EventRef eventRef; 8022 EventRef eventRef;
8026 EventMouseButton mouseBtn; 8023 EventTargetRef toolbox_dispatcher = GetEventDispatcherTarget ();
8024#else
8025 EventMask event_mask;
8027#endif 8026#endif
8028 EventRecord er; 8027 EventRecord er;
8029 int the_modifiers; 8028 struct mac_display_info *dpyinfo = &one_mac_display_info;
8030 EventMask event_mask;
8031 8029
8032#if 0
8033 if (interrupt_input_blocked) 8030 if (interrupt_input_blocked)
8034 { 8031 {
8035 interrupt_input_pending = 1; 8032 interrupt_input_pending = 1;
8036 return -1; 8033 return -1;
8037 } 8034 }
8038#endif
8039 8035
8040 interrupt_input_pending = 0; 8036 interrupt_input_pending = 0;
8041 BLOCK_INPUT; 8037 BLOCK_INPUT;
@@ -8057,26 +8053,33 @@ XTread_socket (int sd, int expected, struct input_event *hold_quit)
8057 if (terminate_flag) 8053 if (terminate_flag)
8058 Fkill_emacs (make_number (1)); 8054 Fkill_emacs (make_number (1));
8059 8055
8060 /* It is necessary to set this (additional) argument slot of an 8056#if !USE_CARBON_EVENTS
8061 event to nil because keyboard.c protects incompletely processed
8062 event from being garbage collected by placing them in the
8063 kbd_buffer_gcpro vector. */
8064 EVENT_INIT (inev);
8065 inev.kind = NO_EVENT;
8066 inev.arg = Qnil;
8067
8068 event_mask = everyEvent; 8057 event_mask = everyEvent;
8069 if (NILP (Fboundp (Qmac_ready_for_drag_n_drop))) 8058 if (NILP (Fboundp (Qmac_ready_for_drag_n_drop)))
8070 event_mask -= highLevelEventMask; 8059 event_mask -= highLevelEventMask;
8071 8060
8072#if USE_CARBON_EVENTS 8061 while (WaitNextEvent (event_mask, &er,
8073 rneResult = ReceiveNextEvent (0, NULL, 8062 (expected ? app_sleep_time : 0L), NULL))
8074 expected 8063#else
8075 ? TicksToEventTime (app_sleep_time) 8064 while (!ReceiveNextEvent (0, NULL,
8076 : 0, 8065 (expected ? TicksToEventTime (app_sleep_time) : 0),
8077 kEventRemoveFromQueue, &eventRef); 8066 kEventRemoveFromQueue, &eventRef))
8078 if (!rneResult) 8067#endif /* !USE_CARBON_EVENTS */
8079 { 8068 {
8069 int do_help = 0;
8070 struct frame *f;
8071
8072 expected = 0;
8073
8074 /* It is necessary to set this (additional) argument slot of an
8075 event to nil because keyboard.c protects incompletely
8076 processed event from being garbage collected by placing them
8077 in the kbd_buffer_gcpro vector. */
8078 EVENT_INIT (inev);
8079 inev.kind = NO_EVENT;
8080 inev.arg = Qnil;
8081
8082#if USE_CARBON_EVENTS
8080 /* Handle new events */ 8083 /* Handle new events */
8081 if (!mac_convert_event_ref (eventRef, &er)) 8084 if (!mac_convert_event_ref (eventRef, &er))
8082 switch (GetEventClass (eventRef)) 8085 switch (GetEventClass (eventRef))
@@ -8086,13 +8089,12 @@ XTread_socket (int sd, int expected, struct input_event *hold_quit)
8086 { 8089 {
8087 SInt32 delta; 8090 SInt32 delta;
8088 Point point; 8091 Point point;
8089 WindowPtr window_ptr = FrontNonFloatingWindow (); 8092 WindowPtr window_ptr = mac_front_window ();
8090 struct mac_output *mwp = (mac_output *) GetWRefCon (window_ptr); 8093
8091 if (!IsValidWindowPtr (window_ptr)) 8094 if (!IsValidWindowPtr (window_ptr))
8092 { 8095 {
8093 SysBeep(1); 8096 SysBeep(1);
8094 UNBLOCK_INPUT; 8097 break;
8095 return 0;
8096 } 8098 }
8097 8099
8098 GetEventParameter(eventRef, kEventParamMouseWheelDelta, 8100 GetEventParameter(eventRef, kEventParamMouseWheelDelta,
@@ -8103,457 +8105,557 @@ XTread_socket (int sd, int expected, struct input_event *hold_quit)
8103 NULL, &point); 8105 NULL, &point);
8104 inev.kind = WHEEL_EVENT; 8106 inev.kind = WHEEL_EVENT;
8105 inev.code = 0; 8107 inev.code = 0;
8106 inev.modifiers = (mac_event_to_emacs_modifiers(eventRef) 8108 inev.modifiers = (mac_event_to_emacs_modifiers (eventRef)
8107 | ((delta < 0) ? down_modifier 8109 | ((delta < 0) ? down_modifier
8108 : up_modifier)); 8110 : up_modifier));
8109 SetPort (GetWindowPort (window_ptr)); 8111 SetPortWindowPort (window_ptr);
8110 GlobalToLocal (&point); 8112 GlobalToLocal (&point);
8111 XSETINT (inev.x, point.h); 8113 XSETINT (inev.x, point.h);
8112 XSETINT (inev.y, point.v); 8114 XSETINT (inev.y, point.v);
8113 XSETFRAME (inev.frame_or_window, mwp->mFP); 8115 XSETFRAME (inev.frame_or_window,
8116 mac_window_to_frame (window_ptr));
8114 inev.timestamp = EventTimeToTicks (GetEventTime (eventRef))*(1000/60); 8117 inev.timestamp = EventTimeToTicks (GetEventTime (eventRef))*(1000/60);
8115 } 8118 }
8116 else 8119 else
8117 SendEventToEventTarget (eventRef, GetEventDispatcherTarget ()); 8120 SendEventToEventTarget (eventRef, toolbox_dispatcher);
8118 8121
8119 break; 8122 break;
8120 default: 8123 default:
8121 /* Send the event to the appropriate receiver. */ 8124 /* Send the event to the appropriate receiver. */
8122 SendEventToEventTarget (eventRef, GetEventDispatcherTarget ()); 8125 SendEventToEventTarget (eventRef, toolbox_dispatcher);
8123 } 8126 }
8124 else 8127 else
8125#else
8126 if (WaitNextEvent (event_mask, &er, (expected ? app_sleep_time : 0L), NULL))
8127#endif /* USE_CARBON_EVENTS */ 8128#endif /* USE_CARBON_EVENTS */
8128 switch (er.what) 8129 switch (er.what)
8129 {
8130 case mouseDown:
8131 case mouseUp:
8132 { 8130 {
8133 WindowPtr window_ptr = FrontWindow (); 8131 case mouseDown:
8134 SInt16 part_code; 8132 case mouseUp:
8133 {
8134 WindowPtr window_ptr;
8135 SInt16 part_code;
8136 int tool_bar_p = 0;
8137
8138 if (dpyinfo->grabbed && last_mouse_frame
8139 && FRAME_LIVE_P (last_mouse_frame))
8140 {
8141 window_ptr = FRAME_MAC_WINDOW (last_mouse_frame);
8142 part_code = inContent;
8143 }
8144 else
8145 {
8146 window_ptr = FrontWindow ();
8147 if (tip_window && window_ptr == tip_window)
8148 {
8149 HideWindow (tip_window);
8150 window_ptr = FrontWindow ();
8151 }
8135 8152
8136#if USE_CARBON_EVENTS 8153#if USE_CARBON_EVENTS
8137 /* This is needed to send mouse events like aqua window buttons 8154 /* This is needed to send mouse events like aqua
8138 to the correct handler. */ 8155 window buttons to the correct handler. */
8139 if (eventNotHandledErr != SendEventToEventTarget (eventRef, GetEventDispatcherTarget ())) { 8156 if (SendEventToEventTarget (eventRef, toolbox_dispatcher)
8140 break; 8157 != eventNotHandledErr)
8141 } 8158 break;
8142 8159
8143 if (!is_emacs_window(window_ptr)) 8160 if (!is_emacs_window (window_ptr))
8144 break; 8161 break;
8145#endif 8162#endif
8163 part_code = FindWindow (er.where, &window_ptr);
8164 }
8165
8166 switch (part_code)
8167 {
8168 case inMenuBar:
8169 if (er.what == mouseDown)
8170 {
8171 f = mac_window_to_frame (mac_front_window ());
8172 saved_menu_event_location = er.where;
8173 inev.kind = MENU_BAR_ACTIVATE_EVENT;
8174 XSETFRAME (inev.frame_or_window, f);
8175 }
8176 break;
8146 8177
8147 if (mouse_tracking_in_progress == mouse_tracking_scroll_bar 8178 case inContent:
8148 && er.what == mouseUp) 8179 if (window_ptr != mac_front_window ())
8149 { 8180 SelectWindow (window_ptr);
8150 struct mac_output *mwp = (mac_output *) GetWRefCon (window_ptr); 8181 else
8151 Point mouse_loc = er.where; 8182 {
8183 SInt16 control_part_code;
8184 ControlHandle ch;
8185 Point mouse_loc = er.where;
8152 8186
8153 /* Convert to local coordinates of new window. */ 8187 f = mac_window_to_frame (window_ptr);
8188 /* convert to local coordinates of new window */
8189 SetPortWindowPort (window_ptr);
8190
8191 GlobalToLocal (&mouse_loc);
8154#if TARGET_API_MAC_CARBON 8192#if TARGET_API_MAC_CARBON
8155 SetPort (GetWindowPort (window_ptr)); 8193 ch = FindControlUnderMouse (mouse_loc, window_ptr,
8194 &control_part_code);
8156#else 8195#else
8157 SetPort (window_ptr); 8196 control_part_code = FindControl (mouse_loc, window_ptr,
8197 &ch);
8158#endif 8198#endif
8159 8199
8160 GlobalToLocal (&mouse_loc);
8161
8162#if USE_CARBON_EVENTS 8200#if USE_CARBON_EVENTS
8163 inev.code = mac_get_mouse_btn (eventRef); 8201 inev.code = mac_get_mouse_btn (eventRef);
8202 inev.modifiers = mac_event_to_emacs_modifiers (eventRef);
8164#else 8203#else
8165 inev.code = mac_get_emulate_btn (er.modifiers); 8204 inev.code = mac_get_emulated_btn (er.modifiers);
8205 inev.modifiers = mac_to_emacs_modifiers (er.modifiers);
8166#endif 8206#endif
8167 inev.kind = SCROLL_BAR_CLICK_EVENT; 8207 XSETINT (inev.x, mouse_loc.h);
8168 inev.frame_or_window = tracked_scroll_bar->window; 8208 XSETINT (inev.y, mouse_loc.v);
8169 inev.part = scroll_bar_handle; 8209 inev.timestamp = er.when * (1000 / 60);
8170#if USE_CARBON_EVENTS 8210 /* ticks to milliseconds */
8171 inev.modifiers = mac_event_to_emacs_modifiers (eventRef); 8211
8212 if (dpyinfo->grabbed && tracked_scroll_bar
8213#if TARGET_API_MAC_CARBON
8214 || ch != 0
8172#else 8215#else
8173 inev.modifiers = mac_to_emacs_modifiers (er.modifiers); 8216 || control_part_code != 0
8174#endif 8217#endif
8175 inev.modifiers |= up_modifier; 8218 )
8176 inev.timestamp = er.when * (1000 / 60); 8219 {
8177 /* ticks to milliseconds */ 8220 struct scroll_bar *bar;
8221
8222 if (dpyinfo->grabbed && tracked_scroll_bar)
8223 {
8224 bar = tracked_scroll_bar;
8225 control_part_code = kControlIndicatorPart;
8226 }
8227 else
8228 bar = (struct scroll_bar *) GetControlReference (ch);
8229 x_scroll_bar_handle_click (bar, control_part_code,
8230 &er, &inev);
8231 if (er.what == mouseDown
8232 && control_part_code == kControlIndicatorPart)
8233 tracked_scroll_bar = bar;
8234 else
8235 tracked_scroll_bar = NULL;
8236 }
8237 else
8238 {
8239 Lisp_Object window;
8240 int x = mouse_loc.h;
8241 int y = mouse_loc.v;
8242
8243 window = window_from_coordinates (f, x, y, 0, 0, 0, 1);
8244 if (EQ (window, f->tool_bar_window))
8245 {
8246 if (er.what == mouseDown)
8247 handle_tool_bar_click (f, x, y, 1, 0);
8248 else
8249 handle_tool_bar_click (f, x, y, 0,
8250 inev.modifiers);
8251 tool_bar_p = 1;
8252 }
8253 else
8254 {
8255 XSETFRAME (inev.frame_or_window, f);
8256 inev.kind = MOUSE_CLICK_EVENT;
8257 }
8258 }
8259
8260 if (er.what == mouseDown)
8261 {
8262 dpyinfo->grabbed |= (1 << inev.code);
8263 last_mouse_frame = f;
8264 /* Ignore any mouse motion that happened
8265 before this event; any subsequent
8266 mouse-movement Emacs events should reflect
8267 only motion after the ButtonPress. */
8268 if (f != 0)
8269 f->mouse_moved = 0;
8270
8271 if (!tool_bar_p)
8272 last_tool_bar_item = -1;
8273 }
8274 else
8275 {
8276 if (dpyinfo->grabbed & (1 << inev.code) == 0)
8277 /* If a button is released though it was not
8278 previously pressed, that would be because
8279 of multi-button emulation. */
8280 dpyinfo->grabbed = 0;
8281 else
8282 dpyinfo->grabbed &= ~(1 << inev.code);
8283 }
8284
8285 switch (er.what)
8286 {
8287 case mouseDown:
8288 inev.modifiers |= down_modifier;
8289 break;
8290 case mouseUp:
8291 inev.modifiers |= up_modifier;
8292 break;
8293 }
8294 }
8295 break;
8178 8296
8179 XSETINT (inev.x, tracked_scroll_bar->left + 2); 8297 case inDrag:
8180 XSETINT (inev.y, mouse_loc.v - 24); 8298#if TARGET_API_MAC_CARBON
8181 tracked_scroll_bar->dragging = Qnil; 8299 if (er.what == mouseDown)
8182 mouse_tracking_in_progress = mouse_tracking_none; 8300 {
8183 tracked_scroll_bar = NULL; 8301 BitMap bm;
8184 break;
8185 }
8186 8302
8187 part_code = FindWindow (er.where, &window_ptr); 8303 GetQDGlobalsScreenBits (&bm);
8304 DragWindow (window_ptr, er.where, &bm.bounds);
8305 }
8306#else /* not TARGET_API_MAC_CARBON */
8307 DragWindow (window_ptr, er.where, &qd.screenBits.bounds);
8308#endif /* not TARGET_API_MAC_CARBON */
8309 break;
8188 8310
8189 switch (part_code) 8311 case inGoAway:
8190 { 8312 if (TrackGoAway (window_ptr, er.where))
8191 case inMenuBar: 8313 {
8192 if (er.what == mouseDown) 8314 inev.kind = DELETE_WINDOW_EVENT;
8193 { 8315 XSETFRAME (inev.frame_or_window,
8194 struct frame *f = ((mac_output *) 8316 mac_window_to_frame (window_ptr));
8195 GetWRefCon (FrontWindow ()))->mFP; 8317 }
8196 saved_menu_event_location = er.where; 8318 break;
8197 inev.kind = MENU_BAR_ACTIVATE_EVENT;
8198 XSETFRAME (inev.frame_or_window, f);
8199 }
8200 break;
8201 8319
8202 case inContent: 8320 /* window resize handling added --ben */
8203 if (window_ptr != FrontWindow ()) 8321 case inGrow:
8204 SelectWindow (window_ptr); 8322 if (er.what == mouseDown)
8205 else 8323 {
8206 { 8324 do_grow_window(window_ptr, &er);
8207 SInt16 control_part_code; 8325 break;
8208 ControlHandle ch; 8326 }
8209 struct mac_output *mwp = (mac_output *)
8210 GetWRefCon (window_ptr);
8211 Point mouse_loc = er.where;
8212
8213 /* convert to local coordinates of new window */
8214#if TARGET_API_MAC_CARBON
8215 SetPort (GetWindowPort (window_ptr));
8216#else
8217 SetPort (window_ptr);
8218#endif
8219 8327
8220 GlobalToLocal (&mouse_loc); 8328 /* window zoom handling added --ben */
8221#if TARGET_API_MAC_CARBON 8329 case inZoomIn:
8222 ch = FindControlUnderMouse (mouse_loc, window_ptr, 8330 case inZoomOut:
8223 &control_part_code); 8331 if (TrackBox (window_ptr, er.where, part_code))
8224#else 8332 do_zoom_window (window_ptr, part_code);
8225 control_part_code = FindControl (mouse_loc, window_ptr, &ch); 8333 break;
8226#endif
8227 8334
8228#if USE_CARBON_EVENTS 8335 default:
8229 inev.code = mac_get_mouse_btn (eventRef); 8336 break;
8230#else 8337 }
8231 inev.code = mac_get_emulate_btn (er.modifiers); 8338 }
8232#endif 8339 break;
8233 XSETINT (inev.x, mouse_loc.h);
8234 XSETINT (inev.y, mouse_loc.v);
8235 inev.timestamp = er.when * (1000 / 60);
8236 /* ticks to milliseconds */
8237 8340
8238#if TARGET_API_MAC_CARBON 8341 case updateEvt:
8239 if (ch != 0)
8240#else
8241 if (control_part_code != 0)
8242#endif
8243 {
8244 struct scroll_bar *bar = (struct scroll_bar *)
8245 GetControlReference (ch);
8246 x_scroll_bar_handle_click (bar, control_part_code, &er,
8247 &inev);
8248 if (er.what == mouseDown
8249 && control_part_code == kControlIndicatorPart)
8250 {
8251 mouse_tracking_in_progress
8252 = mouse_tracking_scroll_bar;
8253 tracked_scroll_bar = bar;
8254 }
8255 else
8256 {
8257 mouse_tracking_in_progress = mouse_tracking_none;
8258 tracked_scroll_bar = NULL;
8259 }
8260 }
8261 else
8262 {
8263 Lisp_Object window;
8264
8265 XSETFRAME (inev.frame_or_window, mwp->mFP);
8266 if (er.what == mouseDown)
8267 mouse_tracking_in_progress
8268 = mouse_tracking_mouse_movement;
8269 else
8270 mouse_tracking_in_progress = mouse_tracking_none;
8271 window = window_from_coordinates (mwp->mFP, inev.x, inev.y, 0, 0, 0, 1);
8272
8273 if (EQ (window, mwp->mFP->tool_bar_window))
8274 {
8275 if (er.what == mouseDown)
8276 handle_tool_bar_click (mwp->mFP, inev.x, inev.y, 1, 0);
8277 else
8278 handle_tool_bar_click (mwp->mFP, inev.x, inev.y, 0,
8279#if USE_CARBON_EVENTS 8342#if USE_CARBON_EVENTS
8280 mac_event_to_emacs_modifiers (eventRef) 8343 if (SendEventToEventTarget (eventRef, toolbox_dispatcher)
8281#else 8344 != eventNotHandledErr)
8282 er.modifiers 8345 break;
8283#endif 8346#endif
8284 ); 8347 do_window_update ((WindowPtr) er.message);
8285 break; 8348 break;
8286 }
8287 else
8288 inev.kind = MOUSE_CLICK_EVENT;
8289 }
8290 8349
8350 case osEvt:
8291#if USE_CARBON_EVENTS 8351#if USE_CARBON_EVENTS
8292 inev.modifiers = mac_event_to_emacs_modifiers (eventRef); 8352 if (SendEventToEventTarget (eventRef, toolbox_dispatcher)
8293#else 8353 != eventNotHandledErr)
8294 inev.modifiers = mac_to_emacs_modifiers (er.modifiers); 8354 break;
8295#endif 8355#endif
8296 8356 switch ((er.message >> 24) & 0x000000FF)
8297 switch (er.what) 8357 {
8298 { 8358 case suspendResumeMessage:
8299 case mouseDown: 8359 if ((er.message & resumeFlag) == 1)
8300 inev.modifiers |= down_modifier; 8360 do_app_resume ();
8301 break; 8361 else
8302 case mouseUp: 8362 do_app_suspend ();
8303 inev.modifiers |= up_modifier;
8304 break;
8305 }
8306 }
8307 break;
8308
8309 case inDrag:
8310#if TARGET_API_MAC_CARBON
8311 if (er.what == mouseDown)
8312 {
8313 BitMap bm;
8314
8315 GetQDGlobalsScreenBits (&bm);
8316 DragWindow (window_ptr, er.where, &bm.bounds);
8317 }
8318#else /* not TARGET_API_MAC_CARBON */
8319 DragWindow (window_ptr, er.where, &qd.screenBits.bounds);
8320#endif /* not TARGET_API_MAC_CARBON */
8321 break; 8363 break;
8322 8364
8323 case inGoAway: 8365 case mouseMovedMessage:
8324 if (TrackGoAway (window_ptr, er.where)) 8366 previous_help_echo_string = help_echo_string;
8325 { 8367 help_echo_string = help_echo_object = help_echo_window = Qnil;
8326 inev.kind = DELETE_WINDOW_EVENT; 8368 help_echo_pos = -1;
8327 XSETFRAME (inev.frame_or_window,
8328 ((mac_output *) GetWRefCon (window_ptr))->mFP);
8329 }
8330 break;
8331 8369
8332 /* window resize handling added --ben */ 8370 do_mouse_moved (er.where, &f);
8333 case inGrow:
8334 if (er.what == mouseDown)
8335 {
8336 do_grow_window(window_ptr, &er);
8337 break;
8338 }
8339
8340 /* window zoom handling added --ben */
8341 case inZoomIn:
8342 case inZoomOut:
8343 if (TrackBox (window_ptr, er.where, part_code))
8344 do_zoom_window (window_ptr, part_code);
8345 break;
8346 8371
8347 default: 8372 /* If the contents of the global variable
8373 help_echo_string has changed, generate a
8374 HELP_EVENT. */
8375 if (!NILP (help_echo_string) || !NILP (previous_help_echo_string))
8376 do_help = 1;
8348 break; 8377 break;
8349 } 8378 }
8350 } 8379 break;
8351 break; 8380
8381 case activateEvt:
8382 {
8383 WindowPtr window_ptr = (WindowPtr) er.message;
8352 8384
8353 case updateEvt:
8354 case osEvt:
8355 case activateEvt:
8356#if USE_CARBON_EVENTS 8385#if USE_CARBON_EVENTS
8357 if (eventNotHandledErr == SendEventToEventTarget (eventRef, GetEventDispatcherTarget ())) 8386 if (SendEventToEventTarget (eventRef, toolbox_dispatcher)
8387 != eventNotHandledErr)
8388 break;
8358#endif 8389#endif
8359 do_events (&er); 8390 if (window_ptr == tip_window)
8360 break; 8391 {
8392 HideWindow (tip_window);
8393 break;
8394 }
8361 8395
8362 case keyDown: 8396 if ((er.modifiers & activeFlag) != 0)
8363 case autoKey: 8397 {
8364 { 8398 Point mouse_loc = er.where;
8365 int keycode = (er.message & keyCodeMask) >> 8;
8366 int xkeysym;
8367 8399
8368#if USE_CARBON_EVENTS 8400 do_window_activate (window_ptr);
8369 /* When using Carbon Events, we need to pass raw keyboard events
8370 to the TSM ourselves. If TSM handles it, it will pass back
8371 noErr, otherwise it will pass back "eventNotHandledErr" and
8372 we can process it normally. */
8373 if ((!NILP (Vmac_pass_command_to_system)
8374 || !(er.modifiers & cmdKey))
8375 && (!NILP (Vmac_pass_control_to_system)
8376 || !(er.modifiers & controlKey)))
8377 {
8378 OSStatus err;
8379 err = SendEventToEventTarget (eventRef,
8380 GetEventDispatcherTarget ());
8381 if (err != eventNotHandledErr)
8382 break;
8383 }
8384#endif
8385 8401
8386 if (!IsValidWindowPtr (FrontNonFloatingWindow ())) 8402 SetPortWindowPort (window_ptr);
8387 { 8403 GlobalToLocal (&mouse_loc);
8388 SysBeep (1); 8404 /* activateEvt counts as mouse movement,
8389 UNBLOCK_INPUT; 8405 so update things that depend on mouse position. */
8390 return 0; 8406 note_mouse_movement (mac_window_to_frame (window_ptr),
8391 } 8407 &mouse_loc);
8408 }
8409 else
8410 {
8411 do_window_deactivate (window_ptr);
8392 8412
8393 ObscureCursor (); 8413 f = mac_window_to_frame (window_ptr);
8414 if (f == dpyinfo->mouse_face_mouse_frame)
8415 {
8416 /* If we move outside the frame, then we're
8417 certainly no longer on any text in the
8418 frame. */
8419 clear_mouse_face (dpyinfo);
8420 dpyinfo->mouse_face_mouse_frame = 0;
8421 }
8394 8422
8395 if (keycode_to_xkeysym (keycode, &xkeysym)) 8423 /* Generate a nil HELP_EVENT to cancel a help-echo.
8396 { 8424 Do it only if there's something to cancel.
8397 inev.code = 0xff00 | xkeysym; 8425 Otherwise, the startup message is cleared when the
8398 inev.kind = NON_ASCII_KEYSTROKE_EVENT; 8426 mouse leaves the frame. */
8399 } 8427 if (any_help_event_p)
8400 else 8428 do_help = -1;
8401 { 8429 }
8402 if (er.modifiers & (controlKey | 8430 }
8403 (NILP (Vmac_command_key_is_meta) ? optionKey 8431 break;
8404 : cmdKey)))
8405 {
8406 /* This code comes from Keyboard Resource, Appendix
8407 C of IM - Text. This is necessary since shift is
8408 ignored in KCHR table translation when option or
8409 command is pressed. It also does not translate
8410 correctly control-shift chars like C-% so mask off
8411 shift here also */
8412 int new_modifiers = er.modifiers & 0xe600;
8413 /* mask off option and command */
8414 int new_keycode = keycode | new_modifiers;
8415 Ptr kchr_ptr = (Ptr) GetScriptManagerVariable (smKCHRCache);
8416 unsigned long some_state = 0;
8417 inev.code = KeyTranslate (kchr_ptr, new_keycode,
8418 &some_state) & 0xff;
8419 }
8420 else
8421 inev.code = er.message & charCodeMask;
8422 inev.kind = ASCII_KEYSTROKE_EVENT;
8423 }
8424 }
8425 8432
8426 /* If variable mac-convert-keyboard-input-to-latin-1 is non-nil, 8433 case keyDown:
8427 convert non-ASCII characters typed at the Mac keyboard 8434 case autoKey:
8428 (presumed to be in the Mac Roman encoding) to iso-latin-1
8429 encoding before they are passed to Emacs. This enables the
8430 Mac keyboard to be used to enter non-ASCII iso-latin-1
8431 characters directly. */
8432 if (mac_keyboard_text_encoding != kTextEncodingMacRoman
8433 && inev.kind == ASCII_KEYSTROKE_EVENT && inev.code >= 128)
8434 { 8435 {
8435 static TECObjectRef converter = NULL; 8436 int keycode = (er.message & keyCodeMask) >> 8;
8436 OSStatus the_err = noErr; 8437 int xkeysym;
8437 OSStatus convert_status = noErr;
8438 8438
8439 if (converter == NULL) 8439#if USE_CARBON_EVENTS
8440 /* When using Carbon Events, we need to pass raw keyboard
8441 events to the TSM ourselves. If TSM handles it, it
8442 will pass back noErr, otherwise it will pass back
8443 "eventNotHandledErr" and we can process it
8444 normally. */
8445 if ((!NILP (Vmac_pass_command_to_system)
8446 || !(er.modifiers & cmdKey))
8447 && (!NILP (Vmac_pass_control_to_system)
8448 || !(er.modifiers & controlKey)))
8449 if (SendEventToEventTarget (eventRef, toolbox_dispatcher)
8450 != eventNotHandledErr)
8451 break;
8452#endif
8453
8454#if TARGET_API_MAC_CARBON
8455 if (!IsValidWindowPtr (mac_front_window ()))
8440 { 8456 {
8441 the_err = TECCreateConverter (&converter, 8457 SysBeep (1);
8442 kTextEncodingMacRoman, 8458 break;
8443 mac_keyboard_text_encoding);
8444 current_mac_keyboard_text_encoding
8445 = mac_keyboard_text_encoding;
8446 } 8459 }
8447 else if (mac_keyboard_text_encoding 8460#endif
8448 != current_mac_keyboard_text_encoding) 8461
8462 ObscureCursor ();
8463
8464 if (!dpyinfo->mouse_face_hidden && INTEGERP (Vmouse_highlight))
8449 { 8465 {
8450 /* Free the converter for the current encoding before 8466 clear_mouse_face (dpyinfo);
8451 creating a new one. */ 8467 dpyinfo->mouse_face_hidden = 1;
8452 TECDisposeConverter (converter);
8453 the_err = TECCreateConverter (&converter,
8454 kTextEncodingMacRoman,
8455 mac_keyboard_text_encoding);
8456 current_mac_keyboard_text_encoding
8457 = mac_keyboard_text_encoding;
8458 } 8468 }
8459 8469
8460 if (the_err == noErr) 8470 if (keycode_to_xkeysym (keycode, &xkeysym))
8461 { 8471 {
8462 unsigned char ch = inev.code; 8472 inev.code = 0xff00 | xkeysym;
8463 ByteCount actual_input_length, actual_output_length; 8473 inev.kind = NON_ASCII_KEYSTROKE_EVENT;
8464 unsigned char outch; 8474 }
8465 8475 else
8466 convert_status = TECConvertText (converter, &ch, 1, 8476 {
8467 &actual_input_length, 8477 if (er.modifiers & (controlKey |
8468 &outch, 1, 8478 (NILP (Vmac_command_key_is_meta) ? optionKey
8469 &actual_output_length); 8479 : cmdKey)))
8470 if (convert_status == noErr 8480 {
8471 && actual_input_length == 1 8481 /* This code comes from Keyboard Resource,
8472 && actual_output_length == 1) 8482 Appendix C of IM - Text. This is necessary
8473 inev.code = outch; 8483 since shift is ignored in KCHR table
8484 translation when option or command is pressed.
8485 It also does not translate correctly
8486 control-shift chars like C-% so mask off shift
8487 here also */
8488 int new_modifiers = er.modifiers & 0xe600;
8489 /* mask off option and command */
8490 int new_keycode = keycode | new_modifiers;
8491 Ptr kchr_ptr = (Ptr) GetScriptManagerVariable (smKCHRCache);
8492 unsigned long some_state = 0;
8493 inev.code = KeyTranslate (kchr_ptr, new_keycode,
8494 &some_state) & 0xff;
8495 }
8496 else
8497 inev.code = er.message & charCodeMask;
8498 inev.kind = ASCII_KEYSTROKE_EVENT;
8474 } 8499 }
8475 } 8500 }
8476 8501
8502 /* If variable mac-convert-keyboard-input-to-latin-1 is
8503 non-nil, convert non-ASCII characters typed at the Mac
8504 keyboard (presumed to be in the Mac Roman encoding) to
8505 iso-latin-1 encoding before they are passed to Emacs.
8506 This enables the Mac keyboard to be used to enter
8507 non-ASCII iso-latin-1 characters directly. */
8508 if (mac_keyboard_text_encoding != kTextEncodingMacRoman
8509 && inev.kind == ASCII_KEYSTROKE_EVENT && inev.code >= 128)
8510 {
8511 static TECObjectRef converter = NULL;
8512 OSStatus the_err = noErr;
8513 OSStatus convert_status = noErr;
8514
8515 if (converter == NULL)
8516 {
8517 the_err = TECCreateConverter (&converter,
8518 kTextEncodingMacRoman,
8519 mac_keyboard_text_encoding);
8520 current_mac_keyboard_text_encoding
8521 = mac_keyboard_text_encoding;
8522 }
8523 else if (mac_keyboard_text_encoding
8524 != current_mac_keyboard_text_encoding)
8525 {
8526 /* Free the converter for the current encoding
8527 before creating a new one. */
8528 TECDisposeConverter (converter);
8529 the_err = TECCreateConverter (&converter,
8530 kTextEncodingMacRoman,
8531 mac_keyboard_text_encoding);
8532 current_mac_keyboard_text_encoding
8533 = mac_keyboard_text_encoding;
8534 }
8535
8536 if (the_err == noErr)
8537 {
8538 unsigned char ch = inev.code;
8539 ByteCount actual_input_length, actual_output_length;
8540 unsigned char outch;
8541
8542 convert_status = TECConvertText (converter, &ch, 1,
8543 &actual_input_length,
8544 &outch, 1,
8545 &actual_output_length);
8546 if (convert_status == noErr
8547 && actual_input_length == 1
8548 && actual_output_length == 1)
8549 inev.code = outch;
8550 }
8551 }
8552
8477#if USE_CARBON_EVENTS 8553#if USE_CARBON_EVENTS
8478 inev.modifiers = mac_event_to_emacs_modifiers (eventRef); 8554 inev.modifiers = mac_event_to_emacs_modifiers (eventRef);
8479#else 8555#else
8480 inev.modifiers = mac_to_emacs_modifiers (er.modifiers); 8556 inev.modifiers = mac_to_emacs_modifiers (er.modifiers);
8481#endif 8557#endif
8558 XSETFRAME (inev.frame_or_window,
8559 mac_window_to_frame (mac_front_window ()));
8560 inev.timestamp = er.when * (1000 / 60); /* ticks to milliseconds */
8561 break;
8482 8562
8483 { 8563 case kHighLevelEvent:
8484 mac_output *mwp 8564 drag_and_drop_file_list = Qnil;
8485 = (mac_output *) GetWRefCon (FrontNonFloatingWindow ());
8486 XSETFRAME (inev.frame_or_window, mwp->mFP);
8487 }
8488
8489 inev.timestamp = er.when * (1000 / 60); /* ticks to milliseconds */
8490 break;
8491
8492 case kHighLevelEvent:
8493 drag_and_drop_file_list = Qnil;
8494 8565
8495 AEProcessAppleEvent(&er); 8566 AEProcessAppleEvent(&er);
8496 8567
8497 /* Build a DRAG_N_DROP_EVENT type event as is done in 8568 /* Build a DRAG_N_DROP_EVENT type event as is done in
8498 constuct_drag_n_drop in w32term.c. */ 8569 constuct_drag_n_drop in w32term.c. */
8499 if (!NILP (drag_and_drop_file_list)) 8570 if (!NILP (drag_and_drop_file_list))
8500 { 8571 {
8501 struct frame *f = NULL; 8572 struct frame *f = NULL;
8502 WindowPtr wp; 8573 WindowPtr wp;
8503 Lisp_Object frame; 8574 Lisp_Object frame;
8504 8575
8505 wp = FrontNonFloatingWindow (); 8576 wp = mac_front_window ();
8506 8577
8507 if (!wp) 8578 if (!wp)
8508 { 8579 {
8509 struct frame *f = XFRAME (XCAR (Vframe_list)); 8580 struct frame *f = XFRAME (XCAR (Vframe_list));
8510 CollapseWindow (FRAME_MAC_WINDOW (f), false); 8581 CollapseWindow (FRAME_MAC_WINDOW (f), false);
8511 wp = FrontNonFloatingWindow (); 8582 wp = mac_front_window ();
8512 } 8583 }
8513 8584
8514 if (wp && is_emacs_window(wp)) 8585 if (wp && is_emacs_window (wp))
8515 f = ((mac_output *) GetWRefCon (wp))->mFP; 8586 f = mac_window_to_frame (wp);
8516 8587
8517 inev.kind = DRAG_N_DROP_EVENT; 8588 inev.kind = DRAG_N_DROP_EVENT;
8518 inev.code = 0; 8589 inev.code = 0;
8519 inev.timestamp = er.when * (1000 / 60); 8590 inev.timestamp = er.when * (1000 / 60);
8520 /* ticks to milliseconds */ 8591 /* ticks to milliseconds */
8521#if USE_CARBON_EVENTS 8592#if USE_CARBON_EVENTS
8522 inev.modifiers = mac_event_to_emacs_modifiers (eventRef); 8593 inev.modifiers = mac_event_to_emacs_modifiers (eventRef);
8523#else 8594#else
8524 inev.modifiers = mac_to_emacs_modifiers (er.modifiers); 8595 inev.modifiers = mac_to_emacs_modifiers (er.modifiers);
8525#endif 8596#endif
8526 8597
8527 XSETINT (inev.x, 0); 8598 XSETINT (inev.x, 0);
8528 XSETINT (inev.y, 0); 8599 XSETINT (inev.y, 0);
8529 8600
8530 XSETFRAME (frame, f); 8601 XSETFRAME (frame, f);
8531 inev.frame_or_window = Fcons (frame, drag_and_drop_file_list); 8602 inev.frame_or_window = Fcons (frame, drag_and_drop_file_list);
8532 8603
8533 /* Regardless of whether Emacs was suspended or in the 8604 /* Regardless of whether Emacs was suspended or in the
8534 foreground, ask it to redraw its entire screen. 8605 foreground, ask it to redraw its entire screen.
8535 Otherwise parts of the screen can be left in an 8606 Otherwise parts of the screen can be left in an
8536 inconsistent state. */ 8607 inconsistent state. */
8537 if (wp) 8608 if (wp)
8538#if TARGET_API_MAC_CARBON 8609#if TARGET_API_MAC_CARBON
8539 { 8610 {
8540 Rect r; 8611 Rect r;
8541 8612
8542 GetWindowPortBounds (wp, &r); 8613 GetWindowPortBounds (wp, &r);
8543 InvalWindowRect (wp, &r); 8614 InvalWindowRect (wp, &r);
8544 } 8615 }
8545#else /* not TARGET_API_MAC_CARBON */ 8616#else /* not TARGET_API_MAC_CARBON */
8546 InvalRect (&(wp->portRect)); 8617 InvalRect (&(wp->portRect));
8547#endif /* not TARGET_API_MAC_CARBON */ 8618#endif /* not TARGET_API_MAC_CARBON */
8548 } 8619 }
8549 default: 8620 default:
8550 break; 8621 break;
8551 } 8622 }
8552#if USE_CARBON_EVENTS 8623#if USE_CARBON_EVENTS
8553 ReleaseEvent (eventRef); 8624 ReleaseEvent (eventRef);
8554 }
8555#endif 8625#endif
8556 8626
8627 if (inev.kind != NO_EVENT)
8628 {
8629 kbd_buffer_store_event_hold (&inev, hold_quit);
8630 count++;
8631 }
8632
8633 if (do_help
8634 && !(hold_quit && hold_quit->kind != NO_EVENT))
8635 {
8636 Lisp_Object frame;
8637
8638 if (f)
8639 XSETFRAME (frame, f);
8640 else
8641 frame = Qnil;
8642
8643 if (do_help > 0)
8644 {
8645 any_help_event_p = 1;
8646 gen_help_event (help_echo_string, frame, help_echo_window,
8647 help_echo_object, help_echo_pos);
8648 }
8649 else
8650 {
8651 help_echo_string = Qnil;
8652 gen_help_event (Qnil, frame, Qnil, Qnil, 0);
8653 }
8654 count++;
8655 }
8656
8657 }
8658
8557 /* If the focus was just given to an autoraising frame, 8659 /* If the focus was just given to an autoraising frame,
8558 raise it now. */ 8660 raise it now. */
8559 /* ??? This ought to be able to handle more than one such frame. */ 8661 /* ??? This ought to be able to handle more than one such frame. */
@@ -8567,58 +8669,6 @@ XTread_socket (int sd, int expected, struct input_event *hold_quit)
8567 check_alarm (); /* simulate the handling of a SIGALRM */ 8669 check_alarm (); /* simulate the handling of a SIGALRM */
8568#endif 8670#endif
8569 8671
8570 {
8571 static Point old_mouse_pos = { -1, -1 };
8572
8573 if (app_is_suspended)
8574 {
8575 old_mouse_pos.h = -1;
8576 old_mouse_pos.v = -1;
8577 }
8578 else
8579 {
8580 Point mouse_pos;
8581 WindowPtr wp;
8582 struct frame *f;
8583 Lisp_Object bar;
8584 struct scroll_bar *sb;
8585
8586 wp = FrontWindow ();
8587 if (is_emacs_window (wp))
8588 {
8589 f = ((mac_output *) GetWRefCon (wp))->mFP;
8590
8591#if TARGET_API_MAC_CARBON
8592 SetPort (GetWindowPort (wp));
8593#else
8594 SetPort (wp);
8595#endif
8596
8597 GetMouse (&mouse_pos);
8598
8599 if (!EqualPt (mouse_pos, old_mouse_pos))
8600 {
8601 if (mouse_tracking_in_progress == mouse_tracking_scroll_bar
8602 && tracked_scroll_bar)
8603 x_scroll_bar_note_movement (tracked_scroll_bar,
8604 mouse_pos.v
8605 - XINT (tracked_scroll_bar->top),
8606 TickCount() * (1000 / 60));
8607 else
8608 note_mouse_movement (f, &mouse_pos);
8609
8610 old_mouse_pos = mouse_pos;
8611 }
8612 }
8613 }
8614 }
8615
8616 if (inev.kind != NO_EVENT)
8617 {
8618 kbd_buffer_store_event_hold (&inev, hold_quit);
8619 count++;
8620 }
8621
8622 UNBLOCK_INPUT; 8672 UNBLOCK_INPUT;
8623 return count; 8673 return count;
8624} 8674}
@@ -8647,7 +8697,7 @@ __convert_from_newlines (unsigned char * p, size_t * n)
8647 ROWS Macintosh window, using font with name FONTNAME and size 8697 ROWS Macintosh window, using font with name FONTNAME and size
8648 FONTSIZE. */ 8698 FONTSIZE. */
8649void 8699void
8650NewMacWindow (FRAME_PTR fp) 8700make_mac_frame (FRAME_PTR fp)
8651{ 8701{
8652 mac_output *mwp; 8702 mac_output *mwp;
8653#if TARGET_API_MAC_CARBON 8703#if TARGET_API_MAC_CARBON
@@ -8666,33 +8716,52 @@ NewMacWindow (FRAME_PTR fp)
8666 making_terminal_window = 0; 8716 making_terminal_window = 0;
8667 } 8717 }
8668 else 8718 else
8669 if (!(mwp->mWP = GetNewCWindow (WINDOW_RESOURCE, NULL, (WindowPtr) -1))) 8719 {
8670 abort (); 8720#if TARGET_API_MAC_CARBON
8721 Rect r;
8722
8723 SetRect (&r, 0, 0, 1, 1);
8724 if (CreateNewWindow (kDocumentWindowClass,
8725 kWindowStandardDocumentAttributes
8726 /* | kWindowToolbarButtonAttribute */,
8727 &r, &mwp->mWP) != noErr)
8728#else
8729 if (!(mwp->mWP = GetNewCWindow (WINDOW_RESOURCE, NULL, (WindowPtr) -1)))
8730#endif
8731 abort ();
8732 }
8671 8733
8672 SetWRefCon (mwp->mWP, (long) mwp); 8734 SetWRefCon (mwp->mWP, (long) mwp);
8673 /* so that update events can find this mac_output struct */ 8735 /* so that update events can find this mac_output struct */
8674 mwp->mFP = fp; /* point back to emacs frame */ 8736 mwp->mFP = fp; /* point back to emacs frame */
8675 8737
8676#if TARGET_API_MAC_CARBON 8738 SetPortWindowPort (mwp->mWP);
8677 SetPort (GetWindowPort (mwp->mWP));
8678#else
8679 SetPort (mwp->mWP);
8680#endif
8681
8682 mwp->fontset = -1;
8683 8739
8684 SizeWindow (mwp->mWP, FRAME_PIXEL_WIDTH (fp), FRAME_PIXEL_HEIGHT (fp), false); 8740 SizeWindow (mwp->mWP, FRAME_PIXEL_WIDTH (fp), FRAME_PIXEL_HEIGHT (fp), false);
8685 ShowWindow (mwp->mWP);
8686
8687} 8741}
8688 8742
8689 8743
8690void 8744void
8691make_mac_frame (struct frame *f) 8745make_mac_terminal_frame (struct frame *f)
8692{ 8746{
8693 FRAME_DESIRED_CURSOR (f) = FILLED_BOX_CURSOR; 8747 Lisp_Object frame;
8694 8748
8695 NewMacWindow(f); 8749 XSETFRAME (frame, f);
8750
8751 f->output_method = output_mac;
8752 f->output_data.mac = (struct mac_output *)
8753 xmalloc (sizeof (struct mac_output));
8754 bzero (f->output_data.mac, sizeof (struct mac_output));
8755
8756 XSETFRAME (FRAME_KBOARD (f)->Vdefault_minibuffer_frame, f);
8757
8758 FRAME_COLS (f) = 96;
8759 FRAME_LINES (f) = 4;
8760
8761 FRAME_CAN_HAVE_SCROLL_BARS (f) = 1;
8762 FRAME_VERTICAL_SCROLL_BAR_TYPE (f) = vertical_scroll_bar_right;
8763
8764 FRAME_DESIRED_CURSOR (f) = FILLED_BOX_CURSOR;
8696 8765
8697 f->output_data.mac->cursor_pixel = 0; 8766 f->output_data.mac->cursor_pixel = 0;
8698 f->output_data.mac->border_pixel = 0x00ff00; 8767 f->output_data.mac->border_pixel = 0x00ff00;
@@ -8700,8 +8769,6 @@ make_mac_frame (struct frame *f)
8700 f->output_data.mac->cursor_foreground_pixel = 0x0000ff; 8769 f->output_data.mac->cursor_foreground_pixel = 0x0000ff;
8701 8770
8702 FRAME_FONTSET (f) = -1; 8771 FRAME_FONTSET (f) = -1;
8703 f->output_data.mac->scroll_bar_foreground_pixel = -1;
8704 f->output_data.mac->scroll_bar_background_pixel = -1;
8705 f->output_data.mac->explicit_parent = 0; 8772 f->output_data.mac->explicit_parent = 0;
8706 f->left_pos = 4; 8773 f->left_pos = 4;
8707 f->top_pos = 4; 8774 f->top_pos = 4;
@@ -8709,37 +8776,11 @@ make_mac_frame (struct frame *f)
8709 8776
8710 f->internal_border_width = 0; 8777 f->internal_border_width = 0;
8711 8778
8712 f->output_method = output_mac;
8713
8714 f->auto_raise = 1; 8779 f->auto_raise = 1;
8715 f->auto_lower = 1; 8780 f->auto_lower = 1;
8716 8781
8717 f->new_text_cols = 0; 8782 f->new_text_cols = 0;
8718 f->new_text_lines = 0; 8783 f->new_text_lines = 0;
8719}
8720
8721void
8722make_mac_terminal_frame (struct frame *f)
8723{
8724 Lisp_Object frame;
8725
8726 XSETFRAME (frame, f);
8727
8728 f->output_method = output_mac;
8729 f->output_data.mac = (struct mac_output *)
8730 xmalloc (sizeof (struct mac_output));
8731 bzero (f->output_data.mac, sizeof (struct mac_output));
8732 FRAME_FONTSET (f) = -1;
8733 f->output_data.mac->scroll_bar_foreground_pixel = -1;
8734 f->output_data.mac->scroll_bar_background_pixel = -1;
8735
8736 XSETFRAME (FRAME_KBOARD (f)->Vdefault_minibuffer_frame, f);
8737
8738 FRAME_COLS (f) = 96;
8739 FRAME_LINES (f) = 4;
8740
8741 FRAME_CAN_HAVE_SCROLL_BARS (f) = 1;
8742 FRAME_VERTICAL_SCROLL_BAR_TYPE (f) = vertical_scroll_bar_right;
8743 8784
8744 make_mac_frame (f); 8785 make_mac_frame (f);
8745 8786
@@ -8757,6 +8798,8 @@ make_mac_terminal_frame (struct frame *f)
8757 Fmodify_frame_parameters (frame, 8798 Fmodify_frame_parameters (frame,
8758 Fcons (Fcons (Qbackground_color, 8799 Fcons (Fcons (Qbackground_color,
8759 build_string ("white")), Qnil)); 8800 build_string ("white")), Qnil));
8801
8802 ShowWindow (f->output_data.mac->mWP);
8760} 8803}
8761 8804
8762 8805
@@ -8797,10 +8840,16 @@ mac_initialize_display_info ()
8797 dpyinfo->resx = 75.0; 8840 dpyinfo->resx = 75.0;
8798 dpyinfo->resy = 75.0; 8841 dpyinfo->resy = 75.0;
8799 dpyinfo->color_p = TestDeviceAttribute (main_device_handle, gdDevType); 8842 dpyinfo->color_p = TestDeviceAttribute (main_device_handle, gdDevType);
8843#ifdef MAC_OSX
8844 /* HasDepth returns true if it is possible to have a 32 bit display,
8845 but this may not be what is actually used. Mac OSX can do better. */
8846 dpyinfo->n_planes = CGDisplayBitsPerPixel (CGMainDisplayID ());
8847#else
8800 for (dpyinfo->n_planes = 32; dpyinfo->n_planes > 0; dpyinfo->n_planes >>= 1) 8848 for (dpyinfo->n_planes = 32; dpyinfo->n_planes > 0; dpyinfo->n_planes >>= 1)
8801 if (HasDepth (main_device_handle, dpyinfo->n_planes, 8849 if (HasDepth (main_device_handle, dpyinfo->n_planes,
8802 gdDevType, dpyinfo->color_p)) 8850 gdDevType, dpyinfo->color_p))
8803 break; 8851 break;
8852#endif
8804 dpyinfo->height = (**main_device_handle).gdRect.bottom; 8853 dpyinfo->height = (**main_device_handle).gdRect.bottom;
8805 dpyinfo->width = (**main_device_handle).gdRect.right; 8854 dpyinfo->width = (**main_device_handle).gdRect.right;
8806 dpyinfo->grabbed = 0; 8855 dpyinfo->grabbed = 0;
@@ -8811,6 +8860,8 @@ mac_initialize_display_info ()
8811 dpyinfo->mouse_face_end_row = dpyinfo->mouse_face_end_col = -1; 8860 dpyinfo->mouse_face_end_row = dpyinfo->mouse_face_end_col = -1;
8812 dpyinfo->mouse_face_face_id = DEFAULT_FACE_ID; 8861 dpyinfo->mouse_face_face_id = DEFAULT_FACE_ID;
8813 dpyinfo->mouse_face_window = Qnil; 8862 dpyinfo->mouse_face_window = Qnil;
8863 dpyinfo->mouse_face_overlay = Qnil;
8864 dpyinfo->mouse_face_hidden = 0;
8814} 8865}
8815 8866
8816struct mac_display_info * 8867struct mac_display_info *
@@ -8959,22 +9010,23 @@ mac_check_for_quit_char ()
8959 mac_determine_quit_char_modifiers (); 9010 mac_determine_quit_char_modifiers ();
8960 9011
8961 /* Fill the queue with events */ 9012 /* Fill the queue with events */
9013 BLOCK_INPUT;
8962 ReceiveNextEvent (0, NULL, kEventDurationNoWait, false, &event); 9014 ReceiveNextEvent (0, NULL, kEventDurationNoWait, false, &event);
8963 event = FindSpecificEventInQueue (GetMainEventQueue (), quit_char_comp, 9015 event = FindSpecificEventInQueue (GetMainEventQueue (), quit_char_comp,
8964 NULL); 9016 NULL);
9017 UNBLOCK_INPUT;
8965 if (event) 9018 if (event)
8966 { 9019 {
8967 struct input_event e; 9020 struct input_event e;
8968 struct mac_output *mwp = 9021
8969 (mac_output *) GetWRefCon (FrontNonFloatingWindow ());
8970 /* Use an input_event to emulate what the interrupt handler does. */ 9022 /* Use an input_event to emulate what the interrupt handler does. */
8971 EVENT_INIT (e); 9023 EVENT_INIT (e);
8972 e.kind = ASCII_KEYSTROKE_EVENT; 9024 e.kind = ASCII_KEYSTROKE_EVENT;
8973 e.code = quit_char; 9025 e.code = quit_char;
8974 e.arg = NULL; 9026 e.arg = Qnil;
8975 e.modifiers = NULL; 9027 e.modifiers = NULL;
8976 e.timestamp = EventTimeToTicks (GetEventTime (event)) * (1000/60); 9028 e.timestamp = EventTimeToTicks (GetEventTime (event)) * (1000/60);
8977 XSETFRAME (e.frame_or_window, mwp->mFP); 9029 XSETFRAME (e.frame_or_window, mac_window_to_frame (mac_front_window ()));
8978 /* Remove event from queue to prevent looping. */ 9030 /* Remove event from queue to prevent looping. */
8979 RemoveEventFromQueue (GetMainEventQueue (), event); 9031 RemoveEventFromQueue (GetMainEventQueue (), event);
8980 ReleaseEvent (event); 9032 ReleaseEvent (event);
@@ -9185,10 +9237,10 @@ Otherwise the option key is used. */);
9185 useful for non-standard keyboard layouts. */); 9237 useful for non-standard keyboard layouts. */);
9186 Vmac_reverse_ctrl_meta = Qnil; 9238 Vmac_reverse_ctrl_meta = Qnil;
9187 9239
9188 DEFVAR_LISP ("mac-emulate-three-button-mouse", 9240 DEFVAR_LISP ("mac-emulate-three-button-mouse",
9189 &Vmac_emulate_three_button_mouse, 9241 &Vmac_emulate_three_button_mouse,
9190 doc: /* t means that when the option-key is held down while pressing the 9242 doc: /* t means that when the option-key is held down while pressing the
9191 mouse button, the click will register as mouse-2 and while the 9243 mouse button, the click will register as mouse-2 and while the
9192 command-key is held down, the click will register as mouse-3. 9244 command-key is held down, the click will register as mouse-3.
9193 'reverse means that the the option-key will register for mouse-3 9245 'reverse means that the the option-key will register for mouse-3
9194 and the command-key will register for mouse-2. nil means that 9246 and the command-key will register for mouse-2. nil means that