doc update; don't use clip's inactive collors for arrows when collapsed
[wmaker-crm.git] / WINGs / Tests / wtest.c
blobfef031029dab95f6aa41caf1cb50d5e047b41d62
1 /*
2 * WINGs test application
3 */
5 #include <WINGs/WINGs.h>
7 #include <stdio.h>
8 #include <stdlib.h>
12 * You need to define this function to link any program to WINGs.
13 * (this is no longer required as there is a default abort handler in WINGs)
14 * This will be called when the application will be terminated because
15 * of a fatal error (only for memory allocation failures ATM).
17 void
18 wAbort()
20 exit(1);
26 Display *dpy;
28 int windowCount = 0;
30 void
31 closeAction(WMWidget *self, void *data)
33 WMDestroyWidget(self);
34 windowCount--;
35 printf("window closed, window count = %d\n", windowCount);
36 if (windowCount < 1)
37 exit(0);
41 void
42 testOpenFilePanel(WMScreen *scr)
44 WMOpenPanel *panel;
46 /* windowCount++; */
48 /* get the shared Open File panel */
49 panel = WMGetOpenPanel(scr);
51 WMRunModalFilePanelForDirectory(panel, NULL, "/usr/local", NULL, NULL);
53 /* free the panel to save some memory. Not needed otherwise. */
54 WMFreeFilePanel(WMGetOpenPanel(scr));
58 void
59 testFontPanel(WMScreen *scr)
61 WMFontPanel *panel;
63 /*windowCount++;*/
65 panel = WMGetFontPanel(scr);
67 WMShowFontPanel(panel);
69 /* WMFreeFontPanel(panel);*/
74 void
75 testFrame(WMScreen *scr)
77 WMWindow *win;
78 WMFrame *frame;
79 int i;
80 static char* titles[] = {
81 "AboveTop",
82 "AtTop",
83 "BelowTop",
84 "AboveBottom",
85 "AtBottom",
86 "BelowBottom"
88 static WMTitlePosition pos[] = {
89 WTPAboveTop,
90 WTPAtTop,
91 WTPBelowTop,
92 WTPAboveBottom,
93 WTPAtBottom,
94 WTPBelowBottom
97 windowCount++;
99 win = WMCreateWindow(scr, "testFrame");
100 WMSetWindowTitle(win, "Frame");
101 WMSetWindowCloseAction(win, closeAction, NULL);
102 WMResizeWidget(win, 400, 300);
104 for (i = 0; i < 6; i++) {
105 frame = WMCreateFrame(win);
106 WMMoveWidget(frame, 8+(i%3)*130, 8+(i/3)*130);
107 WMResizeWidget(frame, 120, 120);
108 WMSetFrameTitle(frame, titles[i]);
109 WMSetFrameTitlePosition(frame, pos[i]);
112 WMRealizeWidget(win);
113 WMMapSubwidgets(win);
114 WMMapWidget(win);
119 static void
120 resizedWindow(void *self, WMNotification *notif)
122 WMView *view = (WMView*)WMGetNotificationObject(notif);
123 WMSize size = WMGetViewSize(view);
125 WMResizeWidget((WMWidget*)self, size.width, size.height);
128 void
129 testBox(WMScreen *scr)
131 WMWindow *win;
132 WMBox *box, *hbox;
133 WMButton *btn;
134 WMPopUpButton *pop;
135 int i;
137 windowCount++;
139 win = WMCreateWindow(scr, "testBox");
140 WMSetWindowTitle(win, "Box");
141 WMSetWindowCloseAction(win, closeAction, NULL);
142 WMResizeWidget(win, 400, 300);
144 box = WMCreateBox(win);
145 WMSetBoxBorderWidth(box, 5);
146 WMSetViewExpandsToParent(WMWidgetView(box), 0, 0, 0, 0);
148 /*WMSetBoxHorizontal(box, True);*/
149 for (i = 0; i < 4; i++) {
150 btn = WMCreateCommandButton(box);
151 WMSetButtonText(btn, "bla");
152 WMMapWidget(btn);
153 WMAddBoxSubview(box, WMWidgetView(btn), i&1, True, 20, 0, 5);
156 pop = WMCreatePopUpButton(box);
157 WMAddPopUpButtonItem(pop, "ewqeq");
158 WMAddPopUpButtonItem(pop, "ewqeqrewrw");
159 WMAddBoxSubview(box, WMWidgetView(pop), False, True, 20, 0, 5);
160 WMMapWidget(pop);
162 hbox = WMCreateBox(box);
163 WMSetBoxHorizontal(hbox, True);
164 WMAddBoxSubview(box, WMWidgetView(hbox), False, True, 24, 0, 0);
165 WMMapWidget(hbox);
167 for (i = 0; i < 4; i++) {
168 btn = WMCreateCommandButton(hbox);
169 WMSetButtonText(btn, "bla");
170 WMMapWidget(btn);
171 WMAddBoxSubview(hbox, WMWidgetView(btn), 1, True, 60, 0, i<3?5:0);
175 WMRealizeWidget(win);
176 WMMapSubwidgets(win);
177 WMMapWidget(win);
183 static void
184 singleClick(WMWidget *self, void *data)
189 static void
190 doubleClick(WMWidget *self, void *data)
192 WMSelectAllListItems((WMList*)self);
196 static void
197 listSelectionObserver(void *observer, WMNotification *notification)
199 WMLabel *label = (WMLabel*)observer;
200 WMList *lPtr = (WMList*)WMGetNotificationObject(notification);
201 char buf[255];
203 sprintf(buf, "Selected items: %d",
204 WMGetArrayItemCount(WMGetListSelectedItems(lPtr)));
205 WMSetLabelText(label, buf);
209 void
210 testList(WMScreen *scr)
212 WMWindow *win;
213 WMList *list;
214 WMList *mlist;
215 WMLabel *label;
216 WMLabel *mlabel;
217 WMLabel *title;
218 WMLabel *mtitle;
219 char text[100];
220 int i;
222 windowCount++;
224 win = WMCreateWindow(scr, "testList");
225 WMResizeWidget(win, 370, 250);
226 WMSetWindowTitle(win, "List");
227 WMSetWindowCloseAction(win, closeAction, NULL);
229 title = WMCreateLabel(win);
230 WMResizeWidget(title, 150, 20);
231 WMMoveWidget(title, 10, 10);
232 WMSetLabelRelief(title, WRRidge);
233 WMSetLabelText(title, "Single selection list");
235 mtitle = WMCreateLabel(win);
236 WMResizeWidget(mtitle, 150, 20);
237 WMMoveWidget(mtitle, 210, 10);
238 WMSetLabelRelief(mtitle, WRRidge);
239 WMSetLabelText(mtitle, "Multiple selection list");
241 list = WMCreateList(win);
242 /*WMSetListAllowEmptySelection(list, True);*/
243 WMMoveWidget(list, 10, 40);
244 for (i=0; i<105; i++) {
245 sprintf(text, "Item %i", i);
246 WMAddListItem(list, text);
248 mlist = WMCreateList(win);
249 WMSetListAllowMultipleSelection(mlist, True);
250 /*WMSetListAllowEmptySelection(mlist, True);*/
251 WMMoveWidget(mlist, 210, 40);
252 for (i=0; i<135; i++) {
253 sprintf(text, "Item %i", i);
254 WMAddListItem(mlist, text);
257 label = WMCreateLabel(win);
258 WMResizeWidget(label, 150, 40);
259 WMMoveWidget(label, 10, 200);
260 WMSetLabelRelief(label, WRRidge);
261 WMSetLabelText(label, "Selected items: 0");
263 mlabel = WMCreateLabel(win);
264 WMResizeWidget(mlabel, 150, 40);
265 WMMoveWidget(mlabel, 210, 200);
266 WMSetLabelRelief(mlabel, WRRidge);
267 WMSetLabelText(mlabel, "Selected items: 0");
269 WMSetListAction(list, singleClick, label);
270 WMSetListDoubleAction(list, doubleClick, label);
271 WMSetListAction(mlist, singleClick, mlabel);
272 WMSetListDoubleAction(mlist, doubleClick, mlabel);
274 WMAddNotificationObserver(listSelectionObserver, label,
275 WMListSelectionDidChangeNotification, list);
276 WMAddNotificationObserver(listSelectionObserver, mlabel,
277 WMListSelectionDidChangeNotification, mlist);
280 WMRealizeWidget(win);
281 WMMapSubwidgets(win);
282 WMMapWidget(win);
286 void
287 testButton(WMScreen *scr)
289 WMWindow *win;
290 int i;
291 char *types[] = {
292 "MomentaryPush",
293 "PushOnPushOff",
294 "Toggle",
295 "Switch",
296 "Radio",
297 "MomentaryChange",
298 "OnOff",
299 "MomentaryLigh"
302 windowCount++;
304 win = WMCreateWindow(scr, "testButton");
305 WMResizeWidget(win, 300, 300);
306 WMSetWindowTitle(win, "Buttons");
308 WMSetWindowCloseAction(win, closeAction, NULL);
310 for (i = 1; i < 9; i++) {
311 WMButton *b;
312 b = WMCreateButton(win, i);
313 WMResizeWidget(b, 150, 24);
314 WMMoveWidget(b, 20, i*30);
315 WMSetButtonText(b, types[i-1]);
318 WMRealizeWidget(win);
319 WMMapSubwidgets(win);
320 WMMapWidget(win);
324 void
325 testGradientButtons(WMScreen *scr)
327 WMWindow *win;
328 WMButton *btn;
329 WMPixmap *pix1, *pix2;
330 RImage *back;
331 RColor light, dark;
332 WMColor *color, *altColor;
334 windowCount++;
336 /* creates the top-level window */
337 win = WMCreateWindow(scr, "testGradientButtons");
338 WMSetWindowTitle(win, "Gradiented Button Demo");
339 WMResizeWidget(win, 300, 200);
341 WMSetWindowCloseAction(win, closeAction, NULL);
344 light.red = 0x90;
345 light.green = 0x85;
346 light.blue = 0x90;
347 dark.red = 0x35;
348 dark.green = 0x30;
349 dark.blue = 0x35;
351 color = WMCreateRGBColor(scr, 0x5900, 0x5100, 0x5900, True);
352 WMSetWidgetBackgroundColor(win, color);
353 WMReleaseColor(color);
355 back = RRenderGradient(60, 24, &dark, &light, RGRD_DIAGONAL);
356 RBevelImage(back, RBEV_RAISED2);
357 pix1 = WMCreatePixmapFromRImage(scr, back, 0);
358 RReleaseImage(back);
360 back = RRenderGradient(60, 24, &dark, &light, RGRD_DIAGONAL);
361 RBevelImage(back, RBEV_SUNKEN);
362 pix2 = WMCreatePixmapFromRImage(scr, back, 0);
363 RReleaseImage(back);
365 color = WMWhiteColor(scr);
366 altColor = WMCreateNamedColor(scr, "red", True);
368 btn = WMCreateButton(win, WBTMomentaryChange);
369 WMResizeWidget(btn, 60, 24);
370 WMMoveWidget(btn, 20, 100);
371 WMSetButtonBordered(btn, False);
372 WMSetButtonImagePosition(btn, WIPOverlaps);
373 WMSetButtonImage(btn, pix1);
374 WMSetButtonAltImage(btn, pix2);
375 WMSetButtonText(btn, "Cool");
376 WMSetButtonTextColor(btn, color);
377 WMSetButtonAltTextColor(btn, altColor);
379 WMSetBalloonTextForView("This is a cool button", WMWidgetView(btn));
381 btn = WMCreateButton(win, WBTMomentaryChange);
382 WMResizeWidget(btn, 60, 24);
383 WMMoveWidget(btn, 90, 100);
384 WMSetButtonBordered(btn, False);
385 WMSetButtonImagePosition(btn, WIPOverlaps);
386 WMSetButtonImage(btn, pix1);
387 WMSetButtonAltImage(btn, pix2);
388 WMSetButtonText(btn, "Button");
389 WMSetButtonTextColor(btn, color);
391 WMSetBalloonTextForView("Este é outro balão.", WMWidgetView(btn));
393 WMReleaseColor(color);
394 color = WMCreateNamedColor(scr, "orange", True);
396 btn = WMCreateButton(win, WBTMomentaryChange);
397 WMResizeWidget(btn, 60, 24);
398 WMMoveWidget(btn, 160, 100);
399 WMSetButtonBordered(btn, False);
400 WMSetButtonImagePosition(btn, WIPOverlaps);
401 WMSetButtonImage(btn, pix1);
402 WMSetButtonAltImage(btn, pix2);
403 WMSetButtonText(btn, "Test");
404 WMSetButtonTextColor(btn, color);
406 WMSetBalloonTextForView("This is yet another button.\nBut the balloon has 3 lines.\nYay!",
407 WMWidgetView(btn));
409 WMReleaseColor(color);
410 WMReleaseColor(altColor);
412 WMRealizeWidget(win);
413 WMMapSubwidgets(win);
414 WMMapWidget(win);
418 void
419 testScrollView(WMScreen *scr)
421 WMWindow *win;
422 WMScrollView *sview;
423 WMFrame *f;
424 WMLabel *l;
425 char buffer[128];
426 int i;
428 windowCount++;
430 /* creates the top-level window */
431 win = WMCreateWindow(scr, "testScroll");
432 WMSetWindowTitle(win, "Scrollable View");
434 WMSetWindowCloseAction(win, closeAction, NULL);
436 /* set the window size */
437 WMResizeWidget(win, 300, 300);
439 /* creates a scrollable view inside the top-level window */
440 sview = WMCreateScrollView(win);
441 WMResizeWidget(sview, 200, 200);
442 WMMoveWidget(sview, 30, 30);
443 WMSetScrollViewRelief(sview, WRSunken);
444 WMSetScrollViewHasVerticalScroller(sview, True);
445 WMSetScrollViewHasHorizontalScroller(sview, True);
447 /* create a frame with a bunch of labels */
448 f = WMCreateFrame(win);
449 WMResizeWidget(f, 400, 400);
450 WMSetFrameRelief(f, WRFlat);
452 for (i=0; i<20; i++) {
453 l = WMCreateLabel(f);
454 WMResizeWidget(l, 50, 18);
455 WMMoveWidget(l, 10, 20*i);
456 sprintf(buffer, "Label %i", i);
457 WMSetLabelText(l, buffer);
458 WMSetLabelRelief(l, WRSimple);
460 WMMapSubwidgets(f);
461 WMMapWidget(f);
463 WMSetScrollViewContentView(sview, WMWidgetView(f));
465 /* make the windows of the widgets be actually created */
466 WMRealizeWidget(win);
468 /* Map all child widgets of the top-level be mapped.
469 * You must call this for each container widget (like frames),
470 * even if they are childs of the top-level window.
472 WMMapSubwidgets(win);
474 /* map the top-level window */
475 WMMapWidget(win);
479 void
480 testColorWell(WMScreen *scr)
482 WMWindow *win;
483 WMColorWell *well1, *well2;
485 windowCount++;
487 win = WMCreateWindow(scr, "testColor");
488 WMResizeWidget(win, 300, 300);
489 WMSetWindowCloseAction(win, closeAction, NULL);
491 well1 = WMCreateColorWell(win);
492 WMResizeWidget(well1, 60, 40);
493 WMMoveWidget(well1, 100, 100);
494 WMSetColorWellColor(well1, WMCreateRGBColor(scr, 0x8888, 0, 0x1111, True));
495 well2 = WMCreateColorWell(win);
496 WMResizeWidget(well2, 60, 40);
497 WMMoveWidget(well2, 200, 100);
498 WMSetColorWellColor(well2, WMCreateRGBColor(scr, 0, 0, 0x8888, True));
500 WMRealizeWidget(win);
501 WMMapSubwidgets(win);
502 WMMapWidget(win);
506 void
507 testColorPanel(WMScreen *scr)
509 WMColorPanel *panel = WMGetColorPanel(scr);
511 /*if (colorname) {
512 startcolor = WMCreateNamedColor(scr, colorname, False);
513 WMSetColorPanelColor(panel, startcolor);
514 WMReleaseColor(startcolor);
517 WMShowColorPanel(panel);
520 void
521 sliderCallback(WMWidget *w, void *data)
523 printf("SLIDER == %i\n", WMGetSliderValue(w));
527 void
528 testSlider(WMScreen *scr)
530 WMWindow *win;
531 WMSlider *s;
533 windowCount++;
535 win = WMCreateWindow(scr, "testSlider");
536 WMResizeWidget(win, 300, 300);
537 WMSetWindowTitle(win, "Sliders");
539 WMSetWindowCloseAction(win, closeAction, NULL);
541 s = WMCreateSlider(win);
542 WMResizeWidget(s, 16, 100);
543 WMMoveWidget(s, 100, 100);
544 WMSetSliderKnobThickness(s, 8);
545 WMSetSliderContinuous(s, False);
546 WMSetSliderAction(s, sliderCallback, s);
548 s = WMCreateSlider(win);
549 WMResizeWidget(s, 100, 16);
550 WMMoveWidget(s, 100, 10);
551 WMSetSliderKnobThickness(s, 8);
553 WMRealizeWidget(win);
554 WMMapSubwidgets(win);
555 WMMapWidget(win);
559 void
560 testTextField(WMScreen *scr)
562 WMWindow *win;
563 WMTextField *field, *field2;
565 windowCount++;
567 win = WMCreateWindow(scr, "testTextField");
568 WMResizeWidget(win, 400, 300);
570 WMSetWindowCloseAction(win, closeAction, NULL);
572 field = WMCreateTextField(win);
573 WMResizeWidget(field, 200, 20);
574 WMMoveWidget(field, 20, 20);
576 field2 = WMCreateTextField(win);
577 WMResizeWidget(field2, 200, 20);
578 WMMoveWidget(field2, 20, 50);
579 WMSetTextFieldAlignment(field2, WARight);
581 WMRealizeWidget(win);
582 WMMapSubwidgets(win);
583 WMMapWidget(win);
588 void
589 testText(WMScreen *scr)
591 WMWindow *win;
592 WMText *text;
593 FILE *file = fopen("wm.html", "rb");
595 windowCount++;
597 win = WMCreateWindow(scr, "testText");
598 WMResizeWidget(win, 500, 300);
600 WMSetWindowCloseAction(win, closeAction, NULL);
602 text = WMCreateText(win);
603 WMResizeWidget(text, 480, 280);
604 WMMoveWidget(text, 10, 10);
605 WMSetTextHasVerticalScroller(text, True);
606 WMSetTextEditable(text, False);
609 WMFont *font, *ifont;
611 font = WMDefaultSystemFont(scr);
612 ifont = WMCopyFontWithChanges(scr, font, WFAEmphasized);
613 if (ifont) {
614 WMSetTextDefaultFont(text, ifont);
615 WMReleaseFont(ifont);
616 } else {
617 WMSetTextDefaultFont(text, font);
619 WMReleaseFont(font);
622 if(file) {
623 char buf[1024];
625 WMFreezeText(text);
626 while(fgets(buf, 1023, file))
627 WMAppendTextStream(text, buf);
629 fclose(file);
630 WMThawText(text);
631 } else {
632 WMAppendTextStream(text,
633 "Window Maker is the GNU window manager for the "
634 "X Window System. It was designed to emulate the "
635 "look and feel of part of the NEXTSTEP(tm) GUI. Its "
636 "supposed to be relatively fast and small, feature "
637 "rich, easy to configure and easy to use, with a simple "
638 "and elegant appearance borrowed from NEXTSTEP(tm).");
641 WMRealizeWidget(win);
642 WMMapSubwidgets(win);
643 WMMapWidget(win);
647 void
648 testProgressIndicator(WMScreen *scr)
650 WMWindow *win;
651 WMProgressIndicator *pPtr;
653 windowCount++;
655 win = WMCreateWindow(scr, "testProgressIndicator");
656 WMResizeWidget(win, 292, 32);
658 WMSetWindowCloseAction(win, closeAction, NULL);
660 pPtr = WMCreateProgressIndicator(win);
661 WMMoveWidget(pPtr, 8, 8);
662 WMSetProgressIndicatorValue(pPtr, 75);
664 WMRealizeWidget(win);
665 WMMapSubwidgets(win);
666 WMMapWidget(win);
671 void
672 testPullDown(WMScreen *scr)
674 WMWindow *win;
675 WMPopUpButton *pop, *pop2;
677 windowCount++;
679 win = WMCreateWindow(scr, "pullDown");
680 WMResizeWidget(win, 400, 300);
682 WMSetWindowCloseAction(win, closeAction, NULL);
684 pop = WMCreatePopUpButton(win);
685 WMResizeWidget(pop, 100, 20);
686 WMMoveWidget(pop, 50, 60);
687 WMSetPopUpButtonPullsDown(pop, True);
688 WMSetPopUpButtonText(pop, "Commands");
689 WMAddPopUpButtonItem(pop, "Add");
690 WMAddPopUpButtonItem(pop, "Remove");
691 WMAddPopUpButtonItem(pop, "Check");
692 WMAddPopUpButtonItem(pop, "Eat");
694 pop2 = WMCreatePopUpButton(win);
695 WMResizeWidget(pop2, 100, 20);
696 WMMoveWidget(pop2, 200, 60);
697 WMSetPopUpButtonText(pop2, "Select");
698 WMAddPopUpButtonItem(pop2, "Apples");
699 WMAddPopUpButtonItem(pop2, "Bananas");
700 WMAddPopUpButtonItem(pop2, "Strawberries");
701 WMAddPopUpButtonItem(pop2, "Blueberries");
703 WMRealizeWidget(win);
704 WMMapSubwidgets(win);
705 WMMapWidget(win);
710 void
711 testTabView(WMScreen *scr)
713 WMWindow *win;
714 WMTabView *tabv;
715 WMTabViewItem *tab;
716 WMFrame *frame;
717 WMLabel *label;
719 windowCount++;
721 win = WMCreateWindow(scr, "testTabs");
722 WMResizeWidget(win, 400, 300);
724 WMSetWindowCloseAction(win, closeAction, NULL);
726 tabv = WMCreateTabView(win);
727 WMMoveWidget(tabv, 50, 50);
728 WMResizeWidget(tabv, 300, 200);
730 frame = WMCreateFrame(win);
731 WMSetFrameRelief(frame, WRFlat);
732 label = WMCreateLabel(frame);
733 WMResizeWidget(label, 100, 100);
734 WMSetLabelText(label, "Label 1");
735 WMMapWidget(label);
738 tab = WMCreateTabViewItemWithIdentifier(0);
739 WMSetTabViewItemView(tab, WMWidgetView(frame));
740 WMAddItemInTabView(tabv, tab);
741 WMSetTabViewItemLabel(tab, "Instances");
743 frame = WMCreateFrame(win);
744 WMSetFrameRelief(frame, WRFlat);
745 label = WMCreateLabel(frame);
746 WMResizeWidget(label, 40, 50);
747 WMSetLabelText(label, "Label 2");
748 WMMapWidget(label);
751 tab = WMCreateTabViewItemWithIdentifier(0);
752 WMSetTabViewItemView(tab, WMWidgetView(frame));
753 WMAddItemInTabView(tabv, tab);
754 WMSetTabViewItemLabel(tab, "Classes");
757 frame = WMCreateFrame(win);
758 WMSetFrameRelief(frame, WRFlat);
759 label = WMCreateLabel(frame);
760 WMResizeWidget(label, 100, 100);
761 WMMoveWidget(label, 60, 40);
762 WMSetLabelText(label, "Label 3");
763 WMMapWidget(label);
765 tab = WMCreateTabViewItemWithIdentifier(0);
766 WMSetTabViewItemView(tab, WMWidgetView(frame));
767 WMAddItemInTabView(tabv, tab);
768 WMSetTabViewItemLabel(tab, "Something");
771 frame = WMCreateFrame(win);
772 WMSetFrameRelief(frame, WRFlat);
773 label = WMCreateLabel(frame);
774 WMResizeWidget(label, 100, 100);
775 WMMoveWidget(label, 160, 40);
776 WMSetLabelText(label, "Label 4");
777 WMMapWidget(label);
779 tab = WMCreateTabViewItemWithIdentifier(0);
780 WMSetTabViewItemView(tab, WMWidgetView(frame));
781 WMAddItemInTabView(tabv, tab);
782 WMSetTabViewItemLabel(tab, "Bla!");
786 frame = WMCreateFrame(win);
787 WMSetFrameRelief(frame, WRFlat);
788 label = WMCreateLabel(frame);
789 WMResizeWidget(label, 100, 100);
790 WMMoveWidget(label, 160, 40);
791 WMSetLabelText(label, "Label fjweqklrj qwl");
792 WMMapWidget(label);
793 tab = WMCreateTabViewItemWithIdentifier(0);
794 WMSetTabViewItemView(tab, WMWidgetView(frame));
795 WMAddItemInTabView(tabv, tab);
796 WMSetTabViewItemLabel(tab, "Weee!");
799 WMRealizeWidget(win);
800 WMMapSubwidgets(win);
801 WMMapWidget(win);
805 void
806 splitViewConstrainProc(WMSplitView *sPtr, int indView,
807 int *minSize, int *maxSize)
809 switch (indView) {
810 case 0:
811 *minSize = 20;
812 break;
813 case 1:
814 *minSize = 40;
815 *maxSize = 80;
816 break;
817 case 2:
818 *maxSize = 60;
819 break;
820 default:
821 break;
826 static void
827 resizeSplitView(XEvent *event, void *data)
829 WMSplitView *sPtr = (WMSplitView*)data;
831 if (event->type == ConfigureNotify) {
832 int width = event->xconfigure.width - 10;
834 if (width < WMGetSplitViewDividerThickness(sPtr))
835 width = WMGetSplitViewDividerThickness(sPtr);
837 if (width != WMWidgetWidth(sPtr) ||
838 event->xconfigure.height != WMWidgetHeight(sPtr))
839 WMResizeWidget(sPtr, width, event->xconfigure.height - 55);
843 void
844 appendSubviewButtonAction(WMWidget *self, void *data)
846 WMSplitView *sPtr = (WMSplitView*)data;
847 char buf[64];
848 WMLabel *label = WMCreateLabel(sPtr);
850 sprintf(buf, "Subview %d", WMGetSplitViewSubviewsCount(sPtr) + 1);
851 WMSetLabelText(label, buf);
852 WMSetLabelRelief(label, WRSunken);
853 WMAddSplitViewSubview(sPtr, WMWidgetView(label));
854 WMRealizeWidget(label);
855 WMMapWidget(label);
858 void
859 removeSubviewButtonAction(WMWidget *self, void *data)
861 WMSplitView *sPtr = (WMSplitView*)data;
862 int count = WMGetSplitViewSubviewsCount(sPtr);
864 if (count > 2) {
865 WMView *view = WMGetSplitViewSubviewAt(sPtr, count-1);
866 WMDestroyWidget(WMWidgetOfView(view));
867 WMRemoveSplitViewSubviewAt(sPtr, count-1);
871 void
872 orientationButtonAction(WMWidget *self, void *data)
874 WMSplitView *sPtr = (WMSplitView*)data;
875 WMSetSplitViewVertical(sPtr, !WMGetSplitViewVertical(sPtr));
878 void
879 adjustSubviewsButtonAction(WMWidget *self, void *data)
881 WMAdjustSplitViewSubviews((WMSplitView*)data);
884 void
885 testSplitView(WMScreen *scr)
887 WMWindow *win;
888 WMSplitView *splitv1, *splitv2;
889 WMFrame *frame;
890 WMLabel *label;
891 WMButton *button;
893 windowCount++;
895 win = WMCreateWindow(scr, "testTabs");
896 WMResizeWidget(win, 300, 400);
897 WMSetWindowCloseAction(win, closeAction, NULL);
899 frame = WMCreateFrame(win);
900 WMSetFrameRelief(frame, WRSunken);
901 WMMoveWidget(frame, 5, 5);
902 WMResizeWidget(frame, 290, 40);
904 splitv1 = WMCreateSplitView(win);
905 WMMoveWidget(splitv1, 5, 50);
906 WMResizeWidget(splitv1, 290, 345);
907 WMSetSplitViewConstrainProc(splitv1, splitViewConstrainProc);
908 WMCreateEventHandler(WMWidgetView(win), StructureNotifyMask,
909 resizeSplitView, splitv1);
911 button = WMCreateCommandButton(frame);
912 WMSetButtonText(button, "+");
913 WMSetButtonAction(button, appendSubviewButtonAction, splitv1);
914 WMMoveWidget(button, 10, 8);
915 WMMapWidget(button);
917 button = WMCreateCommandButton(frame);
918 WMSetButtonText(button, "-");
919 WMSetButtonAction(button, removeSubviewButtonAction, splitv1);
920 WMMoveWidget(button, 80, 8);
921 WMMapWidget(button);
923 button = WMCreateCommandButton(frame);
924 WMSetButtonText(button, "=");
925 WMMoveWidget(button, 150, 8);
926 WMSetButtonAction(button, adjustSubviewsButtonAction, splitv1);
927 WMMapWidget(button);
929 button = WMCreateCommandButton(frame);
930 WMSetButtonText(button, "#");
931 WMMoveWidget(button, 220, 8);
932 WMSetButtonAction(button, orientationButtonAction, splitv1);
933 WMMapWidget(button);
935 label = WMCreateLabel(splitv1);
936 WMSetLabelText(label, "Subview 1");
937 WMSetLabelRelief(label, WRSunken);
938 WMMapWidget(label);
939 WMAddSplitViewSubview(splitv1, WMWidgetView(label));
941 splitv2 = WMCreateSplitView(splitv1);
942 WMResizeWidget(splitv2, 150, 150);
943 WMSetSplitViewVertical(splitv2, True);
945 label = WMCreateLabel(splitv2);
946 WMSetLabelText(label, "Subview 2.1");
947 WMSetLabelRelief(label, WRSunken);
948 WMMapWidget(label);
949 WMAddSplitViewSubview(splitv2, WMWidgetView(label));
951 label = WMCreateLabel(splitv2);
952 WMSetLabelText(label, "Subview 2.2");
953 WMSetLabelRelief(label, WRSunken);
954 WMMapWidget(label);
955 WMAddSplitViewSubview(splitv2, WMWidgetView(label));
957 label = WMCreateLabel(splitv2);
958 WMSetLabelText(label, "Subview 2.3");
959 WMSetLabelRelief(label, WRSunken);
960 WMMapWidget(label);
961 WMAddSplitViewSubview(splitv2, WMWidgetView(label));
963 WMMapWidget(splitv2);
964 WMAddSplitViewSubview(splitv1, WMWidgetView(splitv2));
966 WMRealizeWidget(win);
967 WMMapSubwidgets(win);
968 WMMapWidget(win);
972 /*******************************************************************/
974 #include <sys/types.h>
975 #include <dirent.h>
976 #include <string.h>
979 typedef struct {
980 int x, y;
981 Bool mouseDown;
982 char *filename;
983 } DNDStuff;
985 WMPixmap*
986 getImage(WMScreen *scr, char *file)
988 char buffer[1000];
989 WMPixmap *pix;
991 sprintf(buffer, "../../WindowMaker/Icons/%s", file);
992 pix = WMCreatePixmapFromFile(scr, buffer);
994 return pix;
1000 static void
1001 iconMouseStuff(XEvent *event, void *cdata)
1003 WMLabel *label = (WMLabel*)cdata;
1004 DNDStuff *stuff = WMGetHangedData(label);
1005 WMPoint where;
1007 switch (event->type) {
1008 case ButtonPress:
1009 stuff->x = event->xbutton.x;
1010 stuff->y = event->xbutton.y;
1011 stuff->mouseDown = True;
1012 break;
1013 case ButtonRelease:
1014 stuff->mouseDown = False;
1015 break;
1016 case MotionNotify:
1017 if (!stuff->mouseDown)
1018 break;
1020 if (abs(stuff->x - event->xmotion.x)>4
1021 || abs(stuff->y - event->xmotion.y)>4) {
1023 where = WMGetViewScreenPosition(WMWidgetView(label));
1025 WMDragImageFromView(WMWidgetView(label),
1026 WMGetLabelImage(label),
1027 NULL, /* XXX */
1028 where,
1029 wmksize(stuff->x, stuff->y),
1030 event, True);
1032 break;
1037 static void
1038 endedDragImage(WMView *self, WMPixmap *image, WMPoint point, Bool deposited)
1040 DNDStuff *stuff = WMGetHangedData(WMWidgetOfView(self));
1042 if (deposited) {
1043 WMDestroyWidget(WMWidgetOfView(self));
1046 stuff->mouseDown = False;
1050 static WMData*
1051 fetchDragData(WMView *self, char *type)
1053 DNDStuff *stuff = WMGetHangedData(WMWidgetOfView(self));
1055 return WMCreateDataWithBytes(stuff->filename, strlen(stuff->filename)+1);
1059 WMDragSourceProcs dragSourceProcs = {
1060 NULL,
1061 NULL,
1062 endedDragImage,
1063 fetchDragData
1067 /************************/
1070 unsigned
1071 draggingEntered(WMView *self, WMDraggingInfo *info)
1073 return WDOperationCopy;
1077 unsigned
1078 draggingUpdated(WMView *self, WMDraggingInfo *info)
1080 return WDOperationCopy;
1084 void (*draggingExited)(WMView *self, WMDraggingInfo *info);
1086 char*
1087 prepareForDragOperation(WMView *self, WMDraggingInfo *info)
1089 return "application/X-WINGs-Bla";
1093 WMLabel* makeDraggableLabel(WMWidget *w, char *file, int x, int y);
1095 Bool
1096 performDragOperation(WMView *self, WMDraggingInfo *info, WMData *data)
1098 char *file = (char*)WMDataBytes(data);
1099 WMPoint pos;
1101 pos = WMGetDraggingInfoImageLocation(info);
1103 if (file!=NULL) {
1104 WMLabel *label;
1105 WMPoint pos2 = WMGetViewScreenPosition(self);
1108 label = makeDraggableLabel(WMWidgetOfView(self), file,
1109 pos.x-pos2.x, pos.y-pos2.y);
1110 WMRealizeWidget(label);
1111 WMMapWidget(label);
1115 return True;
1119 void
1120 concludeDragOperation(WMView *self, WMDraggingInfo *info)
1127 WMDragDestinationProcs dragDestProcs = {
1128 draggingEntered,
1129 draggingUpdated,
1130 NULL,
1131 prepareForDragOperation,
1132 performDragOperation,
1133 concludeDragOperation
1139 WMLabel*
1140 makeDraggableLabel(WMWidget *w, char *file, int x, int y)
1142 DNDStuff *stuff;
1143 WMLabel *label;
1144 WMPixmap *image = getImage(WMWidgetScreen(w), file);
1146 stuff = wmalloc(sizeof(DNDStuff));
1147 stuff->mouseDown = False;
1149 stuff->filename = wstrdup(file);
1151 label = WMCreateLabel(w);
1152 WMResizeWidget(label, 48, 48);
1153 WMMoveWidget(label, x, y);
1155 WMSetViewDragSourceProcs(WMWidgetView(label), &dragSourceProcs);
1157 WMHangData(label, stuff);
1159 WMCreateEventHandler(WMWidgetView(label),
1160 ButtonPressMask|ButtonReleaseMask|ButtonMotionMask,
1161 iconMouseStuff, label);
1164 if (image != NULL) {
1165 WMSetLabelImagePosition(label, WIPImageOnly);
1166 WMSetLabelImage(label, image);
1167 WMReleasePixmap(image);
1168 } else puts(file);
1170 return label;
1175 void
1176 testDragAndDrop(WMScreen *scr)
1178 WMWindow *win;
1179 WMFrame *frame;
1180 WMLabel *label;
1181 int i, j;
1182 DIR *dir;
1183 struct dirent *ent;
1184 char *types[] = {
1185 "application/X-WINGs-Bla",
1186 NULL
1189 windowCount++;
1191 win = WMCreateWindow(scr, "dragDrop");
1192 WMResizeWidget(win, 300, 300);
1193 WMSetWindowCloseAction(win, closeAction, NULL);
1194 WMSetWindowTitle(win, "Drag and Drop");
1197 frame = WMCreateFrame(win);
1198 WMSetFrameRelief(frame, WRSunken);
1199 WMResizeWidget(frame, 250, 250);
1200 WMMoveWidget(frame, 25, 25);
1202 WMRegisterViewForDraggedTypes(WMWidgetView(frame), types);
1203 WMSetViewDragDestinationProcs(WMWidgetView(frame), &dragDestProcs);
1205 dir = opendir("../../WindowMaker/Icons");
1206 if (!dir) {
1207 perror("../../WindowMaker/Icons");
1208 return;
1211 for (i = 0, j=0; j < 8; i++) {
1212 ent = readdir(dir);
1213 if (!ent)
1214 break;
1216 if (strstr(ent->d_name, ".xpm")==NULL) {
1217 continue;
1220 label = makeDraggableLabel(frame, ent->d_name,4+(j/4)*64, 4+(j%4)*64);
1222 j++;
1225 closedir(dir);
1227 WMMapSubwidgets(frame);
1229 WMMapSubwidgets(win);
1230 WMRealizeWidget(win);
1231 WMMapWidget(win);
1238 /*******************************************************************/
1241 void
1242 testUD()
1244 WMUserDefaults *defs;
1245 char str[32];
1247 defs = WMGetStandardUserDefaults();
1249 sprintf(str, "TEST DATA");
1250 puts(str);
1251 WMSetUDStringForKey(defs, str, "testKey");
1252 puts(str);
1257 main(int argc, char **argv)
1259 WMScreen *scr;
1260 WMPixmap *pixmap;
1263 /* Initialize the application */
1264 WMInitializeApplication("Test@eqweq_ewq$eqw", &argc, argv);
1266 testUD();
1269 * Open connection to the X display.
1271 dpy = XOpenDisplay("");
1273 if (!dpy) {
1274 puts("could not open display");
1275 exit(1);
1278 /* This is used to disable buffering of X protocol requests.
1279 * Do NOT use it unless when debugging. It will cause a major
1280 * slowdown in your application
1282 #if 0
1283 XSynchronize(dpy, True);
1284 #endif
1286 * Create screen descriptor.
1288 scr = WMCreateScreen(dpy, DefaultScreen(dpy));
1291 * Loads the logo of the application.
1293 pixmap = WMCreatePixmapFromFile(scr, "logo.xpm");
1296 * Makes the logo be used in standard dialog panels.
1298 WMSetApplicationIconPixmap(scr, pixmap); WMReleasePixmap(pixmap);
1301 * Do some test stuff.
1303 * Put the testSomething() function you want to test here.
1307 testText(scr);
1308 testFontPanel(scr);
1311 #if 0
1312 testBox(scr);
1313 testButton(scr);
1314 testColorPanel(scr);
1315 testColorWell(scr);
1316 testDragAndDrop(scr);
1317 testFrame(scr);
1318 testGradientButtons(scr);
1319 testList(scr);
1320 testOpenFilePanel(scr);
1321 testProgressIndicator(scr);
1322 testPullDown(scr);
1323 testScrollView(scr);
1324 testSlider(scr);
1325 testSplitView(scr);
1326 testTabView(scr);
1327 testTextField(scr);
1328 #endif
1330 * The main event loop.
1333 WMScreenMainLoop(scr);
1335 return 0;