comparison lwlib/xlwmenu.c @ 45147:e10cf8f440ae

(xlwMenuResources): New resource. (find_next_selectable): Return current item when the menu is not poped up. Rename `inactive_gc' to `disabled_gc'. Use lighter/darker color for disabled menu items instead of using stipple. Use stipple only when better color can not be determined automatically.
author Pavel Janík <Pavel@Janik.cz>
date Mon, 06 May 2002 18:55:30 +0000
parents 4b2f9e2a9a29
children 0e9984418269
comparison
equal deleted inserted replaced
45146:174fe450ad23 45147:e10cf8f440ae
137 { 137 {
138 {XtNfont, XtCFont, XtRFontStruct, sizeof(XFontStruct *), 138 {XtNfont, XtCFont, XtRFontStruct, sizeof(XFontStruct *),
139 offset(menu.font),XtRString, "XtDefaultFont"}, 139 offset(menu.font),XtRString, "XtDefaultFont"},
140 {XtNforeground, XtCForeground, XtRPixel, sizeof(Pixel), 140 {XtNforeground, XtCForeground, XtRPixel, sizeof(Pixel),
141 offset(menu.foreground), XtRString, "XtDefaultForeground"}, 141 offset(menu.foreground), XtRString, "XtDefaultForeground"},
142 {XtNdisabledForeground, XtCDisabledForeground, XtRPixel, sizeof(Pixel),
143 offset(menu.disabled_foreground), XtRString, (XtPointer)NULL},
142 {XtNbuttonForeground, XtCButtonForeground, XtRPixel, sizeof(Pixel), 144 {XtNbuttonForeground, XtCButtonForeground, XtRPixel, sizeof(Pixel),
143 offset(menu.button_foreground), XtRString, "XtDefaultForeground"}, 145 offset(menu.button_foreground), XtRString, "XtDefaultForeground"},
144 {XtNmargin, XtCMargin, XtRDimension, sizeof(Dimension), 146 {XtNmargin, XtCMargin, XtRDimension, sizeof(Dimension),
145 offset(menu.margin), XtRImmediate, (XtPointer)1}, 147 offset(menu.margin), XtRImmediate, (XtPointer)1},
146 {XtNhorizontalSpacing, XtCMargin, XtRDimension, sizeof(Dimension), 148 {XtNhorizontalSpacing, XtCMargin, XtRDimension, sizeof(Dimension),
995 997
996 /* pick the foreground and background GC. */ 998 /* pick the foreground and background GC. */
997 if (val->enabled) 999 if (val->enabled)
998 text_gc = mw->menu.foreground_gc; 1000 text_gc = mw->menu.foreground_gc;
999 else 1001 else
1000 text_gc = mw->menu.inactive_gc; 1002 text_gc = mw->menu.disabled_gc;
1001 deco_gc = mw->menu.foreground_gc; 1003 deco_gc = mw->menu.foreground_gc;
1002 1004
1003 if (separator_p) 1005 if (separator_p)
1004 { 1006 {
1005 draw_separator (mw, ws->window, x, y, width, separator); 1007 draw_separator (mw, ws->window, x, y, width, separator);
1451 static void 1453 static void
1452 make_drawing_gcs (mw) 1454 make_drawing_gcs (mw)
1453 XlwMenuWidget mw; 1455 XlwMenuWidget mw;
1454 { 1456 {
1455 XGCValues xgcv; 1457 XGCValues xgcv;
1458 XColor temp;
1459 int delta;
1456 1460
1457 xgcv.font = mw->menu.font->fid; 1461 xgcv.font = mw->menu.font->fid;
1458 xgcv.foreground = mw->menu.foreground; 1462 xgcv.foreground = mw->menu.foreground;
1459 xgcv.background = mw->core.background_pixel; 1463 xgcv.background = mw->core.background_pixel;
1460 mw->menu.foreground_gc = XtGetGC ((Widget)mw, 1464 mw->menu.foreground_gc = XtGetGC ((Widget)mw,
1467 mw->menu.button_gc = XtGetGC ((Widget)mw, 1471 mw->menu.button_gc = XtGetGC ((Widget)mw,
1468 GCFont | GCForeground | GCBackground, 1472 GCFont | GCForeground | GCBackground,
1469 &xgcv); 1473 &xgcv);
1470 1474
1471 xgcv.font = mw->menu.font->fid; 1475 xgcv.font = mw->menu.font->fid;
1472 xgcv.foreground = mw->menu.foreground;
1473 xgcv.background = mw->core.background_pixel; 1476 xgcv.background = mw->core.background_pixel;
1474 xgcv.fill_style = FillStippled; 1477
1475 xgcv.stipple = mw->menu.gray_pixmap; 1478 #define BRIGHTNESS(color) (((color) & 0xff) + (((color) >> 8) & 0xff) + (((color) >> 16) & 0xff))
1476 mw->menu.inactive_gc = XtGetGC ((Widget)mw, 1479
1477 (GCFont | GCForeground | GCBackground 1480 /* Allocate color for disabled menu-items. */
1478 | GCFillStyle | GCStipple), &xgcv); 1481 if (BRIGHTNESS(mw->menu.foreground) < BRIGHTNESS(mw->core.background_pixel))
1482 {
1483 delta = 2.3;
1484 temp.pixel = mw->menu.foreground;
1485 }
1486 else
1487 {
1488 delta = 1.2;
1489 temp.pixel = mw->core.background_pixel;
1490 }
1491
1492 x_alloc_lighter_color_for_widget ((Widget) mw, XtDisplay ((Widget) mw),
1493 mw->core.colormap,
1494 &temp.pixel,
1495 delta,
1496 0x8000);
1497 mw->menu.disabled_foreground = temp.pixel;
1498
1499 if (mw->menu.foreground == mw->menu.disabled_foreground
1500 || mw->core.background_pixel == mw->menu.disabled_foreground)
1501 {
1502 /* Too few colors, use stipple. */
1503 xgcv.foreground = mw->menu.foreground;
1504 xgcv.fill_style = FillStippled;
1505 xgcv.stipple = mw->menu.gray_pixmap;
1506 mw->menu.disabled_gc = XtGetGC ((Widget)mw,
1507 (GCFont | GCForeground | GCBackground
1508 | GCFillStyle | GCStipple), &xgcv);
1509 }
1510 else
1511 {
1512 /* Many colors available, use disabled pixel. */
1513 xgcv.foreground = mw->menu.disabled_foreground;
1514 mw->menu.disabled_gc = XtGetGC ((Widget)mw,
1515 (GCFont | GCForeground | GCBackground), &xgcv);
1516 }
1479 1517
1480 xgcv.font = mw->menu.font->fid; 1518 xgcv.font = mw->menu.font->fid;
1481 xgcv.foreground = mw->menu.button_foreground; 1519 xgcv.foreground = mw->menu.button_foreground;
1482 xgcv.background = mw->core.background_pixel; 1520 xgcv.background = mw->core.background_pixel;
1483 xgcv.fill_style = FillStippled; 1521 xgcv.fill_style = FillStippled;
1498 release_drawing_gcs (mw) 1536 release_drawing_gcs (mw)
1499 XlwMenuWidget mw; 1537 XlwMenuWidget mw;
1500 { 1538 {
1501 XtReleaseGC ((Widget) mw, mw->menu.foreground_gc); 1539 XtReleaseGC ((Widget) mw, mw->menu.foreground_gc);
1502 XtReleaseGC ((Widget) mw, mw->menu.button_gc); 1540 XtReleaseGC ((Widget) mw, mw->menu.button_gc);
1503 XtReleaseGC ((Widget) mw, mw->menu.inactive_gc); 1541 XtReleaseGC ((Widget) mw, mw->menu.disabled_gc);
1504 XtReleaseGC ((Widget) mw, mw->menu.inactive_button_gc); 1542 XtReleaseGC ((Widget) mw, mw->menu.inactive_button_gc);
1505 XtReleaseGC ((Widget) mw, mw->menu.background_gc); 1543 XtReleaseGC ((Widget) mw, mw->menu.background_gc);
1506 /* let's get some segvs if we try to use these... */ 1544 /* let's get some segvs if we try to use these... */
1507 mw->menu.foreground_gc = (GC) -1; 1545 mw->menu.foreground_gc = (GC) -1;
1508 mw->menu.button_gc = (GC) -1; 1546 mw->menu.button_gc = (GC) -1;
1509 mw->menu.inactive_gc = (GC) -1; 1547 mw->menu.disabled_gc = (GC) -1;
1510 mw->menu.inactive_button_gc = (GC) -1; 1548 mw->menu.inactive_button_gc = (GC) -1;
1511 mw->menu.background_gc = (GC) -1; 1549 mw->menu.background_gc = (GC) -1;
1512 } 1550 }
1513 1551
1514 #define MINL(x,y) ((((unsigned long) (x)) < ((unsigned long) (y))) \ 1552 #define MINL(x,y) ((((unsigned long) (x)) < ((unsigned long) (y))) \
2048 (lw_separator_p (current->name, &separator, 0) || !current->enabled)) 2086 (lw_separator_p (current->name, &separator, 0) || !current->enabled))
2049 ; 2087 ;
2050 2088
2051 if (current == item) 2089 if (current == item)
2052 { 2090 {
2091 if (mw->menu.old_depth < 2)
2092 return current;
2053 current = mw->menu.old_stack [mw->menu.old_depth - 2]->contents; 2093 current = mw->menu.old_stack [mw->menu.old_depth - 2]->contents;
2054 2094
2055 while (lw_separator_p (current->name, &separator, 0) || !current->enabled) 2095 while (lw_separator_p (current->name, &separator, 0) || !current->enabled)
2056 { 2096 {
2057 if (current->next) 2097 if (current->next)