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