From fa7ae4282592e2850d0af220a43f5ea4da5e5505 Mon Sep 17 00:00:00 2001 From: paul Date: Fri, 19 Sep 2008 14:18:30 +0000 Subject: [PATCH] lcl: add TCustomBitBtn.LoadGlyphFromLazarusResource git-svn-id: trunk@16648 - --- lcl/buttons.pp | 36 ++++++++++++++++++++++++++++++++++++ lcl/include/bitbtn.inc | 5 +++++ lcl/include/buttonglyph.inc | 1 - lcl/include/speedbutton.inc | 32 +------------------------------- 4 files changed, 42 insertions(+), 32 deletions(-) diff --git a/lcl/buttons.pp b/lcl/buttons.pp index 8688584733..068410c93f 100644 --- a/lcl/buttons.pp +++ b/lcl/buttons.pp @@ -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]); diff --git a/lcl/include/bitbtn.inc b/lcl/include/bitbtn.inc index 9d9b9d97db..02cff0154b 100644 --- a/lcl/include/bitbtn.inc +++ b/lcl/include/bitbtn.inc @@ -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; diff --git a/lcl/include/buttonglyph.inc b/lcl/include/buttonglyph.inc index f0521e38db..89064cb0e7 100644 --- a/lcl/include/buttonglyph.inc +++ b/lcl/include/buttonglyph.inc @@ -16,7 +16,6 @@ } type - { TGlyphBitmap } TGlyphBitmap = class(TBitmap) diff --git a/lcl/include/speedbutton.inc b/lcl/include/speedbutton.inc index 844009181d..1934d93519 100644 --- a/lcl/include/speedbutton.inc +++ b/lcl/include/speedbutton.inc @@ -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;