/*========================================================================= A piece of test code that tests out Intuitions new features and little "gotchas" It contains a hodge podge of code to test the effects of flags and other "unknown" strange things. gt.c is the name of this module KEY: ### - Temporary code to be later removed areas of last interest =========================================================================*/ /* The usual header files to be inserted later */ #include #include #include #include #include #include #include #include #include #include #include #include "gad.h" /*------------ External function declarations ------------*/ extern void *OpenLibrary(); extern struct Window *OpenWindow(); extern struct IntuiMessage *GetMsg(); extern char *gadnames[]; /*------------------ extern vars ------------------*/ extern int nextgad; extern int nextprop; extern int nexttext; extern int nx_strings; extern struct Gadget *gads[]; extern struct StringInfo *strings[]; /*------------------- global variables -------------------*/ struct GfxBase *GfxBase; struct IntuitionBase *IntuitionBase; struct RastPort *rp; struct Gadget *SelectedGadget; long mask; int holding = FALSE; /* Set "TRUE" when new gadget is created */ struct Window *w; BOOL updated, saved; /* Gadget status flags used in men.c */ /*------------ Test gadget ------------*/ struct Gadget testgad; struct PropInfo Prop; struct StringInfo String; /* new window structure */ struct NewWindow nw = { 0, 0, 640, 200, 0, 1, /* IDCMP Flags */ MOUSEMOVE | MENUPICK | MOUSEBUTTONS | CLOSEWINDOW | GADGETDOWN | GADGETUP, /* Flags */ WINDOWCLOSE | RMBTRAP | REPORTMOUSE, NULL, /* First gadget */ NULL, /* Checkmark */ (UBYTE *) "Gadget Editor Ver 0.2", /* Window title */ NULL, /* No custom streen */ NULL, /* Not a super bitmap window */ 0, 0, 640, 200, /* Not used, but set up anyway */ WBENCHSCREEN }; /*========================================================================= Main entry to the test routine from CLI ========================================================================*/ main() { /*---------------- local vars ---------------*/ struct IntuiMessage *mes; /* Message pointer */ ULONG class; /* Message class */ USHORT code; /* Message code */ SHORT mx, my; /* Mouse X and Y */ APTR Iadr, adr; /* IAddress from Intuimessage */ ULONG flgs; /* temp IDCMP flags */ /*----------- Open up graphics library and Intuition ------------*/ if ((GfxBase = (struct GfxBase *) OpenLibrary("graphics.library", NULL)) == NULL) { printf("no graphics library on disk\n"); CloseThings(); exit(100); } mask |= GRAPHICS; if ((IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library", NULL)) == NULL) { printf("No intuition library\n"); CloseThings(); exit(100); } mask |= INTUITION; /*----------- open window ----------*/ if ((w = OpenWindow(&nw)) == NULL) { printf("Cannot open window\n"); CloseThings(); } mask |= WINDOW; /* ------------- init stuff here -------------*/ rp = w->RPort; MakeMyMenus(); /* Init the Menus */ init_all_req(); /* Initialize all requesters */ /* --------------- main loop -----------------*/ for (;;) { if ((mes = GetMsg(w->UserPort)) == NULL) { Wait(1L << w->UserPort->mp_SigBit); continue; } class = mes->Class; code = mes->Code; mx = mes->MouseX; my = mes->MouseY; Iadr = mes->IAddress; ReplyMsg(mes); switch (class) { case CLOSEWINDOW: CloseThings(); exit(NULL); break; case GADGETUP: /* do nothing for now - except note that*/ /* the gadget was selected. */ SelectedGadget = (struct Gadget *)Iadr; break; case MENUPICK: if (MENUNUM(code) != MENUNULL) Do_menu((long)MENUNUM(code), (long)ITEMNUM(code)); break; case GADGETDOWN: /* do nothing for now - except note that*/ /* the gadget was selected. */ SelectedGadget = (struct Gadget *)Iadr; break; case MOUSEMOVE: proc_mouse(adr, mx, my); break; case MOUSEBUTTONS: proc_button(code, mx, my); break; } } } /*======================================================================== draw_box - Draws a box, given Left, Top, Width, Height, and a RastPort ==$$$======================================================================*/ draw_box(rport, left, top, width, height) struct RastPort *rport; SHORT left, top, width, height; { long flags; long lf = (long)left; long tp = (long)top; long wd = (long)width; long hg = (long)height; /* flags = (long)testgad.UserData; if ((flags & GAD_BORDER_TYPE) == GAD_BORDER_TYPE) { */ SetDrMd(rport, COMPLEMENT); SetAPen(rport, 1L); SetBPen(rport, 0L); Move(rport, lf, tp); Draw(rport, lf+wd, tp); Draw(rport, lf+wd, tp+hg); Draw(rport, lf, tp+hg); Draw(rport, lf, tp); } /*======================================================================== $$$ CloseThings - Function that closes everything properly if any failures occur before main loop entry, ========================================================================*/ CloseThings() { int i; if (mask & INTUITION) CloseLibrary(IntuitionBase); if (mask & GRAPHICS) CloseLibrary(GfxBase); if (mask & WINDOW) CloseWindow(w); if (mask & MENU) ClearMenuStrip(w); for (i=0; iGadgetType == PROPGADGET) freeprop(gads[i]); if (gads[i]->GadgetType == STRGADGET) freestrgad(gads[i]); if (gads[i]->GadgetType == BOOLGADGET) free_renders(gads[i]); FreeMem(gads[i], (long)sizeof(struct Gadget)); gads[i] = NULL; } } }