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>
37 /* Print the complete X resource name of widget WIDGET to stderr.
38 This is sometimes handy to have available. */
41 x_print_complete_resource_name (widget
)
47 for (i
= 0; i
< 100 && widget
!= NULL
; ++i
)
49 names
[i
] = XtName (widget
);
50 widget
= XtParent (widget
);
53 for (--i
; i
>= 1; --i
)
54 fprintf (stderr
, "%s.", names
[i
]);
55 fprintf (stderr
, "%s\n", names
[0]);
61 \f/* Menu callbacks */
63 /* Callback XtNhighlightCallback for Lucid menus. W is the menu
64 widget, CLIENT_DATA contains a pointer to the widget_instance
65 for the menu, CALL_DATA contains a pointer to the widget_value
66 structure for the highlighted menu item. The latter may be null
67 if there isn't any highlighted menu item. */
70 highlight_hook (w
, client_data
, call_data
)
72 XtPointer client_data
;
75 widget_instance
*instance
= (widget_instance
*) client_data
;
77 if (instance
->info
->highlight_cb
78 && !w
->core
.being_destroyed
)
79 instance
->info
->highlight_cb (w
, instance
->info
->id
, call_data
);
83 pre_hook (w
, client_data
, call_data
)
85 XtPointer client_data
;
88 widget_instance
* instance
= (widget_instance
*)client_data
;
91 if (w
->core
.being_destroyed
)
94 val
= lw_get_widget_value_for_widget (instance
, w
);
95 if (instance
->info
->pre_activate_cb
)
96 instance
->info
->pre_activate_cb (w
, instance
->info
->id
,
97 val
? val
->call_data
: NULL
);
101 pick_hook (w
, client_data
, call_data
)
103 XtPointer client_data
;
106 widget_instance
* instance
= (widget_instance
*)client_data
;
107 widget_value
* contents_val
= (widget_value
*)call_data
;
108 widget_value
* widget_val
;
109 XtPointer widget_arg
;
111 if (w
->core
.being_destroyed
)
114 if (instance
->info
->selection_cb
&& contents_val
&& contents_val
->enabled
115 && !contents_val
->contents
)
116 instance
->info
->selection_cb (w
, instance
->info
->id
,
117 contents_val
->call_data
);
119 widget_val
= lw_get_widget_value_for_widget (instance
, w
);
120 widget_arg
= widget_val
? widget_val
->call_data
: NULL
;
121 if (instance
->info
->post_activate_cb
)
122 instance
->info
->post_activate_cb (w
, instance
->info
->id
, widget_arg
);
126 \f/* creation functions */
129 xlw_create_menubar (instance
)
130 widget_instance
* instance
;
136 XtSetArg (al
[ac
], XtNmenu
, instance
->info
->val
); ac
++;
138 XtSetArg (al
[ac
], XtNshowGrip
, 0); ac
++;
139 XtSetArg (al
[ac
], XtNresizeToPreferred
, 1); ac
++;
140 XtSetArg (al
[ac
], XtNallowResize
, 1); ac
++;
143 /* This used to use XtVaCreateWidget, but an old Xt version
144 has a bug in XtVaCreateWidget that frees instance->info->name. */
146 = XtCreateWidget (instance
->info
->name
, xlwMenuWidgetClass
,
147 instance
->parent
, al
, ac
);
149 XtAddCallback (widget
, XtNopen
, pre_hook
, (XtPointer
)instance
);
150 XtAddCallback (widget
, XtNselect
, pick_hook
, (XtPointer
)instance
);
151 XtAddCallback (widget
, XtNhighlightCallback
, highlight_hook
,
152 (XtPointer
)instance
);
157 xlw_create_popup_menu (instance
)
158 widget_instance
* instance
;
161 = XtCreatePopupShell (instance
->info
->name
, overrideShellWidgetClass
,
162 instance
->parent
, NULL
, 0);
168 XtSetArg (al
[ac
], XtNmenu
, instance
->info
->val
); ac
++;
169 XtSetArg (al
[ac
], XtNhorizontal
, False
); ac
++;
171 /* This used to use XtVaManagedCreateWidget, but an old Xt version
172 has a bug in XtVaManagedCreateWidget that frees instance->info->name. */
174 = XtCreateManagedWidget ("popup", xlwMenuWidgetClass
,
175 popup_shell
, al
, ac
);
177 XtAddCallback (widget
, XtNselect
, pick_hook
, (XtPointer
)instance
);
178 XtAddCallback (widget
, XtNhighlightCallback
, highlight_hook
,
179 (XtPointer
)instance
);
183 widget_creation_entry
184 xlw_creation_table
[] =
186 {"menubar", xlw_create_menubar
},
187 {"popup", xlw_create_popup_menu
},
192 lw_lucid_widget_p (widget
)
195 WidgetClass the_class
= XtClass (widget
);
197 if (the_class
== xlwMenuWidgetClass
)
199 if (the_class
== overrideShellWidgetClass
)
200 return (XtClass (((CompositeWidget
)widget
)->composite
.children
[0])
201 == xlwMenuWidgetClass
);
206 xlw_update_one_widget (instance
, widget
, val
, deep_p
)
207 widget_instance
* instance
;
215 if (XtIsShell (widget
))
216 mw
= (XlwMenuWidget
)((CompositeWidget
)widget
)->composite
.children
[0];
218 mw
= (XlwMenuWidget
)widget
;
220 /* This used to use XtVaSetValues, but some old Xt versions
221 that have a bug in XtVaCreateWidget might have it here too. */
222 XtSetArg (al
[0], XtNmenu
, instance
->info
->val
);
224 XtSetValues (widget
, al
, 1);
228 xlw_update_one_value (instance
, widget
, val
)
229 widget_instance
* instance
;
237 xlw_pop_instance (instance
, up
)
238 widget_instance
* instance
;
244 xlw_popup_menu (widget
, event
)
248 XButtonPressedEvent dummy
;
251 if (!XtIsShell (widget
))
254 mw
= (XlwMenuWidget
)((CompositeWidget
)widget
)->composite
.children
[0];
257 pop_up_menu (mw
, (XButtonPressedEvent
*) event
);
260 dummy
.type
= ButtonPress
;
262 dummy
.send_event
= 0;
263 dummy
.display
= XtDisplay (widget
);
264 dummy
.window
= XtWindow (XtParent (widget
));
265 dummy
.time
= CurrentTime
;
267 XQueryPointer (dummy
.display
, dummy
.window
, &dummy
.root
,
268 &dummy
.subwindow
, &dummy
.x_root
, &dummy
.y_root
,
269 &dummy
.x
, &dummy
.y
, &dummy
.state
);
271 pop_up_menu (mw
, &dummy
);
275 \f/* Destruction of instances */
277 xlw_destroy_instance (instance
)
278 widget_instance
* instance
;
280 if (instance
->widget
)
281 XtDestroyWidget (instance
->widget
);