- fixed speckles (white dots) on dithered images (bug still present on the
[wmaker-crm.git] / WINGs / Tests / wtest.c
blob07839c3de45c20c2c66b92278b964e95ec9a1ee8
1 /*
2 * WINGs test application
3 */
5 #include <WINGs/WINGs.h>
7 #include <stdio.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
14 * on a fatal error.
16 void
17 wAbort()
19 exit(1);
25 Display *dpy;
27 int windowCount = 0;
29 void
30 closeAction(WMWidget *self, void *data)
32 WMDestroyWidget(self);
33 windowCount--;
34 printf("window closed, window count = %d\n", windowCount);
35 if (windowCount < 1)
36 exit(0);
40 void
41 testOpenFilePanel(WMScreen *scr)
43 WMOpenPanel *panel;
45 /* windowCount++; */
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));
57 void
58 testFontPanel(WMScreen *scr)
60 WMFontPanel *panel;
62 /*windowCount++;*/
64 panel = WMGetFontPanel(scr);
66 WMShowFontPanel(panel);
68 /* WMFreeFontPanel(panel);*/
73 void
74 testFrame(WMScreen *scr)
76 WMWindow *win;
77 WMFrame *frame;
78 int i;
79 static char* titles[] = {
80 "AboveTop",
81 "AtTop",
82 "BelowTop",
83 "AboveBottom",
84 "AtBottom",
85 "BelowBottom"
87 static WMTitlePosition pos[] = {
88 WTPAboveTop,
89 WTPAtTop,
90 WTPBelowTop,
91 WTPAboveBottom,
92 WTPAtBottom,
93 WTPBelowBottom
96 windowCount++;
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);
113 WMMapWidget(win);
118 static void
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);
127 void
128 testBox(WMScreen *scr)
130 WMWindow *win;
131 WMBox *box, *hbox;
132 WMButton *btn;
133 WMPopUpButton *pop;
134 int i;
136 windowCount++;
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,
149 WMWidgetView(win));
150 WMResizeWidget(win, 400, 300);
153 /* WMSetBoxHorizontal(box, True); */
154 for (i = 0; i < 4; i++) {
155 btn = WMCreateCommandButton(box);
156 WMSetButtonText(btn, "bla");
157 WMMapWidget(btn);
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);
165 WMMapWidget(pop);
167 hbox = WMCreateBox(box);
168 WMSetBoxHorizontal(hbox, True);
169 WMAddBoxSubview(box, WMWidgetView(hbox), False, True, 24, 0, 0);
170 WMMapWidget(hbox);
172 for (i = 0; i < 4; i++) {
173 btn = WMCreateCommandButton(hbox);
174 WMSetButtonText(btn, "bla");
175 WMMapWidget(btn);
176 WMAddBoxSubview(hbox, WMWidgetView(btn), 1, True, 60, 0, i<3?5:0);
180 WMRealizeWidget(win);
181 WMMapSubwidgets(win);
182 WMMapWidget(win);
188 static void
189 singleClick(WMWidget *self, void *data)
194 static void
195 doubleClick(WMWidget *self, void *data)
197 WMSelectAllListItems((WMList*)self);
201 static void
202 listSelectionObserver(void *observer, WMNotification *notification)
204 WMLabel *label = (WMLabel*)observer;
205 WMList *lPtr = (WMList*)WMGetNotificationObject(notification);
206 char buf[255];
208 sprintf(buf, "Selected items: %d",
209 WMGetArrayItemCount(WMGetListSelectedItems(lPtr)));
210 WMSetLabelText(label, buf);
214 void
215 testList(WMScreen *scr)
217 WMWindow *win;
218 WMList *list;
219 WMList *mlist;
220 WMLabel *label;
221 WMLabel *mlabel;
222 WMLabel *title;
223 WMLabel *mtitle;
224 char text[100];
225 int i;
227 windowCount++;
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);
287 WMMapWidget(win);
291 void
292 testButton(WMScreen *scr)
294 WMWindow *win;
295 int i;
296 char *types[] = {
297 "MomentaryPush",
298 "PushOnPushOff",
299 "Toggle",
300 "Switch",
301 "Radio",
302 "MomentaryChange",
303 "OnOff",
304 "MomentaryLigh"
307 windowCount++;
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++) {
316 WMButton *b;
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);
325 WMMapWidget(win);
329 void
330 testGradientButtons(WMScreen *scr)
332 WMWindow *win;
333 WMButton *btn;
334 WMPixmap *pix1, *pix2;
335 RImage *back;
336 RColor light, dark;
337 WMColor *color, *altColor;
339 windowCount++;
341 /* creates the top-level window */
342 win = WMCreateWindow(scr, "testGradientButtons");
343 WMSetWindowTitle(win, "Gradiented Button Demo");
344 WMResizeWidget(win, 300, 200);
346 light.red = 0x90;
347 light.green = 0x85;
348 light.blue = 0x90;
349 dark.red = 0x35;
350 dark.green = 0x30;
351 dark.blue = 0x35;
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);
360 RReleaseImage(back);
362 back = RRenderGradient(60, 24, &dark, &light, RGRD_DIAGONAL);
363 RBevelImage(back, RBEV_SUNKEN);
364 pix2 = WMCreatePixmapFromRImage(scr, back, 0);
365 RReleaseImage(back);
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!",
409 WMWidgetView(btn));
411 WMReleaseColor(color);
412 WMReleaseColor(altColor);
414 WMRealizeWidget(win);
415 WMMapSubwidgets(win);
416 WMMapWidget(win);
420 void
421 testScrollView(WMScreen *scr)
423 WMWindow *win;
424 WMScrollView *sview;
425 WMFrame *f;
426 WMLabel *l;
427 char buffer[128];
428 int i;
430 windowCount++;
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);
462 WMMapSubwidgets(f);
463 WMMapWidget(f);
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 */
477 WMMapWidget(win);
481 void
482 testColorWell(WMScreen *scr)
484 WMWindow *win;
485 WMColorWell *well1, *well2;
487 windowCount++;
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);
504 WMMapWidget(win);
508 void
509 testColorPanel(WMScreen *scr)
511 WMColorPanel *panel = WMGetColorPanel(scr);
513 /*if (colorname) {
514 startcolor = WMCreateNamedColor(scr, colorname, False);
515 WMSetColorPanelColor(panel, startcolor);
516 WMReleaseColor(startcolor);
519 WMShowColorPanel(panel);
522 void
523 sliderCallback(WMWidget *w, void *data)
525 printf("SLIDER == %i\n", WMGetSliderValue(w));
529 void
530 testSlider(WMScreen *scr)
532 WMWindow *win;
533 WMSlider *s;
535 windowCount++;
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);
557 WMMapWidget(win);
561 void
562 testTextField(WMScreen *scr)
564 WMWindow *win;
565 WMTextField *field, *field2;
567 windowCount++;
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);
585 WMMapWidget(win);
590 void
591 testText(WMScreen *scr)
593 WMWindow *win;
594 WMText *text;
595 FILE *file = fopen("wm.html", "r");
597 windowCount++;
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);
610 if(file) {
611 char buf[1024];
613 WMFreezeText(text);
614 while(fgets(buf, 1023, file))
615 WMAppendTextStream(text, buf);
617 fclose(file);
618 WMThawText(text);
619 } else {
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);
631 WMMapWidget(win);
635 void
636 testProgressIndicator(WMScreen *scr)
638 WMWindow *win;
639 WMProgressIndicator *pPtr;
641 windowCount++;
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);
654 WMMapWidget(win);
659 void
660 testPullDown(WMScreen *scr)
662 WMWindow *win;
663 WMPopUpButton *pop, *pop2;
665 windowCount++;
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);
693 WMMapWidget(win);
698 void
699 testTabView(WMScreen *scr)
701 WMWindow *win;
702 WMTabView *tabv;
703 WMTabViewItem *tab;
704 WMFrame *frame;
705 WMLabel *label;
707 windowCount++;
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");
723 WMMapWidget(label);
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");
736 WMMapWidget(label);
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");
751 WMMapWidget(label);
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");
765 WMMapWidget(label);
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");
780 WMMapWidget(label);
781 tab = WMCreateTabViewItemWithIdentifier(0);
782 WMSetTabViewItemView(tab, WMWidgetView(frame));
783 WMAddItemInTabView(tabv, tab);
784 WMSetTabViewItemLabel(tab, "Weee!");
787 WMRealizeWidget(win);
788 WMMapSubwidgets(win);
789 WMMapWidget(win);
793 void
794 splitViewConstrainProc(WMSplitView *sPtr, int indView,
795 int *minSize, int *maxSize)
797 switch (indView) {
798 case 0:
799 *minSize = 20;
800 break;
801 case 1:
802 *minSize = 40;
803 *maxSize = 80;
804 break;
805 case 2:
806 *maxSize = 60;
807 break;
808 default:
809 break;
814 static void
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);
831 void
832 appendSubviewButtonAction(WMWidget *self, void *data)
834 WMSplitView *sPtr = (WMSplitView*)data;
835 char buf[64];
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);
843 WMMapWidget(label);
846 void
847 removeSubviewButtonAction(WMWidget *self, void *data)
849 WMSplitView *sPtr = (WMSplitView*)data;
850 int count = WMGetSplitViewSubviewsCount(sPtr);
852 if (count > 2) {
853 WMView *view = WMGetSplitViewSubviewAt(sPtr, count-1);
854 WMDestroyWidget(WMWidgetOfView(view));
855 WMRemoveSplitViewSubviewAt(sPtr, count-1);
859 void
860 orientationButtonAction(WMWidget *self, void *data)
862 WMSplitView *sPtr = (WMSplitView*)data;
863 WMSetSplitViewVertical(sPtr, !WMGetSplitViewVertical(sPtr));
866 void
867 adjustSubviewsButtonAction(WMWidget *self, void *data)
869 WMAdjustSplitViewSubviews((WMSplitView*)data);
872 void
873 testSplitView(WMScreen *scr)
875 WMWindow *win;
876 WMSplitView *splitv1, *splitv2;
877 WMFrame *frame;
878 WMLabel *label;
879 WMButton *button;
881 windowCount++;
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);
903 WMMapWidget(button);
905 button = WMCreateCommandButton(frame);
906 WMSetButtonText(button, "-");
907 WMSetButtonAction(button, removeSubviewButtonAction, splitv1);
908 WMMoveWidget(button, 80, 8);
909 WMMapWidget(button);
911 button = WMCreateCommandButton(frame);
912 WMSetButtonText(button, "=");
913 WMMoveWidget(button, 150, 8);
914 WMSetButtonAction(button, adjustSubviewsButtonAction, splitv1);
915 WMMapWidget(button);
917 button = WMCreateCommandButton(frame);
918 WMSetButtonText(button, "#");
919 WMMoveWidget(button, 220, 8);
920 WMSetButtonAction(button, orientationButtonAction, splitv1);
921 WMMapWidget(button);
923 label = WMCreateLabel(splitv1);
924 WMSetLabelText(label, "Subview 1");
925 WMSetLabelRelief(label, WRSunken);
926 WMMapWidget(label);
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);
936 WMMapWidget(label);
937 WMAddSplitViewSubview(splitv2, WMWidgetView(label));
939 label = WMCreateLabel(splitv2);
940 WMSetLabelText(label, "Subview 2.2");
941 WMSetLabelRelief(label, WRSunken);
942 WMMapWidget(label);
943 WMAddSplitViewSubview(splitv2, WMWidgetView(label));
945 label = WMCreateLabel(splitv2);
946 WMSetLabelText(label, "Subview 2.3");
947 WMSetLabelRelief(label, WRSunken);
948 WMMapWidget(label);
949 WMAddSplitViewSubview(splitv2, WMWidgetView(label));
951 WMMapWidget(splitv2);
952 WMAddSplitViewSubview(splitv1, WMWidgetView(splitv2));
954 WMRealizeWidget(win);
955 WMMapSubwidgets(win);
956 WMMapWidget(win);
960 /*******************************************************************/
962 #include <sys/types.h>
963 #include <dirent.h>
964 #include <string.h>
967 typedef struct {
968 int x, y;
969 Bool mouseDown;
970 char *filename;
971 } DNDStuff;
973 WMPixmap*
974 getImage(WMScreen *scr, char *file)
976 char buffer[1000];
977 WMPixmap *pix;
979 sprintf(buffer, "../../WindowMaker/Icons/%s", file);
980 pix = WMCreatePixmapFromFile(scr, buffer);
982 return pix;
988 static void
989 iconMouseStuff(XEvent *event, void *cdata)
991 WMLabel *label = (WMLabel*)cdata;
992 DNDStuff *stuff = WMGetHangedData(label);
993 WMPoint where;
995 switch (event->type) {
996 case ButtonPress:
997 stuff->x = event->xbutton.x;
998 stuff->y = event->xbutton.y;
999 stuff->mouseDown = True;
1000 break;
1001 case ButtonRelease:
1002 stuff->mouseDown = False;
1003 break;
1004 case MotionNotify:
1005 if (!stuff->mouseDown)
1006 break;
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),
1015 NULL, /* XXX */
1016 where,
1017 wmksize(stuff->x, stuff->y),
1018 event, True);
1020 break;
1025 static void
1026 endedDragImage(WMView *self, WMPixmap *image, WMPoint point, Bool deposited)
1028 DNDStuff *stuff = WMGetHangedData(WMWidgetOfView(self));
1030 if (deposited) {
1031 WMDestroyWidget(WMWidgetOfView(self));
1034 stuff->mouseDown = False;
1038 static WMData*
1039 fetchDragData(WMView *self, char *type)
1041 DNDStuff *stuff = WMGetHangedData(WMWidgetOfView(self));
1043 return WMCreateDataWithBytes(stuff->filename, strlen(stuff->filename)+1);
1047 WMDragSourceProcs dragSourceProcs = {
1048 NULL,
1049 NULL,
1050 endedDragImage,
1051 fetchDragData
1055 /************************/
1058 unsigned
1059 draggingEntered(WMView *self, WMDraggingInfo *info)
1061 return WDOperationCopy;
1065 unsigned
1066 draggingUpdated(WMView *self, WMDraggingInfo *info)
1068 return WDOperationCopy;
1072 void (*draggingExited)(WMView *self, WMDraggingInfo *info);
1074 char*
1075 prepareForDragOperation(WMView *self, WMDraggingInfo *info)
1077 return "application/X-WINGs-Bla";
1081 WMLabel* makeDraggableLabel(WMWidget *w, char *file, int x, int y);
1083 Bool
1084 performDragOperation(WMView *self, WMDraggingInfo *info, WMData *data)
1086 char *file = (char*)WMDataBytes(data);
1087 WMPoint pos;
1089 pos = WMGetDraggingInfoImageLocation(info);
1091 if (file!=NULL) {
1092 WMLabel *label;
1093 WMPoint pos2 = WMGetViewScreenPosition(self);
1096 label = makeDraggableLabel(WMWidgetOfView(self), file,
1097 pos.x-pos2.x, pos.y-pos2.y);
1098 WMRealizeWidget(label);
1099 WMMapWidget(label);
1103 return True;
1107 void
1108 concludeDragOperation(WMView *self, WMDraggingInfo *info)
1115 WMDragDestinationProcs dragDestProcs = {
1116 draggingEntered,
1117 draggingUpdated,
1118 NULL,
1119 prepareForDragOperation,
1120 performDragOperation,
1121 concludeDragOperation
1127 WMLabel*
1128 makeDraggableLabel(WMWidget *w, char *file, int x, int y)
1130 DNDStuff *stuff;
1131 WMLabel *label;
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);
1156 } else puts(file);
1158 return label;
1163 void
1164 testDragAndDrop(WMScreen *scr)
1166 WMWindow *win;
1167 WMFrame *frame;
1168 WMLabel *label;
1169 int i, j;
1170 DIR *dir;
1171 struct dirent *ent;
1172 char *types[] = {
1173 "application/X-WINGs-Bla",
1174 NULL
1177 windowCount++;
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");
1194 if (!dir) {
1195 perror("../../WindowMaker/Icons");
1196 return;
1199 for (i = 0, j=0; j < 8; i++) {
1200 ent = readdir(dir);
1201 if (!ent)
1202 break;
1204 if (strstr(ent->d_name, ".xpm")==NULL) {
1205 continue;
1208 label = makeDraggableLabel(frame, ent->d_name,4+(j/4)*64, 4+(j%4)*64);
1210 j++;
1213 closedir(dir);
1215 WMMapSubwidgets(frame);
1217 WMMapSubwidgets(win);
1218 WMRealizeWidget(win);
1219 WMMapWidget(win);
1226 /*******************************************************************/
1229 void
1230 testUD()
1232 WMUserDefaults *defs;
1233 char str[32];
1235 defs = WMGetStandardUserDefaults();
1237 sprintf(str, "TEST DATA");
1238 puts(str);
1239 WMSetUDStringForKey(defs, str, "testKey");
1240 puts(str);
1245 main(int argc, char **argv)
1247 WMScreen *scr;
1248 WMPixmap *pixmap;
1251 /* Initialize the application */
1252 WMInitializeApplication("Test@eqweq_ewq$eqw", &argc, argv);
1254 testUD();
1257 * Open connection to the X display.
1259 dpy = XOpenDisplay("");
1261 if (!dpy) {
1262 puts("could not open display");
1263 exit(1);
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
1270 #if 1
1271 XSynchronize(dpy, True);
1272 #endif
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);
1297 testText(scr);
1298 #if 0
1299 testColorPanel(scr);
1300 testScrollView(scr);
1301 testTabView(scr);
1302 testBox(scr);
1303 testText(scr);
1304 testList(scr);
1306 testProgressIndicator(scr);
1308 testColorWell(scr);
1310 testTextField(scr);
1312 testDragAndDrop(scr);
1313 testFontPanel(scr);
1315 testButton(scr);
1317 testFrame(scr);
1323 testSplitView(scr);
1325 testGradientButtons(scr);
1328 testOpenFilePanel(scr);
1330 testSlider(scr);
1331 testPullDown(scr);
1332 #endif
1334 * The main event loop.
1337 WMScreenMainLoop(scr);
1339 return 0;