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
);
141 WMResizeWidget(win
, 400, 300);
143 box
= WMCreateBox(win
);
144 WMSetBoxBorderWidth(box
, 5);
145 WMSetViewExpandsToParent(WMWidgetView(box
), 0, 0, 0, 0);
147 /*WMSetBoxHorizontal(box, True);*/
148 for (i
= 0; i
< 4; i
++) {
149 btn
= WMCreateCommandButton(box
);
150 WMSetButtonText(btn
, "bla");
152 WMAddBoxSubview(box
, WMWidgetView(btn
), i
&1, True
, 20, 0, 5);
155 pop
= WMCreatePopUpButton(box
);
156 WMAddPopUpButtonItem(pop
, "ewqeq");
157 WMAddPopUpButtonItem(pop
, "ewqeqrewrw");
158 WMAddBoxSubview(box
, WMWidgetView(pop
), False
, True
, 20, 0, 5);
161 hbox
= WMCreateBox(box
);
162 WMSetBoxHorizontal(hbox
, True
);
163 WMAddBoxSubview(box
, WMWidgetView(hbox
), False
, True
, 24, 0, 0);
166 for (i
= 0; i
< 4; i
++) {
167 btn
= WMCreateCommandButton(hbox
);
168 WMSetButtonText(btn
, "bla");
170 WMAddBoxSubview(hbox
, WMWidgetView(btn
), 1, True
, 60, 0, i
<3?5:0);
174 WMRealizeWidget(win
);
175 WMMapSubwidgets(win
);
183 singleClick(WMWidget
*self
, void *data
)
189 doubleClick(WMWidget
*self
, void *data
)
191 WMSelectAllListItems((WMList
*)self
);
196 listSelectionObserver(void *observer
, WMNotification
*notification
)
198 WMLabel
*label
= (WMLabel
*)observer
;
199 WMList
*lPtr
= (WMList
*)WMGetNotificationObject(notification
);
202 sprintf(buf
, "Selected items: %d",
203 WMGetArrayItemCount(WMGetListSelectedItems(lPtr
)));
204 WMSetLabelText(label
, buf
);
209 testList(WMScreen
*scr
)
223 win
= WMCreateWindow(scr
, "testList");
224 WMResizeWidget(win
, 370, 250);
225 WMSetWindowTitle(win
, "List");
226 WMSetWindowCloseAction(win
, closeAction
, NULL
);
228 title
= WMCreateLabel(win
);
229 WMResizeWidget(title
, 150, 20);
230 WMMoveWidget(title
, 10, 10);
231 WMSetLabelRelief(title
, WRRidge
);
232 WMSetLabelText(title
, "Single selection list");
234 mtitle
= WMCreateLabel(win
);
235 WMResizeWidget(mtitle
, 150, 20);
236 WMMoveWidget(mtitle
, 210, 10);
237 WMSetLabelRelief(mtitle
, WRRidge
);
238 WMSetLabelText(mtitle
, "Multiple selection list");
240 list
= WMCreateList(win
);
241 /*WMSetListAllowEmptySelection(list, True);*/
242 WMMoveWidget(list
, 10, 40);
243 for (i
=0; i
<105; i
++) {
244 sprintf(text
, "Item %i", i
);
245 WMAddListItem(list
, text
);
247 mlist
= WMCreateList(win
);
248 WMSetListAllowMultipleSelection(mlist
, True
);
249 /*WMSetListAllowEmptySelection(mlist, True);*/
250 WMMoveWidget(mlist
, 210, 40);
251 for (i
=0; i
<135; i
++) {
252 sprintf(text
, "Item %i", i
);
253 WMAddListItem(mlist
, text
);
256 label
= WMCreateLabel(win
);
257 WMResizeWidget(label
, 150, 40);
258 WMMoveWidget(label
, 10, 200);
259 WMSetLabelRelief(label
, WRRidge
);
260 WMSetLabelText(label
, "Selected items: 0");
262 mlabel
= WMCreateLabel(win
);
263 WMResizeWidget(mlabel
, 150, 40);
264 WMMoveWidget(mlabel
, 210, 200);
265 WMSetLabelRelief(mlabel
, WRRidge
);
266 WMSetLabelText(mlabel
, "Selected items: 0");
268 WMSetListAction(list
, singleClick
, label
);
269 WMSetListDoubleAction(list
, doubleClick
, label
);
270 WMSetListAction(mlist
, singleClick
, mlabel
);
271 WMSetListDoubleAction(mlist
, doubleClick
, mlabel
);
273 WMAddNotificationObserver(listSelectionObserver
, label
,
274 WMListSelectionDidChangeNotification
, list
);
275 WMAddNotificationObserver(listSelectionObserver
, mlabel
,
276 WMListSelectionDidChangeNotification
, mlist
);
279 WMRealizeWidget(win
);
280 WMMapSubwidgets(win
);
286 testButton(WMScreen
*scr
)
303 win
= WMCreateWindow(scr
, "testButton");
304 WMResizeWidget(win
, 300, 300);
305 WMSetWindowTitle(win
, "Buttons");
307 WMSetWindowCloseAction(win
, closeAction
, NULL
);
309 for (i
= 1; i
< 9; i
++) {
311 b
= WMCreateButton(win
, i
);
312 WMResizeWidget(b
, 150, 24);
313 WMMoveWidget(b
, 20, i
*30);
314 WMSetButtonText(b
, types
[i
-1]);
317 WMRealizeWidget(win
);
318 WMMapSubwidgets(win
);
324 testGradientButtons(WMScreen
*scr
)
328 WMPixmap
*pix1
, *pix2
;
331 WMColor
*color
, *altColor
;
335 /* creates the top-level window */
336 win
= WMCreateWindow(scr
, "testGradientButtons");
337 WMSetWindowTitle(win
, "Gradiented Button Demo");
338 WMResizeWidget(win
, 300, 200);
340 WMSetWindowCloseAction(win
, closeAction
, NULL
);
350 color
= WMCreateRGBColor(scr
, 0x5900, 0x5100, 0x5900, True
);
351 WMSetWidgetBackgroundColor(win
, color
);
352 WMReleaseColor(color
);
354 back
= RRenderGradient(60, 24, &dark
, &light
, RGRD_DIAGONAL
);
355 RBevelImage(back
, RBEV_RAISED2
);
356 pix1
= WMCreatePixmapFromRImage(scr
, back
, 0);
359 back
= RRenderGradient(60, 24, &dark
, &light
, RGRD_DIAGONAL
);
360 RBevelImage(back
, RBEV_SUNKEN
);
361 pix2
= WMCreatePixmapFromRImage(scr
, back
, 0);
364 color
= WMWhiteColor(scr
);
365 altColor
= WMCreateNamedColor(scr
, "red", True
);
367 btn
= WMCreateButton(win
, WBTMomentaryChange
);
368 WMResizeWidget(btn
, 60, 24);
369 WMMoveWidget(btn
, 20, 100);
370 WMSetButtonBordered(btn
, False
);
371 WMSetButtonImagePosition(btn
, WIPOverlaps
);
372 WMSetButtonImage(btn
, pix1
);
373 WMSetButtonAltImage(btn
, pix2
);
374 WMSetButtonText(btn
, "Cool");
375 WMSetButtonTextColor(btn
, color
);
376 WMSetButtonAltTextColor(btn
, altColor
);
378 WMSetBalloonTextForView("This is a cool button", WMWidgetView(btn
));
380 btn
= WMCreateButton(win
, WBTMomentaryChange
);
381 WMResizeWidget(btn
, 60, 24);
382 WMMoveWidget(btn
, 90, 100);
383 WMSetButtonBordered(btn
, False
);
384 WMSetButtonImagePosition(btn
, WIPOverlaps
);
385 WMSetButtonImage(btn
, pix1
);
386 WMSetButtonAltImage(btn
, pix2
);
387 WMSetButtonText(btn
, "Button");
388 WMSetButtonTextColor(btn
, color
);
390 WMSetBalloonTextForView("Este é outro balão.", WMWidgetView(btn
));
392 WMReleaseColor(color
);
393 color
= WMCreateNamedColor(scr
, "orange", True
);
395 btn
= WMCreateButton(win
, WBTMomentaryChange
);
396 WMResizeWidget(btn
, 60, 24);
397 WMMoveWidget(btn
, 160, 100);
398 WMSetButtonBordered(btn
, False
);
399 WMSetButtonImagePosition(btn
, WIPOverlaps
);
400 WMSetButtonImage(btn
, pix1
);
401 WMSetButtonAltImage(btn
, pix2
);
402 WMSetButtonText(btn
, "Test");
403 WMSetButtonTextColor(btn
, color
);
405 WMSetBalloonTextForView("This is yet another button.\nBut the balloon has 3 lines.\nYay!",
408 WMReleaseColor(color
);
409 WMReleaseColor(altColor
);
411 WMRealizeWidget(win
);
412 WMMapSubwidgets(win
);
418 testScrollView(WMScreen
*scr
)
429 /* creates the top-level window */
430 win
= WMCreateWindow(scr
, "testScroll");
431 WMSetWindowTitle(win
, "Scrollable View");
433 WMSetWindowCloseAction(win
, closeAction
, NULL
);
435 /* set the window size */
436 WMResizeWidget(win
, 300, 300);
438 /* creates a scrollable view inside the top-level window */
439 sview
= WMCreateScrollView(win
);
440 WMResizeWidget(sview
, 200, 200);
441 WMMoveWidget(sview
, 30, 30);
442 WMSetScrollViewRelief(sview
, WRSunken
);
443 WMSetScrollViewHasVerticalScroller(sview
, True
);
444 WMSetScrollViewHasHorizontalScroller(sview
, True
);
446 /* create a frame with a bunch of labels */
447 f
= WMCreateFrame(win
);
448 WMResizeWidget(f
, 400, 400);
449 WMSetFrameRelief(f
, WRFlat
);
451 for (i
=0; i
<20; i
++) {
452 l
= WMCreateLabel(f
);
453 WMResizeWidget(l
, 50, 18);
454 WMMoveWidget(l
, 10, 20*i
);
455 sprintf(buffer
, "Label %i", i
);
456 WMSetLabelText(l
, buffer
);
457 WMSetLabelRelief(l
, WRSimple
);
462 WMSetScrollViewContentView(sview
, WMWidgetView(f
));
464 /* make the windows of the widgets be actually created */
465 WMRealizeWidget(win
);
467 /* Map all child widgets of the top-level be mapped.
468 * You must call this for each container widget (like frames),
469 * even if they are childs of the top-level window.
471 WMMapSubwidgets(win
);
473 /* map the top-level window */
479 testColorWell(WMScreen
*scr
)
482 WMColorWell
*well1
, *well2
;
486 win
= WMCreateWindow(scr
, "testColor");
487 WMResizeWidget(win
, 300, 300);
488 WMSetWindowCloseAction(win
, closeAction
, NULL
);
490 well1
= WMCreateColorWell(win
);
491 WMResizeWidget(well1
, 60, 40);
492 WMMoveWidget(well1
, 100, 100);
493 WMSetColorWellColor(well1
, WMCreateRGBColor(scr
, 0x8888, 0, 0x1111, True
));
494 well2
= WMCreateColorWell(win
);
495 WMResizeWidget(well2
, 60, 40);
496 WMMoveWidget(well2
, 200, 100);
497 WMSetColorWellColor(well2
, WMCreateRGBColor(scr
, 0, 0, 0x8888, True
));
499 WMRealizeWidget(win
);
500 WMMapSubwidgets(win
);
506 testColorPanel(WMScreen
*scr
)
508 WMColorPanel
*panel
= WMGetColorPanel(scr
);
511 startcolor = WMCreateNamedColor(scr, colorname, False);
512 WMSetColorPanelColor(panel, startcolor);
513 WMReleaseColor(startcolor);
516 WMShowColorPanel(panel
);
520 sliderCallback(WMWidget
*w
, void *data
)
522 printf("SLIDER == %i\n", WMGetSliderValue(w
));
527 testSlider(WMScreen
*scr
)
534 win
= WMCreateWindow(scr
, "testSlider");
535 WMResizeWidget(win
, 300, 300);
536 WMSetWindowTitle(win
, "Sliders");
538 WMSetWindowCloseAction(win
, closeAction
, NULL
);
540 s
= WMCreateSlider(win
);
541 WMResizeWidget(s
, 16, 100);
542 WMMoveWidget(s
, 100, 100);
543 WMSetSliderKnobThickness(s
, 8);
544 WMSetSliderContinuous(s
, False
);
545 WMSetSliderAction(s
, sliderCallback
, s
);
547 s
= WMCreateSlider(win
);
548 WMResizeWidget(s
, 100, 16);
549 WMMoveWidget(s
, 100, 10);
550 WMSetSliderKnobThickness(s
, 8);
552 WMRealizeWidget(win
);
553 WMMapSubwidgets(win
);
559 testTextField(WMScreen
*scr
)
562 WMTextField
*field
, *field2
;
566 win
= WMCreateWindow(scr
, "testTextField");
567 WMResizeWidget(win
, 400, 300);
569 WMSetWindowCloseAction(win
, closeAction
, NULL
);
571 field
= WMCreateTextField(win
);
572 WMResizeWidget(field
, 200, 20);
573 WMMoveWidget(field
, 20, 20);
575 field2
= WMCreateTextField(win
);
576 WMResizeWidget(field2
, 200, 20);
577 WMMoveWidget(field2
, 20, 50);
578 WMSetTextFieldAlignment(field2
, WARight
);
580 WMRealizeWidget(win
);
581 WMMapSubwidgets(win
);
588 testText(WMScreen
*scr
)
592 FILE *file
= fopen("wm.html", "rb");
596 win
= WMCreateWindow(scr
, "testText");
597 WMResizeWidget(win
, 500, 300);
599 WMSetWindowCloseAction(win
, closeAction
, NULL
);
601 text
= WMCreateText(win
);
602 WMResizeWidget(text
, 480, 280);
603 WMMoveWidget(text
, 10, 10);
604 WMSetTextHasVerticalScroller(text
, True
);
605 WMSetTextEditable(text
, False
);
608 WMFont
*font
, *ifont
;
610 font
= WMDefaultSystemFont(scr
);
611 ifont
= WMCopyFontWithChanges(scr
, font
, WFAEmphasized
);
613 WMSetTextDefaultFont(text
, ifont
);
614 WMReleaseFont(ifont
);
616 WMSetTextDefaultFont(text
, font
);
625 while(fgets(buf
, 1023, file
))
626 WMAppendTextStream(text
, buf
);
631 WMAppendTextStream(text
,
632 "Window Maker is the GNU window manager for the "
633 "X Window System. It was designed to emulate the "
634 "look and feel of part of the NEXTSTEP(tm) GUI. Its "
635 "supposed to be relatively fast and small, feature "
636 "rich, easy to configure and easy to use, with a simple "
637 "and elegant appearance borrowed from NEXTSTEP(tm).");
640 WMRealizeWidget(win
);
641 WMMapSubwidgets(win
);
647 testProgressIndicator(WMScreen
*scr
)
650 WMProgressIndicator
*pPtr
;
654 win
= WMCreateWindow(scr
, "testProgressIndicator");
655 WMResizeWidget(win
, 292, 32);
657 WMSetWindowCloseAction(win
, closeAction
, NULL
);
659 pPtr
= WMCreateProgressIndicator(win
);
660 WMMoveWidget(pPtr
, 8, 8);
661 WMSetProgressIndicatorValue(pPtr
, 75);
663 WMRealizeWidget(win
);
664 WMMapSubwidgets(win
);
671 testPullDown(WMScreen
*scr
)
674 WMPopUpButton
*pop
, *pop2
;
678 win
= WMCreateWindow(scr
, "pullDown");
679 WMResizeWidget(win
, 400, 300);
681 WMSetWindowCloseAction(win
, closeAction
, NULL
);
683 pop
= WMCreatePopUpButton(win
);
684 WMResizeWidget(pop
, 100, 20);
685 WMMoveWidget(pop
, 50, 60);
686 WMSetPopUpButtonPullsDown(pop
, True
);
687 WMSetPopUpButtonText(pop
, "Commands");
688 WMAddPopUpButtonItem(pop
, "Add");
689 WMAddPopUpButtonItem(pop
, "Remove");
690 WMAddPopUpButtonItem(pop
, "Check");
691 WMAddPopUpButtonItem(pop
, "Eat");
693 pop2
= WMCreatePopUpButton(win
);
694 WMResizeWidget(pop2
, 100, 20);
695 WMMoveWidget(pop2
, 200, 60);
696 WMSetPopUpButtonText(pop2
, "Select");
697 WMAddPopUpButtonItem(pop2
, "Apples");
698 WMAddPopUpButtonItem(pop2
, "Bananas");
699 WMAddPopUpButtonItem(pop2
, "Strawberries");
700 WMAddPopUpButtonItem(pop2
, "Blueberries");
702 WMRealizeWidget(win
);
703 WMMapSubwidgets(win
);
710 testTabView(WMScreen
*scr
)
720 win
= WMCreateWindow(scr
, "testTabs");
721 WMResizeWidget(win
, 400, 300);
723 WMSetWindowCloseAction(win
, closeAction
, NULL
);
725 tabv
= WMCreateTabView(win
);
726 WMMoveWidget(tabv
, 50, 50);
727 WMResizeWidget(tabv
, 300, 200);
729 frame
= WMCreateFrame(win
);
730 WMSetFrameRelief(frame
, WRFlat
);
731 label
= WMCreateLabel(frame
);
732 WMResizeWidget(label
, 100, 100);
733 WMSetLabelText(label
, "Label 1");
737 tab
= WMCreateTabViewItemWithIdentifier(0);
738 WMSetTabViewItemView(tab
, WMWidgetView(frame
));
739 WMAddItemInTabView(tabv
, tab
);
740 WMSetTabViewItemLabel(tab
, "Instances");
742 frame
= WMCreateFrame(win
);
743 WMSetFrameRelief(frame
, WRFlat
);
744 label
= WMCreateLabel(frame
);
745 WMResizeWidget(label
, 40, 50);
746 WMSetLabelText(label
, "Label 2");
750 tab
= WMCreateTabViewItemWithIdentifier(0);
751 WMSetTabViewItemView(tab
, WMWidgetView(frame
));
752 WMAddItemInTabView(tabv
, tab
);
753 WMSetTabViewItemLabel(tab
, "Classes");
756 frame
= WMCreateFrame(win
);
757 WMSetFrameRelief(frame
, WRFlat
);
758 label
= WMCreateLabel(frame
);
759 WMResizeWidget(label
, 100, 100);
760 WMMoveWidget(label
, 60, 40);
761 WMSetLabelText(label
, "Label 3");
764 tab
= WMCreateTabViewItemWithIdentifier(0);
765 WMSetTabViewItemView(tab
, WMWidgetView(frame
));
766 WMAddItemInTabView(tabv
, tab
);
767 WMSetTabViewItemLabel(tab
, "Something");
770 frame
= WMCreateFrame(win
);
771 WMSetFrameRelief(frame
, WRFlat
);
772 label
= WMCreateLabel(frame
);
773 WMResizeWidget(label
, 100, 100);
774 WMMoveWidget(label
, 160, 40);
775 WMSetLabelText(label
, "Label 4");
778 tab
= WMCreateTabViewItemWithIdentifier(0);
779 WMSetTabViewItemView(tab
, WMWidgetView(frame
));
780 WMAddItemInTabView(tabv
, tab
);
781 WMSetTabViewItemLabel(tab
, "Bla!");
785 frame
= WMCreateFrame(win
);
786 WMSetFrameRelief(frame
, WRFlat
);
787 label
= WMCreateLabel(frame
);
788 WMResizeWidget(label
, 100, 100);
789 WMMoveWidget(label
, 160, 40);
790 WMSetLabelText(label
, "Label fjweqklrj qwl");
792 tab
= WMCreateTabViewItemWithIdentifier(0);
793 WMSetTabViewItemView(tab
, WMWidgetView(frame
));
794 WMAddItemInTabView(tabv
, tab
);
795 WMSetTabViewItemLabel(tab
, "Weee!");
798 WMRealizeWidget(win
);
799 WMMapSubwidgets(win
);
805 splitViewConstrainProc(WMSplitView
*sPtr
, int indView
,
806 int *minSize
, int *maxSize
)
826 resizeSplitView(XEvent
*event
, void *data
)
828 WMSplitView
*sPtr
= (WMSplitView
*)data
;
830 if (event
->type
== ConfigureNotify
) {
831 int width
= event
->xconfigure
.width
- 10;
833 if (width
< WMGetSplitViewDividerThickness(sPtr
))
834 width
= WMGetSplitViewDividerThickness(sPtr
);
836 if (width
!= WMWidgetWidth(sPtr
) ||
837 event
->xconfigure
.height
!= WMWidgetHeight(sPtr
))
838 WMResizeWidget(sPtr
, width
, event
->xconfigure
.height
- 55);
843 appendSubviewButtonAction(WMWidget
*self
, void *data
)
845 WMSplitView
*sPtr
= (WMSplitView
*)data
;
847 WMLabel
*label
= WMCreateLabel(sPtr
);
849 sprintf(buf
, "Subview %d", WMGetSplitViewSubviewsCount(sPtr
) + 1);
850 WMSetLabelText(label
, buf
);
851 WMSetLabelRelief(label
, WRSunken
);
852 WMAddSplitViewSubview(sPtr
, WMWidgetView(label
));
853 WMRealizeWidget(label
);
858 removeSubviewButtonAction(WMWidget
*self
, void *data
)
860 WMSplitView
*sPtr
= (WMSplitView
*)data
;
861 int count
= WMGetSplitViewSubviewsCount(sPtr
);
864 WMView
*view
= WMGetSplitViewSubviewAt(sPtr
, count
-1);
865 WMDestroyWidget(WMWidgetOfView(view
));
866 WMRemoveSplitViewSubviewAt(sPtr
, count
-1);
871 orientationButtonAction(WMWidget
*self
, void *data
)
873 WMSplitView
*sPtr
= (WMSplitView
*)data
;
874 WMSetSplitViewVertical(sPtr
, !WMGetSplitViewVertical(sPtr
));
878 adjustSubviewsButtonAction(WMWidget
*self
, void *data
)
880 WMAdjustSplitViewSubviews((WMSplitView
*)data
);
884 testSplitView(WMScreen
*scr
)
887 WMSplitView
*splitv1
, *splitv2
;
894 win
= WMCreateWindow(scr
, "testTabs");
895 WMResizeWidget(win
, 300, 400);
896 WMSetWindowCloseAction(win
, closeAction
, NULL
);
898 frame
= WMCreateFrame(win
);
899 WMSetFrameRelief(frame
, WRSunken
);
900 WMMoveWidget(frame
, 5, 5);
901 WMResizeWidget(frame
, 290, 40);
903 splitv1
= WMCreateSplitView(win
);
904 WMMoveWidget(splitv1
, 5, 50);
905 WMResizeWidget(splitv1
, 290, 345);
906 WMSetSplitViewConstrainProc(splitv1
, splitViewConstrainProc
);
907 WMCreateEventHandler(WMWidgetView(win
), StructureNotifyMask
,
908 resizeSplitView
, splitv1
);
910 button
= WMCreateCommandButton(frame
);
911 WMSetButtonText(button
, "+");
912 WMSetButtonAction(button
, appendSubviewButtonAction
, splitv1
);
913 WMMoveWidget(button
, 10, 8);
916 button
= WMCreateCommandButton(frame
);
917 WMSetButtonText(button
, "-");
918 WMSetButtonAction(button
, removeSubviewButtonAction
, splitv1
);
919 WMMoveWidget(button
, 80, 8);
922 button
= WMCreateCommandButton(frame
);
923 WMSetButtonText(button
, "=");
924 WMMoveWidget(button
, 150, 8);
925 WMSetButtonAction(button
, adjustSubviewsButtonAction
, splitv1
);
928 button
= WMCreateCommandButton(frame
);
929 WMSetButtonText(button
, "#");
930 WMMoveWidget(button
, 220, 8);
931 WMSetButtonAction(button
, orientationButtonAction
, splitv1
);
934 label
= WMCreateLabel(splitv1
);
935 WMSetLabelText(label
, "Subview 1");
936 WMSetLabelRelief(label
, WRSunken
);
938 WMAddSplitViewSubview(splitv1
, WMWidgetView(label
));
940 splitv2
= WMCreateSplitView(splitv1
);
941 WMResizeWidget(splitv2
, 150, 150);
942 WMSetSplitViewVertical(splitv2
, True
);
944 label
= WMCreateLabel(splitv2
);
945 WMSetLabelText(label
, "Subview 2.1");
946 WMSetLabelRelief(label
, WRSunken
);
948 WMAddSplitViewSubview(splitv2
, WMWidgetView(label
));
950 label
= WMCreateLabel(splitv2
);
951 WMSetLabelText(label
, "Subview 2.2");
952 WMSetLabelRelief(label
, WRSunken
);
954 WMAddSplitViewSubview(splitv2
, WMWidgetView(label
));
956 label
= WMCreateLabel(splitv2
);
957 WMSetLabelText(label
, "Subview 2.3");
958 WMSetLabelRelief(label
, WRSunken
);
960 WMAddSplitViewSubview(splitv2
, WMWidgetView(label
));
962 WMMapWidget(splitv2
);
963 WMAddSplitViewSubview(splitv1
, WMWidgetView(splitv2
));
965 WMRealizeWidget(win
);
966 WMMapSubwidgets(win
);
971 /*******************************************************************/
973 #include <sys/types.h>
985 getImage(WMScreen
*scr
, char *file
)
990 sprintf(buffer
, "../../WindowMaker/Icons/%s", file
);
991 pix
= WMCreatePixmapFromFile(scr
, buffer
);
1000 iconMouseStuff(XEvent
*event
, void *cdata
)
1002 WMLabel
*label
= (WMLabel
*)cdata
;
1003 DNDStuff
*stuff
= WMGetHangedData(label
);
1006 switch (event
->type
) {
1008 stuff
->x
= event
->xbutton
.x
;
1009 stuff
->y
= event
->xbutton
.y
;
1010 stuff
->mouseDown
= True
;
1013 stuff
->mouseDown
= False
;
1016 if (!stuff
->mouseDown
)
1019 if (abs(stuff
->x
- event
->xmotion
.x
)>4
1020 || abs(stuff
->y
- event
->xmotion
.y
)>4) {
1022 where
= WMGetViewScreenPosition(WMWidgetView(label
));
1024 WMDragImageFromView(WMWidgetView(label
),
1025 WMGetLabelImage(label
),
1028 wmksize(stuff
->x
, stuff
->y
),
1037 endedDragImage(WMView
*self
, WMPixmap
*image
, WMPoint point
, Bool deposited
)
1039 DNDStuff
*stuff
= WMGetHangedData(WMWidgetOfView(self
));
1042 WMDestroyWidget(WMWidgetOfView(self
));
1045 stuff
->mouseDown
= False
;
1050 fetchDragData(WMView
*self
, char *type
)
1052 DNDStuff
*stuff
= WMGetHangedData(WMWidgetOfView(self
));
1054 return WMCreateDataWithBytes(stuff
->filename
, strlen(stuff
->filename
)+1);
1058 WMDragSourceProcs dragSourceProcs
= {
1066 /************************/
1070 draggingEntered(WMView
*self
, WMDraggingInfo
*info
)
1072 return WDOperationCopy
;
1077 draggingUpdated(WMView
*self
, WMDraggingInfo
*info
)
1079 return WDOperationCopy
;
1083 void (*draggingExited)(WMView *self, WMDraggingInfo *info);
1086 prepareForDragOperation(WMView
*self
, WMDraggingInfo
*info
)
1088 return "application/X-WINGs-Bla";
1092 WMLabel
* makeDraggableLabel(WMWidget
*w
, char *file
, int x
, int y
);
1095 performDragOperation(WMView
*self
, WMDraggingInfo
*info
, WMData
*data
)
1097 char *file
= (char*)WMDataBytes(data
);
1100 pos
= WMGetDraggingInfoImageLocation(info
);
1104 WMPoint pos2
= WMGetViewScreenPosition(self
);
1107 label
= makeDraggableLabel(WMWidgetOfView(self
), file
,
1108 pos
.x
-pos2
.x
, pos
.y
-pos2
.y
);
1109 WMRealizeWidget(label
);
1119 concludeDragOperation(WMView
*self
, WMDraggingInfo
*info
)
1126 WMDragDestinationProcs dragDestProcs
= {
1130 prepareForDragOperation
,
1131 performDragOperation
,
1132 concludeDragOperation
1139 makeDraggableLabel(WMWidget
*w
, char *file
, int x
, int y
)
1143 WMPixmap
*image
= getImage(WMWidgetScreen(w
), file
);
1145 stuff
= wmalloc(sizeof(DNDStuff
));
1146 stuff
->mouseDown
= False
;
1148 stuff
->filename
= wstrdup(file
);
1150 label
= WMCreateLabel(w
);
1151 WMResizeWidget(label
, 48, 48);
1152 WMMoveWidget(label
, x
, y
);
1154 WMSetViewDragSourceProcs(WMWidgetView(label
), &dragSourceProcs
);
1156 WMHangData(label
, stuff
);
1158 WMCreateEventHandler(WMWidgetView(label
),
1159 ButtonPressMask
|ButtonReleaseMask
|ButtonMotionMask
,
1160 iconMouseStuff
, label
);
1163 if (image
!= NULL
) {
1164 WMSetLabelImagePosition(label
, WIPImageOnly
);
1165 WMSetLabelImage(label
, image
);
1166 WMReleasePixmap(image
);
1175 testDragAndDrop(WMScreen
*scr
)
1184 "application/X-WINGs-Bla",
1190 win
= WMCreateWindow(scr
, "dragDrop");
1191 WMResizeWidget(win
, 300, 300);
1192 WMSetWindowCloseAction(win
, closeAction
, NULL
);
1193 WMSetWindowTitle(win
, "Drag and Drop");
1196 frame
= WMCreateFrame(win
);
1197 WMSetFrameRelief(frame
, WRSunken
);
1198 WMResizeWidget(frame
, 250, 250);
1199 WMMoveWidget(frame
, 25, 25);
1201 WMRegisterViewForDraggedTypes(WMWidgetView(frame
), types
);
1202 WMSetViewDragDestinationProcs(WMWidgetView(frame
), &dragDestProcs
);
1204 dir
= opendir("../../WindowMaker/Icons");
1206 perror("../../WindowMaker/Icons");
1210 for (i
= 0, j
=0; j
< 8; i
++) {
1215 if (strstr(ent
->d_name
, ".xpm")==NULL
) {
1219 label
= makeDraggableLabel(frame
, ent
->d_name
,4+(j
/4)*64, 4+(j
%4)*64);
1226 WMMapSubwidgets(frame
);
1228 WMMapSubwidgets(win
);
1229 WMRealizeWidget(win
);
1237 /*******************************************************************/
1243 WMUserDefaults
*defs
;
1246 defs
= WMGetStandardUserDefaults();
1248 sprintf(str
, "TEST DATA");
1250 WMSetUDStringForKey(defs
, str
, "testKey");
1256 main(int argc
, char **argv
)
1262 /* Initialize the application */
1263 WMInitializeApplication("Test@eqweq_ewq$eqw", &argc
, argv
);
1268 * Open connection to the X display.
1270 dpy
= XOpenDisplay("");
1273 puts("could not open display");
1277 /* This is used to disable buffering of X protocol requests.
1278 * Do NOT use it unless when debugging. It will cause a major
1279 * slowdown in your application
1282 XSynchronize(dpy
, True
);
1285 * Create screen descriptor.
1287 scr
= WMCreateScreen(dpy
, DefaultScreen(dpy
));
1290 * Loads the logo of the application.
1292 pixmap
= WMCreatePixmapFromFile(scr
, "logo.xpm");
1295 * Makes the logo be used in standard dialog panels.
1297 WMSetApplicationIconPixmap(scr
, pixmap
); WMReleasePixmap(pixmap
);
1300 * Do some test stuff.
1302 * Put the testSomething() function you want to test here.
1314 testColorPanel(scr
);
1316 testDragAndDrop(scr
);
1318 testGradientButtons(scr
);
1320 testOpenFilePanel(scr
);
1321 testProgressIndicator(scr
);
1323 testScrollView(scr
);
1329 * The main event loop.
1332 WMScreenMainLoop(scr
);