diff options
| author | Jan Djärv | 2005-04-01 18:42:19 +0000 |
|---|---|---|
| committer | Jan Djärv | 2005-04-01 18:42:19 +0000 |
| commit | 2015c054d972c75c0a579265c97c595887fa199b (patch) | |
| tree | 4487d30a220f6621e3ad491b9dd13d10bf6f16a6 | |
| parent | 1d88af0416848585bd4eb22bb6cadb700615f04d (diff) | |
| download | emacs-2015c054d972c75c0a579265c97c595887fa199b.tar.gz emacs-2015c054d972c75c0a579265c97c595887fa199b.zip | |
* xlwmenu.c (string_width):
(MENU_FONT_HEIGHT, MENU_FONT_ASCENT): Ditto.
(display_menu_item, make_drawing_gcs, XlwMenuInitialize)
(XlwMenuSetValues): Use font if fontSet is NULL, use only
font for !HAVE_X_I18N.
(xlwMenuResources): Add fontSet resource.
| -rw-r--r-- | lwlib/xlwmenu.c | 132 |
1 files changed, 58 insertions, 74 deletions
diff --git a/lwlib/xlwmenu.c b/lwlib/xlwmenu.c index 77b61d32e21..3fab2e80dbe 100644 --- a/lwlib/xlwmenu.c +++ b/lwlib/xlwmenu.c | |||
| @@ -131,20 +131,16 @@ xlwMenuTranslations [] = | |||
| 131 | 131 | ||
| 132 | /* FIXME: F10 should enter the menu, the first one in the menu-bar. */ | 132 | /* FIXME: F10 should enter the menu, the first one in the menu-bar. */ |
| 133 | 133 | ||
| 134 | /* FIXME: HAVE_X_I18N does not work yet. */ | ||
| 135 | #undef HAVE_X_I18N | ||
| 136 | |||
| 137 | #define offset(field) XtOffset(XlwMenuWidget, field) | 134 | #define offset(field) XtOffset(XlwMenuWidget, field) |
| 138 | static XtResource | 135 | static XtResource |
| 139 | xlwMenuResources[] = | 136 | xlwMenuResources[] = |
| 140 | { | 137 | { |
| 141 | #ifdef HAVE_X_I18N | 138 | #ifdef HAVE_X_I18N |
| 142 | {XtNfont, XtCFont, XtRFontSet, sizeof(XFontSet), | 139 | {XtNfontSet, XtCFontSet, XtRFontSet, sizeof(XFontSet), |
| 143 | offset(menu.font), XtRString, "XtDefaultFontSet"}, | 140 | offset(menu.fontSet), XtRFontSet, NULL}, |
| 144 | #else | 141 | #endif |
| 145 | {XtNfont, XtCFont, XtRFontStruct, sizeof(XFontStruct *), | 142 | {XtNfont, XtCFont, XtRFontStruct, sizeof(XFontStruct *), |
| 146 | offset(menu.font), XtRString, "XtDefaultFont"}, | 143 | offset(menu.font), XtRString, "XtDefaultFont"}, |
| 147 | #endif | ||
| 148 | {XtNforeground, XtCForeground, XtRPixel, sizeof(Pixel), | 144 | {XtNforeground, XtCForeground, XtRPixel, sizeof(Pixel), |
| 149 | offset(menu.foreground), XtRString, "XtDefaultForeground"}, | 145 | offset(menu.foreground), XtRString, "XtDefaultForeground"}, |
| 150 | {XtNdisabledForeground, XtCDisabledForeground, XtRPixel, sizeof(Pixel), | 146 | {XtNdisabledForeground, XtCDisabledForeground, XtRPixel, sizeof(Pixel), |
| @@ -361,24 +357,31 @@ string_width (mw, s) | |||
| 361 | XlwMenuWidget mw; | 357 | XlwMenuWidget mw; |
| 362 | char *s; | 358 | char *s; |
| 363 | { | 359 | { |
| 364 | #ifdef HAVE_X_I18N | ||
| 365 | XRectangle ink, logical; | ||
| 366 | XmbTextExtents (mw->menu.font, s, strlen (s), &ink, &logical); | ||
| 367 | return logical.width; | ||
| 368 | #else | ||
| 369 | XCharStruct xcs; | 360 | XCharStruct xcs; |
| 370 | int drop; | 361 | int drop; |
| 362 | #ifdef HAVE_X_I18N | ||
| 363 | XRectangle ink, logical; | ||
| 364 | if (mw->menu.fontSet) | ||
| 365 | { | ||
| 366 | XmbTextExtents (mw->menu.fontSet, s, strlen (s), &ink, &logical); | ||
| 367 | return logical.width; | ||
| 368 | } | ||
| 369 | #endif | ||
| 371 | 370 | ||
| 372 | XTextExtents (mw->menu.font, s, strlen (s), &drop, &drop, &drop, &xcs); | 371 | XTextExtents (mw->menu.font, s, strlen (s), &drop, &drop, &drop, &xcs); |
| 373 | return xcs.width; | 372 | return xcs.width; |
| 374 | #endif | 373 | |
| 375 | } | 374 | } |
| 376 | 375 | ||
| 377 | #ifdef HAVE_X_I18N | 376 | #ifdef HAVE_X_I18N |
| 378 | #define MENU_FONT_HEIGHT(mw) \ | 377 | #define MENU_FONT_HEIGHT(mw) \ |
| 379 | ((mw)->menu.font_extents->max_logical_extent.height) | 378 | ((mw)->menu.fontSet != NULL \ |
| 379 | ? (mw)->menu.font_extents->max_logical_extent.height \ | ||
| 380 | : (mw)->menu.font->ascent + (mw)->menu.font->descent) | ||
| 380 | #define MENU_FONT_ASCENT(mw) \ | 381 | #define MENU_FONT_ASCENT(mw) \ |
| 381 | (- (mw)->menu.font_extents->max_logical_extent.y) | 382 | ((mw)->menu.fontSet != NULL \ |
| 383 | ? - (mw)->menu.font_extents->max_logical_extent.y \ | ||
| 384 | : (mw)->menu.font->ascent) | ||
| 382 | #else | 385 | #else |
| 383 | #define MENU_FONT_HEIGHT(mw) \ | 386 | #define MENU_FONT_HEIGHT(mw) \ |
| 384 | ((mw)->menu.font->ascent + (mw)->menu.font->descent) | 387 | ((mw)->menu.font->ascent + (mw)->menu.font->descent) |
| @@ -1053,10 +1056,14 @@ display_menu_item (mw, val, ws, where, highlighted_p, horizontal_p, | |||
| 1053 | 1056 | ||
| 1054 | 1057 | ||
| 1055 | #ifdef HAVE_X_I18N | 1058 | #ifdef HAVE_X_I18N |
| 1056 | XmbDrawString (XtDisplay (mw), ws->window, mw->menu.font, | 1059 | if (mw->menu.fontSet) |
| 1057 | #else | 1060 | XmbDrawString (XtDisplay (mw), ws->window, mw->menu.fontSet, |
| 1058 | XDrawString (XtDisplay (mw), ws->window, | 1061 | text_gc, x_offset, |
| 1062 | y + v_spacing + shadow + font_ascent, | ||
| 1063 | display_string, strlen (display_string)); | ||
| 1064 | else | ||
| 1059 | #endif | 1065 | #endif |
| 1066 | XDrawString (XtDisplay (mw), ws->window, | ||
| 1060 | text_gc, x_offset, | 1067 | text_gc, x_offset, |
| 1061 | y + v_spacing + shadow + font_ascent, | 1068 | y + v_spacing + shadow + font_ascent, |
| 1062 | display_string, strlen (display_string)); | 1069 | display_string, strlen (display_string)); |
| @@ -1083,10 +1090,16 @@ display_menu_item (mw, val, ws, where, highlighted_p, horizontal_p, | |||
| 1083 | else if (val->key) | 1090 | else if (val->key) |
| 1084 | { | 1091 | { |
| 1085 | #ifdef HAVE_X_I18N | 1092 | #ifdef HAVE_X_I18N |
| 1086 | XmbDrawString (XtDisplay (mw), ws->window, mw->menu.font, | 1093 | if (mw->menu.fontSet) |
| 1087 | #else | 1094 | XmbDrawString (XtDisplay (mw), ws->window, |
| 1088 | XDrawString (XtDisplay (mw), ws->window, | 1095 | mw->menu.fontSet, |
| 1096 | text_gc, | ||
| 1097 | x + label_width + mw->menu.arrow_spacing, | ||
| 1098 | y + v_spacing + shadow + font_ascent, | ||
| 1099 | val->key, strlen (val->key)); | ||
| 1100 | else | ||
| 1089 | #endif | 1101 | #endif |
| 1102 | XDrawString (XtDisplay (mw), ws->window, | ||
| 1090 | text_gc, | 1103 | text_gc, |
| 1091 | x + label_width + mw->menu.arrow_spacing, | 1104 | x + label_width + mw->menu.arrow_spacing, |
| 1092 | y + v_spacing + shadow + font_ascent, | 1105 | y + v_spacing + shadow + font_ascent, |
| @@ -1493,34 +1506,25 @@ make_drawing_gcs (mw) | |||
| 1493 | { | 1506 | { |
| 1494 | XGCValues xgcv; | 1507 | XGCValues xgcv; |
| 1495 | float scale; | 1508 | float scale; |
| 1509 | XtGCMask mask = GCForeground | GCBackground; | ||
| 1496 | 1510 | ||
| 1497 | #ifndef HAVE_X_I18N | 1511 | #ifdef HAVE_X_I18N |
| 1512 | if (!mw->menu.fontSet) | ||
| 1513 | { | ||
| 1514 | xgcv.font = mw->menu.font->fid; | ||
| 1515 | mask |= GCFont; | ||
| 1516 | } | ||
| 1517 | #else | ||
| 1498 | xgcv.font = mw->menu.font->fid; | 1518 | xgcv.font = mw->menu.font->fid; |
| 1519 | mask |= GCFont; | ||
| 1499 | #endif | 1520 | #endif |
| 1500 | xgcv.foreground = mw->menu.foreground; | 1521 | xgcv.foreground = mw->menu.foreground; |
| 1501 | xgcv.background = mw->core.background_pixel; | 1522 | xgcv.background = mw->core.background_pixel; |
| 1502 | mw->menu.foreground_gc = XtGetGC ((Widget)mw, | 1523 | mw->menu.foreground_gc = XtGetGC ((Widget)mw, mask, &xgcv); |
| 1503 | #ifndef HAVE_X_I18N | ||
| 1504 | GCFont | | ||
| 1505 | #endif | ||
| 1506 | GCForeground | GCBackground, | ||
| 1507 | &xgcv); | ||
| 1508 | 1524 | ||
| 1509 | #ifndef HAVE_X_I18N | ||
| 1510 | xgcv.font = mw->menu.font->fid; | ||
| 1511 | #endif | ||
| 1512 | xgcv.foreground = mw->menu.button_foreground; | 1525 | xgcv.foreground = mw->menu.button_foreground; |
| 1513 | xgcv.background = mw->core.background_pixel; | 1526 | mw->menu.button_gc = XtGetGC ((Widget)mw, mask, &xgcv); |
| 1514 | mw->menu.button_gc = XtGetGC ((Widget)mw, | ||
| 1515 | #ifndef HAVE_X_I18N | ||
| 1516 | GCFont | | ||
| 1517 | #endif | ||
| 1518 | GCForeground | GCBackground, | ||
| 1519 | &xgcv); | ||
| 1520 | 1527 | ||
| 1521 | #ifndef HAVE_X_I18N | ||
| 1522 | xgcv.font = mw->menu.font->fid; | ||
| 1523 | #endif | ||
| 1524 | xgcv.background = mw->core.background_pixel; | 1528 | xgcv.background = mw->core.background_pixel; |
| 1525 | 1529 | ||
| 1526 | #define BRIGHTNESS(color) (((color) & 0xff) + (((color) >> 8) & 0xff) + (((color) >> 16) & 0xff)) | 1530 | #define BRIGHTNESS(color) (((color) & 0xff) + (((color) >> 8) & 0xff) + (((color) >> 16) & 0xff)) |
| @@ -1545,49 +1549,26 @@ make_drawing_gcs (mw) | |||
| 1545 | xgcv.foreground = mw->menu.foreground; | 1549 | xgcv.foreground = mw->menu.foreground; |
| 1546 | xgcv.fill_style = FillStippled; | 1550 | xgcv.fill_style = FillStippled; |
| 1547 | xgcv.stipple = mw->menu.gray_pixmap; | 1551 | xgcv.stipple = mw->menu.gray_pixmap; |
| 1548 | mw->menu.disabled_gc = XtGetGC ((Widget)mw, | 1552 | mw->menu.disabled_gc = XtGetGC ((Widget)mw, mask |
| 1549 | #ifndef HAVE_X_I18N | ||
| 1550 | GCFont | | ||
| 1551 | #endif | ||
| 1552 | GCForeground | GCBackground | ||
| 1553 | | GCFillStyle | GCStipple, &xgcv); | 1553 | | GCFillStyle | GCStipple, &xgcv); |
| 1554 | } | 1554 | } |
| 1555 | else | 1555 | else |
| 1556 | { | 1556 | { |
| 1557 | /* Many colors available, use disabled pixel. */ | 1557 | /* Many colors available, use disabled pixel. */ |
| 1558 | xgcv.foreground = mw->menu.disabled_foreground; | 1558 | xgcv.foreground = mw->menu.disabled_foreground; |
| 1559 | mw->menu.disabled_gc = XtGetGC ((Widget)mw, | 1559 | mw->menu.disabled_gc = XtGetGC ((Widget)mw, mask, &xgcv); |
| 1560 | #ifndef HAVE_X_I18N | ||
| 1561 | GCFont | | ||
| 1562 | #endif | ||
| 1563 | GCForeground | GCBackground, &xgcv); | ||
| 1564 | } | 1560 | } |
| 1565 | 1561 | ||
| 1566 | #ifndef HAVE_X_I18N | ||
| 1567 | xgcv.font = mw->menu.font->fid; | ||
| 1568 | #endif | ||
| 1569 | xgcv.foreground = mw->menu.button_foreground; | 1562 | xgcv.foreground = mw->menu.button_foreground; |
| 1570 | xgcv.background = mw->core.background_pixel; | 1563 | xgcv.background = mw->core.background_pixel; |
| 1571 | xgcv.fill_style = FillStippled; | 1564 | xgcv.fill_style = FillStippled; |
| 1572 | xgcv.stipple = mw->menu.gray_pixmap; | 1565 | xgcv.stipple = mw->menu.gray_pixmap; |
| 1573 | mw->menu.inactive_button_gc = XtGetGC ((Widget)mw, | 1566 | mw->menu.inactive_button_gc = XtGetGC ((Widget)mw, mask |
| 1574 | #ifndef HAVE_X_I18N | ||
| 1575 | GCFont | | ||
| 1576 | #endif | ||
| 1577 | GCForeground | GCBackground | ||
| 1578 | | GCFillStyle | GCStipple, &xgcv); | 1567 | | GCFillStyle | GCStipple, &xgcv); |
| 1579 | 1568 | ||
| 1580 | #ifndef HAVE_X_I18N | ||
| 1581 | xgcv.font = mw->menu.font->fid; | ||
| 1582 | #endif | ||
| 1583 | xgcv.foreground = mw->core.background_pixel; | 1569 | xgcv.foreground = mw->core.background_pixel; |
| 1584 | xgcv.background = mw->menu.foreground; | 1570 | xgcv.background = mw->menu.foreground; |
| 1585 | mw->menu.background_gc = XtGetGC ((Widget)mw, | 1571 | mw->menu.background_gc = XtGetGC ((Widget)mw, mask, &xgcv); |
| 1586 | #ifndef HAVE_X_I18N | ||
| 1587 | GCFont | | ||
| 1588 | #endif | ||
| 1589 | GCForeground | GCBackground, | ||
| 1590 | &xgcv); | ||
| 1591 | } | 1572 | } |
| 1592 | 1573 | ||
| 1593 | static void | 1574 | static void |
| @@ -1793,14 +1774,14 @@ XlwMenuInitialize (request, mw, args, num_args) | |||
| 1793 | gray_bitmap_width, gray_bitmap_height, | 1774 | gray_bitmap_width, gray_bitmap_height, |
| 1794 | (unsigned long)1, (unsigned long)0, 1); | 1775 | (unsigned long)1, (unsigned long)0, 1); |
| 1795 | 1776 | ||
| 1796 | #ifndef HAVE_X_I18N | ||
| 1797 | /* I don't understand why this ends up 0 sometimes, | 1777 | /* I don't understand why this ends up 0 sometimes, |
| 1798 | but it does. This kludge works around it. | 1778 | but it does. This kludge works around it. |
| 1799 | Can anyone find a real fix? -- rms. */ | 1779 | Can anyone find a real fix? -- rms. */ |
| 1800 | if (mw->menu.font == 0) | 1780 | if (mw->menu.font == 0) |
| 1801 | mw->menu.font = xlwmenu_default_font; | 1781 | mw->menu.font = xlwmenu_default_font; |
| 1802 | #else | 1782 | #ifdef HAVE_X_I18N |
| 1803 | mw->menu.font_extents = XExtentsOfFontSet (mw->menu.font); | 1783 | if (mw->menu.fontSet) |
| 1784 | mw->menu.font_extents = XExtentsOfFontSet (mw->menu.fontSet); | ||
| 1804 | #endif | 1785 | #endif |
| 1805 | 1786 | ||
| 1806 | make_drawing_gcs (mw); | 1787 | make_drawing_gcs (mw); |
| @@ -1969,7 +1950,10 @@ XlwMenuSetValues (current, request, new) | |||
| 1969 | 1950 | ||
| 1970 | if (newmw->core.background_pixel != oldmw->core.background_pixel | 1951 | if (newmw->core.background_pixel != oldmw->core.background_pixel |
| 1971 | || newmw->menu.foreground != oldmw->menu.foreground | 1952 | || newmw->menu.foreground != oldmw->menu.foreground |
| 1972 | #ifndef HAVE_X_I18N | 1953 | #ifdef HAVE_X_I18N |
| 1954 | || newmw->menu.fontSet != oldmw->menu.fontSet | ||
| 1955 | || (newmw->menu.fontSet == NULL && newmw->menu.font != oldmw->menu.font) | ||
| 1956 | #else | ||
| 1973 | || newmw->menu.font != oldmw->menu.font | 1957 | || newmw->menu.font != oldmw->menu.font |
| 1974 | #endif | 1958 | #endif |
| 1975 | ) | 1959 | ) |
| @@ -1999,10 +1983,10 @@ XlwMenuSetValues (current, request, new) | |||
| 1999 | } | 1983 | } |
| 2000 | 1984 | ||
| 2001 | #ifdef HAVE_X_I18N | 1985 | #ifdef HAVE_X_I18N |
| 2002 | if (newmw->menu.font != oldmw->menu.font) | 1986 | if (newmw->menu.fontSet != oldmw->menu.fontSet && newmw->menu.fontSet != NULL) |
| 2003 | { | 1987 | { |
| 2004 | redisplay = True; | 1988 | redisplay = True; |
| 2005 | newmw->menu.font_extents = XExtentsOfFontSet (newmw->menu.font); | 1989 | newmw->menu.font_extents = XExtentsOfFontSet (newmw->menu.fontSet); |
| 2006 | } | 1990 | } |
| 2007 | #endif | 1991 | #endif |
| 2008 | 1992 | ||