comparison lwlib/xlwmenu.c @ 14:9ee227acff29 r19-15b90

Import from CVS: tag r19-15b90
author cvs
date Mon, 13 Aug 2007 08:48:42 +0200
parents bcdc7deadc19
children 56c54cf7c5b6
comparison
equal deleted inserted replaced
13:13c6d0aaafe5 14:9ee227acff29
103 {XtNselect, XtCCallback, XtRCallback, sizeof(XtPointer), 103 {XtNselect, XtCCallback, XtRCallback, sizeof(XtPointer),
104 offset(menu.select), XtRCallback, (XtPointer)NULL}, 104 offset(menu.select), XtRCallback, (XtPointer)NULL},
105 {XtNmenu, XtCMenu, XtRPointer, sizeof(XtPointer), 105 {XtNmenu, XtCMenu, XtRPointer, sizeof(XtPointer),
106 offset(menu.contents), XtRImmediate, (XtPointer)NULL}, 106 offset(menu.contents), XtRImmediate, (XtPointer)NULL},
107 {XtNcursor, XtCCursor, XtRCursor, sizeof(Cursor), 107 {XtNcursor, XtCCursor, XtRCursor, sizeof(Cursor),
108 offset(menu.cursor_shape), XtRString, (XtPointer)"right_ptr"}, 108 offset(menu.cursor_shape), XtRString, (XtPointer) "right_ptr"},
109 {XtNhorizontal, XtCHorizontal, XtRInt, sizeof(int), 109 {XtNhorizontal, XtCHorizontal, XtRInt, sizeof(int),
110 offset(menu.horizontal), XtRImmediate, (XtPointer)True}, 110 offset(menu.horizontal), XtRImmediate, (XtPointer)True},
111 {XtNuseBackingStore, XtCUseBackingStore, XtRBoolean, sizeof (Boolean), 111 {XtNuseBackingStore, XtCUseBackingStore, XtRBoolean, sizeof (Boolean),
112 offset (menu.use_backing_store), XtRImmediate, (XtPointer)False}, 112 offset (menu.use_backing_store), XtRImmediate, (XtPointer)False},
113 {XtNbounceDown, XtCBounceDown, XtRBoolean, sizeof (Boolean), 113 {XtNbounceDown, XtCBounceDown, XtRBoolean, sizeof (Boolean),
126 static void XlwMenuInitialize (Widget request, Widget new, ArgList args, 126 static void XlwMenuInitialize (Widget request, Widget new, ArgList args,
127 Cardinal *num_args); 127 Cardinal *num_args);
128 static void XlwMenuDestroy (Widget w); 128 static void XlwMenuDestroy (Widget w);
129 static void XlwMenuClassInitialize (void); 129 static void XlwMenuClassInitialize (void);
130 static void Start (Widget w, XEvent *ev, String *params, Cardinal *num_params); 130 static void Start (Widget w, XEvent *ev, String *params, Cardinal *num_params);
131 static void Drag (Widget w, XEvent *ev, String *params, Cardinal *num_params); 131 static void Drag (Widget w, XEvent *ev, String *params, Cardinal *num_params);
132 static void Select (Widget w, XEvent *ev, String *params, 132 static void Select(Widget w, XEvent *ev, String *params, Cardinal *num_params);
133 Cardinal *num_params);
134 133
135 #ifdef NEED_MOTIF 134 #ifdef NEED_MOTIF
136 static XFontStruct *default_font_of_font_list (XmFontList); 135 static XFontStruct *default_font_of_font_list (XmFontList);
137 #endif 136 #endif
138 137
248 { 247 {
249 nearest = x; 248 nearest = x;
250 nearest_delta = delta; 249 nearest_delta = delta;
251 } 250 }
252 } 251 }
253 color_def->red = cells[nearest].red; 252 color_def->red = cells[nearest].red;
254 color_def->green = cells[nearest].green; 253 color_def->green = cells[nearest].green;
255 color_def->blue = cells[nearest].blue; 254 color_def->blue = cells[nearest].blue;
256
257 free (cells); 255 free (cells);
258 return XAllocColor (display, screen_colormap, color_def); 256 return XAllocColor (display, screen_colormap, color_def);
259 } 257 }
260 } 258 }
261 259
271 } 269 }
272 else if (mw->menu.new_depth == mw->menu.new_stack_length) 270 else if (mw->menu.new_depth == mw->menu.new_stack_length)
273 { 271 {
274 mw->menu.new_stack_length *= 2; 272 mw->menu.new_stack_length *= 2;
275 mw->menu.new_stack = 273 mw->menu.new_stack =
276 (widget_value**)XtRealloc ((char*)mw->menu.new_stack, 274 (widget_value**)XtRealloc ((char *)mw->menu.new_stack,
277 mw->menu.new_stack_length * 275 mw->menu.new_stack_length *
278 sizeof (widget_value*)); 276 sizeof (widget_value*));
279 } 277 }
280 mw->menu.new_stack [mw->menu.new_depth++] = val; 278 mw->menu.new_stack [mw->menu.new_depth++] = val;
281 } 279 }
300 } 298 }
301 else if (mw->menu.old_stack_length < n) 299 else if (mw->menu.old_stack_length < n)
302 { 300 {
303 mw->menu.old_stack_length *= 2; 301 mw->menu.old_stack_length *= 2;
304 mw->menu.old_stack = 302 mw->menu.old_stack =
305 (widget_value**)XtRealloc ((char*)mw->menu.old_stack, 303 (widget_value**)XtRealloc ((char *)mw->menu.old_stack,
306 mw->menu.old_stack_length * 304 mw->menu.old_stack_length *
307 sizeof (widget_value*)); 305 sizeof (widget_value*));
308 } 306 }
309 } 307 }
310 308
311 static Boolean 309 static Boolean
312 close_to_reference_time(Widget w, Time reference_time, XEvent *ev) 310 close_to_reference_time(Widget w, Time reference_time, XEvent *ev)
313 { 311 {
314 return (reference_time && 312 return
315 (ev->xbutton.time - reference_time 313 reference_time &&
316 < XtGetMultiClickTime (XtDisplay (w)))); 314 (ev->xbutton.time - reference_time < XtGetMultiClickTime (XtDisplay (w)));
317 } 315 }
318 316
319 /* Size code */ 317 /* Size code */
320 static int 318 static int
321 string_width (XlwMenuWidget mw, 319 string_width (XlwMenuWidget mw,
437 435
438 for (ntimes = 1, result = (char *) string; (percent = strchr(result, '%')); 436 for (ntimes = 1, result = (char *) string; (percent = strchr(result, '%'));
439 ntimes++) 437 ntimes++)
440 result = &percent[1]; 438 result = &percent[1];
441 439
442 result = XtMalloc((ntimes * strlen(value)) + strlen(string) + 4); 440 result = XtMalloc ((ntimes * strlen(value)) + strlen(string) + 4);
443 result[0] = '\0'; 441 result[0] = '\0';
444 442
445 while ((percent = strchr(string, '%'))) 443 while ((percent = strchr(string, '%')))
446 { 444 {
447 unsigned left_pad; 445 unsigned left_pad;
574 XtFree (converted_name); 572 XtFree (converted_name);
575 573
576 val->toolkit_data = complete_name; 574 val->toolkit_data = complete_name;
577 val->free_toolkit_data = True; 575 val->free_toolkit_data = True;
578 } 576 }
579 return ((XmString) val->toolkit_data); 577 return (XmString) val->toolkit_data;
580 } 578 }
581 579
582 /* Unused */ 580 /* Unused */
583 #if 0 581 #if 0
584 /* 582 /*
599 XtGetSubresources (w, 597 XtGetSubresources (w,
600 (XtPointer)&string, 598 (XtPointer)&string,
601 name, 599 name,
602 name, 600 name,
603 nameResource, 1, 601 nameResource, 1,
604 NULL, 0 602 NULL, 0);
605 );
606 603
607 if (!string) 604 if (!string)
608 string = name; 605 string = name;
609 606
610 return parameterize_string (string, arg); 607 return parameterize_string (string, arg);
655 if (complete_name[0] == '\n') 652 if (complete_name[0] == '\n')
656 complete_name[0] = ' '; 653 complete_name[0] = ' ';
657 } 654 }
658 val->free_toolkit_data = True; 655 val->free_toolkit_data = True;
659 } 656 }
660 return (char*)val->toolkit_data; 657 return (char *) val->toolkit_data;
661 } 658 }
662 659
663 #endif /* !Motif */ 660 #endif /* !Motif */
664 661
665 /* 662 /*
666 * Code for drawing strings. 663 * Code for drawing strings.
667 */ 664 */
668 static void 665 static void
669 string_draw( 666 string_draw(XlwMenuWidget mw,
670 XlwMenuWidget mw,
671 Window window, 667 Window window,
672 int x, int y, 668 int x, int y,
673 GC gc, 669 GC gc,
674 #ifdef NEED_MOTIF 670 #ifdef NEED_MOTIF
675 XmString string 671 XmString string
676 #else 672 #else
677 char *string 673 char *string
678 #endif 674 #endif
679 ) { 675 )
676 {
680 #ifdef NEED_MOTIF 677 #ifdef NEED_MOTIF
681 XmStringDraw (XtDisplay (mw), window, 678 XmStringDraw (XtDisplay (mw), window,
682 mw->menu.font_list, 679 mw->menu.font_list,
683 string, gc, 680 string, gc,
684 x, y, 681 x, y,
707 704
708 /* 705 /*
709 * Low level code for drawing 3-D edges. 706 * Low level code for drawing 3-D edges.
710 */ 707 */
711 static void 708 static void
712 shadow_rectangle_draw ( 709 shadow_rectangle_draw (Display *dpy,
713 Display *dpy,
714 Window window, 710 Window window,
715 GC top_gc, 711 GC top_gc,
716 GC bottom_gc, 712 GC bottom_gc,
717 int x, int y, unsigned width, unsigned height, 713 int x, int y, unsigned width, unsigned height,
718 unsigned thickness 714 unsigned thickness)
719 )
720 { 715 {
721 XPoint points [4]; 716 XPoint points [4];
722 717
723 if (!thickness) 718 if (!thickness)
724 return; 719 return;
785 780
786 static void 781 static void
787 shadow_draw (XlwMenuWidget mw, 782 shadow_draw (XlwMenuWidget mw,
788 Window window, 783 Window window,
789 int x, int y, unsigned width, unsigned height, 784 int x, int y, unsigned width, unsigned height,
790 shadow_type type 785 shadow_type type)
791 )
792 { 786 {
793 Display *dpy = XtDisplay (mw); 787 Display *dpy = XtDisplay (mw);
794 GC top_gc; 788 GC top_gc;
795 GC bottom_gc; 789 GC bottom_gc;
796 int thickness = mw->menu.shadow_thickness; 790 int thickness = mw->menu.shadow_thickness;
826 } 820 }
827 821
828 if (etched) 822 if (etched)
829 { 823 {
830 unsigned half = thickness/2; 824 unsigned half = thickness/2;
831 shadow_rectangle_draw ( 825 shadow_rectangle_draw (dpy,
832 dpy,
833 window, 826 window,
834 top_gc, 827 top_gc,
835 top_gc, 828 top_gc,
836 x, y, 829 x, y,
837 width - half, height - half, 830 width - half, height - half,
838 thickness - half 831 thickness - half);
839 ); 832 shadow_rectangle_draw (dpy,
840 shadow_rectangle_draw (
841 dpy,
842 window, 833 window,
843 bottom_gc, 834 bottom_gc,
844 bottom_gc, 835 bottom_gc,
845 x + half, y + half, 836 x + half, y + half,
846 width - half , height - half, 837 width - half , height - half,
847 half 838 half);
848 );
849 } 839 }
850 else 840 else
851 { 841 {
852 shadow_rectangle_draw ( 842 shadow_rectangle_draw (dpy,
853 dpy,
854 window, 843 window,
855 top_gc, 844 top_gc,
856 bottom_gc, 845 bottom_gc,
857 x, y, 846 x, y,
858 width, height, 847 width, height,
859 thickness 848 thickness);
860 );
861 } 849 }
862 } 850 }
863 851
864 static void 852 static void
865 arrow_decoration_draw ( 853 arrow_decoration_draw (XlwMenuWidget mw,
866 XlwMenuWidget mw,
867 Window window, 854 Window window,
868 int x, int y, 855 int x, int y,
869 unsigned width, 856 unsigned width,
870 Boolean raised 857 Boolean raised)
871 )
872 { 858 {
873 Display *dpy = XtDisplay (mw); 859 Display *dpy = XtDisplay (mw);
874 GC top_gc; 860 GC top_gc;
875 GC bottom_gc; 861 GC bottom_gc;
876 GC select_gc; 862 GC select_gc;
887 873
888 select_gc = mw->menu.background_gc; 874 select_gc = mw->menu.background_gc;
889 875
890 if (raised) 876 if (raised)
891 { 877 {
892 top_gc = mw->menu.shadow_bottom_gc; 878 top_gc = mw->menu.shadow_bottom_gc;
893 bottom_gc = mw->menu.shadow_top_gc; 879 bottom_gc = mw->menu.shadow_top_gc;
894 } 880 }
895 else 881 else
896 { 882 {
897 top_gc = mw->menu.shadow_top_gc; 883 top_gc = mw->menu.shadow_top_gc;
898 bottom_gc = mw->menu.shadow_bottom_gc; 884 bottom_gc = mw->menu.shadow_bottom_gc;
899 } 885 }
900 886
901 /* 887 /*
902 * Fill internal area, we do this first so that the borders 888 * Fill internal area, we do this first so that the borders
909 points [2].x = x + length - thickness; 895 points [2].x = x + length - thickness;
910 points [2].y = y + half_width + thickness; 896 points [2].y = y + half_width + thickness;
911 points [3].x = x + thickness; 897 points [3].x = x + thickness;
912 points [3].y = y + width - thickness; 898 points [3].y = y + width - thickness;
913 899
914 XFillPolygon ( 900 XFillPolygon (dpy,
915 dpy,
916 window, 901 window,
917 select_gc, 902 select_gc,
918 points, 903 points,
919 4, 904 4,
920 Convex, 905 Convex,
921 CoordModeOrigin 906 CoordModeOrigin);
922 );
923 907
924 /* left border */ 908 /* left border */
925 points [0].x = x; 909 points [0].x = x;
926 points [0].y = y; 910 points [0].y = y;
927 points [1].x = x + thickness; 911 points [1].x = x + thickness;
957 941
958 XFillPolygon (dpy, window, top_gc, points, 4, Convex, CoordModeOrigin); 942 XFillPolygon (dpy, window, top_gc, points, 4, Convex, CoordModeOrigin);
959 } 943 }
960 944
961 static void 945 static void
962 toggle_decoration_draw ( 946 toggle_decoration_draw (XlwMenuWidget mw,
963 XlwMenuWidget mw,
964 Window window, 947 Window window,
965 int x, int y, 948 int x, int y,
966 unsigned width, 949 unsigned width,
967 Boolean set 950 Boolean set)
968 )
969 { 951 {
970 Display *dpy = XtDisplay (mw); 952 Display *dpy = XtDisplay (mw);
971 int thickness = mw->menu.shadow_thickness; 953 int thickness = mw->menu.shadow_thickness;
972 shadow_type type; 954 shadow_type type;
973 GC select_gc = mw->menu.select_gc; 955 GC select_gc = mw->menu.select_gc;
979 961
980 /* 962 /*
981 * Fill internal area. 963 * Fill internal area.
982 */ 964 */
983 if (set) 965 if (set)
984 XFillRectangle ( 966 XFillRectangle (dpy,
985 dpy,
986 window, 967 window,
987 select_gc, 968 select_gc,
988 x + thickness, 969 x + thickness,
989 y + thickness, 970 y + thickness,
990 width - (2*thickness), 971 width - (2*thickness),
991 width - (2*thickness) 972 width - (2*thickness));
992 );
993 973
994 shadow_draw(mw, window, x, y, width, width, type); 974 shadow_draw(mw, window, x, y, width, width, type);
995 } 975 }
996 976
997 static void 977 static void
998 radio_decoration_draw ( 978 radio_decoration_draw (XlwMenuWidget mw,
999 XlwMenuWidget mw,
1000 Window window, 979 Window window,
1001 int x, int y, 980 int x, int y,
1002 unsigned width, 981 unsigned width,
1003 Boolean enabled 982 Boolean enabled)
1004 )
1005 { 983 {
1006 Display *dpy = XtDisplay (mw); 984 Display *dpy = XtDisplay (mw);
1007 GC top_gc; 985 GC top_gc;
1008 GC bottom_gc; 986 GC bottom_gc;
1009 GC select_gc = mw->menu.select_gc; 987 GC select_gc = mw->menu.select_gc;
1019 997
1020 half_width = width/2; 998 half_width = width/2;
1021 999
1022 if (enabled) 1000 if (enabled)
1023 { 1001 {
1024 top_gc = mw->menu.shadow_bottom_gc; 1002 top_gc = mw->menu.shadow_bottom_gc;
1025 bottom_gc = mw->menu.shadow_top_gc; 1003 bottom_gc = mw->menu.shadow_top_gc;
1026 } 1004 }
1027 else 1005 else
1028 { 1006 {
1029 top_gc = mw->menu.shadow_top_gc; 1007 top_gc = mw->menu.shadow_top_gc;
1030 bottom_gc = mw->menu.shadow_bottom_gc; 1008 bottom_gc = mw->menu.shadow_bottom_gc;
1031 } 1009 }
1032 1010
1033 #if 1 1011 #if 1
1034 /* 1012 /*
1137 window, 1115 window,
1138 select_gc, 1116 select_gc,
1139 points, 1117 points,
1140 4, 1118 4,
1141 Convex, 1119 Convex,
1142 CoordModeOrigin 1120 CoordModeOrigin);
1143 ); 1121 }
1144 } 1122 }
1145 } 1123
1146 1124 static void
1147 static void 1125 separator_decoration_draw (XlwMenuWidget mw,
1148 separator_decoration_draw (
1149 XlwMenuWidget mw,
1150 Window window, 1126 Window window,
1151 int x, int y, 1127 int x, int y,
1152 unsigned width, 1128 unsigned width,
1153 Boolean vertical, 1129 Boolean vertical,
1154 shadow_type type 1130 shadow_type type)
1155 )
1156 { 1131 {
1157 Display *dpy = XtDisplay (mw); 1132 Display *dpy = XtDisplay (mw);
1158 GC top_gc; 1133 GC top_gc;
1159 GC bottom_gc; 1134 GC bottom_gc;
1160 unsigned offset = 0; 1135 unsigned offset = 0;
1232 { 1207 {
1233 for (i = 0; i < top_line_thickness; i++) 1208 for (i = 0; i < top_line_thickness; i++)
1234 XDrawLine (dpy, window, top_gc, x, y + i, x + width, y + i); 1209 XDrawLine (dpy, window, top_gc, x, y + i, x + width, y + i);
1235 1210
1236 for (i = 0; i < bottom_line_thickness; i++) 1211 for (i = 0; i < bottom_line_thickness; i++)
1237 XDrawLine ( 1212 XDrawLine (dpy, window, bottom_gc,
1238 dpy, window, bottom_gc,
1239 x, y + top_line_thickness + offset + i, 1213 x, y + top_line_thickness + offset + i,
1240 x + width, y + top_line_thickness + offset + i 1214 x + width, y + top_line_thickness + offset + i);
1241 );
1242 y += (top_line_thickness + offset + bottom_line_thickness + 1); 1215 y += (top_line_thickness + offset + bottom_line_thickness + 1);
1243 } 1216 }
1244 1217
1245 if (dashed) 1218 if (dashed)
1246 { 1219 {
1341 #endif 1314 #endif
1342 } 1315 }
1343 } 1316 }
1344 1317
1345 static void 1318 static void
1346 label_button_size ( 1319 label_button_size (XlwMenuWidget mw,
1347 XlwMenuWidget mw,
1348 widget_value *val, 1320 widget_value *val,
1349 Boolean in_menubar, 1321 Boolean in_menubar,
1350 unsigned *toggle_width, 1322 unsigned *toggle_width,
1351 unsigned *label_width, 1323 unsigned *label_width,
1352 unsigned *bindings_width, 1324 unsigned *bindings_width,
1353 unsigned *height 1325 unsigned *height)
1354 )
1355 { 1326 {
1356 *height = (mw->menu.font_ascent + mw->menu.font_descent + 1327 *height = (mw->menu.font_ascent + mw->menu.font_descent +
1357 2 * mw->menu.vertical_margin + 1328 2 * mw->menu.vertical_margin +
1358 2 * mw->menu.shadow_thickness); 1329 2 * mw->menu.shadow_thickness);
1359 /* no left column decoration */ 1330 /* no left column decoration */
1362 *label_width = string_width (mw, resource_widget_value (mw, val)); 1333 *label_width = string_width (mw, resource_widget_value (mw, val));
1363 *bindings_width = mw->menu.horizontal_margin + mw->menu.shadow_thickness; 1334 *bindings_width = mw->menu.horizontal_margin + mw->menu.shadow_thickness;
1364 } 1335 }
1365 1336
1366 static void 1337 static void
1367 label_button_draw ( 1338 label_button_draw (XlwMenuWidget mw,
1368 XlwMenuWidget mw,
1369 widget_value *val, 1339 widget_value *val,
1370 Boolean in_menubar, 1340 Boolean in_menubar,
1371 Boolean highlighted, 1341 Boolean highlighted,
1372 Window window, 1342 Window window,
1373 int x, int y, 1343 int x, int y,
1374 unsigned width, 1344 unsigned width,
1375 unsigned height, 1345 unsigned height,
1376 unsigned label_offset, 1346 unsigned label_offset,
1377 unsigned binding_tab 1347 unsigned binding_tab)
1378 )
1379 { 1348 {
1380 int y_offset = mw->menu.shadow_thickness + mw->menu.vertical_margin; 1349 int y_offset = mw->menu.shadow_thickness + mw->menu.vertical_margin;
1381 1350
1382 if (!label_offset) 1351 if (!label_offset)
1383 label_offset = mw->menu.shadow_thickness + mw->menu.horizontal_margin; 1352 label_offset = mw->menu.shadow_thickness + mw->menu.horizontal_margin;
1384 1353
1385 /* 1354 /*
1386 * Draw the label string. 1355 * Draw the label string.
1387 */ 1356 */
1388 string_draw ( 1357 string_draw (mw,
1389 mw,
1390 window, 1358 window,
1391 x + label_offset, y + y_offset, 1359 x + label_offset, y + y_offset,
1392 mw->menu.foreground_gc, 1360 mw->menu.foreground_gc,
1393 resource_widget_value (mw, val) 1361 resource_widget_value (mw, val));
1394 ); 1362 }
1395 } 1363
1396 1364 static void
1397 static void 1365 push_button_size (XlwMenuWidget mw,
1398 push_button_size (
1399 XlwMenuWidget mw,
1400 widget_value *val, 1366 widget_value *val,
1401 Boolean in_menubar, 1367 Boolean in_menubar,
1402 unsigned *toggle_width, 1368 unsigned *toggle_width,
1403 unsigned *label_width, 1369 unsigned *label_width,
1404 unsigned *bindings_width, 1370 unsigned *bindings_width,
1405 unsigned *height 1371 unsigned *height)
1406 )
1407 { 1372 {
1408 /* inherit */ 1373 /* inherit */
1409 label_button_size ( 1374 label_button_size (mw, val, in_menubar,
1410 mw, val, in_menubar,
1411 toggle_width, label_width, bindings_width, 1375 toggle_width, label_width, bindings_width,
1412 height 1376 height);
1413 );
1414 1377
1415 /* key bindings to display? */ 1378 /* key bindings to display? */
1416 if (!in_menubar && val->key) 1379 if (!in_menubar && val->key)
1417 { 1380 {
1418 int w; 1381 int w;
1427 *bindings_width += w + mw->menu.column_spacing; 1390 *bindings_width += w + mw->menu.column_spacing;
1428 } 1391 }
1429 } 1392 }
1430 1393
1431 static void 1394 static void
1432 push_button_draw ( 1395 push_button_draw (XlwMenuWidget mw,
1433 XlwMenuWidget mw,
1434 widget_value *val, 1396 widget_value *val,
1435 Boolean in_menubar, 1397 Boolean in_menubar,
1436 Boolean highlighted, 1398 Boolean highlighted,
1437 Window window, 1399 Window window,
1438 int x, int y, 1400 int x, int y,
1439 unsigned width, unsigned height, 1401 unsigned width, unsigned height,
1440 unsigned label_offset, 1402 unsigned label_offset,
1441 unsigned binding_offset 1403 unsigned binding_offset)
1442 )
1443 { 1404 {
1444 int y_offset = mw->menu.shadow_thickness + mw->menu.vertical_margin; 1405 int y_offset = mw->menu.shadow_thickness + mw->menu.vertical_margin;
1445 GC gc; 1406 GC gc;
1446 shadow_type type; 1407 shadow_type type;
1447 Boolean menu_pb = in_menubar && (menu_item_type (val) == BUTTON_TYPE); 1408 Boolean menu_pb = in_menubar && (menu_item_type (val) == BUTTON_TYPE);
1465 gc = mw->menu.foreground_gc; 1426 gc = mw->menu.foreground_gc;
1466 else 1427 else
1467 gc = mw->menu.inactive_gc; 1428 gc = mw->menu.inactive_gc;
1468 } 1429 }
1469 1430
1470 string_draw ( 1431 string_draw (mw,
1471 mw,
1472 window, 1432 window,
1473 x + label_offset, y + y_offset, 1433 x + label_offset, y + y_offset,
1474 gc, 1434 gc,
1475 resource_widget_value(mw, val) 1435 resource_widget_value(mw, val));
1476 );
1477 1436
1478 /* 1437 /*
1479 * Draw the keybindings 1438 * Draw the keybindings
1480 */ 1439 */
1481 if (val->key) 1440 if (val->key)
1524 1483
1525 return result; 1484 return result;
1526 } 1485 }
1527 1486
1528 static void 1487 static void
1529 cascade_button_size ( 1488 cascade_button_size (XlwMenuWidget mw,
1530 XlwMenuWidget mw,
1531 widget_value *val, 1489 widget_value *val,
1532 Boolean in_menubar, 1490 Boolean in_menubar,
1533 unsigned *toggle_width, 1491 unsigned *toggle_width,
1534 unsigned *label_width, 1492 unsigned *label_width,
1535 unsigned *arrow_width, 1493 unsigned *arrow_width,
1536 unsigned *height 1494 unsigned *height)
1537 )
1538 { 1495 {
1539 /* inherit */ 1496 /* inherit */
1540 label_button_size ( 1497 label_button_size (mw, val, in_menubar,
1541 mw, val, in_menubar,
1542 toggle_width, label_width, arrow_width, 1498 toggle_width, label_width, arrow_width,
1543 height 1499 height);
1544 );
1545 /* we have a pull aside arrow */ 1500 /* we have a pull aside arrow */
1546 if (!in_menubar) 1501 if (!in_menubar)
1547 { 1502 {
1548 *arrow_width += arrow_decoration_height(mw) + mw->menu.column_spacing; 1503 *arrow_width += arrow_decoration_height(mw) + mw->menu.column_spacing;
1549 } 1504 }
1550 } 1505 }
1551 1506
1552 static void 1507 static void
1553 cascade_button_draw ( 1508 cascade_button_draw (XlwMenuWidget mw,
1554 XlwMenuWidget mw,
1555 widget_value *val, 1509 widget_value *val,
1556 Boolean in_menubar, 1510 Boolean in_menubar,
1557 Boolean highlighted, 1511 Boolean highlighted,
1558 Window window, 1512 Window window,
1559 int x, int y, 1513 int x, int y,
1560 unsigned width, unsigned height, 1514 unsigned width, unsigned height,
1561 unsigned label_offset, 1515 unsigned label_offset,
1562 unsigned binding_offset 1516 unsigned binding_offset)
1563 )
1564 { 1517 {
1565 shadow_type type; 1518 shadow_type type;
1566 1519
1567 /* 1520 /*
1568 * Draw the label string. 1521 * Draw the label string.
1591 mw->menu.horizontal_margin; 1544 mw->menu.horizontal_margin;
1592 1545
1593 binding_offset = label_offset + s_width + mw->menu.shadow_thickness; 1546 binding_offset = label_offset + s_width + mw->menu.shadow_thickness;
1594 } 1547 }
1595 1548
1596 arrow_decoration_draw ( 1549 arrow_decoration_draw (mw,
1597 mw,
1598 window, 1550 window,
1599 x + binding_offset + mw->menu.column_spacing, 1551 x + binding_offset + mw->menu.column_spacing,
1600 y + y_offset, 1552 y + y_offset,
1601 arrow_height, 1553 arrow_height,
1602 highlighted 1554 highlighted);
1603 );
1604 } 1555 }
1605 1556
1606 /* 1557 /*
1607 * Draw the shadow 1558 * Draw the shadow
1608 */ 1559 */
1628 1579
1629 return rv; 1580 return rv;
1630 } 1581 }
1631 1582
1632 static void 1583 static void
1633 toggle_button_size ( 1584 toggle_button_size (XlwMenuWidget mw,
1634 XlwMenuWidget mw,
1635 widget_value *val, 1585 widget_value *val,
1636 Boolean in_menubar, 1586 Boolean in_menubar,
1637 unsigned *toggle_width, 1587 unsigned *toggle_width,
1638 unsigned *label_width, 1588 unsigned *label_width,
1639 unsigned *bindings_width, 1589 unsigned *bindings_width,
1640 unsigned *height 1590 unsigned *height)
1641 )
1642 { 1591 {
1643 /* inherit */ 1592 /* inherit */
1644 push_button_size ( 1593 push_button_size (mw, val, in_menubar,
1645 mw, val, in_menubar,
1646 toggle_width, label_width, bindings_width, 1594 toggle_width, label_width, bindings_width,
1647 height 1595 height);
1648 );
1649 /* we have a toggle */ 1596 /* we have a toggle */
1650 *toggle_width += toggle_decoration_height(mw) + mw->menu.column_spacing; 1597 *toggle_width += toggle_decoration_height(mw) + mw->menu.column_spacing;
1651 } 1598 }
1652 1599
1653 static void 1600 static void
1654 toggle_button_draw ( 1601 toggle_button_draw (XlwMenuWidget mw,
1655 XlwMenuWidget mw,
1656 widget_value *val, 1602 widget_value *val,
1657 Boolean in_menubar, 1603 Boolean in_menubar,
1658 Boolean highlighted, 1604 Boolean highlighted,
1659 Window window, 1605 Window window,
1660 int x, int y, 1606 int x, int y,
1661 unsigned width, unsigned height, 1607 unsigned width, unsigned height,
1662 unsigned label_tab, 1608 unsigned label_tab,
1663 unsigned binding_tab 1609 unsigned binding_tab)
1664 )
1665 { 1610 {
1666 int x_offset; 1611 int x_offset;
1667 int y_offset; 1612 int y_offset;
1668 unsigned t_height = toggle_decoration_height(mw); 1613 unsigned t_height = toggle_decoration_height(mw);
1669 1614
1689 { 1634 {
1690 return toggle_decoration_height(mw); 1635 return toggle_decoration_height(mw);
1691 } 1636 }
1692 1637
1693 static void 1638 static void
1694 radio_button_draw ( 1639 radio_button_draw (XlwMenuWidget mw,
1695 XlwMenuWidget mw,
1696 widget_value *val, 1640 widget_value *val,
1697 Boolean in_menubar, 1641 Boolean in_menubar,
1698 Boolean highlighted, 1642 Boolean highlighted,
1699 Window window, 1643 Window window,
1700 int x, int y, 1644 int x, int y,
1701 unsigned width, unsigned height, 1645 unsigned width, unsigned height,
1702 unsigned label_tab, 1646 unsigned label_tab,
1703 unsigned binding_tab 1647 unsigned binding_tab)
1704 )
1705 { 1648 {
1706 int x_offset; 1649 int x_offset;
1707 int y_offset; 1650 int y_offset;
1708 unsigned r_height = radio_decoration_height(mw); 1651 unsigned r_height = radio_decoration_height(mw);
1709 1652
1793 widget_value *val, 1736 widget_value *val,
1794 Boolean in_menubar, 1737 Boolean in_menubar,
1795 unsigned *toggle_width, 1738 unsigned *toggle_width,
1796 unsigned *label_width, 1739 unsigned *label_width,
1797 unsigned *rest_width, 1740 unsigned *rest_width,
1798 unsigned *height 1741 unsigned *height)
1799 )
1800 { 1742 {
1801 *height = separator_decoration_height (mw, val); 1743 *height = separator_decoration_height (mw, val);
1802 *label_width = 1; 1744 *label_width = 1;
1803 *toggle_width = *rest_width = 0; 1745 *toggle_width = *rest_width = 0;
1804 } 1746 }
1810 Boolean highlighted, 1752 Boolean highlighted,
1811 Window window, 1753 Window window,
1812 int x, int y, 1754 int x, int y,
1813 unsigned width, unsigned height, 1755 unsigned width, unsigned height,
1814 unsigned label_tab, 1756 unsigned label_tab,
1815 unsigned binding_tab 1757 unsigned binding_tab)
1816 )
1817 { 1758 {
1818 unsigned sep_width; 1759 unsigned sep_width;
1819 1760
1820 if (in_menubar) 1761 if (in_menubar)
1821 sep_width = height; 1762 sep_width = height;
1826 window, 1767 window,
1827 x, 1768 x,
1828 y, 1769 y,
1829 sep_width, 1770 sep_width,
1830 in_menubar, 1771 in_menubar,
1831 separator_type(val->value) 1772 separator_type(val->value));
1832 );
1833 } 1773 }
1834 1774
1835 static void 1775 static void
1836 pushright_size (XlwMenuWidget mw, 1776 pushright_size (XlwMenuWidget mw,
1837 widget_value *val, 1777 widget_value *val,
1853 unsigned *label_width, 1793 unsigned *label_width,
1854 unsigned *rest_width, 1794 unsigned *rest_width,
1855 unsigned *height 1795 unsigned *height
1856 ) 1796 )
1857 { 1797 {
1858 1798 void (*function_ptr) (XlwMenuWidget _mw,
1859 void (*function_ptr) (
1860 XlwMenuWidget _mw,
1861 widget_value *_val, 1799 widget_value *_val,
1862 Boolean _in_menubar, 1800 Boolean _in_menubar,
1863 unsigned *_toggle_width, 1801 unsigned *_toggle_width,
1864 unsigned *_label_width, 1802 unsigned *_label_width,
1865 unsigned *_rest_width, 1803 unsigned *_rest_width,
1866 unsigned *_height 1804 unsigned *_height);
1867 ); 1805
1868 switch (menu_item_type (val)) 1806 switch (menu_item_type (val))
1869 { 1807 {
1870 case TOGGLE_TYPE: 1808 case TOGGLE_TYPE:
1871 case RADIO_TYPE: 1809 case RADIO_TYPE:
1872 function_ptr = toggle_button_size; 1810 function_ptr = toggle_button_size;
1888 default: 1826 default:
1889 function_ptr = label_button_size; 1827 function_ptr = label_button_size;
1890 break; 1828 break;
1891 } 1829 }
1892 1830
1893 (*function_ptr) ( 1831 (*function_ptr) (mw,
1894 mw,
1895 val, 1832 val,
1896 horizontal, 1833 horizontal,
1897 toggle_width, 1834 toggle_width,
1898 label_width, 1835 label_width,
1899 rest_width, 1836 rest_width,
1900 height 1837 height);
1901 ); 1838 }
1902 } 1839
1903 1840 static void
1904 static void 1841 display_menu_item (XlwMenuWidget mw,
1905 display_menu_item (
1906 XlwMenuWidget mw,
1907 widget_value *val, 1842 widget_value *val,
1908 window_state *ws, 1843 window_state *ws,
1909 XPoint *where, 1844 XPoint *where,
1910 Boolean highlighted, 1845 Boolean highlighted,
1911 Boolean horizontal, 1846 Boolean horizontal,
1912 Boolean just_compute 1847 Boolean just_compute)
1913 )
1914 { 1848 {
1915 1849
1916 int x = where->x /* + mw->menu.shadow_thickness */ ; 1850 int x = where->x /* + mw->menu.shadow_thickness */ ;
1917 int y = where->y /* + mw->menu.shadow_thickness */ ; 1851 int y = where->y /* + mw->menu.shadow_thickness */ ;
1918 unsigned toggle_width; 1852 unsigned toggle_width;
1920 unsigned binding_width; 1854 unsigned binding_width;
1921 unsigned width; 1855 unsigned width;
1922 unsigned height; 1856 unsigned height;
1923 unsigned label_tab; 1857 unsigned label_tab;
1924 unsigned binding_tab; 1858 unsigned binding_tab;
1925 void (*function_ptr) ( 1859 void (*function_ptr) (XlwMenuWidget _mw,
1926 XlwMenuWidget _mw,
1927 widget_value *_val, 1860 widget_value *_val,
1928 Boolean _in_menubar, 1861 Boolean _in_menubar,
1929 Boolean _highlighted, 1862 Boolean _highlighted,
1930 Window _window, 1863 Window _window,
1931 int _x, int _y, 1864 int _x, int _y,
1932 unsigned _width, unsigned _height, 1865 unsigned _width, unsigned _height,
1933 unsigned _label_tab, 1866 unsigned _label_tab,
1934 unsigned _binding_tab 1867 unsigned _binding_tab);
1935 ); 1868
1936 1869 size_menu_item (mw, val, horizontal,
1937 size_menu_item ( 1870 &toggle_width, &label_width, &binding_width, &height);
1938 mw, val, horizontal,
1939 &toggle_width, &label_width, &binding_width, &height
1940 );
1941 1871
1942 if (horizontal) 1872 if (horizontal)
1943 { 1873 {
1944 width = toggle_width + label_width + binding_width; 1874 width = toggle_width + label_width + binding_width;
1945 height = ws->height - 2 * mw->menu.shadow_thickness; 1875 height = ws->height - 2 * mw->menu.shadow_thickness;
1983 break; 1913 break;
1984 default: /* do no drawing */ 1914 default: /* do no drawing */
1985 return; 1915 return;
1986 } 1916 }
1987 1917
1988 (*function_ptr) ( 1918 (*function_ptr) (mw,
1989 mw,
1990 val, 1919 val,
1991 horizontal, 1920 horizontal,
1992 highlighted, 1921 highlighted,
1993 ws->window, 1922 ws->window,
1994 x, y, 1923 x, y,
1995 width, height, 1924 width, height,
1996 label_tab, 1925 label_tab,
1997 binding_tab 1926 binding_tab);
1998 );
1999 } 1927 }
2000 1928
2001 static void 1929 static void
2002 size_menu (XlwMenuWidget mw, int level) 1930 size_menu (XlwMenuWidget mw, int level)
2003 { 1931 {
2004 unsigned toggle_width; 1932 unsigned toggle_width;
2005 unsigned label_width; 1933 unsigned label_width;
2006 unsigned rest_width; 1934 unsigned rest_width;
2007 unsigned height; 1935 unsigned height;
2008 unsigned max_toggle_width = 0; 1936 unsigned max_toggle_width = 0;
2009 unsigned max_label_width = 0; 1937 unsigned max_label_width = 0;
2010 unsigned max_rest_width = 0; 1938 unsigned max_rest_width = 0;
2011 unsigned max_height = 0; 1939 unsigned max_height = 0;
2012 int horizontal_p = mw->menu.horizontal && (level == 0); 1940 int horizontal_p = mw->menu.horizontal && (level == 0);
2013 widget_value* val; 1941 widget_value* val;
2014 window_state* ws; 1942 window_state* ws;
2015 1943
2018 1946
2019 ws = &mw->menu.windows [level]; 1947 ws = &mw->menu.windows [level];
2020 1948
2021 for (val = mw->menu.old_stack [level]->contents; val; val = val->next) 1949 for (val = mw->menu.old_stack [level]->contents; val; val = val->next)
2022 { 1950 {
2023 size_menu_item ( 1951 size_menu_item (mw,
2024 mw,
2025 val, 1952 val,
2026 horizontal_p, 1953 horizontal_p,
2027 &toggle_width, 1954 &toggle_width,
2028 &label_width, 1955 &label_width,
2029 &rest_width, 1956 &rest_width,
2030 &height 1957 &height);
2031 );
2032 if (horizontal_p) 1958 if (horizontal_p)
2033 { 1959 {
2034 max_label_width += toggle_width + label_width + rest_width; 1960 max_label_width += toggle_width + label_width + rest_width;
2035 if (height > max_height) 1961 if (height > max_height)
2036 max_height = height; 1962 max_height = height;
2037 } 1963 }
2038 else 1964 else
2039 { 1965 {
2040 if (toggle_width > max_toggle_width) 1966 if (max_toggle_width < toggle_width)
2041 max_toggle_width = toggle_width; 1967 max_toggle_width = toggle_width;
2042 if (label_width > max_label_width) 1968 if (max_label_width < label_width)
2043 max_label_width = label_width; 1969 max_label_width = label_width;
2044 if (rest_width > max_rest_width) 1970 if (max_rest_width < rest_width)
2045 max_rest_width = rest_width; 1971 max_rest_width = rest_width;
2046 max_height += height; 1972 max_height += height;
2047 } 1973 }
2048 } 1974 }
2049 1975
2050 ws->height = max_height; 1976 ws->height = max_height;
2051 ws->width = max_label_width + max_rest_width + max_toggle_width; 1977 ws->width = max_label_width + max_rest_width + max_toggle_width;
2052 ws->toggle_width = max_toggle_width; 1978 ws->toggle_width = max_toggle_width;
2053 ws->label_width = max_label_width; 1979 ws->label_width = max_label_width;
2054 1980
2055 ws->width += 2 * mw->menu.shadow_thickness; 1981 ws->width += 2 * mw->menu.shadow_thickness;
2056 ws->height += 2 * mw->menu.shadow_thickness; 1982 ws->height += 2 * mw->menu.shadow_thickness;
2057 } 1983 }
2058 1984
2059 static void 1985 static void
2060 display_menu (XlwMenuWidget mw, int level, Boolean just_compute_p, 1986 display_menu (XlwMenuWidget mw, int level, Boolean just_compute_p,
2226 start_at = 0; 2152 start_at = 0;
2227 } 2153 }
2228 else 2154 else
2229 { 2155 {
2230 mw->menu.windows = 2156 mw->menu.windows =
2231 (window_state *) XtRealloc ((char*)mw->menu.windows, 2157 (window_state *) XtRealloc ((char *) mw->menu.windows,
2232 n * sizeof (window_state)); 2158 n * sizeof (window_state));
2233 start_at = mw->menu.windows_length; 2159 start_at = mw->menu.windows_length;
2234 } 2160 }
2235 mw->menu.windows_length = n; 2161 mw->menu.windows_length = n;
2236 2162
2391 window_state *ws = &mw->menu.windows [level]; 2317 window_state *ws = &mw->menu.windows [level];
2392 int x = level == 0 ? ws->x : ws->x + mw->menu.shadow_thickness; 2318 int x = level == 0 ? ws->x : ws->x + mw->menu.shadow_thickness;
2393 int y = level == 0 ? ws->y : ws->y + mw->menu.shadow_thickness; 2319 int y = level == 0 ? ws->y : ws->y + mw->menu.shadow_thickness;
2394 relative_pos->x = ev->x_root - x; 2320 relative_pos->x = ev->x_root - x;
2395 relative_pos->y = ev->y_root - y; 2321 relative_pos->y = ev->y_root - y;
2396 return (x < ev->x_root && ev->x_root < (int) (x + ws->width) 2322 return (x < ev->x_root && ev->x_root < (int) (x + ws->width) &&
2397 && y < ev->y_root && ev->y_root < (int) (y + ws->height)); 2323 y < ev->y_root && ev->y_root < (int) (y + ws->height));
2398 } 2324 }
2399 2325
2400 static Boolean 2326 static Boolean
2401 map_event_to_widget_value (XlwMenuWidget mw, XMotionEvent *ev, 2327 map_event_to_widget_value (XlwMenuWidget mw, XMotionEvent *ev,
2402 widget_value **val_ptr, int *level, 2328 widget_value **val_ptr, int *level,
2500 mw->menu.button_gc = XtGetGC ((Widget)mw, flags, &xgcv); 2426 mw->menu.button_gc = XtGetGC ((Widget)mw, flags, &xgcv);
2501 2427
2502 xgcv.fill_style = FillStippled; 2428 xgcv.fill_style = FillStippled;
2503 xgcv.stipple = mw->menu.gray_pixmap; 2429 xgcv.stipple = mw->menu.gray_pixmap;
2504 mw->menu.inactive_button_gc = XtGetGC ((Widget)mw, 2430 mw->menu.inactive_button_gc = XtGetGC ((Widget)mw,
2505 (flags | GCFillStyle | GCStipple), 2431 (flags | GCFillStyle | GCStipple),
2506 &xgcv); 2432 &xgcv);
2507 } 2433 }
2508 2434
2509 static void 2435 static void
2510 release_drawing_gcs (XlwMenuWidget mw) 2436 release_drawing_gcs (XlwMenuWidget mw)
2514 XtReleaseGC ((Widget) mw, mw->menu.inactive_gc); 2440 XtReleaseGC ((Widget) mw, mw->menu.inactive_gc);
2515 XtReleaseGC ((Widget) mw, mw->menu.inactive_button_gc); 2441 XtReleaseGC ((Widget) mw, mw->menu.inactive_button_gc);
2516 XtReleaseGC ((Widget) mw, mw->menu.background_gc); 2442 XtReleaseGC ((Widget) mw, mw->menu.background_gc);
2517 XtReleaseGC ((Widget) mw, mw->menu.select_gc); 2443 XtReleaseGC ((Widget) mw, mw->menu.select_gc);
2518 /* let's get some segvs if we try to use these... */ 2444 /* let's get some segvs if we try to use these... */
2519 mw->menu.foreground_gc = (GC) -1; 2445 mw->menu.foreground_gc = (GC) -1;
2520 mw->menu.button_gc = (GC) -1; 2446 mw->menu.button_gc = (GC) -1;
2521 mw->menu.inactive_gc = (GC) -1; 2447 mw->menu.inactive_gc = (GC) -1;
2522 mw->menu.inactive_button_gc = (GC) -1; 2448 mw->menu.inactive_button_gc = (GC) -1;
2523 mw->menu.background_gc = (GC) -1; 2449 mw->menu.background_gc = (GC) -1;
2524 mw->menu.select_gc = (GC) -1; 2450 mw->menu.select_gc = (GC) -1;
2525 } 2451 }
2526 2452
2527 #define MINL(x,y) ((((unsigned long) (x)) < ((unsigned long) (y))) \ 2453 #define MINL(x,y) ((((unsigned long) (x)) < ((unsigned long) (y))) \
2528 ? ((unsigned long) (x)) : ((unsigned long) (y))) 2454 ? ((unsigned long) (x)) : ((unsigned long) (y)))
2529 2455
2536 Colormap cmap = DefaultColormapOfScreen (XtScreen ((Widget) mw)); 2462 Colormap cmap = DefaultColormapOfScreen (XtScreen ((Widget) mw));
2537 XColor topc, botc; 2463 XColor topc, botc;
2538 int top_frobbed = 0, bottom_frobbed = 0; 2464 int top_frobbed = 0, bottom_frobbed = 0;
2539 2465
2540 if (mw->menu.top_shadow_color == -1) 2466 if (mw->menu.top_shadow_color == -1)
2541 mw->menu.top_shadow_color = mw->core.background_pixel; 2467 mw->menu.top_shadow_color = mw->core.background_pixel;
2542 if (mw->menu.bottom_shadow_color == -1) 2468 if (mw->menu.bottom_shadow_color == -1)
2543 mw->menu.bottom_shadow_color = mw->menu.foreground; 2469 mw->menu.bottom_shadow_color = mw->menu.foreground;
2544 2470
2545 if (mw->menu.top_shadow_color == mw->core.background_pixel || 2471 if (mw->menu.top_shadow_color == mw->core.background_pixel ||
2546 mw->menu.top_shadow_color == mw->menu.foreground) 2472 mw->menu.top_shadow_color == mw->menu.foreground)
2547 { 2473 {
2548 topc.pixel = mw->core.background_pixel; 2474 topc.pixel = mw->core.background_pixel;
2801 Display *display = XtDisplay (mw); 2727 Display *display = XtDisplay (mw);
2802 2728
2803 /* mw->menu.cursor = XCreateFontCursor (display, mw->menu.cursor_shape); */ 2729 /* mw->menu.cursor = XCreateFontCursor (display, mw->menu.cursor_shape); */
2804 mw->menu.cursor = mw->menu.cursor_shape; 2730 mw->menu.cursor = mw->menu.cursor_shape;
2805 2731
2806 mw->menu.gray_pixmap = XCreatePixmapFromBitmapData (display, window, 2732 mw->menu.gray_pixmap =
2807 (char *) gray_bits, 2733 XCreatePixmapFromBitmapData (display, window, (char *) gray_bits,
2808 gray_width, 2734 gray_width, gray_height, 1, 0, 1);
2809 gray_height, 1, 0, 1);
2810 2735
2811 #ifdef NEED_MOTIF 2736 #ifdef NEED_MOTIF
2812 /* The menu.font_list slot came from the *fontList resource (Motif standard.) 2737 /* The menu.font_list slot came from the *fontList resource (Motif standard.)
2813 The menu.font_list_2 slot came from the *font resource, for backward 2738 The menu.font_list_2 slot came from the *font resource, for backward
2814 compatibility with older versions of this code, and consistency with the 2739 compatibility with older versions of this code, and consistency with the
2922 XtUngrabPointer (w, CurrentTime); 2847 XtUngrabPointer (w, CurrentTime);
2923 mw->menu.pointer_grabbed = False; 2848 mw->menu.pointer_grabbed = False;
2924 } 2849 }
2925 2850
2926 release_drawing_gcs (mw); 2851 release_drawing_gcs (mw);
2927 release_shadow_gcs (mw); 2852 release_shadow_gcs (mw);
2928 2853
2929 /* this doesn't come from the resource db but is created explicitly 2854 /* this doesn't come from the resource db but is created explicitly
2930 so we must free it ourselves. */ 2855 so we must free it ourselves. */
2931 XFreePixmap (XtDisplay (mw), mw->menu.gray_pixmap); 2856 XFreePixmap (XtDisplay (mw), mw->menu.gray_pixmap);
2932 mw->menu.gray_pixmap = (Pixmap) -1; 2857 mw->menu.gray_pixmap = (Pixmap) -1;
2972 2897
2973 if (newmw->core.background_pixel != oldmw->core.background_pixel 2898 if (newmw->core.background_pixel != oldmw->core.background_pixel
2974 || newmw->menu.foreground != oldmw->menu.foreground 2899 || newmw->menu.foreground != oldmw->menu.foreground
2975 /* For the XEditResource protocol, which may want to change the font. */ 2900 /* For the XEditResource protocol, which may want to change the font. */
2976 #ifdef NEED_MOTIF 2901 #ifdef NEED_MOTIF
2977 || newmw->menu.font_list != oldmw->menu.font_list 2902 || newmw->menu.font_list != oldmw->menu.font_list
2978 || newmw->menu.font_list_2 != oldmw->menu.font_list_2 2903 || newmw->menu.font_list_2 != oldmw->menu.font_list_2
2979 || newmw->menu.fallback_font_list != oldmw->menu.fallback_font_list 2904 || newmw->menu.fallback_font_list != oldmw->menu.fallback_font_list
2980 #else 2905 #else
2981 || newmw->menu.font != oldmw->menu.font 2906 || newmw->menu.font != oldmw->menu.font
2982 #endif 2907 #endif
2983 ) 2908 )
3003 static void 2928 static void
3004 XlwMenuResize (Widget w) 2929 XlwMenuResize (Widget w)
3005 { 2930 {
3006 XlwMenuWidget mw = (XlwMenuWidget)w; 2931 XlwMenuWidget mw = (XlwMenuWidget)w;
3007 2932
3008 mw->menu.windows [0].width = mw->core.width; 2933 mw->menu.windows [0].width = mw->core.width;
3009 mw->menu.windows [0].height = mw->core.height; 2934 mw->menu.windows [0].height = mw->core.height;
3010 } 2935 }
3011 2936
3012 /* Action procedures */ 2937 /* Action procedures */
3013 static void 2938 static void
3165 mw->menu.popped_up = False; 3090 mw->menu.popped_up = False;
3166 XtPopdown (XtParent (mw)); 3091 XtPopdown (XtParent (mw));
3167 } 3092 }
3168 3093
3169 /* callback */ 3094 /* callback */
3170 XtCallCallbackList ((Widget)mw, mw->menu.select, (XtPointer)selected_item); 3095 XtCallCallbackList ((Widget) mw, mw->menu.select, (XtPointer) selected_item);
3171 } 3096 }
3172 3097
3173 3098
3174 /* Special code to pop-up a menu */ 3099 /* Special code to pop-up a menu */
3175 void 3100 void
3185 mw->menu.menu_post_time = event->time; 3110 mw->menu.menu_post_time = event->time;
3186 mw->menu.menu_bounce_time = 0; 3111 mw->menu.menu_bounce_time = 0;
3187 mw->menu.next_release_must_exit = True; 3112 mw->menu.next_release_must_exit = True;
3188 mw->menu.last_selected_val = NULL; 3113 mw->menu.last_selected_val = NULL;
3189 3114
3190 XtCallCallbackList ((Widget)mw, mw->menu.open, NULL); 3115 XtCallCallbackList ((Widget) mw, mw->menu.open, NULL);
3191 3116
3192 size_menu (mw, 0); 3117 size_menu (mw, 0);
3193 3118
3194 w = mw->menu.windows [0].width; 3119 w = mw->menu.windows [0].width;
3195 h = mw->menu.windows [0].height; 3120 h = mw->menu.windows [0].height;
3196 3121
3197 x -= borderwidth; 3122 x -= borderwidth;
3198 y -= borderwidth; 3123 y -= borderwidth;
3124
3199 if (x < borderwidth) 3125 if (x < borderwidth)
3200 x = borderwidth; 3126 x = borderwidth;
3201 if (x + w + 2 * borderwidth > WidthOfScreen (screen)) 3127
3202 x = WidthOfScreen (screen) - w - 2 * borderwidth; 3128 if (x > WidthOfScreen (screen) - w - 2 * borderwidth)
3129 x = WidthOfScreen (screen) - w - 2 * borderwidth;
3130
3203 if (y < borderwidth) 3131 if (y < borderwidth)
3204 y = borderwidth; 3132 y = borderwidth;
3205 if (y + h + 2 * borderwidth> HeightOfScreen (screen)) 3133
3206 y = HeightOfScreen (screen) - h - 2 * borderwidth; 3134 if (y > HeightOfScreen (screen) - h - 2 * borderwidth)
3135 y = HeightOfScreen (screen) - h - 2 * borderwidth;
3207 3136
3208 mw->menu.popped_up = True; 3137 mw->menu.popped_up = True;
3209 XtConfigureWidget (XtParent (mw), x, y, w, h, 3138 XtConfigureWidget (XtParent (mw), x, y, w, h,
3210 XtParent (mw)->core.border_width); 3139 XtParent (mw)->core.border_width);
3211 XtPopup (XtParent (mw), XtGrabExclusive); 3140 XtPopup (XtParent (mw), XtGrabExclusive);
3235 */ 3164 */
3236 void 3165 void
3237 xlw_unmunge_class_resize (Widget w) 3166 xlw_unmunge_class_resize (Widget w)
3238 { 3167 {
3239 if (w->core.widget_class->core_class.resize != XlwMenuResize) 3168 if (w->core.widget_class->core_class.resize != XlwMenuResize)
3240 w->core.widget_class->core_class.resize = XlwMenuResize; 3169 w->core.widget_class->core_class.resize = XlwMenuResize;
3241 } 3170 }
3242 #endif /* 0 */ 3171 #endif /* 0 */
3243 3172