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
);
118 static void resizedWindow(void *self
, WMNotification
*notif
)
120 WMView
*view
= (WMView
*)WMGetNotificationObject(notif
);
121 WMSize size
= WMGetViewSize(view
);
123 WMResizeWidget((WMWidget
*)self
, size
.width
, size
.height
);
127 testBox(WMScreen
*scr
)
137 win
= WMCreateWindow(scr
, "testBox");
138 WMSetWindowTitle(win
, "Box");
139 WMSetWindowCloseAction(win
, closeAction
, NULL
);
141 WMSetViewNotifySizeChanges(WMWidgetView(win
), True
);
143 box
= WMCreateBox(win
);
144 WMSetBoxBorderWidth(box
, 5);
146 WMAddNotificationObserver(resizedWindow
, box
,
147 WMViewSizeDidChangeNotification
,
149 WMResizeWidget(win
, 400, 300);
152 /* WMSetBoxHorizontal(box, True); */
153 for (i
= 0; i
< 4; i
++) {
154 btn
= WMCreateCommandButton(box
);
155 WMSetButtonText(btn
, "bla");
157 WMAddBoxSubview(box
, WMWidgetView(btn
), i
&1, True
, 20, 0, 5);
160 pop
= WMCreatePopUpButton(box
);
161 WMAddPopUpButtonItem(pop
, "ewqeq");
162 WMAddPopUpButtonItem(pop
, "ewqeqrewrw");
163 WMAddBoxSubview(box
, WMWidgetView(pop
), False
, True
, 20, 0, 5);
166 hbox
= WMCreateBox(box
);
167 WMSetBoxHorizontal(hbox
, True
);
168 WMAddBoxSubview(box
, WMWidgetView(hbox
), False
, True
, 24, 0, 0);
171 for (i
= 0; i
< 4; i
++) {
172 btn
= WMCreateCommandButton(hbox
);
173 WMSetButtonText(btn
, "bla");
175 WMAddBoxSubview(hbox
, WMWidgetView(btn
), 1, True
, 60, 0, i
<3?5:0);
179 WMRealizeWidget(win
);
180 WMMapSubwidgets(win
);
188 singleClick(WMWidget
*self
, void *data
)
194 doubleClick(WMWidget
*self
, void *data
)
196 WMLabel
*label
= (WMLabel
*)data
;
197 WMList
*lPtr
= (WMList
*)self
;
200 WMSelectAllListItems(lPtr
);
205 listSelectionObserver(void *observer
, WMNotification
*notification
)
207 WMLabel
*label
= (WMLabel
*)observer
;
208 WMList
*lPtr
= (WMList
*)WMGetNotificationObject(notification
);
211 sprintf(buf
, "Selected items: %d",
212 WMGetArrayItemCount(WMGetListSelectedItems(lPtr
)));
213 WMSetLabelText(label
, buf
);
218 testList(WMScreen
*scr
)
232 win
= WMCreateWindow(scr
, "testList");
233 WMResizeWidget(win
, 370, 250);
234 WMSetWindowTitle(win
, "List");
235 WMSetWindowCloseAction(win
, closeAction
, NULL
);
237 title
= WMCreateLabel(win
);
238 WMResizeWidget(title
, 150, 20);
239 WMMoveWidget(title
, 10, 10);
240 WMSetLabelRelief(title
, WRRidge
);
241 WMSetLabelText(title
, "Single selection list");
243 mtitle
= WMCreateLabel(win
);
244 WMResizeWidget(mtitle
, 150, 20);
245 WMMoveWidget(mtitle
, 210, 10);
246 WMSetLabelRelief(mtitle
, WRRidge
);
247 WMSetLabelText(mtitle
, "Multiple selection list");
249 list
= WMCreateList(win
);
250 /*WMSetListAllowEmptySelection(list, True);*/
251 WMMoveWidget(list
, 10, 40);
252 for (i
=0; i
<50; i
++) {
253 sprintf(text
, "Item %i", i
);
254 WMAddListItem(list
, text
);
256 mlist
= WMCreateList(win
);
257 WMSetListAllowMultipleSelection(mlist
, True
);
258 /*WMSetListAllowEmptySelection(mlist, True);*/
259 WMMoveWidget(mlist
, 210, 40);
260 for (i
=0; i
<135; i
++) {
261 sprintf(text
, "Item %i", i
);
262 WMAddListItem(mlist
, text
);
265 label
= WMCreateLabel(win
);
266 WMResizeWidget(label
, 150, 40);
267 WMMoveWidget(label
, 10, 200);
268 WMSetLabelRelief(label
, WRRidge
);
269 WMSetLabelText(label
, "Selected items: 0");
271 mlabel
= WMCreateLabel(win
);
272 WMResizeWidget(mlabel
, 150, 40);
273 WMMoveWidget(mlabel
, 210, 200);
274 WMSetLabelRelief(mlabel
, WRRidge
);
275 WMSetLabelText(mlabel
, "Selected items: 0");
277 WMSetListAction(list
, singleClick
, label
);
278 WMSetListDoubleAction(list
, doubleClick
, label
);
279 WMSetListAction(mlist
, singleClick
, mlabel
);
280 WMSetListDoubleAction(mlist
, doubleClick
, mlabel
);
282 WMAddNotificationObserver(listSelectionObserver
, label
,
283 WMListSelectionDidChangeNotification
, list
);
284 WMAddNotificationObserver(listSelectionObserver
, mlabel
,
285 WMListSelectionDidChangeNotification
, mlist
);
288 WMRealizeWidget(win
);
289 WMMapSubwidgets(win
);
295 testButton(WMScreen
*scr
)
312 win
= WMCreateWindow(scr
, "testButton");
313 WMResizeWidget(win
, 300, 300);
314 WMSetWindowTitle(win
, "Buttons");
316 WMSetWindowCloseAction(win
, closeAction
, NULL
);
318 for (i
= 1; i
< 9; i
++) {
320 b
= WMCreateButton(win
, i
);
321 WMResizeWidget(b
, 150, 24);
322 WMMoveWidget(b
, 20, i
*30);
323 WMSetButtonText(b
, types
[i
-1]);
326 WMRealizeWidget(win
);
327 WMMapSubwidgets(win
);
333 testGradientButtons(WMScreen
*scr
)
337 WMPixmap
*pix1
, *pix2
;
340 WMColor
*color
, *altColor
;
344 /* creates the top-level window */
345 win
= WMCreateWindow(scr
, "testGradientButtons");
346 WMSetWindowTitle(win
, "Gradiented Button Demo");
347 WMResizeWidget(win
, 300, 200);
356 color
= WMCreateRGBColor(scr
, 0x5900, 0x5100, 0x5900, True
);
357 WMSetWidgetBackgroundColor(win
, color
);
358 WMReleaseColor(color
);
360 back
= RRenderGradient(60, 24, &dark
, &light
, RGRD_DIAGONAL
);
361 RBevelImage(back
, RBEV_RAISED2
);
362 pix1
= WMCreatePixmapFromRImage(scr
, back
, 0);
365 back
= RRenderGradient(60, 24, &dark
, &light
, RGRD_DIAGONAL
);
366 RBevelImage(back
, RBEV_SUNKEN
);
367 pix2
= WMCreatePixmapFromRImage(scr
, back
, 0);
370 color
= WMWhiteColor(scr
);
371 altColor
= WMCreateNamedColor(scr
, "red", True
);
373 btn
= WMCreateButton(win
, WBTMomentaryChange
);
374 WMResizeWidget(btn
, 60, 24);
375 WMMoveWidget(btn
, 20, 100);
376 WMSetButtonBordered(btn
, False
);
377 WMSetButtonImagePosition(btn
, WIPOverlaps
);
378 WMSetButtonImage(btn
, pix1
);
379 WMSetButtonAltImage(btn
, pix2
);
380 WMSetButtonText(btn
, "Cool");
381 WMSetButtonTextColor(btn
, color
);
382 WMSetButtonAltTextColor(btn
, altColor
);
384 WMSetBalloonTextForView("This is a cool button", WMWidgetView(btn
));
386 btn
= WMCreateButton(win
, WBTMomentaryChange
);
387 WMResizeWidget(btn
, 60, 24);
388 WMMoveWidget(btn
, 90, 100);
389 WMSetButtonBordered(btn
, False
);
390 WMSetButtonImagePosition(btn
, WIPOverlaps
);
391 WMSetButtonImage(btn
, pix1
);
392 WMSetButtonAltImage(btn
, pix2
);
393 WMSetButtonText(btn
, "Button");
394 WMSetButtonTextColor(btn
, color
);
396 WMSetBalloonTextForView("Este é outro balão.", WMWidgetView(btn
));
398 WMReleaseColor(color
);
399 color
= WMCreateNamedColor(scr
, "orange", True
);
401 btn
= WMCreateButton(win
, WBTMomentaryChange
);
402 WMResizeWidget(btn
, 60, 24);
403 WMMoveWidget(btn
, 160, 100);
404 WMSetButtonBordered(btn
, False
);
405 WMSetButtonImagePosition(btn
, WIPOverlaps
);
406 WMSetButtonImage(btn
, pix1
);
407 WMSetButtonAltImage(btn
, pix2
);
408 WMSetButtonText(btn
, "Test");
409 WMSetButtonTextColor(btn
, color
);
411 WMSetBalloonTextForView("This is yet another button.\nBut the balloon has 3 lines.\nYay!",
414 WMReleaseColor(color
);
415 WMReleaseColor(altColor
);
417 WMRealizeWidget(win
);
418 WMMapSubwidgets(win
);
424 testScrollView(WMScreen
*scr
)
435 /* creates the top-level window */
436 win
= WMCreateWindow(scr
, "testScroll");
437 WMSetWindowTitle(win
, "Scrollable View");
439 WMSetWindowCloseAction(win
, closeAction
, NULL
);
441 /* set the window size */
442 WMResizeWidget(win
, 300, 300);
444 /* creates a scrollable view inside the top-level window */
445 sview
= WMCreateScrollView(win
);
446 WMResizeWidget(sview
, 200, 200);
447 WMMoveWidget(sview
, 30, 30);
448 WMSetScrollViewRelief(sview
, WRSunken
);
449 WMSetScrollViewHasVerticalScroller(sview
, True
);
450 WMSetScrollViewHasHorizontalScroller(sview
, True
);
452 /* create a frame with a bunch of labels */
453 f
= WMCreateFrame(win
);
454 WMResizeWidget(f
, 400, 400);
455 WMSetFrameRelief(f
, WRFlat
);
457 for (i
=0; i
<20; i
++) {
458 l
= WMCreateLabel(f
);
459 WMResizeWidget(l
, 50, 18);
460 WMMoveWidget(l
, 10, 20*i
);
461 sprintf(buffer
, "Label %i", i
);
462 WMSetLabelText(l
, buffer
);
463 WMSetLabelRelief(l
, WRSimple
);
468 WMSetScrollViewContentView(sview
, WMWidgetView(f
));
470 /* make the windows of the widgets be actually created */
471 WMRealizeWidget(win
);
473 /* Map all child widgets of the top-level be mapped.
474 * You must call this for each container widget (like frames),
475 * even if they are childs of the top-level window.
477 WMMapSubwidgets(win
);
479 /* map the top-level window */
485 testColorWell(WMScreen
*scr
)
488 WMColorWell
*well1
, *well2
;
492 win
= WMCreateWindow(scr
, "testColor");
493 WMResizeWidget(win
, 300, 300);
494 WMSetWindowCloseAction(win
, closeAction
, NULL
);
496 well1
= WMCreateColorWell(win
);
497 WMResizeWidget(well1
, 60, 40);
498 WMMoveWidget(well1
, 100, 100);
499 WMSetColorWellColor(well1
, WMCreateRGBColor(scr
, 0x8888, 0, 0x1111, True
));
500 well2
= WMCreateColorWell(win
);
501 WMResizeWidget(well2
, 60, 40);
502 WMMoveWidget(well2
, 200, 100);
503 WMSetColorWellColor(well2
, WMCreateRGBColor(scr
, 0, 0, 0x8888, True
));
505 WMRealizeWidget(win
);
506 WMMapSubwidgets(win
);
511 sliderCallback(WMWidget
*w
, void *data
)
513 printf("SLIDER == %i\n", WMGetSliderValue(w
));
518 testSlider(WMScreen
*scr
)
525 win
= WMCreateWindow(scr
, "testSlider");
526 WMResizeWidget(win
, 300, 300);
527 WMSetWindowTitle(win
, "Sliders");
529 WMSetWindowCloseAction(win
, closeAction
, NULL
);
531 s
= WMCreateSlider(win
);
532 WMResizeWidget(s
, 16, 100);
533 WMMoveWidget(s
, 100, 100);
534 WMSetSliderKnobThickness(s
, 8);
535 WMSetSliderContinuous(s
, False
);
536 WMSetSliderAction(s
, sliderCallback
, s
);
538 s
= WMCreateSlider(win
);
539 WMResizeWidget(s
, 100, 16);
540 WMMoveWidget(s
, 100, 10);
541 WMSetSliderKnobThickness(s
, 8);
543 WMRealizeWidget(win
);
544 WMMapSubwidgets(win
);
549 testTextField(WMScreen
*scr
)
552 WMTextField
*field
, *field2
;
556 win
= WMCreateWindow(scr
, "testTextField");
557 WMResizeWidget(win
, 400, 300);
559 WMSetWindowCloseAction(win
, closeAction
, NULL
);
561 field
= WMCreateTextField(win
);
562 WMResizeWidget(field
, 200, 20);
563 WMMoveWidget(field
, 20, 20);
565 field2
= WMCreateTextField(win
);
566 WMResizeWidget(field2
, 200, 20);
567 WMMoveWidget(field2
, 20, 50);
568 WMSetTextFieldAlignment(field2
, WARight
);
570 WMRealizeWidget(win
);
571 WMMapSubwidgets(win
);
578 testText(WMScreen
*scr
)
582 FILE *file
= fopen("wm.html", "r");
586 win
= WMCreateWindow(scr
, "testText");
587 WMResizeWidget(win
, 500, 300);
589 WMSetWindowCloseAction(win
, closeAction
, NULL
);
591 text
= WMCreateText(win
);
592 WMResizeWidget(text
, 480, 280);
593 WMMoveWidget(text
, 10, 10);
594 WMSetTextHasVerticalScroller(text
, True
);
595 WMSetTextEditable(text
, False
);
601 while(fgets(buf
, 1023, file
))
602 WMAppendTextStream(text
, buf
);
607 WMAppendTextStream(text
, "<HTML><i>Where's</i> the <b>README</b>?");
610 WMRealizeWidget(win
);
611 WMMapSubwidgets(win
);
617 testProgressIndicator(WMScreen
*scr
)
620 WMProgressIndicator
*pPtr
;
624 win
= WMCreateWindow(scr
, "testProgressIndicator");
625 WMResizeWidget(win
, 292, 32);
627 WMSetWindowCloseAction(win
, closeAction
, NULL
);
629 pPtr
= WMCreateProgressIndicator(win
);
630 WMMoveWidget(pPtr
, 8, 8);
631 WMSetProgressIndicatorValue(pPtr
, 75);
633 WMRealizeWidget(win
);
634 WMMapSubwidgets(win
);
641 testPullDown(WMScreen
*scr
)
644 WMPopUpButton
*pop
, *pop2
;
648 win
= WMCreateWindow(scr
, "pullDown");
649 WMResizeWidget(win
, 400, 300);
651 WMSetWindowCloseAction(win
, closeAction
, NULL
);
653 pop
= WMCreatePopUpButton(win
);
654 WMResizeWidget(pop
, 100, 20);
655 WMMoveWidget(pop
, 50, 60);
656 WMSetPopUpButtonPullsDown(pop
, True
);
657 WMSetPopUpButtonText(pop
, "Commands");
658 WMAddPopUpButtonItem(pop
, "Add");
659 WMAddPopUpButtonItem(pop
, "Remove");
660 WMAddPopUpButtonItem(pop
, "Check");
661 WMAddPopUpButtonItem(pop
, "Eat");
663 pop2
= WMCreatePopUpButton(win
);
664 WMResizeWidget(pop2
, 100, 20);
665 WMMoveWidget(pop2
, 200, 60);
666 WMSetPopUpButtonText(pop2
, "Select");
667 WMAddPopUpButtonItem(pop2
, "Apples");
668 WMAddPopUpButtonItem(pop2
, "Bananas");
669 WMAddPopUpButtonItem(pop2
, "Strawberries");
670 WMAddPopUpButtonItem(pop2
, "Blueberries");
672 WMRealizeWidget(win
);
673 WMMapSubwidgets(win
);
680 testTabView(WMScreen
*scr
)
690 win
= WMCreateWindow(scr
, "testTabs");
691 WMResizeWidget(win
, 400, 300);
693 WMSetWindowCloseAction(win
, closeAction
, NULL
);
695 tabv
= WMCreateTabView(win
);
696 WMMoveWidget(tabv
, 50, 50);
697 WMResizeWidget(tabv
, 300, 200);
699 frame
= WMCreateFrame(win
);
700 WMSetFrameRelief(frame
, WRFlat
);
701 label
= WMCreateLabel(frame
);
702 WMResizeWidget(label
, 100, 100);
703 WMSetLabelText(label
, "Label 1");
707 tab
= WMCreateTabViewItemWithIdentifier(0);
708 WMSetTabViewItemView(tab
, WMWidgetView(frame
));
709 WMAddItemInTabView(tabv
, tab
);
710 WMSetTabViewItemLabel(tab
, "Instances");
712 frame
= WMCreateFrame(win
);
713 WMSetFrameRelief(frame
, WRFlat
);
714 label
= WMCreateLabel(frame
);
715 WMResizeWidget(label
, 40, 50);
716 WMSetLabelText(label
, "Label 2");
720 tab
= WMCreateTabViewItemWithIdentifier(0);
721 WMSetTabViewItemView(tab
, WMWidgetView(frame
));
722 WMAddItemInTabView(tabv
, tab
);
723 WMSetTabViewItemLabel(tab
, "Classes");
726 frame
= WMCreateFrame(win
);
727 WMSetFrameRelief(frame
, WRFlat
);
728 label
= WMCreateLabel(frame
);
729 WMResizeWidget(label
, 100, 100);
730 WMMoveWidget(label
, 60, 40);
731 WMSetLabelText(label
, "Label 3");
734 tab
= WMCreateTabViewItemWithIdentifier(0);
735 WMSetTabViewItemView(tab
, WMWidgetView(frame
));
736 WMAddItemInTabView(tabv
, tab
);
737 WMSetTabViewItemLabel(tab
, "Something");
740 frame
= WMCreateFrame(win
);
741 WMSetFrameRelief(frame
, WRFlat
);
742 label
= WMCreateLabel(frame
);
743 WMResizeWidget(label
, 100, 100);
744 WMMoveWidget(label
, 160, 40);
745 WMSetLabelText(label
, "Label 4");
748 tab
= WMCreateTabViewItemWithIdentifier(0);
749 WMSetTabViewItemView(tab
, WMWidgetView(frame
));
750 WMAddItemInTabView(tabv
, tab
);
751 WMSetTabViewItemLabel(tab
, "Bla!");
755 frame
= WMCreateFrame(win
);
756 WMSetFrameRelief(frame
, WRFlat
);
757 label
= WMCreateLabel(frame
);
758 WMResizeWidget(label
, 100, 100);
759 WMMoveWidget(label
, 160, 40);
760 WMSetLabelText(label
, "Label fjweqklrj qwl");
762 tab
= WMCreateTabViewItemWithIdentifier(0);
763 WMSetTabViewItemView(tab
, WMWidgetView(frame
));
764 WMAddItemInTabView(tabv
, tab
);
765 WMSetTabViewItemLabel(tab
, "Weee!");
768 WMRealizeWidget(win
);
769 WMMapSubwidgets(win
);
775 splitViewConstrainProc(WMSplitView
*sPtr
, int indView
,
776 int *minSize
, int *maxSize
)
796 resizeSplitView(XEvent
*event
, void *data
)
798 WMSplitView
*sPtr
= (WMSplitView
*)data
;
800 if (event
->type
== ConfigureNotify
) {
801 int width
= event
->xconfigure
.width
- 10;
803 if (width
< WMGetSplitViewDividerThickness(sPtr
))
804 width
= WMGetSplitViewDividerThickness(sPtr
);
806 if (width
!= WMWidgetWidth(sPtr
) ||
807 event
->xconfigure
.height
!= WMWidgetHeight(sPtr
))
808 WMResizeWidget(sPtr
, width
, event
->xconfigure
.height
- 55);
813 appendSubviewButtonAction(WMWidget
*self
, void *data
)
815 WMSplitView
*sPtr
= (WMSplitView
*)data
;
817 WMLabel
*label
= WMCreateLabel(sPtr
);
819 sprintf(buf
, "Subview %d", WMGetSplitViewSubviewsCount(sPtr
) + 1);
820 WMSetLabelText(label
, buf
);
821 WMSetLabelRelief(label
, WRSunken
);
822 WMAddSplitViewSubview(sPtr
, WMWidgetView(label
));
823 WMRealizeWidget(label
);
828 removeSubviewButtonAction(WMWidget
*self
, void *data
)
830 WMSplitView
*sPtr
= (WMSplitView
*)data
;
831 int count
= WMGetSplitViewSubviewsCount(sPtr
);
834 WMView
*view
= WMGetSplitViewSubviewAt(sPtr
, count
-1);
835 WMDestroyWidget(WMWidgetOfView(view
));
836 WMRemoveSplitViewSubviewAt(sPtr
, count
-1);
841 orientationButtonAction(WMWidget
*self
, void *data
)
843 WMSplitView
*sPtr
= (WMSplitView
*)data
;
844 WMSetSplitViewVertical(sPtr
, !WMGetSplitViewVertical(sPtr
));
848 adjustSubviewsButtonAction(WMWidget
*self
, void *data
)
850 WMAdjustSplitViewSubviews((WMSplitView
*)data
);
854 testSplitView(WMScreen
*scr
)
857 WMSplitView
*splitv1
, *splitv2
;
864 win
= WMCreateWindow(scr
, "testTabs");
865 WMResizeWidget(win
, 300, 400);
866 WMSetWindowCloseAction(win
, closeAction
, NULL
);
868 frame
= WMCreateFrame(win
);
869 WMSetFrameRelief(frame
, WRSunken
);
870 WMMoveWidget(frame
, 5, 5);
871 WMResizeWidget(frame
, 290, 40);
873 splitv1
= WMCreateSplitView(win
);
874 WMMoveWidget(splitv1
, 5, 50);
875 WMResizeWidget(splitv1
, 290, 345);
876 WMSetSplitViewConstrainProc(splitv1
, splitViewConstrainProc
);
877 WMCreateEventHandler(WMWidgetView(win
), StructureNotifyMask
,
878 resizeSplitView
, splitv1
);
880 button
= WMCreateCommandButton(frame
);
881 WMSetButtonText(button
, "+");
882 WMSetButtonAction(button
, appendSubviewButtonAction
, splitv1
);
883 WMMoveWidget(button
, 10, 8);
886 button
= WMCreateCommandButton(frame
);
887 WMSetButtonText(button
, "-");
888 WMSetButtonAction(button
, removeSubviewButtonAction
, splitv1
);
889 WMMoveWidget(button
, 80, 8);
892 button
= WMCreateCommandButton(frame
);
893 WMSetButtonText(button
, "=");
894 WMMoveWidget(button
, 150, 8);
895 WMSetButtonAction(button
, adjustSubviewsButtonAction
, splitv1
);
898 button
= WMCreateCommandButton(frame
);
899 WMSetButtonText(button
, "#");
900 WMMoveWidget(button
, 220, 8);
901 WMSetButtonAction(button
, orientationButtonAction
, splitv1
);
904 label
= WMCreateLabel(splitv1
);
905 WMSetLabelText(label
, "Subview 1");
906 WMSetLabelRelief(label
, WRSunken
);
908 WMAddSplitViewSubview(splitv1
, WMWidgetView(label
));
910 splitv2
= WMCreateSplitView(splitv1
);
911 WMResizeWidget(splitv2
, 150, 150);
912 WMSetSplitViewVertical(splitv2
, True
);
914 label
= WMCreateLabel(splitv2
);
915 WMSetLabelText(label
, "Subview 2.1");
916 WMSetLabelRelief(label
, WRSunken
);
918 WMAddSplitViewSubview(splitv2
, WMWidgetView(label
));
920 label
= WMCreateLabel(splitv2
);
921 WMSetLabelText(label
, "Subview 2.2");
922 WMSetLabelRelief(label
, WRSunken
);
924 WMAddSplitViewSubview(splitv2
, WMWidgetView(label
));
926 label
= WMCreateLabel(splitv2
);
927 WMSetLabelText(label
, "Subview 2.3");
928 WMSetLabelRelief(label
, WRSunken
);
930 WMAddSplitViewSubview(splitv2
, WMWidgetView(label
));
932 WMMapWidget(splitv2
);
933 WMAddSplitViewSubview(splitv1
, WMWidgetView(splitv2
));
935 WMRealizeWidget(win
);
936 WMMapSubwidgets(win
);
941 /*******************************************************************/
943 #include <sys/types.h>
955 getImage(WMScreen
*scr
, char *file
)
960 sprintf(buffer
, "../../WindowMaker/Icons/%s", file
);
961 pix
= WMCreatePixmapFromFile(scr
, buffer
);
970 iconMouseStuff(XEvent
*event
, void *cdata
)
972 WMLabel
*label
= (WMLabel
*)cdata
;
973 DNDStuff
*stuff
= WMGetHangedData(label
);
976 switch (event
->type
) {
978 stuff
->x
= event
->xbutton
.x
;
979 stuff
->y
= event
->xbutton
.y
;
980 stuff
->mouseDown
= True
;
983 stuff
->mouseDown
= False
;
986 if (!stuff
->mouseDown
)
989 if (abs(stuff
->x
- event
->xmotion
.x
)>4
990 || abs(stuff
->y
- event
->xmotion
.y
)>4) {
992 where
= WMGetViewScreenPosition(WMWidgetView(label
));
994 WMDragImageFromView(WMWidgetView(label
),
995 WMGetLabelImage(label
),
998 wmksize(stuff
->x
, stuff
->y
),
1007 endedDragImage(WMView
*self
, WMPixmap
*image
, WMPoint point
, Bool deposited
)
1009 DNDStuff
*stuff
= WMGetHangedData(WMWidgetOfView(self
));
1012 WMDestroyWidget(WMWidgetOfView(self
));
1015 stuff
->mouseDown
= False
;
1020 fetchDragData(WMView
*self
, char *type
)
1022 DNDStuff
*stuff
= WMGetHangedData(WMWidgetOfView(self
));
1024 return WMCreateDataWithBytes(stuff
->filename
, strlen(stuff
->filename
)+1);
1028 WMDragSourceProcs dragSourceProcs
= {
1036 /************************/
1040 draggingEntered(WMView
*self
, WMDraggingInfo
*info
)
1042 return WDOperationCopy
;
1047 draggingUpdated(WMView
*self
, WMDraggingInfo
*info
)
1049 return WDOperationCopy
;
1053 void (*draggingExited)(WMView *self, WMDraggingInfo *info);
1056 prepareForDragOperation(WMView
*self
, WMDraggingInfo
*info
)
1058 return "application/X-WINGs-Bla";
1062 WMLabel
* makeDraggableLabel(WMWidget
*w
, char *file
, int x
, int y
);
1065 performDragOperation(WMView
*self
, WMDraggingInfo
*info
, WMData
*data
)
1067 char *file
= (char*)WMDataBytes(data
);
1070 pos
= WMGetDraggingInfoImageLocation(info
);
1074 WMPoint pos2
= WMGetViewScreenPosition(self
);
1077 label
= makeDraggableLabel(WMWidgetOfView(self
), file
,
1078 pos
.x
-pos2
.x
, pos
.y
-pos2
.y
);
1079 WMRealizeWidget(label
);
1089 concludeDragOperation(WMView
*self
, WMDraggingInfo
*info
)
1096 WMDragDestinationProcs dragDestProcs
= {
1100 prepareForDragOperation
,
1101 performDragOperation
,
1102 concludeDragOperation
1109 makeDraggableLabel(WMWidget
*w
, char *file
, int x
, int y
)
1113 WMPixmap
*image
= getImage(WMWidgetScreen(w
), file
);
1115 stuff
= wmalloc(sizeof(DNDStuff
));
1116 stuff
->mouseDown
= False
;
1118 stuff
->filename
= wstrdup(file
);
1120 label
= WMCreateLabel(w
);
1121 WMResizeWidget(label
, 48, 48);
1122 WMMoveWidget(label
, x
, y
);
1124 WMSetViewDragSourceProcs(WMWidgetView(label
), &dragSourceProcs
);
1126 WMHangData(label
, stuff
);
1128 WMCreateEventHandler(WMWidgetView(label
),
1129 ButtonPressMask
|ButtonReleaseMask
|ButtonMotionMask
,
1130 iconMouseStuff
, label
);
1133 if (image
!= NULL
) {
1134 WMSetLabelImagePosition(label
, WIPImageOnly
);
1135 WMSetLabelImage(label
, image
);
1136 WMReleasePixmap(image
);
1145 testDragAndDrop(WMScreen
*scr
)
1154 "application/X-WINGs-Bla",
1160 win
= WMCreateWindow(scr
, "dragDrop");
1161 WMResizeWidget(win
, 300, 300);
1162 WMSetWindowCloseAction(win
, closeAction
, NULL
);
1163 WMSetWindowTitle(win
, "Drag and Drop");
1166 frame
= WMCreateFrame(win
);
1167 WMSetFrameRelief(frame
, WRSunken
);
1168 WMResizeWidget(frame
, 250, 250);
1169 WMMoveWidget(frame
, 25, 25);
1171 WMRegisterViewForDraggedTypes(WMWidgetView(frame
), types
);
1172 WMSetViewDragDestinationProcs(WMWidgetView(frame
), &dragDestProcs
);
1174 dir
= opendir("../../WindowMaker/Icons");
1176 perror("../../WindowMaker/Icons");
1180 for (i
= 0, j
=0; j
< 8; i
++) {
1185 if (strstr(ent
->d_name
, ".xpm")==NULL
) {
1189 label
= makeDraggableLabel(frame
, ent
->d_name
,4+(j
/4)*64, 4+(j
%4)*64);
1196 WMMapSubwidgets(frame
);
1198 WMMapSubwidgets(win
);
1199 WMRealizeWidget(win
);
1207 /*******************************************************************/
1214 WMUserDefaults
*defs
;
1217 defs
= WMGetStandardUserDefaults();
1219 sprintf(str
, "TEST DATA");
1221 WMSetUDStringForKey(defs
, str
, "testKey");
1227 main(int argc
, char **argv
)
1233 /* Initialize the application */
1234 WMInitializeApplication("Test@eqweq_ewq$eqw", &argc
, argv
);
1239 * Open connection to the X display.
1241 dpy
= XOpenDisplay("");
1244 puts("could not open display");
1248 /* This is used to disable buffering of X protocol requests.
1249 * Do NOT use it unless when debugging. It will cause a major
1250 * slowdown in your application
1253 XSynchronize(dpy
, True
);
1256 * Create screen descriptor.
1258 scr
= WMCreateScreen(dpy
, DefaultScreen(dpy
));
1261 * Loads the logo of the application.
1263 pixmap
= WMCreatePixmapFromFile(scr
, "logo.xpm");
1266 * Makes the logo be used in standard dialog panels.
1268 WMSetApplicationIconImage(scr
, pixmap
); WMReleasePixmap(pixmap
);
1271 * Do some test stuff.
1273 * Put the testSomething() function you want to test here.
1283 testProgressIndicator(scr
);
1289 testDragAndDrop(scr
);
1290 testDragAndDrop(scr
);
1293 testScrollView(scr
);
1304 testGradientButtons(scr
);
1307 testOpenFilePanel(scr
);
1313 * The main event loop.
1316 WMScreenMainLoop(scr
);