1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
|
#include "lwlib-Xol.h"
#include <X11/StringDefs.h>
#include <X11/IntrinsicP.h>
#include <X11/CompositeP.h>
#include <X11/Shell.h>
#include <Xol/Menu.h>
#include <Xol/OpenLook.h>
#include <Xol/MenuButton.h>
#include <Xol/OblongButt.h>
#include <Xol/ControlAre.h>
#include <Xol/Stub.h>
#include <Xol/StaticText.h>
/* forward declarations */
static void
update_menu_widget (widget_instance* instance, Widget widget,
widget_value* val);
/* Menu callbacks */
static void
pre_hook (Widget w, caddr_t client_data, caddr_t call_data)
{
OlVirtualEvent ve = (OlVirtualEvent)call_data;
widget_instance* instance = (widget_instance*)client_data;
if (w->core.being_destroyed)
return;
if (XtParent (w) == instance->widget)
{
if (ve->xevent->type == ButtonPress && instance->info->pre_activate_cb)
instance->info->pre_activate_cb (instance->widget, instance->info->id,
NULL);
}
}
static void
post_hook (Widget w, caddr_t client_data, caddr_t call_data)
{
widget_instance* instance = (widget_instance*)client_data;
if (w->core.being_destroyed)
return;
if (instance->info->post_activate_cb)
instance->info->post_activate_cb (w, instance->info->id, NULL);
}
static void
pick_hook (Widget w, caddr_t client_data, caddr_t call_data)
{
widget_instance* instance = 0;
widget_value* val = (widget_value*)client_data;
if (w->core.being_destroyed)
return;
XtVaGetValues (w, XtNuserData, &instance, 0);
if (!instance)
return;
if (instance->info->selection_cb && val && val->enabled
&& !val->contents)
instance->info->selection_cb (w, instance->info->id, val->call_data);
}
/* creation functions */
static Widget
xol_create_menubar (widget_instance* instance)
{
Widget widget =
XtVaCreateWidget (instance->info->name, controlAreaWidgetClass,
instance->parent, 0);
return widget;
}
static Widget
xol_create_popup_menu (widget_instance* instance)
{
Widget popup_shell =
XtCreatePopupShell (instance->info->name, menuShellWidgetClass,
instance->parent, NULL, 0);
return popup_shell;
}
widget_creation_entry
xol_creation_table [] =
{
{"menubar", xol_create_menubar},
{"popup", xol_create_popup_menu},
{NULL, NULL}
};
Widget
xol_create_dialog (widget_instance* instance)
{
return NULL;
}
Boolean
lw_olit_widget_p (Widget widget)
{
return True;
}
/* update functions */
static void
destroy_all_children (Widget widget)
{
Widget* children;
unsigned int number;
int i;
children = (Widget *) XtCompositeChildren (widget, &number);
if (children)
{
/* Unmanage all children and destroy them. They will only be
* really destroyed when we get out of DispatchEvent. */
for (i = 0; i < number; i++)
{
Widget child = children [i];
if (!child->core.being_destroyed)
{
XtUnmanageChild (child);
XtDestroyWidget (child);
}
}
XtFree (children);
}
}
static Boolean
all_dashes_p (char* s)
{
char* t;
for (t = s; *t; t++)
if (*t != '-')
return False;
return True;
}
static void
make_menu_in_widget (widget_instance* instance, Widget widget,
widget_value* val)
{
widget_value* cur;
Widget button;
Arg al [256];
int ac;
String label;
for (cur = val; cur; cur = cur->next)
{
ac = 0;
XtSetArg (al [ac], XtNsensitive, cur->enabled); ac++;
XtSetArg (al [ac], XtNuserData, instance); ac++;
XtSetArg (al [ac], XtNacceleratorText, cur->key); ac++;
/* label = (char *) resource_string (widget, cur->name);*/
label = cur->name;
if (label)
{
XtSetArg (al [ac], XtNlabel, label); ac++;
}
if (all_dashes_p (cur->name))
{
/* no separator in OpenLook just make some space. */
XtSetArg (al [ac], XtNheight, 5); ac++;
XtSetArg (al [ac], XtNwidth, 5); ac++;
button = XtCreateWidget (cur->name, stubWidgetClass, widget, al, ac);
}
else if (!cur->contents)
{
if (!cur->call_data)
button =
XtCreateManagedWidget (cur->name, staticTextWidgetClass, widget,
al, ac);
else
{
button =
XtCreateManagedWidget (cur->name, oblongButtonWidgetClass,
widget, al, ac);
XtAddCallback (button, XtNselect, pick_hook, cur);
}
}
else
{
Widget menu = NULL;
button =
XtCreateManagedWidget (cur->name, menuButtonWidgetClass, widget,
al, ac);
XtVaGetValues (button, XtNmenuPane, &menu, 0);
if (!menu)
abort ();
make_menu_in_widget (instance, menu, cur->contents);
OlAddCallback (button, XtNconsumeEvent, pre_hook, instance);
}
}
}
static void
update_one_menu_entry (widget_instance* instance, Widget widget,
widget_value* val)
{
Arg al [256];
int ac;
Widget menu;
widget_value* contents;
if (val->change == NO_CHANGE)
return;
/* update the sensitivity */
XtVaSetValues (widget, XtNsensitive, val->enabled, 0);
/* update the pulldown/pullaside as needed */
ac = 0;
menu = NULL;
XtVaGetValues (widget, XtNmenuPane, &menu, 0);
contents = val->contents;
if (!menu)
{
if (contents)
{
/* in OLIT this would have to be a structural change on the
button. */
abort ();
}
}
else if (!contents)
{
/* in OLIT this would have to be a structural change on the button. */
abort ();
}
else if (contents->change != NO_CHANGE)
update_menu_widget (instance, menu, val);
}
static void
update_menu_widget (widget_instance* instance, Widget widget,
widget_value* val)
{
if (val->change == STRUCTURAL_CHANGE
|| val->contents->change == STRUCTURAL_CHANGE)
{
destroy_all_children (widget);
make_menu_in_widget (instance, widget, val->contents);
}
else
{
/* Update all the buttons of the composite widget in order. */
Widget* children;
unsigned int num_children;
int i;
widget_value* cur;
children = (Widget *) XtCompositeChildren (widget, &num_children);
if (children)
{
for (i = 0, cur = val->contents; i < num_children; i++)
{
if (!cur)
abort ();
if (children [i]->core.being_destroyed
|| strcmp (XtName (children [i]), cur->name))
continue;
update_one_menu_entry (instance, children [i], cur);
cur = cur->next;
}
XtFree (children);
}
if (cur)
abort ();
}
}
void
xol_update_one_widget (widget_instance* instance, Widget widget,
widget_value* val, Boolean deep_p)
{
Widget menu = widget;
if (XtIsShell (widget))
XtVaGetValues (widget, XtNmenuPane, &menu, 0);
update_menu_widget (instance, menu, val);
}
void
xol_update_one_value (widget_instance* instance, Widget widget,
widget_value* val)
{
return;
}
void
xol_pop_instance (widget_instance* instance, Boolean up)
{
}
void
xol_popup_menu (Widget widget)
{
OlMenuPost (widget);
}
/* Destruction of instances */
void
xol_destroy_instance (widget_instance* instance)
{
XtDestroyWidget (instance->widget);
}
|