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 "../src/lisp.h"
27 #include "lwlib-Xlw.h"
28 #include <X11/StringDefs.h>
29 #include <X11/IntrinsicP.h>
30 #include <X11/ObjectP.h>
31 #include <X11/CompositeP.h>
32 #include <X11/Shell.h>
39 /* Print the complete X resource name of widget WIDGET to stderr.
40 This is sometimes handy to have available. */
43 x_print_complete_resource_name (widget
)
49 for (i
= 0; i
< 100 && widget
!= NULL
; ++i
)
51 names
[i
] = XtName (widget
);
52 widget
= XtParent (widget
);
55 for (--i
; i
>= 1; --i
)
56 fprintf (stderr
, "%s.", names
[i
]);
57 fprintf (stderr
, "%s\n", names
[0]);
63 \f/* Menu callbacks */
65 /* Callback XtNhighlightCallback for Lucid menus. W is the menu
66 widget, CLIENT_DATA contains a pointer to the widget_instance
67 for the menu, CALL_DATA contains a pointer to the widget_value
68 structure for the highlighted menu item. The latter may be null
69 if there isn't any highlighted menu item. */
72 highlight_hook (w
, client_data
, call_data
)
74 XtPointer client_data
;
77 widget_instance
*instance
= (widget_instance
*) client_data
;
79 if (instance
->info
->highlight_cb
80 && !w
->core
.being_destroyed
)
81 instance
->info
->highlight_cb (w
, instance
->info
->id
, call_data
);
85 pre_hook (w
, client_data
, call_data
)
87 XtPointer client_data
;
90 widget_instance
* instance
= (widget_instance
*)client_data
;
93 if (w
->core
.being_destroyed
)
96 val
= lw_get_widget_value_for_widget (instance
, w
);
97 if (instance
->info
->pre_activate_cb
)
98 instance
->info
->pre_activate_cb (w
, instance
->info
->id
,
99 val
? val
->call_data
: NULL
);
103 pick_hook (w
, client_data
, call_data
)
105 XtPointer client_data
;
108 widget_instance
* instance
= (widget_instance
*)client_data
;
109 widget_value
* contents_val
= (widget_value
*)call_data
;
110 widget_value
* widget_val
;
111 XtPointer widget_arg
;
113 if (w
->core
.being_destroyed
)
116 if (instance
->info
->selection_cb
&& contents_val
&& contents_val
->enabled
117 && !contents_val
->contents
)
118 instance
->info
->selection_cb (w
, instance
->info
->id
,
119 contents_val
->call_data
);
121 widget_val
= lw_get_widget_value_for_widget (instance
, w
);
122 widget_arg
= widget_val
? widget_val
->call_data
: NULL
;
123 if (instance
->info
->post_activate_cb
)
124 instance
->info
->post_activate_cb (w
, instance
->info
->id
, widget_arg
);
128 \f/* creation functions */
131 xlw_create_menubar (instance
)
132 widget_instance
* instance
;
138 XtSetArg (al
[ac
], XtNmenu
, instance
->info
->val
); ac
++;
140 XtSetArg (al
[ac
], XtNshowGrip
, 0); ac
++;
141 XtSetArg (al
[ac
], XtNresizeToPreferred
, 1); ac
++;
142 XtSetArg (al
[ac
], XtNallowResize
, 1); ac
++;
145 /* This used to use XtVaCreateWidget, but an old Xt version
146 has a bug in XtVaCreateWidget that frees instance->info->name. */
148 = XtCreateWidget (instance
->info
->name
, xlwMenuWidgetClass
,
149 instance
->parent
, al
, ac
);
151 XtAddCallback (widget
, XtNopen
, pre_hook
, (XtPointer
)instance
);
152 XtAddCallback (widget
, XtNselect
, pick_hook
, (XtPointer
)instance
);
153 XtAddCallback (widget
, XtNhighlightCallback
, highlight_hook
,
154 (XtPointer
)instance
);
159 xlw_create_popup_menu (instance
)
160 widget_instance
* instance
;
163 = XtCreatePopupShell (instance
->info
->name
, overrideShellWidgetClass
,
164 instance
->parent
, NULL
, 0);
170 XtSetArg (al
[ac
], XtNmenu
, instance
->info
->val
); ac
++;
171 XtSetArg (al
[ac
], XtNhorizontal
, False
); ac
++;
173 /* This used to use XtVaManagedCreateWidget, but an old Xt version
174 has a bug in XtVaManagedCreateWidget that frees instance->info->name. */
176 = XtCreateManagedWidget ("popup", xlwMenuWidgetClass
,
177 popup_shell
, al
, ac
);
179 XtAddCallback (widget
, XtNselect
, pick_hook
, (XtPointer
)instance
);
180 XtAddCallback (widget
, XtNhighlightCallback
, highlight_hook
,
181 (XtPointer
)instance
);
185 widget_creation_entry
186 xlw_creation_table
[] =
188 {"menubar", xlw_create_menubar
},
189 {"popup", xlw_create_popup_menu
},
194 lw_lucid_widget_p (widget
)
197 WidgetClass the_class
= XtClass (widget
);
199 if (the_class
== xlwMenuWidgetClass
)
201 if (the_class
== overrideShellWidgetClass
)
202 return (XtClass (((CompositeWidget
)widget
)->composite
.children
[0])
203 == xlwMenuWidgetClass
);
208 xlw_update_one_widget (instance
, widget
, val
, deep_p
)
209 widget_instance
* instance
;
217 if (XtIsShell (widget
))
218 mw
= (XlwMenuWidget
)((CompositeWidget
)widget
)->composite
.children
[0];
220 mw
= (XlwMenuWidget
)widget
;
222 /* This used to use XtVaSetValues, but some old Xt versions
223 that have a bug in XtVaCreateWidget might have it here too. */
224 XtSetArg (al
[0], XtNmenu
, instance
->info
->val
);
226 XtSetValues (widget
, al
, 1);
230 xlw_update_one_value (instance
, widget
, val
)
231 widget_instance
* instance
;
239 xlw_pop_instance (instance
, up
)
240 widget_instance
* instance
;
246 xlw_popup_menu (widget
, event
)
250 XButtonPressedEvent dummy
;
253 if (!XtIsShell (widget
))
256 mw
= (XlwMenuWidget
)((CompositeWidget
)widget
)->composite
.children
[0];
259 pop_up_menu (mw
, (XButtonPressedEvent
*) event
);
262 dummy
.type
= ButtonPress
;
264 dummy
.send_event
= 0;
265 dummy
.display
= XtDisplay (widget
);
266 dummy
.window
= XtWindow (XtParent (widget
));
267 dummy
.time
= CurrentTime
;
269 XQueryPointer (dummy
.display
, dummy
.window
, &dummy
.root
,
270 &dummy
.subwindow
, &dummy
.x_root
, &dummy
.y_root
,
271 &dummy
.x
, &dummy
.y
, &dummy
.state
);
273 pop_up_menu (mw
, &dummy
);
277 \f/* Destruction of instances */
279 xlw_destroy_instance (instance
)
280 widget_instance
* instance
;
282 if (instance
->widget
)
283 XtDestroyWidget (instance
->widget
);