File: Menu.c

package info (click to toggle)
gridengine 6.2-4
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 51,532 kB
  • ctags: 51,172
  • sloc: ansic: 418,155; java: 37,080; sh: 22,593; jsp: 7,699; makefile: 5,292; csh: 4,244; xml: 2,901; cpp: 2,086; perl: 1,895; tcl: 1,188; lisp: 669; ruby: 642; yacc: 393; lex: 266
file content (1102 lines) | stat: -rwxr-xr-x 32,793 bytes parent folder | download | duplicates (3)
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
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
/* 
 * Motif Tools Library, Version 3.1
 * $Id$
 * 
 * Written by David Flanagan.
 * Copyright (c) 1992-2001 by David Flanagan.
 * All Rights Reserved.  See the file COPYRIGHT for details.
 * This is open source software.  See the file LICENSE for details.
 * There is no warranty for this software.  See NO_WARRANTY for details.
 *
 * $Log$
 * Revision 1.2  2008/02/13 14:35:05  andre
 * AA-2008-02-13-0: Bugfix.:   - jgdi client shall use SGE Daemon keystore for JMX ssl mode
 *                             - jmxeventmon support for SSL, eventmon script
 *                             - memory leaks qmon, cull
 *                  Changed:   jgdi, install scripts
 *                  Review:    RH
 *
 * Revision 1.1.1.1  2001/07/18 11:06:02  root
 * Initial checkin.
 *
 * Revision 1.2  2001/06/12 16:25:28  andre
 * *** empty log message ***
 *
 *
 */

#include <stdio.h>
#include <Xmt/XmtP.h>
#include <Xm/XmP.h>
#include <Xm/RowColumnP.h>
#include <Xm/MenuShellP.h>
#include <Xmt/MenuP.h>
#include <Xmt/Util.h>
#include <Xmt/ConvertersP.h>
#include <Xmt/Procedures.h>
#include <Xmt/Lexer.h>
#include <Xm/Separator.h>
#include <Xm/CascadeB.h>
#include <Xm/PushB.h>
#include <Xm/ToggleB.h>
#include <Xm/Label.h>

#if XmVersion >= 2000
#include <Xm/MenuT.h>
#endif
#if XmVersion >= 2001
#include <Xm/TraitP.h>
#endif

static XtResource resources[] = {
{XmtNitems, XmtCItems, XmtRXmtMenuItemList,
     sizeof(XmtMenuItem *), XtOffsetOf(XmtMenuRec, menu.items),
     XmtRXmtMenuItemList, NULL},
{XmtNnumItems, XmtCNumItems, XtRInt,
     sizeof(Cardinal), XtOffsetOf(XmtMenuRec, menu.num_items),
     XtRImmediate, (XtPointer) -1},
{XmtNacceleratorFontTag, XmtCAcceleratorFontTag, XtRString,
     sizeof(String), XtOffsetOf(XmtMenuRec, menu.accelerator_font_tag),
     XtRImmediate, NULL},
/* override RowCol default */
{XmNrowColumnType, XmCRowColumnType, XmRRowColumnType,
     sizeof(unsigned char), XtOffsetOf(XmtMenuRec, row_column.type),
     XtRImmediate, (XtPointer) XmMENU_BAR}
};

#if NeedFunctionPrototypes
static void ClassPartInitialize(WidgetClass);
static void Initialize(Widget, Widget, ArgList, Cardinal *);
static void Destroy(Widget);
#else
static void ClassPartInitialize();
static void Initialize();
static void Destroy();
#endif

#if XmVersion >= 1002

#if NeedFunctionPrototype
static void ClassInitialize(void);
#else
static void ClassInitialize();
#endif

/*
 * we purposely inherit the initialize prehook here, but not the
 * the initialize posthook.  The posthook scheme is buggy and does
 * not allow recursive creations of submenus.  So instead, we undo
 * what the prehook did explicitly in our Initialize() method.  It is
 * okay that this is not done strictly at the "leaf class", because the
 * prehook really only affects translations which are handled early on,
 * in core class or somewhere.  See the comments in Initialize() for
 * more info.
 */
static XmBaseClassExtRec       baseClassExtRec = {
    NULL,                                     /* Next extension       */
    NULLQUARK,                                /* record type XmQmotif */
    XmBaseClassExtVersion,                    /* version              */
    sizeof(XmBaseClassExtRec),                /* size                 */
    XmInheritInitializePrehook,               /* initialize prehook   */
    XmInheritSetValuesPrehook,                /* set_values prehook   */
    NULL,                                     /* initialize posthook  */
    XmInheritSetValuesPosthook,               /* set_values posthook  */
    XmInheritClass,                           /* secondary class      */
    XmInheritSecObjectCreate,                 /* creation proc        */
    XmInheritGetSecResData,                   /* getSecResData        */
    {0},                                      /* fast subclass        */
    XmInheritGetValuesPrehook,                /* get_values prehook   */
    XmInheritGetValuesPosthook,               /* get_values posthook  */
    NULL,                                     /* classPartInitPrehook */
    NULL,                                     /* classPartInitPosthook*/
    NULL,                                     /* ext_resources        */
    NULL,                                     /* compiled_ext_resources*/
    0,                                        /* num_ext_resources    */
    FALSE,                                    /* use_sub_resources    */
    XmInheritWidgetNavigable,                 /* widgetNavigable      */
    XmInheritFocusChange,                     /* focusChange          */
};

