Moved color panel testing to wtest.c and removed testcolorpanel.c
[wmaker-crm.git] / WINGs / Tests / wtest.c
blobafedd6490df326c776689a4551f1e8271d866bc9
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 WMLabel *label = (WMLabel*)data;
198 WMList *lPtr = (WMList*)self;
199 char buf[255];
201 WMSelectAllListItems(lPtr);
205 static void
206 listSelectionObserver(void *observer, WMNotification *notification)
208 WMLabel *label = (WMLabel*)observer;
209 WMList *lPtr = (WMList*)WMGetNotificationObject(notification);
210 char buf[255];
212 sprintf(buf, "Selected items: %d",
213 WMGetArrayItemCount(WMGetListSelectedItems(lPtr)));
214 WMSetLabelText(label, buf);
218 void
219 testList(WMScreen *scr)
221 WMWindow *win;
222 WMList *list;
223 WMList *mlist;
224 WMLabel *label;
225 WMLabel *mlabel;
226 WMLabel *title;
227 WMLabel *mtitle;
228 char text[100];
229 int i;
231 windowCount++;
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);
291 WMMapWidget(win);
295 void
296 testButton(WMScreen *scr)
298 WMWindow *win;
299 int i;
300 char *types[] = {
301 "MomentaryPush",
302 "PushOnPushOff",
303 "Toggle",
304 "Switch",
305 "Radio",
306 "MomentaryChange",
307 "OnOff",
308 "MomentaryLigh"
311 windowCount++;
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++) {
320 WMButton *b;
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);
329 WMMapWidget(win);
333 void
334 testGradientButtons(WMScreen *scr)
336 WMWindow *win;
337 WMButton *btn;
338 WMPixmap *pix1, *pix2;
339 RImage *back;
340 RColor light, dark;
341 WMColor *color, *altColor;
343 windowCount++;
345 /* creates the top-level window */
346 win = WMCreateWindow(scr, "testGradientButtons");
347 WMSetWindowTitle(win, "Gradiented Button Demo");
348 WMResizeWidget(win, 300, 200);
350 light.red = 0x90;
351 light.green = 0x85;
352 light.blue = 0x90;
353 dark.red = 0x35;
354 dark.green = 0x30;
355 dark.blue = 0x35;
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);
364 RDestroyImage(back);
366 back = RRenderGradient(60, 24, &dark, &light, RGRD_DIAGONAL);
367 RBevelImage(back, RBEV_SUNKEN);
368 pix2 = WMCreatePixmapFromRImage(scr, back, 0);
369 RDestroyImage(back);
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!",
413 WMWidgetView(btn));
415 WMReleaseColor(color);
416 WMReleaseColor(altColor);
418 WMRealizeWidget(win);
419 WMMapSubwidgets(win);
420 WMMapWidget(win);
424 void
425 testScrollView(WMScreen *scr)
427 WMWindow *win;
428 WMScrollView *sview;
429 WMFrame *f;
430 WMLabel *l;
431 char buffer[128];
432 int i;
434 windowCount++;
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);
466 WMMapSubwidgets(f);
467 WMMapWidget(f);
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 */
481 WMMapWidget(win);
485 void
486 testColorWell(WMScreen *scr)
488 WMWindow *win;
489 WMColorWell *well1, *well2;
491 windowCount++;
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);
508 WMMapWidget(win);
512 void
513 testColorPanel(WMScreen *scr)
515 WMColorPanel *panel = WMGetColorPanel(scr);
517 /*if (colorname) {
518 startcolor = WMCreateNamedColor(scr, colorname, False);
519 WMSetColorPanelColor(panel, startcolor);
520 WMReleaseColor(startcolor);
523 WMShowColorPanel(panel);
526 void
527 sliderCallback(WMWidget *w, void *data)
529 printf("SLIDER == %i\n", WMGetSliderValue(w));
533 void
534 testSlider(WMScreen *scr)
536 WMWindow *win;
537 WMSlider *s;
539 windowCount++;
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);
561 WMMapWidget(win);
565 void
566 testTextField(WMScreen *scr)
568 WMWindow *win;
569 WMTextField *field, *field2;
571 windowCount++;
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);
589 WMMapWidget(win);
594 void
595 testText(WMScreen *scr)
597 WMWindow *win;
598 WMText *text;
599 FILE *file = fopen("wm.html", "r");
601 windowCount++;
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);
614 if(file) {
615 char buf[1024];
617 WMFreezeText(text);
618 while(fgets(buf, 1023, file))
619 WMAppendTextStream(text, buf);
621 fclose(file);
622 WMThawText(text);
623 } else {
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);
635 WMMapWidget(win);
639 void
640 testProgressIndicator(WMScreen *scr)
642 WMWindow *win;
643 WMProgressIndicator *pPtr;
645 windowCount++;
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);
658 WMMapWidget(win);
663 void
664 testPullDown(WMScreen *scr)
666 WMWindow *win;
667 WMPopUpButton *pop, *pop2;
669 windowCount++;
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);
697 WMMapWidget(win);
702 void
703 testTabView(WMScreen *scr)
705 WMWindow *win;
706 WMTabView *tabv;
707 WMTabViewItem *tab;
708 WMFrame *frame;
709 WMLabel *label;
711 windowCount++;
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");
727 WMMapWidget(label);
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");
740 WMMapWidget(label);
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");
755 WMMapWidget(label);
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");
769 WMMapWidget(label);
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");
784 WMMapWidget(label);
785 tab = WMCreateTabViewItemWithIdentifier(0);
786 WMSetTabViewItemView(tab, WMWidgetView(frame));
787 WMAddItemInTabView(tabv, tab);
788 WMSetTabViewItemLabel(tab, "Weee!");
791 WMRealizeWidget(win);
792 WMMapSubwidgets(win);
793 WMMapWidget(win);
797 void
798 splitViewConstrainProc(WMSplitView *sPtr, int indView,
799 int *minSize, int *maxSize)
801 switch (indView) {
802 case 0:
803 *minSize = 20;
804 break;
805 case 1:
806 *minSize = 40;
807 *maxSize = 80;
808 break;
809 case 2:
810 *maxSize = 60;
811 break;
812 default:
813 break;
818 static void
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);
835 void
836 appendSubviewButtonAction(WMWidget *self, void *data)
838 WMSplitView *sPtr = (WMSplitView*)data;
839 char buf[64];
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);
847 WMMapWidget(label);
850 void
851 removeSubviewButtonAction(WMWidget *self, void *data)
853 WMSplitView *sPtr = (WMSplitView*)data;
854 int count = WMGetSplitViewSubviewsCount(sPtr);
856 if (count > 2) {
857 WMView *view = WMGetSplitViewSubviewAt(sPtr, count-1);
858 WMDestroyWidget(WMWidgetOfView(view));
859 WMRemoveSplitViewSubviewAt(sPtr, count-1);
863 void
864 orientationButtonAction(WMWidget *self, void *data)
866 WMSplitView *sPtr = (WMSplitView*)data;
867 WMSetSplitViewVertical(sPtr, !WMGetSplitViewVertical(sPtr));
870 void
871 adjustSubviewsButtonAction(WMWidget *self, void *data)
873 WMAdjustSplitViewSubviews((WMSplitView*)data);
876 void
877 testSplitView(WMScreen *scr)
879 WMWindow *win;
880 WMSplitView *splitv1, *splitv2;
881 WMFrame *frame;
882 WMLabel *label;
883 WMButton *button;
885 windowCount++;
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);
907 WMMapWidget(button);
909 button = WMCreateCommandButton(frame);
910 WMSetButtonText(button, "-");
911 WMSetButtonAction(button, removeSubviewButtonAction, splitv1);
912 WMMoveWidget(button, 80, 8);
913 WMMapWidget(button);
915 button = WMCreateCommandButton(frame);
916 WMSetButtonText(button, "=");
917 WMMoveWidget(button, 150, 8);
918 WMSetButtonAction(button, adjustSubviewsButtonAction, splitv1);
919 WMMapWidget(button);
921 button = WMCreateCommandButton(frame);
922 WMSetButtonText(button, "#");
923 WMMoveWidget(button, 220, 8);
924 WMSetButtonAction(button, orientationButtonAction, splitv1);
925 WMMapWidget(button);
927 label = WMCreateLabel(splitv1);
928 WMSetLabelText(label, "Subview 1");
929 WMSetLabelRelief(label, WRSunken);
930 WMMapWidget(label);
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);
940 WMMapWidget(label);
941 WMAddSplitViewSubview(splitv2, WMWidgetView(label));
943 label = WMCreateLabel(splitv2);
944 WMSetLabelText(label, "Subview 2.2");
945 WMSetLabelRelief(label, WRSunken);
946 WMMapWidget(label);
947 WMAddSplitViewSubview(splitv2, WMWidgetView(label));
949 label = WMCreateLabel(splitv2);
950 WMSetLabelText(label, "Subview 2.3");
951 WMSetLabelRelief(label, WRSunken);
952 WMMapWidget(label);
953 WMAddSplitViewSubview(splitv2, WMWidgetView(label));
955 WMMapWidget(splitv2);
956 WMAddSplitViewSubview(splitv1, WMWidgetView(splitv2));
958 WMRealizeWidget(win);
959 WMMapSubwidgets(win);
960 WMMapWidget(win);
964 /*******************************************************************/
966 #include <sys/types.h>
967 #include <dirent.h>
968 #include <string.h>
971 typedef struct {
972 int x, y;
973 Bool mouseDown;
974 char *filename;
975 } DNDStuff;
977 WMPixmap*
978 getImage(WMScreen *scr, char *file)
980 char buffer[1000];
981 WMPixmap *pix;
983 sprintf(buffer, "../../WindowMaker/Icons/%s", file);
984 pix = WMCreatePixmapFromFile(scr, buffer);
986 return pix;
992 static void
993 iconMouseStuff(XEvent *event, void *cdata)
995 WMLabel *label = (WMLabel*)cdata;
996 DNDStuff *stuff = WMGetHangedData(label);
997 WMPoint where;
999 switch (event->type) {
1000 case ButtonPress:
1001 stuff->x = event->xbutton.x;
1002 stuff->y = event->xbutton.y;
1003 stuff->mouseDown = True;
1004 break;
1005 case ButtonRelease:
1006 stuff->mouseDown = False;
1007 break;
1008 case MotionNotify:
1009 if (!stuff->mouseDown)
1010 break;
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),
1019 NULL, /* XXX */
1020 where,
1021 wmksize(stuff->x, stuff->y),
1022 event, True);
1024 break;
1029 static void
1030 endedDragImage(WMView *self, WMPixmap *image, WMPoint point, Bool deposited)
1032 DNDStuff *stuff = WMGetHangedData(WMWidgetOfView(self));
1034 if (deposited) {
1035 WMDestroyWidget(WMWidgetOfView(self));
1038 stuff->mouseDown = False;
1042 static WMData*
1043 fetchDragData(WMView *self, char *type)
1045 DNDStuff *stuff = WMGetHangedData(WMWidgetOfView(self));
1047 return WMCreateDataWithBytes(stuff->filename, strlen(stuff->filename)+1);
1051 WMDragSourceProcs dragSourceProcs = {
1052 NULL,
1053 NULL,
1054 endedDragImage,
1055 fetchDragData
1059 /************************/
1062 unsigned
1063 draggingEntered(WMView *self, WMDraggingInfo *info)
1065 return WDOperationCopy;
1069 unsigned
1070 draggingUpdated(WMView *self, WMDraggingInfo *info)
1072 return WDOperationCopy;
1076 void (*draggingExited)(WMView *self, WMDraggingInfo *info);
1078 char*
1079 prepareForDragOperation(WMView *self, WMDraggingInfo *info)
1081 return "application/X-WINGs-Bla";
1085 WMLabel* makeDraggableLabel(WMWidget *w, char *file, int x, int y);
1087 Bool
1088 performDragOperation(WMView *self, WMDraggingInfo *info, WMData *data)
1090 char *file = (char*)WMDataBytes(data);
1091 WMPoint pos;
1093 pos = WMGetDraggingInfoImageLocation(info);
1095 if (file!=NULL) {
1096 WMLabel *label;
1097 WMPoint pos2 = WMGetViewScreenPosition(self);
1100 label = makeDraggableLabel(WMWidgetOfView(self), file,
1101 pos.x-pos2.x, pos.y-pos2.y);
1102 WMRealizeWidget(label);
1103 WMMapWidget(label);
1107 return True;
1111 void
1112 concludeDragOperation(WMView *self, WMDraggingInfo *info)
1119 WMDragDestinationProcs dragDestProcs = {
1120 draggingEntered,
1121 draggingUpdated,
1122 NULL,
1123 prepareForDragOperation,
1124 performDragOperation,
1125 concludeDragOperation
1131 WMLabel*
1132 makeDraggableLabel(WMWidget *w, char *file, int x, int y)
1134 DNDStuff *stuff;
1135 WMLabel *label;
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);
1160 } else puts(file);
1162 return label;
1167 void
1168 testDragAndDrop(WMScreen *scr)
1170 WMWindow *win;
1171 WMFrame *frame;
1172 WMLabel *label;
1173 int i, j;
1174 DIR *dir;
1175 struct dirent *ent;
1176 char *types[] = {
1177 "application/X-WINGs-Bla",
1178 NULL
1181 windowCount++;
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");
1198 if (!dir) {
1199 perror("../../WindowMaker/Icons");
1200 return;
1203 for (i = 0, j=0; j < 8; i++) {
1204 ent = readdir(dir);
1205 if (!ent)
1206 break;
1208 if (strstr(ent->d_name, ".xpm")==NULL) {
1209 continue;
1212 label = makeDraggableLabel(frame, ent->d_name,4+(j/4)*64, 4+(j%4)*64);
1214 j++;
1217 closedir(dir);
1219 WMMapSubwidgets(frame);
1221 WMMapSubwidgets(win);
1222 WMRealizeWidget(win);
1223 WMMapWidget(win);
1230 /*******************************************************************/
1233 void
1234 testUD()
1236 WMUserDefaults *defs;
1237 char str[32];
1239 defs = WMGetStandardUserDefaults();
1241 sprintf(str, "TEST DATA");
1242 puts(str);
1243 WMSetUDStringForKey(defs, str, "testKey");
1244 puts(str);
1249 main(int argc, char **argv)
1251 WMScreen *scr;
1252 WMPixmap *pixmap;
1255 /* Initialize the application */
1256 WMInitializeApplication("Test@eqweq_ewq$eqw", &argc, argv);
1258 testUD();
1261 * Open connection to the X display.
1263 dpy = XOpenDisplay("");
1265 if (!dpy) {
1266 puts("could not open display");
1267 exit(1);
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
1274 #if 1
1275 XSynchronize(dpy, True);
1276 #endif
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);
1301 #if 0
1302 testColorPanel(scr);
1303 testScrollView(scr);
1304 testTabView(scr);
1305 testBox(scr);
1306 testText(scr);
1307 testList(scr);
1309 testProgressIndicator(scr);
1311 testColorWell(scr);
1313 testTextField(scr);
1315 testDragAndDrop(scr);
1316 testFontPanel(scr);
1318 testButton(scr);
1320 testFrame(scr);
1326 testSplitView(scr);
1328 testGradientButtons(scr);
1331 testOpenFilePanel(scr);
1333 testSlider(scr);
1334 testPullDown(scr);
1335 #endif
1337 * The main event loop.
1340 WMScreenMainLoop(scr);
1342 return 0;