lcl: add TCustomBitBtn.LoadGlyphFromLazarusResource

git-svn-id: trunk@16648 -
This commit is contained in:
paul 2008-09-19 14:18:30 +00:00
parent 5482e9dde7
commit fa7ae42825
4 changed files with 42 additions and 32 deletions

View File

@ -163,6 +163,7 @@ type
constructor Create(TheOwner: TComponent); override;
destructor Destroy; override;
procedure Click; override;
procedure LoadGlyphFromLazarusResource(const AName: String);
public
property Glyph: TBitmap read GetGlyph write SetGlyph stored IsGlyphStored;
property NumGlyphs: Integer read GetNumGlyphs write SetNumGlyphs default 1;
@ -384,6 +385,7 @@ var
GetDefaultBitBtnGlyph: TGetDefaultBitBtnGlyph = nil;
function GetLCLDefaultBtnGlyph(Kind: TBitBtnKind): TGraphic;
procedure LoadGlyphFromLazarusResource(AGlyph: TButtonGlyph; const AName: String);
procedure Register;
@ -428,6 +430,40 @@ begin
Result := CreateBitmapFromLazarusResource(BitBtnResNames[Kind]);
end;
procedure LoadGlyphFromLazarusResource(AGlyph: TButtonGlyph; const AName: String);
var
C: TCustomBitmap;
B: TBitmap;
begin
if AName = '' then
C := nil
else
C := CreateBitmapFromLazarusResource(AName);
if C = nil
then begin
AGlyph.Glyph := nil;
Exit;
end;
B := nil;
try
if AGlyph.Glyph <> nil
then begin
AGlyph.Glyph.Assign(C);
Exit;
end;
// unfortunately a Glyph doesn't support a custom bitmap yet.
// So we need a Bitmap helper
B := TBitmap.Create;
B.Assign(C);
AGlyph.Glyph := B;
finally
B.Free;
C.Free;
end;
end;
procedure Register;
begin
RegisterComponents('Additional',[TBitBtn,TSpeedButton]);

View File

@ -55,6 +55,11 @@ Begin
inherited Click;
End;
procedure TCustomBitBtn.LoadGlyphFromLazarusResource(const AName: String);
begin
Buttons.LoadGlyphFromLazarusResource(FButtonGlyph, AName);
end;
function TCustomBitBtn.GetGlyph : TBitmap;
Begin
Result := FButtonGlyph.Glyph;

View File

@ -16,7 +16,6 @@
}
type
{ TGlyphBitmap }
TGlyphBitmap = class(TBitmap)

View File

@ -862,38 +862,8 @@ begin
end;
procedure TCustomSpeedButton.LoadGlyphFromLazarusResource(const AName: String);
var
C: TCustomBitmap;
B: TBitmap;
begin
if AName = '' then
C := nil
else
C := CreateBitmapFromLazarusResource(AName);
if C = nil
then begin
SetGlyph(nil);
Exit;
end;
try
if FGlyph.Glyph <> nil
then begin
B := nil;
FGlyph.Glyph.Assign(C);
Exit;
end;
// unfortunately a Glyph doesn't support a custom bitmap yet.
// So we need a Bitmap helper
B := TBitmap.Create;
B.Assign(C);
SetGlyph(B);
finally
B.Free;
C.Free;
end;
Buttons.LoadGlyphFromLazarusResource(FGlyph, AName);
end;
function TCustomSpeedButton.GetGlyphSize(PaintRect: TRect): TSize;