static XmManagerClassExtRec managerClassExtRec = {
    NULL,
    NULLQUARK,
    XmManagerClassExtVersion,
    sizeof(XmManagerClassExtRec),
    XmInheritTraversalChildrenProc,
};
#endif

externaldef(xmtmenuclassrec) XmtMenuClassRec xmtMenuClassRec = {
  { /* core fields */
    /* superclass		*/	(WidgetClass) &xmRowColumnClassRec,
    /* class_name		*/	"XmtMenu",
    /* widget_size		*/	sizeof(XmtMenuRec),
#if XmVersion >= 1002
    /* class_initialize		*/	ClassInitialize,
#else					
    /* class_initialize		*/	NULL,
#endif
    /* class_part_initialize	*/	ClassPartInitialize,
    /* class_inited		*/	FALSE,
    /* initialize		*/	Initialize,
    /* initialize_hook		*/	NULL,
    /* realize			*/	XtInheritRealize,
    /* actions			*/	NULL,
    /* num_actions		*/	0,
    /* resources		*/	resources,
    /* num_resources		*/	XtNumber(resources),
    /* xrm_class		*/	NULLQUARK,
    /* compress_motion		*/	TRUE,
    /* compress_exposure	*/	XtExposeCompressMaximal,
    /* compress_enterleave	*/	FALSE,
    /* visible_interest		*/	FALSE,
    /* destroy			*/	Destroy,
    /* resize			*/	XtInheritResize,
    /* expose			*/	XtInheritExpose,
    /* set_values		*/	NULL,
    /* set_values_hook		*/	NULL,
    /* set_values_almost	*/	XtInheritSetValuesAlmost,
    /* get_values_hook		*/	NULL,
    /* accept_focus		*/	XtInheritAcceptFocus,
    /* version			*/	XtVersion,
    /* callback_private		*/	NULL,
    /* tm_table			*/	XtInheritTranslations,
    /* query_geometry		*/	XtInheritQueryGeometry,
    /* display_accelerator	*/	XtInheritDisplayAccelerator,
#if XmVersion >= 1002
    /* extension		*/	(XtPointer)&baseClassExtRec,
#else
    /* extension		*/	NULL,
#endif
  },
  { /* composite_class fields */
    /* geometry_manager   */    XtInheritGeometryManager,
    /* change_managed     */    XtInheritChangeManaged,
    /* insert_child       */    XtInheritInsertChild,
    /* delete_child       */    XtInheritDeleteChild,
    /* extension          */    NULL
  },
  { /* constraint_class fields */
    /* resource list 	  */    NULL,
    /* num resources	  */    0,
    /* constraint size    */    sizeof(XmRowColumnConstraintRec),
    /* init proc	  */    NULL,
    /* destroy proc       */    NULL,
    /* set values proc    */    NULL,
    /* extension 	  */    NULL
  },
  { /* manager_class	  */
    /* translations 	  */    XtInheritTranslations,
    /* syn_resources	  */	NULL,
    /* num_syn_resources  */	0,
    /* syn_cont_resources */	NULL,
    /* num_syn_cont_resources */0,
    /* parent_process     */    XmInheritParentProcess,
#if XmVersion >= 1002
    /* extension	  */	(XtPointer)&managerClassExtRec
#else				
    /* extension	  */	NULL
#endif	
  },
  { /* row column class record        */
    /* proc to interface with widgets */   XmInheritMenuProc,
    /* proc to arm&activate menu      */   XmInheritArmAndActivate,
    /* traversal handler              */   XmInheritMenuTraversalProc,
    /* extension                      */   NULL,
  },
  { /* XmtMenuClassPart */
    /* extension          */ NULL
  }
};

externaldef(xmtmenuwidgetclass)
WidgetClass xmtMenuWidgetClass = (WidgetClass)&xmtMenuClassRec;

#if XmVersion == 2000
/* Traits Declarations */
extern XmMenuSystemTraitRec _XmRC_menuSystemRecord;
#endif


/*
 * a macro for extracting the type bits from the type field of a menu item
 */
#define GetType(item) ((item)->type & 0x07)


#if XmVersion >= 1002

