Mercurial > emacs
comparison lwlib/xlwmenu.c @ 90136:7a3341d65a12
Revision: miles@gnu.org--gnu-2005/emacs--unicode--0--patch-33
Merge from emacs--cvs-trunk--0
Patches applied:
* emacs--cvs-trunk--0 (patch 223-227)
- Update from CVS
author | Miles Bader <miles@gnu.org> |
---|---|
date | Sat, 02 Apr 2005 22:40:25 +0000 |
parents | 13796b0653c7 0769f2fae9d0 |
children | f9a65d7ebd29 |
comparison
equal
deleted
inserted
replaced
90135:baa2d4aa0064 | 90136:7a3341d65a12 |
---|---|
129 | 129 |
130 /* FIXME: Should ESC close one level of menu structure or the complete menu? */ | 130 /* FIXME: Should ESC close one level of menu structure or the complete menu? */ |
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), |
151 offset(menu.disabled_foreground), XtRString, (XtPointer)NULL}, | 147 offset(menu.disabled_foreground), XtRString, (XtPointer)NULL}, |
152 {XtNbuttonForeground, XtCButtonForeground, XtRPixel, sizeof(Pixel), | 148 {XtNbuttonForeground, XtCButtonForeground, XtRPixel, sizeof(Pixel), |
359 int | 355 int |
360 string_width (mw, s) | 356 string_width (mw, s) |
361 XlwMenuWidget mw; | 357 XlwMenuWidget mw; |
362 char *s; | 358 char *s; |
363 { | 359 { |
360 XCharStruct xcs; | |
361 int drop; | |
364 #ifdef HAVE_X_I18N | 362 #ifdef HAVE_X_I18N |
365 XRectangle ink, logical; | 363 XRectangle ink, logical; |
366 XmbTextExtents (mw->menu.font, s, strlen (s), &ink, &logical); | 364 if (mw->menu.fontSet) |
367 return logical.width; | 365 { |
368 #else | 366 XmbTextExtents (mw->menu.fontSet, s, strlen (s), &ink, &logical); |
369 XCharStruct xcs; | 367 return logical.width; |
370 int drop; | 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) |
385 #define MENU_FONT_ASCENT(mw) ((mw)->menu.font->ascent) | 388 #define MENU_FONT_ASCENT(mw) ((mw)->menu.font->ascent) |
386 #endif | 389 #endif |
1051 else if (!horizontal_p && ws->button_width) | 1054 else if (!horizontal_p && ws->button_width) |
1052 x_offset += ws->button_width; | 1055 x_offset += ws->button_width; |
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, |
1061 text_gc, x_offset, | |
1062 y + v_spacing + shadow + font_ascent, | |
1063 display_string, strlen (display_string)); | |
1064 else | |
1065 #endif | |
1058 XDrawString (XtDisplay (mw), ws->window, | 1066 XDrawString (XtDisplay (mw), ws->window, |
1059 #endif | |
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)); |
1063 | 1070 |
1064 if (!horizontal_p) | 1071 if (!horizontal_p) |
1081 highlighted_p); | 1088 highlighted_p); |
1082 } | 1089 } |
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, |
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 | |
1101 #endif | |
1088 XDrawString (XtDisplay (mw), ws->window, | 1102 XDrawString (XtDisplay (mw), ws->window, |
1089 #endif | |
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, |
1093 val->key, strlen (val->key)); | 1106 val->key, strlen (val->key)); |
1094 } | 1107 } |
1491 make_drawing_gcs (mw) | 1504 make_drawing_gcs (mw) |
1492 XlwMenuWidget mw; | 1505 XlwMenuWidget mw; |
1493 { | 1506 { |
1494 XGCValues xgcv; | 1507 XGCValues xgcv; |
1495 float scale; | 1508 float scale; |
1496 | 1509 XtGCMask mask = GCForeground | GCBackground; |
1497 #ifndef HAVE_X_I18N | 1510 |
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 | 1524 |
1504 GCFont | | |
1505 #endif | |
1506 GCForeground | GCBackground, | |
1507 &xgcv); | |
1508 | |
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, | 1527 |
1515 #ifndef HAVE_X_I18N | |
1516 GCFont | | |
1517 #endif | |
1518 GCForeground | GCBackground, | |
1519 &xgcv); | |
1520 | |
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)) |
1527 | 1531 |
1528 /* Allocate color for disabled menu-items. */ | 1532 /* Allocate color for disabled menu-items. */ |
1543 { | 1547 { |
1544 /* Too few colors, use stipple. */ | 1548 /* Too few colors, use stipple. */ |
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 | 1560 } |
1561 GCFont | | 1561 |
1562 #endif | |
1563 GCForeground | GCBackground, &xgcv); | |
1564 } | |
1565 | |
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 |
1594 release_drawing_gcs (mw) | 1575 release_drawing_gcs (mw) |
1595 XlwMenuWidget mw; | 1576 XlwMenuWidget mw; |
1791 mw->menu.gray_pixmap | 1772 mw->menu.gray_pixmap |
1792 = XCreatePixmapFromBitmapData (display, window, gray_bitmap_bits, | 1773 = XCreatePixmapFromBitmapData (display, window, gray_bitmap_bits, |
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); |
1807 make_shadow_gcs (mw); | 1788 make_shadow_gcs (mw); |
1808 | 1789 |
1967 && newmw->menu.contents->change >= VISIBLE_CHANGE) | 1948 && newmw->menu.contents->change >= VISIBLE_CHANGE) |
1968 redisplay = True; | 1949 redisplay = True; |
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 ) |
1976 { | 1960 { |
1977 release_drawing_gcs (newmw); | 1961 release_drawing_gcs (newmw); |
1997 0, 0, 0, 0, True); | 1981 0, 0, 0, 0, True); |
1998 } | 1982 } |
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 |
2009 return redisplay; | 1993 return redisplay; |
2010 } | 1994 } |