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 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 (Widget w
, XtPointer client_data
, XtPointer call_data
)
76 widget_instance
*instance
= (widget_instance
*) client_data
;
78 if (instance
->info
->highlight_cb
79 && !w
->core
.being_destroyed
)
80 instance
->info
->highlight_cb (w
, instance
->info
->id
, call_data
);
84 enter_hook (Widget w
, XtPointer client_data
, XtPointer call_data
)
86 highlight_hook (w
, client_data
, call_data
);
90 leave_hook (Widget w
, XtPointer client_data
, XtPointer call_data
)
92 highlight_hook (w
, client_data
, NULL
);
97 pre_hook (Widget w
, XtPointer client_data
, XtPointer call_data
)
99 widget_instance
* instance
= (widget_instance
*)client_data
;
102 if (w
->core
.being_destroyed
)
105 val
= lw_get_widget_value_for_widget (instance
, w
);
106 if (instance
->info
->pre_activate_cb
)
107 instance
->info
->pre_activate_cb (w
, instance
->info
->id
,
108 val
? val
->call_data
: NULL
);
112 pick_hook (Widget w
, XtPointer client_data
, XtPointer call_data
)
114 widget_instance
* instance
= (widget_instance
*)client_data
;
115 widget_value
* contents_val
= (widget_value
*)call_data
;
116 widget_value
* widget_val
;
117 XtPointer widget_arg
;
119 if (w
->core
.being_destroyed
)
122 if (instance
->info
->selection_cb
&& contents_val
&& contents_val
->enabled
123 && !contents_val
->contents
)
124 instance
->info
->selection_cb (w
, instance
->info
->id
,
125 contents_val
->call_data
);
127 widget_val
= lw_get_widget_value_for_widget (instance
, w
);
128 widget_arg
= widget_val
? widget_val
->call_data
: NULL
;
129 if (instance
->info
->post_activate_cb
)
130 instance
->info
->post_activate_cb (w
, instance
->info
->id
, widget_arg
);
134 \f/* creation functions */
137 xlw_create_menubar (widget_instance
*instance
)
143 XtSetArg (al
[ac
], XtNmenu
, instance
->info
->val
); ac
++;
145 XtSetArg (al
[ac
], XtNshowGrip
, 0); ac
++;
146 XtSetArg (al
[ac
], XtNresizeToPreferred
, 1); ac
++;
147 XtSetArg (al
[ac
], XtNallowResize
, 1); ac
++;
150 /* This used to use XtVaCreateWidget, but an old Xt version
151 has a bug in XtVaCreateWidget that frees instance->info->name. */
153 = XtCreateWidget (instance
->info
->name
, xlwMenuWidgetClass
,
154 instance
->parent
, al
, ac
);
156 XtAddCallback (widget
, XtNopen
, pre_hook
, (XtPointer
)instance
);
157 XtAddCallback (widget
, XtNselect
, pick_hook
, (XtPointer
)instance
);
158 XtAddCallback (widget
, XtNleaveCallback
, leave_hook
, (XtPointer
)instance
);
159 XtAddCallback (widget
, XtNenterCallback
, enter_hook
, (XtPointer
)instance
);
164 xlw_create_popup_menu (widget_instance
*instance
)
167 = XtCreatePopupShell (instance
->info
->name
, overrideShellWidgetClass
,
168 instance
->parent
, NULL
, 0);
174 XtSetArg (al
[ac
], XtNmenu
, instance
->info
->val
); ac
++;
175 XtSetArg (al
[ac
], XtNhorizontal
, False
); ac
++;
177 /* This used to use XtVaManagedCreateWidget, but an old Xt version
178 has a bug in XtVaManagedCreateWidget that frees instance->info->name. */
180 = XtCreateManagedWidget ("popup", xlwMenuWidgetClass
,
181 popup_shell
, al
, ac
);
183 XtAddCallback (widget
, XtNselect
, pick_hook
, (XtPointer
)instance
);
184 XtAddCallback (widget
, XtNleaveCallback
, leave_hook
, (XtPointer
)instance
);
185 XtAddCallback (widget
, XtNenterCallback
, enter_hook
, (XtPointer
)instance
);
190 widget_creation_entry
191 xlw_creation_table
[] =
193 {"menubar", xlw_create_menubar
},
194 {"popup", xlw_create_popup_menu
},
199 lw_lucid_widget_p (Widget widget
)
201 WidgetClass the_class
= XtClass (widget
);
203 if (the_class
== xlwMenuWidgetClass
)
205 if (the_class
== overrideShellWidgetClass
)
206 return (XtClass (((CompositeWidget
)widget
)->composite
.children
[0])
207 == xlwMenuWidgetClass
);
212 xlw_update_one_widget (widget_instance
* instance
, Widget widget
,
213 widget_value
* val
, Boolean deep_p
)
217 /* This used to use XtVaSetValues, but some old Xt versions
218 that have a bug in XtVaCreateWidget might have it here too. */
219 XtSetArg (al
[0], XtNmenu
, instance
->info
->val
);
221 XtSetValues (widget
, al
, 1);
225 xlw_update_one_value (widget_instance
*instance
,
233 xlw_pop_instance (widget_instance
* instance
, Boolean up
)
238 xlw_popup_menu (Widget widget
, XEvent
*event
)
242 if (!XtIsShell (widget
))
245 mw
= (XlwMenuWidget
)((CompositeWidget
)widget
)->composite
.children
[0];
248 XtCallActionProc ((Widget
) mw
, "start", event
, NULL
, 0);
252 XButtonPressedEvent
*bd
= &dummy
.xbutton
;
254 bd
->type
= ButtonPress
;
257 bd
->display
= XtDisplay (widget
);
258 bd
->window
= XtWindow (XtParent (widget
));
259 bd
->time
= CurrentTime
;
261 XQueryPointer (bd
->display
, bd
->window
, &bd
->root
,
262 &bd
->subwindow
, &bd
->x_root
, &bd
->y_root
,
263 &bd
->x
, &bd
->y
, &bd
->state
);
265 XtCallActionProc ((Widget
) mw
, "start", &dummy
, NULL
, 0);
269 \f/* Destruction of instances */
271 xlw_destroy_instance (widget_instance
*instance
)
273 if (instance
->widget
)
274 XtDestroyWidget (instance
->widget
);
277 /* arch-tag: 541e3912-477d-406e-9bf2-dbf2b7ff8c3b
278 (do not change this comment) */