LCL: moved default TSpeedButton frame drawing to TWSSpeedButton.DrawFrame to enable better overriding for different widgetsets

git-svn-id: trunk@11052 -
This commit is contained in:
tombo 2007-05-02 11:49:39 +00:00
parent 71cbca5431
commit 3896c4cd5d
2 changed files with 58 additions and 26 deletions

View File

@ -442,7 +442,6 @@ var
TXTStyle : TTextStyle;
SIndex : Longint;
TMP : String;
xBevel : tBevelCut;
begin
UpdateState(false);
if FGlyph=nil then exit;
@ -451,33 +450,15 @@ begin
FLastDrawFlags:=GetDrawFlags;
//DebugLn('TCustomSpeedButton.Paint ',Name,':',ClassName,' Parent.Name=',Parent.Name);
// do not draw anything if flat and mouse not in control (simplified)
if Transparent then begin
if (FLastDrawFlags and DFCS_FLAT) = 0 then begin
if (FLastDrawFlags and DFCS_PUSHED) <>0 then xBevel := bvLowered
else xBevel := bvRaised;
Canvas.Frame3D(PaintRect,1,xBevel);
InflateRect(PaintRect, -1, -1);
end;
end else begin
if (FLastDrawFlags and DFCS_FLAT) = 0 then begin
DrawFrameControl(Canvas.GetUpdatedHandle([csBrushValid,csPenValid]),
PaintRect, DFC_BUTTON, FLastDrawFlags);
InflateRect(PaintRect, -1, -1);
end;
end;
TWSSpeedButton.DrawFrame(Self, FLastDrawFlags, PaintRect);
//debugln(['TCustomSpeedButton.Paint ',Name,':',ClassName,' Parent.Name=',Parent.Name,
// ' DFCS_BUTTONPUSH=',FLastDrawFlags and DFCS_BUTTONPUSH,
// ' DFCS_PUSHED=',FLastDrawFlags and DFCS_PUSHED,
// ' DFCS_INACTIVE=',FLastDrawFlags and DFCS_INACTIVE,
// ' DFCS_FLAT=',FLastDrawFlags and DFCS_FLAT,
// '']);
if (not Transparent) and Enabled and (Color<>clBtnFace) then begin
Canvas.Brush.Color := Color;
Canvas.FillRect(PaintRect);
end;
GlyphSize := GetGlyphSize(PaintRect);
GlyphWidth := GlyphSize.CX;

View File

@ -44,9 +44,9 @@ uses
// To get as little as posible circles,
// uncomment only when needed for registration
////////////////////////////////////////////////////
Buttons, Graphics,
Classes, Controls, Buttons, Graphics,
////////////////////////////////////////////////////
WSLCLClasses, WSStdCtrls, WSControls, LCLType;
WSLCLClasses, WSStdCtrls, WSControls, LCLType, LCLIntf;
type
@ -71,6 +71,7 @@ type
{ TWSSpeedButton }
TWSSpeedButton = class(TWSGraphicControl)
class procedure DrawFrame(const ASpeedButton: TCustomSpeedButton; const ADrawFlags: Integer; var ARect: TRect); virtual;
end;
@ -111,6 +112,56 @@ begin
end;
{ TWSSpeedButton }
{------------------------------------------------------------------------------
Method: TWSSpeedButton.DrawFrame
Params: ASpeedButton - LCL custom speed button
ADrawFlags - Frame draw flags (DFCS_*)
ARect - Frame rectangle, returned adjusted to frame client
area
Draws a speed button frame according to the specified draw flags
------------------------------------------------------------------------------}
class procedure TWSSpeedButton.DrawFrame(const ASpeedButton: TCustomSpeedButton;
const ADrawFlags: Integer; var ARect: TRect);
var
Bevel: TBevelCut;
begin
// do not draw anything if flat and mouse not in control (simplified)
if ASpeedButton.Transparent then
begin
if (ADrawFlags and DFCS_FLAT) = 0 then
begin
if (ADrawFlags and DFCS_PUSHED) <> 0 then
Bevel := bvLowered
else
Bevel := bvRaised;
ASpeedButton.Canvas.Frame3D(ARect, 1, Bevel);
InflateRect(ARect, -1, -1);
end;
end
else
begin
if (ADrawFlags and DFCS_FLAT) = 0 then
begin
DrawFrameControl(
ASpeedButton.Canvas.GetUpdatedHandle([csBrushValid,csPenValid]),
ARect, DFC_BUTTON, ADrawFlags);
InflateRect(ARect, -1, -1);
end;
end;
if (not ASpeedButton.Transparent) and ASpeedButton.Enabled and
(ASpeedButton.Color <> clBtnFace) then
begin
ASpeedButton.Canvas.Brush.Color := ASpeedButton.Color;
ASpeedButton.Canvas.FillRect(ARect);
end;
end;
initialization
////////////////////////////////////////////////////
@ -119,6 +170,6 @@ initialization
////////////////////////////////////////////////////
// RegisterWSComponent(TCustomButton, TWSButton);
// RegisterWSComponent(TCustomBitBtn, TWSBitBtn);
// RegisterWSComponent(TCustomSpeedButton, TWSSpeedButton);
RegisterWSComponent(TCustomSpeedButton, TWSSpeedButton);
////////////////////////////////////////////////////
end.
end.