#if NeedFunctionPrototypes
static void ClassInitialize(void)
#else
static void ClassInitialize()
#endif
{
    baseClassExtRec.record_type = XmQmotif;

#if XmVersion == 2000
    /* Trait records */
    XmeTraitSet((XtPointer) xmtMenuWidgetClass, XmQTmenuSystem,
                (XtPointer) &_XmRC_menuSystemRecord);
#endif
#if XmVersion >= 2001
    /* Trait records */
    XmeTraitSet((XtPointer) xmtMenuWidgetClass, XmQTmenuSystem,
                XmeTraitGet ((XtPointer) xmRowColumnWidgetClass,
			     XmQTmenuSystem));
#endif
}

#endif

#if NeedFunctionPrototypes
static void ClassPartInitialize(WidgetClass subclass)
#else
static void ClassPartInitialize(subclass)
WidgetClass subclass;
#endif
{
    XmtMenuWidgetClass sub = (XmtMenuWidgetClass)subclass;
    XmtMenuWidgetClass super = (XmtMenuWidgetClass) sub->core_class.superclass;

    /*
     * the XmtMenu widget doesn't have any class fields that need
     * inheritance, but the XmRowColumn does, and that widget does not
     * handle the inheritance itself.  So we do it here.
     */
#define inherit(field) \
    if ((XtProc)sub->field == _XtInherit) sub->field = super->field

     inherit(row_column_class.menuProcedures);
     inherit(row_column_class.armAndActivate);
     inherit(row_column_class.traversalHandler);

#undef inherit    
}


/* ARGSUSED */
#if NeedFunctionPrototypes
static void UpdateWidget(XmtSymbol s, XtPointer tag, XtArgVal value)
#else
static void UpdateWidget(s, tag, value)
XmtSymbol s;
XtPointer tag;
XtArgVal value;
#endif
{
    XmtMenuItem *item = (XmtMenuItem *)tag;

    /*
     * When the user changes the widget, the callback below will change
     * the symbol, and this callback will get called, and will go change
     * the widget again.  But it changes the widget to the same value,
     * and with notify False, it does not call the callbacks again, so
     * it is okay.  
     */
    XmToggleButtonSetState(item->w, value, False);
    if (value)
	item->type |= XmtMenuItemOn;
    else
	item->type &= ~XmtMenuItemOn;
}


/* ARGSUSED */
#if NeedFunctionPrototypes
static void ToggleCallback(Widget w, XtPointer tag, XtPointer data)
#else
static void ToggleCallback(w, tag, data)
Widget w;
XtPointer tag;
XtPointer data;
#endif
{
    XmtMenuItem *item = (XmtMenuItem *)tag;
    XmToggleButtonCallbackStruct *tbcs = (XmToggleButtonCallbackStruct *)data;
    
    /* remember the current state */
    if (tbcs->set)
	item->type |= XmtMenuItemOn;
    else
	item->type &= ~XmtMenuItemOn;

    /*
     * if the toggle has a symbol, update the symbol.
     */
    if (item->symbol) {
	XmtSymbolSetValue(item->symbol, (XtArgVal)tbcs->set);
    }

    /*
     * if there is an alternate string (not a pixmap), add a callback
     * to switch strings  when the state changes.
     */
    if (item->alt_label && !(item->type & XmtMenuItemPixmap)) 
	XtVaSetValues(item->w,
		     XmNlabelString, (tbcs->set)?item->label1:item->label0,
		     XmNmnemonic,(tbcs->set)?item->alt_mnemonic:item->mnemonic,
		     NULL);
}

