wmaker: Added 'const' attribute to function 'wDefaultsInitDomain'
[wmaker-crm.git] / WINGs / Tests / wtest.c
blob1d14744858dc5ddfd5479ceeb9afd927387c6008
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 void wAbort()
19 exit(1);
22 Display *dpy;
24 int windowCount = 0;
26 void closeAction(WMWidget * self, void *data)
28 WMDestroyWidget(self);
29 windowCount--;
30 printf("window closed, window count = %d\n", windowCount);
31 if (windowCount < 1)
32 exit(0);
35 void testOpenFilePanel(WMScreen * scr)
37 WMOpenPanel *panel;
39 /* windowCount++; */
41 /* get the shared Open File panel */
42 panel = WMGetOpenPanel(scr);
44 WMRunModalFilePanelForDirectory(panel, NULL, "/usr/local", NULL, NULL);
46 /* free the panel to save some memory. Not needed otherwise. */
47 WMFreeFilePanel(WMGetOpenPanel(scr));
50 void testFontPanel(WMScreen * scr)
52 WMFontPanel *panel;
54 /*windowCount++; */
56 panel = WMGetFontPanel(scr);
58 WMShowFontPanel(panel);
60 /*WMFreeFontPanel(panel); */
63 void testFrame(WMScreen * scr)
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"
76 static WMTitlePosition pos[] = {
77 WTPAboveTop,
78 WTPAtTop,
79 WTPBelowTop,
80 WTPAboveBottom,
81 WTPAtBottom,
82 WTPBelowBottom
85 windowCount++;
87 win = WMCreateWindow(scr, "testFrame");
88 WMSetWindowTitle(win, "Frame");
89 WMSetWindowCloseAction(win, closeAction, NULL);
90 WMResizeWidget(win, 400, 300);
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]);
100 WMRealizeWidget(win);
101 WMMapSubwidgets(win);
102 WMMapWidget(win);
106 /*static void
107 resizedWindow(void *self, WMNotification *notif)
109 WMView *view = (WMView*)WMGetNotificationObject(notif);
110 WMSize size = WMGetViewSize(view);
112 WMResizeWidget((WMWidget*)self, size.width, size.height);
115 void testBox(WMScreen * scr)
117 WMWindow *win;
118 WMBox *box, *hbox;
119 WMButton *btn;
120 WMPopUpButton *pop;
121 int i;
123 windowCount++;
125 win = WMCreateWindow(scr, "testBox");
126 WMSetWindowTitle(win, "Box");
127 WMSetWindowCloseAction(win, closeAction, NULL);
128 WMResizeWidget(win, 400, 300);
130 box = WMCreateBox(win);
131 WMSetBoxBorderWidth(box, 5);
132 WMSetViewExpandsToParent(WMWidgetView(box), 0, 0, 0, 0);
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);
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);
148 hbox = WMCreateBox(box);
149 WMSetBoxHorizontal(hbox, True);
150 WMAddBoxSubview(box, WMWidgetView(hbox), False, True, 24, 0, 0);
151 WMMapWidget(hbox);
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);
160 WMRealizeWidget(win);
161 WMMapSubwidgets(win);
162 WMMapWidget(win);
166 static void singleClick(WMWidget * self, void *data)
170 static void doubleClick(WMWidget * self, void *data)
172 WMSelectAllListItems((WMList *) self);
175 static void listSelectionObserver(void *observer, WMNotification * notification)
177 WMLabel *label = (WMLabel *) observer;
178 WMList *lPtr = (WMList *) WMGetNotificationObject(notification);
179 char buf[255];
181 sprintf(buf, "Selected items: %d", WMGetArrayItemCount(WMGetListSelectedItems(lPtr)));
182 WMSetLabelText(label, buf);
185 void testList(WMScreen * scr)
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;
197 windowCount++;
199 win = WMCreateWindow(scr, "testList");
200 WMResizeWidget(win, 370, 250);
201 WMSetWindowTitle(win, "List");
202 WMSetWindowCloseAction(win, closeAction, NULL);
204 title = WMCreateLabel(win);
205 WMResizeWidget(title, 150, 20);
206 WMMoveWidget(title, 10, 10);
207 WMSetLabelRelief(title, WRRidge);
208 WMSetLabelText(title, "Single selection list");
210 mtitle = WMCreateLabel(win);
211 WMResizeWidget(mtitle, 150, 20);
212 WMMoveWidget(mtitle, 210, 10);
213 WMSetLabelRelief(mtitle, WRRidge);
214 WMSetLabelText(mtitle, "Multiple selection list");
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);
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);
232 label = WMCreateLabel(win);
233 WMResizeWidget(label, 150, 40);
234 WMMoveWidget(label, 10, 200);
235 WMSetLabelRelief(label, WRRidge);
236 WMSetLabelText(label, "Selected items: 0");
238 mlabel = WMCreateLabel(win);
239 WMResizeWidget(mlabel, 150, 40);
240 WMMoveWidget(mlabel, 210, 200);
241 WMSetLabelRelief(mlabel, WRRidge);
242 WMSetLabelText(mlabel, "Selected items: 0");
244 WMSetListAction(list, singleClick, label);
245 WMSetListDoubleAction(list, doubleClick, label);
246 WMSetListAction(mlist, singleClick, mlabel);
247 WMSetListDoubleAction(mlist, doubleClick, mlabel);
249 WMAddNotificationObserver(listSelectionObserver, label, WMListSelectionDidChangeNotification, list);
250 WMAddNotificationObserver(listSelectionObserver, mlabel, WMListSelectionDidChangeNotification, mlist);
252 WMRealizeWidget(win);
253 WMMapSubwidgets(win);
254 WMMapWidget(win);
257 void testButton(WMScreen * scr)
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"
272 windowCount++;
274 win = WMCreateWindow(scr, "testButton");
275 WMResizeWidget(win, 300, 300);
276 WMSetWindowTitle(win, "Buttons");
278 WMSetWindowCloseAction(win, closeAction, NULL);
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]);
288 WMRealizeWidget(win);
289 WMMapSubwidgets(win);
290 WMMapWidget(win);
293 void testGradientButtons(WMScreen * scr)
295 WMWindow *win;
296 WMButton *btn;
297 WMPixmap *pix1, *pix2;
298 RImage *back;
299 RColor light, dark;
300 WMColor *color, *altColor;
302 windowCount++;
304 /* creates the top-level window */
305 win = WMCreateWindow(scr, "testGradientButtons");
306 WMSetWindowTitle(win, "Gradiented Button Demo");
307 WMResizeWidget(win, 300, 200);
309 WMSetWindowCloseAction(win, closeAction, NULL);
311 light.red = 0x90;
312 light.green = 0x85;
313 light.blue = 0x90;
314 dark.red = 0x35;
315 dark.green = 0x30;
316 dark.blue = 0x35;
318 color = WMCreateRGBColor(scr, 0x5900, 0x5100, 0x5900, True);
319 WMSetWidgetBackgroundColor(win, color);
320 WMReleaseColor(color);
322 back = RRenderGradient(60, 24, &dark, &light, RGRD_DIAGONAL);
323 RBevelImage(back, RBEV_RAISED2);
324 pix1 = WMCreatePixmapFromRImage(scr, back, 0);
325 RReleaseImage(back);
327 back = RRenderGradient(60, 24, &dark, &light, RGRD_DIAGONAL);
328 RBevelImage(back, RBEV_SUNKEN);
329 pix2 = WMCreatePixmapFromRImage(scr, back, 0);
330 RReleaseImage(back);
332 color = WMWhiteColor(scr);
333 altColor = WMCreateNamedColor(scr, "red", True);
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);
346 WMSetBalloonTextForView("This is a cool button", WMWidgetView(btn));
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);
358 WMSetBalloonTextForView("Este é outro balão.", WMWidgetView(btn));
360 WMReleaseColor(color);
361 color = WMCreateNamedColor(scr, "orange", True);
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);
373 WMSetBalloonTextForView("This is yet another button.\nBut the balloon has 3 lines.\nYay!",
374 WMWidgetView(btn));
376 WMReleaseColor(color);
377 WMReleaseColor(altColor);
379 WMRealizeWidget(win);
380 WMMapSubwidgets(win);
381 WMMapWidget(win);
384 void testScrollView(WMScreen * scr)
386 WMWindow *win;
387 WMScrollView *sview;
388 WMFrame *f;
389 WMLabel *l;
390 char buffer[128];
391 int i;
393 windowCount++;
395 /* creates the top-level window */
396 win = WMCreateWindow(scr, "testScroll");
397 WMSetWindowTitle(win, "Scrollable View");
399 WMSetWindowCloseAction(win, closeAction, NULL);
401 /* set the window size */
402 WMResizeWidget(win, 300, 300);
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);
412 /* create a frame with a bunch of labels */
413 f = WMCreateFrame(win);
414 WMResizeWidget(f, 400, 400);
415 WMSetFrameRelief(f, WRFlat);
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);
425 WMMapSubwidgets(f);
426 WMMapWidget(f);
428 WMSetScrollViewContentView(sview, WMWidgetView(f));
430 /* make the windows of the widgets be actually created */
431 WMRealizeWidget(win);
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.
437 WMMapSubwidgets(win);
439 /* map the top-level window */
440 WMMapWidget(win);
443 void testColorWell(WMScreen * scr)
445 WMWindow *win;
446 WMColorWell *well1, *well2;
448 windowCount++;
450 win = WMCreateWindow(scr, "testColor");
451 WMResizeWidget(win, 300, 300);
452 WMSetWindowCloseAction(win, closeAction, NULL);
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));
463 WMRealizeWidget(win);
464 WMMapSubwidgets(win);
465 WMMapWidget(win);
468 void testColorPanel(WMScreen * scr)
470 WMColorPanel *panel = WMGetColorPanel(scr);
472 /*if (colorname) {
473 startcolor = WMCreateNamedColor(scr, colorname, False);
474 WMSetColorPanelColor(panel, startcolor);
475 WMReleaseColor(startcolor);
476 } */
478 WMShowColorPanel(panel);
481 void sliderCallback(WMWidget * w, void *data)
483 printf("SLIDER == %i\n", WMGetSliderValue(w));
486 void testSlider(WMScreen * scr)
488 WMWindow *win;
489 WMSlider *s;
491 windowCount++;
493 win = WMCreateWindow(scr, "testSlider");
494 WMResizeWidget(win, 300, 300);
495 WMSetWindowTitle(win, "Sliders");
497 WMSetWindowCloseAction(win, closeAction, NULL);
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);
506 s = WMCreateSlider(win);
507 WMResizeWidget(s, 100, 16);
508 WMMoveWidget(s, 100, 10);
509 WMSetSliderKnobThickness(s, 8);
511 WMRealizeWidget(win);
512 WMMapSubwidgets(win);
513 WMMapWidget(win);
516 void testTextField(WMScreen * scr)
518 WMWindow *win;
519 WMTextField *field, *field2;
521 windowCount++;
523 win = WMCreateWindow(scr, "testTextField");
524 WMResizeWidget(win, 400, 300);
526 WMSetWindowCloseAction(win, closeAction, NULL);
528 field = WMCreateTextField(win);
529 WMResizeWidget(field, 200, 20);
530 WMMoveWidget(field, 20, 20);
531 WMSetTextFieldText(field, "the little \xc2\xa9 sign");
533 field2 = WMCreateTextField(win);
534 WMResizeWidget(field2, 200, 20);
535 WMMoveWidget(field2, 20, 50);
536 WMSetTextFieldAlignment(field2, WARight);
538 WMRealizeWidget(win);
539 WMMapSubwidgets(win);
540 WMMapWidget(win);
544 void testText(WMScreen * scr)
546 WMWindow *win;
547 WMText *text;
548 WMFont *font;
549 void *tb;
550 FILE *file = fopen("wm.html", "rb");
552 windowCount++;
554 win = WMCreateWindow(scr, "testText");
555 WMResizeWidget(win, 500, 300);
557 WMSetWindowCloseAction(win, closeAction, NULL);
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);
566 #define FNAME "Verdana,sans serif: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)."
575 font = WMCreateFont(scr, FNAME ":autohint=false");
576 WMSetTextDefaultFont(text, font);
577 WMReleaseFont(font);
579 if (0 && file) {
580 char buf[1024];
582 WMFreezeText(text);
583 while (fgets(buf, 1023, file))
584 WMAppendTextStream(text, buf);
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);
600 WMRealizeWidget(win);
601 WMMapSubwidgets(win);
602 WMMapWidget(win);
605 void testProgressIndicator(WMScreen * scr)
607 WMWindow *win;
608 WMProgressIndicator *pPtr;
610 windowCount++;
612 win = WMCreateWindow(scr, "testProgressIndicator");
613 WMResizeWidget(win, 292, 32);
615 WMSetWindowCloseAction(win, closeAction, NULL);
617 pPtr = WMCreateProgressIndicator(win);
618 WMMoveWidget(pPtr, 8, 8);
619 WMSetProgressIndicatorValue(pPtr, 75);
621 WMRealizeWidget(win);
622 WMMapSubwidgets(win);
623 WMMapWidget(win);
627 void testPullDown(WMScreen * scr)
629 WMWindow *win;
630 WMPopUpButton *pop, *pop2;
632 windowCount++;
634 win = WMCreateWindow(scr, "pullDown");
635 WMResizeWidget(win, 400, 300);
637 WMSetWindowCloseAction(win, closeAction, NULL);
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");
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");
658 WMRealizeWidget(win);
659 WMMapSubwidgets(win);
660 WMMapWidget(win);
664 void testTabView(WMScreen * scr)
666 WMWindow *win;
667 WMTabView *tabv;
668 WMTabViewItem *tab;
669 WMFrame *frame;
670 WMLabel *label;
672 windowCount++;
674 win = WMCreateWindow(scr, "testTabs");
675 WMResizeWidget(win, 400, 300);
677 WMSetWindowCloseAction(win, closeAction, NULL);
679 tabv = WMCreateTabView(win);
680 WMMoveWidget(tabv, 50, 50);
681 WMResizeWidget(tabv, 300, 200);
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);
690 tab = WMCreateTabViewItemWithIdentifier(0);
691 WMSetTabViewItemView(tab, WMWidgetView(frame));
692 WMAddItemInTabView(tabv, tab);
693 WMSetTabViewItemLabel(tab, "Instances");
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);
702 tab = WMCreateTabViewItemWithIdentifier(0);
703 WMSetTabViewItemView(tab, WMWidgetView(frame));
704 WMAddItemInTabView(tabv, tab);
705 WMSetTabViewItemLabel(tab, "Classes");
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);
715 tab = WMCreateTabViewItemWithIdentifier(0);
716 WMSetTabViewItemView(tab, WMWidgetView(frame));
717 WMAddItemInTabView(tabv, tab);
718 WMSetTabViewItemLabel(tab, "Something");
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);
728 tab = WMCreateTabViewItemWithIdentifier(0);
729 WMSetTabViewItemView(tab, WMWidgetView(frame));
730 WMAddItemInTabView(tabv, tab);
731 WMSetTabViewItemLabel(tab, "Bla!");
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!");
745 WMRealizeWidget(win);
746 WMMapSubwidgets(win);
747 WMMapWidget(win);
750 void splitViewConstrainProc(WMSplitView * sPtr, int indView, int *minSize, int *maxSize)
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;
768 static void resizeSplitView(XEvent * event, void *data)
770 WMSplitView *sPtr = (WMSplitView *) data;
772 if (event->type == ConfigureNotify) {
773 int width = event->xconfigure.width - 10;
775 if (width < WMGetSplitViewDividerThickness(sPtr))
776 width = WMGetSplitViewDividerThickness(sPtr);
778 if (width != WMWidgetWidth(sPtr) || event->xconfigure.height != WMWidgetHeight(sPtr))
779 WMResizeWidget(sPtr, width, event->xconfigure.height - 55);
783 void appendSubviewButtonAction(WMWidget * self, void *data)
785 WMSplitView *sPtr = (WMSplitView *) data;
786 char buf[64];
787 WMLabel *label = WMCreateLabel(sPtr);
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);
797 void removeSubviewButtonAction(WMWidget * self, void *data)
799 WMSplitView *sPtr = (WMSplitView *) data;
800 int count = WMGetSplitViewSubviewsCount(sPtr);
802 if (count > 2) {
803 WMView *view = WMGetSplitViewSubviewAt(sPtr, count - 1);
804 WMDestroyWidget(WMWidgetOfView(view));
805 WMRemoveSplitViewSubviewAt(sPtr, count - 1);
809 void orientationButtonAction(WMWidget * self, void *data)
811 WMSplitView *sPtr = (WMSplitView *) data;
812 WMSetSplitViewVertical(sPtr, !WMGetSplitViewVertical(sPtr));
815 void adjustSubviewsButtonAction(WMWidget * self, void *data)
817 WMAdjustSplitViewSubviews((WMSplitView *) data);
820 void testSplitView(WMScreen * scr)
822 WMWindow *win;
823 WMSplitView *splitv1, *splitv2;
824 WMFrame *frame;
825 WMLabel *label;
826 WMButton *button;
828 windowCount++;
830 win = WMCreateWindow(scr, "testTabs");
831 WMResizeWidget(win, 300, 400);
832 WMSetWindowCloseAction(win, closeAction, NULL);
834 frame = WMCreateFrame(win);
835 WMSetFrameRelief(frame, WRSunken);
836 WMMoveWidget(frame, 5, 5);
837 WMResizeWidget(frame, 290, 40);
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);
845 button = WMCreateCommandButton(frame);
846 WMSetButtonText(button, "+");
847 WMSetButtonAction(button, appendSubviewButtonAction, splitv1);
848 WMMoveWidget(button, 10, 8);
849 WMMapWidget(button);
851 button = WMCreateCommandButton(frame);
852 WMSetButtonText(button, "-");
853 WMSetButtonAction(button, removeSubviewButtonAction, splitv1);
854 WMMoveWidget(button, 80, 8);
855 WMMapWidget(button);
857 button = WMCreateCommandButton(frame);
858 WMSetButtonText(button, "=");
859 WMMoveWidget(button, 150, 8);
860 WMSetButtonAction(button, adjustSubviewsButtonAction, splitv1);
861 WMMapWidget(button);
863 button = WMCreateCommandButton(frame);
864 WMSetButtonText(button, "#");
865 WMMoveWidget(button, 220, 8);
866 WMSetButtonAction(button, orientationButtonAction, splitv1);
867 WMMapWidget(button);
869 label = WMCreateLabel(splitv1);
870 WMSetLabelText(label, "Subview 1");
871 WMSetLabelRelief(label, WRSunken);
872 WMMapWidget(label);
873 WMAddSplitViewSubview(splitv1, WMWidgetView(label));
875 splitv2 = WMCreateSplitView(splitv1);
876 WMResizeWidget(splitv2, 150, 150);
877 WMSetSplitViewVertical(splitv2, True);
879 label = WMCreateLabel(splitv2);
880 WMSetLabelText(label, "Subview 2.1");
881 WMSetLabelRelief(label, WRSunken);
882 WMMapWidget(label);
883 WMAddSplitViewSubview(splitv2, WMWidgetView(label));
885 label = WMCreateLabel(splitv2);
886 WMSetLabelText(label, "Subview 2.2");
887 WMSetLabelRelief(label, WRSunken);
888 WMMapWidget(label);
889 WMAddSplitViewSubview(splitv2, WMWidgetView(label));
891 label = WMCreateLabel(splitv2);
892 WMSetLabelText(label, "Subview 2.3");
893 WMSetLabelRelief(label, WRSunken);
894 WMMapWidget(label);
895 WMAddSplitViewSubview(splitv2, WMWidgetView(label));
897 WMMapWidget(splitv2);
898 WMAddSplitViewSubview(splitv1, WMWidgetView(splitv2));
900 WMRealizeWidget(win);
901 WMMapSubwidgets(win);
902 WMMapWidget(win);
905 void testUD()
907 WMUserDefaults *defs;
908 char str[32];
910 defs = WMGetStandardUserDefaults();
912 sprintf(str, "TEST DATA");
913 puts(str);
914 WMSetUDStringForKey(defs, str, "testKey");
915 puts(str);
918 int main(int argc, char **argv)
920 WMScreen *scr;
921 WMPixmap *pixmap;
923 /* Initialize the application */
924 WMInitializeApplication("Test@eqweq_ewq$eqw", &argc, argv);
926 testUD();
929 * Open connection to the X display.
931 dpy = XOpenDisplay("");
933 if (!dpy) {
934 puts("could not open display");
935 exit(1);
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
942 #if 0
943 XSynchronize(dpy, True);
944 #endif
946 * Create screen descriptor.
948 scr = WMCreateScreen(dpy, DefaultScreen(dpy));
951 * Loads the logo of the application.
953 pixmap = WMCreatePixmapFromFile(scr, "logo.xpm");
956 * Makes the logo be used in standard dialog panels.
958 if (pixmap) {
959 WMSetApplicationIconPixmap(scr, pixmap);
960 WMReleasePixmap(pixmap);
964 * Do some test stuff.
966 * Put the testSomething() function you want to test here.
969 testText(scr);
970 testFontPanel(scr);
972 testColorPanel(scr);
974 testTextField(scr);
976 #if 0
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
996 * The main event loop.
999 WMScreenMainLoop(scr);
1001 return 0;