WINGs buttons and labels now have text
[wmaker-crm.git] / WINGs / Tests / wtest.c
blobb3bb54f2cf6196b71375bc4ea5029297be40da5b
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 #if 0
36 void testOpenFilePanel(WMScreen * scr)
38 WMOpenPanel *panel;
40 /* 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);
256 #endif
258 void testButton(WMScreen * scr)
260 WMWindow *win;
261 int i;
262 char *types[] = {
263 "MomentaryPush",
264 "PushOnPushOff",
265 "Toggle",
266 "Switch",
267 "Radio",
268 "MomentaryChange",
269 "OnOff",
270 "MomentaryLigh"
273 windowCount++;
275 win = WMCreateWindow(scr, "testButton");
276 WMResizeWidget(win, 300, 300);
277 WMSetWindowTitle(win, "Buttons");
279 WMSetWindowCloseAction(win, closeAction, NULL);
281 for (i = 1; i < 9; i++) {
282 WMButton *b;
283 b = WMCreateButton(win, i);
284 WMResizeWidget(b, 150, 24);
285 WMMoveWidget(b, 20, i * 30);
286 WMSetButtonText(b, types[i - 1]);
289 WMRealizeWidget(win);
290 WMMapSubwidgets(win);
291 WMMapWidget(win);
294 #ifdef obsolete
295 void testGradientButtons(WMScreen * scr)
297 WMWindow *win;
298 WMButton *btn;
299 WMPixmap *pix1, *pix2;
300 RImage *back;
301 RColor light, dark;
302 WMColor *color, *altColor;
304 windowCount++;
306 /* creates the top-level window */
307 win = WMCreateWindow(scr, "testGradientButtons");
308 WMSetWindowTitle(win, "Gradiented Button Demo");
309 WMResizeWidget(win, 300, 200);
311 WMSetWindowCloseAction(win, closeAction, NULL);
313 light.red = 0x90;
314 light.green = 0x85;
315 light.blue = 0x90;
316 dark.red = 0x35;
317 dark.green = 0x30;
318 dark.blue = 0x35;
320 color = WMCreateRGBColor(scr, 0x5900, 0x5100, 0x5900, True);
321 WMSetWidgetBackgroundColor(win, color);
322 WMReleaseColor(color);
324 back = RRenderGradient(60, 24, &dark, &light, RGRD_DIAGONAL);
325 RBevelImage(back, RBEV_RAISED2);
326 pix1 = WMCreatePixmapFromRImage(scr, back, 0);
327 RReleaseImage(back);
329 back = RRenderGradient(60, 24, &dark, &light, RGRD_DIAGONAL);
330 RBevelImage(back, RBEV_SUNKEN);
331 pix2 = WMCreatePixmapFromRImage(scr, back, 0);
332 RReleaseImage(back);
334 color = WMWhiteColor(scr);
335 altColor = WMCreateNamedColor(scr, "red", True);
337 btn = WMCreateButton(win, WBTMomentaryChange);
338 WMResizeWidget(btn, 60, 24);
339 WMMoveWidget(btn, 20, 100);
340 WMSetButtonBordered(btn, False);
341 WMSetButtonImagePosition(btn, WIPOverlaps);
342 WMSetButtonImage(btn, pix1);
343 WMSetButtonAltImage(btn, pix2);
344 WMSetButtonText(btn, "Cool");
345 WMSetButtonTextColor(btn, color);
346 WMSetButtonAltTextColor(btn, altColor);
348 WMSetBalloonTextForView("This is a cool button", WMWidgetView(btn));
350 btn = WMCreateButton(win, WBTMomentaryChange);
351 WMResizeWidget(btn, 60, 24);
352 WMMoveWidget(btn, 90, 100);
353 WMSetButtonBordered(btn, False);
354 WMSetButtonImagePosition(btn, WIPOverlaps);
355 WMSetButtonImage(btn, pix1);
356 WMSetButtonAltImage(btn, pix2);
357 WMSetButtonText(btn, "Button");
358 WMSetButtonTextColor(btn, color);
360 WMSetBalloonTextForView("Este é outro balão.", WMWidgetView(btn));
362 WMReleaseColor(color);
363 color = WMCreateNamedColor(scr, "orange", True);
365 btn = WMCreateButton(win, WBTMomentaryChange);
366 WMResizeWidget(btn, 60, 24);
367 WMMoveWidget(btn, 160, 100);
368 WMSetButtonBordered(btn, False);
369 WMSetButtonImagePosition(btn, WIPOverlaps);
370 WMSetButtonImage(btn, pix1);
371 WMSetButtonAltImage(btn, pix2);
372 WMSetButtonText(btn, "Test");
373 WMSetButtonTextColor(btn, color);
375 WMSetBalloonTextForView("This is yet another button.\nBut the balloon has 3 lines.\nYay!",
376 WMWidgetView(btn));
378 WMReleaseColor(color);
379 WMReleaseColor(altColor);
381 WMRealizeWidget(win);
382 WMMapSubwidgets(win);
383 WMMapWidget(win);
385 #endif
387 #if 0
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 printf("SLIDER == %i\n", WMGetSliderValue(w));
490 void testSlider(WMScreen * scr)
492 WMWindow *win;
493 WMSlider *s;
495 windowCount++;
497 win = WMCreateWindow(scr, "testSlider");
498 WMResizeWidget(win, 300, 300);
499 WMSetWindowTitle(win, "Sliders");
501 WMSetWindowCloseAction(win, closeAction, NULL);
503 s = WMCreateSlider(win);
504 WMResizeWidget(s, 16, 100);
505 WMMoveWidget(s, 100, 100);
506 WMSetSliderKnobThickness(s, 8);
507 WMSetSliderContinuous(s, False);
508 WMSetSliderAction(s, sliderCallback, s);
510 s = WMCreateSlider(win);
511 WMResizeWidget(s, 100, 16);
512 WMMoveWidget(s, 100, 10);
513 WMSetSliderKnobThickness(s, 8);
515 WMRealizeWidget(win);
516 WMMapSubwidgets(win);
517 WMMapWidget(win);
519 #endif
521 void testStuff(WMScreen *scr)
523 WMWindow *win;
524 WMLabel *label;
525 WMButton *button;
527 windowCount++;
529 win = WMCreateWindow(scr, "testTextField");
530 WMResizeWidget(win, 400, 300);
532 WMSetWindowCloseAction(win, closeAction, NULL);
535 label= WMCreateLabel(win);
536 WMSetLabelText(label, "HELLO");
537 WMResizeWidget(label, 100, 20);
538 WMMoveWidget(label, 10, 100);
540 button= WMCreateCommandButton(win);
541 WMSetButtonText(button, "OK");
542 WMResizeWidget(button, 80, 24);
543 WMMoveWidget(button, 400-80-12, 200-24-12);
545 button= WMCreateCommandButton(win);
546 WMSetButtonText(button, "Cancel");
547 WMResizeWidget(button, 80, 24);
548 WMMoveWidget(button, 400-80-12-80-12, 300-24-12);
551 WMRealizeWidget(win);
552 WMMapSubwidgets(win);
553 WMMapWidget(win);
556 #if 0
557 void testTextField(WMScreen * scr)
559 WMWindow *win;
560 WMTextField *field, *field2;
562 windowCount++;
564 win = WMCreateWindow(scr, "testTextField");
565 WMResizeWidget(win, 400, 300);
567 WMSetWindowCloseAction(win, closeAction, NULL);
569 field = WMCreateTextField(win);
570 WMResizeWidget(field, 200, 20);
571 WMMoveWidget(field, 20, 20);
572 WMSetTextFieldText(field, "the little \xc2\xa9 sign");
574 field2 = WMCreateTextField(win);
575 WMResizeWidget(field2, 200, 20);
576 WMMoveWidget(field2, 20, 50);
577 WMSetTextFieldAlignment(field2, WARight);
579 WMRealizeWidget(win);
580 WMMapSubwidgets(win);
581 WMMapWidget(win);
585 void testText(WMScreen * scr)
587 WMWindow *win;
588 WMText *text;
589 WMFont *font;
590 void *tb;
591 FILE *file = fopen("wm.html", "rb");
593 windowCount++;
595 win = WMCreateWindow(scr, "testText");
596 WMResizeWidget(win, 500, 300);
598 WMSetWindowCloseAction(win, closeAction, NULL);
600 text = WMCreateText(win);
601 WMResizeWidget(text, 480, 280);
602 WMMoveWidget(text, 10, 10);
603 WMSetTextHasVerticalScroller(text, True);
604 WMSetTextEditable(text, False);
605 WMSetTextIgnoresNewline(text, False);
607 #define FNAME "Verdana,Luxi Sans:pixelsize=12"
608 #define MSG \
609 "Window Maker is the GNU window manager for the " \
610 "X Window System. It was designed to emulate the " \
611 "look and feel of part of the NEXTSTEP(tm) GUI. It's " \
612 "supposed to be relatively fast and small, feature " \
613 "rich, easy to configure and easy to use, with a simple " \
614 "and elegant appearance borrowed from NEXTSTEP(tm)."
616 font = WMCreateFont(scr, FNAME ":autohint=false");
617 WMSetTextDefaultFont(text, font);
618 WMReleaseFont(font);
620 if (0 && file) {
621 char buf[1024];
623 WMFreezeText(text);
624 while (fgets(buf, 1023, file))
625 WMAppendTextStream(text, buf);
627 fclose(file);
628 WMThawText(text);
629 } else {
630 WMAppendTextStream(text, "First paragraph has autohinting turned off, "
631 "while the second has it turned on:");
632 WMAppendTextStream(text, "\n\n\n");
633 WMAppendTextStream(text, MSG);
634 WMAppendTextStream(text, "\n\n\n");
635 font = WMCreateFont(scr, FNAME ":autohint=true");
636 tb = WMCreateTextBlockWithText(text, MSG, font, WMBlackColor(scr), 0, strlen(MSG));
637 WMAppendTextBlock(text, tb);
638 WMReleaseFont(font);
641 WMRealizeWidget(win);
642 WMMapSubwidgets(win);
643 WMMapWidget(win);
646 void testProgressIndicator(WMScreen * scr)
648 WMWindow *win;
649 WMProgressIndicator *pPtr;
651 windowCount++;
653 win = WMCreateWindow(scr, "testProgressIndicator");
654 WMResizeWidget(win, 292, 32);
656 WMSetWindowCloseAction(win, closeAction, NULL);
658 pPtr = WMCreateProgressIndicator(win);
659 WMMoveWidget(pPtr, 8, 8);
660 WMSetProgressIndicatorValue(pPtr, 75);
662 WMRealizeWidget(win);
663 WMMapSubwidgets(win);
664 WMMapWidget(win);
668 void testPullDown(WMScreen * scr)
670 WMWindow *win;
671 WMPopUpButton *pop, *pop2;
673 windowCount++;
675 win = WMCreateWindow(scr, "pullDown");
676 WMResizeWidget(win, 400, 300);
678 WMSetWindowCloseAction(win, closeAction, NULL);
680 pop = WMCreatePopUpButton(win);
681 WMResizeWidget(pop, 100, 20);
682 WMMoveWidget(pop, 50, 60);
683 WMSetPopUpButtonPullsDown(pop, True);
684 WMSetPopUpButtonText(pop, "Commands");
685 WMAddPopUpButtonItem(pop, "Add");
686 WMAddPopUpButtonItem(pop, "Remove");
687 WMAddPopUpButtonItem(pop, "Check");
688 WMAddPopUpButtonItem(pop, "Eat");
690 pop2 = WMCreatePopUpButton(win);
691 WMResizeWidget(pop2, 100, 20);
692 WMMoveWidget(pop2, 200, 60);
693 WMSetPopUpButtonText(pop2, "Select");
694 WMAddPopUpButtonItem(pop2, "Apples");
695 WMAddPopUpButtonItem(pop2, "Bananas");
696 WMAddPopUpButtonItem(pop2, "Strawberries");
697 WMAddPopUpButtonItem(pop2, "Blueberries");
699 WMRealizeWidget(win);
700 WMMapSubwidgets(win);
701 WMMapWidget(win);
705 void testTabView(WMScreen * scr)
707 WMWindow *win;
708 WMTabView *tabv;
709 WMTabViewItem *tab;
710 WMFrame *frame;
711 WMLabel *label;
713 windowCount++;
715 win = WMCreateWindow(scr, "testTabs");
716 WMResizeWidget(win, 400, 300);
718 WMSetWindowCloseAction(win, closeAction, NULL);
720 tabv = WMCreateTabView(win);
721 WMMoveWidget(tabv, 50, 50);
722 WMResizeWidget(tabv, 300, 200);
724 frame = WMCreateFrame(win);
725 WMSetFrameRelief(frame, WRFlat);
726 label = WMCreateLabel(frame);
727 WMResizeWidget(label, 100, 100);
728 WMSetLabelText(label, "Label 1");
729 WMMapWidget(label);
731 tab = WMCreateTabViewItemWithIdentifier(0);
732 WMSetTabViewItemView(tab, WMWidgetView(frame));
733 WMAddItemInTabView(tabv, tab);
734 WMSetTabViewItemLabel(tab, "Instances");
736 frame = WMCreateFrame(win);
737 WMSetFrameRelief(frame, WRFlat);
738 label = WMCreateLabel(frame);
739 WMResizeWidget(label, 40, 50);
740 WMSetLabelText(label, "Label 2");
741 WMMapWidget(label);
743 tab = WMCreateTabViewItemWithIdentifier(0);
744 WMSetTabViewItemView(tab, WMWidgetView(frame));
745 WMAddItemInTabView(tabv, tab);
746 WMSetTabViewItemLabel(tab, "Classes");
748 frame = WMCreateFrame(win);
749 WMSetFrameRelief(frame, WRFlat);
750 label = WMCreateLabel(frame);
751 WMResizeWidget(label, 100, 100);
752 WMMoveWidget(label, 60, 40);
753 WMSetLabelText(label, "Label 3");
754 WMMapWidget(label);
756 tab = WMCreateTabViewItemWithIdentifier(0);
757 WMSetTabViewItemView(tab, WMWidgetView(frame));
758 WMAddItemInTabView(tabv, tab);
759 WMSetTabViewItemLabel(tab, "Something");
761 frame = WMCreateFrame(win);
762 WMSetFrameRelief(frame, WRFlat);
763 label = WMCreateLabel(frame);
764 WMResizeWidget(label, 100, 100);
765 WMMoveWidget(label, 160, 40);
766 WMSetLabelText(label, "Label 4");
767 WMMapWidget(label);
769 tab = WMCreateTabViewItemWithIdentifier(0);
770 WMSetTabViewItemView(tab, WMWidgetView(frame));
771 WMAddItemInTabView(tabv, tab);
772 WMSetTabViewItemLabel(tab, "Bla!");
774 frame = WMCreateFrame(win);
775 WMSetFrameRelief(frame, WRFlat);
776 label = WMCreateLabel(frame);
777 WMResizeWidget(label, 100, 100);
778 WMMoveWidget(label, 160, 40);
779 WMSetLabelText(label, "Label fjweqklrj qwl");
780 WMMapWidget(label);
781 tab = WMCreateTabViewItemWithIdentifier(0);
782 WMSetTabViewItemView(tab, WMWidgetView(frame));
783 WMAddItemInTabView(tabv, tab);
784 WMSetTabViewItemLabel(tab, "Weee!");
786 WMRealizeWidget(win);
787 WMMapSubwidgets(win);
788 WMMapWidget(win);
791 void splitViewConstrainProc(WMSplitView * sPtr, int indView, int *minSize, int *maxSize)
793 switch (indView) {
794 case 0:
795 *minSize = 20;
796 break;
797 case 1:
798 *minSize = 40;
799 *maxSize = 80;
800 break;
801 case 2:
802 *maxSize = 60;
803 break;
804 default:
805 break;
809 static void resizeSplitView(XEvent * event, void *data)
811 WMSplitView *sPtr = (WMSplitView *) data;
813 if (event->type == ConfigureNotify) {
814 int width = event->xconfigure.width - 10;
816 if (width < WMGetSplitViewDividerThickness(sPtr))
817 width = WMGetSplitViewDividerThickness(sPtr);
819 if (width != WMWidgetWidth(sPtr) || event->xconfigure.height != WMWidgetHeight(sPtr))
820 WMResizeWidget(sPtr, width, event->xconfigure.height - 55);
824 void appendSubviewButtonAction(WMWidget * self, void *data)
826 WMSplitView *sPtr = (WMSplitView *) data;
827 char buf[64];
828 WMLabel *label = WMCreateLabel(sPtr);
830 sprintf(buf, "Subview %d", WMGetSplitViewSubviewsCount(sPtr) + 1);
831 WMSetLabelText(label, buf);
832 WMSetLabelRelief(label, WRSunken);
833 WMAddSplitViewSubview(sPtr, WMWidgetView(label));
834 WMRealizeWidget(label);
835 WMMapWidget(label);
838 void removeSubviewButtonAction(WMWidget * self, void *data)
840 WMSplitView *sPtr = (WMSplitView *) data;
841 int count = WMGetSplitViewSubviewsCount(sPtr);
843 if (count > 2) {
844 WMView *view = WMGetSplitViewSubviewAt(sPtr, count - 1);
845 WMDestroyWidget(WMWidgetOfView(view));
846 WMRemoveSplitViewSubviewAt(sPtr, count - 1);
850 void orientationButtonAction(WMWidget * self, void *data)
852 WMSplitView *sPtr = (WMSplitView *) data;
853 WMSetSplitViewVertical(sPtr, !WMGetSplitViewVertical(sPtr));
856 void adjustSubviewsButtonAction(WMWidget * self, void *data)
858 WMAdjustSplitViewSubviews((WMSplitView *) data);
861 void testSplitView(WMScreen * scr)
863 WMWindow *win;
864 WMSplitView *splitv1, *splitv2;
865 WMFrame *frame;
866 WMLabel *label;
867 WMButton *button;
869 windowCount++;
871 win = WMCreateWindow(scr, "testTabs");
872 WMResizeWidget(win, 300, 400);
873 WMSetWindowCloseAction(win, closeAction, NULL);
875 frame = WMCreateFrame(win);
876 WMSetFrameRelief(frame, WRSunken);
877 WMMoveWidget(frame, 5, 5);
878 WMResizeWidget(frame, 290, 40);
880 splitv1 = WMCreateSplitView(win);
881 WMMoveWidget(splitv1, 5, 50);
882 WMResizeWidget(splitv1, 290, 345);
883 WMSetSplitViewConstrainProc(splitv1, splitViewConstrainProc);
884 WMCreateEventHandler(WMWidgetView(win), StructureNotifyMask, resizeSplitView, splitv1);
886 button = WMCreateCommandButton(frame);
887 WMSetButtonText(button, "+");
888 WMSetButtonAction(button, appendSubviewButtonAction, splitv1);
889 WMMoveWidget(button, 10, 8);
890 WMMapWidget(button);
892 button = WMCreateCommandButton(frame);
893 WMSetButtonText(button, "-");
894 WMSetButtonAction(button, removeSubviewButtonAction, splitv1);
895 WMMoveWidget(button, 80, 8);
896 WMMapWidget(button);
898 button = WMCreateCommandButton(frame);
899 WMSetButtonText(button, "=");
900 WMMoveWidget(button, 150, 8);
901 WMSetButtonAction(button, adjustSubviewsButtonAction, splitv1);
902 WMMapWidget(button);
904 button = WMCreateCommandButton(frame);
905 WMSetButtonText(button, "#");
906 WMMoveWidget(button, 220, 8);
907 WMSetButtonAction(button, orientationButtonAction, splitv1);
908 WMMapWidget(button);
910 label = WMCreateLabel(splitv1);
911 WMSetLabelText(label, "Subview 1");
912 WMSetLabelRelief(label, WRSunken);
913 WMMapWidget(label);
914 WMAddSplitViewSubview(splitv1, WMWidgetView(label));
916 splitv2 = WMCreateSplitView(splitv1);
917 WMResizeWidget(splitv2, 150, 150);
918 WMSetSplitViewVertical(splitv2, True);
920 label = WMCreateLabel(splitv2);
921 WMSetLabelText(label, "Subview 2.1");
922 WMSetLabelRelief(label, WRSunken);
923 WMMapWidget(label);
924 WMAddSplitViewSubview(splitv2, WMWidgetView(label));
926 label = WMCreateLabel(splitv2);
927 WMSetLabelText(label, "Subview 2.2");
928 WMSetLabelRelief(label, WRSunken);
929 WMMapWidget(label);
930 WMAddSplitViewSubview(splitv2, WMWidgetView(label));
932 label = WMCreateLabel(splitv2);
933 WMSetLabelText(label, "Subview 2.3");
934 WMSetLabelRelief(label, WRSunken);
935 WMMapWidget(label);
936 WMAddSplitViewSubview(splitv2, WMWidgetView(label));
938 WMMapWidget(splitv2);
939 WMAddSplitViewSubview(splitv1, WMWidgetView(splitv2));
941 WMRealizeWidget(win);
942 WMMapSubwidgets(win);
943 WMMapWidget(win);
946 void testUD()
948 WMUserDefaults *defs;
949 char str[32];
951 defs = WMGetStandardUserDefaults();
953 sprintf(str, "TEST DATA");
954 puts(str);
955 WMSetUDStringForKey(defs, str, "testKey");
956 puts(str);
958 #endif
960 int main(int argc, char **argv)
962 WMScreen *scr;
963 WMPixmap *pixmap;
965 /* Initialize the application */
966 WMInitializeApplication("Test@eqweq_ewq$eqw", &argc, argv);
968 //XXXtestUD();
971 * Open connection to the X display.
973 dpy = XOpenDisplay("");
975 if (!dpy) {
976 puts("could not open display");
977 exit(1);
980 /* This is used to disable buffering of X protocol requests.
981 * Do NOT use it unless when debugging. It will cause a major
982 * slowdown in your application
984 #if 0
985 XSynchronize(dpy, True);
986 #endif
988 * Create screen descriptor.
990 scr = WMCreateScreen(dpy, DefaultScreen(dpy));
993 * Loads the logo of the application.
995 pixmap = WMCreatePixmapFromFile(scr, "logo.xpm");
998 * Makes the logo be used in standard dialog panels.
1000 if (pixmap) {
1001 //XXXWMSetApplicationIconPixmap(scr, pixmap);
1002 //XXXWMReleasePixmap(pixmap);
1006 * Do some test stuff.
1008 * Put the testSomething() function you want to test here.
1010 testStuff(scr);
1011 testButton(scr);
1013 #if 0
1014 testText(scr);
1015 testFontPanel(scr);
1017 testColorPanel(scr);
1019 testTextField(scr);
1021 testBox(scr);
1022 testButton(scr);
1023 testColorPanel(scr);
1024 testColorWell(scr);
1025 testDragAndDrop(scr);
1026 testFrame(scr);
1027 testGradientButtons(scr);
1028 testList(scr);
1029 testOpenFilePanel(scr);
1030 testProgressIndicator(scr);
1031 testPullDown(scr);
1032 testScrollView(scr);
1033 testSlider(scr);
1034 testSplitView(scr);
1035 testTabView(scr);
1036 testTextField(scr);
1037 #endif
1039 * The main event loop.
1042 WMScreenMainLoop(scr);
1043 return 0;