comparison lwlib/xlwmenu.c @ 80:1ce6082ce73f r20-0b90

Import from CVS: tag r20-0b90
author cvs
date Mon, 13 Aug 2007 09:06:37 +0200
parents c7528f8e288d
children ac0620f6398e
comparison
equal deleted inserted replaced
79:5b0a5bbffab6 80:1ce6082ce73f
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
172 XlwMenuRedisplay, /* expose */ 171 XlwMenuRedisplay, /* expose */
173 XlwMenuSetValues, /* set_values */ 172 XlwMenuSetValues, /* set_values */
174 NULL, /* set_values_hook */ 173 NULL, /* set_values_hook */
175 XtInheritSetValuesAlmost, /* set_values_almost */ 174 XtInheritSetValuesAlmost, /* set_values_almost */
176 NULL, /* get_values_hook */ 175 NULL, /* get_values_hook */
177 NULL, /* #### - should this be set for */ 176 NULL, /* #### - should this be set for grabs? accept_focus */
178 /* grabs? accept_focus */
179 XtVersion, /* version */ 177 XtVersion, /* version */
180 NULL, /* callback_private */ 178 NULL, /* callback_private */
181 xlwMenuTranslations, /* tm_table */ 179 xlwMenuTranslations, /* tm_table */
182 XtInheritQueryGeometry, /* query_geometry */ 180 XtInheritQueryGeometry, /* query_geometry */
183 XtInheritDisplayAccelerator, /* display_accelerator */ 181 XtInheritDisplayAccelerator, /* display_accelerator */
218 if (status) 216 if (status)
219 return status; 217 return status;
220 218
221 { 219 {
222 /* If we got to this point, the colormap is full, so we're 220 /* If we got to this point, the colormap is full, so we're
223 going to try and get the next closest color. 221 going to try to get the next closest color.
224 The algorithm used is a least-squares matching, which is 222 The algorithm used is a least-squares matching, which is
225 what X uses for closest color matching with StaticColor visuals. */ 223 what X uses for closest color matching with StaticColor visuals. */
226 224
227 int nearest, x; 225 int nearest, x;
228 unsigned long nearest_delta = ULONG_MAX; 226 unsigned long nearest_delta = ULONG_MAX;
248 { 246 {
249 nearest = x; 247 nearest = x;
250 nearest_delta = delta; 248 nearest_delta = delta;
251 } 249 }
252 } 250 }
253 color_def->red = cells[nearest].red; 251 color_def->red = cells[nearest].red;
254 color_def->green = cells[nearest].green; 252 color_def->green = cells[nearest].green;
255 color_def->blue = cells[nearest].blue; 253 color_def->blue = cells[nearest].blue;
256
257 free (cells); 254 free (cells);
258 return XAllocColor (display, screen_colormap, color_def); 255 return XAllocColor (display, screen_colormap, color_def);
259 } 256 }
260 } 257 }
261 258
271 } 268 }
272 else if (mw->menu.new_depth == mw->menu.new_stack_length) 269 else if (mw->menu.new_depth == mw->menu.new_stack_length)
273 { 270 {
274 mw->menu.new_stack_length *= 2; 271 mw->menu.new_stack_length *= 2;
275 mw->menu.new_stack = 272 mw->menu.new_stack =
276 (widget_value**)XtRealloc ((char*)mw->menu.new_stack, 273 (widget_value**)XtRealloc ((char *)mw->menu.new_stack,
277 mw->menu.new_stack_length * 274 mw->menu.new_stack_length *
278 sizeof (widget_value*)); 275 sizeof (widget_value*));
279 } 276 }
280 mw->menu.new_stack [mw->menu.new_depth++] = val; 277 mw->menu.new_stack [mw->menu.new_depth++] = val;
281 } 278 }
282 279
283 static void 280 static void
284 pop_new_stack_if_no_contents (XlwMenuWidget mw) 281 pop_new_stack_if_no_contents (XlwMenuWidget mw)
285 { 282 {
286 if (mw->menu.new_depth) 283 if (mw->menu.new_depth &&
287 { 284 !mw->menu.new_stack [mw->menu.new_depth - 1]->contents)
288 if (!mw->menu.new_stack [mw->menu.new_depth - 1]->contents) 285 mw->menu.new_depth -= 1;
289 {
290 mw->menu.new_depth -= 1;
291 }
292 }
293 } 286 }
294 287
295 static void 288 static void
296 make_old_stack_space (XlwMenuWidget mw, int n) 289 make_old_stack_space (XlwMenuWidget mw, int n)
297 { 290 {
304 } 297 }
305 else if (mw->menu.old_stack_length < n) 298 else if (mw->menu.old_stack_length < n)
306 { 299 {
307 mw->menu.old_stack_length *= 2; 300 mw->menu.old_stack_length *= 2;
308 mw->menu.old_stack = 301 mw->menu.old_stack =
309 (widget_value**)XtRealloc ((char*)mw->menu.old_stack, 302 (widget_value**)XtRealloc ((char *)mw->menu.old_stack,
310 mw->menu.old_stack_length * 303 mw->menu.old_stack_length *
311 sizeof (widget_value*)); 304 sizeof (widget_value*));
312 } 305 }
313 } 306 }
314 307
315 static Boolean 308 static Boolean
316 close_to_reference_time(Widget w, Time reference_time, XEvent *ev) 309 close_to_reference_time(Widget w, Time reference_time, XEvent *ev)
317 { 310 {
318 return (reference_time && 311 return
319 (ev->xbutton.time - reference_time 312 reference_time &&
320 < XtGetMultiClickTime (XtDisplay (w)))); 313 (ev->xbutton.time - reference_time < XtGetMultiClickTime (XtDisplay (w)));
321 } 314 }
322 315
323 /* Size code */ 316 /* Size code */
324 static int 317 static int
325 string_width (XlwMenuWidget mw, 318 string_width (XlwMenuWidget mw,
444 437
445 for (ntimes = 1, result = (char *) string; (percent = strchr(result, '%')); 438 for (ntimes = 1, result = (char *) string; (percent = strchr(result, '%'));
446 ntimes++) 439 ntimes++)
447 result = &percent[1]; 440 result = &percent[1];
448 441
449 result = XtMalloc((ntimes * strlen(value)) + strlen(string) + 4); 442 result = XtMalloc ((ntimes * strlen(value)) + strlen(string) + 4);
450 result[0] = '\0'; 443 result[0] = '\0';
451 444
452 while ((percent = strchr(string, '%'))) 445 while ((percent = strchr(string, '%')))
453 { 446 {
454 unsigned left_pad; 447 unsigned left_pad;
581 XtFree (converted_name); 574 XtFree (converted_name);
582 575
583 val->toolkit_data = complete_name; 576 val->toolkit_data = complete_name;
584 val->free_toolkit_data = True; 577 val->free_toolkit_data = True;
585 } 578 }
586 return ((XmString) val->toolkit_data); 579 return (XmString) val->toolkit_data;
587 } 580 }
588 581
589 /* Unused */ 582 /* Unused */
590 #if 0 583 #if 0
591 /* 584 /*
606 XtGetSubresources (w, 599 XtGetSubresources (w,
607 (XtPointer)&string, 600 (XtPointer)&string,
608 name, 601 name,
609 name, 602 name,
610 nameResource, 1, 603 nameResource, 1,
611 NULL, 0 604 NULL, 0);
612 );
613 605
614 if (!string) 606 if (!string)
615 string = name; 607 string = name;
616 608
617 return parameterize_string (string, arg); 609 return parameterize_string (string, arg);
662 if (complete_name[0] == '\n') 654 if (complete_name[0] == '\n')
663 complete_name[0] = ' '; 655 complete_name[0] = ' ';
664 } 656 }
665 val->free_toolkit_data = True; 657 val->free_toolkit_data = True;
666 } 658 }
667 return (char*)val->toolkit_data; 659 return (char *) val->toolkit_data;
668 } 660 }
669 661
670 #endif /* !Motif */ 662 #endif /* !Motif */
671 663
672 /* 664 /*
673 * Code for drawing strings. 665 * Code for drawing strings.
674 */ 666 */
675 static void 667 static void
676 string_draw( 668 string_draw(XlwMenuWidget mw,
677 XlwMenuWidget mw,
678 Window window, 669 Window window,
679 int x, int y, 670 int x, int y,
680 GC gc, 671 GC gc,
681 #ifdef NEED_MOTIF 672 #ifdef NEED_MOTIF
682 XmString string 673 XmString string
683 #else 674 #else
684 char *string 675 char *string
685 #endif 676 #endif
686 ) { 677 )
678 {
687 #ifdef NEED_MOTIF 679 #ifdef NEED_MOTIF
688 XmStringDraw (XtDisplay (mw), window, 680 XmStringDraw (XtDisplay (mw), window,
689 mw->menu.font_list, 681 mw->menu.font_list,
690 string, gc, 682 string, gc,
691 x, y, 683 x, y,
714 706
715 /* 707 /*
716 * Low level code for drawing 3-D edges. 708 * Low level code for drawing 3-D edges.
717 */ 709 */
718 static void 710 static void
719 shadow_rectangle_draw ( 711 shadow_rectangle_draw (Display *dpy,
720 Display *dpy,
721 Window window, 712 Window window,
722 GC top_gc, 713 GC top_gc,
723 GC bottom_gc, 714 GC bottom_gc,
724 int x, int y, unsigned width, unsigned height, 715 int x, int y, unsigned width, unsigned height,
725 unsigned thickness 716 unsigned thickness)
726 )
727 { 717 {
728 XPoint points [4]; 718 XPoint points [4];
729 719
730 if (!thickness) 720 if (!thickness)
731 return; 721 return;
792 782
793 static void 783 static void
794 shadow_draw (XlwMenuWidget mw, 784 shadow_draw (XlwMenuWidget mw,
795 Window window, 785 Window window,
796 int x, int y, unsigned width, unsigned height, 786 int x, int y, unsigned width, unsigned height,
797 shadow_type type 787 shadow_type type)
798 )
799 { 788 {
800 Display *dpy = XtDisplay (mw); 789 Display *dpy = XtDisplay (mw);
801 GC top_gc; 790 GC top_gc;
802 GC bottom_gc; 791 GC bottom_gc;
803 int thickness = mw->menu.shadow_thickness; 792 int thickness = mw->menu.shadow_thickness;
833 } 822 }
834 823
835 if (etched) 824 if (etched)
836 { 825 {
837 unsigned half = thickness/2; 826 unsigned half = thickness/2;
838 shadow_rectangle_draw ( 827 shadow_rectangle_draw (dpy,
839 dpy,
840 window, 828 window,
841 top_gc, 829 top_gc,
842 top_gc, 830 top_gc,
843 x, y, 831 x, y,
844 width - half, height - half, 832 width - half, height - half,
845 thickness - half 833 thickness - half);
846 ); 834 shadow_rectangle_draw (dpy,
847 shadow_rectangle_draw (
848 dpy,
849 window, 835 window,
850 bottom_gc, 836 bottom_gc,
851 bottom_gc, 837 bottom_gc,
852 x + half, y + half, 838 x + half, y + half,
853 width - half , height - half, 839 width - half , height - half,
854 half 840 half);
855 );
856 } 841 }
857 else 842 else
858 { 843 {
859 shadow_rectangle_draw ( 844 shadow_rectangle_draw (dpy,
860 dpy,
861 window, 845 window,
862 top_gc, 846 top_gc,
863 bottom_gc, 847 bottom_gc,
864 x, y, 848 x, y,
865 width, height, 849 width, height,
866 thickness 850 thickness);
867 );
868 } 851 }
869 } 852 }
870 853
871 static void 854 static void
872 arrow_decoration_draw ( 855 arrow_decoration_draw (XlwMenuWidget mw,
873 XlwMenuWidget mw,
874 Window window, 856 Window window,
875 int x, int y, 857 int x, int y,
876 unsigned width, 858 unsigned width,
877 Boolean raised 859 Boolean raised)
878 )
879 { 860 {
880 Display *dpy = XtDisplay (mw); 861 Display *dpy = XtDisplay (mw);
881 GC top_gc; 862 GC top_gc;
882 GC bottom_gc; 863 GC bottom_gc;
883 GC select_gc; 864 GC select_gc;
894 875
895 select_gc = mw->menu.background_gc; 876 select_gc = mw->menu.background_gc;
896 877
897 if (raised) 878 if (raised)
898 { 879 {
899 top_gc = mw->menu.shadow_bottom_gc; 880 top_gc = mw->menu.shadow_bottom_gc;
900 bottom_gc = mw->menu.shadow_top_gc; 881 bottom_gc = mw->menu.shadow_top_gc;
901 } 882 }
902 else 883 else
903 { 884 {
904 top_gc = mw->menu.shadow_top_gc; 885 top_gc = mw->menu.shadow_top_gc;
905 bottom_gc = mw->menu.shadow_bottom_gc; 886 bottom_gc = mw->menu.shadow_bottom_gc;
906 } 887 }
907 888
908 /* 889 /*
909 * Fill internal area, we do this first so that the borders 890 * Fill internal area, we do this first so that the borders
916 points [2].x = x + length - thickness; 897 points [2].x = x + length - thickness;
917 points [2].y = y + half_width + thickness; 898 points [2].y = y + half_width + thickness;
918 points [3].x = x + thickness; 899 points [3].x = x + thickness;
919 points [3].y = y + width - thickness; 900 points [3].y = y + width - thickness;
920 901
921 XFillPolygon ( 902 XFillPolygon (dpy,
922 dpy,
923 window, 903 window,
924 select_gc, 904 select_gc,
925 points, 905 points,
926 4, 906 4,
927 Convex, 907 Convex,
928 CoordModeOrigin 908 CoordModeOrigin);
929 );
930 909
931 /* left border */ 910 /* left border */
932 points [0].x = x; 911 points [0].x = x;
933 points [0].y = y; 912 points [0].y = y;
934 points [1].x = x + thickness; 913 points [1].x = x + thickness;
964 943
965 XFillPolygon (dpy, window, top_gc, points, 4, Convex, CoordModeOrigin); 944 XFillPolygon (dpy, window, top_gc, points, 4, Convex, CoordModeOrigin);
966 } 945 }
967 946
968 static void 947 static void
969 toggle_decoration_draw ( 948 toggle_decoration_draw (XlwMenuWidget mw,
970 XlwMenuWidget mw,
971 Window window, 949 Window window,
972 int x, int y, 950 int x, int y,
973 unsigned width, 951 unsigned width,
974 Boolean set 952 Boolean set)
975 )
976 { 953 {
977 Display *dpy = XtDisplay (mw); 954 Display *dpy = XtDisplay (mw);
978 int thickness = mw->menu.shadow_thickness; 955 int thickness = mw->menu.shadow_thickness;
979 shadow_type type; 956 shadow_type type;
980 GC select_gc = mw->menu.select_gc; 957 GC select_gc = mw->menu.select_gc;
986 963
987 /* 964 /*
988 * Fill internal area. 965 * Fill internal area.
989 */ 966 */
990 if (set) 967 if (set)
991 XFillRectangle ( 968 XFillRectangle (dpy,
992 dpy,
993 window, 969 window,
994 select_gc, 970 select_gc,
995 x + thickness, 971 x + thickness,
996 y + thickness, 972 y + thickness,
997 width - (2*thickness), 973 width - (2*thickness),
998 width - (2*thickness) 974 width - (2*thickness));
999 );
1000 975
1001 shadow_draw(mw, window, x, y, width, width, type); 976 shadow_draw(mw, window, x, y, width, width, type);
1002 } 977 }
1003 978
1004 static void 979 static void
1005 radio_decoration_draw ( 980 radio_decoration_draw (XlwMenuWidget mw,
1006 XlwMenuWidget mw,
1007 Window window, 981 Window window,
1008 int x, int y, 982 int x, int y,
1009 unsigned width, 983 unsigned width,
1010 Boolean enabled 984 Boolean enabled)
1011 )
1012 { 985 {
1013 Display *dpy = XtDisplay (mw); 986 Display *dpy = XtDisplay (mw);
1014 GC top_gc; 987 GC top_gc;
1015 GC bottom_gc; 988 GC bottom_gc;
1016 GC select_gc = mw->menu.select_gc; 989 GC select_gc = mw->menu.select_gc;
1026 999
1027 half_width = width/2; 1000 half_width = width/2;
1028 1001
1029 if (enabled) 1002 if (enabled)
1030 { 1003 {
1031 top_gc = mw->menu.shadow_bottom_gc; 1004 top_gc = mw->menu.shadow_bottom_gc;
1032 bottom_gc = mw->menu.shadow_top_gc; 1005 bottom_gc = mw->menu.shadow_top_gc;
1033 } 1006 }
1034 else 1007 else
1035 { 1008 {
1036 top_gc = mw->menu.shadow_top_gc; 1009 top_gc = mw->menu.shadow_top_gc;
1037 bottom_gc = mw->menu.shadow_bottom_gc; 1010 bottom_gc = mw->menu.shadow_bottom_gc;
1038 } 1011 }
1039 1012
1040 #if 1 1013 #if 1
1041 /* 1014 /*
1144 window, 1117 window,
1145 select_gc, 1118 select_gc,
1146 points, 1119 points,
1147 4, 1120 4,
1148 Convex, 1121 Convex,
1149 CoordModeOrigin 1122 CoordModeOrigin);
1150 ); 1123 }
1151 } 1124 }
1152 } 1125
1153 1126 static void
1154 static void 1127 separator_decoration_draw (XlwMenuWidget mw,
1155 separator_decoration_draw (
1156 XlwMenuWidget mw,
1157 Window window, 1128 Window window,
1158 int x, int y, 1129 int x, int y,
1159 unsigned width, 1130 unsigned width,
1160 Boolean vertical, 1131 Boolean vertical,
1161 shadow_type type 1132 shadow_type type)
1162 )
1163 { 1133 {
1164 Display *dpy = XtDisplay (mw); 1134 Display *dpy = XtDisplay (mw);
1165 GC top_gc; 1135 GC top_gc;
1166 GC bottom_gc; 1136 GC bottom_gc;
1167 unsigned offset = 0; 1137 unsigned offset = 0;
1239 { 1209 {
1240 for (i = 0; i < top_line_thickness; i++) 1210 for (i = 0; i < top_line_thickness; i++)
1241 XDrawLine (dpy, window, top_gc, x, y + i, x + width, y + i); 1211 XDrawLine (dpy, window, top_gc, x, y + i, x + width, y + i);
1242 1212
1243 for (i = 0; i < bottom_line_thickness; i++) 1213 for (i = 0; i < bottom_line_thickness; i++)
1244 XDrawLine ( 1214 XDrawLine (dpy, window, bottom_gc,
1245 dpy, window, bottom_gc,
1246 x, y + top_line_thickness + offset + i, 1215 x, y + top_line_thickness + offset + i,
1247 x + width, y + top_line_thickness + offset + i 1216 x + width, y + top_line_thickness + offset + i);
1248 );
1249 y += (top_line_thickness + offset + bottom_line_thickness + 1); 1217 y += (top_line_thickness + offset + bottom_line_thickness + 1);
1250 } 1218 }
1251 1219
1252 if (dashed) 1220 if (dashed)
1253 { 1221 {
1348 #endif 1316 #endif
1349 } 1317 }
1350 } 1318 }
1351 1319
1352 static void 1320 static void
1353 label_button_size ( 1321 label_button_size (XlwMenuWidget mw,
1354 XlwMenuWidget mw,
1355 widget_value *val, 1322 widget_value *val,
1356 Boolean in_menubar, 1323 Boolean in_menubar,
1357 unsigned *toggle_width, 1324 unsigned *toggle_width,
1358 unsigned *label_width, 1325 unsigned *label_width,
1359 unsigned *bindings_width, 1326 unsigned *bindings_width,
1360 unsigned *height 1327 unsigned *height)
1361 )
1362 { 1328 {
1363 *height = (mw->menu.font_ascent + mw->menu.font_descent + 1329 *height = (mw->menu.font_ascent + mw->menu.font_descent +
1364 2 * mw->menu.vertical_margin + 1330 2 * mw->menu.vertical_margin +
1365 2 * mw->menu.shadow_thickness); 1331 2 * mw->menu.shadow_thickness);
1366 /* no left column decoration */ 1332 /* no left column decoration */
1369 *label_width = string_width (mw, resource_widget_value (mw, val)); 1335 *label_width = string_width (mw, resource_widget_value (mw, val));
1370 *bindings_width = mw->menu.horizontal_margin + mw->menu.shadow_thickness; 1336 *bindings_width = mw->menu.horizontal_margin + mw->menu.shadow_thickness;
1371 } 1337 }
1372 1338
1373 static void 1339 static void
1374 label_button_draw ( 1340 label_button_draw (XlwMenuWidget mw,
1375 XlwMenuWidget mw,
1376 widget_value *val, 1341 widget_value *val,
1377 Boolean in_menubar, 1342 Boolean in_menubar,
1378 Boolean highlighted, 1343 Boolean highlighted,
1379 Window window, 1344 Window window,
1380 int x, int y, 1345 int x, int y,
1381 unsigned width, 1346 unsigned width,
1382 unsigned height, 1347 unsigned height,
1383 unsigned label_offset, 1348 unsigned label_offset,
1384 unsigned binding_tab 1349 unsigned binding_tab)
1385 )
1386 { 1350 {
1387 int y_offset = mw->menu.shadow_thickness + mw->menu.vertical_margin; 1351 int y_offset = mw->menu.shadow_thickness + mw->menu.vertical_margin;
1388 1352
1389 if (!label_offset) 1353 if (!label_offset)
1390 label_offset = mw->menu.shadow_thickness + mw->menu.horizontal_margin; 1354 label_offset = mw->menu.shadow_thickness + mw->menu.horizontal_margin;
1391 1355
1392 /* 1356 /*
1393 * Draw the label string. 1357 * Draw the label string.
1394 */ 1358 */
1395 string_draw ( 1359 string_draw (mw,
1396 mw,
1397 window, 1360 window,
1398 x + label_offset, y + y_offset, 1361 x + label_offset, y + y_offset,
1399 mw->menu.foreground_gc, 1362 mw->menu.foreground_gc,
1400 resource_widget_value (mw, val) 1363 resource_widget_value (mw, val));
1401 ); 1364 }
1402 } 1365
1403 1366 static void
1404 static void 1367 push_button_size (XlwMenuWidget mw,
1405 push_button_size (
1406 XlwMenuWidget mw,
1407 widget_value *val, 1368 widget_value *val,
1408 Boolean in_menubar, 1369 Boolean in_menubar,
1409 unsigned *toggle_width, 1370 unsigned *toggle_width,
1410 unsigned *label_width, 1371 unsigned *label_width,
1411 unsigned *bindings_width, 1372 unsigned *bindings_width,
1412 unsigned *height 1373 unsigned *height)
1413 )
1414 { 1374 {
1415 /* inherit */ 1375 /* inherit */
1416 label_button_size ( 1376 label_button_size (mw, val, in_menubar,
1417 mw, val, in_menubar,
1418 toggle_width, label_width, bindings_width, 1377 toggle_width, label_width, bindings_width,
1419 height 1378 height);
1420 );
1421 1379
1422 /* key bindings to display? */ 1380 /* key bindings to display? */
1423 if (!in_menubar && val->key) 1381 if (!in_menubar && val->key)
1424 { 1382 {
1425 int w; 1383 int w;
1434 *bindings_width += w + mw->menu.column_spacing; 1392 *bindings_width += w + mw->menu.column_spacing;
1435 } 1393 }
1436 } 1394 }
1437 1395
1438 static void 1396 static void
1439 push_button_draw ( 1397 push_button_draw (XlwMenuWidget mw,
1440 XlwMenuWidget mw,
1441 widget_value *val, 1398 widget_value *val,
1442 Boolean in_menubar, 1399 Boolean in_menubar,
1443 Boolean highlighted, 1400 Boolean highlighted,
1444 Window window, 1401 Window window,
1445 int x, int y, 1402 int x, int y,
1446 unsigned width, unsigned height, 1403 unsigned width, unsigned height,
1447 unsigned label_offset, 1404 unsigned label_offset,
1448 unsigned binding_offset 1405 unsigned binding_offset)
1449 )
1450 { 1406 {
1451 int y_offset = mw->menu.shadow_thickness + mw->menu.vertical_margin; 1407 int y_offset = mw->menu.shadow_thickness + mw->menu.vertical_margin;
1452 GC gc; 1408 GC gc;
1453 shadow_type type; 1409 shadow_type type;
1454 Boolean menu_pb = in_menubar && (menu_item_type (val) == BUTTON_TYPE); 1410 Boolean menu_pb = in_menubar && (menu_item_type (val) == BUTTON_TYPE);
1472 gc = mw->menu.foreground_gc; 1428 gc = mw->menu.foreground_gc;
1473 else 1429 else
1474 gc = mw->menu.inactive_gc; 1430 gc = mw->menu.inactive_gc;
1475 } 1431 }
1476 1432
1477 string_draw ( 1433 string_draw (mw,
1478 mw,
1479 window, 1434 window,
1480 x + label_offset, y + y_offset, 1435 x + label_offset, y + y_offset,
1481 gc, 1436 gc,
1482 resource_widget_value(mw, val) 1437 resource_widget_value(mw, val));
1483 );
1484 1438
1485 /* 1439 /*
1486 * Draw the keybindings 1440 * Draw the keybindings
1487 */ 1441 */
1488 if (val->key) 1442 if (val->key)
1531 1485
1532 return result; 1486 return result;
1533 } 1487 }
1534 1488
1535 static void 1489 static void
1536 cascade_button_size ( 1490 cascade_button_size (XlwMenuWidget mw,
1537 XlwMenuWidget mw,
1538 widget_value *val, 1491 widget_value *val,
1539 Boolean in_menubar, 1492 Boolean in_menubar,
1540 unsigned *toggle_width, 1493 unsigned *toggle_width,
1541 unsigned *label_width, 1494 unsigned *label_width,
1542 unsigned *arrow_width, 1495 unsigned *arrow_width,
1543 unsigned *height 1496 unsigned *height)
1544 )
1545 { 1497 {
1546 /* inherit */ 1498 /* inherit */
1547 label_button_size ( 1499 label_button_size (mw, val, in_menubar,
1548 mw, val, in_menubar,
1549 toggle_width, label_width, arrow_width, 1500 toggle_width, label_width, arrow_width,
1550 height 1501 height);
1551 );
1552 /* we have a pull aside arrow */ 1502 /* we have a pull aside arrow */
1553 if (!in_menubar) 1503 if (!in_menubar)
1554 { 1504 {
1555 *arrow_width += arrow_decoration_height(mw) + mw->menu.column_spacing; 1505 *arrow_width += arrow_decoration_height(mw) + mw->menu.column_spacing;
1556 } 1506 }
1557 } 1507 }
1558 1508
1559 static void 1509 static void
1560 cascade_button_draw ( 1510 cascade_button_draw (XlwMenuWidget mw,
1561 XlwMenuWidget mw,
1562 widget_value *val, 1511 widget_value *val,
1563 Boolean in_menubar, 1512 Boolean in_menubar,
1564 Boolean highlighted, 1513 Boolean highlighted,
1565 Window window, 1514 Window window,
1566 int x, int y, 1515 int x, int y,
1567 unsigned width, unsigned height, 1516 unsigned width, unsigned height,
1568 unsigned label_offset, 1517 unsigned label_offset,
1569 unsigned binding_offset 1518 unsigned binding_offset)
1570 )
1571 { 1519 {
1572 shadow_type type; 1520 shadow_type type;
1573 1521
1574 /* 1522 /*
1575 * Draw the label string. 1523 * Draw the label string.
1598 mw->menu.horizontal_margin; 1546 mw->menu.horizontal_margin;
1599 1547
1600 binding_offset = label_offset + s_width + mw->menu.shadow_thickness; 1548 binding_offset = label_offset + s_width + mw->menu.shadow_thickness;
1601 } 1549 }
1602 1550
1603 arrow_decoration_draw ( 1551 arrow_decoration_draw (mw,
1604 mw,
1605 window, 1552 window,
1606 x + binding_offset + mw->menu.column_spacing, 1553 x + binding_offset + mw->menu.column_spacing,
1607 y + y_offset, 1554 y + y_offset,
1608 arrow_height, 1555 arrow_height,
1609 highlighted 1556 highlighted);
1610 );
1611 } 1557 }
1612 1558
1613 /* 1559 /*
1614 * Draw the shadow 1560 * Draw the shadow
1615 */ 1561 */
1635 1581
1636 return rv; 1582 return rv;
1637 } 1583 }
1638 1584
1639 static void 1585 static void
1640 toggle_button_size ( 1586 toggle_button_size (XlwMenuWidget mw,
1641 XlwMenuWidget mw,
1642 widget_value *val, 1587 widget_value *val,
1643 Boolean in_menubar, 1588 Boolean in_menubar,
1644 unsigned *toggle_width, 1589 unsigned *toggle_width,
1645 unsigned *label_width, 1590 unsigned *label_width,
1646 unsigned *bindings_width, 1591 unsigned *bindings_width,
1647 unsigned *height 1592 unsigned *height)
1648 )
1649 { 1593 {
1650 /* inherit */ 1594 /* inherit */
1651 push_button_size ( 1595 push_button_size (mw, val, in_menubar,
1652 mw, val, in_menubar,
1653 toggle_width, label_width, bindings_width, 1596 toggle_width, label_width, bindings_width,
1654 height 1597 height);
1655 );
1656 /* we have a toggle */ 1598 /* we have a toggle */
1657 *toggle_width += toggle_decoration_height(mw) + mw->menu.column_spacing; 1599 *toggle_width += toggle_decoration_height(mw) + mw->menu.column_spacing;
1658 } 1600 }
1659 1601
1660 static void 1602 static void
1661 toggle_button_draw ( 1603 toggle_button_draw (XlwMenuWidget mw,
1662 XlwMenuWidget mw,
1663 widget_value *val, 1604 widget_value *val,
1664 Boolean in_menubar, 1605 Boolean in_menubar,
1665 Boolean highlighted, 1606 Boolean highlighted,
1666 Window window, 1607 Window window,
1667 int x, int y, 1608 int x, int y,
1668 unsigned width, unsigned height, 1609 unsigned width, unsigned height,
1669 unsigned label_tab, 1610 unsigned label_tab,
1670 unsigned binding_tab 1611 unsigned binding_tab)
1671 )
1672 { 1612 {
1673 int x_offset; 1613 int x_offset;
1674 int y_offset; 1614 int y_offset;
1675 unsigned t_height = toggle_decoration_height(mw); 1615 unsigned t_height = toggle_decoration_height(mw);
1676 1616
1696 { 1636 {
1697 return toggle_decoration_height(mw); 1637 return toggle_decoration_height(mw);
1698 } 1638 }
1699 1639
1700 static void 1640 static void
1701 radio_button_draw ( 1641 radio_button_draw (XlwMenuWidget mw,
1702 XlwMenuWidget mw,
1703 widget_value *val, 1642 widget_value *val,
1704 Boolean in_menubar, 1643 Boolean in_menubar,
1705 Boolean highlighted, 1644 Boolean highlighted,
1706 Window window, 1645 Window window,
1707 int x, int y, 1646 int x, int y,
1708 unsigned width, unsigned height, 1647 unsigned width, unsigned height,
1709 unsigned label_tab, 1648 unsigned label_tab,
1710 unsigned binding_tab 1649 unsigned binding_tab)
1711 )
1712 { 1650 {
1713 int x_offset; 1651 int x_offset;
1714 int y_offset; 1652 int y_offset;
1715 unsigned r_height = radio_decoration_height(mw); 1653 unsigned r_height = radio_decoration_height(mw);
1716 1654
1800 widget_value *val, 1738 widget_value *val,
1801 Boolean in_menubar, 1739 Boolean in_menubar,
1802 unsigned *toggle_width, 1740 unsigned *toggle_width,
1803 unsigned *label_width, 1741 unsigned *label_width,
1804 unsigned *rest_width, 1742 unsigned *rest_width,
1805 unsigned *height 1743 unsigned *height)
1806 )
1807 { 1744 {
1808 *height = separator_decoration_height (mw, val); 1745 *height = separator_decoration_height (mw, val);
1809 *label_width = 1; 1746 *label_width = 1;
1810 *toggle_width = *rest_width = 0; 1747 *toggle_width = *rest_width = 0;
1811 } 1748 }
1817 Boolean highlighted, 1754 Boolean highlighted,
1818 Window window, 1755 Window window,
1819 int x, int y, 1756 int x, int y,
1820 unsigned width, unsigned height, 1757 unsigned width, unsigned height,
1821 unsigned label_tab, 1758 unsigned label_tab,
1822 unsigned binding_tab 1759 unsigned binding_tab)
1823 )
1824 { 1760 {
1825 unsigned sep_width; 1761 unsigned sep_width;
1826 1762
1827 if (in_menubar) 1763 if (in_menubar)
1828 sep_width = height; 1764 sep_width = height;
1833 window, 1769 window,
1834 x, 1770 x,
1835 y, 1771 y,
1836 sep_width, 1772 sep_width,
1837 in_menubar, 1773 in_menubar,
1838 separator_type(val->value) 1774 separator_type(val->value));
1839 );
1840 } 1775 }
1841 1776
1842 static void 1777 static void
1843 pushright_size (XlwMenuWidget mw, 1778 pushright_size (XlwMenuWidget mw,
1844 widget_value *val, 1779 widget_value *val,
1860 unsigned *label_width, 1795 unsigned *label_width,
1861 unsigned *rest_width, 1796 unsigned *rest_width,
1862 unsigned *height 1797 unsigned *height
1863 ) 1798 )
1864 { 1799 {
1865 1800 void (*function_ptr) (XlwMenuWidget _mw,
1866 void (*function_ptr) (
1867 XlwMenuWidget _mw,
1868 widget_value *_val, 1801 widget_value *_val,
1869 Boolean _in_menubar, 1802 Boolean _in_menubar,
1870 unsigned *_toggle_width, 1803 unsigned *_toggle_width,
1871 unsigned *_label_width, 1804 unsigned *_label_width,
1872 unsigned *_rest_width, 1805 unsigned *_rest_width,
1873 unsigned *_height 1806 unsigned *_height);
1874 ); 1807
1875 switch (menu_item_type (val)) 1808 switch (menu_item_type (val))
1876 { 1809 {
1877 case TOGGLE_TYPE: 1810 case TOGGLE_TYPE:
1878 case RADIO_TYPE: 1811 case RADIO_TYPE:
1879 function_ptr = toggle_button_size; 1812 function_ptr = toggle_button_size;
1895 default: 1828 default:
1896 function_ptr = label_button_size; 1829 function_ptr = label_button_size;
1897 break; 1830 break;
1898 } 1831 }
1899 1832
1900 (*function_ptr) ( 1833 (*function_ptr) (mw,
1901 mw,
1902 val, 1834 val,
1903 horizontal, 1835 horizontal,
1904 toggle_width, 1836 toggle_width,
1905 label_width, 1837 label_width,
1906 rest_width, 1838 rest_width,
1907 height 1839 height);
1908 ); 1840 }
1909 } 1841
1910 1842 static void
1911 static void 1843 display_menu_item (XlwMenuWidget mw,
1912 display_menu_item (
1913 XlwMenuWidget mw,
1914 widget_value *val, 1844 widget_value *val,
1915 window_state *ws, 1845 window_state *ws,
1916 XPoint *where, 1846 XPoint *where,
1917 Boolean highlighted, 1847 Boolean highlighted,
1918 Boolean horizontal, 1848 Boolean horizontal,
1919 Boolean just_compute 1849 Boolean just_compute)
1920 )
1921 { 1850 {
1922 1851
1923 int x = where->x /* + mw->menu.shadow_thickness */ ; 1852 int x = where->x /* + mw->menu.shadow_thickness */ ;
1924 int y = where->y /* + mw->menu.shadow_thickness */ ; 1853 int y = where->y /* + mw->menu.shadow_thickness */ ;
1925 unsigned toggle_width; 1854 unsigned toggle_width;
1927 unsigned binding_width; 1856 unsigned binding_width;
1928 unsigned width; 1857 unsigned width;
1929 unsigned height; 1858 unsigned height;
1930 unsigned label_tab; 1859 unsigned label_tab;
1931 unsigned binding_tab; 1860 unsigned binding_tab;
1932 void (*function_ptr) ( 1861 void (*function_ptr) (XlwMenuWidget _mw,
1933 XlwMenuWidget _mw,
1934 widget_value *_val, 1862 widget_value *_val,
1935 Boolean _in_menubar, 1863 Boolean _in_menubar,
1936 Boolean _highlighted, 1864 Boolean _highlighted,
1937 Window _window, 1865 Window _window,
1938 int _x, int _y, 1866 int _x, int _y,
1939 unsigned _width, unsigned _height, 1867 unsigned _width, unsigned _height,
1940 unsigned _label_tab, 1868 unsigned _label_tab,
1941 unsigned _binding_tab 1869 unsigned _binding_tab);
1942 ); 1870
1943 1871 size_menu_item (mw, val, horizontal,
1944 size_menu_item ( 1872 &toggle_width, &label_width, &binding_width, &height);
1945 mw, val, horizontal,
1946 &toggle_width, &label_width, &binding_width, &height
1947 );
1948 1873
1949 if (horizontal) 1874 if (horizontal)
1950 { 1875 {
1951 width = toggle_width + label_width + binding_width; 1876 width = toggle_width + label_width + binding_width;
1952 height = ws->height - 2 * mw->menu.shadow_thickness; 1877 height = ws->height - 2 * mw->menu.shadow_thickness;
1990 break; 1915 break;
1991 default: /* do no drawing */ 1916 default: /* do no drawing */
1992 return; 1917 return;
1993 } 1918 }
1994 1919
1995 (*function_ptr) ( 1920 (*function_ptr) (mw,
1996 mw,
1997 val, 1921 val,
1998 horizontal, 1922 horizontal,
1999 highlighted, 1923 highlighted,
2000 ws->window, 1924 ws->window,
2001 x, y, 1925 x, y,
2002 width, height, 1926 width, height,
2003 label_tab, 1927 label_tab,
2004 binding_tab 1928 binding_tab);
2005 );
2006 } 1929 }
2007 1930
2008 static void 1931 static void
2009 size_menu (XlwMenuWidget mw, int level) 1932 size_menu (XlwMenuWidget mw, int level)
2010 { 1933 {
2011 unsigned toggle_width; 1934 unsigned toggle_width;
2012 unsigned label_width; 1935 unsigned label_width;
2013 unsigned rest_width; 1936 unsigned rest_width;
2014 unsigned height; 1937 unsigned height;
2015 unsigned max_toggle_width = 0; 1938 unsigned max_toggle_width = 0;
2016 unsigned max_label_width = 0; 1939 unsigned max_label_width = 0;
2017 unsigned max_rest_width = 0; 1940 unsigned max_rest_width = 0;
2018 unsigned max_height = 0; 1941 unsigned max_height = 0;
2019 int horizontal_p = mw->menu.horizontal && (level == 0); 1942 int horizontal_p = mw->menu.horizontal && (level == 0);
2020 widget_value* val; 1943 widget_value* val;
2021 window_state* ws; 1944 window_state* ws;
2022 1945
2025 1948
2026 ws = &mw->menu.windows [level]; 1949 ws = &mw->menu.windows [level];
2027 1950
2028 for (val = mw->menu.old_stack [level]->contents; val; val = val->next) 1951 for (val = mw->menu.old_stack [level]->contents; val; val = val->next)
2029 { 1952 {
2030 size_menu_item ( 1953 size_menu_item (mw,
2031 mw,
2032 val, 1954 val,
2033 horizontal_p, 1955 horizontal_p,
2034 &toggle_width, 1956 &toggle_width,
2035 &label_width, 1957 &label_width,
2036 &rest_width, 1958 &rest_width,
2037 &height 1959 &height);
2038 );
2039 if (horizontal_p) 1960 if (horizontal_p)
2040 { 1961 {
2041 max_label_width += toggle_width + label_width + rest_width; 1962 max_label_width += toggle_width + label_width + rest_width;
2042 if (height > max_height) 1963 if (height > max_height)
2043 max_height = height; 1964 max_height = height;
2044 } 1965 }
2045 else 1966 else
2046 { 1967 {
2047 if (toggle_width > max_toggle_width) 1968 if (max_toggle_width < toggle_width)
2048 max_toggle_width = toggle_width; 1969 max_toggle_width = toggle_width;
2049 if (label_width > max_label_width) 1970 if (max_label_width < label_width)
2050 max_label_width = label_width; 1971 max_label_width = label_width;
2051 if (rest_width > max_rest_width) 1972 if (max_rest_width < rest_width)
2052 max_rest_width = rest_width; 1973 max_rest_width = rest_width;
2053 max_height += height; 1974 max_height += height;
2054 } 1975 }
2055 } 1976 }
2056 1977
2057 ws->height = max_height; 1978 ws->height = max_height;
2058 ws->width = max_label_width + max_rest_width + max_toggle_width; 1979 ws->width = max_label_width + max_rest_width + max_toggle_width;
2059 ws->toggle_width = max_toggle_width; 1980 ws->toggle_width = max_toggle_width;
2060 ws->label_width = max_label_width; 1981 ws->label_width = max_label_width;
2061 1982
2062 ws->width += 2 * mw->menu.shadow_thickness; 1983 ws->width += 2 * mw->menu.shadow_thickness;
2063 ws->height += 2 * mw->menu.shadow_thickness; 1984 ws->height += 2 * mw->menu.shadow_thickness;
2064 } 1985 }
2065 1986
2066 static void 1987 static void
2067 display_menu (XlwMenuWidget mw, int level, Boolean just_compute_p, 1988 display_menu (XlwMenuWidget mw, int level, Boolean just_compute_p,
2233 start_at = 0; 2154 start_at = 0;
2234 } 2155 }
2235 else 2156 else
2236 { 2157 {
2237 mw->menu.windows = 2158 mw->menu.windows =
2238 (window_state *) XtRealloc ((char*)mw->menu.windows, 2159 (window_state *) XtRealloc ((char *) mw->menu.windows,
2239 n * sizeof (window_state)); 2160 n * sizeof (window_state));
2240 start_at = mw->menu.windows_length; 2161 start_at = mw->menu.windows_length;
2241 } 2162 }
2242 mw->menu.windows_length = n; 2163 mw->menu.windows_length = n;
2243 2164
2398 window_state *ws = &mw->menu.windows [level]; 2319 window_state *ws = &mw->menu.windows [level];
2399 int x = level == 0 ? ws->x : ws->x + mw->menu.shadow_thickness; 2320 int x = level == 0 ? ws->x : ws->x + mw->menu.shadow_thickness;
2400 int y = level == 0 ? ws->y : ws->y + mw->menu.shadow_thickness; 2321 int y = level == 0 ? ws->y : ws->y + mw->menu.shadow_thickness;
2401 relative_pos->x = ev->x_root - x; 2322 relative_pos->x = ev->x_root - x;
2402 relative_pos->y = ev->y_root - y; 2323 relative_pos->y = ev->y_root - y;
2403 return (x < ev->x_root && ev->x_root < (int) (x + ws->width) 2324 return (x < ev->x_root && ev->x_root < (int) (x + ws->width) &&
2404 && y < ev->y_root && ev->y_root < (int) (y + ws->height)); 2325 y < ev->y_root && ev->y_root < (int) (y + ws->height));
2405 } 2326 }
2406 2327
2407 static Boolean 2328 static Boolean
2408 map_event_to_widget_value (XlwMenuWidget mw, XMotionEvent *ev, 2329 map_event_to_widget_value (XlwMenuWidget mw, XMotionEvent *ev,
2409 widget_value **val_ptr, int *level, 2330 widget_value **val_ptr, int *level,
2507 mw->menu.button_gc = XtGetGC ((Widget)mw, flags, &xgcv); 2428 mw->menu.button_gc = XtGetGC ((Widget)mw, flags, &xgcv);
2508 2429
2509 xgcv.fill_style = FillStippled; 2430 xgcv.fill_style = FillStippled;
2510 xgcv.stipple = mw->menu.gray_pixmap; 2431 xgcv.stipple = mw->menu.gray_pixmap;
2511 mw->menu.inactive_button_gc = XtGetGC ((Widget)mw, 2432 mw->menu.inactive_button_gc = XtGetGC ((Widget)mw,
2512 (flags | GCFillStyle | GCStipple), 2433 (flags | GCFillStyle | GCStipple),
2513 &xgcv); 2434 &xgcv);
2514 } 2435 }
2515 2436
2516 static void 2437 static void
2517 release_drawing_gcs (XlwMenuWidget mw) 2438 release_drawing_gcs (XlwMenuWidget mw)
2521 XtReleaseGC ((Widget) mw, mw->menu.inactive_gc); 2442 XtReleaseGC ((Widget) mw, mw->menu.inactive_gc);
2522 XtReleaseGC ((Widget) mw, mw->menu.inactive_button_gc); 2443 XtReleaseGC ((Widget) mw, mw->menu.inactive_button_gc);
2523 XtReleaseGC ((Widget) mw, mw->menu.background_gc); 2444 XtReleaseGC ((Widget) mw, mw->menu.background_gc);
2524 XtReleaseGC ((Widget) mw, mw->menu.select_gc); 2445 XtReleaseGC ((Widget) mw, mw->menu.select_gc);
2525 /* let's get some segvs if we try to use these... */ 2446 /* let's get some segvs if we try to use these... */
2526 mw->menu.foreground_gc = (GC) -1; 2447 mw->menu.foreground_gc = (GC) -1;
2527 mw->menu.button_gc = (GC) -1; 2448 mw->menu.button_gc = (GC) -1;
2528 mw->menu.inactive_gc = (GC) -1; 2449 mw->menu.inactive_gc = (GC) -1;
2529 mw->menu.inactive_button_gc = (GC) -1; 2450 mw->menu.inactive_button_gc = (GC) -1;
2530 mw->menu.background_gc = (GC) -1; 2451 mw->menu.background_gc = (GC) -1;
2531 mw->menu.select_gc = (GC) -1; 2452 mw->menu.select_gc = (GC) -1;
2532 } 2453 }
2533 2454
2534 #define MINL(x,y) ((((unsigned long) (x)) < ((unsigned long) (y))) \ 2455 #define MINL(x,y) ((((unsigned long) (x)) < ((unsigned long) (y))) \
2535 ? ((unsigned long) (x)) : ((unsigned long) (y))) 2456 ? ((unsigned long) (x)) : ((unsigned long) (y)))
2536 2457
2543 Colormap cmap = DefaultColormapOfScreen (XtScreen ((Widget) mw)); 2464 Colormap cmap = DefaultColormapOfScreen (XtScreen ((Widget) mw));
2544 XColor topc, botc; 2465 XColor topc, botc;
2545 int top_frobbed = 0, bottom_frobbed = 0; 2466 int top_frobbed = 0, bottom_frobbed = 0;
2546 2467
2547 if (mw->menu.top_shadow_color == -1) 2468 if (mw->menu.top_shadow_color == -1)
2548 mw->menu.top_shadow_color = mw->core.background_pixel; 2469 mw->menu.top_shadow_color = mw->core.background_pixel;
2549 if (mw->menu.bottom_shadow_color == -1) 2470 if (mw->menu.bottom_shadow_color == -1)
2550 mw->menu.bottom_shadow_color = mw->menu.foreground; 2471 mw->menu.bottom_shadow_color = mw->menu.foreground;
2551 2472
2552 if (mw->menu.top_shadow_color == mw->core.background_pixel || 2473 if (mw->menu.top_shadow_color == mw->core.background_pixel ||
2553 mw->menu.top_shadow_color == mw->menu.foreground) 2474 mw->menu.top_shadow_color == mw->menu.foreground)
2554 { 2475 {
2555 topc.pixel = mw->core.background_pixel; 2476 topc.pixel = mw->core.background_pixel;
2808 Display *display = XtDisplay (mw); 2729 Display *display = XtDisplay (mw);
2809 2730
2810 /* mw->menu.cursor = XCreateFontCursor (display, mw->menu.cursor_shape); */ 2731 /* mw->menu.cursor = XCreateFontCursor (display, mw->menu.cursor_shape); */
2811 mw->menu.cursor = mw->menu.cursor_shape; 2732 mw->menu.cursor = mw->menu.cursor_shape;
2812 2733
2813 mw->menu.gray_pixmap = XCreatePixmapFromBitmapData (display, window, 2734 mw->menu.gray_pixmap =
2814 (char *) gray_bits, 2735 XCreatePixmapFromBitmapData (display, window, (char *) gray_bits,
2815 gray_width, 2736 gray_width, gray_height, 1, 0, 1);
2816 gray_height, 1, 0, 1);
2817 2737
2818 #ifdef NEED_MOTIF 2738 #ifdef NEED_MOTIF
2819 /* The menu.font_list slot came from the *fontList resource (Motif standard.) 2739 /* The menu.font_list slot came from the *fontList resource (Motif standard.)
2820 The menu.font_list_2 slot came from the *font resource, for backward 2740 The menu.font_list_2 slot came from the *font resource, for backward
2821 compatibility with older versions of this code, and consistency with the 2741 compatibility with older versions of this code, and consistency with the
2930 XtUngrabPointer (w, CurrentTime); 2850 XtUngrabPointer (w, CurrentTime);
2931 mw->menu.pointer_grabbed = False; 2851 mw->menu.pointer_grabbed = False;
2932 } 2852 }
2933 2853
2934 release_drawing_gcs (mw); 2854 release_drawing_gcs (mw);
2935 release_shadow_gcs (mw); 2855 release_shadow_gcs (mw);
2936 2856
2937 /* this doesn't come from the resource db but is created explicitly 2857 /* this doesn't come from the resource db but is created explicitly
2938 so we must free it ourselves. */ 2858 so we must free it ourselves. */
2939 XFreePixmap (XtDisplay (mw), mw->menu.gray_pixmap); 2859 XFreePixmap (XtDisplay (mw), mw->menu.gray_pixmap);
2940 mw->menu.gray_pixmap = (Pixmap) -1; 2860 mw->menu.gray_pixmap = (Pixmap) -1;
2980 2900
2981 if (newmw->core.background_pixel != oldmw->core.background_pixel 2901 if (newmw->core.background_pixel != oldmw->core.background_pixel
2982 || newmw->menu.foreground != oldmw->menu.foreground 2902 || newmw->menu.foreground != oldmw->menu.foreground
2983 /* For the XEditResource protocol, which may want to change the font. */ 2903 /* For the XEditResource protocol, which may want to change the font. */
2984 #ifdef NEED_MOTIF 2904 #ifdef NEED_MOTIF
2985 || newmw->menu.font_list != oldmw->menu.font_list 2905 || newmw->menu.font_list != oldmw->menu.font_list
2986 || newmw->menu.font_list_2 != oldmw->menu.font_list_2 2906 || newmw->menu.font_list_2 != oldmw->menu.font_list_2
2987 || newmw->menu.fallback_font_list != oldmw->menu.fallback_font_list 2907 || newmw->menu.fallback_font_list != oldmw->menu.fallback_font_list
2988 #else 2908 #else
2989 || newmw->menu.font != oldmw->menu.font 2909 || newmw->menu.font != oldmw->menu.font
2990 #endif 2910 #endif
2991 ) 2911 )
3011 static void 2931 static void
3012 XlwMenuResize (Widget w) 2932 XlwMenuResize (Widget w)
3013 { 2933 {
3014 XlwMenuWidget mw = (XlwMenuWidget)w; 2934 XlwMenuWidget mw = (XlwMenuWidget)w;
3015 2935
3016 mw->menu.windows [0].width = mw->core.width; 2936 mw->menu.windows [0].width = mw->core.width;
3017 mw->menu.windows [0].height = mw->core.height; 2937 mw->menu.windows [0].height = mw->core.height;
3018 } 2938 }
3019 2939
3020 /* Action procedures */ 2940 /* Action procedures */
3021 static void 2941 static void
3173 mw->menu.popped_up = False; 3093 mw->menu.popped_up = False;
3174 XtPopdown (XtParent (mw)); 3094 XtPopdown (XtParent (mw));
3175 } 3095 }
3176 3096
3177 /* callback */ 3097 /* callback */
3178 XtCallCallbackList ((Widget)mw, mw->menu.select, (XtPointer)selected_item); 3098 XtCallCallbackList ((Widget) mw, mw->menu.select, (XtPointer) selected_item);
3179 } 3099 }
3180 3100
3181 3101
3182 /* Special code to pop-up a menu */ 3102 /* Special code to pop-up a menu */
3183 void 3103 void
3193 mw->menu.menu_post_time = event->time; 3113 mw->menu.menu_post_time = event->time;
3194 mw->menu.menu_bounce_time = 0; 3114 mw->menu.menu_bounce_time = 0;
3195 mw->menu.next_release_must_exit = True; 3115 mw->menu.next_release_must_exit = True;
3196 mw->menu.last_selected_val = NULL; 3116 mw->menu.last_selected_val = NULL;
3197 3117
3198 XtCallCallbackList ((Widget)mw, mw->menu.open, NULL); 3118 XtCallCallbackList ((Widget) mw, mw->menu.open, NULL);
3199 3119
3200 size_menu (mw, 0); 3120 size_menu (mw, 0);
3201 3121
3202 w = mw->menu.windows [0].width; 3122 w = mw->menu.windows [0].width;
3203 h = mw->menu.windows [0].height; 3123 h = mw->menu.windows [0].height;
3204 3124
3205 x -= borderwidth; 3125 x -= borderwidth;
3206 y -= borderwidth; 3126 y -= borderwidth;
3127
3207 if (x < borderwidth) 3128 if (x < borderwidth)
3208 x = borderwidth; 3129 x = borderwidth;
3209 if (x + w + 2 * borderwidth > WidthOfScreen (screen)) 3130
3210 x = WidthOfScreen (screen) - w - 2 * borderwidth; 3131 if (x > WidthOfScreen (screen) - w - 2 * borderwidth)
3132 x = WidthOfScreen (screen) - w - 2 * borderwidth;
3133
3211 if (y < borderwidth) 3134 if (y < borderwidth)
3212 y = borderwidth; 3135 y = borderwidth;
3213 if (y + h + 2 * borderwidth> HeightOfScreen (screen)) 3136
3214 y = HeightOfScreen (screen) - h - 2 * borderwidth; 3137 if (y > HeightOfScreen (screen) - h - 2 * borderwidth)
3138 y = HeightOfScreen (screen) - h - 2 * borderwidth;
3215 3139
3216 mw->menu.popped_up = True; 3140 mw->menu.popped_up = True;
3217 XtConfigureWidget (XtParent (mw), x, y, w, h, 3141 XtConfigureWidget (XtParent (mw), x, y, w, h,
3218 XtParent (mw)->core.border_width); 3142 XtParent (mw)->core.border_width);
3219 XtPopup (XtParent (mw), XtGrabExclusive); 3143 XtPopup (XtParent (mw), XtGrabExclusive);
3243 */ 3167 */
3244 void 3168 void
3245 xlw_unmunge_class_resize (Widget w) 3169 xlw_unmunge_class_resize (Widget w)
3246 { 3170 {
3247 if (w->core.widget_class->core_class.resize != XlwMenuResize) 3171 if (w->core.widget_class->core_class.resize != XlwMenuResize)
3248 w->core.widget_class->core_class.resize = XlwMenuResize; 3172 w->core.widget_class->core_class.resize = XlwMenuResize;
3249 } 3173 }
3250 #endif /* 0 */ 3174 #endif /* 0 */
3251 3175