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
);
510 testText(WMScreen
*scr
)
514 FILE *file
= fopen("../README", "r");
518 win
= WMCreateWindow(scr
, "testText");
519 WMResizeWidget(win
, 500, 300);
521 WMSetWindowCloseAction(win
, closeAction
, NULL
);
523 text
= WMCreateText(win
);
524 WMResizeWidget(text
, 480, 280);
525 WMMoveWidget(text
, 10, 10);
526 WMSetTextHasVerticalScroller(text
, True
);
527 WMSetTextEditable(text
, False
);
534 while(fgets(buf
, 1023, file
))
535 WMAppendTextStream(text
, buf
);
540 WMAppendTextStream(text
, "<HTML><i>Where's</i> the <b>README</b>?");
544 while(fgets(buf
, 1023, file
))
545 WMAppendTextStream(text
, buf
);
549 WMRefreshText(text
, 0, 0);
551 WMAppendTextStream(text
, "<HTML><i>Where's</i> the <b>README</b>?");
555 WMRealizeWidget(win
);
556 WMMapSubwidgets(win
);
563 testProgressIndicator(WMScreen
*scr
)
566 WMProgressIndicator
*pPtr
;
570 win
= WMCreateWindow(scr
, "testProgressIndicator");
571 WMResizeWidget(win
, 292, 32);
573 WMSetWindowCloseAction(win
, closeAction
, NULL
);
575 pPtr
= WMCreateProgressIndicator(win
);
576 WMMoveWidget(pPtr
, 8, 8);
577 WMSetProgressIndicatorValue(pPtr
, 75);
579 WMRealizeWidget(win
);
580 WMMapSubwidgets(win
);
587 testPullDown(WMScreen
*scr
)
590 WMPopUpButton
*pop
, *pop2
;
594 win
= WMCreateWindow(scr
, "pullDown");
595 WMResizeWidget(win
, 400, 300);
597 WMSetWindowCloseAction(win
, closeAction
, NULL
);
599 pop
= WMCreatePopUpButton(win
);
600 WMResizeWidget(pop
, 100, 20);
601 WMMoveWidget(pop
, 50, 60);
602 WMSetPopUpButtonPullsDown(pop
, True
);
603 WMSetPopUpButtonText(pop
, "Commands");
604 WMAddPopUpButtonItem(pop
, "Add");
605 WMAddPopUpButtonItem(pop
, "Remove");
606 WMAddPopUpButtonItem(pop
, "Check");
607 WMAddPopUpButtonItem(pop
, "Eat");
609 pop2
= WMCreatePopUpButton(win
);
610 WMResizeWidget(pop2
, 100, 20);
611 WMMoveWidget(pop2
, 200, 60);
612 WMSetPopUpButtonText(pop2
, "Select");
613 WMAddPopUpButtonItem(pop2
, "Apples");
614 WMAddPopUpButtonItem(pop2
, "Bananas");
615 WMAddPopUpButtonItem(pop2
, "Strawberries");
616 WMAddPopUpButtonItem(pop2
, "Blueberries");
618 WMRealizeWidget(win
);
619 WMMapSubwidgets(win
);
626 testTabView(WMScreen
*scr
)
636 win
= WMCreateWindow(scr
, "testTabs");
637 WMResizeWidget(win
, 400, 300);
639 WMSetWindowCloseAction(win
, closeAction
, NULL
);
641 tabv
= WMCreateTabView(win
);
642 WMMoveWidget(tabv
, 50, 50);
643 WMResizeWidget(tabv
, 300, 200);
645 frame
= WMCreateFrame(win
);
646 WMSetFrameRelief(frame
, WRFlat
);
647 label
= WMCreateLabel(frame
);
648 WMResizeWidget(label
, 100, 100);
649 WMSetLabelText(label
, "Label 1");
653 tab
= WMCreateTabViewItemWithIdentifier(0);
654 WMSetTabViewItemView(tab
, WMWidgetView(frame
));
655 WMAddItemInTabView(tabv
, tab
);
656 WMSetTabViewItemLabel(tab
, "Instances");
658 frame
= WMCreateFrame(win
);
659 WMSetFrameRelief(frame
, WRFlat
);
660 label
= WMCreateLabel(frame
);
661 WMResizeWidget(label
, 40, 50);
662 WMSetLabelText(label
, "Label 2");
666 tab
= WMCreateTabViewItemWithIdentifier(0);
667 WMSetTabViewItemView(tab
, WMWidgetView(frame
));
668 WMAddItemInTabView(tabv
, tab
);
669 WMSetTabViewItemLabel(tab
, "Classes");
672 frame
= WMCreateFrame(win
);
673 WMSetFrameRelief(frame
, WRFlat
);
674 label
= WMCreateLabel(frame
);
675 WMResizeWidget(label
, 100, 100);
676 WMMoveWidget(label
, 60, 40);
677 WMSetLabelText(label
, "Label 3");
680 tab
= WMCreateTabViewItemWithIdentifier(0);
681 WMSetTabViewItemView(tab
, WMWidgetView(frame
));
682 WMAddItemInTabView(tabv
, tab
);
683 WMSetTabViewItemLabel(tab
, "Something");
686 frame
= WMCreateFrame(win
);
687 WMSetFrameRelief(frame
, WRFlat
);
688 label
= WMCreateLabel(frame
);
689 WMResizeWidget(label
, 100, 100);
690 WMMoveWidget(label
, 160, 40);
691 WMSetLabelText(label
, "Label 4");
694 tab
= WMCreateTabViewItemWithIdentifier(0);
695 WMSetTabViewItemView(tab
, WMWidgetView(frame
));
696 WMAddItemInTabView(tabv
, tab
);
697 WMSetTabViewItemLabel(tab
, "Bla!");
701 frame
= WMCreateFrame(win
);
702 WMSetFrameRelief(frame
, WRFlat
);
703 label
= WMCreateLabel(frame
);
704 WMResizeWidget(label
, 100, 100);
705 WMMoveWidget(label
, 160, 40);
706 WMSetLabelText(label
, "Label fjweqklrj qwl");
708 tab
= WMCreateTabViewItemWithIdentifier(0);
709 WMSetTabViewItemView(tab
, WMWidgetView(frame
));
710 WMAddItemInTabView(tabv
, tab
);
711 WMSetTabViewItemLabel(tab
, "Weee!");
714 WMRealizeWidget(win
);
715 WMMapSubwidgets(win
);
721 splitViewConstrainProc(WMSplitView
*sPtr
, int indView
,
722 int *minSize
, int *maxSize
)
742 resizeSplitView(XEvent
*event
, void *data
)
744 WMSplitView
*sPtr
= (WMSplitView
*)data
;
746 if (event
->type
== ConfigureNotify
) {
747 int width
= event
->xconfigure
.width
- 10;
749 if (width
< WMGetSplitViewDividerThickness(sPtr
))
750 width
= WMGetSplitViewDividerThickness(sPtr
);
752 if (width
!= WMWidgetWidth(sPtr
) ||
753 event
->xconfigure
.height
!= WMWidgetHeight(sPtr
))
754 WMResizeWidget(sPtr
, width
, event
->xconfigure
.height
- 55);
759 appendSubviewButtonAction(WMWidget
*self
, void *data
)
761 WMSplitView
*sPtr
= (WMSplitView
*)data
;
763 WMLabel
*label
= WMCreateLabel(sPtr
);
765 sprintf(buf
, "Subview %d", WMGetSplitViewSubviewsCount(sPtr
) + 1);
766 WMSetLabelText(label
, buf
);
767 WMSetLabelRelief(label
, WRSunken
);
768 WMAddSplitViewSubview(sPtr
, WMWidgetView(label
));
769 WMRealizeWidget(label
);
774 removeSubviewButtonAction(WMWidget
*self
, void *data
)
776 WMSplitView
*sPtr
= (WMSplitView
*)data
;
777 int count
= WMGetSplitViewSubviewsCount(sPtr
);
780 WMView
*view
= WMGetSplitViewSubviewAt(sPtr
, count
-1);
781 WMDestroyWidget(WMWidgetOfView(view
));
782 WMRemoveSplitViewSubviewAt(sPtr
, count
-1);
787 orientationButtonAction(WMWidget
*self
, void *data
)
789 WMSplitView
*sPtr
= (WMSplitView
*)data
;
790 WMSetSplitViewVertical(sPtr
, !WMGetSplitViewVertical(sPtr
));
794 adjustSubviewsButtonAction(WMWidget
*self
, void *data
)
796 WMAdjustSplitViewSubviews((WMSplitView
*)data
);
800 testSplitView(WMScreen
*scr
)
803 WMSplitView
*splitv1
, *splitv2
;
810 win
= WMCreateWindow(scr
, "testTabs");
811 WMResizeWidget(win
, 300, 400);
812 WMSetWindowCloseAction(win
, closeAction
, NULL
);
814 frame
= WMCreateFrame(win
);
815 WMSetFrameRelief(frame
, WRSunken
);
816 WMMoveWidget(frame
, 5, 5);
817 WMResizeWidget(frame
, 290, 40);
819 splitv1
= WMCreateSplitView(win
);
820 WMMoveWidget(splitv1
, 5, 50);
821 WMResizeWidget(splitv1
, 290, 345);
822 WMSetSplitViewConstrainProc(splitv1
, splitViewConstrainProc
);
823 WMCreateEventHandler(WMWidgetView(win
), StructureNotifyMask
,
824 resizeSplitView
, splitv1
);
826 button
= WMCreateCommandButton(frame
);
827 WMSetButtonText(button
, "+");
828 WMSetButtonAction(button
, appendSubviewButtonAction
, splitv1
);
829 WMMoveWidget(button
, 10, 8);
832 button
= WMCreateCommandButton(frame
);
833 WMSetButtonText(button
, "-");
834 WMSetButtonAction(button
, removeSubviewButtonAction
, splitv1
);
835 WMMoveWidget(button
, 80, 8);
838 button
= WMCreateCommandButton(frame
);
839 WMSetButtonText(button
, "=");
840 WMMoveWidget(button
, 150, 8);
841 WMSetButtonAction(button
, adjustSubviewsButtonAction
, splitv1
);
844 button
= WMCreateCommandButton(frame
);
845 WMSetButtonText(button
, "#");
846 WMMoveWidget(button
, 220, 8);
847 WMSetButtonAction(button
, orientationButtonAction
, splitv1
);
850 label
= WMCreateLabel(splitv1
);
851 WMSetLabelText(label
, "Subview 1");
852 WMSetLabelRelief(label
, WRSunken
);
854 WMAddSplitViewSubview(splitv1
, WMWidgetView(label
));
856 splitv2
= WMCreateSplitView(splitv1
);
857 WMResizeWidget(splitv2
, 150, 150);
858 WMSetSplitViewVertical(splitv2
, True
);
860 label
= WMCreateLabel(splitv2
);
861 WMSetLabelText(label
, "Subview 2.1");
862 WMSetLabelRelief(label
, WRSunken
);
864 WMAddSplitViewSubview(splitv2
, WMWidgetView(label
));
866 label
= WMCreateLabel(splitv2
);
867 WMSetLabelText(label
, "Subview 2.2");
868 WMSetLabelRelief(label
, WRSunken
);
870 WMAddSplitViewSubview(splitv2
, WMWidgetView(label
));
872 label
= WMCreateLabel(splitv2
);
873 WMSetLabelText(label
, "Subview 2.3");
874 WMSetLabelRelief(label
, WRSunken
);
876 WMAddSplitViewSubview(splitv2
, WMWidgetView(label
));
878 WMMapWidget(splitv2
);
879 WMAddSplitViewSubview(splitv1
, WMWidgetView(splitv2
));
881 WMRealizeWidget(win
);
882 WMMapSubwidgets(win
);
887 /*******************************************************************/
889 #include <sys/types.h>
901 getImage(WMScreen
*scr
, char *file
)
906 sprintf(buffer
, "../../WindowMaker/Icons/%s", file
);
907 pix
= WMCreatePixmapFromFile(scr
, buffer
);
916 iconMouseStuff(XEvent
*event
, void *cdata
)
918 WMLabel
*label
= (WMLabel
*)cdata
;
919 DNDStuff
*stuff
= WMGetHangedData(label
);
922 switch (event
->type
) {
924 stuff
->x
= event
->xbutton
.x
;
925 stuff
->y
= event
->xbutton
.y
;
926 stuff
->mouseDown
= True
;
929 stuff
->mouseDown
= False
;
932 if (!stuff
->mouseDown
)
935 if (abs(stuff
->x
- event
->xmotion
.x
)>4
936 || abs(stuff
->y
- event
->xmotion
.y
)>4) {
938 where
= WMGetViewScreenPosition(WMWidgetView(label
));
940 WMDragImageFromView(WMWidgetView(label
),
941 WMGetLabelImage(label
),
944 wmksize(stuff
->x
, stuff
->y
),
953 endedDragImage(WMView
*self
, WMPixmap
*image
, WMPoint point
, Bool deposited
)
955 DNDStuff
*stuff
= WMGetHangedData(WMWidgetOfView(self
));
958 WMDestroyWidget(WMWidgetOfView(self
));
961 stuff
->mouseDown
= False
;
966 fetchDragData(WMView
*self
, char *type
)
968 DNDStuff
*stuff
= WMGetHangedData(WMWidgetOfView(self
));
970 return WMCreateDataWithBytes(stuff
->filename
, strlen(stuff
->filename
)+1);
974 WMDragSourceProcs dragSourceProcs
= {
982 /************************/
986 draggingEntered(WMView
*self
, WMDraggingInfo
*info
)
988 return WDOperationCopy
;
993 draggingUpdated(WMView
*self
, WMDraggingInfo
*info
)
995 return WDOperationCopy
;
999 void (*draggingExited)(WMView *self, WMDraggingInfo *info);
1002 prepareForDragOperation(WMView
*self
, WMDraggingInfo
*info
)
1004 return "application/X-WINGs-Bla";
1008 WMLabel
* makeDraggableLabel(WMWidget
*w
, char *file
, int x
, int y
);
1011 performDragOperation(WMView
*self
, WMDraggingInfo
*info
, WMData
*data
)
1013 char *file
= (char*)WMDataBytes(data
);
1016 pos
= WMGetDraggingInfoImageLocation(info
);
1020 WMPoint pos2
= WMGetViewScreenPosition(self
);
1023 label
= makeDraggableLabel(WMWidgetOfView(self
), file
,
1024 pos
.x
-pos2
.x
, pos
.y
-pos2
.y
);
1025 WMRealizeWidget(label
);
1035 concludeDragOperation(WMView
*self
, WMDraggingInfo
*info
)
1042 WMDragDestinationProcs dragDestProcs
= {
1046 prepareForDragOperation
,
1047 performDragOperation
,
1048 concludeDragOperation
1055 makeDraggableLabel(WMWidget
*w
, char *file
, int x
, int y
)
1059 WMPixmap
*image
= getImage(WMWidgetScreen(w
), file
);
1061 stuff
= wmalloc(sizeof(DNDStuff
));
1062 stuff
->mouseDown
= False
;
1064 stuff
->filename
= wstrdup(file
);
1066 label
= WMCreateLabel(w
);
1067 WMResizeWidget(label
, 48, 48);
1068 WMMoveWidget(label
, x
, y
);
1070 WMSetViewDragSourceProcs(WMWidgetView(label
), &dragSourceProcs
);
1072 WMHangData(label
, stuff
);
1074 WMCreateEventHandler(WMWidgetView(label
),
1075 ButtonPressMask
|ButtonReleaseMask
|ButtonMotionMask
,
1076 iconMouseStuff
, label
);
1079 if (image
!= NULL
) {
1080 WMSetLabelImagePosition(label
, WIPImageOnly
);
1081 WMSetLabelImage(label
, image
);
1082 WMReleasePixmap(image
);
1091 testDragAndDrop(WMScreen
*scr
)
1100 "application/X-WINGs-Bla",
1106 win
= WMCreateWindow(scr
, "dragDrop");
1107 WMResizeWidget(win
, 300, 300);
1108 WMSetWindowCloseAction(win
, closeAction
, NULL
);
1109 WMSetWindowTitle(win
, "Drag and Drop");
1112 frame
= WMCreateFrame(win
);
1113 WMSetFrameRelief(frame
, WRSunken
);
1114 WMResizeWidget(frame
, 250, 250);
1115 WMMoveWidget(frame
, 25, 25);
1117 WMRegisterViewForDraggedTypes(WMWidgetView(frame
), types
);
1118 WMSetViewDragDestinationProcs(WMWidgetView(frame
), &dragDestProcs
);
1120 dir
= opendir("../../WindowMaker/Icons");
1122 perror("../../WindowMaker/Icons");
1126 for (i
= 0, j
=0; j
< 8; i
++) {
1131 if (strstr(ent
->d_name
, ".xpm")==NULL
) {
1135 label
= makeDraggableLabel(frame
, ent
->d_name
,4+(j
/4)*64, 4+(j
%4)*64);
1142 WMMapSubwidgets(frame
);
1144 WMMapSubwidgets(win
);
1145 WMRealizeWidget(win
);
1153 /*******************************************************************/
1160 WMUserDefaults
*defs
;
1163 defs
= WMGetStandardUserDefaults();
1165 sprintf(str
, "TEST DATA");
1167 WMSetUDStringForKey(defs
, str
, "testKey");
1173 main(int argc
, char **argv
)
1179 /* Initialize the application */
1180 WMInitializeApplication("Test", &argc
, argv
);
1185 * Open connection to the X display.
1187 dpy
= XOpenDisplay("");
1190 puts("could not open display");
1194 /* This is used to disable buffering of X protocol requests.
1195 * Do NOT use it unless when debugging. It will cause a major
1196 * slowdown in your application
1199 XSynchronize(dpy
, True
);
1202 * Create screen descriptor.
1204 scr
= WMCreateScreen(dpy
, DefaultScreen(dpy
));
1207 * Loads the logo of the application.
1209 pixmap
= WMCreatePixmapFromFile(scr
, "logo.xpm");
1212 * Makes the logo be used in standard dialog panels.
1214 WMSetApplicationIconImage(scr
, pixmap
); WMReleasePixmap(pixmap
);
1217 * Do some test stuff.
1219 * Put the testSomething() function you want to test here.
1230 testDragAndDrop(scr
);
1231 testDragAndDrop(scr
);
1234 testScrollView(scr
);
1247 testGradientButtons(scr
);
1248 testProgressIndicator(scr
);
1251 testOpenFilePanel(scr
);
1257 * The main event loop.
1260 WMScreenMainLoop(scr
);