patch to add binary mode on opening files (for Windows+Cygwin compatibility).
[wmaker-crm.git] / WINGs / Tests / wtest.c
blob128b9bc45fa9a684999a9aa9d19de6957d9d2ce6
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);
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");
151 WMMapWidget(btn);
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);
159 WMMapWidget(pop);
161 hbox = WMCreateBox(box);
162 WMSetBoxHorizontal(hbox, True);
163 WMAddBoxSubview(box, WMWidgetView(hbox), False, True, 24, 0, 0);
164 WMMapWidget(hbox);
166 for (i = 0; i < 4; i++) {
167 btn = WMCreateCommandButton(hbox);
168 WMSetButtonText(btn, "bla");
169 WMMapWidget(btn);
170 WMAddBoxSubview(hbox, WMWidgetView(btn), 1, True, 60, 0, i<3?5:0);
174 WMRealizeWidget(win);
175 WMMapSubwidgets(win);
176 WMMapWidget(win);
182 static void
183 singleClick(WMWidget *self, void *data)
188 static void
189 doubleClick(WMWidget *self, void *data)
191 WMSelectAllListItems((WMList*)self);
195 static void
196 listSelectionObserver(void *observer, WMNotification *notification)
198 WMLabel *label = (WMLabel*)observer;
199 WMList *lPtr = (WMList*)WMGetNotificationObject(notification);
200 char buf[255];
202 sprintf(buf, "Selected items: %d",
203 WMGetArrayItemCount(WMGetListSelectedItems(lPtr)));
204 WMSetLabelText(label, buf);
208 void
209 testList(WMScreen *scr)
211 WMWindow *win;
212 WMList *list;
213 WMList *mlist;
214 WMLabel *label;
215 WMLabel *mlabel;
216 WMLabel *title;
217 WMLabel *mtitle;
218 char text[100];
219 int i;
221 windowCount++;
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<50; 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);
281 WMMapWidget(win);
285 void
286 testButton(WMScreen *scr)
288 WMWindow *win;
289 int i;
290 char *types[] = {
291 "MomentaryPush",
292 "PushOnPushOff",
293 "Toggle",
294 "Switch",
295 "Radio",
296 "MomentaryChange",
297 "OnOff",
298 "MomentaryLigh"
301 windowCount++;
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++) {
310 WMButton *b;
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);
319 WMMapWidget(win);
323 void
324 testGradientButtons(WMScreen *scr)
326 WMWindow *win;
327 WMButton *btn;
328 WMPixmap *pix1, *pix2;
329 RImage *back;
330 RColor light, dark;
331 WMColor *color, *altColor;
333 windowCount++;
335 /* creates the top-level window */
336 win = WMCreateWindow(scr, "testGradientButtons");
337 WMSetWindowTitle(win, "Gradiented Button Demo");
338 WMResizeWidget(win, 300, 200);
340 light.red = 0x90;
341 light.green = 0x85;
342 light.blue = 0x90;
343 dark.red = 0x35;
344 dark.green = 0x30;
345 dark.blue = 0x35;
347 color = WMCreateRGBColor(scr, 0x5900, 0x5100, 0x5900, True);
348 WMSetWidgetBackgroundColor(win, color);
349 WMReleaseColor(color);
351 back = RRenderGradient(60, 24, &dark, &light, RGRD_DIAGONAL);
352 RBevelImage(back, RBEV_RAISED2);
353 pix1 = WMCreatePixmapFromRImage(scr, back, 0);
354 RReleaseImage(back);
356 back = RRenderGradient(60, 24, &dark, &light, RGRD_DIAGONAL);
357 RBevelImage(back, RBEV_SUNKEN);
358 pix2 = WMCreatePixmapFromRImage(scr, back, 0);
359 RReleaseImage(back);
361 color = WMWhiteColor(scr);
362 altColor = WMCreateNamedColor(scr, "red", True);
364 btn = WMCreateButton(win, WBTMomentaryChange);
365 WMResizeWidget(btn, 60, 24);
366 WMMoveWidget(btn, 20, 100);
367 WMSetButtonBordered(btn, False);
368 WMSetButtonImagePosition(btn, WIPOverlaps);
369 WMSetButtonImage(btn, pix1);
370 WMSetButtonAltImage(btn, pix2);
371 WMSetButtonText(btn, "Cool");
372 WMSetButtonTextColor(btn, color);
373 WMSetButtonAltTextColor(btn, altColor);
375 WMSetBalloonTextForView("This is a cool button", WMWidgetView(btn));
377 btn = WMCreateButton(win, WBTMomentaryChange);
378 WMResizeWidget(btn, 60, 24);
379 WMMoveWidget(btn, 90, 100);
380 WMSetButtonBordered(btn, False);
381 WMSetButtonImagePosition(btn, WIPOverlaps);
382 WMSetButtonImage(btn, pix1);
383 WMSetButtonAltImage(btn, pix2);
384 WMSetButtonText(btn, "Button");
385 WMSetButtonTextColor(btn, color);
387 WMSetBalloonTextForView("Este é outro balão.", WMWidgetView(btn));
389 WMReleaseColor(color);
390 color = WMCreateNamedColor(scr, "orange", True);
392 btn = WMCreateButton(win, WBTMomentaryChange);
393 WMResizeWidget(btn, 60, 24);
394 WMMoveWidget(btn, 160, 100);
395 WMSetButtonBordered(btn, False);
396 WMSetButtonImagePosition(btn, WIPOverlaps);
397 WMSetButtonImage(btn, pix1);
398 WMSetButtonAltImage(btn, pix2);
399 WMSetButtonText(btn, "Test");
400 WMSetButtonTextColor(btn, color);
402 WMSetBalloonTextForView("This is yet another button.\nBut the balloon has 3 lines.\nYay!",
403 WMWidgetView(btn));
405 WMReleaseColor(color);
406 WMReleaseColor(altColor);
408 WMRealizeWidget(win);
409 WMMapSubwidgets(win);
410 WMMapWidget(win);
414 void
415 testScrollView(WMScreen *scr)
417 WMWindow *win;
418 WMScrollView *sview;
419 WMFrame *f;
420 WMLabel *l;
421 char buffer[128];
422 int i;
424 windowCount++;
426 /* creates the top-level window */
427 win = WMCreateWindow(scr, "testScroll");
428 WMSetWindowTitle(win, "Scrollable View");
430 WMSetWindowCloseAction(win, closeAction, NULL);
432 /* set the window size */
433 WMResizeWidget(win, 300, 300);
435 /* creates a scrollable view inside the top-level window */
436 sview = WMCreateScrollView(win);
437 WMResizeWidget(sview, 200, 200);
438 WMMoveWidget(sview, 30, 30);
439 WMSetScrollViewRelief(sview, WRSunken);
440 WMSetScrollViewHasVerticalScroller(sview, True);
441 WMSetScrollViewHasHorizontalScroller(sview, True);
443 /* create a frame with a bunch of labels */
444 f = WMCreateFrame(win);
445 WMResizeWidget(f, 400, 400);
446 WMSetFrameRelief(f, WRFlat);
448 for (i=0; i<20; i++) {
449 l = WMCreateLabel(f);
450 WMResizeWidget(l, 50, 18);
451 WMMoveWidget(l, 10, 20*i);
452 sprintf(buffer, "Label %i", i);
453 WMSetLabelText(l, buffer);
454 WMSetLabelRelief(l, WRSimple);
456 WMMapSubwidgets(f);
457 WMMapWidget(f);
459 WMSetScrollViewContentView(sview, WMWidgetView(f));
461 /* make the windows of the widgets be actually created */
462 WMRealizeWidget(win);
464 /* Map all child widgets of the top-level be mapped.
465 * You must call this for each container widget (like frames),
466 * even if they are childs of the top-level window.
468 WMMapSubwidgets(win);
470 /* map the top-level window */
471 WMMapWidget(win);
475 void
476 testColorWell(WMScreen *scr)
478 WMWindow *win;
479 WMColorWell *well1, *well2;
481 windowCount++;
483 win = WMCreateWindow(scr, "testColor");
484 WMResizeWidget(win, 300, 300);
485 WMSetWindowCloseAction(win, closeAction, NULL);
487 well1 = WMCreateColorWell(win);
488 WMResizeWidget(well1, 60, 40);
489 WMMoveWidget(well1, 100, 100);
490 WMSetColorWellColor(well1, WMCreateRGBColor(scr, 0x8888, 0, 0x1111, True));
491 well2 = WMCreateColorWell(win);
492 WMResizeWidget(well2, 60, 40);
493 WMMoveWidget(well2, 200, 100);
494 WMSetColorWellColor(well2, WMCreateRGBColor(scr, 0, 0, 0x8888, True));
496 WMRealizeWidget(win);
497 WMMapSubwidgets(win);
498 WMMapWidget(win);
502 void
503 testColorPanel(WMScreen *scr)
505 WMColorPanel *panel = WMGetColorPanel(scr);
507 /*if (colorname) {
508 startcolor = WMCreateNamedColor(scr, colorname, False);
509 WMSetColorPanelColor(panel, startcolor);
510 WMReleaseColor(startcolor);
513 WMShowColorPanel(panel);
516 void
517 sliderCallback(WMWidget *w, void *data)
519 printf("SLIDER == %i\n", WMGetSliderValue(w));
523 void
524 testSlider(WMScreen *scr)
526 WMWindow *win;
527 WMSlider *s;
529 windowCount++;
531 win = WMCreateWindow(scr, "testSlider");
532 WMResizeWidget(win, 300, 300);
533 WMSetWindowTitle(win, "Sliders");
535 WMSetWindowCloseAction(win, closeAction, NULL);
537 s = WMCreateSlider(win);
538 WMResizeWidget(s, 16, 100);
539 WMMoveWidget(s, 100, 100);
540 WMSetSliderKnobThickness(s, 8);
541 WMSetSliderContinuous(s, False);
542 WMSetSliderAction(s, sliderCallback, s);
544 s = WMCreateSlider(win);
545 WMResizeWidget(s, 100, 16);
546 WMMoveWidget(s, 100, 10);
547 WMSetSliderKnobThickness(s, 8);
549 WMRealizeWidget(win);
550 WMMapSubwidgets(win);
551 WMMapWidget(win);
555 void
556 testTextField(WMScreen *scr)
558 WMWindow *win;
559 WMTextField *field, *field2;
561 windowCount++;
563 win = WMCreateWindow(scr, "testTextField");
564 WMResizeWidget(win, 400, 300);
566 WMSetWindowCloseAction(win, closeAction, NULL);
568 field = WMCreateTextField(win);
569 WMResizeWidget(field, 200, 20);
570 WMMoveWidget(field, 20, 20);
572 field2 = WMCreateTextField(win);
573 WMResizeWidget(field2, 200, 20);
574 WMMoveWidget(field2, 20, 50);
575 WMSetTextFieldAlignment(field2, WARight);
577 WMRealizeWidget(win);
578 WMMapSubwidgets(win);
579 WMMapWidget(win);
584 void
585 testText(WMScreen *scr)
587 WMWindow *win;
588 WMText *text;
589 FILE *file = fopen("wm.html", "rb");
591 windowCount++;
593 win = WMCreateWindow(scr, "testText");
594 WMResizeWidget(win, 500, 300);
596 WMSetWindowCloseAction(win, closeAction, NULL);
598 text = WMCreateText(win);
599 WMResizeWidget(text, 480, 280);
600 WMMoveWidget(text, 10, 10);
601 WMSetTextHasVerticalScroller(text, True);
602 WMSetTextEditable(text, False);
604 if(file) {
605 char buf[1024];
607 WMFreezeText(text);
608 while(fgets(buf, 1023, file))
609 WMAppendTextStream(text, buf);
611 fclose(file);
612 WMThawText(text);
613 } else {
614 WMAppendTextStream(text,
615 "Window Maker is the GNU window manager for the "
616 "X Window System. It was designed to emulate the "
617 "look and feel of part of the NEXTSTEP(tm) GUI. Its "
618 "supposed to be relatively fast and small, feature "
619 "rich, easy to configure and easy to use, with a simple "
620 "and elegant appearance borrowed from NEXTSTEP(tm).");
623 WMRealizeWidget(win);
624 WMMapSubwidgets(win);
625 WMMapWidget(win);
629 void
630 testProgressIndicator(WMScreen *scr)
632 WMWindow *win;
633 WMProgressIndicator *pPtr;
635 windowCount++;
637 win = WMCreateWindow(scr, "testProgressIndicator");
638 WMResizeWidget(win, 292, 32);
640 WMSetWindowCloseAction(win, closeAction, NULL);
642 pPtr = WMCreateProgressIndicator(win);
643 WMMoveWidget(pPtr, 8, 8);
644 WMSetProgressIndicatorValue(pPtr, 75);
646 WMRealizeWidget(win);
647 WMMapSubwidgets(win);
648 WMMapWidget(win);
653 void
654 testPullDown(WMScreen *scr)
656 WMWindow *win;
657 WMPopUpButton *pop, *pop2;
659 windowCount++;
661 win = WMCreateWindow(scr, "pullDown");
662 WMResizeWidget(win, 400, 300);
664 WMSetWindowCloseAction(win, closeAction, NULL);
666 pop = WMCreatePopUpButton(win);
667 WMResizeWidget(pop, 100, 20);
668 WMMoveWidget(pop, 50, 60);
669 WMSetPopUpButtonPullsDown(pop, True);
670 WMSetPopUpButtonText(pop, "Commands");
671 WMAddPopUpButtonItem(pop, "Add");
672 WMAddPopUpButtonItem(pop, "Remove");
673 WMAddPopUpButtonItem(pop, "Check");
674 WMAddPopUpButtonItem(pop, "Eat");
676 pop2 = WMCreatePopUpButton(win);
677 WMResizeWidget(pop2, 100, 20);
678 WMMoveWidget(pop2, 200, 60);
679 WMSetPopUpButtonText(pop2, "Select");
680 WMAddPopUpButtonItem(pop2, "Apples");
681 WMAddPopUpButtonItem(pop2, "Bananas");
682 WMAddPopUpButtonItem(pop2, "Strawberries");
683 WMAddPopUpButtonItem(pop2, "Blueberries");
685 WMRealizeWidget(win);
686 WMMapSubwidgets(win);
687 WMMapWidget(win);
692 void
693 testTabView(WMScreen *scr)
695 WMWindow *win;
696 WMTabView *tabv;
697 WMTabViewItem *tab;
698 WMFrame *frame;
699 WMLabel *label;
701 windowCount++;
703 win = WMCreateWindow(scr, "testTabs");
704 WMResizeWidget(win, 400, 300);
706 WMSetWindowCloseAction(win, closeAction, NULL);
708 tabv = WMCreateTabView(win);
709 WMMoveWidget(tabv, 50, 50);
710 WMResizeWidget(tabv, 300, 200);
712 frame = WMCreateFrame(win);
713 WMSetFrameRelief(frame, WRFlat);
714 label = WMCreateLabel(frame);
715 WMResizeWidget(label, 100, 100);
716 WMSetLabelText(label, "Label 1");
717 WMMapWidget(label);
720 tab = WMCreateTabViewItemWithIdentifier(0);
721 WMSetTabViewItemView(tab, WMWidgetView(frame));
722 WMAddItemInTabView(tabv, tab);
723 WMSetTabViewItemLabel(tab, "Instances");
725 frame = WMCreateFrame(win);
726 WMSetFrameRelief(frame, WRFlat);
727 label = WMCreateLabel(frame);
728 WMResizeWidget(label, 40, 50);
729 WMSetLabelText(label, "Label 2");
730 WMMapWidget(label);
733 tab = WMCreateTabViewItemWithIdentifier(0);
734 WMSetTabViewItemView(tab, WMWidgetView(frame));
735 WMAddItemInTabView(tabv, tab);
736 WMSetTabViewItemLabel(tab, "Classes");
739 frame = WMCreateFrame(win);
740 WMSetFrameRelief(frame, WRFlat);
741 label = WMCreateLabel(frame);
742 WMResizeWidget(label, 100, 100);
743 WMMoveWidget(label, 60, 40);
744 WMSetLabelText(label, "Label 3");
745 WMMapWidget(label);
747 tab = WMCreateTabViewItemWithIdentifier(0);
748 WMSetTabViewItemView(tab, WMWidgetView(frame));
749 WMAddItemInTabView(tabv, tab);
750 WMSetTabViewItemLabel(tab, "Something");
753 frame = WMCreateFrame(win);
754 WMSetFrameRelief(frame, WRFlat);
755 label = WMCreateLabel(frame);
756 WMResizeWidget(label, 100, 100);
757 WMMoveWidget(label, 160, 40);
758 WMSetLabelText(label, "Label 4");
759 WMMapWidget(label);
761 tab = WMCreateTabViewItemWithIdentifier(0);
762 WMSetTabViewItemView(tab, WMWidgetView(frame));
763 WMAddItemInTabView(tabv, tab);
764 WMSetTabViewItemLabel(tab, "Bla!");
768 frame = WMCreateFrame(win);
769 WMSetFrameRelief(frame, WRFlat);
770 label = WMCreateLabel(frame);
771 WMResizeWidget(label, 100, 100);
772 WMMoveWidget(label, 160, 40);
773 WMSetLabelText(label, "Label fjweqklrj qwl");
774 WMMapWidget(label);
775 tab = WMCreateTabViewItemWithIdentifier(0);
776 WMSetTabViewItemView(tab, WMWidgetView(frame));
777 WMAddItemInTabView(tabv, tab);
778 WMSetTabViewItemLabel(tab, "Weee!");
781 WMRealizeWidget(win);
782 WMMapSubwidgets(win);
783 WMMapWidget(win);
787 void
788 splitViewConstrainProc(WMSplitView *sPtr, int indView,
789 int *minSize, int *maxSize)
791 switch (indView) {
792 case 0:
793 *minSize = 20;
794 break;
795 case 1:
796 *minSize = 40;
797 *maxSize = 80;
798 break;
799 case 2:
800 *maxSize = 60;
801 break;
802 default:
803 break;
808 static void
809 resizeSplitView(XEvent *event, void *data)
811 WMSplitView *sPtr = (WMSplitView*)data;
813 if (event->type == ConfigureNotify) {
814 int width = event->xconfigure.width - 10;
816 if (width < WMGetSplitViewDividerThickness(sPtr))
817 width = WMGetSplitViewDividerThickness(sPtr);
819 if (width != WMWidgetWidth(sPtr) ||
820 event->xconfigure.height != WMWidgetHeight(sPtr))
821 WMResizeWidget(sPtr, width, event->xconfigure.height - 55);
825 void
826 appendSubviewButtonAction(WMWidget *self, void *data)
828 WMSplitView *sPtr = (WMSplitView*)data;
829 char buf[64];
830 WMLabel *label = WMCreateLabel(sPtr);
832 sprintf(buf, "Subview %d", WMGetSplitViewSubviewsCount(sPtr) + 1);
833 WMSetLabelText(label, buf);
834 WMSetLabelRelief(label, WRSunken);
835 WMAddSplitViewSubview(sPtr, WMWidgetView(label));
836 WMRealizeWidget(label);
837 WMMapWidget(label);
840 void
841 removeSubviewButtonAction(WMWidget *self, void *data)
843 WMSplitView *sPtr = (WMSplitView*)data;
844 int count = WMGetSplitViewSubviewsCount(sPtr);
846 if (count > 2) {
847 WMView *view = WMGetSplitViewSubviewAt(sPtr, count-1);
848 WMDestroyWidget(WMWidgetOfView(view));
849 WMRemoveSplitViewSubviewAt(sPtr, count-1);
853 void
854 orientationButtonAction(WMWidget *self, void *data)
856 WMSplitView *sPtr = (WMSplitView*)data;
857 WMSetSplitViewVertical(sPtr, !WMGetSplitViewVertical(sPtr));
860 void
861 adjustSubviewsButtonAction(WMWidget *self, void *data)
863 WMAdjustSplitViewSubviews((WMSplitView*)data);
866 void
867 testSplitView(WMScreen *scr)
869 WMWindow *win;
870 WMSplitView *splitv1, *splitv2;
871 WMFrame *frame;
872 WMLabel *label;
873 WMButton *button;
875 windowCount++;
877 win = WMCreateWindow(scr, "testTabs");
878 WMResizeWidget(win, 300, 400);
879 WMSetWindowCloseAction(win, closeAction, NULL);
881 frame = WMCreateFrame(win);
882 WMSetFrameRelief(frame, WRSunken);
883 WMMoveWidget(frame, 5, 5);
884 WMResizeWidget(frame, 290, 40);
886 splitv1 = WMCreateSplitView(win);
887 WMMoveWidget(splitv1, 5, 50);
888 WMResizeWidget(splitv1, 290, 345);
889 WMSetSplitViewConstrainProc(splitv1, splitViewConstrainProc);
890 WMCreateEventHandler(WMWidgetView(win), StructureNotifyMask,
891 resizeSplitView, splitv1);
893 button = WMCreateCommandButton(frame);
894 WMSetButtonText(button, "+");
895 WMSetButtonAction(button, appendSubviewButtonAction, splitv1);
896 WMMoveWidget(button, 10, 8);
897 WMMapWidget(button);
899 button = WMCreateCommandButton(frame);
900 WMSetButtonText(button, "-");
901 WMSetButtonAction(button, removeSubviewButtonAction, splitv1);
902 WMMoveWidget(button, 80, 8);
903 WMMapWidget(button);
905 button = WMCreateCommandButton(frame);
906 WMSetButtonText(button, "=");
907 WMMoveWidget(button, 150, 8);
908 WMSetButtonAction(button, adjustSubviewsButtonAction, splitv1);
909 WMMapWidget(button);
911 button = WMCreateCommandButton(frame);
912 WMSetButtonText(button, "#");
913 WMMoveWidget(button, 220, 8);
914 WMSetButtonAction(button, orientationButtonAction, splitv1);
915 WMMapWidget(button);
917 label = WMCreateLabel(splitv1);
918 WMSetLabelText(label, "Subview 1");
919 WMSetLabelRelief(label, WRSunken);
920 WMMapWidget(label);
921 WMAddSplitViewSubview(splitv1, WMWidgetView(label));
923 splitv2 = WMCreateSplitView(splitv1);
924 WMResizeWidget(splitv2, 150, 150);
925 WMSetSplitViewVertical(splitv2, True);
927 label = WMCreateLabel(splitv2);
928 WMSetLabelText(label, "Subview 2.1");
929 WMSetLabelRelief(label, WRSunken);
930 WMMapWidget(label);
931 WMAddSplitViewSubview(splitv2, WMWidgetView(label));
933 label = WMCreateLabel(splitv2);
934 WMSetLabelText(label, "Subview 2.2");
935 WMSetLabelRelief(label, WRSunken);
936 WMMapWidget(label);
937 WMAddSplitViewSubview(splitv2, WMWidgetView(label));
939 label = WMCreateLabel(splitv2);
940 WMSetLabelText(label, "Subview 2.3");
941 WMSetLabelRelief(label, WRSunken);
942 WMMapWidget(label);
943 WMAddSplitViewSubview(splitv2, WMWidgetView(label));
945 WMMapWidget(splitv2);
946 WMAddSplitViewSubview(splitv1, WMWidgetView(splitv2));
948 WMRealizeWidget(win);
949 WMMapSubwidgets(win);
950 WMMapWidget(win);
954 /*******************************************************************/
956 #include <sys/types.h>
957 #include <dirent.h>
958 #include <string.h>
961 typedef struct {
962 int x, y;
963 Bool mouseDown;
964 char *filename;
965 } DNDStuff;
967 WMPixmap*
968 getImage(WMScreen *scr, char *file)
970 char buffer[1000];
971 WMPixmap *pix;
973 sprintf(buffer, "../../WindowMaker/Icons/%s", file);
974 pix = WMCreatePixmapFromFile(scr, buffer);
976 return pix;
982 static void
983 iconMouseStuff(XEvent *event, void *cdata)
985 WMLabel *label = (WMLabel*)cdata;
986 DNDStuff *stuff = WMGetHangedData(label);
987 WMPoint where;
989 switch (event->type) {
990 case ButtonPress:
991 stuff->x = event->xbutton.x;
992 stuff->y = event->xbutton.y;
993 stuff->mouseDown = True;
994 break;
995 case ButtonRelease:
996 stuff->mouseDown = False;
997 break;
998 case MotionNotify:
999 if (!stuff->mouseDown)
1000 break;
1002 if (abs(stuff->x - event->xmotion.x)>4
1003 || abs(stuff->y - event->xmotion.y)>4) {
1005 where = WMGetViewScreenPosition(WMWidgetView(label));
1007 WMDragImageFromView(WMWidgetView(label),
1008 WMGetLabelImage(label),
1009 NULL, /* XXX */
1010 where,
1011 wmksize(stuff->x, stuff->y),
1012 event, True);
1014 break;
1019 static void
1020 endedDragImage(WMView *self, WMPixmap *image, WMPoint point, Bool deposited)
1022 DNDStuff *stuff = WMGetHangedData(WMWidgetOfView(self));
1024 if (deposited) {
1025 WMDestroyWidget(WMWidgetOfView(self));
1028 stuff->mouseDown = False;
1032 static WMData*
1033 fetchDragData(WMView *self, char *type)
1035 DNDStuff *stuff = WMGetHangedData(WMWidgetOfView(self));
1037 return WMCreateDataWithBytes(stuff->filename, strlen(stuff->filename)+1);
1041 WMDragSourceProcs dragSourceProcs = {
1042 NULL,
1043 NULL,
1044 endedDragImage,
1045 fetchDragData
1049 /************************/
1052 unsigned
1053 draggingEntered(WMView *self, WMDraggingInfo *info)
1055 return WDOperationCopy;
1059 unsigned
1060 draggingUpdated(WMView *self, WMDraggingInfo *info)
1062 return WDOperationCopy;
1066 void (*draggingExited)(WMView *self, WMDraggingInfo *info);
1068 char*
1069 prepareForDragOperation(WMView *self, WMDraggingInfo *info)
1071 return "application/X-WINGs-Bla";
1075 WMLabel* makeDraggableLabel(WMWidget *w, char *file, int x, int y);
1077 Bool
1078 performDragOperation(WMView *self, WMDraggingInfo *info, WMData *data)
1080 char *file = (char*)WMDataBytes(data);
1081 WMPoint pos;
1083 pos = WMGetDraggingInfoImageLocation(info);
1085 if (file!=NULL) {
1086 WMLabel *label;
1087 WMPoint pos2 = WMGetViewScreenPosition(self);
1090 label = makeDraggableLabel(WMWidgetOfView(self), file,
1091 pos.x-pos2.x, pos.y-pos2.y);
1092 WMRealizeWidget(label);
1093 WMMapWidget(label);
1097 return True;
1101 void
1102 concludeDragOperation(WMView *self, WMDraggingInfo *info)
1109 WMDragDestinationProcs dragDestProcs = {
1110 draggingEntered,
1111 draggingUpdated,
1112 NULL,
1113 prepareForDragOperation,
1114 performDragOperation,
1115 concludeDragOperation
1121 WMLabel*
1122 makeDraggableLabel(WMWidget *w, char *file, int x, int y)
1124 DNDStuff *stuff;
1125 WMLabel *label;
1126 WMPixmap *image = getImage(WMWidgetScreen(w), file);
1128 stuff = wmalloc(sizeof(DNDStuff));
1129 stuff->mouseDown = False;
1131 stuff->filename = wstrdup(file);
1133 label = WMCreateLabel(w);
1134 WMResizeWidget(label, 48, 48);
1135 WMMoveWidget(label, x, y);
1137 WMSetViewDragSourceProcs(WMWidgetView(label), &dragSourceProcs);
1139 WMHangData(label, stuff);
1141 WMCreateEventHandler(WMWidgetView(label),
1142 ButtonPressMask|ButtonReleaseMask|ButtonMotionMask,
1143 iconMouseStuff, label);
1146 if (image != NULL) {
1147 WMSetLabelImagePosition(label, WIPImageOnly);
1148 WMSetLabelImage(label, image);
1149 WMReleasePixmap(image);
1150 } else puts(file);
1152 return label;
1157 void
1158 testDragAndDrop(WMScreen *scr)
1160 WMWindow *win;
1161 WMFrame *frame;
1162 WMLabel *label;
1163 int i, j;
1164 DIR *dir;
1165 struct dirent *ent;
1166 char *types[] = {
1167 "application/X-WINGs-Bla",
1168 NULL
1171 windowCount++;
1173 win = WMCreateWindow(scr, "dragDrop");
1174 WMResizeWidget(win, 300, 300);
1175 WMSetWindowCloseAction(win, closeAction, NULL);
1176 WMSetWindowTitle(win, "Drag and Drop");
1179 frame = WMCreateFrame(win);
1180 WMSetFrameRelief(frame, WRSunken);
1181 WMResizeWidget(frame, 250, 250);
1182 WMMoveWidget(frame, 25, 25);
1184 WMRegisterViewForDraggedTypes(WMWidgetView(frame), types);
1185 WMSetViewDragDestinationProcs(WMWidgetView(frame), &dragDestProcs);
1187 dir = opendir("../../WindowMaker/Icons");
1188 if (!dir) {
1189 perror("../../WindowMaker/Icons");
1190 return;
1193 for (i = 0, j=0; j < 8; i++) {
1194 ent = readdir(dir);
1195 if (!ent)
1196 break;
1198 if (strstr(ent->d_name, ".xpm")==NULL) {
1199 continue;
1202 label = makeDraggableLabel(frame, ent->d_name,4+(j/4)*64, 4+(j%4)*64);
1204 j++;
1207 closedir(dir);
1209 WMMapSubwidgets(frame);
1211 WMMapSubwidgets(win);
1212 WMRealizeWidget(win);
1213 WMMapWidget(win);
1220 /*******************************************************************/
1223 void
1224 testUD()
1226 WMUserDefaults *defs;
1227 char str[32];
1229 defs = WMGetStandardUserDefaults();
1231 sprintf(str, "TEST DATA");
1232 puts(str);
1233 WMSetUDStringForKey(defs, str, "testKey");
1234 puts(str);
1239 main(int argc, char **argv)
1241 WMScreen *scr;
1242 WMPixmap *pixmap;
1245 /* Initialize the application */
1246 WMInitializeApplication("Test@eqweq_ewq$eqw", &argc, argv);
1248 testUD();
1251 * Open connection to the X display.
1253 dpy = XOpenDisplay("");
1255 if (!dpy) {
1256 puts("could not open display");
1257 exit(1);
1260 /* This is used to disable buffering of X protocol requests.
1261 * Do NOT use it unless when debugging. It will cause a major
1262 * slowdown in your application
1264 #if 1
1265 XSynchronize(dpy, True);
1266 #endif
1268 * Create screen descriptor.
1270 scr = WMCreateScreen(dpy, DefaultScreen(dpy));
1273 * Loads the logo of the application.
1275 pixmap = WMCreatePixmapFromFile(scr, "logo.xpm");
1278 * Makes the logo be used in standard dialog panels.
1280 WMSetApplicationIconPixmap(scr, pixmap); WMReleasePixmap(pixmap);
1283 * Do some test stuff.
1285 * Put the testSomething() function you want to test here.
1290 testDragAndDrop(scr);
1291 testText(scr);
1292 #if 0
1293 testColorPanel(scr);
1294 testScrollView(scr);
1295 testTabView(scr);
1296 testBox(scr);
1297 testText(scr);
1298 testList(scr);
1300 testProgressIndicator(scr);
1302 testColorWell(scr);
1304 testTextField(scr);
1306 testDragAndDrop(scr);
1307 testFontPanel(scr);
1309 testButton(scr);
1311 testFrame(scr);
1313 testSplitView(scr);
1315 testGradientButtons(scr);
1317 testOpenFilePanel(scr);
1319 testSlider(scr);
1320 testPullDown(scr);
1321 #endif
1323 * The main event loop.
1326 WMScreenMainLoop(scr);
1328 return 0;