1 #include <Xm/XmP.h>
2 #include <Xm/FormP.h>
3 #include <Xm/RowColumnP.h>
4 #include <Xm/CascadeBP.h>
5 #include <Xm/CascadeBGP.h>
6 #include <Xm/PushBP.h>
7 #include <Xm/PushBGP.h>
8 #include <Xm/SeparatoGP.h>
9 #include <Xm/MenuShellP.h>
10 #include <Xm/MainWP.h>
11 #include <stdio.h>
12 
13 /* Test to demonstrate de behaviour of XmGetPostedFromWidget.
14  */
15 /* Oh well, it's growing into a generic menu test. */
16 
17 #define RC_Armed(w)	(((XmRowColumnWidget)(w))->row_column.armed)
18 
19 
20 Widget toplevel, mainw, menubar, filepane;
21 Widget button, button1, button2, sep;
22 Widget saveAsPane, button3, button4, button5;
23 Widget button6, button7, button8, button9, editpane;
24 Widget button10, button11, sub_popup_pane;
25 Widget inclPane, button12, button13, button14;
26 Widget one, two, three;
27 Widget optpane;
28 Widget opt1, opt2;
29 Widget ms1, ms2;
30 Widget wa, md, mp, mo, option;
31 Widget popup;
32 #if 0
33 Widget	mb;
34 #endif
35 
36 void
PrintPostedFrom(Widget w)37 PrintPostedFrom(Widget w)
38 {
39     Widget pf = XmGetPostedFromWidget(w);
40 
41     printf("XmGetPostedFromWidget(%s)=%s\n",
42 	   XtName(w),
43 	   pf ? XtName(pf) : "(null)");
44 }
45 
46 void
PopdownCB(Widget w,XtPointer client_data,XtPointer call_data)47 PopdownCB(Widget w, XtPointer client_data, XtPointer call_data)
48 {
49     printf("popdown %s\n", XtName(w));
50 }
51 
52 void
PopupCB(Widget w,XtPointer client_data,XtPointer call_data)53 PopupCB(Widget w, XtPointer client_data, XtPointer call_data)
54 {
55     printf("popup %s\n", XtName(w));
56 }
57 
58 void
MapCB(Widget w,XtPointer client_data,XtPointer call_data)59 MapCB(Widget w, XtPointer client_data, XtPointer call_data)
60 {
61     printf("RC_CascadeBtn(%s)=%p, armed=%x\n", XtName(w), RC_CascadeBtn(w), (int)RC_Armed(w));
62 }
63 
64 void
DisarmCB(Widget w,XtPointer client_data,XtPointer call_data)65 DisarmCB(Widget w, XtPointer client_data, XtPointer call_data)
66 {
67     printf("disarm\n");
68 }
69 
70 void
PushCB(Widget w,XtPointer client_data,XtPointer call_data)71 PushCB(Widget w, XtPointer client_data, XtPointer call_data)
72 {
73     Widget mp = (Widget)client_data;
74 
75     if (XmIsTraversable(wa))
76 	printf("(wa) IS TRAVERSABLE\n");
77     else
78 	printf("(wa) IS NOT TRAVERSABLE\n");
79     if (_XmIsNavigable(wa))
80 	printf("(wa) IS NAVIGABLE\n");
81     else
82 	printf("(wa) IS NOT NAVIGABLE\n");
83 #if 0
84     if (XmIsTraversable(mb))
85 	printf("(mb) IS TRAVERSABLE\n");
86     else
87 	printf("(mb) IS NOT TRAVERSABLE\n");
88     if (_XmIsNavigable(mb))
89 	printf("(mb) IS NAVIGABLE\n");
90     else
91 	printf("(mb) IS NOT NAVIGABLE\n");
92 #endif
93     if (XmIsTraversable(md))
94 	printf("(md) IS TRAVERSABLE\n");
95     else
96 	printf("(md) IS NOT TRAVERSABLE\n");
97     if (_XmIsNavigable(md))
98 	printf("(md) IS NAVIGABLE\n");
99     else
100 	printf("(md) IS NOT NAVIGABLE\n");
101     if (XmIsTraversable(mp))
102 	printf("(mp) IS TRAVERSABLE\n");
103     else
104 	printf("(mp) IS NOT TRAVERSABLE\n");
105     if (_XmIsNavigable(mp))
106 	printf("(mp) IS NAVIGABLE\n");
107     else
108 	printf("(mp) IS NOT NAVIGABLE\n");
109     if (XmIsTraversable(option))
110 	printf("(option) IS TRAVERSABLE\n");
111     else
112 	printf("(option) IS NOT TRAVERSABLE\n");
113     if (_XmIsNavigable(option))
114 	printf("(option) IS NAVIGABLE\n");
115     else
116 	printf("(option) IS NOT NAVIGABLE\n");
117 
118     printf("\n");
119 
120     PrintPostedFrom(mp);
121 }
122 
123 void
buttonPressEventHandler(Widget w,XtPointer client_data,XEvent * e,Boolean * cont)124 buttonPressEventHandler(Widget w,
125 			XtPointer client_data,
126 			XEvent *e,
127 			Boolean *cont)
128 {
129     XButtonEvent *be = (XButtonEvent*)e;
130 
131     if (1/*be->button == 3*/)
132     {
133 	XmMenuPosition(popup, be);
134 
135 	XtManageChild(popup);
136     }
137 }
138 
139 void
buttonPopup(Widget w,XEvent * event,String * params,Cardinal * num_params)140 buttonPopup(Widget w, XEvent *event, String *params, Cardinal *num_params)
141 {
142     XButtonEvent *be = (XButtonEvent*)event;
143 
144     printf("Widget: %s : BUTTON3!\n", XtName(w));
145 
146     XmMenuPosition(popup, be);
147 
148     XtManageChild(popup);
149 }
150 
151 
152 static char but_trans[] = "\
153 #override <Btn3Down> : buttonPopup()\n";
154 
155 static XtActionsRec app_actions[] = {
156 	{ "buttonPopup", buttonPopup }
157 };
158 
159 int
main(int argc,char ** argv)160 main(int argc, char **argv)
161 {
162     XtAppContext theApp;
163     Arg args[6];
164     int ac;
165     Dimension mmt, mmb, mml, mmr, mmw, mmh, st, ht;
166 
167     XmRepTypeInstallTearOffModelConverter();
168 
169     toplevel = XtVaAppInitialize(&theApp, "mainW", NULL, 0,
170 				 &argc, argv, NULL, NULL);
171 
172     XtAppAddActions(theApp, app_actions, XtNumber(app_actions));
173     XtSetArg(args[0], XtNtranslations, XtParseTranslationTable(but_trans));
174     mainw = XmCreateMainWindow(toplevel, "MainWindow", args, 1);
175     XtManageChild(mainw);
176 
177     printf("after creation:\n");
178 
179     wa = XtVaCreateWidget("work_area", xmRowColumnWidgetClass, mainw,
180 			  XmNrowColumnType, XmWORK_AREA,
181 			  NULL);
182 #if 0
183 /* this causes core dumps with Motif-1.2 on Solaris */
184     PrintPostedFrom(wa);
185 #endif
186 
187 #if 0
188     mb = XtVaCreateWidget("menu_bar", xmRowColumnWidgetClass, mainw,
189 			  XmNrowColumnType, XmMENU_BAR,
190 			  NULL);
191 
192     PrintPostedFrom(mb);
193 #endif
194 
195     ms1 = XtVaCreatePopupShell("ms1", xmMenuShellWidgetClass, mainw,
196 			       XmNwidth, 1,
197 			       XmNheight, 1,
198 			       NULL);
199 
200 
201     md = XtVaCreateWidget("menu_pulldown", xmRowColumnWidgetClass, ms1,
202 			  XmNrowColumnType, XmMENU_PULLDOWN,
203 			  NULL);
204 
205     PrintPostedFrom(md);
206 
207     ms2 = XtVaCreatePopupShell("ms2", xmMenuShellWidgetClass, mainw,
208 			       XmNwidth, 1,
209 			       XmNheight, 1,
210 			       NULL);
211 
212     mp = XtVaCreateWidget("menu_popup", xmRowColumnWidgetClass, ms2,
213 			  XmNrowColumnType, XmMENU_POPUP,
214 			  NULL);
215 
216     PrintPostedFrom(mp);
217 
218     mo = XtVaCreateWidget("menu_option", xmRowColumnWidgetClass, mainw,
219 			  XmNrowColumnType, XmMENU_OPTION,
220 			  NULL);
221 
222     PrintPostedFrom(mo);
223 
224     printf("\n");
225 
226     menubar = XmCreateMenuBar(mainw,
227 			      "menuBar",
228 			      NULL,0);
229 
230     filepane = XmCreatePulldownMenu(menubar,
231 				    "file_pane",
232 				    NULL,0);
233 
234     button = XtVaCreateManagedWidget("File",
235 				     xmCascadeButtonGadgetClass,
236 				     menubar,
237 				     XmNsubMenuId, filepane,
238 				     NULL);
239   XtVaGetValues(button,
240 		XmNmarginTop, &mmt, XmNmarginBottom, &mmb,
241 		XmNmarginLeft, &mml, XmNmarginRight, &mmr,
242 		XmNmarginWidth, &mmw, XmNmarginHeight, &mmh,
243 		XmNshadowThickness, &st, XmNhighlightThickness, &ht,
244 		NULL);
245 printf("%d %d %d %d %d %d %d %d\n",
246 	mmt, mmb, mml, mmr, mmw, mmh, st, ht);
247 
248 
249     editpane = XmCreatePulldownMenu(menubar,
250 				    "pane2",
251 				    NULL, 0);
252 
253     button6 = XtVaCreateManagedWidget("Edit",
254 				      xmCascadeButtonGadgetClass,
255 				      menubar,
256 				      XmNsubMenuId, editpane,
257 				      NULL);
258 
259     button7 = XtVaCreateManagedWidget("Cut",
260 				      xmPushButtonGadgetClass,
261 				      editpane,
262 				      NULL);
263 
264     button1 = XtVaCreateManagedWidget("Open",
265 				      xmPushButtonGadgetClass,
266 				      filepane,
267 				      NULL);
268 
269     XtAddCallback(XtParent(filepane), XmNpopdownCallback, PopdownCB, NULL);
270 
271     XtAddCallback(XtParent(filepane), XmNpopupCallback, PopupCB, NULL);
272 
273     XtAddCallback(filepane, XmNmapCallback, MapCB, NULL);
274 
275     XtAddCallback(button1, XmNactivateCallback, PushCB, (Widget)filepane);
276 
277     XtAddCallback(button1, XmNdisarmCallback, DisarmCB, NULL);
278 
279     sep = XtVaCreateManagedWidget("sep",
280 				  xmSeparatorGadgetClass,
281                                   filepane,
282                                   NULL);
283 
284     button2 = XtVaCreateManagedWidget("Close",
285 				      xmPushButtonWidgetClass,
286 				      filepane,
287 				      NULL);
288 
289     inclPane = XmCreatePulldownMenu(filepane,
290 				    "incl_pane",
291 				    NULL, 0);
292 
293     button12 = XtVaCreateManagedWidget("Include",
294 				       xmCascadeButtonWidgetClass,
295 				       filepane,
296 				       XmNsubMenuId, inclPane,
297 				       NULL);
298 
299     button13 = XtVaCreateManagedWidget("fig",
300 				       xmPushButtonGadgetClass,
301 				       inclPane,
302 				       NULL);
303 
304     button14 = XtVaCreateManagedWidget("pic",
305 				       xmPushButtonWidgetClass,
306 				       inclPane,
307 				       NULL);
308 
309     saveAsPane = XmCreatePulldownMenu(filepane,
310 				      "save_as_pane",
311 				      NULL, 0);
312 
313     XtAddCallback(XtParent(saveAsPane), XmNpopupCallback, PopupCB, NULL);
314 
315     XtAddCallback(XtParent(saveAsPane), XmNpopdownCallback, PopdownCB, NULL);
316 
317     XtAddCallback(saveAsPane, XmNmapCallback, MapCB, NULL);
318 
319     button3 = XtVaCreateManagedWidget("Save As",
320 				      xmCascadeButtonWidgetClass,
321 				      filepane,
322 				      XmNsubMenuId, saveAsPane,
323 				      NULL);
324 
325     button4 = XtVaCreateManagedWidget("MS Word",
326 				      xmPushButtonWidgetClass,
327 				      saveAsPane,
328 				      NULL);
329 
330     button5 = XtVaCreateManagedWidget("LaTeX",
331 				      xmPushButtonWidgetClass,
332 				      saveAsPane,
333 				      NULL);
334 
335     XtAddCallback(button5, XmNactivateCallback, PushCB, (Widget)saveAsPane);
336 
337     XtManageChild(menubar);
338 
339     one = XtVaCreateManagedWidget("form", xmFormWidgetClass, mainw,
340 				  NULL);
341 
342     optpane = XmCreatePulldownMenu(mainw, "optpane", NULL, 0);
343 
344     opt1 = XtVaCreateManagedWidget("true",
345 				   xmPushButtonWidgetClass,
346 				   optpane,
347 				   NULL);
348 
349     opt2 = XtVaCreateManagedWidget("false",
350 				   xmPushButtonWidgetClass,
351 				   optpane,
352 				   NULL);
353 
354     ac = 0;
355     XtSetArg(args[ac], XmNsubMenuId, optpane); ac++;
356     XtSetArg(args[ac], XmNlabelString, XmStringCreateLocalized("Guess:")); ac++;
357     XtSetArg(args[ac], XmNtopAttachment, XmATTACH_FORM); ac++;
358     XtSetArg(args[ac], XmNleftAttachment, XmATTACH_FORM); ac++;
359     XtSetArg(args[ac], XmNrightAttachment, XmATTACH_FORM); ac++;
360     XtSetArg(args[ac], XmNbottomAttachment, XmATTACH_NONE); ac++;
361 
362     option = XmCreateOptionMenu(one, "option", args, ac);
363 
364     XtManageChild(option);
365 
366   XtVaGetValues(XmOptionButtonGadget(option),
367 		XmNmarginTop, &mmt, XmNmarginBottom, &mmb,
368 		XmNmarginLeft, &mml, XmNmarginRight, &mmr,
369 		XmNmarginWidth, &mmw, XmNmarginHeight, &mmh,
370 		XmNshadowThickness, &st, XmNhighlightThickness, &ht,
371 		NULL);
372 printf("%d %d %d %d %d %d %d %d %d %d\n",
373 	mmt, mmb, mml, mmr, mmw, mmh, st, ht, XtWidth(option), XtHeight(option));
374 
375     XtAddCallback(opt1, XmNactivateCallback, PushCB, (Widget)option);
376 
377     two = XtVaCreateManagedWidget("option", xmPushButtonWidgetClass, one,
378 				  XmNtopAttachment, XmATTACH_WIDGET,
379 				  XmNtopWidget, option,
380 				  XmNbottomAttachment, XmATTACH_FORM,
381 				  XmNleftAttachment, XmATTACH_NONE,
382 				  XmNrightAttachment, XmATTACH_FORM,
383 				  NULL);
384 
385     XtAddCallback(two, XmNactivateCallback, PushCB, (Widget)option);
386     XtAddCallback(two, XmNactivateCallback, PushCB, (Widget)optpane);
387 
388     three = XtVaCreateManagedWidget("menu", xmPushButtonWidgetClass, one,
389 				    XmNtopAttachment, XmATTACH_WIDGET,
390 				    XmNtopWidget, option,
391 				    XmNbottomAttachment, XmATTACH_FORM,
392 				    XmNleftAttachment, XmATTACH_FORM,
393 				    XmNrightAttachment, XmATTACH_WIDGET,
394 				    XmNrightWidget, two,
395 				    NULL);
396 
397     XtAddEventHandler(two, KeyPressMask, False,
398 		      buttonPressEventHandler, NULL);
399 
400 #if 0
401     XtSetArg(args[0], XmNmenuPost, /* "<Btn3Down>"*/"<Button3>");
402 #endif
403     popup = XmCreatePopupMenu(one, "popup", args, 1);
404 
405 #if 1
406 #endif
407 
408     button8 = XtVaCreateManagedWidget("button8",
409 				      xmPushButtonWidgetClass,
410 				      popup,
411 				      NULL);
412 
413     XtAddCallback(button8, XmNactivateCallback, PushCB, (Widget)popup);
414 
415     sub_popup_pane = XmCreatePulldownMenu(two,
416 					 "save_as_pane",
417 					 NULL, 0);
418 
419     button10 = XtVaCreateManagedWidget("button10", xmPushButtonWidgetClass, sub_popup_pane,
420 				       NULL);
421 
422     XtAddCallback(button10, XmNactivateCallback, PushCB, (Widget)sub_popup_pane);
423 
424     button11 = XtVaCreateManagedWidget("button11", xmPushButtonWidgetClass, sub_popup_pane,
425 				       NULL);
426 
427     button9 = XtVaCreateManagedWidget("button9", xmCascadeButtonWidgetClass, popup,
428 				      XmNsubMenuId, sub_popup_pane,
429 				      NULL);
430 
431     XtAddCallback(three, XmNactivateCallback, PushCB, (Widget)menubar);
432     XtAddCallback(three, XmNactivateCallback, PushCB, (Widget)filepane);
433     XtAddCallback(three, XmNactivateCallback, PushCB, (Widget)saveAsPane);
434 
435     XmMainWindowSetAreas(mainw, menubar, NULL, NULL, NULL, one);
436 
437     XtRealizeWidget(toplevel);
438 
439   XtVaGetValues(XmOptionButtonGadget(option),
440 		XmNmarginTop, &mmt, XmNmarginBottom, &mmb,
441 		XmNmarginLeft, &mml, XmNmarginRight, &mmr,
442 		XmNmarginWidth, &mmw, XmNmarginHeight, &mmh,
443 		XmNshadowThickness, &st, XmNhighlightThickness, &ht,
444 		NULL);
445 printf("%d %d %d %d %d %d %d %d %d %d\n",
446 	mmt, mmb, mml, mmr, mmw, mmh, st, ht, XtWidth(option), XtHeight(option));
447 
448   {
449   static XtWidgetGeometry Expected[] = {
450   	CWWidth | CWHeight,		0,	0,	116,	91,	0,0,0,
451   	CWWidth | CWHeight | CWX | CWY,	3,	3,	4,	25,	0,0,0,
452   	CWWidth | CWHeight | CWX | CWY,	10,	3,	84,	25,	0,0,0,
453   	CWWidth | CWHeight | CWX | CWY,	0,	0,	116,	31,	0,0,0,
454   	CWWidth | CWHeight | CWX | CWY,	5,	5,	40,	21,	0,0,0,
455   	CWWidth | CWHeight | CWX | CWY,	45,	5,	40,	21,	0,0,0,
456   	CWWidth | CWHeight | CWX | CWY,	0,	31,	116,	60,	0,0,0,
457   	CWWidth | CWHeight | CWX | CWY,	0,	0,	116,	35,	0,0,0,
458   	CWWidth | CWHeight | CWX | CWY,	3,	3,	40,	29,	0,0,0,
459   	CWWidth | CWHeight | CWX | CWY,	46,	3,	67,	29,	0,0,0,
460   	CWWidth | CWHeight | CWX | CWY,	68,	35,	48,	25,	0,0,0,
461   	CWWidth | CWHeight | CWX | CWY,	0,	35,	68,	25,	0,0,0,
462 };
463 
464   PrintDetails(toplevel, Expected);
465   }
466     LessTifTestMainLoop(toplevel);
467     /*
468     XtAppMainLoop(theApp);
469     */
470 
471     exit(0);
472 }
473 
474