#if NeedFunctionPrototypes
static void CreateMenuItems(Widget w, XmtMenuItem *items, Cardinal num_items)
#else
static void CreateMenuItems(w, items, num_items)
Widget w;
XmtMenuItem *items;
Cardinal num_items;
#endif
{
    XmtMenuWidget mw = (XmtMenuWidget) w;
    XmtMenuItem *item;
    Arg args[10], submenu_args[10];
    int n, m;
    XmString accel_label = NULL;
    char namebuf[20], submenu_buf[20];
    char *name, *submenu_name;
    int numlabel, numpush, numtoggle, numsep, numsub;
    int i;
    static XrmQuark QBoolean = NULLQUARK;

    if (QBoolean == NULLQUARK) QBoolean = XrmPermStringToQuark(XtRBoolean);
    
    numlabel = numpush = numtoggle = numsep = numsub = 0;

    for(i=0; i < num_items; i++) {
	n = 0;
	item = &items[i];

	/* XXX
	 * We should do some error checking here.  A cascade button
	 * shouldn't have accelerators, for example, and a non-cascade
	 * button shouldn't have the help flag set, and there are probably
	 * more.
	 */

	switch(GetType(item)) {
	case XmtMenuItemLabel:
	    sprintf(namebuf, "label%d", numlabel);  numlabel++; break;
	case XmtMenuItemPushButton:
	    sprintf(namebuf, "button%d", numpush); numpush++; break;
	case XmtMenuItemToggleButton:
	    sprintf(namebuf, "toggle%d", numtoggle); numtoggle++; break;
	case XmtMenuItemCascadeButton:
	    sprintf(namebuf, "cascade%d", numsub); numsub++; break;
	case XmtMenuItemSeparator:
	case XmtMenuItemDoubleSeparator:
	    sprintf(namebuf, "separator%d", numsep); numsep++; break;
	}
	
	if (item->name) name = item->name;
	else name = namebuf;

	/* if there is a symbol name, bind it and get the initial state */
	if ((item->symbol_name) && (GetType(item) == XmtMenuItemToggleButton)){
	    Boolean state;
	    /*  XXX
	     * we should register a callback to free these symbols if
	     * the toggle buttons are destroyed.
	     */
	    item->symbol = XmtLookupSymbol(item->symbol_name);
	    if (!item->symbol ||
		(XmtSymbolTypeQuark(item->symbol) != QBoolean)) {
		XmtWarningMsg("XmtMenu", "symbolType",
			      "item '%s': symbol '%s' undefined or not of type Boolean",
			      item->label, item->symbol_name);
		item->symbol_name = NULL;
		item->symbol = NULL;
	    }
	    else {
		XmtSymbolGetValue(item->symbol, (XtArgVal *)&state);
		if (state) item->type |= XmtMenuItemOn;
		else item->type &= ~XmtMenuItemOn;
	    }
	}

	/*
	 * if there is an alternate label, and this is a toggle button,
	 * create the alternate XmString or pixmap
	 */
	if (item->alt_label && (GetType(item) == XmtMenuItemToggleButton)) {
	    if (item->type & XmtMenuItemPixmap) {
		XrmValue from, to;

		from.addr = item->alt_label;
		from.size = strlen(item->label) + 1;
		to.addr =(XPointer) &item->label1;
		to.size = sizeof(Pixmap);
		item->label1 = (XmString)XmUNSPECIFIED_PIXMAP;
		XtConvertAndStore(w, XtRString, &from, XtRPixmap, &to);
	    }
	    else item->label1 = XmtCreateLocalizedXmString(w, item->alt_label);
	}

	/* if there is a normal label, create the XmString or pixmap */
	if (item->label) {
	    if (item->type & XmtMenuItemPixmap) {
		XrmValue from, to;

		from.addr = item->label;
		from.size = strlen(item->label) + 1;
		to.addr =(XPointer) &item->label0;
		to.size = sizeof(Pixmap);
		item->label0 = (XmString)XmUNSPECIFIED_PIXMAP;
		XtConvertAndStore(w, XtRString, &from, XtRPixmap, &to);
	    }
	    else item->label0 = XmtCreateLocalizedXmString(w, item->label);
	}

	/*
	 * if this is a toggle button w/ an alternate string and mnemonic,
	 * set whichever is appopriate for the initial state.  Otherwise,
	 * just set the normal one.
	 * Also, for toggle buttons with two labels, turn the indicator off.
	 */
	if (item->alt_label && (GetType(item) == XmtMenuItemToggleButton)) {
	    XtSetArg(args[n], XmNindicatorOn, False); n++;
	    if (item->type & XmtMenuItemPixmap) {
		XtSetArg(args[n], XmNlabelType, XmPIXMAP); n++;
		XtSetArg(args[n], XmNlabelPixmap, item->label0); n++;
		XtSetArg(args[n], XmNselectPixmap, item->label1); n++;
	    }
	    else {
		XtSetArg(args[n], XmNlabelString,
			 (item->type&XmtMenuItemOn)?item->label1:item->label0);
		n++;
		XtSetArg(args[n], XmNmnemonic, (item->type&XmtMenuItemOn)
			 ?item->alt_mnemonic
			 :item->mnemonic);
		n++;
	    }
	}
	else {
	    if (item->type & XmtMenuItemPixmap) {
		XtSetArg(args[n], XmNlabelType, XmPIXMAP); n++;
		XtSetArg(args[n], XmNlabelPixmap, item->label0); n++;
	    }
	    else {
		XtSetArg(args[n], XmNlabelString, item->label0); n++;
		XtSetArg(args[n], XmNmnemonic, item->mnemonic); n++;
	    }
	}

	if (item->accelerator_label) {
	    if (mw->menu.accelerator_font_tag)
		accel_label = XmStringCreate(item->accelerator_label,
					     mw->menu.accelerator_font_tag);
	    else
		accel_label = XmStringCreateSimple(item->accelerator_label);
	    XtSetArg(args[n], XmNacceleratorText, accel_label); n++;
	}

	if (item->accelerator) {
	    XtSetArg(args[n], XmNaccelerator, item->accelerator); n++;
	}

	switch (GetType(item)) {
	case XmtMenuItemLabel:
	    item->w = XmCreateLabel(w, name, args, n);
	    break;
	case XmtMenuItemDoubleSeparator:
	    XtSetArg(args[n], XmNseparatorType, XmDOUBLE_LINE); n++;
	case XmtMenuItemSeparator:
	    item->w = XmCreateSeparator(w, name, args, n);
	    break;
	case XmtMenuItemPushButton:
	    item->w = XmCreatePushButton(w, name, args, n);
	    if (item->callback) {
		if (item->type & XmtMenuItemCallbackList)
		    XtAddCallbacks(item->w, XmNactivateCallback,
				   (XtCallbackList)item->callback);
		else
		    XtAddCallback(item->w, XmNactivateCallback,
				  item->callback, item->client_data);
	    }
	    break;
	case XmtMenuItemToggleButton:
	    XtSetArg(args[n], XmNset, (item->type&XmtMenuItemOn)?True:False);
	    n++;
	    item->w = XmCreateToggleButton(w, name, args, n);

	    /*
	     * Add a callback to track the button state and do other
	     * housekeeping.
	     */
	    XtAddCallback(item->w, XmNvalueChangedCallback,
			  ToggleCallback, (XtPointer)item);

	    /* Add any programmer specified callbacks */
	    if (item->callback) {
		if (item->type & XmtMenuItemCallbackList)
		    XtAddCallbacks(item->w, XmNvalueChangedCallback,
				   (XtCallbackList)item->callback);
		else
		    XtAddCallback(item->w, XmNvalueChangedCallback,
				  item->callback, item->client_data);
	    }

	    /*
	     * if the item has a symbol, add a callback to be notifed
	     * when the symbol value changes under us.  Note that
	     * ToggleCallback handles updating the symbol when the
	     * toggle changes
	     */
	    if (item->symbol) {
		XmtSymbolAddCallback(item->symbol,
				     UpdateWidget, (XtPointer) item);
	    }
	    break;
	case XmtMenuItemCascadeButton:
	    m = 0;
	    if (item->submenu) {
		XtSetArg(submenu_args[m], XmtNitems, item->submenu); m++;
		sprintf(submenu_buf, "item%d_pane", i);
		submenu_name = submenu_buf;
	    }
	    else if (item->submenu_name) {
		submenu_name = item->submenu_name;
	    }
	    else {
		submenu_name = NULL;
		XmtWarningMsg("XmtMenu", "noSubmenu",
			      "no submenu specified for menu item %s",
			      item->label);
	    }

	    if (submenu_name) {
		XtSetArg(submenu_args[m],XmNrowColumnType,XmMENU_PULLDOWN);m++;
		if (item->type & XmtMenuItemTearoff) {
#if XmVersion >= 1002
		    XtSetArg(submenu_args[m],
			     XmNtearOffModel, XmTEAR_OFF_ENABLED);
		    m++;
#else
		    XmtWarningMsg("XmtMenu", "tearoff",
		  "item '%s': tearoff menus not supported prior to Motif 1.2",
				  item->label);
#endif		    
		}
		item->submenu_pane = XmtCreateMenuPane(w, submenu_name,
						       submenu_args, m);
		XtSetArg(args[n], XmNsubMenuId, item->submenu_pane); n++;
		if (item->submenu == NULL)
		    item->submenu =
			((XmtMenuWidget)item->submenu_pane)->menu.items;
	    }
	    item->w = XmCreateCascadeButton(w, name, args, n);
	    break;
	default:  /* an error */
	    break;
	}

	XtManageChild(item->w);

	if ((GetType(item) == XmtMenuItemCascadeButton) &&
	    (item->type & XmtMenuItemHelp))
	    XtVaSetValues(w, XmNmenuHelpWidget, item->w, NULL);

	/* free the XmStrings */
	if (item->label
	    && !(item->alt_label && (GetType(item) == XmtMenuItemToggleButton))
	    && !(item->type & XmtMenuItemPixmap))
	    XmStringFree(item->label0);
	if (item->accelerator_label)
	    XmStringFree(accel_label);
    }
}

    
/*ARGSUSED*/
#if NeedFunctionPrototypes
static void Initialize(Widget request, Widget init,
		       ArgList args, Cardinal *num_args)
