2 (C) 1997-98 AROS - The Amiga Research OS
5 Desc: Demo for gadtools.library
9 #include <aros/config.h>
11 #if !(AROS_FLAVOUR & AROS_FLAVOUR_NATIVE)
16 #include <proto/exec.h>
17 #include <exec/libraries.h>
18 #include <exec/types.h>
19 #include <proto/dos.h>
21 #include <proto/intuition.h>
22 #include <intuition/classusr.h>
23 #include <intuition/gadgetclass.h>
24 #include <intuition/intuition.h>
25 #include <intuition/intuitionbase.h>
26 #include <intuition/screens.h>
27 #include <utility/tagitem.h>
28 #include <proto/gadtools.h>
29 #include <libraries/gadtools.h>
31 #include <proto/alib.h>
37 #include <aros/debug.h>
38 struct IntuitionBase
*IntuitionBase
;
39 struct Library
*GadToolsBase
;
44 struct Gadget
*glist
= NULL
;
46 struct Gadget
*button
, *strgad
, *integergadget
;
58 #define ID_LISTVIEW 10
60 struct NewGadget buttongad
=
64 ID_BUTTON
, PLACETEXT_IN
, NULL
, NULL
67 struct NewGadget checkbox
=
71 ID_CHECKBOX
, PLACETEXT_RIGHT
, NULL
, NULL
74 struct NewGadget cyclegad
=
78 ID_CYCLE
, PLACETEXT_ABOVE
, NULL
, NULL
81 struct NewGadget mxgad
=
83 210, 60, MX_WIDTH
, 20,
84 "Mutual Exclude (3)", NULL
,
85 ID_MX
, PLACETEXT_RIGHT
, NULL
, NULL
88 struct NewGadget palettegad
=
92 ID_PALETTE
, PLACETEXT_ABOVE
, NULL
, NULL
95 struct NewGadget textgad
=
102 struct NewGadget numbergad
=
109 struct NewGadget slidergad
=
113 ID_SLIDER
, PLACETEXT_ABOVE
, NULL
, NULL
116 struct NewGadget scrollergad
=
120 ID_SCROLLER
, 0, NULL
, NULL
123 struct NewGadget stringgad
=
127 ID_STRING
, PLACETEXT_ABOVE
, NULL
, NULL
130 struct NewGadget integergad
=
134 ID_INTEGER
, PLACETEXT_ABOVE
, NULL
, NULL
137 struct NewGadget listviewgad
=
140 "Listview (10)", NULL
,
141 ID_LISTVIEW
, PLACETEXT_ABOVE
, NULL
, NULL
144 #define NUMLVNODES 20
145 struct Node lv_nodes
[NUMLVNODES
];
147 STRPTR lv_texts
[] = {"This", "is", "a", "demo", "of", "the", "GadTools", "listview.",
148 "Try", "scrolling", "and", "selecting", "entries",
149 "One", "Two", "Three", "Four", "Five", "Six", "Seven"};
160 STRPTR cyclelabels
[] =
168 VOID
initlvnodes(struct List
*list
, struct Node
*nodes
, STRPTR
*texts
, WORD numnodes
)
173 for (i
= 0; i
< numnodes
; i
++)
175 AddTail(list
, &(nodes
[i
]));
176 nodes
[i
].ln_Name
= texts
[i
];
184 IntuitionBase
= (struct IntuitionBase
*) OpenLibrary("intuition.library", 37);
185 GadToolsBase
= OpenLibrary("gadtools.library", 0);
186 if (!IntuitionBase
) {
187 printf("GTDemo: Error opening intuition.library\n");
191 printf("GTDemo: Error opening gadtools.library\n");
199 D(bug("Closelibs: closing gadtools\n"));
200 CloseLibrary(GadToolsBase
);
201 D(bug("Closelibs: closing intuition\n"));
202 CloseLibrary((struct Library
*) IntuitionBase
);
203 D(bug("Closelibs: libs closed\n"));
207 struct Gadget
*gt_init()
209 struct Gadget
*gad
= NULL
;
210 struct DrawInfo
*dri
;
212 scr
= LockPubScreen(NULL
);
213 vi
= GetVisualInfoA(scr
, NULL
);
215 gad
= CreateContext(&glist
);
217 if ((dri
= GetScreenDrawInfo(scr
)))
219 topoffset
= dri
->dri_Font
->tf_YSize
+ scr
->WBorTop
- 10 + 5;
221 buttongad
.ng_TopEdge
+= topoffset
;
222 checkbox
.ng_TopEdge
+= topoffset
;
223 cyclegad
.ng_TopEdge
+= topoffset
;
224 mxgad
.ng_TopEdge
+= topoffset
;
225 palettegad
.ng_TopEdge
+= topoffset
;
226 textgad
.ng_TopEdge
+= topoffset
;
227 numbergad
.ng_TopEdge
+= topoffset
;
228 slidergad
.ng_TopEdge
+= topoffset
;
229 scrollergad
.ng_TopEdge
+= topoffset
;
230 stringgad
.ng_TopEdge
+= topoffset
;
231 integergad
.ng_TopEdge
+= topoffset
;
232 listviewgad
.ng_TopEdge
+= topoffset
;
234 FreeScreenDrawInfo(scr
,dri
);
242 D(bug("gtend: Freeing gadgets\n"));
244 D(bug("gtend: Freeing visualnfo\n"));
246 D(bug("gtend: Unlocking screen\n"));
247 UnlockPubScreen(NULL
, scr
);
253 win
= OpenWindowTags(NULL
,
254 WA_PubScreen
, (IPTR
)scr
,
258 WA_Height
, 300 + topoffset
,
259 WA_Title
, (IPTR
)"GTDemo",
273 // WA_SimpleRefresh, TRUE,
274 WA_Gadgets
, (IPTR
)glist
,
276 WA_CloseGadget
, TRUE
,
277 WA_DepthGadget
, TRUE
,
280 printf("GTDemo: Error opening window\n");
287 struct Gadget
*makegadgets(struct Gadget
*gad
)
289 buttongad
.ng_VisualInfo
= vi
;
290 checkbox
.ng_VisualInfo
= vi
;
291 cyclegad
.ng_VisualInfo
= vi
;
292 mxgad
.ng_VisualInfo
= vi
;
293 palettegad
.ng_VisualInfo
= vi
;
294 textgad
.ng_VisualInfo
= vi
;
295 numbergad
.ng_VisualInfo
= vi
;
296 slidergad
.ng_VisualInfo
= vi
;
297 scrollergad
.ng_VisualInfo
= vi
;
298 stringgad
.ng_VisualInfo
= vi
;
299 integergad
.ng_VisualInfo
= vi
;
300 listviewgad
.ng_VisualInfo
= vi
;
302 gad
= CreateGadget(BUTTON_KIND
, gad
, &buttongad
,
305 D(bug("Created button gadget: %p\n", gad
));
307 gad
= CreateGadget(CHECKBOX_KIND
, gad
, &checkbox
,
311 D(bug("Created checkbox gadget: %p\n", gad
));
312 gad
= CreateGadget(CYCLE_KIND
, gad
, &cyclegad
,
313 GTCY_Labels
, (IPTR
)&cyclelabels
,
315 D(bug("Created cycle gadget: %p\n", gad
));
316 gad
= CreateGadget(MX_KIND
, gad
, &mxgad
,
317 GTMX_Labels
, (IPTR
)&mxlabels
,
319 GTMX_TitlePlace
, PLACETEXT_ABOVE
,
322 D(bug("Created mx gadget: %p\n", gad
));
323 gad
= CreateGadget(PALETTE_KIND
, gad
, &palettegad
,
325 GTPA_IndicatorHeight
, 30,
329 D(bug("Created palette gadget: %p\n", gad
));
330 gad
= CreateGadget(TEXT_KIND
, gad
, &textgad
,
331 GTTX_Text
, (IPTR
)"Text display",
334 GTTX_Justification
, GTJ_CENTER
,
337 D(bug("Created text gadget: %p\n", gad
));
338 gad
= CreateGadget(NUMBER_KIND
, gad
, &numbergad
,
341 GTNM_Justification
, GTJ_CENTER
,
344 D(bug("Created number gadget: %p\n", gad
));
345 gad
= CreateGadget(SLIDER_KIND
, gad
, &slidergad
,
350 GTSL_LevelFormat
, (IPTR
)"%2ld",
351 GTSL_LevelPlace
, PLACETEXT_RIGHT
,
352 GTSL_Justification
, GTJ_RIGHT
,
353 PGA_Freedom
, LORIENT_HORIZ
,
357 D(bug("Created slider gadget: %p\n", gad
));
358 gad
= CreateGadget(SCROLLER_KIND
, gad
, &scrollergad
,
364 PGA_Freedom
, LORIENT_VERT
,
367 D(bug("Created scroller gadget: %p\n", gad
));
368 gad
= strgad
= CreateGadget(STRING_KIND
, gad
, &stringgad
,
369 GTST_String
, (IPTR
)"Blahblahblah",
375 D(bug("Created string gadget: %p\n", gad
));
377 gad
= integergadget
= CreateGadget(INTEGER_KIND
, gad
, &integergad
,
380 STRINGA_Justification
, GACT_STRINGCENTER
,
384 D(bug("Created integer gadget: %p\n", gad
));
387 initlvnodes(&lv_list
, lv_nodes
, lv_texts
, NUMLVNODES
);
388 D(bug("Inited lv nodes\n"));
389 gad
= CreateGadget(LISTVIEW_KIND
, gad
, &listviewgad
,
390 GTLV_Labels
, (IPTR
)&lv_list
,
391 GTLV_ReadOnly
, FALSE
,
394 D(bug("Created listview gadget: %p\n", gad
));
398 printf("GTDemo: Error creating gadgets\n");
403 void draw_bevels(struct Window
*win
, APTR vi
)
405 DrawBevelBox(win
->RPort
, 10, 10 + topoffset
, 80, 80,
406 GT_VisualInfo
, (IPTR
) vi
, TAG_DONE
);
407 DrawBevelBox(win
->RPort
, 110, 10 + topoffset
, 80, 80,
409 GT_VisualInfo
, (IPTR
) vi
, TAG_DONE
);
410 DrawBevelBox(win
->RPort
, 10, 110 + topoffset
, 80, 80,
411 GTBB_FrameType
, BBFT_RIDGE
,
412 GT_VisualInfo
, (IPTR
) vi
, TAG_DONE
);
413 DrawBevelBox(win
->RPort
, 110, 110 + topoffset
, 80, 80,
414 GTBB_FrameType
, BBFT_RIDGE
, GTBB_Recessed
, TRUE
,
415 GT_VisualInfo
, (IPTR
) vi
, TAG_DONE
);
416 DrawBevelBox(win
->RPort
, 10, 210 + topoffset
, 80, 80,
417 GTBB_FrameType
, BBFT_ICONDROPBOX
,
418 GT_VisualInfo
, (IPTR
) vi
, TAG_DONE
);
419 DrawBevelBox(win
->RPort
, 110, 210 + topoffset
, 80, 80,
420 GTBB_FrameType
, BBFT_ICONDROPBOX
, GTBB_Recessed
, TRUE
,
421 GT_VisualInfo
, (IPTR
) vi
, TAG_DONE
);
427 struct IntuiMessage
*msg
;
429 GT_SetGadgetAttrs(strgad
,win
,NULL
,GTST_String
, (IPTR
)"Hello",
432 GT_SetGadgetAttrs(integergadget
,win
,NULL
,GTIN_Number
,1000,TAG_DONE
);
434 while (ready
== FALSE
) {
435 WaitPort(win
->UserPort
);
436 msg
= GT_GetIMsg(win
->UserPort
);
438 switch (msg
->Class
) {
439 case IDCMP_REFRESHWINDOW
:
440 GT_BeginRefresh(win
);
441 draw_bevels(win
, vi
);
442 GT_EndRefresh(win
, TRUE
);
443 D(bug("Got IDCMP_REFRESHWINDOW msg\n"));
445 case IDCMP_VANILLAKEY
:
446 if (msg
->Code
!= 0x1B) /* if escape, quit */
448 case IDCMP_CLOSEWINDOW
:
451 case IDCMP_GADGETDOWN
:
452 printf("Gadget %d pressed",
453 ((struct Gadget
*) msg
->IAddress
)->GadgetID
);
454 switch (((struct Gadget
*) msg
->IAddress
)->GadgetID
) {
456 printf(" (active: %d)", msg
->Code
);
461 case IDCMP_MOUSEMOVE
:
464 switch (((struct Gadget
*) msg
->IAddress
)->GadgetID
) {
466 printf("Slider moved to value %d\n", msg
->Code
);
470 printf("Scroller moved to value %d\n", msg
->Code
);
479 printf("Gadget %d released",
480 ((struct Gadget
*) msg
->IAddress
)->GadgetID
);
481 switch (((struct Gadget
*) msg
->IAddress
)->GadgetID
) {
487 printf(" (color: %d)", msg
->Code
);
491 printf(" (lv item: %d)", msg
->Code
);
495 printf(" (cycle item: %d)", msg
->Code
);
503 printf(" (checked)");
505 printf(" (not checked)");
506 GT_SetGadgetAttrs(button
, win
, NULL
,
507 GA_Disabled
, (IPTR
)checked
, TAG_DONE
);
522 int error
= RETURN_OK
;
526 #if SDEBUG /* Debugging hack */
529 if ((idtask
= FindTask("input.device")))
530 idtask
->tc_UserData
= NULL
;
535 if (openlibs() != FALSE
) {
539 gad
= makegadgets(gad
);
541 if (openwin() != FALSE
) {
542 draw_bevels(win
, vi
);
550 D(bug("Doing gt_end()\n"));
555 D(bug("closing libs\n"));