- made deiconification not automatically focus window in sloppy focus
[wmaker-crm.git] / WINGs / wtest.c
blobff8deb68fd015ae11dfaaff1d260b7e885f8a2c2
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 WMSetBalloonTextForView("This is a button", WMWidgetView(btn));
148 btn = WMCreateButton(win, WBTMomentaryChange);
149 WMResizeWidget(btn, 60, 24);
150 WMMoveWidget(btn, 90, 100);
151 WMSetButtonBordered(btn, False);
152 WMSetButtonImagePosition(btn, WIPOverlaps);
153 WMSetButtonImage(btn, pix1);
154 WMSetButtonAltImage(btn, pix2);
155 WMSetButtonText(btn, "Button");
157 WMSetBalloonTextForView("This is another button", WMWidgetView(btn));
159 btn = WMCreateButton(win, WBTMomentaryChange);
160 WMResizeWidget(btn, 60, 24);
161 WMMoveWidget(btn, 160, 100);
162 WMSetButtonBordered(btn, False);
163 WMSetButtonImagePosition(btn, WIPOverlaps);
164 WMSetButtonImage(btn, pix1);
165 WMSetButtonAltImage(btn, pix2);
166 WMSetButtonText(btn, "Test");
168 WMSetBalloonTextForView("This is yet another button.\nBut the balloon has 3 lines.\nYay!",
169 WMWidgetView(btn));
171 WMRealizeWidget(win);
172 WMMapSubwidgets(win);
173 WMMapWidget(win);
177 void
178 testScrollView(WMScreen *scr)
180 WMWindow *win;
181 WMScrollView *sview;
182 WMFrame *f;
183 WMLabel *l;
184 char buffer[128];
185 int i;
187 windowCount++;
189 /* creates the top-level window */
190 win = WMCreateWindow(scr, "testScroll");
191 WMSetWindowTitle(win, "Scrollable View");
193 WMSetWindowCloseAction(win, closeAction, NULL);
195 /* set the window size */
196 WMResizeWidget(win, 300, 300);
198 /* creates a scrollable view inside the top-level window */
199 sview = WMCreateScrollView(win);
200 WMResizeWidget(sview, 200, 200);
201 WMMoveWidget(sview, 30, 30);
202 WMSetScrollViewRelief(sview, WRSunken);
203 WMSetScrollViewHasVerticalScroller(sview, True);
204 WMSetScrollViewHasHorizontalScroller(sview, True);
206 /* create a frame with a bunch of labels */
207 f = WMCreateFrame(win);
208 WMResizeWidget(f, 400, 400);
209 WMSetFrameRelief(f, WRFlat);
211 for (i=0; i<20; i++) {
212 l = WMCreateLabel(f);
213 WMResizeWidget(l, 50, 18);
214 WMMoveWidget(l, 10, 20*i);
215 sprintf(buffer, "Label %i", i);
216 WMSetLabelText(l, buffer);
217 WMSetLabelRelief(l, WRSimple);
219 WMMapSubwidgets(f);
220 WMMapWidget(f);
222 WMSetScrollViewContentView(sview, WMWidgetView(f));
224 /* make the windows of the widgets be actually created */
225 WMRealizeWidget(win);
227 /* Map all child widgets of the top-level be mapped.
228 * You must call this for each container widget (like frames),
229 * even if they are childs of the top-level window.
231 WMMapSubwidgets(win);
233 /* map the top-level window */
234 WMMapWidget(win);
238 void
239 testColorWell(WMScreen *scr)
241 WMWindow *win;
242 WMColorWell *well1, *well2;
244 windowCount++;
246 win = WMCreateWindow(scr, "testColor");
247 WMResizeWidget(win, 300, 300);
249 WMSetWindowCloseAction(win, closeAction, NULL);
251 well1 = WMCreateColorWell(win);
252 WMResizeWidget(well1, 60, 40);
253 WMMoveWidget(well1, 100, 100);
254 WMSetColorWellColor(well1, WMCreateRGBColor(scr, 0x8888, 0, 0x1111, True));
255 well2 = WMCreateColorWell(win);
256 WMResizeWidget(well2, 60, 40);
257 WMMoveWidget(well2, 200, 100);
258 WMSetColorWellColor(well2, WMCreateRGBColor(scr, 0, 0, 0x8888, True));
260 WMRealizeWidget(win);
261 WMMapSubwidgets(win);
262 WMMapWidget(win);
265 void
266 sliderCallback(WMWidget *w, void *data)
268 printf("SLIEDER == %i\n", WMGetSliderValue(w));
272 void
273 testSlider(WMScreen *scr)
275 WMWindow *win;
276 WMSlider *s;
278 windowCount++;
280 win = WMCreateWindow(scr, "testSlider");
281 WMResizeWidget(win, 300, 300);
282 WMSetWindowTitle(win, "Sliders");
284 WMSetWindowCloseAction(win, closeAction, NULL);
286 s = WMCreateSlider(win);
287 WMResizeWidget(s, 16, 100);
288 WMMoveWidget(s, 100, 100);
289 WMSetSliderKnobThickness(s, 8);
290 WMSetSliderContinuous(s, False);
291 WMSetSliderAction(s, sliderCallback, s);
293 s = WMCreateSlider(win);
294 WMResizeWidget(s, 100, 16);
295 WMMoveWidget(s, 100, 10);
296 WMSetSliderKnobThickness(s, 8);
298 WMRealizeWidget(win);
299 WMMapSubwidgets(win);
300 WMMapWidget(win);
303 void
304 testTextField(WMScreen *scr)
306 WMWindow *win;
307 WMTextField *field, *field2;
309 windowCount++;
311 win = WMCreateWindow(scr, "testText");
312 WMResizeWidget(win, 400, 300);
314 WMSetWindowCloseAction(win, closeAction, NULL);
316 field = WMCreateTextField(win);
317 WMResizeWidget(field, 200, 20);
318 WMMoveWidget(field, 20, 20);
320 field2 = WMCreateTextField(win);
321 WMResizeWidget(field2, 200, 20);
322 WMMoveWidget(field2, 20, 50);
323 WMSetTextFieldAlignment(field2, WARight);
325 WMRealizeWidget(win);
326 WMMapSubwidgets(win);
327 WMMapWidget(win);
332 void
333 testPullDown(WMScreen *scr)
335 WMWindow *win;
336 WMPopUpButton *pop, *pop2;
338 windowCount++;
340 win = WMCreateWindow(scr, "pullDown");
341 WMResizeWidget(win, 400, 300);
343 WMSetWindowCloseAction(win, closeAction, NULL);
345 pop = WMCreatePopUpButton(win);
346 WMResizeWidget(pop, 100, 20);
347 WMMoveWidget(pop, 50, 60);
348 WMSetPopUpButtonPullsDown(pop, True);
349 WMSetPopUpButtonText(pop, "Commands");
350 WMAddPopUpButtonItem(pop, "Add");
351 WMAddPopUpButtonItem(pop, "Remove");
352 WMAddPopUpButtonItem(pop, "Check");
353 WMAddPopUpButtonItem(pop, "Eat");
355 pop2 = WMCreatePopUpButton(win);
356 WMResizeWidget(pop2, 100, 20);
357 WMMoveWidget(pop2, 200, 60);
358 WMSetPopUpButtonText(pop2, "Select");
359 WMAddPopUpButtonItem(pop2, "Apples");
360 WMAddPopUpButtonItem(pop2, "Bananas");
361 WMAddPopUpButtonItem(pop2, "Strawberries");
362 WMAddPopUpButtonItem(pop2, "Blueberries");
364 WMRealizeWidget(win);
365 WMMapSubwidgets(win);
366 WMMapWidget(win);
372 #include "WUtil.h"
374 int main(int argc, char **argv)
376 WMScreen *scr;
377 WMPixmap *pixmap;
379 /* Initialize the application */
380 WMInitializeApplication("Test", &argc, argv);
383 * Open connection to the X display.
385 dpy = XOpenDisplay("");
387 if (!dpy) {
388 puts("could not open display");
389 exit(1);
392 /* This is used to disable buffering of X protocol requests.
393 * Do NOT use it unless when debugging. It will cause a major
394 * slowdown in your application
396 #ifdef DEBUG
397 XSynchronize(dpy, True);
398 #endif
400 * Create screen descriptor.
402 scr = WMCreateScreen(dpy, DefaultScreen(dpy));
405 * Loads the logo of the application.
407 pixmap = WMCreatePixmapFromFile(scr, "logo.xpm");
410 * Makes the logo be used in standard dialog panels.
412 WMSetApplicationIconImage(scr, pixmap); WMReleasePixmap(pixmap);
415 * Do some test stuff.
417 * Put the testSomething() function you want to test here.
419 testGradientButtons(scr);
421 #if 0
422 testOpenFilePanel(scr);
423 testFontPanel(scr);
424 testList(scr);
425 testGradientButtons(scr);
426 testScrollView(scr);
428 testColorWell(scr);
430 testSlider(scr);
431 testTextField(scr);
432 testPullDown(scr);
433 #endif
435 * The main event loop.
438 WMScreenMainLoop(scr);
440 return 0;