home *** CD-ROM | disk | FTP | other *** search
- /*
- this file does all the intuition-related user I/O stuff;
- displaying the menu options and getting input
- */
-
- #include "header/sb.h"
-
- #define CHOICEWIDTH 280
- #define CHOICEHEIGHT 8
- #define SPACING 9
- #define TOPGADG 30
- #define TWGADG (MAXGADG + 1)
-
- #define PUTTEXT(text, x, y) { Move(rp, (long)x, (long)y); \
- Text(rp, text, (long)strlen(text)); }
-
- struct IntuitionBase *IntuitionBase = NULL;
- struct GfxBase *GfxBase = NULL;
- struct Window *OpenWindow(), *MainWindow = NULL;
- struct RastPort *rp;
- extern int level;
- APTR OpenLibrary();
- struct IntuiText ChoiceText[MAXGADG + 1];
- struct Gadget ChoiceGadg[MAXGADG + 1];
-
- struct IntuiText BackIText = {
- 3, 2, JAM2,
- 5, 2,
- NULL, NULL, NULL
- };
-
- struct IntuiText MoreIText = {
- 2, 3, JAM2,
- 5, 2,
- NULL,
- (UBYTE *)"(MORE)",
- NULL
- };
-
- struct IntuiText twIText = {
- 3, 2, JAM2,
- 5, 2,
- NULL,
- (UBYTE *)"Tiny Window",
- NULL
- };
-
- struct Gadget TWGadg = {
- NULL,
- 520, -12, 110, 12,
- GADGHCOMP | GRELBOTTOM,
- RELVERIFY,
- BOOLGADGET,
- NULL, NULL, &twIText,
- NULL, NULL,
- TWGADG, NULL
- };
-
- struct Gadget BackGadg = {
- NULL,
- 10, -12, 140, 12,
- GADGHCOMP | GRELBOTTOM,
- RELVERIFY,
- BOOLGADGET,
- NULL, NULL, &BackIText,
- NULL, NULL,
- 0, NULL /* gadget ID is zero */
- };
-
- struct Gadget MoreGadg = {
- NULL,
- 300, -12, 59, 12,
- GADGHCOMP | GRELBOTTOM,
- RELVERIFY,
- BOOLGADGET,
- NULL, NULL, &MoreIText,
- NULL, NULL,
- MOREGADG, NULL
- };
-
- struct NewWindow NWindow = {
- 0, 10, 640, 189, /* left, top, width, height */
- -1, -1, /* use screen colours */
- GADGETUP /* IDCMP flags */
- | CLOSEWINDOW,
- WINDOWDEPTH /* window flags */
- | WINDOWCLOSE
- | WINDOWDRAG
- | RMBTRAP
- | ACTIVATE
- | NOCAREREFRESH
- | SMART_REFRESH,
- &BackGadg, /* first gadget in list */
- NULL,
- (UBYTE *)"The Transactor Structure Browser V 1.3",
- NULL, NULL,
- 0, 0, 0, 0, /* sizing limits (non-resizable) */
- WBENCHSCREEN
- };
-
-
- static struct Gadget WakeUpGadget =
- {
- NULL, /* address of next gadget */
- 2, 10, 116, 10, /* left, top, width, height */
- GADGHNONE, /* flags - no highlighting */
- RELVERIFY, /* activation flags */
- BOOLGADGET, /* gadget type */
- NULL, /* no imagery */
- NULL, /* no alternate imagery */
- NULL, /* no text */
- 0, /* mutual exclude */
- NULL, /* SpecialInfo */
- 0, /* gadget ID */
- NULL, /* user data */
- };
-
- struct NewWindow TWindow = {
- 480, 60, 120, 20, /* left, top, width, height */
- -1, -1, /* detail pen, block pen */
- GADGETUP, /* IDCMP flags */
- WINDOWDRAG /* Window flags */
- | WINDOWDEPTH,
- &WakeUpGadget, /* application gadget list */
- NULL, /* special checkmark imagery */
- (UBYTE *)"SB", /* window title */
- NULL, /* custom screen pointer */
- NULL, /* super bitmap pointer */
- 0, 0, 0, 0, /* min/max width and height */
- WBENCHSCREEN /* screen type */
- };
-
-
- SetupGadg ()
- {
- int i;
-
- for (i = 0; i < MAXGADG; i++)
- {
- ChoiceText[i].BackPen = 0;
- ChoiceText[i].DrawMode = JAM2;
- ChoiceText[i].LeftEdge = 0;
- ChoiceText[i].TopEdge = 0;
- ChoiceText[i].ITextFont = NULL;
- ChoiceText[i].IText = NULL;
- ChoiceText[i].NextText = NULL;
- ChoiceGadg[i].LeftEdge = 20;
- ChoiceGadg[i].TopEdge = i * SPACING + TOPGADG;
- ChoiceGadg[i].Width = CHOICEWIDTH;
- ChoiceGadg[i].Height = CHOICEHEIGHT;
- ChoiceGadg[i].Flags = GADGHCOMP;
- ChoiceGadg[i].Activation = RELVERIFY;
- ChoiceGadg[i].GadgetType = BOOLGADGET;
- ChoiceGadg[i].GadgetText = &ChoiceText[i];
- ChoiceGadg[i].GadgetID = i + 1; /* gadget IDs start at 1 */
- }
- }
-
-
- GetChoice (num)
- int num;
- {
- struct IntuiMessage *GetMsg(), *message;
- ULONG msgclass; /* message class from IDCMP */
- APTR IAddr; /* pointer to gadget from IDCMP */
- int id; /* gadget ID of selected gadget */
- int tflag = FALSE;
-
- Redisplay(num); /* put up choices in window */
-
- FOREVER /* main event loop */
- {
- Wait (1L << MainWindow->UserPort->mp_SigBit);
-
- while (message = GetMsg(MainWindow->UserPort))
- {
- /* get what we need from the message port */
- msgclass = message->Class;
- IAddr = message->IAddress;
- ReplyMsg(message); /* reply to message right away */
-
- /* check for gadget selected */
- if (msgclass == GADGETUP)
- {
- id = ((struct Gadget *)IAddr)->GadgetID;
-
- if (id == TWGADG)
- tflag = TRUE;
- else
- return id;
- }
- /* finish up if the close gadget is clicked */
- else if (msgclass == CLOSEWINDOW)
- CloseOut(); /* clean up and exit */
- }
-
- if (tflag)
- {
- tflag = FALSE;
- CloseWindow(MainWindow);
- DoTinyWindow();
- if ((MainWindow = OpenWindow(&NWindow)) == NULL)
- CloseOut();
- rp = MainWindow->RPort; /* rastport for graphics routines */
- return TWGADG;
- }
- }
- }
-
-
- DoTinyWindow()
- {
- struct Window *w;
- struct IntuiMessage *GetMsg(), *message;
-
- MainWindow = NULL;
-
- if (PostMe("StructureBrowser"))
- return;
-
- if ((w = OpenWindow(&TWindow)) == NULL)
- CloseOut();
- Wait (1L << w->UserPort->mp_SigBit);
-
- while (message = GetMsg(w->UserPort))
- ReplyMsg(message);
-
- TWindow.LeftEdge = w->LeftEdge;
- TWindow.TopEdge = w->TopEdge;
-
- CloseWindow(w);
- }
-
-
- /* putHeader
-
- put title and pointer at top of screen -
- if ptr is NULL, put string only.
- */
-
- putHeader (string, ptr)
- char *string;
- APTR ptr;
- {
- char buf[80];
-
- SetAPen(rp, 0L);
- RectFill(rp, 1L, 10L, (long)MainWindow->Width-25, 27L);
- SetAPen(rp, 3L);
-
- if (ptr)
- {
- sprintf(buf, "%d: %s (address $%lx):", level, string, ptr);
- PUTTEXT(
- " Member Type Value (hex/decimal)",
- 20L, 10L + 2 * rp->TxHeight);
- }
- else
- sprintf(buf, "%d: %s:", level, string);
-
- PUTTEXT(buf, 20L, 10L + rp->TxHeight);
- }
-
-
- OpenStuff ()
- {
- if (!(IntuitionBase = (struct IntuitionBase *)
- OpenLibrary ("intuition.library", 0L) ) )
- CloseOut();
-
- if (!(GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 0L) ))
- CloseOut();
-
- twmInit();
-
- /* now attempt to open the main window */
- if (!(MainWindow = OpenWindow(&NWindow)) )
- CloseOut();
-
- rp = MainWindow->RPort; /* rastport for graphics routines */
- }
-
-
- CloseOut ()
- {
- twmCleanUp();
-
- if (MainWindow) CloseWindow(MainWindow);
- if (IntuitionBase) CloseLibrary(IntuitionBase);
- if (GfxBase) CloseLibrary(GfxBase);
-
- exit(0); /* exit program - we may be deeply nested */
- }
-
- /* Redisplay
-
- Clear window, remove old gadgets, prepare and add new ones
- */
-
- Redisplay (num)
- int num;
- {
- struct Gadget *gadg;
- BOOL MoreFlag = FALSE;
- int i, c;
-
- /* rectfill with background colour to clear */
- SetAPen(rp, 0L);
- RectFill(rp, 1L, (long)TOPGADG, (long)MainWindow->Width - 2,
- (long)MainWindow->Height - 2);
-
- if (num > MAXGADG)
- {
- num = MAXGADG;
- MoreFlag = TRUE; /* put up "more" gadget */
- }
- /* remove all choice gadgets */
- gadg = &BackGadg;
- while(gadg = gadg->NextGadget)
- RemoveGadget(MainWindow, gadg);
-
- /* render gadgets according to single-digit code at
- the start of the gadgets's intuitext
- */
- for (i = 0; i < num; i++)
- {
- ChoiceText[i].FrontPen = 1;
- if ((c = *ChoiceText[i].IText) == '-' || c == '(')
- {
- if (c == '-')
- {
- *ChoiceText[i].IText = ' ';
- ChoiceText[i].FrontPen = 2;
- }
- PrintIText(rp, &ChoiceText[i],
- (long)ChoiceGadg[i].LeftEdge,
- (long)ChoiceGadg[i].TopEdge);
- }
- else
- AddGadget(MainWindow, &ChoiceGadg[i], -1L);
- }
- if (MoreFlag)
- AddGadget(MainWindow, &MoreGadg, -1L);
-
- AddGadget(MainWindow, &TWGadg, -1L);
-
- /* display gadget imagery (the text) */
- RefreshGadgets(&BackGadg, MainWindow, NULL);
- }
-
-
- SetBackText (sflag)
- int sflag;
- {
- BackIText.IText = (UBYTE *)(sflag ?
- " Previous Page " : " Previous Level ");
- }
-