The enclosed patch provides a fix for the NumGlyph bug in TBitBtn.
It can be improved in future, adding a State property to the button, but
at least it shows just one glyph when NumGlyph is > 1 and will display a
different glyph for enabled and disabled state.
Giuliano
Index: include/bitbtn.inc
===================================================================
--- include/bitbtn.inc (revisione 12447)
+++ include/bitbtn.inc (copia locale)
@@ -28,6 +28,7 @@
fMargin:=-1;
FButtonGlyph := TButtonGlyph.Create;
FButtonGlyph.OnChange := @GlyphChanged;
+ FGlyph := TBitmap.Create;
Align := alNone;
BorderSpacing.InnerBorder:=4;
SetInitialBounds(0,0,75,30);
@@ -40,6 +41,7 @@
destructor TCustomBitBtn.Destroy;
Begin
FreeThenNil(FButtonGlyph);
+ FreeThenNil(FGlyph);
inherited Destroy;
end;
@@ -84,7 +86,10 @@
procedure TCustomBitBtn.GlyphChanged(Sender: TObject);
begin
if HandleAllocated
- then TWSBitBtnClass(WidgetSetClass).SetGlyph(Self, Glyph);
+ then begin
+ DrawGlyph;
+ TWSBitBtnClass(WidgetSetClass).SetGlyph(Self, FGlyph);
+ end;
InvalidatePreferredSize;
AdjustSize;
end;
@@ -221,6 +226,33 @@
end;
end;
+procedure TCustomBitBtn.DrawGlyph;
+var
+ AGlyphRect: TRect;
+ AOffset: TPoint;
+ AState :TButtonState;
+begin
+ if FButtonGlyph.FOriginal = nil then exit;
+ AOffset.X:= 0;
+ AOffset.Y:= 0;
+ AGlyphRect.Left :=0;
+ AGlyphRect.Top := 0;
+ AGlyphRect.Bottom:= FButtonGlyph.Glyph.Height;
+ if NumGlyphs > 1 then
+ AGlyphRect.Right:= FButtonGlyph.Glyph.Width div NumGlyphs
+ else
+ AGlyphRect.Right:= FButtonGlyph.Glyph.Width;
+ FGlyph.Height:=AGlyphRect.Bottom;
+ FGlyph.Width:=AGlyphRect.Right;
+
+ FGlyph.Canvas.Brush.Color:=Color;
+ FGlyph.Canvas.FillRect(AGlyphRect);
+
+ if Enabled then AState := bsUp
+ else AState := bsDisabled;
+ FButtonGlyph.Draw(FGlyph.Canvas,AGlyphRect,AOffset,AState,True,0);
+end;
+
{ Return the caption associated with the akind value.
This function replaces BitBtnCaption const because the localizing
dont work with an const array }
@@ -246,7 +278,8 @@
procedure TCustomBitBtn.InitializeWnd;
begin
inherited;
- TWSBitBtnClass(WidgetSetClass).SetGlyph(Self, Glyph);
+ DrawGlyph;
+ TWSBitBtnClass(WidgetSetClass).SetGlyph(Self, FGlyph);
TWSBitBtnClass(WidgetSetClass).SetLayout(Self, FLayout);
TWSBitBtnClass(WidgetSetClass).SetMargin(Self, FMargin);
TWSBitBtnClass(WidgetSetClass).SetSpacing(Self, FSpacing);
Index: buttons.pp
===================================================================
--- buttons.pp (revisione 12447)
+++ buttons.pp (copia locale)
@@ -103,6 +103,7 @@
FLayout: TButtonLayout;
FMargin: integer;
FSpacing: Integer;
+ FGlyph: TBitmap;
Function GetGlyph: TBitmap;
function GetNumGlyphs: Integer;
Function IsGlyphStored: Boolean;
@@ -113,7 +114,7 @@
procedure SetNumGlyphs(AValue: Integer);
Procedure SetSpacing(AValue: Integer);
procedure RealizeKind;
-
+ procedure DrawGlyph;
//Return the caption associated with the aKind value.
function GetCaptionOfKind(aKind: TBitBtnKind): String;
protected