Better behavior for the multiple selection in lists.
[wmaker-crm.git] / WINGs / Tests / wtest.c
blob9d717d6861730d98f388f2fd73e137947c500ae3
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 WMUnmapWidget(self);
33 WMDestroyWidget(self);
34 windowCount--;
35 printf("window closed, window count = %d\n", windowCount);
36 if (windowCount < 1)
37 exit(0);
41 void
42 testOpenFilePanel(WMScreen *scr)
44 WMOpenPanel *panel;
46 /* windowCount++; */
48 /* get the shared Open File panel */
49 panel = WMGetOpenPanel(scr);
51 WMRunModalFilePanelForDirectory(panel, NULL, "/usr/local", NULL, NULL);
53 /* free the panel to save some memory. Not needed otherwise. */
54 WMFreeFilePanel(WMGetOpenPanel(scr));
58 void
59 testFontPanel(WMScreen *scr)
61 WMFontPanel *panel;
63 /*windowCount++;*/
65 panel = WMGetFontPanel(scr);
67 WMShowFontPanel(panel);
69 /* WMFreeFontPanel(panel);*/
74 void
75 testFrame(WMScreen *scr)
77 WMWindow *win;
78 WMFrame *frame;
79 int i;
80 static char* titles[] = {
81 "AboveTop",
82 "AtTop",
83 "BelowTop",
84 "AboveBottom",
85 "AtBottom",
86 "BelowBottom"
88 static WMTitlePosition pos[] = {
89 WTPAboveTop,
90 WTPAtTop,
91 WTPBelowTop,
92 WTPAboveBottom,
93 WTPAtBottom,
94 WTPBelowBottom
97 windowCount++;
99 win = WMCreateWindow(scr, "testFrame");
100 WMSetWindowTitle(win, "Frame");
101 WMSetWindowCloseAction(win, closeAction, NULL);
102 WMResizeWidget(win, 400, 300);
104 for (i = 0; i < 6; i++) {
105 frame = WMCreateFrame(win);
106 WMMoveWidget(frame, 8+(i%3)*130, 8+(i/3)*130);
107 WMResizeWidget(frame, 120, 120);
108 WMSetFrameTitle(frame, titles[i]);
109 WMSetFrameTitlePosition(frame, pos[i]);
112 WMRealizeWidget(win);
113 WMMapSubwidgets(win);
114 WMMapWidget(win);
119 static void
120 singleClick(WMWidget *self, void *data)
125 static void
126 doubleClick(WMWidget *self, void *data)
128 WMLabel *label = (WMLabel*)data;
129 WMList *lPtr = (WMList*)self;
130 char buf[255];
132 WMSelectAllListItems(lPtr);
136 static void
137 listSelectionObserver(void *observer, WMNotification *notification)
139 WMLabel *label = (WMLabel*)observer;
140 WMList *lPtr = (WMList*)WMGetNotificationObject(notification);
141 char buf[255];
143 sprintf(buf, "Selected items: %d",
144 WMGetArrayItemCount(WMGetListSelectedItems(lPtr)));
145 WMSetLabelText(label, buf);
149 void
150 testList(WMScreen *scr)
152 WMWindow *win;
153 WMList *list;
154 WMList *mlist;
155 WMLabel *label;
156 WMLabel *mlabel;
157 WMLabel *title;
158 WMLabel *mtitle;
159 char text[100];
160 int i;
162 windowCount++;
164 win = WMCreateWindow(scr, "testList");
165 WMResizeWidget(win, 370, 250);
166 WMSetWindowTitle(win, "List");
167 WMSetWindowCloseAction(win, closeAction, NULL);
169 title = WMCreateLabel(win);
170 WMResizeWidget(title, 150, 20);
171 WMMoveWidget(title, 10, 10);
172 WMSetLabelRelief(title, WRRidge);
173 WMSetLabelText(title, "Single selection list");
175 mtitle = WMCreateLabel(win);
176 WMResizeWidget(mtitle, 150, 20);
177 WMMoveWidget(mtitle, 210, 10);
178 WMSetLabelRelief(mtitle, WRRidge);
179 WMSetLabelText(mtitle, "Multiple selection list");
181 list = WMCreateList(win);
182 //WMSetListAllowEmptySelection(list, True);
183 WMMoveWidget(list, 10, 40);
184 for (i=0; i<50; i++) {
185 sprintf(text, "Item %i", i);
186 WMAddListItem(list, text);
188 mlist = WMCreateList(win);
189 WMSetListAllowMultipleSelection(mlist, True);
190 //WMSetListAllowEmptySelection(mlist, True);
191 WMMoveWidget(mlist, 210, 40);
192 for (i=0; i<135; i++) {
193 sprintf(text, "Item %i", i);
194 WMAddListItem(mlist, text);
197 label = WMCreateLabel(win);
198 WMResizeWidget(label, 150, 40);
199 WMMoveWidget(label, 10, 200);
200 WMSetLabelRelief(label, WRRidge);
201 WMSetLabelText(label, "Selected items: 0");
203 mlabel = WMCreateLabel(win);
204 WMResizeWidget(mlabel, 150, 40);
205 WMMoveWidget(mlabel, 210, 200);
206 WMSetLabelRelief(mlabel, WRRidge);
207 WMSetLabelText(mlabel, "Selected items: 0");
209 WMSetListAction(list, singleClick, label);
210 WMSetListDoubleAction(list, doubleClick, label);
211 WMSetListAction(mlist, singleClick, mlabel);
212 WMSetListDoubleAction(mlist, doubleClick, mlabel);
214 WMAddNotificationObserver(listSelectionObserver, label,
215 WMListSelectionDidChangeNotification, list);
216 WMAddNotificationObserver(listSelectionObserver, mlabel,
217 WMListSelectionDidChangeNotification, mlist);
220 WMRealizeWidget(win);
221 WMMapSubwidgets(win);
222 WMMapWidget(win);
226 void
227 testButton(WMScreen *scr)
229 WMWindow *win;
230 int i;
231 char *types[] = {
232 "MomentaryPush",
233 "PushOnPushOff",
234 "Toggle",
235 "Switch",
236 "Radio",
237 "MomentaryChange",
238 "OnOff",
239 "MomentaryLigh"
242 windowCount++;
244 win = WMCreateWindow(scr, "testButton");
245 WMResizeWidget(win, 300, 300);
246 WMSetWindowTitle(win, "Buttons");
248 WMSetWindowCloseAction(win, closeAction, NULL);
250 for (i = 1; i < 9; i++) {
251 WMButton *b;
252 b = WMCreateButton(win, i);
253 WMResizeWidget(b, 150, 24);
254 WMMoveWidget(b, 20, i*30);
255 WMSetButtonText(b, types[i-1]);
258 WMRealizeWidget(win);
259 WMMapSubwidgets(win);
260 WMMapWidget(win);
264 void
265 testGradientButtons(WMScreen *scr)
267 WMWindow *win;
268 WMButton *btn;
269 WMPixmap *pix1, *pix2;
270 RImage *back;
271 RColor light, dark;
272 WMColor *color, *altColor;
274 windowCount++;
276 /* creates the top-level window */
277 win = WMCreateWindow(scr, "testGradientButtons");
278 WMSetWindowTitle(win, "Gradiented Button Demo");
279 WMResizeWidget(win, 300, 200);
281 light.red = 0x90;
282 light.green = 0x85;
283 light.blue = 0x90;
284 dark.red = 0x35;
285 dark.green = 0x30;
286 dark.blue = 0x35;
288 color = WMCreateRGBColor(scr, 0x5900, 0x5100, 0x5900, True);
289 WMSetWidgetBackgroundColor(win, color);
290 WMReleaseColor(color);
292 back = RRenderGradient(60, 24, &dark, &light, RGRD_DIAGONAL);
293 RBevelImage(back, RBEV_RAISED2);
294 pix1 = WMCreatePixmapFromRImage(scr, back, 0);
295 RDestroyImage(back);
297 back = RRenderGradient(60, 24, &dark, &light, RGRD_DIAGONAL);
298 RBevelImage(back, RBEV_SUNKEN);
299 pix2 = WMCreatePixmapFromRImage(scr, back, 0);
300 RDestroyImage(back);
302 color = WMWhiteColor(scr);
303 altColor = WMCreateNamedColor(scr, "red", True);
305 btn = WMCreateButton(win, WBTMomentaryChange);
306 WMResizeWidget(btn, 60, 24);
307 WMMoveWidget(btn, 20, 100);
308 WMSetButtonBordered(btn, False);
309 WMSetButtonImagePosition(btn, WIPOverlaps);
310 WMSetButtonImage(btn, pix1);
311 WMSetButtonAltImage(btn, pix2);
312 WMSetButtonText(btn, "Cool");
313 WMSetButtonTextColor(btn, color);
314 WMSetButtonAltTextColor(btn, altColor);
316 WMSetBalloonTextForView("This is a cool button", WMWidgetView(btn));
318 btn = WMCreateButton(win, WBTMomentaryChange);
319 WMResizeWidget(btn, 60, 24);
320 WMMoveWidget(btn, 90, 100);
321 WMSetButtonBordered(btn, False);
322 WMSetButtonImagePosition(btn, WIPOverlaps);
323 WMSetButtonImage(btn, pix1);
324 WMSetButtonAltImage(btn, pix2);
325 WMSetButtonText(btn, "Button");
326 WMSetButtonTextColor(btn, color);
328 WMSetBalloonTextForView("Este é outro balão.", WMWidgetView(btn));
330 WMReleaseColor(color);
331 color = WMCreateNamedColor(scr, "orange", True);
333 btn = WMCreateButton(win, WBTMomentaryChange);
334 WMResizeWidget(btn, 60, 24);
335 WMMoveWidget(btn, 160, 100);
336 WMSetButtonBordered(btn, False);
337 WMSetButtonImagePosition(btn, WIPOverlaps);
338 WMSetButtonImage(btn, pix1);
339 WMSetButtonAltImage(btn, pix2);
340 WMSetButtonText(btn, "Test");
341 WMSetButtonTextColor(btn, color);
343 WMSetBalloonTextForView("This is yet another button.\nBut the balloon has 3 lines.\nYay!",
344 WMWidgetView(btn));
346 WMReleaseColor(color);
347 WMReleaseColor(altColor);
349 WMRealizeWidget(win);
350 WMMapSubwidgets(win);
351 WMMapWidget(win);
355 void
356 testScrollView(WMScreen *scr)
358 WMWindow *win;
359 WMScrollView *sview;
360 WMFrame *f;
361 WMLabel *l;
362 char buffer[128];
363 int i;
365 windowCount++;
367 /* creates the top-level window */
368 win = WMCreateWindow(scr, "testScroll");
369 WMSetWindowTitle(win, "Scrollable View");
371 WMSetWindowCloseAction(win, closeAction, NULL);
373 /* set the window size */
374 WMResizeWidget(win, 300, 300);
376 /* creates a scrollable view inside the top-level window */
377 sview = WMCreateScrollView(win);
378 WMResizeWidget(sview, 200, 200);
379 WMMoveWidget(sview, 30, 30);
380 WMSetScrollViewRelief(sview, WRSunken);
381 WMSetScrollViewHasVerticalScroller(sview, True);
382 WMSetScrollViewHasHorizontalScroller(sview, True);
384 /* create a frame with a bunch of labels */
385 f = WMCreateFrame(win);
386 WMResizeWidget(f, 400, 400);
387 WMSetFrameRelief(f, WRFlat);
389 for (i=0; i<20; i++) {
390 l = WMCreateLabel(f);
391 WMResizeWidget(l, 50, 18);
392 WMMoveWidget(l, 10, 20*i);
393 sprintf(buffer, "Label %i", i);
394 WMSetLabelText(l, buffer);
395 WMSetLabelRelief(l, WRSimple);
397 WMMapSubwidgets(f);
398 WMMapWidget(f);
400 WMSetScrollViewContentView(sview, WMWidgetView(f));
402 /* make the windows of the widgets be actually created */
403 WMRealizeWidget(win);
405 /* Map all child widgets of the top-level be mapped.
406 * You must call this for each container widget (like frames),
407 * even if they are childs of the top-level window.
409 WMMapSubwidgets(win);
411 /* map the top-level window */
412 WMMapWidget(win);
416 void
417 testColorWell(WMScreen *scr)
419 WMWindow *win;
420 WMColorWell *well1, *well2;
422 windowCount++;
424 win = WMCreateWindow(scr, "testColor");
425 WMResizeWidget(win, 300, 300);
426 WMSetWindowCloseAction(win, closeAction, NULL);
428 well1 = WMCreateColorWell(win);
429 WMResizeWidget(well1, 60, 40);
430 WMMoveWidget(well1, 100, 100);
431 WMSetColorWellColor(well1, WMCreateRGBColor(scr, 0x8888, 0, 0x1111, True));
432 well2 = WMCreateColorWell(win);
433 WMResizeWidget(well2, 60, 40);
434 WMMoveWidget(well2, 200, 100);
435 WMSetColorWellColor(well2, WMCreateRGBColor(scr, 0, 0, 0x8888, True));
437 WMRealizeWidget(win);
438 WMMapSubwidgets(win);
439 WMMapWidget(win);
442 void
443 sliderCallback(WMWidget *w, void *data)
445 printf("SLIDER == %i\n", WMGetSliderValue(w));
449 void
450 testSlider(WMScreen *scr)
452 WMWindow *win;
453 WMSlider *s;
455 windowCount++;
457 win = WMCreateWindow(scr, "testSlider");
458 WMResizeWidget(win, 300, 300);
459 WMSetWindowTitle(win, "Sliders");
461 WMSetWindowCloseAction(win, closeAction, NULL);
463 s = WMCreateSlider(win);
464 WMResizeWidget(s, 16, 100);
465 WMMoveWidget(s, 100, 100);
466 WMSetSliderKnobThickness(s, 8);
467 WMSetSliderContinuous(s, False);
468 WMSetSliderAction(s, sliderCallback, s);
470 s = WMCreateSlider(win);
471 WMResizeWidget(s, 100, 16);
472 WMMoveWidget(s, 100, 10);
473 WMSetSliderKnobThickness(s, 8);
475 WMRealizeWidget(win);
476 WMMapSubwidgets(win);
477 WMMapWidget(win);
480 void
481 testTextField(WMScreen *scr)
483 WMWindow *win;
484 WMTextField *field, *field2;
486 windowCount++;
488 win = WMCreateWindow(scr, "testTextField");
489 WMResizeWidget(win, 400, 300);
491 WMSetWindowCloseAction(win, closeAction, NULL);
493 field = WMCreateTextField(win);
494 WMResizeWidget(field, 200, 20);
495 WMMoveWidget(field, 20, 20);
497 field2 = WMCreateTextField(win);
498 WMResizeWidget(field2, 200, 20);
499 WMMoveWidget(field2, 20, 50);
500 WMSetTextFieldAlignment(field2, WARight);
502 WMRealizeWidget(win);
503 WMMapSubwidgets(win);
504 WMMapWidget(win);
508 void
509 testText(WMScreen *scr)
511 WMWindow *win;
512 WMText *text;
513 FILE *file = fopen("../README", "r");
515 windowCount++;
517 win = WMCreateWindow(scr, "testText");
518 WMResizeWidget(win, 500, 300);
520 WMSetWindowCloseAction(win, closeAction, NULL);
522 text = WMCreateText(win);
523 WMResizeWidget(text, 480, 280);
524 WMMoveWidget(text, 10, 10);
525 WMSetTextHasVerticalScroller(text, True);
526 WMSetTextEditable(text, False);
528 if(file) {
529 char buf[1024];
531 WMFreezeText(text);
532 while(fgets(buf, 1023, file))
533 WMAppendTextStream(text, buf);
535 fclose(file);
536 WMThawText(text);
537 WMRefreshText(text, 0, 0);
538 } else {
539 WMAppendTextStream(text, "<HTML><i>Where's</i> the <b>README</b>?");
542 WMRealizeWidget(win);
543 WMMapSubwidgets(win);
544 WMMapWidget(win);
549 void
550 testProgressIndicator(WMScreen *scr)
552 WMWindow *win;
553 WMProgressIndicator *pPtr;
555 windowCount++;
557 win = WMCreateWindow(scr, "testProgressIndicator");
558 WMResizeWidget(win, 292, 32);
560 WMSetWindowCloseAction(win, closeAction, NULL);
562 pPtr = WMCreateProgressIndicator(win);
563 WMMoveWidget(pPtr, 8, 8);
564 WMSetProgressIndicatorValue(pPtr, 75);
566 WMRealizeWidget(win);
567 WMMapSubwidgets(win);
568 WMMapWidget(win);
573 void
574 testPullDown(WMScreen *scr)
576 WMWindow *win;
577 WMPopUpButton *pop, *pop2;
579 windowCount++;
581 win = WMCreateWindow(scr, "pullDown");
582 WMResizeWidget(win, 400, 300);
584 WMSetWindowCloseAction(win, closeAction, NULL);
586 pop = WMCreatePopUpButton(win);
587 WMResizeWidget(pop, 100, 20);
588 WMMoveWidget(pop, 50, 60);
589 WMSetPopUpButtonPullsDown(pop, True);
590 WMSetPopUpButtonText(pop, "Commands");
591 WMAddPopUpButtonItem(pop, "Add");
592 WMAddPopUpButtonItem(pop, "Remove");
593 WMAddPopUpButtonItem(pop, "Check");
594 WMAddPopUpButtonItem(pop, "Eat");
596 pop2 = WMCreatePopUpButton(win);
597 WMResizeWidget(pop2, 100, 20);
598 WMMoveWidget(pop2, 200, 60);
599 WMSetPopUpButtonText(pop2, "Select");
600 WMAddPopUpButtonItem(pop2, "Apples");
601 WMAddPopUpButtonItem(pop2, "Bananas");
602 WMAddPopUpButtonItem(pop2, "Strawberries");
603 WMAddPopUpButtonItem(pop2, "Blueberries");
605 WMRealizeWidget(win);
606 WMMapSubwidgets(win);
607 WMMapWidget(win);
612 void
613 testTabView(WMScreen *scr)
615 WMWindow *win;
616 WMTabView *tabv;
617 WMTabViewItem *tab;
618 WMFrame *frame;
619 WMLabel *label;
621 windowCount++;
623 win = WMCreateWindow(scr, "testTabs");
624 WMResizeWidget(win, 400, 300);
626 WMSetWindowCloseAction(win, closeAction, NULL);
628 tabv = WMCreateTabView(win);
629 WMMoveWidget(tabv, 50, 50);
630 WMResizeWidget(tabv, 300, 200);
632 frame = WMCreateFrame(win);
633 WMSetFrameRelief(frame, WRFlat);
634 label = WMCreateLabel(frame);
635 WMResizeWidget(label, 100, 100);
636 WMSetLabelText(label, "Label 1");
637 WMMapWidget(label);
640 tab = WMCreateTabViewItemWithIdentifier(0);
641 WMSetTabViewItemView(tab, WMWidgetView(frame));
642 WMAddItemInTabView(tabv, tab);
643 WMSetTabViewItemLabel(tab, "Instances");
645 frame = WMCreateFrame(win);
646 WMSetFrameRelief(frame, WRFlat);
647 label = WMCreateLabel(frame);
648 WMResizeWidget(label, 40, 50);
649 WMSetLabelText(label, "Label 2");
650 WMMapWidget(label);
653 tab = WMCreateTabViewItemWithIdentifier(0);
654 WMSetTabViewItemView(tab, WMWidgetView(frame));
655 WMAddItemInTabView(tabv, tab);
656 WMSetTabViewItemLabel(tab, "Classes");
659 frame = WMCreateFrame(win);
660 WMSetFrameRelief(frame, WRFlat);
661 label = WMCreateLabel(frame);
662 WMResizeWidget(label, 100, 100);
663 WMMoveWidget(label, 60, 40);
664 WMSetLabelText(label, "Label 3");
665 WMMapWidget(label);
667 tab = WMCreateTabViewItemWithIdentifier(0);
668 WMSetTabViewItemView(tab, WMWidgetView(frame));
669 WMAddItemInTabView(tabv, tab);
670 WMSetTabViewItemLabel(tab, "Something");
673 frame = WMCreateFrame(win);
674 WMSetFrameRelief(frame, WRFlat);
675 label = WMCreateLabel(frame);
676 WMResizeWidget(label, 100, 100);
677 WMMoveWidget(label, 160, 40);
678 WMSetLabelText(label, "Label 4");
679 WMMapWidget(label);
681 tab = WMCreateTabViewItemWithIdentifier(0);
682 WMSetTabViewItemView(tab, WMWidgetView(frame));
683 WMAddItemInTabView(tabv, tab);
684 WMSetTabViewItemLabel(tab, "Bla!");
688 frame = WMCreateFrame(win);
689 WMSetFrameRelief(frame, WRFlat);
690 label = WMCreateLabel(frame);
691 WMResizeWidget(label, 100, 100);
692 WMMoveWidget(label, 160, 40);
693 WMSetLabelText(label, "Label fjweqklrj qwl");
694 WMMapWidget(label);
695 tab = WMCreateTabViewItemWithIdentifier(0);
696 WMSetTabViewItemView(tab, WMWidgetView(frame));
697 WMAddItemInTabView(tabv, tab);
698 WMSetTabViewItemLabel(tab, "Weee!");
701 WMRealizeWidget(win);
702 WMMapSubwidgets(win);
703 WMMapWidget(win);
707 void
708 splitViewConstrainProc(WMSplitView *sPtr, int indView,
709 int *minSize, int *maxSize)
711 switch (indView) {
712 case 0:
713 *minSize = 20;
714 break;
715 case 1:
716 *minSize = 40;
717 *maxSize = 80;
718 break;
719 case 2:
720 *maxSize = 60;
721 break;
722 default:
723 break;
728 static void
729 resizeSplitView(XEvent *event, void *data)
731 WMSplitView *sPtr = (WMSplitView*)data;
733 if (event->type == ConfigureNotify) {
734 int width = event->xconfigure.width - 10;
736 if (width < WMGetSplitViewDividerThickness(sPtr))
737 width = WMGetSplitViewDividerThickness(sPtr);
739 if (width != WMWidgetWidth(sPtr) ||
740 event->xconfigure.height != WMWidgetHeight(sPtr))
741 WMResizeWidget(sPtr, width, event->xconfigure.height - 55);
745 void
746 appendSubviewButtonAction(WMWidget *self, void *data)
748 WMSplitView *sPtr = (WMSplitView*)data;
749 char buf[64];
750 WMLabel *label = WMCreateLabel(sPtr);
752 sprintf(buf, "Subview %d", WMGetSplitViewSubviewsCount(sPtr) + 1);
753 WMSetLabelText(label, buf);
754 WMSetLabelRelief(label, WRSunken);
755 WMAddSplitViewSubview(sPtr, WMWidgetView(label));
756 WMRealizeWidget(label);
757 WMMapWidget(label);
760 void
761 removeSubviewButtonAction(WMWidget *self, void *data)
763 WMSplitView *sPtr = (WMSplitView*)data;
764 int count = WMGetSplitViewSubviewsCount(sPtr);
766 if (count > 2) {
767 WMView *view = WMGetSplitViewSubviewAt(sPtr, count-1);
768 WMDestroyWidget(WMWidgetOfView(view));
769 WMRemoveSplitViewSubviewAt(sPtr, count-1);
773 void
774 orientationButtonAction(WMWidget *self, void *data)
776 WMSplitView *sPtr = (WMSplitView*)data;
777 WMSetSplitViewVertical(sPtr, !WMGetSplitViewVertical(sPtr));
780 void
781 adjustSubviewsButtonAction(WMWidget *self, void *data)
783 WMAdjustSplitViewSubviews((WMSplitView*)data);
786 void
787 testSplitView(WMScreen *scr)
789 WMWindow *win;
790 WMSplitView *splitv1, *splitv2;
791 WMFrame *frame;
792 WMLabel *label;
793 WMButton *button;
795 windowCount++;
797 win = WMCreateWindow(scr, "testTabs");
798 WMResizeWidget(win, 300, 400);
799 WMSetWindowCloseAction(win, closeAction, NULL);
801 frame = WMCreateFrame(win);
802 WMSetFrameRelief(frame, WRSunken);
803 WMMoveWidget(frame, 5, 5);
804 WMResizeWidget(frame, 290, 40);
806 splitv1 = WMCreateSplitView(win);
807 WMMoveWidget(splitv1, 5, 50);
808 WMResizeWidget(splitv1, 290, 345);
809 WMSetSplitViewConstrainProc(splitv1, splitViewConstrainProc);
810 WMCreateEventHandler(WMWidgetView(win), StructureNotifyMask,
811 resizeSplitView, splitv1);
813 button = WMCreateCommandButton(frame);
814 WMSetButtonText(button, "+");
815 WMSetButtonAction(button, appendSubviewButtonAction, splitv1);
816 WMMoveWidget(button, 10, 8);
817 WMMapWidget(button);
819 button = WMCreateCommandButton(frame);
820 WMSetButtonText(button, "-");
821 WMSetButtonAction(button, removeSubviewButtonAction, splitv1);
822 WMMoveWidget(button, 80, 8);
823 WMMapWidget(button);
825 button = WMCreateCommandButton(frame);
826 WMSetButtonText(button, "=");
827 WMMoveWidget(button, 150, 8);
828 WMSetButtonAction(button, adjustSubviewsButtonAction, splitv1);
829 WMMapWidget(button);
831 button = WMCreateCommandButton(frame);
832 WMSetButtonText(button, "#");
833 WMMoveWidget(button, 220, 8);
834 WMSetButtonAction(button, orientationButtonAction, splitv1);
835 WMMapWidget(button);
837 label = WMCreateLabel(splitv1);
838 WMSetLabelText(label, "Subview 1");
839 WMSetLabelRelief(label, WRSunken);
840 WMMapWidget(label);
841 WMAddSplitViewSubview(splitv1, WMWidgetView(label));
843 splitv2 = WMCreateSplitView(splitv1);
844 WMResizeWidget(splitv2, 150, 150);
845 WMSetSplitViewVertical(splitv2, True);
847 label = WMCreateLabel(splitv2);
848 WMSetLabelText(label, "Subview 2.1");
849 WMSetLabelRelief(label, WRSunken);
850 WMMapWidget(label);
851 WMAddSplitViewSubview(splitv2, WMWidgetView(label));
853 label = WMCreateLabel(splitv2);
854 WMSetLabelText(label, "Subview 2.2");
855 WMSetLabelRelief(label, WRSunken);
856 WMMapWidget(label);
857 WMAddSplitViewSubview(splitv2, WMWidgetView(label));
859 label = WMCreateLabel(splitv2);
860 WMSetLabelText(label, "Subview 2.3");
861 WMSetLabelRelief(label, WRSunken);
862 WMMapWidget(label);
863 WMAddSplitViewSubview(splitv2, WMWidgetView(label));
865 WMMapWidget(splitv2);
866 WMAddSplitViewSubview(splitv1, WMWidgetView(splitv2));
868 WMRealizeWidget(win);
869 WMMapSubwidgets(win);
870 WMMapWidget(win);
874 /*******************************************************************/
876 #include <sys/types.h>
877 #include <dirent.h>
878 #include <string.h>
881 typedef struct {
882 int x, y;
883 Bool mouseDown;
884 char *filename;
885 } DNDStuff;
887 WMPixmap*
888 getImage(WMScreen *scr, char *file)
890 char buffer[1000];
891 WMPixmap *pix;
893 sprintf(buffer, "../../WindowMaker/Icons/%s", file);
894 pix = WMCreatePixmapFromFile(scr, buffer);
896 return pix;
902 static void
903 iconMouseStuff(XEvent *event, void *cdata)
905 WMLabel *label = (WMLabel*)cdata;
906 DNDStuff *stuff = WMGetHangedData(label);
907 WMPoint where;
909 switch (event->type) {
910 case ButtonPress:
911 stuff->x = event->xbutton.x;
912 stuff->y = event->xbutton.y;
913 stuff->mouseDown = True;
914 break;
915 case ButtonRelease:
916 stuff->mouseDown = False;
917 break;
918 case MotionNotify:
919 if (!stuff->mouseDown)
920 break;
922 if (abs(stuff->x - event->xmotion.x)>4
923 || abs(stuff->y - event->xmotion.y)>4) {
925 where = WMGetViewScreenPosition(WMWidgetView(label));
927 WMDragImageFromView(WMWidgetView(label),
928 WMGetLabelImage(label),
929 NULL, /* XXX */
930 where,
931 wmksize(stuff->x, stuff->y),
932 event, True);
934 break;
939 static void
940 endedDragImage(WMView *self, WMPixmap *image, WMPoint point, Bool deposited)
942 DNDStuff *stuff = WMGetHangedData(WMWidgetOfView(self));
944 if (deposited) {
945 WMDestroyWidget(WMWidgetOfView(self));
948 stuff->mouseDown = False;
952 static WMData*
953 fetchDragData(WMView *self, char *type)
955 DNDStuff *stuff = WMGetHangedData(WMWidgetOfView(self));
957 return WMCreateDataWithBytes(stuff->filename, strlen(stuff->filename)+1);
961 WMDragSourceProcs dragSourceProcs = {
962 NULL,
963 NULL,
964 endedDragImage,
965 fetchDragData
969 /************************/
972 unsigned
973 draggingEntered(WMView *self, WMDraggingInfo *info)
975 return WDOperationCopy;
979 unsigned
980 draggingUpdated(WMView *self, WMDraggingInfo *info)
982 return WDOperationCopy;
986 void (*draggingExited)(WMView *self, WMDraggingInfo *info);
988 char*
989 prepareForDragOperation(WMView *self, WMDraggingInfo *info)
991 return "application/X-WINGs-Bla";
995 WMLabel* makeDraggableLabel(WMWidget *w, char *file, int x, int y);
997 Bool
998 performDragOperation(WMView *self, WMDraggingInfo *info, WMData *data)
1000 char *file = (char*)WMDataBytes(data);
1001 WMPoint pos;
1003 pos = WMGetDraggingInfoImageLocation(info);
1005 if (file!=NULL) {
1006 WMLabel *label;
1007 WMPoint pos2 = WMGetViewScreenPosition(self);
1010 label = makeDraggableLabel(WMWidgetOfView(self), file,
1011 pos.x-pos2.x, pos.y-pos2.y);
1012 WMRealizeWidget(label);
1013 WMMapWidget(label);
1017 return True;
1021 void
1022 concludeDragOperation(WMView *self, WMDraggingInfo *info)
1029 WMDragDestinationProcs dragDestProcs = {
1030 draggingEntered,
1031 draggingUpdated,
1032 NULL,
1033 prepareForDragOperation,
1034 performDragOperation,
1035 concludeDragOperation
1041 WMLabel*
1042 makeDraggableLabel(WMWidget *w, char *file, int x, int y)
1044 DNDStuff *stuff;
1045 WMLabel *label;
1046 WMPixmap *image = getImage(WMWidgetScreen(w), file);
1048 stuff = wmalloc(sizeof(DNDStuff));
1049 stuff->mouseDown = False;
1051 stuff->filename = wstrdup(file);
1053 label = WMCreateLabel(w);
1054 WMResizeWidget(label, 48, 48);
1055 WMMoveWidget(label, x, y);
1057 WMSetViewDragSourceProcs(WMWidgetView(label), &dragSourceProcs);
1059 WMHangData(label, stuff);
1061 WMCreateEventHandler(WMWidgetView(label),
1062 ButtonPressMask|ButtonReleaseMask|ButtonMotionMask,
1063 iconMouseStuff, label);
1066 if (image != NULL) {
1067 WMSetLabelImagePosition(label, WIPImageOnly);
1068 WMSetLabelImage(label, image);
1069 WMReleasePixmap(image);
1070 } else puts(file);
1072 return label;
1077 void
1078 testDragAndDrop(WMScreen *scr)
1080 WMWindow *win;
1081 WMFrame *frame;
1082 WMLabel *label;
1083 int i, j;
1084 DIR *dir;
1085 struct dirent *ent;
1086 char *types[] = {
1087 "application/X-WINGs-Bla",
1088 NULL
1091 windowCount++;
1093 win = WMCreateWindow(scr, "dragDrop");
1094 WMResizeWidget(win, 300, 300);
1095 WMSetWindowCloseAction(win, closeAction, NULL);
1096 WMSetWindowTitle(win, "Drag and Drop");
1099 frame = WMCreateFrame(win);
1100 WMSetFrameRelief(frame, WRSunken);
1101 WMResizeWidget(frame, 250, 250);
1102 WMMoveWidget(frame, 25, 25);
1104 WMRegisterViewForDraggedTypes(WMWidgetView(frame), types);
1105 WMSetViewDragDestinationProcs(WMWidgetView(frame), &dragDestProcs);
1107 dir = opendir("../../WindowMaker/Icons");
1108 if (!dir) {
1109 perror("../../WindowMaker/Icons");
1110 return;
1113 for (i = 0, j=0; j < 8; i++) {
1114 ent = readdir(dir);
1115 if (!ent)
1116 break;
1118 if (strstr(ent->d_name, ".xpm")==NULL) {
1119 continue;
1122 label = makeDraggableLabel(frame, ent->d_name,4+(j/4)*64, 4+(j%4)*64);
1124 j++;
1127 closedir(dir);
1129 WMMapSubwidgets(frame);
1131 WMMapSubwidgets(win);
1132 WMRealizeWidget(win);
1133 WMMapWidget(win);
1140 /*******************************************************************/
1142 #include "WUtil.h"
1144 void
1145 testUD()
1147 WMUserDefaults *defs;
1148 char str[32];
1150 defs = WMGetStandardUserDefaults();
1152 sprintf(str, "TEST DATA");
1153 puts(str);
1154 WMSetUDStringForKey(defs, str, "testKey");
1155 puts(str);
1160 main(int argc, char **argv)
1162 WMScreen *scr;
1163 WMPixmap *pixmap;
1166 /* Initialize the application */
1167 WMInitializeApplication("Test", &argc, argv);
1169 testUD();
1172 * Open connection to the X display.
1174 dpy = XOpenDisplay("");
1176 if (!dpy) {
1177 puts("could not open display");
1178 exit(1);
1181 /* This is used to disable buffering of X protocol requests.
1182 * Do NOT use it unless when debugging. It will cause a major
1183 * slowdown in your application
1185 #if 1
1186 XSynchronize(dpy, True);
1187 #endif
1189 * Create screen descriptor.
1191 scr = WMCreateScreen(dpy, DefaultScreen(dpy));
1194 * Loads the logo of the application.
1196 pixmap = WMCreatePixmapFromFile(scr, "logo.xpm");
1199 * Makes the logo be used in standard dialog panels.
1201 WMSetApplicationIconImage(scr, pixmap); WMReleasePixmap(pixmap);
1204 * Do some test stuff.
1206 * Put the testSomething() function you want to test here.
1209 testList(scr);
1211 #if 0
1212 testColorWell(scr);
1214 testTextField(scr);
1215 testText(scr);
1217 testDragAndDrop(scr);
1218 testDragAndDrop(scr);
1219 testFontPanel(scr);
1221 testScrollView(scr);
1223 testButton(scr);
1225 testFrame(scr);
1228 testTabView(scr);
1232 testSplitView(scr);
1234 testGradientButtons(scr);
1235 testProgressIndicator(scr);
1238 testOpenFilePanel(scr);
1240 testSlider(scr);
1241 testPullDown(scr);
1242 #endif
1244 * The main event loop.
1247 WMScreenMainLoop(scr);
1249 return 0;