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
)
33 WMDestroyWidget(self
);
35 printf("window closed, window count = %d\n", windowCount
);
42 testOpenFilePanel(WMScreen
*scr
)
48 /* get the shared Open File panel */
49 panel
= WMGetOpenPanel(scr
);
51 WMRunModalFilePanelForDirectory(panel
, NULL
, "/usr/local", NULL
, NULL
);
53 /* free the panel to save some memory. Not needed otherwise. */
54 WMFreeFilePanel(WMGetOpenPanel(scr
));
59 testFontPanel(WMScreen
*scr
)
65 panel
= WMGetFontPanel(scr
);
67 WMShowFontPanel(panel
);
69 /* WMFreeFontPanel(panel);*/
75 testFrame(WMScreen
*scr
)
80 static char* titles
[] = {
88 static WMTitlePosition pos
[] = {
99 win
= WMCreateWindow(scr
, "testFrame");
100 WMSetWindowTitle(win
, "Frame");
101 WMSetWindowCloseAction(win
, closeAction
, NULL
);
102 WMResizeWidget(win
, 400, 300);
104 for (i
= 0; i
< 6; i
++) {
105 frame
= WMCreateFrame(win
);
106 WMMoveWidget(frame
, 8+(i
%3)*130, 8+(i
/3)*130);
107 WMResizeWidget(frame
, 120, 120);
108 WMSetFrameTitle(frame
, titles
[i
]);
109 WMSetFrameTitlePosition(frame
, pos
[i
]);
112 WMRealizeWidget(win
);
113 WMMapSubwidgets(win
);
120 singleClick(WMWidget
*self
, void *data
)
126 doubleClick(WMWidget
*self
, void *data
)
128 WMLabel
*label
= (WMLabel
*)data
;
129 WMList
*lPtr
= (WMList
*)self
;
132 WMSelectAllListItems(lPtr
);
134 //sprintf(buf, "Selected items: %d",
135 // WMGetArrayItemCount(WMGetListSelectedItems(lPtr)));;
136 //WMSetLabelText(label, buf);
141 listSelectionObserver(void *observer
, WMNotification
*notification
)
143 WMLabel
*label
= (WMLabel
*)observer
;
144 WMList
*lPtr
= (WMList
*)WMGetNotificationObject(notification
);
147 sprintf(buf
, "Selected items: %d",
148 WMGetArrayItemCount(WMGetListSelectedItems(lPtr
)));;
149 WMSetLabelText(label
, buf
);
154 testList(WMScreen
*scr
)
168 win
= WMCreateWindow(scr
, "testList");
169 WMResizeWidget(win
, 370, 250);
170 WMSetWindowTitle(win
, "List");
171 WMSetWindowCloseAction(win
, closeAction
, NULL
);
173 title
= WMCreateLabel(win
);
174 WMResizeWidget(title
, 150, 20);
175 WMMoveWidget(title
, 10, 10);
176 WMSetLabelRelief(title
, WRRidge
);
177 WMSetLabelText(title
, "Single selection list");
179 mtitle
= WMCreateLabel(win
);
180 WMResizeWidget(mtitle
, 150, 20);
181 WMMoveWidget(mtitle
, 210, 10);
182 WMSetLabelRelief(mtitle
, WRRidge
);
183 WMSetLabelText(mtitle
, "Multiple selection list");
185 list
= WMCreateList(win
);
186 //WMSetListAllowEmptySelection(list, True);
187 WMMoveWidget(list
, 10, 40);
188 for (i
=0; i
<50; i
++) {
189 sprintf(text
, "Item %i", i
);
190 WMAddListItem(list
, text
);
192 mlist
= WMCreateList(win
);
193 WMSetListAllowMultipleSelection(mlist
, True
);
194 //WMSetListAllowEmptySelection(mlist, True);
195 WMMoveWidget(mlist
, 210, 40);
196 for (i
=0; i
<135; i
++) {
197 sprintf(text
, "Item %i", i
);
198 WMAddListItem(mlist
, text
);
201 label
= WMCreateLabel(win
);
202 WMResizeWidget(label
, 150, 40);
203 WMMoveWidget(label
, 10, 200);
204 WMSetLabelRelief(label
, WRRidge
);
205 WMSetLabelText(label
, "Selected items: 0");
207 mlabel
= WMCreateLabel(win
);
208 WMResizeWidget(mlabel
, 150, 40);
209 WMMoveWidget(mlabel
, 210, 200);
210 WMSetLabelRelief(mlabel
, WRRidge
);
211 WMSetLabelText(mlabel
, "Selected items: 0");
213 WMSetListAction(list
, singleClick
, label
);
214 WMSetListDoubleAction(list
, doubleClick
, label
);
215 WMSetListAction(mlist
, singleClick
, mlabel
);
216 WMSetListDoubleAction(mlist
, doubleClick
, mlabel
);
218 WMAddNotificationObserver(listSelectionObserver
, label
,
219 WMListSelectionDidChangeNotification
, list
);
220 WMAddNotificationObserver(listSelectionObserver
, mlabel
,
221 WMListSelectionDidChangeNotification
, mlist
);
224 WMRealizeWidget(win
);
225 WMMapSubwidgets(win
);
231 testButton(WMScreen
*scr
)
248 win
= WMCreateWindow(scr
, "testButton");
249 WMResizeWidget(win
, 300, 300);
250 WMSetWindowTitle(win
, "Buttons");
252 WMSetWindowCloseAction(win
, closeAction
, NULL
);
254 for (i
= 1; i
< 9; i
++) {
256 b
= WMCreateButton(win
, i
);
257 WMResizeWidget(b
, 150, 24);
258 WMMoveWidget(b
, 20, i
*30);
259 WMSetButtonText(b
, types
[i
-1]);
262 WMRealizeWidget(win
);
263 WMMapSubwidgets(win
);
269 testGradientButtons(WMScreen
*scr
)
273 WMPixmap
*pix1
, *pix2
;
276 WMColor
*color
, *altColor
;
280 /* creates the top-level window */
281 win
= WMCreateWindow(scr
, "testGradientButtons");
282 WMSetWindowTitle(win
, "Gradiented Button Demo");
283 WMResizeWidget(win
, 300, 200);
292 color
= WMCreateRGBColor(scr
, 0x5900, 0x5100, 0x5900, True
);
293 WMSetWidgetBackgroundColor(win
, color
);
294 WMReleaseColor(color
);
296 back
= RRenderGradient(60, 24, &dark
, &light
, RGRD_DIAGONAL
);
297 RBevelImage(back
, RBEV_RAISED2
);
298 pix1
= WMCreatePixmapFromRImage(scr
, back
, 0);
301 back
= RRenderGradient(60, 24, &dark
, &light
, RGRD_DIAGONAL
);
302 RBevelImage(back
, RBEV_SUNKEN
);
303 pix2
= WMCreatePixmapFromRImage(scr
, back
, 0);
306 color
= WMWhiteColor(scr
);
307 altColor
= WMCreateNamedColor(scr
, "red", True
);
309 btn
= WMCreateButton(win
, WBTMomentaryChange
);
310 WMResizeWidget(btn
, 60, 24);
311 WMMoveWidget(btn
, 20, 100);
312 WMSetButtonBordered(btn
, False
);
313 WMSetButtonImagePosition(btn
, WIPOverlaps
);
314 WMSetButtonImage(btn
, pix1
);
315 WMSetButtonAltImage(btn
, pix2
);
316 WMSetButtonText(btn
, "Cool");
317 WMSetButtonTextColor(btn
, color
);
318 WMSetButtonAltTextColor(btn
, altColor
);
320 WMSetBalloonTextForView("This is a cool button", WMWidgetView(btn
));
322 btn
= WMCreateButton(win
, WBTMomentaryChange
);
323 WMResizeWidget(btn
, 60, 24);
324 WMMoveWidget(btn
, 90, 100);
325 WMSetButtonBordered(btn
, False
);
326 WMSetButtonImagePosition(btn
, WIPOverlaps
);
327 WMSetButtonImage(btn
, pix1
);
328 WMSetButtonAltImage(btn
, pix2
);
329 WMSetButtonText(btn
, "Button");
330 WMSetButtonTextColor(btn
, color
);
332 WMSetBalloonTextForView("Este é outro balão.", WMWidgetView(btn
));
334 WMReleaseColor(color
);
335 color
= WMCreateNamedColor(scr
, "orange", True
);
337 btn
= WMCreateButton(win
, WBTMomentaryChange
);
338 WMResizeWidget(btn
, 60, 24);
339 WMMoveWidget(btn
, 160, 100);
340 WMSetButtonBordered(btn
, False
);
341 WMSetButtonImagePosition(btn
, WIPOverlaps
);
342 WMSetButtonImage(btn
, pix1
);
343 WMSetButtonAltImage(btn
, pix2
);
344 WMSetButtonText(btn
, "Test");
345 WMSetButtonTextColor(btn
, color
);
347 WMSetBalloonTextForView("This is yet another button.\nBut the balloon has 3 lines.\nYay!",
350 WMReleaseColor(color
);
351 WMReleaseColor(altColor
);
353 WMRealizeWidget(win
);
354 WMMapSubwidgets(win
);
360 testScrollView(WMScreen
*scr
)
371 /* creates the top-level window */
372 win
= WMCreateWindow(scr
, "testScroll");
373 WMSetWindowTitle(win
, "Scrollable View");
375 WMSetWindowCloseAction(win
, closeAction
, NULL
);
377 /* set the window size */
378 WMResizeWidget(win
, 300, 300);
380 /* creates a scrollable view inside the top-level window */
381 sview
= WMCreateScrollView(win
);
382 WMResizeWidget(sview
, 200, 200);
383 WMMoveWidget(sview
, 30, 30);
384 WMSetScrollViewRelief(sview
, WRSunken
);
385 WMSetScrollViewHasVerticalScroller(sview
, True
);
386 WMSetScrollViewHasHorizontalScroller(sview
, True
);
388 /* create a frame with a bunch of labels */
389 f
= WMCreateFrame(win
);
390 WMResizeWidget(f
, 400, 400);
391 WMSetFrameRelief(f
, WRFlat
);
393 for (i
=0; i
<20; i
++) {
394 l
= WMCreateLabel(f
);
395 WMResizeWidget(l
, 50, 18);
396 WMMoveWidget(l
, 10, 20*i
);
397 sprintf(buffer
, "Label %i", i
);
398 WMSetLabelText(l
, buffer
);
399 WMSetLabelRelief(l
, WRSimple
);
404 WMSetScrollViewContentView(sview
, WMWidgetView(f
));
406 /* make the windows of the widgets be actually created */
407 WMRealizeWidget(win
);
409 /* Map all child widgets of the top-level be mapped.
410 * You must call this for each container widget (like frames),
411 * even if they are childs of the top-level window.
413 WMMapSubwidgets(win
);
415 /* map the top-level window */
421 testColorWell(WMScreen
*scr
)
424 WMColorWell
*well1
, *well2
;
428 win
= WMCreateWindow(scr
, "testColor");
429 WMResizeWidget(win
, 300, 300);
430 WMSetWindowCloseAction(win
, closeAction
, NULL
);
432 well1
= WMCreateColorWell(win
);
433 WMResizeWidget(well1
, 60, 40);
434 WMMoveWidget(well1
, 100, 100);
435 WMSetColorWellColor(well1
, WMCreateRGBColor(scr
, 0x8888, 0, 0x1111, True
));
436 well2
= WMCreateColorWell(win
);
437 WMResizeWidget(well2
, 60, 40);
438 WMMoveWidget(well2
, 200, 100);
439 WMSetColorWellColor(well2
, WMCreateRGBColor(scr
, 0, 0, 0x8888, True
));
441 WMRealizeWidget(win
);
442 WMMapSubwidgets(win
);
447 sliderCallback(WMWidget
*w
, void *data
)
449 printf("SLIDER == %i\n", WMGetSliderValue(w
));
454 testSlider(WMScreen
*scr
)
461 win
= WMCreateWindow(scr
, "testSlider");
462 WMResizeWidget(win
, 300, 300);
463 WMSetWindowTitle(win
, "Sliders");
465 WMSetWindowCloseAction(win
, closeAction
, NULL
);
467 s
= WMCreateSlider(win
);
468 WMResizeWidget(s
, 16, 100);
469 WMMoveWidget(s
, 100, 100);
470 WMSetSliderKnobThickness(s
, 8);
471 WMSetSliderContinuous(s
, False
);
472 WMSetSliderAction(s
, sliderCallback
, s
);
474 s
= WMCreateSlider(win
);
475 WMResizeWidget(s
, 100, 16);
476 WMMoveWidget(s
, 100, 10);
477 WMSetSliderKnobThickness(s
, 8);
479 WMRealizeWidget(win
);
480 WMMapSubwidgets(win
);
485 testTextField(WMScreen
*scr
)
488 WMTextField
*field
, *field2
;
492 win
= WMCreateWindow(scr
, "testTextField");
493 WMResizeWidget(win
, 400, 300);
495 WMSetWindowCloseAction(win
, closeAction
, NULL
);
497 field
= WMCreateTextField(win
);
498 WMResizeWidget(field
, 200, 20);
499 WMMoveWidget(field
, 20, 20);
501 field2
= WMCreateTextField(win
);
502 WMResizeWidget(field2
, 200, 20);
503 WMMoveWidget(field2
, 20, 50);
504 WMSetTextFieldAlignment(field2
, WARight
);
506 WMRealizeWidget(win
);
507 WMMapSubwidgets(win
);
513 testText(WMScreen
*scr
)
517 FILE *file
= fopen("../README", "r");
521 win
= WMCreateWindow(scr
, "testText");
522 WMResizeWidget(win
, 500, 300);
524 WMSetWindowCloseAction(win
, closeAction
, NULL
);
526 text
= WMCreateText(win
);
527 WMResizeWidget(text
, 480, 280);
528 WMMoveWidget(text
, 10, 10);
529 WMSetTextHasVerticalScroller(text
, True
);
530 WMSetTextEditable(text
, False
);
536 while(fgets(buf
, 1023, file
))
537 WMAppendTextStream(text
, buf
);
541 WMRefreshText(text
, 0, 0);
543 WMAppendTextStream(text
, "<HTML><i>Where's</i> the <b>README</b>?");
546 WMRealizeWidget(win
);
547 WMMapSubwidgets(win
);
554 testProgressIndicator(WMScreen
*scr
)
557 WMProgressIndicator
*pPtr
;
561 win
= WMCreateWindow(scr
, "testProgressIndicator");
562 WMResizeWidget(win
, 292, 32);
564 WMSetWindowCloseAction(win
, closeAction
, NULL
);
566 pPtr
= WMCreateProgressIndicator(win
);
567 WMMoveWidget(pPtr
, 8, 8);
568 WMSetProgressIndicatorValue(pPtr
, 75);
570 WMRealizeWidget(win
);
571 WMMapSubwidgets(win
);
578 testPullDown(WMScreen
*scr
)
581 WMPopUpButton
*pop
, *pop2
;
585 win
= WMCreateWindow(scr
, "pullDown");
586 WMResizeWidget(win
, 400, 300);
588 WMSetWindowCloseAction(win
, closeAction
, NULL
);
590 pop
= WMCreatePopUpButton(win
);
591 WMResizeWidget(pop
, 100, 20);
592 WMMoveWidget(pop
, 50, 60);
593 WMSetPopUpButtonPullsDown(pop
, True
);
594 WMSetPopUpButtonText(pop
, "Commands");
595 WMAddPopUpButtonItem(pop
, "Add");
596 WMAddPopUpButtonItem(pop
, "Remove");
597 WMAddPopUpButtonItem(pop
, "Check");
598 WMAddPopUpButtonItem(pop
, "Eat");
600 pop2
= WMCreatePopUpButton(win
);
601 WMResizeWidget(pop2
, 100, 20);
602 WMMoveWidget(pop2
, 200, 60);
603 WMSetPopUpButtonText(pop2
, "Select");
604 WMAddPopUpButtonItem(pop2
, "Apples");
605 WMAddPopUpButtonItem(pop2
, "Bananas");
606 WMAddPopUpButtonItem(pop2
, "Strawberries");
607 WMAddPopUpButtonItem(pop2
, "Blueberries");
609 WMRealizeWidget(win
);
610 WMMapSubwidgets(win
);
617 testTabView(WMScreen
*scr
)
627 win
= WMCreateWindow(scr
, "testTabs");
628 WMResizeWidget(win
, 400, 300);
630 WMSetWindowCloseAction(win
, closeAction
, NULL
);
632 tabv
= WMCreateTabView(win
);
633 WMMoveWidget(tabv
, 50, 50);
634 WMResizeWidget(tabv
, 300, 200);
636 frame
= WMCreateFrame(win
);
637 WMSetFrameRelief(frame
, WRFlat
);
638 label
= WMCreateLabel(frame
);
639 WMResizeWidget(label
, 100, 100);
640 WMSetLabelText(label
, "Label 1");
644 tab
= WMCreateTabViewItemWithIdentifier(0);
645 WMSetTabViewItemView(tab
, WMWidgetView(frame
));
646 WMAddItemInTabView(tabv
, tab
);
647 WMSetTabViewItemLabel(tab
, "Instances");
649 frame
= WMCreateFrame(win
);
650 WMSetFrameRelief(frame
, WRFlat
);
651 label
= WMCreateLabel(frame
);
652 WMResizeWidget(label
, 40, 50);
653 WMSetLabelText(label
, "Label 2");
657 tab
= WMCreateTabViewItemWithIdentifier(0);
658 WMSetTabViewItemView(tab
, WMWidgetView(frame
));
659 WMAddItemInTabView(tabv
, tab
);
660 WMSetTabViewItemLabel(tab
, "Classes");
663 frame
= WMCreateFrame(win
);
664 WMSetFrameRelief(frame
, WRFlat
);
665 label
= WMCreateLabel(frame
);
666 WMResizeWidget(label
, 100, 100);
667 WMMoveWidget(label
, 60, 40);
668 WMSetLabelText(label
, "Label 3");
671 tab
= WMCreateTabViewItemWithIdentifier(0);
672 WMSetTabViewItemView(tab
, WMWidgetView(frame
));
673 WMAddItemInTabView(tabv
, tab
);
674 WMSetTabViewItemLabel(tab
, "Something");
677 frame
= WMCreateFrame(win
);
678 WMSetFrameRelief(frame
, WRFlat
);
679 label
= WMCreateLabel(frame
);
680 WMResizeWidget(label
, 100, 100);
681 WMMoveWidget(label
, 160, 40);
682 WMSetLabelText(label
, "Label 4");
685 tab
= WMCreateTabViewItemWithIdentifier(0);
686 WMSetTabViewItemView(tab
, WMWidgetView(frame
));
687 WMAddItemInTabView(tabv
, tab
);
688 WMSetTabViewItemLabel(tab
, "Bla!");
692 frame
= WMCreateFrame(win
);
693 WMSetFrameRelief(frame
, WRFlat
);
694 label
= WMCreateLabel(frame
);
695 WMResizeWidget(label
, 100, 100);
696 WMMoveWidget(label
, 160, 40);
697 WMSetLabelText(label
, "Label fjweqklrj qwl");
699 tab
= WMCreateTabViewItemWithIdentifier(0);
700 WMSetTabViewItemView(tab
, WMWidgetView(frame
));
701 WMAddItemInTabView(tabv
, tab
);
702 WMSetTabViewItemLabel(tab
, "Weee!");
705 WMRealizeWidget(win
);
706 WMMapSubwidgets(win
);
712 splitViewConstrainProc(WMSplitView
*sPtr
, int indView
,
713 int *minSize
, int *maxSize
)
733 resizeSplitView(XEvent
*event
, void *data
)
735 WMSplitView
*sPtr
= (WMSplitView
*)data
;
737 if (event
->type
== ConfigureNotify
) {
738 int width
= event
->xconfigure
.width
- 10;
740 if (width
< WMGetSplitViewDividerThickness(sPtr
))
741 width
= WMGetSplitViewDividerThickness(sPtr
);
743 if (width
!= WMWidgetWidth(sPtr
) ||
744 event
->xconfigure
.height
!= WMWidgetHeight(sPtr
))
745 WMResizeWidget(sPtr
, width
, event
->xconfigure
.height
- 55);
750 appendSubviewButtonAction(WMWidget
*self
, void *data
)
752 WMSplitView
*sPtr
= (WMSplitView
*)data
;
754 WMLabel
*label
= WMCreateLabel(sPtr
);
756 sprintf(buf
, "Subview %d", WMGetSplitViewSubviewsCount(sPtr
) + 1);
757 WMSetLabelText(label
, buf
);
758 WMSetLabelRelief(label
, WRSunken
);
759 WMAddSplitViewSubview(sPtr
, WMWidgetView(label
));
760 WMRealizeWidget(label
);
765 removeSubviewButtonAction(WMWidget
*self
, void *data
)
767 WMSplitView
*sPtr
= (WMSplitView
*)data
;
768 int count
= WMGetSplitViewSubviewsCount(sPtr
);
771 WMView
*view
= WMGetSplitViewSubviewAt(sPtr
, count
-1);
772 WMDestroyWidget(WMWidgetOfView(view
));
773 WMRemoveSplitViewSubviewAt(sPtr
, count
-1);
778 orientationButtonAction(WMWidget
*self
, void *data
)
780 WMSplitView
*sPtr
= (WMSplitView
*)data
;
781 WMSetSplitViewVertical(sPtr
, !WMGetSplitViewVertical(sPtr
));
785 adjustSubviewsButtonAction(WMWidget
*self
, void *data
)
787 WMAdjustSplitViewSubviews((WMSplitView
*)data
);
791 testSplitView(WMScreen
*scr
)
794 WMSplitView
*splitv1
, *splitv2
;
801 win
= WMCreateWindow(scr
, "testTabs");
802 WMResizeWidget(win
, 300, 400);
803 WMSetWindowCloseAction(win
, closeAction
, NULL
);
805 frame
= WMCreateFrame(win
);
806 WMSetFrameRelief(frame
, WRSunken
);
807 WMMoveWidget(frame
, 5, 5);
808 WMResizeWidget(frame
, 290, 40);
810 splitv1
= WMCreateSplitView(win
);
811 WMMoveWidget(splitv1
, 5, 50);
812 WMResizeWidget(splitv1
, 290, 345);
813 WMSetSplitViewConstrainProc(splitv1
, splitViewConstrainProc
);
814 WMCreateEventHandler(WMWidgetView(win
), StructureNotifyMask
,
815 resizeSplitView
, splitv1
);
817 button
= WMCreateCommandButton(frame
);
818 WMSetButtonText(button
, "+");
819 WMSetButtonAction(button
, appendSubviewButtonAction
, splitv1
);
820 WMMoveWidget(button
, 10, 8);
823 button
= WMCreateCommandButton(frame
);
824 WMSetButtonText(button
, "-");
825 WMSetButtonAction(button
, removeSubviewButtonAction
, splitv1
);
826 WMMoveWidget(button
, 80, 8);
829 button
= WMCreateCommandButton(frame
);
830 WMSetButtonText(button
, "=");
831 WMMoveWidget(button
, 150, 8);
832 WMSetButtonAction(button
, adjustSubviewsButtonAction
, splitv1
);
835 button
= WMCreateCommandButton(frame
);
836 WMSetButtonText(button
, "#");
837 WMMoveWidget(button
, 220, 8);
838 WMSetButtonAction(button
, orientationButtonAction
, splitv1
);
841 label
= WMCreateLabel(splitv1
);
842 WMSetLabelText(label
, "Subview 1");
843 WMSetLabelRelief(label
, WRSunken
);
845 WMAddSplitViewSubview(splitv1
, WMWidgetView(label
));
847 splitv2
= WMCreateSplitView(splitv1
);
848 WMResizeWidget(splitv2
, 150, 150);
849 WMSetSplitViewVertical(splitv2
, True
);
851 label
= WMCreateLabel(splitv2
);
852 WMSetLabelText(label
, "Subview 2.1");
853 WMSetLabelRelief(label
, WRSunken
);
855 WMAddSplitViewSubview(splitv2
, WMWidgetView(label
));
857 label
= WMCreateLabel(splitv2
);
858 WMSetLabelText(label
, "Subview 2.2");
859 WMSetLabelRelief(label
, WRSunken
);
861 WMAddSplitViewSubview(splitv2
, WMWidgetView(label
));
863 label
= WMCreateLabel(splitv2
);
864 WMSetLabelText(label
, "Subview 2.3");
865 WMSetLabelRelief(label
, WRSunken
);
867 WMAddSplitViewSubview(splitv2
, WMWidgetView(label
));
869 WMMapWidget(splitv2
);
870 WMAddSplitViewSubview(splitv1
, WMWidgetView(splitv2
));
872 WMRealizeWidget(win
);
873 WMMapSubwidgets(win
);
878 /*******************************************************************/
880 #include <sys/types.h>
892 getImage(WMScreen
*scr
, char *file
)
897 sprintf(buffer
, "../../WindowMaker/Icons/%s", file
);
898 pix
= WMCreatePixmapFromFile(scr
, buffer
);
907 iconMouseStuff(XEvent
*event
, void *cdata
)
909 WMLabel
*label
= (WMLabel
*)cdata
;
910 DNDStuff
*stuff
= WMGetHangedData(label
);
913 switch (event
->type
) {
915 stuff
->x
= event
->xbutton
.x
;
916 stuff
->y
= event
->xbutton
.y
;
917 stuff
->mouseDown
= True
;
920 stuff
->mouseDown
= False
;
923 if (!stuff
->mouseDown
)
926 if (abs(stuff
->x
- event
->xmotion
.x
)>4
927 || abs(stuff
->y
- event
->xmotion
.y
)>4) {
929 where
= WMGetViewScreenPosition(WMWidgetView(label
));
931 WMDragImageFromView(WMWidgetView(label
),
932 WMGetLabelImage(label
),
935 wmksize(stuff
->x
, stuff
->y
),
944 endedDragImage(WMView
*self
, WMPixmap
*image
, WMPoint point
, Bool deposited
)
946 DNDStuff
*stuff
= WMGetHangedData(WMWidgetOfView(self
));
949 WMDestroyWidget(WMWidgetOfView(self
));
952 stuff
->mouseDown
= False
;
957 fetchDragData(WMView
*self
, char *type
)
959 DNDStuff
*stuff
= WMGetHangedData(WMWidgetOfView(self
));
961 return WMCreateDataWithBytes(stuff
->filename
, strlen(stuff
->filename
)+1);
965 WMDragSourceProcs dragSourceProcs
= {
973 /************************/
977 draggingEntered(WMView
*self
, WMDraggingInfo
*info
)
979 return WDOperationCopy
;
984 draggingUpdated(WMView
*self
, WMDraggingInfo
*info
)
986 return WDOperationCopy
;
990 void (*draggingExited)(WMView *self, WMDraggingInfo *info);
993 prepareForDragOperation(WMView
*self
, WMDraggingInfo
*info
)
995 return "application/X-WINGs-Bla";
999 WMLabel
* makeDraggableLabel(WMWidget
*w
, char *file
, int x
, int y
);
1002 performDragOperation(WMView
*self
, WMDraggingInfo
*info
, WMData
*data
)
1004 char *file
= (char*)WMDataBytes(data
);
1007 pos
= WMGetDraggingInfoImageLocation(info
);
1011 WMPoint pos2
= WMGetViewScreenPosition(self
);
1014 label
= makeDraggableLabel(WMWidgetOfView(self
), file
,
1015 pos
.x
-pos2
.x
, pos
.y
-pos2
.y
);
1016 WMRealizeWidget(label
);
1026 concludeDragOperation(WMView
*self
, WMDraggingInfo
*info
)
1033 WMDragDestinationProcs dragDestProcs
= {
1037 prepareForDragOperation
,
1038 performDragOperation
,
1039 concludeDragOperation
1046 makeDraggableLabel(WMWidget
*w
, char *file
, int x
, int y
)
1050 WMPixmap
*image
= getImage(WMWidgetScreen(w
), file
);
1052 stuff
= wmalloc(sizeof(DNDStuff
));
1053 stuff
->mouseDown
= False
;
1055 stuff
->filename
= wstrdup(file
);
1057 label
= WMCreateLabel(w
);
1058 WMResizeWidget(label
, 48, 48);
1059 WMMoveWidget(label
, x
, y
);
1061 WMSetViewDragSourceProcs(WMWidgetView(label
), &dragSourceProcs
);
1063 WMHangData(label
, stuff
);
1065 WMCreateEventHandler(WMWidgetView(label
),
1066 ButtonPressMask
|ButtonReleaseMask
|ButtonMotionMask
,
1067 iconMouseStuff
, label
);
1070 if (image
!= NULL
) {
1071 WMSetLabelImagePosition(label
, WIPImageOnly
);
1072 WMSetLabelImage(label
, image
);
1073 WMReleasePixmap(image
);
1082 testDragAndDrop(WMScreen
*scr
)
1091 "application/X-WINGs-Bla",
1097 win
= WMCreateWindow(scr
, "dragDrop");
1098 WMResizeWidget(win
, 300, 300);
1099 WMSetWindowCloseAction(win
, closeAction
, NULL
);
1100 WMSetWindowTitle(win
, "Drag and Drop");
1103 frame
= WMCreateFrame(win
);
1104 WMSetFrameRelief(frame
, WRSunken
);
1105 WMResizeWidget(frame
, 250, 250);
1106 WMMoveWidget(frame
, 25, 25);
1108 WMRegisterViewForDraggedTypes(WMWidgetView(frame
), types
);
1109 WMSetViewDragDestinationProcs(WMWidgetView(frame
), &dragDestProcs
);
1111 dir
= opendir("../../WindowMaker/Icons");
1113 perror("../../WindowMaker/Icons");
1117 for (i
= 0, j
=0; j
< 8; i
++) {
1122 if (strstr(ent
->d_name
, ".xpm")==NULL
) {
1126 label
= makeDraggableLabel(frame
, ent
->d_name
,4+(j
/4)*64, 4+(j
%4)*64);
1133 WMMapSubwidgets(frame
);
1135 WMMapSubwidgets(win
);
1136 WMRealizeWidget(win
);
1144 /*******************************************************************/
1151 WMUserDefaults
*defs
;
1154 defs
= WMGetStandardUserDefaults();
1156 sprintf(str
, "TEST DATA");
1158 WMSetUDStringForKey(defs
, str
, "testKey");
1164 main(int argc
, char **argv
)
1170 /* Initialize the application */
1171 WMInitializeApplication("Test", &argc
, argv
);
1176 * Open connection to the X display.
1178 dpy
= XOpenDisplay("");
1181 puts("could not open display");
1185 /* This is used to disable buffering of X protocol requests.
1186 * Do NOT use it unless when debugging. It will cause a major
1187 * slowdown in your application
1190 XSynchronize(dpy
, True
);
1193 * Create screen descriptor.
1195 scr
= WMCreateScreen(dpy
, DefaultScreen(dpy
));
1198 * Loads the logo of the application.
1200 pixmap
= WMCreatePixmapFromFile(scr
, "logo.xpm");
1203 * Makes the logo be used in standard dialog panels.
1205 WMSetApplicationIconImage(scr
, pixmap
); WMReleasePixmap(pixmap
);
1208 * Do some test stuff.
1210 * Put the testSomething() function you want to test here.
1221 testDragAndDrop(scr
);
1222 testDragAndDrop(scr
);
1225 testScrollView(scr
);
1238 testGradientButtons(scr
);
1239 testProgressIndicator(scr
);
1242 testOpenFilePanel(scr
);
1248 * The main event loop.
1251 WMScreenMainLoop(scr
);