From man localtime, January is 0 and December is 11, compare it to 12 won't do such...
[wmaker-crm.git] / WINGs / wtest.c
blob2dec3448a9c41afa31448e740d22ef53c83789c7
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;
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 btn = WMCreateButton(win, WBTMomentaryChange);
138 WMResizeWidget(btn, 60, 24);
139 WMMoveWidget(btn, 20, 100);
140 WMSetButtonBordered(btn, False);
141 WMSetButtonImagePosition(btn, WIPOverlaps);
142 WMSetButtonImage(btn, pix1);
143 WMSetButtonAltImage(btn, pix2);
144 WMSetButtonText(btn, "Cool");
146 WMSetBalloonTextForView("This is a button", WMWidgetView(btn));
148 btn = WMCreateButton(win, WBTMomentaryChange);
149 WMResizeWidget(btn, 60, 24);
150 WMMoveWidget(btn, 90, 100);
151 WMSetButtonBordered(btn, False);
152 WMSetButtonImagePosition(btn, WIPOverlaps);
153 WMSetButtonImage(btn, pix1);
154 WMSetButtonAltImage(btn, pix2);
155 WMSetButtonText(btn, "Button");
157 WMSetBalloonTextForView("Este é outro balão.", WMWidgetView(btn));
159 btn = WMCreateButton(win, WBTMomentaryChange);
160 WMResizeWidget(btn, 60, 24);
161 WMMoveWidget(btn, 160, 100);
162 WMSetButtonBordered(btn, False);
163 WMSetButtonImagePosition(btn, WIPOverlaps);
164 WMSetButtonImage(btn, pix1);
165 WMSetButtonAltImage(btn, pix2);
166 WMSetButtonText(btn, "Test");
168 WMSetBalloonTextForView("This is yet another button.\nBut the balloon has 3 lines.\nYay!",
169 WMWidgetView(btn));
171 WMRealizeWidget(win);
172 WMMapSubwidgets(win);
173 WMMapWidget(win);
177 void
178 testScrollView(WMScreen *scr)
180 WMWindow *win;
181 WMScrollView *sview;
182 WMFrame *f;
183 WMLabel *l;
184 char buffer[128];
185 int i;
187 windowCount++;
189 /* creates the top-level window */
190 win = WMCreateWindow(scr, "testScroll");
191 WMSetWindowTitle(win, "Scrollable View");
193 WMSetWindowCloseAction(win, closeAction, NULL);
195 /* set the window size */
196 WMResizeWidget(win, 300, 300);
198 /* creates a scrollable view inside the top-level window */
199 sview = WMCreateScrollView(win);
200 WMResizeWidget(sview, 200, 200);
201 WMMoveWidget(sview, 30, 30);
202 WMSetScrollViewRelief(sview, WRSunken);
203 WMSetScrollViewHasVerticalScroller(sview, True);
204 WMSetScrollViewHasHorizontalScroller(sview, True);
206 /* create a frame with a bunch of labels */
207 f = WMCreateFrame(win);
208 WMResizeWidget(f, 400, 400);
209 WMSetFrameRelief(f, WRFlat);
211 for (i=0; i<20; i++) {
212 l = WMCreateLabel(f);
213 WMResizeWidget(l, 50, 18);
214 WMMoveWidget(l, 10, 20*i);
215 sprintf(buffer, "Label %i", i);
216 WMSetLabelText(l, buffer);
217 WMSetLabelRelief(l, WRSimple);
219 WMMapSubwidgets(f);
220 WMMapWidget(f);
222 WMSetScrollViewContentView(sview, WMWidgetView(f));
224 /* make the windows of the widgets be actually created */
225 WMRealizeWidget(win);
227 /* Map all child widgets of the top-level be mapped.
228 * You must call this for each container widget (like frames),
229 * even if they are childs of the top-level window.
231 WMMapSubwidgets(win);
233 /* map the top-level window */
234 WMMapWidget(win);
238 void
239 testColorWell(WMScreen *scr)
241 WMWindow *win;
242 WMColorWell *well1, *well2;
244 windowCount++;
246 win = WMCreateWindow(scr, "testColor");
247 WMResizeWidget(win, 300, 300);
249 WMSetWindowCloseAction(win, closeAction, NULL);
251 well1 = WMCreateColorWell(win);
252 WMResizeWidget(well1, 60, 40);
253 WMMoveWidget(well1, 100, 100);
254 WMSetColorWellColor(well1, WMCreateRGBColor(scr, 0x8888, 0, 0x1111, True));
255 well2 = WMCreateColorWell(win);
256 WMResizeWidget(well2, 60, 40);
257 WMMoveWidget(well2, 200, 100);
258 WMSetColorWellColor(well2, WMCreateRGBColor(scr, 0, 0, 0x8888, True));
260 WMRealizeWidget(win);
261 WMMapSubwidgets(win);
262 WMMapWidget(win);
265 void
266 sliderCallback(WMWidget *w, void *data)
268 printf("SLIEDER == %i\n", WMGetSliderValue(w));
272 void
273 testSlider(WMScreen *scr)
275 WMWindow *win;
276 WMSlider *s;
278 windowCount++;
280 win = WMCreateWindow(scr, "testSlider");
281 WMResizeWidget(win, 300, 300);
282 WMSetWindowTitle(win, "Sliders");
284 WMSetWindowCloseAction(win, closeAction, NULL);
286 s = WMCreateSlider(win);
287 WMResizeWidget(s, 16, 100);
288 WMMoveWidget(s, 100, 100);
289 WMSetSliderKnobThickness(s, 8);
290 WMSetSliderContinuous(s, False);
291 WMSetSliderAction(s, sliderCallback, s);
293 s = WMCreateSlider(win);
294 WMResizeWidget(s, 100, 16);
295 WMMoveWidget(s, 100, 10);
296 WMSetSliderKnobThickness(s, 8);
298 WMRealizeWidget(win);
299 WMMapSubwidgets(win);
300 WMMapWidget(win);
304 void
305 testTextField(WMScreen *scr)
307 WMWindow *win;
308 WMTextField *field, *field2;
310 windowCount++;
312 win = WMCreateWindow(scr, "testText");
313 WMResizeWidget(win, 400, 300);
315 WMSetWindowCloseAction(win, closeAction, NULL);
317 field = WMCreateTextField(win);
318 WMResizeWidget(field, 200, 20);
319 WMMoveWidget(field, 20, 20);
321 field2 = WMCreateTextField(win);
322 WMResizeWidget(field2, 200, 20);
323 WMMoveWidget(field2, 20, 50);
324 WMSetTextFieldAlignment(field2, WARight);
326 WMRealizeWidget(win);
327 WMMapSubwidgets(win);
328 WMMapWidget(win);
333 void
334 testProgressIndicator(WMScreen *scr)
336 WMWindow *win;
337 WMProgressIndicator *pPtr;
339 windowCount++;
341 win = WMCreateWindow(scr, "testProgressIndicator");
342 WMResizeWidget(win, 292, 32);
344 WMSetWindowCloseAction(win, closeAction, NULL);
346 pPtr = WMCreateProgressIndicator(win);
347 WMMoveWidget(pPtr, 8, 8);
348 WMSetProgressIndicatorValue(pPtr, 75);
350 WMRealizeWidget(win);
351 WMMapSubwidgets(win);
352 WMMapWidget(win);
357 void
358 testPullDown(WMScreen *scr)
360 WMWindow *win;
361 WMPopUpButton *pop, *pop2;
363 windowCount++;
365 win = WMCreateWindow(scr, "pullDown");
366 WMResizeWidget(win, 400, 300);
368 WMSetWindowCloseAction(win, closeAction, NULL);
370 pop = WMCreatePopUpButton(win);
371 WMResizeWidget(pop, 100, 20);
372 WMMoveWidget(pop, 50, 60);
373 WMSetPopUpButtonPullsDown(pop, True);
374 WMSetPopUpButtonText(pop, "Commands");
375 WMAddPopUpButtonItem(pop, "Add");
376 WMAddPopUpButtonItem(pop, "Remove");
377 WMAddPopUpButtonItem(pop, "Check");
378 WMAddPopUpButtonItem(pop, "Eat");
380 pop2 = WMCreatePopUpButton(win);
381 WMResizeWidget(pop2, 100, 20);
382 WMMoveWidget(pop2, 200, 60);
383 WMSetPopUpButtonText(pop2, "Select");
384 WMAddPopUpButtonItem(pop2, "Apples");
385 WMAddPopUpButtonItem(pop2, "Bananas");
386 WMAddPopUpButtonItem(pop2, "Strawberries");
387 WMAddPopUpButtonItem(pop2, "Blueberries");
389 WMRealizeWidget(win);
390 WMMapSubwidgets(win);
391 WMMapWidget(win);
396 void
397 testTabView(WMScreen *scr)
399 WMWindow *win;
400 WMTabView *tabv;
401 WMTabViewItem *tab;
402 WMFrame *frame;
403 WMLabel *label;
405 windowCount++;
407 win = WMCreateWindow(scr, "testTabs");
408 WMResizeWidget(win, 400, 300);
410 WMSetWindowCloseAction(win, closeAction, NULL);
412 tabv = WMCreateTabView(win);
413 WMMoveWidget(tabv, 50, 50);
414 WMResizeWidget(tabv, 300, 200);
416 frame = WMCreateFrame(win);
417 WMSetFrameRelief(frame, WRFlat);
418 label = WMCreateLabel(frame);
419 WMResizeWidget(label, 100, 100);
420 WMSetLabelText(label, "Label 1");
421 WMMapWidget(label);
424 tab = WMCreateTabViewItemWithIdentifier(0);
425 WMSetTabViewItemView(tab, WMWidgetView(frame));
426 WMAddItemInTabView(tabv, tab);
427 WMSetTabViewItemLabel(tab, "Instances");
429 frame = WMCreateFrame(win);
430 WMSetFrameRelief(frame, WRFlat);
431 label = WMCreateLabel(frame);
432 WMResizeWidget(label, 40, 50);
433 WMSetLabelText(label, "Label 2");
434 WMMapWidget(label);
437 tab = WMCreateTabViewItemWithIdentifier(0);
438 WMSetTabViewItemView(tab, WMWidgetView(frame));
439 WMAddItemInTabView(tabv, tab);
440 WMSetTabViewItemLabel(tab, "Classes");
443 frame = WMCreateFrame(win);
444 WMSetFrameRelief(frame, WRFlat);
445 label = WMCreateLabel(frame);
446 WMResizeWidget(label, 100, 100);
447 WMMoveWidget(label, 60, 40);
448 WMSetLabelText(label, "Label 3");
449 WMMapWidget(label);
451 tab = WMCreateTabViewItemWithIdentifier(0);
452 WMSetTabViewItemView(tab, WMWidgetView(frame));
453 WMAddItemInTabView(tabv, tab);
454 WMSetTabViewItemLabel(tab, "Something");
457 WMRealizeWidget(win);
458 WMMapSubwidgets(win);
459 WMMapWidget(win);
463 void
464 splitViewConstrainProc(WMSplitView *sPtr, int indView,
465 int *minSize, int *maxSize)
467 switch (indView) {
468 case 0:
469 *minSize = 20;
470 break;
471 case 1:
472 *minSize = 40;
473 *maxSize = 80;
474 break;
475 case 2:
476 *maxSize = 60;
477 break;
478 default:
479 break;
484 static void
485 resizeSplitView(XEvent *event, void *data)
487 WMSplitView *sPtr = (WMSplitView*)data;
489 if (event->type == ConfigureNotify) {
490 int width = event->xconfigure.width - 10;
492 if (width < WMGetSplitViewDividerThickness(sPtr))
493 width = WMGetSplitViewDividerThickness(sPtr);
495 if (width != WMWidgetWidth(sPtr) ||
496 event->xconfigure.height != WMWidgetHeight(sPtr))
497 WMResizeWidget(sPtr, width, event->xconfigure.height - 55);
501 void
502 appendSubviewButtonAction(WMWidget *self, void *data)
504 WMSplitView *sPtr = (WMSplitView*)data;
505 char buf[64];
506 WMLabel *label = WMCreateLabel(sPtr);
508 sprintf(buf, "Subview %d", WMGetSplitViewSubviewsCount(sPtr) + 1);
509 WMSetLabelText(label, buf);
510 WMSetLabelRelief(label, WRSunken);
511 WMAddSplitViewSubview(sPtr, WMWidgetView(label));
512 WMRealizeWidget(label);
513 WMMapWidget(label);
516 void
517 removeSubviewButtonAction(WMWidget *self, void *data)
519 WMSplitView *sPtr = (WMSplitView*)data;
520 int count = WMGetSplitViewSubviewsCount(sPtr);
522 if (count > 2) {
523 WMView *view = WMGetSplitViewSubviewAt(sPtr, count-1);
524 WMDestroyWidget(WMWidgetOfView(view));
525 WMRemoveSplitViewSubviewAt(sPtr, count-1);
529 void
530 orientationButtonAction(WMWidget *self, void *data)
532 WMSplitView *sPtr = (WMSplitView*)data;
533 WMSetSplitViewVertical(sPtr, !WMGetSplitViewVertical(sPtr));
536 void
537 adjustSubviewsButtonAction(WMWidget *self, void *data)
539 WMAdjustSplitViewSubviews((WMSplitView*)data);
542 void
543 testSplitView(WMScreen *scr)
545 WMWindow *win;
546 WMSplitView *splitv1, *splitv2;
547 WMFrame *frame;
548 WMLabel *label;
549 WMButton *button;
551 windowCount++;
553 win = WMCreateWindow(scr, "testTabs");
554 WMResizeWidget(win, 300, 400);
555 WMSetWindowCloseAction(win, closeAction, NULL);
557 frame = WMCreateFrame(win);
558 WMSetFrameRelief(frame, WRSunken);
559 WMMoveWidget(frame, 5, 5);
560 WMResizeWidget(frame, 290, 40);
562 splitv1 = WMCreateSplitView(win);
563 WMMoveWidget(splitv1, 5, 50);
564 WMResizeWidget(splitv1, 290, 345);
565 WMSetSplitViewConstrainProc(splitv1, splitViewConstrainProc);
566 WMCreateEventHandler(WMWidgetView(win), StructureNotifyMask,
567 resizeSplitView, splitv1);
569 button = WMCreateCommandButton(frame);
570 WMSetButtonText(button, "+");
571 WMSetButtonAction(button, appendSubviewButtonAction, splitv1);
572 WMMoveWidget(button, 10, 8);
573 WMMapWidget(button);
575 button = WMCreateCommandButton(frame);
576 WMSetButtonText(button, "-");
577 WMSetButtonAction(button, removeSubviewButtonAction, splitv1);
578 WMMoveWidget(button, 80, 8);
579 WMMapWidget(button);
581 button = WMCreateCommandButton(frame);
582 WMSetButtonText(button, "=");
583 WMMoveWidget(button, 150, 8);
584 WMSetButtonAction(button, adjustSubviewsButtonAction, splitv1);
585 WMMapWidget(button);
587 button = WMCreateCommandButton(frame);
588 WMSetButtonText(button, "#");
589 WMMoveWidget(button, 220, 8);
590 WMSetButtonAction(button, orientationButtonAction, splitv1);
591 WMMapWidget(button);
593 label = WMCreateLabel(splitv1);
594 WMSetLabelText(label, "Subview 1");
595 WMSetLabelRelief(label, WRSunken);
596 WMMapWidget(label);
597 WMAddSplitViewSubview(splitv1, WMWidgetView(label));
599 splitv2 = WMCreateSplitView(splitv1);
600 WMResizeWidget(splitv2, 150, 150);
601 WMSetSplitViewVertical(splitv2, True);
603 label = WMCreateLabel(splitv2);
604 WMSetLabelText(label, "Subview 2.1");
605 WMSetLabelRelief(label, WRSunken);
606 WMMapWidget(label);
607 WMAddSplitViewSubview(splitv2, WMWidgetView(label));
609 label = WMCreateLabel(splitv2);
610 WMSetLabelText(label, "Subview 2.2");
611 WMSetLabelRelief(label, WRSunken);
612 WMMapWidget(label);
613 WMAddSplitViewSubview(splitv2, WMWidgetView(label));
615 label = WMCreateLabel(splitv2);
616 WMSetLabelText(label, "Subview 2.3");
617 WMSetLabelRelief(label, WRSunken);
618 WMMapWidget(label);
619 WMAddSplitViewSubview(splitv2, WMWidgetView(label));
621 WMMapWidget(splitv2);
622 WMAddSplitViewSubview(splitv1, WMWidgetView(splitv2));
624 WMRealizeWidget(win);
625 WMMapSubwidgets(win);
626 WMMapWidget(win);
629 #include "WUtil.h"
633 int main(int argc, char **argv)
635 WMScreen *scr;
636 WMPixmap *pixmap;
639 /* Initialize the application */
640 WMInitializeApplication("Test", &argc, argv);
643 * Open connection to the X display.
645 dpy = XOpenDisplay("");
647 if (!dpy) {
648 puts("could not open display");
649 exit(1);
652 /* This is used to disable buffering of X protocol requests.
653 * Do NOT use it unless when debugging. It will cause a major
654 * slowdown in your application
656 #ifdef DEBUG
657 XSynchronize(dpy, True);
658 #endif
660 * Create screen descriptor.
662 scr = WMCreateScreen(dpy, DefaultScreen(dpy));
665 * Loads the logo of the application.
667 pixmap = WMCreatePixmapFromFile(scr, "logo.xpm");
670 * Makes the logo be used in standard dialog panels.
672 WMSetApplicationIconImage(scr, pixmap); WMReleasePixmap(pixmap);
675 * Do some test stuff.
677 * Put the testSomething() function you want to test here.
681 testSplitView(scr);
682 testFontPanel(scr);
683 #if 0
685 testProgressIndicator(scr);
686 testGradientButtons(scr);
687 testColorWell(scr);
689 testTabView(scr);
690 testTextField(scr);
692 testOpenFilePanel(scr);
693 testList(scr);
694 testScrollView(scr);
697 testSlider(scr);
698 testPullDown(scr);
699 #endif
701 * The main event loop.
704 WMScreenMainLoop(scr);
706 return 0;