1 /* $Header: /cvsroot/lesstif/lesstif/test/Xm/scrolledwindow/test13.c,v 1.6 2001/06/18 14:22:06 amai Exp $
2 * This test is an interactive interface to control the resources
3 * of a bunch of widgets. These widgets are really stolen out of
4 * test12.
5 */
6
7 #include <stdlib.h>
8 #include <stdio.h>
9
10 #include <Xm/Xm.h>
11 #include <Xm/ArrowB.h>
12 #include <Xm/CascadeB.h>
13 #include <Xm/Form.h>
14 #include <Xm/PushB.h>
15 #include <Xm/RowColumn.h>
16 #include <Xm/Scale.h>
17 #include <Xm/ScrolledWP.h>
18
19 #ifdef LESSTIF_VERSION
20 #include <XmI/MacrosI.h>
21 #endif
22
23
24 Widget toplevel, sw, ab;
25 Dimension st;
26
27 /*
28 * These are the ScrolledWindow resources that can be set by sliders.
29 */
30 struct x {
31 char *name;
32 int initial, min, max;
33 } list [] = {
34 { XmNwidth, 100, 0, 400 },
35 { XmNheight, 100, 0, 400 },
36 { XmNspacing, 3, 0, 20 },
37 { XmNshadowThickness, 5, 0, 20 },
38 };
39
40 char *fallback[] = {
41 "*sw.background: green",
42 "*sw.topShadowColor: red",
43 "*sw.bottomShadowColor: blue",
44 "*ab.background: yellow",
45 "*ab.foreground: black",
46 NULL
47 };
48
cb(Widget wid,XtPointer cld,XtPointer cad)49 void cb(Widget wid, XtPointer cld, XtPointer cad)
50 {
51 Dimension w,h,bw;
52 static Boolean toggle=False;
53 if ((toggle = !toggle))
54 {
55 w=300; h=300; bw = 1;
56 }
57 else
58 {
59 w=100; h=100; bw = 10;
60 }
61 printf("scrolledW child: asking for %ix%i (bw %i) /",w,h,bw);
62 XtVaSetValues(wid,XmNwidth,w,XmNheight,h,XmNborderWidth,bw,NULL);
63 XtVaGetValues(wid,XmNwidth,&w,XmNheight,&h,XmNborderWidth,&bw,NULL);
64 printf("got %ix%i (bw %i)\n",w,h,bw);
65 }
66
Quit(Widget w,XtPointer client,XtPointer call)67 void Quit(Widget w, XtPointer client, XtPointer call)
68 {
69 exit(0);
70 }
71
ChangePlacement(Widget w,XtPointer client,XtPointer call)72 void ChangePlacement(Widget w, XtPointer client, XtPointer call)
73 {
74 XtVaSetValues(sw, XmNscrollBarPlacement, (int)client, NULL);
75 }
76
Change(Widget w,XtPointer client,XtPointer call)77 void Change(Widget w, XtPointer client, XtPointer call)
78 {
79 int i = (int)client;
80 XmScaleCallbackStruct *p = (XmScaleCallbackStruct *)call;
81
82 XtVaSetValues(sw, list[i].name, p->value, NULL);
83 }
84
main(int argc,char ** argv)85 int main(int argc, char **argv)
86 {
87 XtAppContext app;
88 Widget top, mb, form, fc, fp, quit, s, om, mp, w;
89 int i;
90 Arg arg;
91 XmString xms;
92
93 XtSetLanguageProc(NULL, NULL, NULL);
94
95 toplevel = XtVaAppInitialize(&app, "Label", NULL, 0,
96 &argc, argv, fallback, NULL);
97
98 form = XtVaCreateManagedWidget("form", xmFormWidgetClass, toplevel,
99 XmNwidth, 500,
100 XmNheight, 300,
101 XmNresizePolicy, XmRESIZE_NONE,
102 NULL);
103
104 mb = XtVaCreateManagedWidget("mb", xmRowColumnWidgetClass, form,
105 XmNrowColumnType, XmMENU_BAR,
106 XmNtopAttachment, XmATTACH_FORM,
107 XmNleftAttachment, XmATTACH_FORM,
108 XmNrightAttachment, XmATTACH_FORM,
109 XmNbottomAttachment, XmATTACH_NONE,
110 NULL);
111
112 fp = XmCreatePulldownMenu(mb, "file pulldown", NULL, 0);
113 fc = XtVaCreateManagedWidget("File", xmCascadeButtonWidgetClass, mb,
114 XmNsubMenuId, fp,
115 NULL);
116
117 quit = XtVaCreateManagedWidget("Quit", xmPushButtonWidgetClass, fp,
118 NULL);
119 XtAddCallback(quit, XmNactivateCallback, Quit, NULL);
120
121 /* Panel of scales */
122 top = mb;
123 for (i=0; i<XtNumber(list); i++) {
124 xms = XmStringCreateSimple(list[i].name);
125 s = XtVaCreateManagedWidget(list[i].name, xmScaleWidgetClass, form,
126 XmNorientation, XmHORIZONTAL,
127 XmNminimum, list[i].min,
128 XmNmaximum, list[i].max,
129 XmNvalue, list[i].initial,
130 XmNtopAttachment, XmATTACH_WIDGET,
131 XmNtopWidget, top,
132 XmNleftAttachment, XmATTACH_FORM,
133 XmNrightAttachment, XmATTACH_POSITION,
134 XmNrightPosition, 25,
135 XmNbottomAttachment, XmATTACH_NONE,
136 XmNtitleString, xms,
137 XmNshowValue, True,
138 NULL);
139 XmStringFree(xms);
140 top = s;
141 XtAddCallback(s, XmNvalueChangedCallback, Change, (XtPointer)i);
142 }
143
144 /* Option menu for placement */
145 mp = XmCreatePulldownMenu(form, "option pane", NULL, 0);
146
147 xms = XmStringCreateSimple("Placement");
148 XtSetArg(arg, XmNlabelString, xms);
149 om = XmCreateOptionMenu(form, "option", &arg, 1);
150 XmStringFree(xms);
151
152 XtVaSetValues(om,
153 XmNsubMenuId, mp,
154 XmNtopAttachment, XmATTACH_WIDGET,
155 XmNtopWidget, top,
156 XmNleftAttachment, XmATTACH_FORM,
157 XmNrightAttachment, XmATTACH_POSITION,
158 XmNrightPosition, 25,
159 XmNbottomAttachment, XmATTACH_NONE,
160 NULL);
161 XtManageChild(om);
162
163 w = XtVaCreateManagedWidget("button", xmPushButtonWidgetClass, mp,
164 XtVaTypedArg, XmNlabelString, XmRString, "TOP_RIGHT", 10,
165 NULL);
166 XtAddCallback(w, XmNactivateCallback,
167 ChangePlacement, (XtPointer)XmTOP_RIGHT);
168 w = XtVaCreateManagedWidget("button", xmPushButtonWidgetClass, mp,
169 XtVaTypedArg, XmNlabelString, XmRString, "BOTTOM_RIGHT", 12,
170 NULL);
171 XtAddCallback(w, XmNactivateCallback,
172 ChangePlacement, (XtPointer)XmBOTTOM_RIGHT);
173
174 XtVaSetValues(om, XmNmenuHistory, w, NULL);
175
176 w = XtVaCreateManagedWidget("button", xmPushButtonWidgetClass, mp,
177 XtVaTypedArg, XmNlabelString, XmRString, "BOTTOM_LEFT", 11,
178 NULL);
179 XtAddCallback(w, XmNactivateCallback,
180 ChangePlacement, (XtPointer)XmBOTTOM_LEFT);
181 w = XtVaCreateManagedWidget("button", xmPushButtonWidgetClass, mp,
182 XtVaTypedArg, XmNlabelString, XmRString, "TOP_LEFT", 9,
183 NULL);
184 XtAddCallback(w, XmNactivateCallback,
185 ChangePlacement, (XtPointer)XmTOP_LEFT);
186
187 /* Create the SW */
188 sw = XtVaCreateManagedWidget("sw", xmScrolledWindowWidgetClass, form,
189 XmNscrollingPolicy, XmAUTOMATIC,
190 XmNtopAttachment, XmATTACH_WIDGET,
191 XmNtopWidget, mb,
192 XmNleftAttachment, XmATTACH_POSITION,
193 XmNleftPosition, 25,
194 XmNrightAttachment, XmATTACH_NONE,
195 XmNbottomAttachment, XmATTACH_NONE,
196 XmNwidth, 100,
197 XmNheight, 100,
198 NULL);
199
200 ab = XtVaCreateManagedWidget("ab", xmArrowButtonWidgetClass, sw,
201 XmNwidth, 300,
202 XmNheight, 300,
203 NULL);
204 XtAddCallback(ab,XmNactivateCallback,cb,0);
205
206 XtRealizeWidget(toplevel);
207
208
209
210 {
211 static XtWidgetGeometry Expected[] = {
212 CWWidth | CWHeight , 508, 524, 500, 300, 0,0,0, /* form */
213 CWWidth | CWHeight | CWX | CWY, 0, 0, 500, 31, 0,0,0, /* mb */
214 CWWidth | CWHeight | CWX | CWY, 5, 5, 40, 21, 0,0,0, /* File */
215 CWWidth | CWHeight | CWX | CWY, 0, 31, 125, 56, 0,0,0, /* width */
216 CWWidth | CWHeight | CWX | CWY, 0, 35, 34, 17, 0,0,0, /* Title */
217 CWWidth | CWHeight | CWX | CWY, 0, 16, 125, 19, 0,0,0, /* Scrollbar */
218 CWWidth | CWHeight | CWX | CWY, 0, 87, 125, 56, 0,0,0, /* height */
219 CWWidth | CWHeight | CWX | CWY, 0, 35, 40, 17, 0,0,0, /* Title */
220 CWWidth | CWHeight | CWX | CWY, 0, 16, 125, 19, 0,0,0, /* Scrollbar */
221 CWWidth | CWHeight | CWX | CWY, 0, 143, 125, 56, 0,0,0, /* spacing */
222 CWWidth | CWHeight | CWX | CWY, 0, 35, 46, 17, 0,0,0, /* Title */
223 CWWidth | CWHeight | CWX | CWY, 0, 16, 125, 19, 0,0,0, /* Scrollbar */
224 CWWidth | CWHeight | CWX | CWY, 0, 199, 125, 56, 0,0,0, /* shadowThickness */
225 CWWidth | CWHeight | CWX | CWY, 0, 35, 94, 17, 0,0,0, /* Title */
226 CWWidth | CWHeight | CWX | CWY, 0, 16, 125, 19, 0,0,0, /* Scrollbar */
227 CWWidth | CWHeight | CWX | CWY, 0, 255, 125, 31, 0,0,0, /* option */
228 CWWidth | CWHeight | CWX | CWY, 3, 3, 58, 25, 0,0,0, /* OptionLabel */
229 CWWidth | CWHeight | CWX | CWY, 64, 3, 109, 25, 0,0,0, /* OptionButton */
230 CWWidth | CWHeight | CWX | CWY, 125, 31, 100, 100, 0,0,0, /* sw */
231 CWWidth | CWHeight | CWX | CWY, 4, 4, 69, 69, 0,0,0, /* ScrolledWindowClipWindow */
232 CWWidth | CWHeight | CWX | CWY, 0, 0, 300, 300, 0,0,0, /* ab */
233 CWWidth | CWHeight | CWX | CWY, 81, 0, 19, 77, 0,0,0, /* VertScrollBar */
234 CWWidth | CWHeight | CWX | CWY, 0, 81, 77, 19, 0,0,0, /* HorScrollBar */
235 };
236 PrintDetails(toplevel,Expected);
237 };
238 LessTifTestMainLoop(toplevel);
239
240 exit(0);
241 }
242