Syncing some files updated after running configure
[wmaker-crm.git] / WINGs / wtest.c
blob5322101f72f5befee79bc176ebe219c552928364
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 WMRunModalFilePanelForDirectory(panel, NULL, "/usr/local", NULL, NULL);
51 /* free the panel to save some memory. Not needed otherwise. */
52 WMFreeFilePanel(WMGetOpenPanel(scr));
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);
258 void
259 sliderCallback(WMWidget *w, void *data)
261 printf("SLIEDER == %i\n", WMGetSliderValue(w));
265 void
266 testSlider(WMScreen *scr)
268 WMWindow *win;
269 WMSlider *s;
271 windowCount++;
273 win = WMCreateWindow(scr, "testSlider");
274 WMResizeWidget(win, 300, 300);
275 WMSetWindowTitle(win, "Sliders");
277 WMSetWindowCloseAction(win, closeAction, NULL);
279 s = WMCreateSlider(win);
280 WMResizeWidget(s, 16, 100);
281 WMMoveWidget(s, 100, 100);
282 WMSetSliderKnobThickness(s, 8);
283 WMSetSliderContinuous(s, False);
284 WMSetSliderAction(s, sliderCallback, s);
286 s = WMCreateSlider(win);
287 WMResizeWidget(s, 100, 16);
288 WMMoveWidget(s, 100, 10);
289 WMSetSliderKnobThickness(s, 8);
291 WMRealizeWidget(win);
292 WMMapSubwidgets(win);
293 WMMapWidget(win);
296 void
297 testTextField(WMScreen *scr)
299 WMWindow *win;
300 WMTextField *field, *field2;
302 windowCount++;
304 win = WMCreateWindow(scr, "testText");
305 WMResizeWidget(win, 400, 300);
307 WMSetWindowCloseAction(win, closeAction, NULL);
309 field = WMCreateTextField(win);
310 WMResizeWidget(field, 200, 20);
311 WMMoveWidget(field, 20, 20);
313 field2 = WMCreateTextField(win);
314 WMResizeWidget(field2, 200, 20);
315 WMMoveWidget(field2, 20, 50);
316 WMSetTextFieldAlignment(field2, WARight);
318 WMRealizeWidget(win);
319 WMMapSubwidgets(win);
320 WMMapWidget(win);
325 void
326 testPullDown(WMScreen *scr)
328 WMWindow *win;
329 WMPopUpButton *pop, *pop2;
331 windowCount++;
333 win = WMCreateWindow(scr, "pullDown");
334 WMResizeWidget(win, 400, 300);
336 WMSetWindowCloseAction(win, closeAction, NULL);
338 pop = WMCreatePopUpButton(win);
339 WMResizeWidget(pop, 100, 20);
340 WMMoveWidget(pop, 50, 60);
341 WMSetPopUpButtonPullsDown(pop, True);
342 WMSetPopUpButtonText(pop, "Commands");
343 WMAddPopUpButtonItem(pop, "Add");
344 WMAddPopUpButtonItem(pop, "Remove");
345 WMAddPopUpButtonItem(pop, "Check");
346 WMAddPopUpButtonItem(pop, "Eat");
348 pop2 = WMCreatePopUpButton(win);
349 WMResizeWidget(pop2, 100, 20);
350 WMMoveWidget(pop2, 200, 60);
351 WMSetPopUpButtonText(pop2, "Select");
352 WMAddPopUpButtonItem(pop2, "Apples");
353 WMAddPopUpButtonItem(pop2, "Bananas");
354 WMAddPopUpButtonItem(pop2, "Strawberries");
355 WMAddPopUpButtonItem(pop2, "Blueberries");
357 WMRealizeWidget(win);
358 WMMapSubwidgets(win);
359 WMMapWidget(win);
365 #include "WUtil.h"
367 int main(int argc, char **argv)
369 WMScreen *scr;
370 WMPixmap *pixmap;
372 /* Initialize the application */
373 WMInitializeApplication("Test", &argc, argv);
376 * Open connection to the X display.
378 dpy = XOpenDisplay("");
380 if (!dpy) {
381 puts("could not open display");
382 exit(1);
385 /* This is used to disable buffering of X protocol requests.
386 * Do NOT use it unless when debugging. It will cause a major
387 * slowdown in your application
389 #ifdef DEBUG
390 XSynchronize(dpy, True);
391 #endif
393 * Create screen descriptor.
395 scr = WMCreateScreen(dpy, DefaultScreen(dpy));
398 * Loads the logo of the application.
400 pixmap = WMCreatePixmapFromFile(scr, "logo.xpm");
403 * Makes the logo be used in standard dialog panels.
405 WMSetApplicationIconImage(scr, pixmap); WMReleasePixmap(pixmap);
408 * Do some test stuff.
410 * Put the testSomething() function you want to test here.
412 #if 0
413 testOpenFilePanel(scr);
414 testFontPanel(scr);
415 testList(scr);
416 testGradientButtons(scr);
417 testScrollView(scr);
418 #endif
419 testColorWell(scr);
420 #if 1
421 testSlider(scr);
422 testTextField(scr);
423 testPullDown(scr);
424 #endif
426 * The main event loop.
429 WMScreenMainLoop(scr);
431 return 0;