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 WMLabel
*label
= (WMLabel
*)data
;
198 WMList
*lPtr
= (WMList
*)self
;
201 WMSelectAllListItems(lPtr
);
206 listSelectionObserver(void *observer
, WMNotification
*notification
)
208 WMLabel
*label
= (WMLabel
*)observer
;
209 WMList
*lPtr
= (WMList
*)WMGetNotificationObject(notification
);
212 sprintf(buf
, "Selected items: %d",
213 WMGetArrayItemCount(WMGetListSelectedItems(lPtr
)));
214 WMSetLabelText(label
, buf
);
219 testList(WMScreen
*scr
)
233 win
= WMCreateWindow(scr
, "testList");
234 WMResizeWidget(win
, 370, 250);
235 WMSetWindowTitle(win
, "List");
236 WMSetWindowCloseAction(win
, closeAction
, NULL
);
238 title
= WMCreateLabel(win
);
239 WMResizeWidget(title
, 150, 20);
240 WMMoveWidget(title
, 10, 10);
241 WMSetLabelRelief(title
, WRRidge
);
242 WMSetLabelText(title
, "Single selection list");
244 mtitle
= WMCreateLabel(win
);
245 WMResizeWidget(mtitle
, 150, 20);
246 WMMoveWidget(mtitle
, 210, 10);
247 WMSetLabelRelief(mtitle
, WRRidge
);
248 WMSetLabelText(mtitle
, "Multiple selection list");
250 list
= WMCreateList(win
);
251 /*WMSetListAllowEmptySelection(list, True);*/
252 WMMoveWidget(list
, 10, 40);
253 for (i
=0; i
<50; i
++) {
254 sprintf(text
, "Item %i", i
);
255 WMAddListItem(list
, text
);
257 mlist
= WMCreateList(win
);
258 WMSetListAllowMultipleSelection(mlist
, True
);
259 /*WMSetListAllowEmptySelection(mlist, True);*/
260 WMMoveWidget(mlist
, 210, 40);
261 for (i
=0; i
<135; i
++) {
262 sprintf(text
, "Item %i", i
);
263 WMAddListItem(mlist
, text
);
266 label
= WMCreateLabel(win
);
267 WMResizeWidget(label
, 150, 40);
268 WMMoveWidget(label
, 10, 200);
269 WMSetLabelRelief(label
, WRRidge
);
270 WMSetLabelText(label
, "Selected items: 0");
272 mlabel
= WMCreateLabel(win
);
273 WMResizeWidget(mlabel
, 150, 40);
274 WMMoveWidget(mlabel
, 210, 200);
275 WMSetLabelRelief(mlabel
, WRRidge
);
276 WMSetLabelText(mlabel
, "Selected items: 0");
278 WMSetListAction(list
, singleClick
, label
);
279 WMSetListDoubleAction(list
, doubleClick
, label
);
280 WMSetListAction(mlist
, singleClick
, mlabel
);
281 WMSetListDoubleAction(mlist
, doubleClick
, mlabel
);
283 WMAddNotificationObserver(listSelectionObserver
, label
,
284 WMListSelectionDidChangeNotification
, list
);
285 WMAddNotificationObserver(listSelectionObserver
, mlabel
,
286 WMListSelectionDidChangeNotification
, mlist
);
289 WMRealizeWidget(win
);
290 WMMapSubwidgets(win
);
296 testButton(WMScreen
*scr
)
313 win
= WMCreateWindow(scr
, "testButton");
314 WMResizeWidget(win
, 300, 300);
315 WMSetWindowTitle(win
, "Buttons");
317 WMSetWindowCloseAction(win
, closeAction
, NULL
);
319 for (i
= 1; i
< 9; i
++) {
321 b
= WMCreateButton(win
, i
);
322 WMResizeWidget(b
, 150, 24);
323 WMMoveWidget(b
, 20, i
*30);
324 WMSetButtonText(b
, types
[i
-1]);
327 WMRealizeWidget(win
);
328 WMMapSubwidgets(win
);
334 testGradientButtons(WMScreen
*scr
)
338 WMPixmap
*pix1
, *pix2
;
341 WMColor
*color
, *altColor
;
345 /* creates the top-level window */
346 win
= WMCreateWindow(scr
, "testGradientButtons");
347 WMSetWindowTitle(win
, "Gradiented Button Demo");
348 WMResizeWidget(win
, 300, 200);
357 color
= WMCreateRGBColor(scr
, 0x5900, 0x5100, 0x5900, True
);
358 WMSetWidgetBackgroundColor(win
, color
);
359 WMReleaseColor(color
);
361 back
= RRenderGradient(60, 24, &dark
, &light
, RGRD_DIAGONAL
);
362 RBevelImage(back
, RBEV_RAISED2
);
363 pix1
= WMCreatePixmapFromRImage(scr
, back
, 0);
366 back
= RRenderGradient(60, 24, &dark
, &light
, RGRD_DIAGONAL
);
367 RBevelImage(back
, RBEV_SUNKEN
);
368 pix2
= WMCreatePixmapFromRImage(scr
, back
, 0);
371 color
= WMWhiteColor(scr
);
372 altColor
= WMCreateNamedColor(scr
, "red", True
);
374 btn
= WMCreateButton(win
, WBTMomentaryChange
);
375 WMResizeWidget(btn
, 60, 24);
376 WMMoveWidget(btn
, 20, 100);
377 WMSetButtonBordered(btn
, False
);
378 WMSetButtonImagePosition(btn
, WIPOverlaps
);
379 WMSetButtonImage(btn
, pix1
);
380 WMSetButtonAltImage(btn
, pix2
);
381 WMSetButtonText(btn
, "Cool");
382 WMSetButtonTextColor(btn
, color
);
383 WMSetButtonAltTextColor(btn
, altColor
);
385 WMSetBalloonTextForView("This is a cool button", WMWidgetView(btn
));
387 btn
= WMCreateButton(win
, WBTMomentaryChange
);
388 WMResizeWidget(btn
, 60, 24);
389 WMMoveWidget(btn
, 90, 100);
390 WMSetButtonBordered(btn
, False
);
391 WMSetButtonImagePosition(btn
, WIPOverlaps
);
392 WMSetButtonImage(btn
, pix1
);
393 WMSetButtonAltImage(btn
, pix2
);
394 WMSetButtonText(btn
, "Button");
395 WMSetButtonTextColor(btn
, color
);
397 WMSetBalloonTextForView("Este é outro balão.", WMWidgetView(btn
));
399 WMReleaseColor(color
);
400 color
= WMCreateNamedColor(scr
, "orange", True
);
402 btn
= WMCreateButton(win
, WBTMomentaryChange
);
403 WMResizeWidget(btn
, 60, 24);
404 WMMoveWidget(btn
, 160, 100);
405 WMSetButtonBordered(btn
, False
);
406 WMSetButtonImagePosition(btn
, WIPOverlaps
);
407 WMSetButtonImage(btn
, pix1
);
408 WMSetButtonAltImage(btn
, pix2
);
409 WMSetButtonText(btn
, "Test");
410 WMSetButtonTextColor(btn
, color
);
412 WMSetBalloonTextForView("This is yet another button.\nBut the balloon has 3 lines.\nYay!",
415 WMReleaseColor(color
);
416 WMReleaseColor(altColor
);
418 WMRealizeWidget(win
);
419 WMMapSubwidgets(win
);
425 testScrollView(WMScreen
*scr
)
436 /* creates the top-level window */
437 win
= WMCreateWindow(scr
, "testScroll");
438 WMSetWindowTitle(win
, "Scrollable View");
440 WMSetWindowCloseAction(win
, closeAction
, NULL
);
442 /* set the window size */
443 WMResizeWidget(win
, 300, 300);
445 /* creates a scrollable view inside the top-level window */
446 sview
= WMCreateScrollView(win
);
447 WMResizeWidget(sview
, 200, 200);
448 WMMoveWidget(sview
, 30, 30);
449 WMSetScrollViewRelief(sview
, WRSunken
);
450 WMSetScrollViewHasVerticalScroller(sview
, True
);
451 WMSetScrollViewHasHorizontalScroller(sview
, True
);
453 /* create a frame with a bunch of labels */
454 f
= WMCreateFrame(win
);
455 WMResizeWidget(f
, 400, 400);
456 WMSetFrameRelief(f
, WRFlat
);
458 for (i
=0; i
<20; i
++) {
459 l
= WMCreateLabel(f
);
460 WMResizeWidget(l
, 50, 18);
461 WMMoveWidget(l
, 10, 20*i
);
462 sprintf(buffer
, "Label %i", i
);
463 WMSetLabelText(l
, buffer
);
464 WMSetLabelRelief(l
, WRSimple
);
469 WMSetScrollViewContentView(sview
, WMWidgetView(f
));
471 /* make the windows of the widgets be actually created */
472 WMRealizeWidget(win
);
474 /* Map all child widgets of the top-level be mapped.
475 * You must call this for each container widget (like frames),
476 * even if they are childs of the top-level window.
478 WMMapSubwidgets(win
);
480 /* map the top-level window */
486 testColorWell(WMScreen
*scr
)
489 WMColorWell
*well1
, *well2
;
493 win
= WMCreateWindow(scr
, "testColor");
494 WMResizeWidget(win
, 300, 300);
495 WMSetWindowCloseAction(win
, closeAction
, NULL
);
497 well1
= WMCreateColorWell(win
);
498 WMResizeWidget(well1
, 60, 40);
499 WMMoveWidget(well1
, 100, 100);
500 WMSetColorWellColor(well1
, WMCreateRGBColor(scr
, 0x8888, 0, 0x1111, True
));
501 well2
= WMCreateColorWell(win
);
502 WMResizeWidget(well2
, 60, 40);
503 WMMoveWidget(well2
, 200, 100);
504 WMSetColorWellColor(well2
, WMCreateRGBColor(scr
, 0, 0, 0x8888, True
));
506 WMRealizeWidget(win
);
507 WMMapSubwidgets(win
);
513 testColorPanel(WMScreen
*scr
)
515 WMColorPanel
*panel
= WMGetColorPanel(scr
);
518 startcolor = WMCreateNamedColor(scr, colorname, False);
519 WMSetColorPanelColor(panel, startcolor);
520 WMReleaseColor(startcolor);
523 WMShowColorPanel(panel
);
527 sliderCallback(WMWidget
*w
, void *data
)
529 printf("SLIDER == %i\n", WMGetSliderValue(w
));
534 testSlider(WMScreen
*scr
)
541 win
= WMCreateWindow(scr
, "testSlider");
542 WMResizeWidget(win
, 300, 300);
543 WMSetWindowTitle(win
, "Sliders");
545 WMSetWindowCloseAction(win
, closeAction
, NULL
);
547 s
= WMCreateSlider(win
);
548 WMResizeWidget(s
, 16, 100);
549 WMMoveWidget(s
, 100, 100);
550 WMSetSliderKnobThickness(s
, 8);
551 WMSetSliderContinuous(s
, False
);
552 WMSetSliderAction(s
, sliderCallback
, s
);
554 s
= WMCreateSlider(win
);
555 WMResizeWidget(s
, 100, 16);
556 WMMoveWidget(s
, 100, 10);
557 WMSetSliderKnobThickness(s
, 8);
559 WMRealizeWidget(win
);
560 WMMapSubwidgets(win
);
566 testTextField(WMScreen
*scr
)
569 WMTextField
*field
, *field2
;
573 win
= WMCreateWindow(scr
, "testTextField");
574 WMResizeWidget(win
, 400, 300);
576 WMSetWindowCloseAction(win
, closeAction
, NULL
);
578 field
= WMCreateTextField(win
);
579 WMResizeWidget(field
, 200, 20);
580 WMMoveWidget(field
, 20, 20);
582 field2
= WMCreateTextField(win
);
583 WMResizeWidget(field2
, 200, 20);
584 WMMoveWidget(field2
, 20, 50);
585 WMSetTextFieldAlignment(field2
, WARight
);
587 WMRealizeWidget(win
);
588 WMMapSubwidgets(win
);
595 testText(WMScreen
*scr
)
599 FILE *file
= fopen("wm.html", "r");
603 win
= WMCreateWindow(scr
, "testText");
604 WMResizeWidget(win
, 500, 300);
606 WMSetWindowCloseAction(win
, closeAction
, NULL
);
608 text
= WMCreateText(win
);
609 WMResizeWidget(text
, 480, 280);
610 WMMoveWidget(text
, 10, 10);
611 WMSetTextHasVerticalScroller(text
, True
);
612 WMSetTextEditable(text
, False
);
618 while(fgets(buf
, 1023, file
))
619 WMAppendTextStream(text
, buf
);
624 WMAppendTextStream(text
,
625 "Window Maker is the GNU window manager for the "
626 "X Window System. It was designed to emulate the "
627 "look and feel of part of the NEXTSTEP(tm) GUI. Its "
628 "supposed to be relatively fast and small, feature "
629 "rich, easy to configure and easy to use, with a simple "
630 "and elegant appearance borrowed from NEXTSTEP(tm).");
633 WMRealizeWidget(win
);
634 WMMapSubwidgets(win
);
640 testProgressIndicator(WMScreen
*scr
)
643 WMProgressIndicator
*pPtr
;
647 win
= WMCreateWindow(scr
, "testProgressIndicator");
648 WMResizeWidget(win
, 292, 32);
650 WMSetWindowCloseAction(win
, closeAction
, NULL
);
652 pPtr
= WMCreateProgressIndicator(win
);
653 WMMoveWidget(pPtr
, 8, 8);
654 WMSetProgressIndicatorValue(pPtr
, 75);
656 WMRealizeWidget(win
);
657 WMMapSubwidgets(win
);
664 testPullDown(WMScreen
*scr
)
667 WMPopUpButton
*pop
, *pop2
;
671 win
= WMCreateWindow(scr
, "pullDown");
672 WMResizeWidget(win
, 400, 300);
674 WMSetWindowCloseAction(win
, closeAction
, NULL
);
676 pop
= WMCreatePopUpButton(win
);
677 WMResizeWidget(pop
, 100, 20);
678 WMMoveWidget(pop
, 50, 60);
679 WMSetPopUpButtonPullsDown(pop
, True
);
680 WMSetPopUpButtonText(pop
, "Commands");
681 WMAddPopUpButtonItem(pop
, "Add");
682 WMAddPopUpButtonItem(pop
, "Remove");
683 WMAddPopUpButtonItem(pop
, "Check");
684 WMAddPopUpButtonItem(pop
, "Eat");
686 pop2
= WMCreatePopUpButton(win
);
687 WMResizeWidget(pop2
, 100, 20);
688 WMMoveWidget(pop2
, 200, 60);
689 WMSetPopUpButtonText(pop2
, "Select");
690 WMAddPopUpButtonItem(pop2
, "Apples");
691 WMAddPopUpButtonItem(pop2
, "Bananas");
692 WMAddPopUpButtonItem(pop2
, "Strawberries");
693 WMAddPopUpButtonItem(pop2
, "Blueberries");
695 WMRealizeWidget(win
);
696 WMMapSubwidgets(win
);
703 testTabView(WMScreen
*scr
)
713 win
= WMCreateWindow(scr
, "testTabs");
714 WMResizeWidget(win
, 400, 300);
716 WMSetWindowCloseAction(win
, closeAction
, NULL
);
718 tabv
= WMCreateTabView(win
);
719 WMMoveWidget(tabv
, 50, 50);
720 WMResizeWidget(tabv
, 300, 200);
722 frame
= WMCreateFrame(win
);
723 WMSetFrameRelief(frame
, WRFlat
);
724 label
= WMCreateLabel(frame
);
725 WMResizeWidget(label
, 100, 100);
726 WMSetLabelText(label
, "Label 1");
730 tab
= WMCreateTabViewItemWithIdentifier(0);
731 WMSetTabViewItemView(tab
, WMWidgetView(frame
));
732 WMAddItemInTabView(tabv
, tab
);
733 WMSetTabViewItemLabel(tab
, "Instances");
735 frame
= WMCreateFrame(win
);
736 WMSetFrameRelief(frame
, WRFlat
);
737 label
= WMCreateLabel(frame
);
738 WMResizeWidget(label
, 40, 50);
739 WMSetLabelText(label
, "Label 2");
743 tab
= WMCreateTabViewItemWithIdentifier(0);
744 WMSetTabViewItemView(tab
, WMWidgetView(frame
));
745 WMAddItemInTabView(tabv
, tab
);
746 WMSetTabViewItemLabel(tab
, "Classes");
749 frame
= WMCreateFrame(win
);
750 WMSetFrameRelief(frame
, WRFlat
);
751 label
= WMCreateLabel(frame
);
752 WMResizeWidget(label
, 100, 100);
753 WMMoveWidget(label
, 60, 40);
754 WMSetLabelText(label
, "Label 3");
757 tab
= WMCreateTabViewItemWithIdentifier(0);
758 WMSetTabViewItemView(tab
, WMWidgetView(frame
));
759 WMAddItemInTabView(tabv
, tab
);
760 WMSetTabViewItemLabel(tab
, "Something");
763 frame
= WMCreateFrame(win
);
764 WMSetFrameRelief(frame
, WRFlat
);
765 label
= WMCreateLabel(frame
);
766 WMResizeWidget(label
, 100, 100);
767 WMMoveWidget(label
, 160, 40);
768 WMSetLabelText(label
, "Label 4");
771 tab
= WMCreateTabViewItemWithIdentifier(0);
772 WMSetTabViewItemView(tab
, WMWidgetView(frame
));
773 WMAddItemInTabView(tabv
, tab
);
774 WMSetTabViewItemLabel(tab
, "Bla!");
778 frame
= WMCreateFrame(win
);
779 WMSetFrameRelief(frame
, WRFlat
);
780 label
= WMCreateLabel(frame
);
781 WMResizeWidget(label
, 100, 100);
782 WMMoveWidget(label
, 160, 40);
783 WMSetLabelText(label
, "Label fjweqklrj qwl");
785 tab
= WMCreateTabViewItemWithIdentifier(0);
786 WMSetTabViewItemView(tab
, WMWidgetView(frame
));
787 WMAddItemInTabView(tabv
, tab
);
788 WMSetTabViewItemLabel(tab
, "Weee!");
791 WMRealizeWidget(win
);
792 WMMapSubwidgets(win
);
798 splitViewConstrainProc(WMSplitView
*sPtr
, int indView
,
799 int *minSize
, int *maxSize
)
819 resizeSplitView(XEvent
*event
, void *data
)
821 WMSplitView
*sPtr
= (WMSplitView
*)data
;
823 if (event
->type
== ConfigureNotify
) {
824 int width
= event
->xconfigure
.width
- 10;
826 if (width
< WMGetSplitViewDividerThickness(sPtr
))
827 width
= WMGetSplitViewDividerThickness(sPtr
);
829 if (width
!= WMWidgetWidth(sPtr
) ||
830 event
->xconfigure
.height
!= WMWidgetHeight(sPtr
))
831 WMResizeWidget(sPtr
, width
, event
->xconfigure
.height
- 55);
836 appendSubviewButtonAction(WMWidget
*self
, void *data
)
838 WMSplitView
*sPtr
= (WMSplitView
*)data
;
840 WMLabel
*label
= WMCreateLabel(sPtr
);
842 sprintf(buf
, "Subview %d", WMGetSplitViewSubviewsCount(sPtr
) + 1);
843 WMSetLabelText(label
, buf
);
844 WMSetLabelRelief(label
, WRSunken
);
845 WMAddSplitViewSubview(sPtr
, WMWidgetView(label
));
846 WMRealizeWidget(label
);
851 removeSubviewButtonAction(WMWidget
*self
, void *data
)
853 WMSplitView
*sPtr
= (WMSplitView
*)data
;
854 int count
= WMGetSplitViewSubviewsCount(sPtr
);
857 WMView
*view
= WMGetSplitViewSubviewAt(sPtr
, count
-1);
858 WMDestroyWidget(WMWidgetOfView(view
));
859 WMRemoveSplitViewSubviewAt(sPtr
, count
-1);
864 orientationButtonAction(WMWidget
*self
, void *data
)
866 WMSplitView
*sPtr
= (WMSplitView
*)data
;
867 WMSetSplitViewVertical(sPtr
, !WMGetSplitViewVertical(sPtr
));
871 adjustSubviewsButtonAction(WMWidget
*self
, void *data
)
873 WMAdjustSplitViewSubviews((WMSplitView
*)data
);
877 testSplitView(WMScreen
*scr
)
880 WMSplitView
*splitv1
, *splitv2
;
887 win
= WMCreateWindow(scr
, "testTabs");
888 WMResizeWidget(win
, 300, 400);
889 WMSetWindowCloseAction(win
, closeAction
, NULL
);
891 frame
= WMCreateFrame(win
);
892 WMSetFrameRelief(frame
, WRSunken
);
893 WMMoveWidget(frame
, 5, 5);
894 WMResizeWidget(frame
, 290, 40);
896 splitv1
= WMCreateSplitView(win
);
897 WMMoveWidget(splitv1
, 5, 50);
898 WMResizeWidget(splitv1
, 290, 345);
899 WMSetSplitViewConstrainProc(splitv1
, splitViewConstrainProc
);
900 WMCreateEventHandler(WMWidgetView(win
), StructureNotifyMask
,
901 resizeSplitView
, splitv1
);
903 button
= WMCreateCommandButton(frame
);
904 WMSetButtonText(button
, "+");
905 WMSetButtonAction(button
, appendSubviewButtonAction
, splitv1
);
906 WMMoveWidget(button
, 10, 8);
909 button
= WMCreateCommandButton(frame
);
910 WMSetButtonText(button
, "-");
911 WMSetButtonAction(button
, removeSubviewButtonAction
, splitv1
);
912 WMMoveWidget(button
, 80, 8);
915 button
= WMCreateCommandButton(frame
);
916 WMSetButtonText(button
, "=");
917 WMMoveWidget(button
, 150, 8);
918 WMSetButtonAction(button
, adjustSubviewsButtonAction
, splitv1
);
921 button
= WMCreateCommandButton(frame
);
922 WMSetButtonText(button
, "#");
923 WMMoveWidget(button
, 220, 8);
924 WMSetButtonAction(button
, orientationButtonAction
, splitv1
);
927 label
= WMCreateLabel(splitv1
);
928 WMSetLabelText(label
, "Subview 1");
929 WMSetLabelRelief(label
, WRSunken
);
931 WMAddSplitViewSubview(splitv1
, WMWidgetView(label
));
933 splitv2
= WMCreateSplitView(splitv1
);
934 WMResizeWidget(splitv2
, 150, 150);
935 WMSetSplitViewVertical(splitv2
, True
);
937 label
= WMCreateLabel(splitv2
);
938 WMSetLabelText(label
, "Subview 2.1");
939 WMSetLabelRelief(label
, WRSunken
);
941 WMAddSplitViewSubview(splitv2
, WMWidgetView(label
));
943 label
= WMCreateLabel(splitv2
);
944 WMSetLabelText(label
, "Subview 2.2");
945 WMSetLabelRelief(label
, WRSunken
);
947 WMAddSplitViewSubview(splitv2
, WMWidgetView(label
));
949 label
= WMCreateLabel(splitv2
);
950 WMSetLabelText(label
, "Subview 2.3");
951 WMSetLabelRelief(label
, WRSunken
);
953 WMAddSplitViewSubview(splitv2
, WMWidgetView(label
));
955 WMMapWidget(splitv2
);
956 WMAddSplitViewSubview(splitv1
, WMWidgetView(splitv2
));
958 WMRealizeWidget(win
);
959 WMMapSubwidgets(win
);
964 /*******************************************************************/
966 #include <sys/types.h>
978 getImage(WMScreen
*scr
, char *file
)
983 sprintf(buffer
, "../../WindowMaker/Icons/%s", file
);
984 pix
= WMCreatePixmapFromFile(scr
, buffer
);
993 iconMouseStuff(XEvent
*event
, void *cdata
)
995 WMLabel
*label
= (WMLabel
*)cdata
;
996 DNDStuff
*stuff
= WMGetHangedData(label
);
999 switch (event
->type
) {
1001 stuff
->x
= event
->xbutton
.x
;
1002 stuff
->y
= event
->xbutton
.y
;
1003 stuff
->mouseDown
= True
;
1006 stuff
->mouseDown
= False
;
1009 if (!stuff
->mouseDown
)
1012 if (abs(stuff
->x
- event
->xmotion
.x
)>4
1013 || abs(stuff
->y
- event
->xmotion
.y
)>4) {
1015 where
= WMGetViewScreenPosition(WMWidgetView(label
));
1017 WMDragImageFromView(WMWidgetView(label
),
1018 WMGetLabelImage(label
),
1021 wmksize(stuff
->x
, stuff
->y
),
1030 endedDragImage(WMView
*self
, WMPixmap
*image
, WMPoint point
, Bool deposited
)
1032 DNDStuff
*stuff
= WMGetHangedData(WMWidgetOfView(self
));
1035 WMDestroyWidget(WMWidgetOfView(self
));
1038 stuff
->mouseDown
= False
;
1043 fetchDragData(WMView
*self
, char *type
)
1045 DNDStuff
*stuff
= WMGetHangedData(WMWidgetOfView(self
));
1047 return WMCreateDataWithBytes(stuff
->filename
, strlen(stuff
->filename
)+1);
1051 WMDragSourceProcs dragSourceProcs
= {
1059 /************************/
1063 draggingEntered(WMView
*self
, WMDraggingInfo
*info
)
1065 return WDOperationCopy
;
1070 draggingUpdated(WMView
*self
, WMDraggingInfo
*info
)
1072 return WDOperationCopy
;
1076 void (*draggingExited)(WMView *self, WMDraggingInfo *info);
1079 prepareForDragOperation(WMView
*self
, WMDraggingInfo
*info
)
1081 return "application/X-WINGs-Bla";
1085 WMLabel
* makeDraggableLabel(WMWidget
*w
, char *file
, int x
, int y
);
1088 performDragOperation(WMView
*self
, WMDraggingInfo
*info
, WMData
*data
)
1090 char *file
= (char*)WMDataBytes(data
);
1093 pos
= WMGetDraggingInfoImageLocation(info
);
1097 WMPoint pos2
= WMGetViewScreenPosition(self
);
1100 label
= makeDraggableLabel(WMWidgetOfView(self
), file
,
1101 pos
.x
-pos2
.x
, pos
.y
-pos2
.y
);
1102 WMRealizeWidget(label
);
1112 concludeDragOperation(WMView
*self
, WMDraggingInfo
*info
)
1119 WMDragDestinationProcs dragDestProcs
= {
1123 prepareForDragOperation
,
1124 performDragOperation
,
1125 concludeDragOperation
1132 makeDraggableLabel(WMWidget
*w
, char *file
, int x
, int y
)
1136 WMPixmap
*image
= getImage(WMWidgetScreen(w
), file
);
1138 stuff
= wmalloc(sizeof(DNDStuff
));
1139 stuff
->mouseDown
= False
;
1141 stuff
->filename
= wstrdup(file
);
1143 label
= WMCreateLabel(w
);
1144 WMResizeWidget(label
, 48, 48);
1145 WMMoveWidget(label
, x
, y
);
1147 WMSetViewDragSourceProcs(WMWidgetView(label
), &dragSourceProcs
);
1149 WMHangData(label
, stuff
);
1151 WMCreateEventHandler(WMWidgetView(label
),
1152 ButtonPressMask
|ButtonReleaseMask
|ButtonMotionMask
,
1153 iconMouseStuff
, label
);
1156 if (image
!= NULL
) {
1157 WMSetLabelImagePosition(label
, WIPImageOnly
);
1158 WMSetLabelImage(label
, image
);
1159 WMReleasePixmap(image
);
1168 testDragAndDrop(WMScreen
*scr
)
1177 "application/X-WINGs-Bla",
1183 win
= WMCreateWindow(scr
, "dragDrop");
1184 WMResizeWidget(win
, 300, 300);
1185 WMSetWindowCloseAction(win
, closeAction
, NULL
);
1186 WMSetWindowTitle(win
, "Drag and Drop");
1189 frame
= WMCreateFrame(win
);
1190 WMSetFrameRelief(frame
, WRSunken
);
1191 WMResizeWidget(frame
, 250, 250);
1192 WMMoveWidget(frame
, 25, 25);
1194 WMRegisterViewForDraggedTypes(WMWidgetView(frame
), types
);
1195 WMSetViewDragDestinationProcs(WMWidgetView(frame
), &dragDestProcs
);
1197 dir
= opendir("../../WindowMaker/Icons");
1199 perror("../../WindowMaker/Icons");
1203 for (i
= 0, j
=0; j
< 8; i
++) {
1208 if (strstr(ent
->d_name
, ".xpm")==NULL
) {
1212 label
= makeDraggableLabel(frame
, ent
->d_name
,4+(j
/4)*64, 4+(j
%4)*64);
1219 WMMapSubwidgets(frame
);
1221 WMMapSubwidgets(win
);
1222 WMRealizeWidget(win
);
1230 /*******************************************************************/
1236 WMUserDefaults
*defs
;
1239 defs
= WMGetStandardUserDefaults();
1241 sprintf(str
, "TEST DATA");
1243 WMSetUDStringForKey(defs
, str
, "testKey");
1249 main(int argc
, char **argv
)
1255 /* Initialize the application */
1256 WMInitializeApplication("Test@eqweq_ewq$eqw", &argc
, argv
);
1261 * Open connection to the X display.
1263 dpy
= XOpenDisplay("");
1266 puts("could not open display");
1270 /* This is used to disable buffering of X protocol requests.
1271 * Do NOT use it unless when debugging. It will cause a major
1272 * slowdown in your application
1275 XSynchronize(dpy
, True
);
1278 * Create screen descriptor.
1280 scr
= WMCreateScreen(dpy
, DefaultScreen(dpy
));
1283 * Loads the logo of the application.
1285 pixmap
= WMCreatePixmapFromFile(scr
, "logo.xpm");
1288 * Makes the logo be used in standard dialog panels.
1290 WMSetApplicationIconImage(scr
, pixmap
); WMReleasePixmap(pixmap
);
1293 * Do some test stuff.
1295 * Put the testSomething() function you want to test here.
1300 testDragAndDrop(scr
);
1302 testColorPanel(scr
);
1303 testScrollView(scr
);
1309 testProgressIndicator(scr
);
1315 testDragAndDrop(scr
);
1328 testGradientButtons(scr
);
1331 testOpenFilePanel(scr
);
1337 * The main event loop.
1340 WMScreenMainLoop(scr
);