#else
static void Initialize(request, init, args, num_args)
Widget request;
Widget init;
ArgList args;
Cardinal *num_args;
#endif
{
    XmtMenuWidget w = (XmtMenuWidget)init;
    int i;

#if XmVersion >= 1002
    /*
     * In Motif 1.2, the first thing we do is restore our core_class
     * translations field, which was munged by the initialize prehook
     * method we inherited (in the base class extension record) from
     * the XmRowColumn.  This restore would normally be done by a
     * corresponding posthook method, but we purposely did not inherit
     * that posthook, because if we have a posthook, then we cannot
     * recursively create submenus (as we need to do) -- the post hook
     * does not get restored soon enough, and the recursive creations
     * are done without ever calling this initialize procedure.
     */
#if NeedFunctionPrototypes
    extern void _XmRestoreCoreClassTranslations(Widget);
#else    
    extern void _XmRestoreCoreClassTranslations();
#endif
    _XmRestoreCoreClassTranslations(init);
#endif    
    
    /*
     * Copy the XmtNacceleratorFontTag string.  The only reason we have
     * to do this is so that programmers can query that resource.
     */
    if (w->menu.accelerator_font_tag)
	w->menu.accelerator_font_tag =
	    XtNewString(w->menu.accelerator_font_tag);

    if (w->menu.items != NULL) {
    /*
     * The items resource may be NULL terminated at this point, or it may
     * not be.  If num_items is -1 (ie. unspecified) then it had better be
     * NULL-terminated.  The resource converter delivers a NULL-terminated
     * array, but most programmers will probably use counted arrays.  It is
     * also possible that items is NULL-terminated at less than num_items.
     * So figure out num_items.  Note that NULL-terminated in this case
     * means that the type field is XmtMenuItemEnd.
     */
	if (w->menu.num_items == -1) {
	    /* if unspecified look for a NULL */
	    for(i=0; GetType(&w->menu.items[i]) != XmtMenuItemEnd; i++);
	    w->menu.num_items = i;
	}
	else {
	    /* if specified, look for a NULL anyway */
	    for(i=0;
		i<w->menu.num_items &&
		  GetType(&w->menu.items[i])!=XmtMenuItemEnd;
		i++);
	    w->menu.num_items = i;
	}
    }
    else {/* if no items are specified */
	w->menu.num_items = 0;
	XmtWarningMsg("XmtMenu", "noItems",
		      "no items specified for widget %s",
		      XtName(init));
    }
    
    CreateMenuItems(init, w->menu.items, w->menu.num_items);
}

