home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / amiga / utility / misc / toolmana.lha / ToolManager / Source / prefs / gadget.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-26  |  1.5 KB  |  82 lines

  1. /*
  2.  * gadget.c  V2.0
  3.  *
  4.  * gadget handling
  5.  *
  6.  * (c) 1990-1992 Stefan Becker
  7.  */
  8.  
  9. #include "ToolManagerConf.h"
  10.  
  11. /* Create a gadget list from a GadgetData array */
  12. struct Gadget *CreateGadgetList(struct GadgetData *gdata, ULONG maxgad)
  13. {
  14.  struct Gadget *gl,*g;
  15.  
  16.  /* Create GadTools gadget context */
  17.  gl=NULL;
  18.  if (g=CreateContext(&gl)) {
  19.   struct GadgetData *gd=gdata;
  20.   ULONG i;
  21.  
  22.   for (i=0; i<maxgad; i++, gd++) {
  23.  
  24.    DEBUG_PRINTF("i: %ld\n",i);
  25.  
  26.    /* Set NewGadget values */
  27.    NewGadget.ng_LeftEdge=gd->left;
  28.    NewGadget.ng_TopEdge=gd->top;
  29.    NewGadget.ng_Width=gd->width;
  30.    NewGadget.ng_Height=gd->height;
  31.    NewGadget.ng_GadgetText=gd->name;
  32.    NewGadget.ng_GadgetID=i;
  33.    NewGadget.ng_Flags=gd->flags;
  34.  
  35.    /* Create gadget */
  36.    if (!(g=CreateGadgetA(gd->type,g,&NewGadget,gd->tags))) break;
  37.  
  38.    /* Save gadget pointer */
  39.    gd->gadget=g;
  40.   }
  41.  
  42.   /* All OK. */
  43.   if (g) return(gl);
  44.  
  45.   /* Couldn't create a gadget */
  46.   FreeGadgets(gl);
  47.  }
  48.  
  49.  /* Call failed */
  50.  return(NULL);
  51. }
  52.  
  53. /* Disable a gadget */
  54. void DisableGadget(struct Gadget *g, struct Window *w, BOOL disable)
  55. {
  56.  GT_SetGadgetAttrs(g,w,NULL,GA_Disabled,disable,TAG_DONE);
  57. }
  58.  
  59. /* Duplicate a string gadget buffer */
  60. char *DuplicateBuffer(struct Gadget *gadget)
  61. {
  62.  char *buf=((struct StringInfo *) gadget->SpecialInfo)->Buffer;
  63.  ULONG len=strlen(buf);
  64.  
  65.  /* Buffer not empty? */
  66.  if (len) {
  67.   char *s;
  68.  
  69.   /* Allocate memory for new string */
  70.   if (s=malloc(len+1)) {
  71.    /* Copy string */
  72.    strcpy(s,buf);
  73.    return(s);
  74.   } else
  75.    /* Couldn't allocate memory */
  76.    return(-1);
  77.  }
  78.  
  79.  /* Buffer empty */
  80.  return(NULL);
  81. }
  82.