Fixed some paths after the WINGs directory reorganization
[wmaker-crm.git] / WINGs / Tests / wtest.c
blob51852c91efd35929a082f9b2f357112f53739c11
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);
118 void
119 testList(WMScreen *scr)
121 WMWindow *win;
122 WMList *list;
123 char text[100];
124 int i;
126 windowCount++;
128 win = WMCreateWindow(scr, "testList");
129 WMSetWindowTitle(win, "List");
130 WMSetWindowCloseAction(win, closeAction, NULL);
132 list = WMCreateList(win);
133 for (i=0; i<50; i++) {
134 sprintf(text, "Item %i", i);
135 WMAddListItem(list, text);
137 WMRealizeWidget(win);
138 WMMapSubwidgets(win);
139 WMMapWidget(win);
145 void
146 testButton(WMScreen *scr)
148 WMWindow *win;
149 int i;
150 char *types[] = {
151 "MomentaryPush",
152 "PushOnPushOff",
153 "Toggle",
154 "Switch",
155 "Radio",
156 "MomentaryChange",
157 "OnOff",
158 "MomentaryLigh"
161 windowCount++;
163 win = WMCreateWindow(scr, "testButton");
164 WMResizeWidget(win, 300, 300);
165 WMSetWindowTitle(win, "Buttons");
167 WMSetWindowCloseAction(win, closeAction, NULL);
169 for (i = 1; i < 9; i++) {
170 WMButton *b;
171 b = WMCreateButton(win, i);
172 WMResizeWidget(b, 150, 24);
173 WMMoveWidget(b, 20, i*30);
174 WMSetButtonText(b, types[i-1]);
177 WMRealizeWidget(win);
178 WMMapSubwidgets(win);
179 WMMapWidget(win);
183 void
184 testGradientButtons(WMScreen *scr)
186 WMWindow *win;
187 WMButton *btn;
188 WMPixmap *pix1, *pix2;
189 RImage *back;
190 RColor light, dark;
191 WMColor *color, *altColor;
193 windowCount++;
195 /* creates the top-level window */
196 win = WMCreateWindow(scr, "testGradientButtons");
197 WMSetWindowTitle(win, "Gradiented Button Demo");
198 WMResizeWidget(win, 300, 200);
200 light.red = 0x90;
201 light.green = 0x85;
202 light.blue = 0x90;
203 dark.red = 0x35;
204 dark.green = 0x30;
205 dark.blue = 0x35;
207 color = WMCreateRGBColor(scr, 0x5900, 0x5100, 0x5900, True);
208 WMSetWidgetBackgroundColor(win, color);
209 WMReleaseColor(color);
211 back = RRenderGradient(60, 24, &dark, &light, RGRD_DIAGONAL);
212 RBevelImage(back, RBEV_RAISED2);
213 pix1 = WMCreatePixmapFromRImage(scr, back, 0);
214 RDestroyImage(back);
216 back = RRenderGradient(60, 24, &dark, &light, RGRD_DIAGONAL);
217 RBevelImage(back, RBEV_SUNKEN);
218 pix2 = WMCreatePixmapFromRImage(scr, back, 0);
219 RDestroyImage(back);
221 color = WMWhiteColor(scr);
222 altColor = WMCreateNamedColor(scr, "red", True);
224 btn = WMCreateButton(win, WBTMomentaryChange);
225 WMResizeWidget(btn, 60, 24);
226 WMMoveWidget(btn, 20, 100);
227 WMSetButtonBordered(btn, False);
228 WMSetButtonImagePosition(btn, WIPOverlaps);
229 WMSetButtonImage(btn, pix1);
230 WMSetButtonAltImage(btn, pix2);
231 WMSetButtonText(btn, "Cool");
232 WMSetButtonTextColor(btn, color);
233 WMSetButtonAltTextColor(btn, altColor);
235 WMSetBalloonTextForView("This is a cool button", WMWidgetView(btn));
237 btn = WMCreateButton(win, WBTMomentaryChange);
238 WMResizeWidget(btn, 60, 24);
239 WMMoveWidget(btn, 90, 100);
240 WMSetButtonBordered(btn, False);
241 WMSetButtonImagePosition(btn, WIPOverlaps);
242 WMSetButtonImage(btn, pix1);
243 WMSetButtonAltImage(btn, pix2);
244 WMSetButtonText(btn, "Button");
245 WMSetButtonTextColor(btn, color);
247 WMSetBalloonTextForView("Este é outro balão.", WMWidgetView(btn));
249 WMReleaseColor(color);
250 color = WMCreateNamedColor(scr, "orange", True);
252 btn = WMCreateButton(win, WBTMomentaryChange);
253 WMResizeWidget(btn, 60, 24);
254 WMMoveWidget(btn, 160, 100);
255 WMSetButtonBordered(btn, False);
256 WMSetButtonImagePosition(btn, WIPOverlaps);
257 WMSetButtonImage(btn, pix1);
258 WMSetButtonAltImage(btn, pix2);
259 WMSetButtonText(btn, "Test");
260 WMSetButtonTextColor(btn, color);
262 WMSetBalloonTextForView("This is yet another button.\nBut the balloon has 3 lines.\nYay!",
263 WMWidgetView(btn));
265 WMReleaseColor(color);
266 WMReleaseColor(altColor);
268 WMRealizeWidget(win);
269 WMMapSubwidgets(win);
270 WMMapWidget(win);
274 void
275 testScrollView(WMScreen *scr)
277 WMWindow *win;
278 WMScrollView *sview;
279 WMFrame *f;
280 WMLabel *l;
281 char buffer[128];
282 int i;
284 windowCount++;
286 /* creates the top-level window */
287 win = WMCreateWindow(scr, "testScroll");
288 WMSetWindowTitle(win, "Scrollable View");
290 WMSetWindowCloseAction(win, closeAction, NULL);
292 /* set the window size */
293 WMResizeWidget(win, 300, 300);
295 /* creates a scrollable view inside the top-level window */
296 sview = WMCreateScrollView(win);
297 WMResizeWidget(sview, 200, 200);
298 WMMoveWidget(sview, 30, 30);
299 WMSetScrollViewRelief(sview, WRSunken);
300 WMSetScrollViewHasVerticalScroller(sview, True);
301 WMSetScrollViewHasHorizontalScroller(sview, True);
303 /* create a frame with a bunch of labels */
304 f = WMCreateFrame(win);
305 WMResizeWidget(f, 400, 400);
306 WMSetFrameRelief(f, WRFlat);
308 for (i=0; i<20; i++) {
309 l = WMCreateLabel(f);
310 WMResizeWidget(l, 50, 18);
311 WMMoveWidget(l, 10, 20*i);
312 sprintf(buffer, "Label %i", i);
313 WMSetLabelText(l, buffer);
314 WMSetLabelRelief(l, WRSimple);
316 WMMapSubwidgets(f);
317 WMMapWidget(f);
319 WMSetScrollViewContentView(sview, WMWidgetView(f));
321 /* make the windows of the widgets be actually created */
322 WMRealizeWidget(win);
324 /* Map all child widgets of the top-level be mapped.
325 * You must call this for each container widget (like frames),
326 * even if they are childs of the top-level window.
328 WMMapSubwidgets(win);
330 /* map the top-level window */
331 WMMapWidget(win);
335 void
336 testColorWell(WMScreen *scr)
338 WMWindow *win;
339 WMColorWell *well1, *well2;
341 windowCount++;
343 win = WMCreateWindow(scr, "testColor");
344 WMResizeWidget(win, 300, 300);
345 WMSetWindowCloseAction(win, closeAction, NULL);
347 well1 = WMCreateColorWell(win);
348 WMResizeWidget(well1, 60, 40);
349 WMMoveWidget(well1, 100, 100);
350 WMSetColorWellColor(well1, WMCreateRGBColor(scr, 0x8888, 0, 0x1111, True));
351 well2 = WMCreateColorWell(win);
352 WMResizeWidget(well2, 60, 40);
353 WMMoveWidget(well2, 200, 100);
354 WMSetColorWellColor(well2, WMCreateRGBColor(scr, 0, 0, 0x8888, True));
356 WMRealizeWidget(win);
357 WMMapSubwidgets(win);
358 WMMapWidget(win);
361 void
362 sliderCallback(WMWidget *w, void *data)
364 printf("SLIDER == %i\n", WMGetSliderValue(w));
368 void
369 testSlider(WMScreen *scr)
371 WMWindow *win;
372 WMSlider *s;
374 windowCount++;
376 win = WMCreateWindow(scr, "testSlider");
377 WMResizeWidget(win, 300, 300);
378 WMSetWindowTitle(win, "Sliders");
380 WMSetWindowCloseAction(win, closeAction, NULL);
382 s = WMCreateSlider(win);
383 WMResizeWidget(s, 16, 100);
384 WMMoveWidget(s, 100, 100);
385 WMSetSliderKnobThickness(s, 8);
386 WMSetSliderContinuous(s, False);
387 WMSetSliderAction(s, sliderCallback, s);
389 s = WMCreateSlider(win);
390 WMResizeWidget(s, 100, 16);
391 WMMoveWidget(s, 100, 10);
392 WMSetSliderKnobThickness(s, 8);
394 WMRealizeWidget(win);
395 WMMapSubwidgets(win);
396 WMMapWidget(win);
399 void
400 testTextField(WMScreen *scr)
402 WMWindow *win;
403 WMTextField *field, *field2;
405 windowCount++;
407 win = WMCreateWindow(scr, "testTextField");
408 WMResizeWidget(win, 400, 300);
410 WMSetWindowCloseAction(win, closeAction, NULL);
412 field = WMCreateTextField(win);
413 WMResizeWidget(field, 200, 20);
414 WMMoveWidget(field, 20, 20);
416 field2 = WMCreateTextField(win);
417 WMResizeWidget(field2, 200, 20);
418 WMMoveWidget(field2, 20, 50);
419 WMSetTextFieldAlignment(field2, WARight);
421 WMRealizeWidget(win);
422 WMMapSubwidgets(win);
423 WMMapWidget(win);
427 void
428 testText(WMScreen *scr)
430 WMWindow *win;
431 WMText *text;
432 FILE *file = fopen("../README", "r");
434 windowCount++;
436 win = WMCreateWindow(scr, "testText");
437 WMResizeWidget(win, 500, 300);
439 WMSetWindowCloseAction(win, closeAction, NULL);
441 text = WMCreateText(win);
442 WMResizeWidget(text, 480, 280);
443 WMMoveWidget(text, 10, 10);
444 WMSetTextHasVerticalScroller(text, True);
445 WMSetTextEditable(text, False);
447 if(file) {
448 char buf[1024];
450 WMFreezeText(text);
451 while(fgets(buf, 1023, file))
452 WMAppendTextStream(text, buf);
454 fclose(file);
455 WMThawText(text);
456 WMRefreshText(text, 0, 0);
457 } else {
458 WMAppendTextStream(text, "<HTML><i>Where's</i> the <b>README</b>?");
461 WMRealizeWidget(win);
462 WMMapSubwidgets(win);
463 WMMapWidget(win);
468 void
469 testProgressIndicator(WMScreen *scr)
471 WMWindow *win;
472 WMProgressIndicator *pPtr;
474 windowCount++;
476 win = WMCreateWindow(scr, "testProgressIndicator");
477 WMResizeWidget(win, 292, 32);
479 WMSetWindowCloseAction(win, closeAction, NULL);
481 pPtr = WMCreateProgressIndicator(win);
482 WMMoveWidget(pPtr, 8, 8);
483 WMSetProgressIndicatorValue(pPtr, 75);
485 WMRealizeWidget(win);
486 WMMapSubwidgets(win);
487 WMMapWidget(win);
492 void
493 testPullDown(WMScreen *scr)
495 WMWindow *win;
496 WMPopUpButton *pop, *pop2;
498 windowCount++;
500 win = WMCreateWindow(scr, "pullDown");
501 WMResizeWidget(win, 400, 300);
503 WMSetWindowCloseAction(win, closeAction, NULL);
505 pop = WMCreatePopUpButton(win);
506 WMResizeWidget(pop, 100, 20);
507 WMMoveWidget(pop, 50, 60);
508 WMSetPopUpButtonPullsDown(pop, True);
509 WMSetPopUpButtonText(pop, "Commands");
510 WMAddPopUpButtonItem(pop, "Add");
511 WMAddPopUpButtonItem(pop, "Remove");
512 WMAddPopUpButtonItem(pop, "Check");
513 WMAddPopUpButtonItem(pop, "Eat");
515 pop2 = WMCreatePopUpButton(win);
516 WMResizeWidget(pop2, 100, 20);
517 WMMoveWidget(pop2, 200, 60);
518 WMSetPopUpButtonText(pop2, "Select");
519 WMAddPopUpButtonItem(pop2, "Apples");
520 WMAddPopUpButtonItem(pop2, "Bananas");
521 WMAddPopUpButtonItem(pop2, "Strawberries");
522 WMAddPopUpButtonItem(pop2, "Blueberries");
524 WMRealizeWidget(win);
525 WMMapSubwidgets(win);
526 WMMapWidget(win);
531 void
532 testTabView(WMScreen *scr)
534 WMWindow *win;
535 WMTabView *tabv;
536 WMTabViewItem *tab;
537 WMFrame *frame;
538 WMLabel *label;
540 windowCount++;
542 win = WMCreateWindow(scr, "testTabs");
543 WMResizeWidget(win, 400, 300);
545 WMSetWindowCloseAction(win, closeAction, NULL);
547 tabv = WMCreateTabView(win);
548 WMMoveWidget(tabv, 50, 50);
549 WMResizeWidget(tabv, 300, 200);
551 frame = WMCreateFrame(win);
552 WMSetFrameRelief(frame, WRFlat);
553 label = WMCreateLabel(frame);
554 WMResizeWidget(label, 100, 100);
555 WMSetLabelText(label, "Label 1");
556 WMMapWidget(label);
559 tab = WMCreateTabViewItemWithIdentifier(0);
560 WMSetTabViewItemView(tab, WMWidgetView(frame));
561 WMAddItemInTabView(tabv, tab);
562 WMSetTabViewItemLabel(tab, "Instances");
564 frame = WMCreateFrame(win);
565 WMSetFrameRelief(frame, WRFlat);
566 label = WMCreateLabel(frame);
567 WMResizeWidget(label, 40, 50);
568 WMSetLabelText(label, "Label 2");
569 WMMapWidget(label);
572 tab = WMCreateTabViewItemWithIdentifier(0);
573 WMSetTabViewItemView(tab, WMWidgetView(frame));
574 WMAddItemInTabView(tabv, tab);
575 WMSetTabViewItemLabel(tab, "Classes");
578 frame = WMCreateFrame(win);
579 WMSetFrameRelief(frame, WRFlat);
580 label = WMCreateLabel(frame);
581 WMResizeWidget(label, 100, 100);
582 WMMoveWidget(label, 60, 40);
583 WMSetLabelText(label, "Label 3");
584 WMMapWidget(label);
586 tab = WMCreateTabViewItemWithIdentifier(0);
587 WMSetTabViewItemView(tab, WMWidgetView(frame));
588 WMAddItemInTabView(tabv, tab);
589 WMSetTabViewItemLabel(tab, "Something");
592 frame = WMCreateFrame(win);
593 WMSetFrameRelief(frame, WRFlat);
594 label = WMCreateLabel(frame);
595 WMResizeWidget(label, 100, 100);
596 WMMoveWidget(label, 160, 40);
597 WMSetLabelText(label, "Label 4");
598 WMMapWidget(label);
600 tab = WMCreateTabViewItemWithIdentifier(0);
601 WMSetTabViewItemView(tab, WMWidgetView(frame));
602 WMAddItemInTabView(tabv, tab);
603 WMSetTabViewItemLabel(tab, "Bla!");
607 frame = WMCreateFrame(win);
608 WMSetFrameRelief(frame, WRFlat);
609 label = WMCreateLabel(frame);
610 WMResizeWidget(label, 100, 100);
611 WMMoveWidget(label, 160, 40);
612 WMSetLabelText(label, "Label fjweqklrj qwl");
613 WMMapWidget(label);
614 tab = WMCreateTabViewItemWithIdentifier(0);
615 WMSetTabViewItemView(tab, WMWidgetView(frame));
616 WMAddItemInTabView(tabv, tab);
617 WMSetTabViewItemLabel(tab, "Weee!");
620 WMRealizeWidget(win);
621 WMMapSubwidgets(win);
622 WMMapWidget(win);
626 void
627 splitViewConstrainProc(WMSplitView *sPtr, int indView,
628 int *minSize, int *maxSize)
630 switch (indView) {
631 case 0:
632 *minSize = 20;
633 break;
634 case 1:
635 *minSize = 40;
636 *maxSize = 80;
637 break;
638 case 2:
639 *maxSize = 60;
640 break;
641 default:
642 break;
647 static void
648 resizeSplitView(XEvent *event, void *data)
650 WMSplitView *sPtr = (WMSplitView*)data;
652 if (event->type == ConfigureNotify) {
653 int width = event->xconfigure.width - 10;
655 if (width < WMGetSplitViewDividerThickness(sPtr))
656 width = WMGetSplitViewDividerThickness(sPtr);
658 if (width != WMWidgetWidth(sPtr) ||
659 event->xconfigure.height != WMWidgetHeight(sPtr))
660 WMResizeWidget(sPtr, width, event->xconfigure.height - 55);
664 void
665 appendSubviewButtonAction(WMWidget *self, void *data)
667 WMSplitView *sPtr = (WMSplitView*)data;
668 char buf[64];
669 WMLabel *label = WMCreateLabel(sPtr);
671 sprintf(buf, "Subview %d", WMGetSplitViewSubviewsCount(sPtr) + 1);
672 WMSetLabelText(label, buf);
673 WMSetLabelRelief(label, WRSunken);
674 WMAddSplitViewSubview(sPtr, WMWidgetView(label));
675 WMRealizeWidget(label);
676 WMMapWidget(label);
679 void
680 removeSubviewButtonAction(WMWidget *self, void *data)
682 WMSplitView *sPtr = (WMSplitView*)data;
683 int count = WMGetSplitViewSubviewsCount(sPtr);
685 if (count > 2) {
686 WMView *view = WMGetSplitViewSubviewAt(sPtr, count-1);
687 WMDestroyWidget(WMWidgetOfView(view));
688 WMRemoveSplitViewSubviewAt(sPtr, count-1);
692 void
693 orientationButtonAction(WMWidget *self, void *data)
695 WMSplitView *sPtr = (WMSplitView*)data;
696 WMSetSplitViewVertical(sPtr, !WMGetSplitViewVertical(sPtr));
699 void
700 adjustSubviewsButtonAction(WMWidget *self, void *data)
702 WMAdjustSplitViewSubviews((WMSplitView*)data);
705 void
706 testSplitView(WMScreen *scr)
708 WMWindow *win;
709 WMSplitView *splitv1, *splitv2;
710 WMFrame *frame;
711 WMLabel *label;
712 WMButton *button;
714 windowCount++;
716 win = WMCreateWindow(scr, "testTabs");
717 WMResizeWidget(win, 300, 400);
718 WMSetWindowCloseAction(win, closeAction, NULL);
720 frame = WMCreateFrame(win);
721 WMSetFrameRelief(frame, WRSunken);
722 WMMoveWidget(frame, 5, 5);
723 WMResizeWidget(frame, 290, 40);
725 splitv1 = WMCreateSplitView(win);
726 WMMoveWidget(splitv1, 5, 50);
727 WMResizeWidget(splitv1, 290, 345);
728 WMSetSplitViewConstrainProc(splitv1, splitViewConstrainProc);
729 WMCreateEventHandler(WMWidgetView(win), StructureNotifyMask,
730 resizeSplitView, splitv1);
732 button = WMCreateCommandButton(frame);
733 WMSetButtonText(button, "+");
734 WMSetButtonAction(button, appendSubviewButtonAction, splitv1);
735 WMMoveWidget(button, 10, 8);
736 WMMapWidget(button);
738 button = WMCreateCommandButton(frame);
739 WMSetButtonText(button, "-");
740 WMSetButtonAction(button, removeSubviewButtonAction, splitv1);
741 WMMoveWidget(button, 80, 8);
742 WMMapWidget(button);
744 button = WMCreateCommandButton(frame);
745 WMSetButtonText(button, "=");
746 WMMoveWidget(button, 150, 8);
747 WMSetButtonAction(button, adjustSubviewsButtonAction, splitv1);
748 WMMapWidget(button);
750 button = WMCreateCommandButton(frame);
751 WMSetButtonText(button, "#");
752 WMMoveWidget(button, 220, 8);
753 WMSetButtonAction(button, orientationButtonAction, splitv1);
754 WMMapWidget(button);
756 label = WMCreateLabel(splitv1);
757 WMSetLabelText(label, "Subview 1");
758 WMSetLabelRelief(label, WRSunken);
759 WMMapWidget(label);
760 WMAddSplitViewSubview(splitv1, WMWidgetView(label));
762 splitv2 = WMCreateSplitView(splitv1);
763 WMResizeWidget(splitv2, 150, 150);
764 WMSetSplitViewVertical(splitv2, True);
766 label = WMCreateLabel(splitv2);
767 WMSetLabelText(label, "Subview 2.1");
768 WMSetLabelRelief(label, WRSunken);
769 WMMapWidget(label);
770 WMAddSplitViewSubview(splitv2, WMWidgetView(label));
772 label = WMCreateLabel(splitv2);
773 WMSetLabelText(label, "Subview 2.2");
774 WMSetLabelRelief(label, WRSunken);
775 WMMapWidget(label);
776 WMAddSplitViewSubview(splitv2, WMWidgetView(label));
778 label = WMCreateLabel(splitv2);
779 WMSetLabelText(label, "Subview 2.3");
780 WMSetLabelRelief(label, WRSunken);
781 WMMapWidget(label);
782 WMAddSplitViewSubview(splitv2, WMWidgetView(label));
784 WMMapWidget(splitv2);
785 WMAddSplitViewSubview(splitv1, WMWidgetView(splitv2));
787 WMRealizeWidget(win);
788 WMMapSubwidgets(win);
789 WMMapWidget(win);
793 /*******************************************************************/
795 #include <sys/types.h>
796 #include <dirent.h>
797 #include <string.h>
800 typedef struct {
801 int x, y;
802 Bool mouseDown;
803 char *filename;
804 } DNDStuff;
806 WMPixmap*
807 getImage(WMScreen *scr, char *file)
809 char buffer[1000];
810 WMPixmap *pix;
812 sprintf(buffer, "../../WindowMaker/Icons/%s", file);
813 pix = WMCreatePixmapFromFile(scr, buffer);
815 return pix;
821 static void
822 iconMouseStuff(XEvent *event, void *cdata)
824 WMLabel *label = (WMLabel*)cdata;
825 DNDStuff *stuff = WMGetHangedData(label);
826 WMPoint where;
828 switch (event->type) {
829 case ButtonPress:
830 stuff->x = event->xbutton.x;
831 stuff->y = event->xbutton.y;
832 stuff->mouseDown = True;
833 break;
834 case ButtonRelease:
835 stuff->mouseDown = False;
836 break;
837 case MotionNotify:
838 if (!stuff->mouseDown)
839 break;
841 if (abs(stuff->x - event->xmotion.x)>4
842 || abs(stuff->y - event->xmotion.y)>4) {
844 where = WMGetViewScreenPosition(WMWidgetView(label));
846 WMDragImageFromView(WMWidgetView(label),
847 WMGetLabelImage(label),
848 NULL, /* XXX */
849 where,
850 wmksize(stuff->x, stuff->y),
851 event, True);
853 break;
858 static void
859 endedDragImage(WMView *self, WMPixmap *image, WMPoint point, Bool deposited)
861 DNDStuff *stuff = WMGetHangedData(WMWidgetOfView(self));
863 if (deposited) {
864 WMDestroyWidget(WMWidgetOfView(self));
867 stuff->mouseDown = False;
871 static WMData*
872 fetchDragData(WMView *self, char *type)
874 DNDStuff *stuff = WMGetHangedData(WMWidgetOfView(self));
876 return WMCreateDataWithBytes(stuff->filename, strlen(stuff->filename)+1);
880 WMDragSourceProcs dragSourceProcs = {
881 NULL,
882 NULL,
883 endedDragImage,
884 fetchDragData
888 /************************/
891 unsigned
892 draggingEntered(WMView *self, WMDraggingInfo *info)
894 return WDOperationCopy;
898 unsigned
899 draggingUpdated(WMView *self, WMDraggingInfo *info)
901 return WDOperationCopy;
905 void (*draggingExited)(WMView *self, WMDraggingInfo *info);
907 char*
908 prepareForDragOperation(WMView *self, WMDraggingInfo *info)
910 return "application/X-WINGs-Bla";
914 WMLabel* makeDraggableLabel(WMWidget *w, char *file, int x, int y);
916 Bool
917 performDragOperation(WMView *self, WMDraggingInfo *info, WMData *data)
919 char *file = (char*)WMDataBytes(data);
920 WMPoint pos;
922 pos = WMGetDraggingInfoImageLocation(info);
924 if (file!=NULL) {
925 WMLabel *label;
926 WMPoint pos2 = WMGetViewScreenPosition(self);
929 label = makeDraggableLabel(WMWidgetOfView(self), file,
930 pos.x-pos2.x, pos.y-pos2.y);
931 WMRealizeWidget(label);
932 WMMapWidget(label);
936 return True;
940 void
941 concludeDragOperation(WMView *self, WMDraggingInfo *info)
948 WMDragDestinationProcs dragDestProcs = {
949 draggingEntered,
950 draggingUpdated,
951 NULL,
952 prepareForDragOperation,
953 performDragOperation,
954 concludeDragOperation
960 WMLabel*
961 makeDraggableLabel(WMWidget *w, char *file, int x, int y)
963 DNDStuff *stuff;
964 WMLabel *label;
965 WMPixmap *image = getImage(WMWidgetScreen(w), file);
967 stuff = wmalloc(sizeof(DNDStuff));
968 stuff->mouseDown = False;
970 stuff->filename = wstrdup(file);
972 label = WMCreateLabel(w);
973 WMResizeWidget(label, 48, 48);
974 WMMoveWidget(label, x, y);
976 WMSetViewDragSourceProcs(WMWidgetView(label), &dragSourceProcs);
978 WMHangData(label, stuff);
980 WMCreateEventHandler(WMWidgetView(label),
981 ButtonPressMask|ButtonReleaseMask|ButtonMotionMask,
982 iconMouseStuff, label);
985 if (image != NULL) {
986 WMSetLabelImagePosition(label, WIPImageOnly);
987 WMSetLabelImage(label, image);
988 WMReleasePixmap(image);
989 } else puts(file);
991 return label;
996 void
997 testDragAndDrop(WMScreen *scr)
999 WMWindow *win;
1000 WMFrame *frame;
1001 WMLabel *label;
1002 int i, j;
1003 DIR *dir;
1004 struct dirent *ent;
1005 char *types[] = {
1006 "application/X-WINGs-Bla",
1007 NULL
1010 windowCount++;
1012 win = WMCreateWindow(scr, "dragDrop");
1013 WMResizeWidget(win, 300, 300);
1014 WMSetWindowCloseAction(win, closeAction, NULL);
1015 WMSetWindowTitle(win, "Drag and Drop");
1018 frame = WMCreateFrame(win);
1019 WMSetFrameRelief(frame, WRSunken);
1020 WMResizeWidget(frame, 250, 250);
1021 WMMoveWidget(frame, 25, 25);
1023 WMRegisterViewForDraggedTypes(WMWidgetView(frame), types);
1024 WMSetViewDragDestinationProcs(WMWidgetView(frame), &dragDestProcs);
1026 dir = opendir("../../WindowMaker/Icons");
1027 if (!dir) {
1028 perror("../../WindowMaker/Icons");
1029 return;
1032 for (i = 0, j=0; j < 8; i++) {
1033 ent = readdir(dir);
1034 if (!ent)
1035 break;
1037 if (strstr(ent->d_name, ".xpm")==NULL) {
1038 continue;
1041 label = makeDraggableLabel(frame, ent->d_name,4+(j/4)*64, 4+(j%4)*64);
1043 j++;
1046 closedir(dir);
1048 WMMapSubwidgets(frame);
1050 WMMapSubwidgets(win);
1051 WMRealizeWidget(win);
1052 WMMapWidget(win);
1059 /*******************************************************************/
1061 #include "WUtil.h"
1063 void
1064 testUD()
1066 WMUserDefaults *defs;
1067 char str[32];
1069 defs = WMGetStandardUserDefaults();
1071 sprintf(str, "TEST DATA");
1072 puts(str);
1073 WMSetUDStringForKey(defs, str, "testKey");
1074 puts(str);
1079 main(int argc, char **argv)
1081 WMScreen *scr;
1082 WMPixmap *pixmap;
1085 /* Initialize the application */
1086 WMInitializeApplication("Test", &argc, argv);
1088 testUD();
1091 * Open connection to the X display.
1093 dpy = XOpenDisplay("");
1095 if (!dpy) {
1096 puts("could not open display");
1097 exit(1);
1100 /* This is used to disable buffering of X protocol requests.
1101 * Do NOT use it unless when debugging. It will cause a major
1102 * slowdown in your application
1104 #if 1
1105 XSynchronize(dpy, True);
1106 #endif
1108 * Create screen descriptor.
1110 scr = WMCreateScreen(dpy, DefaultScreen(dpy));
1113 * Loads the logo of the application.
1115 pixmap = WMCreatePixmapFromFile(scr, "logo.xpm");
1118 * Makes the logo be used in standard dialog panels.
1120 WMSetApplicationIconImage(scr, pixmap); WMReleasePixmap(pixmap);
1123 * Do some test stuff.
1125 * Put the testSomething() function you want to test here.
1128 testList(scr);
1129 testColorWell(scr);
1131 #if 0
1132 testTextField(scr);
1133 testText(scr);
1135 testDragAndDrop(scr);
1136 testDragAndDrop(scr);
1137 testFontPanel(scr);
1139 testScrollView(scr);
1141 testButton(scr);
1143 testFrame(scr);
1146 testTabView(scr);
1150 testSplitView(scr);
1152 testGradientButtons(scr);
1153 testProgressIndicator(scr);
1156 testOpenFilePanel(scr);
1158 testSlider(scr);
1159 testPullDown(scr);
1160 #endif
1162 * The main event loop.
1165 WMScreenMainLoop(scr);
1167 return 0;