| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
#ifdef HAVE_CONFIG_H |
|---|
| 22 |
#include <config.h> |
|---|
| 23 |
#endif |
|---|
| 24 |
|
|---|
| 25 |
#include "lwlib-Xlw.h" |
|---|
| 26 |
#include <X11/StringDefs.h> |
|---|
| 27 |
#include <X11/IntrinsicP.h> |
|---|
| 28 |
#include <X11/ObjectP.h> |
|---|
| 29 |
#include <X11/CompositeP.h> |
|---|
| 30 |
#include <X11/Shell.h> |
|---|
| 31 |
#include "xlwmenu.h" |
|---|
| 32 |
|
|---|
| 33 |
#if 0 |
|---|
| 34 |
|
|---|
| 35 |
#include <stdio.h> |
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
void |
|---|
| 41 |
x_print_complete_resource_name (widget) |
|---|
| 42 |
Widget widget; |
|---|
| 43 |
{ |
|---|
| 44 |
int i; |
|---|
| 45 |
String names[100]; |
|---|
| 46 |
|
|---|
| 47 |
for (i = 0; i < 100 && widget != NULL; ++i) |
|---|
| 48 |
{ |
|---|
| 49 |
names[i] = XtName (widget); |
|---|
| 50 |
widget = XtParent (widget); |
|---|
| 51 |
} |
|---|
| 52 |
|
|---|
| 53 |
for (--i; i >= 1; --i) |
|---|
| 54 |
fprintf (stderr, "%s.", names[i]); |
|---|
| 55 |
fprintf (stderr, "%s\n", names[0]); |
|---|
| 56 |
} |
|---|
| 57 |
|
|---|
| 58 |
#endif |
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 |
|
|---|
| 63 |
|
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 |
static void |
|---|
| 70 |
highlight_hook (w, client_data, call_data) |
|---|
| 71 |
Widget w; |
|---|
| 72 |
XtPointer client_data; |
|---|
| 73 |
XtPointer call_data; |
|---|
| 74 |
{ |
|---|
| 75 |
widget_instance *instance = (widget_instance *) client_data; |
|---|
| 76 |
|
|---|
| 77 |
if (instance->info->highlight_cb |
|---|
| 78 |
&& !w->core.being_destroyed) |
|---|
| 79 |
instance->info->highlight_cb (w, instance->info->id, call_data); |
|---|
| 80 |
} |
|---|
| 81 |
|
|---|
| 82 |
static void |
|---|
| 83 |
pre_hook (w, client_data, call_data) |
|---|
| 84 |
Widget w; |
|---|
| 85 |
XtPointer client_data; |
|---|
| 86 |
XtPointer call_data; |
|---|
| 87 |
{ |
|---|
| 88 |
widget_instance* instance = (widget_instance*)client_data; |
|---|
| 89 |
widget_value* val; |
|---|
| 90 |
|
|---|
| 91 |
if (w->core.being_destroyed) |
|---|
| 92 |
return; |
|---|
| 93 |
|
|---|
| 94 |
val = lw_get_widget_value_for_widget (instance, w); |
|---|
| 95 |
if (instance->info->pre_activate_cb) |
|---|
| 96 |
instance->info->pre_activate_cb (w, instance->info->id, |
|---|
| 97 |
val ? val->call_data : NULL); |
|---|
| 98 |
} |
|---|
| 99 |
|
|---|
| 100 |
static void |
|---|
| 101 |
pick_hook (w, client_data, call_data) |
|---|
| 102 |
Widget w; |
|---|
| 103 |
XtPointer client_data; |
|---|
| 104 |
XtPointer call_data; |
|---|
| 105 |
{ |
|---|
| 106 |
widget_instance* instance = (widget_instance*)client_data; |
|---|
| 107 |
widget_value* contents_val = (widget_value*)call_data; |
|---|
| 108 |
widget_value* widget_val; |
|---|
| 109 |
XtPointer widget_arg; |
|---|
| 110 |
|
|---|
| 111 |
if (w->core.being_destroyed) |
|---|
| 112 |
return; |
|---|
| 113 |
|
|---|
| 114 |
if (instance->info->selection_cb && contents_val && contents_val->enabled |
|---|
| 115 |
&& !contents_val->contents) |
|---|
| 116 |
instance->info->selection_cb (w, instance->info->id, |
|---|
| 117 |
contents_val->call_data); |
|---|
| 118 |
|
|---|
| 119 |
widget_val = lw_get_widget_value_for_widget (instance, w); |
|---|
| 120 |
widget_arg = widget_val ? widget_val->call_data : NULL; |
|---|
| 121 |
if (instance->info->post_activate_cb) |
|---|
| 122 |
instance->info->post_activate_cb (w, instance->info->id, widget_arg); |
|---|
| 123 |
|
|---|
| 124 |
} |
|---|
| 125 |
|
|---|
| 126 |
|
|---|
| 127 |
|
|---|
| 128 |
static Widget |
|---|
| 129 |
xlw_create_menubar (instance) |
|---|
| 130 |
widget_instance* instance; |
|---|
| 131 |
{ |
|---|
| 132 |
Widget widget; |
|---|
| 133 |
Arg al[5]; |
|---|
| 134 |
int ac = 0; |
|---|
| 135 |
|
|---|
| 136 |
XtSetArg (al[ac], XtNmenu, instance->info->val); ac++; |
|---|
| 137 |
#ifdef emacs |
|---|
| 138 |
XtSetArg (al[ac], XtNshowGrip, 0); ac++; |
|---|
| 139 |
XtSetArg (al[ac], XtNresizeToPreferred, 1); ac++; |
|---|
| 140 |
XtSetArg (al[ac], XtNallowResize, 1); ac++; |
|---|
| 141 |
#endif |
|---|
| 142 |
|
|---|
| 143 |
|
|---|
| 144 |
|
|---|
| 145 |
widget |
|---|
| 146 |
= XtCreateWidget (instance->info->name, xlwMenuWidgetClass, |
|---|
| 147 |
instance->parent, al, ac); |
|---|
| 148 |
|
|---|
| 149 |
XtAddCallback (widget, XtNopen, pre_hook, (XtPointer)instance); |
|---|
| 150 |
XtAddCallback (widget, XtNselect, pick_hook, (XtPointer)instance); |
|---|
| 151 |
XtAddCallback (widget, XtNhighlightCallback, highlight_hook, |
|---|
| 152 |
(XtPointer)instance); |
|---|
| 153 |
return widget; |
|---|
| 154 |
} |
|---|
| 155 |
|
|---|
| 156 |
static Widget |
|---|
| 157 |
xlw_create_popup_menu (instance) |
|---|
| 158 |
widget_instance* instance; |
|---|
| 159 |
{ |
|---|
| 160 |
Widget popup_shell |
|---|
| 161 |
= XtCreatePopupShell (instance->info->name, overrideShellWidgetClass, |
|---|
| 162 |
instance->parent, NULL, 0); |
|---|
| 163 |
|
|---|
| 164 |
Widget widget; |
|---|
| 165 |
Arg al[2]; |
|---|
| 166 |
int ac = 0; |
|---|
| 167 |
|
|---|
| 168 |
XtSetArg (al[ac], XtNmenu, instance->info->val); ac++; |
|---|
| 169 |
XtSetArg (al[ac], XtNhorizontal, False); ac++; |
|---|
| 170 |
|
|---|
| 171 |
|
|---|
| 172 |
|
|---|
| 173 |
widget |
|---|
| 174 |
= XtCreateManagedWidget ("popup", xlwMenuWidgetClass, |
|---|
| 175 |
popup_shell, al, ac); |
|---|
| 176 |
|
|---|
| 177 |
XtAddCallback (widget, XtNselect, pick_hook, (XtPointer)instance); |
|---|
| 178 |
XtAddCallback (widget, XtNhighlightCallback, highlight_hook, |
|---|
| 179 |
(XtPointer)instance); |
|---|
| 180 |
return popup_shell; |
|---|
| 181 |
} |
|---|
| 182 |
|
|---|
| 183 |
widget_creation_entry |
|---|
| 184 |
xlw_creation_table [] = |
|---|
| 185 |
{ |
|---|
| 186 |
{"menubar", xlw_create_menubar}, |
|---|
| 187 |
{"popup", xlw_create_popup_menu}, |
|---|
| 188 |
{NULL, NULL} |
|---|
| 189 |
}; |
|---|
| 190 |
|
|---|
| 191 |
Boolean |
|---|
| 192 |
lw_lucid_widget_p (widget) |
|---|
| 193 |
Widget widget; |
|---|
| 194 |
{ |
|---|
| 195 |
WidgetClass the_class = XtClass (widget); |
|---|
| 196 |
|
|---|
| 197 |
if (the_class == xlwMenuWidgetClass) |
|---|
| 198 |
return True; |
|---|
| 199 |
if (the_class == overrideShellWidgetClass) |
|---|
| 200 |
return (XtClass (((CompositeWidget)widget)->composite.children [0]) |
|---|
| 201 |
== xlwMenuWidgetClass); |
|---|
| 202 |
return False; |
|---|
| 203 |
} |
|---|
| 204 |
|
|---|
| 205 |
void |
|---|
| 206 |
xlw_update_one_widget (instance, widget, val, deep_p) |
|---|
| 207 |
widget_instance* instance; |
|---|
| 208 |
Widget widget; |
|---|
| 209 |
widget_value* val; |
|---|
| 210 |
Boolean deep_p; |
|---|
| 211 |
{ |
|---|
| 212 |
XlwMenuWidget mw; |
|---|
| 213 |
Arg al[1]; |
|---|
| 214 |
|
|---|
| 215 |
if (XtIsShell (widget)) |
|---|
| 216 |
mw = (XlwMenuWidget)((CompositeWidget)widget)->composite.children [0]; |
|---|
| 217 |
else |
|---|
| 218 |
mw = (XlwMenuWidget)widget; |
|---|
| 219 |
|
|---|
| 220 |
|
|---|
| 221 |
|
|---|
| 222 |
XtSetArg (al[0], XtNmenu, instance->info->val); |
|---|
| 223 |
|
|---|
| 224 |
XtSetValues (widget, al, 1); |
|---|
| 225 |
} |
|---|
| 226 |
|
|---|
| 227 |
void |
|---|
| 228 |
xlw_update_one_value (instance, widget, val) |
|---|
| 229 |
widget_instance* instance; |
|---|
| 230 |
Widget widget; |
|---|
| 231 |
widget_value* val; |
|---|
| 232 |
{ |
|---|
| 233 |
return; |
|---|
| 234 |
} |
|---|
| 235 |
|
|---|
| 236 |
void |
|---|
| 237 |
xlw_pop_instance (instance, up) |
|---|
| 238 |
widget_instance* instance; |
|---|
| 239 |
Boolean up; |
|---|
| 240 |
{ |
|---|
| 241 |
} |
|---|
| 242 |
|
|---|
| 243 |
void |
|---|
| 244 |
xlw_popup_menu (widget, event) |
|---|
| 245 |
Widget widget; |
|---|
| 246 |
XEvent *event; |
|---|
| 247 |
{ |
|---|
| 248 |
XButtonPressedEvent dummy; |
|---|
| 249 |
XlwMenuWidget mw; |
|---|
| 250 |
|
|---|
| 251 |
if (!XtIsShell (widget)) |
|---|
| 252 |
return; |
|---|
| 253 |
|
|---|
| 254 |
mw = (XlwMenuWidget)((CompositeWidget)widget)->composite.children [0]; |
|---|
| 255 |
|
|---|
| 256 |
if (event) |
|---|
| 257 |
pop_up_menu (mw, (XButtonPressedEvent*) event); |
|---|
| 258 |
else |
|---|
| 259 |
{ |
|---|
| 260 |
dummy.type = ButtonPress; |
|---|
| 261 |
dummy.serial = 0; |
|---|
| 262 |
dummy.send_event = 0; |
|---|
| 263 |
dummy.display = XtDisplay (widget); |
|---|
| 264 |
dummy.window = XtWindow (XtParent (widget)); |
|---|
| 265 |
dummy.time = CurrentTime; |
|---|
| 266 |
dummy.button = 0; |
|---|
| 267 |
XQueryPointer (dummy.display, dummy.window, &dummy.root, |
|---|
| 268 |
&dummy.subwindow, &dummy.x_root, &dummy.y_root, |
|---|
| 269 |
&dummy.x, &dummy.y, &dummy.state); |
|---|
| 270 |
|
|---|
| 271 |
pop_up_menu (mw, &dummy); |
|---|
| 272 |
} |
|---|
| 273 |
} |
|---|
| 274 |
|
|---|
| 275 |
|
|---|
| 276 |
void |
|---|
| 277 |
xlw_destroy_instance (instance) |
|---|
| 278 |
widget_instance* instance; |
|---|
| 279 |
{ |
|---|
| 280 |
if (instance->widget) |
|---|
| 281 |
XtDestroyWidget (instance->widget); |
|---|
| 282 |
} |
|---|
| 283 |
|
|---|