Change to the linux kernel coding style
[wmaker-crm.git] / WINGs / Tests / wtest.c
1 /*
2  * WINGs test application
3  */
4
5 #include <WINGs/WINGs.h>
6
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10
11 /*
12  * You need to define this function to link any program to WINGs.
13  * (this is no longer required as there is a default abort handler in WINGs)
14  * This will be called when the application will be terminated because
15  * of a fatal error (only for memory allocation failures ATM).
16  */
17 void wAbort()
18 {
19         exit(1);
20 }
21
22 Display *dpy;
23
24 int windowCount = 0;
25
26 void closeAction(WMWidget * self, void *data)
27 {
28         WMDestroyWidget(self);
29         windowCount--;
30         printf("window closed, window count = %d\n", windowCount);
31         if (windowCount < 1)
32                 exit(0);
33 }
34
35 void testOpenFilePanel(WMScreen * scr)
36 {
37         WMOpenPanel *panel;
38
39         /* windowCount++; */
40
41         /* get the shared Open File panel */
42         panel = WMGetOpenPanel(scr);
43
44         WMRunModalFilePanelForDirectory(panel, NULL, "/usr/local", NULL, NULL);
45
46         /* free the panel to save some memory. Not needed otherwise. */
47         WMFreeFilePanel(WMGetOpenPanel(scr));
48 }
49
50 void testFontPanel(WMScreen * scr)
51 {
52         WMFontPanel *panel;
53
54         /*windowCount++; */
55
56         panel = WMGetFontPanel(scr);
57
58         WMShowFontPanel(panel);
59
60         /*WMFreeFontPanel(panel); */
61 }
62
63 void testFrame(WMScreen * scr)
64 {
65         WMWindow *win;
66         WMFrame *frame;
67         int i;
68         static char *titles[] = {
69                 "AboveTop",
70                 "AtTop",
71                 "BelowTop",
72                 "AboveBottom",
73                 "AtBottom",
74                 "BelowBottom"
75         };
76         static WMTitlePosition pos[] = {
77                 WTPAboveTop,
78                 WTPAtTop,
79                 WTPBelowTop,
80                 WTPAboveBottom,
81                 WTPAtBottom,
82                 WTPBelowBottom
83         };
84
85         windowCount++;
86
87         win = WMCreateWindow(scr, "testFrame");
88         WMSetWindowTitle(win, "Frame");
89         WMSetWindowCloseAction(win, closeAction, NULL);
90         WMResizeWidget(win, 400, 300);
91
92         for (i = 0; i < 6; i++) {
93                 frame = WMCreateFrame(win);
94                 WMMoveWidget(frame, 8 + (i % 3) * 130, 8 + (i / 3) * 130);
95                 WMResizeWidget(frame, 120, 120);
96                 WMSetFrameTitle(frame, titles[i]);
97                 WMSetFrameTitlePosition(frame, pos[i]);
98         }
99
100         WMRealizeWidget(win);
101         WMMapSubwidgets(win);
102         WMMapWidget(win);
103
104 }
105
106 /*static void
107  resizedWindow(void *self, WMNotification *notif)
108  {
109  WMView *view = (WMView*)WMGetNotificationObject(notif);
110  WMSize size = WMGetViewSize(view);
111
112  WMResizeWidget((WMWidget*)self, size.width, size.height);
113  }*/
114
115 void testBox(WMScreen * scr)
116 {
117         WMWindow *win;
118         WMBox *box, *hbox;
119         WMButton *btn;
120         WMPopUpButton *pop;
121         int i;
122
123         windowCount++;
124
125         win = WMCreateWindow(scr, "testBox");
126         WMSetWindowTitle(win, "Box");
127         WMSetWindowCloseAction(win, closeAction, NULL);
128         WMResizeWidget(win, 400, 300);
129
130         box = WMCreateBox(win);
131         WMSetBoxBorderWidth(box, 5);
132         WMSetViewExpandsToParent(WMWidgetView(box), 0, 0, 0, 0);
133
134         /*WMSetBoxHorizontal(box, True); */
135         for (i = 0; i < 4; i++) {
136                 btn = WMCreateCommandButton(box);
137                 WMSetButtonText(btn, "bla");
138                 WMMapWidget(btn);
139                 WMAddBoxSubview(box, WMWidgetView(btn), i & 1, True, 20, 0, 5);
140         }
141
142         pop = WMCreatePopUpButton(box);
143         WMAddPopUpButtonItem(pop, "ewqeq");
144         WMAddPopUpButtonItem(pop, "ewqeqrewrw");
145         WMAddBoxSubview(box, WMWidgetView(pop), False, True, 20, 0, 5);
146         WMMapWidget(pop);
147
148         hbox = WMCreateBox(box);
149         WMSetBoxHorizontal(hbox, True);
150         WMAddBoxSubview(box, WMWidgetView(hbox), False, True, 24, 0, 0);
151         WMMapWidget(hbox);
152
153         for (i = 0; i < 4; i++) {
154                 btn = WMCreateCommandButton(hbox);
155                 WMSetButtonText(btn, "bla");
156                 WMMapWidget(btn);
157                 WMAddBoxSubview(hbox, WMWidgetView(btn), 1, True, 60, 0, i < 3 ? 5 : 0);
158         }
159
160         WMRealizeWidget(win);
161         WMMapSubwidgets(win);
162         WMMapWidget(win);
163
164 }
165
166 static void singleClick(WMWidget * self, void *data)
167 {
168 }
169
170 static void doubleClick(WMWidget * self, void *data)
171 {
172         WMSelectAllListItems((WMList *) self);
173 }
174
175 static void listSelectionObserver(void *observer, WMNotification * notification)
176 {
177         WMLabel *label = (WMLabel *) observer;
178         WMList *lPtr = (WMList *) WMGetNotificationObject(notification);
179         char buf[255];
180
181         sprintf(buf, "Selected items: %d", WMGetArrayItemCount(WMGetListSelectedItems(lPtr)));
182         WMSetLabelText(label, buf);
183 }
184
185 void testList(WMScreen * scr)
186 {
187         WMWindow *win;
188         WMList *list;
189         WMList *mlist;
190         WMLabel *label;
191         WMLabel *mlabel;
192         WMLabel *title;
193         WMLabel *mtitle;
194         char text[100];
195         int i;
196
197         windowCount++;
198
199         win = WMCreateWindow(scr, "testList");
200         WMResizeWidget(win, 370, 250);
201         WMSetWindowTitle(win, "List");
202         WMSetWindowCloseAction(win, closeAction, NULL);
203
204         title = WMCreateLabel(win);
205         WMResizeWidget(title, 150, 20);
206         WMMoveWidget(title, 10, 10);
207         WMSetLabelRelief(title, WRRidge);
208         WMSetLabelText(title, "Single selection list");
209
210         mtitle = WMCreateLabel(win);
211         WMResizeWidget(mtitle, 150, 20);
212         WMMoveWidget(mtitle, 210, 10);
213         WMSetLabelRelief(mtitle, WRRidge);
214         WMSetLabelText(mtitle, "Multiple selection list");
215
216         list = WMCreateList(win);
217         /*WMSetListAllowEmptySelection(list, True); */
218         WMMoveWidget(list, 10, 40);
219         for (i = 0; i < 105; i++) {
220                 sprintf(text, "Item %i", i);
221                 WMAddListItem(list, text);
222         }
223         mlist = WMCreateList(win);
224         WMSetListAllowMultipleSelection(mlist, True);
225         /*WMSetListAllowEmptySelection(mlist, True); */
226         WMMoveWidget(mlist, 210, 40);
227         for (i = 0; i < 135; i++) {
228                 sprintf(text, "Item %i", i);
229                 WMAddListItem(mlist, text);
230         }
231
232         label = WMCreateLabel(win);
233         WMResizeWidget(label, 150, 40);
234         WMMoveWidget(label, 10, 200);
235         WMSetLabelRelief(label, WRRidge);
236         WMSetLabelText(label, "Selected items: 0");
237
238         mlabel = WMCreateLabel(win);
239         WMResizeWidget(mlabel, 150, 40);
240         WMMoveWidget(mlabel, 210, 200);
241         WMSetLabelRelief(mlabel, WRRidge);
242         WMSetLabelText(mlabel, "Selected items: 0");
243
244         WMSetListAction(list, singleClick, label);
245         WMSetListDoubleAction(list, doubleClick, label);
246         WMSetListAction(mlist, singleClick, mlabel);
247         WMSetListDoubleAction(mlist, doubleClick, mlabel);
248
249         WMAddNotificationObserver(listSelectionObserver, label, WMListSelectionDidChangeNotification, list);
250         WMAddNotificationObserver(listSelectionObserver, mlabel, WMListSelectionDidChangeNotification, mlist);
251
252         WMRealizeWidget(win);
253         WMMapSubwidgets(win);
254         WMMapWidget(win);
255 }
256
257 void testButton(WMScreen * scr)
258 {
259         WMWindow *win;
260         int i;
261         char *types[] = {
262                 "MomentaryPush",
263                 "PushOnPushOff",
264                 "Toggle",
265                 "Switch",
266                 "Radio",
267                 "MomentaryChange",
268                 "OnOff",
269                 "MomentaryLigh"
270         };
271
272         windowCount++;
273
274         win = WMCreateWindow(scr, "testButton");
275         WMResizeWidget(win, 300, 300);
276         WMSetWindowTitle(win, "Buttons");
277
278         WMSetWindowCloseAction(win, closeAction, NULL);
279
280         for (i = 1; i < 9; i++) {
281                 WMButton *b;
282                 b = WMCreateButton(win, i);
283                 WMResizeWidget(b, 150, 24);
284                 WMMoveWidget(b, 20, i * 30);
285                 WMSetButtonText(b, types[i - 1]);
286         }
287
288         WMRealizeWidget(win);
289         WMMapSubwidgets(win);
290         WMMapWidget(win);
291 }
292
293 void testGradientButtons(WMScreen * scr)
294 {
295         WMWindow *win;
296         WMButton *btn;
297         WMPixmap *pix1, *pix2;
298         RImage *back;
299         RColor light, dark;
300         WMColor *color, *altColor;
301
302         windowCount++;
303
304         /* creates the top-level window */
305         win = WMCreateWindow(scr, "testGradientButtons");
306         WMSetWindowTitle(win, "Gradiented Button Demo");
307         WMResizeWidget(win, 300, 200);
308
309         WMSetWindowCloseAction(win, closeAction, NULL);
310
311         light.red = 0x90;
312         light.green = 0x85;
313         light.blue = 0x90;
314         dark.red = 0x35;
315         dark.green = 0x30;
316         dark.blue = 0x35;
317
318         color = WMCreateRGBColor(scr, 0x5900, 0x5100, 0x5900, True);
319         WMSetWidgetBackgroundColor(win, color);
320         WMReleaseColor(color);
321
322         back = RRenderGradient(60, 24, &dark, &light, RGRD_DIAGONAL);
323         RBevelImage(back, RBEV_RAISED2);
324         pix1 = WMCreatePixmapFromRImage(scr, back, 0);
325         RReleaseImage(back);
326
327         back = RRenderGradient(60, 24, &dark, &light, RGRD_DIAGONAL);
328         RBevelImage(back, RBEV_SUNKEN);
329         pix2 = WMCreatePixmapFromRImage(scr, back, 0);
330         RReleaseImage(back);
331
332         color = WMWhiteColor(scr);
333         altColor = WMCreateNamedColor(scr, "red", True);
334
335         btn = WMCreateButton(win, WBTMomentaryChange);
336         WMResizeWidget(btn, 60, 24);
337         WMMoveWidget(btn, 20, 100);
338         WMSetButtonBordered(btn, False);
339         WMSetButtonImagePosition(btn, WIPOverlaps);
340         WMSetButtonImage(btn, pix1);
341         WMSetButtonAltImage(btn, pix2);
342         WMSetButtonText(btn, "Cool");
343         WMSetButtonTextColor(btn, color);
344         WMSetButtonAltTextColor(btn, altColor);
345
346         WMSetBalloonTextForView("This is a cool button", WMWidgetView(btn));
347
348         btn = WMCreateButton(win, WBTMomentaryChange);
349         WMResizeWidget(btn, 60, 24);
350         WMMoveWidget(btn, 90, 100);
351         WMSetButtonBordered(btn, False);
352         WMSetButtonImagePosition(btn, WIPOverlaps);
353         WMSetButtonImage(btn, pix1);
354         WMSetButtonAltImage(btn, pix2);
355         WMSetButtonText(btn, "Button");
356         WMSetButtonTextColor(btn, color);
357
358         WMSetBalloonTextForView("Este Ã© outro balão.", WMWidgetView(btn));
359
360         WMReleaseColor(color);
361         color = WMCreateNamedColor(scr, "orange", True);
362
363         btn = WMCreateButton(win, WBTMomentaryChange);
364         WMResizeWidget(btn, 60, 24);
365         WMMoveWidget(btn, 160, 100);
366         WMSetButtonBordered(btn, False);
367         WMSetButtonImagePosition(btn, WIPOverlaps);
368         WMSetButtonImage(btn, pix1);
369         WMSetButtonAltImage(btn, pix2);
370         WMSetButtonText(btn, "Test");
371         WMSetButtonTextColor(btn, color);
372
373         WMSetBalloonTextForView("This is yet another button.\nBut the balloon has 3 lines.\nYay!",
374                                 WMWidgetView(btn));
375
376         WMReleaseColor(color);
377         WMReleaseColor(altColor);
378
379         WMRealizeWidget(win);
380         WMMapSubwidgets(win);
381         WMMapWidget(win);
382 }
383
384 void testScrollView(WMScreen * scr)
385 {
386         WMWindow *win;
387         WMScrollView *sview;
388         WMFrame *f;
389         WMLabel *l;
390         char buffer[128];
391         int i;
392
393         windowCount++;
394
395         /* creates the top-level window */
396         win = WMCreateWindow(scr, "testScroll");
397         WMSetWindowTitle(win, "Scrollable View");
398
399         WMSetWindowCloseAction(win, closeAction, NULL);
400
401         /* set the window size */
402         WMResizeWidget(win, 300, 300);
403
404         /* creates a scrollable view inside the top-level window */
405         sview = WMCreateScrollView(win);
406         WMResizeWidget(sview, 200, 200);
407         WMMoveWidget(sview, 30, 30);
408         WMSetScrollViewRelief(sview, WRSunken);
409         WMSetScrollViewHasVerticalScroller(sview, True);
410         WMSetScrollViewHasHorizontalScroller(sview, True);
411
412         /* create a frame with a bunch of labels */
413         f = WMCreateFrame(win);
414         WMResizeWidget(f, 400, 400);
415         WMSetFrameRelief(f, WRFlat);
416
417         for (i = 0; i < 20; i++) {
418                 l = WMCreateLabel(f);
419                 WMResizeWidget(l, 50, 18);
420                 WMMoveWidget(l, 10, 20 * i);
421                 sprintf(buffer, "Label %i", i);
422                 WMSetLabelText(l, buffer);
423                 WMSetLabelRelief(l, WRSimple);
424         }
425         WMMapSubwidgets(f);
426         WMMapWidget(f);
427
428         WMSetScrollViewContentView(sview, WMWidgetView(f));
429
430         /* make the windows of the widgets be actually created */
431         WMRealizeWidget(win);
432
433         /* Map all child widgets of the top-level be mapped.
434          * You must call this for each container widget (like frames),
435          * even if they are childs of the top-level window.
436          */
437         WMMapSubwidgets(win);
438
439         /* map the top-level window */
440         WMMapWidget(win);
441 }
442
443 void testColorWell(WMScreen * scr)
444 {
445         WMWindow *win;
446         WMColorWell *well1, *well2;
447
448         windowCount++;
449
450         win = WMCreateWindow(scr, "testColor");
451         WMResizeWidget(win, 300, 300);
452         WMSetWindowCloseAction(win, closeAction, NULL);
453
454         well1 = WMCreateColorWell(win);
455         WMResizeWidget(well1, 60, 40);
456         WMMoveWidget(well1, 100, 100);
457         WMSetColorWellColor(well1, WMCreateRGBColor(scr, 0x8888, 0, 0x1111, True));
458         well2 = WMCreateColorWell(win);
459         WMResizeWidget(well2, 60, 40);
460         WMMoveWidget(well2, 200, 100);
461         WMSetColorWellColor(well2, WMCreateRGBColor(scr, 0, 0, 0x8888, True));
462
463         WMRealizeWidget(win);
464         WMMapSubwidgets(win);
465         WMMapWidget(win);
466 }
467
468 void testColorPanel(WMScreen * scr)
469 {
470         WMColorPanel *panel = WMGetColorPanel(scr);
471
472         /*if (colorname) {
473            startcolor = WMCreateNamedColor(scr, colorname, False);
474            WMSetColorPanelColor(panel, startcolor);
475            WMReleaseColor(startcolor);
476            } */
477
478         WMShowColorPanel(panel);
479 }
480
481 void sliderCallback(WMWidget * w, void *data)
482 {
483         printf("SLIDER == %i\n", WMGetSliderValue(w));
484 }
485
486 void testSlider(WMScreen * scr)
487 {
488         WMWindow *win;
489         WMSlider *s;
490
491         windowCount++;
492
493         win = WMCreateWindow(scr, "testSlider");
494         WMResizeWidget(win, 300, 300);
495         WMSetWindowTitle(win, "Sliders");
496
497         WMSetWindowCloseAction(win, closeAction, NULL);
498
499         s = WMCreateSlider(win);
500         WMResizeWidget(s, 16, 100);
501         WMMoveWidget(s, 100, 100);
502         WMSetSliderKnobThickness(s, 8);
503         WMSetSliderContinuous(s, False);
504         WMSetSliderAction(s, sliderCallback, s);
505
506         s = WMCreateSlider(win);
507         WMResizeWidget(s, 100, 16);
508         WMMoveWidget(s, 100, 10);
509         WMSetSliderKnobThickness(s, 8);
510
511         WMRealizeWidget(win);
512         WMMapSubwidgets(win);
513         WMMapWidget(win);
514 }
515
516 void testTextField(WMScreen * scr)
517 {
518         WMWindow *win;
519         WMTextField *field, *field2;
520
521         windowCount++;
522
523         win = WMCreateWindow(scr, "testTextField");
524         WMResizeWidget(win, 400, 300);
525
526         WMSetWindowCloseAction(win, closeAction, NULL);
527
528         field = WMCreateTextField(win);
529         WMResizeWidget(field, 200, 20);
530         WMMoveWidget(field, 20, 20);
531         WMSetTextFieldText(field, "the little \xc2\xa9 sign");
532
533         field2 = WMCreateTextField(win);
534         WMResizeWidget(field2, 200, 20);
535         WMMoveWidget(field2, 20, 50);
536         WMSetTextFieldAlignment(field2, WARight);
537
538         WMRealizeWidget(win);
539         WMMapSubwidgets(win);
540         WMMapWidget(win);
541
542 }
543
544 void testText(WMScreen * scr)
545 {
546         WMWindow *win;
547         WMText *text;
548         WMFont *font;
549         void *tb;
550         FILE *file = fopen("wm.html", "rb");
551
552         windowCount++;
553
554         win = WMCreateWindow(scr, "testText");
555         WMResizeWidget(win, 500, 300);
556
557         WMSetWindowCloseAction(win, closeAction, NULL);
558
559         text = WMCreateText(win);
560         WMResizeWidget(text, 480, 280);
561         WMMoveWidget(text, 10, 10);
562         WMSetTextHasVerticalScroller(text, True);
563         WMSetTextEditable(text, False);
564         WMSetTextIgnoresNewline(text, False);
565
566 #define FNAME "Verdana,Luxi Sans:pixelsize=12"
567 #define MSG \
568     "Window Maker is the GNU window manager for the " \
569     "X Window System. It was designed to emulate the " \
570     "look and feel of part of the NEXTSTEP(tm) GUI. It's " \
571     "supposed to be relatively fast and small, feature " \
572     "rich, easy to configure and easy to use, with a simple " \
573     "and elegant appearance borrowed from NEXTSTEP(tm)."
574
575         font = WMCreateFont(scr, FNAME ":autohint=false");
576         WMSetTextDefaultFont(text, font);
577         WMReleaseFont(font);
578
579         if (0 && file) {
580                 char buf[1024];
581
582                 WMFreezeText(text);
583                 while (fgets(buf, 1023, file))
584                         WMAppendTextStream(text, buf);
585
586                 fclose(file);
587                 WMThawText(text);
588         } else {
589                 WMAppendTextStream(text, "First paragraph has autohinting turned off, "
590                                    "while the second has it turned on:");
591                 WMAppendTextStream(text, "\n\n\n");
592                 WMAppendTextStream(text, MSG);
593                 WMAppendTextStream(text, "\n\n\n");
594                 font = WMCreateFont(scr, FNAME ":autohint=true");
595                 tb = WMCreateTextBlockWithText(text, MSG, font, WMBlackColor(scr), 0, strlen(MSG));
596                 WMAppendTextBlock(text, tb);
597                 WMReleaseFont(font);
598         }
599
600         WMRealizeWidget(win);
601         WMMapSubwidgets(win);
602         WMMapWidget(win);
603 }
604
605 void testProgressIndicator(WMScreen * scr)
606 {
607         WMWindow *win;
608         WMProgressIndicator *pPtr;
609
610         windowCount++;
611
612         win = WMCreateWindow(scr, "testProgressIndicator");
613         WMResizeWidget(win, 292, 32);
614
615         WMSetWindowCloseAction(win, closeAction, NULL);
616
617         pPtr = WMCreateProgressIndicator(win);
618         WMMoveWidget(pPtr, 8, 8);
619         WMSetProgressIndicatorValue(pPtr, 75);
620
621         WMRealizeWidget(win);
622         WMMapSubwidgets(win);
623         WMMapWidget(win);
624
625 }
626
627 void testPullDown(WMScreen * scr)
628 {
629         WMWindow *win;
630         WMPopUpButton *pop, *pop2;
631
632         windowCount++;
633
634         win = WMCreateWindow(scr, "pullDown");
635         WMResizeWidget(win, 400, 300);
636
637         WMSetWindowCloseAction(win, closeAction, NULL);
638
639         pop = WMCreatePopUpButton(win);
640         WMResizeWidget(pop, 100, 20);
641         WMMoveWidget(pop, 50, 60);
642         WMSetPopUpButtonPullsDown(pop, True);
643         WMSetPopUpButtonText(pop, "Commands");
644         WMAddPopUpButtonItem(pop, "Add");
645         WMAddPopUpButtonItem(pop, "Remove");
646         WMAddPopUpButtonItem(pop, "Check");
647         WMAddPopUpButtonItem(pop, "Eat");
648
649         pop2 = WMCreatePopUpButton(win);
650         WMResizeWidget(pop2, 100, 20);
651         WMMoveWidget(pop2, 200, 60);
652         WMSetPopUpButtonText(pop2, "Select");
653         WMAddPopUpButtonItem(pop2, "Apples");
654         WMAddPopUpButtonItem(pop2, "Bananas");
655         WMAddPopUpButtonItem(pop2, "Strawberries");
656         WMAddPopUpButtonItem(pop2, "Blueberries");
657
658         WMRealizeWidget(win);
659         WMMapSubwidgets(win);
660         WMMapWidget(win);
661
662 }
663
664 void testTabView(WMScreen * scr)
665 {
666         WMWindow *win;
667         WMTabView *tabv;
668         WMTabViewItem *tab;
669         WMFrame *frame;
670         WMLabel *label;
671
672         windowCount++;
673
674         win = WMCreateWindow(scr, "testTabs");
675         WMResizeWidget(win, 400, 300);
676
677         WMSetWindowCloseAction(win, closeAction, NULL);
678
679         tabv = WMCreateTabView(win);
680         WMMoveWidget(tabv, 50, 50);
681         WMResizeWidget(tabv, 300, 200);
682
683         frame = WMCreateFrame(win);
684         WMSetFrameRelief(frame, WRFlat);
685         label = WMCreateLabel(frame);
686         WMResizeWidget(label, 100, 100);
687         WMSetLabelText(label, "Label 1");
688         WMMapWidget(label);
689
690         tab = WMCreateTabViewItemWithIdentifier(0);
691         WMSetTabViewItemView(tab, WMWidgetView(frame));
692         WMAddItemInTabView(tabv, tab);
693         WMSetTabViewItemLabel(tab, "Instances");
694
695         frame = WMCreateFrame(win);
696         WMSetFrameRelief(frame, WRFlat);
697         label = WMCreateLabel(frame);
698         WMResizeWidget(label, 40, 50);
699         WMSetLabelText(label, "Label 2");
700         WMMapWidget(label);
701
702         tab = WMCreateTabViewItemWithIdentifier(0);
703         WMSetTabViewItemView(tab, WMWidgetView(frame));
704         WMAddItemInTabView(tabv, tab);
705         WMSetTabViewItemLabel(tab, "Classes");
706
707         frame = WMCreateFrame(win);
708         WMSetFrameRelief(frame, WRFlat);
709         label = WMCreateLabel(frame);
710         WMResizeWidget(label, 100, 100);
711         WMMoveWidget(label, 60, 40);
712         WMSetLabelText(label, "Label 3");
713         WMMapWidget(label);
714
715         tab = WMCreateTabViewItemWithIdentifier(0);
716         WMSetTabViewItemView(tab, WMWidgetView(frame));
717         WMAddItemInTabView(tabv, tab);
718         WMSetTabViewItemLabel(tab, "Something");
719
720         frame = WMCreateFrame(win);
721         WMSetFrameRelief(frame, WRFlat);
722         label = WMCreateLabel(frame);
723         WMResizeWidget(label, 100, 100);
724         WMMoveWidget(label, 160, 40);
725         WMSetLabelText(label, "Label 4");
726         WMMapWidget(label);
727
728         tab = WMCreateTabViewItemWithIdentifier(0);
729         WMSetTabViewItemView(tab, WMWidgetView(frame));
730         WMAddItemInTabView(tabv, tab);
731         WMSetTabViewItemLabel(tab, "Bla!");
732
733         frame = WMCreateFrame(win);
734         WMSetFrameRelief(frame, WRFlat);
735         label = WMCreateLabel(frame);
736         WMResizeWidget(label, 100, 100);
737         WMMoveWidget(label, 160, 40);
738         WMSetLabelText(label, "Label fjweqklrj qwl");
739         WMMapWidget(label);
740         tab = WMCreateTabViewItemWithIdentifier(0);
741         WMSetTabViewItemView(tab, WMWidgetView(frame));
742         WMAddItemInTabView(tabv, tab);
743         WMSetTabViewItemLabel(tab, "Weee!");
744
745         WMRealizeWidget(win);
746         WMMapSubwidgets(win);
747         WMMapWidget(win);
748 }
749
750 void splitViewConstrainProc(WMSplitView * sPtr, int indView, int *minSize, int *maxSize)
751 {
752         switch (indView) {
753         case 0:
754                 *minSize = 20;
755                 break;
756         case 1:
757                 *minSize = 40;
758                 *maxSize = 80;
759                 break;
760         case 2:
761                 *maxSize = 60;
762                 break;
763         default:
764                 break;
765         }
766 }
767
768 static void resizeSplitView(XEvent * event, void *data)
769 {
770         WMSplitView *sPtr = (WMSplitView *) data;
771
772         if (event->type == ConfigureNotify) {
773                 int width = event->xconfigure.width - 10;
774
775                 if (width < WMGetSplitViewDividerThickness(sPtr))
776                         width = WMGetSplitViewDividerThickness(sPtr);
777
778                 if (width != WMWidgetWidth(sPtr) || event->xconfigure.height != WMWidgetHeight(sPtr))
779                         WMResizeWidget(sPtr, width, event->xconfigure.height - 55);
780         }
781 }
782
783 void appendSubviewButtonAction(WMWidget * self, void *data)
784 {
785         WMSplitView *sPtr = (WMSplitView *) data;
786         char buf[64];
787         WMLabel *label = WMCreateLabel(sPtr);
788
789         sprintf(buf, "Subview %d", WMGetSplitViewSubviewsCount(sPtr) + 1);
790         WMSetLabelText(label, buf);
791         WMSetLabelRelief(label, WRSunken);
792         WMAddSplitViewSubview(sPtr, WMWidgetView(label));
793         WMRealizeWidget(label);
794         WMMapWidget(label);
795 }
796
797 void removeSubviewButtonAction(WMWidget * self, void *data)
798 {
799         WMSplitView *sPtr = (WMSplitView *) data;
800         int count = WMGetSplitViewSubviewsCount(sPtr);
801
802         if (count > 2) {
803                 WMView *view = WMGetSplitViewSubviewAt(sPtr, count - 1);
804                 WMDestroyWidget(WMWidgetOfView(view));
805                 WMRemoveSplitViewSubviewAt(sPtr, count - 1);
806         }
807 }
808
809 void orientationButtonAction(WMWidget * self, void *data)
810 {
811         WMSplitView *sPtr = (WMSplitView *) data;
812         WMSetSplitViewVertical(sPtr, !WMGetSplitViewVertical(sPtr));
813 }
814
815 void adjustSubviewsButtonAction(WMWidget * self, void *data)
816 {
817         WMAdjustSplitViewSubviews((WMSplitView *) data);
818 }
819
820 void testSplitView(WMScreen * scr)
821 {
822         WMWindow *win;
823         WMSplitView *splitv1, *splitv2;
824         WMFrame *frame;
825         WMLabel *label;
826         WMButton *button;
827
828         windowCount++;
829
830         win = WMCreateWindow(scr, "testTabs");
831         WMResizeWidget(win, 300, 400);
832         WMSetWindowCloseAction(win, closeAction, NULL);
833
834         frame = WMCreateFrame(win);
835         WMSetFrameRelief(frame, WRSunken);
836         WMMoveWidget(frame, 5, 5);
837         WMResizeWidget(frame, 290, 40);
838
839         splitv1 = WMCreateSplitView(win);
840         WMMoveWidget(splitv1, 5, 50);
841         WMResizeWidget(splitv1, 290, 345);
842         WMSetSplitViewConstrainProc(splitv1, splitViewConstrainProc);
843         WMCreateEventHandler(WMWidgetView(win), StructureNotifyMask, resizeSplitView, splitv1);
844
845         button = WMCreateCommandButton(frame);
846         WMSetButtonText(button, "+");
847         WMSetButtonAction(button, appendSubviewButtonAction, splitv1);
848         WMMoveWidget(button, 10, 8);
849         WMMapWidget(button);
850
851         button = WMCreateCommandButton(frame);
852         WMSetButtonText(button, "-");
853         WMSetButtonAction(button, removeSubviewButtonAction, splitv1);
854         WMMoveWidget(button, 80, 8);
855         WMMapWidget(button);
856
857         button = WMCreateCommandButton(frame);
858         WMSetButtonText(button, "=");
859         WMMoveWidget(button, 150, 8);
860         WMSetButtonAction(button, adjustSubviewsButtonAction, splitv1);
861         WMMapWidget(button);
862
863         button = WMCreateCommandButton(frame);
864         WMSetButtonText(button, "#");
865         WMMoveWidget(button, 220, 8);
866         WMSetButtonAction(button, orientationButtonAction, splitv1);
867         WMMapWidget(button);
868
869         label = WMCreateLabel(splitv1);
870         WMSetLabelText(label, "Subview 1");
871         WMSetLabelRelief(label, WRSunken);
872         WMMapWidget(label);
873         WMAddSplitViewSubview(splitv1, WMWidgetView(label));
874
875         splitv2 = WMCreateSplitView(splitv1);
876         WMResizeWidget(splitv2, 150, 150);
877         WMSetSplitViewVertical(splitv2, True);
878
879         label = WMCreateLabel(splitv2);
880         WMSetLabelText(label, "Subview 2.1");
881         WMSetLabelRelief(label, WRSunken);
882         WMMapWidget(label);
883         WMAddSplitViewSubview(splitv2, WMWidgetView(label));
884
885         label = WMCreateLabel(splitv2);
886         WMSetLabelText(label, "Subview 2.2");
887         WMSetLabelRelief(label, WRSunken);
888         WMMapWidget(label);
889         WMAddSplitViewSubview(splitv2, WMWidgetView(label));
890
891         label = WMCreateLabel(splitv2);
892         WMSetLabelText(label, "Subview 2.3");
893         WMSetLabelRelief(label, WRSunken);
894         WMMapWidget(label);
895         WMAddSplitViewSubview(splitv2, WMWidgetView(label));
896
897         WMMapWidget(splitv2);
898         WMAddSplitViewSubview(splitv1, WMWidgetView(splitv2));
899
900         WMRealizeWidget(win);
901         WMMapSubwidgets(win);
902         WMMapWidget(win);
903 }
904
905 void testUD()
906 {
907         WMUserDefaults *defs;
908         char str[32];
909
910         defs = WMGetStandardUserDefaults();
911
912         sprintf(str, "TEST DATA");
913         puts(str);
914         WMSetUDStringForKey(defs, str, "testKey");
915         puts(str);
916 }
917
918 int main(int argc, char **argv)
919 {
920         WMScreen *scr;
921         WMPixmap *pixmap;
922
923         /* Initialize the application */
924         WMInitializeApplication("Test@eqweq_ewq$eqw", &argc, argv);
925
926         testUD();
927
928         /*
929          * Open connection to the X display.
930          */
931         dpy = XOpenDisplay("");
932
933         if (!dpy) {
934                 puts("could not open display");
935                 exit(1);
936         }
937
938         /* This is used to disable buffering of X protocol requests.
939          * Do NOT use it unless when debugging. It will cause a major
940          * slowdown in your application
941          */
942 #if 0
943         XSynchronize(dpy, True);
944 #endif
945         /*
946          * Create screen descriptor.
947          */
948         scr = WMCreateScreen(dpy, DefaultScreen(dpy));
949
950         /*
951          * Loads the logo of the application.
952          */
953         pixmap = WMCreatePixmapFromFile(scr, "logo.xpm");
954
955         /*
956          * Makes the logo be used in standard dialog panels.
957          */
958         if (pixmap) {
959                 WMSetApplicationIconPixmap(scr, pixmap);
960                 WMReleasePixmap(pixmap);
961         }
962
963         /*
964          * Do some test stuff.
965          *
966          * Put the testSomething() function you want to test here.
967          */
968
969         testText(scr);
970         testFontPanel(scr);
971
972         testColorPanel(scr);
973
974         testTextField(scr);
975
976 #if 0
977
978         testBox(scr);
979         testButton(scr);
980         testColorPanel(scr);
981         testColorWell(scr);
982         testDragAndDrop(scr);
983         testFrame(scr);
984         testGradientButtons(scr);
985         testList(scr);
986         testOpenFilePanel(scr);
987         testProgressIndicator(scr);
988         testPullDown(scr);
989         testScrollView(scr);
990         testSlider(scr);
991         testSplitView(scr);
992         testTabView(scr);
993         testTextField(scr);
994 #endif
995         /*
996          * The main event loop.
997          *
998          */
999         WMScreenMainLoop(scr);
1000
1001         return 0;
1002 }