home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 March / Chip_2002-03_cd1.bin / zkuste / delphi / kolekce / d123456 / SIMONS.ZIP / Units / SRChkBox.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2001-12-18  |  39.1 KB  |  1,416 lines

  1. unit SRChkBox;
  2.  
  3. { TSRCheckBox (C)opyright 2001 Version 1.20
  4.   Autor : Simon Reinhardt
  5.   eMail : reinhardt@picsoft.de
  6.   Internet : http://www.picsoft.de
  7.  
  8.   Die Komponente TSRCheckBox ist eine Checkbox-Komponente mit Autosize-,
  9.   Transparent- und WordWrap-Eigenschaften. Au▀erdem wird kein OnClick-Ereignis
  10.   abgefeuert, wenn die Checked-Eigenschaft per Programmcode geΣndert wird.
  11.   Die Komponente ist abgeleteitet von TGraphicControl.
  12.  
  13.   Die Komponente TEnhancedCheckBox entspricht der Komponente TSRCheckBox,
  14.   ist aber von TCustomControl abgeleitet und kann deshalb auch den Eingabefokus
  15.   bekommen. Dafⁿr entfΣllt die "Transparent"-Eigenschaft.
  16.  
  17.   Die Komponenten sind Public Domain, das Urheberrecht liegt aber beim Autor. }
  18.  
  19. interface
  20.  
  21. {$I SRDefine.inc}
  22.  
  23. uses
  24.   {$IFDEF SR_Win32} Windows, {$ELSE} WinTypes, WinProcs, Menus, {$ENDIF}
  25.   Classes, Graphics, Controls, SysUtils, Messages, StdCtrls;
  26.  
  27. type
  28.   TCheckStyle = (csCheckBox, csDiamond, csPushButton, csRadioButton, csTrafficLight);
  29.   TCheckboxLayout = (clBottom, clCenter, clTop);
  30.  
  31.   TSRCheckBox = class(TGraphicControl)
  32.   private
  33.     FAlignment     : TLeftRight;
  34.     FAllowGrayed,
  35.     FAutoSize      : boolean;
  36.     FColor         : TColor;
  37.     FChecked       : boolean;
  38.     FCheckSize     : integer;
  39.     FGrouped       : boolean;
  40.     FLayout        : TCheckboxLayout;
  41.     FMouseDown     : boolean;
  42.     FSpacing       : integer;
  43.     FState         : TCheckBoxState;
  44.     FStateChanged  : boolean;
  45.     FStyle         : TCheckStyle;
  46.     FTransparent,
  47.     FWordWrap      : boolean;
  48.  
  49.     FOnChange,
  50.     FOnClick,
  51.     FOnDblClick    : TNotifyEvent;
  52.     FOnMouseDown   : TMouseEvent;
  53.     FOnMouseMove   : TMouseMoveEvent;
  54.     FOnMouseUp     : TMouseEvent;
  55.  
  56.     procedure CMDialogChar(var Message: TCMDialogChar);message CM_DIALOGCHAR;
  57.     procedure CMFontChanged(var Message: TMessage); message CM_FONTCHANGED;
  58.     procedure CMTextChanged(var msg: TMessage);message CM_TEXTCHANGED;
  59.  
  60.   protected
  61.     procedure AdjustBounds;
  62.     procedure Change; dynamic;
  63.     procedure DblClick; override;
  64.     function GetTextRect(ARect: TRect): TRect;
  65.     procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
  66.     procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
  67.     procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
  68.     procedure Paint; override;
  69.     procedure PaintButton;
  70.     procedure PaintCaption;
  71.  
  72.     procedure SetAlignment(newValue: TLeftRight);
  73.     procedure SetAutosize(newValue: boolean);
  74.     procedure SetColor(newValue: TColor);
  75.     procedure SetChecked(newValue: boolean);
  76.     procedure SetCheckSize(newValue: integer);
  77.     procedure SetGrouped(newValue: boolean);
  78.     procedure SetLayout(newValue: TCheckboxLayout);
  79.     procedure SetSpacing(newValue: integer);
  80.     procedure SetState(newValue: TCheckBoxState);
  81.     procedure SetStyle(newValue: TCheckStyle);
  82.     procedure SetTransparent(newValue: boolean);
  83.     procedure SetWordWrap(newValue: boolean);
  84.  
  85.     procedure UncheckGroupCheckBoxes;
  86.  
  87.   public
  88.     constructor Create(AOwner: TComponent); override;
  89.     destructor Destroy; override;
  90.  
  91.   published
  92.     {$IFDEF SR_Delphi5_Up}
  93.     property Action;
  94.     {$ENDIF}
  95.     property Alignment: TLeftRight read FAlignment write SetAlignment;
  96.     property AllowGrayed: boolean read FAllowGrayed write FAllowGrayed;
  97.     {$IFDEF SR_Delphi5_Up}
  98.     property Anchors;
  99.     {$ENDIF}
  100.     property AutoSize: boolean read FAutoSize write SetAutoSize;
  101.     {$IFDEF SR_Delphi5_Up}
  102.     property BiDiMode;
  103.     {$ENDIF}
  104.     property Caption;
  105.     property Checked: boolean read FChecked write SetChecked;
  106.     property CheckSize: integer read FCheckSize write SetCheckSize;
  107.     property Color: TColor read FColor write SetColor;
  108.     {$IFDEF SR_Delphi5_Up}
  109.     property Constraints;
  110.     {$ENDIF}
  111.     {$IFDEF SR_Delphi4_Up}
  112.     property DragKind;
  113.     {$ENDIF}
  114.     property DragCursor;
  115.     property DragMode;
  116.     property Enabled;
  117.     property Font;
  118.     property Grouped: boolean read FGrouped write SetGrouped;
  119.     property Layout: TCheckboxLayout read FLayout write SetLayout;
  120.     {$IFDEF SR_Delphi5_Up}
  121.     property ParentBiDiMode;
  122.     {$ENDIF}
  123.     property ParentColor;
  124.     property ParentFont;
  125.     property ParentShowHint;
  126.     property PopupMenu;
  127.     property ShowHint;
  128.     property Spacing: integer read FSpacing write SetSpacing;
  129.     property State: TCheckBoxState read FState write SetState;
  130.     property Style: TCheckStyle read FStyle write SetStyle;
  131.     property Transparent: boolean read FTransparent write SetTransparent;
  132.     property Visible;
  133.     property WordWrap: boolean read FWordWrap write SetWordWrap;
  134.  
  135.     property OnChange: TNotifyEvent read FOnChange write FOnChange;
  136.     {$IFDEF SR_Delphi5_Up}
  137.     property OnContextPopup;
  138.     {$ENDIF}
  139.     property OnClick: TNotifyEvent read FOnClick write FOnClick;
  140.     property OnDblClick: TNotifyEvent read FOnDblClick write FOnDblClick;
  141.     property OnDragDrop;
  142.     property OnDragOver;
  143.     {$IFDEF SR_Delphi4_Up}
  144.     property OnEndDock;
  145.     {$ENDIF}
  146.     property OnEndDrag;
  147.     property OnMouseDown: TMouseEvent read FOnMouseDown write FOnMouseDown;
  148.     property OnMouseMove: TMouseMoveEvent read FOnMouseMove write FOnMouseMove;
  149.     property OnMouseUp: TMouseEvent read FOnMouseUp write FOnMouseUp;
  150.     {$IFDEF SR_Delphi4_Up}
  151.     property OnStartDock;
  152.     {$ENDIF}
  153.     {$IFDEF SR_Delphi2_Up}
  154.     property OnStartDrag;
  155.     {$ENDIF}
  156.   end;
  157.  
  158.   TEnhancedCheckBox = class(TCustomControl)
  159.   private
  160.     FAlignment     : TLeftRight;
  161.     FAllowGrayed,
  162.     FAutoSize      : boolean;
  163.     FColor         : TColor;
  164.     FChecked       : boolean;
  165.     FCheckSize     : integer;
  166.     FGrouped       : boolean;
  167.     FLayout        : TCheckboxLayout;
  168.     FMouseDown     : boolean;
  169.     FSpacing       : integer;
  170.     FState         : TCheckBoxState;
  171.     FStateChanged  : boolean;
  172.     FStyle         : TCheckStyle;
  173.     FWordWrap      : boolean;
  174.  
  175.     FOnChange,
  176.     FOnClick,
  177.     FOnDblClick    : TNotifyEvent;
  178.     FOnMouseDown   : TMouseEvent;
  179.     FOnMouseMove   : TMouseMoveEvent;
  180.     FOnMouseUp     : TMouseEvent;
  181.  
  182.     procedure CMDialogChar(var Message: TCMDialogChar);message CM_DIALOGCHAR;
  183.     procedure CMFontChanged(var Message: TMessage); message CM_FONTCHANGED;
  184.     procedure CMTextChanged(var msg: TMessage);message CM_TEXTCHANGED;
  185.  
  186.   protected
  187.     procedure AdjustBounds;
  188.     procedure Change; dynamic;
  189.     procedure DblClick; override;
  190.     procedure DoDrawFocusRect(IsFocused:boolean); dynamic;
  191.     procedure DrawDotLine(X1,Y1,Length:integer;Horizontal:boolean);
  192.     function GetTextRect(ARect: TRect): TRect;
  193.     procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
  194.     procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
  195.     procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
  196.     procedure Paint; override;
  197.     procedure PaintButton;
  198.     procedure PaintCaption;
  199.  
  200.     procedure SetAlignment(newValue: TLeftRight);
  201.     procedure SetAutosize(newValue: boolean);
  202.     procedure SetColor(newValue: TColor);
  203.     procedure SetChecked(newValue: boolean);
  204.     procedure SetCheckSize(newValue: integer);
  205.     procedure SetGrouped(newValue: boolean);
  206.     procedure SetLayout(newValue: TCheckboxLayout);
  207.     procedure SetSpacing(newValue: integer);
  208.     procedure SetState(newValue: TCheckBoxState);
  209.     procedure SetStyle(newValue: TCheckStyle);
  210.     procedure SetWordWrap(newValue: boolean);
  211.  
  212.     procedure UncheckGroupCheckBoxes;
  213.     procedure WMKillFocus(var Message: TWMKillFocus); message WM_KILLFOCUS;
  214.     procedure WMSetFocus(var Message: TWMSetFocus); message WM_SETFOCUS;
  215.  
  216.   public
  217.     constructor Create(AOwner: TComponent); override;
  218.     destructor Destroy; override;
  219.     procedure KeyDown(var Key: Word; Shift: TShiftState); override;
  220.     procedure KeyUp(var Key: Word; Shift: TShiftState); override;
  221.  
  222.   published
  223.     {$IFDEF SR_Delphi5_Up}
  224.     property Action;
  225.     {$ENDIF}
  226.     property Alignment: TLeftRight read FAlignment write SetAlignment;
  227.     property AllowGrayed: boolean read FAllowGrayed write FAllowGrayed;
  228.     {$IFDEF SR_Delphi5_Up}
  229.     property Anchors;
  230.     {$ENDIF}
  231.     property AutoSize: boolean read FAutoSize write SetAutoSize;
  232.     {$IFDEF SR_Delphi5_Up}
  233.     property BiDiMode;
  234.     {$ENDIF}
  235.     property Caption;
  236.     property Checked: boolean read FChecked write SetChecked;
  237.     property CheckSize: integer read FCheckSize write SetCheckSize;
  238.     property Color: TColor read FColor write SetColor;
  239.     {$IFDEF SR_Delphi5_Up}
  240.     property Constraints;
  241.     {$ENDIF}
  242.     {$IFDEF SR_Delphi4_Up}
  243.     property DragKind;
  244.     {$ENDIF}
  245.     property DragCursor;
  246.     property DragMode;
  247.     property Enabled;
  248.     property Font;
  249.     property Grouped: boolean read FGrouped write SetGrouped;
  250.     property Layout: TCheckboxLayout read FLayout write SetLayout;
  251.     {$IFDEF SR_Delphi5_Up}
  252.     property ParentBiDiMode;
  253.     {$ENDIF}
  254.     property ParentColor;
  255.     property ParentFont;
  256.     property ParentShowHint;
  257.     property PopupMenu;
  258.     property ShowHint;
  259.     property Spacing: integer read FSpacing write SetSpacing;
  260.     property State: TCheckBoxState read FState write SetState;
  261.     property Style: TCheckStyle read FStyle write SetStyle;
  262.     property TabOrder;
  263.     property TabStop;
  264.     property Visible;
  265.     property WordWrap: boolean read FWordWrap write SetWordWrap;
  266.  
  267.     property OnChange: TNotifyEvent read FOnChange write FOnChange;
  268.     property OnClick: TNotifyEvent read FOnClick write FOnClick;
  269.     {$IFDEF SR_Delphi5_Up}
  270.     property OnContextPopup;
  271.     {$ENDIF}
  272.     property OnDblClick: TNotifyEvent read FOnDblClick write FOnDblClick;
  273.     property OnDragDrop;
  274.     property OnDragOver;
  275.     {$IFDEF SR_Delphi4_Up}
  276.     property OnEndDock;
  277.     {$ENDIF}
  278.     property OnEndDrag;
  279.     property OnEnter;
  280.     property OnExit;
  281.     property OnKeyDown;
  282.     property OnKeyPress;
  283.     property OnKeyUp;
  284.     property OnMouseDown: TMouseEvent read FOnMouseDown write FOnMouseDown;
  285.     property OnMouseMove: TMouseMoveEvent read FOnMouseMove write FOnMouseMove;
  286.     property OnMouseUp: TMouseEvent read FOnMouseUp write FOnMouseUp;
  287.     {$IFDEF SR_Delphi4_Up}
  288.     property OnStartDock;
  289.     {$ENDIF}
  290.     {$IFDEF SR_Delphi2_Up}
  291.     property OnStartDrag;
  292.     {$ENDIF}
  293.   end;
  294.  
  295. procedure Register;
  296.  
  297. implementation
  298.  
  299. {$IFDEF SR_Delphi2_Up}
  300. {$R *.D32}
  301. {$ELSE}
  302. {$R *.D16}
  303. {$ENDIF}
  304.  
  305. function IsAccellerator(VK: Word; const Str: string): Boolean;
  306. var P : Integer;
  307. begin
  308.   P := Pos('&', Str);
  309.   Result := (P <> 0) and (P < Length(Str)) and
  310.     (Upcase(Str[P + 1])=Upcase(Char(VK)));
  311. end; {IsAccellerator}
  312.  
  313. procedure DrawDiamond(ACanvas:TCanvas; ARect:TRect; AState:TCheckBoxState; IsEnabled:boolean);
  314. var Offset        : integer;
  315.     OldBrushStyle : TBrushStyle;
  316. begin
  317.   Offset:=(ARect.Right-ARect.Left) div 2;
  318.   with ACanvas do begin
  319.     Pen.Width:=1;
  320.     if AState=cbUnChecked then
  321.       Pen.Color:=clBtnHighlight
  322.     else
  323.       Pen.Color:=clBtnShadow;
  324.     MoveTo(ARect.Left+Offset, ARect.Top);
  325.     LineTo(ARect.Left, ARect.Top+Offset);
  326.     LineTo(ARect.Left+Offset, ARect.Bottom-1);
  327.     if AState=cbUnChecked then
  328.       Pen.Color:=clBtnShadow
  329.     else
  330.       Pen.Color:=clBtnHighlight;
  331.     LineTo(ARect.Right-1, ARect.Top+Offset);
  332.     LineTo(ARect.Left+Offset, ARect.Top);
  333.     if AState<>cbUnchecked then begin
  334.       OldBrushStyle:=Brush.Style;
  335.       Pen.Color:=Brush.Color;
  336.       Brush.Style:=bsSolid;
  337.       if AState=cbChecked then
  338.         Brush.Color:=clBlack
  339.       else
  340.         Brush.Color:=clGray;
  341.       Polygon([Point(ARect.Left+Offset, ARect.Top+1),
  342.               Point(ARect.Right-2, ARect.Top+Offset),
  343.               Point(ARect.Left+Offset, ARect.Bottom-2),
  344.               Point(ARect.Left+1, ARect.Top+Offset)]);
  345.       Brush.Color:=Pen.Color;
  346.       Brush.Style:=OldBrushStyle;
  347.     end;
  348.   end;
  349. end; {DrawDiamond}
  350.  
  351. procedure DrawCheckBox(ACanvas:TCanvas; ARect:TRect; AState:TCheckBoxState; IsEnabled:boolean);
  352. {$IFDEF SR_Delphi1}
  353. var OldColor  : TColor;
  354.     Diff,
  355.     BrdrWidth : integer;
  356.     i         : byte;
  357.  
  358.   procedure Draw3DFrame(ARect:TRect;TLColor,BRColor:TColor);
  359.   begin
  360.     with ACanvas do begin
  361.       Pen.Width:=1;
  362.       Pen.Color:=TLColor;
  363.       MoveTo(ARect.Right-2, ARect.Top);
  364.       LineTo(ARect.Left, ARect.Top);
  365.       LineTo(ARect.Left, ARect.Bottom-2);
  366.       Pen.Color:=BRColor;
  367.       MoveTo(ARect.Right-1, ARect.Top);
  368.       LineTo(ARect.Right-1, ARect.Bottom-1);
  369.       LineTo(ARect.Left, ARect.Bottom-1);
  370.     end;
  371.   end; {Draw3DFrame}
  372.  
  373.   procedure DrawCheckMark(ARect:TRect);
  374.   begin
  375.     with ACanvas do begin
  376.       Pen.Color:=clWindowText;
  377.       MoveTo(ARect.Right-2, ARect.Top+1);
  378.       LineTo(ARect.Right-Diff, ARect.Top+Diff-1);
  379.       LineTo(ARect.Right-Diff-(Diff div 2), ARect.Top+(Diff div 2)-1);
  380.     end;
  381.   end; {DrawCheckMark}
  382. {$ENDIF}
  383.  
  384. begin
  385.   {$IFDEF SR_Delphi2_Up}
  386.   case AState of
  387.     cbUnchecked : DrawFrameControl(ACanvas.Handle, ARect, DFC_Button, DFCS_ButtonCheck);
  388.     cbChecked   : DrawFrameControl(ACanvas.Handle, ARect, DFC_Button, DFCS_ButtonCheck or DFCS_Checked);
  389.     cbGrayed    : DrawFrameControl(ACanvas.Handle, ARect, DFC_Button, DFCS_ButtonCheck or DFCS_Checked or DFCS_Inactive);
  390.   end;
  391.   {$ELSE}
  392.   BrdrWidth:=((ARect.Right-ARect.Left) div 15)+1;
  393.   with ACanvas do begin
  394.     { 3D-Rahmen }
  395.     for i:=1 to BrdrWidth do begin
  396.       Draw3DFrame(ARect, clBtnShadow, clBtnHighlight);
  397.       InflateRect(ARect, -1, -1);
  398.     end;
  399.     for i:=1 to BrdrWidth do begin
  400.       Draw3DFrame(ARect, clBlack, clBtnFace);
  401.       InflateRect(ARect, -1, -1);
  402.     end;
  403.  
  404.     { Hintergrund }
  405.     OldColor:=Brush.Color;
  406.     if IsEnabled and (AState<>cbGrayed) then
  407.       Brush.Color:=clWindow
  408.     else
  409.       Brush.Color:=clBtnFace;
  410.     FillRect(ARect);
  411.  
  412.     { Check-HΣkchen }
  413.     Diff:=round((ARect.Right-ARect.Left)/3*2);
  414.     if AState=cbChecked then begin
  415.       for i:=1 to BrdrWidth+2 do begin
  416.         DrawCheckMark(ARect);
  417.         OffsetRect(ARect, 0, 1);
  418.       end;
  419.     end;
  420.  
  421.     Brush.Color:=OldColor;
  422.   end;
  423.   {$ENDIF}
  424. end; {DrawCheckBox}
  425.  
  426. procedure DrawPushButton(ACanvas:TCanvas; ARect:TRect; AState:TCheckBoxState; IsEnabled:boolean);
  427. {$IFDEF SR_Delphi1}
  428. var OldColor : TColor;
  429.     i        : byte;
  430. {$ENDIF}
  431.  
  432.   procedure Draw3DFrame(ARect:TRect;TLColor,BRColor:TColor);
  433.   begin
  434.     with ACanvas do begin
  435.       Pen.Width:=1;
  436.       Pen.Color:=TLColor;
  437.       MoveTo(ARect.Right-2, ARect.Top);
  438.       LineTo(ARect.Left, ARect.Top);
  439.       LineTo(ARect.Left, ARect.Bottom-2);
  440.       Pen.Color:=BRColor;
  441.       MoveTo(ARect.Right-1, ARect.Top);
  442.       LineTo(ARect.Right-1, ARect.Bottom-1);
  443.       LineTo(ARect.Left, ARect.Bottom-1);
  444.     end;
  445.   end; {Draw3DFrame}
  446.  
  447. begin
  448.   {$IFDEF SR_Delphi2_Up}
  449.   case AState of
  450.     cbUnchecked : DrawFrameControl(ACanvas.Handle, ARect, DFC_Button, DFCS_ButtonPush);
  451.     cbChecked   : DrawFrameControl(ACanvas.Handle, ARect, DFC_Button, DFCS_ButtonPush or DFCS_Pushed);
  452.     cbGrayed    : DrawFrameControl(ACanvas.Handle, ARect, DFC_Button, DFCS_ButtonPush or DFCS_Flat);
  453.   end;
  454.   {$ELSE}
  455.   with ACanvas do begin
  456.     { 3D-Rahmen }
  457.     if AState=cbChecked then begin
  458.       Draw3DFrame(ARect, clBlack, clBtnHighlight);
  459.       InflateRect(ARect, -1, -1);
  460.       Draw3DFrame(ARect, clBtnShadow, clBtnFace);
  461.       InflateRect(ARect, -1, -1);
  462.     end
  463.     else begin
  464.       if AState=cbUnChecked then begin
  465.         Draw3DFrame(ARect, clBtnHighlight, clBlack);
  466.         InflateRect(ARect, -1, -1);
  467.         Draw3DFrame(ARect, clBtnFace, clBtnShadow);
  468.         InflateRect(ARect, -1, -1);
  469.       end
  470.       else begin
  471.         Draw3DFrame(ARect, clBtnShadow, clBtnShadow);
  472.         InflateRect(ARect, -1, -1);
  473.       end;
  474.     end;
  475.  
  476.     { Hintergrund }
  477.     OldColor:=Brush.Color;
  478.     Brush.Color:=clBtnFace;
  479.     FillRect(ARect);
  480.  
  481.     Brush.Color:=OldColor;
  482.   end;
  483.   {$ENDIF}
  484. end; {DrawPushButton}
  485.  
  486. procedure DrawRadioButton(ACanvas:TCanvas; ARect:TRect; AState:TCheckBoxState; IsEnabled:boolean);
  487. {$IFDEF SR_Delphi1}
  488. var OldColor  : TColor;
  489.     BrdrWidth,
  490.     ChckWidth : integer;
  491.     i         : byte;
  492. {$ENDIF}
  493.  
  494.   procedure Draw3DBorder(ARect:TRect;TLColor,BRColor:TColor);
  495.   begin
  496.     with ACanvas do begin
  497.       Pen.Width:=1;
  498.       Pen.Color:=TLColor;
  499.       Brush.Color:=Pen.Color;
  500.       Pie(ARect.Left, ARect.Top, ARect.Right-1, ARect.Bottom-1,
  501.           ARect.Right-1, ARect.Top, ARect.Left, ARect.Bottom-1);
  502.       Pen.Color:=BRColor;
  503.       Brush.Color:=Pen.Color;
  504.       Pie(ARect.Left, ARect.Top, ARect.Right-1, ARect.Bottom-1,
  505.           ARect.Left, ARect.Bottom-1, ARect.Right-1, ARect.Top);
  506.     end;
  507.   end; {Draw3DBorder}
  508.  
  509. begin
  510.   {$IFDEF SR_Delphi2_Up}
  511.   case AState of
  512.     cbUnchecked : DrawFrameControl(ACanvas.Handle, ARect, DFC_Button, DFCS_ButtonRadio);
  513.     cbChecked   : DrawFrameControl(ACanvas.Handle, ARect, DFC_Button, DFCS_ButtonRadio or DFCS_Checked);
  514.     cbGrayed    : DrawFrameControl(ACanvas.Handle, ARect, DFC_Button, DFCS_ButtonRadio or DFCS_Checked or DFCS_Inactive);
  515.   end;
  516.   {$ELSE}
  517.   with ACanvas do begin
  518.     BrdrWidth:=((ARect.Right-ARect.Left) div 15)+1;
  519.     { 3D-Rahmen }
  520.     Draw3DBorder(ARect, clBtnShadow, clBtnHighlight);
  521.     InflateRect(ARect, -BrdrWidth, -BrdrWidth);
  522.     Draw3DBorder(ARect, clBlack, clBtnFace);
  523.     InflateRect(ARect, -BrdrWidth+1, -BrdrWidth+1);
  524.  
  525.     { Hintergrund }
  526.     OldColor:=Brush.Color;
  527.     if IsEnabled and (AState<>cbGrayed) then
  528.       Brush.Color:=clWindow
  529.     else
  530.       Brush.Color:=clBtnFace;
  531.     Ellipse(ARect.Left, ARect.Top, ARect.Right-1, ARect.Bottom-1);
  532.     ChckWidth:=(ARect.Right-ARect.Left) div 5;
  533.     InflateRect(ARect, -ChckWidth-1, -ChckWidth-1);
  534.  
  535.     { Check-Punkt }
  536.     if AState=cbChecked then begin
  537.       Brush.Color:=clWindowText;
  538.       Pen.Color:=clWindowText;
  539.       Ellipse(ARect.Left, ARect.Top, ARect.Right-1, ARect.Bottom-1);
  540.     end;
  541.  
  542.     Brush.Color:=OldColor;
  543.   end;
  544.   {$ENDIF}
  545. end; {DrawRadioButton}
  546.  
  547. procedure DrawTrafficLight(ACanvas:TCanvas; ARect:TRect; AState:TCheckBoxState; IsEnabled:boolean);
  548. const LightColors : array[TCheckBoxState] of TColor =
  549.   (clLime, clRed, clYellow);
  550. var OldColor      : TColor;
  551.     OldBrushStyle : TBrushStyle;
  552. begin
  553.   with ACanvas do begin
  554.     Pen.Color:=clBlack;
  555.     Pen.Width:=1;
  556.     OldColor:=Brush.Color;
  557.     OldBrushStyle:=Brush.Style;
  558.     Brush.Color:=LightColors[AState];
  559.     Brush.Style:=bsSolid;
  560.     InflateRect(ARect, -1, -1);
  561.     Ellipse(ARect.Left, ARect.Top, ARect.Right, ARect.Bottom);
  562.     InflateRect(ARect, 1, 1);
  563.     Pen.Color:=clBtnShadow;
  564.     Arc(ARect.Left, ARect.Top, ARect.Right, ARect.Bottom,
  565.         ARect.Right, ARect.Top, ARect.Left, ARect.Bottom);
  566.     Pen.Color:=clBtnHighlight;
  567.     Arc(ARect.Left, ARect.Top, ARect.Right, ARect.Bottom,
  568.         ARect.Left, ARect.Bottom, ARect.Right, ARect.Top);
  569.     Brush.Color:=OldColor;
  570.     Brush.Style:=OldBrushStyle;
  571.   end;
  572. end; {DrawTrafficLight}
  573.  
  574. procedure DrawTextComp(ACanvas:TCanvas;AText:string;var ARect:TRect;AFormat:Word);
  575. {$IFDEF SR_Delphi1}
  576. var CText : PChar;
  577. {$ENDIF}
  578. begin
  579.   {$IFDEF SR_Delphi1}
  580.   CText:=StrAlloc(255);
  581.   StrPCopy(CText, AText);
  582.   DrawText(ACanvas.Handle, CText, StrLen(CText), ARect, AFormat);
  583.   StrDispose(CText);
  584.   {$ELSE}
  585.   DrawText(ACanvas.Handle, PChar(AText), Length(AText), ARect, AFormat);
  586.   {$ENDIF}
  587. end;
  588.  
  589. { Komponente TSRCheckBox }
  590.  
  591. constructor TSRCheckBox.Create(AOwner: TComponent);
  592. begin
  593.   inherited Create(AOwner);
  594.  
  595.   {Vorgabewerte setzen}
  596.   FAlignment:=taLeftJustify;
  597.   FAllowGrayed:=false;
  598.   FAutosize:=false;
  599.   FColor:=clBtnFace;
  600.   FChecked:=false;
  601.   FCheckSize:=13;
  602.   FGrouped:=false;
  603.   FLayout:=clCenter;
  604.   FSpacing:=4;
  605.   FState:=cbUnchecked;
  606.   FTransparent:=false;
  607.   FWordWrap:=false;
  608.   Width:=90;
  609.   Height:=15;
  610.  
  611.   FMouseDown:=False;
  612.   AdjustBounds;
  613. end;
  614.  
  615. destructor  TSRCheckBox.Destroy;
  616. begin
  617.   inherited Destroy;
  618. end;
  619.  
  620. procedure TSRCheckBox.AdjustBounds;
  621. var ARect : TRect;
  622. begin
  623.   if FAutoSize then begin
  624.     ARect:=GetTextRect(ClientRect);
  625.     ARect.Right:=ARect.Right+FCheckSize+FSpacing;
  626.     InflateRect(ARect, 1, 1);
  627.     SetBounds(Left, Top, ARect.Right, ARect.Bottom);
  628.   end;
  629. end;
  630.  
  631. procedure TSRCheckBox.Change;
  632. begin
  633.   if FChecked and FGrouped then
  634.     UncheckGroupCheckBoxes;
  635.   if Assigned(FOnChange) then
  636.     FOnChange(Self);
  637. end;
  638.  
  639. procedure TSRCheckBox.CMDialogChar(var Message: TCMDialogChar);
  640. var AState : integer;
  641. begin
  642.   with Message do begin
  643.     if IsAccellerator(CharCode, Caption) then begin
  644.       AState:=ord(FState);
  645.       inc(AState);
  646.       if (FAllowGrayed and (AState=3)) or (not FAllowGrayed and (AState=2)) then
  647.         AState:=0;
  648.       SetState(TCheckBoxState(AState));
  649.       if Enabled and Assigned(FOnClick) then
  650.         FOnClick(Self);
  651.       Result:=1;
  652.     end
  653.     else
  654.       inherited;
  655.   end;
  656. end;
  657.  
  658. procedure TSRCheckBox.CMFontChanged(var Message: TMessage);
  659. begin
  660.   inherited;
  661.   AdjustBounds;
  662.   Invalidate;
  663. end;
  664.  
  665. procedure TSRCheckBox.CMTextChanged(var msg: TMessage);
  666. begin
  667.   inherited;
  668.   AdjustBounds;
  669.   Invalidate;
  670. end;
  671.  
  672. procedure TSRCheckBox.DblClick;
  673. begin
  674.   if Enabled then
  675.     if Assigned(FOnDblClick) then
  676.       FOnDblClick(Self);
  677. end;
  678.  
  679. function TSRCheckBox.GetTextRect(ARect: TRect): TRect;
  680. const WordWraps : array[Boolean] of Word = (0, DT_WORDBREAK);
  681. var AText     : string;
  682.     DC        : HDC;
  683.     OldHandle : THandle;
  684. begin
  685.   Result:=ARect;
  686.   AText:=Caption;
  687.   if (AText='') or ((AText[1]='&') and (AText[2]=#0)) then
  688.     AText:=AText+' ';
  689.   OldHandle:=Canvas.Handle;
  690.   DC:=GetDC(0);
  691.   try
  692.     Canvas.Handle:=DC;
  693.     Canvas.Font:=Font;
  694.     DrawTextComp(Canvas, AText, Result, (DT_EXPANDTABS or DT_CALCRECT) or WordWraps[FWordWrap]);
  695.   finally
  696.     Canvas.Handle:=OldHandle;
  697.     ReleaseDC(0, DC);
  698.   end;
  699. end;
  700.  
  701. procedure TSRCheckBox.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  702. begin
  703.   if Enabled then begin
  704.     if Button=mbLeft then begin
  705.       FMouseDown:=true;
  706.       if FState=cbUnChecked then begin
  707.         SetState(cbChecked);
  708.         FStateChanged:=true;
  709.         if Assigned(FOnClick) then
  710.           FOnClick(Self);
  711.       end;
  712.     end;
  713.     if Assigned(FOnMouseDown) then
  714.       FOnMouseDown(Self, Button, Shift, X, Y);
  715.   end;
  716. end;
  717.  
  718. procedure TSRCheckBox.MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  719. begin
  720.   if Enabled and FMouseDown then begin
  721.     { State-Eigenschaft berechnen }
  722.     if not FStateChanged then begin
  723.       if FState=cbChecked then begin
  724.         if not FGrouped then begin
  725.           if FAllowGrayed then
  726.             SetState(cbGrayed)
  727.           else
  728.             SetState(cbUnChecked);
  729.           if Assigned(FOnClick) then
  730.             FOnClick(Self);
  731.         end;
  732.       end
  733.       else begin
  734.         if FState=cbGrayed then begin
  735.           SetState(cbUnChecked);
  736.           if Assigned(FOnClick) then
  737.             FOnClick(Self);
  738.         end;
  739.       end;
  740.     end;
  741.     FStateChanged:=false;
  742.  
  743.     { OnClick-Ereignis abfeuern }
  744.     if Assigned(FOnMouseUp) then
  745.       FOnMouseUp(Self, Button, Shift, X, Y);
  746.   end;
  747.   FMouseDown:=false;
  748. end;
  749.  
  750. procedure TSRCheckBox.MouseMove(Shift: TShiftState; X, Y: Integer);
  751. begin
  752.   if Assigned(FOnMouseMove) then
  753.     FOnMouseMove(Self, Shift, X, Y);
  754. end;
  755.  
  756. procedure TSRCheckBox.Paint;
  757. var ARect : TRect;
  758. begin
  759.   { Hintergrund zeichnen }
  760.   with Canvas do begin
  761.     if FTransparent then
  762.       Brush.Style:=bsClear
  763.     else begin
  764.       Brush.Style:=bsSolid;
  765.       Brush.Color:=Color;
  766.       ARect:=GetClientRect;
  767.       FillRect(ARect);
  768.     end;
  769.   end;
  770.  
  771.   { Den Rest zeichnen }
  772.   PaintButton;
  773.   PaintCaption;
  774. end;
  775.  
  776. procedure TSRCheckBox.PaintButton;
  777. var ARect : TRect;
  778. begin
  779.   { Ausgaberechteck fⁿr Checkbox ermitteln }
  780.   ARect:=GetClientRect;
  781.   if FAlignment=taLeftJustify then
  782.     ARect.Right:=ARect.Left+FCheckSize
  783.   else
  784.     ARect.Left:=ARect.Right-FCheckSize;
  785.   if FLayout=clCenter then
  786.     ARect.Top:=(ARect.Bottom-ARect.Top-FCheckSize) div 2;
  787.   if FLayout=clBottom then
  788.     ARect.Top:=ARect.Bottom-FCheckSize;
  789.   ARect.Bottom:=ARect.Top+FCheckSize;
  790.  
  791.   { Checkbox zeichnen }
  792.   case FStyle of
  793.     csCheckBox     : DrawCheckBox(Canvas, ARect, FState, Enabled);
  794.     csRadioButton  : DrawRadioButton(Canvas, ARect, FState, Enabled);
  795.     csPushButton   : DrawPushButton(Canvas, ARect, FState, Enabled);
  796.     csDiamond      : DrawDiamond(Canvas, ARect, FState, Enabled);
  797.     csTrafficLight : DrawTrafficLight(Canvas, ARect, FState, Enabled);
  798.   end;
  799. end;
  800.  
  801. procedure TSRCheckBox.PaintCaption;
  802. const
  803.   Alignments: array[TAlignment] of Word =
  804.    (DT_Left, DT_Right, DT_Center);
  805.   WordWraps: array[Boolean] of Word =
  806.    (0, DT_WordBreak);
  807.   Lines: array[Boolean] of Word =
  808.    (DT_SingleLine, 0);
  809. var ARect     : TRect;
  810.     DrawStyle : Integer;
  811. begin
  812.   { Ausgaberechteck fⁿr Caption ermitteln }
  813.   ARect:=GetClientRect;
  814.   if FAlignment=taLeftJustify then
  815.     ARect.Left:=ARect.Left+FCheckSize+FSpacing
  816.   else
  817.     ARect.Right:=ARect.Right-FCheckSize-FSpacing;
  818.  
  819.   { Caption zeichnen }
  820.   Canvas.Font.Assign(Font);
  821.   Canvas.Brush.Style:=bsClear;
  822.   if not Enabled then begin
  823.     Canvas.Font.Color:=clBtnHighlight;
  824.     OffsetRect(ARect, 1, 1);
  825.   end;
  826.   DrawStyle:=DT_ExpandTabs or DT_VCenter or Lines[FWordWrap] or WordWraps[FWordWrap] or Alignments[FAlignment];
  827.   DrawTextComp(Canvas, Caption, ARect, DrawStyle);
  828.   if not Enabled then begin
  829.     Canvas.Font.Color:=clInactiveCaption;
  830.     OffsetRect(ARect, -1, -1);
  831.     DrawTextComp(Canvas, Caption, ARect, DrawStyle);
  832.   end;
  833.   Canvas.Brush.Style:=bsSolid;
  834. end;
  835.  
  836. procedure TSRCheckBox.SetAlignment(newValue: TLeftRight);
  837. begin
  838.   if FAlignment<>newValue then begin
  839.     FAlignment:=newValue;
  840.     Invalidate;
  841.   end;
  842. end;
  843.  
  844. procedure TSRCheckBox.SetAutosize(newValue: boolean);
  845. begin
  846.   if FAutosize<>newValue then begin
  847.     FAutosize:=newValue;
  848.     AdjustBounds;
  849.     Invalidate;
  850.   end;
  851. end;
  852.  
  853. procedure TSRCheckBox.SetColor(newValue: TColor);
  854. begin
  855.   if FColor<>newValue then begin
  856.     FColor:=newValue;
  857.     Invalidate;
  858.   end;
  859. end;
  860.  
  861. procedure TSRCheckBox.SetChecked(newValue: boolean);
  862. begin
  863.   if FChecked<>newValue then begin
  864.     FChecked:=newValue;
  865.     if FChecked then
  866.       SetState(cbChecked)
  867.     else
  868.       SetState(cbUnChecked);
  869.     Invalidate;
  870.   end;
  871. end;
  872.  
  873. procedure TSRCheckBox.SetCheckSize(newValue: integer);
  874. begin
  875.   if FCheckSize<>newValue then begin
  876.     FCheckSize:=newValue;
  877.     AdjustBounds;
  878.     Invalidate;
  879.   end;
  880. end;
  881.  
  882. procedure TSRCheckBox.SetGrouped(newValue: boolean);
  883. begin
  884.   if FGrouped<>newValue then begin
  885.     FGrouped:=newValue;
  886.     if FGrouped and FChecked then
  887.       UncheckGroupCheckBoxes;
  888.   end;
  889. end;
  890.  
  891. procedure TSRCheckBox.SetLayout(newValue: TCheckboxLayout);
  892. begin
  893.   if FLayout<>newValue then begin
  894.     FLayout:=newValue;
  895.     Invalidate;
  896.   end;
  897. end;
  898.  
  899. procedure TSRCheckBox.SetSpacing(newValue: integer);
  900. begin
  901.   if FSpacing<>newValue then begin
  902.     FSpacing:=newValue;
  903.     AdjustBounds;
  904.     Invalidate;
  905.   end;
  906. end;
  907.  
  908. procedure TSRCheckBox.SetState(newValue: TCheckBoxState);
  909. begin
  910.   if FState<>newValue then begin
  911.     FState:=newValue;
  912.     if FState=cbChecked then
  913.       FChecked:=true;
  914.     if FState=cbUnChecked then
  915.       FChecked:=false;
  916.     Change;
  917.     Invalidate;
  918.   end;
  919. end;
  920.  
  921. procedure TSRCheckBox.SetStyle(newValue: TCheckStyle);
  922. begin
  923.   if FStyle<>newValue then begin
  924.     FStyle:=newValue;
  925.     Invalidate;
  926.   end;
  927. end;
  928.  
  929. procedure TSRCheckBox.SetTransparent(newValue: boolean);
  930. begin
  931.   if FTransparent<>newValue then begin
  932.     FTransparent:=newValue;
  933.     Invalidate;
  934.   end;
  935. end;
  936.  
  937. procedure TSRCheckBox.SetWordWrap(newValue: boolean);
  938. begin
  939.   if FWordWrap<>newValue then begin
  940.     FWordWrap:=newValue;
  941.     AdjustBounds;
  942.     Invalidate;
  943.   end;
  944. end;
  945.  
  946. procedure TSRCheckBox.UncheckGroupCheckBoxes;
  947. var i : integer;
  948. begin
  949.   for i:=0 to Self.Parent.ControlCount-1 do
  950.     if Self.Parent.Controls[i] is TSRCheckBox then
  951.       if (TSRCheckBox(Self.Parent.Controls[i])<>Self)
  952.        and TSRCheckBox(Self.Parent.Controls[i]).Grouped
  953.        and TSRCheckBox(Self.Parent.Controls[i]).Checked then
  954.          TSRCheckBox(Self.Parent.Controls[i]).Checked:=false;
  955. end;
  956.  
  957. { Komponente TEnhancedCheckBox }
  958.  
  959. constructor TEnhancedCheckBox.Create(AOwner: TComponent);
  960. begin
  961.   inherited Create(AOwner);
  962.  
  963.   {Vorgabewerte setzen}
  964.   FAlignment:=taLeftJustify;
  965.   FAllowGrayed:=false;
  966.   FAutosize:=false;
  967.   FColor:=clBtnFace;
  968.   FChecked:=false;
  969.   FCheckSize:=13;
  970.   FGrouped:=false;
  971.   FLayout:=clCenter;
  972.   FSpacing:=4;
  973.   FState:=cbUnchecked;
  974.   FWordWrap:=false;
  975.   Width:=90;
  976.   Height:=15;
  977.  
  978.   FMouseDown:=False;
  979.   AdjustBounds;
  980. end;
  981.  
  982. destructor  TEnhancedCheckBox.Destroy;
  983. begin
  984.   inherited Destroy;
  985. end;
  986.  
  987. procedure TEnhancedCheckBox.AdjustBounds;
  988. var ARect : TRect;
  989. begin
  990.   if FAutoSize then begin
  991.     ARect:=GetTextRect(ClientRect);
  992.     ARect.Right:=ARect.Right+FCheckSize+FSpacing;
  993.     InflateRect(ARect, 1, 1);
  994.     SetBounds(Left, Top, ARect.Right, ARect.Bottom);
  995.   end;
  996. end;
  997.  
  998. procedure TEnhancedCheckBox.Change;
  999. begin
  1000.   if FChecked and FGrouped then
  1001.     UncheckGroupCheckBoxes;
  1002.   if Assigned(FOnChange) then
  1003.     FOnChange(Self);
  1004. end;
  1005.  
  1006. procedure TEnhancedCheckBox.CMDialogChar(var Message: TCMDialogChar);
  1007. var AState : integer;
  1008. begin
  1009.   with Message do begin
  1010.     if IsAccellerator(CharCode, Caption) then begin
  1011.       AState:=ord(FState);
  1012.       inc(AState);
  1013.       if (FAllowGrayed and (AState=3)) or (not FAllowGrayed and (AState=2)) then
  1014.         AState:=0;
  1015.       SetState(TCheckBoxState(AState));
  1016.       if Enabled and Assigned(FOnClick) then
  1017.         FOnClick(Self);
  1018.       Result:=1;
  1019.     end
  1020.     else
  1021.       inherited;
  1022.   end;
  1023. end;
  1024.  
  1025. procedure TEnhancedCheckBox.CMFontChanged(var Message: TMessage);
  1026. begin
  1027.   inherited;
  1028.   AdjustBounds;
  1029.   Invalidate;
  1030. end;
  1031.  
  1032. procedure TEnhancedCheckBox.CMTextChanged(var msg: TMessage);
  1033. begin
  1034.   inherited;
  1035.   AdjustBounds;
  1036.   Invalidate;
  1037. end;
  1038.  
  1039. procedure TEnhancedCheckBox.DblClick;
  1040. begin
  1041.   if Enabled then
  1042.     if Assigned(FOnDblClick) then
  1043.       FOnDblClick(Self);
  1044. end;
  1045.  
  1046. procedure TEnhancedCheckBox.DoDrawFocusRect(IsFocused:boolean);
  1047. var CRect : TRect;
  1048. begin
  1049.   CRect:=ClientRect;
  1050.   if FAlignment=taLeftJustify then
  1051.     CRect.Left:=CRect.Left+FCheckSize+FSpacing-1
  1052.   else
  1053.     CRect.Right:=CRect.Right-FCheckSize-FSpacing+1;
  1054.   with Canvas do begin
  1055.     if IsFocused then begin
  1056.       Brush.Color:=clBlack;
  1057.       DrawDotLine(CRect.Left+1, CRect.Top, CRect.Right-CRect.Left-2, true);
  1058.       DrawDotLine(CRect.Right-1, CRect.Top+1, CRect.Bottom-CRect.Top-2, false);
  1059.       DrawDotLine(CRect.Left+1, CRect.Bottom-1, CRect.Right-CRect.Left-2, true);
  1060.       DrawDotLine(CRect.Left, CRect.Top+1, CRect.Bottom-CRect.Top-2, false);
  1061.     end
  1062.     else begin
  1063.       Brush.Color:=Color;
  1064.       FrameRect(CRect);
  1065.     end;
  1066.   end;
  1067. end;
  1068.  
  1069. procedure TEnhancedCheckBox.DrawDotLine(X1,Y1,Length:integer;Horizontal:boolean);
  1070. var i : integer;
  1071. begin
  1072.   with Canvas do begin
  1073.     if Horizontal then begin
  1074.       for i:=X1 to X1+Length-1 do
  1075.         if odd(i) then
  1076.           Pixels[i, Y1]:=Brush.Color;
  1077.     end
  1078.     else begin
  1079.       for i:=Y1 to Y1+Length-1 do
  1080.         if odd(i) then
  1081.           Pixels[X1, i]:=Brush.Color;
  1082.     end;
  1083.   end;
  1084. end;
  1085.  
  1086. function TEnhancedCheckBox.GetTextRect(ARect: TRect): TRect;
  1087. const WordWraps : array[Boolean] of Word = (0, DT_WORDBREAK);
  1088. var AText     : string;
  1089.     DC        : HDC;
  1090.     OldHandle : THandle;
  1091. begin
  1092.   Result:=ARect;
  1093.   AText:=Caption;
  1094.   if (AText='') or ((AText[1]='&') and (AText[2]=#0)) then
  1095.     AText:=AText+' ';
  1096.   OldHandle:=Canvas.Handle;
  1097.   DC:=GetDC(0);
  1098.   try
  1099.     Canvas.Handle:=DC;
  1100.     Canvas.Font:=Font;
  1101.     DrawTextComp(Canvas, AText, Result, (DT_EXPANDTABS or DT_CALCRECT) or WordWraps[FWordWrap]);
  1102.   finally
  1103.     Canvas.Handle:=OldHandle;
  1104.     ReleaseDC(0, DC);
  1105.   end;
  1106. end;
  1107.  
  1108. procedure TEnhancedCheckBox.KeyDown(var Key: Word; Shift: TShiftState);
  1109. begin
  1110.   if Enabled then begin
  1111.     if Key=VK_Space then begin
  1112.       if FState=cbUnChecked then begin
  1113.         SetState(cbChecked);
  1114.         FStateChanged:=true;
  1115.         if Assigned(FOnClick) then
  1116.           FOnClick(Self);
  1117.       end;
  1118.     end;
  1119.   end;
  1120.  
  1121.   inherited KeyDown(Key, Shift);
  1122. end;
  1123.  
  1124. procedure TEnhancedCheckBox.KeyUp(var Key: Word; Shift: TShiftState);
  1125. begin
  1126.   if Enabled then begin
  1127.     { State-Eigenschaft berechnen }
  1128.     if not FStateChanged then begin
  1129.       if FState=cbChecked then begin
  1130.         if not FGrouped then begin
  1131.           if FAllowGrayed then
  1132.             SetState(cbGrayed)
  1133.           else
  1134.             SetState(cbUnChecked);
  1135.           if Assigned(FOnClick) then
  1136.             FOnClick(Self);
  1137.         end;
  1138.       end
  1139.       else begin
  1140.         if FState=cbGrayed then begin
  1141.           SetState(cbUnChecked);
  1142.           if Assigned(FOnClick) then
  1143.             FOnClick(Self);
  1144.         end;
  1145.       end;
  1146.     end;
  1147.     FStateChanged:=false;
  1148.   end;
  1149.  
  1150.   inherited KeyUp(Key, Shift);
  1151. end;
  1152.  
  1153. procedure TEnhancedCheckBox.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  1154. begin
  1155.   if Enabled then begin
  1156.     if Button=mbLeft then begin
  1157.       FMouseDown:=true;
  1158.       if FState=cbUnChecked then begin
  1159.         SetState(cbChecked);
  1160.         FStateChanged:=true;
  1161.         if Assigned(FOnClick) then
  1162.           FOnClick(Self);
  1163.       end;
  1164.     end;
  1165.     if Assigned(FOnMouseDown) then
  1166.       FOnMouseDown(Self, Button, Shift, X, Y);
  1167.   end;
  1168. end;
  1169.  
  1170. procedure TEnhancedCheckBox.MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  1171. begin
  1172.   if Enabled and FMouseDown then begin
  1173.     { State-Eigenschaft berechnen }
  1174.     if not FStateChanged then begin
  1175.       if FState=cbChecked then begin
  1176.         if not FGrouped then begin
  1177.           if FAllowGrayed then
  1178.             SetState(cbGrayed)
  1179.           else
  1180.             SetState(cbUnChecked);
  1181.           if Assigned(FOnClick) then
  1182.             FOnClick(Self);
  1183.         end;
  1184.       end
  1185.       else begin
  1186.         if FState=cbGrayed then begin
  1187.           SetState(cbUnChecked);
  1188.           if Assigned(FOnClick) then
  1189.             FOnClick(Self);
  1190.         end;
  1191.       end;
  1192.     end;
  1193.     FStateChanged:=false;
  1194.  
  1195.     { OnClick-Ereignis abfeuern }
  1196.     if Assigned(FOnMouseUp) then
  1197.       FOnMouseUp(Self, Button, Shift, X, Y);
  1198.   end;
  1199.   FMouseDown:=false;
  1200. end;
  1201.  
  1202. procedure TEnhancedCheckBox.MouseMove(Shift: TShiftState; X, Y: Integer);
  1203. begin
  1204.   if Assigned(FOnMouseMove) then
  1205.     FOnMouseMove(Self, Shift, X, Y);
  1206. end;
  1207.  
  1208. procedure TEnhancedCheckBox.Paint;
  1209. var ARect : TRect;
  1210. begin
  1211.   { Hintergrund zeichnen }
  1212.   with Canvas do begin
  1213.     Brush.Style:=bsSolid;
  1214.     Brush.Color:=Color;
  1215.     ARect:=GetClientRect;
  1216.     FillRect(ARect);
  1217.   end;
  1218.  
  1219.   { Den Rest zeichnen }
  1220.   PaintButton;
  1221.   PaintCaption;
  1222.   DoDrawFocusRect(Focused);
  1223. end;
  1224.  
  1225. procedure TEnhancedCheckBox.PaintButton;
  1226. var ARect : TRect;
  1227. begin
  1228.   { Ausgaberechteck fⁿr Checkbox ermitteln }
  1229.   ARect:=GetClientRect;
  1230.   if FAlignment=taLeftJustify then
  1231.     ARect.Right:=ARect.Left+FCheckSize
  1232.   else
  1233.     ARect.Left:=ARect.Right-FCheckSize;
  1234.   if FLayout=clCenter then
  1235.     ARect.Top:=(ARect.Bottom-ARect.Top-FCheckSize) div 2;
  1236.   if FLayout=clBottom then
  1237.     ARect.Top:=ARect.Bottom-FCheckSize;
  1238.   ARect.Bottom:=ARect.Top+FCheckSize;
  1239.  
  1240.   { Checkbox zeichnen }
  1241.   case FStyle of
  1242.     csCheckBox     : DrawCheckBox(Canvas, ARect, FState, Enabled);
  1243.     csRadioButton  : DrawRadioButton(Canvas, ARect, FState, Enabled);
  1244.     csPushButton   : DrawPushButton(Canvas, ARect, FState, Enabled);
  1245.     csDiamond      : DrawDiamond(Canvas, ARect, FState, Enabled);
  1246.     csTrafficLight : DrawTrafficLight(Canvas, ARect, FState, Enabled);
  1247.   end;
  1248. end;
  1249.  
  1250. procedure TEnhancedCheckBox.PaintCaption;
  1251. const
  1252.   Alignments: array[TAlignment] of Word =
  1253.    (DT_Left, DT_Right, DT_Center);
  1254.   WordWraps: array[Boolean] of Word =
  1255.    (0, DT_WordBreak);
  1256.   Lines: array[Boolean] of Word =
  1257.    (DT_SingleLine, 0);
  1258. var ARect     : TRect;
  1259.     DrawStyle : Integer;
  1260. begin
  1261.   { Ausgaberechteck fⁿr Caption ermitteln }
  1262.   ARect:=GetClientRect;
  1263.   if FAlignment=taLeftJustify then
  1264.     ARect.Left:=ARect.Left+FCheckSize+FSpacing
  1265.   else
  1266.     ARect.Right:=ARect.Right-FCheckSize-FSpacing;
  1267.  
  1268.   { Caption zeichnen }
  1269.   Canvas.Font.Assign(Font);
  1270.   Canvas.Brush.Style:=bsClear;
  1271.   if not Enabled then begin
  1272.     Canvas.Font.Color:=clBtnHighlight;
  1273.     OffsetRect(ARect, 1, 1);
  1274.   end;
  1275.   DrawStyle:=DT_ExpandTabs or DT_VCenter or Lines[FWordWrap] or WordWraps[FWordWrap] or Alignments[FAlignment];
  1276.   DrawTextComp(Canvas, Caption, ARect, DrawStyle);
  1277.   if not Enabled then begin
  1278.     Canvas.Font.Color:=clInactiveCaption;
  1279.     OffsetRect(ARect, -1, -1);
  1280.     DrawTextComp(Canvas, Caption, ARect, DrawStyle);
  1281.   end;
  1282.   Canvas.Brush.Style:=bsSolid;
  1283. end;
  1284.  
  1285. procedure TEnhancedCheckBox.SetAlignment(newValue: TLeftRight);
  1286. begin
  1287.   if FAlignment<>newValue then begin
  1288.     FAlignment:=newValue;
  1289.     Invalidate;
  1290.   end;
  1291. end;
  1292.  
  1293. procedure TEnhancedCheckBox.SetAutosize(newValue: boolean);
  1294. begin
  1295.   if FAutosize<>newValue then begin
  1296.     FAutosize:=newValue;
  1297.     AdjustBounds;
  1298.     Invalidate;
  1299.   end;
  1300. end;
  1301.  
  1302. procedure TEnhancedCheckBox.SetColor(newValue: TColor);
  1303. begin
  1304.   if FColor<>newValue then begin
  1305.     FColor:=newValue;
  1306.     Invalidate;
  1307.   end;
  1308. end;
  1309.  
  1310. procedure TEnhancedCheckBox.SetChecked(newValue: boolean);
  1311. begin
  1312.   if FChecked<>newValue then begin
  1313.     FChecked:=newValue;
  1314.     if FChecked then
  1315.       SetState(cbChecked)
  1316.     else
  1317.       SetState(cbUnChecked);
  1318.     Invalidate;
  1319.   end;
  1320. end;
  1321.  
  1322. procedure TEnhancedCheckBox.SetCheckSize(newValue: integer);
  1323. begin
  1324.   if FCheckSize<>newValue then begin
  1325.     FCheckSize:=newValue;
  1326.     AdjustBounds;
  1327.     Invalidate;
  1328.   end;
  1329. end;
  1330.  
  1331. procedure TEnhancedCheckBox.SetGrouped(newValue: boolean);
  1332. begin
  1333.   if FGrouped<>newValue then begin
  1334.     FGrouped:=newValue;
  1335.     if FGrouped and FChecked then
  1336.       UncheckGroupCheckBoxes;
  1337.   end;
  1338. end;
  1339.  
  1340. procedure TEnhancedCheckBox.SetLayout(newValue: TCheckboxLayout);
  1341. begin
  1342.   if FLayout<>newValue then begin
  1343.     FLayout:=newValue;
  1344.     Invalidate;
  1345.   end;
  1346. end;
  1347.  
  1348. procedure TEnhancedCheckBox.SetSpacing(newValue: integer);
  1349. begin
  1350.   if FSpacing<>newValue then begin
  1351.     FSpacing:=newValue;
  1352.     AdjustBounds;
  1353.     Invalidate;
  1354.   end;
  1355. end;
  1356.  
  1357. procedure TEnhancedCheckBox.SetState(newValue: TCheckBoxState);
  1358. begin
  1359.   if FState<>newValue then begin
  1360.     FState:=newValue;
  1361.     if FState=cbChecked then
  1362.       FChecked:=true;
  1363.     if FState=cbUnChecked then
  1364.       FChecked:=false;
  1365.     Change;
  1366.     Invalidate;
  1367.   end;
  1368. end;
  1369.  
  1370. procedure TEnhancedCheckBox.SetStyle(newValue: TCheckStyle);
  1371. begin
  1372.   if FStyle<>newValue then begin
  1373.     FStyle:=newValue;
  1374.     Invalidate;
  1375.   end;
  1376. end;
  1377.  
  1378. procedure TEnhancedCheckBox.SetWordWrap(newValue: boolean);
  1379. begin
  1380.   if FWordWrap<>newValue then begin
  1381.     FWordWrap:=newValue;
  1382.     AdjustBounds;
  1383.     Invalidate;
  1384.   end;
  1385. end;
  1386.  
  1387. procedure TEnhancedCheckBox.UncheckGroupCheckBoxes;
  1388. var i : integer;
  1389. begin
  1390.   for i:=0 to Self.Parent.ControlCount-1 do
  1391.     if Self.Parent.Controls[i] is TEnhancedCheckBox then
  1392.       if (TEnhancedCheckBox(Self.Parent.Controls[i])<>Self)
  1393.        and TEnhancedCheckBox(Self.Parent.Controls[i]).Grouped
  1394.        and TEnhancedCheckBox(Self.Parent.Controls[i]).Checked then
  1395.          TEnhancedCheckBox(Self.Parent.Controls[i]).Checked:=false;
  1396. end;
  1397.  
  1398. procedure TEnhancedCheckBox.WMKillFocus(var Message: TWMKillFocus);
  1399. begin
  1400.   inherited;
  1401.   DoDrawFocusRect(false);
  1402. end;
  1403.  
  1404. procedure TEnhancedCheckBox.WMSetFocus(var Message: TWMSetFocus);
  1405. begin
  1406.   inherited;
  1407.   DoDrawFocusRect(true);
  1408. end;
  1409.  
  1410. procedure Register;
  1411. begin
  1412.   RegisterComponents('Simon', [TSRCheckBox, TEnhancedCheckBox]);
  1413. end;
  1414.  
  1415. end.
  1416.