added quick&dirty game
[wmaker-crm.git] / WINGs / wtest.c
blob8676505cf62202c26dc195827ca49dc569f50ce4
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 testFrame(WMScreen *scr)
75 WMWindow *win;
76 WMFrame *frame;
77 int i;
78 static char* titles[] = {
79 "AboveTop",
80 "AtTop",
81 "BelowTop",
82 "AboveBottom",
83 "AtBottom",
84 "BelowBottom"
86 static WMTitlePosition pos[] = {
87 WTPAboveTop,
88 WTPAtTop,
89 WTPBelowTop,
90 WTPAboveBottom,
91 WTPAtBottom,
92 WTPBelowBottom
95 windowCount++;
97 win = WMCreateWindow(scr, "testFrame");
98 WMSetWindowTitle(win, "Frame");
99 WMSetWindowCloseAction(win, closeAction, NULL);
100 WMResizeWidget(win, 400, 300);
102 for (i = 0; i < 6; i++) {
103 frame = WMCreateFrame(win);
104 WMMoveWidget(frame, 8+(i%3)*130, 8+(i/3)*130);
105 WMResizeWidget(frame, 120, 120);
106 WMSetFrameTitle(frame, titles[i]);
107 WMSetFrameTitlePosition(frame, pos[i]);
110 WMRealizeWidget(win);
111 WMMapSubwidgets(win);
112 WMMapWidget(win);
116 void
117 testList(WMScreen *scr)
119 WMWindow *win;
120 WMList *list;
121 char text[100];
122 int i;
124 windowCount++;
126 win = WMCreateWindow(scr, "testList");
127 WMSetWindowTitle(win, "List");
128 WMSetWindowCloseAction(win, closeAction, NULL);
130 list = WMCreateList(win);
131 for (i=0; i<50; i++) {
132 sprintf(text, "Item %i", i);
133 WMAddListItem(list, text);
135 WMRealizeWidget(win);
136 WMMapSubwidgets(win);
137 WMMapWidget(win);
143 void
144 testGradientButtons(WMScreen *scr)
146 WMWindow *win;
147 WMButton *btn;
148 WMPixmap *pix1, *pix2;
149 RImage *back;
150 RColor light, dark;
151 WMColor *color, *altColor;
153 windowCount++;
155 /* creates the top-level window */
156 win = WMCreateWindow(scr, "testGradientButtons");
157 WMSetWindowTitle(win, "Gradiented Button Demo");
158 WMResizeWidget(win, 300, 200);
160 light.red = 0x90;
161 light.green = 0x85;
162 light.blue = 0x90;
163 dark.red = 0x35;
164 dark.green = 0x30;
165 dark.blue = 0x35;
167 color = WMCreateRGBColor(scr, 0x5900, 0x5100, 0x5900, True);
168 WMSetWidgetBackgroundColor(win, color);
169 WMReleaseColor(color);
171 back = RRenderGradient(60, 24, &dark, &light, RGRD_DIAGONAL);
172 RBevelImage(back, RBEV_RAISED2);
173 pix1 = WMCreatePixmapFromRImage(scr, back, 0);
174 RDestroyImage(back);
176 back = RRenderGradient(60, 24, &dark, &light, RGRD_DIAGONAL);
177 RBevelImage(back, RBEV_SUNKEN);
178 pix2 = WMCreatePixmapFromRImage(scr, back, 0);
179 RDestroyImage(back);
181 color = WMWhiteColor(scr);
182 altColor = WMCreateNamedColor(scr, "red", True);
184 btn = WMCreateButton(win, WBTMomentaryChange);
185 WMResizeWidget(btn, 60, 24);
186 WMMoveWidget(btn, 20, 100);
187 WMSetButtonBordered(btn, False);
188 WMSetButtonImagePosition(btn, WIPOverlaps);
189 WMSetButtonImage(btn, pix1);
190 WMSetButtonAltImage(btn, pix2);
191 WMSetButtonText(btn, "Cool");
192 WMSetButtonTextColor(btn, color);
193 WMSetButtonAltTextColor(btn, altColor);
195 WMSetBalloonTextForView("This is a cool button", WMWidgetView(btn));
197 btn = WMCreateButton(win, WBTMomentaryChange);
198 WMResizeWidget(btn, 60, 24);
199 WMMoveWidget(btn, 90, 100);
200 WMSetButtonBordered(btn, False);
201 WMSetButtonImagePosition(btn, WIPOverlaps);
202 WMSetButtonImage(btn, pix1);
203 WMSetButtonAltImage(btn, pix2);
204 WMSetButtonText(btn, "Button");
205 WMSetButtonTextColor(btn, color);
207 WMSetBalloonTextForView("Este é outro balão.", WMWidgetView(btn));
209 WMReleaseColor(color);
210 color = WMCreateNamedColor(scr, "orange", True);
212 btn = WMCreateButton(win, WBTMomentaryChange);
213 WMResizeWidget(btn, 60, 24);
214 WMMoveWidget(btn, 160, 100);
215 WMSetButtonBordered(btn, False);
216 WMSetButtonImagePosition(btn, WIPOverlaps);
217 WMSetButtonImage(btn, pix1);
218 WMSetButtonAltImage(btn, pix2);
219 WMSetButtonText(btn, "Test");
220 WMSetButtonTextColor(btn, color);
222 WMSetBalloonTextForView("This is yet another button.\nBut the balloon has 3 lines.\nYay!",
223 WMWidgetView(btn));
225 WMReleaseColor(color);
226 WMReleaseColor(altColor);
228 WMRealizeWidget(win);
229 WMMapSubwidgets(win);
230 WMMapWidget(win);
234 void
235 testScrollView(WMScreen *scr)
237 WMWindow *win;
238 WMScrollView *sview;
239 WMFrame *f;
240 WMLabel *l;
241 char buffer[128];
242 int i;
244 windowCount++;
246 /* creates the top-level window */
247 win = WMCreateWindow(scr, "testScroll");
248 WMSetWindowTitle(win, "Scrollable View");
250 WMSetWindowCloseAction(win, closeAction, NULL);
252 /* set the window size */
253 WMResizeWidget(win, 300, 300);
255 /* creates a scrollable view inside the top-level window */
256 sview = WMCreateScrollView(win);
257 WMResizeWidget(sview, 200, 200);
258 WMMoveWidget(sview, 30, 30);
259 WMSetScrollViewRelief(sview, WRSunken);
260 WMSetScrollViewHasVerticalScroller(sview, True);
261 WMSetScrollViewHasHorizontalScroller(sview, True);
263 /* create a frame with a bunch of labels */
264 f = WMCreateFrame(win);
265 WMResizeWidget(f, 400, 400);
266 WMSetFrameRelief(f, WRFlat);
268 for (i=0; i<20; i++) {
269 l = WMCreateLabel(f);
270 WMResizeWidget(l, 50, 18);
271 WMMoveWidget(l, 10, 20*i);
272 sprintf(buffer, "Label %i", i);
273 WMSetLabelText(l, buffer);
274 WMSetLabelRelief(l, WRSimple);
276 WMMapSubwidgets(f);
277 WMMapWidget(f);
279 WMSetScrollViewContentView(sview, WMWidgetView(f));
281 /* make the windows of the widgets be actually created */
282 WMRealizeWidget(win);
284 /* Map all child widgets of the top-level be mapped.
285 * You must call this for each container widget (like frames),
286 * even if they are childs of the top-level window.
288 WMMapSubwidgets(win);
290 /* map the top-level window */
291 WMMapWidget(win);
295 void
296 testColorWell(WMScreen *scr)
298 WMWindow *win;
299 WMColorWell *well1, *well2;
301 windowCount++;
303 win = WMCreateWindow(scr, "testColor");
304 WMResizeWidget(win, 300, 300);
306 WMSetWindowCloseAction(win, closeAction, NULL);
308 well1 = WMCreateColorWell(win);
309 WMResizeWidget(well1, 60, 40);
310 WMMoveWidget(well1, 100, 100);
311 WMSetColorWellColor(well1, WMCreateRGBColor(scr, 0x8888, 0, 0x1111, True));
312 well2 = WMCreateColorWell(win);
313 WMResizeWidget(well2, 60, 40);
314 WMMoveWidget(well2, 200, 100);
315 WMSetColorWellColor(well2, WMCreateRGBColor(scr, 0, 0, 0x8888, True));
317 WMRealizeWidget(win);
318 WMMapSubwidgets(win);
319 WMMapWidget(win);
322 void
323 sliderCallback(WMWidget *w, void *data)
325 printf("SLIEDER == %i\n", WMGetSliderValue(w));
329 void
330 testSlider(WMScreen *scr)
332 WMWindow *win;
333 WMSlider *s;
335 windowCount++;
337 win = WMCreateWindow(scr, "testSlider");
338 WMResizeWidget(win, 300, 300);
339 WMSetWindowTitle(win, "Sliders");
341 WMSetWindowCloseAction(win, closeAction, NULL);
343 s = WMCreateSlider(win);
344 WMResizeWidget(s, 16, 100);
345 WMMoveWidget(s, 100, 100);
346 WMSetSliderKnobThickness(s, 8);
347 WMSetSliderContinuous(s, False);
348 WMSetSliderAction(s, sliderCallback, s);
350 s = WMCreateSlider(win);
351 WMResizeWidget(s, 100, 16);
352 WMMoveWidget(s, 100, 10);
353 WMSetSliderKnobThickness(s, 8);
355 WMRealizeWidget(win);
356 WMMapSubwidgets(win);
357 WMMapWidget(win);
361 void
362 testTextField(WMScreen *scr)
364 WMWindow *win;
365 WMTextField *field, *field2;
367 windowCount++;
369 win = WMCreateWindow(scr, "testText");
370 WMResizeWidget(win, 400, 300);
372 WMSetWindowCloseAction(win, closeAction, NULL);
374 field = WMCreateTextField(win);
375 WMResizeWidget(field, 200, 20);
376 WMMoveWidget(field, 20, 20);
378 field2 = WMCreateTextField(win);
379 WMResizeWidget(field2, 200, 20);
380 WMMoveWidget(field2, 20, 50);
381 WMSetTextFieldAlignment(field2, WARight);
383 WMRealizeWidget(win);
384 WMMapSubwidgets(win);
385 WMMapWidget(win);
390 void
391 testProgressIndicator(WMScreen *scr)
393 WMWindow *win;
394 WMProgressIndicator *pPtr;
396 windowCount++;
398 win = WMCreateWindow(scr, "testProgressIndicator");
399 WMResizeWidget(win, 292, 32);
401 WMSetWindowCloseAction(win, closeAction, NULL);
403 pPtr = WMCreateProgressIndicator(win);
404 WMMoveWidget(pPtr, 8, 8);
405 WMSetProgressIndicatorValue(pPtr, 75);
407 WMRealizeWidget(win);
408 WMMapSubwidgets(win);
409 WMMapWidget(win);
414 void
415 testPullDown(WMScreen *scr)
417 WMWindow *win;
418 WMPopUpButton *pop, *pop2;
420 windowCount++;
422 win = WMCreateWindow(scr, "pullDown");
423 WMResizeWidget(win, 400, 300);
425 WMSetWindowCloseAction(win, closeAction, NULL);
427 pop = WMCreatePopUpButton(win);
428 WMResizeWidget(pop, 100, 20);
429 WMMoveWidget(pop, 50, 60);
430 WMSetPopUpButtonPullsDown(pop, True);
431 WMSetPopUpButtonText(pop, "Commands");
432 WMAddPopUpButtonItem(pop, "Add");
433 WMAddPopUpButtonItem(pop, "Remove");
434 WMAddPopUpButtonItem(pop, "Check");
435 WMAddPopUpButtonItem(pop, "Eat");
437 pop2 = WMCreatePopUpButton(win);
438 WMResizeWidget(pop2, 100, 20);
439 WMMoveWidget(pop2, 200, 60);
440 WMSetPopUpButtonText(pop2, "Select");
441 WMAddPopUpButtonItem(pop2, "Apples");
442 WMAddPopUpButtonItem(pop2, "Bananas");
443 WMAddPopUpButtonItem(pop2, "Strawberries");
444 WMAddPopUpButtonItem(pop2, "Blueberries");
446 WMRealizeWidget(win);
447 WMMapSubwidgets(win);
448 WMMapWidget(win);
453 void
454 testTabView(WMScreen *scr)
456 WMWindow *win;
457 WMTabView *tabv;
458 WMTabViewItem *tab;
459 WMFrame *frame;
460 WMLabel *label;
462 windowCount++;
464 win = WMCreateWindow(scr, "testTabs");
465 WMResizeWidget(win, 400, 300);
467 WMSetWindowCloseAction(win, closeAction, NULL);
469 tabv = WMCreateTabView(win);
470 WMMoveWidget(tabv, 50, 50);
471 WMResizeWidget(tabv, 300, 200);
473 frame = WMCreateFrame(win);
474 WMSetFrameRelief(frame, WRFlat);
475 label = WMCreateLabel(frame);
476 WMResizeWidget(label, 100, 100);
477 WMSetLabelText(label, "Label 1");
478 WMMapWidget(label);
481 tab = WMCreateTabViewItemWithIdentifier(0);
482 WMSetTabViewItemView(tab, WMWidgetView(frame));
483 WMAddItemInTabView(tabv, tab);
484 WMSetTabViewItemLabel(tab, "Instances");
486 frame = WMCreateFrame(win);
487 WMSetFrameRelief(frame, WRFlat);
488 label = WMCreateLabel(frame);
489 WMResizeWidget(label, 40, 50);
490 WMSetLabelText(label, "Label 2");
491 WMMapWidget(label);
494 tab = WMCreateTabViewItemWithIdentifier(0);
495 WMSetTabViewItemView(tab, WMWidgetView(frame));
496 WMAddItemInTabView(tabv, tab);
497 WMSetTabViewItemLabel(tab, "Classes");
500 frame = WMCreateFrame(win);
501 WMSetFrameRelief(frame, WRFlat);
502 label = WMCreateLabel(frame);
503 WMResizeWidget(label, 100, 100);
504 WMMoveWidget(label, 60, 40);
505 WMSetLabelText(label, "Label 3");
506 WMMapWidget(label);
508 tab = WMCreateTabViewItemWithIdentifier(0);
509 WMSetTabViewItemView(tab, WMWidgetView(frame));
510 WMAddItemInTabView(tabv, tab);
511 WMSetTabViewItemLabel(tab, "Something");
514 frame = WMCreateFrame(win);
515 WMSetFrameRelief(frame, WRFlat);
516 label = WMCreateLabel(frame);
517 WMResizeWidget(label, 100, 100);
518 WMMoveWidget(label, 160, 40);
519 WMSetLabelText(label, "Label 4");
520 WMMapWidget(label);
522 tab = WMCreateTabViewItemWithIdentifier(0);
523 WMSetTabViewItemView(tab, WMWidgetView(frame));
524 WMAddItemInTabView(tabv, tab);
525 WMSetTabViewItemLabel(tab, "Bla!");
529 frame = WMCreateFrame(win);
530 WMSetFrameRelief(frame, WRFlat);
531 label = WMCreateLabel(frame);
532 WMResizeWidget(label, 100, 100);
533 WMMoveWidget(label, 160, 40);
534 WMSetLabelText(label, "Label fjweqklrj qwl");
535 WMMapWidget(label);
536 tab = WMCreateTabViewItemWithIdentifier(0);
537 WMSetTabViewItemView(tab, WMWidgetView(frame));
538 WMAddItemInTabView(tabv, tab);
539 WMSetTabViewItemLabel(tab, "Weee!");
542 WMRealizeWidget(win);
543 WMMapSubwidgets(win);
544 WMMapWidget(win);
548 void
549 splitViewConstrainProc(WMSplitView *sPtr, int indView,
550 int *minSize, int *maxSize)
552 switch (indView) {
553 case 0:
554 *minSize = 20;
555 break;
556 case 1:
557 *minSize = 40;
558 *maxSize = 80;
559 break;
560 case 2:
561 *maxSize = 60;
562 break;
563 default:
564 break;
569 static void
570 resizeSplitView(XEvent *event, void *data)
572 WMSplitView *sPtr = (WMSplitView*)data;
574 if (event->type == ConfigureNotify) {
575 int width = event->xconfigure.width - 10;
577 if (width < WMGetSplitViewDividerThickness(sPtr))
578 width = WMGetSplitViewDividerThickness(sPtr);
580 if (width != WMWidgetWidth(sPtr) ||
581 event->xconfigure.height != WMWidgetHeight(sPtr))
582 WMResizeWidget(sPtr, width, event->xconfigure.height - 55);
586 void
587 appendSubviewButtonAction(WMWidget *self, void *data)
589 WMSplitView *sPtr = (WMSplitView*)data;
590 char buf[64];
591 WMLabel *label = WMCreateLabel(sPtr);
593 sprintf(buf, "Subview %d", WMGetSplitViewSubviewsCount(sPtr) + 1);
594 WMSetLabelText(label, buf);
595 WMSetLabelRelief(label, WRSunken);
596 WMAddSplitViewSubview(sPtr, WMWidgetView(label));
597 WMRealizeWidget(label);
598 WMMapWidget(label);
601 void
602 removeSubviewButtonAction(WMWidget *self, void *data)
604 WMSplitView *sPtr = (WMSplitView*)data;
605 int count = WMGetSplitViewSubviewsCount(sPtr);
607 if (count > 2) {
608 WMView *view = WMGetSplitViewSubviewAt(sPtr, count-1);
609 WMDestroyWidget(WMWidgetOfView(view));
610 WMRemoveSplitViewSubviewAt(sPtr, count-1);
614 void
615 orientationButtonAction(WMWidget *self, void *data)
617 WMSplitView *sPtr = (WMSplitView*)data;
618 WMSetSplitViewVertical(sPtr, !WMGetSplitViewVertical(sPtr));
621 void
622 adjustSubviewsButtonAction(WMWidget *self, void *data)
624 WMAdjustSplitViewSubviews((WMSplitView*)data);
627 void
628 testSplitView(WMScreen *scr)
630 WMWindow *win;
631 WMSplitView *splitv1, *splitv2;
632 WMFrame *frame;
633 WMLabel *label;
634 WMButton *button;
636 windowCount++;
638 win = WMCreateWindow(scr, "testTabs");
639 WMResizeWidget(win, 300, 400);
640 WMSetWindowCloseAction(win, closeAction, NULL);
642 frame = WMCreateFrame(win);
643 WMSetFrameRelief(frame, WRSunken);
644 WMMoveWidget(frame, 5, 5);
645 WMResizeWidget(frame, 290, 40);
647 splitv1 = WMCreateSplitView(win);
648 WMMoveWidget(splitv1, 5, 50);
649 WMResizeWidget(splitv1, 290, 345);
650 WMSetSplitViewConstrainProc(splitv1, splitViewConstrainProc);
651 WMCreateEventHandler(WMWidgetView(win), StructureNotifyMask,
652 resizeSplitView, splitv1);
654 button = WMCreateCommandButton(frame);
655 WMSetButtonText(button, "+");
656 WMSetButtonAction(button, appendSubviewButtonAction, splitv1);
657 WMMoveWidget(button, 10, 8);
658 WMMapWidget(button);
660 button = WMCreateCommandButton(frame);
661 WMSetButtonText(button, "-");
662 WMSetButtonAction(button, removeSubviewButtonAction, splitv1);
663 WMMoveWidget(button, 80, 8);
664 WMMapWidget(button);
666 button = WMCreateCommandButton(frame);
667 WMSetButtonText(button, "=");
668 WMMoveWidget(button, 150, 8);
669 WMSetButtonAction(button, adjustSubviewsButtonAction, splitv1);
670 WMMapWidget(button);
672 button = WMCreateCommandButton(frame);
673 WMSetButtonText(button, "#");
674 WMMoveWidget(button, 220, 8);
675 WMSetButtonAction(button, orientationButtonAction, splitv1);
676 WMMapWidget(button);
678 label = WMCreateLabel(splitv1);
679 WMSetLabelText(label, "Subview 1");
680 WMSetLabelRelief(label, WRSunken);
681 WMMapWidget(label);
682 WMAddSplitViewSubview(splitv1, WMWidgetView(label));
684 splitv2 = WMCreateSplitView(splitv1);
685 WMResizeWidget(splitv2, 150, 150);
686 WMSetSplitViewVertical(splitv2, True);
688 label = WMCreateLabel(splitv2);
689 WMSetLabelText(label, "Subview 2.1");
690 WMSetLabelRelief(label, WRSunken);
691 WMMapWidget(label);
692 WMAddSplitViewSubview(splitv2, WMWidgetView(label));
694 label = WMCreateLabel(splitv2);
695 WMSetLabelText(label, "Subview 2.2");
696 WMSetLabelRelief(label, WRSunken);
697 WMMapWidget(label);
698 WMAddSplitViewSubview(splitv2, WMWidgetView(label));
700 label = WMCreateLabel(splitv2);
701 WMSetLabelText(label, "Subview 2.3");
702 WMSetLabelRelief(label, WRSunken);
703 WMMapWidget(label);
704 WMAddSplitViewSubview(splitv2, WMWidgetView(label));
706 WMMapWidget(splitv2);
707 WMAddSplitViewSubview(splitv1, WMWidgetView(splitv2));
709 WMRealizeWidget(win);
710 WMMapSubwidgets(win);
711 WMMapWidget(win);
715 /*******************************************************************/
717 #include <sys/types.h>
718 #include <dirent.h>
719 #include <string.h>
722 typedef struct {
723 int x, y;
724 Bool mouseDown;
725 char *filename;
726 } DNDStuff;
728 WMPixmap*
729 getImage(WMScreen *scr, char *file)
731 char buffer[1000];
732 WMPixmap *pix;
734 sprintf(buffer, "../WindowMaker/Icons/%s", file);
735 pix = WMCreatePixmapFromFile(scr, buffer);
737 return pix;
743 static void iconMouseStuff(XEvent *event, void *cdata)
745 WMLabel *label = (WMLabel*)cdata;
746 DNDStuff *stuff = WMGetHangedData(label);
747 WMPoint where;
749 switch (event->type) {
750 case ButtonPress:
751 stuff->x = event->xbutton.x;
752 stuff->y = event->xbutton.y;
753 stuff->mouseDown = True;
754 break;
755 case ButtonRelease:
756 stuff->mouseDown = False;
757 break;
758 case MotionNotify:
759 if (!stuff->mouseDown)
760 break;
762 if (abs(stuff->x - event->xmotion.x)>4
763 || abs(stuff->y - event->xmotion.y)>4) {
765 where = WMGetViewScreenPosition(WMWidgetView(label));
767 WMDragImageFromView(WMWidgetView(label),
768 WMGetLabelImage(label),
769 NULL, /* XXX */
770 where,
771 wmksize(stuff->x, stuff->y),
772 event, True);
774 break;
779 static void endedDragImage(WMView *self, WMPixmap *image, WMPoint point,
780 Bool deposited)
782 DNDStuff *stuff = WMGetHangedData(WMWidgetOfView(self));
784 if (deposited) {
785 WMDestroyWidget(WMWidgetOfView(self));
788 stuff->mouseDown = False;
792 static WMData* fetchDragData(WMView *self, char *type)
794 DNDStuff *stuff = WMGetHangedData(WMWidgetOfView(self));
796 return WMCreateDataWithBytes(stuff->filename, strlen(stuff->filename)+1);
800 WMDragSourceProcs dragSourceProcs = {
801 NULL,
802 NULL,
803 endedDragImage,
804 fetchDragData
808 /************************/
811 unsigned draggingEntered(WMView *self, WMDraggingInfo *info)
813 return WDOperationCopy;
817 unsigned draggingUpdated(WMView *self, WMDraggingInfo *info)
819 return WDOperationCopy;
823 void (*draggingExited)(WMView *self, WMDraggingInfo *info);
825 char *prepareForDragOperation(WMView *self, WMDraggingInfo *info)
827 return "application/X-WINGs-Bla";
831 WMLabel *makeDraggableLabel(WMWidget *w, char *file, int x, int y);
833 Bool performDragOperation(WMView *self, WMDraggingInfo *info,
834 WMData *data)
836 char *file = (char*)WMDataBytes(data);
837 WMPoint pos;
839 pos = WMGetDraggingInfoImageLocation(info);
841 if (file!=NULL) {
842 WMLabel *label;
843 WMPoint pos2 = WMGetViewScreenPosition(self);
846 label = makeDraggableLabel(WMWidgetOfView(self), file,
847 pos.x-pos2.x, pos.y-pos2.y);
848 WMRealizeWidget(label);
849 WMMapWidget(label);
853 return True;
857 void concludeDragOperation(WMView *self, WMDraggingInfo *info)
864 WMDragDestinationProcs dragDestProcs = {
865 draggingEntered,
866 draggingUpdated,
867 NULL,
868 prepareForDragOperation,
869 performDragOperation,
870 concludeDragOperation
876 WMLabel*
877 makeDraggableLabel(WMWidget *w, char *file, int x, int y)
879 DNDStuff *stuff;
880 WMLabel *label;
881 WMPixmap *image = getImage(WMWidgetScreen(w), file);
883 stuff = wmalloc(sizeof(DNDStuff));
884 stuff->mouseDown = False;
886 stuff->filename = wstrdup(file);
888 label = WMCreateLabel(w);
889 WMResizeWidget(label, 48, 48);
890 WMMoveWidget(label, x, y);
892 WMSetViewDragSourceProcs(WMWidgetView(label), &dragSourceProcs);
894 WMHangData(label, stuff);
896 WMCreateEventHandler(WMWidgetView(label),
897 ButtonPressMask|ButtonReleaseMask|ButtonMotionMask,
898 iconMouseStuff, label);
901 if (image != NULL) {
902 WMSetLabelImagePosition(label, WIPImageOnly);
903 WMSetLabelImage(label, image);
904 WMReleasePixmap(image);
905 } else puts(file);
907 return label;
912 void testDragAndDrop(WMScreen *scr)
914 WMWindow *win;
915 WMFrame *frame;
916 WMLabel *label;
917 int i, j;
918 DIR *dir;
919 struct dirent *ent;
920 char *types[] = {
921 "application/X-WINGs-Bla",
922 NULL
925 windowCount++;
927 win = WMCreateWindow(scr, "dragDrop");
928 WMResizeWidget(win, 300, 300);
929 WMSetWindowCloseAction(win, closeAction, NULL);
930 WMSetWindowTitle(win, "Drag and Drop");
933 frame = WMCreateFrame(win);
934 WMSetFrameRelief(frame, WRSunken);
935 WMResizeWidget(frame, 250, 250);
936 WMMoveWidget(frame, 25, 25);
938 WMRegisterViewForDraggedTypes(WMWidgetView(frame), types);
939 WMSetViewDragDestinationProcs(WMWidgetView(frame), &dragDestProcs);
941 dir = opendir("../WindowMaker/Icons");
942 if (!dir) {
943 perror("../WindowMaker/Icons");
944 return;
947 for (i = 0, j=0; j < 8; i++) {
948 ent = readdir(dir);
949 if (!ent)
950 break;
952 if (strstr(ent->d_name, ".xpm")==NULL) {
953 continue;
956 label = makeDraggableLabel(frame, ent->d_name,4+(j/4)*64, 4+(j%4)*64);
958 j++;
961 closedir(dir);
963 WMMapSubwidgets(frame);
965 WMMapSubwidgets(win);
966 WMRealizeWidget(win);
967 WMMapWidget(win);
974 /*******************************************************************/
976 #include "WUtil.h"
980 int main(int argc, char **argv)
982 WMScreen *scr;
983 WMPixmap *pixmap;
986 /* Initialize the application */
987 WMInitializeApplication("Test", &argc, argv);
990 * Open connection to the X display.
992 dpy = XOpenDisplay("");
994 if (!dpy) {
995 puts("could not open display");
996 exit(1);
999 /* This is used to disable buffering of X protocol requests.
1000 * Do NOT use it unless when debugging. It will cause a major
1001 * slowdown in your application
1003 #if 1
1004 XSynchronize(dpy, True);
1005 #endif
1007 * Create screen descriptor.
1009 scr = WMCreateScreen(dpy, DefaultScreen(dpy));
1012 * Loads the logo of the application.
1014 pixmap = WMCreatePixmapFromFile(scr, "logo.xpm");
1017 * Makes the logo be used in standard dialog panels.
1019 WMSetApplicationIconImage(scr, pixmap); WMReleasePixmap(pixmap);
1022 * Do some test stuff.
1024 * Put the testSomething() function you want to test here.
1028 testDragAndDrop(scr);
1029 testDragAndDrop(scr);
1031 #if 0
1032 testFrame(scr);
1035 testColorWell(scr);
1037 testTabView(scr);
1039 testFontPanel(scr);
1041 testSplitView(scr);
1043 testGradientButtons(scr);
1044 testProgressIndicator(scr);
1046 testTextField(scr);
1048 testOpenFilePanel(scr);
1049 testList(scr);
1050 testScrollView(scr);
1053 testSlider(scr);
1054 testPullDown(scr);
1055 #endif
1057 * The main event loop.
1060 WMScreenMainLoop(scr);
1062 return 0;