#if NeedFunctionPrototypes
static void Destroy(Widget w)
#else
static void Destroy(w)
Widget w;
#endif
{
    XmtMenuWidget mw = (XmtMenuWidget)w;

    XtFree(mw->menu.accelerator_font_tag);
}

#if NeedFunctionPrototypes
Widget XmtCreateMenubar(Widget w, String name,
			ArgList args, Cardinal num_args)
#else
Widget XmtCreateMenubar(w, name, args, num_args)
Widget w;
String name;
ArgList args;
Cardinal num_args;
#endif
{
    return XtCreateWidget(name, xmtMenuWidgetClass, w, args, num_args);
}

#if NeedFunctionPrototypes
static Widget CreateMenuPane(Widget w, String name,
		      ArgList args, Cardinal num_args, int type)
#else
static Widget CreateMenuPane(w, name, args, num_args, type)
Widget w;
String name;
ArgList args;
Cardinal num_args;
int type;
#endif
{
    ArgList pane_args, shell_args;
    Cardinal pane_num_args, shell_num_args;
    Arg new_args[10];
    String shell_name;
    Widget parent, popup, shell = NULL;
    Widget menu;
    int i, n;
    
    /*
     * if this menu pane is a submenu of a pulldown or a popup menu, then
     * the programmer probably passed the rowcol as the parent widget.  What
     * we really want is the menu shell that is the parent of that rowcol.
     * This is kludgy, but it is what the Motif XmCreatePulldownMenu() does.
     */
    if (XtParent(w) && XmIsMenuShell(XtParent(w)))
	parent = XtParent(w);
    else
	parent = w;
    
    /*
     * Now we need a menu shell.  A menubar or menupane with multiple
     * submenus need only have a single menu shell child, because only
     * one submenu can be popped up at a time.  Therefore, before we
     * go create a menu shell, we go see if one already exists as a popup
     * child of our parent.  We only make this check if the supplied parent
     * widget is a menubar or a menupane. Again, this is what Motif does.
     */
    if (XmIsRowColumn(w) &&
	((((XmRowColumnWidget)w)->row_column.type == XmMENU_BAR) ||
	 (((XmRowColumnWidget)w)->row_column.type == XmMENU_PULLDOWN) ||
	 (((XmRowColumnWidget)w)->row_column.type == XmMENU_POPUP))) {
	/* XXX
	 * Motif does the above test, which effectively means that popup
	 * menus never share shells.  I don't know if it is really needed.
	 */
	for (i = 0; i < parent->core.num_popups; i++) {
	    popup = parent->core.popup_list[i];
	    if (XmIsMenuShell(popup) && !popup->core.being_destroyed &&
		((XmMenuShellWidget)popup)->menu_shell.private_shell) {
		shell = popup;
		break;
	    }
	}
    }

    /*
     * if we can't share a shell, create one, and mark it as sharable.
     * We use the same shell naming convention as Motif does.
     */
    if (!shell) {
	/* put together a new arg list */
	n = 0;
	XtSetArg(new_args[n], XmNwidth, 5); n++;
	XtSetArg(new_args[n], XmNheight, 5); n++;
	XtSetArg(new_args[n], XmNallowShellResize, True); n++;
	XtSetArg(new_args[n], XmNoverrideRedirect, True); n++;
	shell_args = XtMergeArgLists(args, num_args, new_args, n);
	shell_num_args = num_args + n;
		     
	/* put together the new name */
	shell_name = XtMalloc(strlen(name) + 7);
	sprintf(shell_name, "popup_%s", name);

	/* create the shell */
	shell = XmCreateMenuShell(parent, shell_name,
				  shell_args, shell_num_args);

	/* free the name and arglist */
	XtFree(shell_name);
	XtFree((char *)shell_args);

	/* mark shell to allow sharing */
	((XmMenuShellWidget)shell)->menu_shell.private_shell = True;
    }

    /*
     * The default type of an XmtMenu widget is MENU_BAR.  We need to
     * explictly specify that this one is a pulldown or popup type.
     */
    n = 0;
    XtSetArg(new_args[n], XmNrowColumnType, type); n++;
    pane_args = XtMergeArgLists(args, num_args, new_args, n);
    pane_num_args = num_args + n;

    /* finally, create the menu */
    menu = XtCreateWidget(name, xmtMenuWidgetClass, shell,
			  pane_args, pane_num_args);

    /* and free the allocated arglist */
    XtFree((char *) pane_args);

    return menu;
}

