1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
| unit mySpeedButton;
//Vers. 10.09.29.18.54
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, Buttons;
type
TmySpeedButton = class(TSpeedButton)
private
{ Private declarations }
FBitmapOver: TBitmap;
FBitmapOut: TBitmap;
FBitmapSelected: TBitmap;
FNumGlyphs : Integer;
// Modification des événements........................................... [partie 1]
FOnMouseEnter: TNotifyEvent;
FOnMouseLeave: TNotifyEvent;
FOnMouseDown : TNotifyEvent;
FOnMouseUp : TNotifyEvent;
FOnResize : TNotifyEvent;
// Modification des évènements............................... [partie 1-bis]
procedure SelfOnMouseEnter (Sender : TObject); //procedure complémentaire
procedure SelfOnMouseLeave (Sender : TObject); // idem
procedure SelfOnResize (Sender : TObject); // idem
procedure SelfOnMouseDown (Sender: TObject;Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure SelfOnMouseUp (Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
// Autres procedures : affectation des valeurs (dont blocage de NumGlyphs)
procedure SetNumGlyphs(Value : Integer);
procedure SetBitmapOver(Value: TBitmap);
procedure SetBitmapOut(Value: TBitmap);
procedure SetBitmapSelected(Value: TBitmap);
protected
{ Protected declarations }
public
{ Public declarations }
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
{ Published declarations }
property GlyphOver: TBitmap Read FBitmapOver Write SetBitmapOver;
property GlyphOut: TBitmap Read FBitmapOut Write SetBitmapOut;
property GlyphSelected:TBitmap Read FBitmapSelected Write SetBitmapSelected;
property NumGlyphs : integer read FNumGlyphs write SetNumGlyphs;
// Modification des évènements .................................. [partie 2]
property OnMouseEnter : TNotifyEvent read FOnMouseEnter write FOnMouseEnter;
property OnMouseLeave : TNotifyEvent read FOnMouseLeave write FOnMouseLeave;
property OnResize : TNotifyEvent read FOnResize write FOnResize;
property OnMouseDown : TNotifyEvent read FOnMouseDown write FOnMouseDown;
property OnMouseUp : TNotifyEvent read FOnMouseUp write FOnMouseUp;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Additional',[TmySpeedButton]);
end;
constructor Tmyspeedbutton.Create(AOwner: TComponent);
begin
Inherited Create(AOwner);
FBitmapOut := TBitmap.Create;
FBitmapOver := TBitmap.Create;
FBitmapSelected := TBitmap.Create;
FNumGlyphs := 1;
// Modification des évènements .................................. [partie 3]
FOnMouseEnter := nil;
Inherited OnMouseEnter := @SelfOnMouseEnter;
FOnMouseLeave := nil;
Inherited OnMouseLeave := @SelfOnMouseLeave;
FOnResize := nil;
Inherited OnResize := @SelfOnResize;
FOnMouseDown := nil;
Inherited OnMouseDown := @SelfOnMouseDown;
FOnMouseUp := nil;
Inherited OnMouseUp := @SelfOnMouseUp;
end;
destructor Tmyspeedbutton.Destroy;
begin
FBitmapSelected.Free;
FBitmapOver.Free;
FBitmapOut.Free;
inherited Destroy;
end;
// Modification des évènements .................................. [partie 4]
procedure Tmyspeedbutton.SelfOnMouseEnter(Sender : TObject);
begin
Self.Glyph := FBitmapOver;
//Si code OnMouseEnter alors l'exécuter
if Assigned(FOnMouseEnter) then FOnMouseEnter(Sender);
//Cette dernière ligne est à éliminer s'il s'agit d'un code de remplacement et
//non d'un code complémentaire précédant ou suivant le code de l'utilisateur.
end;
procedure Tmyspeedbutton.SelfOnMouseLeave(Sender : TObject);
begin
Self.Glyph := FBitmapOut;
if Assigned(FOnMouseLeave) then FOnMouseLeave(Sender);
end;
procedure Tmyspeedbutton.SelfOnResize(Sender : TObject);
begin
Self.Glyph := FBitmapOut;
if Assigned(FOnResize) then FOnResize(Sender);
end;
procedure Tmyspeedbutton.SelfOnMouseDown(Sender: TObject;Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if Button <> mbLeft then
inherited
else begin
Self.Glyph := FBitmapSelected;
if Assigned(FOnMouseDown) then FOnMouseDown(Sender);
end;
end;
procedure Tmyspeedbutton.SelfOnMouseUp(Sender: TObject;Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if Button <> mbLeft then
inherited
else begin
if (X > 0) and (X < Self.Width) and (Y > 0) and (Y < Self.Height) then
Self.Glyph := FBitmapOver
else
Self.Glyph := FBitmapOut;
if Assigned(FOnMouseUp) then FOnMouseUp(Sender);
end;
end;
// Autres procedures : affectation des valeurs (dont blocage de NumGlyphs)
procedure Tmyspeedbutton.SetNumGlyphs(Value : Integer);
begin
value := 1;
end;
procedure Tmyspeedbutton.SetBitmapOver(Value: TBitmap);
begin
FBitmapOver.Assign(value);
invalidate;
end;
procedure Tmyspeedbutton.SetBitmapOut(Value: TBitmap);
begin
FBitmapOut.Assign(value);
invalidate;
end;
procedure Tmyspeedbutton.SetBitmapSelected(Value: TBitmap);
begin
FBitmapSelected.Assign(value);
invalidate;
end;
end. |
Partager