Mercurial > emacs
annotate lwlib/xlwmenu.c @ 9010:9d48b6752dbf
(rmail-retry-failure): Copy the whole block of headers from the message
and then discard those in rmail-retry-ignored-headers. Delete
usage of rmail-retry-setup-hook. Bind mail-signature and
mail-setup-hook to nil when composing retry buffer.
Handle mail-self-blind.
(rmail-retry-ignored-headers): New variable,
specifying the headers that should be removed by rmail-retry-failure.
(rmail-retry-setup-hook): Obsolete variable (see below), deleted.
(rmail-clear-headers): New optional arg is list of headers to clear.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Fri, 23 Sep 1994 04:37:16 +0000 |
parents | a5e3635a9544 |
children | 07d79cbdfbc9 |
rev | line source |
---|---|
5626 | 1 /* Implements a lightweight menubar widget. |
2 Copyright (C) 1992 Lucid, Inc. | |
3 | |
4 This file is part of the Lucid Widget Library. | |
5 | |
6 The Lucid Widget Library is free software; you can redistribute it and/or | |
7 modify it under the terms of the GNU General Public License as published by | |
8 the Free Software Foundation; either version 2, or (at your option) | |
9 any later version. | |
10 | |
11 The Lucid Widget Library is distributed in the hope that it will be useful, | |
12 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 GNU General Public License for more details. | |
15 | |
16 You should have received a copy of the GNU General Public License | |
17 along with GNU Emacs; see the file COPYING. If not, write to | |
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
19 | |
20 /* Created by devin@lucid.com */ | |
21 | |
22 #include <stdio.h> | |
23 | |
24 #include <sys/types.h> | |
25 #include <X11/Xos.h> | |
26 #include <X11/IntrinsicP.h> | |
27 #include <X11/StringDefs.h> | |
28 #include <X11/cursorfont.h> | |
29 #include <X11/bitmaps/gray> | |
30 #include "xlwmenuP.h" | |
8860 | 31 |
32 static int pointer_grabbed; | |
33 static XEvent menu_post_event; | |
5626 | 34 |
35 static char | |
36 xlwMenuTranslations [] = | |
37 "<BtnDown>: start()\n\ | |
8860 | 38 <Motion>: drag()\n\ |
5626 | 39 <BtnUp>: select()\n\ |
40 "; | |
41 | |
42 #define offset(field) XtOffset(XlwMenuWidget, field) | |
43 static XtResource | |
44 xlwMenuResources[] = | |
45 { | |
46 {XtNfont, XtCFont, XtRFontStruct, sizeof(XFontStruct *), | |
47 offset(menu.font),XtRString, "XtDefaultFont"}, | |
48 {XtNforeground, XtCForeground, XtRPixel, sizeof(Pixel), | |
49 offset(menu.foreground), XtRString, "XtDefaultForeground"}, | |
50 {XtNbuttonForeground, XtCButtonForeground, XtRPixel, sizeof(Pixel), | |
51 offset(menu.button_foreground), XtRString, "XtDefaultForeground"}, | |
52 {XtNmargin, XtCMargin, XtRDimension, sizeof(Dimension), | |
53 offset(menu.margin), XtRImmediate, (XtPointer)0}, | |
54 {XtNhorizontalSpacing, XtCMargin, XtRDimension, sizeof(Dimension), | |
55 offset(menu.horizontal_spacing), XtRImmediate, (XtPointer)3}, | |
56 {XtNverticalSpacing, XtCMargin, XtRDimension, sizeof(Dimension), | |
57 offset(menu.vertical_spacing), XtRImmediate, (XtPointer)1}, | |
58 {XtNarrowSpacing, XtCMargin, XtRDimension, sizeof(Dimension), | |
59 offset(menu.arrow_spacing), XtRImmediate, (XtPointer)10}, | |
60 | |
8860 | 61 {XmNshadowThickness, XmCShadowThickness, XtRDimension, |
5626 | 62 sizeof (Dimension), offset (menu.shadow_thickness), |
63 XtRImmediate, (XtPointer) 2}, | |
64 {XmNtopShadowColor, XmCTopShadowColor, XtRPixel, sizeof (Pixel), | |
65 offset (menu.top_shadow_color), XtRImmediate, (XtPointer)-1}, | |
66 {XmNbottomShadowColor, XmCBottomShadowColor, XtRPixel, sizeof (Pixel), | |
67 offset (menu.bottom_shadow_color), XtRImmediate, (XtPointer)-1}, | |
68 {XmNtopShadowPixmap, XmCTopShadowPixmap, XtRPixmap, sizeof (Pixmap), | |
69 offset (menu.top_shadow_pixmap), XtRImmediate, (XtPointer)None}, | |
70 {XmNbottomShadowPixmap, XmCBottomShadowPixmap, XtRPixmap, sizeof (Pixmap), | |
71 offset (menu.bottom_shadow_pixmap), XtRImmediate, (XtPointer)None}, | |
72 | |
73 {XtNopen, XtCCallback, XtRCallback, sizeof(XtPointer), | |
74 offset(menu.open), XtRCallback, (XtPointer)NULL}, | |
75 {XtNselect, XtCCallback, XtRCallback, sizeof(XtPointer), | |
76 offset(menu.select), XtRCallback, (XtPointer)NULL}, | |
77 {XtNmenu, XtCMenu, XtRPointer, sizeof(XtPointer), | |
78 offset(menu.contents), XtRImmediate, (XtPointer)NULL}, | |
79 {XtNcursor, XtCCursor, XtRCursor, sizeof(Cursor), | |
80 offset(menu.cursor_shape), XtRString, (XtPointer)"right_ptr"}, | |
81 {XtNhorizontal, XtCHorizontal, XtRInt, sizeof(int), | |
82 offset(menu.horizontal), XtRImmediate, (XtPointer)True}, | |
83 }; | |
84 #undef offset | |
85 | |
86 static Boolean XlwMenuSetValues(); | |
87 static void XlwMenuRealize(); | |
88 static void XlwMenuRedisplay(); | |
89 static void XlwMenuResize(); | |
90 static void XlwMenuInitialize(); | |
91 static void XlwMenuRedisplay(); | |
92 static void XlwMenuDestroy(); | |
93 static void XlwMenuClassInitialize(); | |
94 static void Start(); | |
95 static void Drag(); | |
96 static void Select(); | |
97 | |
98 static XtActionsRec | |
99 xlwMenuActionsList [] = | |
100 { | |
101 {"start", Start}, | |
102 {"drag", Drag}, | |
103 {"select", Select}, | |
104 }; | |
105 | |
106 #define SuperClass ((CoreWidgetClass)&coreClassRec) | |
107 | |
108 XlwMenuClassRec xlwMenuClassRec = | |
109 { | |
110 { /* CoreClass fields initialization */ | |
111 (WidgetClass) SuperClass, /* superclass */ | |
112 "XlwMenu", /* class_name */ | |
113 sizeof(XlwMenuRec), /* size */ | |
114 XlwMenuClassInitialize, /* class_initialize */ | |
115 NULL, /* class_part_initialize */ | |
116 FALSE, /* class_inited */ | |
117 XlwMenuInitialize, /* initialize */ | |
118 NULL, /* initialize_hook */ | |
119 XlwMenuRealize, /* realize */ | |
120 xlwMenuActionsList, /* actions */ | |
121 XtNumber(xlwMenuActionsList), /* num_actions */ | |
122 xlwMenuResources, /* resources */ | |
123 XtNumber(xlwMenuResources), /* resource_count */ | |
124 NULLQUARK, /* xrm_class */ | |
125 TRUE, /* compress_motion */ | |
126 TRUE, /* compress_exposure */ | |
127 TRUE, /* compress_enterleave */ | |
128 FALSE, /* visible_interest */ | |
129 XlwMenuDestroy, /* destroy */ | |
130 XlwMenuResize, /* resize */ | |
131 XlwMenuRedisplay, /* expose */ | |
132 XlwMenuSetValues, /* set_values */ | |
133 NULL, /* set_values_hook */ | |
134 XtInheritSetValuesAlmost, /* set_values_almost */ | |
135 NULL, /* get_values_hook */ | |
136 NULL, /* accept_focus */ | |
137 XtVersion, /* version */ | |
138 NULL, /* callback_private */ | |
139 xlwMenuTranslations, /* tm_table */ | |
140 XtInheritQueryGeometry, /* query_geometry */ | |
141 XtInheritDisplayAccelerator, /* display_accelerator */ | |
142 NULL /* extension */ | |
143 }, /* XlwMenuClass fields initialization */ | |
144 { | |
145 0 /* dummy */ | |
146 }, | |
147 }; | |
148 | |
149 WidgetClass xlwMenuWidgetClass = (WidgetClass) &xlwMenuClassRec; | |
150 | |
8860 | 151 int submenu_destroyed; |
152 | |
153 static int next_release_must_exit; | |
154 | |
5626 | 155 /* Utilities */ |
156 static void | |
8860 | 157 push_new_stack (mw, val) |
158 XlwMenuWidget mw; | |
159 widget_value* val; | |
5626 | 160 { |
161 if (!mw->menu.new_stack) | |
162 { | |
163 mw->menu.new_stack_length = 10; | |
164 mw->menu.new_stack = | |
165 (widget_value**)XtCalloc (mw->menu.new_stack_length, | |
166 sizeof (widget_value*)); | |
167 } | |
168 else if (mw->menu.new_depth == mw->menu.new_stack_length) | |
169 { | |
170 mw->menu.new_stack_length *= 2; | |
171 mw->menu.new_stack = | |
172 (widget_value**)XtRealloc ((char*)mw->menu.new_stack, | |
173 mw->menu.new_stack_length * sizeof (widget_value*)); | |
174 } | |
175 mw->menu.new_stack [mw->menu.new_depth++] = val; | |
176 } | |
177 | |
178 static void | |
8860 | 179 pop_new_stack_if_no_contents (mw) |
180 XlwMenuWidget mw; | |
5626 | 181 { |
182 if (mw->menu.new_depth) | |
183 { | |
184 if (!mw->menu.new_stack [mw->menu.new_depth - 1]->contents) | |
185 mw->menu.new_depth -= 1; | |
186 } | |
187 } | |
188 | |
189 static void | |
8860 | 190 make_old_stack_space (mw, n) |
191 XlwMenuWidget mw; | |
192 int n; | |
5626 | 193 { |
194 if (!mw->menu.old_stack) | |
195 { | |
196 mw->menu.old_stack_length = 10; | |
197 mw->menu.old_stack = | |
198 (widget_value**)XtCalloc (mw->menu.old_stack_length, | |
199 sizeof (widget_value*)); | |
200 } | |
201 else if (mw->menu.old_stack_length < n) | |
202 { | |
203 mw->menu.old_stack_length *= 2; | |
204 mw->menu.old_stack = | |
205 (widget_value**)XtRealloc ((char*)mw->menu.old_stack, | |
206 mw->menu.old_stack_length * sizeof (widget_value*)); | |
207 } | |
208 } | |
209 | |
210 /* Size code */ | |
211 static Boolean | |
8860 | 212 all_dashes_p (s) |
213 char *s; | |
5626 | 214 { |
215 char* p; | |
216 for (p = s; *p == '-'; p++); | |
217 return !*p; | |
218 } | |
219 | |
8860 | 220 int |
221 string_width (mw, s) | |
222 XlwMenuWidget mw; | |
223 char *s; | |
5626 | 224 { |
225 XCharStruct xcs; | |
226 int drop; | |
227 | |
228 XTextExtents (mw->menu.font, s, strlen (s), &drop, &drop, &drop, &xcs); | |
229 return xcs.width; | |
230 } | |
231 | |
232 static int | |
8860 | 233 arrow_width (mw) |
234 XlwMenuWidget mw; | |
5626 | 235 { |
236 return mw->menu.font->ascent / 2 | 1; | |
237 } | |
238 | |
239 static XtResource | |
240 nameResource[] = | |
241 { | |
242 {"labelString", "LabelString", XtRString, sizeof(String), | |
243 0, XtRImmediate, 0}, | |
244 }; | |
245 | |
246 static char* | |
8860 | 247 resource_widget_value (mw, val) |
248 XlwMenuWidget mw; | |
249 widget_value *val; | |
5626 | 250 { |
251 if (!val->toolkit_data) | |
252 { | |
253 char* resourced_name = NULL; | |
254 char* complete_name; | |
255 XtGetSubresources ((Widget) mw, | |
256 (XtPointer) &resourced_name, | |
257 val->name, val->name, | |
258 nameResource, 1, NULL, 0); | |
259 if (!resourced_name) | |
260 resourced_name = val->name; | |
261 if (!val->value) | |
5654
f84dac6453db
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5626
diff
changeset
|
262 { |
f84dac6453db
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5626
diff
changeset
|
263 complete_name = (char *) XtMalloc (strlen (resourced_name) + 1); |
f84dac6453db
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5626
diff
changeset
|
264 strcpy (complete_name, resourced_name); |
f84dac6453db
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
5626
diff
changeset
|
265 } |
5626 | 266 else |
267 { | |
268 int complete_length = | |
269 strlen (resourced_name) + strlen (val->value) + 2; | |
270 complete_name = XtMalloc (complete_length); | |
271 *complete_name = 0; | |
272 strcat (complete_name, resourced_name); | |
273 strcat (complete_name, " "); | |
274 strcat (complete_name, val->value); | |
275 } | |
276 | |
277 val->toolkit_data = complete_name; | |
278 val->free_toolkit_data = True; | |
279 } | |
280 return (char*)val->toolkit_data; | |
281 } | |
282 | |
283 /* Returns the sizes of an item */ | |
284 static void | |
8860 | 285 size_menu_item (mw, val, horizontal_p, label_width, rest_width, height) |
286 XlwMenuWidget mw; | |
287 widget_value* val; | |
288 int horizontal_p; | |
289 int* label_width; | |
290 int* rest_width; | |
291 int* height; | |
5626 | 292 { |
293 if (all_dashes_p (val->name)) | |
294 { | |
295 *height = 2; | |
296 *label_width = 1; | |
297 *rest_width = 0; | |
298 } | |
299 else | |
300 { | |
301 *height = | |
302 mw->menu.font->ascent + mw->menu.font->descent | |
303 + 2 * mw->menu.vertical_spacing + 2 * mw->menu.shadow_thickness; | |
304 | |
305 *label_width = | |
306 string_width (mw, resource_widget_value (mw, val)) | |
307 + mw->menu.horizontal_spacing + mw->menu.shadow_thickness; | |
308 | |
309 *rest_width = mw->menu.horizontal_spacing + mw->menu.shadow_thickness; | |
310 if (!horizontal_p) | |
311 { | |
312 if (val->contents) | |
313 *rest_width += arrow_width (mw) + mw->menu.arrow_spacing; | |
314 else if (val->key) | |
315 *rest_width += | |
316 string_width (mw, val->key) + mw->menu.arrow_spacing; | |
317 } | |
318 } | |
319 } | |
320 | |
321 static void | |
8860 | 322 size_menu (mw, level) |
323 XlwMenuWidget mw; | |
324 int level; | |
5626 | 325 { |
326 int label_width = 0; | |
327 int rest_width = 0; | |
328 int max_rest_width = 0; | |
329 int height = 0; | |
330 int horizontal_p = mw->menu.horizontal && (level == 0); | |
331 widget_value* val; | |
332 window_state* ws; | |
333 | |
334 if (level >= mw->menu.old_depth) | |
335 abort (); | |
336 | |
337 ws = &mw->menu.windows [level]; | |
338 ws->width = 0; | |
339 ws->height = 0; | |
340 ws->label_width = 0; | |
341 | |
342 for (val = mw->menu.old_stack [level]->contents; val; val = val->next) | |
343 { | |
344 size_menu_item (mw, val, horizontal_p, &label_width, &rest_width, | |
345 &height); | |
346 if (horizontal_p) | |
347 { | |
348 ws->width += label_width + rest_width; | |
349 if (height > ws->height) | |
350 ws->height = height; | |
351 } | |
352 else | |
353 { | |
354 if (label_width > ws->label_width) | |
355 ws->label_width = label_width; | |
356 if (rest_width > max_rest_width) | |
357 max_rest_width = rest_width; | |
358 ws->height += height; | |
359 } | |
360 } | |
361 | |
362 if (horizontal_p) | |
363 ws->label_width = 0; | |
364 else | |
365 ws->width = ws->label_width + max_rest_width; | |
366 | |
367 ws->width += 2 * mw->menu.shadow_thickness; | |
368 ws->height += 2 * mw->menu.shadow_thickness; | |
369 } | |
370 | |
371 | |
372 /* Display code */ | |
373 static void | |
8860 | 374 draw_arrow (mw, window, gc, x, y, width) |
375 XlwMenuWidget mw; | |
376 Window window; | |
377 GC gc; | |
378 int x; | |
379 int y; | |
380 int width; | |
5626 | 381 { |
382 XPoint points [3]; | |
383 points [0].x = x; | |
384 points [0].y = y + mw->menu.font->ascent; | |
385 points [1].x = x; | |
386 points [1].y = y; | |
387 points [2].x = x + width; | |
388 points [2].y = y + mw->menu.font->ascent / 2; | |
389 | |
390 XFillPolygon (XtDisplay (mw), window, gc, points, 3, Convex, | |
391 CoordModeOrigin); | |
392 } | |
393 | |
394 static void | |
8860 | 395 draw_shadow_rectangle (mw, window, x, y, width, height, erase_p) |
396 XlwMenuWidget mw; | |
397 Window window; | |
398 int x; | |
399 int y; | |
400 int width; | |
401 int height; | |
402 int erase_p; | |
5626 | 403 { |
404 Display *dpy = XtDisplay (mw); | |
405 GC top_gc = !erase_p ? mw->menu.shadow_top_gc : mw->menu.background_gc; | |
406 GC bottom_gc = !erase_p ? mw->menu.shadow_bottom_gc : mw->menu.background_gc; | |
407 int thickness = mw->menu.shadow_thickness; | |
408 XPoint points [4]; | |
409 points [0].x = x; | |
410 points [0].y = y; | |
411 points [1].x = x + width; | |
412 points [1].y = y; | |
413 points [2].x = x + width - thickness; | |
414 points [2].y = y + thickness; | |
415 points [3].x = x; | |
416 points [3].y = y + thickness; | |
417 XFillPolygon (dpy, window, top_gc, points, 4, Convex, CoordModeOrigin); | |
418 points [0].x = x; | |
419 points [0].y = y + thickness; | |
420 points [1].x = x; | |
421 points [1].y = y + height; | |
422 points [2].x = x + thickness; | |
423 points [2].y = y + height - thickness; | |
424 points [3].x = x + thickness; | |
425 points [3].y = y + thickness; | |
426 XFillPolygon (dpy, window, top_gc, points, 4, Convex, CoordModeOrigin); | |
427 points [0].x = x + width; | |
428 points [0].y = y; | |
429 points [1].x = x + width - thickness; | |
430 points [1].y = y + thickness; | |
431 points [2].x = x + width - thickness; | |
432 points [2].y = y + height - thickness; | |
433 points [3].x = x + width; | |
434 points [3].y = y + height - thickness; | |
435 XFillPolygon (dpy, window, bottom_gc, points, 4, Convex, CoordModeOrigin); | |
436 points [0].x = x; | |
437 points [0].y = y + height; | |
438 points [1].x = x + width; | |
439 points [1].y = y + height; | |
440 points [2].x = x + width; | |
441 points [2].y = y + height - thickness; | |
442 points [3].x = x + thickness; | |
443 points [3].y = y + height - thickness; | |
444 XFillPolygon (dpy, window, bottom_gc, points, 4, Convex, CoordModeOrigin); | |
445 } | |
446 | |
447 | |
448 /* Display the menu item and increment where.x and where.y to show how large | |
449 ** the menu item was. | |
450 */ | |
451 static void | |
8860 | 452 display_menu_item (mw, val, ws, where, highlighted_p, horizontal_p, just_compute_p) |
453 XlwMenuWidget mw; | |
454 widget_value* val; | |
455 window_state* ws; | |
456 XPoint* where; | |
457 Boolean highlighted_p; | |
458 Boolean horizontal_p; | |
459 Boolean just_compute_p; | |
5626 | 460 { |
461 GC deco_gc; | |
462 GC text_gc; | |
463 int font_ascent = mw->menu.font->ascent; | |
464 int font_descent = mw->menu.font->descent; | |
465 int shadow = mw->menu.shadow_thickness; | |
466 int separator_p = all_dashes_p (val->name); | |
467 int h_spacing = mw->menu.horizontal_spacing; | |
468 int v_spacing = mw->menu.vertical_spacing; | |
469 int label_width; | |
470 int rest_width; | |
471 int height; | |
472 int width; | |
473 int button_p; | |
474 | |
475 /* compute the sizes of the item */ | |
476 size_menu_item (mw, val, horizontal_p, &label_width, &rest_width, &height); | |
477 | |
478 if (horizontal_p) | |
479 width = label_width + rest_width; | |
480 else | |
481 { | |
482 label_width = ws->label_width; | |
483 width = ws->width - 2 * shadow; | |
484 } | |
485 | |
486 /* see if it should be a button in the menubar */ | |
487 button_p = horizontal_p && val->call_data; | |
488 | |
489 /* Only highlight an enabled item that has a callback. */ | |
490 if (highlighted_p) | |
491 if (!val->enabled || !(val->call_data || val->contents)) | |
492 highlighted_p = 0; | |
493 | |
494 /* do the drawing. */ | |
495 if (!just_compute_p) | |
496 { | |
497 /* Add the shadow border of the containing menu */ | |
498 int x = where->x + shadow; | |
499 int y = where->y + shadow; | |
500 | |
501 /* pick the foreground and background GC. */ | |
502 if (val->enabled) | |
503 text_gc = button_p ? mw->menu.button_gc : mw->menu.foreground_gc; | |
504 else | |
505 text_gc = | |
506 button_p ? mw->menu.inactive_button_gc : mw->menu.inactive_gc; | |
507 deco_gc = mw->menu.foreground_gc; | |
508 | |
509 if (separator_p) | |
510 { | |
511 XDrawLine (XtDisplay (mw), ws->window, mw->menu.shadow_bottom_gc, | |
512 x, y, x + width, y); | |
513 XDrawLine (XtDisplay (mw), ws->window, mw->menu.shadow_top_gc, | |
514 x, y + 1, x + width, y + 1); | |
515 } | |
516 else | |
517 { | |
518 char* display_string = resource_widget_value (mw, val); | |
519 draw_shadow_rectangle (mw, ws->window, x, y, width, height, True); | |
520 XDrawString (XtDisplay (mw), ws->window, text_gc, | |
521 x + h_spacing + shadow, | |
522 y + v_spacing + shadow + font_ascent, | |
523 display_string, strlen (display_string)); | |
524 | |
525 if (!horizontal_p) | |
526 { | |
527 if (val->contents) | |
528 { | |
529 int a_w = arrow_width (mw); | |
530 draw_arrow (mw, ws->window, deco_gc, | |
8860 | 531 x + width - arrow_width (mw) |
532 - mw->menu.horizontal_spacing | |
533 - mw->menu.shadow_thickness, | |
5626 | 534 y + v_spacing + shadow, a_w); |
535 } | |
536 else if (val->key) | |
537 { | |
538 XDrawString (XtDisplay (mw), ws->window, text_gc, | |
539 x + label_width + mw->menu.arrow_spacing, | |
540 y + v_spacing + shadow + font_ascent, | |
541 val->key, strlen (val->key)); | |
542 } | |
543 } | |
544 | |
545 else if (button_p) | |
546 { | |
547 #if 1 | |
548 XDrawRectangle (XtDisplay (mw), ws->window, deco_gc, | |
549 x + shadow, y + shadow, | |
550 label_width + h_spacing - 1, | |
551 font_ascent + font_descent + 2 * v_spacing - 1); | |
8860 | 552 draw_shadow_rectangle (mw, ws->window, x, y, width, height, |
553 False); | |
5626 | 554 #else |
555 highlighted_p = True; | |
556 #endif | |
557 } | |
8860 | 558 else |
559 { | |
560 XDrawRectangle (XtDisplay (mw), ws->window, | |
561 mw->menu.background_gc, | |
562 x + shadow, y + shadow, | |
563 label_width + h_spacing - 1, | |
564 font_ascent + font_descent + 2 * v_spacing - 1); | |
565 draw_shadow_rectangle (mw, ws->window, x, y, width, height, | |
566 True); | |
567 } | |
5626 | 568 |
569 if (highlighted_p) | |
570 draw_shadow_rectangle (mw, ws->window, x, y, width, height, False); | |
571 } | |
572 } | |
573 | |
574 where->x += width; | |
575 where->y += height; | |
576 } | |
577 | |
578 static void | |
8860 | 579 display_menu (mw, level, just_compute_p, highlighted_pos, hit, hit_return, |
580 this, that) | |
581 XlwMenuWidget mw; | |
582 int level; | |
583 Boolean just_compute_p; | |
584 XPoint* highlighted_pos; | |
585 XPoint* hit; | |
586 widget_value** hit_return; | |
587 widget_value* this; | |
588 widget_value* that; | |
5626 | 589 { |
590 widget_value* val; | |
591 widget_value* following_item; | |
592 window_state* ws; | |
593 XPoint where; | |
594 int horizontal_p = mw->menu.horizontal && (level == 0); | |
595 int highlighted_p; | |
596 int just_compute_this_one_p; | |
597 | |
598 if (level >= mw->menu.old_depth) | |
599 abort (); | |
600 | |
601 if (level < mw->menu.old_depth - 1) | |
602 following_item = mw->menu.old_stack [level + 1]; | |
603 else | |
604 following_item = NULL; | |
605 | |
606 if (hit) | |
607 *hit_return = NULL; | |
608 | |
609 where.x = 0; | |
610 where.y = 0; | |
611 | |
612 ws = &mw->menu.windows [level]; | |
613 for (val = mw->menu.old_stack [level]->contents; val; val = val->next) | |
614 { | |
615 highlighted_p = val == following_item; | |
616 if (highlighted_p && highlighted_pos) | |
617 { | |
618 if (horizontal_p) | |
619 highlighted_pos->x = where.x; | |
620 else | |
621 highlighted_pos->y = where.y; | |
622 } | |
623 | |
624 just_compute_this_one_p = | |
625 just_compute_p || ((this || that) && val != this && val != that); | |
626 | |
627 display_menu_item (mw, val, ws, &where, highlighted_p, horizontal_p, | |
628 just_compute_this_one_p); | |
629 | |
630 if (highlighted_p && highlighted_pos) | |
631 { | |
632 if (horizontal_p) | |
633 highlighted_pos->y = where.y; | |
634 else | |
635 highlighted_pos->x = where.x; | |
636 } | |
637 | |
638 if (hit | |
639 && !*hit_return | |
640 && (horizontal_p ? hit->x < where.x : hit->y < where.y) | |
641 && !all_dashes_p (val->name)) | |
642 *hit_return = val; | |
643 | |
644 if (horizontal_p) | |
645 where.y = 0; | |
646 else | |
647 where.x = 0; | |
648 } | |
649 | |
650 if (!just_compute_p) | |
651 draw_shadow_rectangle (mw, ws->window, 0, 0, ws->width, ws->height, False); | |
652 } | |
653 | |
654 /* Motion code */ | |
655 static void | |
8860 | 656 set_new_state (mw, val, level) |
657 XlwMenuWidget mw; | |
658 widget_value* val; | |
659 int level; | |
5626 | 660 { |
661 int i; | |
662 | |
663 mw->menu.new_depth = 0; | |
664 for (i = 0; i < level; i++) | |
665 push_new_stack (mw, mw->menu.old_stack [i]); | |
666 push_new_stack (mw, val); | |
667 } | |
668 | |
669 static void | |
8860 | 670 make_windows_if_needed (mw, n) |
671 XlwMenuWidget mw; | |
672 int n; | |
5626 | 673 { |
674 int i; | |
675 int start_at; | |
676 XSetWindowAttributes xswa; | |
677 int mask; | |
678 Window root = RootWindowOfScreen (DefaultScreenOfDisplay (XtDisplay (mw))); | |
679 window_state* windows; | |
680 | |
681 if (mw->menu.windows_length >= n) | |
682 return; | |
683 | |
684 xswa.save_under = True; | |
685 xswa.override_redirect = True; | |
686 xswa.background_pixel = mw->core.background_pixel; | |
687 xswa.border_pixel = mw->core.border_pixel; | |
688 xswa.event_mask = | |
8860 | 689 ExposureMask | PointerMotionMask | PointerMotionHintMask |
5626 | 690 | ButtonReleaseMask | ButtonPressMask; |
691 xswa.cursor = mw->menu.cursor_shape; | |
692 mask = CWSaveUnder | CWOverrideRedirect | CWBackPixel | CWBorderPixel | |
693 | CWEventMask | CWCursor; | |
694 | |
695 if (!mw->menu.windows) | |
696 { | |
697 mw->menu.windows = | |
698 (window_state*)XtMalloc (n * sizeof (window_state)); | |
699 start_at = 0; | |
700 } | |
701 else | |
702 { | |
703 mw->menu.windows = | |
704 (window_state*)XtRealloc ((char*)mw->menu.windows, | |
705 n * sizeof (window_state)); | |
706 start_at = mw->menu.windows_length; | |
707 } | |
708 mw->menu.windows_length = n; | |
709 | |
710 windows = mw->menu.windows; | |
711 | |
712 for (i = start_at; i < n; i++) | |
713 { | |
714 windows [i].x = 0; | |
715 windows [i].y = 0; | |
716 windows [i].width = 1; | |
717 windows [i].height = 1; | |
718 windows [i].window = | |
719 XCreateWindow (XtDisplay (mw), root, 0, 0, 1, 1, | |
720 0, 0, CopyFromParent, CopyFromParent, mask, &xswa); | |
721 } | |
722 } | |
723 | |
724 /* Make the window fit in the screen */ | |
725 static void | |
8860 | 726 fit_to_screen (mw, ws, previous_ws, horizontal_p) |
727 XlwMenuWidget mw; | |
728 window_state* ws; | |
729 window_state* previous_ws; | |
730 Boolean horizontal_p; | |
5626 | 731 { |
732 int screen_width = WidthOfScreen (XtScreen (mw)); | |
733 int screen_height = HeightOfScreen (XtScreen (mw)); | |
734 | |
735 if (ws->x < 0) | |
736 ws->x = 0; | |
737 else if (ws->x + ws->width > screen_width) | |
738 { | |
739 if (!horizontal_p) | |
740 ws->x = previous_ws->x - ws->width; | |
741 else | |
742 ws->x = screen_width - ws->width; | |
743 } | |
744 if (ws->y < 0) | |
745 ws->y = 0; | |
746 else if (ws->y + ws->height > screen_height) | |
747 { | |
748 if (horizontal_p) | |
749 ws->y = previous_ws->y - ws->height; | |
750 else | |
751 ws->y = screen_height - ws->height; | |
752 } | |
753 } | |
754 | |
755 /* Updates old_stack from new_stack and redisplays. */ | |
756 static void | |
8860 | 757 remap_menubar (mw) |
758 XlwMenuWidget mw; | |
5626 | 759 { |
760 int i; | |
761 int last_same; | |
762 XPoint selection_position; | |
763 int old_depth = mw->menu.old_depth; | |
764 int new_depth = mw->menu.new_depth; | |
765 widget_value** old_stack; | |
766 widget_value** new_stack; | |
767 window_state* windows; | |
768 widget_value* old_selection; | |
769 widget_value* new_selection; | |
770 | |
771 /* Check that enough windows and old_stack are ready. */ | |
772 make_windows_if_needed (mw, new_depth); | |
773 make_old_stack_space (mw, new_depth); | |
774 windows = mw->menu.windows; | |
775 old_stack = mw->menu.old_stack; | |
776 new_stack = mw->menu.new_stack; | |
777 | |
778 /* compute the last identical different entry */ | |
779 for (i = 1; i < old_depth && i < new_depth; i++) | |
780 if (old_stack [i] != new_stack [i]) | |
781 break; | |
782 last_same = i - 1; | |
783 | |
784 /* Memorize the previously selected item to be able to refresh it */ | |
785 old_selection = last_same + 1 < old_depth ? old_stack [last_same + 1] : NULL; | |
786 if (old_selection && !old_selection->enabled) | |
787 old_selection = NULL; | |
788 new_selection = last_same + 1 < new_depth ? new_stack [last_same + 1] : NULL; | |
789 if (new_selection && !new_selection->enabled) | |
790 new_selection = NULL; | |
791 | |
792 /* updates old_state from new_state. It has to be done now because | |
793 display_menu (called below) uses the old_stack to know what to display. */ | |
794 for (i = last_same + 1; i < new_depth; i++) | |
795 old_stack [i] = new_stack [i]; | |
796 mw->menu.old_depth = new_depth; | |
797 | |
798 /* refresh the last seletion */ | |
799 selection_position.x = 0; | |
800 selection_position.y = 0; | |
801 display_menu (mw, last_same, new_selection == old_selection, | |
802 &selection_position, NULL, NULL, old_selection, new_selection); | |
803 | |
804 /* Now popup the new menus */ | |
805 for (i = last_same + 1; i < new_depth && new_stack [i]->contents; i++) | |
806 { | |
807 window_state* previous_ws = &windows [i - 1]; | |
808 window_state* ws = &windows [i]; | |
809 | |
810 ws->x = | |
811 previous_ws->x + selection_position.x + mw->menu.shadow_thickness; | |
812 if (!mw->menu.horizontal || i > 1) | |
813 ws->x += mw->menu.shadow_thickness; | |
814 ws->y = | |
815 previous_ws->y + selection_position.y + mw->menu.shadow_thickness; | |
816 | |
817 size_menu (mw, i); | |
818 | |
819 fit_to_screen (mw, ws, previous_ws, mw->menu.horizontal && i == 1); | |
820 | |
821 XClearWindow (XtDisplay (mw), ws->window); | |
822 XMoveResizeWindow (XtDisplay (mw), ws->window, ws->x, ws->y, | |
823 ws->width, ws->height); | |
824 XMapRaised (XtDisplay (mw), ws->window); | |
825 display_menu (mw, i, False, &selection_position, NULL, NULL, NULL, NULL); | |
826 } | |
827 | |
828 /* unmap the menus that popped down */ | |
829 for (i = new_depth - 1; i < old_depth; i++) | |
830 if (i >= new_depth || !new_stack [i]->contents) | |
831 XUnmapWindow (XtDisplay (mw), windows [i].window); | |
832 } | |
833 | |
834 static Boolean | |
8860 | 835 motion_event_is_in_menu (mw, ev, level, relative_pos) |
836 XlwMenuWidget mw; | |
837 XMotionEvent* ev; | |
838 int level; | |
839 XPoint* relative_pos; | |
5626 | 840 { |
841 window_state* ws = &mw->menu.windows [level]; | |
842 int x = level == 0 ? ws->x : ws->x + mw->menu.shadow_thickness; | |
843 int y = level == 0 ? ws->y : ws->y + mw->menu.shadow_thickness; | |
844 relative_pos->x = ev->x_root - x; | |
845 relative_pos->y = ev->y_root - y; | |
846 return (x < ev->x_root && ev->x_root < x + ws->width | |
847 && y < ev->y_root && ev->y_root < y + ws->height); | |
848 } | |
849 | |
850 static Boolean | |
8860 | 851 map_event_to_widget_value (mw, ev, val, level) |
852 XlwMenuWidget mw; | |
853 XMotionEvent* ev; | |
854 widget_value** val; | |
855 int* level; | |
5626 | 856 { |
857 int i; | |
858 XPoint relative_pos; | |
859 window_state* ws; | |
860 | |
861 *val = NULL; | |
862 | |
863 /* Find the window */ | |
864 for (i = mw->menu.old_depth - 1; i >= 0; i--) | |
865 { | |
866 ws = &mw->menu.windows [i]; | |
867 if (ws && motion_event_is_in_menu (mw, ev, i, &relative_pos)) | |
868 { | |
869 display_menu (mw, i, True, NULL, &relative_pos, val, NULL, NULL); | |
870 | |
871 if (*val) | |
872 { | |
873 *level = i + 1; | |
874 return True; | |
875 } | |
876 } | |
877 } | |
878 return False; | |
879 } | |
880 | |
881 /* Procedures */ | |
882 static void | |
8860 | 883 make_drawing_gcs (mw) |
884 XlwMenuWidget mw; | |
5626 | 885 { |
886 XGCValues xgcv; | |
887 | |
888 xgcv.font = mw->menu.font->fid; | |
889 xgcv.foreground = mw->menu.foreground; | |
890 xgcv.background = mw->core.background_pixel; | |
891 mw->menu.foreground_gc = XtGetGC ((Widget)mw, | |
892 GCFont | GCForeground | GCBackground, | |
893 &xgcv); | |
894 | |
895 xgcv.font = mw->menu.font->fid; | |
896 xgcv.foreground = mw->menu.button_foreground; | |
897 xgcv.background = mw->core.background_pixel; | |
898 mw->menu.button_gc = XtGetGC ((Widget)mw, | |
899 GCFont | GCForeground | GCBackground, | |
900 &xgcv); | |
901 | |
902 xgcv.font = mw->menu.font->fid; | |
903 xgcv.foreground = mw->menu.foreground; | |
904 xgcv.background = mw->core.background_pixel; | |
905 xgcv.fill_style = FillStippled; | |
906 xgcv.stipple = mw->menu.gray_pixmap; | |
907 mw->menu.inactive_gc = XtGetGC ((Widget)mw, | |
908 (GCFont | GCForeground | GCBackground | |
909 | GCFillStyle | GCStipple), &xgcv); | |
910 | |
911 xgcv.font = mw->menu.font->fid; | |
912 xgcv.foreground = mw->menu.button_foreground; | |
913 xgcv.background = mw->core.background_pixel; | |
914 xgcv.fill_style = FillStippled; | |
915 xgcv.stipple = mw->menu.gray_pixmap; | |
916 mw->menu.inactive_button_gc = XtGetGC ((Widget)mw, | |
917 (GCFont | GCForeground | GCBackground | |
918 | GCFillStyle | GCStipple), &xgcv); | |
919 | |
920 xgcv.font = mw->menu.font->fid; | |
921 xgcv.foreground = mw->core.background_pixel; | |
922 xgcv.background = mw->menu.foreground; | |
923 mw->menu.background_gc = XtGetGC ((Widget)mw, | |
924 GCFont | GCForeground | GCBackground, | |
925 &xgcv); | |
926 } | |
927 | |
928 static void | |
8860 | 929 release_drawing_gcs (mw) |
930 XlwMenuWidget mw; | |
5626 | 931 { |
932 XtReleaseGC ((Widget) mw, mw->menu.foreground_gc); | |
933 XtReleaseGC ((Widget) mw, mw->menu.button_gc); | |
934 XtReleaseGC ((Widget) mw, mw->menu.inactive_gc); | |
935 XtReleaseGC ((Widget) mw, mw->menu.inactive_button_gc); | |
936 XtReleaseGC ((Widget) mw, mw->menu.background_gc); | |
937 /* let's get some segvs if we try to use these... */ | |
938 mw->menu.foreground_gc = (GC) -1; | |
939 mw->menu.button_gc = (GC) -1; | |
940 mw->menu.inactive_gc = (GC) -1; | |
941 mw->menu.inactive_button_gc = (GC) -1; | |
942 mw->menu.background_gc = (GC) -1; | |
943 } | |
944 | |
945 #define MINL(x,y) ((((unsigned long) (x)) < ((unsigned long) (y))) \ | |
946 ? ((unsigned long) (x)) : ((unsigned long) (y))) | |
947 | |
948 static void | |
8860 | 949 make_shadow_gcs (mw) |
950 XlwMenuWidget mw; | |
5626 | 951 { |
952 XGCValues xgcv; | |
953 unsigned long pm = 0; | |
954 Display *dpy = XtDisplay ((Widget) mw); | |
955 Colormap cmap = DefaultColormapOfScreen (XtScreen ((Widget) mw)); | |
956 XColor topc, botc; | |
957 int top_frobbed = 0, bottom_frobbed = 0; | |
958 | |
959 if (mw->menu.top_shadow_color == -1) | |
960 mw->menu.top_shadow_color = mw->core.background_pixel; | |
961 if (mw->menu.bottom_shadow_color == -1) | |
962 mw->menu.bottom_shadow_color = mw->menu.foreground; | |
963 | |
964 if (mw->menu.top_shadow_color == mw->core.background_pixel || | |
965 mw->menu.top_shadow_color == mw->menu.foreground) | |
966 { | |
967 topc.pixel = mw->core.background_pixel; | |
968 XQueryColor (dpy, cmap, &topc); | |
969 /* don't overflow/wrap! */ | |
970 topc.red = MINL (65535, topc.red * 1.2); | |
971 topc.green = MINL (65535, topc.green * 1.2); | |
972 topc.blue = MINL (65535, topc.blue * 1.2); | |
973 if (XAllocColor (dpy, cmap, &topc)) | |
974 { | |
975 mw->menu.top_shadow_color = topc.pixel; | |
976 top_frobbed = 1; | |
977 } | |
978 } | |
979 if (mw->menu.bottom_shadow_color == mw->menu.foreground || | |
980 mw->menu.bottom_shadow_color == mw->core.background_pixel) | |
981 { | |
982 botc.pixel = mw->core.background_pixel; | |
983 XQueryColor (dpy, cmap, &botc); | |
984 botc.red *= 0.6; | |
985 botc.green *= 0.6; | |
986 botc.blue *= 0.6; | |
987 if (XAllocColor (dpy, cmap, &botc)) | |
988 { | |
989 mw->menu.bottom_shadow_color = botc.pixel; | |
990 bottom_frobbed = 1; | |
991 } | |
992 } | |
993 | |
994 if (top_frobbed && bottom_frobbed) | |
995 { | |
996 int top_avg = ((topc.red / 3) + (topc.green / 3) + (topc.blue / 3)); | |
997 int bot_avg = ((botc.red / 3) + (botc.green / 3) + (botc.blue / 3)); | |
998 if (bot_avg > top_avg) | |
999 { | |
1000 Pixel tmp = mw->menu.top_shadow_color; | |
1001 mw->menu.top_shadow_color = mw->menu.bottom_shadow_color; | |
1002 mw->menu.bottom_shadow_color = tmp; | |
1003 } | |
1004 else if (topc.pixel == botc.pixel) | |
1005 { | |
1006 if (botc.pixel == mw->menu.foreground) | |
1007 mw->menu.top_shadow_color = mw->core.background_pixel; | |
1008 else | |
1009 mw->menu.bottom_shadow_color = mw->menu.foreground; | |
1010 } | |
1011 } | |
1012 | |
1013 if (!mw->menu.top_shadow_pixmap && | |
1014 mw->menu.top_shadow_color == mw->core.background_pixel) | |
1015 { | |
1016 mw->menu.top_shadow_pixmap = mw->menu.gray_pixmap; | |
1017 mw->menu.top_shadow_color = mw->menu.foreground; | |
1018 } | |
1019 if (!mw->menu.bottom_shadow_pixmap && | |
1020 mw->menu.bottom_shadow_color == mw->core.background_pixel) | |
1021 { | |
1022 mw->menu.bottom_shadow_pixmap = mw->menu.gray_pixmap; | |
1023 mw->menu.bottom_shadow_color = mw->menu.foreground; | |
1024 } | |
1025 | |
1026 xgcv.fill_style = FillStippled; | |
1027 xgcv.foreground = mw->menu.top_shadow_color; | |
1028 xgcv.stipple = mw->menu.top_shadow_pixmap; | |
1029 pm = (xgcv.stipple ? GCStipple|GCFillStyle : 0); | |
1030 mw->menu.shadow_top_gc = XtGetGC ((Widget)mw, GCForeground | pm, &xgcv); | |
1031 | |
1032 xgcv.foreground = mw->menu.bottom_shadow_color; | |
1033 xgcv.stipple = mw->menu.bottom_shadow_pixmap; | |
1034 pm = (xgcv.stipple ? GCStipple|GCFillStyle : 0); | |
1035 mw->menu.shadow_bottom_gc = XtGetGC ((Widget)mw, GCForeground | pm, &xgcv); | |
1036 } | |
1037 | |
1038 | |
1039 static void | |
8860 | 1040 release_shadow_gcs (mw) |
1041 XlwMenuWidget mw; | |
5626 | 1042 { |
1043 XtReleaseGC ((Widget) mw, mw->menu.shadow_top_gc); | |
1044 XtReleaseGC ((Widget) mw, mw->menu.shadow_bottom_gc); | |
1045 } | |
1046 | |
1047 static void | |
8860 | 1048 XlwMenuInitialize (request, new, args, num_args) |
1049 Widget request; | |
1050 Widget new; | |
1051 ArgList args; | |
1052 Cardinal *num_args; | |
5626 | 1053 { |
1054 /* Get the GCs and the widget size */ | |
1055 XlwMenuWidget mw = (XlwMenuWidget)new; | |
1056 | |
1057 XSetWindowAttributes xswa; | |
1058 int mask; | |
1059 | |
1060 Window window = RootWindowOfScreen (DefaultScreenOfDisplay (XtDisplay (mw))); | |
1061 Display* display = XtDisplay (mw); | |
1062 | |
8860 | 1063 #if 0 |
1064 widget_value *tem = (widget_value *) XtMalloc (sizeof (widget_value)); | |
1065 | |
1066 /* _XtCreate is freeing the object that was passed to us, | |
1067 so make a copy that we will actually keep. */ | |
1068 lwlib_bcopy (mw->menu.contents, tem, sizeof (widget_value)); | |
1069 mw->menu.contents = tem; | |
1070 #endif | |
1071 | |
5626 | 1072 /* mw->menu.cursor = XCreateFontCursor (display, mw->menu.cursor_shape); */ |
1073 mw->menu.cursor = mw->menu.cursor_shape; | |
1074 | |
1075 mw->menu.gray_pixmap = XCreatePixmapFromBitmapData (display, window, | |
1076 gray_bits, gray_width, | |
1077 gray_height, 1, 0, 1); | |
1078 | |
1079 make_drawing_gcs (mw); | |
1080 make_shadow_gcs (mw); | |
1081 | |
1082 xswa.background_pixel = mw->core.background_pixel; | |
1083 xswa.border_pixel = mw->core.border_pixel; | |
1084 mask = CWBackPixel | CWBorderPixel; | |
1085 | |
1086 mw->menu.popped_up = False; | |
1087 | |
1088 mw->menu.old_depth = 1; | |
1089 mw->menu.old_stack = (widget_value**)XtMalloc (sizeof (widget_value*)); | |
1090 mw->menu.old_stack_length = 1; | |
1091 mw->menu.old_stack [0] = mw->menu.contents; | |
1092 | |
1093 mw->menu.new_depth = 0; | |
1094 mw->menu.new_stack = 0; | |
1095 mw->menu.new_stack_length = 0; | |
1096 push_new_stack (mw, mw->menu.contents); | |
1097 | |
1098 mw->menu.windows = (window_state*)XtMalloc (sizeof (window_state)); | |
1099 mw->menu.windows_length = 1; | |
1100 mw->menu.windows [0].x = 0; | |
1101 mw->menu.windows [0].y = 0; | |
1102 mw->menu.windows [0].width = 0; | |
1103 mw->menu.windows [0].height = 0; | |
1104 size_menu (mw, 0); | |
1105 | |
1106 mw->core.width = mw->menu.windows [0].width; | |
1107 mw->core.height = mw->menu.windows [0].height; | |
1108 } | |
1109 | |
1110 static void | |
1111 XlwMenuClassInitialize () | |
1112 { | |
1113 } | |
1114 | |
1115 static void | |
8860 | 1116 XlwMenuRealize (w, valueMask, attributes) |
1117 Widget w; | |
1118 Mask *valueMask; | |
1119 XSetWindowAttributes *attributes; | |
5626 | 1120 { |
1121 XlwMenuWidget mw = (XlwMenuWidget)w; | |
1122 XSetWindowAttributes xswa; | |
1123 int mask; | |
1124 | |
1125 (*xlwMenuWidgetClass->core_class.superclass->core_class.realize) | |
1126 (w, valueMask, attributes); | |
1127 | |
1128 xswa.save_under = True; | |
1129 xswa.cursor = mw->menu.cursor_shape; | |
1130 mask = CWSaveUnder | CWCursor; | |
1131 XChangeWindowAttributes (XtDisplay (w), XtWindow (w), mask, &xswa); | |
1132 | |
1133 mw->menu.windows [0].window = XtWindow (w); | |
1134 mw->menu.windows [0].x = w->core.x; | |
1135 mw->menu.windows [0].y = w->core.y; | |
1136 mw->menu.windows [0].width = w->core.width; | |
1137 mw->menu.windows [0].height = w->core.height; | |
1138 } | |
1139 | |
1140 /* Only the toplevel menubar/popup is a widget so it's the only one that | |
1141 receives expose events through Xt. So we repaint all the other panes | |
1142 when receiving an Expose event. */ | |
1143 static void | |
8860 | 1144 XlwMenuRedisplay (w, ev, region) |
1145 Widget w; | |
1146 XEvent* ev; | |
1147 Region region; | |
5626 | 1148 { |
1149 XlwMenuWidget mw = (XlwMenuWidget)w; | |
1150 int i; | |
1151 | |
8860 | 1152 /* If we have a depth beyond 1, it's because a submenu was displayed. |
1153 If the submenu has been destroyed, set the depth back to 1. */ | |
1154 if (submenu_destroyed) | |
1155 { | |
1156 mw->menu.old_depth = 1; | |
1157 submenu_destroyed = 0; | |
1158 } | |
1159 | |
5626 | 1160 for (i = 0; i < mw->menu.old_depth; i++) |
1161 display_menu (mw, i, False, NULL, NULL, NULL, NULL, NULL); | |
1162 } | |
1163 | |
1164 static void | |
8860 | 1165 XlwMenuDestroy (w) |
1166 Widget w; | |
5626 | 1167 { |
1168 int i; | |
1169 XlwMenuWidget mw = (XlwMenuWidget) w; | |
1170 | |
8860 | 1171 if (pointer_grabbed) |
1172 XtUngrabPointer ((Widget)w, CurrentTime); | |
1173 pointer_grabbed = 0; | |
1174 | |
1175 submenu_destroyed = 1; | |
1176 | |
5626 | 1177 release_drawing_gcs (mw); |
1178 release_shadow_gcs (mw); | |
1179 | |
1180 /* this doesn't come from the resource db but is created explicitly | |
1181 so we must free it ourselves. */ | |
1182 XFreePixmap (XtDisplay (mw), mw->menu.gray_pixmap); | |
1183 mw->menu.gray_pixmap = (Pixmap) -1; | |
1184 | |
8860 | 1185 #if 0 |
1186 /* Do free mw->menu.contents because nowadays we copy it | |
1187 during initialization. */ | |
1188 XtFree (mw->menu.contents); | |
1189 #endif | |
1190 | |
5626 | 1191 /* Don't free mw->menu.contents because that comes from our creator. |
1192 The `*_stack' elements are just pointers into `contents' so leave | |
1193 that alone too. But free the stacks themselves. */ | |
1194 if (mw->menu.old_stack) XtFree ((char *) mw->menu.old_stack); | |
1195 if (mw->menu.new_stack) XtFree ((char *) mw->menu.new_stack); | |
1196 | |
1197 /* Remember, you can't free anything that came from the resource | |
1198 database. This includes: | |
1199 mw->menu.cursor | |
1200 mw->menu.top_shadow_pixmap | |
1201 mw->menu.bottom_shadow_pixmap | |
1202 mw->menu.font | |
1203 Also the color cells of top_shadow_color, bottom_shadow_color, | |
1204 foreground, and button_foreground will never be freed until this | |
1205 client exits. Nice, eh? | |
1206 */ | |
1207 | |
1208 /* start from 1 because the one in slot 0 is w->core.window */ | |
1209 for (i = 1; i < mw->menu.windows_length; i++) | |
1210 XDestroyWindow (XtDisplay (mw), mw->menu.windows [i].window); | |
1211 if (mw->menu.windows) | |
1212 XtFree ((char *) mw->menu.windows); | |
1213 } | |
1214 | |
1215 static Boolean | |
8860 | 1216 XlwMenuSetValues (current, request, new) |
1217 Widget current; | |
1218 Widget request; | |
1219 Widget new; | |
5626 | 1220 { |
1221 XlwMenuWidget oldmw = (XlwMenuWidget)current; | |
1222 XlwMenuWidget newmw = (XlwMenuWidget)new; | |
1223 Boolean redisplay = False; | |
1224 int i; | |
1225 | |
1226 if (newmw->menu.contents | |
1227 && newmw->menu.contents->contents | |
1228 && newmw->menu.contents->contents->change >= VISIBLE_CHANGE) | |
1229 redisplay = True; | |
1230 | |
1231 if (newmw->core.background_pixel != oldmw->core.background_pixel | |
8860 | 1232 || newmw->menu.foreground != oldmw->menu.foreground |
1233 || newmw->menu.font != oldmw->menu.font) | |
5626 | 1234 { |
1235 release_drawing_gcs (newmw); | |
1236 make_drawing_gcs (newmw); | |
1237 redisplay = True; | |
1238 | |
1239 for (i = 0; i < oldmw->menu.windows_length; i++) | |
1240 { | |
1241 XSetWindowBackground (XtDisplay (oldmw), | |
1242 oldmw->menu.windows [i].window, | |
1243 newmw->core.background_pixel); | |
1244 /* clear windows and generate expose events */ | |
1245 XClearArea (XtDisplay (oldmw), oldmw->menu.windows[i].window, | |
1246 0, 0, 0, 0, True); | |
1247 } | |
1248 } | |
1249 | |
1250 return redisplay; | |
1251 } | |
1252 | |
1253 static void | |
8860 | 1254 XlwMenuResize (w) |
1255 Widget w; | |
5626 | 1256 { |
1257 XlwMenuWidget mw = (XlwMenuWidget)w; | |
1258 | |
8860 | 1259 if (mw->menu.popped_up) |
1260 { | |
1261 /* Don't allow the popup menu to resize itself. */ | |
1262 mw->core.width = mw->menu.windows [0].width; | |
1263 mw->core.height = mw->menu.windows [0].height; | |
1264 mw->core.parent->core.width = mw->core.width ; | |
1265 mw->core.parent->core.height = mw->core.height ; | |
1266 } | |
1267 else | |
1268 { | |
1269 mw->menu.windows [0].width = mw->core.width; | |
1270 mw->menu.windows [0].height = mw->core.height; | |
1271 } | |
5626 | 1272 } |
1273 | |
1274 /* Action procedures */ | |
1275 static void | |
8860 | 1276 handle_single_motion_event (mw, ev) |
1277 XlwMenuWidget mw; | |
1278 XMotionEvent* ev; | |
5626 | 1279 { |
1280 widget_value* val; | |
1281 int level; | |
1282 | |
1283 if (!map_event_to_widget_value (mw, ev, &val, &level)) | |
1284 pop_new_stack_if_no_contents (mw); | |
1285 else | |
1286 set_new_state (mw, val, level); | |
1287 remap_menubar (mw); | |
1288 | |
8860 | 1289 #if 0 |
5626 | 1290 /* Sync with the display. Makes it feel better on X terms. */ |
1291 XSync (XtDisplay (mw), False); | |
8860 | 1292 #endif |
5626 | 1293 } |
1294 | |
1295 static void | |
8860 | 1296 handle_motion_event (mw, ev) |
1297 XlwMenuWidget mw; | |
1298 XMotionEvent* ev; | |
5626 | 1299 { |
1300 int x = ev->x_root; | |
1301 int y = ev->y_root; | |
1302 int state = ev->state; | |
1303 | |
1304 handle_single_motion_event (mw, ev); | |
1305 | |
1306 /* allow motion events to be generated again */ | |
1307 if (ev->is_hint | |
1308 && XQueryPointer (XtDisplay (mw), ev->window, | |
1309 &ev->root, &ev->subwindow, | |
1310 &ev->x_root, &ev->y_root, | |
1311 &ev->x, &ev->y, | |
1312 &ev->state) | |
1313 && ev->state == state | |
1314 && (ev->x_root != x || ev->y_root != y)) | |
1315 handle_single_motion_event (mw, ev); | |
1316 } | |
1317 | |
1318 static void | |
8860 | 1319 Start (w, ev, params, num_params) |
1320 Widget w; | |
1321 XEvent *ev; | |
1322 String *params; | |
1323 Cardinal *num_params; | |
5626 | 1324 { |
1325 XlwMenuWidget mw = (XlwMenuWidget)w; | |
1326 | |
8860 | 1327 if (!mw->menu.popped_up) |
1328 { | |
1329 menu_post_event = *ev; | |
8861 | 1330 next_release_must_exit = 0; |
8860 | 1331 } |
1332 else | |
1333 /* If we push a button while the menu is posted semipermanently, | |
1334 releasing the button should always pop the menu down. */ | |
1335 next_release_must_exit = 1; | |
1336 | |
5626 | 1337 XtCallCallbackList ((Widget)mw, mw->menu.open, NULL); |
1338 | |
1339 /* notes the absolute position of the menubar window */ | |
1340 mw->menu.windows [0].x = ev->xmotion.x_root - ev->xmotion.x; | |
1341 mw->menu.windows [0].y = ev->xmotion.y_root - ev->xmotion.y; | |
1342 | |
1343 /* handles the down like a move, slots are compatible */ | |
1344 handle_motion_event (mw, &ev->xmotion); | |
8861 | 1345 XtGrabPointer ((Widget)mw, False, |
1346 (PointerMotionMask | PointerMotionHintMask | |
1347 | ButtonReleaseMask | ButtonPressMask), | |
1348 GrabModeAsync, GrabModeAsync, None, | |
1349 mw->menu.cursor_shape, | |
1350 ((XButtonPressedEvent *)ev)->time); | |
1351 pointer_grabbed = 1; | |
5626 | 1352 } |
1353 | |
1354 static void | |
8860 | 1355 Drag (w, ev, params, num_params) |
1356 Widget w; | |
1357 XEvent *ev; | |
1358 String *params; | |
1359 Cardinal *num_params; | |
5626 | 1360 { |
1361 XlwMenuWidget mw = (XlwMenuWidget)w; | |
1362 handle_motion_event (mw, &ev->xmotion); | |
1363 } | |
1364 | |
1365 static void | |
8860 | 1366 Select (w, ev, params, num_params) |
1367 Widget w; | |
1368 XEvent *ev; | |
1369 String *params; | |
1370 Cardinal *num_params; | |
5626 | 1371 { |
1372 XlwMenuWidget mw = (XlwMenuWidget)w; | |
1373 widget_value* selected_item = mw->menu.old_stack [mw->menu.old_depth - 1]; | |
1374 | |
8860 | 1375 /* If user releases the button quickly, without selecting anything, |
1376 after the initial down-click that brought the menu up, | |
1377 do nothing. */ | |
1378 if ((selected_item == 0 | |
1379 || ((widget_value *) selected_item)->call_data == 0) | |
1380 && !next_release_must_exit | |
1381 && (ev->xbutton.time - menu_post_event.xbutton.time | |
1382 < XtGetMultiClickTime (XtDisplay (w)))) | |
1383 return; | |
1384 | |
1385 /* pop down everything. */ | |
5626 | 1386 mw->menu.new_depth = 1; |
1387 remap_menubar (mw); | |
1388 | |
1389 if (mw->menu.popped_up) | |
1390 { | |
1391 mw->menu.popped_up = False; | |
1392 XtUngrabPointer ((Widget)mw, ev->xmotion.time); | |
1393 XtPopdown (XtParent (mw)); | |
1394 } | |
1395 | |
1396 /* callback */ | |
1397 XtCallCallbackList ((Widget)mw, mw->menu.select, (XtPointer)selected_item); | |
1398 | |
1399 } | |
1400 | |
1401 | |
1402 /* Special code to pop-up a menu */ | |
1403 void | |
8860 | 1404 pop_up_menu (mw, event) |
1405 XlwMenuWidget mw; | |
1406 XButtonPressedEvent* event; | |
5626 | 1407 { |
1408 int x = event->x_root; | |
1409 int y = event->y_root; | |
1410 int w; | |
1411 int h; | |
1412 int borderwidth = mw->menu.shadow_thickness; | |
1413 Screen* screen = XtScreen (mw); | |
1414 | |
8860 | 1415 next_release_must_exit = 0; |
1416 | |
5626 | 1417 XtCallCallbackList ((Widget)mw, mw->menu.open, NULL); |
1418 | |
1419 size_menu (mw, 0); | |
1420 | |
1421 w = mw->menu.windows [0].width; | |
1422 h = mw->menu.windows [0].height; | |
1423 | |
1424 x -= borderwidth; | |
1425 y -= borderwidth; | |
1426 if (x < borderwidth) | |
1427 x = borderwidth; | |
1428 if (x + w + 2 * borderwidth > WidthOfScreen (screen)) | |
1429 x = WidthOfScreen (screen) - w - 2 * borderwidth; | |
1430 if (y < borderwidth) | |
1431 y = borderwidth; | |
1432 if (y + h + 2 * borderwidth> HeightOfScreen (screen)) | |
1433 y = HeightOfScreen (screen) - h - 2 * borderwidth; | |
1434 | |
1435 mw->menu.popped_up = True; | |
1436 XtConfigureWidget (XtParent (mw), x, y, w, h, | |
1437 XtParent (mw)->core.border_width); | |
1438 XtPopup (XtParent (mw), XtGrabExclusive); | |
1439 display_menu (mw, 0, False, NULL, NULL, NULL, NULL, NULL); | |
8860 | 1440 #ifdef emacs |
1441 x_catch_errors (); | |
1442 #endif | |
5626 | 1443 XtGrabPointer ((Widget)mw, False, |
8860 | 1444 (PointerMotionMask | PointerMotionHintMask | ButtonReleaseMask |
5626 | 1445 | ButtonPressMask), |
1446 GrabModeAsync, GrabModeAsync, None, mw->menu.cursor_shape, | |
1447 event->time); | |
8860 | 1448 pointer_grabbed = 1; |
1449 #ifdef emacs | |
1450 if (x_had_errors_p ()) | |
1451 { | |
1452 pointer_grabbed = 0; | |
1453 XtUngrabPointer ((Widget)mw, event->time); | |
1454 } | |
1455 x_uncatch_errors (); | |
1456 #endif | |
5626 | 1457 |
1458 mw->menu.windows [0].x = x + borderwidth; | |
1459 mw->menu.windows [0].y = y + borderwidth; | |
1460 | |
1461 handle_motion_event (mw, (XMotionEvent*)event); | |
1462 } |