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