- Fixed some issues with WMBrowser and the file panel that were
[wmaker-crm.git] / WINGs / Tests / wtest.c
blob9886b95e1f33129924522b63bd8f84337269ee06
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 WMUnmapWidget(self);
33 WMDestroyWidget(self);
34 windowCount--;
35 printf("window closed, window count = %d\n", windowCount);
36 if (windowCount < 1)
37 exit(0);
41 void
42 testOpenFilePanel(WMScreen *scr)
44 WMOpenPanel *panel;
46 /* windowCount++; */
48 /* get the shared Open File panel */
49 panel = WMGetOpenPanel(scr);
51 WMRunModalFilePanelForDirectory(panel, NULL, "/usr/local", NULL, NULL);
53 /* free the panel to save some memory. Not needed otherwise. */
54 WMFreeFilePanel(WMGetOpenPanel(scr));
58 void
59 testFontPanel(WMScreen *scr)
61 WMFontPanel *panel;
63 /*windowCount++;*/
65 panel = WMGetFontPanel(scr);
67 WMShowFontPanel(panel);
69 /* WMFreeFontPanel(panel);*/
74 void
75 testFrame(WMScreen *scr)
77 WMWindow *win;
78 WMFrame *frame;
79 int i;
80 static char* titles[] = {
81 "AboveTop",
82 "AtTop",
83 "BelowTop",
84 "AboveBottom",
85 "AtBottom",
86 "BelowBottom"
88 static WMTitlePosition pos[] = {
89 WTPAboveTop,
90 WTPAtTop,
91 WTPBelowTop,
92 WTPAboveBottom,
93 WTPAtBottom,
94 WTPBelowBottom
97 windowCount++;
99 win = WMCreateWindow(scr, "testFrame");
100 WMSetWindowTitle(win, "Frame");
101 WMSetWindowCloseAction(win, closeAction, NULL);
102 WMResizeWidget(win, 400, 300);
104 for (i = 0; i < 6; i++) {
105 frame = WMCreateFrame(win);
106 WMMoveWidget(frame, 8+(i%3)*130, 8+(i/3)*130);
107 WMResizeWidget(frame, 120, 120);
108 WMSetFrameTitle(frame, titles[i]);
109 WMSetFrameTitlePosition(frame, pos[i]);
112 WMRealizeWidget(win);
113 WMMapSubwidgets(win);
114 WMMapWidget(win);
119 static void
120 singleClick(WMWidget *self, void *data)
125 static void
126 doubleClick(WMWidget *self, void *data)
128 WMLabel *label = (WMLabel*)data;
129 WMList *lPtr = (WMList*)self;
130 char buf[255];
132 WMSelectAllListItems(lPtr);
134 //sprintf(buf, "Selected items: %d",
135 // WMGetArrayItemCount(WMGetListSelectedItems(lPtr)));;
136 //WMSetLabelText(label, buf);
140 static void
141 listSelectionObserver(void *observer, WMNotification *notification)
143 WMLabel *label = (WMLabel*)observer;
144 WMList *lPtr = (WMList*)WMGetNotificationObject(notification);
145 char buf[255];
147 sprintf(buf, "Selected items: %d",
148 WMGetArrayItemCount(WMGetListSelectedItems(lPtr)));;
149 WMSetLabelText(label, buf);
153 void
154 testList(WMScreen *scr)
156 WMWindow *win;
157 WMList *list;
158 WMList *mlist;
159 WMLabel *label;
160 WMLabel *mlabel;
161 WMLabel *title;
162 WMLabel *mtitle;
163 char text[100];
164 int i;
166 windowCount++;
168 win = WMCreateWindow(scr, "testList");
169 WMResizeWidget(win, 370, 250);
170 WMSetWindowTitle(win, "List");
171 WMSetWindowCloseAction(win, closeAction, NULL);
173 title = WMCreateLabel(win);
174 WMResizeWidget(title, 150, 20);
175 WMMoveWidget(title, 10, 10);
176 WMSetLabelRelief(title, WRRidge);
177 WMSetLabelText(title, "Single selection list");
179 mtitle = WMCreateLabel(win);
180 WMResizeWidget(mtitle, 150, 20);
181 WMMoveWidget(mtitle, 210, 10);
182 WMSetLabelRelief(mtitle, WRRidge);
183 WMSetLabelText(mtitle, "Multiple selection list");
185 list = WMCreateList(win);
186 //WMSetListAllowEmptySelection(list, True);
187 WMMoveWidget(list, 10, 40);
188 for (i=0; i<50; i++) {
189 sprintf(text, "Item %i", i);
190 WMAddListItem(list, text);
192 mlist = WMCreateList(win);
193 WMSetListAllowMultipleSelection(mlist, True);
194 //WMSetListAllowEmptySelection(mlist, True);
195 WMMoveWidget(mlist, 210, 40);
196 for (i=0; i<135; i++) {
197 sprintf(text, "Item %i", i);
198 WMAddListItem(mlist, text);
201 label = WMCreateLabel(win);
202 WMResizeWidget(label, 150, 40);
203 WMMoveWidget(label, 10, 200);
204 WMSetLabelRelief(label, WRRidge);
205 WMSetLabelText(label, "Selected items: 0");
207 mlabel = WMCreateLabel(win);
208 WMResizeWidget(mlabel, 150, 40);
209 WMMoveWidget(mlabel, 210, 200);
210 WMSetLabelRelief(mlabel, WRRidge);
211 WMSetLabelText(mlabel, "Selected items: 0");
213 WMSetListAction(list, singleClick, label);
214 WMSetListDoubleAction(list, doubleClick, label);
215 WMSetListAction(mlist, singleClick, mlabel);
216 WMSetListDoubleAction(mlist, doubleClick, mlabel);
218 WMAddNotificationObserver(listSelectionObserver, label,
219 WMListSelectionDidChangeNotification, list);
220 WMAddNotificationObserver(listSelectionObserver, mlabel,
221 WMListSelectionDidChangeNotification, mlist);
224 WMRealizeWidget(win);
225 WMMapSubwidgets(win);
226 WMMapWidget(win);
230 void
231 testButton(WMScreen *scr)
233 WMWindow *win;
234 int i;
235 char *types[] = {
236 "MomentaryPush",
237 "PushOnPushOff",
238 "Toggle",
239 "Switch",
240 "Radio",
241 "MomentaryChange",
242 "OnOff",
243 "MomentaryLigh"
246 windowCount++;
248 win = WMCreateWindow(scr, "testButton");
249 WMResizeWidget(win, 300, 300);
250 WMSetWindowTitle(win, "Buttons");
252 WMSetWindowCloseAction(win, closeAction, NULL);
254 for (i = 1; i < 9; i++) {
255 WMButton *b;
256 b = WMCreateButton(win, i);
257 WMResizeWidget(b, 150, 24);
258 WMMoveWidget(b, 20, i*30);
259 WMSetButtonText(b, types[i-1]);
262 WMRealizeWidget(win);
263 WMMapSubwidgets(win);
264 WMMapWidget(win);
268 void
269 testGradientButtons(WMScreen *scr)
271 WMWindow *win;
272 WMButton *btn;
273 WMPixmap *pix1, *pix2;
274 RImage *back;
275 RColor light, dark;
276 WMColor *color, *altColor;
278 windowCount++;
280 /* creates the top-level window */
281 win = WMCreateWindow(scr, "testGradientButtons");
282 WMSetWindowTitle(win, "Gradiented Button Demo");
283 WMResizeWidget(win, 300, 200);
285 light.red = 0x90;
286 light.green = 0x85;
287 light.blue = 0x90;
288 dark.red = 0x35;
289 dark.green = 0x30;
290 dark.blue = 0x35;
292 color = WMCreateRGBColor(scr, 0x5900, 0x5100, 0x5900, True);
293 WMSetWidgetBackgroundColor(win, color);
294 WMReleaseColor(color);
296 back = RRenderGradient(60, 24, &dark, &light, RGRD_DIAGONAL);
297 RBevelImage(back, RBEV_RAISED2);
298 pix1 = WMCreatePixmapFromRImage(scr, back, 0);
299 RDestroyImage(back);
301 back = RRenderGradient(60, 24, &dark, &light, RGRD_DIAGONAL);
302 RBevelImage(back, RBEV_SUNKEN);
303 pix2 = WMCreatePixmapFromRImage(scr, back, 0);
304 RDestroyImage(back);
306 color = WMWhiteColor(scr);
307 altColor = WMCreateNamedColor(scr, "red", True);
309 btn = WMCreateButton(win, WBTMomentaryChange);
310 WMResizeWidget(btn, 60, 24);
311 WMMoveWidget(btn, 20, 100);
312 WMSetButtonBordered(btn, False);
313 WMSetButtonImagePosition(btn, WIPOverlaps);
314 WMSetButtonImage(btn, pix1);
315 WMSetButtonAltImage(btn, pix2);
316 WMSetButtonText(btn, "Cool");
317 WMSetButtonTextColor(btn, color);
318 WMSetButtonAltTextColor(btn, altColor);
320 WMSetBalloonTextForView("This is a cool button", WMWidgetView(btn));
322 btn = WMCreateButton(win, WBTMomentaryChange);
323 WMResizeWidget(btn, 60, 24);
324 WMMoveWidget(btn, 90, 100);
325 WMSetButtonBordered(btn, False);
326 WMSetButtonImagePosition(btn, WIPOverlaps);
327 WMSetButtonImage(btn, pix1);
328 WMSetButtonAltImage(btn, pix2);
329 WMSetButtonText(btn, "Button");
330 WMSetButtonTextColor(btn, color);
332 WMSetBalloonTextForView("Este é outro balão.", WMWidgetView(btn));
334 WMReleaseColor(color);
335 color = WMCreateNamedColor(scr, "orange", True);
337 btn = WMCreateButton(win, WBTMomentaryChange);
338 WMResizeWidget(btn, 60, 24);
339 WMMoveWidget(btn, 160, 100);
340 WMSetButtonBordered(btn, False);
341 WMSetButtonImagePosition(btn, WIPOverlaps);
342 WMSetButtonImage(btn, pix1);
343 WMSetButtonAltImage(btn, pix2);
344 WMSetButtonText(btn, "Test");
345 WMSetButtonTextColor(btn, color);
347 WMSetBalloonTextForView("This is yet another button.\nBut the balloon has 3 lines.\nYay!",
348 WMWidgetView(btn));
350 WMReleaseColor(color);
351 WMReleaseColor(altColor);
353 WMRealizeWidget(win);
354 WMMapSubwidgets(win);
355 WMMapWidget(win);
359 void
360 testScrollView(WMScreen *scr)
362 WMWindow *win;
363 WMScrollView *sview;
364 WMFrame *f;
365 WMLabel *l;
366 char buffer[128];
367 int i;
369 windowCount++;
371 /* creates the top-level window */
372 win = WMCreateWindow(scr, "testScroll");
373 WMSetWindowTitle(win, "Scrollable View");
375 WMSetWindowCloseAction(win, closeAction, NULL);
377 /* set the window size */
378 WMResizeWidget(win, 300, 300);
380 /* creates a scrollable view inside the top-level window */
381 sview = WMCreateScrollView(win);
382 WMResizeWidget(sview, 200, 200);
383 WMMoveWidget(sview, 30, 30);
384 WMSetScrollViewRelief(sview, WRSunken);
385 WMSetScrollViewHasVerticalScroller(sview, True);
386 WMSetScrollViewHasHorizontalScroller(sview, True);
388 /* create a frame with a bunch of labels */
389 f = WMCreateFrame(win);
390 WMResizeWidget(f, 400, 400);
391 WMSetFrameRelief(f, WRFlat);
393 for (i=0; i<20; i++) {
394 l = WMCreateLabel(f);
395 WMResizeWidget(l, 50, 18);
396 WMMoveWidget(l, 10, 20*i);
397 sprintf(buffer, "Label %i", i);
398 WMSetLabelText(l, buffer);
399 WMSetLabelRelief(l, WRSimple);
401 WMMapSubwidgets(f);
402 WMMapWidget(f);
404 WMSetScrollViewContentView(sview, WMWidgetView(f));
406 /* make the windows of the widgets be actually created */
407 WMRealizeWidget(win);
409 /* Map all child widgets of the top-level be mapped.
410 * You must call this for each container widget (like frames),
411 * even if they are childs of the top-level window.
413 WMMapSubwidgets(win);
415 /* map the top-level window */
416 WMMapWidget(win);
420 void
421 testColorWell(WMScreen *scr)
423 WMWindow *win;
424 WMColorWell *well1, *well2;
426 windowCount++;
428 win = WMCreateWindow(scr, "testColor");
429 WMResizeWidget(win, 300, 300);
430 WMSetWindowCloseAction(win, closeAction, NULL);
432 well1 = WMCreateColorWell(win);
433 WMResizeWidget(well1, 60, 40);
434 WMMoveWidget(well1, 100, 100);
435 WMSetColorWellColor(well1, WMCreateRGBColor(scr, 0x8888, 0, 0x1111, True));
436 well2 = WMCreateColorWell(win);
437 WMResizeWidget(well2, 60, 40);
438 WMMoveWidget(well2, 200, 100);
439 WMSetColorWellColor(well2, WMCreateRGBColor(scr, 0, 0, 0x8888, True));
441 WMRealizeWidget(win);
442 WMMapSubwidgets(win);
443 WMMapWidget(win);
446 void
447 sliderCallback(WMWidget *w, void *data)
449 printf("SLIDER == %i\n", WMGetSliderValue(w));
453 void
454 testSlider(WMScreen *scr)
456 WMWindow *win;
457 WMSlider *s;
459 windowCount++;
461 win = WMCreateWindow(scr, "testSlider");
462 WMResizeWidget(win, 300, 300);
463 WMSetWindowTitle(win, "Sliders");
465 WMSetWindowCloseAction(win, closeAction, NULL);
467 s = WMCreateSlider(win);
468 WMResizeWidget(s, 16, 100);
469 WMMoveWidget(s, 100, 100);
470 WMSetSliderKnobThickness(s, 8);
471 WMSetSliderContinuous(s, False);
472 WMSetSliderAction(s, sliderCallback, s);
474 s = WMCreateSlider(win);
475 WMResizeWidget(s, 100, 16);
476 WMMoveWidget(s, 100, 10);
477 WMSetSliderKnobThickness(s, 8);
479 WMRealizeWidget(win);
480 WMMapSubwidgets(win);
481 WMMapWidget(win);
484 void
485 testTextField(WMScreen *scr)
487 WMWindow *win;
488 WMTextField *field, *field2;
490 windowCount++;
492 win = WMCreateWindow(scr, "testTextField");
493 WMResizeWidget(win, 400, 300);
495 WMSetWindowCloseAction(win, closeAction, NULL);
497 field = WMCreateTextField(win);
498 WMResizeWidget(field, 200, 20);
499 WMMoveWidget(field, 20, 20);
501 field2 = WMCreateTextField(win);
502 WMResizeWidget(field2, 200, 20);
503 WMMoveWidget(field2, 20, 50);
504 WMSetTextFieldAlignment(field2, WARight);
506 WMRealizeWidget(win);
507 WMMapSubwidgets(win);
508 WMMapWidget(win);
512 void
513 testText(WMScreen *scr)
515 WMWindow *win;
516 WMText *text;
517 FILE *file = fopen("../README", "r");
519 windowCount++;
521 win = WMCreateWindow(scr, "testText");
522 WMResizeWidget(win, 500, 300);
524 WMSetWindowCloseAction(win, closeAction, NULL);
526 text = WMCreateText(win);
527 WMResizeWidget(text, 480, 280);
528 WMMoveWidget(text, 10, 10);
529 WMSetTextHasVerticalScroller(text, True);
530 WMSetTextEditable(text, False);
532 if(file) {
533 char buf[1024];
535 WMFreezeText(text);
536 while(fgets(buf, 1023, file))
537 WMAppendTextStream(text, buf);
539 fclose(file);
540 WMThawText(text);
541 WMRefreshText(text, 0, 0);
542 } else {
543 WMAppendTextStream(text, "<HTML><i>Where's</i> the <b>README</b>?");
546 WMRealizeWidget(win);
547 WMMapSubwidgets(win);
548 WMMapWidget(win);
553 void
554 testProgressIndicator(WMScreen *scr)
556 WMWindow *win;
557 WMProgressIndicator *pPtr;
559 windowCount++;
561 win = WMCreateWindow(scr, "testProgressIndicator");
562 WMResizeWidget(win, 292, 32);
564 WMSetWindowCloseAction(win, closeAction, NULL);
566 pPtr = WMCreateProgressIndicator(win);
567 WMMoveWidget(pPtr, 8, 8);
568 WMSetProgressIndicatorValue(pPtr, 75);
570 WMRealizeWidget(win);
571 WMMapSubwidgets(win);
572 WMMapWidget(win);
577 void
578 testPullDown(WMScreen *scr)
580 WMWindow *win;
581 WMPopUpButton *pop, *pop2;
583 windowCount++;
585 win = WMCreateWindow(scr, "pullDown");
586 WMResizeWidget(win, 400, 300);
588 WMSetWindowCloseAction(win, closeAction, NULL);
590 pop = WMCreatePopUpButton(win);
591 WMResizeWidget(pop, 100, 20);
592 WMMoveWidget(pop, 50, 60);
593 WMSetPopUpButtonPullsDown(pop, True);
594 WMSetPopUpButtonText(pop, "Commands");
595 WMAddPopUpButtonItem(pop, "Add");
596 WMAddPopUpButtonItem(pop, "Remove");
597 WMAddPopUpButtonItem(pop, "Check");
598 WMAddPopUpButtonItem(pop, "Eat");
600 pop2 = WMCreatePopUpButton(win);
601 WMResizeWidget(pop2, 100, 20);
602 WMMoveWidget(pop2, 200, 60);
603 WMSetPopUpButtonText(pop2, "Select");
604 WMAddPopUpButtonItem(pop2, "Apples");
605 WMAddPopUpButtonItem(pop2, "Bananas");
606 WMAddPopUpButtonItem(pop2, "Strawberries");
607 WMAddPopUpButtonItem(pop2, "Blueberries");
609 WMRealizeWidget(win);
610 WMMapSubwidgets(win);
611 WMMapWidget(win);
616 void
617 testTabView(WMScreen *scr)
619 WMWindow *win;
620 WMTabView *tabv;
621 WMTabViewItem *tab;
622 WMFrame *frame;
623 WMLabel *label;
625 windowCount++;
627 win = WMCreateWindow(scr, "testTabs");
628 WMResizeWidget(win, 400, 300);
630 WMSetWindowCloseAction(win, closeAction, NULL);
632 tabv = WMCreateTabView(win);
633 WMMoveWidget(tabv, 50, 50);
634 WMResizeWidget(tabv, 300, 200);
636 frame = WMCreateFrame(win);
637 WMSetFrameRelief(frame, WRFlat);
638 label = WMCreateLabel(frame);
639 WMResizeWidget(label, 100, 100);
640 WMSetLabelText(label, "Label 1");
641 WMMapWidget(label);
644 tab = WMCreateTabViewItemWithIdentifier(0);
645 WMSetTabViewItemView(tab, WMWidgetView(frame));
646 WMAddItemInTabView(tabv, tab);
647 WMSetTabViewItemLabel(tab, "Instances");
649 frame = WMCreateFrame(win);
650 WMSetFrameRelief(frame, WRFlat);
651 label = WMCreateLabel(frame);
652 WMResizeWidget(label, 40, 50);
653 WMSetLabelText(label, "Label 2");
654 WMMapWidget(label);
657 tab = WMCreateTabViewItemWithIdentifier(0);
658 WMSetTabViewItemView(tab, WMWidgetView(frame));
659 WMAddItemInTabView(tabv, tab);
660 WMSetTabViewItemLabel(tab, "Classes");
663 frame = WMCreateFrame(win);
664 WMSetFrameRelief(frame, WRFlat);
665 label = WMCreateLabel(frame);
666 WMResizeWidget(label, 100, 100);
667 WMMoveWidget(label, 60, 40);
668 WMSetLabelText(label, "Label 3");
669 WMMapWidget(label);
671 tab = WMCreateTabViewItemWithIdentifier(0);
672 WMSetTabViewItemView(tab, WMWidgetView(frame));
673 WMAddItemInTabView(tabv, tab);
674 WMSetTabViewItemLabel(tab, "Something");
677 frame = WMCreateFrame(win);
678 WMSetFrameRelief(frame, WRFlat);
679 label = WMCreateLabel(frame);
680 WMResizeWidget(label, 100, 100);
681 WMMoveWidget(label, 160, 40);
682 WMSetLabelText(label, "Label 4");
683 WMMapWidget(label);
685 tab = WMCreateTabViewItemWithIdentifier(0);
686 WMSetTabViewItemView(tab, WMWidgetView(frame));
687 WMAddItemInTabView(tabv, tab);
688 WMSetTabViewItemLabel(tab, "Bla!");
692 frame = WMCreateFrame(win);
693 WMSetFrameRelief(frame, WRFlat);
694 label = WMCreateLabel(frame);
695 WMResizeWidget(label, 100, 100);
696 WMMoveWidget(label, 160, 40);
697 WMSetLabelText(label, "Label fjweqklrj qwl");
698 WMMapWidget(label);
699 tab = WMCreateTabViewItemWithIdentifier(0);
700 WMSetTabViewItemView(tab, WMWidgetView(frame));
701 WMAddItemInTabView(tabv, tab);
702 WMSetTabViewItemLabel(tab, "Weee!");
705 WMRealizeWidget(win);
706 WMMapSubwidgets(win);
707 WMMapWidget(win);
711 void
712 splitViewConstrainProc(WMSplitView *sPtr, int indView,
713 int *minSize, int *maxSize)
715 switch (indView) {
716 case 0:
717 *minSize = 20;
718 break;
719 case 1:
720 *minSize = 40;
721 *maxSize = 80;
722 break;
723 case 2:
724 *maxSize = 60;
725 break;
726 default:
727 break;
732 static void
733 resizeSplitView(XEvent *event, void *data)
735 WMSplitView *sPtr = (WMSplitView*)data;
737 if (event->type == ConfigureNotify) {
738 int width = event->xconfigure.width - 10;
740 if (width < WMGetSplitViewDividerThickness(sPtr))
741 width = WMGetSplitViewDividerThickness(sPtr);
743 if (width != WMWidgetWidth(sPtr) ||
744 event->xconfigure.height != WMWidgetHeight(sPtr))
745 WMResizeWidget(sPtr, width, event->xconfigure.height - 55);
749 void
750 appendSubviewButtonAction(WMWidget *self, void *data)
752 WMSplitView *sPtr = (WMSplitView*)data;
753 char buf[64];
754 WMLabel *label = WMCreateLabel(sPtr);
756 sprintf(buf, "Subview %d", WMGetSplitViewSubviewsCount(sPtr) + 1);
757 WMSetLabelText(label, buf);
758 WMSetLabelRelief(label, WRSunken);
759 WMAddSplitViewSubview(sPtr, WMWidgetView(label));
760 WMRealizeWidget(label);
761 WMMapWidget(label);
764 void
765 removeSubviewButtonAction(WMWidget *self, void *data)
767 WMSplitView *sPtr = (WMSplitView*)data;
768 int count = WMGetSplitViewSubviewsCount(sPtr);
770 if (count > 2) {
771 WMView *view = WMGetSplitViewSubviewAt(sPtr, count-1);
772 WMDestroyWidget(WMWidgetOfView(view));
773 WMRemoveSplitViewSubviewAt(sPtr, count-1);
777 void
778 orientationButtonAction(WMWidget *self, void *data)
780 WMSplitView *sPtr = (WMSplitView*)data;
781 WMSetSplitViewVertical(sPtr, !WMGetSplitViewVertical(sPtr));
784 void
785 adjustSubviewsButtonAction(WMWidget *self, void *data)
787 WMAdjustSplitViewSubviews((WMSplitView*)data);
790 void
791 testSplitView(WMScreen *scr)
793 WMWindow *win;
794 WMSplitView *splitv1, *splitv2;
795 WMFrame *frame;
796 WMLabel *label;
797 WMButton *button;
799 windowCount++;
801 win = WMCreateWindow(scr, "testTabs");
802 WMResizeWidget(win, 300, 400);
803 WMSetWindowCloseAction(win, closeAction, NULL);
805 frame = WMCreateFrame(win);
806 WMSetFrameRelief(frame, WRSunken);
807 WMMoveWidget(frame, 5, 5);
808 WMResizeWidget(frame, 290, 40);
810 splitv1 = WMCreateSplitView(win);
811 WMMoveWidget(splitv1, 5, 50);
812 WMResizeWidget(splitv1, 290, 345);
813 WMSetSplitViewConstrainProc(splitv1, splitViewConstrainProc);
814 WMCreateEventHandler(WMWidgetView(win), StructureNotifyMask,
815 resizeSplitView, splitv1);
817 button = WMCreateCommandButton(frame);
818 WMSetButtonText(button, "+");
819 WMSetButtonAction(button, appendSubviewButtonAction, splitv1);
820 WMMoveWidget(button, 10, 8);
821 WMMapWidget(button);
823 button = WMCreateCommandButton(frame);
824 WMSetButtonText(button, "-");
825 WMSetButtonAction(button, removeSubviewButtonAction, splitv1);
826 WMMoveWidget(button, 80, 8);
827 WMMapWidget(button);
829 button = WMCreateCommandButton(frame);
830 WMSetButtonText(button, "=");
831 WMMoveWidget(button, 150, 8);
832 WMSetButtonAction(button, adjustSubviewsButtonAction, splitv1);
833 WMMapWidget(button);
835 button = WMCreateCommandButton(frame);
836 WMSetButtonText(button, "#");
837 WMMoveWidget(button, 220, 8);
838 WMSetButtonAction(button, orientationButtonAction, splitv1);
839 WMMapWidget(button);
841 label = WMCreateLabel(splitv1);
842 WMSetLabelText(label, "Subview 1");
843 WMSetLabelRelief(label, WRSunken);
844 WMMapWidget(label);
845 WMAddSplitViewSubview(splitv1, WMWidgetView(label));
847 splitv2 = WMCreateSplitView(splitv1);
848 WMResizeWidget(splitv2, 150, 150);
849 WMSetSplitViewVertical(splitv2, True);
851 label = WMCreateLabel(splitv2);
852 WMSetLabelText(label, "Subview 2.1");
853 WMSetLabelRelief(label, WRSunken);
854 WMMapWidget(label);
855 WMAddSplitViewSubview(splitv2, WMWidgetView(label));
857 label = WMCreateLabel(splitv2);
858 WMSetLabelText(label, "Subview 2.2");
859 WMSetLabelRelief(label, WRSunken);
860 WMMapWidget(label);
861 WMAddSplitViewSubview(splitv2, WMWidgetView(label));
863 label = WMCreateLabel(splitv2);
864 WMSetLabelText(label, "Subview 2.3");
865 WMSetLabelRelief(label, WRSunken);
866 WMMapWidget(label);
867 WMAddSplitViewSubview(splitv2, WMWidgetView(label));
869 WMMapWidget(splitv2);
870 WMAddSplitViewSubview(splitv1, WMWidgetView(splitv2));
872 WMRealizeWidget(win);
873 WMMapSubwidgets(win);
874 WMMapWidget(win);
878 /*******************************************************************/
880 #include <sys/types.h>
881 #include <dirent.h>
882 #include <string.h>
885 typedef struct {
886 int x, y;
887 Bool mouseDown;
888 char *filename;
889 } DNDStuff;
891 WMPixmap*
892 getImage(WMScreen *scr, char *file)
894 char buffer[1000];
895 WMPixmap *pix;
897 sprintf(buffer, "../../WindowMaker/Icons/%s", file);
898 pix = WMCreatePixmapFromFile(scr, buffer);
900 return pix;
906 static void
907 iconMouseStuff(XEvent *event, void *cdata)
909 WMLabel *label = (WMLabel*)cdata;
910 DNDStuff *stuff = WMGetHangedData(label);
911 WMPoint where;
913 switch (event->type) {
914 case ButtonPress:
915 stuff->x = event->xbutton.x;
916 stuff->y = event->xbutton.y;
917 stuff->mouseDown = True;
918 break;
919 case ButtonRelease:
920 stuff->mouseDown = False;
921 break;
922 case MotionNotify:
923 if (!stuff->mouseDown)
924 break;
926 if (abs(stuff->x - event->xmotion.x)>4
927 || abs(stuff->y - event->xmotion.y)>4) {
929 where = WMGetViewScreenPosition(WMWidgetView(label));
931 WMDragImageFromView(WMWidgetView(label),
932 WMGetLabelImage(label),
933 NULL, /* XXX */
934 where,
935 wmksize(stuff->x, stuff->y),
936 event, True);
938 break;
943 static void
944 endedDragImage(WMView *self, WMPixmap *image, WMPoint point, Bool deposited)
946 DNDStuff *stuff = WMGetHangedData(WMWidgetOfView(self));
948 if (deposited) {
949 WMDestroyWidget(WMWidgetOfView(self));
952 stuff->mouseDown = False;
956 static WMData*
957 fetchDragData(WMView *self, char *type)
959 DNDStuff *stuff = WMGetHangedData(WMWidgetOfView(self));
961 return WMCreateDataWithBytes(stuff->filename, strlen(stuff->filename)+1);
965 WMDragSourceProcs dragSourceProcs = {
966 NULL,
967 NULL,
968 endedDragImage,
969 fetchDragData
973 /************************/
976 unsigned
977 draggingEntered(WMView *self, WMDraggingInfo *info)
979 return WDOperationCopy;
983 unsigned
984 draggingUpdated(WMView *self, WMDraggingInfo *info)
986 return WDOperationCopy;
990 void (*draggingExited)(WMView *self, WMDraggingInfo *info);
992 char*
993 prepareForDragOperation(WMView *self, WMDraggingInfo *info)
995 return "application/X-WINGs-Bla";
999 WMLabel* makeDraggableLabel(WMWidget *w, char *file, int x, int y);
1001 Bool
1002 performDragOperation(WMView *self, WMDraggingInfo *info, WMData *data)
1004 char *file = (char*)WMDataBytes(data);
1005 WMPoint pos;
1007 pos = WMGetDraggingInfoImageLocation(info);
1009 if (file!=NULL) {
1010 WMLabel *label;
1011 WMPoint pos2 = WMGetViewScreenPosition(self);
1014 label = makeDraggableLabel(WMWidgetOfView(self), file,
1015 pos.x-pos2.x, pos.y-pos2.y);
1016 WMRealizeWidget(label);
1017 WMMapWidget(label);
1021 return True;
1025 void
1026 concludeDragOperation(WMView *self, WMDraggingInfo *info)
1033 WMDragDestinationProcs dragDestProcs = {
1034 draggingEntered,
1035 draggingUpdated,
1036 NULL,
1037 prepareForDragOperation,
1038 performDragOperation,
1039 concludeDragOperation
1045 WMLabel*
1046 makeDraggableLabel(WMWidget *w, char *file, int x, int y)
1048 DNDStuff *stuff;
1049 WMLabel *label;
1050 WMPixmap *image = getImage(WMWidgetScreen(w), file);
1052 stuff = wmalloc(sizeof(DNDStuff));
1053 stuff->mouseDown = False;
1055 stuff->filename = wstrdup(file);
1057 label = WMCreateLabel(w);
1058 WMResizeWidget(label, 48, 48);
1059 WMMoveWidget(label, x, y);
1061 WMSetViewDragSourceProcs(WMWidgetView(label), &dragSourceProcs);
1063 WMHangData(label, stuff);
1065 WMCreateEventHandler(WMWidgetView(label),
1066 ButtonPressMask|ButtonReleaseMask|ButtonMotionMask,
1067 iconMouseStuff, label);
1070 if (image != NULL) {
1071 WMSetLabelImagePosition(label, WIPImageOnly);
1072 WMSetLabelImage(label, image);
1073 WMReleasePixmap(image);
1074 } else puts(file);
1076 return label;
1081 void
1082 testDragAndDrop(WMScreen *scr)
1084 WMWindow *win;
1085 WMFrame *frame;
1086 WMLabel *label;
1087 int i, j;
1088 DIR *dir;
1089 struct dirent *ent;
1090 char *types[] = {
1091 "application/X-WINGs-Bla",
1092 NULL
1095 windowCount++;
1097 win = WMCreateWindow(scr, "dragDrop");
1098 WMResizeWidget(win, 300, 300);
1099 WMSetWindowCloseAction(win, closeAction, NULL);
1100 WMSetWindowTitle(win, "Drag and Drop");
1103 frame = WMCreateFrame(win);
1104 WMSetFrameRelief(frame, WRSunken);
1105 WMResizeWidget(frame, 250, 250);
1106 WMMoveWidget(frame, 25, 25);
1108 WMRegisterViewForDraggedTypes(WMWidgetView(frame), types);
1109 WMSetViewDragDestinationProcs(WMWidgetView(frame), &dragDestProcs);
1111 dir = opendir("../../WindowMaker/Icons");
1112 if (!dir) {
1113 perror("../../WindowMaker/Icons");
1114 return;
1117 for (i = 0, j=0; j < 8; i++) {
1118 ent = readdir(dir);
1119 if (!ent)
1120 break;
1122 if (strstr(ent->d_name, ".xpm")==NULL) {
1123 continue;
1126 label = makeDraggableLabel(frame, ent->d_name,4+(j/4)*64, 4+(j%4)*64);
1128 j++;
1131 closedir(dir);
1133 WMMapSubwidgets(frame);
1135 WMMapSubwidgets(win);
1136 WMRealizeWidget(win);
1137 WMMapWidget(win);
1144 /*******************************************************************/
1146 #include "WUtil.h"
1148 void
1149 testUD()
1151 WMUserDefaults *defs;
1152 char str[32];
1154 defs = WMGetStandardUserDefaults();
1156 sprintf(str, "TEST DATA");
1157 puts(str);
1158 WMSetUDStringForKey(defs, str, "testKey");
1159 puts(str);
1164 main(int argc, char **argv)
1166 WMScreen *scr;
1167 WMPixmap *pixmap;
1170 /* Initialize the application */
1171 WMInitializeApplication("Test", &argc, argv);
1173 testUD();
1176 * Open connection to the X display.
1178 dpy = XOpenDisplay("");
1180 if (!dpy) {
1181 puts("could not open display");
1182 exit(1);
1185 /* This is used to disable buffering of X protocol requests.
1186 * Do NOT use it unless when debugging. It will cause a major
1187 * slowdown in your application
1189 #if 1
1190 XSynchronize(dpy, True);
1191 #endif
1193 * Create screen descriptor.
1195 scr = WMCreateScreen(dpy, DefaultScreen(dpy));
1198 * Loads the logo of the application.
1200 pixmap = WMCreatePixmapFromFile(scr, "logo.xpm");
1203 * Makes the logo be used in standard dialog panels.
1205 WMSetApplicationIconImage(scr, pixmap); WMReleasePixmap(pixmap);
1208 * Do some test stuff.
1210 * Put the testSomething() function you want to test here.
1213 testList(scr);
1215 #if 0
1216 testColorWell(scr);
1218 testTextField(scr);
1219 testText(scr);
1221 testDragAndDrop(scr);
1222 testDragAndDrop(scr);
1223 testFontPanel(scr);
1225 testScrollView(scr);
1227 testButton(scr);
1229 testFrame(scr);
1232 testTabView(scr);
1236 testSplitView(scr);
1238 testGradientButtons(scr);
1239 testProgressIndicator(scr);
1242 testOpenFilePanel(scr);
1244 testSlider(scr);
1245 testPullDown(scr);
1246 #endif
1248 * The main event loop.
1251 WMScreenMainLoop(scr);
1253 return 0;