small update
[wmaker-crm.git] / WINGs / Tests / wtest.c
blobac5e5b2820c3a049d797b05d4b25d478864ce2e6
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);
507 void
508 testText(WMScreen *scr)
510 WMWindow *win;
511 WMText *text;
512 FILE *file = fopen("../README", "r");
514 windowCount++;
516 win = WMCreateWindow(scr, "testText");
517 WMResizeWidget(win, 500, 300);
519 WMSetWindowCloseAction(win, closeAction, NULL);
521 text = WMCreateText(win);
522 WMResizeWidget(text, 480, 280);
523 WMMoveWidget(text, 10, 10);
524 WMSetTextHasVerticalScroller(text, True);
525 WMSetTextEditable(text, False);
527 if(file) {
528 char buf[1024];
530 WMFreezeText(text);
531 while(fgets(buf, 1023, file))
532 WMAppendTextStream(text, buf);
534 fclose(file);
535 WMThawText(text);
536 WMRefreshText(text, 0, 0);
537 } else {
538 WMAppendTextStream(text, "<HTML><i>Where's</i> the <b>README</b>?");
541 WMRealizeWidget(win);
542 WMMapSubwidgets(win);
543 WMMapWidget(win);
548 void
549 testProgressIndicator(WMScreen *scr)
551 WMWindow *win;
552 WMProgressIndicator *pPtr;
554 windowCount++;
556 win = WMCreateWindow(scr, "testProgressIndicator");
557 WMResizeWidget(win, 292, 32);
559 WMSetWindowCloseAction(win, closeAction, NULL);
561 pPtr = WMCreateProgressIndicator(win);
562 WMMoveWidget(pPtr, 8, 8);
563 WMSetProgressIndicatorValue(pPtr, 75);
565 WMRealizeWidget(win);
566 WMMapSubwidgets(win);
567 WMMapWidget(win);
572 void
573 testPullDown(WMScreen *scr)
575 WMWindow *win;
576 WMPopUpButton *pop, *pop2;
578 windowCount++;
580 win = WMCreateWindow(scr, "pullDown");
581 WMResizeWidget(win, 400, 300);
583 WMSetWindowCloseAction(win, closeAction, NULL);
585 pop = WMCreatePopUpButton(win);
586 WMResizeWidget(pop, 100, 20);
587 WMMoveWidget(pop, 50, 60);
588 WMSetPopUpButtonPullsDown(pop, True);
589 WMSetPopUpButtonText(pop, "Commands");
590 WMAddPopUpButtonItem(pop, "Add");
591 WMAddPopUpButtonItem(pop, "Remove");
592 WMAddPopUpButtonItem(pop, "Check");
593 WMAddPopUpButtonItem(pop, "Eat");
595 pop2 = WMCreatePopUpButton(win);
596 WMResizeWidget(pop2, 100, 20);
597 WMMoveWidget(pop2, 200, 60);
598 WMSetPopUpButtonText(pop2, "Select");
599 WMAddPopUpButtonItem(pop2, "Apples");
600 WMAddPopUpButtonItem(pop2, "Bananas");
601 WMAddPopUpButtonItem(pop2, "Strawberries");
602 WMAddPopUpButtonItem(pop2, "Blueberries");
604 WMRealizeWidget(win);
605 WMMapSubwidgets(win);
606 WMMapWidget(win);
611 void
612 testTabView(WMScreen *scr)
614 WMWindow *win;
615 WMTabView *tabv;
616 WMTabViewItem *tab;
617 WMFrame *frame;
618 WMLabel *label;
620 windowCount++;
622 win = WMCreateWindow(scr, "testTabs");
623 WMResizeWidget(win, 400, 300);
625 WMSetWindowCloseAction(win, closeAction, NULL);
627 tabv = WMCreateTabView(win);
628 WMMoveWidget(tabv, 50, 50);
629 WMResizeWidget(tabv, 300, 200);
631 frame = WMCreateFrame(win);
632 WMSetFrameRelief(frame, WRFlat);
633 label = WMCreateLabel(frame);
634 WMResizeWidget(label, 100, 100);
635 WMSetLabelText(label, "Label 1");
636 WMMapWidget(label);
639 tab = WMCreateTabViewItemWithIdentifier(0);
640 WMSetTabViewItemView(tab, WMWidgetView(frame));
641 WMAddItemInTabView(tabv, tab);
642 WMSetTabViewItemLabel(tab, "Instances");
644 frame = WMCreateFrame(win);
645 WMSetFrameRelief(frame, WRFlat);
646 label = WMCreateLabel(frame);
647 WMResizeWidget(label, 40, 50);
648 WMSetLabelText(label, "Label 2");
649 WMMapWidget(label);
652 tab = WMCreateTabViewItemWithIdentifier(0);
653 WMSetTabViewItemView(tab, WMWidgetView(frame));
654 WMAddItemInTabView(tabv, tab);
655 WMSetTabViewItemLabel(tab, "Classes");
658 frame = WMCreateFrame(win);
659 WMSetFrameRelief(frame, WRFlat);
660 label = WMCreateLabel(frame);
661 WMResizeWidget(label, 100, 100);
662 WMMoveWidget(label, 60, 40);
663 WMSetLabelText(label, "Label 3");
664 WMMapWidget(label);
666 tab = WMCreateTabViewItemWithIdentifier(0);
667 WMSetTabViewItemView(tab, WMWidgetView(frame));
668 WMAddItemInTabView(tabv, tab);
669 WMSetTabViewItemLabel(tab, "Something");
672 frame = WMCreateFrame(win);
673 WMSetFrameRelief(frame, WRFlat);
674 label = WMCreateLabel(frame);
675 WMResizeWidget(label, 100, 100);
676 WMMoveWidget(label, 160, 40);
677 WMSetLabelText(label, "Label 4");
678 WMMapWidget(label);
680 tab = WMCreateTabViewItemWithIdentifier(0);
681 WMSetTabViewItemView(tab, WMWidgetView(frame));
682 WMAddItemInTabView(tabv, tab);
683 WMSetTabViewItemLabel(tab, "Bla!");
687 frame = WMCreateFrame(win);
688 WMSetFrameRelief(frame, WRFlat);
689 label = WMCreateLabel(frame);
690 WMResizeWidget(label, 100, 100);
691 WMMoveWidget(label, 160, 40);
692 WMSetLabelText(label, "Label fjweqklrj qwl");
693 WMMapWidget(label);
694 tab = WMCreateTabViewItemWithIdentifier(0);
695 WMSetTabViewItemView(tab, WMWidgetView(frame));
696 WMAddItemInTabView(tabv, tab);
697 WMSetTabViewItemLabel(tab, "Weee!");
700 WMRealizeWidget(win);
701 WMMapSubwidgets(win);
702 WMMapWidget(win);
706 void
707 splitViewConstrainProc(WMSplitView *sPtr, int indView,
708 int *minSize, int *maxSize)
710 switch (indView) {
711 case 0:
712 *minSize = 20;
713 break;
714 case 1:
715 *minSize = 40;
716 *maxSize = 80;
717 break;
718 case 2:
719 *maxSize = 60;
720 break;
721 default:
722 break;
727 static void
728 resizeSplitView(XEvent *event, void *data)
730 WMSplitView *sPtr = (WMSplitView*)data;
732 if (event->type == ConfigureNotify) {
733 int width = event->xconfigure.width - 10;
735 if (width < WMGetSplitViewDividerThickness(sPtr))
736 width = WMGetSplitViewDividerThickness(sPtr);
738 if (width != WMWidgetWidth(sPtr) ||
739 event->xconfigure.height != WMWidgetHeight(sPtr))
740 WMResizeWidget(sPtr, width, event->xconfigure.height - 55);
744 void
745 appendSubviewButtonAction(WMWidget *self, void *data)
747 WMSplitView *sPtr = (WMSplitView*)data;
748 char buf[64];
749 WMLabel *label = WMCreateLabel(sPtr);
751 sprintf(buf, "Subview %d", WMGetSplitViewSubviewsCount(sPtr) + 1);
752 WMSetLabelText(label, buf);
753 WMSetLabelRelief(label, WRSunken);
754 WMAddSplitViewSubview(sPtr, WMWidgetView(label));
755 WMRealizeWidget(label);
756 WMMapWidget(label);
759 void
760 removeSubviewButtonAction(WMWidget *self, void *data)
762 WMSplitView *sPtr = (WMSplitView*)data;
763 int count = WMGetSplitViewSubviewsCount(sPtr);
765 if (count > 2) {
766 WMView *view = WMGetSplitViewSubviewAt(sPtr, count-1);
767 WMDestroyWidget(WMWidgetOfView(view));
768 WMRemoveSplitViewSubviewAt(sPtr, count-1);
772 void
773 orientationButtonAction(WMWidget *self, void *data)
775 WMSplitView *sPtr = (WMSplitView*)data;
776 WMSetSplitViewVertical(sPtr, !WMGetSplitViewVertical(sPtr));
779 void
780 adjustSubviewsButtonAction(WMWidget *self, void *data)
782 WMAdjustSplitViewSubviews((WMSplitView*)data);
785 void
786 testSplitView(WMScreen *scr)
788 WMWindow *win;
789 WMSplitView *splitv1, *splitv2;
790 WMFrame *frame;
791 WMLabel *label;
792 WMButton *button;
794 windowCount++;
796 win = WMCreateWindow(scr, "testTabs");
797 WMResizeWidget(win, 300, 400);
798 WMSetWindowCloseAction(win, closeAction, NULL);
800 frame = WMCreateFrame(win);
801 WMSetFrameRelief(frame, WRSunken);
802 WMMoveWidget(frame, 5, 5);
803 WMResizeWidget(frame, 290, 40);
805 splitv1 = WMCreateSplitView(win);
806 WMMoveWidget(splitv1, 5, 50);
807 WMResizeWidget(splitv1, 290, 345);
808 WMSetSplitViewConstrainProc(splitv1, splitViewConstrainProc);
809 WMCreateEventHandler(WMWidgetView(win), StructureNotifyMask,
810 resizeSplitView, splitv1);
812 button = WMCreateCommandButton(frame);
813 WMSetButtonText(button, "+");
814 WMSetButtonAction(button, appendSubviewButtonAction, splitv1);
815 WMMoveWidget(button, 10, 8);
816 WMMapWidget(button);
818 button = WMCreateCommandButton(frame);
819 WMSetButtonText(button, "-");
820 WMSetButtonAction(button, removeSubviewButtonAction, splitv1);
821 WMMoveWidget(button, 80, 8);
822 WMMapWidget(button);
824 button = WMCreateCommandButton(frame);
825 WMSetButtonText(button, "=");
826 WMMoveWidget(button, 150, 8);
827 WMSetButtonAction(button, adjustSubviewsButtonAction, splitv1);
828 WMMapWidget(button);
830 button = WMCreateCommandButton(frame);
831 WMSetButtonText(button, "#");
832 WMMoveWidget(button, 220, 8);
833 WMSetButtonAction(button, orientationButtonAction, splitv1);
834 WMMapWidget(button);
836 label = WMCreateLabel(splitv1);
837 WMSetLabelText(label, "Subview 1");
838 WMSetLabelRelief(label, WRSunken);
839 WMMapWidget(label);
840 WMAddSplitViewSubview(splitv1, WMWidgetView(label));
842 splitv2 = WMCreateSplitView(splitv1);
843 WMResizeWidget(splitv2, 150, 150);
844 WMSetSplitViewVertical(splitv2, True);
846 label = WMCreateLabel(splitv2);
847 WMSetLabelText(label, "Subview 2.1");
848 WMSetLabelRelief(label, WRSunken);
849 WMMapWidget(label);
850 WMAddSplitViewSubview(splitv2, WMWidgetView(label));
852 label = WMCreateLabel(splitv2);
853 WMSetLabelText(label, "Subview 2.2");
854 WMSetLabelRelief(label, WRSunken);
855 WMMapWidget(label);
856 WMAddSplitViewSubview(splitv2, WMWidgetView(label));
858 label = WMCreateLabel(splitv2);
859 WMSetLabelText(label, "Subview 2.3");
860 WMSetLabelRelief(label, WRSunken);
861 WMMapWidget(label);
862 WMAddSplitViewSubview(splitv2, WMWidgetView(label));
864 WMMapWidget(splitv2);
865 WMAddSplitViewSubview(splitv1, WMWidgetView(splitv2));
867 WMRealizeWidget(win);
868 WMMapSubwidgets(win);
869 WMMapWidget(win);
873 /*******************************************************************/
875 #include <sys/types.h>
876 #include <dirent.h>
877 #include <string.h>
880 typedef struct {
881 int x, y;
882 Bool mouseDown;
883 char *filename;
884 } DNDStuff;
886 WMPixmap*
887 getImage(WMScreen *scr, char *file)
889 char buffer[1000];
890 WMPixmap *pix;
892 sprintf(buffer, "../../WindowMaker/Icons/%s", file);
893 pix = WMCreatePixmapFromFile(scr, buffer);
895 return pix;
901 static void
902 iconMouseStuff(XEvent *event, void *cdata)
904 WMLabel *label = (WMLabel*)cdata;
905 DNDStuff *stuff = WMGetHangedData(label);
906 WMPoint where;
908 switch (event->type) {
909 case ButtonPress:
910 stuff->x = event->xbutton.x;
911 stuff->y = event->xbutton.y;
912 stuff->mouseDown = True;
913 break;
914 case ButtonRelease:
915 stuff->mouseDown = False;
916 break;
917 case MotionNotify:
918 if (!stuff->mouseDown)
919 break;
921 if (abs(stuff->x - event->xmotion.x)>4
922 || abs(stuff->y - event->xmotion.y)>4) {
924 where = WMGetViewScreenPosition(WMWidgetView(label));
926 WMDragImageFromView(WMWidgetView(label),
927 WMGetLabelImage(label),
928 NULL, /* XXX */
929 where,
930 wmksize(stuff->x, stuff->y),
931 event, True);
933 break;
938 static void
939 endedDragImage(WMView *self, WMPixmap *image, WMPoint point, Bool deposited)
941 DNDStuff *stuff = WMGetHangedData(WMWidgetOfView(self));
943 if (deposited) {
944 WMDestroyWidget(WMWidgetOfView(self));
947 stuff->mouseDown = False;
951 static WMData*
952 fetchDragData(WMView *self, char *type)
954 DNDStuff *stuff = WMGetHangedData(WMWidgetOfView(self));
956 return WMCreateDataWithBytes(stuff->filename, strlen(stuff->filename)+1);
960 WMDragSourceProcs dragSourceProcs = {
961 NULL,
962 NULL,
963 endedDragImage,
964 fetchDragData
968 /************************/
971 unsigned
972 draggingEntered(WMView *self, WMDraggingInfo *info)
974 return WDOperationCopy;
978 unsigned
979 draggingUpdated(WMView *self, WMDraggingInfo *info)
981 return WDOperationCopy;
985 void (*draggingExited)(WMView *self, WMDraggingInfo *info);
987 char*
988 prepareForDragOperation(WMView *self, WMDraggingInfo *info)
990 return "application/X-WINGs-Bla";
994 WMLabel* makeDraggableLabel(WMWidget *w, char *file, int x, int y);
996 Bool
997 performDragOperation(WMView *self, WMDraggingInfo *info, WMData *data)
999 char *file = (char*)WMDataBytes(data);
1000 WMPoint pos;
1002 pos = WMGetDraggingInfoImageLocation(info);
1004 if (file!=NULL) {
1005 WMLabel *label;
1006 WMPoint pos2 = WMGetViewScreenPosition(self);
1009 label = makeDraggableLabel(WMWidgetOfView(self), file,
1010 pos.x-pos2.x, pos.y-pos2.y);
1011 WMRealizeWidget(label);
1012 WMMapWidget(label);
1016 return True;
1020 void
1021 concludeDragOperation(WMView *self, WMDraggingInfo *info)
1028 WMDragDestinationProcs dragDestProcs = {
1029 draggingEntered,
1030 draggingUpdated,
1031 NULL,
1032 prepareForDragOperation,
1033 performDragOperation,
1034 concludeDragOperation
1040 WMLabel*
1041 makeDraggableLabel(WMWidget *w, char *file, int x, int y)
1043 DNDStuff *stuff;
1044 WMLabel *label;
1045 WMPixmap *image = getImage(WMWidgetScreen(w), file);
1047 stuff = wmalloc(sizeof(DNDStuff));
1048 stuff->mouseDown = False;
1050 stuff->filename = wstrdup(file);
1052 label = WMCreateLabel(w);
1053 WMResizeWidget(label, 48, 48);
1054 WMMoveWidget(label, x, y);
1056 WMSetViewDragSourceProcs(WMWidgetView(label), &dragSourceProcs);
1058 WMHangData(label, stuff);
1060 WMCreateEventHandler(WMWidgetView(label),
1061 ButtonPressMask|ButtonReleaseMask|ButtonMotionMask,
1062 iconMouseStuff, label);
1065 if (image != NULL) {
1066 WMSetLabelImagePosition(label, WIPImageOnly);
1067 WMSetLabelImage(label, image);
1068 WMReleasePixmap(image);
1069 } else puts(file);
1071 return label;
1076 void
1077 testDragAndDrop(WMScreen *scr)
1079 WMWindow *win;
1080 WMFrame *frame;
1081 WMLabel *label;
1082 int i, j;
1083 DIR *dir;
1084 struct dirent *ent;
1085 char *types[] = {
1086 "application/X-WINGs-Bla",
1087 NULL
1090 windowCount++;
1092 win = WMCreateWindow(scr, "dragDrop");
1093 WMResizeWidget(win, 300, 300);
1094 WMSetWindowCloseAction(win, closeAction, NULL);
1095 WMSetWindowTitle(win, "Drag and Drop");
1098 frame = WMCreateFrame(win);
1099 WMSetFrameRelief(frame, WRSunken);
1100 WMResizeWidget(frame, 250, 250);
1101 WMMoveWidget(frame, 25, 25);
1103 WMRegisterViewForDraggedTypes(WMWidgetView(frame), types);
1104 WMSetViewDragDestinationProcs(WMWidgetView(frame), &dragDestProcs);
1106 dir = opendir("../../WindowMaker/Icons");
1107 if (!dir) {
1108 perror("../../WindowMaker/Icons");
1109 return;
1112 for (i = 0, j=0; j < 8; i++) {
1113 ent = readdir(dir);
1114 if (!ent)
1115 break;
1117 if (strstr(ent->d_name, ".xpm")==NULL) {
1118 continue;
1121 label = makeDraggableLabel(frame, ent->d_name,4+(j/4)*64, 4+(j%4)*64);
1123 j++;
1126 closedir(dir);
1128 WMMapSubwidgets(frame);
1130 WMMapSubwidgets(win);
1131 WMRealizeWidget(win);
1132 WMMapWidget(win);
1139 /*******************************************************************/
1141 #include "WUtil.h"
1143 void
1144 testUD()
1146 WMUserDefaults *defs;
1147 char str[32];
1149 defs = WMGetStandardUserDefaults();
1151 sprintf(str, "TEST DATA");
1152 puts(str);
1153 WMSetUDStringForKey(defs, str, "testKey");
1154 puts(str);
1159 main(int argc, char **argv)
1161 WMScreen *scr;
1162 WMPixmap *pixmap;
1165 /* Initialize the application */
1166 WMInitializeApplication("Test", &argc, argv);
1168 testUD();
1171 * Open connection to the X display.
1173 dpy = XOpenDisplay("");
1175 if (!dpy) {
1176 puts("could not open display");
1177 exit(1);
1180 /* This is used to disable buffering of X protocol requests.
1181 * Do NOT use it unless when debugging. It will cause a major
1182 * slowdown in your application
1184 #if 1
1185 XSynchronize(dpy, True);
1186 #endif
1188 * Create screen descriptor.
1190 scr = WMCreateScreen(dpy, DefaultScreen(dpy));
1193 * Loads the logo of the application.
1195 pixmap = WMCreatePixmapFromFile(scr, "logo.xpm");
1198 * Makes the logo be used in standard dialog panels.
1200 WMSetApplicationIconImage(scr, pixmap); WMReleasePixmap(pixmap);
1203 * Do some test stuff.
1205 * Put the testSomething() function you want to test here.
1208 testList(scr);
1210 #if 0
1211 testColorWell(scr);
1213 testTextField(scr);
1214 testText(scr);
1216 testDragAndDrop(scr);
1217 testDragAndDrop(scr);
1218 testFontPanel(scr);
1220 testScrollView(scr);
1222 testButton(scr);
1224 testFrame(scr);
1227 testTabView(scr);
1231 testSplitView(scr);
1233 testGradientButtons(scr);
1234 testProgressIndicator(scr);
1237 testOpenFilePanel(scr);
1239 testSlider(scr);
1240 testPullDown(scr);
1241 #endif
1243 * The main event loop.
1246 WMScreenMainLoop(scr);
1248 return 0;