1 /*
2 * You should also run this with
3 * test1 -xrm "*tearOffModel: tear_off_enabled"
4 */
5 #include <stdio.h>
6 #include <Xm/Xm.h>
7 #include <Xm/RowColumn.h>
8 #include <Xm/PushB.h>
9 #include <Xm/PushBG.h>
10 #include <Xm/CascadeB.h>
11 #include <Xm/MenuShell.h>
12 #include <Xm/RepType.h>
13 #include <Xm/SelectioB.h>
14
15 #include <Xm/XmP.h>
16
17 char *fallback[] = {
18 "*tearOffModel: tear_off_enabled",
19 "*cascade1.background: Red",
20 "*cascade1.labelString: Menu",
21 "*cascade1.mnemonic: M",
22 "*cascade2.background: Green",
23 "*cascade2.labelString: Other",
24 "*cascade2.mnemonic: t",
25 "*cascade3.labelString: Deep",
26 "*cascade3.mnemonic: D",
27 "*XmPushButtonGadget.labelString: gadget",
28 "*button1.labelString: Button 1",
29 "*button1.mnemonic: B",
30 "*button1.acceleratorText: Ctrl-B",
31 "*button1.accelerator: Ctrl<Key>b",
32 "*button1.recomputeSize: False",
33 "*p2ms.geometry: 10x10",
34 "*p3ms.geometry: 10x10",
35 NULL /* The end */
36 };
37
PrintIt(Widget w)38 void PrintIt(Widget w)
39 {
40 fprintf(stderr, "Widget %s - geo %d %d %d %d\n",
41 XtName(w), XtX(w), XtY(w), XtWidth(w), XtHeight(w));
42 }
43
pb_activate_callback(Widget w,XtPointer clientData,XtPointer callData)44 void pb_activate_callback(Widget w, XtPointer clientData, XtPointer callData)
45 {
46 Widget pf;
47
48 fprintf(stderr, "* Widget = %s - Activated\n", XtName(w));
49
50 pf = XmGetPostedFromWidget(XtParent(w));
51
52 if (pf)
53 fprintf(stderr, "Posted from 0x%X (%s)\n", (unsigned int)pf, XtName(pf));
54
55 /*
56 * Suspicions about windows being too large ...
57 */
58 PrintIt(w); /* The button */
59 PrintIt(XtParent(w)); /* The RC */
60 PrintIt(XtParent(XtParent(w))); /* The shell */
61 }
62
pb_arm_callback(Widget w,XtPointer clientData,XtPointer callData)63 void pb_arm_callback(Widget w, XtPointer clientData, XtPointer callData)
64 {
65 printf ("* Widget = %s - Armed\n", XtName(w));
66 }
67
68 int
main(int argc,char ** argv)69 main(int argc, char **argv)
70 {
71 XtAppContext theApp;
72 Widget toplevel, rc;
73 Widget cascade1, cascade2;
74 Widget pane1, pane2, pane3;
75 Widget w, ms;
76 Arg al[5];
77 int ac;
78
79 /* Install converter to make the command line indicated above work */
80 XmRepTypeInstallTearOffModelConverter();
81
82 /* Toplevel and Menu Bar */
83 toplevel = XtVaAppInitialize(&theApp, "test1", NULL, 0, &argc, argv, fallback, NULL);
84 rc = XmCreateMenuBar(toplevel, "menubar", NULL, 0);
85
86 /* First Menu */
87 ac = 0;
88 XtSetArg(al[ac], XmNnumColumns, 2); ac++;
89 pane1 = XmCreatePulldownMenu(rc, "pane1", al, ac);
90
91 cascade1 = XtVaCreateManagedWidget("cascade1", xmCascadeButtonWidgetClass, rc,
92 XmNsubMenuId, pane1,
93 XmNwidth, 45,
94 XmNheight, 25,
95 XmNrecomputeSize, False,
96 NULL);
97
98 w = XtVaCreateManagedWidget("button1", xmPushButtonWidgetClass, pane1,
99 NULL);
100 XtAddCallback(w, XmNactivateCallback, pb_activate_callback, NULL);
101 XtAddCallback(w, XmNarmCallback, pb_arm_callback, NULL);
102
103 w = XtVaCreateManagedWidget("button2", xmPushButtonGadgetClass, pane1,
104 NULL);
105 XtAddCallback(w, XmNactivateCallback, pb_activate_callback, NULL);
106 XtAddCallback(w, XmNarmCallback, pb_arm_callback, NULL);
107
108 w = XtVaCreateManagedWidget("button3", xmPushButtonWidgetClass, pane1,
109 NULL);
110 XtAddCallback(w, XmNactivateCallback, pb_activate_callback, NULL);
111 XtAddCallback(w, XmNarmCallback, pb_arm_callback, NULL);
112
113 /* Second Menu */
114 cascade2 = XtVaCreateManagedWidget("cascade2", xmCascadeButtonWidgetClass, rc,
115 XmNwidth, 50,
116 XmNheight, 30,
117 XmNrecomputeSize, False,
118 NULL);
119
120 ms = XtCreatePopupShell("p2ms", xmMenuShellWidgetClass, rc,
121 NULL, 0);
122
123 pane2 = XtVaCreateWidget("pane2", xmRowColumnWidgetClass, ms,
124 XmNrowColumnType, XmMENU_PULLDOWN,
125 XmNx, 0,
126 XmNy, 0,
127 XmNwidth, 91,
128 XmNheight, 25,
129 NULL);
130
131 w = XtVaCreateManagedWidget("dummy", xmPushButtonWidgetClass, pane2,
132 NULL);
133
134 XtVaSetValues(cascade2,
135 XmNsubMenuId, pane2,
136 NULL);
137
138 ms = XtCreatePopupShell("p3ms", xmMenuShellWidgetClass, pane2,
139 NULL, 0);
140
141 pane3 = XtVaCreateWidget("pane3", xmRowColumnWidgetClass, ms,
142 XmNrowColumnType, XmMENU_PULLDOWN,
143 NULL);
144
145 w = XtVaCreateManagedWidget("cascade3", xmCascadeButtonWidgetClass, pane2,
146 XmNsubMenuId, pane3,
147 NULL);
148
149 w = XtVaCreateManagedWidget("dummy", xmPushButtonWidgetClass, pane3,
150 NULL);
151
152
153 XtManageChild(rc);
154 XtRealizeWidget(toplevel);
155
156
157
158 {
159 static XtWidgetGeometry Expected[] = {
160 CWWidth | CWHeight , 56, 72, 105, 40, 0,0,0, /* menubar */
161 CWWidth | CWHeight | CWX | CWY, 5, 5, 45, 30, 0,0,0, /* cascade1 */
162 CWWidth | CWHeight | CWX | CWY, 50, 5, 50, 30, 0,0,0, /* cascade2 */
163 };
164 PrintDetails(toplevel,Expected);
165 };
166 LessTifTestMainLoop(toplevel);
167
168 exit(0);
169 }
170