/*
 *  CREATESTRGADGET.C
 */

#include "newlook.h"

struct Gadget *CreateStrGadget(x,y,w, n, id)
SHORT x,y,w,n;
USHORT id;
{
  struct Gadget *g;
  struct StringInfo *si;

  ULONG UserHandle= SetNewLookHandle(PRIVATE_HANDLE);

  if(g= (struct Gadget *)SmartAllocate(GADGETSIZE))
  {
    if(si= (struct StringInfo *)SmartAllocate(STRINGINFOSIZE))
    {
      if(si->Buffer= (UBYTE *)SmartAllocate(n*sizeof(UBYTE)))
      {
        if(si->UndoBuffer= (UBYTE *)SmartAllocate(n*sizeof(UBYTE)))
        { si->BufferPos    = 0;
          si->MaxChars     = n;
          si->DispPos      = 0;

          g->NextGadget    = (struct Gadget *)NULL;
          g->LeftEdge      = x;
          g->TopEdge       = y;
          g->Width         = w;
          g->Height        = 8; /* looks best w/ topaz8 */
          g->Flags         = GADGHCOMP;
          g->Activation    = GADGIMMEDIATE|RELVERIFY;
          g->GadgetType    = STRGADGET;
          g->GadgetRender  = (APTR)NULL;
          g->SelectRender  = (APTR)NULL;
          g->GadgetText    = (struct IntuiText *)NULL;
          g->MutualExclude = (LONG)0L;
          g->SpecialInfo   = si;
          g->GadgetID      = id;
          g->UserData      = (APTR)NULL;

          if(AddGBorder(g,NULL))
          {
            MakePrivateHandlePublic(UserHandle);
            return g;   /* --- control flow ends here --- */
          }
        }
      }
    }
  }
  SmartFreeAll(PRIVATE_HANDLE);
  (void)SetNewLookHandle(UserHandle);
  return (struct Gadget *)NULL;
}
