Mercurial > hg > xemacs-beta
comparison lwlib/xlwmenu.c @ 3094:ad2f4ae9895b
[xemacs-hg @ 2005-11-26 11:45:47 by stephent]
Xft merge. <87k6ev4p8q.fsf@tleepslib.sk.tsukuba.ac.jp>
author | stephent |
---|---|
date | Sat, 26 Nov 2005 11:46:25 +0000 |
parents | 04bc9d2f42c7 |
children | 44a63e4a23cd |
comparison
equal
deleted
inserted
replaced
3093:769dc945b085 | 3094:ad2f4ae9895b |
---|---|
43 #if XmVersion < 1002 /* 1.1 or ancient */ | 43 #if XmVersion < 1002 /* 1.1 or ancient */ |
44 #undef XmFONTLIST_DEFAULT_TAG | 44 #undef XmFONTLIST_DEFAULT_TAG |
45 #define XmFONTLIST_DEFAULT_TAG XmSTRING_DEFAULT_CHARSET | 45 #define XmFONTLIST_DEFAULT_TAG XmSTRING_DEFAULT_CHARSET |
46 #endif /* XmVersion < 1.2 */ | 46 #endif /* XmVersion < 1.2 */ |
47 #endif | 47 #endif |
48 | |
49 /* #### we may want to turn off USE_XFT here if !USE_XFT_MENUBARS | |
50 In fact, maybe that's the right interface overall? */ | |
51 #include "lwlib-fonts.h" | |
52 #include "lwlib-colors.h" | |
48 #include "xlwmenuP.h" | 53 #include "xlwmenuP.h" |
49 | 54 |
50 #ifdef USE_DEBUG_MALLOC | 55 #ifdef USE_DEBUG_MALLOC |
51 #include <dmalloc.h> | 56 #include <dmalloc.h> |
52 #endif | 57 #endif |
67 | 72 |
68 #define offset(field) XtOffset(XlwMenuWidget, field) | 73 #define offset(field) XtOffset(XlwMenuWidget, field) |
69 static XtResource | 74 static XtResource |
70 xlwMenuResources[] = | 75 xlwMenuResources[] = |
71 { | 76 { |
72 #ifdef NEED_MOTIF | 77 #if defined(NEED_MOTIF) && !defined(USE_XFT_MENUBARS) |
73 /* There are three font list resources, so that we can accept either of | 78 /* There are three font list resources, so that we can accept either of |
74 the resources *fontList: or *font:, and so that we can tell the | 79 the resources *fontList: or *font:, and so that we can tell the |
75 difference between them being specified, and being defaulted to a | 80 difference between them being specified, and being defaulted to a |
76 font from the XtRString specified here. */ | 81 font from the XtRString specified here. */ |
77 {XmNfontList, XmCFontList, XmRFontList, sizeof(XmFontList), | 82 {XmNfontList, XmCFontList, XmRFontList, sizeof(XmFontList), |
85 *fontList resource set, or at least know how to deal with this. */ | 90 *fontList resource set, or at least know how to deal with this. */ |
86 XtRString, (XtPointer) "-*-helvetica-bold-r-*-*-*-120-*-*-*-*-iso8859-1"}, | 91 XtRString, (XtPointer) "-*-helvetica-bold-r-*-*-*-120-*-*-*-*-iso8859-1"}, |
87 #else | 92 #else |
88 {XtNfont, XtCFont, XtRFontStruct, sizeof(XFontStruct *), | 93 {XtNfont, XtCFont, XtRFontStruct, sizeof(XFontStruct *), |
89 offset(menu.font), XtRString, (XtPointer) "XtDefaultFont"}, | 94 offset(menu.font), XtRString, (XtPointer) "XtDefaultFont"}, |
95 #ifdef USE_XFT_MENUBARS | |
96 {XtNxftFont, XtCXftFont, XtRString, sizeof (String), | |
97 offset(menu.renderFontSpec), | |
98 XtRString, (XtPointer) "Helvetica-12:bold"}, | |
99 #endif | |
90 # ifdef USE_XFONTSET | 100 # ifdef USE_XFONTSET |
91 /* #### Consider using the same method as for Motif; see the comment in | 101 /* #### Consider using the same method as for Motif; see the comment in |
92 XlwMenuInitialize(). */ | 102 XlwMenuInitialize(). */ |
93 {XtNfontSet, XtCFontSet, XtRFontSet, sizeof(XFontSet), | 103 {XtNfontSet, XtCFontSet, XtRFontSet, sizeof(XFontSet), |
94 offset(menu.font_set), XtRString, (XtPointer) "XtDefaultFontSet"}, | 104 offset(menu.font_set), XtRString, (XtPointer) "XtDefaultFontSet"}, |
163 static void XlwMenuClassInitialize (void); | 173 static void XlwMenuClassInitialize (void); |
164 static void Start (Widget w, XEvent *ev, String *params, Cardinal *num_params); | 174 static void Start (Widget w, XEvent *ev, String *params, Cardinal *num_params); |
165 static void Drag (Widget w, XEvent *ev, String *params, Cardinal *num_params); | 175 static void Drag (Widget w, XEvent *ev, String *params, Cardinal *num_params); |
166 static void Select(Widget w, XEvent *ev, String *params, Cardinal *num_params); | 176 static void Select(Widget w, XEvent *ev, String *params, Cardinal *num_params); |
167 | 177 |
168 #ifdef NEED_MOTIF | 178 #if defined(NEED_MOTIF) && !defined(USE_XFT_MENUBARS) |
169 static XFontStruct *default_font_of_font_list (XmFontList); | 179 static XFontStruct *default_font_of_font_list (XmFontList); |
170 #endif | 180 #endif |
171 | 181 |
172 static XtActionsRec | 182 static XtActionsRec |
173 xlwMenuActionsList [] = | 183 xlwMenuActionsList [] = |
239 return result; | 249 return result; |
240 } | 250 } |
241 | 251 |
242 #endif /* 0 */ | 252 #endif /* 0 */ |
243 | 253 |
244 /* Replacement for XAllocColor() that tries to return the nearest | |
245 available color if the colormap is full. From FSF Emacs. */ | |
246 | |
247 static int | |
248 allocate_nearest_color (Display *display, Colormap screen_colormap, | |
249 XColor *color_def) | |
250 { | |
251 int status = XAllocColor (display, screen_colormap, color_def); | |
252 if (status) | |
253 return status; | |
254 | |
255 { | |
256 /* If we got to this point, the colormap is full, so we're | |
257 going to try to get the next closest color. | |
258 The algorithm used is a least-squares matching, which is | |
259 what X uses for closest color matching with StaticColor visuals. */ | |
260 | |
261 int nearest, x; | |
262 unsigned long nearest_delta = ULONG_MAX; | |
263 | |
264 int no_cells = XDisplayCells (display, XDefaultScreen (display)); | |
265 /* Don't use alloca here because lwlib doesn't have the | |
266 necessary configuration information that src does. */ | |
267 XColor *cells = (XColor *) malloc (sizeof (XColor) * no_cells); | |
268 | |
269 for (x = 0; x < no_cells; x++) | |
270 cells[x].pixel = x; | |
271 | |
272 XQueryColors (display, screen_colormap, cells, no_cells); | |
273 | |
274 for (nearest = 0, x = 0; x < no_cells; x++) | |
275 { | |
276 long dred = (color_def->red >> 8) - (cells[x].red >> 8); | |
277 long dgreen = (color_def->green >> 8) - (cells[x].green >> 8); | |
278 long dblue = (color_def->blue >> 8) - (cells[x].blue >> 8); | |
279 unsigned long delta = dred * dred + dgreen * dgreen + dblue * dblue; | |
280 | |
281 if (delta < nearest_delta) | |
282 { | |
283 nearest = x; | |
284 nearest_delta = delta; | |
285 } | |
286 } | |
287 color_def->red = cells[nearest].red; | |
288 color_def->green = cells[nearest].green; | |
289 color_def->blue = cells[nearest].blue; | |
290 free (cells); | |
291 return XAllocColor (display, screen_colormap, color_def); | |
292 } | |
293 } | |
294 | |
295 static void | 254 static void |
296 push_new_stack (XlwMenuWidget mw, widget_value *val) | 255 push_new_stack (XlwMenuWidget mw, widget_value *val) |
297 { | 256 { |
298 if (!mw->menu.new_stack) | 257 if (!mw->menu.new_stack) |
299 { | 258 { |
353 } | 312 } |
354 | 313 |
355 /* Size code */ | 314 /* Size code */ |
356 static int | 315 static int |
357 string_width (XlwMenuWidget mw, | 316 string_width (XlwMenuWidget mw, |
358 #ifdef NEED_MOTIF | 317 #if defined(NEED_MOTIF) && !defined(USE_XFT_MENUBARS) |
359 XmString s | 318 XmString s |
360 #else | 319 #else |
361 char *s | 320 char *s |
362 #endif | 321 #endif |
363 ) | 322 ) |
364 { | 323 { |
365 #ifdef NEED_MOTIF | 324 #if defined(NEED_MOTIF) && !defined(USE_XFT_MENUBARS) |
366 Dimension width, height; | 325 Dimension width, height; |
367 XmStringExtent (mw->menu.font_list, s, &width, &height); | 326 XmStringExtent (mw->menu.font_list, s, &width, &height); |
368 return width; | 327 return width; |
369 #else | 328 #else |
370 # ifdef USE_XFONTSET | 329 # ifdef USE_XFONTSET |
371 XRectangle ri, rl; | 330 XRectangle ri, rl; |
372 XmbTextExtents (mw->menu.font_set, s, strlen (s), &ri, &rl); | 331 XmbTextExtents (mw->menu.font_set, s, strlen (s), &ri, &rl); |
373 return rl.width; | 332 return rl.width; |
374 # else | 333 # else |
334 #ifdef USE_XFT_MENUBARS | |
335 XGlyphInfo glyphinfo; | |
336 XftTextExtents8 (XtDisplay (mw), mw->menu.renderFont, s, strlen (s), | |
337 &glyphinfo); | |
338 return glyphinfo.xOff; | |
339 #else | |
375 XCharStruct xcs; | 340 XCharStruct xcs; |
376 int drop; | 341 int drop; |
377 XTextExtents (mw->menu.font, s, strlen (s), &drop, &drop, &drop, &xcs); | 342 XTextExtents (mw->menu.font, s, strlen (s), &drop, &drop, &drop, &xcs); |
378 return xcs.width; | 343 return xcs.width; |
344 #endif | |
379 # endif /* USE_XFONTSET */ | 345 # endif /* USE_XFONTSET */ |
380 #endif | 346 #endif |
381 } | 347 } |
382 | 348 |
383 static char massaged_resource_char[256]; | 349 static char massaged_resource_char[256]; |
400 massaged_resource_char ['.'] = '_'; /* Convert Buffers... to buffers___ */ | 366 massaged_resource_char ['.'] = '_'; /* Convert Buffers... to buffers___ */ |
401 } | 367 } |
402 | 368 |
403 static int | 369 static int |
404 string_width_u (XlwMenuWidget mw, | 370 string_width_u (XlwMenuWidget mw, |
405 #ifdef NEED_MOTIF | 371 #if defined(NEED_MOTIF) && !defined(USE_XFT_MENUBARS) |
406 XmString string | 372 XmString string |
407 #else | 373 #else |
408 char *string | 374 char *string |
409 #endif | 375 #endif |
410 ) | 376 ) |
411 { | 377 { |
412 #ifdef NEED_MOTIF | 378 #if defined(NEED_MOTIF) && !defined(USE_XFT_MENUBARS) |
413 Dimension width, height; | 379 Dimension width, height; |
414 XmString newstring; | 380 XmString newstring; |
415 #else | 381 #else |
416 # ifdef USE_XFONTSET | 382 # ifdef USE_XFONTSET |
417 XRectangle ri, rl; | 383 XRectangle ri, rl; |
418 # else /* ! USE_XFONTSET */ | 384 # else /* ! USE_XFONTSET */ |
385 #ifdef USE_XFT_MENUBARS | |
386 XGlyphInfo glyphinfo; | |
387 #else | |
419 XCharStruct xcs; | 388 XCharStruct xcs; |
420 int drop; | 389 int drop; |
390 #endif | |
421 # endif | 391 # endif |
422 #endif | 392 #endif |
423 char* newchars; | 393 char* newchars; |
424 int charslength; | 394 int charslength; |
425 char *chars; | 395 char *chars; |
426 int i, j; | 396 int i, j; |
427 | 397 |
428 #ifdef NEED_MOTIF | 398 #if defined(NEED_MOTIF) && !defined(USE_XFT_MENUBARS) |
429 chars = ""; | 399 chars = ""; |
430 if (!XmStringGetLtoR (string, XmFONTLIST_DEFAULT_TAG, &chars)) | 400 if (!XmStringGetLtoR (string, XmFONTLIST_DEFAULT_TAG, &chars)) |
431 chars = ""; | 401 chars = ""; |
432 #else | 402 #else |
433 chars = string; | 403 chars = string; |
440 i++; | 410 i++; |
441 else | 411 else |
442 newchars[j++] = chars[i]; | 412 newchars[j++] = chars[i]; |
443 newchars[j] = '\0'; | 413 newchars[j] = '\0'; |
444 | 414 |
445 #ifdef NEED_MOTIF | 415 #if defined(NEED_MOTIF) && !defined(USE_XFT_MENUBARS) |
446 newstring = XmStringLtoRCreate (newchars, XmFONTLIST_DEFAULT_TAG); | 416 newstring = XmStringLtoRCreate (newchars, XmFONTLIST_DEFAULT_TAG); |
447 XmStringExtent (mw->menu.font_list, newstring, &width, &height); | 417 XmStringExtent (mw->menu.font_list, newstring, &width, &height); |
448 XmStringFree (newstring); | 418 XmStringFree (newstring); |
449 XtFree (chars); | 419 XtFree (chars); |
450 return width; | 420 return width; |
451 #else | 421 #else |
452 # ifdef USE_XFONTSET | 422 # ifdef USE_XFONTSET |
453 XmbTextExtents (mw->menu.font_set, newchars, j, &ri, &rl); | 423 XmbTextExtents (mw->menu.font_set, newchars, j, &ri, &rl); |
454 return rl.width; | 424 return rl.width; |
455 # else /* ! USE_XFONTSET */ | 425 # else /* ! USE_XFONTSET */ |
426 #ifdef USE_XFT_MENUBARS | |
427 XftTextExtents8 (XtDisplay (mw), mw->menu.renderFont, newchars, j, | |
428 &glyphinfo); | |
429 return glyphinfo.xOff; | |
430 #else | |
456 XTextExtents (mw->menu.font, newchars, j, &drop, &drop, &drop, &xcs); | 431 XTextExtents (mw->menu.font, newchars, j, &drop, &drop, &drop, &xcs); |
457 return xcs.width; | 432 return xcs.width; |
433 #endif | |
458 # endif /* USE_XFONTSET */ | 434 # endif /* USE_XFONTSET */ |
459 #endif | 435 #endif |
460 } | 436 } |
461 | 437 |
462 static void | 438 static void |
619 } | 595 } |
620 | 596 |
621 return result; | 597 return result; |
622 } | 598 } |
623 | 599 |
624 #ifdef NEED_MOTIF | 600 #if defined(NEED_MOTIF) && !defined(USE_XFT_MENUBARS) |
625 | 601 |
626 static XmString | 602 static XmString |
627 resource_widget_value (XlwMenuWidget mw, widget_value *val) | 603 resource_widget_value (XlwMenuWidget mw, widget_value *val) |
628 { | 604 { |
629 if (!val->toolkit_data) | 605 if (!val->toolkit_data) |
767 return (char *) val->toolkit_data; | 743 return (char *) val->toolkit_data; |
768 } | 744 } |
769 | 745 |
770 #endif /* !Motif */ | 746 #endif /* !Motif */ |
771 | 747 |
748 #define MINL(x,y) ((((unsigned long) (x)) < ((unsigned long) (y))) \ | |
749 ? ((unsigned long) (x)) : ((unsigned long) (y))) | |
750 | |
751 #ifdef USE_XFT_MENUBARS | |
752 static int | |
753 x_xft_text_width (Display *dpy, XftFont *xft_font, char *run, int len) | |
754 { | |
755 static XGlyphInfo glyphinfo; | |
756 | |
757 XftTextExtents8 (dpy, | |
758 xft_font, | |
759 run, len, &glyphinfo); | |
760 return glyphinfo.xOff; | |
761 } | |
762 #endif | |
763 | |
772 /* Code for drawing strings. */ | 764 /* Code for drawing strings. */ |
773 static void | 765 static void |
774 string_draw (XlwMenuWidget mw, | 766 string_draw (XlwMenuWidget mw, |
775 Window window, | 767 Window window, |
776 int x, int y, | 768 int x, int y, |
769 #ifdef USE_XFT_MENUBARS | |
770 XftColor *color, | |
771 XftColor *colorBg, | |
772 #else | |
777 GC gc, | 773 GC gc, |
778 #ifdef NEED_MOTIF | 774 #endif |
775 #if defined(NEED_MOTIF) && !defined(USE_XFT_MENUBARS) | |
779 XmString string | 776 XmString string |
780 #else | 777 #else |
781 char *string | 778 char *string |
782 #endif | 779 #endif |
783 ) | 780 ) |
784 { | 781 { |
785 #ifdef NEED_MOTIF | 782 #if defined(NEED_MOTIF) && !defined(USE_XFT_MENUBARS) |
786 XmStringDraw (XtDisplay (mw), window, | 783 XmStringDraw (XtDisplay (mw), window, |
787 mw->menu.font_list, | 784 mw->menu.font_list, |
788 string, gc, | 785 string, gc, |
789 x, y, | 786 x, y, |
790 1000, /* ???? width */ | 787 1000, /* ???? width */ |
791 XmALIGNMENT_BEGINNING, | 788 XmALIGNMENT_BEGINNING, |
792 0, /* ???? layout_direction */ | 789 0, /* ???? layout_direction */ |
793 0); | 790 0); |
794 #else | 791 #else |
795 # ifdef USE_XFONTSET | 792 # ifdef USE_XFT_MENUBARS |
793 Display *display = XtDisplay (mw); | |
794 Visual *visual = DefaultVisualOfScreen (XtScreen (mw)); | |
795 Colormap cmap = mw->core.colormap; | |
796 XftDraw *xftDraw = XftDrawCreate (display, window, visual, cmap); | |
797 XftFont *renderFont = mw->menu.renderFont; | |
798 /* draw background rect */ | |
799 XftDrawRect (xftDraw, colorBg, | |
800 x, y, | |
801 x_xft_text_width (display, renderFont, string, strlen (string)), | |
802 renderFont->ascent + renderFont->descent); /* XXX */ | |
803 /* draw text */ | |
804 XftDrawString8 (xftDraw, color, renderFont, | |
805 x, y + mw->menu.font_ascent, string, strlen (string)); | |
806 XftDrawDestroy (xftDraw); | |
807 # else | |
808 # ifdef USE_XFONTSET | |
796 XmbDrawString (XtDisplay (mw), window, mw->menu.font_set, gc, | 809 XmbDrawString (XtDisplay (mw), window, mw->menu.font_set, gc, |
797 x, y + mw->menu.font_ascent, string, strlen (string)); | 810 x, y + mw->menu.font_ascent, string, strlen (string)); |
798 # else | 811 # else |
799 XDrawString (XtDisplay (mw), window, gc, | 812 XDrawString (XtDisplay (mw), window, gc, |
800 x, y + mw->menu.font_ascent, string, strlen (string)); | 813 x, y + mw->menu.font_ascent, string, strlen (string)); |
801 # endif /* USE_XFONTSET */ | 814 # endif /* USE_XFONTSET */ |
802 | 815 # endif /* USE_XFT_MENUBARS */ |
803 #endif | 816 #endif /* NEED_MOTIF */ |
804 } | 817 } |
805 | 818 |
806 static int | 819 static int |
807 string_draw_range ( | 820 string_draw_range ( |
808 XlwMenuWidget mw, | 821 XlwMenuWidget mw, |
809 Window window, | 822 Window window, |
810 int x, int y, | 823 int x, int y, |
824 #ifdef USE_XFT_MENUBARS | |
825 XftColor *color, | |
826 XftColor *colorBg, | |
827 #else | |
811 GC gc, | 828 GC gc, |
829 #endif | |
812 char *string, | 830 char *string, |
813 int start, | 831 int start, |
814 int end | 832 int end |
815 ) | 833 ) |
816 { | 834 { |
817 #ifdef NEED_MOTIF | 835 #if defined(NEED_MOTIF) && !defined(USE_XFT_MENUBARS) |
818 Dimension width, height; | 836 Dimension width, height; |
819 XmString newstring; | 837 XmString newstring; |
820 int c; | 838 int c; |
821 | 839 |
822 if (end <= start) | 840 if (end <= start) |
849 x, y + mw->menu.font_ascent, &string[start], end - start); | 867 x, y + mw->menu.font_ascent, &string[start], end - start); |
850 XmbTextExtents ( | 868 XmbTextExtents ( |
851 mw->menu.font_set, &string[start], end - start, &ri, &rl); | 869 mw->menu.font_set, &string[start], end - start, &ri, &rl); |
852 return rl.width; | 870 return rl.width; |
853 # else | 871 # else |
872 #ifdef USE_XFT_MENUBARS | |
873 if (end <= start) | |
874 return 0; | |
875 else | |
876 { | |
877 XGlyphInfo glyphinfo; | |
878 Display *display = XtDisplay (mw); | |
879 Visual *visual = DefaultVisualOfScreen (XtScreen (mw)); | |
880 Colormap cmap = mw->core.colormap; | |
881 XftFont *renderFont = mw->menu.renderFont; | |
882 /* #### should use parent frame's .xftDraw? */ | |
883 XftDraw *xftDraw = XftDrawCreate (display, window, visual, cmap); | |
884 /* draw background rect */ | |
885 XftDrawRect (xftDraw, colorBg, | |
886 x, y, | |
887 x_xft_text_width (display, | |
888 renderFont, &string[start], end - start), | |
889 renderFont->ascent + renderFont->descent); /* XXX */ | |
890 /* draw text */ | |
891 XftDrawString8 (xftDraw, color, renderFont, | |
892 x, y + mw->menu.font_ascent, | |
893 &string[start], end - start); | |
894 | |
895 XftTextExtents8 (display, renderFont, &string[start], end - start, | |
896 &glyphinfo); | |
897 | |
898 /* #### should use parent frame's .xftDraw */ | |
899 XftDrawDestroy (xftDraw); | |
900 return glyphinfo.xOff; | |
901 } | |
902 #else | |
854 XCharStruct xcs; | 903 XCharStruct xcs; |
855 int drop; | 904 int drop; |
856 | 905 |
857 if (end <= start) | 906 if (end <= start) |
858 return 0; | 907 return 0; |
859 XDrawString ( | 908 XDrawString ( /* XXX */ |
860 XtDisplay (mw), window, gc, | 909 XtDisplay (mw), window, gc, |
861 x, y + mw->menu.font_ascent, &string[start], end - start); | 910 x, y + mw->menu.font_ascent, &string[start], end - start); |
862 XTextExtents ( | 911 XTextExtents ( |
863 mw->menu.font, &string[start], end - start, | 912 mw->menu.font, &string[start], end - start, |
864 &drop, &drop, &drop, &xcs); | 913 &drop, &drop, &drop, &xcs); |
865 return xcs.width; | 914 return xcs.width; |
915 #endif | |
866 # endif | 916 # endif |
867 #endif | 917 #endif |
868 } | 918 } |
869 | 919 |
870 static void | 920 static void |
871 string_draw_u (XlwMenuWidget mw, | 921 string_draw_u (XlwMenuWidget mw, |
872 Window window, | 922 Window window, |
873 int x, int y, | 923 int x, int y, |
924 #ifdef USE_XFT_MENUBARS | |
925 XftColor *color, XftColor *colorBg, GC gc, | |
926 #else | |
874 GC gc, | 927 GC gc, |
875 #ifdef NEED_MOTIF | 928 #endif |
929 #if defined(NEED_MOTIF) && !defined(USE_XFT_MENUBARS) | |
876 XmString string | 930 XmString string |
877 #else | 931 #else |
878 char *string | 932 char *string |
879 #endif | 933 #endif |
880 ) | 934 ) |
881 { | 935 { |
882 int i, s = 0; | 936 int i, s = 0; |
883 char *chars; | 937 char *chars; |
884 | 938 |
885 #ifdef NEED_MOTIF | 939 #if defined(NEED_MOTIF) && !defined(USE_XFT_MENUBARS) |
886 chars = ""; | 940 chars = ""; |
887 if (!XmStringGetLtoR (string, XmFONTLIST_DEFAULT_TAG, &chars)) | 941 if (!XmStringGetLtoR (string, XmFONTLIST_DEFAULT_TAG, &chars)) |
888 chars = ""; | 942 chars = ""; |
889 #else | 943 #else |
890 chars = string; | 944 chars = string; |
891 #endif | 945 #endif |
892 for (i=0; chars[i]; ++i) { | 946 for (i=0; chars[i]; ++i) { |
893 if (chars[i] == '%' && chars[i+1] == '_') { | 947 if (chars[i] == '%' && chars[i+1] == '_') { |
894 int w; | 948 int w; |
895 | 949 |
950 #ifdef USE_XFT_MENUBARS | |
951 x += string_draw_range (mw, window, x, y, color, colorBg, chars, s, i); | |
952 w = string_draw_range (mw, window, x, y, color, colorBg, chars, i+2, i+3); | |
953 #else | |
896 x += string_draw_range (mw, window, x, y, gc, chars, s, i); | 954 x += string_draw_range (mw, window, x, y, gc, chars, s, i); |
897 w = string_draw_range (mw, window, x, y, gc, chars, i+2, i+3); | 955 w = string_draw_range (mw, window, x, y, gc, chars, i+2, i+3); |
956 #endif | |
898 | 957 |
899 /* underline next character */ | 958 /* underline next character */ |
900 XDrawLine (XtDisplay (mw), window, gc, x - 1, | 959 XDrawLine (XtDisplay (mw), window, gc, x - 1, |
901 y + mw->menu.font_ascent + 1, | 960 y + mw->menu.font_ascent + 1, |
902 x + w - 1, y + mw->menu.font_ascent + 1 ); | 961 x + w - 1, y + mw->menu.font_ascent + 1 ); |
903 x += w; | 962 x += w; |
904 s = i + 3; | 963 s = i + 3; |
905 i += 2; | 964 i += 2; |
906 } | 965 } |
907 } | 966 } |
967 #ifdef USE_XFT_MENUBARS | |
968 x += string_draw_range (mw, window, x, y, color, colorBg, chars, s, i); | |
969 #else | |
908 x += string_draw_range (mw, window, x, y, gc, chars, s, i); | 970 x += string_draw_range (mw, window, x, y, gc, chars, s, i); |
909 #ifdef NEED_MOTIF | 971 #endif |
972 #if defined(NEED_MOTIF) && !defined(USE_XFT_MENUBARS) | |
910 XtFree (chars); | 973 XtFree (chars); |
911 #endif | 974 #endif |
912 } | 975 } |
913 | 976 |
914 static void | 977 static void /* XXX */ |
915 binding_draw (XlwMenuWidget mw, Window w, int x, int y, GC gc, char *value) | 978 binding_draw (XlwMenuWidget mw, Window w, int x, int y, |
916 { | 979 #ifdef USE_XFT_MENUBARS |
917 #ifdef NEED_MOTIF | 980 XftColor *color, |
981 XftColor *colorBg, | |
982 #else | |
983 GC gc, | |
984 #endif | |
985 char *value) | |
986 { | |
987 #if defined(NEED_MOTIF) && !defined(USE_XFT_MENUBARS) | |
918 XmString xm_value = XmStringCreateLtoR(value, XmSTRING_DEFAULT_CHARSET); | 988 XmString xm_value = XmStringCreateLtoR(value, XmSTRING_DEFAULT_CHARSET); |
919 string_draw (mw, w, x, y, gc, xm_value); | 989 string_draw (mw, w, x, y, gc, xm_value); |
920 XmStringFree (xm_value); | 990 XmStringFree (xm_value); |
921 #else | 991 #else |
992 #ifdef USE_XFT_MENUBARS | |
993 string_draw (mw, w, x, y, color, colorBg, value); | |
994 #else | |
922 string_draw (mw, w, x, y, gc, value); | 995 string_draw (mw, w, x, y, gc, value); |
996 #endif | |
923 #endif | 997 #endif |
924 } | 998 } |
925 | 999 |
926 /* Low level code for drawing 3-D edges. */ | 1000 /* Low level code for drawing 3-D edges. */ |
927 static void | 1001 static void |
1560 unsigned int UNUSED (binding_tab)) | 1634 unsigned int UNUSED (binding_tab)) |
1561 { | 1635 { |
1562 int y_offset = mw->menu.shadow_thickness + mw->menu.vertical_margin; | 1636 int y_offset = mw->menu.shadow_thickness + mw->menu.vertical_margin; |
1563 GC gc; | 1637 GC gc; |
1564 | 1638 |
1639 #ifdef USE_XFT_MENUBARS | |
1640 XftColor color, colorBg; | |
1641 Display *display = XtDisplay (mw); | |
1642 Colormap cmap = mw->core.colormap; | |
1643 Visual *visual; | |
1644 int ignored, pixel, pixelBg; | |
1645 | |
1646 visual_info_from_widget ((Widget) mw, &visual, &ignored); | |
1647 #endif | |
1648 | |
1565 if (!label_offset) | 1649 if (!label_offset) |
1566 label_offset = mw->menu.shadow_thickness + mw->menu.horizontal_margin; | 1650 label_offset = mw->menu.shadow_thickness + mw->menu.horizontal_margin; |
1567 | 1651 |
1568 if (highlighted && (in_menubar || val->contents)) | 1652 if (highlighted && (in_menubar || val->contents)) |
1569 gc = mw->menu.highlight_gc; | 1653 { |
1654 #ifdef USE_XFT_MENUBARS | |
1655 pixel = mw->menu.highlight_foreground; | |
1656 pixelBg = mw->core.background_pixel; | |
1657 #endif | |
1658 gc = mw->menu.highlight_gc; | |
1659 } | |
1570 else if (in_menubar || val->contents) | 1660 else if (in_menubar || val->contents) |
1571 gc = mw->menu.foreground_gc; | 1661 { |
1662 #ifdef USE_XFT_MENUBARS | |
1663 pixel = mw->menu.foreground; | |
1664 pixelBg = mw->core.background_pixel; | |
1665 #endif | |
1666 gc = mw->menu.foreground_gc; | |
1667 } | |
1572 else | 1668 else |
1573 gc = mw->menu.title_gc; | 1669 { |
1670 #ifdef USE_XFT_MENUBARS | |
1671 pixel = mw->menu.title_foreground; | |
1672 pixelBg = mw->core.background_pixel; | |
1673 #endif | |
1674 gc = mw->menu.title_gc; | |
1675 } | |
1676 #ifdef USE_XFT_MENUBARS | |
1677 color = xft_convert_color (display, cmap, visual, pixel, 0); | |
1678 colorBg = xft_convert_color (display, cmap, visual, pixelBg, 0); | |
1679 #endif | |
1574 | 1680 |
1575 /* Draw the label string. */ | 1681 /* Draw the label string. */ |
1576 string_draw_u (mw, | 1682 string_draw_u (mw, /* XXX */ |
1577 window, | 1683 window, |
1578 x + label_offset, y + y_offset, | 1684 x + label_offset, y + y_offset, |
1685 #ifdef USE_XFT_MENUBARS | |
1686 &color, &colorBg, gc, | |
1687 #else | |
1579 gc, | 1688 gc, |
1689 #endif | |
1580 resource_widget_value (mw, val)); | 1690 resource_widget_value (mw, val)); |
1581 } | 1691 } |
1582 | 1692 |
1583 static void | 1693 static void |
1584 push_button_size (XlwMenuWidget mw, | 1694 push_button_size (XlwMenuWidget mw, |
1596 | 1706 |
1597 /* key bindings to display? */ | 1707 /* key bindings to display? */ |
1598 if (!in_menubar && val->key) | 1708 if (!in_menubar && val->key) |
1599 { | 1709 { |
1600 int w; | 1710 int w; |
1601 #ifdef NEED_MOTIF | 1711 #if defined(NEED_MOTIF) && !defined(USE_XFT_MENUBARS) |
1602 XmString key = XmStringCreateLtoR (val->key, XmSTRING_DEFAULT_CHARSET); | 1712 XmString key = XmStringCreateLtoR (val->key, XmSTRING_DEFAULT_CHARSET); |
1603 w = string_width (mw, key); | 1713 w = string_width (mw, key); |
1604 XmStringFree (key); | 1714 XmStringFree (key); |
1605 #else | 1715 #else |
1606 char *key = val->key; | 1716 char *key = val->key; |
1625 int y_offset = mw->menu.shadow_thickness + mw->menu.vertical_margin; | 1735 int y_offset = mw->menu.shadow_thickness + mw->menu.vertical_margin; |
1626 GC gc; | 1736 GC gc; |
1627 shadow_type type; | 1737 shadow_type type; |
1628 Boolean menu_pb = in_menubar && (menu_item_type (val) == BUTTON_TYPE); | 1738 Boolean menu_pb = in_menubar && (menu_item_type (val) == BUTTON_TYPE); |
1629 | 1739 |
1740 #ifdef USE_XFT_MENUBARS | |
1741 XftColor color, colorBg; | |
1742 Display *display = XtDisplay (mw); | |
1743 Colormap cmap = mw->core.colormap; | |
1744 Visual *visual; | |
1745 int ignored, pixel, pixelBg, dim = 0; | |
1746 | |
1747 visual_info_from_widget ((Widget) mw, &visual, &ignored); | |
1748 #endif | |
1749 | |
1630 /* Draw the label string. */ | 1750 /* Draw the label string. */ |
1631 if (!label_offset) | 1751 if (!label_offset) |
1632 label_offset = mw->menu.shadow_thickness + mw->menu.horizontal_margin; | 1752 label_offset = mw->menu.shadow_thickness + mw->menu.horizontal_margin; |
1633 | 1753 |
1634 if (highlighted) | 1754 if (highlighted) |
1635 { | 1755 { |
1636 if (val->enabled) | 1756 if (val->enabled) |
1637 gc = mw->menu.highlight_gc; | 1757 { |
1758 #ifdef USE_XFT_MENUBARS | |
1759 pixel = mw->menu.highlight_foreground; | |
1760 pixelBg = mw->core.background_pixel; | |
1761 #endif | |
1762 gc = mw->menu.highlight_gc; | |
1763 } | |
1638 else | 1764 else |
1639 gc = mw->menu.inactive_gc; | 1765 { |
1766 #ifdef USE_XFT_MENUBARS | |
1767 dim = 1; | |
1768 pixel = mw->menu.foreground; | |
1769 pixelBg = mw->core.background_pixel; | |
1770 #endif | |
1771 gc = mw->menu.inactive_gc; | |
1772 } | |
1640 } | 1773 } |
1641 else if (menu_pb) | 1774 else if (menu_pb) |
1642 { | 1775 { |
1643 if (val->enabled) | 1776 if (val->enabled) |
1644 gc = mw->menu.button_gc; | 1777 { |
1778 #ifdef USE_XFT_MENUBARS | |
1779 pixel = mw->menu.button_foreground; | |
1780 pixelBg = mw->core.background_pixel; | |
1781 #endif | |
1782 gc = mw->menu.button_gc; | |
1783 } | |
1645 else | 1784 else |
1646 gc = mw->menu.inactive_button_gc; | 1785 { |
1786 #ifdef USE_XFT_MENUBARS | |
1787 dim = 1; | |
1788 pixel = mw->menu.button_foreground; | |
1789 pixelBg = mw->core.background_pixel; | |
1790 #endif | |
1791 gc = mw->menu.inactive_button_gc; | |
1792 } | |
1647 } | 1793 } |
1648 else | 1794 else |
1649 { | 1795 { |
1650 if (val->enabled) | 1796 if (val->enabled) |
1651 gc = mw->menu.foreground_gc; | 1797 { |
1798 #ifdef USE_XFT_MENUBARS | |
1799 pixel = mw->menu.foreground; | |
1800 pixelBg = mw->core.background_pixel; | |
1801 #endif | |
1802 gc = mw->menu.foreground_gc; | |
1803 } | |
1652 else | 1804 else |
1653 gc = mw->menu.inactive_gc; | 1805 { |
1654 } | 1806 #ifdef USE_XFT_MENUBARS |
1807 dim = 1; | |
1808 pixel = mw->menu.foreground; | |
1809 pixelBg = mw->core.background_pixel; | |
1810 #endif | |
1811 gc = mw->menu.inactive_gc; | |
1812 } | |
1813 } | |
1814 | |
1815 #ifdef USE_XFT_MENUBARS | |
1816 color = xft_convert_color (display, cmap, visual, pixel, dim); | |
1817 colorBg = xft_convert_color (display, cmap, visual, pixelBg, 0); | |
1818 #endif | |
1655 | 1819 |
1656 string_draw_u (mw, | 1820 string_draw_u (mw, |
1657 window, | 1821 window, |
1658 x + label_offset, y + y_offset, | 1822 x + label_offset, y + y_offset, |
1659 gc, | 1823 #ifdef USE_XFT_MENUBARS |
1824 &color, &colorBg, gc, | |
1825 #else | |
1826 gc, | |
1827 #endif | |
1660 resource_widget_value (mw, val)); | 1828 resource_widget_value (mw, val)); |
1661 | 1829 |
1662 /* Draw the keybindings */ | 1830 /* Draw the keybindings */ |
1663 if (val->key) | 1831 if (val->key) |
1664 { | 1832 { |
1668 string_width (mw, resource_widget_value (mw, val)); | 1836 string_width (mw, resource_widget_value (mw, val)); |
1669 binding_offset = label_offset + s_width + mw->menu.shadow_thickness; | 1837 binding_offset = label_offset + s_width + mw->menu.shadow_thickness; |
1670 } | 1838 } |
1671 binding_draw (mw, window, | 1839 binding_draw (mw, window, |
1672 x + binding_offset + mw->menu.column_spacing, | 1840 x + binding_offset + mw->menu.column_spacing, |
1673 y + y_offset, gc, val->key); | 1841 y + y_offset, |
1842 #ifdef USE_XFT_MENUBARS | |
1843 &color, &colorBg, | |
1844 #else | |
1845 gc, | |
1846 #endif | |
1847 val->key); | |
1674 } | 1848 } |
1675 | 1849 |
1676 /* Draw the shadow */ | 1850 /* Draw the shadow */ |
1677 if (menu_pb) | 1851 if (menu_pb) |
1678 { | 1852 { |
2334 | 2508 |
2335 if (mw->menu.windows_length >= n) | 2509 if (mw->menu.windows_length >= n) |
2336 return; | 2510 return; |
2337 | 2511 |
2338 root = RootWindowOfScreen (XtScreen(mw)); | 2512 root = RootWindowOfScreen (XtScreen(mw)); |
2513 /* use visual_info_from_widget() from lwlib-colors.c */ | |
2339 /* grab the visual and depth from the nearest shell ancestor */ | 2514 /* grab the visual and depth from the nearest shell ancestor */ |
2340 visual = CopyFromParent; | 2515 visual = CopyFromParent; |
2341 depth = CopyFromParent; | 2516 depth = CopyFromParent; |
2342 p = XtParent(mw); | 2517 p = XtParent(mw); |
2343 while (visual == CopyFromParent && p) | 2518 while (visual == CopyFromParent && p) |
2613 /* Procedures */ | 2788 /* Procedures */ |
2614 static void | 2789 static void |
2615 make_drawing_gcs (XlwMenuWidget mw) | 2790 make_drawing_gcs (XlwMenuWidget mw) |
2616 { | 2791 { |
2617 XGCValues xgcv; | 2792 XGCValues xgcv; |
2793 #ifdef USE_XFT_MENUBARS | |
2794 unsigned long flags = (GCForeground | GCBackground); | |
2795 #else | |
2618 unsigned long flags = (GCFont | GCForeground | GCBackground); | 2796 unsigned long flags = (GCFont | GCForeground | GCBackground); |
2619 | 2797 #endif |
2620 #ifdef NEED_MOTIF | 2798 |
2799 #if defined(NEED_MOTIF) && !defined(USE_XFT_MENUBARS) | |
2621 xgcv.font = default_font_of_font_list (mw->menu.font_list)->fid; | 2800 xgcv.font = default_font_of_font_list (mw->menu.font_list)->fid; |
2622 #else | 2801 #else |
2802 #ifndef USE_XFT_MENUBARS | |
2623 xgcv.font = mw->menu.font->fid; | 2803 xgcv.font = mw->menu.font->fid; |
2804 #endif | |
2624 #endif | 2805 #endif |
2625 | 2806 |
2626 xgcv.foreground = mw->core.background_pixel; | 2807 xgcv.foreground = mw->core.background_pixel; |
2627 xgcv.background = mw->menu.foreground; | 2808 xgcv.background = mw->menu.foreground; |
2628 mw->menu.background_gc = XtGetGC ((Widget) mw, flags, &xgcv); | 2809 mw->menu.background_gc = XtGetGC ((Widget) mw, flags, &xgcv); |
2643 xgcv.foreground = mw->menu.foreground; | 2824 xgcv.foreground = mw->menu.foreground; |
2644 } | 2825 } |
2645 else | 2826 else |
2646 { /* color */ | 2827 { /* color */ |
2647 XColor xcolor; | 2828 XColor xcolor; |
2829 Visual *visual; | |
2830 int ignore; | |
2831 visual_info_from_widget ((Widget) mw, &visual, &ignore); | |
2648 Colormap cmap = mw->core.colormap; | 2832 Colormap cmap = mw->core.colormap; |
2649 xcolor.pixel = mw->core.background_pixel; | 2833 xcolor.pixel = mw->core.background_pixel; |
2650 XQueryColor (dpy, cmap, &xcolor); | 2834 XQueryColor (dpy, cmap, &xcolor); |
2651 xcolor.red = (xcolor.red * 17) / 20; | 2835 xcolor.red = (xcolor.red * 17) / 20; |
2652 xcolor.green = (xcolor.green * 17) / 20; | 2836 xcolor.green = (xcolor.green * 17) / 20; |
2653 xcolor.blue = (xcolor.blue * 17) / 20; | 2837 xcolor.blue = (xcolor.blue * 17) / 20; |
2654 if (allocate_nearest_color (dpy, cmap, &xcolor)) | 2838 if (x_allocate_nearest_color (dpy, cmap, visual, &xcolor)) |
2655 xgcv.foreground = xcolor.pixel; | 2839 xgcv.foreground = xcolor.pixel; |
2656 } | 2840 } |
2657 } | 2841 } |
2658 xgcv.background = mw->core.background_pixel; | 2842 xgcv.background = mw->core.background_pixel; |
2659 mw->menu.select_gc = XtGetGC ((Widget)mw, flags, &xgcv); | 2843 mw->menu.select_gc = XtGetGC ((Widget) mw, flags, &xgcv); |
2660 | 2844 |
2661 xgcv.foreground = mw->menu.foreground; | 2845 xgcv.foreground = mw->menu.foreground; |
2662 xgcv.background = mw->core.background_pixel; | 2846 xgcv.background = mw->core.background_pixel; |
2663 xgcv.fill_style = FillStippled; | 2847 xgcv.fill_style = FillStippled; |
2664 xgcv.stipple = mw->menu.gray_pixmap; | 2848 xgcv.stipple = mw->menu.gray_pixmap; |
2686 } | 2870 } |
2687 | 2871 |
2688 static void | 2872 static void |
2689 release_drawing_gcs (XlwMenuWidget mw) | 2873 release_drawing_gcs (XlwMenuWidget mw) |
2690 { | 2874 { |
2875 | |
2691 XtReleaseGC ((Widget) mw, mw->menu.foreground_gc); | 2876 XtReleaseGC ((Widget) mw, mw->menu.foreground_gc); |
2692 XtReleaseGC ((Widget) mw, mw->menu.button_gc); | 2877 XtReleaseGC ((Widget) mw, mw->menu.button_gc); |
2693 XtReleaseGC ((Widget) mw, mw->menu.highlight_gc); | 2878 XtReleaseGC ((Widget) mw, mw->menu.highlight_gc); |
2694 XtReleaseGC ((Widget) mw, mw->menu.title_gc); | 2879 XtReleaseGC ((Widget) mw, mw->menu.title_gc); |
2695 XtReleaseGC ((Widget) mw, mw->menu.inactive_gc); | 2880 XtReleaseGC ((Widget) mw, mw->menu.inactive_gc); |
2705 mw->menu.inactive_button_gc = (GC) -1; | 2890 mw->menu.inactive_button_gc = (GC) -1; |
2706 mw->menu.background_gc = (GC) -1; | 2891 mw->menu.background_gc = (GC) -1; |
2707 mw->menu.select_gc = (GC) -1; | 2892 mw->menu.select_gc = (GC) -1; |
2708 } | 2893 } |
2709 | 2894 |
2710 #define MINL(x,y) ((((unsigned long) (x)) < ((unsigned long) (y))) \ | |
2711 ? ((unsigned long) (x)) : ((unsigned long) (y))) | |
2712 | |
2713 static void | 2895 static void |
2714 make_shadow_gcs (XlwMenuWidget mw) | 2896 make_shadow_gcs (XlwMenuWidget mw) |
2715 { | 2897 { |
2716 XGCValues xgcv; | 2898 XGCValues xgcv; |
2717 unsigned long pm = 0; | 2899 unsigned long pm = 0; |
2718 Display *dpy = XtDisplay ((Widget) mw); | 2900 Display *dpy = XtDisplay ((Widget) mw); |
2719 Colormap cmap = mw->core.colormap; | 2901 Colormap cmap = mw->core.colormap; |
2902 Visual *visual; | |
2903 int ignored; | |
2720 XColor topc, botc; | 2904 XColor topc, botc; |
2721 int top_frobbed = 0, bottom_frobbed = 0; | 2905 int top_frobbed = 0, bottom_frobbed = 0; |
2906 | |
2907 visual_info_from_widget ((Widget) mw, &visual, &ignored); | |
2908 /* #### Apparently this is called before any shell has a visual? | |
2909 or maybe the widget doesn't have a parent yet? */ | |
2910 if (visual == CopyFromParent) | |
2911 { | |
2912 Screen *screen = DefaultScreenOfDisplay (dpy); | |
2913 visual = DefaultVisualOfScreen (screen); | |
2914 } | |
2722 | 2915 |
2723 if (mw->menu.top_shadow_color == (Pixel) (-1)) | 2916 if (mw->menu.top_shadow_color == (Pixel) (-1)) |
2724 mw->menu.top_shadow_color = mw->core.background_pixel; | 2917 mw->menu.top_shadow_color = mw->core.background_pixel; |
2725 if (mw->menu.bottom_shadow_color == (Pixel) (-1)) | 2918 if (mw->menu.bottom_shadow_color == (Pixel) (-1)) |
2726 mw->menu.bottom_shadow_color = mw->menu.foreground; | 2919 mw->menu.bottom_shadow_color = mw->menu.foreground; |
2732 XQueryColor (dpy, cmap, &topc); | 2925 XQueryColor (dpy, cmap, &topc); |
2733 /* don't overflow/wrap! */ | 2926 /* don't overflow/wrap! */ |
2734 topc.red = MINL (65535, topc.red * 1.2); | 2927 topc.red = MINL (65535, topc.red * 1.2); |
2735 topc.green = MINL (65535, topc.green * 1.2); | 2928 topc.green = MINL (65535, topc.green * 1.2); |
2736 topc.blue = MINL (65535, topc.blue * 1.2); | 2929 topc.blue = MINL (65535, topc.blue * 1.2); |
2737 if (allocate_nearest_color (dpy, cmap, &topc)) | 2930 if (x_allocate_nearest_color (dpy, cmap, visual, &topc)) |
2738 { | 2931 { |
2739 if (topc.pixel == mw->core.background_pixel) | 2932 if (topc.pixel == mw->core.background_pixel) |
2740 { | 2933 { |
2741 XFreeColors( dpy, cmap, &topc.pixel, 1, 0); | 2934 XFreeColors( dpy, cmap, &topc.pixel, 1, 0); |
2742 topc.red = MINL (65535, topc.red + 0x8000); | 2935 topc.red = MINL (65535, topc.red + 0x8000); |
2743 topc.green = MINL (65535, topc.green + 0x8000); | 2936 topc.green = MINL (65535, topc.green + 0x8000); |
2744 topc.blue = MINL (65535, topc.blue + 0x8000); | 2937 topc.blue = MINL (65535, topc.blue + 0x8000); |
2745 if (allocate_nearest_color (dpy, cmap, &topc)) | 2938 if (x_allocate_nearest_color (dpy, cmap, visual, &topc)) |
2746 { | 2939 { |
2747 mw->menu.top_shadow_color = topc.pixel; | 2940 mw->menu.top_shadow_color = topc.pixel; |
2748 } | 2941 } |
2749 } | 2942 } |
2750 else | 2943 else |
2761 botc.pixel = mw->core.background_pixel; | 2954 botc.pixel = mw->core.background_pixel; |
2762 XQueryColor (dpy, cmap, &botc); | 2955 XQueryColor (dpy, cmap, &botc); |
2763 botc.red = (botc.red * 3) / 5; | 2956 botc.red = (botc.red * 3) / 5; |
2764 botc.green = (botc.green * 3) / 5; | 2957 botc.green = (botc.green * 3) / 5; |
2765 botc.blue = (botc.blue * 3) / 5; | 2958 botc.blue = (botc.blue * 3) / 5; |
2766 if (allocate_nearest_color (dpy, cmap, &botc)) | 2959 if (x_allocate_nearest_color (dpy, cmap, visual, &botc)) |
2767 { | 2960 { |
2768 if (botc.pixel == mw->core.background_pixel) | 2961 if (botc.pixel == mw->core.background_pixel) |
2769 { | 2962 { |
2770 XFreeColors (dpy, cmap, &botc.pixel, 1, 0); | 2963 XFreeColors (dpy, cmap, &botc.pixel, 1, 0); |
2771 botc.red = MINL (65535, botc.red + 0x4000); | 2964 botc.red = MINL (65535, botc.red + 0x4000); |
2772 botc.green = MINL (65535, botc.green + 0x4000); | 2965 botc.green = MINL (65535, botc.green + 0x4000); |
2773 botc.blue = MINL (65535, botc.blue + 0x4000); | 2966 botc.blue = MINL (65535, botc.blue + 0x4000); |
2774 if (allocate_nearest_color (dpy, cmap, &botc)) | 2967 if (x_allocate_nearest_color (dpy, cmap, visual, &botc)) |
2775 { | 2968 { |
2776 mw->menu.bottom_shadow_color = botc.pixel; | 2969 mw->menu.bottom_shadow_color = botc.pixel; |
2777 } | 2970 } |
2778 } | 2971 } |
2779 else | 2972 else |
2852 | 3045 |
2853 | 3046 |
2854 static void | 3047 static void |
2855 extract_font_extents (XlwMenuWidget mw) | 3048 extract_font_extents (XlwMenuWidget mw) |
2856 { | 3049 { |
2857 #ifdef NEED_MOTIF | 3050 #if defined(NEED_MOTIF) && !defined(USE_XFT_MENUBARS) |
2858 /* Find the maximal ascent/descent of the fonts in the font list | 3051 /* Find the maximal ascent/descent of the fonts in the font list |
2859 so that all menu items can be the same height... */ | 3052 so that all menu items can be the same height... */ |
2860 mw->menu.font_ascent = 0; | 3053 mw->menu.font_ascent = 0; |
2861 mw->menu.font_descent = 0; | 3054 mw->menu.font_descent = 0; |
2862 | 3055 |
2937 mw->menu.font_ascent = font->ascent; | 3130 mw->menu.font_ascent = font->ascent; |
2938 if (font->descent > (int) mw->menu.font_descent) | 3131 if (font->descent > (int) mw->menu.font_descent) |
2939 mw->menu.font_descent = font->descent; | 3132 mw->menu.font_descent = font->descent; |
2940 } | 3133 } |
2941 # else /* ! USE_XFONTSET */ | 3134 # else /* ! USE_XFONTSET */ |
3135 #ifdef USE_XFT_MENUBARS | |
3136 mw->menu.font_ascent = mw->menu.renderFont->ascent; | |
3137 mw->menu.font_descent = mw->menu.renderFont->descent; | |
3138 #else | |
2942 mw->menu.font_ascent = mw->menu.font->ascent; | 3139 mw->menu.font_ascent = mw->menu.font->ascent; |
2943 mw->menu.font_descent = mw->menu.font->descent; | 3140 mw->menu.font_descent = mw->menu.font->descent; |
3141 #endif | |
2944 # endif | 3142 # endif |
2945 #endif /* NEED_MOTIF */ | 3143 #endif /* NEED_MOTIF */ |
2946 } | 3144 } |
2947 | 3145 |
2948 #ifdef NEED_MOTIF | 3146 #if defined(NEED_MOTIF) && !defined(USE_XFT_MENUBARS) |
2949 static XFontStruct * | 3147 static XFontStruct * |
2950 default_font_of_font_list (XmFontList font_list) | 3148 default_font_of_font_list (XmFontList font_list) |
2951 { | 3149 { |
2952 XFontStruct *font = 0; | 3150 XFontStruct *font = 0; |
2953 # if 0 | 3151 # if 0 |
3013 | 3211 |
3014 mw->menu.gray_pixmap = | 3212 mw->menu.gray_pixmap = |
3015 XCreatePixmapFromBitmapData (display, window, (char *) gray_bits, | 3213 XCreatePixmapFromBitmapData (display, window, (char *) gray_bits, |
3016 gray_width, gray_height, 1, 0, 1); | 3214 gray_width, gray_height, 1, 0, 1); |
3017 | 3215 |
3018 #ifdef NEED_MOTIF | 3216 #if defined(NEED_MOTIF) && !defined(USE_XFT_MENUBARS) |
3019 /* #### Even if it's a kludge!!!, we should consider doing the same for | 3217 /* #### Even if it's a kludge!!!, we should consider doing the same for |
3020 X Font Sets. */ | 3218 X Font Sets. */ |
3021 /* The menu.font_list slot came from the *fontList resource (Motif standard.) | 3219 /* The menu.font_list slot came from the *fontList resource (Motif standard.) |
3022 The menu.font_list_2 slot came from the *font resource, for backward | 3220 The menu.font_list_2 slot came from the *font resource, for backward |
3023 compatibility with older versions of this code, and consistency with the | 3221 compatibility with older versions of this code, and consistency with the |
3033 ; | 3231 ; |
3034 else if (mw->menu.font_list_2) /* else if *font is specified, use that */ | 3232 else if (mw->menu.font_list_2) /* else if *font is specified, use that */ |
3035 mw->menu.font_list = mw->menu.font_list_2; | 3233 mw->menu.font_list = mw->menu.font_list_2; |
3036 else /* otherwise use default */ | 3234 else /* otherwise use default */ |
3037 mw->menu.font_list = mw->menu.fallback_font_list; | 3235 mw->menu.font_list = mw->menu.fallback_font_list; |
3236 #endif | |
3237 | |
3238 #ifdef USE_XFT_MENUBARS | |
3239 /* to do this right, we should add a new Xt Resource type + | |
3240 conversion function | |
3241 */ | |
3242 mw->menu.renderFont = | |
3243 xft_open_font_by_name (XtDisplay (mw), mw->menu.renderFontSpec); | |
3038 #endif | 3244 #endif |
3039 | 3245 |
3040 make_drawing_gcs (mw); | 3246 make_drawing_gcs (mw); |
3041 make_shadow_gcs (mw); | 3247 make_shadow_gcs (mw); |
3042 extract_font_extents (mw); | 3248 extract_font_extents (mw); |
3177 redisplay = True; | 3383 redisplay = True; |
3178 | 3384 |
3179 if (newmw->core.background_pixel != oldmw->core.background_pixel | 3385 if (newmw->core.background_pixel != oldmw->core.background_pixel |
3180 || newmw->menu.foreground != oldmw->menu.foreground | 3386 || newmw->menu.foreground != oldmw->menu.foreground |
3181 /* For the XEditResource protocol, which may want to change the font. */ | 3387 /* For the XEditResource protocol, which may want to change the font. */ |
3182 #ifdef NEED_MOTIF | 3388 #if defined(NEED_MOTIF) && !defined(USE_XFT_MENUBARS) |
3183 || newmw->menu.font_list != oldmw->menu.font_list | 3389 || newmw->menu.font_list != oldmw->menu.font_list |
3184 || newmw->menu.font_list_2 != oldmw->menu.font_list_2 | 3390 || newmw->menu.font_list_2 != oldmw->menu.font_list_2 |
3185 || newmw->menu.fallback_font_list != oldmw->menu.fallback_font_list | 3391 || newmw->menu.fallback_font_list != oldmw->menu.fallback_font_list |
3186 #else | 3392 #else |
3393 #ifdef USE_XFT_MENUBARS | |
3394 || newmw->menu.renderFont != oldmw->menu.renderFont | |
3395 #else | |
3187 || newmw->menu.font != oldmw->menu.font | 3396 || newmw->menu.font != oldmw->menu.font |
3397 #endif | |
3188 #endif | 3398 #endif |
3189 ) | 3399 ) |
3190 { | 3400 { |
3191 release_drawing_gcs (newmw); | 3401 release_drawing_gcs (newmw); |
3192 make_drawing_gcs (newmw); | 3402 make_drawing_gcs (newmw); |