2 * WINGs test application
5 #include <WINGs/WINGs.h>
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
,
608 "Window Maker is the GNU window manager for the "
609 "X Window System. It was designed to emulate the "
610 "look and feel of part of the NEXTSTEP(tm) GUI. Its "
611 "supposed to be relatively fast and small, feature "
612 "rich, easy to configure and easy to use, with a simple "
613 "and elegant appearance borrowed from NEXTSTEP(tm).");
616 WMRealizeWidget(win
);
617 WMMapSubwidgets(win
);
623 testProgressIndicator(WMScreen
*scr
)
626 WMProgressIndicator
*pPtr
;
630 win
= WMCreateWindow(scr
, "testProgressIndicator");
631 WMResizeWidget(win
, 292, 32);
633 WMSetWindowCloseAction(win
, closeAction
, NULL
);
635 pPtr
= WMCreateProgressIndicator(win
);
636 WMMoveWidget(pPtr
, 8, 8);
637 WMSetProgressIndicatorValue(pPtr
, 75);
639 WMRealizeWidget(win
);
640 WMMapSubwidgets(win
);
647 testPullDown(WMScreen
*scr
)
650 WMPopUpButton
*pop
, *pop2
;
654 win
= WMCreateWindow(scr
, "pullDown");
655 WMResizeWidget(win
, 400, 300);
657 WMSetWindowCloseAction(win
, closeAction
, NULL
);
659 pop
= WMCreatePopUpButton(win
);
660 WMResizeWidget(pop
, 100, 20);
661 WMMoveWidget(pop
, 50, 60);
662 WMSetPopUpButtonPullsDown(pop
, True
);
663 WMSetPopUpButtonText(pop
, "Commands");
664 WMAddPopUpButtonItem(pop
, "Add");
665 WMAddPopUpButtonItem(pop
, "Remove");
666 WMAddPopUpButtonItem(pop
, "Check");
667 WMAddPopUpButtonItem(pop
, "Eat");
669 pop2
= WMCreatePopUpButton(win
);
670 WMResizeWidget(pop2
, 100, 20);
671 WMMoveWidget(pop2
, 200, 60);
672 WMSetPopUpButtonText(pop2
, "Select");
673 WMAddPopUpButtonItem(pop2
, "Apples");
674 WMAddPopUpButtonItem(pop2
, "Bananas");
675 WMAddPopUpButtonItem(pop2
, "Strawberries");
676 WMAddPopUpButtonItem(pop2
, "Blueberries");
678 WMRealizeWidget(win
);
679 WMMapSubwidgets(win
);
686 testTabView(WMScreen
*scr
)
696 win
= WMCreateWindow(scr
, "testTabs");
697 WMResizeWidget(win
, 400, 300);
699 WMSetWindowCloseAction(win
, closeAction
, NULL
);
701 tabv
= WMCreateTabView(win
);
702 WMMoveWidget(tabv
, 50, 50);
703 WMResizeWidget(tabv
, 300, 200);
705 frame
= WMCreateFrame(win
);
706 WMSetFrameRelief(frame
, WRFlat
);
707 label
= WMCreateLabel(frame
);
708 WMResizeWidget(label
, 100, 100);
709 WMSetLabelText(label
, "Label 1");
713 tab
= WMCreateTabViewItemWithIdentifier(0);
714 WMSetTabViewItemView(tab
, WMWidgetView(frame
));
715 WMAddItemInTabView(tabv
, tab
);
716 WMSetTabViewItemLabel(tab
, "Instances");
718 frame
= WMCreateFrame(win
);
719 WMSetFrameRelief(frame
, WRFlat
);
720 label
= WMCreateLabel(frame
);
721 WMResizeWidget(label
, 40, 50);
722 WMSetLabelText(label
, "Label 2");
726 tab
= WMCreateTabViewItemWithIdentifier(0);
727 WMSetTabViewItemView(tab
, WMWidgetView(frame
));
728 WMAddItemInTabView(tabv
, tab
);
729 WMSetTabViewItemLabel(tab
, "Classes");
732 frame
= WMCreateFrame(win
);
733 WMSetFrameRelief(frame
, WRFlat
);
734 label
= WMCreateLabel(frame
);
735 WMResizeWidget(label
, 100, 100);
736 WMMoveWidget(label
, 60, 40);
737 WMSetLabelText(label
, "Label 3");
740 tab
= WMCreateTabViewItemWithIdentifier(0);
741 WMSetTabViewItemView(tab
, WMWidgetView(frame
));
742 WMAddItemInTabView(tabv
, tab
);
743 WMSetTabViewItemLabel(tab
, "Something");
746 frame
= WMCreateFrame(win
);
747 WMSetFrameRelief(frame
, WRFlat
);
748 label
= WMCreateLabel(frame
);
749 WMResizeWidget(label
, 100, 100);
750 WMMoveWidget(label
, 160, 40);
751 WMSetLabelText(label
, "Label 4");
754 tab
= WMCreateTabViewItemWithIdentifier(0);
755 WMSetTabViewItemView(tab
, WMWidgetView(frame
));
756 WMAddItemInTabView(tabv
, tab
);
757 WMSetTabViewItemLabel(tab
, "Bla!");
761 frame
= WMCreateFrame(win
);
762 WMSetFrameRelief(frame
, WRFlat
);
763 label
= WMCreateLabel(frame
);
764 WMResizeWidget(label
, 100, 100);
765 WMMoveWidget(label
, 160, 40);
766 WMSetLabelText(label
, "Label fjweqklrj qwl");
768 tab
= WMCreateTabViewItemWithIdentifier(0);
769 WMSetTabViewItemView(tab
, WMWidgetView(frame
));
770 WMAddItemInTabView(tabv
, tab
);
771 WMSetTabViewItemLabel(tab
, "Weee!");
774 WMRealizeWidget(win
);
775 WMMapSubwidgets(win
);
781 splitViewConstrainProc(WMSplitView
*sPtr
, int indView
,
782 int *minSize
, int *maxSize
)
802 resizeSplitView(XEvent
*event
, void *data
)
804 WMSplitView
*sPtr
= (WMSplitView
*)data
;
806 if (event
->type
== ConfigureNotify
) {
807 int width
= event
->xconfigure
.width
- 10;
809 if (width
< WMGetSplitViewDividerThickness(sPtr
))
810 width
= WMGetSplitViewDividerThickness(sPtr
);
812 if (width
!= WMWidgetWidth(sPtr
) ||
813 event
->xconfigure
.height
!= WMWidgetHeight(sPtr
))
814 WMResizeWidget(sPtr
, width
, event
->xconfigure
.height
- 55);
819 appendSubviewButtonAction(WMWidget
*self
, void *data
)
821 WMSplitView
*sPtr
= (WMSplitView
*)data
;
823 WMLabel
*label
= WMCreateLabel(sPtr
);
825 sprintf(buf
, "Subview %d", WMGetSplitViewSubviewsCount(sPtr
) + 1);
826 WMSetLabelText(label
, buf
);
827 WMSetLabelRelief(label
, WRSunken
);
828 WMAddSplitViewSubview(sPtr
, WMWidgetView(label
));
829 WMRealizeWidget(label
);
834 removeSubviewButtonAction(WMWidget
*self
, void *data
)
836 WMSplitView
*sPtr
= (WMSplitView
*)data
;
837 int count
= WMGetSplitViewSubviewsCount(sPtr
);
840 WMView
*view
= WMGetSplitViewSubviewAt(sPtr
, count
-1);
841 WMDestroyWidget(WMWidgetOfView(view
));
842 WMRemoveSplitViewSubviewAt(sPtr
, count
-1);
847 orientationButtonAction(WMWidget
*self
, void *data
)
849 WMSplitView
*sPtr
= (WMSplitView
*)data
;
850 WMSetSplitViewVertical(sPtr
, !WMGetSplitViewVertical(sPtr
));
854 adjustSubviewsButtonAction(WMWidget
*self
, void *data
)
856 WMAdjustSplitViewSubviews((WMSplitView
*)data
);
860 testSplitView(WMScreen
*scr
)
863 WMSplitView
*splitv1
, *splitv2
;
870 win
= WMCreateWindow(scr
, "testTabs");
871 WMResizeWidget(win
, 300, 400);
872 WMSetWindowCloseAction(win
, closeAction
, NULL
);
874 frame
= WMCreateFrame(win
);
875 WMSetFrameRelief(frame
, WRSunken
);
876 WMMoveWidget(frame
, 5, 5);
877 WMResizeWidget(frame
, 290, 40);
879 splitv1
= WMCreateSplitView(win
);
880 WMMoveWidget(splitv1
, 5, 50);
881 WMResizeWidget(splitv1
, 290, 345);
882 WMSetSplitViewConstrainProc(splitv1
, splitViewConstrainProc
);
883 WMCreateEventHandler(WMWidgetView(win
), StructureNotifyMask
,
884 resizeSplitView
, splitv1
);
886 button
= WMCreateCommandButton(frame
);
887 WMSetButtonText(button
, "+");
888 WMSetButtonAction(button
, appendSubviewButtonAction
, splitv1
);
889 WMMoveWidget(button
, 10, 8);
892 button
= WMCreateCommandButton(frame
);
893 WMSetButtonText(button
, "-");
894 WMSetButtonAction(button
, removeSubviewButtonAction
, splitv1
);
895 WMMoveWidget(button
, 80, 8);
898 button
= WMCreateCommandButton(frame
);
899 WMSetButtonText(button
, "=");
900 WMMoveWidget(button
, 150, 8);
901 WMSetButtonAction(button
, adjustSubviewsButtonAction
, splitv1
);
904 button
= WMCreateCommandButton(frame
);
905 WMSetButtonText(button
, "#");
906 WMMoveWidget(button
, 220, 8);
907 WMSetButtonAction(button
, orientationButtonAction
, splitv1
);
910 label
= WMCreateLabel(splitv1
);
911 WMSetLabelText(label
, "Subview 1");
912 WMSetLabelRelief(label
, WRSunken
);
914 WMAddSplitViewSubview(splitv1
, WMWidgetView(label
));
916 splitv2
= WMCreateSplitView(splitv1
);
917 WMResizeWidget(splitv2
, 150, 150);
918 WMSetSplitViewVertical(splitv2
, True
);
920 label
= WMCreateLabel(splitv2
);
921 WMSetLabelText(label
, "Subview 2.1");
922 WMSetLabelRelief(label
, WRSunken
);
924 WMAddSplitViewSubview(splitv2
, WMWidgetView(label
));
926 label
= WMCreateLabel(splitv2
);
927 WMSetLabelText(label
, "Subview 2.2");
928 WMSetLabelRelief(label
, WRSunken
);
930 WMAddSplitViewSubview(splitv2
, WMWidgetView(label
));
932 label
= WMCreateLabel(splitv2
);
933 WMSetLabelText(label
, "Subview 2.3");
934 WMSetLabelRelief(label
, WRSunken
);
936 WMAddSplitViewSubview(splitv2
, WMWidgetView(label
));
938 WMMapWidget(splitv2
);
939 WMAddSplitViewSubview(splitv1
, WMWidgetView(splitv2
));
941 WMRealizeWidget(win
);
942 WMMapSubwidgets(win
);
947 /*******************************************************************/
949 #include <sys/types.h>
961 getImage(WMScreen
*scr
, char *file
)
966 sprintf(buffer
, "../../WindowMaker/Icons/%s", file
);
967 pix
= WMCreatePixmapFromFile(scr
, buffer
);
976 iconMouseStuff(XEvent
*event
, void *cdata
)
978 WMLabel
*label
= (WMLabel
*)cdata
;
979 DNDStuff
*stuff
= WMGetHangedData(label
);
982 switch (event
->type
) {
984 stuff
->x
= event
->xbutton
.x
;
985 stuff
->y
= event
->xbutton
.y
;
986 stuff
->mouseDown
= True
;
989 stuff
->mouseDown
= False
;
992 if (!stuff
->mouseDown
)
995 if (abs(stuff
->x
- event
->xmotion
.x
)>4
996 || abs(stuff
->y
- event
->xmotion
.y
)>4) {
998 where
= WMGetViewScreenPosition(WMWidgetView(label
));
1000 WMDragImageFromView(WMWidgetView(label
),
1001 WMGetLabelImage(label
),
1004 wmksize(stuff
->x
, stuff
->y
),
1013 endedDragImage(WMView
*self
, WMPixmap
*image
, WMPoint point
, Bool deposited
)
1015 DNDStuff
*stuff
= WMGetHangedData(WMWidgetOfView(self
));
1018 WMDestroyWidget(WMWidgetOfView(self
));
1021 stuff
->mouseDown
= False
;
1026 fetchDragData(WMView
*self
, char *type
)
1028 DNDStuff
*stuff
= WMGetHangedData(WMWidgetOfView(self
));
1030 return WMCreateDataWithBytes(stuff
->filename
, strlen(stuff
->filename
)+1);
1034 WMDragSourceProcs dragSourceProcs
= {
1042 /************************/
1046 draggingEntered(WMView
*self
, WMDraggingInfo
*info
)
1048 return WDOperationCopy
;
1053 draggingUpdated(WMView
*self
, WMDraggingInfo
*info
)
1055 return WDOperationCopy
;
1059 void (*draggingExited)(WMView *self, WMDraggingInfo *info);
1062 prepareForDragOperation(WMView
*self
, WMDraggingInfo
*info
)
1064 return "application/X-WINGs-Bla";
1068 WMLabel
* makeDraggableLabel(WMWidget
*w
, char *file
, int x
, int y
);
1071 performDragOperation(WMView
*self
, WMDraggingInfo
*info
, WMData
*data
)
1073 char *file
= (char*)WMDataBytes(data
);
1076 pos
= WMGetDraggingInfoImageLocation(info
);
1080 WMPoint pos2
= WMGetViewScreenPosition(self
);
1083 label
= makeDraggableLabel(WMWidgetOfView(self
), file
,
1084 pos
.x
-pos2
.x
, pos
.y
-pos2
.y
);
1085 WMRealizeWidget(label
);
1095 concludeDragOperation(WMView
*self
, WMDraggingInfo
*info
)
1102 WMDragDestinationProcs dragDestProcs
= {
1106 prepareForDragOperation
,
1107 performDragOperation
,
1108 concludeDragOperation
1115 makeDraggableLabel(WMWidget
*w
, char *file
, int x
, int y
)
1119 WMPixmap
*image
= getImage(WMWidgetScreen(w
), file
);
1121 stuff
= wmalloc(sizeof(DNDStuff
));
1122 stuff
->mouseDown
= False
;
1124 stuff
->filename
= wstrdup(file
);
1126 label
= WMCreateLabel(w
);
1127 WMResizeWidget(label
, 48, 48);
1128 WMMoveWidget(label
, x
, y
);
1130 WMSetViewDragSourceProcs(WMWidgetView(label
), &dragSourceProcs
);
1132 WMHangData(label
, stuff
);
1134 WMCreateEventHandler(WMWidgetView(label
),
1135 ButtonPressMask
|ButtonReleaseMask
|ButtonMotionMask
,
1136 iconMouseStuff
, label
);
1139 if (image
!= NULL
) {
1140 WMSetLabelImagePosition(label
, WIPImageOnly
);
1141 WMSetLabelImage(label
, image
);
1142 WMReleasePixmap(image
);
1151 testDragAndDrop(WMScreen
*scr
)
1160 "application/X-WINGs-Bla",
1166 win
= WMCreateWindow(scr
, "dragDrop");
1167 WMResizeWidget(win
, 300, 300);
1168 WMSetWindowCloseAction(win
, closeAction
, NULL
);
1169 WMSetWindowTitle(win
, "Drag and Drop");
1172 frame
= WMCreateFrame(win
);
1173 WMSetFrameRelief(frame
, WRSunken
);
1174 WMResizeWidget(frame
, 250, 250);
1175 WMMoveWidget(frame
, 25, 25);
1177 WMRegisterViewForDraggedTypes(WMWidgetView(frame
), types
);
1178 WMSetViewDragDestinationProcs(WMWidgetView(frame
), &dragDestProcs
);
1180 dir
= opendir("../../WindowMaker/Icons");
1182 perror("../../WindowMaker/Icons");
1186 for (i
= 0, j
=0; j
< 8; i
++) {
1191 if (strstr(ent
->d_name
, ".xpm")==NULL
) {
1195 label
= makeDraggableLabel(frame
, ent
->d_name
,4+(j
/4)*64, 4+(j
%4)*64);
1202 WMMapSubwidgets(frame
);
1204 WMMapSubwidgets(win
);
1205 WMRealizeWidget(win
);
1213 /*******************************************************************/
1219 WMUserDefaults
*defs
;
1222 defs
= WMGetStandardUserDefaults();
1224 sprintf(str
, "TEST DATA");
1226 WMSetUDStringForKey(defs
, str
, "testKey");
1232 main(int argc
, char **argv
)
1238 /* Initialize the application */
1239 WMInitializeApplication("Test@eqweq_ewq$eqw", &argc
, argv
);
1244 * Open connection to the X display.
1246 dpy
= XOpenDisplay("");
1249 puts("could not open display");
1253 /* This is used to disable buffering of X protocol requests.
1254 * Do NOT use it unless when debugging. It will cause a major
1255 * slowdown in your application
1258 XSynchronize(dpy
, True
);
1261 * Create screen descriptor.
1263 scr
= WMCreateScreen(dpy
, DefaultScreen(dpy
));
1266 * Loads the logo of the application.
1268 pixmap
= WMCreatePixmapFromFile(scr
, "logo.xpm");
1271 * Makes the logo be used in standard dialog panels.
1273 WMSetApplicationIconImage(scr
, pixmap
); WMReleasePixmap(pixmap
);
1276 * Do some test stuff.
1278 * Put the testSomething() function you want to test here.
1283 testDragAndDrop(scr
);
1285 testScrollView(scr
);
1291 testProgressIndicator(scr
);
1297 testDragAndDrop(scr
);
1310 testGradientButtons(scr
);
1313 testOpenFilePanel(scr
);
1319 * The main event loop.
1322 WMScreenMainLoop(scr
);