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 testBox(WMScreen
*scr
)
128 win
= WMCreateWindow(scr
, "testBox");
129 WMSetWindowTitle(win
, "Box");
130 WMSetWindowCloseAction(win
, closeAction
, NULL
);
131 WMResizeWidget(win
, 400, 300);
133 box
= WMCreateBox(win
);
134 WMMoveWidget(box
, 50, 50);
135 WMResizeWidget(box
, 300, 200);
136 // WMSetBoxHorizontal(box, True);
137 for (i
= 0; i
< 4; i
++) {
138 btn
= WMCreateCommandButton(box
);
139 WMSetButtonText(btn
, "bla");
141 WMAddBoxSubview(box
, WMWidgetView(btn
), i
&1, True
, 20, 0, 5);
144 WMRealizeWidget(win
);
145 WMMapSubwidgets(win
);
153 singleClick(WMWidget
*self
, void *data
)
159 doubleClick(WMWidget
*self
, void *data
)
161 WMLabel
*label
= (WMLabel
*)data
;
162 WMList
*lPtr
= (WMList
*)self
;
165 WMSelectAllListItems(lPtr
);
170 listSelectionObserver(void *observer
, WMNotification
*notification
)
172 WMLabel
*label
= (WMLabel
*)observer
;
173 WMList
*lPtr
= (WMList
*)WMGetNotificationObject(notification
);
176 sprintf(buf
, "Selected items: %d",
177 WMGetArrayItemCount(WMGetListSelectedItems(lPtr
)));
178 WMSetLabelText(label
, buf
);
183 testList(WMScreen
*scr
)
197 win
= WMCreateWindow(scr
, "testList");
198 WMResizeWidget(win
, 370, 250);
199 WMSetWindowTitle(win
, "List");
200 WMSetWindowCloseAction(win
, closeAction
, NULL
);
202 title
= WMCreateLabel(win
);
203 WMResizeWidget(title
, 150, 20);
204 WMMoveWidget(title
, 10, 10);
205 WMSetLabelRelief(title
, WRRidge
);
206 WMSetLabelText(title
, "Single selection list");
208 mtitle
= WMCreateLabel(win
);
209 WMResizeWidget(mtitle
, 150, 20);
210 WMMoveWidget(mtitle
, 210, 10);
211 WMSetLabelRelief(mtitle
, WRRidge
);
212 WMSetLabelText(mtitle
, "Multiple selection list");
214 list
= WMCreateList(win
);
215 /*WMSetListAllowEmptySelection(list, True);*/
216 WMMoveWidget(list
, 10, 40);
217 for (i
=0; i
<50; i
++) {
218 sprintf(text
, "Item %i", i
);
219 WMAddListItem(list
, text
);
221 mlist
= WMCreateList(win
);
222 WMSetListAllowMultipleSelection(mlist
, True
);
223 /*WMSetListAllowEmptySelection(mlist, True);*/
224 WMMoveWidget(mlist
, 210, 40);
225 for (i
=0; i
<135; i
++) {
226 sprintf(text
, "Item %i", i
);
227 WMAddListItem(mlist
, text
);
230 label
= WMCreateLabel(win
);
231 WMResizeWidget(label
, 150, 40);
232 WMMoveWidget(label
, 10, 200);
233 WMSetLabelRelief(label
, WRRidge
);
234 WMSetLabelText(label
, "Selected items: 0");
236 mlabel
= WMCreateLabel(win
);
237 WMResizeWidget(mlabel
, 150, 40);
238 WMMoveWidget(mlabel
, 210, 200);
239 WMSetLabelRelief(mlabel
, WRRidge
);
240 WMSetLabelText(mlabel
, "Selected items: 0");
242 WMSetListAction(list
, singleClick
, label
);
243 WMSetListDoubleAction(list
, doubleClick
, label
);
244 WMSetListAction(mlist
, singleClick
, mlabel
);
245 WMSetListDoubleAction(mlist
, doubleClick
, mlabel
);
247 WMAddNotificationObserver(listSelectionObserver
, label
,
248 WMListSelectionDidChangeNotification
, list
);
249 WMAddNotificationObserver(listSelectionObserver
, mlabel
,
250 WMListSelectionDidChangeNotification
, mlist
);
253 WMRealizeWidget(win
);
254 WMMapSubwidgets(win
);
260 testButton(WMScreen
*scr
)
277 win
= WMCreateWindow(scr
, "testButton");
278 WMResizeWidget(win
, 300, 300);
279 WMSetWindowTitle(win
, "Buttons");
281 WMSetWindowCloseAction(win
, closeAction
, NULL
);
283 for (i
= 1; i
< 9; i
++) {
285 b
= WMCreateButton(win
, i
);
286 WMResizeWidget(b
, 150, 24);
287 WMMoveWidget(b
, 20, i
*30);
288 WMSetButtonText(b
, types
[i
-1]);
291 WMRealizeWidget(win
);
292 WMMapSubwidgets(win
);
298 testGradientButtons(WMScreen
*scr
)
302 WMPixmap
*pix1
, *pix2
;
305 WMColor
*color
, *altColor
;
309 /* creates the top-level window */
310 win
= WMCreateWindow(scr
, "testGradientButtons");
311 WMSetWindowTitle(win
, "Gradiented Button Demo");
312 WMResizeWidget(win
, 300, 200);
321 color
= WMCreateRGBColor(scr
, 0x5900, 0x5100, 0x5900, True
);
322 WMSetWidgetBackgroundColor(win
, color
);
323 WMReleaseColor(color
);
325 back
= RRenderGradient(60, 24, &dark
, &light
, RGRD_DIAGONAL
);
326 RBevelImage(back
, RBEV_RAISED2
);
327 pix1
= WMCreatePixmapFromRImage(scr
, back
, 0);
330 back
= RRenderGradient(60, 24, &dark
, &light
, RGRD_DIAGONAL
);
331 RBevelImage(back
, RBEV_SUNKEN
);
332 pix2
= WMCreatePixmapFromRImage(scr
, back
, 0);
335 color
= WMWhiteColor(scr
);
336 altColor
= WMCreateNamedColor(scr
, "red", True
);
338 btn
= WMCreateButton(win
, WBTMomentaryChange
);
339 WMResizeWidget(btn
, 60, 24);
340 WMMoveWidget(btn
, 20, 100);
341 WMSetButtonBordered(btn
, False
);
342 WMSetButtonImagePosition(btn
, WIPOverlaps
);
343 WMSetButtonImage(btn
, pix1
);
344 WMSetButtonAltImage(btn
, pix2
);
345 WMSetButtonText(btn
, "Cool");
346 WMSetButtonTextColor(btn
, color
);
347 WMSetButtonAltTextColor(btn
, altColor
);
349 WMSetBalloonTextForView("This is a cool button", WMWidgetView(btn
));
351 btn
= WMCreateButton(win
, WBTMomentaryChange
);
352 WMResizeWidget(btn
, 60, 24);
353 WMMoveWidget(btn
, 90, 100);
354 WMSetButtonBordered(btn
, False
);
355 WMSetButtonImagePosition(btn
, WIPOverlaps
);
356 WMSetButtonImage(btn
, pix1
);
357 WMSetButtonAltImage(btn
, pix2
);
358 WMSetButtonText(btn
, "Button");
359 WMSetButtonTextColor(btn
, color
);
361 WMSetBalloonTextForView("Este é outro balão.", WMWidgetView(btn
));
363 WMReleaseColor(color
);
364 color
= WMCreateNamedColor(scr
, "orange", True
);
366 btn
= WMCreateButton(win
, WBTMomentaryChange
);
367 WMResizeWidget(btn
, 60, 24);
368 WMMoveWidget(btn
, 160, 100);
369 WMSetButtonBordered(btn
, False
);
370 WMSetButtonImagePosition(btn
, WIPOverlaps
);
371 WMSetButtonImage(btn
, pix1
);
372 WMSetButtonAltImage(btn
, pix2
);
373 WMSetButtonText(btn
, "Test");
374 WMSetButtonTextColor(btn
, color
);
376 WMSetBalloonTextForView("This is yet another button.\nBut the balloon has 3 lines.\nYay!",
379 WMReleaseColor(color
);
380 WMReleaseColor(altColor
);
382 WMRealizeWidget(win
);
383 WMMapSubwidgets(win
);
389 testScrollView(WMScreen
*scr
)
400 /* creates the top-level window */
401 win
= WMCreateWindow(scr
, "testScroll");
402 WMSetWindowTitle(win
, "Scrollable View");
404 WMSetWindowCloseAction(win
, closeAction
, NULL
);
406 /* set the window size */
407 WMResizeWidget(win
, 300, 300);
409 /* creates a scrollable view inside the top-level window */
410 sview
= WMCreateScrollView(win
);
411 WMResizeWidget(sview
, 200, 200);
412 WMMoveWidget(sview
, 30, 30);
413 WMSetScrollViewRelief(sview
, WRSunken
);
414 WMSetScrollViewHasVerticalScroller(sview
, True
);
415 WMSetScrollViewHasHorizontalScroller(sview
, True
);
417 /* create a frame with a bunch of labels */
418 f
= WMCreateFrame(win
);
419 WMResizeWidget(f
, 400, 400);
420 WMSetFrameRelief(f
, WRFlat
);
422 for (i
=0; i
<20; i
++) {
423 l
= WMCreateLabel(f
);
424 WMResizeWidget(l
, 50, 18);
425 WMMoveWidget(l
, 10, 20*i
);
426 sprintf(buffer
, "Label %i", i
);
427 WMSetLabelText(l
, buffer
);
428 WMSetLabelRelief(l
, WRSimple
);
433 WMSetScrollViewContentView(sview
, WMWidgetView(f
));
435 /* make the windows of the widgets be actually created */
436 WMRealizeWidget(win
);
438 /* Map all child widgets of the top-level be mapped.
439 * You must call this for each container widget (like frames),
440 * even if they are childs of the top-level window.
442 WMMapSubwidgets(win
);
444 /* map the top-level window */
450 testColorWell(WMScreen
*scr
)
453 WMColorWell
*well1
, *well2
;
457 win
= WMCreateWindow(scr
, "testColor");
458 WMResizeWidget(win
, 300, 300);
459 WMSetWindowCloseAction(win
, closeAction
, NULL
);
461 well1
= WMCreateColorWell(win
);
462 WMResizeWidget(well1
, 60, 40);
463 WMMoveWidget(well1
, 100, 100);
464 WMSetColorWellColor(well1
, WMCreateRGBColor(scr
, 0x8888, 0, 0x1111, True
));
465 well2
= WMCreateColorWell(win
);
466 WMResizeWidget(well2
, 60, 40);
467 WMMoveWidget(well2
, 200, 100);
468 WMSetColorWellColor(well2
, WMCreateRGBColor(scr
, 0, 0, 0x8888, True
));
470 WMRealizeWidget(win
);
471 WMMapSubwidgets(win
);
476 sliderCallback(WMWidget
*w
, void *data
)
478 printf("SLIDER == %i\n", WMGetSliderValue(w
));
483 testSlider(WMScreen
*scr
)
490 win
= WMCreateWindow(scr
, "testSlider");
491 WMResizeWidget(win
, 300, 300);
492 WMSetWindowTitle(win
, "Sliders");
494 WMSetWindowCloseAction(win
, closeAction
, NULL
);
496 s
= WMCreateSlider(win
);
497 WMResizeWidget(s
, 16, 100);
498 WMMoveWidget(s
, 100, 100);
499 WMSetSliderKnobThickness(s
, 8);
500 WMSetSliderContinuous(s
, False
);
501 WMSetSliderAction(s
, sliderCallback
, s
);
503 s
= WMCreateSlider(win
);
504 WMResizeWidget(s
, 100, 16);
505 WMMoveWidget(s
, 100, 10);
506 WMSetSliderKnobThickness(s
, 8);
508 WMRealizeWidget(win
);
509 WMMapSubwidgets(win
);
514 testTextField(WMScreen
*scr
)
517 WMTextField
*field
, *field2
;
521 win
= WMCreateWindow(scr
, "testTextField");
522 WMResizeWidget(win
, 400, 300);
524 WMSetWindowCloseAction(win
, closeAction
, NULL
);
526 field
= WMCreateTextField(win
);
527 WMResizeWidget(field
, 200, 20);
528 WMMoveWidget(field
, 20, 20);
530 field2
= WMCreateTextField(win
);
531 WMResizeWidget(field2
, 200, 20);
532 WMMoveWidget(field2
, 20, 50);
533 WMSetTextFieldAlignment(field2
, WARight
);
535 WMRealizeWidget(win
);
536 WMMapSubwidgets(win
);
543 testText(WMScreen
*scr
)
547 FILE *file
= fopen("../README", "r");
551 win
= WMCreateWindow(scr
, "testText");
552 WMResizeWidget(win
, 500, 300);
554 WMSetWindowCloseAction(win
, closeAction
, NULL
);
556 text
= WMCreateText(win
);
557 WMResizeWidget(text
, 480, 280);
558 WMMoveWidget(text
, 10, 10);
559 WMSetTextHasVerticalScroller(text
, True
);
560 WMSetTextEditable(text
, False
);
566 while(fgets(buf
, 1023, file
))
567 WMAppendTextStream(text
, buf
);
572 WMAppendTextStream(text
, "<HTML><i>Where's</i> the <b>README</b>?");
575 WMRealizeWidget(win
);
576 WMMapSubwidgets(win
);
582 testProgressIndicator(WMScreen
*scr
)
585 WMProgressIndicator
*pPtr
;
589 win
= WMCreateWindow(scr
, "testProgressIndicator");
590 WMResizeWidget(win
, 292, 32);
592 WMSetWindowCloseAction(win
, closeAction
, NULL
);
594 pPtr
= WMCreateProgressIndicator(win
);
595 WMMoveWidget(pPtr
, 8, 8);
596 WMSetProgressIndicatorValue(pPtr
, 75);
598 WMRealizeWidget(win
);
599 WMMapSubwidgets(win
);
606 testPullDown(WMScreen
*scr
)
609 WMPopUpButton
*pop
, *pop2
;
613 win
= WMCreateWindow(scr
, "pullDown");
614 WMResizeWidget(win
, 400, 300);
616 WMSetWindowCloseAction(win
, closeAction
, NULL
);
618 pop
= WMCreatePopUpButton(win
);
619 WMResizeWidget(pop
, 100, 20);
620 WMMoveWidget(pop
, 50, 60);
621 WMSetPopUpButtonPullsDown(pop
, True
);
622 WMSetPopUpButtonText(pop
, "Commands");
623 WMAddPopUpButtonItem(pop
, "Add");
624 WMAddPopUpButtonItem(pop
, "Remove");
625 WMAddPopUpButtonItem(pop
, "Check");
626 WMAddPopUpButtonItem(pop
, "Eat");
628 pop2
= WMCreatePopUpButton(win
);
629 WMResizeWidget(pop2
, 100, 20);
630 WMMoveWidget(pop2
, 200, 60);
631 WMSetPopUpButtonText(pop2
, "Select");
632 WMAddPopUpButtonItem(pop2
, "Apples");
633 WMAddPopUpButtonItem(pop2
, "Bananas");
634 WMAddPopUpButtonItem(pop2
, "Strawberries");
635 WMAddPopUpButtonItem(pop2
, "Blueberries");
637 WMRealizeWidget(win
);
638 WMMapSubwidgets(win
);
645 testTabView(WMScreen
*scr
)
655 win
= WMCreateWindow(scr
, "testTabs");
656 WMResizeWidget(win
, 400, 300);
658 WMSetWindowCloseAction(win
, closeAction
, NULL
);
660 tabv
= WMCreateTabView(win
);
661 WMMoveWidget(tabv
, 50, 50);
662 WMResizeWidget(tabv
, 300, 200);
664 frame
= WMCreateFrame(win
);
665 WMSetFrameRelief(frame
, WRFlat
);
666 label
= WMCreateLabel(frame
);
667 WMResizeWidget(label
, 100, 100);
668 WMSetLabelText(label
, "Label 1");
672 tab
= WMCreateTabViewItemWithIdentifier(0);
673 WMSetTabViewItemView(tab
, WMWidgetView(frame
));
674 WMAddItemInTabView(tabv
, tab
);
675 WMSetTabViewItemLabel(tab
, "Instances");
677 frame
= WMCreateFrame(win
);
678 WMSetFrameRelief(frame
, WRFlat
);
679 label
= WMCreateLabel(frame
);
680 WMResizeWidget(label
, 40, 50);
681 WMSetLabelText(label
, "Label 2");
685 tab
= WMCreateTabViewItemWithIdentifier(0);
686 WMSetTabViewItemView(tab
, WMWidgetView(frame
));
687 WMAddItemInTabView(tabv
, tab
);
688 WMSetTabViewItemLabel(tab
, "Classes");
691 frame
= WMCreateFrame(win
);
692 WMSetFrameRelief(frame
, WRFlat
);
693 label
= WMCreateLabel(frame
);
694 WMResizeWidget(label
, 100, 100);
695 WMMoveWidget(label
, 60, 40);
696 WMSetLabelText(label
, "Label 3");
699 tab
= WMCreateTabViewItemWithIdentifier(0);
700 WMSetTabViewItemView(tab
, WMWidgetView(frame
));
701 WMAddItemInTabView(tabv
, tab
);
702 WMSetTabViewItemLabel(tab
, "Something");
705 frame
= WMCreateFrame(win
);
706 WMSetFrameRelief(frame
, WRFlat
);
707 label
= WMCreateLabel(frame
);
708 WMResizeWidget(label
, 100, 100);
709 WMMoveWidget(label
, 160, 40);
710 WMSetLabelText(label
, "Label 4");
713 tab
= WMCreateTabViewItemWithIdentifier(0);
714 WMSetTabViewItemView(tab
, WMWidgetView(frame
));
715 WMAddItemInTabView(tabv
, tab
);
716 WMSetTabViewItemLabel(tab
, "Bla!");
720 frame
= WMCreateFrame(win
);
721 WMSetFrameRelief(frame
, WRFlat
);
722 label
= WMCreateLabel(frame
);
723 WMResizeWidget(label
, 100, 100);
724 WMMoveWidget(label
, 160, 40);
725 WMSetLabelText(label
, "Label fjweqklrj qwl");
727 tab
= WMCreateTabViewItemWithIdentifier(0);
728 WMSetTabViewItemView(tab
, WMWidgetView(frame
));
729 WMAddItemInTabView(tabv
, tab
);
730 WMSetTabViewItemLabel(tab
, "Weee!");
733 WMRealizeWidget(win
);
734 WMMapSubwidgets(win
);
740 splitViewConstrainProc(WMSplitView
*sPtr
, int indView
,
741 int *minSize
, int *maxSize
)
761 resizeSplitView(XEvent
*event
, void *data
)
763 WMSplitView
*sPtr
= (WMSplitView
*)data
;
765 if (event
->type
== ConfigureNotify
) {
766 int width
= event
->xconfigure
.width
- 10;
768 if (width
< WMGetSplitViewDividerThickness(sPtr
))
769 width
= WMGetSplitViewDividerThickness(sPtr
);
771 if (width
!= WMWidgetWidth(sPtr
) ||
772 event
->xconfigure
.height
!= WMWidgetHeight(sPtr
))
773 WMResizeWidget(sPtr
, width
, event
->xconfigure
.height
- 55);
778 appendSubviewButtonAction(WMWidget
*self
, void *data
)
780 WMSplitView
*sPtr
= (WMSplitView
*)data
;
782 WMLabel
*label
= WMCreateLabel(sPtr
);
784 sprintf(buf
, "Subview %d", WMGetSplitViewSubviewsCount(sPtr
) + 1);
785 WMSetLabelText(label
, buf
);
786 WMSetLabelRelief(label
, WRSunken
);
787 WMAddSplitViewSubview(sPtr
, WMWidgetView(label
));
788 WMRealizeWidget(label
);
793 removeSubviewButtonAction(WMWidget
*self
, void *data
)
795 WMSplitView
*sPtr
= (WMSplitView
*)data
;
796 int count
= WMGetSplitViewSubviewsCount(sPtr
);
799 WMView
*view
= WMGetSplitViewSubviewAt(sPtr
, count
-1);
800 WMDestroyWidget(WMWidgetOfView(view
));
801 WMRemoveSplitViewSubviewAt(sPtr
, count
-1);
806 orientationButtonAction(WMWidget
*self
, void *data
)
808 WMSplitView
*sPtr
= (WMSplitView
*)data
;
809 WMSetSplitViewVertical(sPtr
, !WMGetSplitViewVertical(sPtr
));
813 adjustSubviewsButtonAction(WMWidget
*self
, void *data
)
815 WMAdjustSplitViewSubviews((WMSplitView
*)data
);
819 testSplitView(WMScreen
*scr
)
822 WMSplitView
*splitv1
, *splitv2
;
829 win
= WMCreateWindow(scr
, "testTabs");
830 WMResizeWidget(win
, 300, 400);
831 WMSetWindowCloseAction(win
, closeAction
, NULL
);
833 frame
= WMCreateFrame(win
);
834 WMSetFrameRelief(frame
, WRSunken
);
835 WMMoveWidget(frame
, 5, 5);
836 WMResizeWidget(frame
, 290, 40);
838 splitv1
= WMCreateSplitView(win
);
839 WMMoveWidget(splitv1
, 5, 50);
840 WMResizeWidget(splitv1
, 290, 345);
841 WMSetSplitViewConstrainProc(splitv1
, splitViewConstrainProc
);
842 WMCreateEventHandler(WMWidgetView(win
), StructureNotifyMask
,
843 resizeSplitView
, splitv1
);
845 button
= WMCreateCommandButton(frame
);
846 WMSetButtonText(button
, "+");
847 WMSetButtonAction(button
, appendSubviewButtonAction
, splitv1
);
848 WMMoveWidget(button
, 10, 8);
851 button
= WMCreateCommandButton(frame
);
852 WMSetButtonText(button
, "-");
853 WMSetButtonAction(button
, removeSubviewButtonAction
, splitv1
);
854 WMMoveWidget(button
, 80, 8);
857 button
= WMCreateCommandButton(frame
);
858 WMSetButtonText(button
, "=");
859 WMMoveWidget(button
, 150, 8);
860 WMSetButtonAction(button
, adjustSubviewsButtonAction
, splitv1
);
863 button
= WMCreateCommandButton(frame
);
864 WMSetButtonText(button
, "#");
865 WMMoveWidget(button
, 220, 8);
866 WMSetButtonAction(button
, orientationButtonAction
, splitv1
);
869 label
= WMCreateLabel(splitv1
);
870 WMSetLabelText(label
, "Subview 1");
871 WMSetLabelRelief(label
, WRSunken
);
873 WMAddSplitViewSubview(splitv1
, WMWidgetView(label
));
875 splitv2
= WMCreateSplitView(splitv1
);
876 WMResizeWidget(splitv2
, 150, 150);
877 WMSetSplitViewVertical(splitv2
, True
);
879 label
= WMCreateLabel(splitv2
);
880 WMSetLabelText(label
, "Subview 2.1");
881 WMSetLabelRelief(label
, WRSunken
);
883 WMAddSplitViewSubview(splitv2
, WMWidgetView(label
));
885 label
= WMCreateLabel(splitv2
);
886 WMSetLabelText(label
, "Subview 2.2");
887 WMSetLabelRelief(label
, WRSunken
);
889 WMAddSplitViewSubview(splitv2
, WMWidgetView(label
));
891 label
= WMCreateLabel(splitv2
);
892 WMSetLabelText(label
, "Subview 2.3");
893 WMSetLabelRelief(label
, WRSunken
);
895 WMAddSplitViewSubview(splitv2
, WMWidgetView(label
));
897 WMMapWidget(splitv2
);
898 WMAddSplitViewSubview(splitv1
, WMWidgetView(splitv2
));
900 WMRealizeWidget(win
);
901 WMMapSubwidgets(win
);
906 /*******************************************************************/
908 #include <sys/types.h>
920 getImage(WMScreen
*scr
, char *file
)
925 sprintf(buffer
, "../../WindowMaker/Icons/%s", file
);
926 pix
= WMCreatePixmapFromFile(scr
, buffer
);
935 iconMouseStuff(XEvent
*event
, void *cdata
)
937 WMLabel
*label
= (WMLabel
*)cdata
;
938 DNDStuff
*stuff
= WMGetHangedData(label
);
941 switch (event
->type
) {
943 stuff
->x
= event
->xbutton
.x
;
944 stuff
->y
= event
->xbutton
.y
;
945 stuff
->mouseDown
= True
;
948 stuff
->mouseDown
= False
;
951 if (!stuff
->mouseDown
)
954 if (abs(stuff
->x
- event
->xmotion
.x
)>4
955 || abs(stuff
->y
- event
->xmotion
.y
)>4) {
957 where
= WMGetViewScreenPosition(WMWidgetView(label
));
959 WMDragImageFromView(WMWidgetView(label
),
960 WMGetLabelImage(label
),
963 wmksize(stuff
->x
, stuff
->y
),
972 endedDragImage(WMView
*self
, WMPixmap
*image
, WMPoint point
, Bool deposited
)
974 DNDStuff
*stuff
= WMGetHangedData(WMWidgetOfView(self
));
977 WMDestroyWidget(WMWidgetOfView(self
));
980 stuff
->mouseDown
= False
;
985 fetchDragData(WMView
*self
, char *type
)
987 DNDStuff
*stuff
= WMGetHangedData(WMWidgetOfView(self
));
989 return WMCreateDataWithBytes(stuff
->filename
, strlen(stuff
->filename
)+1);
993 WMDragSourceProcs dragSourceProcs
= {
1001 /************************/
1005 draggingEntered(WMView
*self
, WMDraggingInfo
*info
)
1007 return WDOperationCopy
;
1012 draggingUpdated(WMView
*self
, WMDraggingInfo
*info
)
1014 return WDOperationCopy
;
1018 void (*draggingExited)(WMView *self, WMDraggingInfo *info);
1021 prepareForDragOperation(WMView
*self
, WMDraggingInfo
*info
)
1023 return "application/X-WINGs-Bla";
1027 WMLabel
* makeDraggableLabel(WMWidget
*w
, char *file
, int x
, int y
);
1030 performDragOperation(WMView
*self
, WMDraggingInfo
*info
, WMData
*data
)
1032 char *file
= (char*)WMDataBytes(data
);
1035 pos
= WMGetDraggingInfoImageLocation(info
);
1039 WMPoint pos2
= WMGetViewScreenPosition(self
);
1042 label
= makeDraggableLabel(WMWidgetOfView(self
), file
,
1043 pos
.x
-pos2
.x
, pos
.y
-pos2
.y
);
1044 WMRealizeWidget(label
);
1054 concludeDragOperation(WMView
*self
, WMDraggingInfo
*info
)
1061 WMDragDestinationProcs dragDestProcs
= {
1065 prepareForDragOperation
,
1066 performDragOperation
,
1067 concludeDragOperation
1074 makeDraggableLabel(WMWidget
*w
, char *file
, int x
, int y
)
1078 WMPixmap
*image
= getImage(WMWidgetScreen(w
), file
);
1080 stuff
= wmalloc(sizeof(DNDStuff
));
1081 stuff
->mouseDown
= False
;
1083 stuff
->filename
= wstrdup(file
);
1085 label
= WMCreateLabel(w
);
1086 WMResizeWidget(label
, 48, 48);
1087 WMMoveWidget(label
, x
, y
);
1089 WMSetViewDragSourceProcs(WMWidgetView(label
), &dragSourceProcs
);
1091 WMHangData(label
, stuff
);
1093 WMCreateEventHandler(WMWidgetView(label
),
1094 ButtonPressMask
|ButtonReleaseMask
|ButtonMotionMask
,
1095 iconMouseStuff
, label
);
1098 if (image
!= NULL
) {
1099 WMSetLabelImagePosition(label
, WIPImageOnly
);
1100 WMSetLabelImage(label
, image
);
1101 WMReleasePixmap(image
);
1110 testDragAndDrop(WMScreen
*scr
)
1119 "application/X-WINGs-Bla",
1125 win
= WMCreateWindow(scr
, "dragDrop");
1126 WMResizeWidget(win
, 300, 300);
1127 WMSetWindowCloseAction(win
, closeAction
, NULL
);
1128 WMSetWindowTitle(win
, "Drag and Drop");
1131 frame
= WMCreateFrame(win
);
1132 WMSetFrameRelief(frame
, WRSunken
);
1133 WMResizeWidget(frame
, 250, 250);
1134 WMMoveWidget(frame
, 25, 25);
1136 WMRegisterViewForDraggedTypes(WMWidgetView(frame
), types
);
1137 WMSetViewDragDestinationProcs(WMWidgetView(frame
), &dragDestProcs
);
1139 dir
= opendir("../../WindowMaker/Icons");
1141 perror("../../WindowMaker/Icons");
1145 for (i
= 0, j
=0; j
< 8; i
++) {
1150 if (strstr(ent
->d_name
, ".xpm")==NULL
) {
1154 label
= makeDraggableLabel(frame
, ent
->d_name
,4+(j
/4)*64, 4+(j
%4)*64);
1161 WMMapSubwidgets(frame
);
1163 WMMapSubwidgets(win
);
1164 WMRealizeWidget(win
);
1172 /*******************************************************************/
1179 WMUserDefaults
*defs
;
1182 defs
= WMGetStandardUserDefaults();
1184 sprintf(str
, "TEST DATA");
1186 WMSetUDStringForKey(defs
, str
, "testKey");
1192 main(int argc
, char **argv
)
1198 /* Initialize the application */
1199 WMInitializeApplication("Test", &argc
, argv
);
1204 * Open connection to the X display.
1206 dpy
= XOpenDisplay("");
1209 puts("could not open display");
1213 /* This is used to disable buffering of X protocol requests.
1214 * Do NOT use it unless when debugging. It will cause a major
1215 * slowdown in your application
1218 XSynchronize(dpy
, True
);
1221 * Create screen descriptor.
1223 scr
= WMCreateScreen(dpy
, DefaultScreen(dpy
));
1226 * Loads the logo of the application.
1228 pixmap
= WMCreatePixmapFromFile(scr
, "logo.xpm");
1231 * Makes the logo be used in standard dialog panels.
1233 WMSetApplicationIconImage(scr
, pixmap
); WMReleasePixmap(pixmap
);
1236 * Do some test stuff.
1238 * Put the testSomething() function you want to test here.
1245 testProgressIndicator(scr
);
1252 testDragAndDrop(scr
);
1253 testDragAndDrop(scr
);
1256 testScrollView(scr
);
1268 testGradientButtons(scr
);
1271 testOpenFilePanel(scr
);
1277 * The main event loop.
1280 WMScreenMainLoop(scr
);