comparison lwlib/xlwmenu.c @ 193:f53b5ca2e663 r20-3b23

Import from CVS: tag r20-3b23
author cvs
date Mon, 13 Aug 2007 09:58:30 +0200
parents 3d6bfa290dbd
children a2f645c6b9f8
comparison
equal deleted inserted replaced
192:9d35321dd38c 193:f53b5ca2e663
388 } 388 }
389 389
390 static int 390 static int
391 string_width_u (XlwMenuWidget mw, 391 string_width_u (XlwMenuWidget mw,
392 #ifdef NEED_MOTIF 392 #ifdef NEED_MOTIF
393 XmString s 393 XmString string
394 #else 394 #else
395 char *string 395 char *string
396 #endif 396 #endif
397 ) 397 )
398 { 398 {
399 #ifdef NEED_MOTIF 399 #ifdef NEED_MOTIF
400 Dimension width, height; 400 Dimension width, height;
401 XmStringExtent (mw->menu.font_list, s, &width, &height); 401 XmString newstring;
402 #else
403 # ifdef USE_XFONTSET
404 XRectangle ri, rl;
405 # else /* ! USE_XFONTSET */
406 XCharStruct xcs;
407 int drop;
408 # endif
409 #endif
410 char newchars[64];
411 char *chars;
412 int i, j;
413
414 #ifdef NEED_MOTIF
415 XmStringGetLtoR (string, XmFONTLIST_DEFAULT_TAG, &chars);
416 #else
417 chars = string;
418 #endif
419
420 for (i = j = 0; chars[i]; i++)
421 if (chars[i]=='%'&&chars[i+1]=='_')
422 i++;
423 else
424 newchars[j++] = chars[i];
425 newchars[j] = '\0';
426
427 #ifdef NEED_MOTIF
428 newstring = XmStringLtoRCreate (newchars, XmFONTLIST_DEFAULT_TAG);
429 XmStringExtent (mw->menu.font_list, newstring, &width, &height);
430 XmStringFree(newstring);
402 return width; 431 return width;
403 #else 432 #else
404 # ifdef USE_XFONTSET 433 # ifdef USE_XFONTSET
405 XRectangle ri, rl; 434 int i, s=0, w=0;
406 XmbTextExtents (mw->menu.font_set, string, strlen (string), &ri, &rl); 435 for (i=0; string[i]; ++i) {
407 return rl.width; 436 if (string[i]=='%' && string[i+1]=='_') {
408 # else /* ! USE_XFONTSET */ 437 XmbTextExtents(mw->menu.font_set, &string[s], i-s, &ri, &rl);
409 XCharStruct xcs; 438 w += rl.width;
410 int i,s=0,w=0;
411 int drop;
412 for (i=0;string[i];++i) {
413 if (string[i]=='%'&&string[i+1]=='_') {
414 XTextExtents (mw->menu.font, &string[s], i-s, &drop, &drop, &drop, &xcs);
415 w += xcs.width;
416 s = i + 2; 439 s = i + 2;
417 ++i; 440 ++i;
418 } 441 }
419 } 442 }
420 if (string[s]) { 443 if (string[s]) {
421 XTextExtents (mw->menu.font, &string[s], i-s, &drop, &drop, &drop, &xcs); 444 XmbTextExtents(mw->menu.font_set, &string[s], i-s, &ri, &rl);
422 w += xcs.width; 445 w += rl.width;
423 } 446 }
424 return w; 447 return w;
448 # else /* ! USE_XFONTSET */
449 XTextExtents (mw->menu.font, newchars, j, &drop, &drop, &drop, &xcs);
450 return xcs.width;
425 # endif /* USE_XFONTSET */ 451 # endif /* USE_XFONTSET */
426 #endif 452 #endif
427 } 453 }
428 454
429 static void 455 static void
766 # endif /* USE_XFONTSET */ 792 # endif /* USE_XFONTSET */
767 793
768 #endif 794 #endif
769 } 795 }
770 796
797 static int
798 string_draw_range (
799 XlwMenuWidget mw,
800 Window window,
801 int x, int y,
802 GC gc,
803 char *string,
804 int start,
805 int end
806 )
807 {
808 #ifdef NEED_MOTIF
809 Dimension width, height;
810 XmString newstring;
811 int c;
812
813 if (end <= start)
814 return 0;
815 c = string[end];
816 string[end] = '\0';
817 newstring = XmStringLtoRCreate (&string[start], XmFONTLIST_DEFAULT_TAG);
818 XmStringDraw (
819 XtDisplay (mw), window,
820 mw->menu.font_list,
821 newstring, gc,
822 x, y,
823 1000, /* ???? width */
824 XmALIGNMENT_BEGINNING,
825 0, /* ???? layout_direction */
826 0
827 );
828 XmStringExtent (mw->menu.font_list, newstring, &width, &height);
829 XmStringFree (newstring);
830 string[end] = c;
831 return width;
832 #else
833 # ifdef USE_XFONTSET
834 XRectangle ri, rl;
835
836 if (end <= start)
837 return 0;
838 XmbDrawString (
839 XtDisplay (mw), window, mw->menu.font_set, gc,
840 x, y + mw->menu.font_ascent, &string[start], i-s
841 );
842 XmbTextExtents (
843 mw->menu.font_set, &string[start], end - start, &ri, &rl
844 );
845 return rl.width;
846 # else
847 XCharStruct xcs;
848 int drop;
849
850 if (end <= start)
851 return 0;
852 XDrawString (
853 XtDisplay (mw), window, gc,
854 x, y + mw->menu.font_ascent, &string[start], end - start);
855 XTextExtents (
856 mw->menu.font, &string[start], end - start,
857 &drop, &drop, &drop, &xcs);
858 return xcs.width;
859 # endif
860 #endif
861 }
862
771 static void 863 static void
772 string_draw_u (XlwMenuWidget mw, 864 string_draw_u (XlwMenuWidget mw,
773 Window window, 865 Window window,
774 int x, int y, 866 int x, int y,
775 GC gc, 867 GC gc,
778 #else 870 #else
779 char *string 871 char *string
780 #endif 872 #endif
781 ) 873 )
782 { 874 {
875 int i,s=0;
876 char *chars;
877
783 #ifdef NEED_MOTIF 878 #ifdef NEED_MOTIF
784 XmStringDraw (XtDisplay (mw), window, 879 XmStringGetLtoR (string, XmFONTLIST_DEFAULT_TAG, &chars);
785 mw->menu.font_list,
786 string, gc,
787 x, y,
788 1000, /* ???? width */
789 XmALIGNMENT_BEGINNING,
790 0, /* ???? layout_direction */
791 0);
792 #else 880 #else
793 int i,s=0; 881 chars = string;
794 for (i=0;string[i];++i) { 882 #endif
795 if (string[i]=='%'&&string[i+1]=='_') { 883 for (i=0;chars[i];++i) {
796 XCharStruct xcs; 884 if (chars[i]=='%'&&chars[i+1]=='_') {
797 int drop; 885 int w;
886
887 x += string_draw_range (mw, window, x, y, gc, chars, s, i);
888 w = string_draw_range (mw, window, x, y, gc, chars, i+2, i+3);
889
798 /* underline next character */ 890 /* underline next character */
799 if (i>s)
800 # ifdef USE_XFONTSET
801 XmbDrawString (XtDisplay (mw), window, mw->menu.font_set, gc,
802 x, y + mw->menu.font_ascent, &string[s], i-s);
803 # else
804 XDrawString (XtDisplay (mw), window, gc,
805 x, y + mw->menu.font_ascent, &string[s], i-s);
806 # endif /* USE_XFONTSET */
807
808 XTextExtents (mw->menu.font, &string[s], i-s, &drop, &drop, &drop,
809 &xcs);
810 x += xcs.width;
811
812 s=i+3;
813 i+=2;
814
815 # ifdef USE_XFONTSET
816 XmbDrawString (XtDisplay (mw), window, mw->menu.font_set, gc,
817 x, y + mw->menu.font_ascent, &string[i], 1);
818 # else
819 XDrawString (XtDisplay (mw), window, gc,
820 x, y + mw->menu.font_ascent, &string[i], 1);
821 # endif /* USE_XFONTSET */
822
823 XTextExtents (mw->menu.font, &string[i], 1, &drop, &drop, &drop,
824 &xcs);
825
826 XDrawLine (XtDisplay (mw), window, gc, x - 1, 891 XDrawLine (XtDisplay (mw), window, gc, x - 1,
827 y + mw->menu.font_ascent + 1, 892 y + mw->menu.font_ascent + 1,
828 x + xcs.width - 1, y + mw->menu.font_ascent + 1 ); 893 x + w - 1, y + mw->menu.font_ascent + 1 );
829 894 x += w;
830 x += xcs.width; 895 s = i + 3;
896 i += 2;
831 } 897 }
832 } 898 }
833 if (string[s]) 899 x += string_draw_range (mw, window, x, y, gc, chars, s, i);
834 # ifdef USE_XFONTSET
835 XmbDrawString (XtDisplay (mw), window, mw->menu.font_set, gc,
836 x, y + mw->menu.font_ascent, &string[s],
837 strlen (&string[s]));
838 # else
839 XDrawString (XtDisplay (mw), window, gc,
840 x, y + mw->menu.font_ascent, &string[s],
841 strlen (&string[s]));
842 # endif /* USE_XFONTSET */
843 #endif /* NEED_MOTIF */
844 } 900 }
845 901
846 static void 902 static void
847 binding_draw (XlwMenuWidget mw, Window w, int x, int y, GC gc, char *value) 903 binding_draw (XlwMenuWidget mw, Window w, int x, int y, GC gc, char *value)
848 { 904 {