1 /*
2  * $Header: /cvsroot/lesstif/lesstif/test/Xm/mainw/test14.c,v 1.10 2001/05/15 14:08:33 amai Exp $
3  * Simpler version of test12.c.  Demonstrate problems with menu wrapping code.
4  *
5  * This seems to work the same in motif and in lesstif.
6  */
7 #include <stdio.h>
8 
9 #include <X11/Intrinsic.h>
10 #include <Xm/Xm.h>
11 #include <Xm/RepType.h>
12 #include <Xm/PushB.h>
13 #include <Xm/Text.h>
14 #include <Xm/TextF.h>
15 #include <Xm/ToggleB.h>
16 #include <Xm/MainWP.h>
17 #include <Xm/RowColumn.h>
18 #include <Xm/MessageB.h>
19 #include <Xm/CascadeB.h>
20 #include <Xm/Command.h>
21 #include <Xm/Frame.h>
22 #include <Xm/Label.h>
23 
24 #include "../../common/Test.h"
25 
26 
27 Widget GXTextIn, GXTextOut, GXStatus;
28 #define INITIAL_WIDTH 400
29 static String fallback_resources[] =
30 {
31     "*background: tan",
32     "*fontList: *-*-*-medium-r-*-*-*-100-*-*-p-*-*-*",
33     "*tearOffModel: TEAR_OFF_ENABLED",
34     "*GLWidget.width: 400",
35     "*GLWidget.height: 200",
36     "*GXStatus.height: 30",
37     NULL
38 };
39 
40 static XtWidgetGeometry Expected[] = {
41    CWWidth | CWHeight            ,  508,  524,  444,   30, 0,0,0, /* menuBar */
42    CWWidth | CWHeight | CWX | CWY,    5,    5,   61,   20, 0,0,0, /* fileButton */
43    CWWidth | CWHeight | CWX | CWY,   66,    5,   70,   20, 0,0,0, /* Edit dummy */
44    CWWidth | CWHeight | CWX | CWY,  136,    5,   88,   20, 0,0,0, /* Options dummy */
45    CWWidth | CWHeight | CWX | CWY,  224,    5,   94,   20, 0,0,0, /* Detonate dummy */
46    CWWidth | CWHeight | CWX | CWY,  318,    5,   84,   20, 0,0,0, /* Launch dummy */
47    CWWidth | CWHeight | CWX | CWY,  402,    5,   37,   20, 0,0,0, /* Help */
48    CWWidth | CWHeight            ,  508,  524,  400,   65, 0,0,0, /* menuBar */
49    CWWidth | CWHeight | CWX | CWY,    5,    5,   61,   20, 0,0,0, /* fileButton */
50    CWWidth | CWHeight | CWX | CWY,   66,    5,   70,   20, 0,0,0, /* Edit dummy */
51    CWWidth | CWHeight | CWX | CWY,  136,    5,   88,   20, 0,0,0, /* Options dummy */
52    CWWidth | CWHeight | CWX | CWY,  224,    5,   94,   20, 0,0,0, /* Detonate dummy */
53    CWWidth | CWHeight | CWX | CWY,    5,   30,   84,   30, 0,0,0, /* Launch dummy */
54    CWWidth | CWHeight | CWX | CWY,  358,   30,   37,   30, 0,0,0, /* Help */
55 };
56 
ShowHelp(w,client_data,call_data)57 void ShowHelp(w, client_data, call_data)
58 Widget w;
59 XtPointer client_data;
60 XtPointer call_data;
61 {
62   if (XmToggleButtonGetState(w))
63     XtManageChild(GXStatus);
64   else
65     XtUnmanageChild(GXStatus);
66 }
67 
Quit(w,client_data,call_data)68 void Quit(w, client_data, call_data)
69 Widget w;
70 XtPointer client_data, call_data;
71 {
72     exit(0);
73 }
74 
GXSetStatus(char * str)75 void GXSetStatus(char *str)
76 /* display str on status line */
77 {
78   char *buf=str;
79   if (!str)
80     buf=" ";
81   {
82     XmString xmstr;
83     if (!GXStatus)
84       return;
85     xmstr=XmStringCreateLocalized(buf);
86     XtVaSetValues(GXStatus,
87 		  XmNlabelString,xmstr,
88 		  NULL);
89     XmStringFree(xmstr);
90   }
91 }
92 
GXInitCommand(Widget parent,Boolean TEXTPORT)93 void GXInitCommand(Widget parent, Boolean TEXTPORT)
94 /*-
95  * Initialize the command area. if textport is true, grab standard output
96  * and standard error and send them to a text output widget
97 -*/
98 {
99     Arg args[20];
100     int n;
101     Widget w;
102 
103     /* make the text IO region */
104     if (TEXTPORT) {
105 	GXTextOut = XmCreateScrolledText(parent, "GXTextOut", NULL, 0);
106 #ifndef __linux__
107 	/* FIXME */
108 	XmTextSetAddMode(GXTextOut, TRUE);
109 #endif
110 	XtVaSetValues(GXTextOut,
111 		      XmNskipAdjust, TRUE,
112 		      XmNeditMode, XmMULTI_LINE_EDIT,
113 		      XmNeditable, FALSE,
114 		      XmNtraversalOn, FALSE,
115 		      XmNwordWrap, TRUE,
116 		      XmNhighlightOnEnter, False,
117 		      XmNhighlightThickness, 0,
118 		      XmNrows, 6,
119 		      NULL);
120 	XtVaSetValues(XtParent(GXTextOut),
121 		      XmNskipAdjust, TRUE,
122 		      XmNleftOffset, 5,
123 		      XmNrightOffset, 5,
124 		      XmNbottomOffset, 5,
125 		      XmNhighlightOnEnter, FALSE,
126 		      XmNhighlightThickness, 0,
127 		      XmNresizeWidth, TRUE,
128 		      XmNresizeHeight, FALSE,
129 		      NULL);
130 	XtVaGetValues(XtParent(GXTextOut),
131 		      XmNhorizontalScrollBar, &w,
132 		      NULL);
133 	XtUnmanageChild(w);	/* kill off unneeded scrollbar */
134 	XtManageChild(GXTextOut);
135 
136     }
137 
138     /*- make the command Widget -*/
139     GXTextIn = XmCreateTextField(parent, "GXTextIN", NULL, 0);
140     XtVaSetValues(GXTextIn,
141 		  XmNhighlightOnEnter, False,
142 		  XmNhighlightThickness, 0,
143 		  XmNpaneMaximum, 30,
144 		  XmNpaneMinimum, 30,
145 		  XmNwidth, INITIAL_WIDTH,
146 		  NULL);
147     XtManageChild(GXTextIn);
148 #if (XmVersion>=1002)		/* motif 1.2 or higher */
149     XtVaSetValues(parent,
150 		  XmNinitialFocus, GXTextIn,
151 		  NULL);
152 #endif
153 }
154 
main(argc,argv)155 int main(argc, argv)
156 int argc;
157 char **argv;
158 {
159   XtAppContext app_context;
160   Widget topLevel, mainWindow, menuBar, frame;
161   Display *GXDisplay;
162   Widget command, paned, GLWidget;
163 
164   Widget fileButton, fileMenu, quit, helpButton, helpMenu, help, helpBox;
165   Widget temp;
166   int n;
167   Arg args[10];
168 
169   /* if compiling on a SGI, allow for non-default visuals. */
170   XtToolkitInitialize();
171   app_context = XtCreateApplicationContext();
172   XtAppSetFallbackResources(app_context, fallback_resources);
173   GXDisplay = XtOpenDisplay(app_context, NULL, "Mainw12", "Mainw12",
174 			    NULL, 0, &argc, argv);
175   if (!GXDisplay) {
176     printf("Couldn't open display. \n");
177     exit(-1);
178   }
179 
180   n = 0;
181   topLevel = XtAppCreateShell("Mainw12", "Mainw12",
182 			      applicationShellWidgetClass,
183 			      GXDisplay, args, n);
184 
185   /* register converter for tearoff menus */
186   XmRepTypeInstallTearOffModelConverter();
187 
188   /* create menu bar along top inside of main window */
189   menuBar = XmCreateMenuBar(
190 			    topLevel, /* parent widget*/
191 			    "menuBar",  /* widget name */
192 			    NULL,       /* no arguments needed */
193 			    0);         /* no arguments needed */
194   XtManageChild(menuBar);
195 
196 
197   /*
198    *  CREATE FILE MENU AND CHILDREN
199    */
200 
201   /* create button that will pop up the menu */
202   fileButton = XtVaCreateManagedWidget(
203 				       "fileButton",               /* widget name */
204 				       xmCascadeButtonWidgetClass, /* widget class */
205 				       menuBar,                    /* parent widget*/
206 				       XmNwidth, 61,
207 				       XmNheight, 20,
208 				       XmNrecomputeSize, False,
209 				       NULL);                      /* terminate varargs list */
210 
211   XtVaCreateManagedWidget(
212 			  "Edit dummy",               /* widget name */
213 			  xmCascadeButtonWidgetClass, /* widget class */
214 			  menuBar,                    /* parent widget*/
215 				       XmNwidth, 70,
216 				       XmNheight, 20,
217 				       XmNrecomputeSize, False,
218 			  NULL);                      /* terminate varargs list */
219 
220   XtVaCreateManagedWidget(
221 			  "Options dummy",               /* widget name */
222 			  xmCascadeButtonWidgetClass, /* widget class */
223 			  menuBar,                    /* parent widget*/
224 				       XmNwidth, 88,
225 				       XmNheight, 20,
226 				       XmNrecomputeSize, False,
227 			  NULL);                      /* terminate varargs list */
228 
229   XtVaCreateManagedWidget(
230 			  "Detonate dummy",               /* widget name */
231 			  xmCascadeButtonWidgetClass, /* widget class */
232 			  menuBar,                    /* parent widget*/
233 				       XmNwidth, 94,
234 				       XmNheight, 20,
235 				       XmNrecomputeSize, False,
236 			  NULL);                      /* terminate varargs list */
237 
238   XtVaCreateManagedWidget(
239 			  "Launch dummy",               /* widget name */
240 			  xmCascadeButtonWidgetClass, /* widget class */
241 			  menuBar,                    /* parent widget*/
242 				       XmNwidth, 84,
243 				       XmNheight, 20,
244 				       XmNrecomputeSize, False,
245 			  NULL);                      /* terminate varargs list */
246 
247   /* create menu (really a Shell widget and RowColumn widget combo) */
248   fileMenu = XmCreatePulldownMenu(
249 				  menuBar,    /* parent widget*/
250 				  "fileMenu", /* widget name */
251 				  NULL,       /* no argument list needed */
252 				  0);         /* no argument list needed */
253 
254   /* create the quit button up in the menu */
255   quit = XtVaCreateManagedWidget(
256 				 "quit",                     /* widget name */
257 				 xmPushButtonWidgetClass,    /* widget class */
258 				 fileMenu,                   /* parent widget*/
259 				 NULL);                      /* terminate varargs list */
260 
261   /*
262    * Specify which menu fileButton will pop up.
263    */
264   XtVaSetValues(fileButton,
265 		XmNsubMenuId, fileMenu,
266 		NULL);
267 
268   /* arrange for quit button to call function that exits. */
269   XtAddCallback(quit, XmNactivateCallback, Quit, 0);
270 
271   /*
272    *  CREATE HELP BUTTON AND BOX
273    */
274 
275   /* create button that will bring up help menu */
276   helpButton = XtVaCreateManagedWidget(
277 				       "Help",             /* widget name */
278 				       xmCascadeButtonWidgetClass, /* widget class */
279 				       menuBar,                   /* parent widget*/
280 				       XmNwidth, 37,
281 				       XmNheight, 20,
282 				       XmNrecomputeSize, False,
283 				       NULL);                     /* terminate varargs list */
284 
285   /* tell menuBar which is the help button (will be specially
286      positioned) */
287   XtVaSetValues(menuBar,
288 		XmNmenuHelpWidget, helpButton,
289 		NULL);
290 
291   /* create menu (really a Shell widget and RowColumn widget combo) */
292   helpMenu = XmCreatePulldownMenu(
293 				  menuBar,    /* parent widget*/
294 				  "helpMenu", /* widget name */
295 				  NULL,       /* no argument list needed */
296 				  0);         /* no argument list needed */
297 
298   /* create the help button up in the menu */
299   help = XtVaCreateManagedWidget(
300 				 "status line",                     /* widget name */
301 				 xmToggleButtonWidgetClass,    /* widget class */
302 				 helpMenu,                   /* parent widget*/
303 				 NULL);                      /* terminate varargs list */
304 
305   /*
306    * Specify which menu helpButton will pop up.
307    */
308   XtVaSetValues(helpButton,
309 		XmNsubMenuId, helpMenu,
310 		NULL);
311 
312   /* create popup that will contain help */
313   helpBox = XmCreateMessageDialog(
314 				  help,       /* parent widget*/
315 				  "helpBox",  /* widget name   */
316 				  NULL,       /* no arguments needed */
317 				  0);         /* no arguments needed */
318 
319   temp = XmMessageBoxGetChild (helpBox, XmDIALOG_CANCEL_BUTTON);
320   XtUnmanageChild (temp);
321   temp = XmMessageBoxGetChild (helpBox, XmDIALOG_HELP_BUTTON);
322   XtUnmanageChild (temp);
323 
324   /* arrange for getHelp button to pop up helpBox */
325   XtAddCallback(help, XmNvalueChangedCallback, ShowHelp, helpBox);
326 
327   XtRealizeWidget(topLevel);
328 
329 
330   PrintDetails(topLevel,Expected);
331   LessTifTestWaitForIt(topLevel);
332   LessTifTestResizeWidget(topLevel, 400, 65);
333   PrintDetails(topLevel,Expected);
334   LessTifTestMainLoop(topLevel);
335 
336   exit(0);
337 }
338 
339