*** empty log message ***
[wmaker-crm.git] / WINGs / Tests / wtest.c
blob014481443cb3a207013a58a9979e45c3964b7a76
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
119 singleClick(WMWidget *self, void *data)
124 static void
125 doubleClick(WMWidget *self, void *data)
127 WMLabel *label = (WMLabel*)data;
128 WMList *lPtr = (WMList*)self;
129 char buf[255];
131 WMSelectAllListItems(lPtr);
135 static void
136 listSelectionObserver(void *observer, WMNotification *notification)
138 WMLabel *label = (WMLabel*)observer;
139 WMList *lPtr = (WMList*)WMGetNotificationObject(notification);
140 char buf[255];
142 sprintf(buf, "Selected items: %d",
143 WMGetArrayItemCount(WMGetListSelectedItems(lPtr)));
144 WMSetLabelText(label, buf);
148 void
149 testList(WMScreen *scr)
151 WMWindow *win;
152 WMList *list;
153 WMList *mlist;
154 WMLabel *label;
155 WMLabel *mlabel;
156 WMLabel *title;
157 WMLabel *mtitle;
158 char text[100];
159 int i;
161 windowCount++;
163 win = WMCreateWindow(scr, "testList");
164 WMResizeWidget(win, 370, 250);
165 WMSetWindowTitle(win, "List");
166 WMSetWindowCloseAction(win, closeAction, NULL);
168 title = WMCreateLabel(win);
169 WMResizeWidget(title, 150, 20);
170 WMMoveWidget(title, 10, 10);
171 WMSetLabelRelief(title, WRRidge);
172 WMSetLabelText(title, "Single selection list");
174 mtitle = WMCreateLabel(win);
175 WMResizeWidget(mtitle, 150, 20);
176 WMMoveWidget(mtitle, 210, 10);
177 WMSetLabelRelief(mtitle, WRRidge);
178 WMSetLabelText(mtitle, "Multiple selection list");
180 list = WMCreateList(win);
181 WMSetListAllowEmptySelection(list, True);
182 WMMoveWidget(list, 10, 40);
183 for (i=0; i<50; i++) {
184 sprintf(text, "Item %i", i);
185 WMAddListItem(list, text);
187 mlist = WMCreateList(win);
188 WMSetListAllowMultipleSelection(mlist, True);
189 WMSetListAllowEmptySelection(mlist, True);
190 WMMoveWidget(mlist, 210, 40);
191 for (i=0; i<135; i++) {
192 sprintf(text, "Item %i", i);
193 WMAddListItem(mlist, text);
196 label = WMCreateLabel(win);
197 WMResizeWidget(label, 150, 40);
198 WMMoveWidget(label, 10, 200);
199 WMSetLabelRelief(label, WRRidge);
200 WMSetLabelText(label, "Selected items: 0");
202 mlabel = WMCreateLabel(win);
203 WMResizeWidget(mlabel, 150, 40);
204 WMMoveWidget(mlabel, 210, 200);
205 WMSetLabelRelief(mlabel, WRRidge);
206 WMSetLabelText(mlabel, "Selected items: 0");
208 WMSetListAction(list, singleClick, label);
209 WMSetListDoubleAction(list, doubleClick, label);
210 WMSetListAction(mlist, singleClick, mlabel);
211 WMSetListDoubleAction(mlist, doubleClick, mlabel);
213 WMAddNotificationObserver(listSelectionObserver, label,
214 WMListSelectionDidChangeNotification, list);
215 WMAddNotificationObserver(listSelectionObserver, mlabel,
216 WMListSelectionDidChangeNotification, mlist);
219 WMRealizeWidget(win);
220 WMMapSubwidgets(win);
221 WMMapWidget(win);
225 void
226 testButton(WMScreen *scr)
228 WMWindow *win;
229 int i;
230 char *types[] = {
231 "MomentaryPush",
232 "PushOnPushOff",
233 "Toggle",
234 "Switch",
235 "Radio",
236 "MomentaryChange",
237 "OnOff",
238 "MomentaryLigh"
241 windowCount++;
243 win = WMCreateWindow(scr, "testButton");
244 WMResizeWidget(win, 300, 300);
245 WMSetWindowTitle(win, "Buttons");
247 WMSetWindowCloseAction(win, closeAction, NULL);
249 for (i = 1; i < 9; i++) {
250 WMButton *b;
251 b = WMCreateButton(win, i);
252 WMResizeWidget(b, 150, 24);
253 WMMoveWidget(b, 20, i*30);
254 WMSetButtonText(b, types[i-1]);
257 WMRealizeWidget(win);
258 WMMapSubwidgets(win);
259 WMMapWidget(win);
263 void
264 testGradientButtons(WMScreen *scr)
266 WMWindow *win;
267 WMButton *btn;
268 WMPixmap *pix1, *pix2;
269 RImage *back;
270 RColor light, dark;
271 WMColor *color, *altColor;
273 windowCount++;
275 /* creates the top-level window */
276 win = WMCreateWindow(scr, "testGradientButtons");
277 WMSetWindowTitle(win, "Gradiented Button Demo");
278 WMResizeWidget(win, 300, 200);
280 light.red = 0x90;
281 light.green = 0x85;
282 light.blue = 0x90;
283 dark.red = 0x35;
284 dark.green = 0x30;
285 dark.blue = 0x35;
287 color = WMCreateRGBColor(scr, 0x5900, 0x5100, 0x5900, True);
288 WMSetWidgetBackgroundColor(win, color);
289 WMReleaseColor(color);
291 back = RRenderGradient(60, 24, &dark, &light, RGRD_DIAGONAL);
292 RBevelImage(back, RBEV_RAISED2);
293 pix1 = WMCreatePixmapFromRImage(scr, back, 0);
294 RDestroyImage(back);
296 back = RRenderGradient(60, 24, &dark, &light, RGRD_DIAGONAL);
297 RBevelImage(back, RBEV_SUNKEN);
298 pix2 = WMCreatePixmapFromRImage(scr, back, 0);
299 RDestroyImage(back);
301 color = WMWhiteColor(scr);
302 altColor = WMCreateNamedColor(scr, "red", True);
304 btn = WMCreateButton(win, WBTMomentaryChange);
305 WMResizeWidget(btn, 60, 24);
306 WMMoveWidget(btn, 20, 100);
307 WMSetButtonBordered(btn, False);
308 WMSetButtonImagePosition(btn, WIPOverlaps);
309 WMSetButtonImage(btn, pix1);
310 WMSetButtonAltImage(btn, pix2);
311 WMSetButtonText(btn, "Cool");
312 WMSetButtonTextColor(btn, color);
313 WMSetButtonAltTextColor(btn, altColor);
315 WMSetBalloonTextForView("This is a cool button", WMWidgetView(btn));
317 btn = WMCreateButton(win, WBTMomentaryChange);
318 WMResizeWidget(btn, 60, 24);
319 WMMoveWidget(btn, 90, 100);
320 WMSetButtonBordered(btn, False);
321 WMSetButtonImagePosition(btn, WIPOverlaps);
322 WMSetButtonImage(btn, pix1);
323 WMSetButtonAltImage(btn, pix2);
324 WMSetButtonText(btn, "Button");
325 WMSetButtonTextColor(btn, color);
327 WMSetBalloonTextForView("Este é outro balão.", WMWidgetView(btn));
329 WMReleaseColor(color);
330 color = WMCreateNamedColor(scr, "orange", True);
332 btn = WMCreateButton(win, WBTMomentaryChange);
333 WMResizeWidget(btn, 60, 24);
334 WMMoveWidget(btn, 160, 100);
335 WMSetButtonBordered(btn, False);
336 WMSetButtonImagePosition(btn, WIPOverlaps);
337 WMSetButtonImage(btn, pix1);
338 WMSetButtonAltImage(btn, pix2);
339 WMSetButtonText(btn, "Test");
340 WMSetButtonTextColor(btn, color);
342 WMSetBalloonTextForView("This is yet another button.\nBut the balloon has 3 lines.\nYay!",
343 WMWidgetView(btn));
345 WMReleaseColor(color);
346 WMReleaseColor(altColor);
348 WMRealizeWidget(win);
349 WMMapSubwidgets(win);
350 WMMapWidget(win);
354 void
355 testScrollView(WMScreen *scr)
357 WMWindow *win;
358 WMScrollView *sview;
359 WMFrame *f;
360 WMLabel *l;
361 char buffer[128];
362 int i;
364 windowCount++;
366 /* creates the top-level window */
367 win = WMCreateWindow(scr, "testScroll");
368 WMSetWindowTitle(win, "Scrollable View");
370 WMSetWindowCloseAction(win, closeAction, NULL);
372 /* set the window size */
373 WMResizeWidget(win, 300, 300);
375 /* creates a scrollable view inside the top-level window */
376 sview = WMCreateScrollView(win);
377 WMResizeWidget(sview, 200, 200);
378 WMMoveWidget(sview, 30, 30);
379 WMSetScrollViewRelief(sview, WRSunken);
380 WMSetScrollViewHasVerticalScroller(sview, True);
381 WMSetScrollViewHasHorizontalScroller(sview, True);
383 /* create a frame with a bunch of labels */
384 f = WMCreateFrame(win);
385 WMResizeWidget(f, 400, 400);
386 WMSetFrameRelief(f, WRFlat);
388 for (i=0; i<20; i++) {
389 l = WMCreateLabel(f);
390 WMResizeWidget(l, 50, 18);
391 WMMoveWidget(l, 10, 20*i);
392 sprintf(buffer, "Label %i", i);
393 WMSetLabelText(l, buffer);
394 WMSetLabelRelief(l, WRSimple);
396 WMMapSubwidgets(f);
397 WMMapWidget(f);
399 WMSetScrollViewContentView(sview, WMWidgetView(f));
401 /* make the windows of the widgets be actually created */
402 WMRealizeWidget(win);
404 /* Map all child widgets of the top-level be mapped.
405 * You must call this for each container widget (like frames),
406 * even if they are childs of the top-level window.
408 WMMapSubwidgets(win);
410 /* map the top-level window */
411 WMMapWidget(win);
415 void
416 testColorWell(WMScreen *scr)
418 WMWindow *win;
419 WMColorWell *well1, *well2;
421 windowCount++;
423 win = WMCreateWindow(scr, "testColor");
424 WMResizeWidget(win, 300, 300);
425 WMSetWindowCloseAction(win, closeAction, NULL);
427 well1 = WMCreateColorWell(win);
428 WMResizeWidget(well1, 60, 40);
429 WMMoveWidget(well1, 100, 100);
430 WMSetColorWellColor(well1, WMCreateRGBColor(scr, 0x8888, 0, 0x1111, True));
431 well2 = WMCreateColorWell(win);
432 WMResizeWidget(well2, 60, 40);
433 WMMoveWidget(well2, 200, 100);
434 WMSetColorWellColor(well2, WMCreateRGBColor(scr, 0, 0, 0x8888, True));
436 WMRealizeWidget(win);
437 WMMapSubwidgets(win);
438 WMMapWidget(win);
441 void
442 sliderCallback(WMWidget *w, void *data)
444 printf("SLIDER == %i\n", WMGetSliderValue(w));
448 void
449 testSlider(WMScreen *scr)
451 WMWindow *win;
452 WMSlider *s;
454 windowCount++;
456 win = WMCreateWindow(scr, "testSlider");
457 WMResizeWidget(win, 300, 300);
458 WMSetWindowTitle(win, "Sliders");
460 WMSetWindowCloseAction(win, closeAction, NULL);
462 s = WMCreateSlider(win);
463 WMResizeWidget(s, 16, 100);
464 WMMoveWidget(s, 100, 100);
465 WMSetSliderKnobThickness(s, 8);
466 WMSetSliderContinuous(s, False);
467 WMSetSliderAction(s, sliderCallback, s);
469 s = WMCreateSlider(win);
470 WMResizeWidget(s, 100, 16);
471 WMMoveWidget(s, 100, 10);
472 WMSetSliderKnobThickness(s, 8);
474 WMRealizeWidget(win);
475 WMMapSubwidgets(win);
476 WMMapWidget(win);
479 void
480 testTextField(WMScreen *scr)
482 WMWindow *win;
483 WMTextField *field, *field2;
485 windowCount++;
487 win = WMCreateWindow(scr, "testTextField");
488 WMResizeWidget(win, 400, 300);
490 WMSetWindowCloseAction(win, closeAction, NULL);
492 field = WMCreateTextField(win);
493 WMResizeWidget(field, 200, 20);
494 WMMoveWidget(field, 20, 20);
496 field2 = WMCreateTextField(win);
497 WMResizeWidget(field2, 200, 20);
498 WMMoveWidget(field2, 20, 50);
499 WMSetTextFieldAlignment(field2, WARight);
501 WMRealizeWidget(win);
502 WMMapSubwidgets(win);
503 WMMapWidget(win);
508 #if 0
509 void
510 testText(WMScreen *scr)
512 WMWindow *win;
513 WMText *text;
514 FILE *file = fopen("../README", "r");
516 windowCount++;
518 win = WMCreateWindow(scr, "testText");
519 WMResizeWidget(win, 500, 300);
521 WMSetWindowCloseAction(win, closeAction, NULL);
523 text = WMCreateText(win);
524 WMResizeWidget(text, 480, 280);
525 WMMoveWidget(text, 10, 10);
526 WMSetTextHasVerticalScroller(text, True);
527 WMSetTextEditable(text, False);
529 if(file) {
530 char buf[1024];
532 <<<<<<< wtest.c
533 WMFreezeText(text);
534 while(fgets(buf, 1023, file))
535 WMAppendTextStream(text, buf);
537 fclose(file);
538 WMThawText(text);
539 } else {
540 WMAppendTextStream(text, "<HTML><i>Where's</i> the <b>README</b>?");
542 =======
543 WMFreezeText(text);
544 while(fgets(buf, 1023, file))
545 WMAppendTextStream(text, buf);
547 fclose(file);
548 WMThawText(text);
549 WMRefreshText(text, 0, 0);
550 } else {
551 WMAppendTextStream(text, "<HTML><i>Where's</i> the <b>README</b>?");
553 >>>>>>> 1.12
555 WMRealizeWidget(win);
556 WMMapSubwidgets(win);
557 WMMapWidget(win);
559 #endif
562 void
563 testProgressIndicator(WMScreen *scr)
565 WMWindow *win;
566 WMProgressIndicator *pPtr;
568 windowCount++;
570 win = WMCreateWindow(scr, "testProgressIndicator");
571 WMResizeWidget(win, 292, 32);
573 WMSetWindowCloseAction(win, closeAction, NULL);
575 pPtr = WMCreateProgressIndicator(win);
576 WMMoveWidget(pPtr, 8, 8);
577 WMSetProgressIndicatorValue(pPtr, 75);
579 WMRealizeWidget(win);
580 WMMapSubwidgets(win);
581 WMMapWidget(win);
586 void
587 testPullDown(WMScreen *scr)
589 WMWindow *win;
590 WMPopUpButton *pop, *pop2;
592 windowCount++;
594 win = WMCreateWindow(scr, "pullDown");
595 WMResizeWidget(win, 400, 300);
597 WMSetWindowCloseAction(win, closeAction, NULL);
599 pop = WMCreatePopUpButton(win);
600 WMResizeWidget(pop, 100, 20);
601 WMMoveWidget(pop, 50, 60);
602 WMSetPopUpButtonPullsDown(pop, True);
603 WMSetPopUpButtonText(pop, "Commands");
604 WMAddPopUpButtonItem(pop, "Add");
605 WMAddPopUpButtonItem(pop, "Remove");
606 WMAddPopUpButtonItem(pop, "Check");
607 WMAddPopUpButtonItem(pop, "Eat");
609 pop2 = WMCreatePopUpButton(win);
610 WMResizeWidget(pop2, 100, 20);
611 WMMoveWidget(pop2, 200, 60);
612 WMSetPopUpButtonText(pop2, "Select");
613 WMAddPopUpButtonItem(pop2, "Apples");
614 WMAddPopUpButtonItem(pop2, "Bananas");
615 WMAddPopUpButtonItem(pop2, "Strawberries");
616 WMAddPopUpButtonItem(pop2, "Blueberries");
618 WMRealizeWidget(win);
619 WMMapSubwidgets(win);
620 WMMapWidget(win);
625 void
626 testTabView(WMScreen *scr)
628 WMWindow *win;
629 WMTabView *tabv;
630 WMTabViewItem *tab;
631 WMFrame *frame;
632 WMLabel *label;
634 windowCount++;
636 win = WMCreateWindow(scr, "testTabs");
637 WMResizeWidget(win, 400, 300);
639 WMSetWindowCloseAction(win, closeAction, NULL);
641 tabv = WMCreateTabView(win);
642 WMMoveWidget(tabv, 50, 50);
643 WMResizeWidget(tabv, 300, 200);
645 frame = WMCreateFrame(win);
646 WMSetFrameRelief(frame, WRFlat);
647 label = WMCreateLabel(frame);
648 WMResizeWidget(label, 100, 100);
649 WMSetLabelText(label, "Label 1");
650 WMMapWidget(label);
653 tab = WMCreateTabViewItemWithIdentifier(0);
654 WMSetTabViewItemView(tab, WMWidgetView(frame));
655 WMAddItemInTabView(tabv, tab);
656 WMSetTabViewItemLabel(tab, "Instances");
658 frame = WMCreateFrame(win);
659 WMSetFrameRelief(frame, WRFlat);
660 label = WMCreateLabel(frame);
661 WMResizeWidget(label, 40, 50);
662 WMSetLabelText(label, "Label 2");
663 WMMapWidget(label);
666 tab = WMCreateTabViewItemWithIdentifier(0);
667 WMSetTabViewItemView(tab, WMWidgetView(frame));
668 WMAddItemInTabView(tabv, tab);
669 WMSetTabViewItemLabel(tab, "Classes");
672 frame = WMCreateFrame(win);
673 WMSetFrameRelief(frame, WRFlat);
674 label = WMCreateLabel(frame);
675 WMResizeWidget(label, 100, 100);
676 WMMoveWidget(label, 60, 40);
677 WMSetLabelText(label, "Label 3");
678 WMMapWidget(label);
680 tab = WMCreateTabViewItemWithIdentifier(0);
681 WMSetTabViewItemView(tab, WMWidgetView(frame));
682 WMAddItemInTabView(tabv, tab);
683 WMSetTabViewItemLabel(tab, "Something");
686 frame = WMCreateFrame(win);
687 WMSetFrameRelief(frame, WRFlat);
688 label = WMCreateLabel(frame);
689 WMResizeWidget(label, 100, 100);
690 WMMoveWidget(label, 160, 40);
691 WMSetLabelText(label, "Label 4");
692 WMMapWidget(label);
694 tab = WMCreateTabViewItemWithIdentifier(0);
695 WMSetTabViewItemView(tab, WMWidgetView(frame));
696 WMAddItemInTabView(tabv, tab);
697 WMSetTabViewItemLabel(tab, "Bla!");
701 frame = WMCreateFrame(win);
702 WMSetFrameRelief(frame, WRFlat);
703 label = WMCreateLabel(frame);
704 WMResizeWidget(label, 100, 100);
705 WMMoveWidget(label, 160, 40);
706 WMSetLabelText(label, "Label fjweqklrj qwl");
707 WMMapWidget(label);
708 tab = WMCreateTabViewItemWithIdentifier(0);
709 WMSetTabViewItemView(tab, WMWidgetView(frame));
710 WMAddItemInTabView(tabv, tab);
711 WMSetTabViewItemLabel(tab, "Weee!");
714 WMRealizeWidget(win);
715 WMMapSubwidgets(win);
716 WMMapWidget(win);
720 void
721 splitViewConstrainProc(WMSplitView *sPtr, int indView,
722 int *minSize, int *maxSize)
724 switch (indView) {
725 case 0:
726 *minSize = 20;
727 break;
728 case 1:
729 *minSize = 40;
730 *maxSize = 80;
731 break;
732 case 2:
733 *maxSize = 60;
734 break;
735 default:
736 break;
741 static void
742 resizeSplitView(XEvent *event, void *data)
744 WMSplitView *sPtr = (WMSplitView*)data;
746 if (event->type == ConfigureNotify) {
747 int width = event->xconfigure.width - 10;
749 if (width < WMGetSplitViewDividerThickness(sPtr))
750 width = WMGetSplitViewDividerThickness(sPtr);
752 if (width != WMWidgetWidth(sPtr) ||
753 event->xconfigure.height != WMWidgetHeight(sPtr))
754 WMResizeWidget(sPtr, width, event->xconfigure.height - 55);
758 void
759 appendSubviewButtonAction(WMWidget *self, void *data)
761 WMSplitView *sPtr = (WMSplitView*)data;
762 char buf[64];
763 WMLabel *label = WMCreateLabel(sPtr);
765 sprintf(buf, "Subview %d", WMGetSplitViewSubviewsCount(sPtr) + 1);
766 WMSetLabelText(label, buf);
767 WMSetLabelRelief(label, WRSunken);
768 WMAddSplitViewSubview(sPtr, WMWidgetView(label));
769 WMRealizeWidget(label);
770 WMMapWidget(label);
773 void
774 removeSubviewButtonAction(WMWidget *self, void *data)
776 WMSplitView *sPtr = (WMSplitView*)data;
777 int count = WMGetSplitViewSubviewsCount(sPtr);
779 if (count > 2) {
780 WMView *view = WMGetSplitViewSubviewAt(sPtr, count-1);
781 WMDestroyWidget(WMWidgetOfView(view));
782 WMRemoveSplitViewSubviewAt(sPtr, count-1);
786 void
787 orientationButtonAction(WMWidget *self, void *data)
789 WMSplitView *sPtr = (WMSplitView*)data;
790 WMSetSplitViewVertical(sPtr, !WMGetSplitViewVertical(sPtr));
793 void
794 adjustSubviewsButtonAction(WMWidget *self, void *data)
796 WMAdjustSplitViewSubviews((WMSplitView*)data);
799 void
800 testSplitView(WMScreen *scr)
802 WMWindow *win;
803 WMSplitView *splitv1, *splitv2;
804 WMFrame *frame;
805 WMLabel *label;
806 WMButton *button;
808 windowCount++;
810 win = WMCreateWindow(scr, "testTabs");
811 WMResizeWidget(win, 300, 400);
812 WMSetWindowCloseAction(win, closeAction, NULL);
814 frame = WMCreateFrame(win);
815 WMSetFrameRelief(frame, WRSunken);
816 WMMoveWidget(frame, 5, 5);
817 WMResizeWidget(frame, 290, 40);
819 splitv1 = WMCreateSplitView(win);
820 WMMoveWidget(splitv1, 5, 50);
821 WMResizeWidget(splitv1, 290, 345);
822 WMSetSplitViewConstrainProc(splitv1, splitViewConstrainProc);
823 WMCreateEventHandler(WMWidgetView(win), StructureNotifyMask,
824 resizeSplitView, splitv1);
826 button = WMCreateCommandButton(frame);
827 WMSetButtonText(button, "+");
828 WMSetButtonAction(button, appendSubviewButtonAction, splitv1);
829 WMMoveWidget(button, 10, 8);
830 WMMapWidget(button);
832 button = WMCreateCommandButton(frame);
833 WMSetButtonText(button, "-");
834 WMSetButtonAction(button, removeSubviewButtonAction, splitv1);
835 WMMoveWidget(button, 80, 8);
836 WMMapWidget(button);
838 button = WMCreateCommandButton(frame);
839 WMSetButtonText(button, "=");
840 WMMoveWidget(button, 150, 8);
841 WMSetButtonAction(button, adjustSubviewsButtonAction, splitv1);
842 WMMapWidget(button);
844 button = WMCreateCommandButton(frame);
845 WMSetButtonText(button, "#");
846 WMMoveWidget(button, 220, 8);
847 WMSetButtonAction(button, orientationButtonAction, splitv1);
848 WMMapWidget(button);
850 label = WMCreateLabel(splitv1);
851 WMSetLabelText(label, "Subview 1");
852 WMSetLabelRelief(label, WRSunken);
853 WMMapWidget(label);
854 WMAddSplitViewSubview(splitv1, WMWidgetView(label));
856 splitv2 = WMCreateSplitView(splitv1);
857 WMResizeWidget(splitv2, 150, 150);
858 WMSetSplitViewVertical(splitv2, True);
860 label = WMCreateLabel(splitv2);
861 WMSetLabelText(label, "Subview 2.1");
862 WMSetLabelRelief(label, WRSunken);
863 WMMapWidget(label);
864 WMAddSplitViewSubview(splitv2, WMWidgetView(label));
866 label = WMCreateLabel(splitv2);
867 WMSetLabelText(label, "Subview 2.2");
868 WMSetLabelRelief(label, WRSunken);
869 WMMapWidget(label);
870 WMAddSplitViewSubview(splitv2, WMWidgetView(label));
872 label = WMCreateLabel(splitv2);
873 WMSetLabelText(label, "Subview 2.3");
874 WMSetLabelRelief(label, WRSunken);
875 WMMapWidget(label);
876 WMAddSplitViewSubview(splitv2, WMWidgetView(label));
878 WMMapWidget(splitv2);
879 WMAddSplitViewSubview(splitv1, WMWidgetView(splitv2));
881 WMRealizeWidget(win);
882 WMMapSubwidgets(win);
883 WMMapWidget(win);
887 /*******************************************************************/
889 #include <sys/types.h>
890 #include <dirent.h>
891 #include <string.h>
894 typedef struct {
895 int x, y;
896 Bool mouseDown;
897 char *filename;
898 } DNDStuff;
900 WMPixmap*
901 getImage(WMScreen *scr, char *file)
903 char buffer[1000];
904 WMPixmap *pix;
906 sprintf(buffer, "../../WindowMaker/Icons/%s", file);
907 pix = WMCreatePixmapFromFile(scr, buffer);
909 return pix;
915 static void
916 iconMouseStuff(XEvent *event, void *cdata)
918 WMLabel *label = (WMLabel*)cdata;
919 DNDStuff *stuff = WMGetHangedData(label);
920 WMPoint where;
922 switch (event->type) {
923 case ButtonPress:
924 stuff->x = event->xbutton.x;
925 stuff->y = event->xbutton.y;
926 stuff->mouseDown = True;
927 break;
928 case ButtonRelease:
929 stuff->mouseDown = False;
930 break;
931 case MotionNotify:
932 if (!stuff->mouseDown)
933 break;
935 if (abs(stuff->x - event->xmotion.x)>4
936 || abs(stuff->y - event->xmotion.y)>4) {
938 where = WMGetViewScreenPosition(WMWidgetView(label));
940 WMDragImageFromView(WMWidgetView(label),
941 WMGetLabelImage(label),
942 NULL, /* XXX */
943 where,
944 wmksize(stuff->x, stuff->y),
945 event, True);
947 break;
952 static void
953 endedDragImage(WMView *self, WMPixmap *image, WMPoint point, Bool deposited)
955 DNDStuff *stuff = WMGetHangedData(WMWidgetOfView(self));
957 if (deposited) {
958 WMDestroyWidget(WMWidgetOfView(self));
961 stuff->mouseDown = False;
965 static WMData*
966 fetchDragData(WMView *self, char *type)
968 DNDStuff *stuff = WMGetHangedData(WMWidgetOfView(self));
970 return WMCreateDataWithBytes(stuff->filename, strlen(stuff->filename)+1);
974 WMDragSourceProcs dragSourceProcs = {
975 NULL,
976 NULL,
977 endedDragImage,
978 fetchDragData
982 /************************/
985 unsigned
986 draggingEntered(WMView *self, WMDraggingInfo *info)
988 return WDOperationCopy;
992 unsigned
993 draggingUpdated(WMView *self, WMDraggingInfo *info)
995 return WDOperationCopy;
999 void (*draggingExited)(WMView *self, WMDraggingInfo *info);
1001 char*
1002 prepareForDragOperation(WMView *self, WMDraggingInfo *info)
1004 return "application/X-WINGs-Bla";
1008 WMLabel* makeDraggableLabel(WMWidget *w, char *file, int x, int y);
1010 Bool
1011 performDragOperation(WMView *self, WMDraggingInfo *info, WMData *data)
1013 char *file = (char*)WMDataBytes(data);
1014 WMPoint pos;
1016 pos = WMGetDraggingInfoImageLocation(info);
1018 if (file!=NULL) {
1019 WMLabel *label;
1020 WMPoint pos2 = WMGetViewScreenPosition(self);
1023 label = makeDraggableLabel(WMWidgetOfView(self), file,
1024 pos.x-pos2.x, pos.y-pos2.y);
1025 WMRealizeWidget(label);
1026 WMMapWidget(label);
1030 return True;
1034 void
1035 concludeDragOperation(WMView *self, WMDraggingInfo *info)
1042 WMDragDestinationProcs dragDestProcs = {
1043 draggingEntered,
1044 draggingUpdated,
1045 NULL,
1046 prepareForDragOperation,
1047 performDragOperation,
1048 concludeDragOperation
1054 WMLabel*
1055 makeDraggableLabel(WMWidget *w, char *file, int x, int y)
1057 DNDStuff *stuff;
1058 WMLabel *label;
1059 WMPixmap *image = getImage(WMWidgetScreen(w), file);
1061 stuff = wmalloc(sizeof(DNDStuff));
1062 stuff->mouseDown = False;
1064 stuff->filename = wstrdup(file);
1066 label = WMCreateLabel(w);
1067 WMResizeWidget(label, 48, 48);
1068 WMMoveWidget(label, x, y);
1070 WMSetViewDragSourceProcs(WMWidgetView(label), &dragSourceProcs);
1072 WMHangData(label, stuff);
1074 WMCreateEventHandler(WMWidgetView(label),
1075 ButtonPressMask|ButtonReleaseMask|ButtonMotionMask,
1076 iconMouseStuff, label);
1079 if (image != NULL) {
1080 WMSetLabelImagePosition(label, WIPImageOnly);
1081 WMSetLabelImage(label, image);
1082 WMReleasePixmap(image);
1083 } else puts(file);
1085 return label;
1090 void
1091 testDragAndDrop(WMScreen *scr)
1093 WMWindow *win;
1094 WMFrame *frame;
1095 WMLabel *label;
1096 int i, j;
1097 DIR *dir;
1098 struct dirent *ent;
1099 char *types[] = {
1100 "application/X-WINGs-Bla",
1101 NULL
1104 windowCount++;
1106 win = WMCreateWindow(scr, "dragDrop");
1107 WMResizeWidget(win, 300, 300);
1108 WMSetWindowCloseAction(win, closeAction, NULL);
1109 WMSetWindowTitle(win, "Drag and Drop");
1112 frame = WMCreateFrame(win);
1113 WMSetFrameRelief(frame, WRSunken);
1114 WMResizeWidget(frame, 250, 250);
1115 WMMoveWidget(frame, 25, 25);
1117 WMRegisterViewForDraggedTypes(WMWidgetView(frame), types);
1118 WMSetViewDragDestinationProcs(WMWidgetView(frame), &dragDestProcs);
1120 dir = opendir("../../WindowMaker/Icons");
1121 if (!dir) {
1122 perror("../../WindowMaker/Icons");
1123 return;
1126 for (i = 0, j=0; j < 8; i++) {
1127 ent = readdir(dir);
1128 if (!ent)
1129 break;
1131 if (strstr(ent->d_name, ".xpm")==NULL) {
1132 continue;
1135 label = makeDraggableLabel(frame, ent->d_name,4+(j/4)*64, 4+(j%4)*64);
1137 j++;
1140 closedir(dir);
1142 WMMapSubwidgets(frame);
1144 WMMapSubwidgets(win);
1145 WMRealizeWidget(win);
1146 WMMapWidget(win);
1153 /*******************************************************************/
1155 #include "WUtil.h"
1157 void
1158 testUD()
1160 WMUserDefaults *defs;
1161 char str[32];
1163 defs = WMGetStandardUserDefaults();
1165 sprintf(str, "TEST DATA");
1166 puts(str);
1167 WMSetUDStringForKey(defs, str, "testKey");
1168 puts(str);
1173 main(int argc, char **argv)
1175 WMScreen *scr;
1176 WMPixmap *pixmap;
1179 /* Initialize the application */
1180 WMInitializeApplication("Test", &argc, argv);
1182 testUD();
1185 * Open connection to the X display.
1187 dpy = XOpenDisplay("");
1189 if (!dpy) {
1190 puts("could not open display");
1191 exit(1);
1194 /* This is used to disable buffering of X protocol requests.
1195 * Do NOT use it unless when debugging. It will cause a major
1196 * slowdown in your application
1198 #if 1
1199 XSynchronize(dpy, True);
1200 #endif
1202 * Create screen descriptor.
1204 scr = WMCreateScreen(dpy, DefaultScreen(dpy));
1207 * Loads the logo of the application.
1209 pixmap = WMCreatePixmapFromFile(scr, "logo.xpm");
1212 * Makes the logo be used in standard dialog panels.
1214 WMSetApplicationIconImage(scr, pixmap); WMReleasePixmap(pixmap);
1217 * Do some test stuff.
1219 * Put the testSomething() function you want to test here.
1222 testList(scr);
1224 #if 0
1225 testColorWell(scr);
1227 testTextField(scr);
1228 testText(scr);
1230 testDragAndDrop(scr);
1231 testDragAndDrop(scr);
1232 testFontPanel(scr);
1234 testScrollView(scr);
1236 testButton(scr);
1238 testFrame(scr);
1241 testTabView(scr);
1245 testSplitView(scr);
1247 testGradientButtons(scr);
1248 testProgressIndicator(scr);
1251 testOpenFilePanel(scr);
1253 testSlider(scr);
1254 testPullDown(scr);
1255 #endif
1257 * The main event loop.
1260 WMScreenMainLoop(scr);
1262 return 0;