1 /* The lwlib interface to "xlwmenu" menus.
3 Copyright (C) 1992 Lucid, Inc.
4 Copyright (C) 1994, 2000-2012 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. */
28 #include "lwlib-Xlw.h"
29 #include <X11/StringDefs.h>
30 #include <X11/IntrinsicP.h>
31 #include <X11/ObjectP.h>
32 #include <X11/CompositeP.h>
33 #include <X11/Shell.h>
40 /* Print the complete X resource name of widget WIDGET to stderr.
41 This is sometimes handy to have available. */
44 x_print_complete_resource_name (Widget 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 (Widget w
, XtPointer client_data
, XtPointer call_data
)
74 widget_instance
*instance
= (widget_instance
*) client_data
;
76 if (instance
->info
->highlight_cb
77 && !w
->core
.being_destroyed
)
78 instance
->info
->highlight_cb (w
, instance
->info
->id
, call_data
);
82 enter_hook (Widget w
, XtPointer client_data
, XtPointer call_data
)
84 highlight_hook (w
, client_data
, call_data
);
88 leave_hook (Widget w
, XtPointer client_data
, XtPointer call_data
)
90 highlight_hook (w
, client_data
, NULL
);
95 pre_hook (Widget w
, XtPointer client_data
, XtPointer call_data
)
97 widget_instance
* instance
= (widget_instance
*)client_data
;
100 if (w
->core
.being_destroyed
)
103 val
= lw_get_widget_value_for_widget (instance
, w
);
104 if (instance
->info
->pre_activate_cb
)
105 instance
->info
->pre_activate_cb (w
, instance
->info
->id
,
106 val
? val
->call_data
: NULL
);
110 pick_hook (Widget w
, XtPointer client_data
, XtPointer call_data
)
112 widget_instance
* instance
= (widget_instance
*)client_data
;
113 widget_value
* contents_val
= (widget_value
*)call_data
;
114 widget_value
* widget_val
;
115 XtPointer widget_arg
;
117 if (w
->core
.being_destroyed
)
120 if (instance
->info
->selection_cb
&& contents_val
&& contents_val
->enabled
121 && !contents_val
->contents
)
122 instance
->info
->selection_cb (w
, instance
->info
->id
,
123 contents_val
->call_data
);
125 widget_val
= lw_get_widget_value_for_widget (instance
, w
);
126 widget_arg
= widget_val
? widget_val
->call_data
: NULL
;
127 if (instance
->info
->post_activate_cb
)
128 instance
->info
->post_activate_cb (w
, instance
->info
->id
, widget_arg
);
132 \f/* creation functions */
135 xlw_create_menubar (widget_instance
*instance
)
141 XtSetArg (al
[ac
], XtNmenu
, instance
->info
->val
); ac
++;
143 XtSetArg (al
[ac
], XtNshowGrip
, 0); ac
++;
144 XtSetArg (al
[ac
], XtNresizeToPreferred
, 1); ac
++;
145 XtSetArg (al
[ac
], XtNallowResize
, 1); ac
++;
148 /* This used to use XtVaCreateWidget, but an old Xt version
149 has a bug in XtVaCreateWidget that frees instance->info->name. */
151 = XtCreateWidget (instance
->info
->name
, xlwMenuWidgetClass
,
152 instance
->parent
, al
, ac
);
154 XtAddCallback (widget
, XtNopen
, pre_hook
, (XtPointer
)instance
);
155 XtAddCallback (widget
, XtNselect
, pick_hook
, (XtPointer
)instance
);
156 XtAddCallback (widget
, XtNleaveCallback
, leave_hook
, (XtPointer
)instance
);
157 XtAddCallback (widget
, XtNenterCallback
, enter_hook
, (XtPointer
)instance
);
162 xlw_create_popup_menu (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
, XtNleaveCallback
, leave_hook
, (XtPointer
)instance
);
183 XtAddCallback (widget
, XtNenterCallback
, enter_hook
, (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 widget
)
199 WidgetClass the_class
= XtClass (widget
);
201 if (the_class
== xlwMenuWidgetClass
)
203 if (the_class
== overrideShellWidgetClass
)
204 return (XtClass (((CompositeWidget
)widget
)->composite
.children
[0])
205 == xlwMenuWidgetClass
);
210 xlw_update_one_widget (widget_instance
* instance
, Widget widget
,
211 widget_value
* val
, Boolean deep_p
)
215 /* This used to use XtVaSetValues, but some old Xt versions
216 that have a bug in XtVaCreateWidget might have it here too. */
217 XtSetArg (al
[0], XtNmenu
, instance
->info
->val
);
219 XtSetValues (widget
, al
, 1);
223 xlw_update_one_value (widget_instance
*instance
,
231 xlw_pop_instance (widget_instance
* instance
, Boolean up
)
236 xlw_popup_menu (Widget widget
, XEvent
*event
)
240 if (!XtIsShell (widget
))
243 mw
= (XlwMenuWidget
)((CompositeWidget
)widget
)->composite
.children
[0];
246 XtCallActionProc ((Widget
) mw
, "start", event
, NULL
, 0);
250 XButtonPressedEvent
*bd
= &dummy
.xbutton
;
252 bd
->type
= ButtonPress
;
255 bd
->display
= XtDisplay (widget
);
256 bd
->window
= XtWindow (XtParent (widget
));
257 bd
->time
= CurrentTime
;
259 XQueryPointer (bd
->display
, bd
->window
, &bd
->root
,
260 &bd
->subwindow
, &bd
->x_root
, &bd
->y_root
,
261 &bd
->x
, &bd
->y
, &bd
->state
);
263 XtCallActionProc ((Widget
) mw
, "start", &dummy
, NULL
, 0);
267 \f/* Destruction of instances */
269 xlw_destroy_instance (widget_instance
*instance
)
271 if (instance
->widget
)
272 XtDestroyWidget (instance
->widget
);