comparison src/macterm.c @ 66841:b633b787c04d

[USE_CG_TEXT_DRAWING] (mac_draw_string_cg): New function. (x_draw_glyph_string_foreground) [USE_CG_TEXT_DRAWING]: Use it. (XLoadQueryFont) [USE_CG_TEXT_DRAWING]: Set members cg_font and cg_glyphs in struct MacFontStruct if synthesized bold or italic is not used and font substitution never occurs for ASCII and Latin-1 characters. (XLoadQueryFont): Maximum and minimum metrics are now those among ASCII characters. (XLoadQueryFont) [!MAC_OS8 || USE_ATSUI]: Apply WebKit-style height adjustments for Courier, Helvetica, and Times.
author YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
date Sun, 13 Nov 2005 05:46:52 +0000
parents d85a089fce11
children e99c1fd37bcd 03934708f1e9
comparison
equal deleted inserted replaced
66840:8c0a6fb71ce1 66841:b633b787c04d
84 #include "window.h" 84 #include "window.h"
85 #include "keyboard.h" 85 #include "keyboard.h"
86 #include "intervals.h" 86 #include "intervals.h"
87 #include "atimer.h" 87 #include "atimer.h"
88 #include "keymap.h" 88 #include "keymap.h"
89 89
90 90
91 91
92 /* Non-nil means Emacs uses toolkit scroll bars. */ 92 /* Non-nil means Emacs uses toolkit scroll bars. */
93 93
94 Lisp_Object Vx_toolkit_scroll_bars; 94 Lisp_Object Vx_toolkit_scroll_bars;
769 Long2Fix (x), Long2Fix (port_height - y)); 769 Long2Fix (x), Long2Fix (port_height - y));
770 CGContextSynchronize (context); 770 CGContextSynchronize (context);
771 QDEndCGContext (port, &context); 771 QDEndCGContext (port, &context);
772 #if 0 772 #if 0
773 /* This doesn't work on Mac OS X 10.1. */ 773 /* This doesn't work on Mac OS X 10.1. */
774 ATSUClearLayoutControls (text_layout, 774 ATSUClearLayoutControls (text_layout,
775 sizeof (tags) / sizeof (tags[0]), 775 sizeof (tags) / sizeof (tags[0]),
776 tags); 776 tags);
777 #else 777 #else
778 ATSUSetLayoutControls (text_layout, 778 ATSUSetLayoutControls (text_layout,
779 sizeof (tags) / sizeof (tags[0]), 779 sizeof (tags) / sizeof (tags[0]),
860 XChar2b *buf; 860 XChar2b *buf;
861 int nchars; 861 int nchars;
862 { 862 {
863 mac_draw_string_common (f, gc, x, y, (char *) buf, nchars, srcCopy, 2); 863 mac_draw_string_common (f, gc, x, y, (char *) buf, nchars, srcCopy, 2);
864 } 864 }
865
866
867 #if USE_CG_TEXT_DRAWING
868 static XCharStruct *x_per_char_metric P_ ((XFontStruct *, XChar2b *));
869
870 static int
871 mac_draw_string_cg (f, gc, x, y, buf, nchars)
872 struct frame *f;
873 GC gc;
874 int x, y;
875 XChar2b *buf;
876 int nchars;
877 {
878 CGrafPtr port;
879 float port_height, gx, gy;
880 int i;
881 CGContextRef context;
882 CGGlyph *glyphs;
883 CGSize *advances;
884
885 if (NILP (Vmac_use_core_graphics) || GC_FONT (gc)->cg_font == NULL)
886 return 0;
887
888 port = GetWindowPort (FRAME_MAC_WINDOW (f));
889 port_height = FRAME_PIXEL_HEIGHT (f);
890 gx = x;
891 gy = port_height - y;
892 glyphs = (CGGlyph *)buf;
893 advances = xmalloc (sizeof (CGSize) * nchars);
894 for (i = 0; i < nchars; i++)
895 {
896 advances[i].width = x_per_char_metric (GC_FONT (gc), buf)->width;
897 advances[i].height = 0;
898 glyphs[i] = GC_FONT (gc)->cg_glyphs[buf->byte2];
899 buf++;
900 }
901
902 QDBeginCGContext (port, &context);
903 if (gc->n_clip_rects)
904 {
905 CGContextTranslateCTM (context, 0, port_height);
906 CGContextScaleCTM (context, 1, -1);
907 CGContextClipToRects (context, gc->clip_rects, gc->n_clip_rects);
908 CGContextScaleCTM (context, 1, -1);
909 CGContextTranslateCTM (context, 0, -port_height);
910 }
911 CGContextSetRGBFillColor (context,
912 RED_FROM_ULONG (gc->xgcv.foreground) / 255.0,
913 GREEN_FROM_ULONG (gc->xgcv.foreground) / 255.0,
914 BLUE_FROM_ULONG (gc->xgcv.foreground) / 255.0,
915 1.0);
916 CGContextSetFont (context, GC_FONT (gc)->cg_font);
917 CGContextSetFontSize (context, GC_FONT (gc)->mac_fontsize);
918 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030
919 CGContextSetTextPosition (context, gx, gy);
920 CGContextShowGlyphsWithAdvances (context, glyphs, advances, nchars);
921 #else
922 for (i = 0; i < nchars; i++)
923 {
924 CGContextShowGlyphsAtPoint (context, gx, gy, glyphs + i, 1);
925 gx += advances[i].width;
926 }
927 #endif
928 CGContextSynchronize (context);
929 QDEndCGContext (port, &context);
930
931 xfree (advances);
932
933 return 1;
934 }
935 #endif
865 936
866 937
867 /* Mac replacement for XCopyArea: dest must be window. */ 938 /* Mac replacement for XCopyArea: dest must be window. */
868 939
869 static void 940 static void
2256 if (s->two_byte_p 2327 if (s->two_byte_p
2257 #if USE_ATSUI 2328 #if USE_ATSUI
2258 || GC_FONT (s->gc)->mac_style 2329 || GC_FONT (s->gc)->mac_style
2259 #endif 2330 #endif
2260 ) 2331 )
2332 #if USE_CG_TEXT_DRAWING
2333 if (!s->two_byte_p
2334 && mac_draw_string_cg (s->f, s->gc, x, s->ybase - boff,
2335 s->char2b, s->nchars))
2336 ;
2337 else
2338 #endif
2261 mac_draw_string_16 (s->f, s->gc, x, s->ybase - boff, 2339 mac_draw_string_16 (s->f, s->gc, x, s->ybase - boff,
2262 s->char2b, s->nchars); 2340 s->char2b, s->nchars);
2263 else 2341 else
2264 mac_draw_string (s->f, s->gc, x, s->ybase - boff, 2342 mac_draw_string (s->f, s->gc, x, s->ybase - boff,
2265 char1b, s->nchars); 2343 char1b, s->nchars);
7279 char *name; 7357 char *name;
7280 Str255 family; 7358 Str255 family;
7281 Str31 charset; 7359 Str31 charset;
7282 SInt16 fontnum; 7360 SInt16 fontnum;
7283 #if USE_ATSUI 7361 #if USE_ATSUI
7362 static ATSUFontID font_id;
7284 ATSUStyle mac_style = NULL; 7363 ATSUStyle mac_style = NULL;
7285 #endif 7364 #endif
7286 Style fontface; 7365 Style fontface;
7287 #if TARGET_API_MAC_CARBON 7366 #if TARGET_API_MAC_CARBON
7288 TextEncoding encoding; 7367 TextEncoding encoding;
7313 OSErr err; 7392 OSErr err;
7314 ATSUAttributeTag tags[] = {kATSUFontTag, kATSUSizeTag, 7393 ATSUAttributeTag tags[] = {kATSUFontTag, kATSUSizeTag,
7315 kATSUQDBoldfaceTag, kATSUQDItalicTag}; 7394 kATSUQDBoldfaceTag, kATSUQDItalicTag};
7316 ByteCount sizes[] = {sizeof (ATSUFontID), sizeof (Fixed), 7395 ByteCount sizes[] = {sizeof (ATSUFontID), sizeof (Fixed),
7317 sizeof (Boolean), sizeof (Boolean)}; 7396 sizeof (Boolean), sizeof (Boolean)};
7318 static ATSUFontID font_id;
7319 static Fixed size_fixed; 7397 static Fixed size_fixed;
7320 static Boolean bold_p, italic_p; 7398 static Boolean bold_p, italic_p;
7321 ATSUAttributeValuePtr values[] = {&font_id, &size_fixed, 7399 ATSUAttributeValuePtr values[] = {&font_id, &size_fixed,
7322 &bold_p, &italic_p}; 7400 &bold_p, &italic_p};
7323 ATSUFontFeatureType types[] = {kAllTypographicFeaturesType}; 7401 ATSUFontFeatureType types[] = {kAllTypographicFeaturesType};
7367 font->mac_fontsize = size; 7445 font->mac_fontsize = size;
7368 font->mac_fontface = fontface; 7446 font->mac_fontface = fontface;
7369 font->mac_scriptcode = scriptcode; 7447 font->mac_scriptcode = scriptcode;
7370 #if USE_ATSUI 7448 #if USE_ATSUI
7371 font->mac_style = mac_style; 7449 font->mac_style = mac_style;
7450 #if USE_CG_TEXT_DRAWING
7451 font->cg_font = NULL;
7452 font->cg_glyphs = NULL;
7453 #endif
7372 #endif 7454 #endif
7373 7455
7374 /* Apple Japanese (SJIS) font is listed as both 7456 /* Apple Japanese (SJIS) font is listed as both
7375 "*-jisx0208.1983-sjis" (Japanese script) and "*-jisx0201.1976-0" 7457 "*-jisx0208.1983-sjis" (Japanese script) and "*-jisx0201.1976-0"
7376 (Roman script) in init_font_name_table (). The latter should be 7458 (Roman script) in init_font_name_table (). The latter should be
7395 { 7477 {
7396 mac_unload_font (&one_mac_display_info, font); 7478 mac_unload_font (&one_mac_display_info, font);
7397 return NULL; 7479 return NULL;
7398 } 7480 }
7399 bzero (font->per_char, sizeof (XCharStruct) * 0x10000); 7481 bzero (font->per_char, sizeof (XCharStruct) * 0x10000);
7482
7483 #if USE_CG_TEXT_DRAWING
7484 {
7485 FMFontFamily font_family;
7486 FMFontStyle style;
7487 ATSFontRef ats_font;
7488
7489 err = FMGetFontFamilyInstanceFromFont (font_id, &font_family, &style);
7490 if (err == noErr)
7491 err = FMGetFontFromFontFamilyInstance (font_family, fontface,
7492 &font_id, &style);
7493 /* Use CG text drawing if italic/bold is not synthesized. */
7494 if (err == noErr && style == fontface)
7495 {
7496 ats_font = FMGetATSFontRefFromFont (font_id);
7497 font->cg_font = CGFontCreateWithPlatformFont (&ats_font);
7498 }
7499 }
7500
7501 if (font->cg_font)
7502 font->cg_glyphs = xmalloc (sizeof (CGGlyph) * 0x100);
7503 if (font->cg_glyphs)
7504 bzero (font->cg_glyphs, sizeof (CGGlyph) * 0x100);
7505 #endif
7400 7506
7401 err = atsu_get_text_layout_with_text_ptr (&c, 1, 7507 err = atsu_get_text_layout_with_text_ptr (&c, 1,
7402 font->mac_style, 7508 font->mac_style,
7403 &text_layout); 7509 &text_layout);
7404 if (err != noErr) 7510 if (err != noErr)
7405 { 7511 {
7406 mac_unload_font (&one_mac_display_info, font); 7512 mac_unload_font (&one_mac_display_info, font);
7407 return NULL; 7513 return NULL;
7408 } 7514 }
7409 7515
7410 for (c = 0x20; c <= 0x7e; c++) 7516 for (c = 0x20; c <= 0xff; c++)
7411 { 7517 {
7518 if (c == 0xad)
7519 /* Soft hyphen is not supported in ATSUI. */
7520 continue;
7521 else if (c == 0x7f)
7522 {
7523 STORE_XCHARSTRUCT (font->min_bounds, min_width, min_bounds);
7524 STORE_XCHARSTRUCT (font->max_bounds, max_width, max_bounds);
7525 c = 0x9f;
7526 continue;
7527 }
7528
7412 err = ATSUClearLayoutCache (text_layout, kATSUFromTextBeginning); 7529 err = ATSUClearLayoutCache (text_layout, kATSUFromTextBeginning);
7413 if (err == noErr) 7530 if (err == noErr)
7414 err = ATSUMeasureTextImage (text_layout, 7531 err = ATSUMeasureTextImage (text_layout,
7415 kATSUFromTextBeginning, kATSUToTextEnd, 7532 kATSUFromTextBeginning, kATSUToTextEnd,
7416 0, 0, &char_bounds); 7533 0, 0, &char_bounds);
7455 min (min_bounds.bottom, char_bounds.bottom)); 7572 min (min_bounds.bottom, char_bounds.bottom));
7456 UnionRect (&max_bounds, &char_bounds, &max_bounds); 7573 UnionRect (&max_bounds, &char_bounds, &max_bounds);
7457 } 7574 }
7458 } 7575 }
7459 } 7576 }
7577 #if USE_CG_TEXT_DRAWING
7578 if (err == noErr && char_width > 0 && font->cg_font)
7579 {
7580 ATSUGlyphInfoArray glyph_info_array;
7581 ByteCount count = sizeof (ATSUGlyphInfoArray);
7582
7583 err = ATSUMatchFontsToText (text_layout, kATSUFromTextBeginning,
7584 kATSUToTextEnd, NULL, NULL, NULL);
7585 if (err == noErr)
7586 err = ATSUGetGlyphInfo (text_layout, kATSUFromTextBeginning,
7587 kATSUToTextEnd, &count,
7588 &glyph_info_array);
7589 if (err == noErr)
7590 font->cg_glyphs[c] = glyph_info_array.glyphs[0].glyphID;
7591 else
7592 {
7593 /* Don't use CG text drawing if font substitution
7594 occurs in ASCII or Latin-1 characters. */
7595 CGFontRelease (font->cg_font);
7596 font->cg_font = NULL;
7597 xfree (font->cg_glyphs);
7598 font->cg_glyphs = NULL;
7599 }
7600 }
7601 #endif
7460 } 7602 }
7461 STORE_XCHARSTRUCT (font->min_bounds, min_width, min_bounds);
7462 STORE_XCHARSTRUCT (font->max_bounds, max_width, max_bounds);
7463 7603
7464 font->min_byte1 = 0; 7604 font->min_byte1 = 0;
7465 font->max_byte1 = 0xff; 7605 font->max_byte1 = 0xff;
7466 font->min_char_or_byte2 = 0; 7606 font->min_char_or_byte2 = 0;
7467 font->max_char_or_byte2 = 0xff; 7607 font->max_char_or_byte2 = 0xff;
7570 min_width = max_width = char_width; 7710 min_width = max_width = char_width;
7571 SetRect (&min_bounds, -32767, -32767, 32767, 32767); 7711 SetRect (&min_bounds, -32767, -32767, 32767, 32767);
7572 SetRect (&max_bounds, 0, 0, 0, 0); 7712 SetRect (&max_bounds, 0, 0, 0, 0);
7573 for (c = 0x20; c <= 0xff; c++) 7713 for (c = 0x20; c <= 0xff; c++)
7574 { 7714 {
7715 if (c == 0x7f)
7716 {
7717 STORE_XCHARSTRUCT (font->min_bounds, min_width, min_bounds);
7718 STORE_XCHARSTRUCT (font->max_bounds, max_width, max_bounds);
7719 continue;
7720 }
7721
7575 ch = c; 7722 ch = c;
7576 char_width = CharWidth (ch); 7723 char_width = CharWidth (ch);
7577 QDTextBounds (1, &ch, &char_bounds); 7724 QDTextBounds (1, &ch, &char_bounds);
7578 STORE_XCHARSTRUCT (font->per_char[c - 0x20], 7725 STORE_XCHARSTRUCT (font->per_char[c - 0x20],
7579 char_width, char_bounds); 7726 char_width, char_bounds);
7592 min (min_bounds.right, char_bounds.right), 7739 min (min_bounds.right, char_bounds.right),
7593 min (min_bounds.bottom, char_bounds.bottom)); 7740 min (min_bounds.bottom, char_bounds.bottom));
7594 UnionRect (&max_bounds, &char_bounds, &max_bounds); 7741 UnionRect (&max_bounds, &char_bounds, &max_bounds);
7595 } 7742 }
7596 } 7743 }
7597 STORE_XCHARSTRUCT (font->min_bounds, min_width, min_bounds);
7598 STORE_XCHARSTRUCT (font->max_bounds, max_width, max_bounds);
7599 if (min_width == max_width 7744 if (min_width == max_width
7600 && max_bounds.left >= 0 && max_bounds.right <= max_width) 7745 && max_bounds.left >= 0 && max_bounds.right <= max_width)
7601 { 7746 {
7602 /* Fixed width and no overhangs. */ 7747 /* Fixed width and no overhangs. */
7603 xfree (font->per_char); 7748 xfree (font->per_char);
7609 TextFont (old_fontnum); 7754 TextFont (old_fontnum);
7610 TextSize (old_fontsize); 7755 TextSize (old_fontsize);
7611 TextFace (old_fontface); 7756 TextFace (old_fontface);
7612 } 7757 }
7613 7758
7759 #if !defined (MAC_OS8) || USE_ATSUI
7760 /* AppKit and WebKit do some adjustment to the heights of Courier,
7761 Helvetica, and Times. This only works on the environments where
7762 the XDrawImageString counterpart is never used. */
7763 if (strcmp (family, "courier") == 0 || strcmp (family, "helvetica") == 0
7764 || strcmp (family, "times") == 0)
7765 font->ascent += (font->ascent + font->descent) * .15 + 0.5;
7766 #endif
7767
7614 return font; 7768 return font;
7615 } 7769 }
7616 7770
7617 7771
7618 void 7772 void
7624 if (font->per_char) 7778 if (font->per_char)
7625 xfree (font->per_char); 7779 xfree (font->per_char);
7626 #if USE_ATSUI 7780 #if USE_ATSUI
7627 if (font->mac_style) 7781 if (font->mac_style)
7628 ATSUDisposeStyle (font->mac_style); 7782 ATSUDisposeStyle (font->mac_style);
7783 #if USE_CG_TEXT_DRAWING
7784 if (font->cg_font)
7785 CGFontRelease (font->cg_font);
7786 if (font->cg_glyphs)
7787 xfree (font->cg_glyphs);
7788 #endif
7629 #endif 7789 #endif
7630 xfree (font); 7790 xfree (font);
7631 } 7791 }
7632 7792
7633 7793
7998 #endif 8158 #endif
7999 { 8159 {
8000 unsigned int result = 0; 8160 unsigned int result = 0;
8001 if (mods & shiftKey) 8161 if (mods & shiftKey)
8002 result |= shift_modifier; 8162 result |= shift_modifier;
8003 8163
8004 8164
8005 8165
8006 /* Deactivated to simplify configuration: 8166 /* Deactivated to simplify configuration:
8007 if Vmac_option_modifier is non-NIL, we fully process the Option 8167 if Vmac_option_modifier is non-NIL, we fully process the Option
8008 key. Otherwise, we only process it if an additional Ctrl or Command 8168 key. Otherwise, we only process it if an additional Ctrl or Command
8009 is pressed. That way the system may convert the character to a 8169 is pressed. That way the system may convert the character to a
8010 composed one. 8170 composed one.
8011 if ((mods & optionKey) && 8171 if ((mods & optionKey) &&
8012 (( !NILP(Vmac_option_modifier) || 8172 (( !NILP(Vmac_option_modifier) ||
8013 ((mods & cmdKey) || (mods & controlKey))))) */ 8173 ((mods & cmdKey) || (mods & controlKey))))) */
8014 8174
8015 if (!NILP (Vmac_option_modifier) && (mods & optionKey)) { 8175 if (!NILP (Vmac_option_modifier) && (mods & optionKey)) {
8016 Lisp_Object val = Fget(Vmac_option_modifier, Qmodifier_value); 8176 Lisp_Object val = Fget(Vmac_option_modifier, Qmodifier_value);
8017 if (INTEGERP(val)) 8177 if (INTEGERP(val))
8019 } 8179 }
8020 if (!NILP (Vmac_command_modifier) && (mods & cmdKey)) { 8180 if (!NILP (Vmac_command_modifier) && (mods & cmdKey)) {
8021 Lisp_Object val = Fget(Vmac_command_modifier, Qmodifier_value); 8181 Lisp_Object val = Fget(Vmac_command_modifier, Qmodifier_value);
8022 if (INTEGERP(val)) 8182 if (INTEGERP(val))
8023 result |= XUINT(val); 8183 result |= XUINT(val);
8024 } 8184 }
8025 if (!NILP (Vmac_control_modifier) && (mods & controlKey)) { 8185 if (!NILP (Vmac_control_modifier) && (mods & controlKey)) {
8026 Lisp_Object val = Fget(Vmac_control_modifier, Qmodifier_value); 8186 Lisp_Object val = Fget(Vmac_control_modifier, Qmodifier_value);
8027 if (INTEGERP(val)) 8187 if (INTEGERP(val))
8028 result |= XUINT(val); 8188 result |= XUINT(val);
8029 } 8189 }
8030 8190
8031 #ifdef MAC_OSX 8191 #ifdef MAC_OSX
8032 if (!NILP (Vmac_function_modifier) && (mods & kEventKeyModifierFnMask)) { 8192 if (!NILP (Vmac_function_modifier) && (mods & kEventKeyModifierFnMask)) {
8033 Lisp_Object val = Fget(Vmac_function_modifier, Qmodifier_value); 8193 Lisp_Object val = Fget(Vmac_function_modifier, Qmodifier_value);
8034 if (INTEGERP(val)) 8194 if (INTEGERP(val))
8035 result |= XUINT(val); 8195 result |= XUINT(val);
8036 } 8196 }
8037 #endif 8197 #endif
8038 8198
8039 return result; 8199 return result;
8040 } 8200 }
8041 8201
8042 static int 8202 static int
8043 mac_get_emulated_btn ( UInt32 modifiers ) 8203 mac_get_emulated_btn ( UInt32 modifiers )
9405 /*0x78*/ 0xbf /*f2*/, 0x56 /*pgdown*/, 0xbe /*f1*/, 0x51 /*left*/, 9565 /*0x78*/ 0xbf /*f2*/, 0x56 /*pgdown*/, 0xbe /*f1*/, 0x51 /*left*/,
9406 /*0x7C*/ 0x53 /*right*/, 0x54 /*down*/, 0x52 /*up*/, 0 9566 /*0x7C*/ 0x53 /*right*/, 0x54 /*down*/, 0x52 /*up*/, 0
9407 }; 9567 };
9408 9568
9409 9569
9410 static int 9570 static int
9411 keycode_to_xkeysym (int keyCode, int *xKeySym) 9571 keycode_to_xkeysym (int keyCode, int *xKeySym)
9412 { 9572 {
9413 *xKeySym = keycode_to_xkeysym_table [keyCode & 0x7f]; 9573 *xKeySym = keycode_to_xkeysym_table [keyCode & 0x7f];
9414 return *xKeySym != 0; 9574 return *xKeySym != 0;
9415 } 9575 }
9446 }; 9606 };
9447 static int 9607 static int
9448 convert_fn_keycode (EventRef eventRef, int keyCode, int *newCode) 9608 convert_fn_keycode (EventRef eventRef, int keyCode, int *newCode)
9449 { 9609 {
9450 #ifdef MAC_OSX 9610 #ifdef MAC_OSX
9451 /* Use the special map to translate keys when function modifier is 9611 /* Use the special map to translate keys when function modifier is
9452 to be caught. KeyTranslate can't be used in that case. 9612 to be caught. KeyTranslate can't be used in that case.
9453 We can't detect the function key using the input_event.modifiers, 9613 We can't detect the function key using the input_event.modifiers,
9454 because this uses the high word of an UInt32. Therefore, 9614 because this uses the high word of an UInt32. Therefore,
9455 we'll just read it out of the original eventRef. 9615 we'll just read it out of the original eventRef.
9456 */ 9616 */
9462 The above table always translates to lower characters. We need to use 9622 The above table always translates to lower characters. We need to use
9463 the KCHR keyboard resource (KeyTranslate() ) to map k->K and 8->*. 9623 the KCHR keyboard resource (KeyTranslate() ) to map k->K and 8->*.
9464 9624
9465 - The table is meant for English language keyboards, and it will work 9625 - The table is meant for English language keyboards, and it will work
9466 for many others with the exception of key combinations like Fn-ö on 9626 for many others with the exception of key combinations like Fn-ö on
9467 a German keyboard, which is currently mapped to Fn-;. 9627 a German keyboard, which is currently mapped to Fn-;.
9468 How to solve this without keeping separate tables for all keyboards 9628 How to solve this without keeping separate tables for all keyboards
9469 around? KeyTranslate isn't of much help here, as it only takes a 16-bit 9629 around? KeyTranslate isn't of much help here, as it only takes a 16-bit
9470 value for keycode with the modifiers in he high byte, i.e. no room for the 9630 value for keycode with the modifiers in he high byte, i.e. no room for the
9471 Fn modifier. That's why we need the table. 9631 Fn modifier. That's why we need the table.
9472 9632
9473 */ 9633 */
9474 9634
9475 UInt32 mods = 0; 9635 UInt32 mods = 0;
9476 if (!NILP(Vmac_function_modifier)) 9636 if (!NILP(Vmac_function_modifier))
9477 { 9637 {
9478 GetEventParameter (eventRef, kEventParamKeyModifiers, typeUInt32, NULL, 9638 GetEventParameter (eventRef, kEventParamKeyModifiers, typeUInt32, NULL,
9479 sizeof (UInt32), NULL, &mods); 9639 sizeof (UInt32), NULL, &mods);
9480 if (mods & kEventKeyModifierFnMask) 9640 if (mods & kEventKeyModifierFnMask)
9481 { *newCode = fn_keycode_to_xkeysym_table [keyCode & 0x7f]; 9641 { *newCode = fn_keycode_to_xkeysym_table [keyCode & 0x7f];
9482 9642
9483 return (*newCode != 0); 9643 return (*newCode != 0);
9484 } 9644 }
9485 } 9645 }
9486 #endif 9646 #endif
9487 return false; 9647 return false;
9488 } 9648 }
9489 9649
9490 static int 9650 static int
9491 backtranslate_modified_keycode(int mods, int keycode, int def) 9651 backtranslate_modified_keycode(int mods, int keycode, int def)
9492 { 9652 {
9493 if (mods & 9653 if (mods &
9494 (controlKey | 9654 (controlKey |
9495 (NILP (Vmac_option_modifier) ? 0 : optionKey) | 9655 (NILP (Vmac_option_modifier) ? 0 : optionKey) |
9496 cmdKey)) 9656 cmdKey))
9497 { 9657 {
9498 /* This code comes from Keyboard Resource, 9658 /* This code comes from Keyboard Resource,
9499 Appendix C of IM - Text. This is necessary 9659 Appendix C of IM - Text. This is necessary
9500 since shift is ignored in KCHR table 9660 since shift is ignored in KCHR table
9502 It also does not translate correctly 9662 It also does not translate correctly
9503 control-shift chars like C-% so mask off shift 9663 control-shift chars like C-% so mask off shift
9504 here also. 9664 here also.
9505 9665
9506 Not done for combinations with the option key (alt) 9666 Not done for combinations with the option key (alt)
9507 unless it is to be caught by Emacs: this is 9667 unless it is to be caught by Emacs: this is
9508 to preserve key combinations translated by the OS 9668 to preserve key combinations translated by the OS
9509 such as Alt-3. 9669 such as Alt-3.
9510 */ 9670 */
9511 /* mask off option and command */ 9671 /* mask off option and command */
9512 int new_modifiers = mods & 0xe600; 9672 int new_modifiers = mods & 0xe600;
9513 /* set high byte of keycode to modifier high byte*/ 9673 /* set high byte of keycode to modifier high byte*/
9514 int new_keycode = keycode | new_modifiers; 9674 int new_keycode = keycode | new_modifiers;
9515 Ptr kchr_ptr = (Ptr) GetScriptManagerVariable (smKCHRCache); 9675 Ptr kchr_ptr = (Ptr) GetScriptManagerVariable (smKCHRCache);
9516 unsigned long some_state = 0; 9676 unsigned long some_state = 0;
9517 return (int) KeyTranslate (kchr_ptr, new_keycode, 9677 return (int) KeyTranslate (kchr_ptr, new_keycode,
10124 #if USE_CARBON_EVENTS 10284 #if USE_CARBON_EVENTS
10125 if (convert_fn_keycode (eventRef, keycode, &xkeysym)) 10285 if (convert_fn_keycode (eventRef, keycode, &xkeysym))
10126 { 10286 {
10127 inev.code = xkeysym; 10287 inev.code = xkeysym;
10128 /* this doesn't work - tried to add shift modifiers */ 10288 /* this doesn't work - tried to add shift modifiers */
10129 inev.code = 10289 inev.code =
10130 backtranslate_modified_keycode(er.modifiers & (~0x2200), 10290 backtranslate_modified_keycode(er.modifiers & (~0x2200),
10131 xkeysym | 0x80, xkeysym); 10291 xkeysym | 0x80, xkeysym);
10132 inev.kind = ASCII_KEYSTROKE_EVENT; 10292 inev.kind = ASCII_KEYSTROKE_EVENT;
10133 } 10293 }
10134 else 10294 else
10135 #endif 10295 #endif
10136 if (keycode_to_xkeysym (keycode, &xkeysym)) 10296 if (keycode_to_xkeysym (keycode, &xkeysym))
10137 { 10297 {
10138 inev.code = 0xff00 | xkeysym; 10298 inev.code = 0xff00 | xkeysym;
10139 inev.kind = NON_ASCII_KEYSTROKE_EVENT; 10299 inev.kind = NON_ASCII_KEYSTROKE_EVENT;
10140 } 10300 }
10141 else 10301 else
10142 { 10302 {
10143 10303
10144 inev.code = 10304 inev.code =
10145 backtranslate_modified_keycode(er.modifiers, keycode, 10305 backtranslate_modified_keycode(er.modifiers, keycode,
10146 er.message & charCodeMask); 10306 er.message & charCodeMask);
10147 inev.kind = ASCII_KEYSTROKE_EVENT; 10307 inev.kind = ASCII_KEYSTROKE_EVENT;
10148 10308
10149 } 10309 }
10150 } 10310 }
10151 10311
10152 #if USE_CARBON_EVENTS 10312 #if USE_CARBON_EVENTS
10153 inev.modifiers = mac_event_to_emacs_modifiers (eventRef); 10313 inev.modifiers = mac_event_to_emacs_modifiers (eventRef);
10585 UInt32 qc_modifiers = ctrl_modifier; 10745 UInt32 qc_modifiers = ctrl_modifier;
10586 10746
10587 /* Map modifiers */ 10747 /* Map modifiers */
10588 mac_quit_char_modifiers = 0; 10748 mac_quit_char_modifiers = 0;
10589 if (qc_modifiers & ctrl_modifier) mac_quit_char_modifiers |= controlKey; 10749 if (qc_modifiers & ctrl_modifier) mac_quit_char_modifiers |= controlKey;
10590 if (qc_modifiers & shift_modifier) mac_quit_char_modifiers |= shiftKey; 10750 if (qc_modifiers & shift_modifier) mac_quit_char_modifiers |= shiftKey;
10591 if (qc_modifiers & alt_modifier) mac_quit_char_modifiers |= optionKey; 10751 if (qc_modifiers & alt_modifier) mac_quit_char_modifiers |= optionKey;
10592 } 10752 }
10593 10753
10594 static void 10754 static void
10595 init_quit_char_handler () 10755 init_quit_char_handler ()
10746 10906
10747 Qmodifier_value = intern ("modifier-value"); 10907 Qmodifier_value = intern ("modifier-value");
10748 Qctrl = intern ("ctrl"); 10908 Qctrl = intern ("ctrl");
10749 Fput (Qctrl, Qmodifier_value, make_number (ctrl_modifier)); 10909 Fput (Qctrl, Qmodifier_value, make_number (ctrl_modifier));
10750 Qmeta = intern ("meta"); 10910 Qmeta = intern ("meta");
10751 Fput (Qmeta, Qmodifier_value, make_number (meta_modifier)); 10911 Fput (Qmeta, Qmodifier_value, make_number (meta_modifier));
10752 Qalt = intern ("alt"); 10912 Qalt = intern ("alt");
10753 Fput (Qalt, Qmodifier_value, make_number (alt_modifier)); 10913 Fput (Qalt, Qmodifier_value, make_number (alt_modifier));
10754 Qhyper = intern ("hyper"); 10914 Qhyper = intern ("hyper");
10755 Fput (Qhyper, Qmodifier_value, make_number (hyper_modifier)); 10915 Fput (Qhyper, Qmodifier_value, make_number (hyper_modifier));
10756 Qsuper = intern ("super"); 10916 Qsuper = intern ("super");
10798 Vx_toolkit_scroll_bars = Qnil; 10958 Vx_toolkit_scroll_bars = Qnil;
10799 #endif 10959 #endif
10800 10960
10801 staticpro (&last_mouse_motion_frame); 10961 staticpro (&last_mouse_motion_frame);
10802 last_mouse_motion_frame = Qnil; 10962 last_mouse_motion_frame = Qnil;
10803 10963
10804 10964
10805 10965
10806 /* Variables to configure modifier key assignment. */ 10966 /* Variables to configure modifier key assignment. */
10807 10967
10808 DEFVAR_LISP ("mac-control-modifier", &Vmac_control_modifier, 10968 DEFVAR_LISP ("mac-control-modifier", &Vmac_control_modifier,
10809 doc: /* Modifier key assumed when the Mac control key is pressed. 10969 doc: /* Modifier key assumed when the Mac control key is pressed.
10810 The value can be `alt', `ctrl', `hyper', or `super' for the respective 10970 The value can be `alt', `ctrl', `hyper', or `super' for the respective
10811 modifier. The default is `ctrl'. */); 10971 modifier. The default is `ctrl'. */);
10812 Vmac_control_modifier = Qctrl; 10972 Vmac_control_modifier = Qctrl;
10813 10973
10814 DEFVAR_LISP ("mac-option-modifier", &Vmac_option_modifier, 10974 DEFVAR_LISP ("mac-option-modifier", &Vmac_option_modifier,
10815 doc: /* Modifier key assumed when the Mac alt/option key is pressed. 10975 doc: /* Modifier key assumed when the Mac alt/option key is pressed.
10816 The value can be `alt', `ctrl', `hyper', or `super' for the respective 10976 The value can be `alt', `ctrl', `hyper', or `super' for the respective
10817 modifier. If the value is nil then the key will act as the normal 10977 modifier. If the value is nil then the key will act as the normal
10818 Mac control modifier, and the option key can be used to compose 10978 Mac control modifier, and the option key can be used to compose
10819 characters depending on the chosen Mac keyboard setting. */); 10979 characters depending on the chosen Mac keyboard setting. */);
10820 Vmac_option_modifier = Qnil; 10980 Vmac_option_modifier = Qnil;
10821 10981
10822 DEFVAR_LISP ("mac-command-modifier", &Vmac_command_modifier, 10982 DEFVAR_LISP ("mac-command-modifier", &Vmac_command_modifier,
10823 doc: /* Modifier key assumed when the Mac command key is pressed. 10983 doc: /* Modifier key assumed when the Mac command key is pressed.
10824 The value can be `alt', `ctrl', `hyper', or `super' for the respective 10984 The value can be `alt', `ctrl', `hyper', or `super' for the respective
10825 modifier. The default is `meta'. */); 10985 modifier. The default is `meta'. */);
10826 Vmac_command_modifier = Qmeta; 10986 Vmac_command_modifier = Qmeta;
10827 10987
10828 DEFVAR_LISP ("mac-function-modifier", &Vmac_function_modifier, 10988 DEFVAR_LISP ("mac-function-modifier", &Vmac_function_modifier,
10829 doc: /* Modifier key assumed when the Mac function key is pressed. 10989 doc: /* Modifier key assumed when the Mac function key is pressed.
10830 The value can be `alt', `ctrl', `hyper', or `super' for the respective 10990 The value can be `alt', `ctrl', `hyper', or `super' for the respective
10831 modifier. Note that remapping the function key may lead to unexpected 10991 modifier. Note that remapping the function key may lead to unexpected
10832 results for some keys on non-US/GB keyboards. */); 10992 results for some keys on non-US/GB keyboards. */);
10833 Vmac_function_modifier = Qnil; 10993 Vmac_function_modifier = Qnil;
10834 10994