2 ** $Id: SliderBarDemo.c,v 1.1 1999/02/07 14:24:43 bernie Exp $
4 ** Copyright (C) 1999 Bernardo Innocenti (<bernardo.innocenti@usa.net>)
5 ** All rights reserved.
7 ** Use 4 chars wide TABs to read this file
13 ** This program shows the usage of the `boopsi' "sliderbargclass" gadget.
14 ** It can only be started from the shell (not from Workbench).
20 ** This project can be compiled with SAS/C 6.58 or better and
21 ** StormC 2.00.23 or better. You get the smaller and faster
22 ** executable with SAS/C. SAS/C will give you a couple of warnings
23 ** on the library bases which are defined static. This warning can't be
24 ** fixed without patching the system headers. Don't worry about it.
30 ** 1.0 (30.1.99) First release
36 ** - This code has never been tested on V37.
42 ** This software is freely distributable as long as the source code,
43 ** documentation and executables are kept together. Permission is granted
44 ** to release modified versions of this program as long as all existing
45 ** copyright notices are left intact.
48 #define INTUI_V36_NAMES_ONLY
50 #define CLIB_ALIB_PROTOS_H /* Avoid including this header file because of
51 * conflicting definitions in BoopsiStubs.h
54 #include <exec/types.h>
55 #include <exec/memory.h>
56 #include <exec/execbase.h>
60 #include <intuition/intuition.h>
61 #include <intuition/intuitionbase.h>
62 #include <intuition/screens.h>
63 #include <intuition/classes.h>
64 #include <intuition/gadgetclass.h>
65 #include <intuition/icclass.h>
67 #include <proto/exec.h>
68 #include <proto/intuition.h>
70 #include "CompilerSpecific.h"
71 #include "DebugMacros.h"
72 #include "BoopsiStubs.h"
74 #include "SliderBarGClass.h"
77 /* Local function prototypes */
78 LONG SAVEDS main (void);
79 static struct SBDHandle *OpenSBDWin (UBYTE *pubscreen, ULONG left, ULONG top,
80 ULONG width, ULONG height);
81 static void CloseSBDWin (struct SBDHandle *sbdhandle);
82 static struct Gadget *CreateGadgets (struct SBDHandle *sbdhandle);
83 static void DisposeGadgets (struct SBDHandle *sbdhandle);
84 static struct ClassLibrary *OpenClass (STRPTR name, ULONG version);
88 /* This structure describes an open SliderBarDemo window */
94 struct Gadget *Slider[4];
101 static UBYTE versiontag[] = "$VER: SlideBarDemo 1.0 (30.1.99) by Bernardo Innocenti";
105 static struct ExecBase *SysBase;
106 static struct IntuitionBase *IntuitionBase;
108 /* `boopsi' class library base */
109 static struct ClassLibrary *SliderBarBase;
113 LONG SAVEDS _main (void)
115 /* Main program entry point. When linking without startup code, this
116 * must be the first function in the first object module listed on the
117 * linker command line. We also need to initialize SysBase and open
118 * all needed libraries manually.
121 struct SBDHandle *sbdhandle;
122 LONG sigwait, sigrcvd;
123 LONG retval = RETURN_FAIL;
127 /* Initialize SysBase */
128 SysBase = *((struct ExecBase **)4UL);
130 if (IntuitionBase = (struct IntuitionBase *)OpenLibrary ("intuition.library", 39L))
132 if (SliderBarBase = OpenClass ("sliderbar.gadget", 0))
134 if (sbdhandle = OpenSBDWin (NULL, 0, 20, 320, 200))
136 /* Pre-calculate the signal mask for Wait() */
137 sigwait = (1 << sbdhandle->Win->UserPort->mp_SigBit) |
140 /* Now for the main loop. As you can see, it is really
141 * very compact. That's the magic of boopsi! :-)
145 /* Sleep until something interesting occurs */
146 sigrcvd = Wait (sigwait);
148 /* Now handle received signals */
151 if (sigrcvd & SIGBREAKF_CTRL_C)
155 if (sigrcvd & (1 << sbdhandle->Win->UserPort->mp_SigBit))
157 struct IntuiMessage *msg;
159 while (msg = (struct IntuiMessage *) GetMsg (sbdhandle->Win->UserPort))
163 case IDCMP_CLOSEWINDOW:
170 ReplyMsg ((struct Message *) msg);
173 } /* End while (!quit) */
177 CloseSBDWin (sbdhandle);
180 /* This cannot fail. Passing NULL is ok. */
181 CloseLibrary ((struct Library *)SliderBarBase);
183 CloseLibrary ((struct Library *)IntuitionBase);
191 static struct SBDHandle *OpenSBDWin (UBYTE *pubscreen,
192 ULONG left, ULONG top, ULONG width, ULONG height)
194 struct SBDHandle *sbdhandle;
195 struct Gadget *glist;
197 if (sbdhandle = AllocMem (sizeof (struct SBDHandle), MEMF_ANY | MEMF_CLEAR))
199 if (sbdhandle->Scr = LockPubScreen (pubscreen))
201 if (glist = CreateGadgets (sbdhandle))
203 if (sbdhandle->Win = OpenWindowTags (NULL,
206 WA_InnerWidth, width,
207 WA_InnerHeight, height,
208 WA_PubScreen, sbdhandle->Scr,
209 WA_PubScreenFallBack, TRUE,
211 WA_IDCMP, IDCMP_CLOSEWINDOW,
212 WA_Flags, WFLG_DRAGBAR | WFLG_DEPTHGADGET | WFLG_CLOSEGADGET |
213 WFLG_SIZEGADGET | WFLG_SIMPLE_REFRESH | WFLG_NOCAREREFRESH,
215 WA_Title, versiontag + 6,
222 UnlockPubScreen (NULL, sbdhandle->Scr);
225 DisposeGadgets (sbdhandle);
227 UnlockPubScreen (NULL, sbdhandle->Scr);
229 FreeMem (sbdhandle, sizeof (struct SBDHandle));
236 static void CloseSBDWin (struct SBDHandle *sbdhandle)
238 /* Close our window. No need to reply queued messages,
239 * Intuition is clever enough to care about this for us.
241 CloseWindow (sbdhandle->Win);
242 DisposeGadgets (sbdhandle);
243 FreeMem (sbdhandle, sizeof (struct SBDHandle));
246 #define SLIDER_THICKNESS 20
248 static struct Gadget *CreateGadgets (struct SBDHandle *sbdhandle)
250 struct Screen *scr = sbdhandle->Scr;
251 LONG left,right, top, bottom, width, height;
254 left = scr->WBorLeft + 10;
255 right = - scr->WBorRight - 25 - SLIDER_THICKNESS;
256 top = scr->WBorTop + scr->Font->ta_YSize + 10;
257 bottom = - scr->WBorBottom - 10 - SLIDER_THICKNESS;
258 width = right - left - 1;
259 height = bottom - top - 1;
261 sbdhandle->Slider[0] = NewObject (NULL, SLIDERBARGCLASS,
264 GA_Width, SLIDER_THICKNESS,
265 GA_RelHeight, height,
269 LAYOUTA_Orientation, LORIENT_VERT,
272 sbdhandle->Slider[1] = NewObject (NULL, SLIDERBARGCLASS,
273 GA_Previous, sbdhandle->Slider[0],
275 GA_RelBottom, bottom,
276 GA_RelWidth, width + SLIDER_THICKNESS,
277 GA_Height, SLIDER_THICKNESS,
281 LAYOUTA_Orientation, LORIENT_HORIZ,
282 ICA_TARGET, sbdhandle->Slider[0],
285 sbdhandle->Slider[2] = NewObject (NULL, SLIDERBARGCLASS,
286 GA_Previous, sbdhandle->Slider[1],
289 GA_Width, SLIDER_THICKNESS,
290 GA_RelHeight, height,
294 LAYOUTA_Orientation, LORIENT_VERT,
295 ICA_TARGET, sbdhandle->Slider[1],
298 sbdhandle->Slider[3] = NewObject (NULL, SLIDERBARGCLASS,
299 GA_Previous, sbdhandle->Slider[2],
301 GA_Left, left + SLIDER_THICKNESS,
302 GA_RelWidth, width - SLIDER_THICKNESS,
303 GA_Height, SLIDER_THICKNESS,
307 LAYOUTA_Orientation, LORIENT_HORIZ,
308 ICA_TARGET, sbdhandle->Slider[2],
312 if (sbdhandle->Slider[0] &&
313 sbdhandle->Slider[1] &&
314 sbdhandle->Slider[2] &&
315 sbdhandle->Slider[3])
317 return sbdhandle->Slider[0];
321 DisposeGadgets (sbdhandle);
328 static void DisposeGadgets (struct SBDHandle *sbdhandle)
332 for (i = 0; i < 4; i++)
333 DisposeObject (sbdhandle->Slider[i]);
338 static struct ClassLibrary *OpenClass (STRPTR name, ULONG version)
340 /* Open named class. Look both in current and gadgets/ directory
343 static struct EasyStruct OpenClassES =
345 sizeof (struct EasyStruct),
348 "Couldn't open %s version %ld or greater",
351 static const char prefix[] = "gadgets/";
353 struct ClassLibrary *classbase;
358 if (!(classbase = (struct ClassLibrary *)OpenLibrary (name, version)))
360 /* We can't use AddPart() here because we didn't open dos.library */
362 /* Copy the prefix in the buffer */
363 for (i = 0; buf[i] = prefix[i]; i++);
365 /* Append the name */
366 while (buf[i++] = *name++);
369 classbase = (struct ClassLibrary *)OpenLibrary (buf, version);
373 /* Report an error */
374 EasyRequest (NULL, &OpenClassES, NULL, buf, version);