2 * WINGs test application
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
30 closeAction(WMWidget
*self
, void *data
)
32 WMDestroyWidget(self
);
40 testOpenFilePanel(WMScreen
*scr
)
46 /* get the shared Open File panel */
47 panel
= WMGetOpenPanel(scr
);
49 WMRunModalFilePanelForDirectory(panel
, NULL
, "/usr/local", NULL
, NULL
);
51 /* free the panel to save some memory. Not needed otherwise. */
52 WMFreeFilePanel(WMGetOpenPanel(scr
));
57 testFontPanel(WMScreen
*scr
)
63 panel
= WMGetFontPanel(scr
);
65 WMShowFontPanel(panel
);
67 /* WMFreeFontPanel(panel);*/
73 testList(WMScreen
*scr
)
82 win
= WMCreateWindow(scr
, "testList");
83 WMSetWindowTitle(win
, "List");
84 WMSetWindowCloseAction(win
, closeAction
, NULL
);
86 list
= WMCreateList(win
);
87 for (i
=0; i
<50; i
++) {
88 sprintf(text
, "Item %i", i
);
89 WMAddListItem(list
, text
);
100 testGradientButtons(WMScreen
*scr
)
104 WMPixmap
*pix1
, *pix2
;
107 WMColor
*color
, *altColor
;
111 /* creates the top-level window */
112 win
= WMCreateWindow(scr
, "testGradientButtons");
113 WMSetWindowTitle(win
, "Gradiented Button Demo");
114 WMResizeWidget(win
, 300, 200);
123 color
= WMCreateRGBColor(scr
, 0x5900, 0x5100, 0x5900, True
);
124 WMSetWidgetBackgroundColor(win
, color
);
125 WMReleaseColor(color
);
127 back
= RRenderGradient(60, 24, &dark
, &light
, RGRD_DIAGONAL
);
128 RBevelImage(back
, RBEV_RAISED2
);
129 pix1
= WMCreatePixmapFromRImage(scr
, back
, 0);
132 back
= RRenderGradient(60, 24, &dark
, &light
, RGRD_DIAGONAL
);
133 RBevelImage(back
, RBEV_SUNKEN
);
134 pix2
= WMCreatePixmapFromRImage(scr
, back
, 0);
137 color
= WMWhiteColor(scr
);
138 altColor
= WMCreateNamedColor(scr
, "red", True
);
140 btn
= WMCreateButton(win
, WBTMomentaryChange
);
141 WMResizeWidget(btn
, 60, 24);
142 WMMoveWidget(btn
, 20, 100);
143 WMSetButtonBordered(btn
, False
);
144 WMSetButtonImagePosition(btn
, WIPOverlaps
);
145 WMSetButtonImage(btn
, pix1
);
146 WMSetButtonAltImage(btn
, pix2
);
147 WMSetButtonText(btn
, "Cool");
148 WMSetButtonTextColor(btn
, color
);
149 WMSetButtonAltTextColor(btn
, altColor
);
151 WMSetBalloonTextForView("This is a cool button", WMWidgetView(btn
));
153 btn
= WMCreateButton(win
, WBTMomentaryChange
);
154 WMResizeWidget(btn
, 60, 24);
155 WMMoveWidget(btn
, 90, 100);
156 WMSetButtonBordered(btn
, False
);
157 WMSetButtonImagePosition(btn
, WIPOverlaps
);
158 WMSetButtonImage(btn
, pix1
);
159 WMSetButtonAltImage(btn
, pix2
);
160 WMSetButtonText(btn
, "Button");
161 WMSetButtonTextColor(btn
, color
);
163 WMSetBalloonTextForView("Este é outro balão.", WMWidgetView(btn
));
165 WMReleaseColor(color
);
166 color
= WMCreateNamedColor(scr
, "orange", True
);
168 btn
= WMCreateButton(win
, WBTMomentaryChange
);
169 WMResizeWidget(btn
, 60, 24);
170 WMMoveWidget(btn
, 160, 100);
171 WMSetButtonBordered(btn
, False
);
172 WMSetButtonImagePosition(btn
, WIPOverlaps
);
173 WMSetButtonImage(btn
, pix1
);
174 WMSetButtonAltImage(btn
, pix2
);
175 WMSetButtonText(btn
, "Test");
176 WMSetButtonTextColor(btn
, color
);
178 WMSetBalloonTextForView("This is yet another button.\nBut the balloon has 3 lines.\nYay!",
181 WMReleaseColor(color
);
182 WMReleaseColor(altColor
);
184 WMRealizeWidget(win
);
185 WMMapSubwidgets(win
);
191 testScrollView(WMScreen
*scr
)
202 /* creates the top-level window */
203 win
= WMCreateWindow(scr
, "testScroll");
204 WMSetWindowTitle(win
, "Scrollable View");
206 WMSetWindowCloseAction(win
, closeAction
, NULL
);
208 /* set the window size */
209 WMResizeWidget(win
, 300, 300);
211 /* creates a scrollable view inside the top-level window */
212 sview
= WMCreateScrollView(win
);
213 WMResizeWidget(sview
, 200, 200);
214 WMMoveWidget(sview
, 30, 30);
215 WMSetScrollViewRelief(sview
, WRSunken
);
216 WMSetScrollViewHasVerticalScroller(sview
, True
);
217 WMSetScrollViewHasHorizontalScroller(sview
, True
);
219 /* create a frame with a bunch of labels */
220 f
= WMCreateFrame(win
);
221 WMResizeWidget(f
, 400, 400);
222 WMSetFrameRelief(f
, WRFlat
);
224 for (i
=0; i
<20; i
++) {
225 l
= WMCreateLabel(f
);
226 WMResizeWidget(l
, 50, 18);
227 WMMoveWidget(l
, 10, 20*i
);
228 sprintf(buffer
, "Label %i", i
);
229 WMSetLabelText(l
, buffer
);
230 WMSetLabelRelief(l
, WRSimple
);
235 WMSetScrollViewContentView(sview
, WMWidgetView(f
));
237 /* make the windows of the widgets be actually created */
238 WMRealizeWidget(win
);
240 /* Map all child widgets of the top-level be mapped.
241 * You must call this for each container widget (like frames),
242 * even if they are childs of the top-level window.
244 WMMapSubwidgets(win
);
246 /* map the top-level window */
252 testColorWell(WMScreen
*scr
)
255 WMColorWell
*well1
, *well2
;
259 win
= WMCreateWindow(scr
, "testColor");
260 WMResizeWidget(win
, 300, 300);
262 WMSetWindowCloseAction(win
, closeAction
, NULL
);
264 well1
= WMCreateColorWell(win
);
265 WMResizeWidget(well1
, 60, 40);
266 WMMoveWidget(well1
, 100, 100);
267 WMSetColorWellColor(well1
, WMCreateRGBColor(scr
, 0x8888, 0, 0x1111, True
));
268 well2
= WMCreateColorWell(win
);
269 WMResizeWidget(well2
, 60, 40);
270 WMMoveWidget(well2
, 200, 100);
271 WMSetColorWellColor(well2
, WMCreateRGBColor(scr
, 0, 0, 0x8888, True
));
273 WMRealizeWidget(win
);
274 WMMapSubwidgets(win
);
279 sliderCallback(WMWidget
*w
, void *data
)
281 printf("SLIEDER == %i\n", WMGetSliderValue(w
));
286 testSlider(WMScreen
*scr
)
293 win
= WMCreateWindow(scr
, "testSlider");
294 WMResizeWidget(win
, 300, 300);
295 WMSetWindowTitle(win
, "Sliders");
297 WMSetWindowCloseAction(win
, closeAction
, NULL
);
299 s
= WMCreateSlider(win
);
300 WMResizeWidget(s
, 16, 100);
301 WMMoveWidget(s
, 100, 100);
302 WMSetSliderKnobThickness(s
, 8);
303 WMSetSliderContinuous(s
, False
);
304 WMSetSliderAction(s
, sliderCallback
, s
);
306 s
= WMCreateSlider(win
);
307 WMResizeWidget(s
, 100, 16);
308 WMMoveWidget(s
, 100, 10);
309 WMSetSliderKnobThickness(s
, 8);
311 WMRealizeWidget(win
);
312 WMMapSubwidgets(win
);
318 testTextField(WMScreen
*scr
)
321 WMTextField
*field
, *field2
;
325 win
= WMCreateWindow(scr
, "testText");
326 WMResizeWidget(win
, 400, 300);
328 WMSetWindowCloseAction(win
, closeAction
, NULL
);
330 field
= WMCreateTextField(win
);
331 WMResizeWidget(field
, 200, 20);
332 WMMoveWidget(field
, 20, 20);
334 field2
= WMCreateTextField(win
);
335 WMResizeWidget(field2
, 200, 20);
336 WMMoveWidget(field2
, 20, 50);
337 WMSetTextFieldAlignment(field2
, WARight
);
339 WMRealizeWidget(win
);
340 WMMapSubwidgets(win
);
347 testProgressIndicator(WMScreen
*scr
)
350 WMProgressIndicator
*pPtr
;
354 win
= WMCreateWindow(scr
, "testProgressIndicator");
355 WMResizeWidget(win
, 292, 32);
357 WMSetWindowCloseAction(win
, closeAction
, NULL
);
359 pPtr
= WMCreateProgressIndicator(win
);
360 WMMoveWidget(pPtr
, 8, 8);
361 WMSetProgressIndicatorValue(pPtr
, 75);
363 WMRealizeWidget(win
);
364 WMMapSubwidgets(win
);
371 testPullDown(WMScreen
*scr
)
374 WMPopUpButton
*pop
, *pop2
;
378 win
= WMCreateWindow(scr
, "pullDown");
379 WMResizeWidget(win
, 400, 300);
381 WMSetWindowCloseAction(win
, closeAction
, NULL
);
383 pop
= WMCreatePopUpButton(win
);
384 WMResizeWidget(pop
, 100, 20);
385 WMMoveWidget(pop
, 50, 60);
386 WMSetPopUpButtonPullsDown(pop
, True
);
387 WMSetPopUpButtonText(pop
, "Commands");
388 WMAddPopUpButtonItem(pop
, "Add");
389 WMAddPopUpButtonItem(pop
, "Remove");
390 WMAddPopUpButtonItem(pop
, "Check");
391 WMAddPopUpButtonItem(pop
, "Eat");
393 pop2
= WMCreatePopUpButton(win
);
394 WMResizeWidget(pop2
, 100, 20);
395 WMMoveWidget(pop2
, 200, 60);
396 WMSetPopUpButtonText(pop2
, "Select");
397 WMAddPopUpButtonItem(pop2
, "Apples");
398 WMAddPopUpButtonItem(pop2
, "Bananas");
399 WMAddPopUpButtonItem(pop2
, "Strawberries");
400 WMAddPopUpButtonItem(pop2
, "Blueberries");
402 WMRealizeWidget(win
);
403 WMMapSubwidgets(win
);
410 testTabView(WMScreen
*scr
)
420 win
= WMCreateWindow(scr
, "testTabs");
421 WMResizeWidget(win
, 400, 300);
423 WMSetWindowCloseAction(win
, closeAction
, NULL
);
425 tabv
= WMCreateTabView(win
);
426 WMMoveWidget(tabv
, 50, 50);
427 WMResizeWidget(tabv
, 300, 200);
429 frame
= WMCreateFrame(win
);
430 WMSetFrameRelief(frame
, WRFlat
);
431 label
= WMCreateLabel(frame
);
432 WMResizeWidget(label
, 100, 100);
433 WMSetLabelText(label
, "Label 1");
437 tab
= WMCreateTabViewItemWithIdentifier(0);
438 WMSetTabViewItemView(tab
, WMWidgetView(frame
));
439 WMAddItemInTabView(tabv
, tab
);
440 WMSetTabViewItemLabel(tab
, "Instances");
442 frame
= WMCreateFrame(win
);
443 WMSetFrameRelief(frame
, WRFlat
);
444 label
= WMCreateLabel(frame
);
445 WMResizeWidget(label
, 40, 50);
446 WMSetLabelText(label
, "Label 2");
450 tab
= WMCreateTabViewItemWithIdentifier(0);
451 WMSetTabViewItemView(tab
, WMWidgetView(frame
));
452 WMAddItemInTabView(tabv
, tab
);
453 WMSetTabViewItemLabel(tab
, "Classes");
456 frame
= WMCreateFrame(win
);
457 WMSetFrameRelief(frame
, WRFlat
);
458 label
= WMCreateLabel(frame
);
459 WMResizeWidget(label
, 100, 100);
460 WMMoveWidget(label
, 60, 40);
461 WMSetLabelText(label
, "Label 3");
464 tab
= WMCreateTabViewItemWithIdentifier(0);
465 WMSetTabViewItemView(tab
, WMWidgetView(frame
));
466 WMAddItemInTabView(tabv
, tab
);
467 WMSetTabViewItemLabel(tab
, "Something");
470 frame
= WMCreateFrame(win
);
471 WMSetFrameRelief(frame
, WRFlat
);
472 label
= WMCreateLabel(frame
);
473 WMResizeWidget(label
, 100, 100);
474 WMMoveWidget(label
, 160, 40);
475 WMSetLabelText(label
, "Label 4");
478 tab
= WMCreateTabViewItemWithIdentifier(0);
479 WMSetTabViewItemView(tab
, WMWidgetView(frame
));
480 WMAddItemInTabView(tabv
, tab
);
481 WMSetTabViewItemLabel(tab
, "Bla!");
485 frame
= WMCreateFrame(win
);
486 WMSetFrameRelief(frame
, WRFlat
);
487 label
= WMCreateLabel(frame
);
488 WMResizeWidget(label
, 100, 100);
489 WMMoveWidget(label
, 160, 40);
490 WMSetLabelText(label
, "Label fjweqklrj qwl");
492 tab
= WMCreateTabViewItemWithIdentifier(0);
493 WMSetTabViewItemView(tab
, WMWidgetView(frame
));
494 WMAddItemInTabView(tabv
, tab
);
495 WMSetTabViewItemLabel(tab
, "Weee!");
498 WMRealizeWidget(win
);
499 WMMapSubwidgets(win
);
505 splitViewConstrainProc(WMSplitView
*sPtr
, int indView
,
506 int *minSize
, int *maxSize
)
526 resizeSplitView(XEvent
*event
, void *data
)
528 WMSplitView
*sPtr
= (WMSplitView
*)data
;
530 if (event
->type
== ConfigureNotify
) {
531 int width
= event
->xconfigure
.width
- 10;
533 if (width
< WMGetSplitViewDividerThickness(sPtr
))
534 width
= WMGetSplitViewDividerThickness(sPtr
);
536 if (width
!= WMWidgetWidth(sPtr
) ||
537 event
->xconfigure
.height
!= WMWidgetHeight(sPtr
))
538 WMResizeWidget(sPtr
, width
, event
->xconfigure
.height
- 55);
543 appendSubviewButtonAction(WMWidget
*self
, void *data
)
545 WMSplitView
*sPtr
= (WMSplitView
*)data
;
547 WMLabel
*label
= WMCreateLabel(sPtr
);
549 sprintf(buf
, "Subview %d", WMGetSplitViewSubviewsCount(sPtr
) + 1);
550 WMSetLabelText(label
, buf
);
551 WMSetLabelRelief(label
, WRSunken
);
552 WMAddSplitViewSubview(sPtr
, WMWidgetView(label
));
553 WMRealizeWidget(label
);
558 removeSubviewButtonAction(WMWidget
*self
, void *data
)
560 WMSplitView
*sPtr
= (WMSplitView
*)data
;
561 int count
= WMGetSplitViewSubviewsCount(sPtr
);
564 WMView
*view
= WMGetSplitViewSubviewAt(sPtr
, count
-1);
565 WMDestroyWidget(WMWidgetOfView(view
));
566 WMRemoveSplitViewSubviewAt(sPtr
, count
-1);
571 orientationButtonAction(WMWidget
*self
, void *data
)
573 WMSplitView
*sPtr
= (WMSplitView
*)data
;
574 WMSetSplitViewVertical(sPtr
, !WMGetSplitViewVertical(sPtr
));
578 adjustSubviewsButtonAction(WMWidget
*self
, void *data
)
580 WMAdjustSplitViewSubviews((WMSplitView
*)data
);
584 testSplitView(WMScreen
*scr
)
587 WMSplitView
*splitv1
, *splitv2
;
594 win
= WMCreateWindow(scr
, "testTabs");
595 WMResizeWidget(win
, 300, 400);
596 WMSetWindowCloseAction(win
, closeAction
, NULL
);
598 frame
= WMCreateFrame(win
);
599 WMSetFrameRelief(frame
, WRSunken
);
600 WMMoveWidget(frame
, 5, 5);
601 WMResizeWidget(frame
, 290, 40);
603 splitv1
= WMCreateSplitView(win
);
604 WMMoveWidget(splitv1
, 5, 50);
605 WMResizeWidget(splitv1
, 290, 345);
606 WMSetSplitViewConstrainProc(splitv1
, splitViewConstrainProc
);
607 WMCreateEventHandler(WMWidgetView(win
), StructureNotifyMask
,
608 resizeSplitView
, splitv1
);
610 button
= WMCreateCommandButton(frame
);
611 WMSetButtonText(button
, "+");
612 WMSetButtonAction(button
, appendSubviewButtonAction
, splitv1
);
613 WMMoveWidget(button
, 10, 8);
616 button
= WMCreateCommandButton(frame
);
617 WMSetButtonText(button
, "-");
618 WMSetButtonAction(button
, removeSubviewButtonAction
, splitv1
);
619 WMMoveWidget(button
, 80, 8);
622 button
= WMCreateCommandButton(frame
);
623 WMSetButtonText(button
, "=");
624 WMMoveWidget(button
, 150, 8);
625 WMSetButtonAction(button
, adjustSubviewsButtonAction
, splitv1
);
628 button
= WMCreateCommandButton(frame
);
629 WMSetButtonText(button
, "#");
630 WMMoveWidget(button
, 220, 8);
631 WMSetButtonAction(button
, orientationButtonAction
, splitv1
);
634 label
= WMCreateLabel(splitv1
);
635 WMSetLabelText(label
, "Subview 1");
636 WMSetLabelRelief(label
, WRSunken
);
638 WMAddSplitViewSubview(splitv1
, WMWidgetView(label
));
640 splitv2
= WMCreateSplitView(splitv1
);
641 WMResizeWidget(splitv2
, 150, 150);
642 WMSetSplitViewVertical(splitv2
, True
);
644 label
= WMCreateLabel(splitv2
);
645 WMSetLabelText(label
, "Subview 2.1");
646 WMSetLabelRelief(label
, WRSunken
);
648 WMAddSplitViewSubview(splitv2
, WMWidgetView(label
));
650 label
= WMCreateLabel(splitv2
);
651 WMSetLabelText(label
, "Subview 2.2");
652 WMSetLabelRelief(label
, WRSunken
);
654 WMAddSplitViewSubview(splitv2
, WMWidgetView(label
));
656 label
= WMCreateLabel(splitv2
);
657 WMSetLabelText(label
, "Subview 2.3");
658 WMSetLabelRelief(label
, WRSunken
);
660 WMAddSplitViewSubview(splitv2
, WMWidgetView(label
));
662 WMMapWidget(splitv2
);
663 WMAddSplitViewSubview(splitv1
, WMWidgetView(splitv2
));
665 WMRealizeWidget(win
);
666 WMMapSubwidgets(win
);
674 int main(int argc
, char **argv
)
680 /* Initialize the application */
681 WMInitializeApplication("Test", &argc
, argv
);
684 * Open connection to the X display.
686 dpy
= XOpenDisplay("");
689 puts("could not open display");
693 /* This is used to disable buffering of X protocol requests.
694 * Do NOT use it unless when debugging. It will cause a major
695 * slowdown in your application
698 XSynchronize(dpy
, True
);
701 * Create screen descriptor.
703 scr
= WMCreateScreen(dpy
, DefaultScreen(dpy
));
706 * Loads the logo of the application.
708 pixmap
= WMCreatePixmapFromFile(scr
, "logo.xpm");
711 * Makes the logo be used in standard dialog panels.
713 WMSetApplicationIconImage(scr
, pixmap
); WMReleasePixmap(pixmap
);
716 * Do some test stuff.
718 * Put the testSomething() function you want to test here.
730 testGradientButtons(scr
);
731 testProgressIndicator(scr
);
735 testOpenFilePanel(scr
);
744 * The main event loop.
747 WMScreenMainLoop(scr
);