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
);
508 testText(WMScreen
*scr
)
512 FILE *file
= fopen("../README", "r");
516 win
= WMCreateWindow(scr
, "testText");
517 WMResizeWidget(win
, 500, 300);
519 WMSetWindowCloseAction(win
, closeAction
, NULL
);
521 text
= WMCreateText(win
);
522 WMResizeWidget(text
, 480, 280);
523 WMMoveWidget(text
, 10, 10);
524 WMSetTextHasVerticalScroller(text
, True
);
525 WMSetTextEditable(text
, False
);
531 while(fgets(buf
, 1023, file
))
532 WMAppendTextStream(text
, buf
);
536 WMRefreshText(text
, 0, 0);
538 WMAppendTextStream(text
, "<HTML><i>Where's</i> the <b>README</b>?");
541 WMRealizeWidget(win
);
542 WMMapSubwidgets(win
);
549 testProgressIndicator(WMScreen
*scr
)
552 WMProgressIndicator
*pPtr
;
556 win
= WMCreateWindow(scr
, "testProgressIndicator");
557 WMResizeWidget(win
, 292, 32);
559 WMSetWindowCloseAction(win
, closeAction
, NULL
);
561 pPtr
= WMCreateProgressIndicator(win
);
562 WMMoveWidget(pPtr
, 8, 8);
563 WMSetProgressIndicatorValue(pPtr
, 75);
565 WMRealizeWidget(win
);
566 WMMapSubwidgets(win
);
573 testPullDown(WMScreen
*scr
)
576 WMPopUpButton
*pop
, *pop2
;
580 win
= WMCreateWindow(scr
, "pullDown");
581 WMResizeWidget(win
, 400, 300);
583 WMSetWindowCloseAction(win
, closeAction
, NULL
);
585 pop
= WMCreatePopUpButton(win
);
586 WMResizeWidget(pop
, 100, 20);
587 WMMoveWidget(pop
, 50, 60);
588 WMSetPopUpButtonPullsDown(pop
, True
);
589 WMSetPopUpButtonText(pop
, "Commands");
590 WMAddPopUpButtonItem(pop
, "Add");
591 WMAddPopUpButtonItem(pop
, "Remove");
592 WMAddPopUpButtonItem(pop
, "Check");
593 WMAddPopUpButtonItem(pop
, "Eat");
595 pop2
= WMCreatePopUpButton(win
);
596 WMResizeWidget(pop2
, 100, 20);
597 WMMoveWidget(pop2
, 200, 60);
598 WMSetPopUpButtonText(pop2
, "Select");
599 WMAddPopUpButtonItem(pop2
, "Apples");
600 WMAddPopUpButtonItem(pop2
, "Bananas");
601 WMAddPopUpButtonItem(pop2
, "Strawberries");
602 WMAddPopUpButtonItem(pop2
, "Blueberries");
604 WMRealizeWidget(win
);
605 WMMapSubwidgets(win
);
612 testTabView(WMScreen
*scr
)
622 win
= WMCreateWindow(scr
, "testTabs");
623 WMResizeWidget(win
, 400, 300);
625 WMSetWindowCloseAction(win
, closeAction
, NULL
);
627 tabv
= WMCreateTabView(win
);
628 WMMoveWidget(tabv
, 50, 50);
629 WMResizeWidget(tabv
, 300, 200);
631 frame
= WMCreateFrame(win
);
632 WMSetFrameRelief(frame
, WRFlat
);
633 label
= WMCreateLabel(frame
);
634 WMResizeWidget(label
, 100, 100);
635 WMSetLabelText(label
, "Label 1");
639 tab
= WMCreateTabViewItemWithIdentifier(0);
640 WMSetTabViewItemView(tab
, WMWidgetView(frame
));
641 WMAddItemInTabView(tabv
, tab
);
642 WMSetTabViewItemLabel(tab
, "Instances");
644 frame
= WMCreateFrame(win
);
645 WMSetFrameRelief(frame
, WRFlat
);
646 label
= WMCreateLabel(frame
);
647 WMResizeWidget(label
, 40, 50);
648 WMSetLabelText(label
, "Label 2");
652 tab
= WMCreateTabViewItemWithIdentifier(0);
653 WMSetTabViewItemView(tab
, WMWidgetView(frame
));
654 WMAddItemInTabView(tabv
, tab
);
655 WMSetTabViewItemLabel(tab
, "Classes");
658 frame
= WMCreateFrame(win
);
659 WMSetFrameRelief(frame
, WRFlat
);
660 label
= WMCreateLabel(frame
);
661 WMResizeWidget(label
, 100, 100);
662 WMMoveWidget(label
, 60, 40);
663 WMSetLabelText(label
, "Label 3");
666 tab
= WMCreateTabViewItemWithIdentifier(0);
667 WMSetTabViewItemView(tab
, WMWidgetView(frame
));
668 WMAddItemInTabView(tabv
, tab
);
669 WMSetTabViewItemLabel(tab
, "Something");
672 frame
= WMCreateFrame(win
);
673 WMSetFrameRelief(frame
, WRFlat
);
674 label
= WMCreateLabel(frame
);
675 WMResizeWidget(label
, 100, 100);
676 WMMoveWidget(label
, 160, 40);
677 WMSetLabelText(label
, "Label 4");
680 tab
= WMCreateTabViewItemWithIdentifier(0);
681 WMSetTabViewItemView(tab
, WMWidgetView(frame
));
682 WMAddItemInTabView(tabv
, tab
);
683 WMSetTabViewItemLabel(tab
, "Bla!");
687 frame
= WMCreateFrame(win
);
688 WMSetFrameRelief(frame
, WRFlat
);
689 label
= WMCreateLabel(frame
);
690 WMResizeWidget(label
, 100, 100);
691 WMMoveWidget(label
, 160, 40);
692 WMSetLabelText(label
, "Label fjweqklrj qwl");
694 tab
= WMCreateTabViewItemWithIdentifier(0);
695 WMSetTabViewItemView(tab
, WMWidgetView(frame
));
696 WMAddItemInTabView(tabv
, tab
);
697 WMSetTabViewItemLabel(tab
, "Weee!");
700 WMRealizeWidget(win
);
701 WMMapSubwidgets(win
);
707 splitViewConstrainProc(WMSplitView
*sPtr
, int indView
,
708 int *minSize
, int *maxSize
)
728 resizeSplitView(XEvent
*event
, void *data
)
730 WMSplitView
*sPtr
= (WMSplitView
*)data
;
732 if (event
->type
== ConfigureNotify
) {
733 int width
= event
->xconfigure
.width
- 10;
735 if (width
< WMGetSplitViewDividerThickness(sPtr
))
736 width
= WMGetSplitViewDividerThickness(sPtr
);
738 if (width
!= WMWidgetWidth(sPtr
) ||
739 event
->xconfigure
.height
!= WMWidgetHeight(sPtr
))
740 WMResizeWidget(sPtr
, width
, event
->xconfigure
.height
- 55);
745 appendSubviewButtonAction(WMWidget
*self
, void *data
)
747 WMSplitView
*sPtr
= (WMSplitView
*)data
;
749 WMLabel
*label
= WMCreateLabel(sPtr
);
751 sprintf(buf
, "Subview %d", WMGetSplitViewSubviewsCount(sPtr
) + 1);
752 WMSetLabelText(label
, buf
);
753 WMSetLabelRelief(label
, WRSunken
);
754 WMAddSplitViewSubview(sPtr
, WMWidgetView(label
));
755 WMRealizeWidget(label
);
760 removeSubviewButtonAction(WMWidget
*self
, void *data
)
762 WMSplitView
*sPtr
= (WMSplitView
*)data
;
763 int count
= WMGetSplitViewSubviewsCount(sPtr
);
766 WMView
*view
= WMGetSplitViewSubviewAt(sPtr
, count
-1);
767 WMDestroyWidget(WMWidgetOfView(view
));
768 WMRemoveSplitViewSubviewAt(sPtr
, count
-1);
773 orientationButtonAction(WMWidget
*self
, void *data
)
775 WMSplitView
*sPtr
= (WMSplitView
*)data
;
776 WMSetSplitViewVertical(sPtr
, !WMGetSplitViewVertical(sPtr
));
780 adjustSubviewsButtonAction(WMWidget
*self
, void *data
)
782 WMAdjustSplitViewSubviews((WMSplitView
*)data
);
786 testSplitView(WMScreen
*scr
)
789 WMSplitView
*splitv1
, *splitv2
;
796 win
= WMCreateWindow(scr
, "testTabs");
797 WMResizeWidget(win
, 300, 400);
798 WMSetWindowCloseAction(win
, closeAction
, NULL
);
800 frame
= WMCreateFrame(win
);
801 WMSetFrameRelief(frame
, WRSunken
);
802 WMMoveWidget(frame
, 5, 5);
803 WMResizeWidget(frame
, 290, 40);
805 splitv1
= WMCreateSplitView(win
);
806 WMMoveWidget(splitv1
, 5, 50);
807 WMResizeWidget(splitv1
, 290, 345);
808 WMSetSplitViewConstrainProc(splitv1
, splitViewConstrainProc
);
809 WMCreateEventHandler(WMWidgetView(win
), StructureNotifyMask
,
810 resizeSplitView
, splitv1
);
812 button
= WMCreateCommandButton(frame
);
813 WMSetButtonText(button
, "+");
814 WMSetButtonAction(button
, appendSubviewButtonAction
, splitv1
);
815 WMMoveWidget(button
, 10, 8);
818 button
= WMCreateCommandButton(frame
);
819 WMSetButtonText(button
, "-");
820 WMSetButtonAction(button
, removeSubviewButtonAction
, splitv1
);
821 WMMoveWidget(button
, 80, 8);
824 button
= WMCreateCommandButton(frame
);
825 WMSetButtonText(button
, "=");
826 WMMoveWidget(button
, 150, 8);
827 WMSetButtonAction(button
, adjustSubviewsButtonAction
, splitv1
);
830 button
= WMCreateCommandButton(frame
);
831 WMSetButtonText(button
, "#");
832 WMMoveWidget(button
, 220, 8);
833 WMSetButtonAction(button
, orientationButtonAction
, splitv1
);
836 label
= WMCreateLabel(splitv1
);
837 WMSetLabelText(label
, "Subview 1");
838 WMSetLabelRelief(label
, WRSunken
);
840 WMAddSplitViewSubview(splitv1
, WMWidgetView(label
));
842 splitv2
= WMCreateSplitView(splitv1
);
843 WMResizeWidget(splitv2
, 150, 150);
844 WMSetSplitViewVertical(splitv2
, True
);
846 label
= WMCreateLabel(splitv2
);
847 WMSetLabelText(label
, "Subview 2.1");
848 WMSetLabelRelief(label
, WRSunken
);
850 WMAddSplitViewSubview(splitv2
, WMWidgetView(label
));
852 label
= WMCreateLabel(splitv2
);
853 WMSetLabelText(label
, "Subview 2.2");
854 WMSetLabelRelief(label
, WRSunken
);
856 WMAddSplitViewSubview(splitv2
, WMWidgetView(label
));
858 label
= WMCreateLabel(splitv2
);
859 WMSetLabelText(label
, "Subview 2.3");
860 WMSetLabelRelief(label
, WRSunken
);
862 WMAddSplitViewSubview(splitv2
, WMWidgetView(label
));
864 WMMapWidget(splitv2
);
865 WMAddSplitViewSubview(splitv1
, WMWidgetView(splitv2
));
867 WMRealizeWidget(win
);
868 WMMapSubwidgets(win
);
873 /*******************************************************************/
875 #include <sys/types.h>
887 getImage(WMScreen
*scr
, char *file
)
892 sprintf(buffer
, "../../WindowMaker/Icons/%s", file
);
893 pix
= WMCreatePixmapFromFile(scr
, buffer
);
902 iconMouseStuff(XEvent
*event
, void *cdata
)
904 WMLabel
*label
= (WMLabel
*)cdata
;
905 DNDStuff
*stuff
= WMGetHangedData(label
);
908 switch (event
->type
) {
910 stuff
->x
= event
->xbutton
.x
;
911 stuff
->y
= event
->xbutton
.y
;
912 stuff
->mouseDown
= True
;
915 stuff
->mouseDown
= False
;
918 if (!stuff
->mouseDown
)
921 if (abs(stuff
->x
- event
->xmotion
.x
)>4
922 || abs(stuff
->y
- event
->xmotion
.y
)>4) {
924 where
= WMGetViewScreenPosition(WMWidgetView(label
));
926 WMDragImageFromView(WMWidgetView(label
),
927 WMGetLabelImage(label
),
930 wmksize(stuff
->x
, stuff
->y
),
939 endedDragImage(WMView
*self
, WMPixmap
*image
, WMPoint point
, Bool deposited
)
941 DNDStuff
*stuff
= WMGetHangedData(WMWidgetOfView(self
));
944 WMDestroyWidget(WMWidgetOfView(self
));
947 stuff
->mouseDown
= False
;
952 fetchDragData(WMView
*self
, char *type
)
954 DNDStuff
*stuff
= WMGetHangedData(WMWidgetOfView(self
));
956 return WMCreateDataWithBytes(stuff
->filename
, strlen(stuff
->filename
)+1);
960 WMDragSourceProcs dragSourceProcs
= {
968 /************************/
972 draggingEntered(WMView
*self
, WMDraggingInfo
*info
)
974 return WDOperationCopy
;
979 draggingUpdated(WMView
*self
, WMDraggingInfo
*info
)
981 return WDOperationCopy
;
985 void (*draggingExited)(WMView *self, WMDraggingInfo *info);
988 prepareForDragOperation(WMView
*self
, WMDraggingInfo
*info
)
990 return "application/X-WINGs-Bla";
994 WMLabel
* makeDraggableLabel(WMWidget
*w
, char *file
, int x
, int y
);
997 performDragOperation(WMView
*self
, WMDraggingInfo
*info
, WMData
*data
)
999 char *file
= (char*)WMDataBytes(data
);
1002 pos
= WMGetDraggingInfoImageLocation(info
);
1006 WMPoint pos2
= WMGetViewScreenPosition(self
);
1009 label
= makeDraggableLabel(WMWidgetOfView(self
), file
,
1010 pos
.x
-pos2
.x
, pos
.y
-pos2
.y
);
1011 WMRealizeWidget(label
);
1021 concludeDragOperation(WMView
*self
, WMDraggingInfo
*info
)
1028 WMDragDestinationProcs dragDestProcs
= {
1032 prepareForDragOperation
,
1033 performDragOperation
,
1034 concludeDragOperation
1041 makeDraggableLabel(WMWidget
*w
, char *file
, int x
, int y
)
1045 WMPixmap
*image
= getImage(WMWidgetScreen(w
), file
);
1047 stuff
= wmalloc(sizeof(DNDStuff
));
1048 stuff
->mouseDown
= False
;
1050 stuff
->filename
= wstrdup(file
);
1052 label
= WMCreateLabel(w
);
1053 WMResizeWidget(label
, 48, 48);
1054 WMMoveWidget(label
, x
, y
);
1056 WMSetViewDragSourceProcs(WMWidgetView(label
), &dragSourceProcs
);
1058 WMHangData(label
, stuff
);
1060 WMCreateEventHandler(WMWidgetView(label
),
1061 ButtonPressMask
|ButtonReleaseMask
|ButtonMotionMask
,
1062 iconMouseStuff
, label
);
1065 if (image
!= NULL
) {
1066 WMSetLabelImagePosition(label
, WIPImageOnly
);
1067 WMSetLabelImage(label
, image
);
1068 WMReleasePixmap(image
);
1077 testDragAndDrop(WMScreen
*scr
)
1086 "application/X-WINGs-Bla",
1092 win
= WMCreateWindow(scr
, "dragDrop");
1093 WMResizeWidget(win
, 300, 300);
1094 WMSetWindowCloseAction(win
, closeAction
, NULL
);
1095 WMSetWindowTitle(win
, "Drag and Drop");
1098 frame
= WMCreateFrame(win
);
1099 WMSetFrameRelief(frame
, WRSunken
);
1100 WMResizeWidget(frame
, 250, 250);
1101 WMMoveWidget(frame
, 25, 25);
1103 WMRegisterViewForDraggedTypes(WMWidgetView(frame
), types
);
1104 WMSetViewDragDestinationProcs(WMWidgetView(frame
), &dragDestProcs
);
1106 dir
= opendir("../../WindowMaker/Icons");
1108 perror("../../WindowMaker/Icons");
1112 for (i
= 0, j
=0; j
< 8; i
++) {
1117 if (strstr(ent
->d_name
, ".xpm")==NULL
) {
1121 label
= makeDraggableLabel(frame
, ent
->d_name
,4+(j
/4)*64, 4+(j
%4)*64);
1128 WMMapSubwidgets(frame
);
1130 WMMapSubwidgets(win
);
1131 WMRealizeWidget(win
);
1139 /*******************************************************************/
1146 WMUserDefaults
*defs
;
1149 defs
= WMGetStandardUserDefaults();
1151 sprintf(str
, "TEST DATA");
1153 WMSetUDStringForKey(defs
, str
, "testKey");
1159 main(int argc
, char **argv
)
1165 /* Initialize the application */
1166 WMInitializeApplication("Test", &argc
, argv
);
1171 * Open connection to the X display.
1173 dpy
= XOpenDisplay("");
1176 puts("could not open display");
1180 /* This is used to disable buffering of X protocol requests.
1181 * Do NOT use it unless when debugging. It will cause a major
1182 * slowdown in your application
1185 XSynchronize(dpy
, True
);
1188 * Create screen descriptor.
1190 scr
= WMCreateScreen(dpy
, DefaultScreen(dpy
));
1193 * Loads the logo of the application.
1195 pixmap
= WMCreatePixmapFromFile(scr
, "logo.xpm");
1198 * Makes the logo be used in standard dialog panels.
1200 WMSetApplicationIconImage(scr
, pixmap
); WMReleasePixmap(pixmap
);
1203 * Do some test stuff.
1205 * Put the testSomething() function you want to test here.
1216 testDragAndDrop(scr
);
1217 testDragAndDrop(scr
);
1220 testScrollView(scr
);
1233 testGradientButtons(scr
);
1234 testProgressIndicator(scr
);
1237 testOpenFilePanel(scr
);
1243 * The main event loop.
1246 WMScreenMainLoop(scr
);