2 * WINGs test application
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
30 closeAction(WMWidget
*self
, void *data
)
32 WMDestroyWidget(self
);
34 printf("window closed, window count = %d\n", windowCount
);
41 testOpenFilePanel(WMScreen
*scr
)
47 /* get the shared Open File panel */
48 panel
= WMGetOpenPanel(scr
);
50 WMRunModalFilePanelForDirectory(panel
, NULL
, "/usr/local", NULL
, NULL
);
52 /* free the panel to save some memory. Not needed otherwise. */
53 WMFreeFilePanel(WMGetOpenPanel(scr
));
58 testFontPanel(WMScreen
*scr
)
64 panel
= WMGetFontPanel(scr
);
66 WMShowFontPanel(panel
);
68 /* WMFreeFontPanel(panel);*/
74 testFrame(WMScreen
*scr
)
79 static char* titles
[] = {
87 static WMTitlePosition pos
[] = {
98 win
= WMCreateWindow(scr
, "testFrame");
99 WMSetWindowTitle(win
, "Frame");
100 WMSetWindowCloseAction(win
, closeAction
, NULL
);
101 WMResizeWidget(win
, 400, 300);
103 for (i
= 0; i
< 6; i
++) {
104 frame
= WMCreateFrame(win
);
105 WMMoveWidget(frame
, 8+(i
%3)*130, 8+(i
/3)*130);
106 WMResizeWidget(frame
, 120, 120);
107 WMSetFrameTitle(frame
, titles
[i
]);
108 WMSetFrameTitlePosition(frame
, pos
[i
]);
111 WMRealizeWidget(win
);
112 WMMapSubwidgets(win
);
119 singleClick(WMWidget
*self
, void *data
)
125 doubleClick(WMWidget
*self
, void *data
)
127 WMLabel
*label
= (WMLabel
*)data
;
128 WMList
*lPtr
= (WMList
*)self
;
131 WMSelectAllListItems(lPtr
);
136 listSelectionObserver(void *observer
, WMNotification
*notification
)
138 WMLabel
*label
= (WMLabel
*)observer
;
139 WMList
*lPtr
= (WMList
*)WMGetNotificationObject(notification
);
142 sprintf(buf
, "Selected items: %d",
143 WMGetArrayItemCount(WMGetListSelectedItems(lPtr
)));
144 WMSetLabelText(label
, buf
);
149 testList(WMScreen
*scr
)
163 win
= WMCreateWindow(scr
, "testList");
164 WMResizeWidget(win
, 370, 250);
165 WMSetWindowTitle(win
, "List");
166 WMSetWindowCloseAction(win
, closeAction
, NULL
);
168 title
= WMCreateLabel(win
);
169 WMResizeWidget(title
, 150, 20);
170 WMMoveWidget(title
, 10, 10);
171 WMSetLabelRelief(title
, WRRidge
);
172 WMSetLabelText(title
, "Single selection list");
174 mtitle
= WMCreateLabel(win
);
175 WMResizeWidget(mtitle
, 150, 20);
176 WMMoveWidget(mtitle
, 210, 10);
177 WMSetLabelRelief(mtitle
, WRRidge
);
178 WMSetLabelText(mtitle
, "Multiple selection list");
180 list
= WMCreateList(win
);
181 WMSetListAllowEmptySelection(list
, True
);
182 WMMoveWidget(list
, 10, 40);
183 for (i
=0; i
<50; i
++) {
184 sprintf(text
, "Item %i", i
);
185 WMAddListItem(list
, text
);
187 mlist
= WMCreateList(win
);
188 WMSetListAllowMultipleSelection(mlist
, True
);
189 WMSetListAllowEmptySelection(mlist
, True
);
190 WMMoveWidget(mlist
, 210, 40);
191 for (i
=0; i
<135; i
++) {
192 sprintf(text
, "Item %i", i
);
193 WMAddListItem(mlist
, text
);
196 label
= WMCreateLabel(win
);
197 WMResizeWidget(label
, 150, 40);
198 WMMoveWidget(label
, 10, 200);
199 WMSetLabelRelief(label
, WRRidge
);
200 WMSetLabelText(label
, "Selected items: 0");
202 mlabel
= WMCreateLabel(win
);
203 WMResizeWidget(mlabel
, 150, 40);
204 WMMoveWidget(mlabel
, 210, 200);
205 WMSetLabelRelief(mlabel
, WRRidge
);
206 WMSetLabelText(mlabel
, "Selected items: 0");
208 WMSetListAction(list
, singleClick
, label
);
209 WMSetListDoubleAction(list
, doubleClick
, label
);
210 WMSetListAction(mlist
, singleClick
, mlabel
);
211 WMSetListDoubleAction(mlist
, doubleClick
, mlabel
);
213 WMAddNotificationObserver(listSelectionObserver
, label
,
214 WMListSelectionDidChangeNotification
, list
);
215 WMAddNotificationObserver(listSelectionObserver
, mlabel
,
216 WMListSelectionDidChangeNotification
, mlist
);
219 WMRealizeWidget(win
);
220 WMMapSubwidgets(win
);
226 testButton(WMScreen
*scr
)
243 win
= WMCreateWindow(scr
, "testButton");
244 WMResizeWidget(win
, 300, 300);
245 WMSetWindowTitle(win
, "Buttons");
247 WMSetWindowCloseAction(win
, closeAction
, NULL
);
249 for (i
= 1; i
< 9; i
++) {
251 b
= WMCreateButton(win
, i
);
252 WMResizeWidget(b
, 150, 24);
253 WMMoveWidget(b
, 20, i
*30);
254 WMSetButtonText(b
, types
[i
-1]);
257 WMRealizeWidget(win
);
258 WMMapSubwidgets(win
);
264 testGradientButtons(WMScreen
*scr
)
268 WMPixmap
*pix1
, *pix2
;
271 WMColor
*color
, *altColor
;
275 /* creates the top-level window */
276 win
= WMCreateWindow(scr
, "testGradientButtons");
277 WMSetWindowTitle(win
, "Gradiented Button Demo");
278 WMResizeWidget(win
, 300, 200);
287 color
= WMCreateRGBColor(scr
, 0x5900, 0x5100, 0x5900, True
);
288 WMSetWidgetBackgroundColor(win
, color
);
289 WMReleaseColor(color
);
291 back
= RRenderGradient(60, 24, &dark
, &light
, RGRD_DIAGONAL
);
292 RBevelImage(back
, RBEV_RAISED2
);
293 pix1
= WMCreatePixmapFromRImage(scr
, back
, 0);
296 back
= RRenderGradient(60, 24, &dark
, &light
, RGRD_DIAGONAL
);
297 RBevelImage(back
, RBEV_SUNKEN
);
298 pix2
= WMCreatePixmapFromRImage(scr
, back
, 0);
301 color
= WMWhiteColor(scr
);
302 altColor
= WMCreateNamedColor(scr
, "red", True
);
304 btn
= WMCreateButton(win
, WBTMomentaryChange
);
305 WMResizeWidget(btn
, 60, 24);
306 WMMoveWidget(btn
, 20, 100);
307 WMSetButtonBordered(btn
, False
);
308 WMSetButtonImagePosition(btn
, WIPOverlaps
);
309 WMSetButtonImage(btn
, pix1
);
310 WMSetButtonAltImage(btn
, pix2
);
311 WMSetButtonText(btn
, "Cool");
312 WMSetButtonTextColor(btn
, color
);
313 WMSetButtonAltTextColor(btn
, altColor
);
315 WMSetBalloonTextForView("This is a cool button", WMWidgetView(btn
));
317 btn
= WMCreateButton(win
, WBTMomentaryChange
);
318 WMResizeWidget(btn
, 60, 24);
319 WMMoveWidget(btn
, 90, 100);
320 WMSetButtonBordered(btn
, False
);
321 WMSetButtonImagePosition(btn
, WIPOverlaps
);
322 WMSetButtonImage(btn
, pix1
);
323 WMSetButtonAltImage(btn
, pix2
);
324 WMSetButtonText(btn
, "Button");
325 WMSetButtonTextColor(btn
, color
);
327 WMSetBalloonTextForView("Este é outro balão.", WMWidgetView(btn
));
329 WMReleaseColor(color
);
330 color
= WMCreateNamedColor(scr
, "orange", True
);
332 btn
= WMCreateButton(win
, WBTMomentaryChange
);
333 WMResizeWidget(btn
, 60, 24);
334 WMMoveWidget(btn
, 160, 100);
335 WMSetButtonBordered(btn
, False
);
336 WMSetButtonImagePosition(btn
, WIPOverlaps
);
337 WMSetButtonImage(btn
, pix1
);
338 WMSetButtonAltImage(btn
, pix2
);
339 WMSetButtonText(btn
, "Test");
340 WMSetButtonTextColor(btn
, color
);
342 WMSetBalloonTextForView("This is yet another button.\nBut the balloon has 3 lines.\nYay!",
345 WMReleaseColor(color
);
346 WMReleaseColor(altColor
);
348 WMRealizeWidget(win
);
349 WMMapSubwidgets(win
);
355 testScrollView(WMScreen
*scr
)
366 /* creates the top-level window */
367 win
= WMCreateWindow(scr
, "testScroll");
368 WMSetWindowTitle(win
, "Scrollable View");
370 WMSetWindowCloseAction(win
, closeAction
, NULL
);
372 /* set the window size */
373 WMResizeWidget(win
, 300, 300);
375 /* creates a scrollable view inside the top-level window */
376 sview
= WMCreateScrollView(win
);
377 WMResizeWidget(sview
, 200, 200);
378 WMMoveWidget(sview
, 30, 30);
379 WMSetScrollViewRelief(sview
, WRSunken
);
380 WMSetScrollViewHasVerticalScroller(sview
, True
);
381 WMSetScrollViewHasHorizontalScroller(sview
, True
);
383 /* create a frame with a bunch of labels */
384 f
= WMCreateFrame(win
);
385 WMResizeWidget(f
, 400, 400);
386 WMSetFrameRelief(f
, WRFlat
);
388 for (i
=0; i
<20; i
++) {
389 l
= WMCreateLabel(f
);
390 WMResizeWidget(l
, 50, 18);
391 WMMoveWidget(l
, 10, 20*i
);
392 sprintf(buffer
, "Label %i", i
);
393 WMSetLabelText(l
, buffer
);
394 WMSetLabelRelief(l
, WRSimple
);
399 WMSetScrollViewContentView(sview
, WMWidgetView(f
));
401 /* make the windows of the widgets be actually created */
402 WMRealizeWidget(win
);
404 /* Map all child widgets of the top-level be mapped.
405 * You must call this for each container widget (like frames),
406 * even if they are childs of the top-level window.
408 WMMapSubwidgets(win
);
410 /* map the top-level window */
416 testColorWell(WMScreen
*scr
)
419 WMColorWell
*well1
, *well2
;
423 win
= WMCreateWindow(scr
, "testColor");
424 WMResizeWidget(win
, 300, 300);
425 WMSetWindowCloseAction(win
, closeAction
, NULL
);
427 well1
= WMCreateColorWell(win
);
428 WMResizeWidget(well1
, 60, 40);
429 WMMoveWidget(well1
, 100, 100);
430 WMSetColorWellColor(well1
, WMCreateRGBColor(scr
, 0x8888, 0, 0x1111, True
));
431 well2
= WMCreateColorWell(win
);
432 WMResizeWidget(well2
, 60, 40);
433 WMMoveWidget(well2
, 200, 100);
434 WMSetColorWellColor(well2
, WMCreateRGBColor(scr
, 0, 0, 0x8888, True
));
436 WMRealizeWidget(win
);
437 WMMapSubwidgets(win
);
442 sliderCallback(WMWidget
*w
, void *data
)
444 printf("SLIDER == %i\n", WMGetSliderValue(w
));
449 testSlider(WMScreen
*scr
)
456 win
= WMCreateWindow(scr
, "testSlider");
457 WMResizeWidget(win
, 300, 300);
458 WMSetWindowTitle(win
, "Sliders");
460 WMSetWindowCloseAction(win
, closeAction
, NULL
);
462 s
= WMCreateSlider(win
);
463 WMResizeWidget(s
, 16, 100);
464 WMMoveWidget(s
, 100, 100);
465 WMSetSliderKnobThickness(s
, 8);
466 WMSetSliderContinuous(s
, False
);
467 WMSetSliderAction(s
, sliderCallback
, s
);
469 s
= WMCreateSlider(win
);
470 WMResizeWidget(s
, 100, 16);
471 WMMoveWidget(s
, 100, 10);
472 WMSetSliderKnobThickness(s
, 8);
474 WMRealizeWidget(win
);
475 WMMapSubwidgets(win
);
480 testTextField(WMScreen
*scr
)
483 WMTextField
*field
, *field2
;
487 win
= WMCreateWindow(scr
, "testTextField");
488 WMResizeWidget(win
, 400, 300);
490 WMSetWindowCloseAction(win
, closeAction
, NULL
);
492 field
= WMCreateTextField(win
);
493 WMResizeWidget(field
, 200, 20);
494 WMMoveWidget(field
, 20, 20);
496 field2
= WMCreateTextField(win
);
497 WMResizeWidget(field2
, 200, 20);
498 WMMoveWidget(field2
, 20, 50);
499 WMSetTextFieldAlignment(field2
, WARight
);
501 WMRealizeWidget(win
);
502 WMMapSubwidgets(win
);
509 testText(WMScreen
*scr
)
513 FILE *file
= fopen("../README", "r");
517 win
= WMCreateWindow(scr
, "testText");
518 WMResizeWidget(win
, 500, 300);
520 WMSetWindowCloseAction(win
, closeAction
, NULL
);
522 text
= WMCreateText(win
);
523 WMResizeWidget(text
, 480, 280);
524 WMMoveWidget(text
, 10, 10);
525 WMSetTextHasVerticalScroller(text
, True
);
526 WMSetTextEditable(text
, False
);
532 while(fgets(buf
, 1023, file
))
533 WMAppendTextStream(text
, buf
);
538 WMAppendTextStream(text
, "<HTML><i>Where's</i> the <b>README</b>?");
541 WMRealizeWidget(win
);
542 WMMapSubwidgets(win
);
548 testProgressIndicator(WMScreen
*scr
)
551 WMProgressIndicator
*pPtr
;
555 win
= WMCreateWindow(scr
, "testProgressIndicator");
556 WMResizeWidget(win
, 292, 32);
558 WMSetWindowCloseAction(win
, closeAction
, NULL
);
560 pPtr
= WMCreateProgressIndicator(win
);
561 WMMoveWidget(pPtr
, 8, 8);
562 WMSetProgressIndicatorValue(pPtr
, 75);
564 WMRealizeWidget(win
);
565 WMMapSubwidgets(win
);
572 testPullDown(WMScreen
*scr
)
575 WMPopUpButton
*pop
, *pop2
;
579 win
= WMCreateWindow(scr
, "pullDown");
580 WMResizeWidget(win
, 400, 300);
582 WMSetWindowCloseAction(win
, closeAction
, NULL
);
584 pop
= WMCreatePopUpButton(win
);
585 WMResizeWidget(pop
, 100, 20);
586 WMMoveWidget(pop
, 50, 60);
587 WMSetPopUpButtonPullsDown(pop
, True
);
588 WMSetPopUpButtonText(pop
, "Commands");
589 WMAddPopUpButtonItem(pop
, "Add");
590 WMAddPopUpButtonItem(pop
, "Remove");
591 WMAddPopUpButtonItem(pop
, "Check");
592 WMAddPopUpButtonItem(pop
, "Eat");
594 pop2
= WMCreatePopUpButton(win
);
595 WMResizeWidget(pop2
, 100, 20);
596 WMMoveWidget(pop2
, 200, 60);
597 WMSetPopUpButtonText(pop2
, "Select");
598 WMAddPopUpButtonItem(pop2
, "Apples");
599 WMAddPopUpButtonItem(pop2
, "Bananas");
600 WMAddPopUpButtonItem(pop2
, "Strawberries");
601 WMAddPopUpButtonItem(pop2
, "Blueberries");
603 WMRealizeWidget(win
);
604 WMMapSubwidgets(win
);
611 testTabView(WMScreen
*scr
)
621 win
= WMCreateWindow(scr
, "testTabs");
622 WMResizeWidget(win
, 400, 300);
624 WMSetWindowCloseAction(win
, closeAction
, NULL
);
626 tabv
= WMCreateTabView(win
);
627 WMMoveWidget(tabv
, 50, 50);
628 WMResizeWidget(tabv
, 300, 200);
630 frame
= WMCreateFrame(win
);
631 WMSetFrameRelief(frame
, WRFlat
);
632 label
= WMCreateLabel(frame
);
633 WMResizeWidget(label
, 100, 100);
634 WMSetLabelText(label
, "Label 1");
638 tab
= WMCreateTabViewItemWithIdentifier(0);
639 WMSetTabViewItemView(tab
, WMWidgetView(frame
));
640 WMAddItemInTabView(tabv
, tab
);
641 WMSetTabViewItemLabel(tab
, "Instances");
643 frame
= WMCreateFrame(win
);
644 WMSetFrameRelief(frame
, WRFlat
);
645 label
= WMCreateLabel(frame
);
646 WMResizeWidget(label
, 40, 50);
647 WMSetLabelText(label
, "Label 2");
651 tab
= WMCreateTabViewItemWithIdentifier(0);
652 WMSetTabViewItemView(tab
, WMWidgetView(frame
));
653 WMAddItemInTabView(tabv
, tab
);
654 WMSetTabViewItemLabel(tab
, "Classes");
657 frame
= WMCreateFrame(win
);
658 WMSetFrameRelief(frame
, WRFlat
);
659 label
= WMCreateLabel(frame
);
660 WMResizeWidget(label
, 100, 100);
661 WMMoveWidget(label
, 60, 40);
662 WMSetLabelText(label
, "Label 3");
665 tab
= WMCreateTabViewItemWithIdentifier(0);
666 WMSetTabViewItemView(tab
, WMWidgetView(frame
));
667 WMAddItemInTabView(tabv
, tab
);
668 WMSetTabViewItemLabel(tab
, "Something");
671 frame
= WMCreateFrame(win
);
672 WMSetFrameRelief(frame
, WRFlat
);
673 label
= WMCreateLabel(frame
);
674 WMResizeWidget(label
, 100, 100);
675 WMMoveWidget(label
, 160, 40);
676 WMSetLabelText(label
, "Label 4");
679 tab
= WMCreateTabViewItemWithIdentifier(0);
680 WMSetTabViewItemView(tab
, WMWidgetView(frame
));
681 WMAddItemInTabView(tabv
, tab
);
682 WMSetTabViewItemLabel(tab
, "Bla!");
686 frame
= WMCreateFrame(win
);
687 WMSetFrameRelief(frame
, WRFlat
);
688 label
= WMCreateLabel(frame
);
689 WMResizeWidget(label
, 100, 100);
690 WMMoveWidget(label
, 160, 40);
691 WMSetLabelText(label
, "Label fjweqklrj qwl");
693 tab
= WMCreateTabViewItemWithIdentifier(0);
694 WMSetTabViewItemView(tab
, WMWidgetView(frame
));
695 WMAddItemInTabView(tabv
, tab
);
696 WMSetTabViewItemLabel(tab
, "Weee!");
699 WMRealizeWidget(win
);
700 WMMapSubwidgets(win
);
706 splitViewConstrainProc(WMSplitView
*sPtr
, int indView
,
707 int *minSize
, int *maxSize
)
727 resizeSplitView(XEvent
*event
, void *data
)
729 WMSplitView
*sPtr
= (WMSplitView
*)data
;
731 if (event
->type
== ConfigureNotify
) {
732 int width
= event
->xconfigure
.width
- 10;
734 if (width
< WMGetSplitViewDividerThickness(sPtr
))
735 width
= WMGetSplitViewDividerThickness(sPtr
);
737 if (width
!= WMWidgetWidth(sPtr
) ||
738 event
->xconfigure
.height
!= WMWidgetHeight(sPtr
))
739 WMResizeWidget(sPtr
, width
, event
->xconfigure
.height
- 55);
744 appendSubviewButtonAction(WMWidget
*self
, void *data
)
746 WMSplitView
*sPtr
= (WMSplitView
*)data
;
748 WMLabel
*label
= WMCreateLabel(sPtr
);
750 sprintf(buf
, "Subview %d", WMGetSplitViewSubviewsCount(sPtr
) + 1);
751 WMSetLabelText(label
, buf
);
752 WMSetLabelRelief(label
, WRSunken
);
753 WMAddSplitViewSubview(sPtr
, WMWidgetView(label
));
754 WMRealizeWidget(label
);
759 removeSubviewButtonAction(WMWidget
*self
, void *data
)
761 WMSplitView
*sPtr
= (WMSplitView
*)data
;
762 int count
= WMGetSplitViewSubviewsCount(sPtr
);
765 WMView
*view
= WMGetSplitViewSubviewAt(sPtr
, count
-1);
766 WMDestroyWidget(WMWidgetOfView(view
));
767 WMRemoveSplitViewSubviewAt(sPtr
, count
-1);
772 orientationButtonAction(WMWidget
*self
, void *data
)
774 WMSplitView
*sPtr
= (WMSplitView
*)data
;
775 WMSetSplitViewVertical(sPtr
, !WMGetSplitViewVertical(sPtr
));
779 adjustSubviewsButtonAction(WMWidget
*self
, void *data
)
781 WMAdjustSplitViewSubviews((WMSplitView
*)data
);
785 testSplitView(WMScreen
*scr
)
788 WMSplitView
*splitv1
, *splitv2
;
795 win
= WMCreateWindow(scr
, "testTabs");
796 WMResizeWidget(win
, 300, 400);
797 WMSetWindowCloseAction(win
, closeAction
, NULL
);
799 frame
= WMCreateFrame(win
);
800 WMSetFrameRelief(frame
, WRSunken
);
801 WMMoveWidget(frame
, 5, 5);
802 WMResizeWidget(frame
, 290, 40);
804 splitv1
= WMCreateSplitView(win
);
805 WMMoveWidget(splitv1
, 5, 50);
806 WMResizeWidget(splitv1
, 290, 345);
807 WMSetSplitViewConstrainProc(splitv1
, splitViewConstrainProc
);
808 WMCreateEventHandler(WMWidgetView(win
), StructureNotifyMask
,
809 resizeSplitView
, splitv1
);
811 button
= WMCreateCommandButton(frame
);
812 WMSetButtonText(button
, "+");
813 WMSetButtonAction(button
, appendSubviewButtonAction
, splitv1
);
814 WMMoveWidget(button
, 10, 8);
817 button
= WMCreateCommandButton(frame
);
818 WMSetButtonText(button
, "-");
819 WMSetButtonAction(button
, removeSubviewButtonAction
, splitv1
);
820 WMMoveWidget(button
, 80, 8);
823 button
= WMCreateCommandButton(frame
);
824 WMSetButtonText(button
, "=");
825 WMMoveWidget(button
, 150, 8);
826 WMSetButtonAction(button
, adjustSubviewsButtonAction
, splitv1
);
829 button
= WMCreateCommandButton(frame
);
830 WMSetButtonText(button
, "#");
831 WMMoveWidget(button
, 220, 8);
832 WMSetButtonAction(button
, orientationButtonAction
, splitv1
);
835 label
= WMCreateLabel(splitv1
);
836 WMSetLabelText(label
, "Subview 1");
837 WMSetLabelRelief(label
, WRSunken
);
839 WMAddSplitViewSubview(splitv1
, WMWidgetView(label
));
841 splitv2
= WMCreateSplitView(splitv1
);
842 WMResizeWidget(splitv2
, 150, 150);
843 WMSetSplitViewVertical(splitv2
, True
);
845 label
= WMCreateLabel(splitv2
);
846 WMSetLabelText(label
, "Subview 2.1");
847 WMSetLabelRelief(label
, WRSunken
);
849 WMAddSplitViewSubview(splitv2
, WMWidgetView(label
));
851 label
= WMCreateLabel(splitv2
);
852 WMSetLabelText(label
, "Subview 2.2");
853 WMSetLabelRelief(label
, WRSunken
);
855 WMAddSplitViewSubview(splitv2
, WMWidgetView(label
));
857 label
= WMCreateLabel(splitv2
);
858 WMSetLabelText(label
, "Subview 2.3");
859 WMSetLabelRelief(label
, WRSunken
);
861 WMAddSplitViewSubview(splitv2
, WMWidgetView(label
));
863 WMMapWidget(splitv2
);
864 WMAddSplitViewSubview(splitv1
, WMWidgetView(splitv2
));
866 WMRealizeWidget(win
);
867 WMMapSubwidgets(win
);
872 /*******************************************************************/
874 #include <sys/types.h>
886 getImage(WMScreen
*scr
, char *file
)
891 sprintf(buffer
, "../../WindowMaker/Icons/%s", file
);
892 pix
= WMCreatePixmapFromFile(scr
, buffer
);
901 iconMouseStuff(XEvent
*event
, void *cdata
)
903 WMLabel
*label
= (WMLabel
*)cdata
;
904 DNDStuff
*stuff
= WMGetHangedData(label
);
907 switch (event
->type
) {
909 stuff
->x
= event
->xbutton
.x
;
910 stuff
->y
= event
->xbutton
.y
;
911 stuff
->mouseDown
= True
;
914 stuff
->mouseDown
= False
;
917 if (!stuff
->mouseDown
)
920 if (abs(stuff
->x
- event
->xmotion
.x
)>4
921 || abs(stuff
->y
- event
->xmotion
.y
)>4) {
923 where
= WMGetViewScreenPosition(WMWidgetView(label
));
925 WMDragImageFromView(WMWidgetView(label
),
926 WMGetLabelImage(label
),
929 wmksize(stuff
->x
, stuff
->y
),
938 endedDragImage(WMView
*self
, WMPixmap
*image
, WMPoint point
, Bool deposited
)
940 DNDStuff
*stuff
= WMGetHangedData(WMWidgetOfView(self
));
943 WMDestroyWidget(WMWidgetOfView(self
));
946 stuff
->mouseDown
= False
;
951 fetchDragData(WMView
*self
, char *type
)
953 DNDStuff
*stuff
= WMGetHangedData(WMWidgetOfView(self
));
955 return WMCreateDataWithBytes(stuff
->filename
, strlen(stuff
->filename
)+1);
959 WMDragSourceProcs dragSourceProcs
= {
967 /************************/
971 draggingEntered(WMView
*self
, WMDraggingInfo
*info
)
973 return WDOperationCopy
;
978 draggingUpdated(WMView
*self
, WMDraggingInfo
*info
)
980 return WDOperationCopy
;
984 void (*draggingExited)(WMView *self, WMDraggingInfo *info);
987 prepareForDragOperation(WMView
*self
, WMDraggingInfo
*info
)
989 return "application/X-WINGs-Bla";
993 WMLabel
* makeDraggableLabel(WMWidget
*w
, char *file
, int x
, int y
);
996 performDragOperation(WMView
*self
, WMDraggingInfo
*info
, WMData
*data
)
998 char *file
= (char*)WMDataBytes(data
);
1001 pos
= WMGetDraggingInfoImageLocation(info
);
1005 WMPoint pos2
= WMGetViewScreenPosition(self
);
1008 label
= makeDraggableLabel(WMWidgetOfView(self
), file
,
1009 pos
.x
-pos2
.x
, pos
.y
-pos2
.y
);
1010 WMRealizeWidget(label
);
1020 concludeDragOperation(WMView
*self
, WMDraggingInfo
*info
)
1027 WMDragDestinationProcs dragDestProcs
= {
1031 prepareForDragOperation
,
1032 performDragOperation
,
1033 concludeDragOperation
1040 makeDraggableLabel(WMWidget
*w
, char *file
, int x
, int y
)
1044 WMPixmap
*image
= getImage(WMWidgetScreen(w
), file
);
1046 stuff
= wmalloc(sizeof(DNDStuff
));
1047 stuff
->mouseDown
= False
;
1049 stuff
->filename
= wstrdup(file
);
1051 label
= WMCreateLabel(w
);
1052 WMResizeWidget(label
, 48, 48);
1053 WMMoveWidget(label
, x
, y
);
1055 WMSetViewDragSourceProcs(WMWidgetView(label
), &dragSourceProcs
);
1057 WMHangData(label
, stuff
);
1059 WMCreateEventHandler(WMWidgetView(label
),
1060 ButtonPressMask
|ButtonReleaseMask
|ButtonMotionMask
,
1061 iconMouseStuff
, label
);
1064 if (image
!= NULL
) {
1065 WMSetLabelImagePosition(label
, WIPImageOnly
);
1066 WMSetLabelImage(label
, image
);
1067 WMReleasePixmap(image
);
1076 testDragAndDrop(WMScreen
*scr
)
1085 "application/X-WINGs-Bla",
1091 win
= WMCreateWindow(scr
, "dragDrop");
1092 WMResizeWidget(win
, 300, 300);
1093 WMSetWindowCloseAction(win
, closeAction
, NULL
);
1094 WMSetWindowTitle(win
, "Drag and Drop");
1097 frame
= WMCreateFrame(win
);
1098 WMSetFrameRelief(frame
, WRSunken
);
1099 WMResizeWidget(frame
, 250, 250);
1100 WMMoveWidget(frame
, 25, 25);
1102 WMRegisterViewForDraggedTypes(WMWidgetView(frame
), types
);
1103 WMSetViewDragDestinationProcs(WMWidgetView(frame
), &dragDestProcs
);
1105 dir
= opendir("../../WindowMaker/Icons");
1107 perror("../../WindowMaker/Icons");
1111 for (i
= 0, j
=0; j
< 8; i
++) {
1116 if (strstr(ent
->d_name
, ".xpm")==NULL
) {
1120 label
= makeDraggableLabel(frame
, ent
->d_name
,4+(j
/4)*64, 4+(j
%4)*64);
1127 WMMapSubwidgets(frame
);
1129 WMMapSubwidgets(win
);
1130 WMRealizeWidget(win
);
1138 /*******************************************************************/
1145 WMUserDefaults
*defs
;
1148 defs
= WMGetStandardUserDefaults();
1150 sprintf(str
, "TEST DATA");
1152 WMSetUDStringForKey(defs
, str
, "testKey");
1158 main(int argc
, char **argv
)
1164 /* Initialize the application */
1165 WMInitializeApplication("Test", &argc
, argv
);
1170 * Open connection to the X display.
1172 dpy
= XOpenDisplay("");
1175 puts("could not open display");
1179 /* This is used to disable buffering of X protocol requests.
1180 * Do NOT use it unless when debugging. It will cause a major
1181 * slowdown in your application
1184 XSynchronize(dpy
, True
);
1187 * Create screen descriptor.
1189 scr
= WMCreateScreen(dpy
, DefaultScreen(dpy
));
1192 * Loads the logo of the application.
1194 pixmap
= WMCreatePixmapFromFile(scr
, "logo.xpm");
1197 * Makes the logo be used in standard dialog panels.
1199 WMSetApplicationIconImage(scr
, pixmap
); WMReleasePixmap(pixmap
);
1202 * Do some test stuff.
1204 * Put the testSomething() function you want to test here.
1215 testDragAndDrop(scr
);
1216 testDragAndDrop(scr
);
1219 testScrollView(scr
);
1232 testGradientButtons(scr
);
1233 testProgressIndicator(scr
);
1236 testOpenFilePanel(scr
);
1242 * The main event loop.
1245 WMScreenMainLoop(scr
);