various table widget updates
[wmaker-crm.git] / WINGs / Tests / wtest.c
blob43b9879b37bffa168be3a0fb3a090697523dadaf
1 /*
2 * WINGs test application
3 */
5 #include "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, "<HTML><i>Where's</i> the <b>README</b>?");
610 WMRealizeWidget(win);
611 WMMapSubwidgets(win);
612 WMMapWidget(win);
616 void
617 testProgressIndicator(WMScreen *scr)
619 WMWindow *win;
620 WMProgressIndicator *pPtr;
622 windowCount++;
624 win = WMCreateWindow(scr, "testProgressIndicator");
625 WMResizeWidget(win, 292, 32);
627 WMSetWindowCloseAction(win, closeAction, NULL);
629 pPtr = WMCreateProgressIndicator(win);
630 WMMoveWidget(pPtr, 8, 8);
631 WMSetProgressIndicatorValue(pPtr, 75);
633 WMRealizeWidget(win);
634 WMMapSubwidgets(win);
635 WMMapWidget(win);
640 void
641 testPullDown(WMScreen *scr)
643 WMWindow *win;
644 WMPopUpButton *pop, *pop2;
646 windowCount++;
648 win = WMCreateWindow(scr, "pullDown");
649 WMResizeWidget(win, 400, 300);
651 WMSetWindowCloseAction(win, closeAction, NULL);
653 pop = WMCreatePopUpButton(win);
654 WMResizeWidget(pop, 100, 20);
655 WMMoveWidget(pop, 50, 60);
656 WMSetPopUpButtonPullsDown(pop, True);
657 WMSetPopUpButtonText(pop, "Commands");
658 WMAddPopUpButtonItem(pop, "Add");
659 WMAddPopUpButtonItem(pop, "Remove");
660 WMAddPopUpButtonItem(pop, "Check");
661 WMAddPopUpButtonItem(pop, "Eat");
663 pop2 = WMCreatePopUpButton(win);
664 WMResizeWidget(pop2, 100, 20);
665 WMMoveWidget(pop2, 200, 60);
666 WMSetPopUpButtonText(pop2, "Select");
667 WMAddPopUpButtonItem(pop2, "Apples");
668 WMAddPopUpButtonItem(pop2, "Bananas");
669 WMAddPopUpButtonItem(pop2, "Strawberries");
670 WMAddPopUpButtonItem(pop2, "Blueberries");
672 WMRealizeWidget(win);
673 WMMapSubwidgets(win);
674 WMMapWidget(win);
679 void
680 testTabView(WMScreen *scr)
682 WMWindow *win;
683 WMTabView *tabv;
684 WMTabViewItem *tab;
685 WMFrame *frame;
686 WMLabel *label;
688 windowCount++;
690 win = WMCreateWindow(scr, "testTabs");
691 WMResizeWidget(win, 400, 300);
693 WMSetWindowCloseAction(win, closeAction, NULL);
695 tabv = WMCreateTabView(win);
696 WMMoveWidget(tabv, 50, 50);
697 WMResizeWidget(tabv, 300, 200);
699 frame = WMCreateFrame(win);
700 WMSetFrameRelief(frame, WRFlat);
701 label = WMCreateLabel(frame);
702 WMResizeWidget(label, 100, 100);
703 WMSetLabelText(label, "Label 1");
704 WMMapWidget(label);
707 tab = WMCreateTabViewItemWithIdentifier(0);
708 WMSetTabViewItemView(tab, WMWidgetView(frame));
709 WMAddItemInTabView(tabv, tab);
710 WMSetTabViewItemLabel(tab, "Instances");
712 frame = WMCreateFrame(win);
713 WMSetFrameRelief(frame, WRFlat);
714 label = WMCreateLabel(frame);
715 WMResizeWidget(label, 40, 50);
716 WMSetLabelText(label, "Label 2");
717 WMMapWidget(label);
720 tab = WMCreateTabViewItemWithIdentifier(0);
721 WMSetTabViewItemView(tab, WMWidgetView(frame));
722 WMAddItemInTabView(tabv, tab);
723 WMSetTabViewItemLabel(tab, "Classes");
726 frame = WMCreateFrame(win);
727 WMSetFrameRelief(frame, WRFlat);
728 label = WMCreateLabel(frame);
729 WMResizeWidget(label, 100, 100);
730 WMMoveWidget(label, 60, 40);
731 WMSetLabelText(label, "Label 3");
732 WMMapWidget(label);
734 tab = WMCreateTabViewItemWithIdentifier(0);
735 WMSetTabViewItemView(tab, WMWidgetView(frame));
736 WMAddItemInTabView(tabv, tab);
737 WMSetTabViewItemLabel(tab, "Something");
740 frame = WMCreateFrame(win);
741 WMSetFrameRelief(frame, WRFlat);
742 label = WMCreateLabel(frame);
743 WMResizeWidget(label, 100, 100);
744 WMMoveWidget(label, 160, 40);
745 WMSetLabelText(label, "Label 4");
746 WMMapWidget(label);
748 tab = WMCreateTabViewItemWithIdentifier(0);
749 WMSetTabViewItemView(tab, WMWidgetView(frame));
750 WMAddItemInTabView(tabv, tab);
751 WMSetTabViewItemLabel(tab, "Bla!");
755 frame = WMCreateFrame(win);
756 WMSetFrameRelief(frame, WRFlat);
757 label = WMCreateLabel(frame);
758 WMResizeWidget(label, 100, 100);
759 WMMoveWidget(label, 160, 40);
760 WMSetLabelText(label, "Label fjweqklrj qwl");
761 WMMapWidget(label);
762 tab = WMCreateTabViewItemWithIdentifier(0);
763 WMSetTabViewItemView(tab, WMWidgetView(frame));
764 WMAddItemInTabView(tabv, tab);
765 WMSetTabViewItemLabel(tab, "Weee!");
768 WMRealizeWidget(win);
769 WMMapSubwidgets(win);
770 WMMapWidget(win);
774 void
775 splitViewConstrainProc(WMSplitView *sPtr, int indView,
776 int *minSize, int *maxSize)
778 switch (indView) {
779 case 0:
780 *minSize = 20;
781 break;
782 case 1:
783 *minSize = 40;
784 *maxSize = 80;
785 break;
786 case 2:
787 *maxSize = 60;
788 break;
789 default:
790 break;
795 static void
796 resizeSplitView(XEvent *event, void *data)
798 WMSplitView *sPtr = (WMSplitView*)data;
800 if (event->type == ConfigureNotify) {
801 int width = event->xconfigure.width - 10;
803 if (width < WMGetSplitViewDividerThickness(sPtr))
804 width = WMGetSplitViewDividerThickness(sPtr);
806 if (width != WMWidgetWidth(sPtr) ||
807 event->xconfigure.height != WMWidgetHeight(sPtr))
808 WMResizeWidget(sPtr, width, event->xconfigure.height - 55);
812 void
813 appendSubviewButtonAction(WMWidget *self, void *data)
815 WMSplitView *sPtr = (WMSplitView*)data;
816 char buf[64];
817 WMLabel *label = WMCreateLabel(sPtr);
819 sprintf(buf, "Subview %d", WMGetSplitViewSubviewsCount(sPtr) + 1);
820 WMSetLabelText(label, buf);
821 WMSetLabelRelief(label, WRSunken);
822 WMAddSplitViewSubview(sPtr, WMWidgetView(label));
823 WMRealizeWidget(label);
824 WMMapWidget(label);
827 void
828 removeSubviewButtonAction(WMWidget *self, void *data)
830 WMSplitView *sPtr = (WMSplitView*)data;
831 int count = WMGetSplitViewSubviewsCount(sPtr);
833 if (count > 2) {
834 WMView *view = WMGetSplitViewSubviewAt(sPtr, count-1);
835 WMDestroyWidget(WMWidgetOfView(view));
836 WMRemoveSplitViewSubviewAt(sPtr, count-1);
840 void
841 orientationButtonAction(WMWidget *self, void *data)
843 WMSplitView *sPtr = (WMSplitView*)data;
844 WMSetSplitViewVertical(sPtr, !WMGetSplitViewVertical(sPtr));
847 void
848 adjustSubviewsButtonAction(WMWidget *self, void *data)
850 WMAdjustSplitViewSubviews((WMSplitView*)data);
853 void
854 testSplitView(WMScreen *scr)
856 WMWindow *win;
857 WMSplitView *splitv1, *splitv2;
858 WMFrame *frame;
859 WMLabel *label;
860 WMButton *button;
862 windowCount++;
864 win = WMCreateWindow(scr, "testTabs");
865 WMResizeWidget(win, 300, 400);
866 WMSetWindowCloseAction(win, closeAction, NULL);
868 frame = WMCreateFrame(win);
869 WMSetFrameRelief(frame, WRSunken);
870 WMMoveWidget(frame, 5, 5);
871 WMResizeWidget(frame, 290, 40);
873 splitv1 = WMCreateSplitView(win);
874 WMMoveWidget(splitv1, 5, 50);
875 WMResizeWidget(splitv1, 290, 345);
876 WMSetSplitViewConstrainProc(splitv1, splitViewConstrainProc);
877 WMCreateEventHandler(WMWidgetView(win), StructureNotifyMask,
878 resizeSplitView, splitv1);
880 button = WMCreateCommandButton(frame);
881 WMSetButtonText(button, "+");
882 WMSetButtonAction(button, appendSubviewButtonAction, splitv1);
883 WMMoveWidget(button, 10, 8);
884 WMMapWidget(button);
886 button = WMCreateCommandButton(frame);
887 WMSetButtonText(button, "-");
888 WMSetButtonAction(button, removeSubviewButtonAction, splitv1);
889 WMMoveWidget(button, 80, 8);
890 WMMapWidget(button);
892 button = WMCreateCommandButton(frame);
893 WMSetButtonText(button, "=");
894 WMMoveWidget(button, 150, 8);
895 WMSetButtonAction(button, adjustSubviewsButtonAction, splitv1);
896 WMMapWidget(button);
898 button = WMCreateCommandButton(frame);
899 WMSetButtonText(button, "#");
900 WMMoveWidget(button, 220, 8);
901 WMSetButtonAction(button, orientationButtonAction, splitv1);
902 WMMapWidget(button);
904 label = WMCreateLabel(splitv1);
905 WMSetLabelText(label, "Subview 1");
906 WMSetLabelRelief(label, WRSunken);
907 WMMapWidget(label);
908 WMAddSplitViewSubview(splitv1, WMWidgetView(label));
910 splitv2 = WMCreateSplitView(splitv1);
911 WMResizeWidget(splitv2, 150, 150);
912 WMSetSplitViewVertical(splitv2, True);
914 label = WMCreateLabel(splitv2);
915 WMSetLabelText(label, "Subview 2.1");
916 WMSetLabelRelief(label, WRSunken);
917 WMMapWidget(label);
918 WMAddSplitViewSubview(splitv2, WMWidgetView(label));
920 label = WMCreateLabel(splitv2);
921 WMSetLabelText(label, "Subview 2.2");
922 WMSetLabelRelief(label, WRSunken);
923 WMMapWidget(label);
924 WMAddSplitViewSubview(splitv2, WMWidgetView(label));
926 label = WMCreateLabel(splitv2);
927 WMSetLabelText(label, "Subview 2.3");
928 WMSetLabelRelief(label, WRSunken);
929 WMMapWidget(label);
930 WMAddSplitViewSubview(splitv2, WMWidgetView(label));
932 WMMapWidget(splitv2);
933 WMAddSplitViewSubview(splitv1, WMWidgetView(splitv2));
935 WMRealizeWidget(win);
936 WMMapSubwidgets(win);
937 WMMapWidget(win);
941 /*******************************************************************/
943 #include <sys/types.h>
944 #include <dirent.h>
945 #include <string.h>
948 typedef struct {
949 int x, y;
950 Bool mouseDown;
951 char *filename;
952 } DNDStuff;
954 WMPixmap*
955 getImage(WMScreen *scr, char *file)
957 char buffer[1000];
958 WMPixmap *pix;
960 sprintf(buffer, "../../WindowMaker/Icons/%s", file);
961 pix = WMCreatePixmapFromFile(scr, buffer);
963 return pix;
969 static void
970 iconMouseStuff(XEvent *event, void *cdata)
972 WMLabel *label = (WMLabel*)cdata;
973 DNDStuff *stuff = WMGetHangedData(label);
974 WMPoint where;
976 switch (event->type) {
977 case ButtonPress:
978 stuff->x = event->xbutton.x;
979 stuff->y = event->xbutton.y;
980 stuff->mouseDown = True;
981 break;
982 case ButtonRelease:
983 stuff->mouseDown = False;
984 break;
985 case MotionNotify:
986 if (!stuff->mouseDown)
987 break;
989 if (abs(stuff->x - event->xmotion.x)>4
990 || abs(stuff->y - event->xmotion.y)>4) {
992 where = WMGetViewScreenPosition(WMWidgetView(label));
994 WMDragImageFromView(WMWidgetView(label),
995 WMGetLabelImage(label),
996 NULL, /* XXX */
997 where,
998 wmksize(stuff->x, stuff->y),
999 event, True);
1001 break;
1006 static void
1007 endedDragImage(WMView *self, WMPixmap *image, WMPoint point, Bool deposited)
1009 DNDStuff *stuff = WMGetHangedData(WMWidgetOfView(self));
1011 if (deposited) {
1012 WMDestroyWidget(WMWidgetOfView(self));
1015 stuff->mouseDown = False;
1019 static WMData*
1020 fetchDragData(WMView *self, char *type)
1022 DNDStuff *stuff = WMGetHangedData(WMWidgetOfView(self));
1024 return WMCreateDataWithBytes(stuff->filename, strlen(stuff->filename)+1);
1028 WMDragSourceProcs dragSourceProcs = {
1029 NULL,
1030 NULL,
1031 endedDragImage,
1032 fetchDragData
1036 /************************/
1039 unsigned
1040 draggingEntered(WMView *self, WMDraggingInfo *info)
1042 return WDOperationCopy;
1046 unsigned
1047 draggingUpdated(WMView *self, WMDraggingInfo *info)
1049 return WDOperationCopy;
1053 void (*draggingExited)(WMView *self, WMDraggingInfo *info);
1055 char*
1056 prepareForDragOperation(WMView *self, WMDraggingInfo *info)
1058 return "application/X-WINGs-Bla";
1062 WMLabel* makeDraggableLabel(WMWidget *w, char *file, int x, int y);
1064 Bool
1065 performDragOperation(WMView *self, WMDraggingInfo *info, WMData *data)
1067 char *file = (char*)WMDataBytes(data);
1068 WMPoint pos;
1070 pos = WMGetDraggingInfoImageLocation(info);
1072 if (file!=NULL) {
1073 WMLabel *label;
1074 WMPoint pos2 = WMGetViewScreenPosition(self);
1077 label = makeDraggableLabel(WMWidgetOfView(self), file,
1078 pos.x-pos2.x, pos.y-pos2.y);
1079 WMRealizeWidget(label);
1080 WMMapWidget(label);
1084 return True;
1088 void
1089 concludeDragOperation(WMView *self, WMDraggingInfo *info)
1096 WMDragDestinationProcs dragDestProcs = {
1097 draggingEntered,
1098 draggingUpdated,
1099 NULL,
1100 prepareForDragOperation,
1101 performDragOperation,
1102 concludeDragOperation
1108 WMLabel*
1109 makeDraggableLabel(WMWidget *w, char *file, int x, int y)
1111 DNDStuff *stuff;
1112 WMLabel *label;
1113 WMPixmap *image = getImage(WMWidgetScreen(w), file);
1115 stuff = wmalloc(sizeof(DNDStuff));
1116 stuff->mouseDown = False;
1118 stuff->filename = wstrdup(file);
1120 label = WMCreateLabel(w);
1121 WMResizeWidget(label, 48, 48);
1122 WMMoveWidget(label, x, y);
1124 WMSetViewDragSourceProcs(WMWidgetView(label), &dragSourceProcs);
1126 WMHangData(label, stuff);
1128 WMCreateEventHandler(WMWidgetView(label),
1129 ButtonPressMask|ButtonReleaseMask|ButtonMotionMask,
1130 iconMouseStuff, label);
1133 if (image != NULL) {
1134 WMSetLabelImagePosition(label, WIPImageOnly);
1135 WMSetLabelImage(label, image);
1136 WMReleasePixmap(image);
1137 } else puts(file);
1139 return label;
1144 void
1145 testDragAndDrop(WMScreen *scr)
1147 WMWindow *win;
1148 WMFrame *frame;
1149 WMLabel *label;
1150 int i, j;
1151 DIR *dir;
1152 struct dirent *ent;
1153 char *types[] = {
1154 "application/X-WINGs-Bla",
1155 NULL
1158 windowCount++;
1160 win = WMCreateWindow(scr, "dragDrop");
1161 WMResizeWidget(win, 300, 300);
1162 WMSetWindowCloseAction(win, closeAction, NULL);
1163 WMSetWindowTitle(win, "Drag and Drop");
1166 frame = WMCreateFrame(win);
1167 WMSetFrameRelief(frame, WRSunken);
1168 WMResizeWidget(frame, 250, 250);
1169 WMMoveWidget(frame, 25, 25);
1171 WMRegisterViewForDraggedTypes(WMWidgetView(frame), types);
1172 WMSetViewDragDestinationProcs(WMWidgetView(frame), &dragDestProcs);
1174 dir = opendir("../../WindowMaker/Icons");
1175 if (!dir) {
1176 perror("../../WindowMaker/Icons");
1177 return;
1180 for (i = 0, j=0; j < 8; i++) {
1181 ent = readdir(dir);
1182 if (!ent)
1183 break;
1185 if (strstr(ent->d_name, ".xpm")==NULL) {
1186 continue;
1189 label = makeDraggableLabel(frame, ent->d_name,4+(j/4)*64, 4+(j%4)*64);
1191 j++;
1194 closedir(dir);
1196 WMMapSubwidgets(frame);
1198 WMMapSubwidgets(win);
1199 WMRealizeWidget(win);
1200 WMMapWidget(win);
1207 /*******************************************************************/
1209 #include "WUtil.h"
1211 void
1212 testUD()
1214 WMUserDefaults *defs;
1215 char str[32];
1217 defs = WMGetStandardUserDefaults();
1219 sprintf(str, "TEST DATA");
1220 puts(str);
1221 WMSetUDStringForKey(defs, str, "testKey");
1222 puts(str);
1227 main(int argc, char **argv)
1229 WMScreen *scr;
1230 WMPixmap *pixmap;
1233 /* Initialize the application */
1234 WMInitializeApplication("Test@eqweq_ewq$eqw", &argc, argv);
1236 testUD();
1239 * Open connection to the X display.
1241 dpy = XOpenDisplay("");
1243 if (!dpy) {
1244 puts("could not open display");
1245 exit(1);
1248 /* This is used to disable buffering of X protocol requests.
1249 * Do NOT use it unless when debugging. It will cause a major
1250 * slowdown in your application
1252 #if 1
1253 XSynchronize(dpy, True);
1254 #endif
1256 * Create screen descriptor.
1258 scr = WMCreateScreen(dpy, DefaultScreen(dpy));
1261 * Loads the logo of the application.
1263 pixmap = WMCreatePixmapFromFile(scr, "logo.xpm");
1266 * Makes the logo be used in standard dialog panels.
1268 WMSetApplicationIconImage(scr, pixmap); WMReleasePixmap(pixmap);
1271 * Do some test stuff.
1273 * Put the testSomething() function you want to test here.
1277 testTabView(scr);
1278 #if 0
1279 testBox(scr);
1280 testText(scr);
1281 testList(scr);
1283 testProgressIndicator(scr);
1285 testColorWell(scr);
1287 testTextField(scr);
1289 testDragAndDrop(scr);
1290 testDragAndDrop(scr);
1291 testFontPanel(scr);
1293 testScrollView(scr);
1294 testButton(scr);
1296 testFrame(scr);
1302 testSplitView(scr);
1304 testGradientButtons(scr);
1307 testOpenFilePanel(scr);
1309 testSlider(scr);
1310 testPullDown(scr);
1311 #endif
1313 * The main event loop.
1316 WMScreenMainLoop(scr);
1318 return 0;