- the list multiple selection code is working now. it still needs some
[wmaker-crm.git] / WINGs / Tests / wtest.c
blobc30c061ed67ff182853447a1b05a0de0e4a6f11c
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);
134 //sprintf(buf, "Selected items: %d",
135 // WMGetArrayItemCount(WMGetListSelectedItems(lPtr)));;
136 //WMSetLabelText(label, buf);
140 static void
141 listSelectionObserver(void *observer, WMNotification *notification)
143 WMLabel *label = (WMLabel*)observer;
144 WMList *lPtr = (WMList*)WMGetNotificationObject(notification);
145 char buf[255];
147 sprintf(buf, "Selected items: %d",
148 WMGetArrayItemCount(WMGetListSelectedItems(lPtr)));;
149 WMSetLabelText(label, buf);
153 void
154 testList(WMScreen *scr)
156 WMWindow *win;
157 WMList *list;
158 WMList *mlist;
159 WMLabel *label;
160 WMLabel *mlabel;
161 WMLabel *title;
162 WMLabel *mtitle;
163 char text[100];
164 int i;
166 windowCount++;
168 win = WMCreateWindow(scr, "testList");
169 WMResizeWidget(win, 370, 250);
170 WMSetWindowTitle(win, "List");
171 WMSetWindowCloseAction(win, closeAction, NULL);
173 title = WMCreateLabel(win);
174 WMResizeWidget(title, 150, 20);
175 WMMoveWidget(title, 10, 10);
176 WMSetLabelRelief(title, WRRidge);
177 WMSetLabelText(title, "Single selection list");
179 mtitle = WMCreateLabel(win);
180 WMResizeWidget(mtitle, 150, 20);
181 WMMoveWidget(mtitle, 210, 10);
182 WMSetLabelRelief(mtitle, WRRidge);
183 WMSetLabelText(mtitle, "Multiple selection list");
185 list = WMCreateList(win);
186 WMMoveWidget(list, 10, 40);
187 for (i=0; i<50; i++) {
188 sprintf(text, "Item %i", i);
189 WMAddListItem(list, text);
191 mlist = WMCreateList(win);
192 WMSetListAllowMultipleSelection(mlist, True);
193 WMMoveWidget(mlist, 210, 40);
194 for (i=0; i<135; i++) {
195 sprintf(text, "Item %i", i);
196 WMAddListItem(mlist, text);
199 label = WMCreateLabel(win);
200 WMResizeWidget(label, 150, 40);
201 WMMoveWidget(label, 10, 200);
202 WMSetLabelRelief(label, WRRidge);
203 WMSetLabelText(label, "Selected items: 0");
205 mlabel = WMCreateLabel(win);
206 WMResizeWidget(mlabel, 150, 40);
207 WMMoveWidget(mlabel, 210, 200);
208 WMSetLabelRelief(mlabel, WRRidge);
209 WMSetLabelText(mlabel, "Selected items: 0");
211 WMSetListAction(list, singleClick, label);
212 WMSetListDoubleAction(list, doubleClick, label);
213 WMSetListAction(mlist, singleClick, mlabel);
214 WMSetListDoubleAction(mlist, doubleClick, mlabel);
216 WMAddNotificationObserver(listSelectionObserver, label,
217 WMListSelectionDidChangeNotification, list);
218 WMAddNotificationObserver(listSelectionObserver, mlabel,
219 WMListSelectionDidChangeNotification, mlist);
222 WMRealizeWidget(win);
223 WMMapSubwidgets(win);
224 WMMapWidget(win);
228 void
229 testButton(WMScreen *scr)
231 WMWindow *win;
232 int i;
233 char *types[] = {
234 "MomentaryPush",
235 "PushOnPushOff",
236 "Toggle",
237 "Switch",
238 "Radio",
239 "MomentaryChange",
240 "OnOff",
241 "MomentaryLigh"
244 windowCount++;
246 win = WMCreateWindow(scr, "testButton");
247 WMResizeWidget(win, 300, 300);
248 WMSetWindowTitle(win, "Buttons");
250 WMSetWindowCloseAction(win, closeAction, NULL);
252 for (i = 1; i < 9; i++) {
253 WMButton *b;
254 b = WMCreateButton(win, i);
255 WMResizeWidget(b, 150, 24);
256 WMMoveWidget(b, 20, i*30);
257 WMSetButtonText(b, types[i-1]);
260 WMRealizeWidget(win);
261 WMMapSubwidgets(win);
262 WMMapWidget(win);
266 void
267 testGradientButtons(WMScreen *scr)
269 WMWindow *win;
270 WMButton *btn;
271 WMPixmap *pix1, *pix2;
272 RImage *back;
273 RColor light, dark;
274 WMColor *color, *altColor;
276 windowCount++;
278 /* creates the top-level window */
279 win = WMCreateWindow(scr, "testGradientButtons");
280 WMSetWindowTitle(win, "Gradiented Button Demo");
281 WMResizeWidget(win, 300, 200);
283 light.red = 0x90;
284 light.green = 0x85;
285 light.blue = 0x90;
286 dark.red = 0x35;
287 dark.green = 0x30;
288 dark.blue = 0x35;
290 color = WMCreateRGBColor(scr, 0x5900, 0x5100, 0x5900, True);
291 WMSetWidgetBackgroundColor(win, color);
292 WMReleaseColor(color);
294 back = RRenderGradient(60, 24, &dark, &light, RGRD_DIAGONAL);
295 RBevelImage(back, RBEV_RAISED2);
296 pix1 = WMCreatePixmapFromRImage(scr, back, 0);
297 RDestroyImage(back);
299 back = RRenderGradient(60, 24, &dark, &light, RGRD_DIAGONAL);
300 RBevelImage(back, RBEV_SUNKEN);
301 pix2 = WMCreatePixmapFromRImage(scr, back, 0);
302 RDestroyImage(back);
304 color = WMWhiteColor(scr);
305 altColor = WMCreateNamedColor(scr, "red", True);
307 btn = WMCreateButton(win, WBTMomentaryChange);
308 WMResizeWidget(btn, 60, 24);
309 WMMoveWidget(btn, 20, 100);
310 WMSetButtonBordered(btn, False);
311 WMSetButtonImagePosition(btn, WIPOverlaps);
312 WMSetButtonImage(btn, pix1);
313 WMSetButtonAltImage(btn, pix2);
314 WMSetButtonText(btn, "Cool");
315 WMSetButtonTextColor(btn, color);
316 WMSetButtonAltTextColor(btn, altColor);
318 WMSetBalloonTextForView("This is a cool button", WMWidgetView(btn));
320 btn = WMCreateButton(win, WBTMomentaryChange);
321 WMResizeWidget(btn, 60, 24);
322 WMMoveWidget(btn, 90, 100);
323 WMSetButtonBordered(btn, False);
324 WMSetButtonImagePosition(btn, WIPOverlaps);
325 WMSetButtonImage(btn, pix1);
326 WMSetButtonAltImage(btn, pix2);
327 WMSetButtonText(btn, "Button");
328 WMSetButtonTextColor(btn, color);
330 WMSetBalloonTextForView("Este é outro balão.", WMWidgetView(btn));
332 WMReleaseColor(color);
333 color = WMCreateNamedColor(scr, "orange", True);
335 btn = WMCreateButton(win, WBTMomentaryChange);
336 WMResizeWidget(btn, 60, 24);
337 WMMoveWidget(btn, 160, 100);
338 WMSetButtonBordered(btn, False);
339 WMSetButtonImagePosition(btn, WIPOverlaps);
340 WMSetButtonImage(btn, pix1);
341 WMSetButtonAltImage(btn, pix2);
342 WMSetButtonText(btn, "Test");
343 WMSetButtonTextColor(btn, color);
345 WMSetBalloonTextForView("This is yet another button.\nBut the balloon has 3 lines.\nYay!",
346 WMWidgetView(btn));
348 WMReleaseColor(color);
349 WMReleaseColor(altColor);
351 WMRealizeWidget(win);
352 WMMapSubwidgets(win);
353 WMMapWidget(win);
357 void
358 testScrollView(WMScreen *scr)
360 WMWindow *win;
361 WMScrollView *sview;
362 WMFrame *f;
363 WMLabel *l;
364 char buffer[128];
365 int i;
367 windowCount++;
369 /* creates the top-level window */
370 win = WMCreateWindow(scr, "testScroll");
371 WMSetWindowTitle(win, "Scrollable View");
373 WMSetWindowCloseAction(win, closeAction, NULL);
375 /* set the window size */
376 WMResizeWidget(win, 300, 300);
378 /* creates a scrollable view inside the top-level window */
379 sview = WMCreateScrollView(win);
380 WMResizeWidget(sview, 200, 200);
381 WMMoveWidget(sview, 30, 30);
382 WMSetScrollViewRelief(sview, WRSunken);
383 WMSetScrollViewHasVerticalScroller(sview, True);
384 WMSetScrollViewHasHorizontalScroller(sview, True);
386 /* create a frame with a bunch of labels */
387 f = WMCreateFrame(win);
388 WMResizeWidget(f, 400, 400);
389 WMSetFrameRelief(f, WRFlat);
391 for (i=0; i<20; i++) {
392 l = WMCreateLabel(f);
393 WMResizeWidget(l, 50, 18);
394 WMMoveWidget(l, 10, 20*i);
395 sprintf(buffer, "Label %i", i);
396 WMSetLabelText(l, buffer);
397 WMSetLabelRelief(l, WRSimple);
399 WMMapSubwidgets(f);
400 WMMapWidget(f);
402 WMSetScrollViewContentView(sview, WMWidgetView(f));
404 /* make the windows of the widgets be actually created */
405 WMRealizeWidget(win);
407 /* Map all child widgets of the top-level be mapped.
408 * You must call this for each container widget (like frames),
409 * even if they are childs of the top-level window.
411 WMMapSubwidgets(win);
413 /* map the top-level window */
414 WMMapWidget(win);
418 void
419 testColorWell(WMScreen *scr)
421 WMWindow *win;
422 WMColorWell *well1, *well2;
424 windowCount++;
426 win = WMCreateWindow(scr, "testColor");
427 WMResizeWidget(win, 300, 300);
428 WMSetWindowCloseAction(win, closeAction, NULL);
430 well1 = WMCreateColorWell(win);
431 WMResizeWidget(well1, 60, 40);
432 WMMoveWidget(well1, 100, 100);
433 WMSetColorWellColor(well1, WMCreateRGBColor(scr, 0x8888, 0, 0x1111, True));
434 well2 = WMCreateColorWell(win);
435 WMResizeWidget(well2, 60, 40);
436 WMMoveWidget(well2, 200, 100);
437 WMSetColorWellColor(well2, WMCreateRGBColor(scr, 0, 0, 0x8888, True));
439 WMRealizeWidget(win);
440 WMMapSubwidgets(win);
441 WMMapWidget(win);
444 void
445 sliderCallback(WMWidget *w, void *data)
447 printf("SLIDER == %i\n", WMGetSliderValue(w));
451 void
452 testSlider(WMScreen *scr)
454 WMWindow *win;
455 WMSlider *s;
457 windowCount++;
459 win = WMCreateWindow(scr, "testSlider");
460 WMResizeWidget(win, 300, 300);
461 WMSetWindowTitle(win, "Sliders");
463 WMSetWindowCloseAction(win, closeAction, NULL);
465 s = WMCreateSlider(win);
466 WMResizeWidget(s, 16, 100);
467 WMMoveWidget(s, 100, 100);
468 WMSetSliderKnobThickness(s, 8);
469 WMSetSliderContinuous(s, False);
470 WMSetSliderAction(s, sliderCallback, s);
472 s = WMCreateSlider(win);
473 WMResizeWidget(s, 100, 16);
474 WMMoveWidget(s, 100, 10);
475 WMSetSliderKnobThickness(s, 8);
477 WMRealizeWidget(win);
478 WMMapSubwidgets(win);
479 WMMapWidget(win);
482 void
483 testTextField(WMScreen *scr)
485 WMWindow *win;
486 WMTextField *field, *field2;
488 windowCount++;
490 win = WMCreateWindow(scr, "testTextField");
491 WMResizeWidget(win, 400, 300);
493 WMSetWindowCloseAction(win, closeAction, NULL);
495 field = WMCreateTextField(win);
496 WMResizeWidget(field, 200, 20);
497 WMMoveWidget(field, 20, 20);
499 field2 = WMCreateTextField(win);
500 WMResizeWidget(field2, 200, 20);
501 WMMoveWidget(field2, 20, 50);
502 WMSetTextFieldAlignment(field2, WARight);
504 WMRealizeWidget(win);
505 WMMapSubwidgets(win);
506 WMMapWidget(win);
510 void
511 testText(WMScreen *scr)
513 WMWindow *win;
514 WMText *text;
515 FILE *file = fopen("../README", "r");
517 windowCount++;
519 win = WMCreateWindow(scr, "testText");
520 WMResizeWidget(win, 500, 300);
522 WMSetWindowCloseAction(win, closeAction, NULL);
524 text = WMCreateText(win);
525 WMResizeWidget(text, 480, 280);
526 WMMoveWidget(text, 10, 10);
527 WMSetTextHasVerticalScroller(text, True);
528 WMSetTextEditable(text, False);
530 if(file) {
531 char buf[1024];
533 WMFreezeText(text);
534 while(fgets(buf, 1023, file))
535 WMAppendTextStream(text, buf);
537 fclose(file);
538 WMThawText(text);
539 WMRefreshText(text, 0, 0);
540 } else {
541 WMAppendTextStream(text, "<HTML><i>Where's</i> the <b>README</b>?");
544 WMRealizeWidget(win);
545 WMMapSubwidgets(win);
546 WMMapWidget(win);
551 void
552 testProgressIndicator(WMScreen *scr)
554 WMWindow *win;
555 WMProgressIndicator *pPtr;
557 windowCount++;
559 win = WMCreateWindow(scr, "testProgressIndicator");
560 WMResizeWidget(win, 292, 32);
562 WMSetWindowCloseAction(win, closeAction, NULL);
564 pPtr = WMCreateProgressIndicator(win);
565 WMMoveWidget(pPtr, 8, 8);
566 WMSetProgressIndicatorValue(pPtr, 75);
568 WMRealizeWidget(win);
569 WMMapSubwidgets(win);
570 WMMapWidget(win);
575 void
576 testPullDown(WMScreen *scr)
578 WMWindow *win;
579 WMPopUpButton *pop, *pop2;
581 windowCount++;
583 win = WMCreateWindow(scr, "pullDown");
584 WMResizeWidget(win, 400, 300);
586 WMSetWindowCloseAction(win, closeAction, NULL);
588 pop = WMCreatePopUpButton(win);
589 WMResizeWidget(pop, 100, 20);
590 WMMoveWidget(pop, 50, 60);
591 WMSetPopUpButtonPullsDown(pop, True);
592 WMSetPopUpButtonText(pop, "Commands");
593 WMAddPopUpButtonItem(pop, "Add");
594 WMAddPopUpButtonItem(pop, "Remove");
595 WMAddPopUpButtonItem(pop, "Check");
596 WMAddPopUpButtonItem(pop, "Eat");
598 pop2 = WMCreatePopUpButton(win);
599 WMResizeWidget(pop2, 100, 20);
600 WMMoveWidget(pop2, 200, 60);
601 WMSetPopUpButtonText(pop2, "Select");
602 WMAddPopUpButtonItem(pop2, "Apples");
603 WMAddPopUpButtonItem(pop2, "Bananas");
604 WMAddPopUpButtonItem(pop2, "Strawberries");
605 WMAddPopUpButtonItem(pop2, "Blueberries");
607 WMRealizeWidget(win);
608 WMMapSubwidgets(win);
609 WMMapWidget(win);
614 void
615 testTabView(WMScreen *scr)
617 WMWindow *win;
618 WMTabView *tabv;
619 WMTabViewItem *tab;
620 WMFrame *frame;
621 WMLabel *label;
623 windowCount++;
625 win = WMCreateWindow(scr, "testTabs");
626 WMResizeWidget(win, 400, 300);
628 WMSetWindowCloseAction(win, closeAction, NULL);
630 tabv = WMCreateTabView(win);
631 WMMoveWidget(tabv, 50, 50);
632 WMResizeWidget(tabv, 300, 200);
634 frame = WMCreateFrame(win);
635 WMSetFrameRelief(frame, WRFlat);
636 label = WMCreateLabel(frame);
637 WMResizeWidget(label, 100, 100);
638 WMSetLabelText(label, "Label 1");
639 WMMapWidget(label);
642 tab = WMCreateTabViewItemWithIdentifier(0);
643 WMSetTabViewItemView(tab, WMWidgetView(frame));
644 WMAddItemInTabView(tabv, tab);
645 WMSetTabViewItemLabel(tab, "Instances");
647 frame = WMCreateFrame(win);
648 WMSetFrameRelief(frame, WRFlat);
649 label = WMCreateLabel(frame);
650 WMResizeWidget(label, 40, 50);
651 WMSetLabelText(label, "Label 2");
652 WMMapWidget(label);
655 tab = WMCreateTabViewItemWithIdentifier(0);
656 WMSetTabViewItemView(tab, WMWidgetView(frame));
657 WMAddItemInTabView(tabv, tab);
658 WMSetTabViewItemLabel(tab, "Classes");
661 frame = WMCreateFrame(win);
662 WMSetFrameRelief(frame, WRFlat);
663 label = WMCreateLabel(frame);
664 WMResizeWidget(label, 100, 100);
665 WMMoveWidget(label, 60, 40);
666 WMSetLabelText(label, "Label 3");
667 WMMapWidget(label);
669 tab = WMCreateTabViewItemWithIdentifier(0);
670 WMSetTabViewItemView(tab, WMWidgetView(frame));
671 WMAddItemInTabView(tabv, tab);
672 WMSetTabViewItemLabel(tab, "Something");
675 frame = WMCreateFrame(win);
676 WMSetFrameRelief(frame, WRFlat);
677 label = WMCreateLabel(frame);
678 WMResizeWidget(label, 100, 100);
679 WMMoveWidget(label, 160, 40);
680 WMSetLabelText(label, "Label 4");
681 WMMapWidget(label);
683 tab = WMCreateTabViewItemWithIdentifier(0);
684 WMSetTabViewItemView(tab, WMWidgetView(frame));
685 WMAddItemInTabView(tabv, tab);
686 WMSetTabViewItemLabel(tab, "Bla!");
690 frame = WMCreateFrame(win);
691 WMSetFrameRelief(frame, WRFlat);
692 label = WMCreateLabel(frame);
693 WMResizeWidget(label, 100, 100);
694 WMMoveWidget(label, 160, 40);
695 WMSetLabelText(label, "Label fjweqklrj qwl");
696 WMMapWidget(label);
697 tab = WMCreateTabViewItemWithIdentifier(0);
698 WMSetTabViewItemView(tab, WMWidgetView(frame));
699 WMAddItemInTabView(tabv, tab);
700 WMSetTabViewItemLabel(tab, "Weee!");
703 WMRealizeWidget(win);
704 WMMapSubwidgets(win);
705 WMMapWidget(win);
709 void
710 splitViewConstrainProc(WMSplitView *sPtr, int indView,
711 int *minSize, int *maxSize)
713 switch (indView) {
714 case 0:
715 *minSize = 20;
716 break;
717 case 1:
718 *minSize = 40;
719 *maxSize = 80;
720 break;
721 case 2:
722 *maxSize = 60;
723 break;
724 default:
725 break;
730 static void
731 resizeSplitView(XEvent *event, void *data)
733 WMSplitView *sPtr = (WMSplitView*)data;
735 if (event->type == ConfigureNotify) {
736 int width = event->xconfigure.width - 10;
738 if (width < WMGetSplitViewDividerThickness(sPtr))
739 width = WMGetSplitViewDividerThickness(sPtr);
741 if (width != WMWidgetWidth(sPtr) ||
742 event->xconfigure.height != WMWidgetHeight(sPtr))
743 WMResizeWidget(sPtr, width, event->xconfigure.height - 55);
747 void
748 appendSubviewButtonAction(WMWidget *self, void *data)
750 WMSplitView *sPtr = (WMSplitView*)data;
751 char buf[64];
752 WMLabel *label = WMCreateLabel(sPtr);
754 sprintf(buf, "Subview %d", WMGetSplitViewSubviewsCount(sPtr) + 1);
755 WMSetLabelText(label, buf);
756 WMSetLabelRelief(label, WRSunken);
757 WMAddSplitViewSubview(sPtr, WMWidgetView(label));
758 WMRealizeWidget(label);
759 WMMapWidget(label);
762 void
763 removeSubviewButtonAction(WMWidget *self, void *data)
765 WMSplitView *sPtr = (WMSplitView*)data;
766 int count = WMGetSplitViewSubviewsCount(sPtr);
768 if (count > 2) {
769 WMView *view = WMGetSplitViewSubviewAt(sPtr, count-1);
770 WMDestroyWidget(WMWidgetOfView(view));
771 WMRemoveSplitViewSubviewAt(sPtr, count-1);
775 void
776 orientationButtonAction(WMWidget *self, void *data)
778 WMSplitView *sPtr = (WMSplitView*)data;
779 WMSetSplitViewVertical(sPtr, !WMGetSplitViewVertical(sPtr));
782 void
783 adjustSubviewsButtonAction(WMWidget *self, void *data)
785 WMAdjustSplitViewSubviews((WMSplitView*)data);
788 void
789 testSplitView(WMScreen *scr)
791 WMWindow *win;
792 WMSplitView *splitv1, *splitv2;
793 WMFrame *frame;
794 WMLabel *label;
795 WMButton *button;
797 windowCount++;
799 win = WMCreateWindow(scr, "testTabs");
800 WMResizeWidget(win, 300, 400);
801 WMSetWindowCloseAction(win, closeAction, NULL);
803 frame = WMCreateFrame(win);
804 WMSetFrameRelief(frame, WRSunken);
805 WMMoveWidget(frame, 5, 5);
806 WMResizeWidget(frame, 290, 40);
808 splitv1 = WMCreateSplitView(win);
809 WMMoveWidget(splitv1, 5, 50);
810 WMResizeWidget(splitv1, 290, 345);
811 WMSetSplitViewConstrainProc(splitv1, splitViewConstrainProc);
812 WMCreateEventHandler(WMWidgetView(win), StructureNotifyMask,
813 resizeSplitView, splitv1);
815 button = WMCreateCommandButton(frame);
816 WMSetButtonText(button, "+");
817 WMSetButtonAction(button, appendSubviewButtonAction, splitv1);
818 WMMoveWidget(button, 10, 8);
819 WMMapWidget(button);
821 button = WMCreateCommandButton(frame);
822 WMSetButtonText(button, "-");
823 WMSetButtonAction(button, removeSubviewButtonAction, splitv1);
824 WMMoveWidget(button, 80, 8);
825 WMMapWidget(button);
827 button = WMCreateCommandButton(frame);
828 WMSetButtonText(button, "=");
829 WMMoveWidget(button, 150, 8);
830 WMSetButtonAction(button, adjustSubviewsButtonAction, splitv1);
831 WMMapWidget(button);
833 button = WMCreateCommandButton(frame);
834 WMSetButtonText(button, "#");
835 WMMoveWidget(button, 220, 8);
836 WMSetButtonAction(button, orientationButtonAction, splitv1);
837 WMMapWidget(button);
839 label = WMCreateLabel(splitv1);
840 WMSetLabelText(label, "Subview 1");
841 WMSetLabelRelief(label, WRSunken);
842 WMMapWidget(label);
843 WMAddSplitViewSubview(splitv1, WMWidgetView(label));
845 splitv2 = WMCreateSplitView(splitv1);
846 WMResizeWidget(splitv2, 150, 150);
847 WMSetSplitViewVertical(splitv2, True);
849 label = WMCreateLabel(splitv2);
850 WMSetLabelText(label, "Subview 2.1");
851 WMSetLabelRelief(label, WRSunken);
852 WMMapWidget(label);
853 WMAddSplitViewSubview(splitv2, WMWidgetView(label));
855 label = WMCreateLabel(splitv2);
856 WMSetLabelText(label, "Subview 2.2");
857 WMSetLabelRelief(label, WRSunken);
858 WMMapWidget(label);
859 WMAddSplitViewSubview(splitv2, WMWidgetView(label));
861 label = WMCreateLabel(splitv2);
862 WMSetLabelText(label, "Subview 2.3");
863 WMSetLabelRelief(label, WRSunken);
864 WMMapWidget(label);
865 WMAddSplitViewSubview(splitv2, WMWidgetView(label));
867 WMMapWidget(splitv2);
868 WMAddSplitViewSubview(splitv1, WMWidgetView(splitv2));
870 WMRealizeWidget(win);
871 WMMapSubwidgets(win);
872 WMMapWidget(win);
876 /*******************************************************************/
878 #include <sys/types.h>
879 #include <dirent.h>
880 #include <string.h>
883 typedef struct {
884 int x, y;
885 Bool mouseDown;
886 char *filename;
887 } DNDStuff;
889 WMPixmap*
890 getImage(WMScreen *scr, char *file)
892 char buffer[1000];
893 WMPixmap *pix;
895 sprintf(buffer, "../../WindowMaker/Icons/%s", file);
896 pix = WMCreatePixmapFromFile(scr, buffer);
898 return pix;
904 static void
905 iconMouseStuff(XEvent *event, void *cdata)
907 WMLabel *label = (WMLabel*)cdata;
908 DNDStuff *stuff = WMGetHangedData(label);
909 WMPoint where;
911 switch (event->type) {
912 case ButtonPress:
913 stuff->x = event->xbutton.x;
914 stuff->y = event->xbutton.y;
915 stuff->mouseDown = True;
916 break;
917 case ButtonRelease:
918 stuff->mouseDown = False;
919 break;
920 case MotionNotify:
921 if (!stuff->mouseDown)
922 break;
924 if (abs(stuff->x - event->xmotion.x)>4
925 || abs(stuff->y - event->xmotion.y)>4) {
927 where = WMGetViewScreenPosition(WMWidgetView(label));
929 WMDragImageFromView(WMWidgetView(label),
930 WMGetLabelImage(label),
931 NULL, /* XXX */
932 where,
933 wmksize(stuff->x, stuff->y),
934 event, True);
936 break;
941 static void
942 endedDragImage(WMView *self, WMPixmap *image, WMPoint point, Bool deposited)
944 DNDStuff *stuff = WMGetHangedData(WMWidgetOfView(self));
946 if (deposited) {
947 WMDestroyWidget(WMWidgetOfView(self));
950 stuff->mouseDown = False;
954 static WMData*
955 fetchDragData(WMView *self, char *type)
957 DNDStuff *stuff = WMGetHangedData(WMWidgetOfView(self));
959 return WMCreateDataWithBytes(stuff->filename, strlen(stuff->filename)+1);
963 WMDragSourceProcs dragSourceProcs = {
964 NULL,
965 NULL,
966 endedDragImage,
967 fetchDragData
971 /************************/
974 unsigned
975 draggingEntered(WMView *self, WMDraggingInfo *info)
977 return WDOperationCopy;
981 unsigned
982 draggingUpdated(WMView *self, WMDraggingInfo *info)
984 return WDOperationCopy;
988 void (*draggingExited)(WMView *self, WMDraggingInfo *info);
990 char*
991 prepareForDragOperation(WMView *self, WMDraggingInfo *info)
993 return "application/X-WINGs-Bla";
997 WMLabel* makeDraggableLabel(WMWidget *w, char *file, int x, int y);
999 Bool
1000 performDragOperation(WMView *self, WMDraggingInfo *info, WMData *data)
1002 char *file = (char*)WMDataBytes(data);
1003 WMPoint pos;
1005 pos = WMGetDraggingInfoImageLocation(info);
1007 if (file!=NULL) {
1008 WMLabel *label;
1009 WMPoint pos2 = WMGetViewScreenPosition(self);
1012 label = makeDraggableLabel(WMWidgetOfView(self), file,
1013 pos.x-pos2.x, pos.y-pos2.y);
1014 WMRealizeWidget(label);
1015 WMMapWidget(label);
1019 return True;
1023 void
1024 concludeDragOperation(WMView *self, WMDraggingInfo *info)
1031 WMDragDestinationProcs dragDestProcs = {
1032 draggingEntered,
1033 draggingUpdated,
1034 NULL,
1035 prepareForDragOperation,
1036 performDragOperation,
1037 concludeDragOperation
1043 WMLabel*
1044 makeDraggableLabel(WMWidget *w, char *file, int x, int y)
1046 DNDStuff *stuff;
1047 WMLabel *label;
1048 WMPixmap *image = getImage(WMWidgetScreen(w), file);
1050 stuff = wmalloc(sizeof(DNDStuff));
1051 stuff->mouseDown = False;
1053 stuff->filename = wstrdup(file);
1055 label = WMCreateLabel(w);
1056 WMResizeWidget(label, 48, 48);
1057 WMMoveWidget(label, x, y);
1059 WMSetViewDragSourceProcs(WMWidgetView(label), &dragSourceProcs);
1061 WMHangData(label, stuff);
1063 WMCreateEventHandler(WMWidgetView(label),
1064 ButtonPressMask|ButtonReleaseMask|ButtonMotionMask,
1065 iconMouseStuff, label);
1068 if (image != NULL) {
1069 WMSetLabelImagePosition(label, WIPImageOnly);
1070 WMSetLabelImage(label, image);
1071 WMReleasePixmap(image);
1072 } else puts(file);
1074 return label;
1079 void
1080 testDragAndDrop(WMScreen *scr)
1082 WMWindow *win;
1083 WMFrame *frame;
1084 WMLabel *label;
1085 int i, j;
1086 DIR *dir;
1087 struct dirent *ent;
1088 char *types[] = {
1089 "application/X-WINGs-Bla",
1090 NULL
1093 windowCount++;
1095 win = WMCreateWindow(scr, "dragDrop");
1096 WMResizeWidget(win, 300, 300);
1097 WMSetWindowCloseAction(win, closeAction, NULL);
1098 WMSetWindowTitle(win, "Drag and Drop");
1101 frame = WMCreateFrame(win);
1102 WMSetFrameRelief(frame, WRSunken);
1103 WMResizeWidget(frame, 250, 250);
1104 WMMoveWidget(frame, 25, 25);
1106 WMRegisterViewForDraggedTypes(WMWidgetView(frame), types);
1107 WMSetViewDragDestinationProcs(WMWidgetView(frame), &dragDestProcs);
1109 dir = opendir("../../WindowMaker/Icons");
1110 if (!dir) {
1111 perror("../../WindowMaker/Icons");
1112 return;
1115 for (i = 0, j=0; j < 8; i++) {
1116 ent = readdir(dir);
1117 if (!ent)
1118 break;
1120 if (strstr(ent->d_name, ".xpm")==NULL) {
1121 continue;
1124 label = makeDraggableLabel(frame, ent->d_name,4+(j/4)*64, 4+(j%4)*64);
1126 j++;
1129 closedir(dir);
1131 WMMapSubwidgets(frame);
1133 WMMapSubwidgets(win);
1134 WMRealizeWidget(win);
1135 WMMapWidget(win);
1142 /*******************************************************************/
1144 #include "WUtil.h"
1146 void
1147 testUD()
1149 WMUserDefaults *defs;
1150 char str[32];
1152 defs = WMGetStandardUserDefaults();
1154 sprintf(str, "TEST DATA");
1155 puts(str);
1156 WMSetUDStringForKey(defs, str, "testKey");
1157 puts(str);
1162 main(int argc, char **argv)
1164 WMScreen *scr;
1165 WMPixmap *pixmap;
1168 /* Initialize the application */
1169 WMInitializeApplication("Test", &argc, argv);
1171 testUD();
1174 * Open connection to the X display.
1176 dpy = XOpenDisplay("");
1178 if (!dpy) {
1179 puts("could not open display");
1180 exit(1);
1183 /* This is used to disable buffering of X protocol requests.
1184 * Do NOT use it unless when debugging. It will cause a major
1185 * slowdown in your application
1187 #if 1
1188 XSynchronize(dpy, True);
1189 #endif
1191 * Create screen descriptor.
1193 scr = WMCreateScreen(dpy, DefaultScreen(dpy));
1196 * Loads the logo of the application.
1198 pixmap = WMCreatePixmapFromFile(scr, "logo.xpm");
1201 * Makes the logo be used in standard dialog panels.
1203 WMSetApplicationIconImage(scr, pixmap); WMReleasePixmap(pixmap);
1206 * Do some test stuff.
1208 * Put the testSomething() function you want to test here.
1211 testList(scr);
1213 #if 0
1214 testColorWell(scr);
1216 testTextField(scr);
1217 testText(scr);
1219 testDragAndDrop(scr);
1220 testDragAndDrop(scr);
1221 testFontPanel(scr);
1223 testScrollView(scr);
1225 testButton(scr);
1227 testFrame(scr);
1230 testTabView(scr);
1234 testSplitView(scr);
1236 testGradientButtons(scr);
1237 testProgressIndicator(scr);
1240 testOpenFilePanel(scr);
1242 testSlider(scr);
1243 testPullDown(scr);
1244 #endif
1246 * The main event loop.
1249 WMScreenMainLoop(scr);
1251 return 0;