*** empty log message ***
[wmaker-crm.git] / WINGs / wtest.c
blob0d9b1680b68f37cf889215bfdafcb294763305eb
1 /*
2 * WINGs test application
3 */
5 #include "WINGs.h"
7 #include <stdio.h>
12 * You need to define this function to link any program to WINGs.
13 * This will be called when the application will be terminated because
14 * on a fatal error.
16 void
17 wAbort()
19 exit(1);
25 Display *dpy;
27 int windowCount = 0;
29 void
30 closeAction(WMWidget *self, void *data)
32 WMDestroyWidget(self);
33 windowCount--;
34 if (windowCount < 1)
35 exit(0);
39 void
40 testOpenFilePanel(WMScreen *scr)
42 WMOpenPanel *panel;
44 windowCount++;
46 /* get the shared Open File panel */
47 panel = WMGetOpenPanel(scr);
49 WMRunModalFilePanelForDirectory(panel, NULL, "/usr/local", NULL, NULL);
51 /* free the panel to save some memory. Not needed otherwise. */
52 WMFreeFilePanel(WMGetOpenPanel(scr));
56 void
57 testFontPanel(WMScreen *scr)
59 WMFontPanel *panel;
61 windowCount++;
63 panel = WMGetFontPanel(scr);
65 WMShowFontPanel(panel);
67 /* WMFreeFontPanel(panel);*/
72 void
73 testList(WMScreen *scr)
75 WMWindow *win;
76 WMList *list;
77 char text[100];
78 int i;
80 windowCount++;
82 win = WMCreateWindow(scr, "testList");
83 WMSetWindowTitle(win, "List");
84 WMSetWindowCloseAction(win, closeAction, NULL);
86 list = WMCreateList(win);
87 for (i=0; i<50; i++) {
88 sprintf(text, "Item %i", i);
89 WMAddListItem(list, text);
91 WMRealizeWidget(win);
92 WMMapSubwidgets(win);
93 WMMapWidget(win);
99 void
100 testGradientButtons(WMScreen *scr)
102 WMWindow *win;
103 WMButton *btn;
104 WMPixmap *pix1, *pix2;
105 RImage *back;
106 RColor light, dark;
107 WMColor *color, *altColor;
109 windowCount++;
111 /* creates the top-level window */
112 win = WMCreateWindow(scr, "testGradientButtons");
113 WMSetWindowTitle(win, "Gradiented Button Demo");
114 WMResizeWidget(win, 300, 200);
116 light.red = 0x90;
117 light.green = 0x85;
118 light.blue = 0x90;
119 dark.red = 0x35;
120 dark.green = 0x30;
121 dark.blue = 0x35;
123 color = WMCreateRGBColor(scr, 0x5900, 0x5100, 0x5900, True);
124 WMSetWidgetBackgroundColor(win, color);
125 WMReleaseColor(color);
127 back = RRenderGradient(60, 24, &dark, &light, RGRD_DIAGONAL);
128 RBevelImage(back, RBEV_RAISED2);
129 pix1 = WMCreatePixmapFromRImage(scr, back, 0);
130 RDestroyImage(back);
132 back = RRenderGradient(60, 24, &dark, &light, RGRD_DIAGONAL);
133 RBevelImage(back, RBEV_SUNKEN);
134 pix2 = WMCreatePixmapFromRImage(scr, back, 0);
135 RDestroyImage(back);
137 color = WMWhiteColor(scr);
138 altColor = WMCreateNamedColor(scr, "red", True);
140 btn = WMCreateButton(win, WBTMomentaryChange);
141 WMResizeWidget(btn, 60, 24);
142 WMMoveWidget(btn, 20, 100);
143 WMSetButtonBordered(btn, False);
144 WMSetButtonImagePosition(btn, WIPOverlaps);
145 WMSetButtonImage(btn, pix1);
146 WMSetButtonAltImage(btn, pix2);
147 WMSetButtonText(btn, "Cool");
148 WMSetButtonTextColor(btn, color);
149 WMSetButtonAltTextColor(btn, altColor);
151 WMSetBalloonTextForView("This is a cool button", WMWidgetView(btn));
153 btn = WMCreateButton(win, WBTMomentaryChange);
154 WMResizeWidget(btn, 60, 24);
155 WMMoveWidget(btn, 90, 100);
156 WMSetButtonBordered(btn, False);
157 WMSetButtonImagePosition(btn, WIPOverlaps);
158 WMSetButtonImage(btn, pix1);
159 WMSetButtonAltImage(btn, pix2);
160 WMSetButtonText(btn, "Button");
161 WMSetButtonTextColor(btn, color);
163 WMSetBalloonTextForView("Este é outro balão.", WMWidgetView(btn));
165 WMReleaseColor(color);
166 color = WMCreateNamedColor(scr, "orange", True);
168 btn = WMCreateButton(win, WBTMomentaryChange);
169 WMResizeWidget(btn, 60, 24);
170 WMMoveWidget(btn, 160, 100);
171 WMSetButtonBordered(btn, False);
172 WMSetButtonImagePosition(btn, WIPOverlaps);
173 WMSetButtonImage(btn, pix1);
174 WMSetButtonAltImage(btn, pix2);
175 WMSetButtonText(btn, "Test");
176 WMSetButtonTextColor(btn, color);
178 WMSetBalloonTextForView("This is yet another button.\nBut the balloon has 3 lines.\nYay!",
179 WMWidgetView(btn));
181 WMReleaseColor(color);
182 WMReleaseColor(altColor);
184 WMRealizeWidget(win);
185 WMMapSubwidgets(win);
186 WMMapWidget(win);
190 void
191 testScrollView(WMScreen *scr)
193 WMWindow *win;
194 WMScrollView *sview;
195 WMFrame *f;
196 WMLabel *l;
197 char buffer[128];
198 int i;
200 windowCount++;
202 /* creates the top-level window */
203 win = WMCreateWindow(scr, "testScroll");
204 WMSetWindowTitle(win, "Scrollable View");
206 WMSetWindowCloseAction(win, closeAction, NULL);
208 /* set the window size */
209 WMResizeWidget(win, 300, 300);
211 /* creates a scrollable view inside the top-level window */
212 sview = WMCreateScrollView(win);
213 WMResizeWidget(sview, 200, 200);
214 WMMoveWidget(sview, 30, 30);
215 WMSetScrollViewRelief(sview, WRSunken);
216 WMSetScrollViewHasVerticalScroller(sview, True);
217 WMSetScrollViewHasHorizontalScroller(sview, True);
219 /* create a frame with a bunch of labels */
220 f = WMCreateFrame(win);
221 WMResizeWidget(f, 400, 400);
222 WMSetFrameRelief(f, WRFlat);
224 for (i=0; i<20; i++) {
225 l = WMCreateLabel(f);
226 WMResizeWidget(l, 50, 18);
227 WMMoveWidget(l, 10, 20*i);
228 sprintf(buffer, "Label %i", i);
229 WMSetLabelText(l, buffer);
230 WMSetLabelRelief(l, WRSimple);
232 WMMapSubwidgets(f);
233 WMMapWidget(f);
235 WMSetScrollViewContentView(sview, WMWidgetView(f));
237 /* make the windows of the widgets be actually created */
238 WMRealizeWidget(win);
240 /* Map all child widgets of the top-level be mapped.
241 * You must call this for each container widget (like frames),
242 * even if they are childs of the top-level window.
244 WMMapSubwidgets(win);
246 /* map the top-level window */
247 WMMapWidget(win);
251 void
252 testColorWell(WMScreen *scr)
254 WMWindow *win;
255 WMColorWell *well1, *well2;
257 windowCount++;
259 win = WMCreateWindow(scr, "testColor");
260 WMResizeWidget(win, 300, 300);
262 WMSetWindowCloseAction(win, closeAction, NULL);
264 well1 = WMCreateColorWell(win);
265 WMResizeWidget(well1, 60, 40);
266 WMMoveWidget(well1, 100, 100);
267 WMSetColorWellColor(well1, WMCreateRGBColor(scr, 0x8888, 0, 0x1111, True));
268 well2 = WMCreateColorWell(win);
269 WMResizeWidget(well2, 60, 40);
270 WMMoveWidget(well2, 200, 100);
271 WMSetColorWellColor(well2, WMCreateRGBColor(scr, 0, 0, 0x8888, True));
273 WMRealizeWidget(win);
274 WMMapSubwidgets(win);
275 WMMapWidget(win);
278 void
279 sliderCallback(WMWidget *w, void *data)
281 printf("SLIEDER == %i\n", WMGetSliderValue(w));
285 void
286 testSlider(WMScreen *scr)
288 WMWindow *win;
289 WMSlider *s;
291 windowCount++;
293 win = WMCreateWindow(scr, "testSlider");
294 WMResizeWidget(win, 300, 300);
295 WMSetWindowTitle(win, "Sliders");
297 WMSetWindowCloseAction(win, closeAction, NULL);
299 s = WMCreateSlider(win);
300 WMResizeWidget(s, 16, 100);
301 WMMoveWidget(s, 100, 100);
302 WMSetSliderKnobThickness(s, 8);
303 WMSetSliderContinuous(s, False);
304 WMSetSliderAction(s, sliderCallback, s);
306 s = WMCreateSlider(win);
307 WMResizeWidget(s, 100, 16);
308 WMMoveWidget(s, 100, 10);
309 WMSetSliderKnobThickness(s, 8);
311 WMRealizeWidget(win);
312 WMMapSubwidgets(win);
313 WMMapWidget(win);
317 void
318 testTextField(WMScreen *scr)
320 WMWindow *win;
321 WMTextField *field, *field2;
323 windowCount++;
325 win = WMCreateWindow(scr, "testText");
326 WMResizeWidget(win, 400, 300);
328 WMSetWindowCloseAction(win, closeAction, NULL);
330 field = WMCreateTextField(win);
331 WMResizeWidget(field, 200, 20);
332 WMMoveWidget(field, 20, 20);
334 field2 = WMCreateTextField(win);
335 WMResizeWidget(field2, 200, 20);
336 WMMoveWidget(field2, 20, 50);
337 WMSetTextFieldAlignment(field2, WARight);
339 WMRealizeWidget(win);
340 WMMapSubwidgets(win);
341 WMMapWidget(win);
346 void
347 testProgressIndicator(WMScreen *scr)
349 WMWindow *win;
350 WMProgressIndicator *pPtr;
352 windowCount++;
354 win = WMCreateWindow(scr, "testProgressIndicator");
355 WMResizeWidget(win, 292, 32);
357 WMSetWindowCloseAction(win, closeAction, NULL);
359 pPtr = WMCreateProgressIndicator(win);
360 WMMoveWidget(pPtr, 8, 8);
361 WMSetProgressIndicatorValue(pPtr, 75);
363 WMRealizeWidget(win);
364 WMMapSubwidgets(win);
365 WMMapWidget(win);
370 void
371 testPullDown(WMScreen *scr)
373 WMWindow *win;
374 WMPopUpButton *pop, *pop2;
376 windowCount++;
378 win = WMCreateWindow(scr, "pullDown");
379 WMResizeWidget(win, 400, 300);
381 WMSetWindowCloseAction(win, closeAction, NULL);
383 pop = WMCreatePopUpButton(win);
384 WMResizeWidget(pop, 100, 20);
385 WMMoveWidget(pop, 50, 60);
386 WMSetPopUpButtonPullsDown(pop, True);
387 WMSetPopUpButtonText(pop, "Commands");
388 WMAddPopUpButtonItem(pop, "Add");
389 WMAddPopUpButtonItem(pop, "Remove");
390 WMAddPopUpButtonItem(pop, "Check");
391 WMAddPopUpButtonItem(pop, "Eat");
393 pop2 = WMCreatePopUpButton(win);
394 WMResizeWidget(pop2, 100, 20);
395 WMMoveWidget(pop2, 200, 60);
396 WMSetPopUpButtonText(pop2, "Select");
397 WMAddPopUpButtonItem(pop2, "Apples");
398 WMAddPopUpButtonItem(pop2, "Bananas");
399 WMAddPopUpButtonItem(pop2, "Strawberries");
400 WMAddPopUpButtonItem(pop2, "Blueberries");
402 WMRealizeWidget(win);
403 WMMapSubwidgets(win);
404 WMMapWidget(win);
409 void
410 testTabView(WMScreen *scr)
412 WMWindow *win;
413 WMTabView *tabv;
414 WMTabViewItem *tab;
415 WMFrame *frame;
416 WMLabel *label;
418 windowCount++;
420 win = WMCreateWindow(scr, "testTabs");
421 WMResizeWidget(win, 400, 300);
423 WMSetWindowCloseAction(win, closeAction, NULL);
425 tabv = WMCreateTabView(win);
426 WMMoveWidget(tabv, 50, 50);
427 WMResizeWidget(tabv, 300, 200);
429 frame = WMCreateFrame(win);
430 WMSetFrameRelief(frame, WRFlat);
431 label = WMCreateLabel(frame);
432 WMResizeWidget(label, 100, 100);
433 WMSetLabelText(label, "Label 1");
434 WMMapWidget(label);
437 tab = WMCreateTabViewItemWithIdentifier(0);
438 WMSetTabViewItemView(tab, WMWidgetView(frame));
439 WMAddItemInTabView(tabv, tab);
440 WMSetTabViewItemLabel(tab, "Instances");
442 frame = WMCreateFrame(win);
443 WMSetFrameRelief(frame, WRFlat);
444 label = WMCreateLabel(frame);
445 WMResizeWidget(label, 40, 50);
446 WMSetLabelText(label, "Label 2");
447 WMMapWidget(label);
450 tab = WMCreateTabViewItemWithIdentifier(0);
451 WMSetTabViewItemView(tab, WMWidgetView(frame));
452 WMAddItemInTabView(tabv, tab);
453 WMSetTabViewItemLabel(tab, "Classes");
456 frame = WMCreateFrame(win);
457 WMSetFrameRelief(frame, WRFlat);
458 label = WMCreateLabel(frame);
459 WMResizeWidget(label, 100, 100);
460 WMMoveWidget(label, 60, 40);
461 WMSetLabelText(label, "Label 3");
462 WMMapWidget(label);
464 tab = WMCreateTabViewItemWithIdentifier(0);
465 WMSetTabViewItemView(tab, WMWidgetView(frame));
466 WMAddItemInTabView(tabv, tab);
467 WMSetTabViewItemLabel(tab, "Something");
470 frame = WMCreateFrame(win);
471 WMSetFrameRelief(frame, WRFlat);
472 label = WMCreateLabel(frame);
473 WMResizeWidget(label, 100, 100);
474 WMMoveWidget(label, 160, 40);
475 WMSetLabelText(label, "Label 4");
476 WMMapWidget(label);
478 tab = WMCreateTabViewItemWithIdentifier(0);
479 WMSetTabViewItemView(tab, WMWidgetView(frame));
480 WMAddItemInTabView(tabv, tab);
481 WMSetTabViewItemLabel(tab, "Bla!");
485 frame = WMCreateFrame(win);
486 WMSetFrameRelief(frame, WRFlat);
487 label = WMCreateLabel(frame);
488 WMResizeWidget(label, 100, 100);
489 WMMoveWidget(label, 160, 40);
490 WMSetLabelText(label, "Label fjweqklrj qwl");
491 WMMapWidget(label);
492 tab = WMCreateTabViewItemWithIdentifier(0);
493 WMSetTabViewItemView(tab, WMWidgetView(frame));
494 WMAddItemInTabView(tabv, tab);
495 WMSetTabViewItemLabel(tab, "Weee!");
498 WMRealizeWidget(win);
499 WMMapSubwidgets(win);
500 WMMapWidget(win);
504 void
505 splitViewConstrainProc(WMSplitView *sPtr, int indView,
506 int *minSize, int *maxSize)
508 switch (indView) {
509 case 0:
510 *minSize = 20;
511 break;
512 case 1:
513 *minSize = 40;
514 *maxSize = 80;
515 break;
516 case 2:
517 *maxSize = 60;
518 break;
519 default:
520 break;
525 static void
526 resizeSplitView(XEvent *event, void *data)
528 WMSplitView *sPtr = (WMSplitView*)data;
530 if (event->type == ConfigureNotify) {
531 int width = event->xconfigure.width - 10;
533 if (width < WMGetSplitViewDividerThickness(sPtr))
534 width = WMGetSplitViewDividerThickness(sPtr);
536 if (width != WMWidgetWidth(sPtr) ||
537 event->xconfigure.height != WMWidgetHeight(sPtr))
538 WMResizeWidget(sPtr, width, event->xconfigure.height - 55);
542 void
543 appendSubviewButtonAction(WMWidget *self, void *data)
545 WMSplitView *sPtr = (WMSplitView*)data;
546 char buf[64];
547 WMLabel *label = WMCreateLabel(sPtr);
549 sprintf(buf, "Subview %d", WMGetSplitViewSubviewsCount(sPtr) + 1);
550 WMSetLabelText(label, buf);
551 WMSetLabelRelief(label, WRSunken);
552 WMAddSplitViewSubview(sPtr, WMWidgetView(label));
553 WMRealizeWidget(label);
554 WMMapWidget(label);
557 void
558 removeSubviewButtonAction(WMWidget *self, void *data)
560 WMSplitView *sPtr = (WMSplitView*)data;
561 int count = WMGetSplitViewSubviewsCount(sPtr);
563 if (count > 2) {
564 WMView *view = WMGetSplitViewSubviewAt(sPtr, count-1);
565 WMDestroyWidget(WMWidgetOfView(view));
566 WMRemoveSplitViewSubviewAt(sPtr, count-1);
570 void
571 orientationButtonAction(WMWidget *self, void *data)
573 WMSplitView *sPtr = (WMSplitView*)data;
574 WMSetSplitViewVertical(sPtr, !WMGetSplitViewVertical(sPtr));
577 void
578 adjustSubviewsButtonAction(WMWidget *self, void *data)
580 WMAdjustSplitViewSubviews((WMSplitView*)data);
583 void
584 testSplitView(WMScreen *scr)
586 WMWindow *win;
587 WMSplitView *splitv1, *splitv2;
588 WMFrame *frame;
589 WMLabel *label;
590 WMButton *button;
592 windowCount++;
594 win = WMCreateWindow(scr, "testTabs");
595 WMResizeWidget(win, 300, 400);
596 WMSetWindowCloseAction(win, closeAction, NULL);
598 frame = WMCreateFrame(win);
599 WMSetFrameRelief(frame, WRSunken);
600 WMMoveWidget(frame, 5, 5);
601 WMResizeWidget(frame, 290, 40);
603 splitv1 = WMCreateSplitView(win);
604 WMMoveWidget(splitv1, 5, 50);
605 WMResizeWidget(splitv1, 290, 345);
606 WMSetSplitViewConstrainProc(splitv1, splitViewConstrainProc);
607 WMCreateEventHandler(WMWidgetView(win), StructureNotifyMask,
608 resizeSplitView, splitv1);
610 button = WMCreateCommandButton(frame);
611 WMSetButtonText(button, "+");
612 WMSetButtonAction(button, appendSubviewButtonAction, splitv1);
613 WMMoveWidget(button, 10, 8);
614 WMMapWidget(button);
616 button = WMCreateCommandButton(frame);
617 WMSetButtonText(button, "-");
618 WMSetButtonAction(button, removeSubviewButtonAction, splitv1);
619 WMMoveWidget(button, 80, 8);
620 WMMapWidget(button);
622 button = WMCreateCommandButton(frame);
623 WMSetButtonText(button, "=");
624 WMMoveWidget(button, 150, 8);
625 WMSetButtonAction(button, adjustSubviewsButtonAction, splitv1);
626 WMMapWidget(button);
628 button = WMCreateCommandButton(frame);
629 WMSetButtonText(button, "#");
630 WMMoveWidget(button, 220, 8);
631 WMSetButtonAction(button, orientationButtonAction, splitv1);
632 WMMapWidget(button);
634 label = WMCreateLabel(splitv1);
635 WMSetLabelText(label, "Subview 1");
636 WMSetLabelRelief(label, WRSunken);
637 WMMapWidget(label);
638 WMAddSplitViewSubview(splitv1, WMWidgetView(label));
640 splitv2 = WMCreateSplitView(splitv1);
641 WMResizeWidget(splitv2, 150, 150);
642 WMSetSplitViewVertical(splitv2, True);
644 label = WMCreateLabel(splitv2);
645 WMSetLabelText(label, "Subview 2.1");
646 WMSetLabelRelief(label, WRSunken);
647 WMMapWidget(label);
648 WMAddSplitViewSubview(splitv2, WMWidgetView(label));
650 label = WMCreateLabel(splitv2);
651 WMSetLabelText(label, "Subview 2.2");
652 WMSetLabelRelief(label, WRSunken);
653 WMMapWidget(label);
654 WMAddSplitViewSubview(splitv2, WMWidgetView(label));
656 label = WMCreateLabel(splitv2);
657 WMSetLabelText(label, "Subview 2.3");
658 WMSetLabelRelief(label, WRSunken);
659 WMMapWidget(label);
660 WMAddSplitViewSubview(splitv2, WMWidgetView(label));
662 WMMapWidget(splitv2);
663 WMAddSplitViewSubview(splitv1, WMWidgetView(splitv2));
665 WMRealizeWidget(win);
666 WMMapSubwidgets(win);
667 WMMapWidget(win);
670 #include "WUtil.h"
674 int main(int argc, char **argv)
676 WMScreen *scr;
677 WMPixmap *pixmap;
680 /* Initialize the application */
681 WMInitializeApplication("Test", &argc, argv);
684 * Open connection to the X display.
686 dpy = XOpenDisplay("");
688 if (!dpy) {
689 puts("could not open display");
690 exit(1);
693 /* This is used to disable buffering of X protocol requests.
694 * Do NOT use it unless when debugging. It will cause a major
695 * slowdown in your application
697 #ifdef DEBUG
698 XSynchronize(dpy, True);
699 #endif
701 * Create screen descriptor.
703 scr = WMCreateScreen(dpy, DefaultScreen(dpy));
706 * Loads the logo of the application.
708 pixmap = WMCreatePixmapFromFile(scr, "logo.xpm");
711 * Makes the logo be used in standard dialog panels.
713 WMSetApplicationIconImage(scr, pixmap); WMReleasePixmap(pixmap);
716 * Do some test stuff.
718 * Put the testSomething() function you want to test here.
722 testColorWell(scr);
723 #if 0
724 testTabView(scr);
726 testFontPanel(scr);
728 testSplitView(scr);
730 testGradientButtons(scr);
731 testProgressIndicator(scr);
733 testTextField(scr);
735 testOpenFilePanel(scr);
736 testList(scr);
737 testScrollView(scr);
740 testSlider(scr);
741 testPullDown(scr);
742 #endif
744 * The main event loop.
747 WMScreenMainLoop(scr);
749 return 0;