1 /* The lwlib interface to "xlwmenu" menus.
2 Copyright (C) 1992 Lucid, Inc.
3 Copyright (C) 1994, 2000-2011 Free Software Foundation, Inc.
5 This file is part of the Lucid Widget Library.
7 The Lucid Widget Library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 1, or (at your option)
12 The Lucid Widget Library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 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 widget
)
50 for (i
= 0; i
< 100 && widget
!= NULL
; ++i
)
52 names
[i
] = XtName (widget
);
53 widget
= XtParent (widget
);
56 for (--i
; i
>= 1; --i
)
57 fprintf (stderr
, "%s.", names
[i
]);
58 fprintf (stderr
, "%s\n", names
[0]);
64 \f/* Menu callbacks */
66 /* Callback XtNhighlightCallback for Lucid menus. W is the menu
67 widget, CLIENT_DATA contains a pointer to the widget_instance
68 for the menu, CALL_DATA contains a pointer to the widget_value
69 structure for the highlighted menu item. The latter may be null
70 if there isn't any highlighted menu item. */
73 highlight_hook (Widget w
, XtPointer client_data
, XtPointer call_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 enter_hook (Widget w
, XtPointer client_data
, XtPointer call_data
)
85 highlight_hook (w
, client_data
, call_data
);
89 leave_hook (Widget w
, XtPointer client_data
, XtPointer call_data
)
91 highlight_hook (w
, client_data
, NULL
);
96 pre_hook (Widget w
, XtPointer client_data
, XtPointer call_data
)
98 widget_instance
* instance
= (widget_instance
*)client_data
;
101 if (w
->core
.being_destroyed
)
104 val
= lw_get_widget_value_for_widget (instance
, w
);
105 if (instance
->info
->pre_activate_cb
)
106 instance
->info
->pre_activate_cb (w
, instance
->info
->id
,
107 val
? val
->call_data
: NULL
);
111 pick_hook (Widget w
, XtPointer client_data
, XtPointer call_data
)
113 widget_instance
* instance
= (widget_instance
*)client_data
;
114 widget_value
* contents_val
= (widget_value
*)call_data
;
115 widget_value
* widget_val
;
116 XtPointer widget_arg
;
118 if (w
->core
.being_destroyed
)
121 if (instance
->info
->selection_cb
&& contents_val
&& contents_val
->enabled
122 && !contents_val
->contents
)
123 instance
->info
->selection_cb (w
, instance
->info
->id
,
124 contents_val
->call_data
);
126 widget_val
= lw_get_widget_value_for_widget (instance
, w
);
127 widget_arg
= widget_val
? widget_val
->call_data
: NULL
;
128 if (instance
->info
->post_activate_cb
)
129 instance
->info
->post_activate_cb (w
, instance
->info
->id
, widget_arg
);
133 \f/* creation functions */
136 xlw_create_menubar (widget_instance
*instance
)
142 XtSetArg (al
[ac
], XtNmenu
, instance
->info
->val
); ac
++;
144 XtSetArg (al
[ac
], XtNshowGrip
, 0); ac
++;
145 XtSetArg (al
[ac
], XtNresizeToPreferred
, 1); ac
++;
146 XtSetArg (al
[ac
], XtNallowResize
, 1); ac
++;
149 /* This used to use XtVaCreateWidget, but an old Xt version
150 has a bug in XtVaCreateWidget that frees instance->info->name. */
152 = XtCreateWidget (instance
->info
->name
, xlwMenuWidgetClass
,
153 instance
->parent
, al
, ac
);
155 XtAddCallback (widget
, XtNopen
, pre_hook
, (XtPointer
)instance
);
156 XtAddCallback (widget
, XtNselect
, pick_hook
, (XtPointer
)instance
);
157 XtAddCallback (widget
, XtNleaveCallback
, leave_hook
, (XtPointer
)instance
);
158 XtAddCallback (widget
, XtNenterCallback
, enter_hook
, (XtPointer
)instance
);
163 xlw_create_popup_menu (widget_instance
*instance
)
166 = XtCreatePopupShell (instance
->info
->name
, overrideShellWidgetClass
,
167 instance
->parent
, NULL
, 0);
173 XtSetArg (al
[ac
], XtNmenu
, instance
->info
->val
); ac
++;
174 XtSetArg (al
[ac
], XtNhorizontal
, False
); ac
++;
176 /* This used to use XtVaManagedCreateWidget, but an old Xt version
177 has a bug in XtVaManagedCreateWidget that frees instance->info->name. */
179 = XtCreateManagedWidget ("popup", xlwMenuWidgetClass
,
180 popup_shell
, al
, ac
);
182 XtAddCallback (widget
, XtNselect
, pick_hook
, (XtPointer
)instance
);
183 XtAddCallback (widget
, XtNleaveCallback
, leave_hook
, (XtPointer
)instance
);
184 XtAddCallback (widget
, XtNenterCallback
, enter_hook
, (XtPointer
)instance
);
189 widget_creation_entry
190 xlw_creation_table
[] =
192 {"menubar", xlw_create_menubar
},
193 {"popup", xlw_create_popup_menu
},
198 lw_lucid_widget_p (Widget 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
);
211 xlw_update_one_widget (widget_instance
* instance
, Widget widget
,
212 widget_value
* val
, Boolean deep_p
)
216 /* This used to use XtVaSetValues, but some old Xt versions
217 that have a bug in XtVaCreateWidget might have it here too. */
218 XtSetArg (al
[0], XtNmenu
, instance
->info
->val
);
220 XtSetValues (widget
, al
, 1);
224 xlw_update_one_value (widget_instance
*instance
,
232 xlw_pop_instance (widget_instance
* instance
, Boolean up
)
237 xlw_popup_menu (Widget widget
, XEvent
*event
)
241 if (!XtIsShell (widget
))
244 mw
= (XlwMenuWidget
)((CompositeWidget
)widget
)->composite
.children
[0];
247 XtCallActionProc ((Widget
) mw
, "start", event
, NULL
, 0);
251 XButtonPressedEvent
*bd
= &dummy
.xbutton
;
253 bd
->type
= ButtonPress
;
256 bd
->display
= XtDisplay (widget
);
257 bd
->window
= XtWindow (XtParent (widget
));
258 bd
->time
= CurrentTime
;
260 XQueryPointer (bd
->display
, bd
->window
, &bd
->root
,
261 &bd
->subwindow
, &bd
->x_root
, &bd
->y_root
,
262 &bd
->x
, &bd
->y
, &bd
->state
);
264 XtCallActionProc ((Widget
) mw
, "start", &dummy
, NULL
, 0);
268 \f/* Destruction of instances */
270 xlw_destroy_instance (widget_instance
*instance
)
272 if (instance
->widget
)
273 XtDestroyWidget (instance
->widget
);