1 /* $Header: /cvsroot/lesstif/lesstif/test/Xm/form/test12.c,v 1.7 2001/05/23 14:09:45 amai Exp $
2  */
3 
4 #include <stdlib.h>
5 #include <stdio.h>
6 #include <X11/Xatom.h>
7 #include <X11/Intrinsic.h>
8 #include <X11/Shell.h>
9 
10 #include <Xm/Xm.h>
11 #include <Xm/DialogS.h>
12 #include <Xm/Form.h>
13 #include <Xm/Label.h>
14 #include <Xm/Text.h>
15 
16 
17 Widget          appshell = (Widget) NULL;
18 
19 
20 void
create_appshell(display,app_name,app_argc,app_argv)21 create_appshell(display, app_name, app_argc, app_argv)
22 	Display        *display;
23 	char           *app_name;
24 	int             app_argc;
25 	char          **app_argv;
26 {
27 	Arg             al[64];	/* Arg List */
28 	register int    ac = 0;	/* Arg Count */
29 	Dimension       widest, width, spacing;
30 	Widget          form;
31 	Widget          label1, label2, label3;
32 	Widget          text1, text2, text3;
33 
34 	XtSetArg(al[ac], XmNallowShellResize, TRUE);
35 	ac++;
36 	XtSetArg(al[ac], XmNtitle, "Column layout using calculated offsets");
37 	ac++;
38 	XtSetArg(al[ac], XmNargc, app_argc);
39 	ac++;
40 	XtSetArg(al[ac], XmNargv, app_argv);
41 	ac++;
42 	appshell = XtAppCreateShell(app_name, "XApplication", applicationShellWidgetClass, display, al, ac);
43 
44 	ac = 0;
45 
46 	form = XmCreateForm(appshell, "form", al, ac);
47 	XtVaSetValues(form,
48 		XmNhorizontalSpacing, 12,
49 		XmNverticalSpacing, 12,
50 		NULL);
51 	label1 = XmCreateLabel(form, "label1", al, ac);
52 	XtVaSetValues(label1,
53 		XmNlabelString, XmStringCreateSimple("Label"),
54 		NULL);
55 	text1 = XmCreateText(form, "text1", al, ac);
56 	label2 = XmCreateLabel(form, "label2", al, ac);
57 	XtVaSetValues(label2,
58 		XmNlabelString, XmStringCreateSimple("Long label"),
59 		NULL);
60 	text2 = XmCreateText(form, "text2", al, ac);
61 	label3 = XmCreateLabel(form, "label3", al, ac);
62 	XtVaSetValues(label3,
63 		XmNlabelString, XmStringCreateSimple("L"),
64 		NULL);
65 	text3 = XmCreateText(form, "text3", al, ac);
66 
67 	ac = 0;
68 	XtSetArg(al[ac], XmNwidth, &width); ac++;
69 	XtGetValues(label1, al, ac);
70 	widest = width;
71 	XtGetValues(label2, al, ac);
72 	if (width > widest)
73 		widest = width;
74 	XtGetValues(label1, al, ac);
75 	if (width > widest)
76 		widest = width;
77 	XtVaGetValues(form, XmNhorizontalSpacing, &spacing, NULL);
78 
79 	XtVaSetValues(label1,
80 		      XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET,
81 		      XmNtopOffset, 0,
82 		      XmNtopWidget, text1,
83 		      XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET,
84 		      XmNbottomOffset, 0,
85 		      XmNbottomWidget, text1,
86 		      XmNleftAttachment, XmATTACH_FORM,
87 		      NULL);
88 
89 	XtVaSetValues(text1,
90 		      XmNtopAttachment, XmATTACH_FORM,
91 		      XmNbottomAttachment, XmATTACH_NONE,
92 		      XmNleftAttachment, XmATTACH_FORM,
93 		      XmNleftOffset, widest + spacing,
94 		      XmNrightAttachment, XmATTACH_FORM,
95 		      NULL);
96 
97 	XtVaSetValues(label2,
98 		      XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET,
99 		      XmNtopOffset, 0,
100 		      XmNtopWidget, text2,
101 		      XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET,
102 		      XmNbottomOffset, 0,
103 		      XmNbottomWidget, text2,
104 		      XmNleftAttachment, XmATTACH_FORM,
105 		      NULL);
106 
107 	XtVaSetValues(text2,
108 		      XmNtopAttachment, XmATTACH_WIDGET,
109 		      XmNtopWidget, text1,
110 		      XmNbottomAttachment, XmATTACH_NONE,
111 		      XmNleftAttachment, XmATTACH_FORM,
112 		      XmNleftOffset, widest + spacing,
113 		      XmNrightAttachment, XmATTACH_FORM,
114 		      NULL);
115 
116 	XtVaSetValues(label3,
117 		      XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET,
118 		      XmNtopOffset, 0,
119 		      XmNtopWidget, text3,
120 		      XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET,
121 		      XmNbottomOffset, 0,
122 		      XmNbottomWidget, text3,
123 		      XmNleftAttachment, XmATTACH_FORM,
124 		      NULL);
125 
126 	XtVaSetValues(text3,
127 		      XmNtopAttachment, XmATTACH_WIDGET,
128 		      XmNtopWidget, text2,
129 		      XmNbottomAttachment, XmATTACH_NONE,
130 		      XmNleftAttachment, XmATTACH_FORM,
131 		      XmNleftOffset, widest + spacing,
132 		      XmNrightAttachment, XmATTACH_FORM,
133 		      NULL);
134 
135 	XtManageChild(label1);
136 	XtManageChild(label2);
137 	XtManageChild(label3);
138 	XtManageChild(text1);
139 	XtManageChild(text2);
140 	XtManageChild(text3);
141 	XtManageChild(form);
142 
143 }
144 
145 
146 
147 XtAppContext    app_context;
148 Display        *display;	/* Display             */
149 
150 int
main(argc,argv)151 main(argc, argv)
152 	int             argc;
153 	char          **argv;
154 {
155 	/* Pick up resources from current directory */
156 	putenv("XAPPLRESDIR=.");
157 
158 	XtSetLanguageProc((XtAppContext) NULL, (XtLanguageProc) NULL, (XtPointer) NULL);
159 	XtToolkitInitialize();
160 	app_context = XtCreateApplicationContext();
161 	display = XtOpenDisplay(app_context, NULL, argv[0], "Form12",
162 				NULL, 0, &argc, argv);
163 	if (!display) {
164 		printf("%s: can't open display, exiting...\n", argv[0]);
165 		exit(-1);
166 	}
167 	create_appshell(display, argv[0], argc, argv);
168 	XtRealizeWidget(appshell);
169   {
170   static XtWidgetGeometry Expected[] = {
171   	CWWidth | CWHeight,		0,	0,	226,	129,	0,0,0,	/* Form */
172   	CWWidth | CWHeight | CWX | CWY,	12,	12,	34,	31,	0,0,0,	/* two */
173   	CWWidth | CWHeight | CWX | CWY,	76,	12,	138,	31,	0,0,0,	/* two */
174   	CWWidth | CWHeight | CWX | CWY,	12,	55,	64,	31,	0,0,0,	/* two */
175   	CWWidth | CWHeight | CWX | CWY,	76,	55,	138,	31,	0,0,0,	/* two */
176   	CWWidth | CWHeight | CWX | CWY,	12,	98,	10,	31,	0,0,0,	/* two */
177   	CWWidth | CWHeight | CWX | CWY,	76,	98,	138,	31,	0,0,0,	/* two */
178 };
179 
180   PrintDetails(appshell, Expected);
181   }
182 	    LessTifTestMainLoop(appshell);
183 	exit(0);
184 }
185