[comp.sys.amiga] First 3 changes

crunch@well.UUCP (John Draper) (12/29/86)

                       EGAD CHANGES
                       ------------
		       
  There have been TWO Official changes I made to Egad.    All of my changes
will reflect from the Fish disk 46 as the BASE.

  All changes will be numbered,  so if anyone needs to refer to a specific 
change,  Please use THESE numbers to reflect them.    The following changes
fixed one bug, and added a new and useful feature.


Change #1 - Fixes a problem when using Boolean gadgets,  where the area
described by the image was shorter than it should be.    Thus Boolean 
gadgets had smaller than normal image sizes.   The change is in "men.c"
module.

 ----------------------------  OLD PIECE ------------------------------
            case SET_IMAG_BORD: /* Add GadgetRender */
                       if (SelectedGadget == NULL) {
                            autoreq(
                          "First click on the gadget you want to add the
imageto.",
                                        " 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;   /* This is NOT correct */
 *****>>           wid -= 8;   /* And here,  so delete both these lines */
 
                   if (SelectedGadget->GadgetType == PROPGADGET) {
                      pi = (struct PropInfo *)SelectedGadget->SpecialInfo;
                      if ((pi->Flags & FREEHORIZ) == FREEHORIZ) wid >>= 2;
                      if ((pi->Flags & FREEVERT)  == FREEVERT)  hgt >>= 2;
                   }

 ----------------------- END OLD PORTION ---------------------------

   The following code should be substituted and replace the code listed
 above.

 ------------------------- NEW PORTION -----------------------------
 
            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 */
                   if (SelectedGadget->GadgetType == PROPGADGET) {
 
 ****>>               /* ### JD - Moved "wid" & "hgt" tweak here */
 ****>>               wid -= 8;   hgt -= 3;
                      pi = (struct PropInfo *)SelectedGadget->SpecialInfo;
                      if ((pi->Flags & FREEHORIZ) == FREEHORIZ) wid >>= 2;
                      if ((pi->Flags & FREEVERT)  == FREEVERT)  hgt >>= 2;
                   }

------------------------ END NEW PORTION --------------------------


Change #2  - As I fiddled with Egad,   I noticed that somehow,  I had used
the same name somewhere,  and found that the compiler was getting errors.
So,  I modified the "Set Gadget Name" menu item in the "Utilities" menu
so that if a gadget already is named,  just select it,  them pull down
"Set Gadget Name",  and the name appears in the requester box,   you can
then change the name,  then press OK,  and the gadget name is changed.
Otherwise,  there is NO way to retrieve the names unless you "save as
source", then search for duplicate names.     This change is in the
"men.c" module.

-------------------------- OLD PORTION ---------------------------

           case SET_GAD_NAME:  /* $$$ Open Requester, get name */
                            si = nam_info();
                            *si->Buffer = '\0';
                            si->BufferPos = 0;
                            str = getrname("Enter Gadget name");
                            if (str == NULL) {
                                SelectedGadget = NULL;
                                break;
                            }
                            strcpy(names[curgad], str);
                            gadnames[curgad] = names[curgad];
                            break;

----------------------- END OF OLD PORTION ----------------------

    Should be replaced with the following portion.
    
-------------------------- NEW PORTION --------------------------

           case SET_GAD_NAME:  /* $$$ Open Requester, get name */
 
              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 (!get_req_name("Enter Gadget Name", names[curgad])) {
                  SelectedGadget = NULL;
              }
              break;

-------------------------- END OF NEW PORTION ------------------------

   This concludes Changes #1 and #2,  the ONLY official changes currently
made to EGAD.    If you have made any changes that corrects stupid errors
on our part,   or just plain old bugs,    Please mail me a copy of the
"changed module" along with a DIFF of your changes Vs the Fish #46 BASE
file,   I'll make sure everyone gets it,  and do the integrating.


Thanx.....
Crunch - Programmers Network 
"A global village of programmers"

UUCP:  ihnp4!ptsfa!well!crunch
WELL:  crunch
BIX: crunch
CIS: 76703,4322  <-- At least for now



Change #3
---------
   
   This change fixes bugs #11 & 12..  Where there was a problem when you
try and change IntuiText after saving and getting the Gadget set.

   These changes are in the gadio.c module.    And are as follows:
   
--------------------- OLD portion of PutItext() ------------------

   while (anIText != NULL) {
        /* Start by writing structure into file. */
        Write(fd, (char *)anIText, (long)sizeof(struct IntuiText));
 
        /* If non-system font, save font attributes next */
        if (anIText->ITextFont != NULL) /* gonna have to store a structure */
            Write(fd, (APTR) anIText->ITextFont, (long)sizeof(struct TextAttr));
 
        /* Write the text now.  Read function will read up to zero-byte to
           get the whole string. */
        putString(anIText->IText, fd);
 
        /* Do it again, if there's more text following... */
        anIText = anIText->NextText;
    }

--------------------- NEW portion of Putitext() -------------------

   while (anIText != NULL) {
        /* Start by writing structure into file. */
        Write(fd, (char *)anIText, (long)sizeof(struct IntuiText));
 
        /* If non-system font,  save INDEX to the font */
 
        if (anIText->ITextFont != NULL) { /* gonna have to store a structure */
           for(fontnum=0; anIText->ITextFont != TxtFonts[fontnum]; fontnum++);
 
            Write(fd, &fontnum, (long)sizeof(fontnum));
 
        } else anIText->ITextFont = -1;
        /* Write the text now.  Read function will read up to zero-byte to
           get the whole string. */
        putString(anIText->IText, fd);
 
        /* Do it again, if there's more text following... */
        anIText = anIText->NextText;
    }

---------------------- OLD portion of getitext() --------------------

    do {
        /* Read structure from file. */
        Read(fd, anIText, (long)sizeof(struct IntuiText));
 
        /* If non-system font used, get proper font structure. */
        if (anIText->ITextFont != NULL) {
            anIText->ITextFont = (struct TextAttr *)
                AllocRemember(rememberBase,
                  (long)sizeof(struct TextAttr),CLRMEM);
            Read(fd, anIText->ITextFont, (long)sizeof(struct TextAttr));
            /* added by RRL - ITextFont is another pointer */
            anIText->ITextFont->ta_Name = (STRPTR)def_font;
        }
        /* Read the text now.  Read up to (and including) zero-byte. */
        anIText->IText = getString(fd,0L);
        /* Do it again, if there's more text following... */
        if (anIText->NextText != NULL) {
           anIText->NextText = (struct IntuiText *)
              AllocRemember(rememberBase,
                (long)sizeof(struct IntuiText),CLRMEM);
           anIText = anIText->NextText; /* this was missing - RRL */
        }
        else
            done = TRUE;
    } while (! done);


---------------------- New portion of getitext() ---------------------

    do {
        /* Read structure from file. */
        Read(fd, anIText, (long)sizeof(struct IntuiText));
 
        /* If non-system font used, get proper font structure. */
 
/* NEW VERSION $$$ */
        if (anIText->ITextFont != -1L) {
            Read(fd, &fontnum, (long)sizeof(fontnum));
            anIText->ITextFont = TxtFonts[fontnum];
/* END OF NEW VERSION */
 
/* OLD VERSION - Activate THIS part, and De-activate above portion
   to convert old files,  then save it,  and new format will be written
 
        if (anIText->ITextFont != NULL) {
            anIText->ITextFont = (struct TextAttr *)
                AllocRemember(rememberBase,
                  (long)sizeof(struct TextAttr),CLRMEM);
            Read(fd, anIText->ITextFont, (long)sizeof(struct TextAttr));
END OF OLD VERSION */
 
            /* added by RRL - ITextFont is another pointer */
            anIText->ITextFont->ta_Name = (STRPTR)def_font;
        }
        /* Read the text now.  Read up to (and including) zero-byte. */
        anIText->IText = getString(fd,0L);
        /* Do it again, if there's more text following... */
        if (anIText->NextText != NULL) {
           anIText->NextText = (struct IntuiText *)
              AllocRemember(rememberBase,
                (long)sizeof(struct IntuiText),CLRMEM);
           anIText = anIText->NextText; /* this was missing - RRL */
        }
        else
            done = TRUE;
    } while (! done);

------------------------ END OF CHANGE 3 -------------------------

CHANGE #4
---------
   This is a new cludge so you can use your gadgets with requesters
instead of windows.    I basically used the un_implemented  "Utility"
menu choices to set an internal flag "isreq" which will set the
REQGADGET flag on all subsequent gadgets created.    When the source
is printed out,  the flag is set.    These changes affect "men.c"
and "pgad.c".

---------------------- men.c OLD CODE ---------------------

/*================== 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 */


A portion of Do_menu (OLD):

           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;
			    
			    
Another portion of OLD Do-menu:

           case ADD_MUT_EXCLUD: /* Add Mutual exclude */
                            dispgad(gads[0]);
                            break;
 
           case ADD_USR_ID: /* Add User ID value */
                            trap();      /* Debug trap */
                            break;



----------------------- men.c NEW CODE -------------------

/*================== 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 */
int isreq = FALSE;          /* Set TRUE if gadgets are for requesters */
 
    (ADDED "isreq" as shown above )

New portion of Do_menu:
    
           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);
                            if (isreq)   /* $$$ */
                               testgad.Flags |= REQGADGET;
                            linkgadgets();
             SelectedGadget = NULL;
                            break;
 

New portion of Do_menu:

           case ADD_MUT_EXCLUD: /* Add Mutual exclude */
                            isreq = TRUE;
                            printf("Gadgets are for requesters...\n");
                            break;
 
           case ADD_USR_ID: /* Add User ID value */
                            isreq = FALSE;
                            printf("Gadgets are for windows....\n");
                            break;


Now the new and old changes to pgad.c:


----------------------OLD pgad.c------------------------

/* external variables */
 
extern char *gadnames[];
extern int nextgad;
extern struct Gadget *gads[];
extern char gadimage [MAX_PROPINFOS] [NAM_SIZ];
extern char selectimage [MAX_PROPINFOS] [NAM_SIZ];
extern struct IntuiText *ITMap[]; /* Pointers to the Gad's Intuitexts */


Old disp_gadget():


    fprintf(fd, ",\n");     /* put comma at end */
    fprintf(fd, "  /* GadgetType */\n");
    switch (gad->GadgetType) {
        case BOOLGADGET: fprintf(fd, "  BOOLGADGET,\n"); break;
        case PROPGADGET: fprintf(fd, "  PROPGADGET,\n"); break;
        case STRGADGET : fprintf(fd, "  STRGADGET,\n"); break;
    }                    /* $$$ */
 
    fprintf(fd, "  ");
 
----------------------- NEW pgad.c------------------------

/* external variables */
 
extern char *gadnames[];
extern int nextgad;
extern int isreq;
extern struct Gadget *gads[];
extern char gadimage [MAX_PROPINFOS] [NAM_SIZ];
extern char selectimage [MAX_PROPINFOS] [NAM_SIZ];
extern struct IntuiText *ITMap[]; /* Pointers to the Gad's Intuitexts */


Changes to disp_gadget():

    fprintf(fd, ",\n");     /* put comma at end */
    fprintf(fd, "  /* GadgetType */\n");
    if (isreq) {
       fprintf(fd, "  REQGADGET |");
    }
    switch (gad->GadgetType) {
        case BOOLGADGET: fprintf(fd, "  BOOLGADGET,\n"); break;
        case PROPGADGET: fprintf(fd, "  PROPGADGET,\n"); break;
        case STRGADGET : fprintf(fd, "  STRGADGET,\n"); break;
    }                    /* $$$ */
 
    fprintf(fd, "  ");