added box widget
[wmaker-crm.git] / WINGs / Tests / wtest.c
blobf4381aa3d512a56b2803a9b1bc5044901b56027e
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 printf("window closed, window count = %d\n", windowCount);
35 if (windowCount < 1)
36 exit(0);
40 void
41 testOpenFilePanel(WMScreen *scr)
43 WMOpenPanel *panel;
45 /* windowCount++; */
47 /* get the shared Open File panel */
48 panel = WMGetOpenPanel(scr);
50 WMRunModalFilePanelForDirectory(panel, NULL, "/usr/local", NULL, NULL);
52 /* free the panel to save some memory. Not needed otherwise. */
53 WMFreeFilePanel(WMGetOpenPanel(scr));
57 void
58 testFontPanel(WMScreen *scr)
60 WMFontPanel *panel;
62 /*windowCount++;*/
64 panel = WMGetFontPanel(scr);
66 WMShowFontPanel(panel);
68 /* WMFreeFontPanel(panel);*/
73 void
74 testFrame(WMScreen *scr)
76 WMWindow *win;
77 WMFrame *frame;
78 int i;
79 static char* titles[] = {
80 "AboveTop",
81 "AtTop",
82 "BelowTop",
83 "AboveBottom",
84 "AtBottom",
85 "BelowBottom"
87 static WMTitlePosition pos[] = {
88 WTPAboveTop,
89 WTPAtTop,
90 WTPBelowTop,
91 WTPAboveBottom,
92 WTPAtBottom,
93 WTPBelowBottom
96 windowCount++;
98 win = WMCreateWindow(scr, "testFrame");
99 WMSetWindowTitle(win, "Frame");
100 WMSetWindowCloseAction(win, closeAction, NULL);
101 WMResizeWidget(win, 400, 300);
103 for (i = 0; i < 6; i++) {
104 frame = WMCreateFrame(win);
105 WMMoveWidget(frame, 8+(i%3)*130, 8+(i/3)*130);
106 WMResizeWidget(frame, 120, 120);
107 WMSetFrameTitle(frame, titles[i]);
108 WMSetFrameTitlePosition(frame, pos[i]);
111 WMRealizeWidget(win);
112 WMMapSubwidgets(win);
113 WMMapWidget(win);
118 void
119 testBox(WMScreen *scr)
121 WMWindow *win;
122 WMBox *box;
123 WMButton *btn;
124 int i;
126 windowCount++;
128 win = WMCreateWindow(scr, "testBox");
129 WMSetWindowTitle(win, "Box");
130 WMSetWindowCloseAction(win, closeAction, NULL);
131 WMResizeWidget(win, 400, 300);
133 box = WMCreateBox(win);
134 WMMoveWidget(box, 50, 50);
135 WMResizeWidget(box, 300, 200);
136 // WMSetBoxHorizontal(box, True);
137 for (i = 0; i < 4; i++) {
138 btn = WMCreateCommandButton(box);
139 WMSetButtonText(btn, "bla");
140 WMMapWidget(btn);
141 WMAddBoxSubview(box, WMWidgetView(btn), i&1, True, 20, 0, 5);
144 WMRealizeWidget(win);
145 WMMapSubwidgets(win);
146 WMMapWidget(win);
152 static void
153 singleClick(WMWidget *self, void *data)
158 static void
159 doubleClick(WMWidget *self, void *data)
161 WMLabel *label = (WMLabel*)data;
162 WMList *lPtr = (WMList*)self;
163 char buf[255];
165 WMSelectAllListItems(lPtr);
169 static void
170 listSelectionObserver(void *observer, WMNotification *notification)
172 WMLabel *label = (WMLabel*)observer;
173 WMList *lPtr = (WMList*)WMGetNotificationObject(notification);
174 char buf[255];
176 sprintf(buf, "Selected items: %d",
177 WMGetArrayItemCount(WMGetListSelectedItems(lPtr)));
178 WMSetLabelText(label, buf);
182 void
183 testList(WMScreen *scr)
185 WMWindow *win;
186 WMList *list;
187 WMList *mlist;
188 WMLabel *label;
189 WMLabel *mlabel;
190 WMLabel *title;
191 WMLabel *mtitle;
192 char text[100];
193 int i;
195 windowCount++;
197 win = WMCreateWindow(scr, "testList");
198 WMResizeWidget(win, 370, 250);
199 WMSetWindowTitle(win, "List");
200 WMSetWindowCloseAction(win, closeAction, NULL);
202 title = WMCreateLabel(win);
203 WMResizeWidget(title, 150, 20);
204 WMMoveWidget(title, 10, 10);
205 WMSetLabelRelief(title, WRRidge);
206 WMSetLabelText(title, "Single selection list");
208 mtitle = WMCreateLabel(win);
209 WMResizeWidget(mtitle, 150, 20);
210 WMMoveWidget(mtitle, 210, 10);
211 WMSetLabelRelief(mtitle, WRRidge);
212 WMSetLabelText(mtitle, "Multiple selection list");
214 list = WMCreateList(win);
215 /*WMSetListAllowEmptySelection(list, True);*/
216 WMMoveWidget(list, 10, 40);
217 for (i=0; i<50; i++) {
218 sprintf(text, "Item %i", i);
219 WMAddListItem(list, text);
221 mlist = WMCreateList(win);
222 WMSetListAllowMultipleSelection(mlist, True);
223 /*WMSetListAllowEmptySelection(mlist, True);*/
224 WMMoveWidget(mlist, 210, 40);
225 for (i=0; i<135; i++) {
226 sprintf(text, "Item %i", i);
227 WMAddListItem(mlist, text);
230 label = WMCreateLabel(win);
231 WMResizeWidget(label, 150, 40);
232 WMMoveWidget(label, 10, 200);
233 WMSetLabelRelief(label, WRRidge);
234 WMSetLabelText(label, "Selected items: 0");
236 mlabel = WMCreateLabel(win);
237 WMResizeWidget(mlabel, 150, 40);
238 WMMoveWidget(mlabel, 210, 200);
239 WMSetLabelRelief(mlabel, WRRidge);
240 WMSetLabelText(mlabel, "Selected items: 0");
242 WMSetListAction(list, singleClick, label);
243 WMSetListDoubleAction(list, doubleClick, label);
244 WMSetListAction(mlist, singleClick, mlabel);
245 WMSetListDoubleAction(mlist, doubleClick, mlabel);
247 WMAddNotificationObserver(listSelectionObserver, label,
248 WMListSelectionDidChangeNotification, list);
249 WMAddNotificationObserver(listSelectionObserver, mlabel,
250 WMListSelectionDidChangeNotification, mlist);
253 WMRealizeWidget(win);
254 WMMapSubwidgets(win);
255 WMMapWidget(win);
259 void
260 testButton(WMScreen *scr)
262 WMWindow *win;
263 int i;
264 char *types[] = {
265 "MomentaryPush",
266 "PushOnPushOff",
267 "Toggle",
268 "Switch",
269 "Radio",
270 "MomentaryChange",
271 "OnOff",
272 "MomentaryLigh"
275 windowCount++;
277 win = WMCreateWindow(scr, "testButton");
278 WMResizeWidget(win, 300, 300);
279 WMSetWindowTitle(win, "Buttons");
281 WMSetWindowCloseAction(win, closeAction, NULL);
283 for (i = 1; i < 9; i++) {
284 WMButton *b;
285 b = WMCreateButton(win, i);
286 WMResizeWidget(b, 150, 24);
287 WMMoveWidget(b, 20, i*30);
288 WMSetButtonText(b, types[i-1]);
291 WMRealizeWidget(win);
292 WMMapSubwidgets(win);
293 WMMapWidget(win);
297 void
298 testGradientButtons(WMScreen *scr)
300 WMWindow *win;
301 WMButton *btn;
302 WMPixmap *pix1, *pix2;
303 RImage *back;
304 RColor light, dark;
305 WMColor *color, *altColor;
307 windowCount++;
309 /* creates the top-level window */
310 win = WMCreateWindow(scr, "testGradientButtons");
311 WMSetWindowTitle(win, "Gradiented Button Demo");
312 WMResizeWidget(win, 300, 200);
314 light.red = 0x90;
315 light.green = 0x85;
316 light.blue = 0x90;
317 dark.red = 0x35;
318 dark.green = 0x30;
319 dark.blue = 0x35;
321 color = WMCreateRGBColor(scr, 0x5900, 0x5100, 0x5900, True);
322 WMSetWidgetBackgroundColor(win, color);
323 WMReleaseColor(color);
325 back = RRenderGradient(60, 24, &dark, &light, RGRD_DIAGONAL);
326 RBevelImage(back, RBEV_RAISED2);
327 pix1 = WMCreatePixmapFromRImage(scr, back, 0);
328 RDestroyImage(back);
330 back = RRenderGradient(60, 24, &dark, &light, RGRD_DIAGONAL);
331 RBevelImage(back, RBEV_SUNKEN);
332 pix2 = WMCreatePixmapFromRImage(scr, back, 0);
333 RDestroyImage(back);
335 color = WMWhiteColor(scr);
336 altColor = WMCreateNamedColor(scr, "red", True);
338 btn = WMCreateButton(win, WBTMomentaryChange);
339 WMResizeWidget(btn, 60, 24);
340 WMMoveWidget(btn, 20, 100);
341 WMSetButtonBordered(btn, False);
342 WMSetButtonImagePosition(btn, WIPOverlaps);
343 WMSetButtonImage(btn, pix1);
344 WMSetButtonAltImage(btn, pix2);
345 WMSetButtonText(btn, "Cool");
346 WMSetButtonTextColor(btn, color);
347 WMSetButtonAltTextColor(btn, altColor);
349 WMSetBalloonTextForView("This is a cool button", WMWidgetView(btn));
351 btn = WMCreateButton(win, WBTMomentaryChange);
352 WMResizeWidget(btn, 60, 24);
353 WMMoveWidget(btn, 90, 100);
354 WMSetButtonBordered(btn, False);
355 WMSetButtonImagePosition(btn, WIPOverlaps);
356 WMSetButtonImage(btn, pix1);
357 WMSetButtonAltImage(btn, pix2);
358 WMSetButtonText(btn, "Button");
359 WMSetButtonTextColor(btn, color);
361 WMSetBalloonTextForView("Este é outro balão.", WMWidgetView(btn));
363 WMReleaseColor(color);
364 color = WMCreateNamedColor(scr, "orange", True);
366 btn = WMCreateButton(win, WBTMomentaryChange);
367 WMResizeWidget(btn, 60, 24);
368 WMMoveWidget(btn, 160, 100);
369 WMSetButtonBordered(btn, False);
370 WMSetButtonImagePosition(btn, WIPOverlaps);
371 WMSetButtonImage(btn, pix1);
372 WMSetButtonAltImage(btn, pix2);
373 WMSetButtonText(btn, "Test");
374 WMSetButtonTextColor(btn, color);
376 WMSetBalloonTextForView("This is yet another button.\nBut the balloon has 3 lines.\nYay!",
377 WMWidgetView(btn));
379 WMReleaseColor(color);
380 WMReleaseColor(altColor);
382 WMRealizeWidget(win);
383 WMMapSubwidgets(win);
384 WMMapWidget(win);
388 void
389 testScrollView(WMScreen *scr)
391 WMWindow *win;
392 WMScrollView *sview;
393 WMFrame *f;
394 WMLabel *l;
395 char buffer[128];
396 int i;
398 windowCount++;
400 /* creates the top-level window */
401 win = WMCreateWindow(scr, "testScroll");
402 WMSetWindowTitle(win, "Scrollable View");
404 WMSetWindowCloseAction(win, closeAction, NULL);
406 /* set the window size */
407 WMResizeWidget(win, 300, 300);
409 /* creates a scrollable view inside the top-level window */
410 sview = WMCreateScrollView(win);
411 WMResizeWidget(sview, 200, 200);
412 WMMoveWidget(sview, 30, 30);
413 WMSetScrollViewRelief(sview, WRSunken);
414 WMSetScrollViewHasVerticalScroller(sview, True);
415 WMSetScrollViewHasHorizontalScroller(sview, True);
417 /* create a frame with a bunch of labels */
418 f = WMCreateFrame(win);
419 WMResizeWidget(f, 400, 400);
420 WMSetFrameRelief(f, WRFlat);
422 for (i=0; i<20; i++) {
423 l = WMCreateLabel(f);
424 WMResizeWidget(l, 50, 18);
425 WMMoveWidget(l, 10, 20*i);
426 sprintf(buffer, "Label %i", i);
427 WMSetLabelText(l, buffer);
428 WMSetLabelRelief(l, WRSimple);
430 WMMapSubwidgets(f);
431 WMMapWidget(f);
433 WMSetScrollViewContentView(sview, WMWidgetView(f));
435 /* make the windows of the widgets be actually created */
436 WMRealizeWidget(win);
438 /* Map all child widgets of the top-level be mapped.
439 * You must call this for each container widget (like frames),
440 * even if they are childs of the top-level window.
442 WMMapSubwidgets(win);
444 /* map the top-level window */
445 WMMapWidget(win);
449 void
450 testColorWell(WMScreen *scr)
452 WMWindow *win;
453 WMColorWell *well1, *well2;
455 windowCount++;
457 win = WMCreateWindow(scr, "testColor");
458 WMResizeWidget(win, 300, 300);
459 WMSetWindowCloseAction(win, closeAction, NULL);
461 well1 = WMCreateColorWell(win);
462 WMResizeWidget(well1, 60, 40);
463 WMMoveWidget(well1, 100, 100);
464 WMSetColorWellColor(well1, WMCreateRGBColor(scr, 0x8888, 0, 0x1111, True));
465 well2 = WMCreateColorWell(win);
466 WMResizeWidget(well2, 60, 40);
467 WMMoveWidget(well2, 200, 100);
468 WMSetColorWellColor(well2, WMCreateRGBColor(scr, 0, 0, 0x8888, True));
470 WMRealizeWidget(win);
471 WMMapSubwidgets(win);
472 WMMapWidget(win);
475 void
476 sliderCallback(WMWidget *w, void *data)
478 printf("SLIDER == %i\n", WMGetSliderValue(w));
482 void
483 testSlider(WMScreen *scr)
485 WMWindow *win;
486 WMSlider *s;
488 windowCount++;
490 win = WMCreateWindow(scr, "testSlider");
491 WMResizeWidget(win, 300, 300);
492 WMSetWindowTitle(win, "Sliders");
494 WMSetWindowCloseAction(win, closeAction, NULL);
496 s = WMCreateSlider(win);
497 WMResizeWidget(s, 16, 100);
498 WMMoveWidget(s, 100, 100);
499 WMSetSliderKnobThickness(s, 8);
500 WMSetSliderContinuous(s, False);
501 WMSetSliderAction(s, sliderCallback, s);
503 s = WMCreateSlider(win);
504 WMResizeWidget(s, 100, 16);
505 WMMoveWidget(s, 100, 10);
506 WMSetSliderKnobThickness(s, 8);
508 WMRealizeWidget(win);
509 WMMapSubwidgets(win);
510 WMMapWidget(win);
513 void
514 testTextField(WMScreen *scr)
516 WMWindow *win;
517 WMTextField *field, *field2;
519 windowCount++;
521 win = WMCreateWindow(scr, "testTextField");
522 WMResizeWidget(win, 400, 300);
524 WMSetWindowCloseAction(win, closeAction, NULL);
526 field = WMCreateTextField(win);
527 WMResizeWidget(field, 200, 20);
528 WMMoveWidget(field, 20, 20);
530 field2 = WMCreateTextField(win);
531 WMResizeWidget(field2, 200, 20);
532 WMMoveWidget(field2, 20, 50);
533 WMSetTextFieldAlignment(field2, WARight);
535 WMRealizeWidget(win);
536 WMMapSubwidgets(win);
537 WMMapWidget(win);
542 void
543 testText(WMScreen *scr)
545 WMWindow *win;
546 WMText *text;
547 FILE *file = fopen("../README", "r");
549 windowCount++;
551 win = WMCreateWindow(scr, "testText");
552 WMResizeWidget(win, 500, 300);
554 WMSetWindowCloseAction(win, closeAction, NULL);
556 text = WMCreateText(win);
557 WMResizeWidget(text, 480, 280);
558 WMMoveWidget(text, 10, 10);
559 WMSetTextHasVerticalScroller(text, True);
560 WMSetTextEditable(text, False);
562 if(file) {
563 char buf[1024];
565 WMFreezeText(text);
566 while(fgets(buf, 1023, file))
567 WMAppendTextStream(text, buf);
569 fclose(file);
570 WMThawText(text);
571 } else {
572 WMAppendTextStream(text, "<HTML><i>Where's</i> the <b>README</b>?");
575 WMRealizeWidget(win);
576 WMMapSubwidgets(win);
577 WMMapWidget(win);
581 void
582 testProgressIndicator(WMScreen *scr)
584 WMWindow *win;
585 WMProgressIndicator *pPtr;
587 windowCount++;
589 win = WMCreateWindow(scr, "testProgressIndicator");
590 WMResizeWidget(win, 292, 32);
592 WMSetWindowCloseAction(win, closeAction, NULL);
594 pPtr = WMCreateProgressIndicator(win);
595 WMMoveWidget(pPtr, 8, 8);
596 WMSetProgressIndicatorValue(pPtr, 75);
598 WMRealizeWidget(win);
599 WMMapSubwidgets(win);
600 WMMapWidget(win);
605 void
606 testPullDown(WMScreen *scr)
608 WMWindow *win;
609 WMPopUpButton *pop, *pop2;
611 windowCount++;
613 win = WMCreateWindow(scr, "pullDown");
614 WMResizeWidget(win, 400, 300);
616 WMSetWindowCloseAction(win, closeAction, NULL);
618 pop = WMCreatePopUpButton(win);
619 WMResizeWidget(pop, 100, 20);
620 WMMoveWidget(pop, 50, 60);
621 WMSetPopUpButtonPullsDown(pop, True);
622 WMSetPopUpButtonText(pop, "Commands");
623 WMAddPopUpButtonItem(pop, "Add");
624 WMAddPopUpButtonItem(pop, "Remove");
625 WMAddPopUpButtonItem(pop, "Check");
626 WMAddPopUpButtonItem(pop, "Eat");
628 pop2 = WMCreatePopUpButton(win);
629 WMResizeWidget(pop2, 100, 20);
630 WMMoveWidget(pop2, 200, 60);
631 WMSetPopUpButtonText(pop2, "Select");
632 WMAddPopUpButtonItem(pop2, "Apples");
633 WMAddPopUpButtonItem(pop2, "Bananas");
634 WMAddPopUpButtonItem(pop2, "Strawberries");
635 WMAddPopUpButtonItem(pop2, "Blueberries");
637 WMRealizeWidget(win);
638 WMMapSubwidgets(win);
639 WMMapWidget(win);
644 void
645 testTabView(WMScreen *scr)
647 WMWindow *win;
648 WMTabView *tabv;
649 WMTabViewItem *tab;
650 WMFrame *frame;
651 WMLabel *label;
653 windowCount++;
655 win = WMCreateWindow(scr, "testTabs");
656 WMResizeWidget(win, 400, 300);
658 WMSetWindowCloseAction(win, closeAction, NULL);
660 tabv = WMCreateTabView(win);
661 WMMoveWidget(tabv, 50, 50);
662 WMResizeWidget(tabv, 300, 200);
664 frame = WMCreateFrame(win);
665 WMSetFrameRelief(frame, WRFlat);
666 label = WMCreateLabel(frame);
667 WMResizeWidget(label, 100, 100);
668 WMSetLabelText(label, "Label 1");
669 WMMapWidget(label);
672 tab = WMCreateTabViewItemWithIdentifier(0);
673 WMSetTabViewItemView(tab, WMWidgetView(frame));
674 WMAddItemInTabView(tabv, tab);
675 WMSetTabViewItemLabel(tab, "Instances");
677 frame = WMCreateFrame(win);
678 WMSetFrameRelief(frame, WRFlat);
679 label = WMCreateLabel(frame);
680 WMResizeWidget(label, 40, 50);
681 WMSetLabelText(label, "Label 2");
682 WMMapWidget(label);
685 tab = WMCreateTabViewItemWithIdentifier(0);
686 WMSetTabViewItemView(tab, WMWidgetView(frame));
687 WMAddItemInTabView(tabv, tab);
688 WMSetTabViewItemLabel(tab, "Classes");
691 frame = WMCreateFrame(win);
692 WMSetFrameRelief(frame, WRFlat);
693 label = WMCreateLabel(frame);
694 WMResizeWidget(label, 100, 100);
695 WMMoveWidget(label, 60, 40);
696 WMSetLabelText(label, "Label 3");
697 WMMapWidget(label);
699 tab = WMCreateTabViewItemWithIdentifier(0);
700 WMSetTabViewItemView(tab, WMWidgetView(frame));
701 WMAddItemInTabView(tabv, tab);
702 WMSetTabViewItemLabel(tab, "Something");
705 frame = WMCreateFrame(win);
706 WMSetFrameRelief(frame, WRFlat);
707 label = WMCreateLabel(frame);
708 WMResizeWidget(label, 100, 100);
709 WMMoveWidget(label, 160, 40);
710 WMSetLabelText(label, "Label 4");
711 WMMapWidget(label);
713 tab = WMCreateTabViewItemWithIdentifier(0);
714 WMSetTabViewItemView(tab, WMWidgetView(frame));
715 WMAddItemInTabView(tabv, tab);
716 WMSetTabViewItemLabel(tab, "Bla!");
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 fjweqklrj qwl");
726 WMMapWidget(label);
727 tab = WMCreateTabViewItemWithIdentifier(0);
728 WMSetTabViewItemView(tab, WMWidgetView(frame));
729 WMAddItemInTabView(tabv, tab);
730 WMSetTabViewItemLabel(tab, "Weee!");
733 WMRealizeWidget(win);
734 WMMapSubwidgets(win);
735 WMMapWidget(win);
739 void
740 splitViewConstrainProc(WMSplitView *sPtr, int indView,
741 int *minSize, int *maxSize)
743 switch (indView) {
744 case 0:
745 *minSize = 20;
746 break;
747 case 1:
748 *minSize = 40;
749 *maxSize = 80;
750 break;
751 case 2:
752 *maxSize = 60;
753 break;
754 default:
755 break;
760 static void
761 resizeSplitView(XEvent *event, void *data)
763 WMSplitView *sPtr = (WMSplitView*)data;
765 if (event->type == ConfigureNotify) {
766 int width = event->xconfigure.width - 10;
768 if (width < WMGetSplitViewDividerThickness(sPtr))
769 width = WMGetSplitViewDividerThickness(sPtr);
771 if (width != WMWidgetWidth(sPtr) ||
772 event->xconfigure.height != WMWidgetHeight(sPtr))
773 WMResizeWidget(sPtr, width, event->xconfigure.height - 55);
777 void
778 appendSubviewButtonAction(WMWidget *self, void *data)
780 WMSplitView *sPtr = (WMSplitView*)data;
781 char buf[64];
782 WMLabel *label = WMCreateLabel(sPtr);
784 sprintf(buf, "Subview %d", WMGetSplitViewSubviewsCount(sPtr) + 1);
785 WMSetLabelText(label, buf);
786 WMSetLabelRelief(label, WRSunken);
787 WMAddSplitViewSubview(sPtr, WMWidgetView(label));
788 WMRealizeWidget(label);
789 WMMapWidget(label);
792 void
793 removeSubviewButtonAction(WMWidget *self, void *data)
795 WMSplitView *sPtr = (WMSplitView*)data;
796 int count = WMGetSplitViewSubviewsCount(sPtr);
798 if (count > 2) {
799 WMView *view = WMGetSplitViewSubviewAt(sPtr, count-1);
800 WMDestroyWidget(WMWidgetOfView(view));
801 WMRemoveSplitViewSubviewAt(sPtr, count-1);
805 void
806 orientationButtonAction(WMWidget *self, void *data)
808 WMSplitView *sPtr = (WMSplitView*)data;
809 WMSetSplitViewVertical(sPtr, !WMGetSplitViewVertical(sPtr));
812 void
813 adjustSubviewsButtonAction(WMWidget *self, void *data)
815 WMAdjustSplitViewSubviews((WMSplitView*)data);
818 void
819 testSplitView(WMScreen *scr)
821 WMWindow *win;
822 WMSplitView *splitv1, *splitv2;
823 WMFrame *frame;
824 WMLabel *label;
825 WMButton *button;
827 windowCount++;
829 win = WMCreateWindow(scr, "testTabs");
830 WMResizeWidget(win, 300, 400);
831 WMSetWindowCloseAction(win, closeAction, NULL);
833 frame = WMCreateFrame(win);
834 WMSetFrameRelief(frame, WRSunken);
835 WMMoveWidget(frame, 5, 5);
836 WMResizeWidget(frame, 290, 40);
838 splitv1 = WMCreateSplitView(win);
839 WMMoveWidget(splitv1, 5, 50);
840 WMResizeWidget(splitv1, 290, 345);
841 WMSetSplitViewConstrainProc(splitv1, splitViewConstrainProc);
842 WMCreateEventHandler(WMWidgetView(win), StructureNotifyMask,
843 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);
906 /*******************************************************************/
908 #include <sys/types.h>
909 #include <dirent.h>
910 #include <string.h>
913 typedef struct {
914 int x, y;
915 Bool mouseDown;
916 char *filename;
917 } DNDStuff;
919 WMPixmap*
920 getImage(WMScreen *scr, char *file)
922 char buffer[1000];
923 WMPixmap *pix;
925 sprintf(buffer, "../../WindowMaker/Icons/%s", file);
926 pix = WMCreatePixmapFromFile(scr, buffer);
928 return pix;
934 static void
935 iconMouseStuff(XEvent *event, void *cdata)
937 WMLabel *label = (WMLabel*)cdata;
938 DNDStuff *stuff = WMGetHangedData(label);
939 WMPoint where;
941 switch (event->type) {
942 case ButtonPress:
943 stuff->x = event->xbutton.x;
944 stuff->y = event->xbutton.y;
945 stuff->mouseDown = True;
946 break;
947 case ButtonRelease:
948 stuff->mouseDown = False;
949 break;
950 case MotionNotify:
951 if (!stuff->mouseDown)
952 break;
954 if (abs(stuff->x - event->xmotion.x)>4
955 || abs(stuff->y - event->xmotion.y)>4) {
957 where = WMGetViewScreenPosition(WMWidgetView(label));
959 WMDragImageFromView(WMWidgetView(label),
960 WMGetLabelImage(label),
961 NULL, /* XXX */
962 where,
963 wmksize(stuff->x, stuff->y),
964 event, True);
966 break;
971 static void
972 endedDragImage(WMView *self, WMPixmap *image, WMPoint point, Bool deposited)
974 DNDStuff *stuff = WMGetHangedData(WMWidgetOfView(self));
976 if (deposited) {
977 WMDestroyWidget(WMWidgetOfView(self));
980 stuff->mouseDown = False;
984 static WMData*
985 fetchDragData(WMView *self, char *type)
987 DNDStuff *stuff = WMGetHangedData(WMWidgetOfView(self));
989 return WMCreateDataWithBytes(stuff->filename, strlen(stuff->filename)+1);
993 WMDragSourceProcs dragSourceProcs = {
994 NULL,
995 NULL,
996 endedDragImage,
997 fetchDragData
1001 /************************/
1004 unsigned
1005 draggingEntered(WMView *self, WMDraggingInfo *info)
1007 return WDOperationCopy;
1011 unsigned
1012 draggingUpdated(WMView *self, WMDraggingInfo *info)
1014 return WDOperationCopy;
1018 void (*draggingExited)(WMView *self, WMDraggingInfo *info);
1020 char*
1021 prepareForDragOperation(WMView *self, WMDraggingInfo *info)
1023 return "application/X-WINGs-Bla";
1027 WMLabel* makeDraggableLabel(WMWidget *w, char *file, int x, int y);
1029 Bool
1030 performDragOperation(WMView *self, WMDraggingInfo *info, WMData *data)
1032 char *file = (char*)WMDataBytes(data);
1033 WMPoint pos;
1035 pos = WMGetDraggingInfoImageLocation(info);
1037 if (file!=NULL) {
1038 WMLabel *label;
1039 WMPoint pos2 = WMGetViewScreenPosition(self);
1042 label = makeDraggableLabel(WMWidgetOfView(self), file,
1043 pos.x-pos2.x, pos.y-pos2.y);
1044 WMRealizeWidget(label);
1045 WMMapWidget(label);
1049 return True;
1053 void
1054 concludeDragOperation(WMView *self, WMDraggingInfo *info)
1061 WMDragDestinationProcs dragDestProcs = {
1062 draggingEntered,
1063 draggingUpdated,
1064 NULL,
1065 prepareForDragOperation,
1066 performDragOperation,
1067 concludeDragOperation
1073 WMLabel*
1074 makeDraggableLabel(WMWidget *w, char *file, int x, int y)
1076 DNDStuff *stuff;
1077 WMLabel *label;
1078 WMPixmap *image = getImage(WMWidgetScreen(w), file);
1080 stuff = wmalloc(sizeof(DNDStuff));
1081 stuff->mouseDown = False;
1083 stuff->filename = wstrdup(file);
1085 label = WMCreateLabel(w);
1086 WMResizeWidget(label, 48, 48);
1087 WMMoveWidget(label, x, y);
1089 WMSetViewDragSourceProcs(WMWidgetView(label), &dragSourceProcs);
1091 WMHangData(label, stuff);
1093 WMCreateEventHandler(WMWidgetView(label),
1094 ButtonPressMask|ButtonReleaseMask|ButtonMotionMask,
1095 iconMouseStuff, label);
1098 if (image != NULL) {
1099 WMSetLabelImagePosition(label, WIPImageOnly);
1100 WMSetLabelImage(label, image);
1101 WMReleasePixmap(image);
1102 } else puts(file);
1104 return label;
1109 void
1110 testDragAndDrop(WMScreen *scr)
1112 WMWindow *win;
1113 WMFrame *frame;
1114 WMLabel *label;
1115 int i, j;
1116 DIR *dir;
1117 struct dirent *ent;
1118 char *types[] = {
1119 "application/X-WINGs-Bla",
1120 NULL
1123 windowCount++;
1125 win = WMCreateWindow(scr, "dragDrop");
1126 WMResizeWidget(win, 300, 300);
1127 WMSetWindowCloseAction(win, closeAction, NULL);
1128 WMSetWindowTitle(win, "Drag and Drop");
1131 frame = WMCreateFrame(win);
1132 WMSetFrameRelief(frame, WRSunken);
1133 WMResizeWidget(frame, 250, 250);
1134 WMMoveWidget(frame, 25, 25);
1136 WMRegisterViewForDraggedTypes(WMWidgetView(frame), types);
1137 WMSetViewDragDestinationProcs(WMWidgetView(frame), &dragDestProcs);
1139 dir = opendir("../../WindowMaker/Icons");
1140 if (!dir) {
1141 perror("../../WindowMaker/Icons");
1142 return;
1145 for (i = 0, j=0; j < 8; i++) {
1146 ent = readdir(dir);
1147 if (!ent)
1148 break;
1150 if (strstr(ent->d_name, ".xpm")==NULL) {
1151 continue;
1154 label = makeDraggableLabel(frame, ent->d_name,4+(j/4)*64, 4+(j%4)*64);
1156 j++;
1159 closedir(dir);
1161 WMMapSubwidgets(frame);
1163 WMMapSubwidgets(win);
1164 WMRealizeWidget(win);
1165 WMMapWidget(win);
1172 /*******************************************************************/
1174 #include "WUtil.h"
1176 void
1177 testUD()
1179 WMUserDefaults *defs;
1180 char str[32];
1182 defs = WMGetStandardUserDefaults();
1184 sprintf(str, "TEST DATA");
1185 puts(str);
1186 WMSetUDStringForKey(defs, str, "testKey");
1187 puts(str);
1192 main(int argc, char **argv)
1194 WMScreen *scr;
1195 WMPixmap *pixmap;
1198 /* Initialize the application */
1199 WMInitializeApplication("Test", &argc, argv);
1201 testUD();
1204 * Open connection to the X display.
1206 dpy = XOpenDisplay("");
1208 if (!dpy) {
1209 puts("could not open display");
1210 exit(1);
1213 /* This is used to disable buffering of X protocol requests.
1214 * Do NOT use it unless when debugging. It will cause a major
1215 * slowdown in your application
1217 #if 1
1218 XSynchronize(dpy, True);
1219 #endif
1221 * Create screen descriptor.
1223 scr = WMCreateScreen(dpy, DefaultScreen(dpy));
1226 * Loads the logo of the application.
1228 pixmap = WMCreatePixmapFromFile(scr, "logo.xpm");
1231 * Makes the logo be used in standard dialog panels.
1233 WMSetApplicationIconImage(scr, pixmap); WMReleasePixmap(pixmap);
1236 * Do some test stuff.
1238 * Put the testSomething() function you want to test here.
1241 testBox(scr);
1242 #if 0
1243 testList(scr);
1245 testProgressIndicator(scr);
1247 testColorWell(scr);
1249 testTextField(scr);
1250 testText(scr);
1252 testDragAndDrop(scr);
1253 testDragAndDrop(scr);
1254 testFontPanel(scr);
1256 testScrollView(scr);
1257 testButton(scr);
1259 testFrame(scr);
1262 testTabView(scr);
1266 testSplitView(scr);
1268 testGradientButtons(scr);
1271 testOpenFilePanel(scr);
1273 testSlider(scr);
1274 testPullDown(scr);
1275 #endif
1277 * The main event loop.
1280 WMScreenMainLoop(scr);
1282 return 0;