#if NeedFunctionPrototypes
Widget XmtCreateMenuPane(Widget w, String name,
			 ArgList args, Cardinal num_args)
#else
Widget XmtCreateMenuPane(w, name, args, num_args)
Widget w;
String name;
ArgList args;
Cardinal num_args;
#endif
{
    return CreateMenuPane(w, name, args, num_args, XmMENU_PULLDOWN);
}

/* ARGSUSED */
#if NeedFunctionPrototypes
void XmtMenuPopupHandler(Widget w, XtPointer data, XEvent *event,Boolean *cont)
#else
void XmtMenuPopupHandler(w, data, event, cont)
Widget w;
XtPointer data;
XEvent *event;
Boolean *cont;
#endif
{
    XmtMenuWidget menu = (XmtMenuWidget) data;
    XButtonPressedEvent *e = (XButtonPressedEvent *)event;
    int state;

    /* mask buttons out of modifiers/buttons state */
    state = e->state & (ShiftMask | ControlMask | LockMask | Mod1Mask |
			Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask);

    if ((e->button == RC_PostButton(menu)) &&
	((state == RC_PostModifiers(menu)) ||
	 (RC_PostModifiers(menu) == AnyModifier))) {
	XmMenuPosition((Widget)menu, e);
	XtManageChild((Widget)menu);
    }
}

#if NeedFunctionPrototypes
Widget XmtCreatePopupMenu(Widget w, String name,
			  ArgList args, Cardinal num_args)
#else
Widget XmtCreatePopupMenu(w, name, args, num_args)
Widget w;
String name;
ArgList args;
Cardinal num_args;
#endif
{
    Widget menu;

    menu = CreateMenuPane(w, name, args, num_args, XmMENU_POPUP);
    XtAddEventHandler(w, ButtonPressMask,
		      False, XmtMenuPopupHandler, (XtPointer)menu);
    return menu;
}

#if NeedFunctionPrototypes
Widget XmtCreateOptionMenu(Widget w, String name,
			   ArgList args, Cardinal num_args)
#else
Widget XmtCreateOptionMenu(w, name, args, num_args)
Widget w;
String name;
ArgList args;
Cardinal num_args;
#endif
{
    Widget pane;
    Widget option;
    String pane_name;

    /* XXX
     * This is sort of a bad convenience routine.  It returns an XmRowColumn,
     * rather than an XmMenu widget.  It passes the same arglist to both
     * creation routines, and because they are similar widgets, there could
     * be arguments that are only intended for one.
     */

    pane_name = XtMalloc(strlen(name) + 6);
    sprintf(pane_name, "%s_pane", name);
    pane = XmtCreateMenuPane(w, pane_name, args, num_args);
    XtFree(pane_name);
    
    option = XmCreateOptionMenu(w, (String)name, args, num_args);
    XtVaSetValues(option, XmNsubMenuId, pane, NULL);
    return option;
}


#if NeedFunctionPrototypes
Widget XmtMenuItemGetSubmenu(XmtMenuItem *item)
#else
Widget XmtMenuItemGetSubmenu(item)
XmtMenuItem *item;
#endif
{
    if (GetType(item) != XmtMenuItemCascadeButton) {
	XmtWarningMsg("XmtMenuItemGetSubmenu", "typeMismatch",
		      "specified item is not a cascade button.");
	return NULL;
    }
    else
	return item->submenu_pane;
}

#if NeedFunctionPrototypes
Widget XmtMenuItemGetWidget(XmtMenuItem *item)
#else
Widget XmtMenuItemGetWidget(item)
XmtMenuItem *item;
#endif
{
    return item->w;
}

#if NeedFunctionPrototypes
Boolean XmtMenuItemGetState(XmtMenuItem *item)
#else
Boolean XmtMenuItemGetState(item)
XmtMenuItem *item;
#endif
{
    if (GetType(item) != XmtMenuItemToggleButton) {
	XmtWarningMsg("XmtMenuItemGetState", "typeMismatch",
		      "specified item is not a toggle button.");
	return False;
    }
    else return ((item->type & XmtMenuItemOn) != 0);
}

