aboutsummaryrefslogtreecommitdiffstats
path: root/src/macterm.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/macterm.c')
-rw-r--r--src/macterm.c497
1 files changed, 293 insertions, 204 deletions
diff --git a/src/macterm.c b/src/macterm.c
index 76efa80d606..6902ac72304 100644
--- a/src/macterm.c
+++ b/src/macterm.c
@@ -108,6 +108,10 @@ static Lisp_Object last_window;
108 (Not yet supported.) */ 108 (Not yet supported.) */
109int x_use_underline_position_properties; 109int x_use_underline_position_properties;
110 110
111/* Non-zero means to draw the underline at the same place as the descent line. */
112
113int x_underline_at_descent_line;
114
111/* This is a chain of structures for all the X displays currently in 115/* This is a chain of structures for all the X displays currently in
112 use. */ 116 use. */
113 117
@@ -261,9 +265,6 @@ static int is_emacs_window P_ ((WindowPtr));
261static XCharStruct *mac_per_char_metric P_ ((XFontStruct *, XChar2b *, int)); 265static XCharStruct *mac_per_char_metric P_ ((XFontStruct *, XChar2b *, int));
262static void XSetFont P_ ((Display *, GC, XFontStruct *)); 266static void XSetFont P_ ((Display *, GC, XFontStruct *));
263 267
264/* Defined in macmenu.h. */
265extern void menubar_selection_callback (FRAME_PTR, int);
266
267#define GC_FORE_COLOR(gc) (&(gc)->fore_color) 268#define GC_FORE_COLOR(gc) (&(gc)->fore_color)
268#define GC_BACK_COLOR(gc) (&(gc)->back_color) 269#define GC_BACK_COLOR(gc) (&(gc)->back_color)
269#define GC_FONT(gc) ((gc)->xgcv.font) 270#define GC_FONT(gc) ((gc)->xgcv.font)
@@ -890,12 +891,13 @@ mac_invert_rectangle (f, x, y, width, height)
890 891
891 892
892static void 893static void
893mac_draw_string_common (f, gc, x, y, buf, nchars, bg_width, bytes_per_char) 894mac_draw_string_common (f, gc, x, y, buf, nchars, bg_width,
895 overstrike_p, bytes_per_char)
894 struct frame *f; 896 struct frame *f;
895 GC gc; 897 GC gc;
896 int x, y; 898 int x, y;
897 char *buf; 899 char *buf;
898 int nchars, bg_width, bytes_per_char; 900 int nchars, bg_width, overstrike_p, bytes_per_char;
899{ 901{
900 SetPortWindowPort (FRAME_MAC_WINDOW (f)); 902 SetPortWindowPort (FRAME_MAC_WINDOW (f));
901 903
@@ -945,6 +947,13 @@ mac_draw_string_common (f, gc, x, y, buf, nchars, bg_width, bytes_per_char)
945 ATSUDrawText (text_layout, 947 ATSUDrawText (text_layout,
946 kATSUFromTextBeginning, kATSUToTextEnd, 948 kATSUFromTextBeginning, kATSUToTextEnd,
947 kATSUUseGrafPortPenLoc, kATSUUseGrafPortPenLoc); 949 kATSUUseGrafPortPenLoc, kATSUUseGrafPortPenLoc);
950 if (overstrike_p)
951 {
952 MoveTo (x + 1, y);
953 ATSUDrawText (text_layout,
954 kATSUFromTextBeginning, kATSUToTextEnd,
955 kATSUUseGrafPortPenLoc, kATSUUseGrafPortPenLoc);
956 }
948 mac_end_clip (gc); 957 mac_end_clip (gc);
949#ifdef MAC_OSX 958#ifdef MAC_OSX
950 } 959 }
@@ -988,9 +997,15 @@ mac_draw_string_common (f, gc, x, y, buf, nchars, bg_width, bytes_per_char)
988 sizeof (tags) / sizeof (tags[0]), 997 sizeof (tags) / sizeof (tags[0]),
989 tags, sizes, values); 998 tags, sizes, values);
990 if (err == noErr) 999 if (err == noErr)
991 ATSUDrawText (text_layout, 1000 {
992 kATSUFromTextBeginning, kATSUToTextEnd, 1001 ATSUDrawText (text_layout,
993 Long2Fix (x), Long2Fix (port_height - y)); 1002 kATSUFromTextBeginning, kATSUToTextEnd,
1003 Long2Fix (x), Long2Fix (port_height - y));
1004 if (overstrike_p)
1005 ATSUDrawText (text_layout,
1006 kATSUFromTextBeginning, kATSUToTextEnd,
1007 Long2Fix (x + 1), Long2Fix (port_height - y));
1008 }
994#if USE_CG_DRAWING 1009#if USE_CG_DRAWING
995 mac_end_cg_clip (f); 1010 mac_end_cg_clip (f);
996 context = NULL; 1011 context = NULL;
@@ -1056,6 +1071,12 @@ mac_draw_string_common (f, gc, x, y, buf, nchars, bg_width, bytes_per_char)
1056 TextFace (GC_FONT (gc)->mac_fontface); 1071 TextFace (GC_FONT (gc)->mac_fontface);
1057 MoveTo (x, y); 1072 MoveTo (x, y);
1058 DrawText (buf, 0, nchars * bytes_per_char); 1073 DrawText (buf, 0, nchars * bytes_per_char);
1074 if (overstrike_p)
1075 {
1076 TextMode (srcOr);
1077 MoveTo (x + 1, y);
1078 DrawText (buf, 0, nchars * bytes_per_char);
1079 }
1059 if (bg_width) 1080 if (bg_width)
1060 RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f))); 1081 RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f)));
1061 mac_end_clip (gc); 1082 mac_end_clip (gc);
@@ -1068,59 +1089,33 @@ mac_draw_string_common (f, gc, x, y, buf, nchars, bg_width, bytes_per_char)
1068} 1089}
1069 1090
1070 1091
1071/* Mac replacement for XDrawString. */
1072
1073static void
1074mac_draw_string (f, gc, x, y, buf, nchars)
1075 struct frame *f;
1076 GC gc;
1077 int x, y;
1078 char *buf;
1079 int nchars;
1080{
1081 mac_draw_string_common (f, gc, x, y, buf, nchars, 0, 1);
1082}
1083
1084
1085/* Mac replacement for XDrawString16. */
1086
1087static void
1088mac_draw_string_16 (f, gc, x, y, buf, nchars)
1089 struct frame *f;
1090 GC gc;
1091 int x, y;
1092 XChar2b *buf;
1093 int nchars;
1094{
1095 mac_draw_string_common (f, gc, x, y, (char *) buf, nchars, 0, 2);
1096}
1097
1098
1099/* Mac replacement for XDrawImageString. */ 1092/* Mac replacement for XDrawImageString. */
1100 1093
1101static void 1094static void
1102mac_draw_image_string (f, gc, x, y, buf, nchars, bg_width) 1095mac_draw_image_string (f, gc, x, y, buf, nchars, bg_width, overstrike_p)
1103 struct frame *f; 1096 struct frame *f;
1104 GC gc; 1097 GC gc;
1105 int x, y; 1098 int x, y;
1106 char *buf; 1099 char *buf;
1107 int nchars, bg_width; 1100 int nchars, bg_width, overstrike_p;
1108{ 1101{
1109 mac_draw_string_common (f, gc, x, y, buf, nchars, bg_width, 1); 1102 mac_draw_string_common (f, gc, x, y, buf, nchars, bg_width,
1103 overstrike_p, 1);
1110} 1104}
1111 1105
1112 1106
1113/* Mac replacement for XDrawString16. */ 1107/* Mac replacement for XDrawImageString16. */
1114 1108
1115static void 1109static void
1116mac_draw_image_string_16 (f, gc, x, y, buf, nchars, bg_width) 1110mac_draw_image_string_16 (f, gc, x, y, buf, nchars, bg_width, overstrike_p)
1117 struct frame *f; 1111 struct frame *f;
1118 GC gc; 1112 GC gc;
1119 int x, y; 1113 int x, y;
1120 XChar2b *buf; 1114 XChar2b *buf;
1121 int nchars, bg_width; 1115 int nchars, bg_width, overstrike_p;
1122{ 1116{
1123 mac_draw_string_common (f, gc, x, y, (char *) buf, nchars, bg_width, 2); 1117 mac_draw_string_common (f, gc, x, y, (char *) buf, nchars, bg_width,
1118 overstrike_p, 2);
1124} 1119}
1125 1120
1126 1121
@@ -1294,12 +1289,12 @@ init_cg_text_anti_aliasing_threshold ()
1294} 1289}
1295 1290
1296static int 1291static int
1297mac_draw_image_string_cg (f, gc, x, y, buf, nchars, bg_width) 1292mac_draw_image_string_cg (f, gc, x, y, buf, nchars, bg_width, overstrike_p)
1298 struct frame *f; 1293 struct frame *f;
1299 GC gc; 1294 GC gc;
1300 int x, y; 1295 int x, y;
1301 XChar2b *buf; 1296 XChar2b *buf;
1302 int nchars, bg_width; 1297 int nchars, bg_width, overstrike_p;
1303{ 1298{
1304 CGrafPtr port; 1299 CGrafPtr port;
1305 float port_height, gx, gy; 1300 float port_height, gx, gy;
@@ -1361,10 +1356,17 @@ mac_draw_image_string_cg (f, gc, x, y, buf, nchars, bg_width)
1361#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030 1356#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030
1362 CGContextSetTextPosition (context, gx, gy); 1357 CGContextSetTextPosition (context, gx, gy);
1363 CGContextShowGlyphsWithAdvances (context, glyphs, advances, nchars); 1358 CGContextShowGlyphsWithAdvances (context, glyphs, advances, nchars);
1359 if (overstrike_p)
1360 {
1361 CGContextSetTextPosition (context, gx + 1.0f, gy);
1362 CGContextShowGlyphsWithAdvances (context, glyphs, advances, nchars);
1363 }
1364#else 1364#else
1365 for (i = 0; i < nchars; i++) 1365 for (i = 0; i < nchars; i++)
1366 { 1366 {
1367 CGContextShowGlyphsAtPoint (context, gx, gy, glyphs + i, 1); 1367 CGContextShowGlyphsAtPoint (context, gx, gy, glyphs + i, 1);
1368 if (overstrike_p)
1369 CGContextShowGlyphsAtPoint (context, gx + 1.0f, gy, glyphs + i, 1);
1368 gx += advances[i].width; 1370 gx += advances[i].width;
1369 } 1371 }
1370#endif 1372#endif
@@ -2633,6 +2635,11 @@ mac_compute_glyph_string_overhangs (s)
2633 Rect r; 2635 Rect r;
2634 MacFontStruct *font = s->font; 2636 MacFontStruct *font = s->font;
2635 2637
2638#if USE_CG_DRAWING
2639 mac_prepare_for_quickdraw (s->f);
2640#endif
2641 SetPortWindowPort (FRAME_MAC_WINDOW (s->f));
2642
2636 TextFont (font->mac_fontnum); 2643 TextFont (font->mac_fontnum);
2637 TextSize (font->mac_fontsize); 2644 TextSize (font->mac_fontsize);
2638 TextFace (font->mac_fontface); 2645 TextFace (font->mac_fontface);
@@ -2765,15 +2772,18 @@ x_draw_glyph_string_foreground (s)
2765#if USE_CG_TEXT_DRAWING 2772#if USE_CG_TEXT_DRAWING
2766 if (!s->two_byte_p 2773 if (!s->two_byte_p
2767 && mac_draw_image_string_cg (s->f, s->gc, x, s->ybase - boff, 2774 && mac_draw_image_string_cg (s->f, s->gc, x, s->ybase - boff,
2768 s->char2b, s->nchars, bg_width)) 2775 s->char2b, s->nchars, bg_width,
2776 s->face->overstrike))
2769 ; 2777 ;
2770 else 2778 else
2771#endif 2779#endif
2772 mac_draw_image_string_16 (s->f, s->gc, x, s->ybase - boff, 2780 mac_draw_image_string_16 (s->f, s->gc, x, s->ybase - boff,
2773 s->char2b, s->nchars, bg_width); 2781 s->char2b, s->nchars, bg_width,
2782 s->face->overstrike);
2774 else 2783 else
2775 mac_draw_image_string (s->f, s->gc, x, s->ybase - boff, 2784 mac_draw_image_string (s->f, s->gc, x, s->ybase - boff,
2776 char1b, s->nchars, bg_width); 2785 char1b, s->nchars, bg_width,
2786 s->face->overstrike);
2777 } 2787 }
2778} 2788}
2779 2789
@@ -2809,10 +2819,10 @@ x_draw_composite_glyph_string_foreground (s)
2809 else 2819 else
2810 { 2820 {
2811 for (i = 0; i < s->nchars; i++, ++s->gidx) 2821 for (i = 0; i < s->nchars; i++, ++s->gidx)
2812 mac_draw_string_16 (s->f, s->gc, 2822 mac_draw_image_string_16 (s->f, s->gc,
2813 x + s->cmp->offsets[s->gidx * 2], 2823 x + s->cmp->offsets[s->gidx * 2],
2814 s->ybase - s->cmp->offsets[s->gidx * 2 + 1], 2824 s->ybase - s->cmp->offsets[s->gidx * 2 + 1],
2815 s->char2b + i, 1); 2825 s->char2b + i, 1, 0, s->face->overstrike);
2816 } 2826 }
2817} 2827}
2818 2828
@@ -3674,18 +3684,45 @@ x_draw_glyph_string (s)
3674 /* Draw underline. */ 3684 /* Draw underline. */
3675 if (s->face->underline_p) 3685 if (s->face->underline_p)
3676 { 3686 {
3677 unsigned long h = 1; 3687 unsigned long tem, h;
3678 unsigned long dy = s->height - h; 3688 int y;
3689
3690#if 0
3691 /* Get the underline thickness. Default is 1 pixel. */
3692 if (!XGetFontProperty (s->font, XA_UNDERLINE_THICKNESS, &h))
3693#endif
3694 h = 1;
3695
3696 y = s->y + s->height - h;
3697 if (!x_underline_at_descent_line)
3698 {
3699 /* Get the underline position. This is the recommended
3700 vertical offset in pixels from the baseline to the top of
3701 the underline. This is a signed value according to the
3702 specs, and its default is
3703
3704 ROUND ((maximum descent) / 2), with
3705 ROUND(x) = floor (x + 0.5) */
3706
3707#if 0
3708 if (x_use_underline_position_properties
3709 && XGetFontProperty (s->font, XA_UNDERLINE_POSITION, &tem))
3710 y = s->ybase + (long) tem;
3711 else
3712#endif
3713 if (s->face->font)
3714 y = s->ybase + (s->face->font->max_bounds.descent + 1) / 2;
3715 }
3679 3716
3680 if (s->face->underline_defaulted_p) 3717 if (s->face->underline_defaulted_p)
3681 mac_fill_rectangle (s->f, s->gc, s->x, s->y + dy, 3718 mac_fill_rectangle (s->f, s->gc, s->x, y,
3682 s->background_width, h); 3719 s->background_width, h);
3683 else 3720 else
3684 { 3721 {
3685 XGCValues xgcv; 3722 XGCValues xgcv;
3686 XGetGCValues (s->display, s->gc, GCForeground, &xgcv); 3723 XGetGCValues (s->display, s->gc, GCForeground, &xgcv);
3687 XSetForeground (s->display, s->gc, s->face->underline_color); 3724 XSetForeground (s->display, s->gc, s->face->underline_color);
3688 mac_fill_rectangle (s->f, s->gc, s->x, s->y + dy, 3725 mac_fill_rectangle (s->f, s->gc, s->x, y,
3689 s->background_width, h); 3726 s->background_width, h);
3690 XSetForeground (s->display, s->gc, xgcv.foreground); 3727 XSetForeground (s->display, s->gc, xgcv.foreground);
3691 } 3728 }
@@ -5805,6 +5842,57 @@ mac_get_window_bounds (f, inner, outer)
5805#endif /* not TARGET_API_MAC_CARBON */ 5842#endif /* not TARGET_API_MAC_CARBON */
5806} 5843}
5807 5844
5845static void
5846mac_handle_origin_change (f)
5847 struct frame *f;
5848{
5849 x_real_positions (f, &f->left_pos, &f->top_pos);
5850}
5851
5852static void
5853mac_handle_size_change (f, pixelwidth, pixelheight)
5854 struct frame *f;
5855 int pixelwidth, pixelheight;
5856{
5857 int cols, rows;
5858
5859 cols = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, pixelwidth);
5860 rows = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, pixelheight);
5861
5862 if (cols != FRAME_COLS (f)
5863 || rows != FRAME_LINES (f)
5864 || pixelwidth != FRAME_PIXEL_WIDTH (f)
5865 || pixelheight != FRAME_PIXEL_HEIGHT (f))
5866 {
5867 /* We pass 1 for DELAY since we can't run Lisp code inside of
5868 a BLOCK_INPUT. */
5869 change_frame_size (f, rows, cols, 0, 1, 0);
5870 FRAME_PIXEL_WIDTH (f) = pixelwidth;
5871 FRAME_PIXEL_HEIGHT (f) = pixelheight;
5872 SET_FRAME_GARBAGED (f);
5873
5874 /* If cursor was outside the new size, mark it as off. */
5875 mark_window_cursors_off (XWINDOW (f->root_window));
5876
5877 /* Clear out any recollection of where the mouse highlighting
5878 was, since it might be in a place that's outside the new
5879 frame size. Actually checking whether it is outside is a
5880 pain in the neck, so don't try--just let the highlighting be
5881 done afresh with new size. */
5882 cancel_mouse_face (f);
5883
5884#if TARGET_API_MAC_CARBON
5885 if (f->output_data.mac->hourglass_control)
5886 {
5887#if USE_CG_DRAWING
5888 mac_prepare_for_quickdraw (f);
5889#endif
5890 MoveControl (f->output_data.mac->hourglass_control,
5891 pixelwidth - HOURGLASS_WIDTH, 0);
5892 }
5893#endif
5894 }
5895}
5808 5896
5809 5897
5810/* Calculate the absolute position in frame F 5898/* Calculate the absolute position in frame F
@@ -5885,7 +5973,10 @@ x_set_offset (f, xoff, yoff, change_gravity)
5885 ConstrainWindowToScreen (FRAME_MAC_WINDOW (f), kWindowTitleBarRgn, 5973 ConstrainWindowToScreen (FRAME_MAC_WINDOW (f), kWindowTitleBarRgn,
5886 kWindowConstrainMoveRegardlessOfFit 5974 kWindowConstrainMoveRegardlessOfFit
5887 | kWindowConstrainAllowPartial, NULL, NULL); 5975 | kWindowConstrainAllowPartial, NULL, NULL);
5888 x_real_positions (f, &f->left_pos, &f->top_pos); 5976#if USE_CARBON_EVENTS
5977 if (!NILP (tip_frame) && XFRAME (tip_frame) == f)
5978#endif
5979 mac_handle_origin_change (f);
5889#else 5980#else
5890 { 5981 {
5891 Rect inner, outer, screen_rect, dummy; 5982 Rect inner, outer, screen_rect, dummy;
@@ -5959,50 +6050,11 @@ x_set_window_size (f, change_gravity, cols, rows)
5959 x_wm_set_size_hint (f, (long) 0, 0); 6050 x_wm_set_size_hint (f, (long) 0, 0);
5960 6051
5961 SizeWindow (FRAME_MAC_WINDOW (f), pixelwidth, pixelheight, 0); 6052 SizeWindow (FRAME_MAC_WINDOW (f), pixelwidth, pixelheight, 0);
5962#if TARGET_API_MAC_CARBON
5963 if (f->output_data.mac->hourglass_control)
5964 {
5965#if USE_CG_DRAWING
5966 mac_prepare_for_quickdraw (f);
5967#endif
5968 MoveControl (f->output_data.mac->hourglass_control,
5969 pixelwidth - HOURGLASS_WIDTH, 0);
5970 }
5971#endif
5972
5973 /* Now, strictly speaking, we can't be sure that this is accurate,
5974 but the window manager will get around to dealing with the size
5975 change request eventually, and we'll hear how it went when the
5976 ConfigureNotify event gets here.
5977
5978 We could just not bother storing any of this information here,
5979 and let the ConfigureNotify event set everything up, but that
5980 might be kind of confusing to the Lisp code, since size changes
5981 wouldn't be reported in the frame parameters until some random
5982 point in the future when the ConfigureNotify event arrives.
5983
5984 We pass 1 for DELAY since we can't run Lisp code inside of
5985 a BLOCK_INPUT. */
5986 change_frame_size (f, rows, cols, 0, 1, 0);
5987 FRAME_PIXEL_WIDTH (f) = pixelwidth;
5988 FRAME_PIXEL_HEIGHT (f) = pixelheight;
5989
5990 /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
5991 receive in the ConfigureNotify event; if we get what we asked
5992 for, then the event won't cause the screen to become garbaged, so
5993 we have to make sure to do it here. */
5994 SET_FRAME_GARBAGED (f);
5995
5996 XFlush (FRAME_X_DISPLAY (f));
5997
5998 /* If cursor was outside the new size, mark it as off. */
5999 mark_window_cursors_off (XWINDOW (f->root_window));
6000 6053
6001 /* Clear out any recollection of where the mouse highlighting was, 6054#if USE_CARBON_EVENTS
6002 since it might be in a place that's outside the new frame size. 6055 if (!NILP (tip_frame) && f == XFRAME (tip_frame))
6003 Actually checking whether it is outside is a pain in the neck, 6056#endif
6004 so don't try--just let the highlighting be done afresh with new size. */ 6057 mac_handle_size_change (f, pixelwidth, pixelheight);
6005 cancel_mouse_face (f);
6006 6058
6007 UNBLOCK_INPUT; 6059 UNBLOCK_INPUT;
6008} 6060}
@@ -6213,7 +6265,10 @@ x_make_frame_visible (f)
6213 kWindowCascadeOnParentWindowScreen 6265 kWindowCascadeOnParentWindowScreen
6214#endif 6266#endif
6215 ); 6267 );
6216 x_real_positions (f, &f->left_pos, &f->top_pos); 6268#if USE_CARBON_EVENTS
6269 if (!NILP (tip_frame) && f == XFRAME (tip_frame))
6270#endif
6271 mac_handle_origin_change (f);
6217 } 6272 }
6218 else 6273 else
6219#endif 6274#endif
@@ -7731,14 +7786,16 @@ is_fully_specified_xlfd (char *p)
7731} 7786}
7732 7787
7733 7788
7734/* XLoadQueryFont creates and returns an internal representation for a 7789/* mac_load_query_font creates and returns an internal representation
7735 font in a MacFontStruct struct. There is really no concept 7790 for a font in a MacFontStruct struct. There is really no concept
7736 corresponding to "loading" a font on the Mac. But we check its 7791 corresponding to "loading" a font on the Mac. But we check its
7737 existence and find the font number and all other information for it 7792 existence and find the font number and all other information for it
7738 and store them in the returned MacFontStruct. */ 7793 and store them in the returned MacFontStruct. */
7739 7794
7740static MacFontStruct * 7795static MacFontStruct *
7741XLoadQueryFont (Display *dpy, char *fontname) 7796mac_load_query_font (f, fontname)
7797 struct frame *f;
7798 char *fontname;
7742{ 7799{
7743 int size; 7800 int size;
7744 char *name; 7801 char *name;
@@ -7949,23 +8006,13 @@ XLoadQueryFont (Display *dpy, char *fontname)
7949 else 8006 else
7950#endif 8007#endif
7951 { 8008 {
7952 GrafPtr port;
7953 SInt16 old_fontnum, old_fontsize;
7954 Style old_fontface;
7955 FontInfo the_fontinfo; 8009 FontInfo the_fontinfo;
7956 int is_two_byte_font; 8010 int is_two_byte_font;
7957 8011
7958 /* Save the current font number used. */ 8012#if USE_CG_DRAWING
7959 GetPort (&port); 8013 mac_prepare_for_quickdraw (f);
7960#if TARGET_API_MAC_CARBON
7961 old_fontnum = GetPortTextFont (port);
7962 old_fontsize = GetPortTextSize (port);
7963 old_fontface = GetPortTextFace (port);
7964#else
7965 old_fontnum = port->txFont;
7966 old_fontsize = port->txSize;
7967 old_fontface = port->txFace;
7968#endif 8014#endif
8015 SetPortWindowPort (FRAME_MAC_WINDOW (f));
7969 8016
7970 TextFont (fontnum); 8017 TextFont (fontnum);
7971 TextSize (size); 8018 TextSize (size);
@@ -8047,11 +8094,6 @@ XLoadQueryFont (Display *dpy, char *fontname)
8047 for (c = 0x21, pcm = space_bounds + 1; c <= 0xff; c++, pcm++) 8094 for (c = 0x21, pcm = space_bounds + 1; c <= 0xff; c++, pcm++)
8048 mac_query_char_extents (NULL, c, NULL, NULL, pcm, NULL); 8095 mac_query_char_extents (NULL, c, NULL, NULL, pcm, NULL);
8049 } 8096 }
8050
8051 /* Restore previous font number, size and face. */
8052 TextFont (old_fontnum);
8053 TextSize (old_fontsize);
8054 TextFace (old_fontface);
8055 } 8097 }
8056 8098
8057 if (space_bounds) 8099 if (space_bounds)
@@ -8070,6 +8112,8 @@ XLoadQueryFont (Display *dpy, char *fontname)
8070 pcm->width); 8112 pcm->width);
8071 font->min_bounds.ascent = min (font->min_bounds.ascent, 8113 font->min_bounds.ascent = min (font->min_bounds.ascent,
8072 pcm->ascent); 8114 pcm->ascent);
8115 font->min_bounds.descent = min (font->min_bounds.descent,
8116 pcm->descent);
8073 8117
8074 font->max_bounds.lbearing = max (font->max_bounds.lbearing, 8118 font->max_bounds.lbearing = max (font->max_bounds.lbearing,
8075 pcm->lbearing); 8119 pcm->lbearing);
@@ -8079,6 +8123,8 @@ XLoadQueryFont (Display *dpy, char *fontname)
8079 pcm->width); 8123 pcm->width);
8080 font->max_bounds.ascent = max (font->max_bounds.ascent, 8124 font->max_bounds.ascent = max (font->max_bounds.ascent,
8081 pcm->ascent); 8125 pcm->ascent);
8126 font->max_bounds.descent = max (font->max_bounds.descent,
8127 pcm->descent);
8082 } 8128 }
8083 if ( 8129 if (
8084#if USE_ATSUI 8130#if USE_ATSUI
@@ -8187,7 +8233,7 @@ x_load_font (f, fontname, size)
8187 fontname = (char *) SDATA (XCAR (font_names)); 8233 fontname = (char *) SDATA (XCAR (font_names));
8188 8234
8189 BLOCK_INPUT; 8235 BLOCK_INPUT;
8190 font = (MacFontStruct *) XLoadQueryFont (FRAME_MAC_DISPLAY (f), fontname); 8236 font = mac_load_query_font (f, fontname);
8191 UNBLOCK_INPUT; 8237 UNBLOCK_INPUT;
8192 if (!font) 8238 if (!font)
8193 return NULL; 8239 return NULL;
@@ -8474,7 +8520,7 @@ mac_set_font_info_for_selection (f, face_id, c)
8474#endif 8520#endif
8475#endif /* ! TARGET_API_MAC_CARBON */ 8521#endif /* ! TARGET_API_MAC_CARBON */
8476 8522
8477#define M_APPLE 128 8523#define M_APPLE 234
8478#define I_ABOUT 1 8524#define I_ABOUT 1
8479 8525
8480#define WINDOW_RESOURCE 128 8526#define WINDOW_RESOURCE 128
@@ -9064,10 +9110,10 @@ mac_tsm_suspend ()
9064} 9110}
9065#endif 9111#endif
9066 9112
9067static void 9113#if !TARGET_API_MAC_CARBON
9114void
9068do_apple_menu (SInt16 menu_item) 9115do_apple_menu (SInt16 menu_item)
9069{ 9116{
9070#if !TARGET_API_MAC_CARBON
9071 Str255 item_name; 9117 Str255 item_name;
9072 SInt16 da_driver_refnum; 9118 SInt16 da_driver_refnum;
9073 9119
@@ -9078,43 +9124,8 @@ do_apple_menu (SInt16 menu_item)
9078 GetMenuItemText (GetMenuHandle (M_APPLE), menu_item, item_name); 9124 GetMenuItemText (GetMenuHandle (M_APPLE), menu_item, item_name);
9079 da_driver_refnum = OpenDeskAcc (item_name); 9125 da_driver_refnum = OpenDeskAcc (item_name);
9080 } 9126 }
9081#endif /* !TARGET_API_MAC_CARBON */
9082}
9083
9084void
9085do_menu_choice (SInt32 menu_choice)
9086{
9087 SInt16 menu_id, menu_item;
9088
9089 menu_id = HiWord (menu_choice);
9090 menu_item = LoWord (menu_choice);
9091
9092 switch (menu_id)
9093 {
9094 case 0:
9095 break;
9096
9097 case M_APPLE:
9098 do_apple_menu (menu_item);
9099 break;
9100
9101 default:
9102 {
9103 struct frame *f = mac_focus_frame (&one_mac_display_info);
9104 MenuHandle menu = GetMenuHandle (menu_id);
9105 if (menu)
9106 {
9107 UInt32 refcon;
9108
9109 GetMenuItemRefCon (menu, menu_item, &refcon);
9110 menubar_selection_callback (f, refcon);
9111 }
9112 }
9113 }
9114
9115 HiliteMenu (0);
9116} 9127}
9117 9128#endif /* !TARGET_API_MAC_CARBON */
9118 9129
9119/* Handle drags in size box. Based on code contributed by Ben 9130/* Handle drags in size box. Based on code contributed by Ben
9120 Mesander and IM - Window Manager A. */ 9131 Mesander and IM - Window Manager A. */
@@ -9165,6 +9176,32 @@ do_grow_window (WindowPtr w, EventRecord *e)
9165} 9176}
9166 9177
9167 9178
9179#if TARGET_API_MAC_CARBON
9180static Point
9181mac_get_ideal_size (f)
9182 struct frame *f;
9183{
9184 struct mac_display_info *dpyinfo = FRAME_MAC_DISPLAY_INFO (f);
9185 WindowPtr w = FRAME_MAC_WINDOW (f);
9186 Point ideal_size;
9187 Rect standard_rect;
9188 int height, width, columns, rows;
9189
9190 ideal_size.h = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, DEFAULT_NUM_COLS);
9191 ideal_size.v = dpyinfo->height;
9192 IsWindowInStandardState (w, &ideal_size, &standard_rect);
9193 /* Adjust the standard size according to character boundaries. */
9194 width = standard_rect.right - standard_rect.left;
9195 height = standard_rect.bottom - standard_rect.top;
9196 columns = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, width);
9197 rows = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, height);
9198 ideal_size.h = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, columns);
9199 ideal_size.v = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, rows);
9200
9201 return ideal_size;
9202}
9203#endif
9204
9168/* Handle clicks in zoom box. Calculation of "standard state" based 9205/* Handle clicks in zoom box. Calculation of "standard state" based
9169 on code in IM - Window Manager A and code contributed by Ben 9206 on code in IM - Window Manager A and code contributed by Ben
9170 Mesander. The standard state of an Emacs window is 80-characters 9207 Mesander. The standard state of an Emacs window is 80-characters
@@ -9174,39 +9211,28 @@ static void
9174do_zoom_window (WindowPtr w, int zoom_in_or_out) 9211do_zoom_window (WindowPtr w, int zoom_in_or_out)
9175{ 9212{
9176 Rect zoom_rect, port_rect; 9213 Rect zoom_rect, port_rect;
9177 int columns, rows, width, height; 9214 int width, height;
9178 struct frame *f = mac_window_to_frame (w); 9215 struct frame *f = mac_window_to_frame (w);
9179 struct mac_display_info *dpyinfo = FRAME_MAC_DISPLAY_INFO (f);
9180#if TARGET_API_MAC_CARBON 9216#if TARGET_API_MAC_CARBON
9181 Point standard_size; 9217 Point ideal_size = mac_get_ideal_size (f);
9182 9218
9183 standard_size.h = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, DEFAULT_NUM_COLS); 9219 GetWindowBounds (w, kWindowContentRgn, &port_rect);
9184 standard_size.v = dpyinfo->height; 9220 if (IsWindowInStandardState (w, &ideal_size, &zoom_rect)
9185 9221 && port_rect.left == zoom_rect.left
9186 if (IsWindowInStandardState (w, &standard_size, &zoom_rect)) 9222 && port_rect.top == zoom_rect.top)
9187 zoom_in_or_out = inZoomIn; 9223 zoom_in_or_out = inZoomIn;
9188 else 9224 else
9189 { 9225 zoom_in_or_out = inZoomOut;
9190 /* Adjust the standard size according to character boundaries. */
9191 9226
9192 columns = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, zoom_rect.right - zoom_rect.left); 9227#ifdef MAC_OS8
9193 rows = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, zoom_rect.bottom - zoom_rect.top); 9228 mac_clear_window (f);
9194 standard_size.h = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, columns); 9229#endif
9195 standard_size.v = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, rows); 9230 ZoomWindowIdeal (w, zoom_in_or_out, &ideal_size);
9196 GetWindowBounds (w, kWindowContentRgn, &port_rect);
9197 if (IsWindowInStandardState (w, &standard_size, &zoom_rect)
9198 && port_rect.left == zoom_rect.left
9199 && port_rect.top == zoom_rect.top)
9200 zoom_in_or_out = inZoomIn;
9201 else
9202 zoom_in_or_out = inZoomOut;
9203 }
9204
9205 ZoomWindowIdeal (w, zoom_in_or_out, &standard_size);
9206#else /* not TARGET_API_MAC_CARBON */ 9231#else /* not TARGET_API_MAC_CARBON */
9207 GrafPtr save_port; 9232 GrafPtr save_port;
9208 Point top_left; 9233 Point top_left;
9209 int w_title_height; 9234 int w_title_height, rows;
9235 struct mac_display_info *dpyinfo = FRAME_MAC_DISPLAY_INFO (f);
9210 9236
9211 GetPort (&save_port); 9237 GetPort (&save_port);
9212 9238
@@ -9245,6 +9271,7 @@ do_zoom_window (WindowPtr w, int zoom_in_or_out)
9245 SetPort (save_port); 9271 SetPort (save_port);
9246#endif /* not TARGET_API_MAC_CARBON */ 9272#endif /* not TARGET_API_MAC_CARBON */
9247 9273
9274#if !USE_CARBON_EVENTS
9248 /* retrieve window size and update application values */ 9275 /* retrieve window size and update application values */
9249#if TARGET_API_MAC_CARBON 9276#if TARGET_API_MAC_CARBON
9250 GetWindowPortBounds (w, &port_rect); 9277 GetWindowPortBounds (w, &port_rect);
@@ -9254,20 +9281,9 @@ do_zoom_window (WindowPtr w, int zoom_in_or_out)
9254 height = port_rect.bottom - port_rect.top; 9281 height = port_rect.bottom - port_rect.top;
9255 width = port_rect.right - port_rect.left; 9282 width = port_rect.right - port_rect.left;
9256 9283
9257 if (width != FRAME_PIXEL_WIDTH (f) 9284 mac_handle_size_change (f, width, height);
9258 || height != FRAME_PIXEL_HEIGHT (f)) 9285 mac_handle_origin_change (f);
9259 { 9286#endif
9260 rows = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, height);
9261 columns = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, width);
9262
9263 change_frame_size (f, rows, columns, 0, 1, 0);
9264 SET_FRAME_GARBAGED (f);
9265 cancel_mouse_face (f);
9266
9267 FRAME_PIXEL_WIDTH (f) = width;
9268 FRAME_PIXEL_HEIGHT (f) = height;
9269 }
9270 x_real_positions (f, &f->left_pos, &f->top_pos);
9271} 9287}
9272 9288
9273void 9289void
@@ -9406,6 +9422,7 @@ mac_handle_window_event (next_handler, event, data)
9406{ 9422{
9407 WindowPtr wp; 9423 WindowPtr wp;
9408 OSStatus result, err; 9424 OSStatus result, err;
9425 struct frame *f;
9409 UInt32 attributes; 9426 UInt32 attributes;
9410 XSizeHints *size_hints; 9427 XSizeHints *size_hints;
9411 9428
@@ -9414,6 +9431,7 @@ mac_handle_window_event (next_handler, event, data)
9414 if (err != noErr) 9431 if (err != noErr)
9415 return eventNotHandledErr; 9432 return eventNotHandledErr;
9416 9433
9434 f = mac_window_to_frame (wp);
9417 switch (GetEventKind (event)) 9435 switch (GetEventKind (event))
9418 { 9436 {
9419 case kEventWindowUpdate: 9437 case kEventWindowUpdate:
@@ -9424,6 +9442,21 @@ mac_handle_window_event (next_handler, event, data)
9424 do_window_update (wp); 9442 do_window_update (wp);
9425 return noErr; 9443 return noErr;
9426 9444
9445 case kEventWindowGetIdealSize:
9446 result = CallNextEventHandler (next_handler, event);
9447 if (result != eventNotHandledErr)
9448 return result;
9449
9450 {
9451 Point ideal_size = mac_get_ideal_size (f);
9452
9453 err = SetEventParameter (event, kEventParamDimensions,
9454 typeQDPoint, sizeof (Point), &ideal_size);
9455 if (err == noErr)
9456 return noErr;
9457 }
9458 break;
9459
9427 case kEventWindowBoundsChanging: 9460 case kEventWindowBoundsChanging:
9428 result = CallNextEventHandler (next_handler, event); 9461 result = CallNextEventHandler (next_handler, event);
9429 if (result != eventNotHandledErr) 9462 if (result != eventNotHandledErr)
@@ -9434,7 +9467,7 @@ mac_handle_window_event (next_handler, event, data)
9434 if (err != noErr) 9467 if (err != noErr)
9435 break; 9468 break;
9436 9469
9437 size_hints = FRAME_SIZE_HINTS (mac_window_to_frame (wp)); 9470 size_hints = FRAME_SIZE_HINTS (f);
9438 if ((attributes & kWindowBoundsChangeUserResize) 9471 if ((attributes & kWindowBoundsChangeUserResize)
9439 && ((size_hints->flags & (PResizeInc | PBaseSize | PMinSize)) 9472 && ((size_hints->flags & (PResizeInc | PBaseSize | PMinSize))
9440 == (PResizeInc | PBaseSize | PMinSize))) 9473 == (PResizeInc | PBaseSize | PMinSize)))
@@ -9475,17 +9508,58 @@ mac_handle_window_event (next_handler, event, data)
9475 } 9508 }
9476 break; 9509 break;
9477 9510
9511 case kEventWindowBoundsChanged:
9512 err = GetEventParameter (event, kEventParamAttributes, typeUInt32,
9513 NULL, sizeof (UInt32), NULL, &attributes);
9514 if (err != noErr)
9515 break;
9516
9517 if (attributes & kWindowBoundsChangeSizeChanged)
9518 {
9519 Rect bounds;
9520
9521 err = GetEventParameter (event, kEventParamCurrentBounds,
9522 typeQDRectangle, NULL, sizeof (Rect),
9523 NULL, &bounds);
9524 if (err == noErr)
9525 {
9526 int width, height;
9527
9528 width = bounds.right - bounds.left;
9529 height = bounds.bottom - bounds.top;
9530 mac_handle_size_change (f, width, height);
9531 }
9532 }
9533
9534 if (attributes & kWindowBoundsChangeOriginChanged)
9535 mac_handle_origin_change (f);
9536
9537 return noErr;
9538
9478 case kEventWindowShown: 9539 case kEventWindowShown:
9479 case kEventWindowHidden: 9540 case kEventWindowHidden:
9480 case kEventWindowExpanded: 9541 case kEventWindowExpanded:
9481 case kEventWindowCollapsed: 9542 case kEventWindowCollapsed:
9482 result = CallNextEventHandler (next_handler, event); 9543 result = CallNextEventHandler (next_handler, event);
9483 9544
9484 mac_handle_visibility_change (mac_window_to_frame (wp)); 9545 mac_handle_visibility_change (f);
9485 return noErr; 9546 return noErr;
9486 9547
9487 break; 9548 break;
9488 9549
9550 case kEventWindowClose:
9551 result = CallNextEventHandler (next_handler, event);
9552 {
9553 struct input_event buf;
9554
9555 EVENT_INIT (buf);
9556 buf.kind = DELETE_WINDOW_EVENT;
9557 XSETFRAME (buf.frame_or_window, f);
9558 buf.arg = Qnil;
9559 kbd_buffer_store_event (&buf);
9560 }
9561 return noErr;
9562
9489#ifdef MAC_OSX 9563#ifdef MAC_OSX
9490 case kEventWindowToolbarSwitchMode: 9564 case kEventWindowToolbarSwitchMode:
9491 result = CallNextEventHandler (next_handler, event); 9565 result = CallNextEventHandler (next_handler, event);
@@ -9775,6 +9849,8 @@ mac_handle_text_input_event (next_handler, event, data)
9775 read_socket_inev->kind = ASCII_KEYSTROKE_EVENT; 9849 read_socket_inev->kind = ASCII_KEYSTROKE_EVENT;
9776 read_socket_inev->code = code; 9850 read_socket_inev->code = code;
9777 read_socket_inev->modifiers = 9851 read_socket_inev->modifiers =
9852 mac_to_emacs_modifiers (modifiers);
9853 read_socket_inev->modifiers |=
9778 (extra_keyboard_modifiers 9854 (extra_keyboard_modifiers
9779 & (meta_modifier | alt_modifier 9855 & (meta_modifier | alt_modifier
9780 | hyper_modifier | super_modifier)); 9856 | hyper_modifier | super_modifier));
@@ -9894,11 +9970,14 @@ install_window_handler (window)
9894#if USE_CARBON_EVENTS 9970#if USE_CARBON_EVENTS
9895 EventTypeSpec specs_window[] = 9971 EventTypeSpec specs_window[] =
9896 {{kEventClassWindow, kEventWindowUpdate}, 9972 {{kEventClassWindow, kEventWindowUpdate},
9973 {kEventClassWindow, kEventWindowGetIdealSize},
9897 {kEventClassWindow, kEventWindowBoundsChanging}, 9974 {kEventClassWindow, kEventWindowBoundsChanging},
9975 {kEventClassWindow, kEventWindowBoundsChanged},
9898 {kEventClassWindow, kEventWindowShown}, 9976 {kEventClassWindow, kEventWindowShown},
9899 {kEventClassWindow, kEventWindowHidden}, 9977 {kEventClassWindow, kEventWindowHidden},
9900 {kEventClassWindow, kEventWindowExpanded}, 9978 {kEventClassWindow, kEventWindowExpanded},
9901 {kEventClassWindow, kEventWindowCollapsed}, 9979 {kEventClassWindow, kEventWindowCollapsed},
9980 {kEventClassWindow, kEventWindowClose},
9902#ifdef MAC_OSX 9981#ifdef MAC_OSX
9903 {kEventClassWindow, kEventWindowToolbarSwitchMode}, 9982 {kEventClassWindow, kEventWindowToolbarSwitchMode},
9904#endif 9983#endif
@@ -10457,12 +10536,14 @@ XTread_socket (sd, expected, hold_quit)
10457 DragWindow (window_ptr, er.where, &qd.screenBits.bounds); 10536 DragWindow (window_ptr, er.where, &qd.screenBits.bounds);
10458#endif /* not TARGET_API_MAC_CARBON */ 10537#endif /* not TARGET_API_MAC_CARBON */
10459 /* Update the frame parameters. */ 10538 /* Update the frame parameters. */
10539#if !USE_CARBON_EVENTS
10460 { 10540 {
10461 struct frame *f = mac_window_to_frame (window_ptr); 10541 struct frame *f = mac_window_to_frame (window_ptr);
10462 10542
10463 if (f && !f->async_iconified) 10543 if (f && !f->async_iconified)
10464 x_real_positions (f, &f->left_pos, &f->top_pos); 10544 mac_handle_origin_change (f);
10465 } 10545 }
10546#endif
10466 break; 10547 break;
10467 10548
10468 case inGoAway: 10549 case inGoAway:
@@ -10561,7 +10642,7 @@ XTread_socket (sd, expected, hold_quit)
10561 else 10642 else
10562 { 10643 {
10563 /* Generate SELECT_WINDOW_EVENTs when needed. */ 10644 /* Generate SELECT_WINDOW_EVENTs when needed. */
10564 if (mouse_autoselect_window) 10645 if (!NILP (Vmouse_autoselect_window))
10565 { 10646 {
10566 Lisp_Object window; 10647 Lisp_Object window;
10567 10648
@@ -11571,6 +11652,14 @@ to 4.1, set this to nil.
11571NOTE: Not supported on Mac yet. */); 11652NOTE: Not supported on Mac yet. */);
11572 x_use_underline_position_properties = 0; 11653 x_use_underline_position_properties = 0;
11573 11654
11655 DEFVAR_BOOL ("x-underline-at-descent-line",
11656 &x_underline_at_descent_line,
11657 doc: /* *Non-nil means to draw the underline at the same place as the descent line.
11658nil means to draw the underline according to the value of the variable
11659`x-use-underline-position-properties', which is usually at the baseline
11660level. The default value is nil. */);
11661 x_underline_at_descent_line = 0;
11662
11574 DEFVAR_LISP ("x-toolkit-scroll-bars", &Vx_toolkit_scroll_bars, 11663 DEFVAR_LISP ("x-toolkit-scroll-bars", &Vx_toolkit_scroll_bars,
11575 doc: /* If not nil, Emacs uses toolkit scroll bars. */); 11664 doc: /* If not nil, Emacs uses toolkit scroll bars. */);
11576#ifdef USE_TOOLKIT_SCROLL_BARS 11665#ifdef USE_TOOLKIT_SCROLL_BARS