home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / gui / precog2_1.lha / Precognition2_1 / src / src.lha / Library / IntegerGadget.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-16  |  2.2 KB  |  100 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "IntegerGadget.h"
  4. #include "IntegerGadgetClass.h"
  5. #include "StringGadgetClass.h"
  6. #include "minmax.h"
  7. #ifndef __GNUC__
  8. #include <clib/exec_protos.h>
  9. #include <clib/intuition_protos.h>
  10. #endif
  11. #ifdef __GNUC__
  12. #include <proto/exec.h>
  13. #include <proto/intuition.h>
  14. #endif
  15. #ifdef __SASC
  16. #include <proto/exec.h>
  17. #include <proto/intuition.h>
  18. #endif
  19. #include "amigamem.h"
  20.  
  21.  
  22.  
  23. LONG IntegerGadget_Value( IntegerGadget *self )
  24. {
  25.    LONG selection;
  26.    struct StringInfo *stringinfo;
  27.  
  28.    stringinfo = (StringInfo *) self->g.SpecialInfo;
  29.  
  30.    Forbid();
  31.    sscanf( stringinfo->Buffer, "%d", &selection );
  32.    Permit();
  33.  
  34.    return selection;
  35. }
  36.  
  37. LONG IntegerGadget_SetValue( IntegerGadget *self, LONG selection )
  38. {
  39.    struct StringInfo *stringinfo;
  40.  
  41.    stringinfo = (StringInfo *) self->g.SpecialInfo;
  42.    Forbid();
  43.    sprintf( stringinfo->Buffer, "%d", selection );
  44.    Permit();
  45.  
  46.    return selection;
  47. }
  48.  
  49.  
  50. BOOL IntegerGadget_elaborated = FALSE;
  51.  
  52. struct ValuatorClass IntegerGadget_Class;
  53.  
  54. void IntegerGadgetClass_Init( struct ValuatorClass *class )
  55. {
  56.    StringGadgetClass_Init( class );
  57.    class->isa          = StringGadgetClass();
  58.    class->ClassName    = "IntegerGadget";
  59.  
  60.    class->Value    = (LONG(*)(Valuator *))IntegerGadget_Value;
  61.    class->SetValue = (LONG(*)(Valuator *, LONG))IntegerGadget_SetValue;
  62.  
  63. }
  64.  
  65.  
  66. struct ValuatorClass *IntegerGadgetClass( void )
  67. {
  68.    if( ! IntegerGadget_elaborated )
  69.    {
  70.       IntegerGadgetClass_Init( &IntegerGadget_Class );
  71.       IntegerGadget_elaborated = TRUE;
  72.    }
  73.  
  74.    return &IntegerGadget_Class;
  75. }
  76.  
  77.  
  78.  
  79. void IntegerGadget_Init( IntegerGadget *self,
  80.                          PIXELS        LeftEdge,
  81.                          PIXELS        TopEdge,
  82.                          PIXELS        Width,
  83.                          USHORT        nChars,
  84.                          pcg_3DPens    Pens,
  85.                          char         *label )
  86. {
  87.    struct StringInfo *stringinfo;
  88.  
  89.    StringGadget_Init( self, LeftEdge, TopEdge, Width, nChars,
  90.                         Pens, label );
  91.  
  92.    self->isa = IntegerGadgetClass();
  93.  
  94.    stringinfo = (struct StringInfo *)self->g.SpecialInfo;
  95.  
  96.    self->g.Activation |= LONGINT;
  97.    SetValue( (Valuator *)self, 0 );
  98. }
  99.  
  100.