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