home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 13 / AACD13.ISO / AACD / Resources / System / BoingBag1 / Contributions / Workbench / RexxArpLib3p6 / src / sreq / simpgad.c < prev    next >
C/C++ Source or Header  |  1998-06-17  |  16KB  |  791 lines

  1. /** simpgad.c
  2.  *
  3.  *   Simple Gadget routines.
  4.  *
  5. **/
  6. #include <exec/types.h>
  7. #include <exec/io.h>
  8. #include <exec/memory.h>
  9. #include <libraries/dos.h>
  10. #include <intuition/intuition.h>
  11. #include <intuition/intuitionbase.h>
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <string.h>
  15. #include <functions.h>
  16.  
  17. #include <simpreq.h>
  18. #include "simpdefs.h"
  19.  
  20. extern struct IntuitionBase *IntuitionBase;
  21. extern struct GfxBase *GfxBase;
  22.  
  23. /**
  24.  *
  25.  *
  26.  *    MakeBox(1.0)    ARP Programmers Manual   MakeBox(1.0)
  27.  *
  28.  *
  29.  *    NAME
  30.  *   MakeBox      -- Make a box and shadow Border.
  31.  *
  32.  *    SYNOPSIS
  33.  *   struct Border *MakeBox(pen1, pen2, dm, xo, yo, x1, y1, x2, y2)
  34.  *
  35.  *    FUNCTION
  36.  *   This function is used to create a Border structure to draw a box
  37.  *         and its shadow.
  38.  *
  39.  *    INPUTS
  40.  *   int pen1                  Color for the box pen
  41.  *   int pen2                  Color for the shadow pen
  42.  *   int dm                    Drawing mode
  43.  *   int xo, yo                Offsets for the left upper corner
  44.  *   int x1, y1                left upper corner
  45.  *   int x2, y2                right lower corner
  46.  *
  47.  *    RESULT
  48.  *   Pointer to Border structure, NULL on failure.
  49.  *
  50.  *    ADDITIONAL CONSIDERATIONS
  51.  *   This routine assumes the necessary libraries to be open.
  52.  *
  53.  *    BUGS
  54.  *   None reported sofar.
  55.  *
  56.  *    AUTHOR
  57.  *   W.G.J. Langeveld (WGL)
  58.  *
  59.  *
  60.  *
  61. **/
  62. #define BSIZE ((long) sizeof(struct Border))
  63. #define GSIZE ((long) sizeof(struct Gadget))
  64. #define SISIZE ((long) sizeof(struct StringInfo))
  65. #define XYSIZE 20L
  66.     
  67. /*                          pen1, pen2, dm, xo, yo, x1, y1, x2, y2) */
  68. struct Border *MakeBox ( UBYTE pen1, UBYTE pen2, UBYTE dm, WORD xo, WORD yo, WORD x1, WORD y1, WORD x2, WORD y2 )
  69. {
  70.     SHORT *xy1 = NULL, *xy2 = NULL;
  71.     struct Border *b1 = NULL, *b2 = NULL;
  72.     
  73.     b1 = AllocMem(BSIZE, MEMF_CLEAR);
  74.     if (b1 == NULL)
  75.         goto cleanup;
  76.     
  77.     b2 = AllocMem(BSIZE, MEMF_CLEAR);
  78.     if (b2 == NULL)
  79.         goto cleanup;
  80.     
  81.     xy1 = AllocMem(XYSIZE, 0L);
  82.     if (xy1 == NULL)
  83.         goto cleanup;
  84.     
  85.     xy2 = AllocMem(XYSIZE, 0L);
  86.     if (xy2 == NULL)
  87.         goto cleanup;
  88.     
  89.     b1->NextBorder = b2;
  90.     b1->DrawMode   = dm;
  91.     b1->XY         = xy1;
  92.     b1->LeftEdge   = xo;
  93.     b1->TopEdge    = yo;
  94.     b1->Count      = 5;
  95.     b1->FrontPen   = pen1;
  96.     
  97.     if (IntuitionBase->LibNode.lib_Version >= 36) 
  98.     {
  99.         xy1[0] = x2 - 1;
  100.         xy1[1] = y1;
  101.         xy1[2] = x1;
  102.         xy1[3] = y1;
  103.         xy1[4] = x1;
  104.         xy1[5] = y2;
  105.         xy1[6] = x1 + 1;
  106.         xy1[7] = y2 - 1;
  107.         xy1[8] = x1 + 1;
  108.         xy1[9] = y1;
  109.     }
  110.     else
  111.     {
  112.         xy1[0] = x1;
  113.         xy1[1] = y1;
  114.         xy1[2] = x1;
  115.         xy1[3] = y2;
  116.         xy1[4] = x2;
  117.         xy1[5] = y2;
  118.         xy1[6] = x2;
  119.         xy1[7] = y1;
  120.         xy1[8] = x1;
  121.         xy1[9] = y1;
  122.     }
  123.     
  124.     b2->NextBorder = NULL;
  125.     b2->DrawMode   = dm;
  126.     b2->XY         = xy2;
  127.     b2->LeftEdge   = xo;
  128.     b2->TopEdge    = yo;
  129.     b2->Count      = 5;
  130.     b2->FrontPen   = pen2;
  131.     
  132.     if (IntuitionBase->LibNode.lib_Version >= 36) 
  133.     {
  134.         xy2[0] = x1 + 1;
  135.         xy2[1] = y2;
  136.         xy2[2] = x2;
  137.         xy2[3] = y2;
  138.         xy2[4] = x2;
  139.         xy2[5] = y1;
  140.         xy2[6] = x2 - 1;
  141.         xy2[7] = y1 + 1;
  142.         xy2[8] = x2 - 1;
  143.         xy2[9] = y2;
  144.     }
  145.     else
  146.     {
  147.         xy2[0] = x1 + 2;
  148.         xy2[1] = y2 + 1;
  149.         xy2[2] = x2 + 2;
  150.         xy2[3] = y2 + 1;
  151.         xy2[4] = x2 + 2;
  152.         xy2[5] = y1 + 1;
  153.         xy2[6] = x2 + 1;
  154.         xy2[7] = y1 + 1;
  155.         xy2[8] = x2 + 1;
  156.         xy2[9] = y2 + 1;
  157.     }
  158.     return(b1);
  159.     
  160.     cleanup:
  161.     if (b1)
  162.         FreeMem(b1, BSIZE);
  163.     if (b2)
  164.         FreeMem(b2, BSIZE);
  165.     if (xy1)
  166.         FreeMem(xy1, XYSIZE);
  167.     if (xy2)
  168.         FreeMem(xy2, XYSIZE);
  169.     
  170.     return(NULL);
  171. }
  172.  
  173. /**
  174.  *
  175.  *
  176.  *    FreeBox(1.0)    ARP Programmers Manual   FreeBox(1.0)
  177.  *
  178.  *
  179.  *    NAME
  180.  *   FreeBox      -- Free an IntuiText structure.
  181.  *
  182.  *    SYNOPSIS
  183.  *   struct Border *FreeBox(b)
  184.  *
  185.  *    FUNCTION
  186.  *   This function is used to free a list of Border structures.
  187.  *
  188.  *    INPUTS
  189.  *   struct Border *b First in a linked list of Borders to be
  190.  *    freed.
  191.  *
  192.  *    RESULT
  193.  *   Guaranteed NULL.
  194.  *
  195.  *    ADDITIONAL CONSIDERATIONS
  196.  *   This routine assumes the necessary libraries to be open.
  197.  *
  198.  *    BUGS
  199.  *   None reported sofar.
  200.  *
  201.  *    AUTHOR
  202.  *   W.G.J. Langeveld (WGL)
  203.  *
  204.  *
  205.  *
  206. **/
  207. struct Border *FreeBox( struct Border *b )
  208. {
  209.     struct Border *b1 = NULL;
  210.     
  211.     while (b) 
  212.     {
  213.         b1 = b->NextBorder;
  214.         
  215.         if (b->XY)
  216.             FreeMem(b->XY, XYSIZE);
  217.         FreeMem(b, BSIZE);
  218.         b = b1;
  219.     }
  220.     
  221.     return(NULL);
  222. }
  223.  
  224.  
  225. /**
  226.  *
  227.  *
  228.  *    MakeSIText(1.0)    ARP Programmers Manual   MakeSIText(1.0)
  229.  *
  230.  *
  231.  *    NAME
  232.  *   MakeSIText      -- Make a linked list of IntuiText structures.
  233.  *
  234.  *    SYNOPSIS
  235.  *   struct IntuiText *MakeSIText(pen1, pen2, dm, xo, yo, text)
  236.  *
  237.  *    FUNCTION
  238.  *   This function is used to create a IntuiText structures given some
  239.  *         text.
  240.  *
  241.  *    INPUTS
  242.  *   int pen1                  Color for the front pen
  243.  *   int pen2                  Color for the back pen
  244.  *   int dm                    Drawing mode
  245.  *   int xo, yo                Offsets for the left upper corner
  246.  *   UBYTE *text               The actual text.
  247.  *
  248.  *    RESULT
  249.  *   Pointer to IntuitText structure, NULL on failure.
  250.  *
  251.  *    ADDITIONAL CONSIDERATIONS
  252.  *   This routine assumes the necessary libraries to be open.
  253.  *   If there are embedded linefeeds in the string, multiple IntuiText
  254.  *   structures will be created and added to the list. The individual
  255.  *   IntuiText's will be spaced vertically.
  256.  *
  257.  *    BUGS
  258.  *   None reported sofar.
  259.  *
  260.  *    AUTHOR
  261.  *   W.G.J. Langeveld (WGL)
  262.  *
  263.  *
  264.  *
  265. **/
  266. #define ISIZE ((long) sizeof(struct IntuiText))
  267.     
  268. struct IntuiText *MakeSIText( UBYTE pen1, UBYTE pen2, UBYTE dm, WORD xo, WORD yo, UBYTE *text)
  269. {
  270.     struct IntuiText *i1 = NULL, *i2 = NULL, *it = NULL;
  271.     UBYTE *t1 = NULL, *t2 = NULL;
  272.     ULONG *foo;
  273.     unsigned int n = 0;
  274.     int l = 0;
  275.     
  276.     t1 = text;
  277.     while (t1) 
  278.     {
  279.         t2 = strchr(t1, '\n');
  280.         
  281.         if (t2)
  282.             n = t2 - t1;
  283.         else
  284.             n = strlen(t1);
  285.         
  286.         i2 = AllocMem(ISIZE, MEMF_CLEAR);
  287.         if (i2 == NULL)
  288.             goto cleanup;
  289.         
  290.         if (i1) 
  291.         {
  292.             i1->NextText = i2;
  293.             i1 = i2;
  294.         }
  295.         else
  296.         {
  297.             it = i1 = i2;
  298.         }
  299.         
  300.         i1->FrontPen   = pen1;
  301.         i1->BackPen    = pen2;
  302.         i1->DrawMode   = dm;
  303.         i1->LeftEdge   = xo;
  304.         i1->TopEdge    = yo + LINEHEIGHT * l;
  305.         i1->ITextFont  = Topaz80Equiv();
  306.         i1->NextText   = NULL;
  307.         
  308. //        i1->IText      =  malloc( n + 1 );
  309.     
  310.         foo            = (ULONG *) AllocMem( (ULONG) (n + 5), MEMF_CLEAR );
  311.         *foo++         = (ULONG) (n + 5);
  312.         i1->IText      = (UBYTE *) foo;
  313.         if (i1->IText == NULL)
  314.             goto cleanup;
  315.         strncpy(i1->IText, t1, (size_t) n);
  316.         i1->IText[n] = '\0';
  317.         
  318.         if (t2 == NULL)
  319.             break;
  320.         t1 = t2;
  321.         t1++;
  322.         l++;
  323.     }
  324.     
  325.     return(it);
  326.     
  327.     cleanup:
  328.     FreeSIText(it);
  329.     
  330.     return(NULL);
  331. }
  332.  
  333.  
  334. /**
  335.  *
  336.  *
  337.  *    FreeSIText(1.0)    ARP Programmers Manual   FreeSIText(1.0)
  338.  *
  339.  *
  340.  *    NAME
  341.  *   FreeSIText      -- Free an IntuiText structure.
  342.  *
  343.  *    SYNOPSIS
  344.  *   struct IntuiText *FreeSIText(it)
  345.  *
  346.  *    FUNCTION
  347.  *   This function is used to free a list of IntuiText structures.
  348.  *
  349.  *    INPUTS
  350.  *   struct IntuiText *it First in a linked list of IntuiText's to be
  351.  *    freed.
  352.  *
  353.  *    RESULT
  354.  *   Guaranteed NULL.
  355.  *
  356.  *    ADDITIONAL CONSIDERATIONS
  357.  *   This routine assumes the necessary libraries to be open.
  358.  *
  359.  *    BUGS
  360.  *   None reported sofar.
  361.  *
  362.  *    AUTHOR
  363.  *   W.G.J. Langeveld (WGL)
  364.  *
  365.  *
  366.  *
  367. **/
  368. struct IntuiText *FreeSIText( struct IntuiText *it )
  369. {
  370.     struct IntuiText *it1 = NULL;
  371.     ULONG             *foo = NULL;
  372.     
  373.     while (it) 
  374.     {
  375.         if (it->IText)
  376.         {
  377.             foo = (ULONG *) it->IText;
  378.             foo--;
  379.             FreeMem( foo, *foo );
  380.         }
  381.         
  382.         it1 = it->NextText;
  383.         FreeMem(it, ISIZE);
  384.         it = it1;
  385.     }
  386.     return(NULL);
  387. }
  388.  
  389.  
  390. /**
  391.  *
  392.  *
  393.  *    SITextLength(1.0)    ARP Programmers Manual   SITextLength(1.0)
  394.  *
  395.  *
  396.  *    NAME
  397.  *   SITextLength      -- Determine width of list of IntuiText structures.
  398.  *
  399.  *    SYNOPSIS
  400.  *   int SITextLength(it)
  401.  *
  402.  *    FUNCTION
  403.  *   This function is used to find the horizontal size of the
  404.  *   enclosing box of a list of IntuiText structures.
  405.  *
  406.  *    INPUTS
  407.  *   struct IntuiText *it First in a linked list of IntuiText's to be
  408.  *    measured.
  409.  *
  410.  *    RESULT
  411.  *   Horizontal size.
  412.  *
  413.  *    ADDITIONAL CONSIDERATIONS
  414.  *   This routine assumes the necessary libraries to be open.
  415.  *
  416.  *    BUGS
  417.  *   None reported sofar.
  418.  *
  419.  *    AUTHOR
  420.  *   W.G.J. Langeveld (WGL)
  421.  *
  422.  *
  423.  *
  424. **/
  425. WORD SITextLength( struct IntuiText *it )
  426. {
  427.     WORD hsize = 0, temp = 0;
  428.     
  429.     while (it) 
  430.     {
  431.         if ((temp = it->LeftEdge + (strlen(it->IText) << 3)) > hsize)
  432.             hsize = temp;
  433.         it = it->NextText;
  434.     }
  435.     return(hsize);
  436. }
  437.  
  438.  
  439. /**
  440.  *
  441.  *
  442.  *    SITextHeight(1.0)    ARP Programmers Manual   SITextHeight(1.0)
  443.  *
  444.  *
  445.  *    NAME
  446.  *   SITextHeight      -- Determine height of list of IntuiText structures.
  447.  *
  448.  *    SYNOPSIS
  449.  *   int SITextHeight(it)
  450.  *
  451.  *    FUNCTION
  452.  *   This function is used to determine the height of a limked list of
  453.  *   IntuiText structures
  454.  *
  455.  *    INPUTS
  456.  *   struct IntuiText *it First in a linked list of IntuiText's to be
  457.  *    freed.
  458.  *
  459.  *    RESULT
  460.  *   Height.
  461.  *
  462.  *    ADDITIONAL CONSIDERATIONS
  463.  *   This routine assumes the necessary libraries to be open.
  464.  *   Also, it assumes all text is in the positive direction.
  465.  *
  466.  *    BUGS
  467.  *   None reported sofar.
  468.  *
  469.  *    AUTHOR
  470.  *   W.G.J. Langeveld (WGL)
  471.  *
  472. **/
  473. WORD SITextHeight( struct IntuiText *it )
  474. {
  475.     WORD vsize = 0, temp = 0;
  476.     
  477.     while (it) 
  478.     {
  479.         if ((temp = it->TopEdge + it->ITextFont->ta_YSize) > vsize)
  480.             vsize = temp;
  481.         it = it->NextText;
  482.     }
  483.     return(vsize);
  484. }
  485.  
  486.  
  487. /**
  488.  *    MakeSStrGad(1.0)    ARP Programmers Manual   MakeSStrGad(1.0)
  489.  *
  490.  *
  491.  *    NAME
  492.  *   MakeSStrGad   -- Make a simple string gadget
  493.  *
  494.  *    SYNOPSIS
  495.  *   StrGadget = MakeSStrGad(s, p1, p2, x, y, width, id, ec)
  496.  *
  497.  *    FUNCTION
  498.  *   This function creates asimple string gadget. You still need to add
  499.  *   it to the window and refresh it.
  500.  *
  501.  *    INPUTS
  502.  *   char *s     Pointer to a string for the string gadget
  503.  *   int p1     Pen number for the gadget border
  504.  *   int p2     Pen number for the gadget border's shadow
  505.  *   int x      Top left x coordinate of gadget
  506.  *   int y      Top left y coordinate of gadget
  507.  *   int width     Width of gadget
  508.  *   int id     Gadget id
  509.  *
  510.  *    OUTPUTS
  511.  *   int *ec     Error code
  512.  *
  513.  *    RESULT
  514.  *   struct Gadget *StrGadget   A pointer to the Gadget structure.
  515.  *
  516.  *    ADDITIONAL CONSIDERATIONS
  517.  *   This routine assumes the necessary libraries to be open.
  518.  *   Use FreeSimpGad() to deallocate all allocated structures.
  519.  *
  520.  *    BUGS
  521.  *   None reported sofar.
  522.  *
  523.  *    AUTHOR
  524.  *   W.G.J. Langeveld (WGL)
  525.  *
  526.  *
  527. **/
  528. struct Gadget *MakeSStrGad(UBYTE *s, UBYTE p1, UBYTE p2, WORD x, WORD y, WORD width, WORD id, ULONG *ec)
  529. {
  530.     UBYTE *undobuffer = NULL, *SREQSIBuff = NULL;
  531.     struct Gadget *SREQString = NULL;
  532.     struct StringInfo *SREQSInfo = NULL;
  533.     WORD wd, xoff, yoff, vsize, tht;
  534.     
  535.     if (width > 0) 
  536.     {
  537.         wd    = width;
  538.         xoff  = -2;
  539.         yoff  = -1;
  540.         vsize =  9;
  541.         tht   =  8;
  542.     }
  543.     else
  544.     {
  545.         wd    = -width - 4;
  546.         x    += 4;
  547.         xoff  = -4;
  548.         y    -= 1;
  549.         yoff  = -2;
  550.         vsize = 11;
  551.         tht   = 10;
  552.     }
  553.     /*
  554.      *   Get the string gadget structure.
  555.      */
  556.     SREQString = (struct Gadget *) AllocMem(GSIZE, MEMF_CLEAR);
  557.     if (SREQString == NULL) 
  558.     {
  559.         *ec = SR_OUTOFMEMORY;
  560.         return(NULL);
  561.     }
  562.     /*
  563.      *   Get a StringInfo structure
  564.      */
  565.     SREQSInfo = (struct StringInfo *) AllocMem(SISIZE, MEMF_CLEAR);
  566.     if (SREQSInfo == NULL) 
  567.     {
  568.         *ec = SR_OUTOFMEMORY;
  569.         return(FreeSimpGad(SREQString));
  570.     }
  571.     SREQString->SpecialInfo = (APTR) SREQSInfo;
  572.     /*
  573.      *   Give it an UndoBuffer
  574.      */
  575.     undobuffer = (UBYTE *) AllocMem(BUFLEN, MEMF_CLEAR);
  576.     if (undobuffer == NULL) 
  577.     {
  578.         *ec = SR_OUTOFMEMORY;
  579.         return(FreeSimpGad(SREQString));
  580.     }
  581.     SREQSInfo->UndoBuffer = undobuffer;
  582.     /*
  583.      *   Give it a string buffer and copy the default string into it.
  584.      */
  585.     SREQSIBuff = (UBYTE *) AllocMem(BUFLEN, MEMF_CLEAR);
  586.     if (SREQSIBuff == NULL) 
  587.     {
  588.         *ec = SR_OUTOFMEMORY;
  589.         return(FreeSimpGad(SREQString));
  590.     }
  591.     SREQSInfo->Buffer   = SREQSIBuff;
  592.     SREQSInfo->MaxChars = BUFLEN;
  593.     
  594.     strcpy(SREQSIBuff, s);
  595.     
  596.     SREQString->LeftEdge     = x;
  597.     SREQString->TopEdge      = y;
  598.     SREQString->Width        = wd;
  599.     SREQString->Height       = tht;
  600.     SREQString->Activation   = RELVERIFY;
  601.     SREQString->GadgetType   = STRGADGET;
  602.     SREQString->GadgetID     = id;
  603.     /*
  604.      *   Give it the "look and feel"...
  605.      */
  606.     if (IntuitionBase->LibNode.lib_Version >= 36) 
  607.     {
  608.         SREQString->GadgetRender = ( APTR )    /* ( struct Border * ) */
  609.         MakeBox ( p2, p1, (int) JAM1, xoff, yoff, 0, 0, wd + 3, vsize );
  610.         if (  SREQString->GadgetRender == NULL) 
  611.         {
  612.             *ec = SR_OUTOFMEMORY;
  613.             return(FreeSimpGad(SREQString));
  614.         }
  615.         if (width < 0) 
  616.         {
  617.             if (((  (struct Border *) SREQString->GadgetRender)->
  618.                 NextBorder->NextBorder = ( APTR )
  619.             MakeBox(p1, p2, (int) JAM1, -6, -3, 0, 0, wd + 7, 13)) == NULL) 
  620.             {
  621.                 *ec = SR_OUTOFMEMORY;
  622.                 return(FreeSimpGad(SREQString));
  623.             }
  624.         }
  625.     }
  626.     else
  627.     {
  628.         SREQString->GadgetRender =
  629.         (APTR) MakeBox(p1, p2, (int) JAM1, -2, -2, 0, 0, wd + 3, 11);
  630.         if (SREQString->GadgetRender == NULL) 
  631.         {
  632.             *ec = SR_OUTOFMEMORY;
  633.             return(FreeSimpGad(SREQString));
  634.         }
  635.     }
  636.     
  637.     return(SREQString);
  638. }
  639.  
  640. /**
  641.  *    FreeSimpGad(1.0)    ARP Programmers Manual   FreeSimpGad(1.0)
  642.  *
  643.  *
  644.  *    NAME
  645.  *   FreeSimpGad   -- Free a simple gadget
  646.  *
  647.  *    SYNOPSIS
  648.  *   result = FreeSimpGad(Gadget)
  649.  *
  650.  *    FUNCTION
  651.  *   This function frees a simple gadget safely.
  652.  *
  653.  *    INPUTS
  654.  *   struct Gadget *Gadget   A pointer to the Gadget structure.
  655.  *
  656.  *    RESULT
  657.  *   struct Gadget *result      Guaranteed NULL.
  658.  *
  659.  *    ADDITIONAL CONSIDERATIONS
  660.  *   This routine assumes the necessary libraries to be open.
  661.  *   This function HAS to be used after calling MakeSStrGad or
  662.  *   MakeSBoolGad to free up the storage allocated.
  663.  *
  664.  *    BUGS
  665.  *   None reported sofar.
  666.  *
  667.  *    AUTHOR
  668.  *   W.G.J. Langeveld (WGL)
  669.  *
  670.  *
  671. **/
  672. struct Gadget *FreeSimpGad( struct Gadget *g )
  673. {
  674.     register struct StringInfo *SREQSInfo;
  675.     
  676.     if (g) 
  677.     {
  678.         FreeBox(g->GadgetRender);
  679.         FreeSIText(g->GadgetText);
  680.         
  681.         if (g->GadgetType == STRGADGET) 
  682.         {
  683.             SREQSInfo = (struct StringInfo *) g->SpecialInfo;
  684.             if (SREQSInfo) 
  685.             {
  686.                 if (SREQSInfo->Buffer)
  687.                     FreeMem(SREQSInfo->Buffer,     BUFLEN);
  688.                 if (SREQSInfo->UndoBuffer)
  689.                     FreeMem(SREQSInfo->UndoBuffer, BUFLEN);
  690.                 
  691.                 FreeMem(SREQSInfo, SISIZE);
  692.             }
  693.         }
  694.         
  695.         FreeMem(g, GSIZE);
  696.     }
  697.     return(NULL);
  698. }
  699.  
  700.  
  701.  
  702. /**
  703.  *    MakeSBoolGad(1.0)    ARP Programmers Manual   MakeSBoolGad(1.0)
  704.  *
  705.  *
  706.  *    NAME
  707.  *   MakeSBoolGad   -- Make  a simple boolean gadget
  708.  *
  709.  *    SYNOPSIS
  710.  *   BoolGadget = MakeSBoolGad(s, p1, p2, p3, x, y, hslop, vslop,
  711.  *                            id, ec)
  712.  *
  713.  *    FUNCTION
  714.  *   This function creates a simple boolean gadget. You still need to add
  715.  *   it to the window and refresh it.
  716.  *
  717.  *    INPUTS
  718.  *   char *s     Pointer to a string for the gadget text
  719.  *   int p1     Pen number for the gadget border
  720.  *   int p2     Pen number for the gadget border's shadow
  721.  *   int p3     Pen number for the gadget text
  722.  *   int x      Top left x coordinate of gadget
  723.  *   int y      Top left y coordinate of gadget
  724.  *   int hslop     Extra room before and after text of gadget
  725.  *   int vslop     Extra room above and below gadget
  726.  *   int id     Gadget id
  727.  *
  728.  *    OUTPUTS
  729.  *   int *ec     Error code
  730.  *
  731.  *    RESULT
  732.  *   struct Gadget *BoolGadget   A pointer to the Gadget structure.
  733.  *
  734.  *    ADDITIONAL CONSIDERATIONS
  735.  *   This routine assumes the necessary libraries to be open.
  736.  *   Use FreeSimpGad() to free all allocated structures.
  737.  *
  738.  *    BUGS
  739.  *   None reported sofar.
  740.  *
  741.  *    AUTHOR
  742.  *   W.G.J. Langeveld (WGL)
  743.  *
  744.  *
  745. **/
  746. struct Gadget *MakeSBoolGad(UBYTE *s, UBYTE p1, UBYTE p2, UBYTE p3, WORD x, WORD y, WORD hslop, WORD vslop, WORD id, ULONG *ec)
  747. {
  748.     struct Gadget *SREQGadget;
  749.     int width, height;
  750.     
  751.     *ec = 0;
  752.     
  753.     SREQGadget = (struct Gadget *) AllocMem(GSIZE, MEMF_CLEAR);
  754.     if (SREQGadget == NULL) 
  755.     {
  756.         *ec = SR_OUTOFMEMORY;
  757.         return(NULL);
  758.     }
  759.     /*
  760.      *   Add the text
  761.      */
  762.     SREQGadget->GadgetText = MakeSIText(p3, 0, (int) JAM1, hslop, vslop, s);
  763.     
  764.     width  = SITextLength(SREQGadget->GadgetText) + hslop;
  765.     height = SITextHeight(SREQGadget->GadgetText) + vslop;
  766.     
  767.     SREQGadget->LeftEdge     = x;
  768.     SREQGadget->TopEdge      = y;
  769.     SREQGadget->Width        = width;
  770.     SREQGadget->Height       = height;
  771.     SREQGadget->Activation   = RELVERIFY;
  772.     SREQGadget->GadgetType   = BOOLGADGET;
  773.     SREQGadget->GadgetID     = id;
  774.     /*
  775.      *   Give it the "look and feel"...
  776.      */
  777.     SREQGadget->GadgetRender =
  778.     (APTR) MakeBox(p1, p2, (int) JAM1, -2, -1, 0, 0, width + 3, height + 1);
  779.     
  780.     if (SREQGadget->GadgetRender == NULL) 
  781.     {
  782.         *ec = SR_OUTOFMEMORY;
  783.         return(FreeSimpGad(SREQGadget));
  784.     }
  785.     /*
  786.      *   All done, add the gadget
  787.      */
  788.     return(SREQGadget);
  789. }
  790.  
  791.