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 WMMoveWidget(list
, 10, 40);
187 for (i
=0; i
<50; i
++) {
188 sprintf(text
, "Item %i", i
);
189 WMAddListItem(list
, text
);
191 mlist
= WMCreateList(win
);
192 WMSetListAllowMultipleSelection(mlist
, True
);
193 WMMoveWidget(mlist
, 210, 40);
194 for (i
=0; i
<135; i
++) {
195 sprintf(text
, "Item %i", i
);
196 WMAddListItem(mlist
, text
);
199 label
= WMCreateLabel(win
);
200 WMResizeWidget(label
, 150, 40);
201 WMMoveWidget(label
, 10, 200);
202 WMSetLabelRelief(label
, WRRidge
);
203 WMSetLabelText(label
, "Selected items: 0");
205 mlabel
= WMCreateLabel(win
);
206 WMResizeWidget(mlabel
, 150, 40);
207 WMMoveWidget(mlabel
, 210, 200);
208 WMSetLabelRelief(mlabel
, WRRidge
);
209 WMSetLabelText(mlabel
, "Selected items: 0");
211 WMSetListAction(list
, singleClick
, label
);
212 WMSetListDoubleAction(list
, doubleClick
, label
);
213 WMSetListAction(mlist
, singleClick
, mlabel
);
214 WMSetListDoubleAction(mlist
, doubleClick
, mlabel
);
216 WMAddNotificationObserver(listSelectionObserver
, label
,
217 WMListSelectionDidChangeNotification
, list
);
218 WMAddNotificationObserver(listSelectionObserver
, mlabel
,
219 WMListSelectionDidChangeNotification
, mlist
);
222 WMRealizeWidget(win
);
223 WMMapSubwidgets(win
);
229 testButton(WMScreen
*scr
)
246 win
= WMCreateWindow(scr
, "testButton");
247 WMResizeWidget(win
, 300, 300);
248 WMSetWindowTitle(win
, "Buttons");
250 WMSetWindowCloseAction(win
, closeAction
, NULL
);
252 for (i
= 1; i
< 9; i
++) {
254 b
= WMCreateButton(win
, i
);
255 WMResizeWidget(b
, 150, 24);
256 WMMoveWidget(b
, 20, i
*30);
257 WMSetButtonText(b
, types
[i
-1]);
260 WMRealizeWidget(win
);
261 WMMapSubwidgets(win
);
267 testGradientButtons(WMScreen
*scr
)
271 WMPixmap
*pix1
, *pix2
;
274 WMColor
*color
, *altColor
;
278 /* creates the top-level window */
279 win
= WMCreateWindow(scr
, "testGradientButtons");
280 WMSetWindowTitle(win
, "Gradiented Button Demo");
281 WMResizeWidget(win
, 300, 200);
290 color
= WMCreateRGBColor(scr
, 0x5900, 0x5100, 0x5900, True
);
291 WMSetWidgetBackgroundColor(win
, color
);
292 WMReleaseColor(color
);
294 back
= RRenderGradient(60, 24, &dark
, &light
, RGRD_DIAGONAL
);
295 RBevelImage(back
, RBEV_RAISED2
);
296 pix1
= WMCreatePixmapFromRImage(scr
, back
, 0);
299 back
= RRenderGradient(60, 24, &dark
, &light
, RGRD_DIAGONAL
);
300 RBevelImage(back
, RBEV_SUNKEN
);
301 pix2
= WMCreatePixmapFromRImage(scr
, back
, 0);
304 color
= WMWhiteColor(scr
);
305 altColor
= WMCreateNamedColor(scr
, "red", True
);
307 btn
= WMCreateButton(win
, WBTMomentaryChange
);
308 WMResizeWidget(btn
, 60, 24);
309 WMMoveWidget(btn
, 20, 100);
310 WMSetButtonBordered(btn
, False
);
311 WMSetButtonImagePosition(btn
, WIPOverlaps
);
312 WMSetButtonImage(btn
, pix1
);
313 WMSetButtonAltImage(btn
, pix2
);
314 WMSetButtonText(btn
, "Cool");
315 WMSetButtonTextColor(btn
, color
);
316 WMSetButtonAltTextColor(btn
, altColor
);
318 WMSetBalloonTextForView("This is a cool button", WMWidgetView(btn
));
320 btn
= WMCreateButton(win
, WBTMomentaryChange
);
321 WMResizeWidget(btn
, 60, 24);
322 WMMoveWidget(btn
, 90, 100);
323 WMSetButtonBordered(btn
, False
);
324 WMSetButtonImagePosition(btn
, WIPOverlaps
);
325 WMSetButtonImage(btn
, pix1
);
326 WMSetButtonAltImage(btn
, pix2
);
327 WMSetButtonText(btn
, "Button");
328 WMSetButtonTextColor(btn
, color
);
330 WMSetBalloonTextForView("Este é outro balão.", WMWidgetView(btn
));
332 WMReleaseColor(color
);
333 color
= WMCreateNamedColor(scr
, "orange", True
);
335 btn
= WMCreateButton(win
, WBTMomentaryChange
);
336 WMResizeWidget(btn
, 60, 24);
337 WMMoveWidget(btn
, 160, 100);
338 WMSetButtonBordered(btn
, False
);
339 WMSetButtonImagePosition(btn
, WIPOverlaps
);
340 WMSetButtonImage(btn
, pix1
);
341 WMSetButtonAltImage(btn
, pix2
);
342 WMSetButtonText(btn
, "Test");
343 WMSetButtonTextColor(btn
, color
);
345 WMSetBalloonTextForView("This is yet another button.\nBut the balloon has 3 lines.\nYay!",
348 WMReleaseColor(color
);
349 WMReleaseColor(altColor
);
351 WMRealizeWidget(win
);
352 WMMapSubwidgets(win
);
358 testScrollView(WMScreen
*scr
)
369 /* creates the top-level window */
370 win
= WMCreateWindow(scr
, "testScroll");
371 WMSetWindowTitle(win
, "Scrollable View");
373 WMSetWindowCloseAction(win
, closeAction
, NULL
);
375 /* set the window size */
376 WMResizeWidget(win
, 300, 300);
378 /* creates a scrollable view inside the top-level window */
379 sview
= WMCreateScrollView(win
);
380 WMResizeWidget(sview
, 200, 200);
381 WMMoveWidget(sview
, 30, 30);
382 WMSetScrollViewRelief(sview
, WRSunken
);
383 WMSetScrollViewHasVerticalScroller(sview
, True
);
384 WMSetScrollViewHasHorizontalScroller(sview
, True
);
386 /* create a frame with a bunch of labels */
387 f
= WMCreateFrame(win
);
388 WMResizeWidget(f
, 400, 400);
389 WMSetFrameRelief(f
, WRFlat
);
391 for (i
=0; i
<20; i
++) {
392 l
= WMCreateLabel(f
);
393 WMResizeWidget(l
, 50, 18);
394 WMMoveWidget(l
, 10, 20*i
);
395 sprintf(buffer
, "Label %i", i
);
396 WMSetLabelText(l
, buffer
);
397 WMSetLabelRelief(l
, WRSimple
);
402 WMSetScrollViewContentView(sview
, WMWidgetView(f
));
404 /* make the windows of the widgets be actually created */
405 WMRealizeWidget(win
);
407 /* Map all child widgets of the top-level be mapped.
408 * You must call this for each container widget (like frames),
409 * even if they are childs of the top-level window.
411 WMMapSubwidgets(win
);
413 /* map the top-level window */
419 testColorWell(WMScreen
*scr
)
422 WMColorWell
*well1
, *well2
;
426 win
= WMCreateWindow(scr
, "testColor");
427 WMResizeWidget(win
, 300, 300);
428 WMSetWindowCloseAction(win
, closeAction
, NULL
);
430 well1
= WMCreateColorWell(win
);
431 WMResizeWidget(well1
, 60, 40);
432 WMMoveWidget(well1
, 100, 100);
433 WMSetColorWellColor(well1
, WMCreateRGBColor(scr
, 0x8888, 0, 0x1111, True
));
434 well2
= WMCreateColorWell(win
);
435 WMResizeWidget(well2
, 60, 40);
436 WMMoveWidget(well2
, 200, 100);
437 WMSetColorWellColor(well2
, WMCreateRGBColor(scr
, 0, 0, 0x8888, True
));
439 WMRealizeWidget(win
);
440 WMMapSubwidgets(win
);
445 sliderCallback(WMWidget
*w
, void *data
)
447 printf("SLIDER == %i\n", WMGetSliderValue(w
));
452 testSlider(WMScreen
*scr
)
459 win
= WMCreateWindow(scr
, "testSlider");
460 WMResizeWidget(win
, 300, 300);
461 WMSetWindowTitle(win
, "Sliders");
463 WMSetWindowCloseAction(win
, closeAction
, NULL
);
465 s
= WMCreateSlider(win
);
466 WMResizeWidget(s
, 16, 100);
467 WMMoveWidget(s
, 100, 100);
468 WMSetSliderKnobThickness(s
, 8);
469 WMSetSliderContinuous(s
, False
);
470 WMSetSliderAction(s
, sliderCallback
, s
);
472 s
= WMCreateSlider(win
);
473 WMResizeWidget(s
, 100, 16);
474 WMMoveWidget(s
, 100, 10);
475 WMSetSliderKnobThickness(s
, 8);
477 WMRealizeWidget(win
);
478 WMMapSubwidgets(win
);
483 testTextField(WMScreen
*scr
)
486 WMTextField
*field
, *field2
;
490 win
= WMCreateWindow(scr
, "testTextField");
491 WMResizeWidget(win
, 400, 300);
493 WMSetWindowCloseAction(win
, closeAction
, NULL
);
495 field
= WMCreateTextField(win
);
496 WMResizeWidget(field
, 200, 20);
497 WMMoveWidget(field
, 20, 20);
499 field2
= WMCreateTextField(win
);
500 WMResizeWidget(field2
, 200, 20);
501 WMMoveWidget(field2
, 20, 50);
502 WMSetTextFieldAlignment(field2
, WARight
);
504 WMRealizeWidget(win
);
505 WMMapSubwidgets(win
);
511 testText(WMScreen
*scr
)
515 FILE *file
= fopen("../README", "r");
519 win
= WMCreateWindow(scr
, "testText");
520 WMResizeWidget(win
, 500, 300);
522 WMSetWindowCloseAction(win
, closeAction
, NULL
);
524 text
= WMCreateText(win
);
525 WMResizeWidget(text
, 480, 280);
526 WMMoveWidget(text
, 10, 10);
527 WMSetTextHasVerticalScroller(text
, True
);
528 WMSetTextEditable(text
, False
);
534 while(fgets(buf
, 1023, file
))
535 WMAppendTextStream(text
, buf
);
539 WMRefreshText(text
, 0, 0);
541 WMAppendTextStream(text
, "<HTML><i>Where's</i> the <b>README</b>?");
544 WMRealizeWidget(win
);
545 WMMapSubwidgets(win
);
552 testProgressIndicator(WMScreen
*scr
)
555 WMProgressIndicator
*pPtr
;
559 win
= WMCreateWindow(scr
, "testProgressIndicator");
560 WMResizeWidget(win
, 292, 32);
562 WMSetWindowCloseAction(win
, closeAction
, NULL
);
564 pPtr
= WMCreateProgressIndicator(win
);
565 WMMoveWidget(pPtr
, 8, 8);
566 WMSetProgressIndicatorValue(pPtr
, 75);
568 WMRealizeWidget(win
);
569 WMMapSubwidgets(win
);
576 testPullDown(WMScreen
*scr
)
579 WMPopUpButton
*pop
, *pop2
;
583 win
= WMCreateWindow(scr
, "pullDown");
584 WMResizeWidget(win
, 400, 300);
586 WMSetWindowCloseAction(win
, closeAction
, NULL
);
588 pop
= WMCreatePopUpButton(win
);
589 WMResizeWidget(pop
, 100, 20);
590 WMMoveWidget(pop
, 50, 60);
591 WMSetPopUpButtonPullsDown(pop
, True
);
592 WMSetPopUpButtonText(pop
, "Commands");
593 WMAddPopUpButtonItem(pop
, "Add");
594 WMAddPopUpButtonItem(pop
, "Remove");
595 WMAddPopUpButtonItem(pop
, "Check");
596 WMAddPopUpButtonItem(pop
, "Eat");
598 pop2
= WMCreatePopUpButton(win
);
599 WMResizeWidget(pop2
, 100, 20);
600 WMMoveWidget(pop2
, 200, 60);
601 WMSetPopUpButtonText(pop2
, "Select");
602 WMAddPopUpButtonItem(pop2
, "Apples");
603 WMAddPopUpButtonItem(pop2
, "Bananas");
604 WMAddPopUpButtonItem(pop2
, "Strawberries");
605 WMAddPopUpButtonItem(pop2
, "Blueberries");
607 WMRealizeWidget(win
);
608 WMMapSubwidgets(win
);
615 testTabView(WMScreen
*scr
)
625 win
= WMCreateWindow(scr
, "testTabs");
626 WMResizeWidget(win
, 400, 300);
628 WMSetWindowCloseAction(win
, closeAction
, NULL
);
630 tabv
= WMCreateTabView(win
);
631 WMMoveWidget(tabv
, 50, 50);
632 WMResizeWidget(tabv
, 300, 200);
634 frame
= WMCreateFrame(win
);
635 WMSetFrameRelief(frame
, WRFlat
);
636 label
= WMCreateLabel(frame
);
637 WMResizeWidget(label
, 100, 100);
638 WMSetLabelText(label
, "Label 1");
642 tab
= WMCreateTabViewItemWithIdentifier(0);
643 WMSetTabViewItemView(tab
, WMWidgetView(frame
));
644 WMAddItemInTabView(tabv
, tab
);
645 WMSetTabViewItemLabel(tab
, "Instances");
647 frame
= WMCreateFrame(win
);
648 WMSetFrameRelief(frame
, WRFlat
);
649 label
= WMCreateLabel(frame
);
650 WMResizeWidget(label
, 40, 50);
651 WMSetLabelText(label
, "Label 2");
655 tab
= WMCreateTabViewItemWithIdentifier(0);
656 WMSetTabViewItemView(tab
, WMWidgetView(frame
));
657 WMAddItemInTabView(tabv
, tab
);
658 WMSetTabViewItemLabel(tab
, "Classes");
661 frame
= WMCreateFrame(win
);
662 WMSetFrameRelief(frame
, WRFlat
);
663 label
= WMCreateLabel(frame
);
664 WMResizeWidget(label
, 100, 100);
665 WMMoveWidget(label
, 60, 40);
666 WMSetLabelText(label
, "Label 3");
669 tab
= WMCreateTabViewItemWithIdentifier(0);
670 WMSetTabViewItemView(tab
, WMWidgetView(frame
));
671 WMAddItemInTabView(tabv
, tab
);
672 WMSetTabViewItemLabel(tab
, "Something");
675 frame
= WMCreateFrame(win
);
676 WMSetFrameRelief(frame
, WRFlat
);
677 label
= WMCreateLabel(frame
);
678 WMResizeWidget(label
, 100, 100);
679 WMMoveWidget(label
, 160, 40);
680 WMSetLabelText(label
, "Label 4");
683 tab
= WMCreateTabViewItemWithIdentifier(0);
684 WMSetTabViewItemView(tab
, WMWidgetView(frame
));
685 WMAddItemInTabView(tabv
, tab
);
686 WMSetTabViewItemLabel(tab
, "Bla!");
690 frame
= WMCreateFrame(win
);
691 WMSetFrameRelief(frame
, WRFlat
);
692 label
= WMCreateLabel(frame
);
693 WMResizeWidget(label
, 100, 100);
694 WMMoveWidget(label
, 160, 40);
695 WMSetLabelText(label
, "Label fjweqklrj qwl");
697 tab
= WMCreateTabViewItemWithIdentifier(0);
698 WMSetTabViewItemView(tab
, WMWidgetView(frame
));
699 WMAddItemInTabView(tabv
, tab
);
700 WMSetTabViewItemLabel(tab
, "Weee!");
703 WMRealizeWidget(win
);
704 WMMapSubwidgets(win
);
710 splitViewConstrainProc(WMSplitView
*sPtr
, int indView
,
711 int *minSize
, int *maxSize
)
731 resizeSplitView(XEvent
*event
, void *data
)
733 WMSplitView
*sPtr
= (WMSplitView
*)data
;
735 if (event
->type
== ConfigureNotify
) {
736 int width
= event
->xconfigure
.width
- 10;
738 if (width
< WMGetSplitViewDividerThickness(sPtr
))
739 width
= WMGetSplitViewDividerThickness(sPtr
);
741 if (width
!= WMWidgetWidth(sPtr
) ||
742 event
->xconfigure
.height
!= WMWidgetHeight(sPtr
))
743 WMResizeWidget(sPtr
, width
, event
->xconfigure
.height
- 55);
748 appendSubviewButtonAction(WMWidget
*self
, void *data
)
750 WMSplitView
*sPtr
= (WMSplitView
*)data
;
752 WMLabel
*label
= WMCreateLabel(sPtr
);
754 sprintf(buf
, "Subview %d", WMGetSplitViewSubviewsCount(sPtr
) + 1);
755 WMSetLabelText(label
, buf
);
756 WMSetLabelRelief(label
, WRSunken
);
757 WMAddSplitViewSubview(sPtr
, WMWidgetView(label
));
758 WMRealizeWidget(label
);
763 removeSubviewButtonAction(WMWidget
*self
, void *data
)
765 WMSplitView
*sPtr
= (WMSplitView
*)data
;
766 int count
= WMGetSplitViewSubviewsCount(sPtr
);
769 WMView
*view
= WMGetSplitViewSubviewAt(sPtr
, count
-1);
770 WMDestroyWidget(WMWidgetOfView(view
));
771 WMRemoveSplitViewSubviewAt(sPtr
, count
-1);
776 orientationButtonAction(WMWidget
*self
, void *data
)
778 WMSplitView
*sPtr
= (WMSplitView
*)data
;
779 WMSetSplitViewVertical(sPtr
, !WMGetSplitViewVertical(sPtr
));
783 adjustSubviewsButtonAction(WMWidget
*self
, void *data
)
785 WMAdjustSplitViewSubviews((WMSplitView
*)data
);
789 testSplitView(WMScreen
*scr
)
792 WMSplitView
*splitv1
, *splitv2
;
799 win
= WMCreateWindow(scr
, "testTabs");
800 WMResizeWidget(win
, 300, 400);
801 WMSetWindowCloseAction(win
, closeAction
, NULL
);
803 frame
= WMCreateFrame(win
);
804 WMSetFrameRelief(frame
, WRSunken
);
805 WMMoveWidget(frame
, 5, 5);
806 WMResizeWidget(frame
, 290, 40);
808 splitv1
= WMCreateSplitView(win
);
809 WMMoveWidget(splitv1
, 5, 50);
810 WMResizeWidget(splitv1
, 290, 345);
811 WMSetSplitViewConstrainProc(splitv1
, splitViewConstrainProc
);
812 WMCreateEventHandler(WMWidgetView(win
), StructureNotifyMask
,
813 resizeSplitView
, splitv1
);
815 button
= WMCreateCommandButton(frame
);
816 WMSetButtonText(button
, "+");
817 WMSetButtonAction(button
, appendSubviewButtonAction
, splitv1
);
818 WMMoveWidget(button
, 10, 8);
821 button
= WMCreateCommandButton(frame
);
822 WMSetButtonText(button
, "-");
823 WMSetButtonAction(button
, removeSubviewButtonAction
, splitv1
);
824 WMMoveWidget(button
, 80, 8);
827 button
= WMCreateCommandButton(frame
);
828 WMSetButtonText(button
, "=");
829 WMMoveWidget(button
, 150, 8);
830 WMSetButtonAction(button
, adjustSubviewsButtonAction
, splitv1
);
833 button
= WMCreateCommandButton(frame
);
834 WMSetButtonText(button
, "#");
835 WMMoveWidget(button
, 220, 8);
836 WMSetButtonAction(button
, orientationButtonAction
, splitv1
);
839 label
= WMCreateLabel(splitv1
);
840 WMSetLabelText(label
, "Subview 1");
841 WMSetLabelRelief(label
, WRSunken
);
843 WMAddSplitViewSubview(splitv1
, WMWidgetView(label
));
845 splitv2
= WMCreateSplitView(splitv1
);
846 WMResizeWidget(splitv2
, 150, 150);
847 WMSetSplitViewVertical(splitv2
, True
);
849 label
= WMCreateLabel(splitv2
);
850 WMSetLabelText(label
, "Subview 2.1");
851 WMSetLabelRelief(label
, WRSunken
);
853 WMAddSplitViewSubview(splitv2
, WMWidgetView(label
));
855 label
= WMCreateLabel(splitv2
);
856 WMSetLabelText(label
, "Subview 2.2");
857 WMSetLabelRelief(label
, WRSunken
);
859 WMAddSplitViewSubview(splitv2
, WMWidgetView(label
));
861 label
= WMCreateLabel(splitv2
);
862 WMSetLabelText(label
, "Subview 2.3");
863 WMSetLabelRelief(label
, WRSunken
);
865 WMAddSplitViewSubview(splitv2
, WMWidgetView(label
));
867 WMMapWidget(splitv2
);
868 WMAddSplitViewSubview(splitv1
, WMWidgetView(splitv2
));
870 WMRealizeWidget(win
);
871 WMMapSubwidgets(win
);
876 /*******************************************************************/
878 #include <sys/types.h>
890 getImage(WMScreen
*scr
, char *file
)
895 sprintf(buffer
, "../../WindowMaker/Icons/%s", file
);
896 pix
= WMCreatePixmapFromFile(scr
, buffer
);
905 iconMouseStuff(XEvent
*event
, void *cdata
)
907 WMLabel
*label
= (WMLabel
*)cdata
;
908 DNDStuff
*stuff
= WMGetHangedData(label
);
911 switch (event
->type
) {
913 stuff
->x
= event
->xbutton
.x
;
914 stuff
->y
= event
->xbutton
.y
;
915 stuff
->mouseDown
= True
;
918 stuff
->mouseDown
= False
;
921 if (!stuff
->mouseDown
)
924 if (abs(stuff
->x
- event
->xmotion
.x
)>4
925 || abs(stuff
->y
- event
->xmotion
.y
)>4) {
927 where
= WMGetViewScreenPosition(WMWidgetView(label
));
929 WMDragImageFromView(WMWidgetView(label
),
930 WMGetLabelImage(label
),
933 wmksize(stuff
->x
, stuff
->y
),
942 endedDragImage(WMView
*self
, WMPixmap
*image
, WMPoint point
, Bool deposited
)
944 DNDStuff
*stuff
= WMGetHangedData(WMWidgetOfView(self
));
947 WMDestroyWidget(WMWidgetOfView(self
));
950 stuff
->mouseDown
= False
;
955 fetchDragData(WMView
*self
, char *type
)
957 DNDStuff
*stuff
= WMGetHangedData(WMWidgetOfView(self
));
959 return WMCreateDataWithBytes(stuff
->filename
, strlen(stuff
->filename
)+1);
963 WMDragSourceProcs dragSourceProcs
= {
971 /************************/
975 draggingEntered(WMView
*self
, WMDraggingInfo
*info
)
977 return WDOperationCopy
;
982 draggingUpdated(WMView
*self
, WMDraggingInfo
*info
)
984 return WDOperationCopy
;
988 void (*draggingExited)(WMView *self, WMDraggingInfo *info);
991 prepareForDragOperation(WMView
*self
, WMDraggingInfo
*info
)
993 return "application/X-WINGs-Bla";
997 WMLabel
* makeDraggableLabel(WMWidget
*w
, char *file
, int x
, int y
);
1000 performDragOperation(WMView
*self
, WMDraggingInfo
*info
, WMData
*data
)
1002 char *file
= (char*)WMDataBytes(data
);
1005 pos
= WMGetDraggingInfoImageLocation(info
);
1009 WMPoint pos2
= WMGetViewScreenPosition(self
);
1012 label
= makeDraggableLabel(WMWidgetOfView(self
), file
,
1013 pos
.x
-pos2
.x
, pos
.y
-pos2
.y
);
1014 WMRealizeWidget(label
);
1024 concludeDragOperation(WMView
*self
, WMDraggingInfo
*info
)
1031 WMDragDestinationProcs dragDestProcs
= {
1035 prepareForDragOperation
,
1036 performDragOperation
,
1037 concludeDragOperation
1044 makeDraggableLabel(WMWidget
*w
, char *file
, int x
, int y
)
1048 WMPixmap
*image
= getImage(WMWidgetScreen(w
), file
);
1050 stuff
= wmalloc(sizeof(DNDStuff
));
1051 stuff
->mouseDown
= False
;
1053 stuff
->filename
= wstrdup(file
);
1055 label
= WMCreateLabel(w
);
1056 WMResizeWidget(label
, 48, 48);
1057 WMMoveWidget(label
, x
, y
);
1059 WMSetViewDragSourceProcs(WMWidgetView(label
), &dragSourceProcs
);
1061 WMHangData(label
, stuff
);
1063 WMCreateEventHandler(WMWidgetView(label
),
1064 ButtonPressMask
|ButtonReleaseMask
|ButtonMotionMask
,
1065 iconMouseStuff
, label
);
1068 if (image
!= NULL
) {
1069 WMSetLabelImagePosition(label
, WIPImageOnly
);
1070 WMSetLabelImage(label
, image
);
1071 WMReleasePixmap(image
);
1080 testDragAndDrop(WMScreen
*scr
)
1089 "application/X-WINGs-Bla",
1095 win
= WMCreateWindow(scr
, "dragDrop");
1096 WMResizeWidget(win
, 300, 300);
1097 WMSetWindowCloseAction(win
, closeAction
, NULL
);
1098 WMSetWindowTitle(win
, "Drag and Drop");
1101 frame
= WMCreateFrame(win
);
1102 WMSetFrameRelief(frame
, WRSunken
);
1103 WMResizeWidget(frame
, 250, 250);
1104 WMMoveWidget(frame
, 25, 25);
1106 WMRegisterViewForDraggedTypes(WMWidgetView(frame
), types
);
1107 WMSetViewDragDestinationProcs(WMWidgetView(frame
), &dragDestProcs
);
1109 dir
= opendir("../../WindowMaker/Icons");
1111 perror("../../WindowMaker/Icons");
1115 for (i
= 0, j
=0; j
< 8; i
++) {
1120 if (strstr(ent
->d_name
, ".xpm")==NULL
) {
1124 label
= makeDraggableLabel(frame
, ent
->d_name
,4+(j
/4)*64, 4+(j
%4)*64);
1131 WMMapSubwidgets(frame
);
1133 WMMapSubwidgets(win
);
1134 WMRealizeWidget(win
);
1142 /*******************************************************************/
1149 WMUserDefaults
*defs
;
1152 defs
= WMGetStandardUserDefaults();
1154 sprintf(str
, "TEST DATA");
1156 WMSetUDStringForKey(defs
, str
, "testKey");
1162 main(int argc
, char **argv
)
1168 /* Initialize the application */
1169 WMInitializeApplication("Test", &argc
, argv
);
1174 * Open connection to the X display.
1176 dpy
= XOpenDisplay("");
1179 puts("could not open display");
1183 /* This is used to disable buffering of X protocol requests.
1184 * Do NOT use it unless when debugging. It will cause a major
1185 * slowdown in your application
1188 XSynchronize(dpy
, True
);
1191 * Create screen descriptor.
1193 scr
= WMCreateScreen(dpy
, DefaultScreen(dpy
));
1196 * Loads the logo of the application.
1198 pixmap
= WMCreatePixmapFromFile(scr
, "logo.xpm");
1201 * Makes the logo be used in standard dialog panels.
1203 WMSetApplicationIconImage(scr
, pixmap
); WMReleasePixmap(pixmap
);
1206 * Do some test stuff.
1208 * Put the testSomething() function you want to test here.
1219 testDragAndDrop(scr
);
1220 testDragAndDrop(scr
);
1223 testScrollView(scr
);
1236 testGradientButtons(scr
);
1237 testProgressIndicator(scr
);
1240 testOpenFilePanel(scr
);
1246 * The main event loop.
1249 WMScreenMainLoop(scr
);