            :
       Unit : UEnablingCheckBox
            :
 Programmer : Cal Evans
            : cal.evans@jjmusic.com
            : 5572263@jjmusic.com (pager)
            : http://www.scguild.com/usr/1411R.html
            :
  Copyright : 1997 Tranquility Base
            : Virginia Beach VA, 23464
            :
Create Date : September 10th, 1996
            :
Last Update : February 17th, 1997
            :
 Components : TCustomEnablingCheckBox
 Contained  :      |
            :      +- TEnablingCheckbox
            :      |
            :      +- TDBEnablingCheckbox
            :
     Action : This check box, when placed in a container, form, panel, etc.)
            : will enable or disable all components in the container based on
            : the value of Checked.
            :
            : To prevent an object from being changed, change
            : it's TAG to <>0
            :
   Author's : Source code is available upon polite request.
      Notes :
            : ****************************************************************
            : *                                                              *
            : *                   I am available for                         *
            : *                     Contract work                            *
            : *                     Consultations                            *
            : *                     Kid's parties                            *
            : *                                                              *
            : * Looking for a contract programmer?  I am fluent in Delphi    *
            : * 1.0, 2.01 and beyond.  I also design and implement Internet  *
            : * presences for companies. Interactive web sites, mailing      *
            : * lists, email generators, cgi scripts, new groups, if it's    *
            : * Internet I can help your company get it up and running.      *
            : *                                                              *
            : * Visit my homepage for more details.                          *
            : ****************************************************************
            :
    Install : + Unzip into the directory you keep your components in.
      Notes :   (..\delphi 2.0\bin)
            : + Chose Tools\Install Component
            : + Select Add
            : + Find the component using the Browse button. (Look for the DCU!)
            : + Select OK
            : + Create A new Application
            : + Drop a uEnablingCheckBox on the form
            : + Drop a Button on the form
            : + Run the application
            : + The button should be initially disabled and should become
            :   enabled when you check the checkbox.
            :
    Version : 1.0
      Notes : Initial Release
            :
            : 2.0
            : Added the data aware version.
            :
            : TEnablingCheckBox
            :   Custom Properties -
            :     Reverse - reverses the nomal behavoure.  Normal is to enable
            :     everything when the box is checked and disable when not
            :     checked. With REVERSE set to TRUE, everything is enabled when
            :     the box is unchecked.
            :
            :   Custom Events  - None
            :   Custom Methods - None
            :
type
 { TCustomEnablingCheckBox }
  TCustomEnablingCheckBox = Class(TCustomCheckBox)
  private
    { Private declarations }
  protected
    { Protected declarations }
    fReverse : boolean;
    procedure toggle; override;
    procedure FlipTheSwitch;

  public
    { Public declarations }
    constructor create(aOwner:TComponent); override;
    procedure SetState(aState : TCheckBoxState); virtual;
    function  GetState : TCheckBoxState;
    procedure setchecked(aChecked : Boolean);
    function GetChecked : Boolean;

    property state   : TCheckBoxState read getstate write setstate;
    property Checked : boolean read getchecked write setchecked;
    property Reverse : boolean read fReverse write fReverse;

    property Alignment;
    property Caption;
    property Color;
    property Ctl3D;
    property DragCursor;
    property DragMode;
    property Enabled;
    property Font;
    property ParentColor;
    property ParentCtl3D;
    property ParentFont;
    property ParentShowHint;
    property PopupMenu;
    property ShowHint;
    property TabOrder;
    property TabStop;
    property Visible;
    property OnClick;
    property OnDragDrop;
    property OnDragOver;
    property OnEndDrag;
    property OnEnter;
    property OnExit;
    property OnKeyDown;
    property OnKeyPress;
    property OnKeyUp;
    property OnMouseDown;
    property OnMouseMove;
    property OnMouseUp;
    property OnStartDrag;

  published

  end;


 { TEnablingCheckBox }
  TEnablingCheckBox = Class(TCustomEnablingCheckBox)
  private
    { Private declarations }

  protected
    { Protected declarations }

  public
    { Public declarations }
    constructor Create(aOwner:TComponent); override;

  published
    { Published declarations }
    property state;
    property Checked;
    property Reverse;

    property Alignment;
    property Caption;
    property Color;
    property Ctl3D;
    property DragCursor;
    property DragMode;
    property Enabled;
    property Font;
    property ParentColor;
    property ParentCtl3D;
    property ParentFont;
    property ParentShowHint;
    property PopupMenu;
    property ShowHint;
    property TabOrder;
    property TabStop;
    property Visible;
    property OnClick;
    property OnDragDrop;
    property OnDragOver;
    property OnEndDrag;
    property OnEnter;
    property OnExit;
    property OnKeyDown;
    property OnKeyPress;
    property OnKeyUp;
    property OnMouseDown;
    property OnMouseMove;
    property OnMouseUp;
    property OnStartDrag;

  end;

{ TDBEnablingCheckBox }
  TDBEnablingCheckBox = class(TCustomEnablingCheckBox)
  private
    FDataLink: TFieldDataLink;
    FValueCheck: string;
    FValueUncheck: string;
    FPaintControl: TPaintControl;
    procedure DataChange(Sender: TObject);
    function GetDataField: string;
    function GetDataSource: TDataSource;
    function GetField: TField;
    function GetFieldState: TCheckBoxState;
    function GetReadOnly: Boolean;
    procedure SetDataField(const Value: string);
    procedure SetDataSource(Value: TDataSource);
    procedure SetReadOnly(Value: Boolean);
    procedure SetValueCheck(const Value: string);
    procedure SetValueUncheck(const Value: string);
    procedure UpdateData(Sender: TObject);
    function ValueMatch(const ValueList, Value: string): Boolean;
    procedure WMPaint(var Message: TWMPaint); message WM_PAINT;
    procedure CMExit(var Message: TCMExit); message CM_EXIT;
    procedure CMGetDataLink(var Message: TMessage); message CM_GETDATALINK;

  protected
    procedure Toggle; override;
    procedure KeyPress(var Key: Char); override;
    procedure Notification(AComponent: TComponent;
      Operation: TOperation); override;
    procedure WndProc(var Message: TMessage); override;

  public
    procedure SetState(aState : TCheckBoxState); override;
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    property Checked;
    property Field: TField read GetField;
    property State;

  published
    property Reverse;

    property Alignment;
    property Caption;
    property Color;
    property Ctl3D;
    property DataField: string read GetDataField write SetDataField;
    property DataSource: TDataSource read GetDataSource write SetDataSource;
    property DragCursor;
    property DragMode;
    property Enabled;
    property Font;
    property ParentColor;
    property ParentCtl3D;
    property ParentFont;
    property ParentShowHint;
    property PopupMenu;
    property ReadOnly: Boolean read GetReadOnly write SetReadOnly default False;
    property ShowHint;
    property TabOrder;
    property TabStop;
    property ValueChecked: string read FValueCheck write SetValueCheck;
    property ValueUnchecked: string read FValueUncheck write SetValueUncheck;
    property Visible;
    property OnClick;
    property OnDragDrop;
    property OnDragOver;
    property OnEndDrag;
    property OnEnter;
    property OnExit;
    property OnKeyDown;
    property OnKeyPress;
    property OnKeyUp;
    property OnMouseDown;
    property OnMouseMove;
    property OnMouseUp;
    property OnStartDrag;
  end;
