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
);
137 listSelectionObserver(void *observer
, WMNotification
*notification
)
139 WMLabel
*label
= (WMLabel
*)observer
;
140 WMList
*lPtr
= (WMList
*)WMGetNotificationObject(notification
);
143 sprintf(buf
, "Selected items: %d",
144 WMGetArrayItemCount(WMGetListSelectedItems(lPtr
)));
145 WMSetLabelText(label
, buf
);
150 testList(WMScreen
*scr
)
164 win
= WMCreateWindow(scr
, "testList");
165 WMResizeWidget(win
, 370, 250);
166 WMSetWindowTitle(win
, "List");
167 WMSetWindowCloseAction(win
, closeAction
, NULL
);
169 title
= WMCreateLabel(win
);
170 WMResizeWidget(title
, 150, 20);
171 WMMoveWidget(title
, 10, 10);
172 WMSetLabelRelief(title
, WRRidge
);
173 WMSetLabelText(title
, "Single selection list");
175 mtitle
= WMCreateLabel(win
);
176 WMResizeWidget(mtitle
, 150, 20);
177 WMMoveWidget(mtitle
, 210, 10);
178 WMSetLabelRelief(mtitle
, WRRidge
);
179 WMSetLabelText(mtitle
, "Multiple selection list");
181 list
= WMCreateList(win
);
182 //WMSetListAllowEmptySelection(list, True);
183 WMMoveWidget(list
, 10, 40);
184 for (i
=0; i
<50; i
++) {
185 sprintf(text
, "Item %i", i
);
186 WMAddListItem(list
, text
);
188 mlist
= WMCreateList(win
);
189 WMSetListAllowMultipleSelection(mlist
, True
);
190 //WMSetListAllowEmptySelection(mlist, True);
191 WMMoveWidget(mlist
, 210, 40);
192 for (i
=0; i
<135; i
++) {
193 sprintf(text
, "Item %i", i
);
194 WMAddListItem(mlist
, text
);
197 label
= WMCreateLabel(win
);
198 WMResizeWidget(label
, 150, 40);
199 WMMoveWidget(label
, 10, 200);
200 WMSetLabelRelief(label
, WRRidge
);
201 WMSetLabelText(label
, "Selected items: 0");
203 mlabel
= WMCreateLabel(win
);
204 WMResizeWidget(mlabel
, 150, 40);
205 WMMoveWidget(mlabel
, 210, 200);
206 WMSetLabelRelief(mlabel
, WRRidge
);
207 WMSetLabelText(mlabel
, "Selected items: 0");
209 WMSetListAction(list
, singleClick
, label
);
210 WMSetListDoubleAction(list
, doubleClick
, label
);
211 WMSetListAction(mlist
, singleClick
, mlabel
);
212 WMSetListDoubleAction(mlist
, doubleClick
, mlabel
);
214 WMAddNotificationObserver(listSelectionObserver
, label
,
215 WMListSelectionDidChangeNotification
, list
);
216 WMAddNotificationObserver(listSelectionObserver
, mlabel
,
217 WMListSelectionDidChangeNotification
, mlist
);
220 WMRealizeWidget(win
);
221 WMMapSubwidgets(win
);
227 testButton(WMScreen
*scr
)
244 win
= WMCreateWindow(scr
, "testButton");
245 WMResizeWidget(win
, 300, 300);
246 WMSetWindowTitle(win
, "Buttons");
248 WMSetWindowCloseAction(win
, closeAction
, NULL
);
250 for (i
= 1; i
< 9; i
++) {
252 b
= WMCreateButton(win
, i
);
253 WMResizeWidget(b
, 150, 24);
254 WMMoveWidget(b
, 20, i
*30);
255 WMSetButtonText(b
, types
[i
-1]);
258 WMRealizeWidget(win
);
259 WMMapSubwidgets(win
);
265 testGradientButtons(WMScreen
*scr
)
269 WMPixmap
*pix1
, *pix2
;
272 WMColor
*color
, *altColor
;
276 /* creates the top-level window */
277 win
= WMCreateWindow(scr
, "testGradientButtons");
278 WMSetWindowTitle(win
, "Gradiented Button Demo");
279 WMResizeWidget(win
, 300, 200);
288 color
= WMCreateRGBColor(scr
, 0x5900, 0x5100, 0x5900, True
);
289 WMSetWidgetBackgroundColor(win
, color
);
290 WMReleaseColor(color
);
292 back
= RRenderGradient(60, 24, &dark
, &light
, RGRD_DIAGONAL
);
293 RBevelImage(back
, RBEV_RAISED2
);
294 pix1
= WMCreatePixmapFromRImage(scr
, back
, 0);
297 back
= RRenderGradient(60, 24, &dark
, &light
, RGRD_DIAGONAL
);
298 RBevelImage(back
, RBEV_SUNKEN
);
299 pix2
= WMCreatePixmapFromRImage(scr
, back
, 0);
302 color
= WMWhiteColor(scr
);
303 altColor
= WMCreateNamedColor(scr
, "red", True
);
305 btn
= WMCreateButton(win
, WBTMomentaryChange
);
306 WMResizeWidget(btn
, 60, 24);
307 WMMoveWidget(btn
, 20, 100);
308 WMSetButtonBordered(btn
, False
);
309 WMSetButtonImagePosition(btn
, WIPOverlaps
);
310 WMSetButtonImage(btn
, pix1
);
311 WMSetButtonAltImage(btn
, pix2
);
312 WMSetButtonText(btn
, "Cool");
313 WMSetButtonTextColor(btn
, color
);
314 WMSetButtonAltTextColor(btn
, altColor
);
316 WMSetBalloonTextForView("This is a cool button", WMWidgetView(btn
));
318 btn
= WMCreateButton(win
, WBTMomentaryChange
);
319 WMResizeWidget(btn
, 60, 24);
320 WMMoveWidget(btn
, 90, 100);
321 WMSetButtonBordered(btn
, False
);
322 WMSetButtonImagePosition(btn
, WIPOverlaps
);
323 WMSetButtonImage(btn
, pix1
);
324 WMSetButtonAltImage(btn
, pix2
);
325 WMSetButtonText(btn
, "Button");
326 WMSetButtonTextColor(btn
, color
);
328 WMSetBalloonTextForView("Este é outro balão.", WMWidgetView(btn
));
330 WMReleaseColor(color
);
331 color
= WMCreateNamedColor(scr
, "orange", True
);
333 btn
= WMCreateButton(win
, WBTMomentaryChange
);
334 WMResizeWidget(btn
, 60, 24);
335 WMMoveWidget(btn
, 160, 100);
336 WMSetButtonBordered(btn
, False
);
337 WMSetButtonImagePosition(btn
, WIPOverlaps
);
338 WMSetButtonImage(btn
, pix1
);
339 WMSetButtonAltImage(btn
, pix2
);
340 WMSetButtonText(btn
, "Test");
341 WMSetButtonTextColor(btn
, color
);
343 WMSetBalloonTextForView("This is yet another button.\nBut the balloon has 3 lines.\nYay!",
346 WMReleaseColor(color
);
347 WMReleaseColor(altColor
);
349 WMRealizeWidget(win
);
350 WMMapSubwidgets(win
);
356 testScrollView(WMScreen
*scr
)
367 /* creates the top-level window */
368 win
= WMCreateWindow(scr
, "testScroll");
369 WMSetWindowTitle(win
, "Scrollable View");
371 WMSetWindowCloseAction(win
, closeAction
, NULL
);
373 /* set the window size */
374 WMResizeWidget(win
, 300, 300);
376 /* creates a scrollable view inside the top-level window */
377 sview
= WMCreateScrollView(win
);
378 WMResizeWidget(sview
, 200, 200);
379 WMMoveWidget(sview
, 30, 30);
380 WMSetScrollViewRelief(sview
, WRSunken
);
381 WMSetScrollViewHasVerticalScroller(sview
, True
);
382 WMSetScrollViewHasHorizontalScroller(sview
, True
);
384 /* create a frame with a bunch of labels */
385 f
= WMCreateFrame(win
);
386 WMResizeWidget(f
, 400, 400);
387 WMSetFrameRelief(f
, WRFlat
);
389 for (i
=0; i
<20; i
++) {
390 l
= WMCreateLabel(f
);
391 WMResizeWidget(l
, 50, 18);
392 WMMoveWidget(l
, 10, 20*i
);
393 sprintf(buffer
, "Label %i", i
);
394 WMSetLabelText(l
, buffer
);
395 WMSetLabelRelief(l
, WRSimple
);
400 WMSetScrollViewContentView(sview
, WMWidgetView(f
));
402 /* make the windows of the widgets be actually created */
403 WMRealizeWidget(win
);
405 /* Map all child widgets of the top-level be mapped.
406 * You must call this for each container widget (like frames),
407 * even if they are childs of the top-level window.
409 WMMapSubwidgets(win
);
411 /* map the top-level window */
417 testColorWell(WMScreen
*scr
)
420 WMColorWell
*well1
, *well2
;
424 win
= WMCreateWindow(scr
, "testColor");
425 WMResizeWidget(win
, 300, 300);
426 WMSetWindowCloseAction(win
, closeAction
, NULL
);
428 well1
= WMCreateColorWell(win
);
429 WMResizeWidget(well1
, 60, 40);
430 WMMoveWidget(well1
, 100, 100);
431 WMSetColorWellColor(well1
, WMCreateRGBColor(scr
, 0x8888, 0, 0x1111, True
));
432 well2
= WMCreateColorWell(win
);
433 WMResizeWidget(well2
, 60, 40);
434 WMMoveWidget(well2
, 200, 100);
435 WMSetColorWellColor(well2
, WMCreateRGBColor(scr
, 0, 0, 0x8888, True
));
437 WMRealizeWidget(win
);
438 WMMapSubwidgets(win
);
443 sliderCallback(WMWidget
*w
, void *data
)
445 printf("SLIDER == %i\n", WMGetSliderValue(w
));
450 testSlider(WMScreen
*scr
)
457 win
= WMCreateWindow(scr
, "testSlider");
458 WMResizeWidget(win
, 300, 300);
459 WMSetWindowTitle(win
, "Sliders");
461 WMSetWindowCloseAction(win
, closeAction
, NULL
);
463 s
= WMCreateSlider(win
);
464 WMResizeWidget(s
, 16, 100);
465 WMMoveWidget(s
, 100, 100);
466 WMSetSliderKnobThickness(s
, 8);
467 WMSetSliderContinuous(s
, False
);
468 WMSetSliderAction(s
, sliderCallback
, s
);
470 s
= WMCreateSlider(win
);
471 WMResizeWidget(s
, 100, 16);
472 WMMoveWidget(s
, 100, 10);
473 WMSetSliderKnobThickness(s
, 8);
475 WMRealizeWidget(win
);
476 WMMapSubwidgets(win
);
481 testTextField(WMScreen
*scr
)
484 WMTextField
*field
, *field2
;
488 win
= WMCreateWindow(scr
, "testTextField");
489 WMResizeWidget(win
, 400, 300);
491 WMSetWindowCloseAction(win
, closeAction
, NULL
);
493 field
= WMCreateTextField(win
);
494 WMResizeWidget(field
, 200, 20);
495 WMMoveWidget(field
, 20, 20);
497 field2
= WMCreateTextField(win
);
498 WMResizeWidget(field2
, 200, 20);
499 WMMoveWidget(field2
, 20, 50);
500 WMSetTextFieldAlignment(field2
, WARight
);
502 WMRealizeWidget(win
);
503 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
);
537 WMRefreshText(text
, 0, 0);
539 WMAppendTextStream(text
, "<HTML><i>Where's</i> the <b>README</b>?");
542 WMRealizeWidget(win
);
543 WMMapSubwidgets(win
);
550 testProgressIndicator(WMScreen
*scr
)
553 WMProgressIndicator
*pPtr
;
557 win
= WMCreateWindow(scr
, "testProgressIndicator");
558 WMResizeWidget(win
, 292, 32);
560 WMSetWindowCloseAction(win
, closeAction
, NULL
);
562 pPtr
= WMCreateProgressIndicator(win
);
563 WMMoveWidget(pPtr
, 8, 8);
564 WMSetProgressIndicatorValue(pPtr
, 75);
566 WMRealizeWidget(win
);
567 WMMapSubwidgets(win
);
574 testPullDown(WMScreen
*scr
)
577 WMPopUpButton
*pop
, *pop2
;
581 win
= WMCreateWindow(scr
, "pullDown");
582 WMResizeWidget(win
, 400, 300);
584 WMSetWindowCloseAction(win
, closeAction
, NULL
);
586 pop
= WMCreatePopUpButton(win
);
587 WMResizeWidget(pop
, 100, 20);
588 WMMoveWidget(pop
, 50, 60);
589 WMSetPopUpButtonPullsDown(pop
, True
);
590 WMSetPopUpButtonText(pop
, "Commands");
591 WMAddPopUpButtonItem(pop
, "Add");
592 WMAddPopUpButtonItem(pop
, "Remove");
593 WMAddPopUpButtonItem(pop
, "Check");
594 WMAddPopUpButtonItem(pop
, "Eat");
596 pop2
= WMCreatePopUpButton(win
);
597 WMResizeWidget(pop2
, 100, 20);
598 WMMoveWidget(pop2
, 200, 60);
599 WMSetPopUpButtonText(pop2
, "Select");
600 WMAddPopUpButtonItem(pop2
, "Apples");
601 WMAddPopUpButtonItem(pop2
, "Bananas");
602 WMAddPopUpButtonItem(pop2
, "Strawberries");
603 WMAddPopUpButtonItem(pop2
, "Blueberries");
605 WMRealizeWidget(win
);
606 WMMapSubwidgets(win
);
613 testTabView(WMScreen
*scr
)
623 win
= WMCreateWindow(scr
, "testTabs");
624 WMResizeWidget(win
, 400, 300);
626 WMSetWindowCloseAction(win
, closeAction
, NULL
);
628 tabv
= WMCreateTabView(win
);
629 WMMoveWidget(tabv
, 50, 50);
630 WMResizeWidget(tabv
, 300, 200);
632 frame
= WMCreateFrame(win
);
633 WMSetFrameRelief(frame
, WRFlat
);
634 label
= WMCreateLabel(frame
);
635 WMResizeWidget(label
, 100, 100);
636 WMSetLabelText(label
, "Label 1");
640 tab
= WMCreateTabViewItemWithIdentifier(0);
641 WMSetTabViewItemView(tab
, WMWidgetView(frame
));
642 WMAddItemInTabView(tabv
, tab
);
643 WMSetTabViewItemLabel(tab
, "Instances");
645 frame
= WMCreateFrame(win
);
646 WMSetFrameRelief(frame
, WRFlat
);
647 label
= WMCreateLabel(frame
);
648 WMResizeWidget(label
, 40, 50);
649 WMSetLabelText(label
, "Label 2");
653 tab
= WMCreateTabViewItemWithIdentifier(0);
654 WMSetTabViewItemView(tab
, WMWidgetView(frame
));
655 WMAddItemInTabView(tabv
, tab
);
656 WMSetTabViewItemLabel(tab
, "Classes");
659 frame
= WMCreateFrame(win
);
660 WMSetFrameRelief(frame
, WRFlat
);
661 label
= WMCreateLabel(frame
);
662 WMResizeWidget(label
, 100, 100);
663 WMMoveWidget(label
, 60, 40);
664 WMSetLabelText(label
, "Label 3");
667 tab
= WMCreateTabViewItemWithIdentifier(0);
668 WMSetTabViewItemView(tab
, WMWidgetView(frame
));
669 WMAddItemInTabView(tabv
, tab
);
670 WMSetTabViewItemLabel(tab
, "Something");
673 frame
= WMCreateFrame(win
);
674 WMSetFrameRelief(frame
, WRFlat
);
675 label
= WMCreateLabel(frame
);
676 WMResizeWidget(label
, 100, 100);
677 WMMoveWidget(label
, 160, 40);
678 WMSetLabelText(label
, "Label 4");
681 tab
= WMCreateTabViewItemWithIdentifier(0);
682 WMSetTabViewItemView(tab
, WMWidgetView(frame
));
683 WMAddItemInTabView(tabv
, tab
);
684 WMSetTabViewItemLabel(tab
, "Bla!");
688 frame
= WMCreateFrame(win
);
689 WMSetFrameRelief(frame
, WRFlat
);
690 label
= WMCreateLabel(frame
);
691 WMResizeWidget(label
, 100, 100);
692 WMMoveWidget(label
, 160, 40);
693 WMSetLabelText(label
, "Label fjweqklrj qwl");
695 tab
= WMCreateTabViewItemWithIdentifier(0);
696 WMSetTabViewItemView(tab
, WMWidgetView(frame
));
697 WMAddItemInTabView(tabv
, tab
);
698 WMSetTabViewItemLabel(tab
, "Weee!");
701 WMRealizeWidget(win
);
702 WMMapSubwidgets(win
);
708 splitViewConstrainProc(WMSplitView
*sPtr
, int indView
,
709 int *minSize
, int *maxSize
)
729 resizeSplitView(XEvent
*event
, void *data
)
731 WMSplitView
*sPtr
= (WMSplitView
*)data
;
733 if (event
->type
== ConfigureNotify
) {
734 int width
= event
->xconfigure
.width
- 10;
736 if (width
< WMGetSplitViewDividerThickness(sPtr
))
737 width
= WMGetSplitViewDividerThickness(sPtr
);
739 if (width
!= WMWidgetWidth(sPtr
) ||
740 event
->xconfigure
.height
!= WMWidgetHeight(sPtr
))
741 WMResizeWidget(sPtr
, width
, event
->xconfigure
.height
- 55);
746 appendSubviewButtonAction(WMWidget
*self
, void *data
)
748 WMSplitView
*sPtr
= (WMSplitView
*)data
;
750 WMLabel
*label
= WMCreateLabel(sPtr
);
752 sprintf(buf
, "Subview %d", WMGetSplitViewSubviewsCount(sPtr
) + 1);
753 WMSetLabelText(label
, buf
);
754 WMSetLabelRelief(label
, WRSunken
);
755 WMAddSplitViewSubview(sPtr
, WMWidgetView(label
));
756 WMRealizeWidget(label
);
761 removeSubviewButtonAction(WMWidget
*self
, void *data
)
763 WMSplitView
*sPtr
= (WMSplitView
*)data
;
764 int count
= WMGetSplitViewSubviewsCount(sPtr
);
767 WMView
*view
= WMGetSplitViewSubviewAt(sPtr
, count
-1);
768 WMDestroyWidget(WMWidgetOfView(view
));
769 WMRemoveSplitViewSubviewAt(sPtr
, count
-1);
774 orientationButtonAction(WMWidget
*self
, void *data
)
776 WMSplitView
*sPtr
= (WMSplitView
*)data
;
777 WMSetSplitViewVertical(sPtr
, !WMGetSplitViewVertical(sPtr
));
781 adjustSubviewsButtonAction(WMWidget
*self
, void *data
)
783 WMAdjustSplitViewSubviews((WMSplitView
*)data
);
787 testSplitView(WMScreen
*scr
)
790 WMSplitView
*splitv1
, *splitv2
;
797 win
= WMCreateWindow(scr
, "testTabs");
798 WMResizeWidget(win
, 300, 400);
799 WMSetWindowCloseAction(win
, closeAction
, NULL
);
801 frame
= WMCreateFrame(win
);
802 WMSetFrameRelief(frame
, WRSunken
);
803 WMMoveWidget(frame
, 5, 5);
804 WMResizeWidget(frame
, 290, 40);
806 splitv1
= WMCreateSplitView(win
);
807 WMMoveWidget(splitv1
, 5, 50);
808 WMResizeWidget(splitv1
, 290, 345);
809 WMSetSplitViewConstrainProc(splitv1
, splitViewConstrainProc
);
810 WMCreateEventHandler(WMWidgetView(win
), StructureNotifyMask
,
811 resizeSplitView
, splitv1
);
813 button
= WMCreateCommandButton(frame
);
814 WMSetButtonText(button
, "+");
815 WMSetButtonAction(button
, appendSubviewButtonAction
, splitv1
);
816 WMMoveWidget(button
, 10, 8);
819 button
= WMCreateCommandButton(frame
);
820 WMSetButtonText(button
, "-");
821 WMSetButtonAction(button
, removeSubviewButtonAction
, splitv1
);
822 WMMoveWidget(button
, 80, 8);
825 button
= WMCreateCommandButton(frame
);
826 WMSetButtonText(button
, "=");
827 WMMoveWidget(button
, 150, 8);
828 WMSetButtonAction(button
, adjustSubviewsButtonAction
, splitv1
);
831 button
= WMCreateCommandButton(frame
);
832 WMSetButtonText(button
, "#");
833 WMMoveWidget(button
, 220, 8);
834 WMSetButtonAction(button
, orientationButtonAction
, splitv1
);
837 label
= WMCreateLabel(splitv1
);
838 WMSetLabelText(label
, "Subview 1");
839 WMSetLabelRelief(label
, WRSunken
);
841 WMAddSplitViewSubview(splitv1
, WMWidgetView(label
));
843 splitv2
= WMCreateSplitView(splitv1
);
844 WMResizeWidget(splitv2
, 150, 150);
845 WMSetSplitViewVertical(splitv2
, True
);
847 label
= WMCreateLabel(splitv2
);
848 WMSetLabelText(label
, "Subview 2.1");
849 WMSetLabelRelief(label
, WRSunken
);
851 WMAddSplitViewSubview(splitv2
, WMWidgetView(label
));
853 label
= WMCreateLabel(splitv2
);
854 WMSetLabelText(label
, "Subview 2.2");
855 WMSetLabelRelief(label
, WRSunken
);
857 WMAddSplitViewSubview(splitv2
, WMWidgetView(label
));
859 label
= WMCreateLabel(splitv2
);
860 WMSetLabelText(label
, "Subview 2.3");
861 WMSetLabelRelief(label
, WRSunken
);
863 WMAddSplitViewSubview(splitv2
, WMWidgetView(label
));
865 WMMapWidget(splitv2
);
866 WMAddSplitViewSubview(splitv1
, WMWidgetView(splitv2
));
868 WMRealizeWidget(win
);
869 WMMapSubwidgets(win
);
874 /*******************************************************************/
876 #include <sys/types.h>
888 getImage(WMScreen
*scr
, char *file
)
893 sprintf(buffer
, "../../WindowMaker/Icons/%s", file
);
894 pix
= WMCreatePixmapFromFile(scr
, buffer
);
903 iconMouseStuff(XEvent
*event
, void *cdata
)
905 WMLabel
*label
= (WMLabel
*)cdata
;
906 DNDStuff
*stuff
= WMGetHangedData(label
);
909 switch (event
->type
) {
911 stuff
->x
= event
->xbutton
.x
;
912 stuff
->y
= event
->xbutton
.y
;
913 stuff
->mouseDown
= True
;
916 stuff
->mouseDown
= False
;
919 if (!stuff
->mouseDown
)
922 if (abs(stuff
->x
- event
->xmotion
.x
)>4
923 || abs(stuff
->y
- event
->xmotion
.y
)>4) {
925 where
= WMGetViewScreenPosition(WMWidgetView(label
));
927 WMDragImageFromView(WMWidgetView(label
),
928 WMGetLabelImage(label
),
931 wmksize(stuff
->x
, stuff
->y
),
940 endedDragImage(WMView
*self
, WMPixmap
*image
, WMPoint point
, Bool deposited
)
942 DNDStuff
*stuff
= WMGetHangedData(WMWidgetOfView(self
));
945 WMDestroyWidget(WMWidgetOfView(self
));
948 stuff
->mouseDown
= False
;
953 fetchDragData(WMView
*self
, char *type
)
955 DNDStuff
*stuff
= WMGetHangedData(WMWidgetOfView(self
));
957 return WMCreateDataWithBytes(stuff
->filename
, strlen(stuff
->filename
)+1);
961 WMDragSourceProcs dragSourceProcs
= {
969 /************************/
973 draggingEntered(WMView
*self
, WMDraggingInfo
*info
)
975 return WDOperationCopy
;
980 draggingUpdated(WMView
*self
, WMDraggingInfo
*info
)
982 return WDOperationCopy
;
986 void (*draggingExited)(WMView *self, WMDraggingInfo *info);
989 prepareForDragOperation(WMView
*self
, WMDraggingInfo
*info
)
991 return "application/X-WINGs-Bla";
995 WMLabel
* makeDraggableLabel(WMWidget
*w
, char *file
, int x
, int y
);
998 performDragOperation(WMView
*self
, WMDraggingInfo
*info
, WMData
*data
)
1000 char *file
= (char*)WMDataBytes(data
);
1003 pos
= WMGetDraggingInfoImageLocation(info
);
1007 WMPoint pos2
= WMGetViewScreenPosition(self
);
1010 label
= makeDraggableLabel(WMWidgetOfView(self
), file
,
1011 pos
.x
-pos2
.x
, pos
.y
-pos2
.y
);
1012 WMRealizeWidget(label
);
1022 concludeDragOperation(WMView
*self
, WMDraggingInfo
*info
)
1029 WMDragDestinationProcs dragDestProcs
= {
1033 prepareForDragOperation
,
1034 performDragOperation
,
1035 concludeDragOperation
1042 makeDraggableLabel(WMWidget
*w
, char *file
, int x
, int y
)
1046 WMPixmap
*image
= getImage(WMWidgetScreen(w
), file
);
1048 stuff
= wmalloc(sizeof(DNDStuff
));
1049 stuff
->mouseDown
= False
;
1051 stuff
->filename
= wstrdup(file
);
1053 label
= WMCreateLabel(w
);
1054 WMResizeWidget(label
, 48, 48);
1055 WMMoveWidget(label
, x
, y
);
1057 WMSetViewDragSourceProcs(WMWidgetView(label
), &dragSourceProcs
);
1059 WMHangData(label
, stuff
);
1061 WMCreateEventHandler(WMWidgetView(label
),
1062 ButtonPressMask
|ButtonReleaseMask
|ButtonMotionMask
,
1063 iconMouseStuff
, label
);
1066 if (image
!= NULL
) {
1067 WMSetLabelImagePosition(label
, WIPImageOnly
);
1068 WMSetLabelImage(label
, image
);
1069 WMReleasePixmap(image
);
1078 testDragAndDrop(WMScreen
*scr
)
1087 "application/X-WINGs-Bla",
1093 win
= WMCreateWindow(scr
, "dragDrop");
1094 WMResizeWidget(win
, 300, 300);
1095 WMSetWindowCloseAction(win
, closeAction
, NULL
);
1096 WMSetWindowTitle(win
, "Drag and Drop");
1099 frame
= WMCreateFrame(win
);
1100 WMSetFrameRelief(frame
, WRSunken
);
1101 WMResizeWidget(frame
, 250, 250);
1102 WMMoveWidget(frame
, 25, 25);
1104 WMRegisterViewForDraggedTypes(WMWidgetView(frame
), types
);
1105 WMSetViewDragDestinationProcs(WMWidgetView(frame
), &dragDestProcs
);
1107 dir
= opendir("../../WindowMaker/Icons");
1109 perror("../../WindowMaker/Icons");
1113 for (i
= 0, j
=0; j
< 8; i
++) {
1118 if (strstr(ent
->d_name
, ".xpm")==NULL
) {
1122 label
= makeDraggableLabel(frame
, ent
->d_name
,4+(j
/4)*64, 4+(j
%4)*64);
1129 WMMapSubwidgets(frame
);
1131 WMMapSubwidgets(win
);
1132 WMRealizeWidget(win
);
1140 /*******************************************************************/
1147 WMUserDefaults
*defs
;
1150 defs
= WMGetStandardUserDefaults();
1152 sprintf(str
, "TEST DATA");
1154 WMSetUDStringForKey(defs
, str
, "testKey");
1160 main(int argc
, char **argv
)
1166 /* Initialize the application */
1167 WMInitializeApplication("Test", &argc
, argv
);
1172 * Open connection to the X display.
1174 dpy
= XOpenDisplay("");
1177 puts("could not open display");
1181 /* This is used to disable buffering of X protocol requests.
1182 * Do NOT use it unless when debugging. It will cause a major
1183 * slowdown in your application
1186 XSynchronize(dpy
, True
);
1189 * Create screen descriptor.
1191 scr
= WMCreateScreen(dpy
, DefaultScreen(dpy
));
1194 * Loads the logo of the application.
1196 pixmap
= WMCreatePixmapFromFile(scr
, "logo.xpm");
1199 * Makes the logo be used in standard dialog panels.
1201 WMSetApplicationIconImage(scr
, pixmap
); WMReleasePixmap(pixmap
);
1204 * Do some test stuff.
1206 * Put the testSomething() function you want to test here.
1217 testDragAndDrop(scr
);
1218 testDragAndDrop(scr
);
1221 testScrollView(scr
);
1234 testGradientButtons(scr
);
1235 testProgressIndicator(scr
);
1238 testOpenFilePanel(scr
);
1244 * The main event loop.
1247 WMScreenMainLoop(scr
);