- added WMCopyFontWithChanges() a more generic and powerful function, meant
[wmaker-crm.git] / WINGs / Tests / wtest.c
blobac0268a8cf6f771bae60b7b3dbb1ed42af0194f9
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 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<105; 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 WMSetWindowCloseAction(win, closeAction, NULL);
343 light.red = 0x90;
344 light.green = 0x85;
345 light.blue = 0x90;
346 dark.red = 0x35;
347 dark.green = 0x30;
348 dark.blue = 0x35;
350 color = WMCreateRGBColor(scr, 0x5900, 0x5100, 0x5900, True);
351 WMSetWidgetBackgroundColor(win, color);
352 WMReleaseColor(color);
354 back = RRenderGradient(60, 24, &dark, &light, RGRD_DIAGONAL);
355 RBevelImage(back, RBEV_RAISED2);
356 pix1 = WMCreatePixmapFromRImage(scr, back, 0);
357 RReleaseImage(back);
359 back = RRenderGradient(60, 24, &dark, &light, RGRD_DIAGONAL);
360 RBevelImage(back, RBEV_SUNKEN);
361 pix2 = WMCreatePixmapFromRImage(scr, back, 0);
362 RReleaseImage(back);
364 color = WMWhiteColor(scr);
365 altColor = WMCreateNamedColor(scr, "red", True);
367 btn = WMCreateButton(win, WBTMomentaryChange);
368 WMResizeWidget(btn, 60, 24);
369 WMMoveWidget(btn, 20, 100);
370 WMSetButtonBordered(btn, False);
371 WMSetButtonImagePosition(btn, WIPOverlaps);
372 WMSetButtonImage(btn, pix1);
373 WMSetButtonAltImage(btn, pix2);
374 WMSetButtonText(btn, "Cool");
375 WMSetButtonTextColor(btn, color);
376 WMSetButtonAltTextColor(btn, altColor);
378 WMSetBalloonTextForView("This is a cool button", WMWidgetView(btn));
380 btn = WMCreateButton(win, WBTMomentaryChange);
381 WMResizeWidget(btn, 60, 24);
382 WMMoveWidget(btn, 90, 100);
383 WMSetButtonBordered(btn, False);
384 WMSetButtonImagePosition(btn, WIPOverlaps);
385 WMSetButtonImage(btn, pix1);
386 WMSetButtonAltImage(btn, pix2);
387 WMSetButtonText(btn, "Button");
388 WMSetButtonTextColor(btn, color);
390 WMSetBalloonTextForView("Este é outro balão.", WMWidgetView(btn));
392 WMReleaseColor(color);
393 color = WMCreateNamedColor(scr, "orange", True);
395 btn = WMCreateButton(win, WBTMomentaryChange);
396 WMResizeWidget(btn, 60, 24);
397 WMMoveWidget(btn, 160, 100);
398 WMSetButtonBordered(btn, False);
399 WMSetButtonImagePosition(btn, WIPOverlaps);
400 WMSetButtonImage(btn, pix1);
401 WMSetButtonAltImage(btn, pix2);
402 WMSetButtonText(btn, "Test");
403 WMSetButtonTextColor(btn, color);
405 WMSetBalloonTextForView("This is yet another button.\nBut the balloon has 3 lines.\nYay!",
406 WMWidgetView(btn));
408 WMReleaseColor(color);
409 WMReleaseColor(altColor);
411 WMRealizeWidget(win);
412 WMMapSubwidgets(win);
413 WMMapWidget(win);
417 void
418 testScrollView(WMScreen *scr)
420 WMWindow *win;
421 WMScrollView *sview;
422 WMFrame *f;
423 WMLabel *l;
424 char buffer[128];
425 int i;
427 windowCount++;
429 /* creates the top-level window */
430 win = WMCreateWindow(scr, "testScroll");
431 WMSetWindowTitle(win, "Scrollable View");
433 WMSetWindowCloseAction(win, closeAction, NULL);
435 /* set the window size */
436 WMResizeWidget(win, 300, 300);
438 /* creates a scrollable view inside the top-level window */
439 sview = WMCreateScrollView(win);
440 WMResizeWidget(sview, 200, 200);
441 WMMoveWidget(sview, 30, 30);
442 WMSetScrollViewRelief(sview, WRSunken);
443 WMSetScrollViewHasVerticalScroller(sview, True);
444 WMSetScrollViewHasHorizontalScroller(sview, True);
446 /* create a frame with a bunch of labels */
447 f = WMCreateFrame(win);
448 WMResizeWidget(f, 400, 400);
449 WMSetFrameRelief(f, WRFlat);
451 for (i=0; i<20; i++) {
452 l = WMCreateLabel(f);
453 WMResizeWidget(l, 50, 18);
454 WMMoveWidget(l, 10, 20*i);
455 sprintf(buffer, "Label %i", i);
456 WMSetLabelText(l, buffer);
457 WMSetLabelRelief(l, WRSimple);
459 WMMapSubwidgets(f);
460 WMMapWidget(f);
462 WMSetScrollViewContentView(sview, WMWidgetView(f));
464 /* make the windows of the widgets be actually created */
465 WMRealizeWidget(win);
467 /* Map all child widgets of the top-level be mapped.
468 * You must call this for each container widget (like frames),
469 * even if they are childs of the top-level window.
471 WMMapSubwidgets(win);
473 /* map the top-level window */
474 WMMapWidget(win);
478 void
479 testColorWell(WMScreen *scr)
481 WMWindow *win;
482 WMColorWell *well1, *well2;
484 windowCount++;
486 win = WMCreateWindow(scr, "testColor");
487 WMResizeWidget(win, 300, 300);
488 WMSetWindowCloseAction(win, closeAction, NULL);
490 well1 = WMCreateColorWell(win);
491 WMResizeWidget(well1, 60, 40);
492 WMMoveWidget(well1, 100, 100);
493 WMSetColorWellColor(well1, WMCreateRGBColor(scr, 0x8888, 0, 0x1111, True));
494 well2 = WMCreateColorWell(win);
495 WMResizeWidget(well2, 60, 40);
496 WMMoveWidget(well2, 200, 100);
497 WMSetColorWellColor(well2, WMCreateRGBColor(scr, 0, 0, 0x8888, True));
499 WMRealizeWidget(win);
500 WMMapSubwidgets(win);
501 WMMapWidget(win);
505 void
506 testColorPanel(WMScreen *scr)
508 WMColorPanel *panel = WMGetColorPanel(scr);
510 /*if (colorname) {
511 startcolor = WMCreateNamedColor(scr, colorname, False);
512 WMSetColorPanelColor(panel, startcolor);
513 WMReleaseColor(startcolor);
516 WMShowColorPanel(panel);
519 void
520 sliderCallback(WMWidget *w, void *data)
522 printf("SLIDER == %i\n", WMGetSliderValue(w));
526 void
527 testSlider(WMScreen *scr)
529 WMWindow *win;
530 WMSlider *s;
532 windowCount++;
534 win = WMCreateWindow(scr, "testSlider");
535 WMResizeWidget(win, 300, 300);
536 WMSetWindowTitle(win, "Sliders");
538 WMSetWindowCloseAction(win, closeAction, NULL);
540 s = WMCreateSlider(win);
541 WMResizeWidget(s, 16, 100);
542 WMMoveWidget(s, 100, 100);
543 WMSetSliderKnobThickness(s, 8);
544 WMSetSliderContinuous(s, False);
545 WMSetSliderAction(s, sliderCallback, s);
547 s = WMCreateSlider(win);
548 WMResizeWidget(s, 100, 16);
549 WMMoveWidget(s, 100, 10);
550 WMSetSliderKnobThickness(s, 8);
552 WMRealizeWidget(win);
553 WMMapSubwidgets(win);
554 WMMapWidget(win);
558 void
559 testTextField(WMScreen *scr)
561 WMWindow *win;
562 WMTextField *field, *field2;
564 windowCount++;
566 win = WMCreateWindow(scr, "testTextField");
567 WMResizeWidget(win, 400, 300);
569 WMSetWindowCloseAction(win, closeAction, NULL);
571 field = WMCreateTextField(win);
572 WMResizeWidget(field, 200, 20);
573 WMMoveWidget(field, 20, 20);
575 field2 = WMCreateTextField(win);
576 WMResizeWidget(field2, 200, 20);
577 WMMoveWidget(field2, 20, 50);
578 WMSetTextFieldAlignment(field2, WARight);
580 WMRealizeWidget(win);
581 WMMapSubwidgets(win);
582 WMMapWidget(win);
587 void
588 testText(WMScreen *scr)
590 WMWindow *win;
591 WMText *text;
592 FILE *file = fopen("wm.html", "rb");
594 windowCount++;
596 win = WMCreateWindow(scr, "testText");
597 WMResizeWidget(win, 500, 300);
599 WMSetWindowCloseAction(win, closeAction, NULL);
601 text = WMCreateText(win);
602 WMResizeWidget(text, 480, 280);
603 WMMoveWidget(text, 10, 10);
604 WMSetTextHasVerticalScroller(text, True);
605 WMSetTextEditable(text, False);
607 if (1) {
608 WMFont *font, *ifont;
610 font = WMDefaultSystemFont(scr);
611 ifont = WMCopyFontWithChanges(scr, font, WFAEmphasized);
612 WMSetTextDefaultFont(text, ifont);
613 WMReleaseFont(font);
614 WMReleaseFont(ifont);
617 if(file) {
618 char buf[1024];
620 WMFreezeText(text);
621 while(fgets(buf, 1023, file))
622 WMAppendTextStream(text, buf);
624 fclose(file);
625 WMThawText(text);
626 } else {
627 WMAppendTextStream(text,
628 "Window Maker is the GNU window manager for the "
629 "X Window System. It was designed to emulate the "
630 "look and feel of part of the NEXTSTEP(tm) GUI. Its "
631 "supposed to be relatively fast and small, feature "
632 "rich, easy to configure and easy to use, with a simple "
633 "and elegant appearance borrowed from NEXTSTEP(tm).");
636 WMRealizeWidget(win);
637 WMMapSubwidgets(win);
638 WMMapWidget(win);
642 void
643 testProgressIndicator(WMScreen *scr)
645 WMWindow *win;
646 WMProgressIndicator *pPtr;
648 windowCount++;
650 win = WMCreateWindow(scr, "testProgressIndicator");
651 WMResizeWidget(win, 292, 32);
653 WMSetWindowCloseAction(win, closeAction, NULL);
655 pPtr = WMCreateProgressIndicator(win);
656 WMMoveWidget(pPtr, 8, 8);
657 WMSetProgressIndicatorValue(pPtr, 75);
659 WMRealizeWidget(win);
660 WMMapSubwidgets(win);
661 WMMapWidget(win);
666 void
667 testPullDown(WMScreen *scr)
669 WMWindow *win;
670 WMPopUpButton *pop, *pop2;
672 windowCount++;
674 win = WMCreateWindow(scr, "pullDown");
675 WMResizeWidget(win, 400, 300);
677 WMSetWindowCloseAction(win, closeAction, NULL);
679 pop = WMCreatePopUpButton(win);
680 WMResizeWidget(pop, 100, 20);
681 WMMoveWidget(pop, 50, 60);
682 WMSetPopUpButtonPullsDown(pop, True);
683 WMSetPopUpButtonText(pop, "Commands");
684 WMAddPopUpButtonItem(pop, "Add");
685 WMAddPopUpButtonItem(pop, "Remove");
686 WMAddPopUpButtonItem(pop, "Check");
687 WMAddPopUpButtonItem(pop, "Eat");
689 pop2 = WMCreatePopUpButton(win);
690 WMResizeWidget(pop2, 100, 20);
691 WMMoveWidget(pop2, 200, 60);
692 WMSetPopUpButtonText(pop2, "Select");
693 WMAddPopUpButtonItem(pop2, "Apples");
694 WMAddPopUpButtonItem(pop2, "Bananas");
695 WMAddPopUpButtonItem(pop2, "Strawberries");
696 WMAddPopUpButtonItem(pop2, "Blueberries");
698 WMRealizeWidget(win);
699 WMMapSubwidgets(win);
700 WMMapWidget(win);
705 void
706 testTabView(WMScreen *scr)
708 WMWindow *win;
709 WMTabView *tabv;
710 WMTabViewItem *tab;
711 WMFrame *frame;
712 WMLabel *label;
714 windowCount++;
716 win = WMCreateWindow(scr, "testTabs");
717 WMResizeWidget(win, 400, 300);
719 WMSetWindowCloseAction(win, closeAction, NULL);
721 tabv = WMCreateTabView(win);
722 WMMoveWidget(tabv, 50, 50);
723 WMResizeWidget(tabv, 300, 200);
725 frame = WMCreateFrame(win);
726 WMSetFrameRelief(frame, WRFlat);
727 label = WMCreateLabel(frame);
728 WMResizeWidget(label, 100, 100);
729 WMSetLabelText(label, "Label 1");
730 WMMapWidget(label);
733 tab = WMCreateTabViewItemWithIdentifier(0);
734 WMSetTabViewItemView(tab, WMWidgetView(frame));
735 WMAddItemInTabView(tabv, tab);
736 WMSetTabViewItemLabel(tab, "Instances");
738 frame = WMCreateFrame(win);
739 WMSetFrameRelief(frame, WRFlat);
740 label = WMCreateLabel(frame);
741 WMResizeWidget(label, 40, 50);
742 WMSetLabelText(label, "Label 2");
743 WMMapWidget(label);
746 tab = WMCreateTabViewItemWithIdentifier(0);
747 WMSetTabViewItemView(tab, WMWidgetView(frame));
748 WMAddItemInTabView(tabv, tab);
749 WMSetTabViewItemLabel(tab, "Classes");
752 frame = WMCreateFrame(win);
753 WMSetFrameRelief(frame, WRFlat);
754 label = WMCreateLabel(frame);
755 WMResizeWidget(label, 100, 100);
756 WMMoveWidget(label, 60, 40);
757 WMSetLabelText(label, "Label 3");
758 WMMapWidget(label);
760 tab = WMCreateTabViewItemWithIdentifier(0);
761 WMSetTabViewItemView(tab, WMWidgetView(frame));
762 WMAddItemInTabView(tabv, tab);
763 WMSetTabViewItemLabel(tab, "Something");
766 frame = WMCreateFrame(win);
767 WMSetFrameRelief(frame, WRFlat);
768 label = WMCreateLabel(frame);
769 WMResizeWidget(label, 100, 100);
770 WMMoveWidget(label, 160, 40);
771 WMSetLabelText(label, "Label 4");
772 WMMapWidget(label);
774 tab = WMCreateTabViewItemWithIdentifier(0);
775 WMSetTabViewItemView(tab, WMWidgetView(frame));
776 WMAddItemInTabView(tabv, tab);
777 WMSetTabViewItemLabel(tab, "Bla!");
781 frame = WMCreateFrame(win);
782 WMSetFrameRelief(frame, WRFlat);
783 label = WMCreateLabel(frame);
784 WMResizeWidget(label, 100, 100);
785 WMMoveWidget(label, 160, 40);
786 WMSetLabelText(label, "Label fjweqklrj qwl");
787 WMMapWidget(label);
788 tab = WMCreateTabViewItemWithIdentifier(0);
789 WMSetTabViewItemView(tab, WMWidgetView(frame));
790 WMAddItemInTabView(tabv, tab);
791 WMSetTabViewItemLabel(tab, "Weee!");
794 WMRealizeWidget(win);
795 WMMapSubwidgets(win);
796 WMMapWidget(win);
800 void
801 splitViewConstrainProc(WMSplitView *sPtr, int indView,
802 int *minSize, int *maxSize)
804 switch (indView) {
805 case 0:
806 *minSize = 20;
807 break;
808 case 1:
809 *minSize = 40;
810 *maxSize = 80;
811 break;
812 case 2:
813 *maxSize = 60;
814 break;
815 default:
816 break;
821 static void
822 resizeSplitView(XEvent *event, void *data)
824 WMSplitView *sPtr = (WMSplitView*)data;
826 if (event->type == ConfigureNotify) {
827 int width = event->xconfigure.width - 10;
829 if (width < WMGetSplitViewDividerThickness(sPtr))
830 width = WMGetSplitViewDividerThickness(sPtr);
832 if (width != WMWidgetWidth(sPtr) ||
833 event->xconfigure.height != WMWidgetHeight(sPtr))
834 WMResizeWidget(sPtr, width, event->xconfigure.height - 55);
838 void
839 appendSubviewButtonAction(WMWidget *self, void *data)
841 WMSplitView *sPtr = (WMSplitView*)data;
842 char buf[64];
843 WMLabel *label = WMCreateLabel(sPtr);
845 sprintf(buf, "Subview %d", WMGetSplitViewSubviewsCount(sPtr) + 1);
846 WMSetLabelText(label, buf);
847 WMSetLabelRelief(label, WRSunken);
848 WMAddSplitViewSubview(sPtr, WMWidgetView(label));
849 WMRealizeWidget(label);
850 WMMapWidget(label);
853 void
854 removeSubviewButtonAction(WMWidget *self, void *data)
856 WMSplitView *sPtr = (WMSplitView*)data;
857 int count = WMGetSplitViewSubviewsCount(sPtr);
859 if (count > 2) {
860 WMView *view = WMGetSplitViewSubviewAt(sPtr, count-1);
861 WMDestroyWidget(WMWidgetOfView(view));
862 WMRemoveSplitViewSubviewAt(sPtr, count-1);
866 void
867 orientationButtonAction(WMWidget *self, void *data)
869 WMSplitView *sPtr = (WMSplitView*)data;
870 WMSetSplitViewVertical(sPtr, !WMGetSplitViewVertical(sPtr));
873 void
874 adjustSubviewsButtonAction(WMWidget *self, void *data)
876 WMAdjustSplitViewSubviews((WMSplitView*)data);
879 void
880 testSplitView(WMScreen *scr)
882 WMWindow *win;
883 WMSplitView *splitv1, *splitv2;
884 WMFrame *frame;
885 WMLabel *label;
886 WMButton *button;
888 windowCount++;
890 win = WMCreateWindow(scr, "testTabs");
891 WMResizeWidget(win, 300, 400);
892 WMSetWindowCloseAction(win, closeAction, NULL);
894 frame = WMCreateFrame(win);
895 WMSetFrameRelief(frame, WRSunken);
896 WMMoveWidget(frame, 5, 5);
897 WMResizeWidget(frame, 290, 40);
899 splitv1 = WMCreateSplitView(win);
900 WMMoveWidget(splitv1, 5, 50);
901 WMResizeWidget(splitv1, 290, 345);
902 WMSetSplitViewConstrainProc(splitv1, splitViewConstrainProc);
903 WMCreateEventHandler(WMWidgetView(win), StructureNotifyMask,
904 resizeSplitView, splitv1);
906 button = WMCreateCommandButton(frame);
907 WMSetButtonText(button, "+");
908 WMSetButtonAction(button, appendSubviewButtonAction, splitv1);
909 WMMoveWidget(button, 10, 8);
910 WMMapWidget(button);
912 button = WMCreateCommandButton(frame);
913 WMSetButtonText(button, "-");
914 WMSetButtonAction(button, removeSubviewButtonAction, splitv1);
915 WMMoveWidget(button, 80, 8);
916 WMMapWidget(button);
918 button = WMCreateCommandButton(frame);
919 WMSetButtonText(button, "=");
920 WMMoveWidget(button, 150, 8);
921 WMSetButtonAction(button, adjustSubviewsButtonAction, splitv1);
922 WMMapWidget(button);
924 button = WMCreateCommandButton(frame);
925 WMSetButtonText(button, "#");
926 WMMoveWidget(button, 220, 8);
927 WMSetButtonAction(button, orientationButtonAction, splitv1);
928 WMMapWidget(button);
930 label = WMCreateLabel(splitv1);
931 WMSetLabelText(label, "Subview 1");
932 WMSetLabelRelief(label, WRSunken);
933 WMMapWidget(label);
934 WMAddSplitViewSubview(splitv1, WMWidgetView(label));
936 splitv2 = WMCreateSplitView(splitv1);
937 WMResizeWidget(splitv2, 150, 150);
938 WMSetSplitViewVertical(splitv2, True);
940 label = WMCreateLabel(splitv2);
941 WMSetLabelText(label, "Subview 2.1");
942 WMSetLabelRelief(label, WRSunken);
943 WMMapWidget(label);
944 WMAddSplitViewSubview(splitv2, WMWidgetView(label));
946 label = WMCreateLabel(splitv2);
947 WMSetLabelText(label, "Subview 2.2");
948 WMSetLabelRelief(label, WRSunken);
949 WMMapWidget(label);
950 WMAddSplitViewSubview(splitv2, WMWidgetView(label));
952 label = WMCreateLabel(splitv2);
953 WMSetLabelText(label, "Subview 2.3");
954 WMSetLabelRelief(label, WRSunken);
955 WMMapWidget(label);
956 WMAddSplitViewSubview(splitv2, WMWidgetView(label));
958 WMMapWidget(splitv2);
959 WMAddSplitViewSubview(splitv1, WMWidgetView(splitv2));
961 WMRealizeWidget(win);
962 WMMapSubwidgets(win);
963 WMMapWidget(win);
967 /*******************************************************************/
969 #include <sys/types.h>
970 #include <dirent.h>
971 #include <string.h>
974 typedef struct {
975 int x, y;
976 Bool mouseDown;
977 char *filename;
978 } DNDStuff;
980 WMPixmap*
981 getImage(WMScreen *scr, char *file)
983 char buffer[1000];
984 WMPixmap *pix;
986 sprintf(buffer, "../../WindowMaker/Icons/%s", file);
987 pix = WMCreatePixmapFromFile(scr, buffer);
989 return pix;
995 static void
996 iconMouseStuff(XEvent *event, void *cdata)
998 WMLabel *label = (WMLabel*)cdata;
999 DNDStuff *stuff = WMGetHangedData(label);
1000 WMPoint where;
1002 switch (event->type) {
1003 case ButtonPress:
1004 stuff->x = event->xbutton.x;
1005 stuff->y = event->xbutton.y;
1006 stuff->mouseDown = True;
1007 break;
1008 case ButtonRelease:
1009 stuff->mouseDown = False;
1010 break;
1011 case MotionNotify:
1012 if (!stuff->mouseDown)
1013 break;
1015 if (abs(stuff->x - event->xmotion.x)>4
1016 || abs(stuff->y - event->xmotion.y)>4) {
1018 where = WMGetViewScreenPosition(WMWidgetView(label));
1020 WMDragImageFromView(WMWidgetView(label),
1021 WMGetLabelImage(label),
1022 NULL, /* XXX */
1023 where,
1024 wmksize(stuff->x, stuff->y),
1025 event, True);
1027 break;
1032 static void
1033 endedDragImage(WMView *self, WMPixmap *image, WMPoint point, Bool deposited)
1035 DNDStuff *stuff = WMGetHangedData(WMWidgetOfView(self));
1037 if (deposited) {
1038 WMDestroyWidget(WMWidgetOfView(self));
1041 stuff->mouseDown = False;
1045 static WMData*
1046 fetchDragData(WMView *self, char *type)
1048 DNDStuff *stuff = WMGetHangedData(WMWidgetOfView(self));
1050 return WMCreateDataWithBytes(stuff->filename, strlen(stuff->filename)+1);
1054 WMDragSourceProcs dragSourceProcs = {
1055 NULL,
1056 NULL,
1057 endedDragImage,
1058 fetchDragData
1062 /************************/
1065 unsigned
1066 draggingEntered(WMView *self, WMDraggingInfo *info)
1068 return WDOperationCopy;
1072 unsigned
1073 draggingUpdated(WMView *self, WMDraggingInfo *info)
1075 return WDOperationCopy;
1079 void (*draggingExited)(WMView *self, WMDraggingInfo *info);
1081 char*
1082 prepareForDragOperation(WMView *self, WMDraggingInfo *info)
1084 return "application/X-WINGs-Bla";
1088 WMLabel* makeDraggableLabel(WMWidget *w, char *file, int x, int y);
1090 Bool
1091 performDragOperation(WMView *self, WMDraggingInfo *info, WMData *data)
1093 char *file = (char*)WMDataBytes(data);
1094 WMPoint pos;
1096 pos = WMGetDraggingInfoImageLocation(info);
1098 if (file!=NULL) {
1099 WMLabel *label;
1100 WMPoint pos2 = WMGetViewScreenPosition(self);
1103 label = makeDraggableLabel(WMWidgetOfView(self), file,
1104 pos.x-pos2.x, pos.y-pos2.y);
1105 WMRealizeWidget(label);
1106 WMMapWidget(label);
1110 return True;
1114 void
1115 concludeDragOperation(WMView *self, WMDraggingInfo *info)
1122 WMDragDestinationProcs dragDestProcs = {
1123 draggingEntered,
1124 draggingUpdated,
1125 NULL,
1126 prepareForDragOperation,
1127 performDragOperation,
1128 concludeDragOperation
1134 WMLabel*
1135 makeDraggableLabel(WMWidget *w, char *file, int x, int y)
1137 DNDStuff *stuff;
1138 WMLabel *label;
1139 WMPixmap *image = getImage(WMWidgetScreen(w), file);
1141 stuff = wmalloc(sizeof(DNDStuff));
1142 stuff->mouseDown = False;
1144 stuff->filename = wstrdup(file);
1146 label = WMCreateLabel(w);
1147 WMResizeWidget(label, 48, 48);
1148 WMMoveWidget(label, x, y);
1150 WMSetViewDragSourceProcs(WMWidgetView(label), &dragSourceProcs);
1152 WMHangData(label, stuff);
1154 WMCreateEventHandler(WMWidgetView(label),
1155 ButtonPressMask|ButtonReleaseMask|ButtonMotionMask,
1156 iconMouseStuff, label);
1159 if (image != NULL) {
1160 WMSetLabelImagePosition(label, WIPImageOnly);
1161 WMSetLabelImage(label, image);
1162 WMReleasePixmap(image);
1163 } else puts(file);
1165 return label;
1170 void
1171 testDragAndDrop(WMScreen *scr)
1173 WMWindow *win;
1174 WMFrame *frame;
1175 WMLabel *label;
1176 int i, j;
1177 DIR *dir;
1178 struct dirent *ent;
1179 char *types[] = {
1180 "application/X-WINGs-Bla",
1181 NULL
1184 windowCount++;
1186 win = WMCreateWindow(scr, "dragDrop");
1187 WMResizeWidget(win, 300, 300);
1188 WMSetWindowCloseAction(win, closeAction, NULL);
1189 WMSetWindowTitle(win, "Drag and Drop");
1192 frame = WMCreateFrame(win);
1193 WMSetFrameRelief(frame, WRSunken);
1194 WMResizeWidget(frame, 250, 250);
1195 WMMoveWidget(frame, 25, 25);
1197 WMRegisterViewForDraggedTypes(WMWidgetView(frame), types);
1198 WMSetViewDragDestinationProcs(WMWidgetView(frame), &dragDestProcs);
1200 dir = opendir("../../WindowMaker/Icons");
1201 if (!dir) {
1202 perror("../../WindowMaker/Icons");
1203 return;
1206 for (i = 0, j=0; j < 8; i++) {
1207 ent = readdir(dir);
1208 if (!ent)
1209 break;
1211 if (strstr(ent->d_name, ".xpm")==NULL) {
1212 continue;
1215 label = makeDraggableLabel(frame, ent->d_name,4+(j/4)*64, 4+(j%4)*64);
1217 j++;
1220 closedir(dir);
1222 WMMapSubwidgets(frame);
1224 WMMapSubwidgets(win);
1225 WMRealizeWidget(win);
1226 WMMapWidget(win);
1233 /*******************************************************************/
1236 void
1237 testUD()
1239 WMUserDefaults *defs;
1240 char str[32];
1242 defs = WMGetStandardUserDefaults();
1244 sprintf(str, "TEST DATA");
1245 puts(str);
1246 WMSetUDStringForKey(defs, str, "testKey");
1247 puts(str);
1252 main(int argc, char **argv)
1254 WMScreen *scr;
1255 WMPixmap *pixmap;
1258 /* Initialize the application */
1259 WMInitializeApplication("Test@eqweq_ewq$eqw", &argc, argv);
1261 testUD();
1264 * Open connection to the X display.
1266 dpy = XOpenDisplay("");
1268 if (!dpy) {
1269 puts("could not open display");
1270 exit(1);
1273 /* This is used to disable buffering of X protocol requests.
1274 * Do NOT use it unless when debugging. It will cause a major
1275 * slowdown in your application
1277 #if 0
1278 XSynchronize(dpy, True);
1279 #endif
1281 * Create screen descriptor.
1283 scr = WMCreateScreen(dpy, DefaultScreen(dpy));
1286 * Loads the logo of the application.
1288 pixmap = WMCreatePixmapFromFile(scr, "logo.xpm");
1291 * Makes the logo be used in standard dialog panels.
1293 WMSetApplicationIconPixmap(scr, pixmap); WMReleasePixmap(pixmap);
1296 * Do some test stuff.
1298 * Put the testSomething() function you want to test here.
1303 testDragAndDrop(scr);
1304 testText(scr);
1306 testFontPanel(scr);
1309 #if 0
1310 testColorPanel(scr);
1311 testScrollView(scr);
1312 testTabView(scr);
1313 testBox(scr);
1314 testText(scr);
1315 testList(scr);
1317 testProgressIndicator(scr);
1319 testColorWell(scr);
1321 testTextField(scr);
1323 testDragAndDrop(scr);
1324 testFontPanel(scr);
1326 testButton(scr);
1328 testFrame(scr);
1330 testSplitView(scr);
1332 testGradientButtons(scr);
1334 testOpenFilePanel(scr);
1336 testSlider(scr);
1337 testPullDown(scr);
1338 #endif
1340 * The main event loop.
1343 WMScreenMainLoop(scr);
1345 return 0;