added drag and drop
[wmaker-crm.git] / WINGs / wtest.c
blob4d97b02dd29cff8ba2c89969bc266fa51d60d556
1 /*
2 * WINGs test application
3 */
5 #include "WINGs.h"
7 #include <stdio.h>
12 * You need to define this function to link any program to WINGs.
13 * This will be called when the application will be terminated because
14 * on a fatal error.
16 void
17 wAbort()
19 exit(1);
25 Display *dpy;
27 int windowCount = 0;
29 void
30 closeAction(WMWidget *self, void *data)
32 WMDestroyWidget(self);
33 windowCount--;
34 if (windowCount < 1)
35 exit(0);
39 void
40 testOpenFilePanel(WMScreen *scr)
42 WMOpenPanel *panel;
44 windowCount++;
46 /* get the shared Open File panel */
47 panel = WMGetOpenPanel(scr);
49 WMRunModalFilePanelForDirectory(panel, NULL, "/usr/local", NULL, NULL);
51 /* free the panel to save some memory. Not needed otherwise. */
52 WMFreeFilePanel(WMGetOpenPanel(scr));
56 void
57 testFontPanel(WMScreen *scr)
59 WMFontPanel *panel;
61 windowCount++;
63 panel = WMGetFontPanel(scr);
65 WMShowFontPanel(panel);
67 /* WMFreeFontPanel(panel);*/
72 void
73 testList(WMScreen *scr)
75 WMWindow *win;
76 WMList *list;
77 char text[100];
78 int i;
80 windowCount++;
82 win = WMCreateWindow(scr, "testList");
83 WMSetWindowTitle(win, "List");
84 WMSetWindowCloseAction(win, closeAction, NULL);
86 list = WMCreateList(win);
87 for (i=0; i<50; i++) {
88 sprintf(text, "Item %i", i);
89 WMAddListItem(list, text);
91 WMRealizeWidget(win);
92 WMMapSubwidgets(win);
93 WMMapWidget(win);
99 void
100 testGradientButtons(WMScreen *scr)
102 WMWindow *win;
103 WMButton *btn;
104 WMPixmap *pix1, *pix2;
105 RImage *back;
106 RColor light, dark;
107 WMColor *color, *altColor;
109 windowCount++;
111 /* creates the top-level window */
112 win = WMCreateWindow(scr, "testGradientButtons");
113 WMSetWindowTitle(win, "Gradiented Button Demo");
114 WMResizeWidget(win, 300, 200);
116 light.red = 0x90;
117 light.green = 0x85;
118 light.blue = 0x90;
119 dark.red = 0x35;
120 dark.green = 0x30;
121 dark.blue = 0x35;
123 color = WMCreateRGBColor(scr, 0x5900, 0x5100, 0x5900, True);
124 WMSetWidgetBackgroundColor(win, color);
125 WMReleaseColor(color);
127 back = RRenderGradient(60, 24, &dark, &light, RGRD_DIAGONAL);
128 RBevelImage(back, RBEV_RAISED2);
129 pix1 = WMCreatePixmapFromRImage(scr, back, 0);
130 RDestroyImage(back);
132 back = RRenderGradient(60, 24, &dark, &light, RGRD_DIAGONAL);
133 RBevelImage(back, RBEV_SUNKEN);
134 pix2 = WMCreatePixmapFromRImage(scr, back, 0);
135 RDestroyImage(back);
137 color = WMWhiteColor(scr);
138 altColor = WMCreateNamedColor(scr, "red", True);
140 btn = WMCreateButton(win, WBTMomentaryChange);
141 WMResizeWidget(btn, 60, 24);
142 WMMoveWidget(btn, 20, 100);
143 WMSetButtonBordered(btn, False);
144 WMSetButtonImagePosition(btn, WIPOverlaps);
145 WMSetButtonImage(btn, pix1);
146 WMSetButtonAltImage(btn, pix2);
147 WMSetButtonText(btn, "Cool");
148 WMSetButtonTextColor(btn, color);
149 WMSetButtonAltTextColor(btn, altColor);
151 WMSetBalloonTextForView("This is a cool button", WMWidgetView(btn));
153 btn = WMCreateButton(win, WBTMomentaryChange);
154 WMResizeWidget(btn, 60, 24);
155 WMMoveWidget(btn, 90, 100);
156 WMSetButtonBordered(btn, False);
157 WMSetButtonImagePosition(btn, WIPOverlaps);
158 WMSetButtonImage(btn, pix1);
159 WMSetButtonAltImage(btn, pix2);
160 WMSetButtonText(btn, "Button");
161 WMSetButtonTextColor(btn, color);
163 WMSetBalloonTextForView("Este é outro balão.", WMWidgetView(btn));
165 WMReleaseColor(color);
166 color = WMCreateNamedColor(scr, "orange", True);
168 btn = WMCreateButton(win, WBTMomentaryChange);
169 WMResizeWidget(btn, 60, 24);
170 WMMoveWidget(btn, 160, 100);
171 WMSetButtonBordered(btn, False);
172 WMSetButtonImagePosition(btn, WIPOverlaps);
173 WMSetButtonImage(btn, pix1);
174 WMSetButtonAltImage(btn, pix2);
175 WMSetButtonText(btn, "Test");
176 WMSetButtonTextColor(btn, color);
178 WMSetBalloonTextForView("This is yet another button.\nBut the balloon has 3 lines.\nYay!",
179 WMWidgetView(btn));
181 WMReleaseColor(color);
182 WMReleaseColor(altColor);
184 WMRealizeWidget(win);
185 WMMapSubwidgets(win);
186 WMMapWidget(win);
190 void
191 testScrollView(WMScreen *scr)
193 WMWindow *win;
194 WMScrollView *sview;
195 WMFrame *f;
196 WMLabel *l;
197 char buffer[128];
198 int i;
200 windowCount++;
202 /* creates the top-level window */
203 win = WMCreateWindow(scr, "testScroll");
204 WMSetWindowTitle(win, "Scrollable View");
206 WMSetWindowCloseAction(win, closeAction, NULL);
208 /* set the window size */
209 WMResizeWidget(win, 300, 300);
211 /* creates a scrollable view inside the top-level window */
212 sview = WMCreateScrollView(win);
213 WMResizeWidget(sview, 200, 200);
214 WMMoveWidget(sview, 30, 30);
215 WMSetScrollViewRelief(sview, WRSunken);
216 WMSetScrollViewHasVerticalScroller(sview, True);
217 WMSetScrollViewHasHorizontalScroller(sview, True);
219 /* create a frame with a bunch of labels */
220 f = WMCreateFrame(win);
221 WMResizeWidget(f, 400, 400);
222 WMSetFrameRelief(f, WRFlat);
224 for (i=0; i<20; i++) {
225 l = WMCreateLabel(f);
226 WMResizeWidget(l, 50, 18);
227 WMMoveWidget(l, 10, 20*i);
228 sprintf(buffer, "Label %i", i);
229 WMSetLabelText(l, buffer);
230 WMSetLabelRelief(l, WRSimple);
232 WMMapSubwidgets(f);
233 WMMapWidget(f);
235 WMSetScrollViewContentView(sview, WMWidgetView(f));
237 /* make the windows of the widgets be actually created */
238 WMRealizeWidget(win);
240 /* Map all child widgets of the top-level be mapped.
241 * You must call this for each container widget (like frames),
242 * even if they are childs of the top-level window.
244 WMMapSubwidgets(win);
246 /* map the top-level window */
247 WMMapWidget(win);
251 void
252 testColorWell(WMScreen *scr)
254 WMWindow *win;
255 WMColorWell *well1, *well2;
257 windowCount++;
259 win = WMCreateWindow(scr, "testColor");
260 WMResizeWidget(win, 300, 300);
262 WMSetWindowCloseAction(win, closeAction, NULL);
264 well1 = WMCreateColorWell(win);
265 WMResizeWidget(well1, 60, 40);
266 WMMoveWidget(well1, 100, 100);
267 WMSetColorWellColor(well1, WMCreateRGBColor(scr, 0x8888, 0, 0x1111, True));
268 well2 = WMCreateColorWell(win);
269 WMResizeWidget(well2, 60, 40);
270 WMMoveWidget(well2, 200, 100);
271 WMSetColorWellColor(well2, WMCreateRGBColor(scr, 0, 0, 0x8888, True));
273 WMRealizeWidget(win);
274 WMMapSubwidgets(win);
275 WMMapWidget(win);
278 void
279 sliderCallback(WMWidget *w, void *data)
281 printf("SLIEDER == %i\n", WMGetSliderValue(w));
285 void
286 testSlider(WMScreen *scr)
288 WMWindow *win;
289 WMSlider *s;
291 windowCount++;
293 win = WMCreateWindow(scr, "testSlider");
294 WMResizeWidget(win, 300, 300);
295 WMSetWindowTitle(win, "Sliders");
297 WMSetWindowCloseAction(win, closeAction, NULL);
299 s = WMCreateSlider(win);
300 WMResizeWidget(s, 16, 100);
301 WMMoveWidget(s, 100, 100);
302 WMSetSliderKnobThickness(s, 8);
303 WMSetSliderContinuous(s, False);
304 WMSetSliderAction(s, sliderCallback, s);
306 s = WMCreateSlider(win);
307 WMResizeWidget(s, 100, 16);
308 WMMoveWidget(s, 100, 10);
309 WMSetSliderKnobThickness(s, 8);
311 WMRealizeWidget(win);
312 WMMapSubwidgets(win);
313 WMMapWidget(win);
317 void
318 testTextField(WMScreen *scr)
320 WMWindow *win;
321 WMTextField *field, *field2;
323 windowCount++;
325 win = WMCreateWindow(scr, "testText");
326 WMResizeWidget(win, 400, 300);
328 WMSetWindowCloseAction(win, closeAction, NULL);
330 field = WMCreateTextField(win);
331 WMResizeWidget(field, 200, 20);
332 WMMoveWidget(field, 20, 20);
334 field2 = WMCreateTextField(win);
335 WMResizeWidget(field2, 200, 20);
336 WMMoveWidget(field2, 20, 50);
337 WMSetTextFieldAlignment(field2, WARight);
339 WMRealizeWidget(win);
340 WMMapSubwidgets(win);
341 WMMapWidget(win);
346 void
347 testProgressIndicator(WMScreen *scr)
349 WMWindow *win;
350 WMProgressIndicator *pPtr;
352 windowCount++;
354 win = WMCreateWindow(scr, "testProgressIndicator");
355 WMResizeWidget(win, 292, 32);
357 WMSetWindowCloseAction(win, closeAction, NULL);
359 pPtr = WMCreateProgressIndicator(win);
360 WMMoveWidget(pPtr, 8, 8);
361 WMSetProgressIndicatorValue(pPtr, 75);
363 WMRealizeWidget(win);
364 WMMapSubwidgets(win);
365 WMMapWidget(win);
370 void
371 testPullDown(WMScreen *scr)
373 WMWindow *win;
374 WMPopUpButton *pop, *pop2;
376 windowCount++;
378 win = WMCreateWindow(scr, "pullDown");
379 WMResizeWidget(win, 400, 300);
381 WMSetWindowCloseAction(win, closeAction, NULL);
383 pop = WMCreatePopUpButton(win);
384 WMResizeWidget(pop, 100, 20);
385 WMMoveWidget(pop, 50, 60);
386 WMSetPopUpButtonPullsDown(pop, True);
387 WMSetPopUpButtonText(pop, "Commands");
388 WMAddPopUpButtonItem(pop, "Add");
389 WMAddPopUpButtonItem(pop, "Remove");
390 WMAddPopUpButtonItem(pop, "Check");
391 WMAddPopUpButtonItem(pop, "Eat");
393 pop2 = WMCreatePopUpButton(win);
394 WMResizeWidget(pop2, 100, 20);
395 WMMoveWidget(pop2, 200, 60);
396 WMSetPopUpButtonText(pop2, "Select");
397 WMAddPopUpButtonItem(pop2, "Apples");
398 WMAddPopUpButtonItem(pop2, "Bananas");
399 WMAddPopUpButtonItem(pop2, "Strawberries");
400 WMAddPopUpButtonItem(pop2, "Blueberries");
402 WMRealizeWidget(win);
403 WMMapSubwidgets(win);
404 WMMapWidget(win);
409 void
410 testTabView(WMScreen *scr)
412 WMWindow *win;
413 WMTabView *tabv;
414 WMTabViewItem *tab;
415 WMFrame *frame;
416 WMLabel *label;
418 windowCount++;
420 win = WMCreateWindow(scr, "testTabs");
421 WMResizeWidget(win, 400, 300);
423 WMSetWindowCloseAction(win, closeAction, NULL);
425 tabv = WMCreateTabView(win);
426 WMMoveWidget(tabv, 50, 50);
427 WMResizeWidget(tabv, 300, 200);
429 frame = WMCreateFrame(win);
430 WMSetFrameRelief(frame, WRFlat);
431 label = WMCreateLabel(frame);
432 WMResizeWidget(label, 100, 100);
433 WMSetLabelText(label, "Label 1");
434 WMMapWidget(label);
437 tab = WMCreateTabViewItemWithIdentifier(0);
438 WMSetTabViewItemView(tab, WMWidgetView(frame));
439 WMAddItemInTabView(tabv, tab);
440 WMSetTabViewItemLabel(tab, "Instances");
442 frame = WMCreateFrame(win);
443 WMSetFrameRelief(frame, WRFlat);
444 label = WMCreateLabel(frame);
445 WMResizeWidget(label, 40, 50);
446 WMSetLabelText(label, "Label 2");
447 WMMapWidget(label);
450 tab = WMCreateTabViewItemWithIdentifier(0);
451 WMSetTabViewItemView(tab, WMWidgetView(frame));
452 WMAddItemInTabView(tabv, tab);
453 WMSetTabViewItemLabel(tab, "Classes");
456 frame = WMCreateFrame(win);
457 WMSetFrameRelief(frame, WRFlat);
458 label = WMCreateLabel(frame);
459 WMResizeWidget(label, 100, 100);
460 WMMoveWidget(label, 60, 40);
461 WMSetLabelText(label, "Label 3");
462 WMMapWidget(label);
464 tab = WMCreateTabViewItemWithIdentifier(0);
465 WMSetTabViewItemView(tab, WMWidgetView(frame));
466 WMAddItemInTabView(tabv, tab);
467 WMSetTabViewItemLabel(tab, "Something");
470 frame = WMCreateFrame(win);
471 WMSetFrameRelief(frame, WRFlat);
472 label = WMCreateLabel(frame);
473 WMResizeWidget(label, 100, 100);
474 WMMoveWidget(label, 160, 40);
475 WMSetLabelText(label, "Label 4");
476 WMMapWidget(label);
478 tab = WMCreateTabViewItemWithIdentifier(0);
479 WMSetTabViewItemView(tab, WMWidgetView(frame));
480 WMAddItemInTabView(tabv, tab);
481 WMSetTabViewItemLabel(tab, "Bla!");
485 frame = WMCreateFrame(win);
486 WMSetFrameRelief(frame, WRFlat);
487 label = WMCreateLabel(frame);
488 WMResizeWidget(label, 100, 100);
489 WMMoveWidget(label, 160, 40);
490 WMSetLabelText(label, "Label fjweqklrj qwl");
491 WMMapWidget(label);
492 tab = WMCreateTabViewItemWithIdentifier(0);
493 WMSetTabViewItemView(tab, WMWidgetView(frame));
494 WMAddItemInTabView(tabv, tab);
495 WMSetTabViewItemLabel(tab, "Weee!");
498 WMRealizeWidget(win);
499 WMMapSubwidgets(win);
500 WMMapWidget(win);
504 void
505 splitViewConstrainProc(WMSplitView *sPtr, int indView,
506 int *minSize, int *maxSize)
508 switch (indView) {
509 case 0:
510 *minSize = 20;
511 break;
512 case 1:
513 *minSize = 40;
514 *maxSize = 80;
515 break;
516 case 2:
517 *maxSize = 60;
518 break;
519 default:
520 break;
525 static void
526 resizeSplitView(XEvent *event, void *data)
528 WMSplitView *sPtr = (WMSplitView*)data;
530 if (event->type == ConfigureNotify) {
531 int width = event->xconfigure.width - 10;
533 if (width < WMGetSplitViewDividerThickness(sPtr))
534 width = WMGetSplitViewDividerThickness(sPtr);
536 if (width != WMWidgetWidth(sPtr) ||
537 event->xconfigure.height != WMWidgetHeight(sPtr))
538 WMResizeWidget(sPtr, width, event->xconfigure.height - 55);
542 void
543 appendSubviewButtonAction(WMWidget *self, void *data)
545 WMSplitView *sPtr = (WMSplitView*)data;
546 char buf[64];
547 WMLabel *label = WMCreateLabel(sPtr);
549 sprintf(buf, "Subview %d", WMGetSplitViewSubviewsCount(sPtr) + 1);
550 WMSetLabelText(label, buf);
551 WMSetLabelRelief(label, WRSunken);
552 WMAddSplitViewSubview(sPtr, WMWidgetView(label));
553 WMRealizeWidget(label);
554 WMMapWidget(label);
557 void
558 removeSubviewButtonAction(WMWidget *self, void *data)
560 WMSplitView *sPtr = (WMSplitView*)data;
561 int count = WMGetSplitViewSubviewsCount(sPtr);
563 if (count > 2) {
564 WMView *view = WMGetSplitViewSubviewAt(sPtr, count-1);
565 WMDestroyWidget(WMWidgetOfView(view));
566 WMRemoveSplitViewSubviewAt(sPtr, count-1);
570 void
571 orientationButtonAction(WMWidget *self, void *data)
573 WMSplitView *sPtr = (WMSplitView*)data;
574 WMSetSplitViewVertical(sPtr, !WMGetSplitViewVertical(sPtr));
577 void
578 adjustSubviewsButtonAction(WMWidget *self, void *data)
580 WMAdjustSplitViewSubviews((WMSplitView*)data);
583 void
584 testSplitView(WMScreen *scr)
586 WMWindow *win;
587 WMSplitView *splitv1, *splitv2;
588 WMFrame *frame;
589 WMLabel *label;
590 WMButton *button;
592 windowCount++;
594 win = WMCreateWindow(scr, "testTabs");
595 WMResizeWidget(win, 300, 400);
596 WMSetWindowCloseAction(win, closeAction, NULL);
598 frame = WMCreateFrame(win);
599 WMSetFrameRelief(frame, WRSunken);
600 WMMoveWidget(frame, 5, 5);
601 WMResizeWidget(frame, 290, 40);
603 splitv1 = WMCreateSplitView(win);
604 WMMoveWidget(splitv1, 5, 50);
605 WMResizeWidget(splitv1, 290, 345);
606 WMSetSplitViewConstrainProc(splitv1, splitViewConstrainProc);
607 WMCreateEventHandler(WMWidgetView(win), StructureNotifyMask,
608 resizeSplitView, splitv1);
610 button = WMCreateCommandButton(frame);
611 WMSetButtonText(button, "+");
612 WMSetButtonAction(button, appendSubviewButtonAction, splitv1);
613 WMMoveWidget(button, 10, 8);
614 WMMapWidget(button);
616 button = WMCreateCommandButton(frame);
617 WMSetButtonText(button, "-");
618 WMSetButtonAction(button, removeSubviewButtonAction, splitv1);
619 WMMoveWidget(button, 80, 8);
620 WMMapWidget(button);
622 button = WMCreateCommandButton(frame);
623 WMSetButtonText(button, "=");
624 WMMoveWidget(button, 150, 8);
625 WMSetButtonAction(button, adjustSubviewsButtonAction, splitv1);
626 WMMapWidget(button);
628 button = WMCreateCommandButton(frame);
629 WMSetButtonText(button, "#");
630 WMMoveWidget(button, 220, 8);
631 WMSetButtonAction(button, orientationButtonAction, splitv1);
632 WMMapWidget(button);
634 label = WMCreateLabel(splitv1);
635 WMSetLabelText(label, "Subview 1");
636 WMSetLabelRelief(label, WRSunken);
637 WMMapWidget(label);
638 WMAddSplitViewSubview(splitv1, WMWidgetView(label));
640 splitv2 = WMCreateSplitView(splitv1);
641 WMResizeWidget(splitv2, 150, 150);
642 WMSetSplitViewVertical(splitv2, True);
644 label = WMCreateLabel(splitv2);
645 WMSetLabelText(label, "Subview 2.1");
646 WMSetLabelRelief(label, WRSunken);
647 WMMapWidget(label);
648 WMAddSplitViewSubview(splitv2, WMWidgetView(label));
650 label = WMCreateLabel(splitv2);
651 WMSetLabelText(label, "Subview 2.2");
652 WMSetLabelRelief(label, WRSunken);
653 WMMapWidget(label);
654 WMAddSplitViewSubview(splitv2, WMWidgetView(label));
656 label = WMCreateLabel(splitv2);
657 WMSetLabelText(label, "Subview 2.3");
658 WMSetLabelRelief(label, WRSunken);
659 WMMapWidget(label);
660 WMAddSplitViewSubview(splitv2, WMWidgetView(label));
662 WMMapWidget(splitv2);
663 WMAddSplitViewSubview(splitv1, WMWidgetView(splitv2));
665 WMRealizeWidget(win);
666 WMMapSubwidgets(win);
667 WMMapWidget(win);
671 /*******************************************************************/
673 #include <sys/types.h>
674 #include <dirent.h>
675 #include <string.h>
678 typedef struct {
679 int x, y;
680 Bool mouseDown;
681 char *filename;
682 } DNDStuff;
684 WMPixmap*
685 getImage(WMScreen *scr, char *file)
687 char buffer[1000];
688 WMPixmap *pix;
690 sprintf(buffer, "../WindowMaker/Icons/%s", file);
691 pix = WMCreatePixmapFromFile(scr, buffer);
693 return pix;
699 static void iconMouseStuff(XEvent *event, void *cdata)
701 WMLabel *label = (WMLabel*)cdata;
702 DNDStuff *stuff = WMGetHangedData(label);
703 WMPoint where;
705 switch (event->type) {
706 case ButtonPress:
707 stuff->x = event->xbutton.x_root;
708 stuff->y = event->xbutton.y_root;
709 stuff->mouseDown = True;
710 break;
711 case ButtonRelease:
712 stuff->mouseDown = False;
713 break;
714 case MotionNotify:
715 if (!stuff->mouseDown)
716 break;
718 if (abs(stuff->x - event->xmotion.x_root)>4
719 || abs(stuff->y - event->xmotion.y_root)>4) {
721 where = WMGetViewScreenPosition(WMWidgetView(label));
723 WMDragImageFromView(WMWidgetView(label),
724 WMGetLabelImage(label),
725 NULL, /* XXX */
726 where,
727 wmksize(event->xmotion.x, event->xmotion.y),
728 event, True);
730 break;
735 static void endedDragImage(WMView *self, WMPixmap *image, WMPoint point,
736 Bool deposited)
738 DNDStuff *stuff = WMGetHangedData(WMWidgetOfView(self));
740 if (deposited) {
741 WMDestroyWidget(WMWidgetOfView(self));
744 stuff->mouseDown = False;
748 static WMData* fetchDragData(WMView *self, char *type)
750 DNDStuff *stuff = WMGetHangedData(WMWidgetOfView(self));
752 return WMCreateDataWithBytes(stuff->filename, strlen(stuff->filename)+1);
756 WMDragSourceProcs dragSourceProcs = {
757 NULL,
758 NULL,
759 endedDragImage,
760 fetchDragData
764 /************************/
767 unsigned draggingEntered(WMView *self, WMDraggingInfo *info)
769 return WDOperationCopy;
773 unsigned draggingUpdated(WMView *self, WMDraggingInfo *info)
775 return WDOperationCopy;
779 void (*draggingExited)(WMView *self, WMDraggingInfo *info);
781 char *prepareForDragOperation(WMView *self, WMDraggingInfo *info)
783 return "application/X-WINGs-Bla";
787 WMLabel *makeDraggableLabel(WMWidget *w, char *file, int x, int y);
789 Bool performDragOperation(WMView *self, WMDraggingInfo *info,
790 WMData *data)
792 char *file = (char*)WMDataBytes(data);
793 WMPoint pos;
795 pos = WMGetDraggingInfoImageLocation(info);
797 if (file!=NULL) {
798 WMLabel *label;
799 WMPoint pos2 = WMGetViewScreenPosition(self);
802 label = makeDraggableLabel(WMWidgetOfView(self), file,
803 pos.x-pos2.x, pos.y-pos2.y);
804 WMRealizeWidget(label);
805 WMMapWidget(label);
809 return True;
813 void concludeDragOperation(WMView *self, WMDraggingInfo *info)
815 puts("concluded");
821 WMDragDestinationProcs dragDestProcs = {
822 draggingEntered,
823 draggingUpdated,
824 NULL,
825 prepareForDragOperation,
826 performDragOperation,
827 concludeDragOperation
833 WMLabel*
834 makeDraggableLabel(WMWidget *w, char *file, int x, int y)
836 DNDStuff *stuff;
837 WMLabel *label;
838 WMPixmap *image = getImage(WMWidgetScreen(w), file);
840 stuff = wmalloc(sizeof(DNDStuff));
841 stuff->mouseDown = False;
843 stuff->filename = wstrdup(file);
845 label = WMCreateLabel(w);
846 WMResizeWidget(label, 48, 48);
847 WMMoveWidget(label, x, y);
849 WMSetViewDragSourceProcs(WMWidgetView(label), &dragSourceProcs);
851 WMHangData(label, stuff);
853 WMCreateEventHandler(WMWidgetView(label),
854 ButtonPressMask|ButtonReleaseMask|ButtonMotionMask,
855 iconMouseStuff, label);
858 WMSetLabelImagePosition(label, WIPImageOnly);
859 WMSetLabelImage(label, image);
860 WMReleasePixmap(image);
862 return label;
867 void testDragAndDrop(WMScreen *scr)
869 WMWindow *win;
870 WMFrame *frame;
871 WMLabel *label;
872 int i, j;
873 DIR *dir;
874 struct dirent *ent;
875 char *types[] = {
876 "application/X-WINGs-Bla",
877 NULL
880 windowCount++;
882 win = WMCreateWindow(scr, "dragDrop");
883 WMResizeWidget(win, 300, 300);
884 WMSetWindowCloseAction(win, closeAction, NULL);
885 WMSetWindowTitle(win, "Drag and Drop");
888 frame = WMCreateFrame(win);
889 WMSetFrameRelief(frame, WRSunken);
890 WMResizeWidget(frame, 250, 250);
891 WMMoveWidget(frame, 25, 25);
893 WMRegisterViewForDraggedTypes(WMWidgetView(frame), types);
894 WMSetViewDragDestinationProcs(WMWidgetView(frame), &dragDestProcs);
896 dir = opendir("../WindowMaker/Icons");
897 if (!dir) {
898 perror("../WindowMaker/Icons");
899 return;
902 for (i = 0, j=0; j < 8; i++) {
903 ent = readdir(dir);
904 if (!ent)
905 break;
907 if (strstr(ent->d_name, ".xpm")==NULL) {
908 continue;
911 label = makeDraggableLabel(frame, ent->d_name,4+(j/4)*64, 4+(j%4)*64);
913 j++;
916 closedir(dir);
918 WMMapSubwidgets(frame);
920 WMMapSubwidgets(win);
921 WMRealizeWidget(win);
922 WMMapWidget(win);
929 /*******************************************************************/
931 #include "WUtil.h"
935 int main(int argc, char **argv)
937 WMScreen *scr;
938 WMPixmap *pixmap;
941 /* Initialize the application */
942 WMInitializeApplication("Test", &argc, argv);
945 * Open connection to the X display.
947 dpy = XOpenDisplay("");
949 if (!dpy) {
950 puts("could not open display");
951 exit(1);
954 /* This is used to disable buffering of X protocol requests.
955 * Do NOT use it unless when debugging. It will cause a major
956 * slowdown in your application
958 #ifdef DEBUG
959 XSynchronize(dpy, True);
960 #endif
962 * Create screen descriptor.
964 scr = WMCreateScreen(dpy, DefaultScreen(dpy));
967 * Loads the logo of the application.
969 pixmap = WMCreatePixmapFromFile(scr, "logo.xpm");
972 * Makes the logo be used in standard dialog panels.
974 WMSetApplicationIconImage(scr, pixmap); WMReleasePixmap(pixmap);
977 * Do some test stuff.
979 * Put the testSomething() function you want to test here.
983 testDragAndDrop(scr);
984 testDragAndDrop(scr);
986 #if 0
987 testColorWell(scr);
989 testTabView(scr);
991 testFontPanel(scr);
993 testSplitView(scr);
995 testGradientButtons(scr);
996 testProgressIndicator(scr);
998 testTextField(scr);
1000 testOpenFilePanel(scr);
1001 testList(scr);
1002 testScrollView(scr);
1005 testSlider(scr);
1006 testPullDown(scr);
1007 #endif
1009 * The main event loop.
1012 WMScreenMainLoop(scr);
1014 return 0;