1 /* The lwlib interface to "xlwmenu" menus.
2 Copyright (C) 1992 Lucid, Inc.
3 Copyright (C) 1994, 2000, 2001, 2002, 2003, 2004,
4 2005 Free Software Foundation, Inc.
6 This file is part of the Lucid Widget Library.
8 The Lucid Widget Library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 1, or (at your option)
13 The Lucid Widget Library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs; see the file COPYING. If not, write to
20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
29 #include "lwlib-Xlw.h"
30 #include <X11/StringDefs.h>
31 #include <X11/IntrinsicP.h>
32 #include <X11/ObjectP.h>
33 #include <X11/CompositeP.h>
34 #include <X11/Shell.h>
41 /* Print the complete X resource name of widget WIDGET to stderr.
42 This is sometimes handy to have available. */
45 x_print_complete_resource_name (widget
)
51 for (i
= 0; i
< 100 && widget
!= NULL
; ++i
)
53 names
[i
] = XtName (widget
);
54 widget
= XtParent (widget
);
57 for (--i
; i
>= 1; --i
)
58 fprintf (stderr
, "%s.", names
[i
]);
59 fprintf (stderr
, "%s\n", names
[0]);
65 \f/* Menu callbacks */
67 /* Callback XtNhighlightCallback for Lucid menus. W is the menu
68 widget, CLIENT_DATA contains a pointer to the widget_instance
69 for the menu, CALL_DATA contains a pointer to the widget_value
70 structure for the highlighted menu item. The latter may be null
71 if there isn't any highlighted menu item. */
74 highlight_hook (w
, client_data
, call_data
)
76 XtPointer client_data
;
79 widget_instance
*instance
= (widget_instance
*) client_data
;
81 if (instance
->info
->highlight_cb
82 && !w
->core
.being_destroyed
)
83 instance
->info
->highlight_cb (w
, instance
->info
->id
, call_data
);
87 pre_hook (w
, client_data
, call_data
)
89 XtPointer client_data
;
92 widget_instance
* instance
= (widget_instance
*)client_data
;
95 if (w
->core
.being_destroyed
)
98 val
= lw_get_widget_value_for_widget (instance
, w
);
99 if (instance
->info
->pre_activate_cb
)
100 instance
->info
->pre_activate_cb (w
, instance
->info
->id
,
101 val
? val
->call_data
: NULL
);
105 pick_hook (w
, client_data
, call_data
)
107 XtPointer client_data
;
110 widget_instance
* instance
= (widget_instance
*)client_data
;
111 widget_value
* contents_val
= (widget_value
*)call_data
;
112 widget_value
* widget_val
;
113 XtPointer widget_arg
;
115 if (w
->core
.being_destroyed
)
118 if (instance
->info
->selection_cb
&& contents_val
&& contents_val
->enabled
119 && !contents_val
->contents
)
120 instance
->info
->selection_cb (w
, instance
->info
->id
,
121 contents_val
->call_data
);
123 widget_val
= lw_get_widget_value_for_widget (instance
, w
);
124 widget_arg
= widget_val
? widget_val
->call_data
: NULL
;
125 if (instance
->info
->post_activate_cb
)
126 instance
->info
->post_activate_cb (w
, instance
->info
->id
, widget_arg
);
130 \f/* creation functions */
133 xlw_create_menubar (instance
)
134 widget_instance
* instance
;
140 XtSetArg (al
[ac
], XtNmenu
, instance
->info
->val
); ac
++;
142 XtSetArg (al
[ac
], XtNshowGrip
, 0); ac
++;
143 XtSetArg (al
[ac
], XtNresizeToPreferred
, 1); ac
++;
144 XtSetArg (al
[ac
], XtNallowResize
, 1); ac
++;
147 /* This used to use XtVaCreateWidget, but an old Xt version
148 has a bug in XtVaCreateWidget that frees instance->info->name. */
150 = XtCreateWidget (instance
->info
->name
, xlwMenuWidgetClass
,
151 instance
->parent
, al
, ac
);
153 XtAddCallback (widget
, XtNopen
, pre_hook
, (XtPointer
)instance
);
154 XtAddCallback (widget
, XtNselect
, pick_hook
, (XtPointer
)instance
);
155 XtAddCallback (widget
, XtNhighlightCallback
, highlight_hook
,
156 (XtPointer
)instance
);
161 xlw_create_popup_menu (instance
)
162 widget_instance
* instance
;
165 = XtCreatePopupShell (instance
->info
->name
, overrideShellWidgetClass
,
166 instance
->parent
, NULL
, 0);
172 XtSetArg (al
[ac
], XtNmenu
, instance
->info
->val
); ac
++;
173 XtSetArg (al
[ac
], XtNhorizontal
, False
); ac
++;
175 /* This used to use XtVaManagedCreateWidget, but an old Xt version
176 has a bug in XtVaManagedCreateWidget that frees instance->info->name. */
178 = XtCreateManagedWidget ("popup", xlwMenuWidgetClass
,
179 popup_shell
, al
, ac
);
181 XtAddCallback (widget
, XtNselect
, pick_hook
, (XtPointer
)instance
);
182 XtAddCallback (widget
, XtNhighlightCallback
, highlight_hook
,
183 (XtPointer
)instance
);
188 widget_creation_entry
189 xlw_creation_table
[] =
191 {"menubar", xlw_create_menubar
},
192 {"popup", xlw_create_popup_menu
},
197 lw_lucid_widget_p (widget
)
200 WidgetClass the_class
= XtClass (widget
);
202 if (the_class
== xlwMenuWidgetClass
)
204 if (the_class
== overrideShellWidgetClass
)
205 return (XtClass (((CompositeWidget
)widget
)->composite
.children
[0])
206 == xlwMenuWidgetClass
);
212 xlw_update_one_widget (widget_instance
* instance
, Widget widget
,
213 widget_value
* val
, Boolean deep_p
)
215 xlw_update_one_widget (instance
, widget
, val
, deep_p
)
216 widget_instance
* instance
;
224 /* This used to use XtVaSetValues, but some old Xt versions
225 that have a bug in XtVaCreateWidget might have it here too. */
226 XtSetArg (al
[0], XtNmenu
, instance
->info
->val
);
228 XtSetValues (widget
, al
, 1);
232 xlw_update_one_value (instance
, widget
, val
)
233 widget_instance
* instance
;
242 xlw_pop_instance (widget_instance
* instance
, Boolean up
)
244 xlw_pop_instance (instance
, up
)
245 widget_instance
* instance
;
252 xlw_popup_menu (widget
, event
)
258 if (!XtIsShell (widget
))
261 mw
= (XlwMenuWidget
)((CompositeWidget
)widget
)->composite
.children
[0];
264 XtCallActionProc ((Widget
) mw
, "start", event
, NULL
, 0);
268 XButtonPressedEvent
*bd
= &dummy
.xbutton
;
270 bd
->type
= ButtonPress
;
273 bd
->display
= XtDisplay (widget
);
274 bd
->window
= XtWindow (XtParent (widget
));
275 bd
->time
= CurrentTime
;
277 XQueryPointer (bd
->display
, bd
->window
, &bd
->root
,
278 &bd
->subwindow
, &bd
->x_root
, &bd
->y_root
,
279 &bd
->x
, &bd
->y
, &bd
->state
);
281 XtCallActionProc ((Widget
) mw
, "start", &dummy
, NULL
, 0);
285 \f/* Destruction of instances */
287 xlw_destroy_instance (instance
)
288 widget_instance
* instance
;
290 if (instance
->widget
)
291 XtDestroyWidget (instance
->widget
);
294 /* arch-tag: 541e3912-477d-406e-9bf2-dbf2b7ff8c3b
295 (do not change this comment) */