Updating to version 0.20.2
[wmaker-crm.git] / WINGs / wtest.c
bloba466c6215357e7612e937d7654689f0d6dbf2d84
1 /*
2 * WINGs test application
3 */
5 #include "WINGs.h"
7 #include <stdio.h>
12 * You need to define this function to link any program to WINGs.
13 * This will be called when the application will be terminated because
14 * on a fatal error.
16 void
17 wAbort()
19 exit(1);
25 Display *dpy;
27 int windowCount = 0;
29 void
30 closeAction(WMWidget *self, void *data)
32 WMDestroyWidget(self);
33 windowCount--;
34 if (windowCount < 1)
35 exit(0);
39 void
40 testOpenFilePanel(WMScreen *scr)
42 WMOpenPanel *panel;
44 windowCount++;
46 /* get the shared Open File panel */
47 panel = WMGetOpenPanel(scr);
49 WMRunModalOpenPanelForDirectory(panel, NULL, "/usr/local", NULL, NULL);
51 /* free the panel to save some memory. Not needed otherwise. */
52 WMFreeFilePanel(panel);
56 void
57 testFontPanel(WMScreen *scr)
59 WMFontPanel *panel;
61 windowCount++;
63 panel = WMGetFontPanel(scr);
65 WMShowFontPanel(panel);
67 /* WMFreeFontPanel(panel);*/
72 void
73 testList(WMScreen *scr)
75 WMWindow *win;
76 WMList *list;
77 char text[100];
78 int i;
80 windowCount++;
82 win = WMCreateWindow(scr, "testList");
83 WMSetWindowTitle(win, "List");
84 WMSetWindowCloseAction(win, closeAction, NULL);
86 list = WMCreateList(win);
87 for (i=0; i<50; i++) {
88 sprintf(text, "Item %i", i);
89 WMAddListItem(list, text);
91 WMRealizeWidget(win);
92 WMMapSubwidgets(win);
93 WMMapWidget(win);
99 void
100 testGradientButtons(WMScreen *scr)
102 WMWindow *win;
103 WMButton *btn;
104 WMPixmap *pix1, *pix2;
105 RImage *back;
106 RColor light, dark;
107 WMColor *color;
109 windowCount++;
111 /* creates the top-level window */
112 win = WMCreateWindow(scr, "testGradientButtons");
113 WMSetWindowTitle(win, "Gradiented Button Demo");
114 WMResizeWidget(win, 300, 200);
116 light.red = 0x90;
117 light.green = 0x85;
118 light.blue = 0x90;
119 dark.red = 0x35;
120 dark.green = 0x30;
121 dark.blue = 0x35;
123 color = WMCreateRGBColor(scr, 0x5900, 0x5100, 0x5900, True);
124 WMSetWidgetBackgroundColor(win, color);
125 WMReleaseColor(color);
127 back = RRenderGradient(60, 24, &dark, &light, RGRD_DIAGONAL);
128 RBevelImage(back, RBEV_RAISED2);
129 pix1 = WMCreatePixmapFromRImage(scr, back, 0);
130 RDestroyImage(back);
132 back = RRenderGradient(60, 24, &dark, &light, RGRD_DIAGONAL);
133 RBevelImage(back, RBEV_SUNKEN);
134 pix2 = WMCreatePixmapFromRImage(scr, back, 0);
135 RDestroyImage(back);
137 btn = WMCreateButton(win, WBTMomentaryChange);
138 WMResizeWidget(btn, 60, 24);
139 WMMoveWidget(btn, 20, 100);
140 WMSetButtonBordered(btn, False);
141 WMSetButtonImagePosition(btn, WIPOverlaps);
142 WMSetButtonImage(btn, pix1);
143 WMSetButtonAltImage(btn, pix2);
144 WMSetButtonText(btn, "Cool");
146 btn = WMCreateButton(win, WBTMomentaryChange);
147 WMResizeWidget(btn, 60, 24);
148 WMMoveWidget(btn, 90, 100);
149 WMSetButtonBordered(btn, False);
150 WMSetButtonImagePosition(btn, WIPOverlaps);
151 WMSetButtonImage(btn, pix1);
152 WMSetButtonAltImage(btn, pix2);
153 WMSetButtonText(btn, "Button");
155 btn = WMCreateButton(win, WBTMomentaryChange);
156 WMResizeWidget(btn, 60, 24);
157 WMMoveWidget(btn, 160, 100);
158 WMSetButtonBordered(btn, False);
159 WMSetButtonImagePosition(btn, WIPOverlaps);
160 WMSetButtonImage(btn, pix1);
161 WMSetButtonAltImage(btn, pix2);
162 WMSetButtonText(btn, "Test");
164 WMRealizeWidget(win);
165 WMMapSubwidgets(win);
166 WMMapWidget(win);
170 void
171 testScrollView(WMScreen *scr)
173 WMWindow *win;
174 WMScrollView *sview;
175 WMFrame *f;
176 WMLabel *l;
177 char buffer[128];
178 int i;
180 windowCount++;
182 /* creates the top-level window */
183 win = WMCreateWindow(scr, "testScroll");
184 WMSetWindowTitle(win, "Scrollable View");
186 WMSetWindowCloseAction(win, closeAction, NULL);
188 /* set the window size */
189 WMResizeWidget(win, 300, 300);
191 /* creates a scrollable view inside the top-level window */
192 sview = WMCreateScrollView(win);
193 WMResizeWidget(sview, 200, 200);
194 WMMoveWidget(sview, 30, 30);
195 WMSetScrollViewRelief(sview, WRSunken);
196 WMSetScrollViewHasVerticalScroller(sview, True);
197 WMSetScrollViewHasHorizontalScroller(sview, True);
199 /* create a frame with a bunch of labels */
200 f = WMCreateFrame(win);
201 WMResizeWidget(f, 400, 400);
202 WMSetFrameRelief(f, WRFlat);
204 for (i=0; i<20; i++) {
205 l = WMCreateLabel(f);
206 WMResizeWidget(l, 50, 18);
207 WMMoveWidget(l, 10, 20*i);
208 sprintf(buffer, "Label %i", i);
209 WMSetLabelText(l, buffer);
210 WMSetLabelRelief(l, WRSimple);
212 WMMapSubwidgets(f);
213 WMMapWidget(f);
215 WMSetScrollViewContentView(sview, WMWidgetView(f));
217 /* make the windows of the widgets be actually created */
218 WMRealizeWidget(win);
220 /* Map all child widgets of the top-level be mapped.
221 * You must call this for each container widget (like frames),
222 * even if they are childs of the top-level window.
224 WMMapSubwidgets(win);
226 /* map the top-level window */
227 WMMapWidget(win);
231 void
232 testColorWell(WMScreen *scr)
234 WMWindow *win;
235 WMColorWell *well1, *well2;
237 windowCount++;
239 win = WMCreateWindow(scr, "testColor");
240 WMResizeWidget(win, 300, 300);
242 WMSetWindowCloseAction(win, closeAction, NULL);
244 well1 = WMCreateColorWell(win);
245 WMResizeWidget(well1, 60, 40);
246 WMMoveWidget(well1, 100, 100);
247 WMSetColorWellColor(well1, WMCreateRGBColor(scr, 0x8888, 0, 0x1111, True));
248 well2 = WMCreateColorWell(win);
249 WMResizeWidget(well2, 60, 40);
250 WMMoveWidget(well2, 200, 100);
251 WMSetColorWellColor(well2, WMCreateRGBColor(scr, 0, 0, 0x8888, True));
253 WMRealizeWidget(win);
254 WMMapSubwidgets(win);
255 WMMapWidget(win);
259 void
260 testSlider(WMScreen *scr)
262 WMWindow *win;
263 WMSlider *s;
265 windowCount++;
267 win = WMCreateWindow(scr, "testSlider");
268 WMResizeWidget(win, 300, 300);
269 WMSetWindowTitle(win, "Sliders");
271 WMSetWindowCloseAction(win, closeAction, NULL);
273 s = WMCreateSlider(win);
274 WMResizeWidget(s, 16, 100);
275 WMMoveWidget(s, 100, 100);
277 s = WMCreateSlider(win);
278 WMResizeWidget(s, 100, 16);
279 WMMoveWidget(s, 100, 10);
281 WMRealizeWidget(win);
282 WMMapSubwidgets(win);
283 WMMapWidget(win);
286 #if 0
287 void
288 testText(WMScreen *scr)
290 WMWindow *win;
291 WMSimpleText *text;
293 windowCount++;
295 win = WMCreateWindow(scr, "testText");
296 WMResizeWidget(win, 300, 300);
297 WMSetWindowTitle(win, "Text");
299 WMSetWindowCloseAction(win, closeAction, NULL);
301 text = WMCreateSimpleText(win);
302 WMResizeWidget(text, 280, 280);
303 WMMoveWidget(text, 10, 10);
305 WMRealizeWidget(win);
306 WMMapSubwidgets(win);
307 WMMapWidget(win);
309 #endif
311 void
312 testTextField(WMScreen *scr)
314 WMWindow *win;
315 WMTextField *field, *field2;
317 windowCount++;
319 win = WMCreateWindow(scr, "testText");
320 WMResizeWidget(win, 400, 300);
322 WMSetWindowCloseAction(win, closeAction, NULL);
324 field = WMCreateTextField(win);
325 WMResizeWidget(field, 200, 20);
326 WMMoveWidget(field, 20, 20);
328 field2 = WMCreateTextField(win);
329 WMResizeWidget(field2, 200, 20);
330 WMMoveWidget(field2, 20, 50);
331 WMSetTextFieldAlignment(field2, WARight);
333 WMRealizeWidget(win);
334 WMMapSubwidgets(win);
335 WMMapWidget(win);
340 void
341 testPullDown(WMScreen *scr)
343 WMWindow *win;
344 WMPopUpButton *pop, *pop2;
346 windowCount++;
348 win = WMCreateWindow(scr, "pullDown");
349 WMResizeWidget(win, 400, 300);
351 WMSetWindowCloseAction(win, closeAction, NULL);
353 pop = WMCreatePopUpButton(win);
354 WMResizeWidget(pop, 100, 20);
355 WMMoveWidget(pop, 50, 60);
356 WMSetPopUpButtonPullsDown(pop, True);
357 WMSetPopUpButtonText(pop, "Commands");
358 WMAddPopUpButtonItem(pop, "Add");
359 WMAddPopUpButtonItem(pop, "Remove");
360 WMAddPopUpButtonItem(pop, "Check");
361 WMAddPopUpButtonItem(pop, "Eat");
363 pop2 = WMCreatePopUpButton(win);
364 WMResizeWidget(pop2, 100, 20);
365 WMMoveWidget(pop2, 200, 60);
366 WMSetPopUpButtonText(pop2, "Select");
367 WMAddPopUpButtonItem(pop2, "Apples");
368 WMAddPopUpButtonItem(pop2, "Bananas");
369 WMAddPopUpButtonItem(pop2, "Strawberries");
370 WMAddPopUpButtonItem(pop2, "Blueberries");
372 WMRealizeWidget(win);
373 WMMapSubwidgets(win);
374 WMMapWidget(win);
380 #include "WUtil.h"
382 int main(int argc, char **argv)
384 WMScreen *scr;
385 WMPixmap *pixmap;
387 /* Initialize the application */
388 WMInitializeApplication("Test", &argc, argv);
391 * Open connection to the X display.
393 dpy = XOpenDisplay("");
395 if (!dpy) {
396 puts("could not open display");
397 exit(1);
400 /* This is used to disable buffering of X protocol requests.
401 * Do NOT use it unless when debugging. It will cause a major
402 * slowdown in your application
404 #ifdef DEBUG
405 XSynchronize(dpy, True);
406 #endif
408 * Create screen descriptor.
410 scr = WMCreateScreen(dpy, DefaultScreen(dpy));
413 * Loads the logo of the application.
415 pixmap = WMCreatePixmapFromFile(scr, "logo.xpm");
418 * Makes the logo be used in standard dialog panels.
420 WMSetApplicationIconImage(scr, pixmap); WMReleasePixmap(pixmap);
423 * Do some test stuff.
425 * Put the testSomething() function you want to test here.
427 #if 1
428 testOpenFilePanel(scr);
429 testFontPanel(scr);
430 testList(scr);
431 testGradientButtons(scr);
432 testScrollView(scr);
433 testColorWell(scr);
434 testSlider(scr);
435 testTextField(scr);
436 testPullDown(scr);
437 #endif
439 * The main event loop.
442 WMScreenMainLoop(scr);
444 return 0;