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, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
25 #include "lwlib-Xlw.h"
26 #include <X11/StringDefs.h>
27 #include <X11/IntrinsicP.h>
28 #include <X11/ObjectP.h>
29 #include <X11/CompositeP.h>
30 #include <X11/Shell.h>
33 \f/* Menu callbacks */
35 pre_hook (w
, client_data
, call_data
)
37 XtPointer client_data
;
40 widget_instance
* instance
= (widget_instance
*)client_data
;
43 if (w
->core
.being_destroyed
)
46 val
= lw_get_widget_value_for_widget (instance
, w
);
47 if (instance
->info
->pre_activate_cb
)
48 instance
->info
->pre_activate_cb (w
, instance
->info
->id
,
49 val
? val
->call_data
: NULL
);
53 pick_hook (w
, client_data
, call_data
)
55 XtPointer client_data
;
58 widget_instance
* instance
= (widget_instance
*)client_data
;
59 widget_value
* contents_val
= (widget_value
*)call_data
;
60 widget_value
* widget_val
;
63 if (w
->core
.being_destroyed
)
66 if (instance
->info
->selection_cb
&& contents_val
&& contents_val
->enabled
67 && !contents_val
->contents
)
68 instance
->info
->selection_cb (w
, instance
->info
->id
,
69 contents_val
->call_data
);
71 widget_val
= lw_get_widget_value_for_widget (instance
, w
);
72 widget_arg
= widget_val
? widget_val
->call_data
: NULL
;
73 if (instance
->info
->post_activate_cb
)
74 instance
->info
->post_activate_cb (w
, instance
->info
->id
, widget_arg
);
78 \f/* creation functions */
81 xlw_create_menubar (instance
)
82 widget_instance
* instance
;
88 XtSetArg (al
[ac
], XtNmenu
, instance
->info
->val
); ac
++;
90 XtSetArg (al
[ac
], XtNshowGrip
, 0); ac
++;
91 XtSetArg (al
[ac
], XtNresizeToPreferred
, 1); ac
++;
92 XtSetArg (al
[ac
], XtNallowResize
, 1); ac
++;
95 /* This used to use XtVaCreateWidget, but an old Xt version
96 has a bug in XtVaCreateWidget that frees instance->info->name. */
98 = XtCreateWidget (instance
->info
->name
, xlwMenuWidgetClass
,
99 instance
->parent
, al
, ac
);
101 XtAddCallback (widget
, XtNopen
, pre_hook
, (XtPointer
)instance
);
102 XtAddCallback (widget
, XtNselect
, pick_hook
, (XtPointer
)instance
);
107 xlw_create_popup_menu (instance
)
108 widget_instance
* instance
;
111 = XtCreatePopupShell (instance
->info
->name
, overrideShellWidgetClass
,
112 instance
->parent
, NULL
, 0);
118 XtSetArg (al
[ac
], XtNmenu
, instance
->info
->val
); ac
++;
119 XtSetArg (al
[ac
], XtNhorizontal
, False
); ac
++;
121 /* This used to use XtVaManagedCreateWidget, but an old Xt version
122 has a bug in XtVaManagedCreateWidget that frees instance->info->name. */
124 = XtCreateManagedWidget ("popup", xlwMenuWidgetClass
,
125 popup_shell
, al
, ac
);
127 XtAddCallback (widget
, XtNselect
, pick_hook
, (XtPointer
)instance
);
132 widget_creation_entry
133 xlw_creation_table
[] =
135 {"menubar", xlw_create_menubar
},
136 {"popup", xlw_create_popup_menu
},
141 lw_lucid_widget_p (widget
)
144 WidgetClass the_class
= XtClass (widget
);
146 if (the_class
== xlwMenuWidgetClass
)
148 if (the_class
== overrideShellWidgetClass
)
149 return (XtClass (((CompositeWidget
)widget
)->composite
.children
[0])
150 == xlwMenuWidgetClass
);
155 xlw_update_one_widget (instance
, widget
, val
, deep_p
)
156 widget_instance
* instance
;
164 if (XtIsShell (widget
))
165 mw
= (XlwMenuWidget
)((CompositeWidget
)widget
)->composite
.children
[0];
167 mw
= (XlwMenuWidget
)widget
;
169 /* This used to use XtVaSetValues, but some old Xt versions
170 that have a bug in XtVaCreateWidget might have it here too. */
171 XtSetArg (al
[0], XtNmenu
, instance
->info
->val
);
173 XtSetValues (widget
, al
, 1);
177 xlw_update_one_value (instance
, widget
, val
)
178 widget_instance
* instance
;
186 xlw_pop_instance (instance
, up
)
187 widget_instance
* instance
;
193 xlw_popup_menu (widget
, event
)
197 XButtonPressedEvent dummy
;
200 if (!XtIsShell (widget
))
203 mw
= (XlwMenuWidget
)((CompositeWidget
)widget
)->composite
.children
[0];
206 pop_up_menu (mw
, event
);
209 dummy
.type
= ButtonPress
;
211 dummy
.send_event
= 0;
212 dummy
.display
= XtDisplay (widget
);
213 dummy
.window
= XtWindow (XtParent (widget
));
214 dummy
.time
= CurrentTime
;
216 XQueryPointer (dummy
.display
, dummy
.window
, &dummy
.root
,
217 &dummy
.subwindow
, &dummy
.x_root
, &dummy
.y_root
,
218 &dummy
.x
, &dummy
.y
, &dummy
.state
);
220 pop_up_menu (mw
, &dummy
);
224 \f/* Destruction of instances */
226 xlw_destroy_instance (instance
)
227 widget_instance
* instance
;
229 if (instance
->widget
)
230 XtDestroyWidget (instance
->widget
);