فهرست منبع

Cleanup OnClick and make OnDblClick actually work.

Martijn Laan 1 ماه پیش
والد
کامیت
282e8ca166
1فایلهای تغییر یافته به همراه8 افزوده شده و 9 حذف شده
  1. 8 9
      Components/BitmapButton.pas

+ 8 - 9
Components/BitmapButton.pas

@@ -26,8 +26,6 @@ type
   private
   private
     FFocusBorderWidthHeight: Integer;
     FFocusBorderWidthHeight: Integer;
     FImpl: TBitmapImageImplementation;
     FImpl: TBitmapImageImplementation;
-    FOnClick: TNotifyEvent;
-    FOnDblClick: TNotifyEvent;
     procedure SetBackColor(Value: TColor);
     procedure SetBackColor(Value: TColor);
     procedure SetBitmap(Value: TBitmap);
     procedure SetBitmap(Value: TBitmap);
     procedure SetCenter(Value: Boolean);
     procedure SetCenter(Value: Boolean);
@@ -64,8 +62,8 @@ type
     property TabOrder;
     property TabOrder;
     property TabStop default True;
     property TabStop default True;
     property Visible;
     property Visible;
-    property OnClick: TNotifyEvent read FOnClick write FOnClick;
-    property OnDblClick: TNotifyEvent read FOnDblClick write FOnDblClick;
+    property OnClick;
+    property OnDblClick;
     property OnPaint: TPaintEvent read FImpl.OnPaint write FImpl.OnPaint;
     property OnPaint: TPaintEvent read FImpl.OnPaint write FImpl.OnPaint;
   end;
   end;
 
 
@@ -81,7 +79,7 @@ end;
 constructor TBitmapButton.Create(AOwner: TComponent);
 constructor TBitmapButton.Create(AOwner: TComponent);
 begin
 begin
   inherited;
   inherited;
-  ControlStyle := ControlStyle + [csReplicatable];
+  ControlStyle := ControlStyle + [csReplicatable] - [csClickEvents];
   { Using a fixed focus border width/height to avoid design problems between systems }
   { Using a fixed focus border width/height to avoid design problems between systems }
   FFocusBorderWidthHeight := 2;
   FFocusBorderWidthHeight := 2;
   const DoubleFBWH = 2*FFocusBorderWidthHeight;
   const DoubleFBWH = 2*FFocusBorderWidthHeight;
@@ -96,6 +94,7 @@ procedure TBitmapButton.CreateParams(var Params: TCreateParams);
 begin
 begin
   inherited;
   inherited;
   CreateSubClass(Params, 'BUTTON');
   CreateSubClass(Params, 'BUTTON');
+  Params.Style := Params.Style or BS_NOTIFY; { For BN_DBLCLK }
 end;
 end;
 
 
 destructor TBitmapButton.Destroy;
 destructor TBitmapButton.Destroy;
@@ -184,10 +183,10 @@ end;
 
 
 procedure TBitmapButton.CNCommand(var Message: TWMCommand);
 procedure TBitmapButton.CNCommand(var Message: TWMCommand);
 begin
 begin
-  if (Message.NotifyCode = BN_CLICKED) and Assigned(FOnClick) then
-    FOnClick(Self)
-  else if (Message.NotifyCode = BN_DBLCLK) and Assigned(FOnDblClick) then
-    FOnDblClick(Self);
+  if (Message.NotifyCode = BN_CLICKED) then
+    Click
+  else if (Message.NotifyCode = BN_DBLCLK) then
+    DblClick;
 end;
 end;
 
 
 end.
 end.