1 /* The lwlib interface to "xlwmenu" menus.
3 Copyright (C) 1992 Lucid, Inc.
4 Copyright (C) 1994, 2000-2014 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. If not, see <http://www.gnu.org/licenses/>. */
26 #include "lwlib-Xlw.h"
27 #include <X11/StringDefs.h>
28 #include <X11/IntrinsicP.h>
29 #include <X11/ObjectP.h>
30 #include <X11/CompositeP.h>
31 #include <X11/Shell.h>
38 /* Print the complete X resource name of widget WIDGET to stderr.
39 This is sometimes handy to have available. */
42 x_print_complete_resource_name (Widget widget
)
47 for (i
= 0; i
< 100 && widget
!= NULL
; ++i
)
49 names
[i
] = XtName (widget
);
50 widget
= XtParent (widget
);
53 for (--i
; i
>= 1; --i
)
54 fprintf (stderr
, "%s.", names
[i
]);
55 fprintf (stderr
, "%s\n", names
[0]);
61 \f/* Menu callbacks */
63 /* Callback XtNhighlightCallback for Lucid menus. W is the menu
64 widget, CLIENT_DATA contains a pointer to the widget_instance
65 for the menu, CALL_DATA contains a pointer to the widget_value
66 structure for the highlighted menu item. The latter may be null
67 if there isn't any highlighted menu item. */
70 highlight_hook (Widget w
, XtPointer client_data
, XtPointer call_data
)
72 widget_instance
*instance
= (widget_instance
*) client_data
;
74 if (instance
->info
->highlight_cb
75 && !w
->core
.being_destroyed
)
76 instance
->info
->highlight_cb (w
, instance
->info
->id
, call_data
);
80 enter_hook (Widget w
, XtPointer client_data
, XtPointer call_data
)
82 highlight_hook (w
, client_data
, call_data
);
86 leave_hook (Widget w
, XtPointer client_data
, XtPointer call_data
)
88 highlight_hook (w
, client_data
, NULL
);
93 pre_hook (Widget w
, XtPointer client_data
, XtPointer call_data
)
95 widget_instance
* instance
= (widget_instance
*)client_data
;
98 if (w
->core
.being_destroyed
)
101 val
= lw_get_widget_value_for_widget (instance
, w
);
102 if (instance
->info
->pre_activate_cb
)
103 instance
->info
->pre_activate_cb (w
, instance
->info
->id
,
104 val
? val
->call_data
: NULL
);
108 pick_hook (Widget w
, XtPointer client_data
, XtPointer call_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 (widget_instance
*instance
)
139 XtSetArg (al
[ac
], XtNmenu
, instance
->info
->val
); ac
++;
141 XtSetArg (al
[ac
], XtNshowGrip
, 0); ac
++;
142 XtSetArg (al
[ac
], XtNresizeToPreferred
, 1); ac
++;
143 XtSetArg (al
[ac
], XtNallowResize
, 1); ac
++;
146 /* This used to use XtVaCreateWidget, but an old Xt version
147 has a bug in XtVaCreateWidget that frees instance->info->name. */
149 = XtCreateWidget (instance
->info
->name
, xlwMenuWidgetClass
,
150 instance
->parent
, al
, ac
);
152 XtAddCallback (widget
, XtNopen
, pre_hook
, (XtPointer
)instance
);
153 XtAddCallback (widget
, XtNselect
, pick_hook
, (XtPointer
)instance
);
154 XtAddCallback (widget
, XtNleaveCallback
, leave_hook
, (XtPointer
)instance
);
155 XtAddCallback (widget
, XtNenterCallback
, enter_hook
, (XtPointer
)instance
);
160 xlw_create_popup_menu (widget_instance
*instance
)
163 = XtCreatePopupShell (instance
->info
->name
, overrideShellWidgetClass
,
164 instance
->parent
, NULL
, 0);
170 XtSetArg (al
[ac
], XtNmenu
, instance
->info
->val
); ac
++;
171 XtSetArg (al
[ac
], XtNhorizontal
, False
); ac
++;
173 /* This used to use XtVaManagedCreateWidget, but an old Xt version
174 has a bug in XtVaManagedCreateWidget that frees instance->info->name. */
176 = XtCreateManagedWidget ("popup", xlwMenuWidgetClass
,
177 popup_shell
, al
, ac
);
179 XtAddCallback (widget
, XtNselect
, pick_hook
, (XtPointer
)instance
);
180 XtAddCallback (widget
, XtNleaveCallback
, leave_hook
, (XtPointer
)instance
);
181 XtAddCallback (widget
, XtNenterCallback
, enter_hook
, (XtPointer
)instance
);
186 widget_creation_entry
187 xlw_creation_table
[] =
189 {"menubar", xlw_create_menubar
},
190 {"popup", xlw_create_popup_menu
},
195 lw_lucid_widget_p (Widget widget
)
197 WidgetClass the_class
= XtClass (widget
);
199 if (the_class
== xlwMenuWidgetClass
)
201 if (the_class
== overrideShellWidgetClass
)
202 return (XtClass (((CompositeWidget
)widget
)->composite
.children
[0])
203 == xlwMenuWidgetClass
);
208 xlw_update_one_widget (widget_instance
* instance
, Widget widget
,
209 widget_value
* val
, Boolean deep_p
)
213 /* This used to use XtVaSetValues, but some old Xt versions
214 that have a bug in XtVaCreateWidget might have it here too. */
215 XtSetArg (al
[0], XtNmenu
, instance
->info
->val
);
217 XtSetValues (widget
, al
, 1);
221 xlw_update_one_value (widget_instance
*instance
,
229 xlw_pop_instance (widget_instance
* instance
, Boolean up
)
234 xlw_popup_menu (Widget widget
, XEvent
*event
)
238 if (!XtIsShell (widget
))
241 mw
= (XlwMenuWidget
)((CompositeWidget
)widget
)->composite
.children
[0];
244 XtCallActionProc ((Widget
) mw
, "start", event
, NULL
, 0);
248 XButtonPressedEvent
*bd
= &dummy
.xbutton
;
250 bd
->type
= ButtonPress
;
253 bd
->display
= XtDisplay (widget
);
254 bd
->window
= XtWindow (XtParent (widget
));
255 bd
->time
= CurrentTime
;
257 XQueryPointer (bd
->display
, bd
->window
, &bd
->root
,
258 &bd
->subwindow
, &bd
->x_root
, &bd
->y_root
,
259 &bd
->x
, &bd
->y
, &bd
->state
);
261 XtCallActionProc ((Widget
) mw
, "start", &dummy
, NULL
, 0);
265 \f/* Destruction of instances */
267 xlw_destroy_instance (widget_instance
*instance
)
269 if (instance
->widget
)
270 XtDestroyWidget (instance
->widget
);