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
);
119 resizedWindow(void *self
, WMNotification
*notif
)
121 WMView
*view
= (WMView
*)WMGetNotificationObject(notif
);
122 WMSize size
= WMGetViewSize(view
);
124 WMResizeWidget((WMWidget
*)self
, size
.width
, size
.height
);
128 testBox(WMScreen
*scr
)
138 win
= WMCreateWindow(scr
, "testBox");
139 WMSetWindowTitle(win
, "Box");
140 WMSetWindowCloseAction(win
, closeAction
, NULL
);
142 WMSetViewNotifySizeChanges(WMWidgetView(win
), True
);
144 box
= WMCreateBox(win
);
145 WMSetBoxBorderWidth(box
, 5);
147 WMAddNotificationObserver(resizedWindow
, box
,
148 WMViewSizeDidChangeNotification
,
150 WMResizeWidget(win
, 400, 300);
153 /* WMSetBoxHorizontal(box, True); */
154 for (i
= 0; i
< 4; i
++) {
155 btn
= WMCreateCommandButton(box
);
156 WMSetButtonText(btn
, "bla");
158 WMAddBoxSubview(box
, WMWidgetView(btn
), i
&1, True
, 20, 0, 5);
161 pop
= WMCreatePopUpButton(box
);
162 WMAddPopUpButtonItem(pop
, "ewqeq");
163 WMAddPopUpButtonItem(pop
, "ewqeqrewrw");
164 WMAddBoxSubview(box
, WMWidgetView(pop
), False
, True
, 20, 0, 5);
167 hbox
= WMCreateBox(box
);
168 WMSetBoxHorizontal(hbox
, True
);
169 WMAddBoxSubview(box
, WMWidgetView(hbox
), False
, True
, 24, 0, 0);
172 for (i
= 0; i
< 4; i
++) {
173 btn
= WMCreateCommandButton(hbox
);
174 WMSetButtonText(btn
, "bla");
176 WMAddBoxSubview(hbox
, WMWidgetView(btn
), 1, True
, 60, 0, i
<3?5:0);
180 WMRealizeWidget(win
);
181 WMMapSubwidgets(win
);
189 singleClick(WMWidget
*self
, void *data
)
195 doubleClick(WMWidget
*self
, void *data
)
197 WMSelectAllListItems((WMList
*)self
);
202 listSelectionObserver(void *observer
, WMNotification
*notification
)
204 WMLabel
*label
= (WMLabel
*)observer
;
205 WMList
*lPtr
= (WMList
*)WMGetNotificationObject(notification
);
208 sprintf(buf
, "Selected items: %d",
209 WMGetArrayItemCount(WMGetListSelectedItems(lPtr
)));
210 WMSetLabelText(label
, buf
);
215 testList(WMScreen
*scr
)
229 win
= WMCreateWindow(scr
, "testList");
230 WMResizeWidget(win
, 370, 250);
231 WMSetWindowTitle(win
, "List");
232 WMSetWindowCloseAction(win
, closeAction
, NULL
);
234 title
= WMCreateLabel(win
);
235 WMResizeWidget(title
, 150, 20);
236 WMMoveWidget(title
, 10, 10);
237 WMSetLabelRelief(title
, WRRidge
);
238 WMSetLabelText(title
, "Single selection list");
240 mtitle
= WMCreateLabel(win
);
241 WMResizeWidget(mtitle
, 150, 20);
242 WMMoveWidget(mtitle
, 210, 10);
243 WMSetLabelRelief(mtitle
, WRRidge
);
244 WMSetLabelText(mtitle
, "Multiple selection list");
246 list
= WMCreateList(win
);
247 /*WMSetListAllowEmptySelection(list, True);*/
248 WMMoveWidget(list
, 10, 40);
249 for (i
=0; i
<50; i
++) {
250 sprintf(text
, "Item %i", i
);
251 WMAddListItem(list
, text
);
253 mlist
= WMCreateList(win
);
254 WMSetListAllowMultipleSelection(mlist
, True
);
255 /*WMSetListAllowEmptySelection(mlist, True);*/
256 WMMoveWidget(mlist
, 210, 40);
257 for (i
=0; i
<135; i
++) {
258 sprintf(text
, "Item %i", i
);
259 WMAddListItem(mlist
, text
);
262 label
= WMCreateLabel(win
);
263 WMResizeWidget(label
, 150, 40);
264 WMMoveWidget(label
, 10, 200);
265 WMSetLabelRelief(label
, WRRidge
);
266 WMSetLabelText(label
, "Selected items: 0");
268 mlabel
= WMCreateLabel(win
);
269 WMResizeWidget(mlabel
, 150, 40);
270 WMMoveWidget(mlabel
, 210, 200);
271 WMSetLabelRelief(mlabel
, WRRidge
);
272 WMSetLabelText(mlabel
, "Selected items: 0");
274 WMSetListAction(list
, singleClick
, label
);
275 WMSetListDoubleAction(list
, doubleClick
, label
);
276 WMSetListAction(mlist
, singleClick
, mlabel
);
277 WMSetListDoubleAction(mlist
, doubleClick
, mlabel
);
279 WMAddNotificationObserver(listSelectionObserver
, label
,
280 WMListSelectionDidChangeNotification
, list
);
281 WMAddNotificationObserver(listSelectionObserver
, mlabel
,
282 WMListSelectionDidChangeNotification
, mlist
);
285 WMRealizeWidget(win
);
286 WMMapSubwidgets(win
);
292 testButton(WMScreen
*scr
)
309 win
= WMCreateWindow(scr
, "testButton");
310 WMResizeWidget(win
, 300, 300);
311 WMSetWindowTitle(win
, "Buttons");
313 WMSetWindowCloseAction(win
, closeAction
, NULL
);
315 for (i
= 1; i
< 9; i
++) {
317 b
= WMCreateButton(win
, i
);
318 WMResizeWidget(b
, 150, 24);
319 WMMoveWidget(b
, 20, i
*30);
320 WMSetButtonText(b
, types
[i
-1]);
323 WMRealizeWidget(win
);
324 WMMapSubwidgets(win
);
330 testGradientButtons(WMScreen
*scr
)
334 WMPixmap
*pix1
, *pix2
;
337 WMColor
*color
, *altColor
;
341 /* creates the top-level window */
342 win
= WMCreateWindow(scr
, "testGradientButtons");
343 WMSetWindowTitle(win
, "Gradiented Button Demo");
344 WMResizeWidget(win
, 300, 200);
353 color
= WMCreateRGBColor(scr
, 0x5900, 0x5100, 0x5900, True
);
354 WMSetWidgetBackgroundColor(win
, color
);
355 WMReleaseColor(color
);
357 back
= RRenderGradient(60, 24, &dark
, &light
, RGRD_DIAGONAL
);
358 RBevelImage(back
, RBEV_RAISED2
);
359 pix1
= WMCreatePixmapFromRImage(scr
, back
, 0);
362 back
= RRenderGradient(60, 24, &dark
, &light
, RGRD_DIAGONAL
);
363 RBevelImage(back
, RBEV_SUNKEN
);
364 pix2
= WMCreatePixmapFromRImage(scr
, back
, 0);
367 color
= WMWhiteColor(scr
);
368 altColor
= WMCreateNamedColor(scr
, "red", True
);
370 btn
= WMCreateButton(win
, WBTMomentaryChange
);
371 WMResizeWidget(btn
, 60, 24);
372 WMMoveWidget(btn
, 20, 100);
373 WMSetButtonBordered(btn
, False
);
374 WMSetButtonImagePosition(btn
, WIPOverlaps
);
375 WMSetButtonImage(btn
, pix1
);
376 WMSetButtonAltImage(btn
, pix2
);
377 WMSetButtonText(btn
, "Cool");
378 WMSetButtonTextColor(btn
, color
);
379 WMSetButtonAltTextColor(btn
, altColor
);
381 WMSetBalloonTextForView("This is a cool button", WMWidgetView(btn
));
383 btn
= WMCreateButton(win
, WBTMomentaryChange
);
384 WMResizeWidget(btn
, 60, 24);
385 WMMoveWidget(btn
, 90, 100);
386 WMSetButtonBordered(btn
, False
);
387 WMSetButtonImagePosition(btn
, WIPOverlaps
);
388 WMSetButtonImage(btn
, pix1
);
389 WMSetButtonAltImage(btn
, pix2
);
390 WMSetButtonText(btn
, "Button");
391 WMSetButtonTextColor(btn
, color
);
393 WMSetBalloonTextForView("Este é outro balão.", WMWidgetView(btn
));
395 WMReleaseColor(color
);
396 color
= WMCreateNamedColor(scr
, "orange", True
);
398 btn
= WMCreateButton(win
, WBTMomentaryChange
);
399 WMResizeWidget(btn
, 60, 24);
400 WMMoveWidget(btn
, 160, 100);
401 WMSetButtonBordered(btn
, False
);
402 WMSetButtonImagePosition(btn
, WIPOverlaps
);
403 WMSetButtonImage(btn
, pix1
);
404 WMSetButtonAltImage(btn
, pix2
);
405 WMSetButtonText(btn
, "Test");
406 WMSetButtonTextColor(btn
, color
);
408 WMSetBalloonTextForView("This is yet another button.\nBut the balloon has 3 lines.\nYay!",
411 WMReleaseColor(color
);
412 WMReleaseColor(altColor
);
414 WMRealizeWidget(win
);
415 WMMapSubwidgets(win
);
421 testScrollView(WMScreen
*scr
)
432 /* creates the top-level window */
433 win
= WMCreateWindow(scr
, "testScroll");
434 WMSetWindowTitle(win
, "Scrollable View");
436 WMSetWindowCloseAction(win
, closeAction
, NULL
);
438 /* set the window size */
439 WMResizeWidget(win
, 300, 300);
441 /* creates a scrollable view inside the top-level window */
442 sview
= WMCreateScrollView(win
);
443 WMResizeWidget(sview
, 200, 200);
444 WMMoveWidget(sview
, 30, 30);
445 WMSetScrollViewRelief(sview
, WRSunken
);
446 WMSetScrollViewHasVerticalScroller(sview
, True
);
447 WMSetScrollViewHasHorizontalScroller(sview
, True
);
449 /* create a frame with a bunch of labels */
450 f
= WMCreateFrame(win
);
451 WMResizeWidget(f
, 400, 400);
452 WMSetFrameRelief(f
, WRFlat
);
454 for (i
=0; i
<20; i
++) {
455 l
= WMCreateLabel(f
);
456 WMResizeWidget(l
, 50, 18);
457 WMMoveWidget(l
, 10, 20*i
);
458 sprintf(buffer
, "Label %i", i
);
459 WMSetLabelText(l
, buffer
);
460 WMSetLabelRelief(l
, WRSimple
);
465 WMSetScrollViewContentView(sview
, WMWidgetView(f
));
467 /* make the windows of the widgets be actually created */
468 WMRealizeWidget(win
);
470 /* Map all child widgets of the top-level be mapped.
471 * You must call this for each container widget (like frames),
472 * even if they are childs of the top-level window.
474 WMMapSubwidgets(win
);
476 /* map the top-level window */
482 testColorWell(WMScreen
*scr
)
485 WMColorWell
*well1
, *well2
;
489 win
= WMCreateWindow(scr
, "testColor");
490 WMResizeWidget(win
, 300, 300);
491 WMSetWindowCloseAction(win
, closeAction
, NULL
);
493 well1
= WMCreateColorWell(win
);
494 WMResizeWidget(well1
, 60, 40);
495 WMMoveWidget(well1
, 100, 100);
496 WMSetColorWellColor(well1
, WMCreateRGBColor(scr
, 0x8888, 0, 0x1111, True
));
497 well2
= WMCreateColorWell(win
);
498 WMResizeWidget(well2
, 60, 40);
499 WMMoveWidget(well2
, 200, 100);
500 WMSetColorWellColor(well2
, WMCreateRGBColor(scr
, 0, 0, 0x8888, True
));
502 WMRealizeWidget(win
);
503 WMMapSubwidgets(win
);
509 testColorPanel(WMScreen
*scr
)
511 WMColorPanel
*panel
= WMGetColorPanel(scr
);
514 startcolor = WMCreateNamedColor(scr, colorname, False);
515 WMSetColorPanelColor(panel, startcolor);
516 WMReleaseColor(startcolor);
519 WMShowColorPanel(panel
);
523 sliderCallback(WMWidget
*w
, void *data
)
525 printf("SLIDER == %i\n", WMGetSliderValue(w
));
530 testSlider(WMScreen
*scr
)
537 win
= WMCreateWindow(scr
, "testSlider");
538 WMResizeWidget(win
, 300, 300);
539 WMSetWindowTitle(win
, "Sliders");
541 WMSetWindowCloseAction(win
, closeAction
, NULL
);
543 s
= WMCreateSlider(win
);
544 WMResizeWidget(s
, 16, 100);
545 WMMoveWidget(s
, 100, 100);
546 WMSetSliderKnobThickness(s
, 8);
547 WMSetSliderContinuous(s
, False
);
548 WMSetSliderAction(s
, sliderCallback
, s
);
550 s
= WMCreateSlider(win
);
551 WMResizeWidget(s
, 100, 16);
552 WMMoveWidget(s
, 100, 10);
553 WMSetSliderKnobThickness(s
, 8);
555 WMRealizeWidget(win
);
556 WMMapSubwidgets(win
);
562 testTextField(WMScreen
*scr
)
565 WMTextField
*field
, *field2
;
569 win
= WMCreateWindow(scr
, "testTextField");
570 WMResizeWidget(win
, 400, 300);
572 WMSetWindowCloseAction(win
, closeAction
, NULL
);
574 field
= WMCreateTextField(win
);
575 WMResizeWidget(field
, 200, 20);
576 WMMoveWidget(field
, 20, 20);
578 field2
= WMCreateTextField(win
);
579 WMResizeWidget(field2
, 200, 20);
580 WMMoveWidget(field2
, 20, 50);
581 WMSetTextFieldAlignment(field2
, WARight
);
583 WMRealizeWidget(win
);
584 WMMapSubwidgets(win
);
591 testText(WMScreen
*scr
)
595 FILE *file
= fopen("wm.html", "r");
599 win
= WMCreateWindow(scr
, "testText");
600 WMResizeWidget(win
, 500, 300);
602 WMSetWindowCloseAction(win
, closeAction
, NULL
);
604 text
= WMCreateText(win
);
605 WMResizeWidget(text
, 480, 280);
606 WMMoveWidget(text
, 10, 10);
607 WMSetTextHasVerticalScroller(text
, True
);
608 WMSetTextEditable(text
, False
);
614 while(fgets(buf
, 1023, file
))
615 WMAppendTextStream(text
, buf
);
620 WMAppendTextStream(text
,
621 "Window Maker is the GNU window manager for the "
622 "X Window System. It was designed to emulate the "
623 "look and feel of part of the NEXTSTEP(tm) GUI. Its "
624 "supposed to be relatively fast and small, feature "
625 "rich, easy to configure and easy to use, with a simple "
626 "and elegant appearance borrowed from NEXTSTEP(tm).");
629 WMRealizeWidget(win
);
630 WMMapSubwidgets(win
);
636 testProgressIndicator(WMScreen
*scr
)
639 WMProgressIndicator
*pPtr
;
643 win
= WMCreateWindow(scr
, "testProgressIndicator");
644 WMResizeWidget(win
, 292, 32);
646 WMSetWindowCloseAction(win
, closeAction
, NULL
);
648 pPtr
= WMCreateProgressIndicator(win
);
649 WMMoveWidget(pPtr
, 8, 8);
650 WMSetProgressIndicatorValue(pPtr
, 75);
652 WMRealizeWidget(win
);
653 WMMapSubwidgets(win
);
660 testPullDown(WMScreen
*scr
)
663 WMPopUpButton
*pop
, *pop2
;
667 win
= WMCreateWindow(scr
, "pullDown");
668 WMResizeWidget(win
, 400, 300);
670 WMSetWindowCloseAction(win
, closeAction
, NULL
);
672 pop
= WMCreatePopUpButton(win
);
673 WMResizeWidget(pop
, 100, 20);
674 WMMoveWidget(pop
, 50, 60);
675 WMSetPopUpButtonPullsDown(pop
, True
);
676 WMSetPopUpButtonText(pop
, "Commands");
677 WMAddPopUpButtonItem(pop
, "Add");
678 WMAddPopUpButtonItem(pop
, "Remove");
679 WMAddPopUpButtonItem(pop
, "Check");
680 WMAddPopUpButtonItem(pop
, "Eat");
682 pop2
= WMCreatePopUpButton(win
);
683 WMResizeWidget(pop2
, 100, 20);
684 WMMoveWidget(pop2
, 200, 60);
685 WMSetPopUpButtonText(pop2
, "Select");
686 WMAddPopUpButtonItem(pop2
, "Apples");
687 WMAddPopUpButtonItem(pop2
, "Bananas");
688 WMAddPopUpButtonItem(pop2
, "Strawberries");
689 WMAddPopUpButtonItem(pop2
, "Blueberries");
691 WMRealizeWidget(win
);
692 WMMapSubwidgets(win
);
699 testTabView(WMScreen
*scr
)
709 win
= WMCreateWindow(scr
, "testTabs");
710 WMResizeWidget(win
, 400, 300);
712 WMSetWindowCloseAction(win
, closeAction
, NULL
);
714 tabv
= WMCreateTabView(win
);
715 WMMoveWidget(tabv
, 50, 50);
716 WMResizeWidget(tabv
, 300, 200);
718 frame
= WMCreateFrame(win
);
719 WMSetFrameRelief(frame
, WRFlat
);
720 label
= WMCreateLabel(frame
);
721 WMResizeWidget(label
, 100, 100);
722 WMSetLabelText(label
, "Label 1");
726 tab
= WMCreateTabViewItemWithIdentifier(0);
727 WMSetTabViewItemView(tab
, WMWidgetView(frame
));
728 WMAddItemInTabView(tabv
, tab
);
729 WMSetTabViewItemLabel(tab
, "Instances");
731 frame
= WMCreateFrame(win
);
732 WMSetFrameRelief(frame
, WRFlat
);
733 label
= WMCreateLabel(frame
);
734 WMResizeWidget(label
, 40, 50);
735 WMSetLabelText(label
, "Label 2");
739 tab
= WMCreateTabViewItemWithIdentifier(0);
740 WMSetTabViewItemView(tab
, WMWidgetView(frame
));
741 WMAddItemInTabView(tabv
, tab
);
742 WMSetTabViewItemLabel(tab
, "Classes");
745 frame
= WMCreateFrame(win
);
746 WMSetFrameRelief(frame
, WRFlat
);
747 label
= WMCreateLabel(frame
);
748 WMResizeWidget(label
, 100, 100);
749 WMMoveWidget(label
, 60, 40);
750 WMSetLabelText(label
, "Label 3");
753 tab
= WMCreateTabViewItemWithIdentifier(0);
754 WMSetTabViewItemView(tab
, WMWidgetView(frame
));
755 WMAddItemInTabView(tabv
, tab
);
756 WMSetTabViewItemLabel(tab
, "Something");
759 frame
= WMCreateFrame(win
);
760 WMSetFrameRelief(frame
, WRFlat
);
761 label
= WMCreateLabel(frame
);
762 WMResizeWidget(label
, 100, 100);
763 WMMoveWidget(label
, 160, 40);
764 WMSetLabelText(label
, "Label 4");
767 tab
= WMCreateTabViewItemWithIdentifier(0);
768 WMSetTabViewItemView(tab
, WMWidgetView(frame
));
769 WMAddItemInTabView(tabv
, tab
);
770 WMSetTabViewItemLabel(tab
, "Bla!");
774 frame
= WMCreateFrame(win
);
775 WMSetFrameRelief(frame
, WRFlat
);
776 label
= WMCreateLabel(frame
);
777 WMResizeWidget(label
, 100, 100);
778 WMMoveWidget(label
, 160, 40);
779 WMSetLabelText(label
, "Label fjweqklrj qwl");
781 tab
= WMCreateTabViewItemWithIdentifier(0);
782 WMSetTabViewItemView(tab
, WMWidgetView(frame
));
783 WMAddItemInTabView(tabv
, tab
);
784 WMSetTabViewItemLabel(tab
, "Weee!");
787 WMRealizeWidget(win
);
788 WMMapSubwidgets(win
);
794 splitViewConstrainProc(WMSplitView
*sPtr
, int indView
,
795 int *minSize
, int *maxSize
)
815 resizeSplitView(XEvent
*event
, void *data
)
817 WMSplitView
*sPtr
= (WMSplitView
*)data
;
819 if (event
->type
== ConfigureNotify
) {
820 int width
= event
->xconfigure
.width
- 10;
822 if (width
< WMGetSplitViewDividerThickness(sPtr
))
823 width
= WMGetSplitViewDividerThickness(sPtr
);
825 if (width
!= WMWidgetWidth(sPtr
) ||
826 event
->xconfigure
.height
!= WMWidgetHeight(sPtr
))
827 WMResizeWidget(sPtr
, width
, event
->xconfigure
.height
- 55);
832 appendSubviewButtonAction(WMWidget
*self
, void *data
)
834 WMSplitView
*sPtr
= (WMSplitView
*)data
;
836 WMLabel
*label
= WMCreateLabel(sPtr
);
838 sprintf(buf
, "Subview %d", WMGetSplitViewSubviewsCount(sPtr
) + 1);
839 WMSetLabelText(label
, buf
);
840 WMSetLabelRelief(label
, WRSunken
);
841 WMAddSplitViewSubview(sPtr
, WMWidgetView(label
));
842 WMRealizeWidget(label
);
847 removeSubviewButtonAction(WMWidget
*self
, void *data
)
849 WMSplitView
*sPtr
= (WMSplitView
*)data
;
850 int count
= WMGetSplitViewSubviewsCount(sPtr
);
853 WMView
*view
= WMGetSplitViewSubviewAt(sPtr
, count
-1);
854 WMDestroyWidget(WMWidgetOfView(view
));
855 WMRemoveSplitViewSubviewAt(sPtr
, count
-1);
860 orientationButtonAction(WMWidget
*self
, void *data
)
862 WMSplitView
*sPtr
= (WMSplitView
*)data
;
863 WMSetSplitViewVertical(sPtr
, !WMGetSplitViewVertical(sPtr
));
867 adjustSubviewsButtonAction(WMWidget
*self
, void *data
)
869 WMAdjustSplitViewSubviews((WMSplitView
*)data
);
873 testSplitView(WMScreen
*scr
)
876 WMSplitView
*splitv1
, *splitv2
;
883 win
= WMCreateWindow(scr
, "testTabs");
884 WMResizeWidget(win
, 300, 400);
885 WMSetWindowCloseAction(win
, closeAction
, NULL
);
887 frame
= WMCreateFrame(win
);
888 WMSetFrameRelief(frame
, WRSunken
);
889 WMMoveWidget(frame
, 5, 5);
890 WMResizeWidget(frame
, 290, 40);
892 splitv1
= WMCreateSplitView(win
);
893 WMMoveWidget(splitv1
, 5, 50);
894 WMResizeWidget(splitv1
, 290, 345);
895 WMSetSplitViewConstrainProc(splitv1
, splitViewConstrainProc
);
896 WMCreateEventHandler(WMWidgetView(win
), StructureNotifyMask
,
897 resizeSplitView
, splitv1
);
899 button
= WMCreateCommandButton(frame
);
900 WMSetButtonText(button
, "+");
901 WMSetButtonAction(button
, appendSubviewButtonAction
, splitv1
);
902 WMMoveWidget(button
, 10, 8);
905 button
= WMCreateCommandButton(frame
);
906 WMSetButtonText(button
, "-");
907 WMSetButtonAction(button
, removeSubviewButtonAction
, splitv1
);
908 WMMoveWidget(button
, 80, 8);
911 button
= WMCreateCommandButton(frame
);
912 WMSetButtonText(button
, "=");
913 WMMoveWidget(button
, 150, 8);
914 WMSetButtonAction(button
, adjustSubviewsButtonAction
, splitv1
);
917 button
= WMCreateCommandButton(frame
);
918 WMSetButtonText(button
, "#");
919 WMMoveWidget(button
, 220, 8);
920 WMSetButtonAction(button
, orientationButtonAction
, splitv1
);
923 label
= WMCreateLabel(splitv1
);
924 WMSetLabelText(label
, "Subview 1");
925 WMSetLabelRelief(label
, WRSunken
);
927 WMAddSplitViewSubview(splitv1
, WMWidgetView(label
));
929 splitv2
= WMCreateSplitView(splitv1
);
930 WMResizeWidget(splitv2
, 150, 150);
931 WMSetSplitViewVertical(splitv2
, True
);
933 label
= WMCreateLabel(splitv2
);
934 WMSetLabelText(label
, "Subview 2.1");
935 WMSetLabelRelief(label
, WRSunken
);
937 WMAddSplitViewSubview(splitv2
, WMWidgetView(label
));
939 label
= WMCreateLabel(splitv2
);
940 WMSetLabelText(label
, "Subview 2.2");
941 WMSetLabelRelief(label
, WRSunken
);
943 WMAddSplitViewSubview(splitv2
, WMWidgetView(label
));
945 label
= WMCreateLabel(splitv2
);
946 WMSetLabelText(label
, "Subview 2.3");
947 WMSetLabelRelief(label
, WRSunken
);
949 WMAddSplitViewSubview(splitv2
, WMWidgetView(label
));
951 WMMapWidget(splitv2
);
952 WMAddSplitViewSubview(splitv1
, WMWidgetView(splitv2
));
954 WMRealizeWidget(win
);
955 WMMapSubwidgets(win
);
960 /*******************************************************************/
962 #include <sys/types.h>
974 getImage(WMScreen
*scr
, char *file
)
979 sprintf(buffer
, "../../WindowMaker/Icons/%s", file
);
980 pix
= WMCreatePixmapFromFile(scr
, buffer
);
989 iconMouseStuff(XEvent
*event
, void *cdata
)
991 WMLabel
*label
= (WMLabel
*)cdata
;
992 DNDStuff
*stuff
= WMGetHangedData(label
);
995 switch (event
->type
) {
997 stuff
->x
= event
->xbutton
.x
;
998 stuff
->y
= event
->xbutton
.y
;
999 stuff
->mouseDown
= True
;
1002 stuff
->mouseDown
= False
;
1005 if (!stuff
->mouseDown
)
1008 if (abs(stuff
->x
- event
->xmotion
.x
)>4
1009 || abs(stuff
->y
- event
->xmotion
.y
)>4) {
1011 where
= WMGetViewScreenPosition(WMWidgetView(label
));
1013 WMDragImageFromView(WMWidgetView(label
),
1014 WMGetLabelImage(label
),
1017 wmksize(stuff
->x
, stuff
->y
),
1026 endedDragImage(WMView
*self
, WMPixmap
*image
, WMPoint point
, Bool deposited
)
1028 DNDStuff
*stuff
= WMGetHangedData(WMWidgetOfView(self
));
1031 WMDestroyWidget(WMWidgetOfView(self
));
1034 stuff
->mouseDown
= False
;
1039 fetchDragData(WMView
*self
, char *type
)
1041 DNDStuff
*stuff
= WMGetHangedData(WMWidgetOfView(self
));
1043 return WMCreateDataWithBytes(stuff
->filename
, strlen(stuff
->filename
)+1);
1047 WMDragSourceProcs dragSourceProcs
= {
1055 /************************/
1059 draggingEntered(WMView
*self
, WMDraggingInfo
*info
)
1061 return WDOperationCopy
;
1066 draggingUpdated(WMView
*self
, WMDraggingInfo
*info
)
1068 return WDOperationCopy
;
1072 void (*draggingExited)(WMView *self, WMDraggingInfo *info);
1075 prepareForDragOperation(WMView
*self
, WMDraggingInfo
*info
)
1077 return "application/X-WINGs-Bla";
1081 WMLabel
* makeDraggableLabel(WMWidget
*w
, char *file
, int x
, int y
);
1084 performDragOperation(WMView
*self
, WMDraggingInfo
*info
, WMData
*data
)
1086 char *file
= (char*)WMDataBytes(data
);
1089 pos
= WMGetDraggingInfoImageLocation(info
);
1093 WMPoint pos2
= WMGetViewScreenPosition(self
);
1096 label
= makeDraggableLabel(WMWidgetOfView(self
), file
,
1097 pos
.x
-pos2
.x
, pos
.y
-pos2
.y
);
1098 WMRealizeWidget(label
);
1108 concludeDragOperation(WMView
*self
, WMDraggingInfo
*info
)
1115 WMDragDestinationProcs dragDestProcs
= {
1119 prepareForDragOperation
,
1120 performDragOperation
,
1121 concludeDragOperation
1128 makeDraggableLabel(WMWidget
*w
, char *file
, int x
, int y
)
1132 WMPixmap
*image
= getImage(WMWidgetScreen(w
), file
);
1134 stuff
= wmalloc(sizeof(DNDStuff
));
1135 stuff
->mouseDown
= False
;
1137 stuff
->filename
= wstrdup(file
);
1139 label
= WMCreateLabel(w
);
1140 WMResizeWidget(label
, 48, 48);
1141 WMMoveWidget(label
, x
, y
);
1143 WMSetViewDragSourceProcs(WMWidgetView(label
), &dragSourceProcs
);
1145 WMHangData(label
, stuff
);
1147 WMCreateEventHandler(WMWidgetView(label
),
1148 ButtonPressMask
|ButtonReleaseMask
|ButtonMotionMask
,
1149 iconMouseStuff
, label
);
1152 if (image
!= NULL
) {
1153 WMSetLabelImagePosition(label
, WIPImageOnly
);
1154 WMSetLabelImage(label
, image
);
1155 WMReleasePixmap(image
);
1164 testDragAndDrop(WMScreen
*scr
)
1173 "application/X-WINGs-Bla",
1179 win
= WMCreateWindow(scr
, "dragDrop");
1180 WMResizeWidget(win
, 300, 300);
1181 WMSetWindowCloseAction(win
, closeAction
, NULL
);
1182 WMSetWindowTitle(win
, "Drag and Drop");
1185 frame
= WMCreateFrame(win
);
1186 WMSetFrameRelief(frame
, WRSunken
);
1187 WMResizeWidget(frame
, 250, 250);
1188 WMMoveWidget(frame
, 25, 25);
1190 WMRegisterViewForDraggedTypes(WMWidgetView(frame
), types
);
1191 WMSetViewDragDestinationProcs(WMWidgetView(frame
), &dragDestProcs
);
1193 dir
= opendir("../../WindowMaker/Icons");
1195 perror("../../WindowMaker/Icons");
1199 for (i
= 0, j
=0; j
< 8; i
++) {
1204 if (strstr(ent
->d_name
, ".xpm")==NULL
) {
1208 label
= makeDraggableLabel(frame
, ent
->d_name
,4+(j
/4)*64, 4+(j
%4)*64);
1215 WMMapSubwidgets(frame
);
1217 WMMapSubwidgets(win
);
1218 WMRealizeWidget(win
);
1226 /*******************************************************************/
1232 WMUserDefaults
*defs
;
1235 defs
= WMGetStandardUserDefaults();
1237 sprintf(str
, "TEST DATA");
1239 WMSetUDStringForKey(defs
, str
, "testKey");
1245 main(int argc
, char **argv
)
1251 /* Initialize the application */
1252 WMInitializeApplication("Test@eqweq_ewq$eqw", &argc
, argv
);
1257 * Open connection to the X display.
1259 dpy
= XOpenDisplay("");
1262 puts("could not open display");
1266 /* This is used to disable buffering of X protocol requests.
1267 * Do NOT use it unless when debugging. It will cause a major
1268 * slowdown in your application
1271 XSynchronize(dpy
, True
);
1274 * Create screen descriptor.
1276 scr
= WMCreateScreen(dpy
, DefaultScreen(dpy
));
1279 * Loads the logo of the application.
1281 pixmap
= WMCreatePixmapFromFile(scr
, "logo.xpm");
1284 * Makes the logo be used in standard dialog panels.
1286 WMSetApplicationIconPixmap(scr
, pixmap
); WMReleasePixmap(pixmap
);
1289 * Do some test stuff.
1291 * Put the testSomething() function you want to test here.
1296 testDragAndDrop(scr
);
1299 testColorPanel(scr
);
1300 testScrollView(scr
);
1306 testProgressIndicator(scr
);
1312 testDragAndDrop(scr
);
1325 testGradientButtons(scr
);
1328 testOpenFilePanel(scr
);
1334 * The main event loop.
1337 WMScreenMainLoop(scr
);