-
Notifications
You must be signed in to change notification settings - Fork 88
/
Copy pathXmx2.c
499 lines (414 loc) · 16.9 KB
/
Xmx2.c
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
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
/****************************************************************************
* NCSA Mosaic for the X Window System *
* Software Development Group *
* National Center for Supercomputing Applications *
* University of Illinois at Urbana-Champaign *
* 605 E. Springfield, Champaign IL 61820 *
* *
* Copyright (C) 1993, Board of Trustees of the University of Illinois *
* *
* NCSA Mosaic software, both binary and source (hereafter, Software) is *
* copyrighted by The Board of Trustees of the University of Illinois *
* (UI), and ownership remains with the UI. *
* *
* The UI grants you (hereafter, Licensee) a license to use the Software *
* for academic, research and internal business purposes only, without a *
* fee. Licensee may distribute the binary and source code (if released) *
* to third parties provided that the copyright notice and this statement *
* appears on all copies and that no charge is associated with such *
* copies. *
* *
* Licensee may make derivative works. However, if Licensee distributes *
* any derivative work based on or derived from the Software, then *
* Licensee will (1) notify NCSA regarding its distribution of the *
* derivative work, and (2) clearly notify users that such derivative *
* work is a modified version and not the original NCSA Mosaic *
* distributed by the UI. *
* *
* Any Licensee wishing to make commercial use of the Software should *
* contact the UI, c/o NCSA, to negotiate an appropriate license for such *
* commercial use. Commercial use includes (1) integration of all or *
* part of the source code into a product for sale or license by or on *
* behalf of Licensee to third parties, or (2) distribution of the binary *
* code or source code to third parties that need it to utilize a *
* commercial product sold or licensed by or on behalf of Licensee. *
* *
* UI MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF THIS SOFTWARE FOR *
* ANY PURPOSE. IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED *
* WARRANTY. THE UI SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY THE *
* USERS OF THIS SOFTWARE. *
* *
* By using or copying this Software, Licensee agrees to abide by the *
* copyright law and all other applicable laws of the U.S. including, but *
* not limited to, export control laws, and the terms of this license. *
* UI shall have the right to terminate this license immediately by *
* written notice upon Licensee's breach of, or non-compliance with, any *
* of its terms. Licensee may be held legally responsible for any *
* copyright infringement that is caused or encouraged by Licensee's *
* failure to abide by the terms of this license. *
* *
* Comments and questions are welcome and can be sent to *
* [email protected]. *
****************************************************************************/
#include <stdlib.h>
#include "../config.h"
#include "XmxP.h"
/* ------------------------------------------------------------------------ */
/* --------------------------- PRIVATE ROUTINES --------------------------- */
/* ------------------------------------------------------------------------ */
/* ----------------------- _XmxMenuAddEntryToRecord ----------------------- */
/* Create a new MenuEntry and add it to the head of a MenuRecord list. */
private void
_XmxMenuAddEntryToRecord (XmxMenuRecord *rec, Widget w, int token)
{
XmxMenuEntry *_ent;
/* Create new menu entry. */
_ent = (XmxMenuEntry *)malloc (sizeof (XmxMenuEntry));
_ent->w = w;
_ent->token = token;
/* Add rest of list to tail of this entry. */
_ent->next = rec->first_entry;
/* Make this entry head of list. */
rec->first_entry = _ent;
return;
}
/* ---------------------- _XmxMenuGetEntryFromRecord ---------------------- */
private XmxMenuEntry *
_XmxMenuGetEntryFromRecord (XmxMenuRecord *rec, int token)
{
/* Given token, fetch the corresponding entry. */
XmxMenuEntry *_ent = NULL;
int _done;
/* Search the linked list. */
_ent = rec->first_entry;
_done = 0;
while (_ent != NULL && !_done)
{
if (_ent->token == token)
_done = 1;
else
_ent = _ent->next;
}
/* Punish the application for asking for a nonexistent entry. */
/* assert (_done); */
return _ent;
}
/* ------------------------- _XmxMenuCreateRecord ------------------------- */
/* Create a new MenuRecord and clear out its list. */
private XmxMenuRecord *
_XmxMenuCreateRecord (Widget base)
{
XmxMenuRecord *_rec;
/* Create the new XmxMenuRecord. */
_rec = (XmxMenuRecord *)malloc (sizeof (XmxMenuRecord));
_rec->base = base;
_rec->first_entry = NULL;
return _rec;
}
/* ------------------------------------------------------------------------ */
/* --------------------------- PUBLIC ROUTINES ---------------------------- */
/* ------------------------------------------------------------------------ */
/* --------------------------- XmxRSetSensitive --------------------------- */
/* args NOT used on Widget */
public void
XmxRSetSensitive (XmxMenuRecord *rec, int token, int state)
{
XmxMenuEntry *_entry;
assert (state == XmxSensitive || state == XmxUnsensitive);
_entry = _XmxMenuGetEntryFromRecord (rec, XmxExtractToken (token));
/* XtSetSensitive propagates down Widget hierarchy. */
if (_entry)
XtSetSensitive (_entry->w, (state == XmxSensitive) ? True : False);
return;
}
/* -------------------------- XmxRSetToggleState -------------------------- */
/* args not used */
public void
XmxRSetToggleState (XmxMenuRecord *rec, int token, int state)
{
XmxMenuEntry *_entry;
assert (state == XmxSet || state == XmxUnset);
_entry = _XmxMenuGetEntryFromRecord (rec, XmxExtractToken (token));
if (_entry)
XmToggleButtonGadgetSetState
(_entry->w, (state == XmxSet) ? True : False, False);
return;
}
/* ------------------------- XmxRUnsetAllToggles -------------------------- */
/* args not used */
public void
XmxRUnsetAllToggles (XmxMenuRecord *rec)
{
XmxMenuEntry *_ent;
for (_ent = rec->first_entry; _ent != NULL; _ent = _ent->next)
XmToggleButtonGadgetSetState
(_ent->w, False, False);
return;
}
/* ----------------------- XmxRSetOptionMenuHistory ----------------------- */
/* args used on Widget */
public void
XmxRSetOptionMenuHistory (XmxMenuRecord *rec, int token)
{
XmxMenuEntry *_entry;
_entry = _XmxMenuGetEntryFromRecord (rec, XmxExtractToken (token));
if (_entry)
{
XmxSetArg (XmNmenuHistory, (XtArgVal)(_entry->w));
XtSetValues (rec->base, Xmx_wargs, Xmx_n);
}
Xmx_n = 0;
return;
}
/* ---------------------------- XmxRSetValues ----------------------------- */
/* args used on Widget */
public void
XmxRSetValues (XmxMenuRecord *rec, int token)
{
XmxMenuEntry *_entry;
/* Strip out uniqid, if present. */
_entry = _XmxMenuGetEntryFromRecord (rec, XmxExtractToken (token));
if (_entry)
XtSetValues (_entry->w, Xmx_wargs, Xmx_n);
Xmx_n = 0;
return;
}
/* ---------------------------- XmxRGetWidget ----------------------------- */
/* args irrelevant */
public Widget
XmxRGetWidget (XmxMenuRecord *rec, int token)
{
XmxMenuEntry *_entry;
/* Strip out uniqid, if present. */
_entry = _XmxMenuGetEntryFromRecord (rec, XmxExtractToken (token));
if (_entry)
return _entry->w;
else
return NULL;
}
/* -------------------------- XmxRMakeOptionMenu -------------------------- */
/* args apply to pulldown menu */
public XmxMenuRecord *
XmxRMakeOptionMenu (Widget parent, String name, XtCallbackProc cb,
XmxOptionMenuStruct *opts)
{
XmxMenuRecord *_rec;
Widget _pulldown, _button, _menuhist = (Widget)NULL;
int _i;
/* Create a pulldown menupane to attach to the option menu;
preloaded wargs affect this. */
_pulldown = XmCreatePulldownMenu (parent, "pulldownmenu", Xmx_wargs, Xmx_n);
/* menuHistory will not be applied to _pulldown, so we'll modify
_rec directly after creating the option menu. */
_rec = _XmxMenuCreateRecord (_pulldown);
/* Create pushbutton gadgets as childen of the pulldown menu. */
_i = 0;
while (opts[_i].namestr)
{
Xmx_n = 0;
XmxSetArg (XmNlabelString,
(XtArgVal)XmStringCreateLtoR (opts[_i].namestr,
XmSTRING_DEFAULT_CHARSET));
_button = XmCreatePushButtonGadget (_pulldown, "pushbutton",
Xmx_wargs, Xmx_n);
XtManageChild (_button);
XtAddCallback (_button, XmNactivateCallback, cb,
(XtPointer)_XmxMakeClientData (opts[_i].data));
if (opts[_i].set_state == XmxSet)
_menuhist = _button;
_XmxMenuAddEntryToRecord (_rec, _button, opts[_i].data);
_i++;
}
/* Create the option menu itself; tie in the pulldown menu. */
Xmx_n = 0;
XmxSetArg (XmNsubMenuId, (XtArgVal)_pulldown);
if (_menuhist != (Widget)NULL)
XmxSetArg (XmNmenuHistory, (XtArgVal)_menuhist);
Xmx_w = XmCreateOptionMenu (parent, "optionmenu", Xmx_wargs, Xmx_n);
XtManageChild (Xmx_w);
XmxSetArg (XmNalignment, (XtArgVal)XmALIGNMENT_BEGINNING);
XmxSetValues (XmOptionButtonGadget (Xmx_w));
if (name)
{
XmxSetArg (XmNlabelString,
(XtArgVal)XmStringCreateLtoR (name, XmSTRING_DEFAULT_CHARSET));
XmxSetValues (XmOptionLabelGadget (Xmx_w));
}
else
{
XmxSetArg (XmNspacing, (XtArgVal)0);
XmxSetArg (XmNmarginWidth, (XtArgVal)0);
XmxSetValues (Xmx_w);
XmxSetArg (XmNlabelString, (XtArgVal)NULL);
XmxSetValues (XmOptionLabelGadget (Xmx_w));
}
/* Explicitly set base Widget of record. */
_rec->base = Xmx_w;
Xmx_n = 0;
return _rec;
}
/* -------------------------- XmxRMakeToggleMenu -------------------------- */
/* args apply to radiobox or optionbox */
public XmxMenuRecord *
XmxRMakeToggleMenu (Widget parent, int behavior, XtCallbackProc cb,
XmxToggleMenuStruct *opts)
{
XmxMenuRecord *_rec;
Widget _box;
int _i;
assert (behavior == XmxOneOfMany || behavior == XmxNOfMany);
switch (behavior)
{
case XmxOneOfMany:
_box = XmxMakeRadioBox (parent);
break;
case XmxNOfMany:
_box = XmxMakeOptionBox (parent);
break;
}
_rec = _XmxMenuCreateRecord (_box);
_i = 0;
while (opts[_i].namestr)
{
XmxMakeToggleButton (_box, opts[_i].namestr, cb, opts[_i].data);
XmxSetToggleButton (Xmx_w, opts[_i].set_state);
_XmxMenuAddEntryToRecord (_rec, Xmx_w, opts[_i].data);
_i++;
}
Xmx_w = _box;
Xmx_n = 0;
return _rec;
}
/* -------------------------- _XmxRCreateMenubar -------------------------- */
/* Possible deficiency: will not be able to grey out a submenu
(cascade button). */
private void
_XmxRCreateMenubar (Widget menu, XmxMenubarStruct *menulist,
XmxMenuRecord *rec)
{
int _i;
Widget *_buttons;
int _separators = 0, _nitems;
_nitems = 0;
while (menulist[_nitems].namestr)
_nitems++;
_buttons = (Widget *)XtMalloc (_nitems * sizeof (Widget));
for (_i = 0; _i < _nitems; _i++)
{
/* Name of "----" means make a separator. */
if (strcmp(menulist[_i].namestr, "----") == 0)
{
XtCreateManagedWidget ("separator", xmSeparatorGadgetClass,
menu, NULL, 0);
_separators++;
}
/* A function means it's an ordinary entry with callback. */
else if (menulist[_i].func)
{
Xmx_n = 0;
if (menulist[_i].mnemonic)
XmxSetArg (XmNmnemonic, (XtArgVal)(menulist[_i].mnemonic));
if (menulist[_i].namestr[0] == '#' ||
menulist[_i].namestr[0] == '<') /* option/toggle button */
{
XmString xmstr;
/* A toggle button is diamond-shaped. */
if (menulist[_i].namestr[0] == '<')
XmxSetArg (XmNindicatorType, (XtArgVal)XmONE_OF_MANY);
/* Make sure the button shows up even when toggled off. */
if (menulist[_i].namestr[0] == '#')
XmxSetArg (XmNvisibleWhenOff, (XtArgVal)True);
/* Ignore first character of label. */
xmstr = XmxMakeXmstrFromString (&(menulist[_i].namestr[1]));
XmxSetArg (XmNlabelString, (XtArgVal)xmstr);
_buttons[_i - _separators] = XtCreateManagedWidget
("togglebutton", xmToggleButtonGadgetClass,
menu, Xmx_wargs, Xmx_n);
XmStringFree (xmstr);
XtAddCallback
(_buttons[_i - _separators], XmNvalueChangedCallback,
menulist[_i].func,
(XtPointer)_XmxMakeClientData (menulist[_i].data));
/* Add thie button to the menu record. */
_XmxMenuAddEntryToRecord
(rec, _buttons[_i - _separators], menulist[_i].data);
}
else /* regular button */
{
XmString xmstr =
XmStringCreateLtoR
(menulist[_i].namestr, XmSTRING_DEFAULT_CHARSET);
XmxSetArg (XmNlabelString, (XtArgVal)xmstr);
_buttons[_i - _separators] = XtCreateManagedWidget
("pushbutton", xmPushButtonGadgetClass,
menu, Xmx_wargs, Xmx_n);
XmStringFree (xmstr);
XtAddCallback
(_buttons[_i - _separators], XmNactivateCallback,
menulist[_i].func,
(XtPointer)_XmxMakeClientData (menulist[_i].data));
/* Add thie button to the menu record. */
_XmxMenuAddEntryToRecord
(rec, _buttons[_i - _separators], menulist[_i].data);
}
}
/* No function and no submenu entry means it's just a label. */
else if (menulist[_i].sub_menu == (XmxMenubarStruct *)NULL)
{
Xmx_n = 0;
XmxSetArg (XmNlabelString, (XtArgVal)XmStringCreateLtoR
(menulist[_i].namestr, XmSTRING_DEFAULT_CHARSET));
_buttons[_i - _separators] = XtCreateManagedWidget
("label", xmLabelGadgetClass, menu, Xmx_wargs, Xmx_n);
}
/* If all else fails, it's a submenu. */
else
{
XmString xmstr;
Widget _sub_menu;
_sub_menu = XmCreatePulldownMenu (menu, "pulldownmenu", NULL, 0);
Xmx_n = 0;
XmxSetArg (XmNsubMenuId, (XtArgVal)_sub_menu);
if (menulist[_i].mnemonic)
XmxSetArg (XmNmnemonic, (XtArgVal)(menulist[_i].mnemonic));
xmstr = XmStringCreateLtoR
(menulist[_i].namestr, XmSTRING_DEFAULT_CHARSET);
XmxSetArg (XmNlabelString, (XtArgVal)xmstr);
_buttons[_i - _separators] = XtCreateWidget
("cascadebutton", xmCascadeButtonGadgetClass,
menu, Xmx_wargs, Xmx_n);
XmStringFree (xmstr);
/* If name is "Help", put on far right. */
if (strcmp (menulist[_i].namestr, "Help") == 0)
{
Xmx_n = 0;
XmxSetArg (XmNmenuHelpWidget, (XtArgVal)_buttons[_i - _separators]);
XtSetValues (menu, Xmx_wargs, Xmx_n);
}
/* Recursively create new submenu. */
_XmxRCreateMenubar (_sub_menu, menulist[_i].sub_menu, rec);
}
}
XtManageChildren (_buttons, _nitems - _separators);
XtFree ((char *)_buttons);
return;
}
/* --------------------------- XmxRMakeMenubar ---------------------------- */
/* args apply to menubar */
public XmxMenuRecord *
XmxRMakeMenubar (Widget parent, XmxMenubarStruct *mainmenu)
{
Widget _menubar;
XmxMenuRecord *_rec;
/* Preset resources applied to main menubar only. */
_menubar = XmCreateMenuBar (parent, "menubar", Xmx_wargs, Xmx_n);
XtManageChild (_menubar);
/* Create the new XmxMenuRecord. */
_rec = _XmxMenuCreateRecord (_menubar);
Xmx_n = 0;
_XmxRCreateMenubar (_menubar, mainmenu, _rec);
Xmx_n = 0;
Xmx_w = _menubar;
return _rec;
}