added testtext
[wmaker-crm.git] / WINGs / wtest.c
blobb29aa52d36e29fb5fafa4c5e7a63290d24d40ced
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 testButton(WMScreen *scr)
146 WMWindow *win;
147 int i;
148 char *types[] = {
149 "MomentaryPush",
150 "PushOnPushOff",
151 "Toggle",
152 "Switch",
153 "Radio",
154 "MomentaryChange",
155 "OnOff",
156 "MomentaryLigh"
159 windowCount++;
161 win = WMCreateWindow(scr, "testButton");
162 WMResizeWidget(win, 300, 300);
163 WMSetWindowTitle(win, "Buttons");
165 WMSetWindowCloseAction(win, closeAction, NULL);
167 for (i = 1; i < 9; i++) {
168 WMButton *b;
169 b = WMCreateButton(win, i);
170 WMResizeWidget(b, 150, 24);
171 WMMoveWidget(b, 20, i*30);
172 WMSetButtonText(b, types[i-1]);
175 WMRealizeWidget(win);
176 WMMapSubwidgets(win);
177 WMMapWidget(win);
181 void
182 testGradientButtons(WMScreen *scr)
184 WMWindow *win;
185 WMButton *btn;
186 WMPixmap *pix1, *pix2;
187 RImage *back;
188 RColor light, dark;
189 WMColor *color, *altColor;
191 windowCount++;
193 /* creates the top-level window */
194 win = WMCreateWindow(scr, "testGradientButtons");
195 WMSetWindowTitle(win, "Gradiented Button Demo");
196 WMResizeWidget(win, 300, 200);
198 light.red = 0x90;
199 light.green = 0x85;
200 light.blue = 0x90;
201 dark.red = 0x35;
202 dark.green = 0x30;
203 dark.blue = 0x35;
205 color = WMCreateRGBColor(scr, 0x5900, 0x5100, 0x5900, True);
206 WMSetWidgetBackgroundColor(win, color);
207 WMReleaseColor(color);
209 back = RRenderGradient(60, 24, &dark, &light, RGRD_DIAGONAL);
210 RBevelImage(back, RBEV_RAISED2);
211 pix1 = WMCreatePixmapFromRImage(scr, back, 0);
212 RDestroyImage(back);
214 back = RRenderGradient(60, 24, &dark, &light, RGRD_DIAGONAL);
215 RBevelImage(back, RBEV_SUNKEN);
216 pix2 = WMCreatePixmapFromRImage(scr, back, 0);
217 RDestroyImage(back);
219 color = WMWhiteColor(scr);
220 altColor = WMCreateNamedColor(scr, "red", True);
222 btn = WMCreateButton(win, WBTMomentaryChange);
223 WMResizeWidget(btn, 60, 24);
224 WMMoveWidget(btn, 20, 100);
225 WMSetButtonBordered(btn, False);
226 WMSetButtonImagePosition(btn, WIPOverlaps);
227 WMSetButtonImage(btn, pix1);
228 WMSetButtonAltImage(btn, pix2);
229 WMSetButtonText(btn, "Cool");
230 WMSetButtonTextColor(btn, color);
231 WMSetButtonAltTextColor(btn, altColor);
233 WMSetBalloonTextForView("This is a cool button", WMWidgetView(btn));
235 btn = WMCreateButton(win, WBTMomentaryChange);
236 WMResizeWidget(btn, 60, 24);
237 WMMoveWidget(btn, 90, 100);
238 WMSetButtonBordered(btn, False);
239 WMSetButtonImagePosition(btn, WIPOverlaps);
240 WMSetButtonImage(btn, pix1);
241 WMSetButtonAltImage(btn, pix2);
242 WMSetButtonText(btn, "Button");
243 WMSetButtonTextColor(btn, color);
245 WMSetBalloonTextForView("Este é outro balão.", WMWidgetView(btn));
247 WMReleaseColor(color);
248 color = WMCreateNamedColor(scr, "orange", True);
250 btn = WMCreateButton(win, WBTMomentaryChange);
251 WMResizeWidget(btn, 60, 24);
252 WMMoveWidget(btn, 160, 100);
253 WMSetButtonBordered(btn, False);
254 WMSetButtonImagePosition(btn, WIPOverlaps);
255 WMSetButtonImage(btn, pix1);
256 WMSetButtonAltImage(btn, pix2);
257 WMSetButtonText(btn, "Test");
258 WMSetButtonTextColor(btn, color);
260 WMSetBalloonTextForView("This is yet another button.\nBut the balloon has 3 lines.\nYay!",
261 WMWidgetView(btn));
263 WMReleaseColor(color);
264 WMReleaseColor(altColor);
266 WMRealizeWidget(win);
267 WMMapSubwidgets(win);
268 WMMapWidget(win);
272 void
273 testScrollView(WMScreen *scr)
275 WMWindow *win;
276 WMScrollView *sview;
277 WMFrame *f;
278 WMLabel *l;
279 char buffer[128];
280 int i;
282 windowCount++;
284 /* creates the top-level window */
285 win = WMCreateWindow(scr, "testScroll");
286 WMSetWindowTitle(win, "Scrollable View");
288 WMSetWindowCloseAction(win, closeAction, NULL);
290 /* set the window size */
291 WMResizeWidget(win, 300, 300);
293 /* creates a scrollable view inside the top-level window */
294 sview = WMCreateScrollView(win);
295 WMResizeWidget(sview, 200, 200);
296 WMMoveWidget(sview, 30, 30);
297 WMSetScrollViewRelief(sview, WRSunken);
298 WMSetScrollViewHasVerticalScroller(sview, True);
299 WMSetScrollViewHasHorizontalScroller(sview, True);
301 /* create a frame with a bunch of labels */
302 f = WMCreateFrame(win);
303 WMResizeWidget(f, 400, 400);
304 WMSetFrameRelief(f, WRFlat);
306 for (i=0; i<20; i++) {
307 l = WMCreateLabel(f);
308 WMResizeWidget(l, 50, 18);
309 WMMoveWidget(l, 10, 20*i);
310 sprintf(buffer, "Label %i", i);
311 WMSetLabelText(l, buffer);
312 WMSetLabelRelief(l, WRSimple);
314 WMMapSubwidgets(f);
315 WMMapWidget(f);
317 WMSetScrollViewContentView(sview, WMWidgetView(f));
319 /* make the windows of the widgets be actually created */
320 WMRealizeWidget(win);
322 /* Map all child widgets of the top-level be mapped.
323 * You must call this for each container widget (like frames),
324 * even if they are childs of the top-level window.
326 WMMapSubwidgets(win);
328 /* map the top-level window */
329 WMMapWidget(win);
333 void
334 testColorWell(WMScreen *scr)
336 WMWindow *win;
337 WMColorWell *well1, *well2;
339 windowCount++;
341 win = WMCreateWindow(scr, "testColor");
342 WMResizeWidget(win, 300, 300);
344 WMSetWindowCloseAction(win, closeAction, NULL);
346 well1 = WMCreateColorWell(win);
347 WMResizeWidget(well1, 60, 40);
348 WMMoveWidget(well1, 100, 100);
349 WMSetColorWellColor(well1, WMCreateRGBColor(scr, 0x8888, 0, 0x1111, True));
350 well2 = WMCreateColorWell(win);
351 WMResizeWidget(well2, 60, 40);
352 WMMoveWidget(well2, 200, 100);
353 WMSetColorWellColor(well2, WMCreateRGBColor(scr, 0, 0, 0x8888, True));
355 WMRealizeWidget(win);
356 WMMapSubwidgets(win);
357 WMMapWidget(win);
360 void
361 sliderCallback(WMWidget *w, void *data)
363 printf("SLIEDER == %i\n", WMGetSliderValue(w));
367 void
368 testSlider(WMScreen *scr)
370 WMWindow *win;
371 WMSlider *s;
373 windowCount++;
375 win = WMCreateWindow(scr, "testSlider");
376 WMResizeWidget(win, 300, 300);
377 WMSetWindowTitle(win, "Sliders");
379 WMSetWindowCloseAction(win, closeAction, NULL);
381 s = WMCreateSlider(win);
382 WMResizeWidget(s, 16, 100);
383 WMMoveWidget(s, 100, 100);
384 WMSetSliderKnobThickness(s, 8);
385 WMSetSliderContinuous(s, False);
386 WMSetSliderAction(s, sliderCallback, s);
388 s = WMCreateSlider(win);
389 WMResizeWidget(s, 100, 16);
390 WMMoveWidget(s, 100, 10);
391 WMSetSliderKnobThickness(s, 8);
393 WMRealizeWidget(win);
394 WMMapSubwidgets(win);
395 WMMapWidget(win);
399 void
400 testTextField(WMScreen *scr)
402 WMWindow *win;
403 WMTextField *field, *field2;
405 windowCount++;
407 win = WMCreateWindow(scr, "testText");
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);
428 void
429 testProgressIndicator(WMScreen *scr)
431 WMWindow *win;
432 WMProgressIndicator *pPtr;
434 windowCount++;
436 win = WMCreateWindow(scr, "testProgressIndicator");
437 WMResizeWidget(win, 292, 32);
439 WMSetWindowCloseAction(win, closeAction, NULL);
441 pPtr = WMCreateProgressIndicator(win);
442 WMMoveWidget(pPtr, 8, 8);
443 WMSetProgressIndicatorValue(pPtr, 75);
445 WMRealizeWidget(win);
446 WMMapSubwidgets(win);
447 WMMapWidget(win);
452 void
453 testPullDown(WMScreen *scr)
455 WMWindow *win;
456 WMPopUpButton *pop, *pop2;
458 windowCount++;
460 win = WMCreateWindow(scr, "pullDown");
461 WMResizeWidget(win, 400, 300);
463 WMSetWindowCloseAction(win, closeAction, NULL);
465 pop = WMCreatePopUpButton(win);
466 WMResizeWidget(pop, 100, 20);
467 WMMoveWidget(pop, 50, 60);
468 WMSetPopUpButtonPullsDown(pop, True);
469 WMSetPopUpButtonText(pop, "Commands");
470 WMAddPopUpButtonItem(pop, "Add");
471 WMAddPopUpButtonItem(pop, "Remove");
472 WMAddPopUpButtonItem(pop, "Check");
473 WMAddPopUpButtonItem(pop, "Eat");
475 pop2 = WMCreatePopUpButton(win);
476 WMResizeWidget(pop2, 100, 20);
477 WMMoveWidget(pop2, 200, 60);
478 WMSetPopUpButtonText(pop2, "Select");
479 WMAddPopUpButtonItem(pop2, "Apples");
480 WMAddPopUpButtonItem(pop2, "Bananas");
481 WMAddPopUpButtonItem(pop2, "Strawberries");
482 WMAddPopUpButtonItem(pop2, "Blueberries");
484 WMRealizeWidget(win);
485 WMMapSubwidgets(win);
486 WMMapWidget(win);
491 void
492 testTabView(WMScreen *scr)
494 WMWindow *win;
495 WMTabView *tabv;
496 WMTabViewItem *tab;
497 WMFrame *frame;
498 WMLabel *label;
500 windowCount++;
502 win = WMCreateWindow(scr, "testTabs");
503 WMResizeWidget(win, 400, 300);
505 WMSetWindowCloseAction(win, closeAction, NULL);
507 tabv = WMCreateTabView(win);
508 WMMoveWidget(tabv, 50, 50);
509 WMResizeWidget(tabv, 300, 200);
511 frame = WMCreateFrame(win);
512 WMSetFrameRelief(frame, WRFlat);
513 label = WMCreateLabel(frame);
514 WMResizeWidget(label, 100, 100);
515 WMSetLabelText(label, "Label 1");
516 WMMapWidget(label);
519 tab = WMCreateTabViewItemWithIdentifier(0);
520 WMSetTabViewItemView(tab, WMWidgetView(frame));
521 WMAddItemInTabView(tabv, tab);
522 WMSetTabViewItemLabel(tab, "Instances");
524 frame = WMCreateFrame(win);
525 WMSetFrameRelief(frame, WRFlat);
526 label = WMCreateLabel(frame);
527 WMResizeWidget(label, 40, 50);
528 WMSetLabelText(label, "Label 2");
529 WMMapWidget(label);
532 tab = WMCreateTabViewItemWithIdentifier(0);
533 WMSetTabViewItemView(tab, WMWidgetView(frame));
534 WMAddItemInTabView(tabv, tab);
535 WMSetTabViewItemLabel(tab, "Classes");
538 frame = WMCreateFrame(win);
539 WMSetFrameRelief(frame, WRFlat);
540 label = WMCreateLabel(frame);
541 WMResizeWidget(label, 100, 100);
542 WMMoveWidget(label, 60, 40);
543 WMSetLabelText(label, "Label 3");
544 WMMapWidget(label);
546 tab = WMCreateTabViewItemWithIdentifier(0);
547 WMSetTabViewItemView(tab, WMWidgetView(frame));
548 WMAddItemInTabView(tabv, tab);
549 WMSetTabViewItemLabel(tab, "Something");
552 frame = WMCreateFrame(win);
553 WMSetFrameRelief(frame, WRFlat);
554 label = WMCreateLabel(frame);
555 WMResizeWidget(label, 100, 100);
556 WMMoveWidget(label, 160, 40);
557 WMSetLabelText(label, "Label 4");
558 WMMapWidget(label);
560 tab = WMCreateTabViewItemWithIdentifier(0);
561 WMSetTabViewItemView(tab, WMWidgetView(frame));
562 WMAddItemInTabView(tabv, tab);
563 WMSetTabViewItemLabel(tab, "Bla!");
567 frame = WMCreateFrame(win);
568 WMSetFrameRelief(frame, WRFlat);
569 label = WMCreateLabel(frame);
570 WMResizeWidget(label, 100, 100);
571 WMMoveWidget(label, 160, 40);
572 WMSetLabelText(label, "Label fjweqklrj qwl");
573 WMMapWidget(label);
574 tab = WMCreateTabViewItemWithIdentifier(0);
575 WMSetTabViewItemView(tab, WMWidgetView(frame));
576 WMAddItemInTabView(tabv, tab);
577 WMSetTabViewItemLabel(tab, "Weee!");
580 WMRealizeWidget(win);
581 WMMapSubwidgets(win);
582 WMMapWidget(win);
586 void
587 splitViewConstrainProc(WMSplitView *sPtr, int indView,
588 int *minSize, int *maxSize)
590 switch (indView) {
591 case 0:
592 *minSize = 20;
593 break;
594 case 1:
595 *minSize = 40;
596 *maxSize = 80;
597 break;
598 case 2:
599 *maxSize = 60;
600 break;
601 default:
602 break;
607 static void
608 resizeSplitView(XEvent *event, void *data)
610 WMSplitView *sPtr = (WMSplitView*)data;
612 if (event->type == ConfigureNotify) {
613 int width = event->xconfigure.width - 10;
615 if (width < WMGetSplitViewDividerThickness(sPtr))
616 width = WMGetSplitViewDividerThickness(sPtr);
618 if (width != WMWidgetWidth(sPtr) ||
619 event->xconfigure.height != WMWidgetHeight(sPtr))
620 WMResizeWidget(sPtr, width, event->xconfigure.height - 55);
624 void
625 appendSubviewButtonAction(WMWidget *self, void *data)
627 WMSplitView *sPtr = (WMSplitView*)data;
628 char buf[64];
629 WMLabel *label = WMCreateLabel(sPtr);
631 sprintf(buf, "Subview %d", WMGetSplitViewSubviewsCount(sPtr) + 1);
632 WMSetLabelText(label, buf);
633 WMSetLabelRelief(label, WRSunken);
634 WMAddSplitViewSubview(sPtr, WMWidgetView(label));
635 WMRealizeWidget(label);
636 WMMapWidget(label);
639 void
640 removeSubviewButtonAction(WMWidget *self, void *data)
642 WMSplitView *sPtr = (WMSplitView*)data;
643 int count = WMGetSplitViewSubviewsCount(sPtr);
645 if (count > 2) {
646 WMView *view = WMGetSplitViewSubviewAt(sPtr, count-1);
647 WMDestroyWidget(WMWidgetOfView(view));
648 WMRemoveSplitViewSubviewAt(sPtr, count-1);
652 void
653 orientationButtonAction(WMWidget *self, void *data)
655 WMSplitView *sPtr = (WMSplitView*)data;
656 WMSetSplitViewVertical(sPtr, !WMGetSplitViewVertical(sPtr));
659 void
660 adjustSubviewsButtonAction(WMWidget *self, void *data)
662 WMAdjustSplitViewSubviews((WMSplitView*)data);
665 void
666 testSplitView(WMScreen *scr)
668 WMWindow *win;
669 WMSplitView *splitv1, *splitv2;
670 WMFrame *frame;
671 WMLabel *label;
672 WMButton *button;
674 windowCount++;
676 win = WMCreateWindow(scr, "testTabs");
677 WMResizeWidget(win, 300, 400);
678 WMSetWindowCloseAction(win, closeAction, NULL);
680 frame = WMCreateFrame(win);
681 WMSetFrameRelief(frame, WRSunken);
682 WMMoveWidget(frame, 5, 5);
683 WMResizeWidget(frame, 290, 40);
685 splitv1 = WMCreateSplitView(win);
686 WMMoveWidget(splitv1, 5, 50);
687 WMResizeWidget(splitv1, 290, 345);
688 WMSetSplitViewConstrainProc(splitv1, splitViewConstrainProc);
689 WMCreateEventHandler(WMWidgetView(win), StructureNotifyMask,
690 resizeSplitView, splitv1);
692 button = WMCreateCommandButton(frame);
693 WMSetButtonText(button, "+");
694 WMSetButtonAction(button, appendSubviewButtonAction, splitv1);
695 WMMoveWidget(button, 10, 8);
696 WMMapWidget(button);
698 button = WMCreateCommandButton(frame);
699 WMSetButtonText(button, "-");
700 WMSetButtonAction(button, removeSubviewButtonAction, splitv1);
701 WMMoveWidget(button, 80, 8);
702 WMMapWidget(button);
704 button = WMCreateCommandButton(frame);
705 WMSetButtonText(button, "=");
706 WMMoveWidget(button, 150, 8);
707 WMSetButtonAction(button, adjustSubviewsButtonAction, splitv1);
708 WMMapWidget(button);
710 button = WMCreateCommandButton(frame);
711 WMSetButtonText(button, "#");
712 WMMoveWidget(button, 220, 8);
713 WMSetButtonAction(button, orientationButtonAction, splitv1);
714 WMMapWidget(button);
716 label = WMCreateLabel(splitv1);
717 WMSetLabelText(label, "Subview 1");
718 WMSetLabelRelief(label, WRSunken);
719 WMMapWidget(label);
720 WMAddSplitViewSubview(splitv1, WMWidgetView(label));
722 splitv2 = WMCreateSplitView(splitv1);
723 WMResizeWidget(splitv2, 150, 150);
724 WMSetSplitViewVertical(splitv2, True);
726 label = WMCreateLabel(splitv2);
727 WMSetLabelText(label, "Subview 2.1");
728 WMSetLabelRelief(label, WRSunken);
729 WMMapWidget(label);
730 WMAddSplitViewSubview(splitv2, WMWidgetView(label));
732 label = WMCreateLabel(splitv2);
733 WMSetLabelText(label, "Subview 2.2");
734 WMSetLabelRelief(label, WRSunken);
735 WMMapWidget(label);
736 WMAddSplitViewSubview(splitv2, WMWidgetView(label));
738 label = WMCreateLabel(splitv2);
739 WMSetLabelText(label, "Subview 2.3");
740 WMSetLabelRelief(label, WRSunken);
741 WMMapWidget(label);
742 WMAddSplitViewSubview(splitv2, WMWidgetView(label));
744 WMMapWidget(splitv2);
745 WMAddSplitViewSubview(splitv1, WMWidgetView(splitv2));
747 WMRealizeWidget(win);
748 WMMapSubwidgets(win);
749 WMMapWidget(win);
753 /*******************************************************************/
755 #include <sys/types.h>
756 #include <dirent.h>
757 #include <string.h>
760 typedef struct {
761 int x, y;
762 Bool mouseDown;
763 char *filename;
764 } DNDStuff;
766 WMPixmap*
767 getImage(WMScreen *scr, char *file)
769 char buffer[1000];
770 WMPixmap *pix;
772 sprintf(buffer, "../WindowMaker/Icons/%s", file);
773 pix = WMCreatePixmapFromFile(scr, buffer);
775 return pix;
781 static void iconMouseStuff(XEvent *event, void *cdata)
783 WMLabel *label = (WMLabel*)cdata;
784 DNDStuff *stuff = WMGetHangedData(label);
785 WMPoint where;
787 switch (event->type) {
788 case ButtonPress:
789 stuff->x = event->xbutton.x;
790 stuff->y = event->xbutton.y;
791 stuff->mouseDown = True;
792 break;
793 case ButtonRelease:
794 stuff->mouseDown = False;
795 break;
796 case MotionNotify:
797 if (!stuff->mouseDown)
798 break;
800 if (abs(stuff->x - event->xmotion.x)>4
801 || abs(stuff->y - event->xmotion.y)>4) {
803 where = WMGetViewScreenPosition(WMWidgetView(label));
805 WMDragImageFromView(WMWidgetView(label),
806 WMGetLabelImage(label),
807 NULL, /* XXX */
808 where,
809 wmksize(stuff->x, stuff->y),
810 event, True);
812 break;
817 static void endedDragImage(WMView *self, WMPixmap *image, WMPoint point,
818 Bool deposited)
820 DNDStuff *stuff = WMGetHangedData(WMWidgetOfView(self));
822 if (deposited) {
823 WMDestroyWidget(WMWidgetOfView(self));
826 stuff->mouseDown = False;
830 static WMData* fetchDragData(WMView *self, char *type)
832 DNDStuff *stuff = WMGetHangedData(WMWidgetOfView(self));
834 return WMCreateDataWithBytes(stuff->filename, strlen(stuff->filename)+1);
838 WMDragSourceProcs dragSourceProcs = {
839 NULL,
840 NULL,
841 endedDragImage,
842 fetchDragData
846 /************************/
849 unsigned draggingEntered(WMView *self, WMDraggingInfo *info)
851 return WDOperationCopy;
855 unsigned draggingUpdated(WMView *self, WMDraggingInfo *info)
857 return WDOperationCopy;
861 void (*draggingExited)(WMView *self, WMDraggingInfo *info);
863 char *prepareForDragOperation(WMView *self, WMDraggingInfo *info)
865 return "application/X-WINGs-Bla";
869 WMLabel *makeDraggableLabel(WMWidget *w, char *file, int x, int y);
871 Bool performDragOperation(WMView *self, WMDraggingInfo *info,
872 WMData *data)
874 char *file = (char*)WMDataBytes(data);
875 WMPoint pos;
877 pos = WMGetDraggingInfoImageLocation(info);
879 if (file!=NULL) {
880 WMLabel *label;
881 WMPoint pos2 = WMGetViewScreenPosition(self);
884 label = makeDraggableLabel(WMWidgetOfView(self), file,
885 pos.x-pos2.x, pos.y-pos2.y);
886 WMRealizeWidget(label);
887 WMMapWidget(label);
891 return True;
895 void concludeDragOperation(WMView *self, WMDraggingInfo *info)
902 WMDragDestinationProcs dragDestProcs = {
903 draggingEntered,
904 draggingUpdated,
905 NULL,
906 prepareForDragOperation,
907 performDragOperation,
908 concludeDragOperation
914 WMLabel*
915 makeDraggableLabel(WMWidget *w, char *file, int x, int y)
917 DNDStuff *stuff;
918 WMLabel *label;
919 WMPixmap *image = getImage(WMWidgetScreen(w), file);
921 stuff = wmalloc(sizeof(DNDStuff));
922 stuff->mouseDown = False;
924 stuff->filename = wstrdup(file);
926 label = WMCreateLabel(w);
927 WMResizeWidget(label, 48, 48);
928 WMMoveWidget(label, x, y);
930 WMSetViewDragSourceProcs(WMWidgetView(label), &dragSourceProcs);
932 WMHangData(label, stuff);
934 WMCreateEventHandler(WMWidgetView(label),
935 ButtonPressMask|ButtonReleaseMask|ButtonMotionMask,
936 iconMouseStuff, label);
939 if (image != NULL) {
940 WMSetLabelImagePosition(label, WIPImageOnly);
941 WMSetLabelImage(label, image);
942 WMReleasePixmap(image);
943 } else puts(file);
945 return label;
950 void testDragAndDrop(WMScreen *scr)
952 WMWindow *win;
953 WMFrame *frame;
954 WMLabel *label;
955 int i, j;
956 DIR *dir;
957 struct dirent *ent;
958 char *types[] = {
959 "application/X-WINGs-Bla",
960 NULL
963 windowCount++;
965 win = WMCreateWindow(scr, "dragDrop");
966 WMResizeWidget(win, 300, 300);
967 WMSetWindowCloseAction(win, closeAction, NULL);
968 WMSetWindowTitle(win, "Drag and Drop");
971 frame = WMCreateFrame(win);
972 WMSetFrameRelief(frame, WRSunken);
973 WMResizeWidget(frame, 250, 250);
974 WMMoveWidget(frame, 25, 25);
976 WMRegisterViewForDraggedTypes(WMWidgetView(frame), types);
977 WMSetViewDragDestinationProcs(WMWidgetView(frame), &dragDestProcs);
979 dir = opendir("../WindowMaker/Icons");
980 if (!dir) {
981 perror("../WindowMaker/Icons");
982 return;
985 for (i = 0, j=0; j < 8; i++) {
986 ent = readdir(dir);
987 if (!ent)
988 break;
990 if (strstr(ent->d_name, ".xpm")==NULL) {
991 continue;
994 label = makeDraggableLabel(frame, ent->d_name,4+(j/4)*64, 4+(j%4)*64);
996 j++;
999 closedir(dir);
1001 WMMapSubwidgets(frame);
1003 WMMapSubwidgets(win);
1004 WMRealizeWidget(win);
1005 WMMapWidget(win);
1012 /*******************************************************************/
1014 #include "WUtil.h"
1016 void testUD()
1018 WMUserDefaults *defs;
1019 char str[32];
1021 defs = WMGetStandardUserDefaults();
1023 sprintf(str, "TEST DATA");
1024 puts(str);
1025 WMSetUDStringForKey(defs, str, "testKey");
1026 puts(str);
1030 int main(int argc, char **argv)
1032 WMScreen *scr;
1033 WMPixmap *pixmap;
1036 /* Initialize the application */
1037 WMInitializeApplication("Test", &argc, argv);
1039 testUD();
1042 * Open connection to the X display.
1044 dpy = XOpenDisplay("");
1046 if (!dpy) {
1047 puts("could not open display");
1048 exit(1);
1051 /* This is used to disable buffering of X protocol requests.
1052 * Do NOT use it unless when debugging. It will cause a major
1053 * slowdown in your application
1055 #if 1
1056 XSynchronize(dpy, True);
1057 #endif
1059 * Create screen descriptor.
1061 scr = WMCreateScreen(dpy, DefaultScreen(dpy));
1064 * Loads the logo of the application.
1066 pixmap = WMCreatePixmapFromFile(scr, "logo.xpm");
1069 * Makes the logo be used in standard dialog panels.
1071 WMSetApplicationIconImage(scr, pixmap); WMReleasePixmap(pixmap);
1074 * Do some test stuff.
1076 * Put the testSomething() function you want to test here.
1078 testTabView(scr);
1080 #if 0
1082 testDragAndDrop(scr);
1083 testDragAndDrop(scr);
1085 testScrollView(scr);
1087 testButton(scr);
1089 testFrame(scr);
1092 testColorWell(scr);
1095 testFontPanel(scr);
1097 testSplitView(scr);
1099 testGradientButtons(scr);
1100 testProgressIndicator(scr);
1102 testTextField(scr);
1104 testOpenFilePanel(scr);
1105 testList(scr);
1108 testSlider(scr);
1109 testPullDown(scr);
1110 #endif
1112 * The main event loop.
1115 WMScreenMainLoop(scr);
1117 return 0;