1 /* The lwlib interface to "xlwmenu" menus.
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 1, 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 along with GNU Emacs; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
20 #include "lwlib-Xlw.h"
21 #include <X11/StringDefs.h>
22 #include <X11/IntrinsicP.h>
23 #include <X11/ObjectP.h>
24 #include <X11/CompositeP.h>
25 #include <X11/Shell.h>
28 \f/* Menu callbacks */
30 pre_hook (Widget w
, XtPointer client_data
, XtPointer call_data
)
32 widget_instance
* instance
= (widget_instance
*)client_data
;
35 if (w
->core
.being_destroyed
)
38 val
= lw_get_widget_value_for_widget (instance
, w
);
39 if (instance
->info
->pre_activate_cb
)
40 instance
->info
->pre_activate_cb (w
, instance
->info
->id
,
41 val
? val
->call_data
: NULL
);
45 pick_hook (Widget w
, XtPointer client_data
, XtPointer call_data
)
47 widget_instance
* instance
= (widget_instance
*)client_data
;
48 widget_value
* contents_val
= (widget_value
*)call_data
;
49 widget_value
* widget_val
;
52 if (w
->core
.being_destroyed
)
55 if (instance
->info
->selection_cb
&& contents_val
&& contents_val
->enabled
56 && !contents_val
->contents
)
57 instance
->info
->selection_cb (w
, instance
->info
->id
,
58 contents_val
->call_data
);
60 widget_val
= lw_get_widget_value_for_widget (instance
, w
);
61 widget_arg
= widget_val
? widget_val
->call_data
: NULL
;
62 if (instance
->info
->post_activate_cb
)
63 instance
->info
->post_activate_cb (w
, instance
->info
->id
, widget_arg
);
67 \f/* creation functions */
69 xlw_create_menubar (widget_instance
* instance
)
72 XtVaCreateWidget (instance
->info
->name
, xlwMenuWidgetClass
,
74 XtNmenu
, instance
->info
->val
,
76 XtAddCallback (widget
, XtNopen
, pre_hook
, (XtPointer
)instance
);
77 XtAddCallback (widget
, XtNselect
, pick_hook
, (XtPointer
)instance
);
82 xlw_create_popup_menu (widget_instance
* instance
)
85 XtCreatePopupShell (instance
->info
->name
, overrideShellWidgetClass
,
86 instance
->parent
, NULL
, 0);
89 XtVaCreateManagedWidget ("popup", xlwMenuWidgetClass
,
91 XtNmenu
, instance
->info
->val
,
95 XtAddCallback (widget
, XtNselect
, pick_hook
, (XtPointer
)instance
);
100 widget_creation_entry
101 xlw_creation_table
[] =
103 {"menubar", xlw_create_menubar
},
104 {"popup", xlw_create_popup_menu
},
109 lw_lucid_widget_p (Widget widget
)
111 WidgetClass the_class
= XtClass (widget
);
112 if (the_class
== xlwMenuWidgetClass
)
114 if (the_class
== overrideShellWidgetClass
)
116 XtClass (((CompositeWidget
)widget
)->composite
.children
[0])
117 == xlwMenuWidgetClass
;
122 xlw_update_one_widget (widget_instance
* instance
, Widget widget
,
123 widget_value
* val
, Boolean deep_p
)
127 if (XtIsShell (widget
))
128 mw
= (XlwMenuWidget
)((CompositeWidget
)widget
)->composite
.children
[0];
130 mw
= (XlwMenuWidget
)widget
;
131 XtVaSetValues (widget
, XtNmenu
, val
, 0);
135 xlw_update_one_value (widget_instance
* instance
, Widget widget
,
142 xlw_pop_instance (widget_instance
* instance
, Boolean up
)
147 xlw_popup_menu (Widget widget
)
149 XButtonPressedEvent dummy
;
152 if (!XtIsShell (widget
))
155 mw
= (XlwMenuWidget
)((CompositeWidget
)widget
)->composite
.children
[0];
157 dummy
.type
= ButtonPress
;
159 dummy
.send_event
= 0;
160 dummy
.display
= XtDisplay (widget
);
161 dummy
.window
= XtWindow (XtParent (widget
));
162 dummy
.time
= CurrentTime
;
164 XQueryPointer (dummy
.display
, dummy
.window
, &dummy
.root
,
165 &dummy
.subwindow
, &dummy
.x_root
, &dummy
.y_root
,
166 &dummy
.x
, &dummy
.y
, &dummy
.state
);
168 pop_up_menu (mw
, &dummy
);
171 \f/* Destruction of instances */
173 xlw_destroy_instance (widget_instance
* instance
)
175 if (instance
->widget
)
176 XtDestroyWidget (instance
->widget
);