1 /* Implements a lightweight menubar widget.
2 Copyright (C) 1992 Lucid, Inc.
4 This file is part of the Lucid Widget Library.
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)
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.
16 You should have received a copy of the GNU General Public License
17 Alongalong with GNU Emacs; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
20 /* Created by devin@lucid.com */
24 #include <sys/types.h>
26 #include <X11/IntrinsicP.h>
27 #include <X11/ObjectP.h>
28 #include <X11/StringDefs.h>
29 #include <X11/cursorfont.h>
30 #include <X11/bitmaps/gray>
33 static int pointer_grabbed
;
34 static XEvent menu_post_event
;
36 XFontStruct
*xlwmenu_default_font
;
39 xlwMenuTranslations
[] =
40 "<BtnDown>: start()\n\
43 <Key>Shift_L: nothing()\n\
44 <Key>Shift_R: nothing()\n\
45 <Key>Meta_L: nothing()\n\
46 <Key>Meta_R: nothing()\n\
47 <Key>Control_L: nothing()\n\
48 <Key>Control_R: nothing()\n\
49 <Key>Hyper_L: nothing()\n\
50 <Key>Hyper_R: nothing()\n\
51 <Key>Super_L: nothing()\n\
52 <Key>Super_R: nothing()\n\
53 <Key>Alt_L: nothing()\n\
54 <Key>Alt_R: nothing()\n\
55 <Key>Caps_Lock: nothing()\n\
56 <Key>Shift_Lock: nothing()\n\
57 <KeyUp>Shift_L: nothing()\n\
58 <KeyUp>Shift_R: nothing()\n\
59 <KeyUp>Meta_L: nothing()\n\
60 <KeyUp>Meta_R: nothing()\n\
61 <KeyUp>Control_L: nothing()\n\
62 <KeyUp>Control_R: nothing()\n\
63 <KeyUp>Hyper_L: nothing()\n\
64 <KeyUp>Hyper_R: nothing()\n\
65 <KeyUp>Super_L: nothing()\n\
66 <KeyUp>Super_R: nothing()\n\
67 <KeyUp>Alt_L: nothing()\n\
68 <KeyUp>Alt_R: nothing()\n\
69 <KeyUp>Caps_Lock: nothing()\n\
70 <KeyUp>Shift_Lock:nothing()\n\
75 #define offset(field) XtOffset(XlwMenuWidget, field)
79 {XtNfont
, XtCFont
, XtRFontStruct
, sizeof(XFontStruct
*),
80 offset(menu
.font
),XtRString
, "XtDefaultFont"},
81 {XtNforeground
, XtCForeground
, XtRPixel
, sizeof(Pixel
),
82 offset(menu
.foreground
), XtRString
, "XtDefaultForeground"},
83 {XtNbuttonForeground
, XtCButtonForeground
, XtRPixel
, sizeof(Pixel
),
84 offset(menu
.button_foreground
), XtRString
, "XtDefaultForeground"},
85 {XtNmargin
, XtCMargin
, XtRDimension
, sizeof(Dimension
),
86 offset(menu
.margin
), XtRImmediate
, (XtPointer
)0},
87 {XtNhorizontalSpacing
, XtCMargin
, XtRDimension
, sizeof(Dimension
),
88 offset(menu
.horizontal_spacing
), XtRImmediate
, (XtPointer
)3},
89 {XtNverticalSpacing
, XtCMargin
, XtRDimension
, sizeof(Dimension
),
90 offset(menu
.vertical_spacing
), XtRImmediate
, (XtPointer
)1},
91 {XtNarrowSpacing
, XtCMargin
, XtRDimension
, sizeof(Dimension
),
92 offset(menu
.arrow_spacing
), XtRImmediate
, (XtPointer
)10},
94 {XmNshadowThickness
, XmCShadowThickness
, XtRDimension
,
95 sizeof (Dimension
), offset (menu
.shadow_thickness
),
96 XtRImmediate
, (XtPointer
) 2},
97 {XmNtopShadowColor
, XmCTopShadowColor
, XtRPixel
, sizeof (Pixel
),
98 offset (menu
.top_shadow_color
), XtRImmediate
, (XtPointer
)-1},
99 {XmNbottomShadowColor
, XmCBottomShadowColor
, XtRPixel
, sizeof (Pixel
),
100 offset (menu
.bottom_shadow_color
), XtRImmediate
, (XtPointer
)-1},
101 {XmNtopShadowPixmap
, XmCTopShadowPixmap
, XtRPixmap
, sizeof (Pixmap
),
102 offset (menu
.top_shadow_pixmap
), XtRImmediate
, (XtPointer
)None
},
103 {XmNbottomShadowPixmap
, XmCBottomShadowPixmap
, XtRPixmap
, sizeof (Pixmap
),
104 offset (menu
.bottom_shadow_pixmap
), XtRImmediate
, (XtPointer
)None
},
106 {XtNopen
, XtCCallback
, XtRCallback
, sizeof(XtPointer
),
107 offset(menu
.open
), XtRCallback
, (XtPointer
)NULL
},
108 {XtNselect
, XtCCallback
, XtRCallback
, sizeof(XtPointer
),
109 offset(menu
.select
), XtRCallback
, (XtPointer
)NULL
},
110 {XtNmenu
, XtCMenu
, XtRPointer
, sizeof(XtPointer
),
111 offset(menu
.contents
), XtRImmediate
, (XtPointer
)NULL
},
112 {XtNcursor
, XtCCursor
, XtRCursor
, sizeof(Cursor
),
113 offset(menu
.cursor_shape
), XtRString
, (XtPointer
)"right_ptr"},
114 {XtNhorizontal
, XtCHorizontal
, XtRInt
, sizeof(int),
115 offset(menu
.horizontal
), XtRImmediate
, (XtPointer
)True
},
119 static Boolean
XlwMenuSetValues();
120 static void XlwMenuRealize();
121 static void XlwMenuRedisplay();
122 static void XlwMenuResize();
123 static void XlwMenuInitialize();
124 static void XlwMenuRedisplay();
125 static void XlwMenuDestroy();
126 static void XlwMenuClassInitialize();
129 static void Select();
131 static void Nothing();
134 xlwMenuActionsList
[] =
140 {"nothing", Nothing
},
143 #define SuperClass ((CoreWidgetClass)&coreClassRec)
145 XlwMenuClassRec xlwMenuClassRec
=
147 { /* CoreClass fields initialization */
148 (WidgetClass
) SuperClass
, /* superclass */
149 "XlwMenu", /* class_name */
150 sizeof(XlwMenuRec
), /* size */
151 XlwMenuClassInitialize
, /* class_initialize */
152 NULL
, /* class_part_initialize */
153 FALSE
, /* class_inited */
154 XlwMenuInitialize
, /* initialize */
155 NULL
, /* initialize_hook */
156 XlwMenuRealize
, /* realize */
157 xlwMenuActionsList
, /* actions */
158 XtNumber(xlwMenuActionsList
), /* num_actions */
159 xlwMenuResources
, /* resources */
160 XtNumber(xlwMenuResources
), /* resource_count */
161 NULLQUARK
, /* xrm_class */
162 TRUE
, /* compress_motion */
163 TRUE
, /* compress_exposure */
164 TRUE
, /* compress_enterleave */
165 FALSE
, /* visible_interest */
166 XlwMenuDestroy
, /* destroy */
167 XlwMenuResize
, /* resize */
168 XlwMenuRedisplay
, /* expose */
169 XlwMenuSetValues
, /* set_values */
170 NULL
, /* set_values_hook */
171 XtInheritSetValuesAlmost
, /* set_values_almost */
172 NULL
, /* get_values_hook */
173 NULL
, /* accept_focus */
174 XtVersion
, /* version */
175 NULL
, /* callback_private */
176 xlwMenuTranslations
, /* tm_table */
177 XtInheritQueryGeometry
, /* query_geometry */
178 XtInheritDisplayAccelerator
, /* display_accelerator */
180 }, /* XlwMenuClass fields initialization */
186 WidgetClass xlwMenuWidgetClass
= (WidgetClass
) &xlwMenuClassRec
;
188 int submenu_destroyed
;
190 static int next_release_must_exit
;
194 push_new_stack (mw
, val
)
198 if (!mw
->menu
.new_stack
)
200 mw
->menu
.new_stack_length
= 10;
202 (widget_value
**)XtCalloc (mw
->menu
.new_stack_length
,
203 sizeof (widget_value
*));
205 else if (mw
->menu
.new_depth
== mw
->menu
.new_stack_length
)
207 mw
->menu
.new_stack_length
*= 2;
209 (widget_value
**)XtRealloc ((char*)mw
->menu
.new_stack
,
210 mw
->menu
.new_stack_length
* sizeof (widget_value
*));
212 mw
->menu
.new_stack
[mw
->menu
.new_depth
++] = val
;
216 pop_new_stack_if_no_contents (mw
)
219 if (mw
->menu
.new_depth
)
221 if (!mw
->menu
.new_stack
[mw
->menu
.new_depth
- 1]->contents
)
222 mw
->menu
.new_depth
-= 1;
227 make_old_stack_space (mw
, n
)
231 if (!mw
->menu
.old_stack
)
233 mw
->menu
.old_stack_length
= 10;
235 (widget_value
**)XtCalloc (mw
->menu
.old_stack_length
,
236 sizeof (widget_value
*));
238 else if (mw
->menu
.old_stack_length
< n
)
240 mw
->menu
.old_stack_length
*= 2;
242 (widget_value
**)XtRealloc ((char*)mw
->menu
.old_stack
,
243 mw
->menu
.old_stack_length
* sizeof (widget_value
*));
253 for (p
= s
; *p
== '-'; p
++);
265 XTextExtents (mw
->menu
.font
, s
, strlen (s
), &drop
, &drop
, &drop
, &xcs
);
273 return mw
->menu
.font
->ascent
/ 2 | 1;
279 {"labelString", "LabelString", XtRString
, sizeof(String
),
284 resource_widget_value (mw
, val
)
288 if (!val
->toolkit_data
)
290 char* resourced_name
= NULL
;
292 XtGetSubresources ((Widget
) mw
,
293 (XtPointer
) &resourced_name
,
294 val
->name
, val
->name
,
295 nameResource
, 1, NULL
, 0);
297 resourced_name
= val
->name
;
300 complete_name
= (char *) XtMalloc (strlen (resourced_name
) + 1);
301 strcpy (complete_name
, resourced_name
);
305 int complete_length
=
306 strlen (resourced_name
) + strlen (val
->value
) + 2;
307 complete_name
= XtMalloc (complete_length
);
309 strcat (complete_name
, resourced_name
);
310 strcat (complete_name
, " ");
311 strcat (complete_name
, val
->value
);
314 val
->toolkit_data
= complete_name
;
315 val
->free_toolkit_data
= True
;
317 return (char*)val
->toolkit_data
;
320 /* Returns the sizes of an item */
322 size_menu_item (mw
, val
, horizontal_p
, label_width
, rest_width
, height
)
330 if (all_dashes_p (val
->name
))
339 mw
->menu
.font
->ascent
+ mw
->menu
.font
->descent
340 + 2 * mw
->menu
.vertical_spacing
+ 2 * mw
->menu
.shadow_thickness
;
343 string_width (mw
, resource_widget_value (mw
, val
))
344 + mw
->menu
.horizontal_spacing
+ mw
->menu
.shadow_thickness
;
346 *rest_width
= mw
->menu
.horizontal_spacing
+ mw
->menu
.shadow_thickness
;
350 *rest_width
+= arrow_width (mw
) + mw
->menu
.arrow_spacing
;
353 string_width (mw
, val
->key
) + mw
->menu
.arrow_spacing
;
359 size_menu (mw
, level
)
363 unsigned int label_width
= 0;
365 int max_rest_width
= 0;
366 unsigned int height
= 0;
367 int horizontal_p
= mw
->menu
.horizontal
&& (level
== 0);
371 if (level
>= mw
->menu
.old_depth
)
374 ws
= &mw
->menu
.windows
[level
];
379 for (val
= mw
->menu
.old_stack
[level
]->contents
; val
; val
= val
->next
)
381 size_menu_item (mw
, val
, horizontal_p
, &label_width
, &rest_width
,
385 ws
->width
+= label_width
+ rest_width
;
386 if (height
> ws
->height
)
391 if (label_width
> ws
->label_width
)
392 ws
->label_width
= label_width
;
393 if (rest_width
> max_rest_width
)
394 max_rest_width
= rest_width
;
395 ws
->height
+= height
;
402 ws
->width
= ws
->label_width
+ max_rest_width
;
404 ws
->width
+= 2 * mw
->menu
.shadow_thickness
;
405 ws
->height
+= 2 * mw
->menu
.shadow_thickness
;
411 draw_arrow (mw
, window
, gc
, x
, y
, width
)
421 points
[0].y
= y
+ mw
->menu
.font
->ascent
;
424 points
[2].x
= x
+ width
;
425 points
[2].y
= y
+ mw
->menu
.font
->ascent
/ 2;
427 XFillPolygon (XtDisplay (mw
), window
, gc
, points
, 3, Convex
,
432 draw_shadow_rectangle (mw
, window
, x
, y
, width
, height
, erase_p
)
441 Display
*dpy
= XtDisplay (mw
);
442 GC top_gc
= !erase_p
? mw
->menu
.shadow_top_gc
: mw
->menu
.background_gc
;
443 GC bottom_gc
= !erase_p
? mw
->menu
.shadow_bottom_gc
: mw
->menu
.background_gc
;
444 int thickness
= mw
->menu
.shadow_thickness
;
448 points
[1].x
= x
+ width
;
450 points
[2].x
= x
+ width
- thickness
;
451 points
[2].y
= y
+ thickness
;
453 points
[3].y
= y
+ thickness
;
454 XFillPolygon (dpy
, window
, top_gc
, points
, 4, Convex
, CoordModeOrigin
);
456 points
[0].y
= y
+ thickness
;
458 points
[1].y
= y
+ height
;
459 points
[2].x
= x
+ thickness
;
460 points
[2].y
= y
+ height
- thickness
;
461 points
[3].x
= x
+ thickness
;
462 points
[3].y
= y
+ thickness
;
463 XFillPolygon (dpy
, window
, top_gc
, points
, 4, Convex
, CoordModeOrigin
);
464 points
[0].x
= x
+ width
;
466 points
[1].x
= x
+ width
- thickness
;
467 points
[1].y
= y
+ thickness
;
468 points
[2].x
= x
+ width
- thickness
;
469 points
[2].y
= y
+ height
- thickness
;
470 points
[3].x
= x
+ width
;
471 points
[3].y
= y
+ height
- thickness
;
472 XFillPolygon (dpy
, window
, bottom_gc
, points
, 4, Convex
, CoordModeOrigin
);
474 points
[0].y
= y
+ height
;
475 points
[1].x
= x
+ width
;
476 points
[1].y
= y
+ height
;
477 points
[2].x
= x
+ width
;
478 points
[2].y
= y
+ height
- thickness
;
479 points
[3].x
= x
+ thickness
;
480 points
[3].y
= y
+ height
- thickness
;
481 XFillPolygon (dpy
, window
, bottom_gc
, points
, 4, Convex
, CoordModeOrigin
);
485 /* Display the menu item and increment where.x and where.y to show how large
486 ** the menu item was.
489 display_menu_item (mw
, val
, ws
, where
, highlighted_p
, horizontal_p
, just_compute_p
)
494 Boolean highlighted_p
;
495 Boolean horizontal_p
;
496 Boolean just_compute_p
;
500 int font_ascent
= mw
->menu
.font
->ascent
;
501 int font_descent
= mw
->menu
.font
->descent
;
502 int shadow
= mw
->menu
.shadow_thickness
;
503 int separator_p
= all_dashes_p (val
->name
);
504 int h_spacing
= mw
->menu
.horizontal_spacing
;
505 int v_spacing
= mw
->menu
.vertical_spacing
;
512 /* compute the sizes of the item */
513 size_menu_item (mw
, val
, horizontal_p
, &label_width
, &rest_width
, &height
);
516 width
= label_width
+ rest_width
;
519 label_width
= ws
->label_width
;
520 width
= ws
->width
- 2 * shadow
;
524 /* see if it should be a button in the menubar */
525 button_p
= horizontal_p
&& val
->call_data
;
529 /* Only highlight an enabled item that has a callback. */
531 if (!val
->enabled
|| !(val
->call_data
|| val
->contents
))
534 /* do the drawing. */
537 /* Add the shadow border of the containing menu */
538 int x
= where
->x
+ shadow
;
539 int y
= where
->y
+ shadow
;
541 /* pick the foreground and background GC. */
543 text_gc
= button_p
? mw
->menu
.button_gc
: mw
->menu
.foreground_gc
;
546 button_p
? mw
->menu
.inactive_button_gc
: mw
->menu
.inactive_gc
;
547 deco_gc
= mw
->menu
.foreground_gc
;
551 XDrawLine (XtDisplay (mw
), ws
->window
, mw
->menu
.shadow_bottom_gc
,
553 XDrawLine (XtDisplay (mw
), ws
->window
, mw
->menu
.shadow_top_gc
,
554 x
, y
+ 1, x
+ width
, y
+ 1);
558 int x_offset
= x
+ h_spacing
+ shadow
;
559 char* display_string
= resource_widget_value (mw
, val
);
560 draw_shadow_rectangle (mw
, ws
->window
, x
, y
, width
, height
, True
);
562 /* Deal with centering a menu title. */
563 if (!horizontal_p
&& !val
->contents
&& !val
->call_data
)
565 int l
= string_width (mw
, display_string
);
568 x_offset
= (width
- l
) >> 1;
570 XDrawString (XtDisplay (mw
), ws
->window
, text_gc
, x_offset
,
571 y
+ v_spacing
+ shadow
+ font_ascent
,
572 display_string
, strlen (display_string
));
578 int a_w
= arrow_width (mw
);
579 draw_arrow (mw
, ws
->window
, deco_gc
,
580 x
+ width
- arrow_width (mw
)
581 - mw
->menu
.horizontal_spacing
582 - mw
->menu
.shadow_thickness
,
583 y
+ v_spacing
+ shadow
, a_w
);
587 XDrawString (XtDisplay (mw
), ws
->window
, text_gc
,
588 x
+ label_width
+ mw
->menu
.arrow_spacing
,
589 y
+ v_spacing
+ shadow
+ font_ascent
,
590 val
->key
, strlen (val
->key
));
597 XDrawRectangle (XtDisplay (mw
), ws
->window
, deco_gc
,
598 x
+ shadow
, y
+ shadow
,
599 label_width
+ h_spacing
- 1,
600 font_ascent
+ font_descent
+ 2 * v_spacing
- 1);
601 draw_shadow_rectangle (mw
, ws
->window
, x
, y
, width
, height
,
604 highlighted_p
= True
;
609 XDrawRectangle (XtDisplay (mw
), ws
->window
,
610 mw
->menu
.background_gc
,
611 x
+ shadow
, y
+ shadow
,
612 label_width
+ h_spacing
- 1,
613 font_ascent
+ font_descent
+ 2 * v_spacing
- 1);
614 draw_shadow_rectangle (mw
, ws
->window
, x
, y
, width
, height
,
619 draw_shadow_rectangle (mw
, ws
->window
, x
, y
, width
, height
, False
);
628 display_menu (mw
, level
, just_compute_p
, highlighted_pos
, hit
, hit_return
,
632 Boolean just_compute_p
;
633 XPoint
* highlighted_pos
;
635 widget_value
** hit_return
;
640 widget_value
* following_item
;
643 int horizontal_p
= mw
->menu
.horizontal
&& (level
== 0);
645 int just_compute_this_one_p
;
647 if (level
>= mw
->menu
.old_depth
)
650 if (level
< mw
->menu
.old_depth
- 1)
651 following_item
= mw
->menu
.old_stack
[level
+ 1];
653 following_item
= NULL
;
661 ws
= &mw
->menu
.windows
[level
];
662 for (val
= mw
->menu
.old_stack
[level
]->contents
; val
; val
= val
->next
)
664 highlighted_p
= val
== following_item
;
665 if (highlighted_p
&& highlighted_pos
)
668 highlighted_pos
->x
= where
.x
;
670 highlighted_pos
->y
= where
.y
;
673 just_compute_this_one_p
=
674 just_compute_p
|| ((this || that
) && val
!= this && val
!= that
);
676 display_menu_item (mw
, val
, ws
, &where
, highlighted_p
, horizontal_p
,
677 just_compute_this_one_p
);
679 if (highlighted_p
&& highlighted_pos
)
682 highlighted_pos
->y
= where
.y
;
684 highlighted_pos
->x
= where
.x
;
689 && (horizontal_p
? hit
->x
< where
.x
: hit
->y
< where
.y
)
690 && !all_dashes_p (val
->name
))
700 draw_shadow_rectangle (mw
, ws
->window
, 0, 0, ws
->width
, ws
->height
, False
);
705 set_new_state (mw
, val
, level
)
712 mw
->menu
.new_depth
= 0;
713 for (i
= 0; i
< level
; i
++)
714 push_new_stack (mw
, mw
->menu
.old_stack
[i
]);
715 push_new_stack (mw
, val
);
719 make_windows_if_needed (mw
, n
)
725 XSetWindowAttributes xswa
;
727 Window root
= RootWindowOfScreen (DefaultScreenOfDisplay (XtDisplay (mw
)));
728 window_state
* windows
;
730 if (mw
->menu
.windows_length
>= n
)
733 xswa
.save_under
= True
;
734 xswa
.override_redirect
= True
;
735 xswa
.background_pixel
= mw
->core
.background_pixel
;
736 xswa
.border_pixel
= mw
->core
.border_pixel
;
738 ExposureMask
| PointerMotionMask
| PointerMotionHintMask
739 | ButtonReleaseMask
| ButtonPressMask
;
740 xswa
.cursor
= mw
->menu
.cursor_shape
;
741 mask
= CWSaveUnder
| CWOverrideRedirect
| CWBackPixel
| CWBorderPixel
742 | CWEventMask
| CWCursor
;
744 if (!mw
->menu
.windows
)
747 (window_state
*)XtMalloc (n
* sizeof (window_state
));
753 (window_state
*)XtRealloc ((char*)mw
->menu
.windows
,
754 n
* sizeof (window_state
));
755 start_at
= mw
->menu
.windows_length
;
757 mw
->menu
.windows_length
= n
;
759 windows
= mw
->menu
.windows
;
761 for (i
= start_at
; i
< n
; i
++)
765 windows
[i
].width
= 1;
766 windows
[i
].height
= 1;
768 XCreateWindow (XtDisplay (mw
), root
, 0, 0, 1, 1,
769 0, 0, CopyFromParent
, CopyFromParent
, mask
, &xswa
);
773 /* Make the window fit in the screen */
775 fit_to_screen (mw
, ws
, previous_ws
, horizontal_p
)
778 window_state
* previous_ws
;
779 Boolean horizontal_p
;
781 unsigned int screen_width
= WidthOfScreen (XtScreen (mw
));
782 unsigned int screen_height
= HeightOfScreen (XtScreen (mw
));
786 else if (ws
->x
+ ws
->width
> screen_width
)
789 ws
->x
= previous_ws
->x
- ws
->width
;
791 ws
->x
= screen_width
- ws
->width
;
797 else if (ws
->y
+ ws
->height
> screen_height
)
800 ws
->y
= previous_ws
->y
- ws
->height
;
802 ws
->y
= screen_height
- ws
->height
;
808 /* Updates old_stack from new_stack and redisplays. */
815 XPoint selection_position
;
816 int old_depth
= mw
->menu
.old_depth
;
817 int new_depth
= mw
->menu
.new_depth
;
818 widget_value
** old_stack
;
819 widget_value
** new_stack
;
820 window_state
* windows
;
821 widget_value
* old_selection
;
822 widget_value
* new_selection
;
824 /* Check that enough windows and old_stack are ready. */
825 make_windows_if_needed (mw
, new_depth
);
826 make_old_stack_space (mw
, new_depth
);
827 windows
= mw
->menu
.windows
;
828 old_stack
= mw
->menu
.old_stack
;
829 new_stack
= mw
->menu
.new_stack
;
831 /* compute the last identical different entry */
832 for (i
= 1; i
< old_depth
&& i
< new_depth
; i
++)
833 if (old_stack
[i
] != new_stack
[i
])
837 /* Memorize the previously selected item to be able to refresh it */
838 old_selection
= last_same
+ 1 < old_depth
? old_stack
[last_same
+ 1] : NULL
;
839 if (old_selection
&& !old_selection
->enabled
)
840 old_selection
= NULL
;
841 new_selection
= last_same
+ 1 < new_depth
? new_stack
[last_same
+ 1] : NULL
;
842 if (new_selection
&& !new_selection
->enabled
)
843 new_selection
= NULL
;
845 /* updates old_state from new_state. It has to be done now because
846 display_menu (called below) uses the old_stack to know what to display. */
847 for (i
= last_same
+ 1; i
< new_depth
; i
++)
848 old_stack
[i
] = new_stack
[i
];
849 mw
->menu
.old_depth
= new_depth
;
851 /* refresh the last selection */
852 selection_position
.x
= 0;
853 selection_position
.y
= 0;
854 display_menu (mw
, last_same
, new_selection
== old_selection
,
855 &selection_position
, NULL
, NULL
, old_selection
, new_selection
);
857 /* Now popup the new menus */
858 for (i
= last_same
+ 1; i
< new_depth
&& new_stack
[i
]->contents
; i
++)
860 window_state
* previous_ws
= &windows
[i
- 1];
861 window_state
* ws
= &windows
[i
];
864 previous_ws
->x
+ selection_position
.x
+ mw
->menu
.shadow_thickness
;
865 if (!mw
->menu
.horizontal
|| i
> 1)
866 ws
->x
+= mw
->menu
.shadow_thickness
;
868 previous_ws
->y
+ selection_position
.y
+ mw
->menu
.shadow_thickness
;
872 fit_to_screen (mw
, ws
, previous_ws
, mw
->menu
.horizontal
&& i
== 1);
874 XClearWindow (XtDisplay (mw
), ws
->window
);
875 XMoveResizeWindow (XtDisplay (mw
), ws
->window
, ws
->x
, ws
->y
,
876 ws
->width
, ws
->height
);
877 XMapRaised (XtDisplay (mw
), ws
->window
);
878 display_menu (mw
, i
, False
, &selection_position
, NULL
, NULL
, NULL
, NULL
);
881 /* unmap the menus that popped down */
882 for (i
= new_depth
- 1; i
< old_depth
; i
++)
883 if (i
>= new_depth
|| !new_stack
[i
]->contents
)
884 XUnmapWindow (XtDisplay (mw
), windows
[i
].window
);
888 motion_event_is_in_menu (mw
, ev
, level
, relative_pos
)
892 XPoint
* relative_pos
;
894 window_state
* ws
= &mw
->menu
.windows
[level
];
895 int x
= level
== 0 ? ws
->x
: ws
->x
+ mw
->menu
.shadow_thickness
;
896 int y
= level
== 0 ? ws
->y
: ws
->y
+ mw
->menu
.shadow_thickness
;
897 relative_pos
->x
= ev
->x_root
- x
;
898 relative_pos
->y
= ev
->y_root
- y
;
899 return (x
< ev
->x_root
&& ev
->x_root
< x
+ ws
->width
900 && y
< ev
->y_root
&& ev
->y_root
< y
+ ws
->height
);
904 map_event_to_widget_value (mw
, ev
, val
, level
)
916 /* Find the window */
917 for (i
= mw
->menu
.old_depth
- 1; i
>= 0; i
--)
919 ws
= &mw
->menu
.windows
[i
];
920 if (ws
&& motion_event_is_in_menu (mw
, ev
, i
, &relative_pos
))
922 display_menu (mw
, i
, True
, NULL
, &relative_pos
, val
, NULL
, NULL
);
936 make_drawing_gcs (mw
)
941 xgcv
.font
= mw
->menu
.font
->fid
;
942 xgcv
.foreground
= mw
->menu
.foreground
;
943 xgcv
.background
= mw
->core
.background_pixel
;
944 mw
->menu
.foreground_gc
= XtGetGC ((Widget
)mw
,
945 GCFont
| GCForeground
| GCBackground
,
948 xgcv
.font
= mw
->menu
.font
->fid
;
949 xgcv
.foreground
= mw
->menu
.button_foreground
;
950 xgcv
.background
= mw
->core
.background_pixel
;
951 mw
->menu
.button_gc
= XtGetGC ((Widget
)mw
,
952 GCFont
| GCForeground
| GCBackground
,
955 xgcv
.font
= mw
->menu
.font
->fid
;
956 xgcv
.foreground
= mw
->menu
.foreground
;
957 xgcv
.background
= mw
->core
.background_pixel
;
958 xgcv
.fill_style
= FillStippled
;
959 xgcv
.stipple
= mw
->menu
.gray_pixmap
;
960 mw
->menu
.inactive_gc
= XtGetGC ((Widget
)mw
,
961 (GCFont
| GCForeground
| GCBackground
962 | GCFillStyle
| GCStipple
), &xgcv
);
964 xgcv
.font
= mw
->menu
.font
->fid
;
965 xgcv
.foreground
= mw
->menu
.button_foreground
;
966 xgcv
.background
= mw
->core
.background_pixel
;
967 xgcv
.fill_style
= FillStippled
;
968 xgcv
.stipple
= mw
->menu
.gray_pixmap
;
969 mw
->menu
.inactive_button_gc
= XtGetGC ((Widget
)mw
,
970 (GCFont
| GCForeground
| GCBackground
971 | GCFillStyle
| GCStipple
), &xgcv
);
973 xgcv
.font
= mw
->menu
.font
->fid
;
974 xgcv
.foreground
= mw
->core
.background_pixel
;
975 xgcv
.background
= mw
->menu
.foreground
;
976 mw
->menu
.background_gc
= XtGetGC ((Widget
)mw
,
977 GCFont
| GCForeground
| GCBackground
,
982 release_drawing_gcs (mw
)
985 XtReleaseGC ((Widget
) mw
, mw
->menu
.foreground_gc
);
986 XtReleaseGC ((Widget
) mw
, mw
->menu
.button_gc
);
987 XtReleaseGC ((Widget
) mw
, mw
->menu
.inactive_gc
);
988 XtReleaseGC ((Widget
) mw
, mw
->menu
.inactive_button_gc
);
989 XtReleaseGC ((Widget
) mw
, mw
->menu
.background_gc
);
990 /* let's get some segvs if we try to use these... */
991 mw
->menu
.foreground_gc
= (GC
) -1;
992 mw
->menu
.button_gc
= (GC
) -1;
993 mw
->menu
.inactive_gc
= (GC
) -1;
994 mw
->menu
.inactive_button_gc
= (GC
) -1;
995 mw
->menu
.background_gc
= (GC
) -1;
998 #define MINL(x,y) ((((unsigned long) (x)) < ((unsigned long) (y))) \
999 ? ((unsigned long) (x)) : ((unsigned long) (y)))
1002 make_shadow_gcs (mw
)
1006 unsigned long pm
= 0;
1007 Display
*dpy
= XtDisplay ((Widget
) mw
);
1008 Colormap cmap
= DefaultColormapOfScreen (XtScreen ((Widget
) mw
));
1010 int top_frobbed
= 0, bottom_frobbed
= 0;
1012 if (mw
->menu
.top_shadow_color
== -1)
1013 mw
->menu
.top_shadow_color
= mw
->core
.background_pixel
;
1014 if (mw
->menu
.bottom_shadow_color
== -1)
1015 mw
->menu
.bottom_shadow_color
= mw
->menu
.foreground
;
1017 if (mw
->menu
.top_shadow_color
== mw
->core
.background_pixel
||
1018 mw
->menu
.top_shadow_color
== mw
->menu
.foreground
)
1020 topc
.pixel
= mw
->core
.background_pixel
;
1021 XQueryColor (dpy
, cmap
, &topc
);
1022 /* don't overflow/wrap! */
1023 topc
.red
= MINL (65535, topc
.red
* 1.2);
1024 topc
.green
= MINL (65535, topc
.green
* 1.2);
1025 topc
.blue
= MINL (65535, topc
.blue
* 1.2);
1026 if (XAllocColor (dpy
, cmap
, &topc
))
1028 mw
->menu
.top_shadow_color
= topc
.pixel
;
1032 if (mw
->menu
.bottom_shadow_color
== mw
->menu
.foreground
||
1033 mw
->menu
.bottom_shadow_color
== mw
->core
.background_pixel
)
1035 botc
.pixel
= mw
->core
.background_pixel
;
1036 XQueryColor (dpy
, cmap
, &botc
);
1040 if (XAllocColor (dpy
, cmap
, &botc
))
1042 mw
->menu
.bottom_shadow_color
= botc
.pixel
;
1047 if (top_frobbed
&& bottom_frobbed
)
1049 int top_avg
= ((topc
.red
/ 3) + (topc
.green
/ 3) + (topc
.blue
/ 3));
1050 int bot_avg
= ((botc
.red
/ 3) + (botc
.green
/ 3) + (botc
.blue
/ 3));
1051 if (bot_avg
> top_avg
)
1053 Pixel tmp
= mw
->menu
.top_shadow_color
;
1054 mw
->menu
.top_shadow_color
= mw
->menu
.bottom_shadow_color
;
1055 mw
->menu
.bottom_shadow_color
= tmp
;
1057 else if (topc
.pixel
== botc
.pixel
)
1059 if (botc
.pixel
== mw
->menu
.foreground
)
1060 mw
->menu
.top_shadow_color
= mw
->core
.background_pixel
;
1062 mw
->menu
.bottom_shadow_color
= mw
->menu
.foreground
;
1066 if (!mw
->menu
.top_shadow_pixmap
&&
1067 mw
->menu
.top_shadow_color
== mw
->core
.background_pixel
)
1069 mw
->menu
.top_shadow_pixmap
= mw
->menu
.gray_pixmap
;
1070 mw
->menu
.top_shadow_color
= mw
->menu
.foreground
;
1072 if (!mw
->menu
.bottom_shadow_pixmap
&&
1073 mw
->menu
.bottom_shadow_color
== mw
->core
.background_pixel
)
1075 mw
->menu
.bottom_shadow_pixmap
= mw
->menu
.gray_pixmap
;
1076 mw
->menu
.bottom_shadow_color
= mw
->menu
.foreground
;
1079 xgcv
.fill_style
= FillStippled
;
1080 xgcv
.foreground
= mw
->menu
.top_shadow_color
;
1081 xgcv
.stipple
= mw
->menu
.top_shadow_pixmap
;
1082 pm
= (xgcv
.stipple
? GCStipple
|GCFillStyle
: 0);
1083 mw
->menu
.shadow_top_gc
= XtGetGC ((Widget
)mw
, GCForeground
| pm
, &xgcv
);
1085 xgcv
.foreground
= mw
->menu
.bottom_shadow_color
;
1086 xgcv
.stipple
= mw
->menu
.bottom_shadow_pixmap
;
1087 pm
= (xgcv
.stipple
? GCStipple
|GCFillStyle
: 0);
1088 mw
->menu
.shadow_bottom_gc
= XtGetGC ((Widget
)mw
, GCForeground
| pm
, &xgcv
);
1093 release_shadow_gcs (mw
)
1096 XtReleaseGC ((Widget
) mw
, mw
->menu
.shadow_top_gc
);
1097 XtReleaseGC ((Widget
) mw
, mw
->menu
.shadow_bottom_gc
);
1101 XlwMenuInitialize (request
, mw
, args
, num_args
)
1107 /* Get the GCs and the widget size */
1108 XSetWindowAttributes xswa
;
1111 Window window
= RootWindowOfScreen (DefaultScreenOfDisplay (XtDisplay (mw
)));
1112 Display
* display
= XtDisplay (mw
);
1115 widget_value
*tem
= (widget_value
*) XtMalloc (sizeof (widget_value
));
1117 /* _XtCreate is freeing the object that was passed to us,
1118 so make a copy that we will actually keep. */
1119 lwlib_bcopy (mw
->menu
.contents
, tem
, sizeof (widget_value
));
1120 mw
->menu
.contents
= tem
;
1123 /* mw->menu.cursor = XCreateFontCursor (display, mw->menu.cursor_shape); */
1124 mw
->menu
.cursor
= mw
->menu
.cursor_shape
;
1126 mw
->menu
.gray_pixmap
1127 = XCreatePixmapFromBitmapData (display
, window
, gray_bits
,
1128 gray_width
, gray_height
,
1129 (unsigned long)1, (unsigned long)0, 1);
1131 /* I don't understand why this ends up 0 sometimes,
1132 but it does. This kludge works around it.
1133 Can anyone find a real fix? -- rms. */
1134 if (mw
->menu
.font
== 0)
1135 mw
->menu
.font
= xlwmenu_default_font
;
1137 make_drawing_gcs (mw
);
1138 make_shadow_gcs (mw
);
1140 xswa
.background_pixel
= mw
->core
.background_pixel
;
1141 xswa
.border_pixel
= mw
->core
.border_pixel
;
1142 mask
= CWBackPixel
| CWBorderPixel
;
1144 mw
->menu
.popped_up
= False
;
1146 mw
->menu
.old_depth
= 1;
1147 mw
->menu
.old_stack
= (widget_value
**)XtMalloc (sizeof (widget_value
*));
1148 mw
->menu
.old_stack_length
= 1;
1149 mw
->menu
.old_stack
[0] = mw
->menu
.contents
;
1151 mw
->menu
.new_depth
= 0;
1152 mw
->menu
.new_stack
= 0;
1153 mw
->menu
.new_stack_length
= 0;
1154 push_new_stack (mw
, mw
->menu
.contents
);
1156 mw
->menu
.windows
= (window_state
*)XtMalloc (sizeof (window_state
));
1157 mw
->menu
.windows_length
= 1;
1158 mw
->menu
.windows
[0].x
= 0;
1159 mw
->menu
.windows
[0].y
= 0;
1160 mw
->menu
.windows
[0].width
= 0;
1161 mw
->menu
.windows
[0].height
= 0;
1164 mw
->core
.width
= mw
->menu
.windows
[0].width
;
1165 mw
->core
.height
= mw
->menu
.windows
[0].height
;
1169 XlwMenuClassInitialize ()
1174 XlwMenuRealize (w
, valueMask
, attributes
)
1177 XSetWindowAttributes
*attributes
;
1179 XlwMenuWidget mw
= (XlwMenuWidget
)w
;
1180 XSetWindowAttributes xswa
;
1183 (*xlwMenuWidgetClass
->core_class
.superclass
->core_class
.realize
)
1184 (w
, valueMask
, attributes
);
1186 xswa
.save_under
= True
;
1187 xswa
.cursor
= mw
->menu
.cursor_shape
;
1188 mask
= CWSaveUnder
| CWCursor
;
1189 XChangeWindowAttributes (XtDisplay (w
), XtWindow (w
), mask
, &xswa
);
1191 mw
->menu
.windows
[0].window
= XtWindow (w
);
1192 mw
->menu
.windows
[0].x
= w
->core
.x
;
1193 mw
->menu
.windows
[0].y
= w
->core
.y
;
1194 mw
->menu
.windows
[0].width
= w
->core
.width
;
1195 mw
->menu
.windows
[0].height
= w
->core
.height
;
1198 /* Only the toplevel menubar/popup is a widget so it's the only one that
1199 receives expose events through Xt. So we repaint all the other panes
1200 when receiving an Expose event. */
1202 XlwMenuRedisplay (w
, ev
, region
)
1207 XlwMenuWidget mw
= (XlwMenuWidget
)w
;
1210 /* If we have a depth beyond 1, it's because a submenu was displayed.
1211 If the submenu has been destroyed, set the depth back to 1. */
1212 if (submenu_destroyed
)
1214 mw
->menu
.old_depth
= 1;
1215 submenu_destroyed
= 0;
1218 for (i
= 0; i
< mw
->menu
.old_depth
; i
++)
1219 display_menu (mw
, i
, False
, NULL
, NULL
, NULL
, NULL
, NULL
);
1227 XlwMenuWidget mw
= (XlwMenuWidget
) w
;
1229 if (pointer_grabbed
)
1230 XtUngrabPointer ((Widget
)w
, CurrentTime
);
1231 pointer_grabbed
= 0;
1233 submenu_destroyed
= 1;
1235 release_drawing_gcs (mw
);
1236 release_shadow_gcs (mw
);
1238 /* this doesn't come from the resource db but is created explicitly
1239 so we must free it ourselves. */
1240 XFreePixmap (XtDisplay (mw
), mw
->menu
.gray_pixmap
);
1241 mw
->menu
.gray_pixmap
= (Pixmap
) -1;
1244 /* Do free mw->menu.contents because nowadays we copy it
1245 during initialization. */
1246 XtFree (mw
->menu
.contents
);
1249 /* Don't free mw->menu.contents because that comes from our creator.
1250 The `*_stack' elements are just pointers into `contents' so leave
1251 that alone too. But free the stacks themselves. */
1252 if (mw
->menu
.old_stack
) XtFree ((char *) mw
->menu
.old_stack
);
1253 if (mw
->menu
.new_stack
) XtFree ((char *) mw
->menu
.new_stack
);
1255 /* Remember, you can't free anything that came from the resource
1256 database. This includes:
1258 mw->menu.top_shadow_pixmap
1259 mw->menu.bottom_shadow_pixmap
1261 Also the color cells of top_shadow_color, bottom_shadow_color,
1262 foreground, and button_foreground will never be freed until this
1263 client exits. Nice, eh?
1266 /* start from 1 because the one in slot 0 is w->core.window */
1267 for (i
= 1; i
< mw
->menu
.windows_length
; i
++)
1268 XDestroyWindow (XtDisplay (mw
), mw
->menu
.windows
[i
].window
);
1269 if (mw
->menu
.windows
)
1270 XtFree ((char *) mw
->menu
.windows
);
1274 XlwMenuSetValues (current
, request
, new)
1279 XlwMenuWidget oldmw
= (XlwMenuWidget
)current
;
1280 XlwMenuWidget newmw
= (XlwMenuWidget
)new;
1281 Boolean redisplay
= False
;
1284 if (newmw
->menu
.contents
1285 && newmw
->menu
.contents
->contents
1286 && newmw
->menu
.contents
->contents
->change
>= VISIBLE_CHANGE
)
1288 /* Do redisplay if the contents are entirely eliminated. */
1289 if (newmw
->menu
.contents
1290 && newmw
->menu
.contents
->contents
== 0
1291 && newmw
->menu
.contents
->change
>= VISIBLE_CHANGE
)
1294 if (newmw
->core
.background_pixel
!= oldmw
->core
.background_pixel
1295 || newmw
->menu
.foreground
!= oldmw
->menu
.foreground
1296 || newmw
->menu
.font
!= oldmw
->menu
.font
)
1298 release_drawing_gcs (newmw
);
1299 make_drawing_gcs (newmw
);
1302 for (i
= 0; i
< oldmw
->menu
.windows_length
; i
++)
1304 XSetWindowBackground (XtDisplay (oldmw
),
1305 oldmw
->menu
.windows
[i
].window
,
1306 newmw
->core
.background_pixel
);
1307 /* clear windows and generate expose events */
1308 XClearArea (XtDisplay (oldmw
), oldmw
->menu
.windows
[i
].window
,
1320 XlwMenuWidget mw
= (XlwMenuWidget
)w
;
1322 if (mw
->menu
.popped_up
)
1324 /* Don't allow the popup menu to resize itself. */
1325 mw
->core
.width
= mw
->menu
.windows
[0].width
;
1326 mw
->core
.height
= mw
->menu
.windows
[0].height
;
1327 mw
->core
.parent
->core
.width
= mw
->core
.width
;
1328 mw
->core
.parent
->core
.height
= mw
->core
.height
;
1332 mw
->menu
.windows
[0].width
= mw
->core
.width
;
1333 mw
->menu
.windows
[0].height
= mw
->core
.height
;
1337 \f/* Action procedures */
1339 handle_single_motion_event (mw
, ev
)
1346 if (!map_event_to_widget_value (mw
, ev
, &val
, &level
))
1347 pop_new_stack_if_no_contents (mw
);
1349 set_new_state (mw
, val
, level
);
1352 /* Sync with the display. Makes it feel better on X terms. */
1353 XSync (XtDisplay (mw
), False
);
1357 handle_motion_event (mw
, ev
)
1363 int state
= ev
->state
;
1365 handle_single_motion_event (mw
, ev
);
1367 /* allow motion events to be generated again */
1369 && XQueryPointer (XtDisplay (mw
), ev
->window
,
1370 &ev
->root
, &ev
->subwindow
,
1371 &ev
->x_root
, &ev
->y_root
,
1374 && ev
->state
== state
1375 && (ev
->x_root
!= x
|| ev
->y_root
!= y
))
1376 handle_single_motion_event (mw
, ev
);
1380 Start (w
, ev
, params
, num_params
)
1384 Cardinal
*num_params
;
1386 XlwMenuWidget mw
= (XlwMenuWidget
)w
;
1388 if (!mw
->menu
.popped_up
)
1390 menu_post_event
= *ev
;
1391 pop_up_menu (mw
, ev
);
1395 /* If we push a button while the menu is posted semipermanently,
1396 releasing the button should always pop the menu down. */
1397 next_release_must_exit
= 1;
1399 /* notes the absolute position of the menubar window */
1400 mw
->menu
.windows
[0].x
= ev
->xmotion
.x_root
- ev
->xmotion
.x
;
1401 mw
->menu
.windows
[0].y
= ev
->xmotion
.y_root
- ev
->xmotion
.y
;
1403 /* handles the down like a move, slots are compatible */
1404 handle_motion_event (mw
, &ev
->xmotion
);
1409 Drag (w
, ev
, params
, num_params
)
1413 Cardinal
*num_params
;
1415 XlwMenuWidget mw
= (XlwMenuWidget
)w
;
1416 if (mw
->menu
.popped_up
)
1417 handle_motion_event (mw
, &ev
->xmotion
);
1421 This is how we handle presses and releases of modifier keys. */
1423 Nothing (w
, ev
, params
, num_params
)
1427 Cardinal
*num_params
;
1431 /* Handle key press and release events while menu is popped up.
1432 Our action is to get rid of the menu. */
1434 Key (w
, ev
, params
, num_params
)
1438 Cardinal
*num_params
;
1440 XlwMenuWidget mw
= (XlwMenuWidget
)w
;
1442 /* Pop down everything. */
1443 mw
->menu
.new_depth
= 1;
1446 if (mw
->menu
.popped_up
)
1448 mw
->menu
.popped_up
= False
;
1449 XtUngrabPointer ((Widget
)mw
, ev
->xmotion
.time
);
1450 if (XtIsShell (XtParent ((Widget
) mw
)))
1451 XtPopdown (XtParent ((Widget
) mw
));
1454 XtRemoveGrab ((Widget
) mw
);
1455 display_menu (mw
, 0, False
, NULL
, NULL
, NULL
, NULL
, NULL
);
1460 XtCallCallbackList ((Widget
)mw
, mw
->menu
.select
, (XtPointer
)0);
1464 Select (w
, ev
, params
, num_params
)
1468 Cardinal
*num_params
;
1470 XlwMenuWidget mw
= (XlwMenuWidget
)w
;
1471 widget_value
* selected_item
= mw
->menu
.old_stack
[mw
->menu
.old_depth
- 1];
1473 /* If user releases the button quickly, without selecting anything,
1474 after the initial down-click that brought the menu up,
1476 if ((selected_item
== 0
1477 || ((widget_value
*) selected_item
)->call_data
== 0)
1478 && !next_release_must_exit
1479 && (ev
->xbutton
.time
- menu_post_event
.xbutton
.time
1480 < XtGetMultiClickTime (XtDisplay (w
))))
1483 /* pop down everything. */
1484 mw
->menu
.new_depth
= 1;
1487 if (mw
->menu
.popped_up
)
1489 mw
->menu
.popped_up
= False
;
1490 XtUngrabPointer ((Widget
)mw
, ev
->xmotion
.time
);
1491 if (XtIsShell (XtParent ((Widget
) mw
)))
1492 XtPopdown (XtParent ((Widget
) mw
));
1495 XtRemoveGrab ((Widget
) mw
);
1496 display_menu (mw
, 0, False
, NULL
, NULL
, NULL
, NULL
, NULL
);
1501 XtCallCallbackList ((Widget
)mw
, mw
->menu
.select
, (XtPointer
)selected_item
);
1505 \f/* Special code to pop-up a menu */
1507 pop_up_menu (mw
, event
)
1509 XButtonPressedEvent
* event
;
1511 int x
= event
->x_root
;
1512 int y
= event
->y_root
;
1515 int borderwidth
= mw
->menu
.shadow_thickness
;
1516 Screen
* screen
= XtScreen (mw
);
1517 Display
*display
= XtDisplay (mw
);
1519 next_release_must_exit
= 0;
1521 XtCallCallbackList ((Widget
)mw
, mw
->menu
.open
, NULL
);
1523 if (XtIsShell (XtParent ((Widget
)mw
)))
1526 w
= mw
->menu
.windows
[0].width
;
1527 h
= mw
->menu
.windows
[0].height
;
1531 if (x
< borderwidth
)
1533 if (x
+ w
+ 2 * borderwidth
> WidthOfScreen (screen
))
1534 x
= WidthOfScreen (screen
) - w
- 2 * borderwidth
;
1535 if (y
< borderwidth
)
1537 if (y
+ h
+ 2 * borderwidth
> HeightOfScreen (screen
))
1538 y
= HeightOfScreen (screen
) - h
- 2 * borderwidth
;
1540 mw
->menu
.popped_up
= True
;
1541 if (XtIsShell (XtParent ((Widget
)mw
)))
1543 XtConfigureWidget (XtParent ((Widget
)mw
), x
, y
, w
, h
,
1544 XtParent ((Widget
)mw
)->core
.border_width
);
1545 XtPopup (XtParent ((Widget
)mw
), XtGrabExclusive
);
1546 display_menu (mw
, 0, False
, NULL
, NULL
, NULL
, NULL
, NULL
);
1547 mw
->menu
.windows
[0].x
= x
+ borderwidth
;
1548 mw
->menu
.windows
[0].y
= y
+ borderwidth
;
1552 XEvent
*ev
= (XEvent
*) event
;
1554 XtAddGrab ((Widget
) mw
, True
, True
);
1556 /* notes the absolute position of the menubar window */
1557 mw
->menu
.windows
[0].x
= ev
->xmotion
.x_root
- ev
->xmotion
.x
;
1558 mw
->menu
.windows
[0].y
= ev
->xmotion
.y_root
- ev
->xmotion
.y
;
1562 x_catch_errors (display
);
1564 XtGrabPointer ((Widget
)mw
, False
,
1566 | PointerMotionHintMask
1569 GrabModeAsync
, GrabModeAsync
, None
,
1570 mw
->menu
.cursor_shape
,
1572 pointer_grabbed
= 1;
1574 if (x_had_errors_p (display
))
1576 pointer_grabbed
= 0;
1577 XtUngrabPointer ((Widget
)mw
, event
->time
);
1579 x_uncatch_errors (display
);
1582 handle_motion_event (mw
, (XMotionEvent
*)event
);