#if NeedFunctionPrototypes
void XmtMenuItemSetState(XmtMenuItem *item, XmtWideBoolean state,
			 XmtWideBoolean notify)
#else
void XmtMenuItemSetState(item, state, notify)
XmtMenuItem *item;
int state;
int notify;
#endif
{
    if (GetType(item) != XmtMenuItemToggleButton) {
	XmtWarningMsg("XmtMenuItemSetState", "typeMismatch",
		      "specified item is not a toggle button.");
    }
    else {
	if (item->w)
	    XmToggleButtonSetState(item->w, state, notify);
	if (state) item->type |= XmtMenuItemOn;
	else item->type &= ~XmtMenuItemOn;
    }
}

#if NeedFunctionPrototypes
void XmtMenuItemSetSensitivity(XmtMenuItem *item, XmtWideBoolean sensitive)
#else
void XmtMenuItemSetSensitivity(item, sensitive)
XmtMenuItem *item;
int sensitive;
#endif
{
    if (sensitive) {
	if (item->sensitive == 0)  /* if already sensitive */
	    return;
	item->sensitive--;
	if ((item->sensitive == 0) && (item->w))  /* if newly sensitive */
	    XtSetSensitive(item->w, True);
    }
    else {
	if ((item->sensitive == 0) && item->w)  /* if currently sensitive */
	    XtSetSensitive(item->w, False);
	item->sensitive++;
    }
}

#if NeedFunctionPrototypes
static XmtMenuItem *GetMenuItem(XmtMenuWidget mw, XrmName quark)
#else
static XmtMenuItem *GetMenuItem(mw, quark)
XmtMenuWidget mw;
XrmName quark;
#endif
{
    int i;
    XmtMenuItem *item, *subitem;

    /*
     * check each of the items in the menu.
     * Note that we use the widget name rather than item->name, because
     * comparing quarks is faster.
     */
    for(i=0; i < mw->menu.num_items; i++) {
	item = &mw->menu.items[i];
	if (item->w && (item->w->core.xrm_name == quark))
	    return item;
    }

    /* if no item matched, recursively check any submenus */
    for(i=0; i < mw->menu.num_items; i++) {
	item = &mw->menu.items[i];
	if (GetType(item) == XmtMenuItemCascadeButton) {
	    subitem = GetMenuItem((XmtMenuWidget)item->submenu_pane, quark);
	    if (subitem) return subitem;
	}
    }

    /* if no subitem matched, give up */
    return NULL;
}


#if NeedFunctionPrototypes
XmtMenuItem *XmtMenuGetMenuItem(Widget w, StringConst name)
#else
XmtMenuItem *XmtMenuGetMenuItem(w, name)
Widget w;
StringConst name;
#endif
{
    XmtMenuWidget mw = (XmtMenuWidget) w;
    XmtMenuItem *item;
    
    XmtAssertWidgetClass(w, xmtMenuWidgetClass, "XmtMenuGetMenuItem");
    item = GetMenuItem(mw, XrmStringToQuark(name));
    return item;
}

#if NeedFunctionPrototypes
static void CheckSensitivity(Widget w, XtCallbackProc proc, Boolean sensitive)
#else
static void CheckSensitivity(w, proc, sensitive)
Widget w;
XtCallbackProc proc;
Boolean sensitive;
#endif
{
    XmtMenuWidget mw = (XmtMenuWidget) w;
    XmtMenuItem *item;
    int i;

    if (!mw) return;
    
    for(i=0; i < mw->menu.num_items; i++) {
	item = &mw->menu.items[i];
	if (GetType(item) == XmtMenuItemCascadeButton)
	    CheckSensitivity(item->submenu_pane, proc, sensitive);
	else {
	    if (((item->type & XmtMenuItemCallbackList) &&
		 (XmtCallbackCheckList((XtCallbackList) item->callback,
				       (XmtProcedure) proc))) ||
		(!(item->type & XmtMenuItemCallbackList) &&
		 (item->callback == proc)))
		XmtMenuItemSetSensitivity(item, sensitive);
	}
    }
}

#if NeedFunctionPrototypes
void XmtMenuInactivateProcedure(Widget w, XtCallbackProc proc)
#else
void XmtMenuInactivateProcedure(w, proc)
Widget w;
XtCallbackProc proc;
#endif
{
    XmtAssertWidgetClass(w, xmtMenuWidgetClass, "XmtMenuInactivateProcedure");
    CheckSensitivity(w, proc, False);
}

#if NeedFunctionPrototypes
void XmtMenuActivateProcedure(Widget w, XtCallbackProc proc)
#else
void XmtMenuActivateProcedure(w, proc)
Widget w;
XtCallbackProc proc;
#endif
{
    XmtAssertWidgetClass(w, xmtMenuWidgetClass, "XmtMenuActivateProcedure");
    CheckSensitivity(w, proc, True);
}