Fixed some // style comments
[wmaker-crm.git] / WINGs / Tests / wtest.c
blob5b283af9c151a418d63bd21eac7d08e02e49027b
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 static void
119 singleClick(WMWidget *self, void *data)
124 static void
125 doubleClick(WMWidget *self, void *data)
127 WMLabel *label = (WMLabel*)data;
128 WMList *lPtr = (WMList*)self;
129 char buf[255];
131 WMSelectAllListItems(lPtr);
135 static void
136 listSelectionObserver(void *observer, WMNotification *notification)
138 WMLabel *label = (WMLabel*)observer;
139 WMList *lPtr = (WMList*)WMGetNotificationObject(notification);
140 char buf[255];
142 sprintf(buf, "Selected items: %d",
143 WMGetArrayItemCount(WMGetListSelectedItems(lPtr)));
144 WMSetLabelText(label, buf);
148 void
149 testList(WMScreen *scr)
151 WMWindow *win;
152 WMList *list;
153 WMList *mlist;
154 WMLabel *label;
155 WMLabel *mlabel;
156 WMLabel *title;
157 WMLabel *mtitle;
158 char text[100];
159 int i;
161 windowCount++;
163 win = WMCreateWindow(scr, "testList");
164 WMResizeWidget(win, 370, 250);
165 WMSetWindowTitle(win, "List");
166 WMSetWindowCloseAction(win, closeAction, NULL);
168 title = WMCreateLabel(win);
169 WMResizeWidget(title, 150, 20);
170 WMMoveWidget(title, 10, 10);
171 WMSetLabelRelief(title, WRRidge);
172 WMSetLabelText(title, "Single selection list");
174 mtitle = WMCreateLabel(win);
175 WMResizeWidget(mtitle, 150, 20);
176 WMMoveWidget(mtitle, 210, 10);
177 WMSetLabelRelief(mtitle, WRRidge);
178 WMSetLabelText(mtitle, "Multiple selection list");
180 list = WMCreateList(win);
181 /*WMSetListAllowEmptySelection(list, True);*/
182 WMMoveWidget(list, 10, 40);
183 for (i=0; i<50; i++) {
184 sprintf(text, "Item %i", i);
185 WMAddListItem(list, text);
187 mlist = WMCreateList(win);
188 WMSetListAllowMultipleSelection(mlist, True);
189 /*WMSetListAllowEmptySelection(mlist, True);*/
190 WMMoveWidget(mlist, 210, 40);
191 for (i=0; i<135; i++) {
192 sprintf(text, "Item %i", i);
193 WMAddListItem(mlist, text);
196 label = WMCreateLabel(win);
197 WMResizeWidget(label, 150, 40);
198 WMMoveWidget(label, 10, 200);
199 WMSetLabelRelief(label, WRRidge);
200 WMSetLabelText(label, "Selected items: 0");
202 mlabel = WMCreateLabel(win);
203 WMResizeWidget(mlabel, 150, 40);
204 WMMoveWidget(mlabel, 210, 200);
205 WMSetLabelRelief(mlabel, WRRidge);
206 WMSetLabelText(mlabel, "Selected items: 0");
208 WMSetListAction(list, singleClick, label);
209 WMSetListDoubleAction(list, doubleClick, label);
210 WMSetListAction(mlist, singleClick, mlabel);
211 WMSetListDoubleAction(mlist, doubleClick, mlabel);
213 WMAddNotificationObserver(listSelectionObserver, label,
214 WMListSelectionDidChangeNotification, list);
215 WMAddNotificationObserver(listSelectionObserver, mlabel,
216 WMListSelectionDidChangeNotification, mlist);
219 WMRealizeWidget(win);
220 WMMapSubwidgets(win);
221 WMMapWidget(win);
225 void
226 testButton(WMScreen *scr)
228 WMWindow *win;
229 int i;
230 char *types[] = {
231 "MomentaryPush",
232 "PushOnPushOff",
233 "Toggle",
234 "Switch",
235 "Radio",
236 "MomentaryChange",
237 "OnOff",
238 "MomentaryLigh"
241 windowCount++;
243 win = WMCreateWindow(scr, "testButton");
244 WMResizeWidget(win, 300, 300);
245 WMSetWindowTitle(win, "Buttons");
247 WMSetWindowCloseAction(win, closeAction, NULL);
249 for (i = 1; i < 9; i++) {
250 WMButton *b;
251 b = WMCreateButton(win, i);
252 WMResizeWidget(b, 150, 24);
253 WMMoveWidget(b, 20, i*30);
254 WMSetButtonText(b, types[i-1]);
257 WMRealizeWidget(win);
258 WMMapSubwidgets(win);
259 WMMapWidget(win);
263 void
264 testGradientButtons(WMScreen *scr)
266 WMWindow *win;
267 WMButton *btn;
268 WMPixmap *pix1, *pix2;
269 RImage *back;
270 RColor light, dark;
271 WMColor *color, *altColor;
273 windowCount++;
275 /* creates the top-level window */
276 win = WMCreateWindow(scr, "testGradientButtons");
277 WMSetWindowTitle(win, "Gradiented Button Demo");
278 WMResizeWidget(win, 300, 200);
280 light.red = 0x90;
281 light.green = 0x85;
282 light.blue = 0x90;
283 dark.red = 0x35;
284 dark.green = 0x30;
285 dark.blue = 0x35;
287 color = WMCreateRGBColor(scr, 0x5900, 0x5100, 0x5900, True);
288 WMSetWidgetBackgroundColor(win, color);
289 WMReleaseColor(color);
291 back = RRenderGradient(60, 24, &dark, &light, RGRD_DIAGONAL);
292 RBevelImage(back, RBEV_RAISED2);
293 pix1 = WMCreatePixmapFromRImage(scr, back, 0);
294 RDestroyImage(back);
296 back = RRenderGradient(60, 24, &dark, &light, RGRD_DIAGONAL);
297 RBevelImage(back, RBEV_SUNKEN);
298 pix2 = WMCreatePixmapFromRImage(scr, back, 0);
299 RDestroyImage(back);
301 color = WMWhiteColor(scr);
302 altColor = WMCreateNamedColor(scr, "red", True);
304 btn = WMCreateButton(win, WBTMomentaryChange);
305 WMResizeWidget(btn, 60, 24);
306 WMMoveWidget(btn, 20, 100);
307 WMSetButtonBordered(btn, False);
308 WMSetButtonImagePosition(btn, WIPOverlaps);
309 WMSetButtonImage(btn, pix1);
310 WMSetButtonAltImage(btn, pix2);
311 WMSetButtonText(btn, "Cool");
312 WMSetButtonTextColor(btn, color);
313 WMSetButtonAltTextColor(btn, altColor);
315 WMSetBalloonTextForView("This is a cool button", WMWidgetView(btn));
317 btn = WMCreateButton(win, WBTMomentaryChange);
318 WMResizeWidget(btn, 60, 24);
319 WMMoveWidget(btn, 90, 100);
320 WMSetButtonBordered(btn, False);
321 WMSetButtonImagePosition(btn, WIPOverlaps);
322 WMSetButtonImage(btn, pix1);
323 WMSetButtonAltImage(btn, pix2);
324 WMSetButtonText(btn, "Button");
325 WMSetButtonTextColor(btn, color);
327 WMSetBalloonTextForView("Este é outro balão.", WMWidgetView(btn));
329 WMReleaseColor(color);
330 color = WMCreateNamedColor(scr, "orange", True);
332 btn = WMCreateButton(win, WBTMomentaryChange);
333 WMResizeWidget(btn, 60, 24);
334 WMMoveWidget(btn, 160, 100);
335 WMSetButtonBordered(btn, False);
336 WMSetButtonImagePosition(btn, WIPOverlaps);
337 WMSetButtonImage(btn, pix1);
338 WMSetButtonAltImage(btn, pix2);
339 WMSetButtonText(btn, "Test");
340 WMSetButtonTextColor(btn, color);
342 WMSetBalloonTextForView("This is yet another button.\nBut the balloon has 3 lines.\nYay!",
343 WMWidgetView(btn));
345 WMReleaseColor(color);
346 WMReleaseColor(altColor);
348 WMRealizeWidget(win);
349 WMMapSubwidgets(win);
350 WMMapWidget(win);
354 void
355 testScrollView(WMScreen *scr)
357 WMWindow *win;
358 WMScrollView *sview;
359 WMFrame *f;
360 WMLabel *l;
361 char buffer[128];
362 int i;
364 windowCount++;
366 /* creates the top-level window */
367 win = WMCreateWindow(scr, "testScroll");
368 WMSetWindowTitle(win, "Scrollable View");
370 WMSetWindowCloseAction(win, closeAction, NULL);
372 /* set the window size */
373 WMResizeWidget(win, 300, 300);
375 /* creates a scrollable view inside the top-level window */
376 sview = WMCreateScrollView(win);
377 WMResizeWidget(sview, 200, 200);
378 WMMoveWidget(sview, 30, 30);
379 WMSetScrollViewRelief(sview, WRSunken);
380 WMSetScrollViewHasVerticalScroller(sview, True);
381 WMSetScrollViewHasHorizontalScroller(sview, True);
383 /* create a frame with a bunch of labels */
384 f = WMCreateFrame(win);
385 WMResizeWidget(f, 400, 400);
386 WMSetFrameRelief(f, WRFlat);
388 for (i=0; i<20; i++) {
389 l = WMCreateLabel(f);
390 WMResizeWidget(l, 50, 18);
391 WMMoveWidget(l, 10, 20*i);
392 sprintf(buffer, "Label %i", i);
393 WMSetLabelText(l, buffer);
394 WMSetLabelRelief(l, WRSimple);
396 WMMapSubwidgets(f);
397 WMMapWidget(f);
399 WMSetScrollViewContentView(sview, WMWidgetView(f));
401 /* make the windows of the widgets be actually created */
402 WMRealizeWidget(win);
404 /* Map all child widgets of the top-level be mapped.
405 * You must call this for each container widget (like frames),
406 * even if they are childs of the top-level window.
408 WMMapSubwidgets(win);
410 /* map the top-level window */
411 WMMapWidget(win);
415 void
416 testColorWell(WMScreen *scr)
418 WMWindow *win;
419 WMColorWell *well1, *well2;
421 windowCount++;
423 win = WMCreateWindow(scr, "testColor");
424 WMResizeWidget(win, 300, 300);
425 WMSetWindowCloseAction(win, closeAction, NULL);
427 well1 = WMCreateColorWell(win);
428 WMResizeWidget(well1, 60, 40);
429 WMMoveWidget(well1, 100, 100);
430 WMSetColorWellColor(well1, WMCreateRGBColor(scr, 0x8888, 0, 0x1111, True));
431 well2 = WMCreateColorWell(win);
432 WMResizeWidget(well2, 60, 40);
433 WMMoveWidget(well2, 200, 100);
434 WMSetColorWellColor(well2, WMCreateRGBColor(scr, 0, 0, 0x8888, True));
436 WMRealizeWidget(win);
437 WMMapSubwidgets(win);
438 WMMapWidget(win);
441 void
442 sliderCallback(WMWidget *w, void *data)
444 printf("SLIDER == %i\n", WMGetSliderValue(w));
448 void
449 testSlider(WMScreen *scr)
451 WMWindow *win;
452 WMSlider *s;
454 windowCount++;
456 win = WMCreateWindow(scr, "testSlider");
457 WMResizeWidget(win, 300, 300);
458 WMSetWindowTitle(win, "Sliders");
460 WMSetWindowCloseAction(win, closeAction, NULL);
462 s = WMCreateSlider(win);
463 WMResizeWidget(s, 16, 100);
464 WMMoveWidget(s, 100, 100);
465 WMSetSliderKnobThickness(s, 8);
466 WMSetSliderContinuous(s, False);
467 WMSetSliderAction(s, sliderCallback, s);
469 s = WMCreateSlider(win);
470 WMResizeWidget(s, 100, 16);
471 WMMoveWidget(s, 100, 10);
472 WMSetSliderKnobThickness(s, 8);
474 WMRealizeWidget(win);
475 WMMapSubwidgets(win);
476 WMMapWidget(win);
479 void
480 testTextField(WMScreen *scr)
482 WMWindow *win;
483 WMTextField *field, *field2;
485 windowCount++;
487 win = WMCreateWindow(scr, "testTextField");
488 WMResizeWidget(win, 400, 300);
490 WMSetWindowCloseAction(win, closeAction, NULL);
492 field = WMCreateTextField(win);
493 WMResizeWidget(field, 200, 20);
494 WMMoveWidget(field, 20, 20);
496 field2 = WMCreateTextField(win);
497 WMResizeWidget(field2, 200, 20);
498 WMMoveWidget(field2, 20, 50);
499 WMSetTextFieldAlignment(field2, WARight);
501 WMRealizeWidget(win);
502 WMMapSubwidgets(win);
503 WMMapWidget(win);
508 void
509 testText(WMScreen *scr)
511 WMWindow *win;
512 WMText *text;
513 FILE *file = fopen("../README", "r");
515 windowCount++;
517 win = WMCreateWindow(scr, "testText");
518 WMResizeWidget(win, 500, 300);
520 WMSetWindowCloseAction(win, closeAction, NULL);
522 text = WMCreateText(win);
523 WMResizeWidget(text, 480, 280);
524 WMMoveWidget(text, 10, 10);
525 WMSetTextHasVerticalScroller(text, True);
526 WMSetTextEditable(text, False);
528 if(file) {
529 char buf[1024];
531 WMFreezeText(text);
532 while(fgets(buf, 1023, file))
533 WMAppendTextStream(text, buf);
535 fclose(file);
536 WMThawText(text);
537 } else {
538 WMAppendTextStream(text, "<HTML><i>Where's</i> the <b>README</b>?");
541 WMRealizeWidget(win);
542 WMMapSubwidgets(win);
543 WMMapWidget(win);
547 void
548 testProgressIndicator(WMScreen *scr)
550 WMWindow *win;
551 WMProgressIndicator *pPtr;
553 windowCount++;
555 win = WMCreateWindow(scr, "testProgressIndicator");
556 WMResizeWidget(win, 292, 32);
558 WMSetWindowCloseAction(win, closeAction, NULL);
560 pPtr = WMCreateProgressIndicator(win);
561 WMMoveWidget(pPtr, 8, 8);
562 WMSetProgressIndicatorValue(pPtr, 75);
564 WMRealizeWidget(win);
565 WMMapSubwidgets(win);
566 WMMapWidget(win);
571 void
572 testPullDown(WMScreen *scr)
574 WMWindow *win;
575 WMPopUpButton *pop, *pop2;
577 windowCount++;
579 win = WMCreateWindow(scr, "pullDown");
580 WMResizeWidget(win, 400, 300);
582 WMSetWindowCloseAction(win, closeAction, NULL);
584 pop = WMCreatePopUpButton(win);
585 WMResizeWidget(pop, 100, 20);
586 WMMoveWidget(pop, 50, 60);
587 WMSetPopUpButtonPullsDown(pop, True);
588 WMSetPopUpButtonText(pop, "Commands");
589 WMAddPopUpButtonItem(pop, "Add");
590 WMAddPopUpButtonItem(pop, "Remove");
591 WMAddPopUpButtonItem(pop, "Check");
592 WMAddPopUpButtonItem(pop, "Eat");
594 pop2 = WMCreatePopUpButton(win);
595 WMResizeWidget(pop2, 100, 20);
596 WMMoveWidget(pop2, 200, 60);
597 WMSetPopUpButtonText(pop2, "Select");
598 WMAddPopUpButtonItem(pop2, "Apples");
599 WMAddPopUpButtonItem(pop2, "Bananas");
600 WMAddPopUpButtonItem(pop2, "Strawberries");
601 WMAddPopUpButtonItem(pop2, "Blueberries");
603 WMRealizeWidget(win);
604 WMMapSubwidgets(win);
605 WMMapWidget(win);
610 void
611 testTabView(WMScreen *scr)
613 WMWindow *win;
614 WMTabView *tabv;
615 WMTabViewItem *tab;
616 WMFrame *frame;
617 WMLabel *label;
619 windowCount++;
621 win = WMCreateWindow(scr, "testTabs");
622 WMResizeWidget(win, 400, 300);
624 WMSetWindowCloseAction(win, closeAction, NULL);
626 tabv = WMCreateTabView(win);
627 WMMoveWidget(tabv, 50, 50);
628 WMResizeWidget(tabv, 300, 200);
630 frame = WMCreateFrame(win);
631 WMSetFrameRelief(frame, WRFlat);
632 label = WMCreateLabel(frame);
633 WMResizeWidget(label, 100, 100);
634 WMSetLabelText(label, "Label 1");
635 WMMapWidget(label);
638 tab = WMCreateTabViewItemWithIdentifier(0);
639 WMSetTabViewItemView(tab, WMWidgetView(frame));
640 WMAddItemInTabView(tabv, tab);
641 WMSetTabViewItemLabel(tab, "Instances");
643 frame = WMCreateFrame(win);
644 WMSetFrameRelief(frame, WRFlat);
645 label = WMCreateLabel(frame);
646 WMResizeWidget(label, 40, 50);
647 WMSetLabelText(label, "Label 2");
648 WMMapWidget(label);
651 tab = WMCreateTabViewItemWithIdentifier(0);
652 WMSetTabViewItemView(tab, WMWidgetView(frame));
653 WMAddItemInTabView(tabv, tab);
654 WMSetTabViewItemLabel(tab, "Classes");
657 frame = WMCreateFrame(win);
658 WMSetFrameRelief(frame, WRFlat);
659 label = WMCreateLabel(frame);
660 WMResizeWidget(label, 100, 100);
661 WMMoveWidget(label, 60, 40);
662 WMSetLabelText(label, "Label 3");
663 WMMapWidget(label);
665 tab = WMCreateTabViewItemWithIdentifier(0);
666 WMSetTabViewItemView(tab, WMWidgetView(frame));
667 WMAddItemInTabView(tabv, tab);
668 WMSetTabViewItemLabel(tab, "Something");
671 frame = WMCreateFrame(win);
672 WMSetFrameRelief(frame, WRFlat);
673 label = WMCreateLabel(frame);
674 WMResizeWidget(label, 100, 100);
675 WMMoveWidget(label, 160, 40);
676 WMSetLabelText(label, "Label 4");
677 WMMapWidget(label);
679 tab = WMCreateTabViewItemWithIdentifier(0);
680 WMSetTabViewItemView(tab, WMWidgetView(frame));
681 WMAddItemInTabView(tabv, tab);
682 WMSetTabViewItemLabel(tab, "Bla!");
686 frame = WMCreateFrame(win);
687 WMSetFrameRelief(frame, WRFlat);
688 label = WMCreateLabel(frame);
689 WMResizeWidget(label, 100, 100);
690 WMMoveWidget(label, 160, 40);
691 WMSetLabelText(label, "Label fjweqklrj qwl");
692 WMMapWidget(label);
693 tab = WMCreateTabViewItemWithIdentifier(0);
694 WMSetTabViewItemView(tab, WMWidgetView(frame));
695 WMAddItemInTabView(tabv, tab);
696 WMSetTabViewItemLabel(tab, "Weee!");
699 WMRealizeWidget(win);
700 WMMapSubwidgets(win);
701 WMMapWidget(win);
705 void
706 splitViewConstrainProc(WMSplitView *sPtr, int indView,
707 int *minSize, int *maxSize)
709 switch (indView) {
710 case 0:
711 *minSize = 20;
712 break;
713 case 1:
714 *minSize = 40;
715 *maxSize = 80;
716 break;
717 case 2:
718 *maxSize = 60;
719 break;
720 default:
721 break;
726 static void
727 resizeSplitView(XEvent *event, void *data)
729 WMSplitView *sPtr = (WMSplitView*)data;
731 if (event->type == ConfigureNotify) {
732 int width = event->xconfigure.width - 10;
734 if (width < WMGetSplitViewDividerThickness(sPtr))
735 width = WMGetSplitViewDividerThickness(sPtr);
737 if (width != WMWidgetWidth(sPtr) ||
738 event->xconfigure.height != WMWidgetHeight(sPtr))
739 WMResizeWidget(sPtr, width, event->xconfigure.height - 55);
743 void
744 appendSubviewButtonAction(WMWidget *self, void *data)
746 WMSplitView *sPtr = (WMSplitView*)data;
747 char buf[64];
748 WMLabel *label = WMCreateLabel(sPtr);
750 sprintf(buf, "Subview %d", WMGetSplitViewSubviewsCount(sPtr) + 1);
751 WMSetLabelText(label, buf);
752 WMSetLabelRelief(label, WRSunken);
753 WMAddSplitViewSubview(sPtr, WMWidgetView(label));
754 WMRealizeWidget(label);
755 WMMapWidget(label);
758 void
759 removeSubviewButtonAction(WMWidget *self, void *data)
761 WMSplitView *sPtr = (WMSplitView*)data;
762 int count = WMGetSplitViewSubviewsCount(sPtr);
764 if (count > 2) {
765 WMView *view = WMGetSplitViewSubviewAt(sPtr, count-1);
766 WMDestroyWidget(WMWidgetOfView(view));
767 WMRemoveSplitViewSubviewAt(sPtr, count-1);
771 void
772 orientationButtonAction(WMWidget *self, void *data)
774 WMSplitView *sPtr = (WMSplitView*)data;
775 WMSetSplitViewVertical(sPtr, !WMGetSplitViewVertical(sPtr));
778 void
779 adjustSubviewsButtonAction(WMWidget *self, void *data)
781 WMAdjustSplitViewSubviews((WMSplitView*)data);
784 void
785 testSplitView(WMScreen *scr)
787 WMWindow *win;
788 WMSplitView *splitv1, *splitv2;
789 WMFrame *frame;
790 WMLabel *label;
791 WMButton *button;
793 windowCount++;
795 win = WMCreateWindow(scr, "testTabs");
796 WMResizeWidget(win, 300, 400);
797 WMSetWindowCloseAction(win, closeAction, NULL);
799 frame = WMCreateFrame(win);
800 WMSetFrameRelief(frame, WRSunken);
801 WMMoveWidget(frame, 5, 5);
802 WMResizeWidget(frame, 290, 40);
804 splitv1 = WMCreateSplitView(win);
805 WMMoveWidget(splitv1, 5, 50);
806 WMResizeWidget(splitv1, 290, 345);
807 WMSetSplitViewConstrainProc(splitv1, splitViewConstrainProc);
808 WMCreateEventHandler(WMWidgetView(win), StructureNotifyMask,
809 resizeSplitView, splitv1);
811 button = WMCreateCommandButton(frame);
812 WMSetButtonText(button, "+");
813 WMSetButtonAction(button, appendSubviewButtonAction, splitv1);
814 WMMoveWidget(button, 10, 8);
815 WMMapWidget(button);
817 button = WMCreateCommandButton(frame);
818 WMSetButtonText(button, "-");
819 WMSetButtonAction(button, removeSubviewButtonAction, splitv1);
820 WMMoveWidget(button, 80, 8);
821 WMMapWidget(button);
823 button = WMCreateCommandButton(frame);
824 WMSetButtonText(button, "=");
825 WMMoveWidget(button, 150, 8);
826 WMSetButtonAction(button, adjustSubviewsButtonAction, splitv1);
827 WMMapWidget(button);
829 button = WMCreateCommandButton(frame);
830 WMSetButtonText(button, "#");
831 WMMoveWidget(button, 220, 8);
832 WMSetButtonAction(button, orientationButtonAction, splitv1);
833 WMMapWidget(button);
835 label = WMCreateLabel(splitv1);
836 WMSetLabelText(label, "Subview 1");
837 WMSetLabelRelief(label, WRSunken);
838 WMMapWidget(label);
839 WMAddSplitViewSubview(splitv1, WMWidgetView(label));
841 splitv2 = WMCreateSplitView(splitv1);
842 WMResizeWidget(splitv2, 150, 150);
843 WMSetSplitViewVertical(splitv2, True);
845 label = WMCreateLabel(splitv2);
846 WMSetLabelText(label, "Subview 2.1");
847 WMSetLabelRelief(label, WRSunken);
848 WMMapWidget(label);
849 WMAddSplitViewSubview(splitv2, WMWidgetView(label));
851 label = WMCreateLabel(splitv2);
852 WMSetLabelText(label, "Subview 2.2");
853 WMSetLabelRelief(label, WRSunken);
854 WMMapWidget(label);
855 WMAddSplitViewSubview(splitv2, WMWidgetView(label));
857 label = WMCreateLabel(splitv2);
858 WMSetLabelText(label, "Subview 2.3");
859 WMSetLabelRelief(label, WRSunken);
860 WMMapWidget(label);
861 WMAddSplitViewSubview(splitv2, WMWidgetView(label));
863 WMMapWidget(splitv2);
864 WMAddSplitViewSubview(splitv1, WMWidgetView(splitv2));
866 WMRealizeWidget(win);
867 WMMapSubwidgets(win);
868 WMMapWidget(win);
872 /*******************************************************************/
874 #include <sys/types.h>
875 #include <dirent.h>
876 #include <string.h>
879 typedef struct {
880 int x, y;
881 Bool mouseDown;
882 char *filename;
883 } DNDStuff;
885 WMPixmap*
886 getImage(WMScreen *scr, char *file)
888 char buffer[1000];
889 WMPixmap *pix;
891 sprintf(buffer, "../../WindowMaker/Icons/%s", file);
892 pix = WMCreatePixmapFromFile(scr, buffer);
894 return pix;
900 static void
901 iconMouseStuff(XEvent *event, void *cdata)
903 WMLabel *label = (WMLabel*)cdata;
904 DNDStuff *stuff = WMGetHangedData(label);
905 WMPoint where;
907 switch (event->type) {
908 case ButtonPress:
909 stuff->x = event->xbutton.x;
910 stuff->y = event->xbutton.y;
911 stuff->mouseDown = True;
912 break;
913 case ButtonRelease:
914 stuff->mouseDown = False;
915 break;
916 case MotionNotify:
917 if (!stuff->mouseDown)
918 break;
920 if (abs(stuff->x - event->xmotion.x)>4
921 || abs(stuff->y - event->xmotion.y)>4) {
923 where = WMGetViewScreenPosition(WMWidgetView(label));
925 WMDragImageFromView(WMWidgetView(label),
926 WMGetLabelImage(label),
927 NULL, /* XXX */
928 where,
929 wmksize(stuff->x, stuff->y),
930 event, True);
932 break;
937 static void
938 endedDragImage(WMView *self, WMPixmap *image, WMPoint point, Bool deposited)
940 DNDStuff *stuff = WMGetHangedData(WMWidgetOfView(self));
942 if (deposited) {
943 WMDestroyWidget(WMWidgetOfView(self));
946 stuff->mouseDown = False;
950 static WMData*
951 fetchDragData(WMView *self, char *type)
953 DNDStuff *stuff = WMGetHangedData(WMWidgetOfView(self));
955 return WMCreateDataWithBytes(stuff->filename, strlen(stuff->filename)+1);
959 WMDragSourceProcs dragSourceProcs = {
960 NULL,
961 NULL,
962 endedDragImage,
963 fetchDragData
967 /************************/
970 unsigned
971 draggingEntered(WMView *self, WMDraggingInfo *info)
973 return WDOperationCopy;
977 unsigned
978 draggingUpdated(WMView *self, WMDraggingInfo *info)
980 return WDOperationCopy;
984 void (*draggingExited)(WMView *self, WMDraggingInfo *info);
986 char*
987 prepareForDragOperation(WMView *self, WMDraggingInfo *info)
989 return "application/X-WINGs-Bla";
993 WMLabel* makeDraggableLabel(WMWidget *w, char *file, int x, int y);
995 Bool
996 performDragOperation(WMView *self, WMDraggingInfo *info, WMData *data)
998 char *file = (char*)WMDataBytes(data);
999 WMPoint pos;
1001 pos = WMGetDraggingInfoImageLocation(info);
1003 if (file!=NULL) {
1004 WMLabel *label;
1005 WMPoint pos2 = WMGetViewScreenPosition(self);
1008 label = makeDraggableLabel(WMWidgetOfView(self), file,
1009 pos.x-pos2.x, pos.y-pos2.y);
1010 WMRealizeWidget(label);
1011 WMMapWidget(label);
1015 return True;
1019 void
1020 concludeDragOperation(WMView *self, WMDraggingInfo *info)
1027 WMDragDestinationProcs dragDestProcs = {
1028 draggingEntered,
1029 draggingUpdated,
1030 NULL,
1031 prepareForDragOperation,
1032 performDragOperation,
1033 concludeDragOperation
1039 WMLabel*
1040 makeDraggableLabel(WMWidget *w, char *file, int x, int y)
1042 DNDStuff *stuff;
1043 WMLabel *label;
1044 WMPixmap *image = getImage(WMWidgetScreen(w), file);
1046 stuff = wmalloc(sizeof(DNDStuff));
1047 stuff->mouseDown = False;
1049 stuff->filename = wstrdup(file);
1051 label = WMCreateLabel(w);
1052 WMResizeWidget(label, 48, 48);
1053 WMMoveWidget(label, x, y);
1055 WMSetViewDragSourceProcs(WMWidgetView(label), &dragSourceProcs);
1057 WMHangData(label, stuff);
1059 WMCreateEventHandler(WMWidgetView(label),
1060 ButtonPressMask|ButtonReleaseMask|ButtonMotionMask,
1061 iconMouseStuff, label);
1064 if (image != NULL) {
1065 WMSetLabelImagePosition(label, WIPImageOnly);
1066 WMSetLabelImage(label, image);
1067 WMReleasePixmap(image);
1068 } else puts(file);
1070 return label;
1075 void
1076 testDragAndDrop(WMScreen *scr)
1078 WMWindow *win;
1079 WMFrame *frame;
1080 WMLabel *label;
1081 int i, j;
1082 DIR *dir;
1083 struct dirent *ent;
1084 char *types[] = {
1085 "application/X-WINGs-Bla",
1086 NULL
1089 windowCount++;
1091 win = WMCreateWindow(scr, "dragDrop");
1092 WMResizeWidget(win, 300, 300);
1093 WMSetWindowCloseAction(win, closeAction, NULL);
1094 WMSetWindowTitle(win, "Drag and Drop");
1097 frame = WMCreateFrame(win);
1098 WMSetFrameRelief(frame, WRSunken);
1099 WMResizeWidget(frame, 250, 250);
1100 WMMoveWidget(frame, 25, 25);
1102 WMRegisterViewForDraggedTypes(WMWidgetView(frame), types);
1103 WMSetViewDragDestinationProcs(WMWidgetView(frame), &dragDestProcs);
1105 dir = opendir("../../WindowMaker/Icons");
1106 if (!dir) {
1107 perror("../../WindowMaker/Icons");
1108 return;
1111 for (i = 0, j=0; j < 8; i++) {
1112 ent = readdir(dir);
1113 if (!ent)
1114 break;
1116 if (strstr(ent->d_name, ".xpm")==NULL) {
1117 continue;
1120 label = makeDraggableLabel(frame, ent->d_name,4+(j/4)*64, 4+(j%4)*64);
1122 j++;
1125 closedir(dir);
1127 WMMapSubwidgets(frame);
1129 WMMapSubwidgets(win);
1130 WMRealizeWidget(win);
1131 WMMapWidget(win);
1138 /*******************************************************************/
1140 #include "WUtil.h"
1142 void
1143 testUD()
1145 WMUserDefaults *defs;
1146 char str[32];
1148 defs = WMGetStandardUserDefaults();
1150 sprintf(str, "TEST DATA");
1151 puts(str);
1152 WMSetUDStringForKey(defs, str, "testKey");
1153 puts(str);
1158 main(int argc, char **argv)
1160 WMScreen *scr;
1161 WMPixmap *pixmap;
1164 /* Initialize the application */
1165 WMInitializeApplication("Test", &argc, argv);
1167 testUD();
1170 * Open connection to the X display.
1172 dpy = XOpenDisplay("");
1174 if (!dpy) {
1175 puts("could not open display");
1176 exit(1);
1179 /* This is used to disable buffering of X protocol requests.
1180 * Do NOT use it unless when debugging. It will cause a major
1181 * slowdown in your application
1183 #if 1
1184 XSynchronize(dpy, True);
1185 #endif
1187 * Create screen descriptor.
1189 scr = WMCreateScreen(dpy, DefaultScreen(dpy));
1192 * Loads the logo of the application.
1194 pixmap = WMCreatePixmapFromFile(scr, "logo.xpm");
1197 * Makes the logo be used in standard dialog panels.
1199 WMSetApplicationIconImage(scr, pixmap); WMReleasePixmap(pixmap);
1202 * Do some test stuff.
1204 * Put the testSomething() function you want to test here.
1207 testList(scr);
1209 #if 0
1210 testColorWell(scr);
1212 testTextField(scr);
1213 testText(scr);
1215 testDragAndDrop(scr);
1216 testDragAndDrop(scr);
1217 testFontPanel(scr);
1219 testScrollView(scr);
1221 testButton(scr);
1223 testFrame(scr);
1226 testTabView(scr);
1230 testSplitView(scr);
1232 testGradientButtons(scr);
1233 testProgressIndicator(scr);
1236 testOpenFilePanel(scr);
1238 testSlider(scr);
1239 testPullDown(scr);
1240 #endif
1242 * The main event loop.
1245 WMScreenMainLoop(scr);
1247 return 0;