Added some (default) icons for files/dirs used by boot floppies.
[cake.git] / test / scrollerwin.c
blobe468fdbee33c5cadf3ae651fc0a151964d328367
1 #include <dos/dos.h>
2 #include <intuition/intuition.h>
3 #include <intuition/imageclass.h>
4 #include <intuition/gadgetclass.h>
5 #include <graphics/gfx.h>
6 #include <utility/hooks.h>
8 #include <proto/exec.h>
9 #include <proto/intuition.h>
10 #include <proto/graphics.h>
11 #include <proto/alib.h>
13 #include <stdio.h>
14 #include <stdlib.h>
16 enum
18 GAD_UPARROW,
19 GAD_DOWNARROW,
20 GAD_LEFTARROW,
21 GAD_RIGHTARROW,
22 GAD_VERTSCROLL,
23 GAD_HORIZSCROLL,
24 NUM_GADGETS
27 enum
29 IMG_UPARROW,
30 IMG_DOWNARROW,
31 IMG_LEFTARROW,
32 IMG_RIGHTARROW,
33 IMG_SIZE,
34 NUM_IMAGES
37 struct IntuitionBase *IntuitionBase;
38 struct GfxBase *GfxBase;
40 static struct Screen *scr;
41 static struct Window *win;
42 static struct DrawInfo *dri;
44 static struct Gadget *gad[NUM_GADGETS], *firstgadget;
45 static struct Image *img[NUM_GADGETS];
47 static void Cleanup(char *msg)
49 WORD rc, i;
51 if (msg)
53 printf("scrollerwin: %s\n",msg);
54 rc = RETURN_WARN;
55 } else {
56 rc = RETURN_OK;
59 if (win)
61 for(i = 0; i < NUM_GADGETS;i++)
63 if (gad[i]) RemoveGadget(win,gad[i]);
66 CloseWindow(win);
69 for(i = 0; i < NUM_GADGETS;i++)
71 if (gad[i]) DisposeObject(gad[i]);
73 for(i = 0; i < NUM_IMAGES;i++)
75 if (img[i]) DisposeObject(img[i]);
78 if (dri) FreeScreenDrawInfo(scr,dri);
79 if (scr) UnlockPubScreen(0,scr);
81 if (GfxBase) CloseLibrary((struct Library *)GfxBase);
82 if (IntuitionBase) CloseLibrary((struct Library *)IntuitionBase);
84 exit(rc);
87 static void OpenLibs(void)
89 if (!(IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",39)))
91 Cleanup("Can't open intuition.library V39!");
94 if (!(GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",39)))
96 Cleanup("Can't open graphics.library V39!");
100 static void GetVisual(void)
102 if (!(scr = LockPubScreen(0)))
104 Cleanup("Can't lock pub screen!");
107 if (!(dri = GetScreenDrawInfo(scr)))
109 Cleanup("Can't get drawinfo!");
113 static void MakeGadgets(void)
115 static WORD img2which[] =
117 UPIMAGE,
118 DOWNIMAGE,
119 LEFTIMAGE,
120 RIGHTIMAGE,
121 SIZEIMAGE
124 IPTR imagew[NUM_IMAGES],imageh[NUM_IMAGES];
125 WORD v_offset,h_offset, btop, i;
127 for(i = 0;i < NUM_IMAGES;i++)
129 img[i] = NewObject(0,SYSICLASS,SYSIA_DrawInfo,(IPTR)dri,
130 SYSIA_Which,img2which[i],
131 TAG_DONE);
133 if (!img[i]) Cleanup("Can't create SYSICLASS image!");
135 GetAttr(IA_Width,(Object *)img[i],&imagew[i]);
136 GetAttr(IA_Height,(Object *)img[i],&imageh[i]);
139 btop = scr->WBorTop + dri->dri_Font->tf_YSize + 1;
141 v_offset = imagew[IMG_DOWNARROW] / 4;
142 h_offset = imageh[IMG_LEFTARROW] / 4;
144 firstgadget = gad[GAD_UPARROW] = NewObject(0,BUTTONGCLASS,
145 GA_Image,(IPTR)img[IMG_UPARROW],
146 GA_RelRight,-imagew[IMG_UPARROW] + 1,
147 GA_RelBottom,-imageh[IMG_DOWNARROW] - imageh[IMG_UPARROW] - imageh[IMG_SIZE] + 1,
148 GA_ID,GAD_UPARROW,
149 GA_RightBorder,TRUE,
150 GA_Immediate,TRUE,
151 TAG_DONE);
153 gad[GAD_DOWNARROW] = NewObject(0,BUTTONGCLASS,
154 GA_Image,(IPTR)img[IMG_DOWNARROW],
155 GA_RelRight,-imagew[IMG_UPARROW] + 1,
156 GA_RelBottom,-imageh[IMG_UPARROW] - imageh[IMG_SIZE] + 1,
157 GA_ID,GAD_DOWNARROW,
158 GA_RightBorder,TRUE,
159 GA_Previous,(IPTR)gad[GAD_UPARROW],
160 GA_Immediate,TRUE,
161 TAG_DONE);
163 gad[GAD_VERTSCROLL] = NewObject(0,PROPGCLASS,
164 GA_Top,btop + 1,
165 GA_RelRight,-imagew[IMG_DOWNARROW] + v_offset + 1,
166 GA_Width,imagew[IMG_DOWNARROW] - v_offset * 2,
167 GA_RelHeight,-imageh[IMG_DOWNARROW] - imageh[IMG_UPARROW] - imageh[IMG_SIZE] - btop -2,
168 GA_ID,GAD_VERTSCROLL,
169 GA_Previous,(IPTR)gad[GAD_DOWNARROW],
170 GA_RightBorder,TRUE,
171 GA_RelVerify,TRUE,
172 GA_Immediate,TRUE,
173 PGA_NewLook,TRUE,
174 PGA_Borderless,TRUE,
175 PGA_Total,100,
176 PGA_Visible,20,
177 PGA_Freedom,FREEVERT,
178 TAG_DONE);
180 gad[GAD_RIGHTARROW] = NewObject(0,BUTTONGCLASS,
181 GA_Image,(IPTR)img[IMG_RIGHTARROW],
182 GA_RelRight,-imagew[IMG_SIZE] - imagew[IMG_RIGHTARROW] + 1,
183 GA_RelBottom,-imageh[IMG_RIGHTARROW] + 1,
184 GA_ID,GAD_RIGHTARROW,
185 GA_BottomBorder,TRUE,
186 GA_Previous,(IPTR)gad[GAD_VERTSCROLL],
187 GA_Immediate,TRUE,
188 TAG_DONE);
190 gad[GAD_LEFTARROW] = NewObject(0,BUTTONGCLASS,
191 GA_Image,(IPTR)img[IMG_LEFTARROW],
192 GA_RelRight,-imagew[IMG_SIZE] - imagew[IMG_RIGHTARROW] - imagew[IMG_LEFTARROW] + 1,
193 GA_RelBottom,-imageh[IMG_RIGHTARROW] + 1,
194 GA_ID,GAD_LEFTARROW,
195 GA_BottomBorder,TRUE,
196 GA_Previous,(IPTR)gad[GAD_RIGHTARROW],
197 GA_Immediate,TRUE,
198 TAG_DONE);
200 gad[GAD_HORIZSCROLL] = NewObject(0,PROPGCLASS,
201 GA_Left,scr->WBorLeft,
202 GA_RelBottom,-imageh[IMG_LEFTARROW] + h_offset + 1,
203 GA_RelWidth,-imagew[IMG_LEFTARROW] - imagew[IMG_RIGHTARROW] - imagew[IMG_SIZE] - scr->WBorRight - 2,
204 GA_Height,imageh[IMG_LEFTARROW] - (h_offset * 2),
205 GA_ID,GAD_HORIZSCROLL,
206 GA_Previous,(IPTR)gad[GAD_LEFTARROW],
207 GA_BottomBorder,TRUE,
208 GA_RelVerify,TRUE,
209 GA_Immediate,TRUE,
210 PGA_NewLook,TRUE,
211 PGA_Borderless,TRUE,
212 PGA_Total,100,
213 PGA_Visible,20,
214 PGA_Freedom,FREEHORIZ,
215 TAG_DONE);
217 for(i = 0;i < NUM_GADGETS;i++)
219 if (!gad[i]) Cleanup("Can't create gadget!");
223 static void MakeWin(void)
225 if (!(win = OpenWindowTags(0,WA_PubScreen,(IPTR)scr,
226 WA_Left,10,
227 WA_Top,10,
228 WA_Width,300,
229 WA_Height,150,
230 WA_Title,(IPTR)"Scroller Window",
231 WA_SimpleRefresh,TRUE,
232 WA_CloseGadget,TRUE,
233 WA_DepthGadget,TRUE,
234 WA_DragBar,TRUE,
235 WA_SizeGadget,TRUE,
236 WA_SizeBBottom,TRUE,
237 WA_SizeBRight,TRUE,
238 WA_Gadgets,(IPTR)firstgadget,
239 WA_MinWidth,50,
240 WA_MinHeight,50,
241 WA_MaxWidth,scr->Width,
242 WA_MaxHeight,scr->Height,
243 WA_IDCMP,IDCMP_CLOSEWINDOW | IDCMP_REFRESHWINDOW,
244 TAG_DONE)))
246 Cleanup("Can't open window!");
249 ScreenToFront(win->WScreen);
253 static void HandleAll(void)
255 struct IntuiMessage *msg;
257 BOOL quitme = FALSE;
259 while(!quitme)
261 WaitPort(win->UserPort);
262 while ((msg = (struct IntuiMessage *)GetMsg(win->UserPort)))
264 switch(msg->Class)
266 case IDCMP_CLOSEWINDOW:
267 quitme = TRUE;
268 break;
270 case IDCMP_REFRESHWINDOW:
271 BeginRefresh(win);
272 EndRefresh(win,TRUE);
273 break;
275 ReplyMsg((struct Message *)msg);
280 int main(void)
282 OpenLibs();
283 GetVisual();
284 MakeGadgets();
285 MakeWin();
286 HandleAll();
287 Cleanup(0);
288 return 0;