Mercurial > hg > xemacs-beta
comparison lwlib/xlwmenu.c @ 442:abe6d1db359e r21-2-36
Import from CVS: tag r21-2-36
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:35:02 +0200 |
parents | a5df635868b2 |
children | 1ccc32a20af4 |
comparison
equal
deleted
inserted
replaced
441:72a7cfa4a488 | 442:abe6d1db359e |
---|---|
49 | 49 |
50 #ifdef USE_DEBUG_MALLOC | 50 #ifdef USE_DEBUG_MALLOC |
51 #include <dmalloc.h> | 51 #include <dmalloc.h> |
52 #endif | 52 #endif |
53 | 53 |
54 /* simple, naieve integer maximum */ | 54 /* simple, naive integer maximum */ |
55 #ifndef max | 55 #ifndef max |
56 #define max(a,b) ((a)>(b)?(a):(b)) | 56 #define max(a,b) ((a)>(b)?(a):(b)) |
57 #endif | 57 #endif |
58 | 58 |
59 static char | 59 static char |
86 XtRString, (XtPointer) "-*-helvetica-bold-r-*-*-*-120-*-*-*-*-iso8859-1"}, | 86 XtRString, (XtPointer) "-*-helvetica-bold-r-*-*-*-120-*-*-*-*-iso8859-1"}, |
87 #else | 87 #else |
88 {XtNfont, XtCFont, XtRFontStruct, sizeof(XFontStruct *), | 88 {XtNfont, XtCFont, XtRFontStruct, sizeof(XFontStruct *), |
89 offset(menu.font), XtRString, (XtPointer) "XtDefaultFont"}, | 89 offset(menu.font), XtRString, (XtPointer) "XtDefaultFont"}, |
90 # ifdef USE_XFONTSET | 90 # ifdef USE_XFONTSET |
91 /* #### Consider using the same method as for Motif; see the comment in | |
92 XlwMenuInitialize(). */ | |
91 {XtNfontSet, XtCFontSet, XtRFontSet, sizeof(XFontSet), | 93 {XtNfontSet, XtCFontSet, XtRFontSet, sizeof(XFontSet), |
92 offset(menu.font_set), XtRString, (XtPointer) "XtDefaultFontSet"}, | 94 offset(menu.font_set), XtRString, (XtPointer) "XtDefaultFontSet"}, |
93 # endif | 95 # endif |
94 #endif | 96 #endif |
95 {XtNforeground, XtCForeground, XtRPixel, sizeof(Pixel), | 97 {XtNforeground, XtCForeground, XtRPixel, sizeof(Pixel), |
455 # endif /* USE_XFONTSET */ | 457 # endif /* USE_XFONTSET */ |
456 #endif | 458 #endif |
457 } | 459 } |
458 | 460 |
459 static void | 461 static void |
460 massage_resource_name (CONST char *in, char *out) | 462 massage_resource_name (const char *in, char *out) |
461 { | 463 { |
462 /* Turn a random string into something suitable for using as a resource. | 464 /* Turn a random string into something suitable for using as a resource. |
463 For example: | 465 For example: |
464 | 466 |
465 "Kill Buffer" -> "killBuffer" | 467 "Kill Buffer" -> "killBuffer" |
477 #endif | 479 #endif |
478 | 480 |
479 Boolean firstp = True; | 481 Boolean firstp = True; |
480 while (*in) | 482 while (*in) |
481 { | 483 { |
482 char ch = massaged_resource_char[(unsigned char) *in++]; | 484 if (*in == '%' && *(in + 1) == '_') |
483 if (ch) | 485 in += 2; |
486 else | |
484 { | 487 { |
485 int int_ch = (int) (unsigned char) ch; | 488 char ch; |
486 *out++ = firstp ? tolower (int_ch) : toupper (int_ch); | 489 |
487 firstp = False; | 490 if (*in == '%' && *(in + 1) == '%') |
488 while ((ch = massaged_resource_char[(unsigned char) *in++]) != '\0') | 491 in++; |
489 *out++ = ch; | 492 ch = massaged_resource_char[(unsigned char) *in++]; |
490 if (!*(in-1)) /* Overshot the NULL byte? */ | 493 if (ch) |
491 break; | 494 { |
495 int int_ch = (int) (unsigned char) ch; | |
496 *out++ = firstp ? tolower (int_ch) : toupper (int_ch); | |
497 firstp = False; | |
498 while ((ch = massaged_resource_char[(unsigned char) *in++]) | |
499 != '\0') | |
500 *out++ = ch; | |
501 if (!*(in-1)) /* Overshot the NULL byte? */ | |
502 break; | |
503 } | |
492 } | 504 } |
493 } | 505 } |
494 *out = 0; | 506 *out = 0; |
495 | 507 |
496 #ifdef PRINT_XLWMENU_RESOURCE_CONVERSIONS | 508 #ifdef PRINT_XLWMENU_RESOURCE_CONVERSIONS |
504 { | 516 { |
505 { "labelString", "LabelString", XtRString, sizeof(String), | 517 { "labelString", "LabelString", XtRString, sizeof(String), |
506 0, XtRImmediate, 0 } | 518 0, XtRImmediate, 0 } |
507 }; | 519 }; |
508 | 520 |
509 /* | 521 /* This function searches STRING for parameter inserts of the form: |
510 * This function looks through string searching for parameter | 522 %[padding]1 |
511 * inserts of the form: | 523 padding is either space (' ') or dash ('-') meaning |
512 * %[padding]1 | 524 padding to the left or right of the inserted parameter. |
513 * padding is space (' ') or dash ('-') characters meaning | 525 In essence, all %1 strings are replaced by VALUE in the return value. |
514 * padding to the left or right of the inserted parameter. | 526 The caller is expected to free the return value using XtFree(). |
515 * In essence all %1 strings are replaced by value in the return | 527 %% means insert one % (like printf). |
516 * value (which the caller is expected to free). | 528 %1 means insert VALUE. |
517 * %% means insert one % (like printf). | 529 %-1 means insert VALUE followed by one space. The latter is |
518 * %1 means insert value. | 530 not inserted if VALUE is a zero length string. |
519 * %-1 means insert value followed by one space. The latter is | 531 */ |
520 * not inserted if value is a zero length string. | |
521 */ | |
522 static char* | 532 static char* |
523 parameterize_string (CONST char *string, CONST char *value) | 533 parameterize_string (const char *string, const char *value) |
524 { | 534 { |
525 char *percent; | 535 const char *percent; |
526 char *result; | 536 char *result; |
527 unsigned int done = 0; | 537 unsigned int done = 0; |
528 unsigned int ntimes; | 538 unsigned int ntimes; |
529 | 539 |
530 if (!string) | 540 if (!string) |
531 { | 541 { |
532 result = XtMalloc(1); | 542 result = XtMalloc(1); |
533 result[0] = '\0'; | 543 result[0] = '\0'; |
534 return (result); | 544 return result; |
535 } | 545 } |
536 | 546 |
537 if (!value) | 547 if (!value) |
538 value = ""; | 548 value = ""; |
539 | 549 |
540 for (ntimes = 1, result = (char *) string; (percent = strchr(result, '%')); | 550 for (ntimes = 1, percent = string; |
551 (percent = strchr (percent, '%')); | |
541 ntimes++) | 552 ntimes++) |
542 result = &percent[1]; | 553 percent++; |
543 | 554 |
544 result = XtMalloc ((ntimes * strlen(value)) + strlen(string) + 4); | 555 result = XtMalloc ((ntimes * strlen(value)) + strlen(string) + 4); |
545 result[0] = '\0'; | 556 result[0] = '\0'; |
546 | 557 |
547 while ((percent = strchr(string, '%'))) | 558 while ((percent = strchr (string, '%'))) |
548 { | 559 { |
549 unsigned int left_pad; | 560 unsigned int left_pad; |
550 unsigned int right_pad; | 561 unsigned int right_pad; |
551 char *p; | 562 const char *p; |
552 | 563 |
553 if (percent[1] == '%') | 564 if (percent[1] == '%') |
554 { /* it's a real % */ | 565 { /* it's a real % */ |
555 strncat (result, string, 1 + percent - string); /* incl % */ | 566 strncat (result, string, 1 + percent - string); /* incl % */ |
556 string = &percent[2]; /* after the second '%' */ | 567 string = &percent[2]; /* after the second '%' */ |
677 return (XmString) val->toolkit_data; | 688 return (XmString) val->toolkit_data; |
678 } | 689 } |
679 | 690 |
680 /* Unused */ | 691 /* Unused */ |
681 #if 0 | 692 #if 0 |
682 /* These two routines should be a seperate file..djw */ | 693 /* These two routines should be a separate file..djw */ |
683 static char * | 694 static char * |
684 xlw_create_localized_string (Widget w, | 695 xlw_create_localized_string (Widget w, |
685 char *name, | 696 char *name, |
686 char **args, | 697 char **args, |
687 unsigned int nargs) | 698 unsigned int nargs) |
1508 else if (val->call_data) /* push button */ | 1519 else if (val->call_data) /* push button */ |
1509 return BUTTON_TYPE; | 1520 return BUTTON_TYPE; |
1510 else | 1521 else |
1511 return TEXT_TYPE; | 1522 return TEXT_TYPE; |
1512 #else | 1523 #else |
1513 else | 1524 else |
1514 abort(); | 1525 abort(); |
1515 return UNSPECIFIED_TYPE; /* Not reached */ | 1526 return UNSPECIFIED_TYPE; /* Not reached */ |
1516 #endif | 1527 #endif |
1517 } | 1528 } |
1518 | 1529 |
1871 height, label_tab, binding_tab); | 1882 height, label_tab, binding_tab); |
1872 } | 1883 } |
1873 | 1884 |
1874 static struct _shadow_names | 1885 static struct _shadow_names |
1875 { | 1886 { |
1876 CONST char * name; | 1887 const char * name; |
1877 shadow_type type; | 1888 shadow_type type; |
1878 } shadow_names[] = | 1889 } shadow_names[] = |
1879 { | 1890 { |
1880 /* Motif */ | 1891 /* Motif */ |
1881 { "singleLine", SHADOW_SINGLE_LINE }, | 1892 { "singleLine", SHADOW_SINGLE_LINE }, |
2480 for (i = last_same + 1; i < new_depth; i++) | 2491 for (i = last_same + 1; i < new_depth; i++) |
2481 old_stack [i] = new_stack [i]; | 2492 old_stack [i] = new_stack [i]; |
2482 | 2493 |
2483 mw->menu.old_depth = new_depth; | 2494 mw->menu.old_depth = new_depth; |
2484 | 2495 |
2485 /* refresh the last seletion */ | 2496 /* refresh the last selection */ |
2486 selection_position.x = 0; | 2497 selection_position.x = 0; |
2487 selection_position.y = 0; | 2498 selection_position.y = 0; |
2488 display_menu (mw, last_same, new_selection == old_selection, | 2499 display_menu (mw, last_same, new_selection == old_selection, |
2489 &selection_position, NULL, NULL, old_selection, new_selection); | 2500 &selection_position, NULL, NULL, old_selection, new_selection); |
2490 | 2501 |
2807 | 2818 |
2808 xgcv.fill_style = FillOpaqueStippled; | 2819 xgcv.fill_style = FillOpaqueStippled; |
2809 xgcv.foreground = mw->menu.top_shadow_color; | 2820 xgcv.foreground = mw->menu.top_shadow_color; |
2810 xgcv.background = mw->core.background_pixel; | 2821 xgcv.background = mw->core.background_pixel; |
2811 /* xgcv.stipple = mw->menu.top_shadow_pixmap; gtb */ | 2822 /* xgcv.stipple = mw->menu.top_shadow_pixmap; gtb */ |
2812 #ifdef NEED_MOTIF | |
2813 if (mw->menu.top_shadow_pixmap && | 2823 if (mw->menu.top_shadow_pixmap && |
2814 mw->menu.top_shadow_pixmap != XmUNSPECIFIED_PIXMAP) | 2824 mw->menu.top_shadow_pixmap != XmUNSPECIFIED_PIXMAP) |
2815 xgcv.stipple = mw->menu.top_shadow_pixmap; | 2825 xgcv.stipple = mw->menu.top_shadow_pixmap; |
2816 else | 2826 else |
2817 xgcv.stipple = 0; | 2827 xgcv.stipple = 0; |
2818 #else | |
2819 xgcv.stipple = mw->menu.top_shadow_pixmap; | |
2820 #endif /* NEED_MOTIF */ | |
2821 pm = (xgcv.stipple ? GCStipple|GCFillStyle : 0); | 2828 pm = (xgcv.stipple ? GCStipple|GCFillStyle : 0); |
2822 mw->menu.shadow_top_gc = | 2829 mw->menu.shadow_top_gc = |
2823 XtGetGC((Widget)mw, GCForeground|GCBackground|pm, &xgcv); | 2830 XtGetGC((Widget)mw, GCForeground|GCBackground|pm, &xgcv); |
2824 | 2831 |
2825 xgcv.foreground = mw->menu.bottom_shadow_color; | 2832 xgcv.foreground = mw->menu.bottom_shadow_color; |
2826 /* xgcv.stipple = mw->menu.bottom_shadow_pixmap; gtb */ | 2833 /* xgcv.stipple = mw->menu.bottom_shadow_pixmap; gtb */ |
2827 #ifdef NEED_MOTIF | |
2828 if (mw->menu.bottom_shadow_pixmap && | 2834 if (mw->menu.bottom_shadow_pixmap && |
2829 mw->menu.bottom_shadow_pixmap != XmUNSPECIFIED_PIXMAP) | 2835 mw->menu.bottom_shadow_pixmap != XmUNSPECIFIED_PIXMAP) |
2830 xgcv.stipple = mw->menu.bottom_shadow_pixmap; | 2836 xgcv.stipple = mw->menu.bottom_shadow_pixmap; |
2831 else | 2837 else |
2832 xgcv.stipple = 0; | 2838 xgcv.stipple = 0; |
2833 #else | |
2834 xgcv.stipple = mw->menu.bottom_shadow_pixmap; | |
2835 #endif /* NEED_MOTIF */ | |
2836 pm = (xgcv.stipple ? GCStipple|GCFillStyle : 0); | 2839 pm = (xgcv.stipple ? GCStipple|GCFillStyle : 0); |
2837 mw->menu.shadow_bottom_gc = | 2840 mw->menu.shadow_bottom_gc = |
2838 XtGetGC ((Widget)mw, GCForeground|GCBackground|pm, &xgcv); | 2841 XtGetGC ((Widget)mw, GCForeground|GCBackground|pm, &xgcv); |
2839 } | 2842 } |
2840 | 2843 |
3014 mw->menu.gray_pixmap = | 3017 mw->menu.gray_pixmap = |
3015 XCreatePixmapFromBitmapData (display, window, (char *) gray_bits, | 3018 XCreatePixmapFromBitmapData (display, window, (char *) gray_bits, |
3016 gray_width, gray_height, 1, 0, 1); | 3019 gray_width, gray_height, 1, 0, 1); |
3017 | 3020 |
3018 #ifdef NEED_MOTIF | 3021 #ifdef NEED_MOTIF |
3022 /* #### Even if it's a kludge!!!, we should consider doing the same for | |
3023 X Font Sets. */ | |
3019 /* The menu.font_list slot came from the *fontList resource (Motif standard.) | 3024 /* The menu.font_list slot came from the *fontList resource (Motif standard.) |
3020 The menu.font_list_2 slot came from the *font resource, for backward | 3025 The menu.font_list_2 slot came from the *font resource, for backward |
3021 compatibility with older versions of this code, and consistency with the | 3026 compatibility with older versions of this code, and consistency with the |
3022 rest of emacs. If both font and fontList are specified, we use font. | 3027 rest of emacs. If both font and fontList are specified, we use fontList. |
3023 If only one is specified, we use that. If neither are specified, we | 3028 If only one is specified, we use that. If neither are specified, we |
3024 use the "fallback" value. What a kludge!!! | 3029 use the "fallback" value. What a kludge!!! |
3025 | 3030 |
3026 Note that this has the bug that a more general wildcard like "*fontList:" | 3031 Note that this has the bug that a more general wildcard like "*fontList:" |
3027 will override a more specific resource like "Emacs*menubar.font:". But | 3032 will override a more specific resource like "Emacs*menubar.font:". But |