crunch@well.UUCP (John Draper) (12/07/86)
#! /bin/sh # This is a shell archive, meaning: # 1. Remove everything above the #! /bin/sh line. # 2. Save the resulting text in a file. # 3. Execute the file with /bin/sh (not csh) to create: # itexted.c # kp.c # men.c # menstructs.c # misc.c # This archive created: Sat Dec 6 23:47:49 1986 export PATH; PATH=/bin:/usr/bin:$PATH if test -f 'itexted.c' then echo shar: "will not over-write existing file 'itexted.c'" else cat << \SHAR_EOF > 'itexted.c' /****************************** ITextEd.c ************************************ * * ITextEd() - IntuiText Editor Requester for the Gadget editor * * By Ray R. Larson * * Copyright (C) 1986. All rights reserved. * * This program is freely distributable as long as this copyright notice * is retained. It intended for personal, non-commercial use. * ***************************************************************************/ #include <exec/types.h> #include <graphics/gfxbase.h> #include <libraries/dos.h> #include <libraries/dosextens.h> #include <intuition/intuition.h> #include <intuition/intuitionbase.h> #include <ctype.h> #include <stdio.h> #include <workbench/workbench.h> /* ========================================================================*/ /* Intuitext requester gadget ids */ #define CLASSBITS 8 #define UPDOWNCLASS 1 #define CHOICECLASS 2 #define CHANGECLASS 3 #define BUTTONCLASS 4 #define GADGETNUM 255 #define LOAD 0 #define CANCEL 1 #define ADDTXT 2 #define UP 0 #define DOWN 1 #define POT 2 #define ITXT0 0 #define ITXT1 1 #define ITXT2 2 #define ITXT3 3 #define ITXT4 4 #define ITXT5 5 #define ITXT6 6 #define ITXT7 7 #define PLAIN 0 #define UNDERLIN 1 #define BOLD 2 #define ITALIC 4 #define BACKGPEN 5 #define FGPEN 6 #define MODJAM1 7 #define MODJAM2 8 #define MODINV 9 #define STRGAD 10 #define LOADGADGET BUTTONCLASS << CLASSBITS | LOAD #define CANCELGADGET BUTTONCLASS << CLASSBITS | CANCEL #define ADDTXTGADGET BUTTONCLASS << CLASSBITS | ADDTXT #define UPGADGET UPDOWNCLASS << CLASSBITS | UP #define DOWNGADGET UPDOWNCLASS << CLASSBITS | DOWN #define POTGADGET UPDOWNCLASS << CLASSBITS | POT #define ITXT0GADGET CHOICECLASS << CLASSBITS | ITXT0 #define ITXT1GADGET CHOICECLASS << CLASSBITS | ITXT1 #define ITXT2GADGET CHOICECLASS << CLASSBITS | ITXT2 #define ITXT3GADGET CHOICECLASS << CLASSBITS | ITXT3 #define ITXT4GADGET CHOICECLASS << CLASSBITS | ITXT4 #define ITXT5GADGET CHOICECLASS << CLASSBITS | ITXT5 #define ITXT6GADGET CHOICECLASS << CLASSBITS | ITXT6 #define ITXT7GADGET CHOICECLASS << CLASSBITS | ITXT7 #define PLAINGAD CHANGECLASS << CLASSBITS | PLAIN #define UNDERLGAD CHANGECLASS << CLASSBITS | UNDERLIN #define BOLDGAD CHANGECLASS << CLASSBITS | BOLD #define ITALICGAD CHANGECLASS << CLASSBITS | ITALIC #define BGPENGAD CHANGECLASS << CLASSBITS | BACKGPEN #define FGPENGAD CHANGECLASS << CLASSBITS | FGPEN #define JAM1GAD CHANGECLASS << CLASSBITS | MODJAM1 #define JAM2GAD CHANGECLASS << CLASSBITS | MODJAM2 #define INVGAD CHANGECLASS << CLASSBITS | MODINV #define MODITGAD CHANGECLASS << CLASSBITS | STRGAD /**************************************************************************** * Global Structures ***************************************************************************/ /* the newwindow structure used in GT */ extern struct NewWindow nw; extern struct Window *w; /* external definitions for IntuiText from men.c */ extern struct IntuiText *Texts[]; extern int nexttext; /* the list of gadgets */ extern struct Gadget *gads[]; extern int nextgad; /* global memory allocation base */ extern struct Remember *rememberBase; /**************************************************************************** * External function definitions ***************************************************************************/ extern APTR AllocRemember(); extern USHORT RemoveGadget(); extern SHORT AddGadget(); struct IntuiText *WaitChoiceReq(); struct IntuiText *WaitITReq(); extern struct IntuiMessage *GetMsg(); extern BOOL autoreq(); /* in misc.c */ /**************************************************************************** * Requester structures and local/global buffers and counters ***************************************************************************/ struct Requester ITxtRequester; struct Requester ChoiceRequester; USHORT ITxtCount; /* Number of IntuiTexts for the gad */ struct IntuiText *ITMap[50]; /* Pointers to the Gad's Intuitexts */ USHORT FirstITxt; /* Index into ITMap */ #define STRINGBUFFSIZ 1000 UBYTE ITxtStringBuff[STRINGBUFFSIZ];/* storage area for text strings */ USHORT StringBuffPos = 0; /* Index into String Buffer */ /*************************************************************************** * The ITxt list selection Gadgets from the choice requester **************************************************************************/ extern struct IntuiText ITxtList[]; extern struct Gadget ITxtListGadget[]; /************************************************************************** * The Scroll Selection list up down Potentiometer **************************************************************************/ extern struct PropInfo KnobInfo; extern struct Gadget PotGadget; extern struct Gadget DownGadget; /*************************************************** * Other Requester structures * ***************************************************/ extern struct IntuiText HeadingText; extern struct Border Requester3Border; /**************************************************************************** * Structures for the IntuiText Add and Modify Requester ***************************************************************************/ extern struct Border ITxtReqBord; extern struct IntuiText ModTxtText; extern struct IntuiText ITDispText; extern struct Gadget DummyGad; extern struct Gadget ModTxtGad; extern UBYTE ModBuff[]; /* string buffer used to enter/modify itext */ /* This array's subscripts are the ORed bit values of the text types */ extern struct TextAttr *TxtFonts[]; /**************************************************************************** * The Code part of the ITextEd module. ***************************************************************************/ ITextEd(Gad,ReqWindow) struct Gadget *Gad; struct Window *ReqWindow; { UBYTE *StrPtr; LONG iflags; struct IntuiText *modtext, *ITxtPtr, *nextptr; USHORT savegadpos, rmgadpos; SHORT i; BOOL cancelchosen = FALSE; modtext = NULL; if (Gad == NULL) { /* use auto requestor to tell user to click on gad to modify */ autoreq("First click on Gadget to add or modify IntuiTexts", " Right "," OK "); return; } /* remove all the gadgets from the window */ for (i=0; i < nextgad; i++) RemoveGadget(ReqWindow,gads[i]); /* fix the IDCMP flags to report requester set and clear */ iflags = nw.IDCMPFlags; iflags |= REQCLEAR; ModifyIDCMP(ReqWindow,iflags); if (Gad->GadgetText != NULL) { /* initialize the text choice requester */ InitCHReq(); /* Put the intuitext linked list into a work array */ MapTexts(Gad); /* move the texts into the requester */ AttachList(0); /* Put up the requester */ Request(&ChoiceRequester,ReqWindow); /* Add the IntuiTexts associated with the gadget to the requester */ /* and let the user select one. */ modtext = WaitChoiceReq(&cancelchosen); ClearListGads(); } if (cancelchosen != TRUE) { if (modtext != NULL) ClearITexts(modtext,(LONG)Gad->LeftEdge,(LONG)Gad->TopEdge); /* initialize the text add and modify requester */ InitTxtReq(); /* let the user add or modify text */ ITxtPtr = WaitITReq(modtext); if (ITxtPtr != NULL) { if (modtext != ITxtPtr) /* must be new itext */ { Texts[nexttext] = ITxtPtr; nexttext++; /* follow the list of itexts to the end */ if (Gad->GadgetText == NULL) Gad->GadgetText = ITxtPtr; else { for(nextptr = Gad->GadgetText; nextptr->NextText != NULL; nextptr = nextptr->NextText); nextptr->NextText = ITxtPtr; } } /*if it is old itext it stays in the list - same spot*/ /* let the user drag and position the text */ DragText(ITxtPtr,(LONG)Gad->LeftEdge,(LONG)Gad->TopEdge); } /* drop to here if ITxtPtr is NULL - user cancelled */ } /* restore the gadgets */ for (i=0; i < nextgad; i++) AddGadget(ReqWindow,gads[i],(LONG)-1); RefreshGadgets(Gad,ReqWindow,NULL); } /* ITextEd */ /* * Init the Itext choice requester */ InitCHReq() { InitRequester(&ChoiceRequester); ChoiceRequester.LeftEdge = 100; ChoiceRequester.TopEdge = 20; ChoiceRequester.Width = 264; ChoiceRequester.Height = 146; ChoiceRequester.ReqGadget = &PotGadget; ChoiceRequester.ReqText = &HeadingText; ChoiceRequester.BackFill = 0; ChoiceRequester.Flags = 0; ChoiceRequester.ReqBorder = &Requester3Border; } /* InitCHReq */ /* * Init the intuitext input and modification requester */ InitTxtReq() { InitRequester(&ITxtRequester); ITxtRequester.LeftEdge = 100; ITxtRequester.TopEdge = 20; ITxtRequester.Width = 350; ITxtRequester.Height = 135; ITxtRequester.ReqGadget = &ModTxtGad; ITxtRequester.ReqText = &ModTxtText; ITxtRequester.BackFill = 0; ITxtRequester.Flags = 0; ITxtRequester.ReqBorder = &ITxtReqBord; } /* InitTxtReq */ /* Copy pointers of the linked list of IntuiTexts associated with the * selected gadget into the ITMap array */ MapTexts(gadgetp) struct Gadget *gadgetp; { ITMap[0] = gadgetp->GadgetText; for(ITxtCount = 0; ITxtCount < 50 && ITMap[ITxtCount] != NULL; ITxtCount++) ITMap[ITxtCount+1] = ITMap[ITxtCount]->NextText; } /* * WaitChoiceReq - List dirs, scroll, and set drawer and file strings until * one of the LOAD(SAVE) or CANCEL buttons pushed. */ struct IntuiText *WaitChoiceReq(cancelflag) BOOL *cancelflag; { ULONG class = GADGETDOWN; USHORT choice = CANCELGADGET; USHORT selected = 0; struct IntuiMessage *message; struct Gadget *gadget; *cancelflag = FALSE; while (class != REQCLEAR) { if ((message=(struct IntuiMessage *) GetMsg(w->UserPort)) == 0L) { Wait(1L<<w->UserPort->mp_SigBit); continue; } class = message->Class; gadget = (struct Gadget *) message->IAddress; ReplyMsg(message); switch (class) { case GADGETDOWN: switch (gadget->GadgetID >> CLASSBITS) { case UPDOWNCLASS: ScrollList(gadget); /* scroll up/down 1 file */ break; case BUTTONCLASS: /* LOAD or CANCEL */ choice = gadget->GadgetID & GADGETNUM; break; } case GADGETUP: switch (gadget->GadgetID >> CLASSBITS) { case UPDOWNCLASS: PotScrollList(gadget); break; case CHOICECLASS: /* set the text in string gads */ if (ITxtCount == 0) break; if (gadget->GadgetText != NULL) selected = gadget->GadgetID & GADGETNUM; break; } } } /* use selected and ITMap to locate correct intuitext */ /* return pointer to selected intuitext */ if (choice == ADDTXT) return(NULL); else if (choice == CANCEL) { *cancelflag = TRUE; return(NULL); } else return((struct IntuiText *)ITxtListGadget[selected].UserData); } /* WaitChoiceReq */ /* * WaitITReq - Let user set the characteristics of the text, such as * fonts, colors, drawing mode, and enter or modify the * text itself. */ struct IntuiText *WaitITReq(itextp) struct IntuiText *itextp; { ULONG class = GADGETDOWN; USHORT choice = CANCELGADGET; USHORT selected = -1; SHORT fontnum = 0; USHORT dummypos; SHORT Mx,My, OldTextLen, NewTextLen; UBYTE drawmode, savefrontp, savebackp; BOOL nullinput = FALSE; struct IntuiMessage *message; struct Gadget *gadget; struct RastPort *rp; if (itextp == NULL) /* allocate a new text structure and fill it in */ { itextp = (struct IntuiText *)AllocRemember( rememberBase,(long)sizeof(struct IntuiText), MEMF_PUBLIC | MEMF_CLEAR); if (itextp == NULL) return (NULL); itextp->FrontPen = 1; itextp->BackPen = 0; itextp->DrawMode = JAM1; itextp->LeftEdge = 0; itextp->TopEdge = 0; itextp->ITextFont = NULL; ITxtStringBuff[StringBuffPos] = '\0'; itextp->IText = &ITxtStringBuff[StringBuffPos]; itextp->NextText = NULL; nullinput = TRUE; } /* set the display text to the values for the selected text */ ITDispText.FrontPen = itextp->FrontPen; ITDispText.BackPen = itextp->BackPen ; ITDispText.ITextFont = itextp->ITextFont; if (itextp->ITextFont != NULL)/* set the right font index */ { for(fontnum=0; itextp->ITextFont != TxtFonts[fontnum]; fontnum++);} ITDispText.DrawMode = itextp->DrawMode; strcpy(ModBuff,itextp->IText); /* put text into string buffer */ /* set the requester */ Request(&ITxtRequester,w); rp = ITxtRequester.ReqLayer->rp; while (class != REQCLEAR) { if ((message=(struct IntuiMessage *) GetMsg(w->UserPort)) == 0L) { Wait(1L<<w->UserPort->mp_SigBit); continue; } class = message->Class; Mx = message->MouseX; My = message->MouseY; gadget = (struct Gadget *) message->IAddress; ReplyMsg(message); if (class == GADGETUP) { switch (gadget->GadgetID >> CLASSBITS) { case BUTTONCLASS: /* LOAD or CANCEL */ choice = gadget->GadgetID & GADGETNUM; EndRequest(&ITxtRequester,w); break; case CHANGECLASS: /* save the current pens */ savefrontp = ITDispText.FrontPen; savebackp = ITDispText.BackPen; /* clear the text display area */ ITDispText.FrontPen = 0; ITDispText.BackPen = 0; PrintIText(rp,&ITDispText,25L,33L); switch (gadget->GadgetID & GADGETNUM) { case PLAIN: fontnum = 0; break; case UNDERLIN: fontnum |= 1; break; case BOLD: fontnum |= 2; break; case ITALIC: fontnum |= 4; break; case BACKGPEN: savebackp = (UBYTE)(Mx - 320)/25; break; case FGPEN: savefrontp = (UBYTE)(Mx - 320)/25; break; case MODJAM1: ITDispText.DrawMode = JAM1; break; case MODJAM2: ITDispText.DrawMode = JAM2; break; case MODINV: ITDispText.DrawMode = COMPLEMENT; break; } /* set any new text attributes and display */ ITDispText.ITextFont = TxtFonts[fontnum]; ITDispText.FrontPen = savefrontp; ITDispText.BackPen = savebackp; PrintIText(rp,&ITDispText,25L,33L); break; }/* CLASSBITS switch */ } /* if GADGETDOWN */ } /* while loop */ /* return pointer to selected intuitext */ if (choice == CANCEL) { if (nullinput) /* FreeMem(itextp,(LONG)sizeof(struct IntuiText));*/ return(NULL); } /* User must have chosen OK, so update the real IntuiText */ OldTextLen = strlen(itextp->IText); NewTextLen = strlen(ModBuff); if (OldTextLen < NewTextLen) { if ((NewTextLen+1) > (STRINGBUFFSIZ - StringBuffPos)) { /* no room for new text */ if (autoreq("Out of string space! ", "Add Partial String", "Cancel Text")) /* chop the string */ ModBuff[STRINGBUFFSIZ-StringBuffPos] = '\0'; else return(NULL); } itextp->IText = &ITxtStringBuff[StringBuffPos]; StringBuffPos += (NewTextLen + 1); } /* if we got to here, means there is space in the buffer and pointer */ /* is set to the correct position in the buffer */ strcpy(itextp->IText,ModBuff); /* copy the string */ /*set the attributes*/ itextp->FrontPen = ITDispText.FrontPen; itextp->BackPen = ITDispText.BackPen; itextp->ITextFont = ITDispText.ITextFont; itextp->DrawMode = ITDispText.DrawMode; return(itextp); /* send back the pointer to the IntuiText structure */ } /* WaitITReq */ /* * AttachList - Attach list of file (directory) names to Selection gadgets */ AttachList(Start) USHORT Start; { USHORT Gadget; USHORT Pos; struct IntuiText *itextp; for (Gadget = 0; Gadget <= 7 && Gadget+Start < ITxtCount; Gadget++) { itextp = ITMap[Start + Gadget]; ITxtList[Gadget].IText = itextp->IText; /* set the display text to the values for the selected text */ ITxtList[Gadget].FrontPen = itextp->FrontPen; ITxtList[Gadget].BackPen = itextp->BackPen ; ITxtList[Gadget].ITextFont = itextp->ITextFont; ITxtList[Gadget].DrawMode = itextp->DrawMode; ITxtListGadget[Gadget].UserData = (APTR)itextp; } for (; Gadget <= 7; Gadget++) { ITxtList[Gadget].IText = (UBYTE *)" "; ITxtList[Gadget].FrontPen = 1; ITxtList[Gadget].BackPen = 0; ITxtList[Gadget].DrawMode = JAM1; ITxtList[Gadget].ITextFont = NULL; ITxtListGadget[Gadget].UserData = NULL; } } /* AttachList */ /* * ClearListGads - clears ITxtList after removing the requester ends */ ClearListGads() { SHORT Gadget; for (Gadget = 0; Gadget < 8; Gadget++) { ITxtList[Gadget].IText = (UBYTE *)" "; ITxtList[Gadget].FrontPen = 1; ITxtList[Gadget].BackPen = 0; ITxtList[Gadget].DrawMode = JAM1; ITxtList[Gadget].ITextFont = NULL; ITxtListGadget[Gadget].UserData = NULL; } } /* * ScrollList - Scroll the list up or down 1 file if possible */ ScrollList(gadget) struct Gadget *gadget; { ULONG VertPot = 0; switch(gadget->GadgetID & GADGETNUM) { case DOWN: if (ITxtCount > FirstITxt + 8) ++FirstITxt; break; case UP: if (FirstITxt > 0) --FirstITxt; } if (ITxtCount > 8) VertPot = 0xffff/(ITxtCount-6)*FirstITxt; ModifyProp(&PotGadget,w,&ChoiceRequester,AUTOKNOB|FREEVERT|PROPBORDERLESS, 0L,VertPot,0L,(LONG)KnobInfo.VertBody); ClearListGads(); RefreshGadgets(&DownGadget,w,&ChoiceRequester); AttachList(FirstITxt); RefreshGadgets(&DownGadget,w,&ChoiceRequester); } /* ScrollList */ /* * PotScrollList - Calculate the file number from Pot value and attach * names to Selector List gadgets. */ PotScrollList(gadget) struct Gadget *gadget; { switch (gadget->GadgetID & GADGETNUM) { case POT: FirstITxt = (ITxtCount-6)*KnobInfo.VertPot >> 16; ClearListGads(); RefreshGadgets(&DownGadget,w,&ChoiceRequester); AttachList(FirstITxt); RefreshGadgets(&DownGadget,w,&ChoiceRequester); } } /* PotScrollList */ /* * ClearITexts - this routine clears an IntuiText * from the display by overprinting in color 0. */ ClearITexts(text,Loff,Toff) struct IntuiText *text; LONG Loff,Toff; { UBYTE tempFpen,tempBpen; struct IntuiText *temptext; if (text == NULL) return; tempFpen = text->FrontPen; tempBpen = text->BackPen; temptext = text->NextText; text->NextText = NULL; text->FrontPen = 0; text->BackPen = 0; PrintIText(w->RPort,text,Loff,Toff); text->FrontPen = tempFpen; text->BackPen = tempBpen; text->NextText = temptext; } /* * ClearAllTexts - this routine clears all IntuiTexts * from the display for a particular gadget. */ ClearAllTexts(gadget,Loff,Toff) struct Gadget *gadget; LONG Loff,Toff; { struct IntuiText *nextptr; if (gadget == NULL) return; /* follow the list of itexts to the end */ if (gadget->GadgetText == NULL) return; else { for(nextptr = gadget->GadgetText; nextptr != NULL; nextptr = nextptr->NextText) ClearITexts(nextptr,Loff,Toff); } } /* * DragText - this routine recursively clears all of the itexts * from the display for a particular gadget. */ DragText(text,GadLeft,GadTop) struct IntuiText *text; LONG GadLeft,GadTop; { UBYTE SaveDrawMode; struct IntuiText *SaveText; struct IntuiMessage *message; LONG Mx, My, LastX, LastY; ULONG class = 0; USHORT btcode; SHORT skip; BOOL notdone = TRUE; if (text == NULL) return; /* save the current settings */ SaveDrawMode = text->DrawMode; SaveText = text->NextText; /* set the things needed for dragging text */ text->NextText = NULL; text->DrawMode |= COMPLEMENT; text->LeftEdge = 0; text->TopEdge = 0; /* set the location based on the mouse position */ Mx = (LONG)w->MouseX + 15; My = (LONG)w->MouseY; /* print the text */ PrintIText(w->RPort,text,Mx,My); /* save the position where it was printed */ LastX = Mx; LastY = My; /* Start IDCMP loop - go until a mouse button is clicked */ skip = 0; while (notdone) { if ((message=(struct IntuiMessage *) GetMsg(w->UserPort)) == 0L) { Wait(1L<<w->UserPort->mp_SigBit); continue; } class = message->Class; btcode = message->Code; Mx = (LONG)message->MouseX + 15; My = (LONG)message->MouseY; ReplyMsg(message); switch (class) { case MOUSEMOVE: skip++; if (skip == 2) { skip = 0; /* erase the old text */ PrintIText(w->RPort,text,LastX,LastY); /* print the text in the new spot */ PrintIText(w->RPort,text,Mx,My); /* save the position where it was printed */ LastX = Mx; LastY = My; } break; case GADGETUP: notdone = FALSE; break; case MOUSEBUTTONS: if (btcode = SELECTUP) notdone = FALSE; break; }/* end of switch */ }/* end of while loop */ /* erase the last text */ PrintIText(w->RPort,text,LastX,LastY); /* restore the mode and next pointer */ text->DrawMode = SaveDrawMode; text->NextText = SaveText; /* set the offset from the gadget */ text->LeftEdge = (SHORT)Mx - GadLeft; text->TopEdge = (SHORT)My - GadTop; } /* end of DragText */ SHAR_EOF fi if test -f 'kp.c' then echo shar: "will not over-write existing file 'kp.c'" else cat << \SHAR_EOF > 'kp.c' /* * This is a debug library which interacts directly with the Serial * port. * * Functions are: * kprintf(fmt, arg1, arg2,....); * kputchar(char); * kputs(string); */ kprintf(fmt, args) char *fmt; int args; { int kputchar(); return(format(kputchar, fmt, &args)); } kputs(str) char *str; { while (*str) kputchar(*str++); kputchar('\n'); } #asm public _LVORawPutChar public _kputchar _kputchar move.l 4,a6 move.w 4(sp),d0 ;make the 'w' an 'l' if using c32.lib cmp.b #$a,d0 bne.s .1 jsr _LVORawPutChar(a6) move.l #$d,d0 .1 jsr _LVORawPutChar(a6) move.w 4(sp),d0 rts #endasm SHAR_EOF fi if test -f 'men.c' then echo shar: "will not over-write existing file 'men.c'" else cat << \SHAR_EOF > 'men.c' /** men.c ************************************************************* * * men.c - Menu functions for John Draper's GadEd * * Routines in this module: Do_menu * Temporarily : initgads(), getgad(), savegad() * these belong in the filemenu.c module. * * David Milligan - Cleaned up menu appearance & layout. * 6/7/86 - Broke up menu into discrete structures for fine-tuning. * - Added shortcut keys to Flags & Activation items. * - Added rudimentary MutualExcluding. * 6/9/86 - Made menu structures into separate file in consideration * of other programmers on project. * 6/11/86 - Re-implemented 'stamping' method of menu init. * - Re-wrote the NewMenu() function to use pointer indexing. * Much cleaner & more efficient. * 6/14/86 - Broke men.c into three files: menstructs.c, men.c, men.h * 7/6/86 - Put men.h BACK into men.c. It seems John didn't like it. * Compiled his new changes with no problems. * * 11/17/86- RRL added some code to call the intuitext requesters * and to clear the flags and checkmarks when a new type * of gadget is selected. * * 11/22/86- RRL added the delete function and modified the image * editor interface. Made GADGIMAGE and GADGHIMAGE flags * non-selectable by the user to avoid bad flag crashes. * * David Milligan, Surrealistic Software, Sacramento, CA. * The WELL - dmil * CompuServe - 70707,2521 * BIX - dmilligan * home phone - (916)366-1269 ***********************************************************************/ /** men.h ************************************************************* * * men.h - Menu definitions for John Draper's GadEd * * created 6/14/86 -- David Milligan, Surrealistic Software * ***********************************************************************/ /* The usual header files to be inserted later */ #include <intuition/intuition.h> #include <libraries/dosextens.h> #include <graphics/gfxbase.h> #include <graphics/gfx.h> #include <graphics/display.h> #include <exec/memory.h> #include <workbench/workbench.h> #include <workbench/startup.h> #include <devices/narrator.h> #include <devices/audio.h> #include <libraries/translator.h> #include "gad.h" #include "men.h" /*================== global variables ===============*/ /* gadget index pointers */ int pflag = FALSE; /* propinfo flag */ int curgad = 0; /* Pointer into gadget pointer array */ int nextgad = 0; /* Pointer into Next gadget to be entered */ extern int nextlink; /* the index of the next gad to linked */ int nextprop = 0; /* index into next propinfo pointer */ int nexttext = 0; /* index to next intuitext structure pointer */ int nx_strings = 0; /* index to next stringinfo pointer */ USHORT oldtype; /* Last gadget type before change */ struct Gadget *gads[MAX_NUM_GADGETS]; struct IntuiText *Texts[MAX_INTUITEXTS]; char gadimage[MAX_PROPINFOS][NAM_SIZ]; char selectimage[MAX_PROPINFOS][NAM_SIZ]; struct PropInfo *props[MAX_PROPINFOS]; struct StringInfo *strings[MAX_STRINGINFOS]; UBYTE *gadnames[MAX_NUM_GADGETS]; char *textnames[MAX_INTUITEXTS]; char *propnames[MAX_PROPINFOS]; char *strnames[MAX_STRINGINFOS]; /* space for gadget names */ UBYTE names [MAX_NUM_GADGETS] [NAM_SIZ]; /*================== EXTERNAL FUNCTION DECLARATIONS ===================*/ extern SHORT AddGadget(); extern UBYTE *getrname(); /* in reqn.c */ extern struct Image *Image_Ed(); /* Ray's stuff in image.c */ extern struct StringInfo *nam_info(); /* Returns Info for getrname */ /*===================== EXTERNAL GLOBAL VARIABLES =====================*/ extern struct Gadget testgad; extern struct Gadget *SelectedGadget; extern struct PropInfo Prop; extern struct StringInfo String; extern struct Window *w; extern struct RastPort *rp; extern long mask; extern int holding; extern int erase; extern int siz_flag; extern SHORT Left, Top, Width, Height; extern SHORT N_Bitplanes; extern struct Menu file_menu; extern struct MenuItem info_items[]; extern struct MenuItem flags_items[]; extern struct MenuItem act_items[]; /*----------------------- Important arrays -------------------*/ /* Gadget types */ USHORT gadtype[] = { BOOLGADGET, PROPGADGET, STRGADGET }; /* Activation flags supported */ USHORT actflags[] = { 0, /* Clear all flags */ RELVERIFY, FOLLOWMOUSE, GADGIMMEDIATE, ENDGADGET, TOGGLESELECT, LONGINT, RIGHTBORDER, LEFTBORDER, TOPBORDER, BOTTOMBORDER, STRINGCENTER, STRINGRIGHT, ALTKEYMAP }; /* Gadget flags supported */ USHORT gadflags[] = { 0, /* Reset all flags */ GADGHCOMP, GADGHBOX, GADGHIMAGE, GADGIMAGE, GRELBOTTOM, GRELRIGHT, GRELWIDTH, GRELHEIGHT, SELECTED, GADGDISABLED }; /* Propinfo flags supported */ USHORT propflags[] = { 0, /* reset all flags */ AUTOKNOB, FREEHORIZ, FREEVERT, PROPBORDERLESS, KNOBHIT }; /*************************************************************************** DO THE MENU SELECTIONS ***************************************************************************/ Do_menu(menu, item) long menu, item; { struct PropInfo *pr; SHORT val; SHORT wid, hgt; UBYTE *str; int i; struct Image *imag1, *imag2; struct StringInfo *si; /* Info for getrname */ struct PropInfo *pi; /* PropInfo pointer */ long flags, lf, tp, wd, ht; switch (menu) { case FILE_MENU: switch(item) { case NEW_GAD: initgads(); /* Init the gadget area */ break; case GET_GAD: /* Gets the gadget info from file */ ClearMenuStrip(w);/* don't let user quit while */ /* file is being read */ getgad(); SetMenuStrip(w,&file_menu); break; case SAVE_GAD: /* Saves the gadget to disk */ ClearMenuStrip(w);/* don't let user quit while */ /* source is being dumped */ savegad(); SetMenuStrip(w,&file_menu); break; case SAV_SOURCE: /* Saves the source */ ClearMenuStrip(w);/* don't let user quit while */ /* source is being dumped */ dumpgadgets(); SetMenuStrip(w,&file_menu); break; case QUIT_PROG: CloseThings(); /* Close down */ exit(NULL); break; } break; case GAD_TYPE_MENU: oldtype = testgad.GadgetType; testgad.GadgetType = gadtype[item]; /* ### new RRL */ ClearMenuStrip(w); for(i=1;i<NUM_SPEC_ITEMS;i++) info_items[i].Flags &= ~CHECKED; pflag = 0; for(i=1;i<NUM_FLAGS;i++) flags_items[i].Flags &= ~CHECKED; testgad.Flags = 0; for(i=1;i<NUM_ACT_FLAGS;i++) act_items[i].Flags &= ~CHECKED; testgad.Activation = 0; SetMenuStrip(w,&file_menu); break; case GAD_ACT_MENU: if (item == 0) testgad.Activation = 0; else testgad.Activation |= actflags[item]; break; case GADFLAGS_MENU: if (item == 0) testgad.Flags = 0; else testgad.Flags |= gadflags[item]; break; case UTIL_MENU: switch(item) { case NEW_GADGET: /* Adds gadget to list */ if ((testgad.GadgetType == PROPGADGET) && (pflag == 0)){ autoreq("You need to set PROPINFO flags first!", "OK","CANCEL"); break; } /* erase the last box */ draw_box(rp, Left-1, Top-1, Width, Height); /* clear image flags if they are hanging around */ testgad.Flags &= ~(GADGIMAGE | GADGHIMAGE); linkgadgets(); SelectedGadget = NULL; break; case DEL_GADGET: /* Delete selected gadget - works now -RRL*/ if (SelectedGadget == NULL) { autoreq( "You have to click on the gadget to delete first", " OK ","Right"); SelectedGadget = NULL; break; } /* highlight the selected gadget */ SetDrMd(rp, COMPLEMENT); RectFill(rp, (LONG)SelectedGadget->LeftEdge-1, (LONG)SelectedGadget->TopEdge-1, (LONG)SelectedGadget->LeftEdge + (LONG)SelectedGadget->Width, (LONG)SelectedGadget->TopEdge + (LONG)SelectedGadget->Height); if(autoreq("REALLY delete the highlighted gadget?", "YES","NO!! CANCEL")) { /* we just remove the gad and it's imagery */ RemoveGadget(w,SelectedGadget); ClearAllTexts(SelectedGadget, (LONG)SelectedGadget->LeftEdge, (LONG)SelectedGadget->TopEdge); SetAPen(rp,0L); SetDrMd(rp, JAM1); RectFill(rp, (LONG)SelectedGadget->LeftEdge-1, (LONG)SelectedGadget->TopEdge-1, (LONG)SelectedGadget->LeftEdge + (LONG)SelectedGadget->Width, (LONG)SelectedGadget->TopEdge + (LONG)SelectedGadget->Height); /* remove the gadget pointer from the */ /* gads array and move others up. Also*/ /* move names associated with the gad */ curgad = findadr(gads,SelectedGadget,nextgad); if (curgad != -1){ for (i=curgad; i < nextgad; i++) { gads[i] = gads[i+1]; gadnames[i] = gadnames[i+1]; strcpy(gadimage[i], gadimage[i+1]); strcpy(selectimage[i], selectimage[i+1]); } nextgad--; nextlink--; } } else /* undo the highlighting */ SetDrMd(rp, COMPLEMENT); RectFill(rp, (LONG)SelectedGadget->LeftEdge-1, (LONG)SelectedGadget->TopEdge-1, (LONG)SelectedGadget->LeftEdge + (LONG)SelectedGadget->Width, (LONG)SelectedGadget->TopEdge + (LONG)SelectedGadget->Height); SetAPen(rp,1L); SetDrMd(rp, JAM1); holding = FALSE; erase = FALSE; break; case SET_GAD_NAME: /* Open Requester, get name */ si = nam_info(); /* Get name info */ *si->Buffer = '\0'; /* Zap old name */ si->BufferPos = 0; str = getrname("Enter Gadget name"); if (str == NULL) { SelectedGadget = NULL; break; } strcpy(names[curgad], str); gadnames[curgad] = names[curgad]; break; case ADD_INTUITEXT: /* Add Intuitext to border */ ITextEd(SelectedGadget,w); break; case SET_IMAG_BORD: /* Add GadgetRender */ if (SelectedGadget == NULL) { autoreq( "First click on the gadget you want to add the image to.", " OK ","Right"); SelectedGadget = NULL; break; } i = curgad; curgad = findadr(gads,SelectedGadget,nextgad); if (curgad == -1) { kprintf("couldn't find selected gad in gads array!!\n"); break; } if (nextgad) { if (!get_req_name("Enter Image Name", gadimage[curgad])) { SelectedGadget = NULL; break; } flags = (long)SelectedGadget->UserData; wid = SelectedGadget->Width; /* Image width */ hgt = SelectedGadget->Height; /* Image Width */ hgt -= 3; /* So it don't mess with borders */ wid -= 8; if (SelectedGadget->GadgetType == PROPGADGET) { pi = (struct PropInfo *)SelectedGadget->SpecialInfo; if ((pi->Flags & FREEHORIZ) == FREEHORIZ) wid >>= 2; if ((pi->Flags & FREEVERT) == FREEVERT) hgt >>= 2; } if ((flags & GAD_BORDER_TYPE) == GAD_BORDER_TYPE) { imag1 = Image_Ed(w->WScreen, wid, /* Image same as Gadget */ hgt, /* Height same also */ N_Bitplanes, /* WB Scrn depth */ NULL ); /* Create new image */ if (imag1 == NULL) break; SelectedGadget->GadgetRender = (APTR)imag1; flags &= ~GAD_BORDER_TYPE; flags |= GAD_IMAGE_TYPE; SelectedGadget->Flags |= GADGIMAGE; ClearMenuStrip(w); flags_items[4].Flags |= CHECKED; SetMenuStrip(w,&file_menu); SelectedGadget->UserData = (APTR)flags; } else if ((flags & GAD_IMAGE_TYPE) == GAD_IMAGE_TYPE) { imag2 = (struct Image *)SelectedGadget->GadgetRender; imag1 = Image_Ed(w->WScreen, wid, /* Use same as Gadget */ hgt, /* Same as Gadget */ N_Bitplanes, /* WB Scrn depth */ imag2); /* Use current image */ if (imag1 == NULL) break; SelectedGadget->GadgetRender = (APTR)imag1; } else if ((flags & KNOB_IMAGE_TYPE) == KNOB_IMAGE_TYPE) { imag1 = Image_Ed(w->WScreen, wid, /* Use same as Gadget */ hgt, /* Same as Gadget */ N_Bitplanes, /* WB Scrn depth */ NULL); /* Use current image */ if (imag1 == NULL) break; SelectedGadget->GadgetRender = (APTR)imag1; pi = (struct PropInfo *)SelectedGadget->SpecialInfo; pi->Flags &= ~AUTOKNOB; flags &= ~KNOB_IMAGE_TYPE; flags |= GAD_IMAGE_TYPE; SelectedGadget->Flags |= GADGIMAGE; ClearMenuStrip(w); flags_items[4].Flags |= CHECKED; SetMenuStrip(w,&file_menu); SelectedGadget->UserData = (APTR)flags; } } SetAPen(rp, 0L); SetDrMd(rp, JAM1); lf = (long)(SelectedGadget->LeftEdge-1); tp = (long)(SelectedGadget->TopEdge-1); wd = (long)(SelectedGadget->Width+1); ht = (long)(SelectedGadget->Height+1); RectFill(rp, lf, tp, lf+wd, tp+ht); RefreshGadgets(gads[0], w, NULL); break; case SET_SEL_BORD: /* Add SelectRender */ if (SelectedGadget == NULL) { autoreq( "First click on the gadget you want to add the image to.", " OK ","Right"); SelectedGadget = NULL; break; } flags = (long)SelectedGadget->UserData; if ((flags & GAD_IMAGE_TYPE) != GAD_IMAGE_TYPE){ /* can't do a select image without a gad image */ autoreq("Must create Gadget image before Select image!", "OK","Sure Thing"); SelectedGadget = NULL; break; } i = curgad; curgad = findadr(gads,SelectedGadget,nextgad); if (curgad == -1) { kprintf("couldn't find selected gad in gads array!!\n"); break; } if (nextgad) { if (!get_req_name("Enter Image name", selectimage[curgad])) { SelectedGadget = NULL; break; } flags = (long)SelectedGadget->UserData; wid = SelectedGadget->Width; /* Imahe width */ hgt = SelectedGadget->Height; /* Image Width */ hgt -= 3; /* So it don't mess with borders */ wid -= 8; if (SelectedGadget->GadgetType == PROPGADGET) { pi = (struct PropInfo *)SelectedGadget->SpecialInfo; if ((pi->Flags & FREEHORIZ) == FREEHORIZ) wid >>= 2; if ((pi->Flags & FREEVERT) == FREEVERT) hgt >>= 2; } if (((flags & SEL_BORDER_TYPE) == SEL_BORDER_TYPE) || SelectedGadget->SelectRender == NULL) { /* let user edit select image if desired */ if( autoreq("Modify gadget image for select image?", "YES","No- New Image")) imag2 = (struct Image *)SelectedGadget->GadgetRender; else imag2 = NULL; imag1 = (struct Image *)Image_Ed(w->WScreen, wid, /* Image same as Gadget */ hgt, /* Width same also */ N_Bitplanes, /* WB Scrn depth */ imag2 ); /* image to mod or new */ if (imag1 == NULL) break; flags &= ~SEL_BORDER_TYPE; SelectedGadget->SelectRender = (APTR)imag1; flags |= SEL_IMAGE_TYPE; SelectedGadget->Flags |= GADGHIMAGE; ClearMenuStrip(w); flags_items[3].Flags |= CHECKED; SetMenuStrip(w,&file_menu); SelectedGadget->UserData = (APTR)flags; } else if ((flags & SEL_IMAGE_TYPE) == SEL_IMAGE_TYPE) { imag2 = (struct Image *)SelectedGadget->SelectRender; imag1 = (struct Image *)Image_Ed(w->WScreen, wid, /* Use same as Gadget */ hgt, /* Same as Gadget */ N_Bitplanes, /* WB Scrn depth */ imag2); /* Use current image */ if (imag1 == NULL) break; SelectedGadget->SelectRender = (APTR)imag1; } } SetAPen(rp, 0L); SetDrMd(rp, JAM1); lf = (long)(SelectedGadget->LeftEdge-1); tp = (long)(SelectedGadget->TopEdge-1); wd = (long)(SelectedGadget->Width+1); ht = (long)(SelectedGadget->Height+1); RectFill(rp, lf, tp, lf+wd, tp+ht); RefreshGadgets(gads[0], w, NULL); break; case SET_GADSIZ: siz_flag = TRUE; break; case SET_GADLOC: siz_flag = FALSE; break; case ADD_MUT_EXCLUD: /* Add Mutual exclude */ dispgad(gads[0]); break; case ADD_USR_ID: /* Add User ID value */ trap(); /* Debug trap */ break; } break; case SPEC_MENU: if (item == 0) pflag = NULL; else pflag |= propflags[item]; break; } } /* Go here if we want to go into the debugger */ trap() { kprintf("Entered into debugger\n"); } /*=================== Menu Action functions here ===================*/ /*------- Clear out for new gadget file -------*/ initgads() { } SHAR_EOF fi if test -f 'menstructs.c' then echo shar: "will not over-write existing file 'menstructs.c'" else cat << \SHAR_EOF > 'menstructs.c' /** menstructs.c ******************************************************** * * menstructs.c - Menu structures & init functions * * Routines in this module: MakeMyMenus , NewMenu * * David Milligan - Cleaned up menu appearance & layout. * 6/7/86 - Broke up menu into discrete structures for fine-tuning. * - Added shortcut keys to Flags & Activation items. * - Added rudimentary MutualExcluding. * 6/9/86 - Made menu structures into separate file in consideration * of other programmers on project. * 6/11/86 - Re-implemented 'stamping' method of menu init. * - Re-wrote the NewMenu() function to use pointer indexing. * Much cleaner & more efficient. * * David Milligan, Surrealistic Software, Sacramento, CA. * The WELL - dmil * CompuServe - 70707,2521 * BIX - dmilligan * home phone - (916)366-1269 ***********************************************************************/ /* The usual header files to be inserted later */ #include <intuition/intuition.h> #include <libraries/dosextens.h> #include <graphics/gfxbase.h> #include <graphics/gfx.h> #include <graphics/display.h> #include <exec/memory.h> #include <workbench/workbench.h> #include <workbench/startup.h> #include <devices/narrator.h> #include <devices/audio.h> #include <libraries/translator.h> #include "gad.h" #include "men.h" /*===================== EXTERNAL GLOBAL VARIABLES =====================*/ extern struct Gadget testgad; extern struct PropInfo Prop; extern struct StringInfo String; extern struct Window *w; extern long mask; extern int holding; extern int erase; extern int siz_flag; /* Copies of this structure will get "stamped" into many more */ /* Allocated later */ struct IntuiText generic = { 0, 1, /* Bluepen, Whitepen */ JAM2, 5, /* mode, LeftEdge */ 0, NULL, /* Top (to be filled later), Font */ NULL, /* Name (to be filled later) */ NULL /* Next one */ }; /*----------- Array of Menu Widths --------------*/ int item_widths[NUM_MENUS] = { 190, 135, 171, 171, 182, 145 }; /*********** Array of MenuItem LeftEdge values ****************/ int item_lefts[NUM_MENUS] = { FILE_LEFT,TYPE_LEFT,ACT_LEFT,FLAGS_LEFT,UTIL_LEFT,SPEC_LEFT }; /*======================== Propinfo flags menu ========================*/ struct MenuItem info_items[NUM_SPEC_ITEMS]; struct IntuiText info_texts[NUM_SPEC_ITEMS]; char *info_names[] = { " Clear All Flags", " AUTOKNOB", " FREEHORIZ", " FREEVERT", " PROPBORDERLESS", " KNOBHIT" }; USHORT info_menuflags [] = { MENU_COMP,MENU_BOX,MENU_BOX,MENU_BOX,MENU_BOX,MENU_BOX }; USHORT info_exclude [] = { 0xfffe,0x0001,0x0001,0x0001,0x0001,0x0001 }; UBYTE info_commkeys[] = { 0,0,0,0,0,0 }; struct Menu info_menu = { NULL, /* No next menu */ UTIL_WIDTH + FLAGS_WIDTH + ACT_WIDTH + TYPE_WIDTH + FILE_WIDTH, 0, SPEC_WIDTH, 10, /* TopEdge, Width, Height */ MENUENABLED, /* FLAGS */ " PropInfo flags", /* Name of menu */ info_items /* First Item structure */ }; /*================== DECLARATIONS FOR "UTILITY" MENU ==================*/ struct MenuItem util_items[NUM_UTIL_ITEMS]; struct IntuiText util_Itexts[NUM_UTIL_ITEMS]; char *util_names[] = { "Add New Gadget", "Delete Last Gadget", "Set Gadget Name", "Add Intuitext", "Set Image/Border", "Selected Image/Border", "Change Gadget Size", /* Don't need this */ "Change Gadget Location", /* Nor this........*/ "Set Mutual Exclude", "Add UserID", /* Definately not this */ "Set PropInfo" /* Not sure about this */ }; USHORT util_menuflags [] = { MENU_COMP,MENU_COMP,MENU_COMP,MENU_COMP,MENU_COMP,MENU_COMP, MENU_COMP,MENU_COMP,MENU_COMP,MENU_COMP,MENU_COMP }; USHORT util_exclude [] = { NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL }; UBYTE util_commkeys[] = { 0,0,0,0,0,0,0,0,0,0,0 }; struct Menu util_menu = { &info_menu, /* No next menu */ FLAGS_WIDTH + ACT_WIDTH + TYPE_WIDTH + FILE_WIDTH, 0, UTIL_WIDTH, 10, /* TopEdge, Width, Height */ MENUENABLED, /* FLAGS */ " Utilities", /* Name of menu */ util_items /* First Item structure */ }; /*======================= Gadget flags menu =========================*/ struct MenuItem flags_items[NUM_FLAGS]; struct IntuiText flags_texts[NUM_FLAGS]; char *flags_names[] = { " Clear All Flags", " GADGHCOMP", " GADGHBOX", " GADGHIMAGE", " GADGIMAGE", " GRELBOTTOM", " GRELRIGHT", " GRELWIDTH", " GRELHEIGHT", " SELECTED", " GADGDISABLED" }; USHORT flag_menuflags [] = { MENU_COMP,MENU_BOX_COMM,MENU_BOX_COMM,MENU_DISABLE_BOX, MENU_DISABLE_BOX,MENU_BOX_COMM,MENU_BOX_COMM,MENU_BOX_COMM, MENU_BOX_COMM,MENU_BOX_COMM,MENU_BOX_COMM }; USHORT flag_exclude [] = { 0xfffe,0x0001,0x0001,0x0001,0x0001,0x0001, 0x0001,0x0001,0x0001,0x0001,0x0001 }; UBYTE flag_commkeys[] = { 0,'P','R','S','T','U','V','W','X','Y','Z' }; struct Menu flags_menu = { &util_menu, /* No next menu */ ACT_WIDTH + TYPE_WIDTH + FILE_WIDTH, 0, FLAGS_WIDTH, 10, /* TopEdge, Width, Height */ MENUENABLED, /* FLAGS */ " Gadget Flags", /* Name of menu */ flags_items /* First Item structure */ }; /*============= DECLARATIONS FOR "Activation" MENU ==================*/ struct MenuItem act_items[NUM_ACT_FLAGS]; struct IntuiText act_texts[NUM_ACT_FLAGS]; char *act_item_names[] = { " Clear All Flags", " RELVERIFY", " FOLLOWMOUSE", " GADGIMMEDIATE", " ENDGADGET", " TOGGLESELECT", " LONGINT", " RIGHTBORDER", " LEFTBORDER", " TOPBORDER", " BOTTOMBORDER", " STRINGCENTER", " STRINGRIGHT", " ALTKEYMAP" }; USHORT act_menuflags [] = { MENU_COMP,MENU_BOX_COMM,MENU_BOX_COMM,MENU_BOX_COMM,MENU_BOX_COMM, MENU_BOX_COMM,MENU_BOX_COMM,MENU_BOX_COMM,MENU_BOX_COMM,MENU_BOX_COMM, MENU_BOX_COMM,MENU_BOX_COMM,MENU_BOX_COMM,MENU_BOX_COMM }; USHORT act_exclude [] = { 0xfffe,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001, 0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001 }; UBYTE act_commkeys[] = { 0,'A','B','C','D','E','F','G','H','I','J','K','L','O' }; struct Menu act_menu = { &flags_menu, /* No next menu */ TYPE_WIDTH + FILE_WIDTH, 0, ACT_WIDTH, 10, /* TopEdge, Width, Height */ MENUENABLED, /* FLAGS */ " Activation", /* Name of menu */ act_items /* First Item structure */ }; /*============ DECLARATIONS FOR Gadget Type MENU ===============*/ struct MenuItem type_items[NUM_GAD_TYPES]; struct IntuiText type_texts[NUM_GAD_TYPES]; char *type_names[] = { " Boolean gadget", " Prop Gadget", " String Gadget" }; USHORT gad_menuflags [] = { MENU_BOX,MENU_BOX,MENU_BOX }; USHORT gad_exclude [] = { 0xfffe,0xffd,0xffb }; UBYTE gad_commkeys[] = { 0,0,0 }; struct Menu type_menu = { &act_menu, FILE_WIDTH, /* Leftedge */ 0, TYPE_WIDTH, 10, /* TopEdge, Width, Height */ MENUENABLED, /* Flags */ " Gadget Type", /* Name on menu */ type_items }; /*===================== File menu declarations =====================*/ struct MenuItem file_items[NUM_FILE_ITEMS]; struct IntuiText file_texts[NUM_FILE_ITEMS]; char *file_names[] = { "New Gadgets File", "Get Gadgets File", "Save Gadgets File", "Save As Source", "Quit Program" }; USHORT file_menuflags [] = { MENU_COMP,MENU_COMP,MENU_COMP,MENU_COMP,MENU_COMP_COMM }; USHORT file_exclude [] = { NULL,NULL,NULL,NULL,NULL }; UBYTE file_commkeys[] = { 0,0,0,0,'Q' }; struct Menu file_menu = { &type_menu, 0, /* Leftedge */ 0, FILE_WIDTH, 10, /* TopEdge, Width, Height */ MENUENABLED, /* Flags */ " FILE", /* Name on menu */ file_items }; /*************************************************************************** C R E A T E A N E W M E N U ***************************************************************************/ NewMenu ( menu, item_names, menu_items, menu_text, num_items, LEdge , m_exclude, commkeys, Mwidth, item_flags) struct Menu *menu; /* Menu structure */ char *item_names[]; /* Pointer to array of item names */ register struct MenuItem *menu_items; /* pointer to array of structures */ register struct IntuiText *menu_text; /* Pointer to array of text structures register int num_items; /* Number of items */ int LEdge; /* Item's LeftEdge */ USHORT *m_exclude; UBYTE *commkeys; int Mwidth; /* Menu Width */ USHORT *item_flags; /* Pointer to array of Item flags */ { int height; height = 0; while (num_items--) { /* Doing structure assignments is not portable, but then this stuff would only work on an Amiga anyway since it is made for one. */ *menu_text = generic; menu_text->IText = (UBYTE *) *(item_names++); menu_items->NextItem = menu_items+1; /* Link to next menu item */ menu_items->TopEdge = height; menu_items->LeftEdge = LEdge; menu_items->Height = 8; menu_items->ItemFill = (APTR)menu_text; menu_items->Flags = *(item_flags++); menu_items->Width = Mwidth; menu_items->MutualExclude = *(m_exclude++); menu_items->Command = *(commkeys++); menu_items->SubItem = NULL; menu_items->NextSelect = NULL; height += 10; /* Increment all of the pointers */ menu_text++; menu_items++; } (menu_items-1)->NextItem = NULL; } /*=$$$===================== CREATE THE NEW MENUS =======================*/ MakeMyMenus() { NewMenu( &file_menu, file_names, file_items, file_texts, NUM_FILE_ITEMS, item_lefts[0], file_exclude, file_commkeys, item_widths[0], file_menuflags); NewMenu( &type_menu, type_names, type_items, type_texts, NUM_GAD_TYPES, item_lefts[1], gad_exclude, gad_commkeys, item_widths[1], gad_menuflags); NewMenu( &act_menu, act_item_names, act_items, act_texts, NUM_ACT_FLAGS, item_lefts[2], act_exclude, act_commkeys, item_widths[2], act_menuflags); NewMenu( &flags_menu, flags_names, flags_items, flags_texts, NUM_FLAGS, item_lefts[3], flag_exclude, flag_commkeys, item_widths[3], flag_menuflags); NewMenu( &util_menu, util_names, util_items, util_Itexts, NUM_UTIL_ITEMS, item_lefts[4], util_exclude, util_commkeys, item_widths[4], util_menuflags); NewMenu( &info_menu, info_names, info_items, info_texts, NUM_SPEC_ITEMS, item_lefts[5], info_exclude, info_commkeys, item_widths[5], info_menuflags); mask |= MENU; SetMenuStrip(w, &file_menu); } SHAR_EOF fi if test -f 'misc.c' then echo shar: "will not over-write existing file 'misc.c'" else cat << \SHAR_EOF > 'misc.c' /*========================================================================= misc.c - Misc Routines not going anywhere else. If not sure where to put it, then put it here =========================================================================*/ /* The usual header files to be inserted later */ #include <intuition/intuition.h> #include <libraries/dosextens.h> #include <graphics/gfxbase.h> #include <graphics/gfx.h> #include <graphics/display.h> #include <exec/memory.h> #include <workbench/workbench.h> #include <workbench/startup.h> #include <devices/narrator.h> #include <devices/audio.h> #include <libraries/translator.h> #include "gad.h" /* constants */ /* global vars */ extern struct Window *w; /* extern vars */ /* extern functions */ /*-------------------------------------- findadr - Finds the address in a table of addresses, returns an index to it --------------------------------------*/ int findadr(ptr, adr, len) ULONG ptr[]; ULONG adr; int len; { int i; for (i=0; i<len; i++) { if (adr == (ULONG)ptr[i]) return(i); } return(-1); } /*---------------------------------------- findnull - finds the first NULL address in a table of addresses. Returns an index to the NULL address in the table ----------------------------------------*/ int findnull(ptr, len) ULONG ptr[]; int len; { int i; for (i=0; i<len; i++) { if (ptr[i] == NULL) return(i); } return(-1); } /*--------------------------------------- freeprop - Called in gt.c to free the proportional gadget memory usage. Pointer to gadget is passed, returns nothing ---------------------------------------*/ freeprop(gad) struct Gadget *gad; /* pointer to gadget */ { free_renders(gad); /* Free all the renders */ if (gad->SpecialInfo != NULL ) { FreeMem(gad->SpecialInfo, (long)sizeof(struct PropInfo)); } } /* Frees BOTH GadgetRender or SelectRender fields. Depends on UserData being used to hold a flag that determines if a border or Image was allocated */ free_bords(gad,freeflag) struct Gadget *gad; long freeflag; { struct Border *bord, *selbord; long size; long flags; BOOL bothsame; /* for testing - just return */ return; if (gad->GadgetRender == gad->SelectRender) bothsame = TRUE; flags = (long)gad->UserData; if((freeflag & GAD_BORDER_TYPE) == GAD_BORDER_TYPE){ if (gad->GadgetRender != NULL ) { if ((flags & GAD_BORDER_TYPE) == GAD_BORDER_TYPE) { bord = (struct Border *)gad->GadgetRender; FreeMem(bord->XY, 20L); FreeMem(bord, (long)sizeof(struct Border)); gad->GadgetRender = NULL; flags &= ~GAD_BORDER_TYPE; /* $$$ */ gad->UserData = (APTR)flags; } } } if ((freeflag & SEL_BORDER_TYPE) == SEL_BORDER_TYPE) { if (gad->SelectRender != NULL ) { if ((flags & SEL_BORDER_TYPE) == SEL_BORDER_TYPE) { selbord = (struct Border *)gad->SelectRender; if (bothsame == FALSE) { FreeMem(selbord->XY, 20L); FreeMem(selbord, (long)sizeof(struct Border)); } gad->SelectRender = NULL; flags &= ~SEL_BORDER_TYPE; /* $$$ */ gad->UserData = (APTR)flags; } } } if (bothsame) { /* if the same border was used for both */ /* gadget and select only one should be */ /* freed - but the other stuff must be */ /* updated for both. */ flags &= ~(SEL_BORDER_TYPE | GAD_BORDER_TYPE); gad->UserData = (APTR)flags; gad->GadgetRender = NULL; gad->SelectRender = NULL; } } free_images(gad,freeflag) struct Gadget *gad; long freeflag; { struct Image *imag; long size; long flags; return; flags = (long)gad->UserData; if ((freeflag & GAD_IMAGE_TYPE) == GAD_IMAGE_TYPE) { if (gad->GadgetRender != NULL ) { if ((flags & GAD_IMAGE_TYPE) == GAD_IMAGE_TYPE) { FreeImage(gad->GadgetRender); /* defined in imagfunc.c */ gad->GadgetRender = NULL; flags &= ~GAD_IMAGE_TYPE; /* $$$ */ gad->UserData = (APTR)flags; } /* $$$ */ } } if ((freeflag & SEL_IMAGE_TYPE) == SEL_IMAGE_TYPE) { if (gad->SelectRender != NULL ) { if ((flags & SEL_IMAGE_TYPE) == SEL_IMAGE_TYPE) { FreeImage(gad->SelectRender); gad->SelectRender = NULL; flags &= ~SEL_IMAGE_TYPE; /* $$$ */ gad->UserData = (APTR)flags; } } } if ((gad->GadgetRender != NULL) && (gad->GadgetType == PROPGADGET)){ if ((flags & KNOB_IMAGE_TYPE) == KNOB_IMAGE_TYPE) { /* AUTOKNOB structures have an image struct but no data */ FreeMem(gad->GadgetRender, (long)sizeof(struct Image)); flags &= ~KNOB_IMAGE_TYPE; gad->UserData = (APTR)flags; } } } /*---------------------------------------------------------------- this routine frees the list of intuitexts allocated to a gadget it is recursive ---------------------------------------------------------------- */ free_itxt(text) struct IntuiText *text; { if (text == NULL) return; free_itxt(text->NextText); FreeMem(text, (LONG)sizeof(struct IntuiText)); } /* ----------------------------------------------------------------- free_renders gets rid of allocated images, borders and intuitexts ------------------------------------------------------------------ */ free_renders(gad) struct Gadget *gad; { LONG freeflags; return; freeflags = GAD_BORDER_TYPE | GAD_IMAGE_TYPE | SEL_BORDER_TYPE | SEL_IMAGE_TYPE; free_images(gad,freeflags); /* try to free images first */ free_bords(gad,freeflags); free_itxt(gad->GadgetText); } /*--------------------------------------- freestrgad - Frees the string gadget which is allocated by addgadget, called from gt.c ----------------------------------------*/ freestrgad(gad) struct Gadget *gad; /* gadget pointer */ { struct StringInfo *si; /* StringInfo structure */ /* Get pointer to StringInfo */ si = (struct StringInfo *)gad->SpecialInfo; if (si) { /* De-allocate the Buffer */ if (si->Buffer) FreeMem(si->Buffer, BUFSIZE); /* And the Stringinfo structures */ FreeMem(si, (long)sizeof(struct StringInfo)); } free_renders(gad); /* Frees select render's etc */ } /* IntuiText structures for message autorequesters */ struct IntuiText autotxt1 = {2,1,JAM2,5,5,NULL,NULL,NULL}; struct IntuiText autotxt2 = {2,1,JAM2,5,2,NULL,NULL,NULL}; struct IntuiText autotxt3 = {2,1,JAM2,5,2,NULL,NULL,NULL}; /*============================================================*/ /* autoreq uses the AutoRequest routine to do simple messages */ /* and yes/no requests to the user. */ /*============================================================*/ autoreq(bodtext,postext,negtext) char *bodtext, *postext, *negtext; { long reqwidth, reqheight; SHORT txtlength; BOOL result; txtlength = strlen(bodtext)*10; if (txtlength < 60) txtlength = 60; reqwidth = (LONG)txtlength + 16; reqheight = (LONG)55; autotxt1.IText = (UBYTE *)bodtext; autotxt2.IText = (UBYTE *)postext; autotxt3.IText = (UBYTE *)negtext; result = AutoRequest(w,&autotxt1,&autotxt2,&autotxt3, 0L,0L,reqwidth,reqheight); autotxt1.IText = NULL; autotxt2.IText = NULL; autotxt3.IText = NULL; return(result); } SHAR_EOF fi exit 0 # End of shell archive