added WINDOWS_MENU to rootmenu
[wmaker-crm.git] / WINGs / Tests / wtest.c
blobb3df3e400b39e934a22d0ac09168ed7891c369f9
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 resizedWindow(void *self, WMNotification *notif)
120 WMView *view = (WMView*)WMGetNotificationObject(notif);
121 WMSize size = WMGetViewSize(view);
123 WMResizeWidget((WMWidget*)self, size.width, size.height);
126 void
127 testBox(WMScreen *scr)
129 WMWindow *win;
130 WMBox *box, *hbox;
131 WMButton *btn;
132 WMPopUpButton *pop;
133 int i;
135 windowCount++;
137 win = WMCreateWindow(scr, "testBox");
138 WMSetWindowTitle(win, "Box");
139 WMSetWindowCloseAction(win, closeAction, NULL);
141 WMSetViewNotifySizeChanges(WMWidgetView(win), True);
143 box = WMCreateBox(win);
144 WMSetBoxBorderWidth(box, 5);
146 WMAddNotificationObserver(resizedWindow, box,
147 WMViewSizeDidChangeNotification,
148 WMWidgetView(win));
149 WMResizeWidget(win, 400, 300);
152 /* WMSetBoxHorizontal(box, True); */
153 for (i = 0; i < 4; i++) {
154 btn = WMCreateCommandButton(box);
155 WMSetButtonText(btn, "bla");
156 WMMapWidget(btn);
157 WMAddBoxSubview(box, WMWidgetView(btn), i&1, True, 20, 0, 5);
160 pop = WMCreatePopUpButton(box);
161 WMAddPopUpButtonItem(pop, "ewqeq");
162 WMAddPopUpButtonItem(pop, "ewqeqrewrw");
163 WMAddBoxSubview(box, WMWidgetView(pop), False, True, 20, 0, 5);
164 WMMapWidget(pop);
166 hbox = WMCreateBox(box);
167 WMSetBoxHorizontal(hbox, True);
168 WMAddBoxSubview(box, WMWidgetView(hbox), False, True, 24, 0, 0);
169 WMMapWidget(hbox);
171 for (i = 0; i < 4; i++) {
172 btn = WMCreateCommandButton(hbox);
173 WMSetButtonText(btn, "bla");
174 WMMapWidget(btn);
175 WMAddBoxSubview(hbox, WMWidgetView(btn), 1, True, 60, 0, i<3?5:0);
179 WMRealizeWidget(win);
180 WMMapSubwidgets(win);
181 WMMapWidget(win);
187 static void
188 singleClick(WMWidget *self, void *data)
193 static void
194 doubleClick(WMWidget *self, void *data)
196 WMLabel *label = (WMLabel*)data;
197 WMList *lPtr = (WMList*)self;
198 char buf[255];
200 WMSelectAllListItems(lPtr);
204 static void
205 listSelectionObserver(void *observer, WMNotification *notification)
207 WMLabel *label = (WMLabel*)observer;
208 WMList *lPtr = (WMList*)WMGetNotificationObject(notification);
209 char buf[255];
211 sprintf(buf, "Selected items: %d",
212 WMGetArrayItemCount(WMGetListSelectedItems(lPtr)));
213 WMSetLabelText(label, buf);
217 void
218 testList(WMScreen *scr)
220 WMWindow *win;
221 WMList *list;
222 WMList *mlist;
223 WMLabel *label;
224 WMLabel *mlabel;
225 WMLabel *title;
226 WMLabel *mtitle;
227 char text[100];
228 int i;
230 windowCount++;
232 win = WMCreateWindow(scr, "testList");
233 WMResizeWidget(win, 370, 250);
234 WMSetWindowTitle(win, "List");
235 WMSetWindowCloseAction(win, closeAction, NULL);
237 title = WMCreateLabel(win);
238 WMResizeWidget(title, 150, 20);
239 WMMoveWidget(title, 10, 10);
240 WMSetLabelRelief(title, WRRidge);
241 WMSetLabelText(title, "Single selection list");
243 mtitle = WMCreateLabel(win);
244 WMResizeWidget(mtitle, 150, 20);
245 WMMoveWidget(mtitle, 210, 10);
246 WMSetLabelRelief(mtitle, WRRidge);
247 WMSetLabelText(mtitle, "Multiple selection list");
249 list = WMCreateList(win);
250 /*WMSetListAllowEmptySelection(list, True);*/
251 WMMoveWidget(list, 10, 40);
252 for (i=0; i<50; i++) {
253 sprintf(text, "Item %i", i);
254 WMAddListItem(list, text);
256 mlist = WMCreateList(win);
257 WMSetListAllowMultipleSelection(mlist, True);
258 /*WMSetListAllowEmptySelection(mlist, True);*/
259 WMMoveWidget(mlist, 210, 40);
260 for (i=0; i<135; i++) {
261 sprintf(text, "Item %i", i);
262 WMAddListItem(mlist, text);
265 label = WMCreateLabel(win);
266 WMResizeWidget(label, 150, 40);
267 WMMoveWidget(label, 10, 200);
268 WMSetLabelRelief(label, WRRidge);
269 WMSetLabelText(label, "Selected items: 0");
271 mlabel = WMCreateLabel(win);
272 WMResizeWidget(mlabel, 150, 40);
273 WMMoveWidget(mlabel, 210, 200);
274 WMSetLabelRelief(mlabel, WRRidge);
275 WMSetLabelText(mlabel, "Selected items: 0");
277 WMSetListAction(list, singleClick, label);
278 WMSetListDoubleAction(list, doubleClick, label);
279 WMSetListAction(mlist, singleClick, mlabel);
280 WMSetListDoubleAction(mlist, doubleClick, mlabel);
282 WMAddNotificationObserver(listSelectionObserver, label,
283 WMListSelectionDidChangeNotification, list);
284 WMAddNotificationObserver(listSelectionObserver, mlabel,
285 WMListSelectionDidChangeNotification, mlist);
288 WMRealizeWidget(win);
289 WMMapSubwidgets(win);
290 WMMapWidget(win);
294 void
295 testButton(WMScreen *scr)
297 WMWindow *win;
298 int i;
299 char *types[] = {
300 "MomentaryPush",
301 "PushOnPushOff",
302 "Toggle",
303 "Switch",
304 "Radio",
305 "MomentaryChange",
306 "OnOff",
307 "MomentaryLigh"
310 windowCount++;
312 win = WMCreateWindow(scr, "testButton");
313 WMResizeWidget(win, 300, 300);
314 WMSetWindowTitle(win, "Buttons");
316 WMSetWindowCloseAction(win, closeAction, NULL);
318 for (i = 1; i < 9; i++) {
319 WMButton *b;
320 b = WMCreateButton(win, i);
321 WMResizeWidget(b, 150, 24);
322 WMMoveWidget(b, 20, i*30);
323 WMSetButtonText(b, types[i-1]);
326 WMRealizeWidget(win);
327 WMMapSubwidgets(win);
328 WMMapWidget(win);
332 void
333 testGradientButtons(WMScreen *scr)
335 WMWindow *win;
336 WMButton *btn;
337 WMPixmap *pix1, *pix2;
338 RImage *back;
339 RColor light, dark;
340 WMColor *color, *altColor;
342 windowCount++;
344 /* creates the top-level window */
345 win = WMCreateWindow(scr, "testGradientButtons");
346 WMSetWindowTitle(win, "Gradiented Button Demo");
347 WMResizeWidget(win, 300, 200);
349 light.red = 0x90;
350 light.green = 0x85;
351 light.blue = 0x90;
352 dark.red = 0x35;
353 dark.green = 0x30;
354 dark.blue = 0x35;
356 color = WMCreateRGBColor(scr, 0x5900, 0x5100, 0x5900, True);
357 WMSetWidgetBackgroundColor(win, color);
358 WMReleaseColor(color);
360 back = RRenderGradient(60, 24, &dark, &light, RGRD_DIAGONAL);
361 RBevelImage(back, RBEV_RAISED2);
362 pix1 = WMCreatePixmapFromRImage(scr, back, 0);
363 RDestroyImage(back);
365 back = RRenderGradient(60, 24, &dark, &light, RGRD_DIAGONAL);
366 RBevelImage(back, RBEV_SUNKEN);
367 pix2 = WMCreatePixmapFromRImage(scr, back, 0);
368 RDestroyImage(back);
370 color = WMWhiteColor(scr);
371 altColor = WMCreateNamedColor(scr, "red", True);
373 btn = WMCreateButton(win, WBTMomentaryChange);
374 WMResizeWidget(btn, 60, 24);
375 WMMoveWidget(btn, 20, 100);
376 WMSetButtonBordered(btn, False);
377 WMSetButtonImagePosition(btn, WIPOverlaps);
378 WMSetButtonImage(btn, pix1);
379 WMSetButtonAltImage(btn, pix2);
380 WMSetButtonText(btn, "Cool");
381 WMSetButtonTextColor(btn, color);
382 WMSetButtonAltTextColor(btn, altColor);
384 WMSetBalloonTextForView("This is a cool button", WMWidgetView(btn));
386 btn = WMCreateButton(win, WBTMomentaryChange);
387 WMResizeWidget(btn, 60, 24);
388 WMMoveWidget(btn, 90, 100);
389 WMSetButtonBordered(btn, False);
390 WMSetButtonImagePosition(btn, WIPOverlaps);
391 WMSetButtonImage(btn, pix1);
392 WMSetButtonAltImage(btn, pix2);
393 WMSetButtonText(btn, "Button");
394 WMSetButtonTextColor(btn, color);
396 WMSetBalloonTextForView("Este é outro balão.", WMWidgetView(btn));
398 WMReleaseColor(color);
399 color = WMCreateNamedColor(scr, "orange", True);
401 btn = WMCreateButton(win, WBTMomentaryChange);
402 WMResizeWidget(btn, 60, 24);
403 WMMoveWidget(btn, 160, 100);
404 WMSetButtonBordered(btn, False);
405 WMSetButtonImagePosition(btn, WIPOverlaps);
406 WMSetButtonImage(btn, pix1);
407 WMSetButtonAltImage(btn, pix2);
408 WMSetButtonText(btn, "Test");
409 WMSetButtonTextColor(btn, color);
411 WMSetBalloonTextForView("This is yet another button.\nBut the balloon has 3 lines.\nYay!",
412 WMWidgetView(btn));
414 WMReleaseColor(color);
415 WMReleaseColor(altColor);
417 WMRealizeWidget(win);
418 WMMapSubwidgets(win);
419 WMMapWidget(win);
423 void
424 testScrollView(WMScreen *scr)
426 WMWindow *win;
427 WMScrollView *sview;
428 WMFrame *f;
429 WMLabel *l;
430 char buffer[128];
431 int i;
433 windowCount++;
435 /* creates the top-level window */
436 win = WMCreateWindow(scr, "testScroll");
437 WMSetWindowTitle(win, "Scrollable View");
439 WMSetWindowCloseAction(win, closeAction, NULL);
441 /* set the window size */
442 WMResizeWidget(win, 300, 300);
444 /* creates a scrollable view inside the top-level window */
445 sview = WMCreateScrollView(win);
446 WMResizeWidget(sview, 200, 200);
447 WMMoveWidget(sview, 30, 30);
448 WMSetScrollViewRelief(sview, WRSunken);
449 WMSetScrollViewHasVerticalScroller(sview, True);
450 WMSetScrollViewHasHorizontalScroller(sview, True);
452 /* create a frame with a bunch of labels */
453 f = WMCreateFrame(win);
454 WMResizeWidget(f, 400, 400);
455 WMSetFrameRelief(f, WRFlat);
457 for (i=0; i<20; i++) {
458 l = WMCreateLabel(f);
459 WMResizeWidget(l, 50, 18);
460 WMMoveWidget(l, 10, 20*i);
461 sprintf(buffer, "Label %i", i);
462 WMSetLabelText(l, buffer);
463 WMSetLabelRelief(l, WRSimple);
465 WMMapSubwidgets(f);
466 WMMapWidget(f);
468 WMSetScrollViewContentView(sview, WMWidgetView(f));
470 /* make the windows of the widgets be actually created */
471 WMRealizeWidget(win);
473 /* Map all child widgets of the top-level be mapped.
474 * You must call this for each container widget (like frames),
475 * even if they are childs of the top-level window.
477 WMMapSubwidgets(win);
479 /* map the top-level window */
480 WMMapWidget(win);
484 void
485 testColorWell(WMScreen *scr)
487 WMWindow *win;
488 WMColorWell *well1, *well2;
490 windowCount++;
492 win = WMCreateWindow(scr, "testColor");
493 WMResizeWidget(win, 300, 300);
494 WMSetWindowCloseAction(win, closeAction, NULL);
496 well1 = WMCreateColorWell(win);
497 WMResizeWidget(well1, 60, 40);
498 WMMoveWidget(well1, 100, 100);
499 WMSetColorWellColor(well1, WMCreateRGBColor(scr, 0x8888, 0, 0x1111, True));
500 well2 = WMCreateColorWell(win);
501 WMResizeWidget(well2, 60, 40);
502 WMMoveWidget(well2, 200, 100);
503 WMSetColorWellColor(well2, WMCreateRGBColor(scr, 0, 0, 0x8888, True));
505 WMRealizeWidget(win);
506 WMMapSubwidgets(win);
507 WMMapWidget(win);
510 void
511 sliderCallback(WMWidget *w, void *data)
513 printf("SLIDER == %i\n", WMGetSliderValue(w));
517 void
518 testSlider(WMScreen *scr)
520 WMWindow *win;
521 WMSlider *s;
523 windowCount++;
525 win = WMCreateWindow(scr, "testSlider");
526 WMResizeWidget(win, 300, 300);
527 WMSetWindowTitle(win, "Sliders");
529 WMSetWindowCloseAction(win, closeAction, NULL);
531 s = WMCreateSlider(win);
532 WMResizeWidget(s, 16, 100);
533 WMMoveWidget(s, 100, 100);
534 WMSetSliderKnobThickness(s, 8);
535 WMSetSliderContinuous(s, False);
536 WMSetSliderAction(s, sliderCallback, s);
538 s = WMCreateSlider(win);
539 WMResizeWidget(s, 100, 16);
540 WMMoveWidget(s, 100, 10);
541 WMSetSliderKnobThickness(s, 8);
543 WMRealizeWidget(win);
544 WMMapSubwidgets(win);
545 WMMapWidget(win);
548 void
549 testTextField(WMScreen *scr)
551 WMWindow *win;
552 WMTextField *field, *field2;
554 windowCount++;
556 win = WMCreateWindow(scr, "testTextField");
557 WMResizeWidget(win, 400, 300);
559 WMSetWindowCloseAction(win, closeAction, NULL);
561 field = WMCreateTextField(win);
562 WMResizeWidget(field, 200, 20);
563 WMMoveWidget(field, 20, 20);
565 field2 = WMCreateTextField(win);
566 WMResizeWidget(field2, 200, 20);
567 WMMoveWidget(field2, 20, 50);
568 WMSetTextFieldAlignment(field2, WARight);
570 WMRealizeWidget(win);
571 WMMapSubwidgets(win);
572 WMMapWidget(win);
577 void
578 testText(WMScreen *scr)
580 WMWindow *win;
581 WMText *text;
582 FILE *file = fopen("wm.html", "r");
584 windowCount++;
586 win = WMCreateWindow(scr, "testText");
587 WMResizeWidget(win, 500, 300);
589 WMSetWindowCloseAction(win, closeAction, NULL);
591 text = WMCreateText(win);
592 WMResizeWidget(text, 480, 280);
593 WMMoveWidget(text, 10, 10);
594 WMSetTextHasVerticalScroller(text, True);
595 WMSetTextEditable(text, False);
597 if(file) {
598 char buf[1024];
600 WMFreezeText(text);
601 while(fgets(buf, 1023, file))
602 WMAppendTextStream(text, buf);
604 fclose(file);
605 WMThawText(text);
606 } else {
607 WMAppendTextStream(text,
608 "Window Maker is the GNU window manager for the "
609 "X Window System. It was designed to emulate the "
610 "look and feel of part of the NEXTSTEP(tm) GUI. Its "
611 "supposed to be relatively fast and small, feature "
612 "rich, easy to configure and easy to use, with a simple "
613 "and elegant appearance borrowed from NEXTSTEP(tm).");
616 WMRealizeWidget(win);
617 WMMapSubwidgets(win);
618 WMMapWidget(win);
622 void
623 testProgressIndicator(WMScreen *scr)
625 WMWindow *win;
626 WMProgressIndicator *pPtr;
628 windowCount++;
630 win = WMCreateWindow(scr, "testProgressIndicator");
631 WMResizeWidget(win, 292, 32);
633 WMSetWindowCloseAction(win, closeAction, NULL);
635 pPtr = WMCreateProgressIndicator(win);
636 WMMoveWidget(pPtr, 8, 8);
637 WMSetProgressIndicatorValue(pPtr, 75);
639 WMRealizeWidget(win);
640 WMMapSubwidgets(win);
641 WMMapWidget(win);
646 void
647 testPullDown(WMScreen *scr)
649 WMWindow *win;
650 WMPopUpButton *pop, *pop2;
652 windowCount++;
654 win = WMCreateWindow(scr, "pullDown");
655 WMResizeWidget(win, 400, 300);
657 WMSetWindowCloseAction(win, closeAction, NULL);
659 pop = WMCreatePopUpButton(win);
660 WMResizeWidget(pop, 100, 20);
661 WMMoveWidget(pop, 50, 60);
662 WMSetPopUpButtonPullsDown(pop, True);
663 WMSetPopUpButtonText(pop, "Commands");
664 WMAddPopUpButtonItem(pop, "Add");
665 WMAddPopUpButtonItem(pop, "Remove");
666 WMAddPopUpButtonItem(pop, "Check");
667 WMAddPopUpButtonItem(pop, "Eat");
669 pop2 = WMCreatePopUpButton(win);
670 WMResizeWidget(pop2, 100, 20);
671 WMMoveWidget(pop2, 200, 60);
672 WMSetPopUpButtonText(pop2, "Select");
673 WMAddPopUpButtonItem(pop2, "Apples");
674 WMAddPopUpButtonItem(pop2, "Bananas");
675 WMAddPopUpButtonItem(pop2, "Strawberries");
676 WMAddPopUpButtonItem(pop2, "Blueberries");
678 WMRealizeWidget(win);
679 WMMapSubwidgets(win);
680 WMMapWidget(win);
685 void
686 testTabView(WMScreen *scr)
688 WMWindow *win;
689 WMTabView *tabv;
690 WMTabViewItem *tab;
691 WMFrame *frame;
692 WMLabel *label;
694 windowCount++;
696 win = WMCreateWindow(scr, "testTabs");
697 WMResizeWidget(win, 400, 300);
699 WMSetWindowCloseAction(win, closeAction, NULL);
701 tabv = WMCreateTabView(win);
702 WMMoveWidget(tabv, 50, 50);
703 WMResizeWidget(tabv, 300, 200);
705 frame = WMCreateFrame(win);
706 WMSetFrameRelief(frame, WRFlat);
707 label = WMCreateLabel(frame);
708 WMResizeWidget(label, 100, 100);
709 WMSetLabelText(label, "Label 1");
710 WMMapWidget(label);
713 tab = WMCreateTabViewItemWithIdentifier(0);
714 WMSetTabViewItemView(tab, WMWidgetView(frame));
715 WMAddItemInTabView(tabv, tab);
716 WMSetTabViewItemLabel(tab, "Instances");
718 frame = WMCreateFrame(win);
719 WMSetFrameRelief(frame, WRFlat);
720 label = WMCreateLabel(frame);
721 WMResizeWidget(label, 40, 50);
722 WMSetLabelText(label, "Label 2");
723 WMMapWidget(label);
726 tab = WMCreateTabViewItemWithIdentifier(0);
727 WMSetTabViewItemView(tab, WMWidgetView(frame));
728 WMAddItemInTabView(tabv, tab);
729 WMSetTabViewItemLabel(tab, "Classes");
732 frame = WMCreateFrame(win);
733 WMSetFrameRelief(frame, WRFlat);
734 label = WMCreateLabel(frame);
735 WMResizeWidget(label, 100, 100);
736 WMMoveWidget(label, 60, 40);
737 WMSetLabelText(label, "Label 3");
738 WMMapWidget(label);
740 tab = WMCreateTabViewItemWithIdentifier(0);
741 WMSetTabViewItemView(tab, WMWidgetView(frame));
742 WMAddItemInTabView(tabv, tab);
743 WMSetTabViewItemLabel(tab, "Something");
746 frame = WMCreateFrame(win);
747 WMSetFrameRelief(frame, WRFlat);
748 label = WMCreateLabel(frame);
749 WMResizeWidget(label, 100, 100);
750 WMMoveWidget(label, 160, 40);
751 WMSetLabelText(label, "Label 4");
752 WMMapWidget(label);
754 tab = WMCreateTabViewItemWithIdentifier(0);
755 WMSetTabViewItemView(tab, WMWidgetView(frame));
756 WMAddItemInTabView(tabv, tab);
757 WMSetTabViewItemLabel(tab, "Bla!");
761 frame = WMCreateFrame(win);
762 WMSetFrameRelief(frame, WRFlat);
763 label = WMCreateLabel(frame);
764 WMResizeWidget(label, 100, 100);
765 WMMoveWidget(label, 160, 40);
766 WMSetLabelText(label, "Label fjweqklrj qwl");
767 WMMapWidget(label);
768 tab = WMCreateTabViewItemWithIdentifier(0);
769 WMSetTabViewItemView(tab, WMWidgetView(frame));
770 WMAddItemInTabView(tabv, tab);
771 WMSetTabViewItemLabel(tab, "Weee!");
774 WMRealizeWidget(win);
775 WMMapSubwidgets(win);
776 WMMapWidget(win);
780 void
781 splitViewConstrainProc(WMSplitView *sPtr, int indView,
782 int *minSize, int *maxSize)
784 switch (indView) {
785 case 0:
786 *minSize = 20;
787 break;
788 case 1:
789 *minSize = 40;
790 *maxSize = 80;
791 break;
792 case 2:
793 *maxSize = 60;
794 break;
795 default:
796 break;
801 static void
802 resizeSplitView(XEvent *event, void *data)
804 WMSplitView *sPtr = (WMSplitView*)data;
806 if (event->type == ConfigureNotify) {
807 int width = event->xconfigure.width - 10;
809 if (width < WMGetSplitViewDividerThickness(sPtr))
810 width = WMGetSplitViewDividerThickness(sPtr);
812 if (width != WMWidgetWidth(sPtr) ||
813 event->xconfigure.height != WMWidgetHeight(sPtr))
814 WMResizeWidget(sPtr, width, event->xconfigure.height - 55);
818 void
819 appendSubviewButtonAction(WMWidget *self, void *data)
821 WMSplitView *sPtr = (WMSplitView*)data;
822 char buf[64];
823 WMLabel *label = WMCreateLabel(sPtr);
825 sprintf(buf, "Subview %d", WMGetSplitViewSubviewsCount(sPtr) + 1);
826 WMSetLabelText(label, buf);
827 WMSetLabelRelief(label, WRSunken);
828 WMAddSplitViewSubview(sPtr, WMWidgetView(label));
829 WMRealizeWidget(label);
830 WMMapWidget(label);
833 void
834 removeSubviewButtonAction(WMWidget *self, void *data)
836 WMSplitView *sPtr = (WMSplitView*)data;
837 int count = WMGetSplitViewSubviewsCount(sPtr);
839 if (count > 2) {
840 WMView *view = WMGetSplitViewSubviewAt(sPtr, count-1);
841 WMDestroyWidget(WMWidgetOfView(view));
842 WMRemoveSplitViewSubviewAt(sPtr, count-1);
846 void
847 orientationButtonAction(WMWidget *self, void *data)
849 WMSplitView *sPtr = (WMSplitView*)data;
850 WMSetSplitViewVertical(sPtr, !WMGetSplitViewVertical(sPtr));
853 void
854 adjustSubviewsButtonAction(WMWidget *self, void *data)
856 WMAdjustSplitViewSubviews((WMSplitView*)data);
859 void
860 testSplitView(WMScreen *scr)
862 WMWindow *win;
863 WMSplitView *splitv1, *splitv2;
864 WMFrame *frame;
865 WMLabel *label;
866 WMButton *button;
868 windowCount++;
870 win = WMCreateWindow(scr, "testTabs");
871 WMResizeWidget(win, 300, 400);
872 WMSetWindowCloseAction(win, closeAction, NULL);
874 frame = WMCreateFrame(win);
875 WMSetFrameRelief(frame, WRSunken);
876 WMMoveWidget(frame, 5, 5);
877 WMResizeWidget(frame, 290, 40);
879 splitv1 = WMCreateSplitView(win);
880 WMMoveWidget(splitv1, 5, 50);
881 WMResizeWidget(splitv1, 290, 345);
882 WMSetSplitViewConstrainProc(splitv1, splitViewConstrainProc);
883 WMCreateEventHandler(WMWidgetView(win), StructureNotifyMask,
884 resizeSplitView, splitv1);
886 button = WMCreateCommandButton(frame);
887 WMSetButtonText(button, "+");
888 WMSetButtonAction(button, appendSubviewButtonAction, splitv1);
889 WMMoveWidget(button, 10, 8);
890 WMMapWidget(button);
892 button = WMCreateCommandButton(frame);
893 WMSetButtonText(button, "-");
894 WMSetButtonAction(button, removeSubviewButtonAction, splitv1);
895 WMMoveWidget(button, 80, 8);
896 WMMapWidget(button);
898 button = WMCreateCommandButton(frame);
899 WMSetButtonText(button, "=");
900 WMMoveWidget(button, 150, 8);
901 WMSetButtonAction(button, adjustSubviewsButtonAction, splitv1);
902 WMMapWidget(button);
904 button = WMCreateCommandButton(frame);
905 WMSetButtonText(button, "#");
906 WMMoveWidget(button, 220, 8);
907 WMSetButtonAction(button, orientationButtonAction, splitv1);
908 WMMapWidget(button);
910 label = WMCreateLabel(splitv1);
911 WMSetLabelText(label, "Subview 1");
912 WMSetLabelRelief(label, WRSunken);
913 WMMapWidget(label);
914 WMAddSplitViewSubview(splitv1, WMWidgetView(label));
916 splitv2 = WMCreateSplitView(splitv1);
917 WMResizeWidget(splitv2, 150, 150);
918 WMSetSplitViewVertical(splitv2, True);
920 label = WMCreateLabel(splitv2);
921 WMSetLabelText(label, "Subview 2.1");
922 WMSetLabelRelief(label, WRSunken);
923 WMMapWidget(label);
924 WMAddSplitViewSubview(splitv2, WMWidgetView(label));
926 label = WMCreateLabel(splitv2);
927 WMSetLabelText(label, "Subview 2.2");
928 WMSetLabelRelief(label, WRSunken);
929 WMMapWidget(label);
930 WMAddSplitViewSubview(splitv2, WMWidgetView(label));
932 label = WMCreateLabel(splitv2);
933 WMSetLabelText(label, "Subview 2.3");
934 WMSetLabelRelief(label, WRSunken);
935 WMMapWidget(label);
936 WMAddSplitViewSubview(splitv2, WMWidgetView(label));
938 WMMapWidget(splitv2);
939 WMAddSplitViewSubview(splitv1, WMWidgetView(splitv2));
941 WMRealizeWidget(win);
942 WMMapSubwidgets(win);
943 WMMapWidget(win);
947 /*******************************************************************/
949 #include <sys/types.h>
950 #include <dirent.h>
951 #include <string.h>
954 typedef struct {
955 int x, y;
956 Bool mouseDown;
957 char *filename;
958 } DNDStuff;
960 WMPixmap*
961 getImage(WMScreen *scr, char *file)
963 char buffer[1000];
964 WMPixmap *pix;
966 sprintf(buffer, "../../WindowMaker/Icons/%s", file);
967 pix = WMCreatePixmapFromFile(scr, buffer);
969 return pix;
975 static void
976 iconMouseStuff(XEvent *event, void *cdata)
978 WMLabel *label = (WMLabel*)cdata;
979 DNDStuff *stuff = WMGetHangedData(label);
980 WMPoint where;
982 switch (event->type) {
983 case ButtonPress:
984 stuff->x = event->xbutton.x;
985 stuff->y = event->xbutton.y;
986 stuff->mouseDown = True;
987 break;
988 case ButtonRelease:
989 stuff->mouseDown = False;
990 break;
991 case MotionNotify:
992 if (!stuff->mouseDown)
993 break;
995 if (abs(stuff->x - event->xmotion.x)>4
996 || abs(stuff->y - event->xmotion.y)>4) {
998 where = WMGetViewScreenPosition(WMWidgetView(label));
1000 WMDragImageFromView(WMWidgetView(label),
1001 WMGetLabelImage(label),
1002 NULL, /* XXX */
1003 where,
1004 wmksize(stuff->x, stuff->y),
1005 event, True);
1007 break;
1012 static void
1013 endedDragImage(WMView *self, WMPixmap *image, WMPoint point, Bool deposited)
1015 DNDStuff *stuff = WMGetHangedData(WMWidgetOfView(self));
1017 if (deposited) {
1018 WMDestroyWidget(WMWidgetOfView(self));
1021 stuff->mouseDown = False;
1025 static WMData*
1026 fetchDragData(WMView *self, char *type)
1028 DNDStuff *stuff = WMGetHangedData(WMWidgetOfView(self));
1030 return WMCreateDataWithBytes(stuff->filename, strlen(stuff->filename)+1);
1034 WMDragSourceProcs dragSourceProcs = {
1035 NULL,
1036 NULL,
1037 endedDragImage,
1038 fetchDragData
1042 /************************/
1045 unsigned
1046 draggingEntered(WMView *self, WMDraggingInfo *info)
1048 return WDOperationCopy;
1052 unsigned
1053 draggingUpdated(WMView *self, WMDraggingInfo *info)
1055 return WDOperationCopy;
1059 void (*draggingExited)(WMView *self, WMDraggingInfo *info);
1061 char*
1062 prepareForDragOperation(WMView *self, WMDraggingInfo *info)
1064 return "application/X-WINGs-Bla";
1068 WMLabel* makeDraggableLabel(WMWidget *w, char *file, int x, int y);
1070 Bool
1071 performDragOperation(WMView *self, WMDraggingInfo *info, WMData *data)
1073 char *file = (char*)WMDataBytes(data);
1074 WMPoint pos;
1076 pos = WMGetDraggingInfoImageLocation(info);
1078 if (file!=NULL) {
1079 WMLabel *label;
1080 WMPoint pos2 = WMGetViewScreenPosition(self);
1083 label = makeDraggableLabel(WMWidgetOfView(self), file,
1084 pos.x-pos2.x, pos.y-pos2.y);
1085 WMRealizeWidget(label);
1086 WMMapWidget(label);
1090 return True;
1094 void
1095 concludeDragOperation(WMView *self, WMDraggingInfo *info)
1102 WMDragDestinationProcs dragDestProcs = {
1103 draggingEntered,
1104 draggingUpdated,
1105 NULL,
1106 prepareForDragOperation,
1107 performDragOperation,
1108 concludeDragOperation
1114 WMLabel*
1115 makeDraggableLabel(WMWidget *w, char *file, int x, int y)
1117 DNDStuff *stuff;
1118 WMLabel *label;
1119 WMPixmap *image = getImage(WMWidgetScreen(w), file);
1121 stuff = wmalloc(sizeof(DNDStuff));
1122 stuff->mouseDown = False;
1124 stuff->filename = wstrdup(file);
1126 label = WMCreateLabel(w);
1127 WMResizeWidget(label, 48, 48);
1128 WMMoveWidget(label, x, y);
1130 WMSetViewDragSourceProcs(WMWidgetView(label), &dragSourceProcs);
1132 WMHangData(label, stuff);
1134 WMCreateEventHandler(WMWidgetView(label),
1135 ButtonPressMask|ButtonReleaseMask|ButtonMotionMask,
1136 iconMouseStuff, label);
1139 if (image != NULL) {
1140 WMSetLabelImagePosition(label, WIPImageOnly);
1141 WMSetLabelImage(label, image);
1142 WMReleasePixmap(image);
1143 } else puts(file);
1145 return label;
1150 void
1151 testDragAndDrop(WMScreen *scr)
1153 WMWindow *win;
1154 WMFrame *frame;
1155 WMLabel *label;
1156 int i, j;
1157 DIR *dir;
1158 struct dirent *ent;
1159 char *types[] = {
1160 "application/X-WINGs-Bla",
1161 NULL
1164 windowCount++;
1166 win = WMCreateWindow(scr, "dragDrop");
1167 WMResizeWidget(win, 300, 300);
1168 WMSetWindowCloseAction(win, closeAction, NULL);
1169 WMSetWindowTitle(win, "Drag and Drop");
1172 frame = WMCreateFrame(win);
1173 WMSetFrameRelief(frame, WRSunken);
1174 WMResizeWidget(frame, 250, 250);
1175 WMMoveWidget(frame, 25, 25);
1177 WMRegisterViewForDraggedTypes(WMWidgetView(frame), types);
1178 WMSetViewDragDestinationProcs(WMWidgetView(frame), &dragDestProcs);
1180 dir = opendir("../../WindowMaker/Icons");
1181 if (!dir) {
1182 perror("../../WindowMaker/Icons");
1183 return;
1186 for (i = 0, j=0; j < 8; i++) {
1187 ent = readdir(dir);
1188 if (!ent)
1189 break;
1191 if (strstr(ent->d_name, ".xpm")==NULL) {
1192 continue;
1195 label = makeDraggableLabel(frame, ent->d_name,4+(j/4)*64, 4+(j%4)*64);
1197 j++;
1200 closedir(dir);
1202 WMMapSubwidgets(frame);
1204 WMMapSubwidgets(win);
1205 WMRealizeWidget(win);
1206 WMMapWidget(win);
1213 /*******************************************************************/
1216 void
1217 testUD()
1219 WMUserDefaults *defs;
1220 char str[32];
1222 defs = WMGetStandardUserDefaults();
1224 sprintf(str, "TEST DATA");
1225 puts(str);
1226 WMSetUDStringForKey(defs, str, "testKey");
1227 puts(str);
1232 main(int argc, char **argv)
1234 WMScreen *scr;
1235 WMPixmap *pixmap;
1238 /* Initialize the application */
1239 WMInitializeApplication("Test@eqweq_ewq$eqw", &argc, argv);
1241 testUD();
1244 * Open connection to the X display.
1246 dpy = XOpenDisplay("");
1248 if (!dpy) {
1249 puts("could not open display");
1250 exit(1);
1253 /* This is used to disable buffering of X protocol requests.
1254 * Do NOT use it unless when debugging. It will cause a major
1255 * slowdown in your application
1257 #if 1
1258 XSynchronize(dpy, True);
1259 #endif
1261 * Create screen descriptor.
1263 scr = WMCreateScreen(dpy, DefaultScreen(dpy));
1266 * Loads the logo of the application.
1268 pixmap = WMCreatePixmapFromFile(scr, "logo.xpm");
1271 * Makes the logo be used in standard dialog panels.
1273 WMSetApplicationIconImage(scr, pixmap); WMReleasePixmap(pixmap);
1276 * Do some test stuff.
1278 * Put the testSomething() function you want to test here.
1282 testScrollView(scr);
1283 testTabView(scr);
1284 #if 0
1285 testBox(scr);
1286 testText(scr);
1287 testList(scr);
1289 testProgressIndicator(scr);
1291 testColorWell(scr);
1293 testTextField(scr);
1295 testDragAndDrop(scr);
1296 testDragAndDrop(scr);
1297 testFontPanel(scr);
1299 testButton(scr);
1301 testFrame(scr);
1307 testSplitView(scr);
1309 testGradientButtons(scr);
1312 testOpenFilePanel(scr);
1314 testSlider(scr);
1315 testPullDown(scr);
1316 #endif
1318 * The main event loop.
1321 WMScreenMainLoop(scr);
1323 return 0;