1 /* The lwlib interface to "xlwmenu" menus.
2 Copyright (C) 1992 Lucid, Inc.
3 Copyright (C) 1994, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
4 2008, 2009, 2010 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. */
30 #include "lwlib-Xlw.h"
31 #include <X11/StringDefs.h>
32 #include <X11/IntrinsicP.h>
33 #include <X11/ObjectP.h>
34 #include <X11/CompositeP.h>
35 #include <X11/Shell.h>
42 /* Print the complete X resource name of widget WIDGET to stderr.
43 This is sometimes handy to have available. */
46 x_print_complete_resource_name (widget
)
52 for (i
= 0; i
< 100 && widget
!= NULL
; ++i
)
54 names
[i
] = XtName (widget
);
55 widget
= XtParent (widget
);
58 for (--i
; i
>= 1; --i
)
59 fprintf (stderr
, "%s.", names
[i
]);
60 fprintf (stderr
, "%s\n", names
[0]);
66 \f/* Menu callbacks */
68 /* Callback XtNhighlightCallback for Lucid menus. W is the menu
69 widget, CLIENT_DATA contains a pointer to the widget_instance
70 for the menu, CALL_DATA contains a pointer to the widget_value
71 structure for the highlighted menu item. The latter may be null
72 if there isn't any highlighted menu item. */
75 highlight_hook (Widget w
, XtPointer client_data
, XtPointer call_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 enter_hook (Widget w
, XtPointer client_data
, XtPointer call_data
)
87 highlight_hook (w
, client_data
, call_data
);
91 leave_hook (Widget w
, XtPointer client_data
, XtPointer call_data
)
93 highlight_hook (w
, client_data
, NULL
);
98 pre_hook (Widget w
, XtPointer client_data
, XtPointer call_data
)
100 widget_instance
* instance
= (widget_instance
*)client_data
;
103 if (w
->core
.being_destroyed
)
106 val
= lw_get_widget_value_for_widget (instance
, w
);
107 if (instance
->info
->pre_activate_cb
)
108 instance
->info
->pre_activate_cb (w
, instance
->info
->id
,
109 val
? val
->call_data
: NULL
);
113 pick_hook (Widget w
, XtPointer client_data
, XtPointer call_data
)
115 widget_instance
* instance
= (widget_instance
*)client_data
;
116 widget_value
* contents_val
= (widget_value
*)call_data
;
117 widget_value
* widget_val
;
118 XtPointer widget_arg
;
120 if (w
->core
.being_destroyed
)
123 if (instance
->info
->selection_cb
&& contents_val
&& contents_val
->enabled
124 && !contents_val
->contents
)
125 instance
->info
->selection_cb (w
, instance
->info
->id
,
126 contents_val
->call_data
);
128 widget_val
= lw_get_widget_value_for_widget (instance
, w
);
129 widget_arg
= widget_val
? widget_val
->call_data
: NULL
;
130 if (instance
->info
->post_activate_cb
)
131 instance
->info
->post_activate_cb (w
, instance
->info
->id
, widget_arg
);
135 \f/* creation functions */
138 xlw_create_menubar (widget_instance
*instance
)
144 XtSetArg (al
[ac
], XtNmenu
, instance
->info
->val
); ac
++;
146 XtSetArg (al
[ac
], XtNshowGrip
, 0); ac
++;
147 XtSetArg (al
[ac
], XtNresizeToPreferred
, 1); ac
++;
148 XtSetArg (al
[ac
], XtNallowResize
, 1); ac
++;
151 /* This used to use XtVaCreateWidget, but an old Xt version
152 has a bug in XtVaCreateWidget that frees instance->info->name. */
154 = XtCreateWidget (instance
->info
->name
, xlwMenuWidgetClass
,
155 instance
->parent
, al
, ac
);
157 XtAddCallback (widget
, XtNopen
, pre_hook
, (XtPointer
)instance
);
158 XtAddCallback (widget
, XtNselect
, pick_hook
, (XtPointer
)instance
);
159 XtAddCallback (widget
, XtNleaveCallback
, leave_hook
, (XtPointer
)instance
);
160 XtAddCallback (widget
, XtNenterCallback
, enter_hook
, (XtPointer
)instance
);
165 xlw_create_popup_menu (widget_instance
*instance
)
168 = XtCreatePopupShell (instance
->info
->name
, overrideShellWidgetClass
,
169 instance
->parent
, NULL
, 0);
175 XtSetArg (al
[ac
], XtNmenu
, instance
->info
->val
); ac
++;
176 XtSetArg (al
[ac
], XtNhorizontal
, False
); ac
++;
178 /* This used to use XtVaManagedCreateWidget, but an old Xt version
179 has a bug in XtVaManagedCreateWidget that frees instance->info->name. */
181 = XtCreateManagedWidget ("popup", xlwMenuWidgetClass
,
182 popup_shell
, al
, ac
);
184 XtAddCallback (widget
, XtNselect
, pick_hook
, (XtPointer
)instance
);
185 XtAddCallback (widget
, XtNleaveCallback
, leave_hook
, (XtPointer
)instance
);
186 XtAddCallback (widget
, XtNenterCallback
, enter_hook
, (XtPointer
)instance
);
191 widget_creation_entry
192 xlw_creation_table
[] =
194 {"menubar", xlw_create_menubar
},
195 {"popup", xlw_create_popup_menu
},
200 lw_lucid_widget_p (Widget widget
)
202 WidgetClass the_class
= XtClass (widget
);
204 if (the_class
== xlwMenuWidgetClass
)
206 if (the_class
== overrideShellWidgetClass
)
207 return (XtClass (((CompositeWidget
)widget
)->composite
.children
[0])
208 == xlwMenuWidgetClass
);
214 xlw_update_one_widget (widget_instance
* instance
, Widget widget
,
215 widget_value
* val
, Boolean deep_p
)
217 xlw_update_one_widget (instance
, widget
, val
, deep_p
)
218 widget_instance
* instance
;
226 /* This used to use XtVaSetValues, but some old Xt versions
227 that have a bug in XtVaCreateWidget might have it here too. */
228 XtSetArg (al
[0], XtNmenu
, instance
->info
->val
);
230 XtSetValues (widget
, al
, 1);
234 xlw_update_one_value (widget_instance
*instance
, Widget widget
, widget_value
*val
)
241 xlw_pop_instance (widget_instance
* instance
, Boolean up
)
243 xlw_pop_instance (instance
, up
)
244 widget_instance
* instance
;
251 xlw_popup_menu (Widget widget
, XEvent
*event
)
255 if (!XtIsShell (widget
))
258 mw
= (XlwMenuWidget
)((CompositeWidget
)widget
)->composite
.children
[0];
261 XtCallActionProc ((Widget
) mw
, "start", event
, NULL
, 0);
265 XButtonPressedEvent
*bd
= &dummy
.xbutton
;
267 bd
->type
= ButtonPress
;
270 bd
->display
= XtDisplay (widget
);
271 bd
->window
= XtWindow (XtParent (widget
));
272 bd
->time
= CurrentTime
;
274 XQueryPointer (bd
->display
, bd
->window
, &bd
->root
,
275 &bd
->subwindow
, &bd
->x_root
, &bd
->y_root
,
276 &bd
->x
, &bd
->y
, &bd
->state
);
278 XtCallActionProc ((Widget
) mw
, "start", &dummy
, NULL
, 0);
282 \f/* Destruction of instances */
284 xlw_destroy_instance (widget_instance
*instance
)
286 if (instance
->widget
)
287 XtDestroyWidget (instance
->widget
);
290 /* arch-tag: 541e3912-477d-406e-9bf2-dbf2b7ff8c3b
291 (do not change this comment) */