comparison lwlib/xlwmenu.c @ 412:697ef44129c6 r21-2-14

Import from CVS: tag r21-2-14
author cvs
date Mon, 13 Aug 2007 11:20:41 +0200
parents de805c49cfc1
children da8ed4261e83
comparison
equal deleted inserted replaced
411:12e008d41344 412:697ef44129c6
455 # endif /* USE_XFONTSET */ 455 # endif /* USE_XFONTSET */
456 #endif 456 #endif
457 } 457 }
458 458
459 static void 459 static void
460 massage_resource_name (const char *in, char *out) 460 massage_resource_name (CONST char *in, char *out)
461 { 461 {
462 /* Turn a random string into something suitable for using as a resource. 462 /* Turn a random string into something suitable for using as a resource.
463 For example: 463 For example:
464 464
465 "Kill Buffer" -> "killBuffer" 465 "Kill Buffer" -> "killBuffer"
477 #endif 477 #endif
478 478
479 Boolean firstp = True; 479 Boolean firstp = True;
480 while (*in) 480 while (*in)
481 { 481 {
482 if (*in == '%' && *(in + 1) == '_') 482 char ch = massaged_resource_char[(unsigned char) *in++];
483 in += 2; 483 if (ch)
484 else
485 { 484 {
486 char ch; 485 int int_ch = (int) (unsigned char) ch;
487 486 *out++ = firstp ? tolower (int_ch) : toupper (int_ch);
488 if (*in == '%' && *(in + 1) == '%') 487 firstp = False;
489 in++; 488 while ((ch = massaged_resource_char[(unsigned char) *in++]) != '\0')
490 ch = massaged_resource_char[(unsigned char) *in++]; 489 *out++ = ch;
491 if (ch) 490 if (!*(in-1)) /* Overshot the NULL byte? */
492 { 491 break;
493 int int_ch = (int) (unsigned char) ch;
494 *out++ = firstp ? tolower (int_ch) : toupper (int_ch);
495 firstp = False;
496 while ((ch = massaged_resource_char[(unsigned char) *in++])
497 != '\0')
498 *out++ = ch;
499 if (!*(in-1)) /* Overshot the NULL byte? */
500 break;
501 }
502 } 492 }
503 } 493 }
504 *out = 0; 494 *out = 0;
505 495
506 #ifdef PRINT_XLWMENU_RESOURCE_CONVERSIONS 496 #ifdef PRINT_XLWMENU_RESOURCE_CONVERSIONS
514 { 504 {
515 { "labelString", "LabelString", XtRString, sizeof(String), 505 { "labelString", "LabelString", XtRString, sizeof(String),
516 0, XtRImmediate, 0 } 506 0, XtRImmediate, 0 }
517 }; 507 };
518 508
519 /* This function searches STRING for parameter inserts of the form: 509 /*
520 %[padding]1 510 * This function looks through string searching for parameter
521 padding is either space (' ') or dash ('-') meaning 511 * inserts of the form:
522 padding to the left or right of the inserted parameter. 512 * %[padding]1
523 In essence, all %1 strings are replaced by VALUE in the return value. 513 * padding is space (' ') or dash ('-') characters meaning
524 The caller is expected to free the return value using XtFree(). 514 * padding to the left or right of the inserted parameter.
525 %% means insert one % (like printf). 515 * In essence all %1 strings are replaced by value in the return
526 %1 means insert VALUE. 516 * value (which the caller is expected to free).
527 %-1 means insert VALUE followed by one space. The latter is 517 * %% means insert one % (like printf).
528 not inserted if VALUE is a zero length string. 518 * %1 means insert value.
529 */ 519 * %-1 means insert value followed by one space. The latter is
520 * not inserted if value is a zero length string.
521 */
530 static char* 522 static char*
531 parameterize_string (const char *string, const char *value) 523 parameterize_string (CONST char *string, CONST char *value)
532 { 524 {
533 const char *percent; 525 char *percent;
534 char *result; 526 char *result;
535 unsigned int done = 0; 527 unsigned int done = 0;
536 unsigned int ntimes; 528 unsigned int ntimes;
537 529
538 if (!string) 530 if (!string)
539 { 531 {
540 result = XtMalloc(1); 532 result = XtMalloc(1);
541 result[0] = '\0'; 533 result[0] = '\0';
542 return result; 534 return (result);
543 } 535 }
544 536
545 if (!value) 537 if (!value)
546 value = ""; 538 value = "";
547 539
548 for (ntimes = 1, percent = string; 540 for (ntimes = 1, result = (char *) string; (percent = strchr(result, '%'));
549 (percent = strchr (percent, '%'));
550 ntimes++) 541 ntimes++)
551 percent++; 542 result = &percent[1];
552 543
553 result = XtMalloc ((ntimes * strlen(value)) + strlen(string) + 4); 544 result = XtMalloc ((ntimes * strlen(value)) + strlen(string) + 4);
554 result[0] = '\0'; 545 result[0] = '\0';
555 546
556 while ((percent = strchr (string, '%'))) 547 while ((percent = strchr(string, '%')))
557 { 548 {
558 unsigned int left_pad; 549 unsigned int left_pad;
559 unsigned int right_pad; 550 unsigned int right_pad;
560 const char *p; 551 char *p;
561 552
562 if (percent[1] == '%') 553 if (percent[1] == '%')
563 { /* it's a real % */ 554 { /* it's a real % */
564 strncat (result, string, 1 + percent - string); /* incl % */ 555 strncat (result, string, 1 + percent - string); /* incl % */
565 string = &percent[2]; /* after the second '%' */ 556 string = &percent[2]; /* after the second '%' */
1536 { 1527 {
1537 *height = (mw->menu.font_ascent + mw->menu.font_descent + 1528 *height = (mw->menu.font_ascent + mw->menu.font_descent +
1538 2 * mw->menu.vertical_margin + 1529 2 * mw->menu.vertical_margin +
1539 2 * mw->menu.shadow_thickness); 1530 2 * mw->menu.shadow_thickness);
1540 /* no left column decoration */ 1531 /* no left column decoration */
1541 *toggle_width = mw->menu.horizontal_margin + mw->menu.shadow_thickness; 1532 *toggle_width = mw->menu.horizontal_margin + mw->menu.shadow_thickness;;
1542 1533
1543 *label_width = string_width_u (mw, resource_widget_value (mw, val)); 1534 *label_width = string_width_u (mw, resource_widget_value (mw, val));
1544 *bindings_width = mw->menu.horizontal_margin + mw->menu.shadow_thickness; 1535 *bindings_width = mw->menu.horizontal_margin + mw->menu.shadow_thickness;
1545 } 1536 }
1546 1537
1880 height, label_tab, binding_tab); 1871 height, label_tab, binding_tab);
1881 } 1872 }
1882 1873
1883 static struct _shadow_names 1874 static struct _shadow_names
1884 { 1875 {
1885 const char * name; 1876 CONST char * name;
1886 shadow_type type; 1877 shadow_type type;
1887 } shadow_names[] = 1878 } shadow_names[] =
1888 { 1879 {
1889 /* Motif */ 1880 /* Motif */
1890 { "singleLine", SHADOW_SINGLE_LINE }, 1881 { "singleLine", SHADOW_SINGLE_LINE },
2816 2807
2817 xgcv.fill_style = FillOpaqueStippled; 2808 xgcv.fill_style = FillOpaqueStippled;
2818 xgcv.foreground = mw->menu.top_shadow_color; 2809 xgcv.foreground = mw->menu.top_shadow_color;
2819 xgcv.background = mw->core.background_pixel; 2810 xgcv.background = mw->core.background_pixel;
2820 /* xgcv.stipple = mw->menu.top_shadow_pixmap; gtb */ 2811 /* xgcv.stipple = mw->menu.top_shadow_pixmap; gtb */
2812 #ifdef NEED_MOTIF
2821 if (mw->menu.top_shadow_pixmap && 2813 if (mw->menu.top_shadow_pixmap &&
2822 mw->menu.top_shadow_pixmap != XmUNSPECIFIED_PIXMAP) 2814 mw->menu.top_shadow_pixmap != XmUNSPECIFIED_PIXMAP)
2823 xgcv.stipple = mw->menu.top_shadow_pixmap; 2815 xgcv.stipple = mw->menu.top_shadow_pixmap;
2824 else 2816 else
2825 xgcv.stipple = 0; 2817 xgcv.stipple = 0;
2818 #else
2819 xgcv.stipple = mw->menu.top_shadow_pixmap;
2820 #endif /* NEED_MOTIF */
2826 pm = (xgcv.stipple ? GCStipple|GCFillStyle : 0); 2821 pm = (xgcv.stipple ? GCStipple|GCFillStyle : 0);
2827 mw->menu.shadow_top_gc = 2822 mw->menu.shadow_top_gc =
2828 XtGetGC((Widget)mw, GCForeground|GCBackground|pm, &xgcv); 2823 XtGetGC((Widget)mw, GCForeground|GCBackground|pm, &xgcv);
2829 2824
2830 xgcv.foreground = mw->menu.bottom_shadow_color; 2825 xgcv.foreground = mw->menu.bottom_shadow_color;
2831 /* xgcv.stipple = mw->menu.bottom_shadow_pixmap; gtb */ 2826 /* xgcv.stipple = mw->menu.bottom_shadow_pixmap; gtb */
2832 if (mw->menu.bottom_shadow_pixmap && 2827 #ifdef NEED_MOTIF
2833 mw->menu.bottom_shadow_pixmap != XmUNSPECIFIED_PIXMAP) 2828 if (mw->menu.top_shadow_pixmap &&
2829 mw->menu.top_shadow_pixmap != XmUNSPECIFIED_PIXMAP)
2834 xgcv.stipple = mw->menu.bottom_shadow_pixmap; 2830 xgcv.stipple = mw->menu.bottom_shadow_pixmap;
2835 else 2831 else
2836 xgcv.stipple = 0; 2832 xgcv.stipple = 0;
2833 #else
2834 xgcv.stipple = mw->menu.bottom_shadow_pixmap;
2835 #endif /* NEED_MOTIF */
2837 pm = (xgcv.stipple ? GCStipple|GCFillStyle : 0); 2836 pm = (xgcv.stipple ? GCStipple|GCFillStyle : 0);
2838 mw->menu.shadow_bottom_gc = 2837 mw->menu.shadow_bottom_gc =
2839 XtGetGC ((Widget)mw, GCForeground|GCBackground|pm, &xgcv); 2838 XtGetGC ((Widget)mw, GCForeground|GCBackground|pm, &xgcv);
2840 } 2839 }
2841 2840