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 / BoolGadget.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-19  |  2.3 KB  |  99 lines

  1. #include "BoolGadget.h"
  2. #include "BoolGadgetClass.h"
  3. #include "EmbossedGadgetClass.h"
  4. #include "pcgWindow.h"
  5. #ifndef __GNUC__
  6. #include <clib/exec_protos.h>
  7. #endif
  8. #ifdef __GNUC__
  9. #include <proto/exec.h>
  10. #endif
  11. #ifdef __SASC
  12. #include <proto/exec.h>
  13. #endif
  14. #include "amigamem.h"
  15.  
  16. LONG BoolGadget_Value( BoolGadget *self )
  17. {
  18.    return ( self->g.Flags & SELECTED );
  19. }
  20.  
  21.  
  22. LONG BoolGadget_SetValue( BoolGadget *self, LONG selection )
  23. {
  24.    struct pcgWindow *window;
  25.  
  26.    window = InteractorWindow( (Interactor *)self );
  27.    if( window->Window ) /* window is open */
  28.    {
  29.       /* NOTE: This may not be KOSHER.  The PROPER way is to remove
  30.        * the gadget from the window list, twiddle its bits, and
  31.        * then add it back to the list.  (It does work, though.)
  32.        */
  33.       Forbid();
  34.  
  35.       if( selection )
  36.          self->g.Flags |= SELECTED;
  37.       else
  38.          self->g.Flags &= ( ~SELECTED );
  39.  
  40.       Permit();
  41.    }
  42.    else /* Window is not open, can just do it the easy way */
  43.    {
  44.       if( selection )
  45.          self->g.Flags |= SELECTED;
  46.       else
  47.          self->g.Flags &= ( ~SELECTED );
  48.    }
  49.  
  50.    return selection;
  51. }
  52.  
  53.  
  54. BOOL BoolGadget_elaborated = FALSE;
  55.  
  56. struct ValuatorClass BoolGadget_Class;
  57.  
  58. void BoolGadgetClass_Init( struct ValuatorClass *class )
  59. {
  60.    ValuatorClass_Init( class );
  61.    EmbossedGadgetClass_Init( (struct InteractorClass *)class );
  62.    class->isa           = ValuatorClass();
  63.    class->ClassName     = "BoolGadget";
  64.    class->Value         = (LONG(*)(Valuator *))BoolGadget_Value;
  65.    class->SetValue      = (LONG(*)(Valuator *, LONG))BoolGadget_SetValue;
  66.  
  67. }
  68.  
  69.  
  70. struct ValuatorClass *BoolGadgetClass( void )
  71. {
  72.    if( ! BoolGadget_elaborated )
  73.    {
  74.       BoolGadgetClass_Init( &BoolGadget_Class );
  75.       BoolGadget_elaborated = TRUE;
  76.    }
  77.  
  78.    return &BoolGadget_Class;
  79. }
  80.  
  81.  
  82.  
  83. void BoolGadget_Init( BoolGadget *self,
  84.                       PIXELS      LeftEdge,
  85.                       PIXELS      TopEdge,
  86.                       PIXELS      Width,
  87.                       PIXELS      Height,
  88.                       pcg_3DPens  Pens,
  89.                       char       *Label )
  90. {
  91.                    /* REMOVE GADGHCOMP -- EDB */
  92.    EmbossedGadget_Init( self, LeftEdge, TopEdge, Width, Height,
  93.                        GADGHCOMP /* GFLG_GADGHNONE */, RELVERIFY, BOOLGADGET,
  94.                         Pens, Label );
  95.  
  96.    self->isa = BoolGadgetClass();
  97. }
  98.  
  99.