mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-15 07:42:10 +02:00
- implement speedbutton theme painting (disabled through define UseThemes now)
git-svn-id: trunk@11163 -
This commit is contained in:
parent
a3507ade6c
commit
dc5845e19a
@ -40,7 +40,7 @@ interface
|
|||||||
uses
|
uses
|
||||||
Types, Classes, SysUtils, LCLType, LCLProc, LCLIntf, LCLStrConsts,
|
Types, Classes, SysUtils, LCLType, LCLProc, LCLIntf, LCLStrConsts,
|
||||||
GraphType, Graphics, ImgList, ActnList, Controls, StdCtrls, lMessages, Forms,
|
GraphType, Graphics, ImgList, ActnList, Controls, StdCtrls, lMessages, Forms,
|
||||||
Menus {for ShortCut procedures};
|
Themes, Menus {for ShortCut procedures};
|
||||||
|
|
||||||
type
|
type
|
||||||
{ TButton }
|
{ TButton }
|
||||||
@ -278,6 +278,7 @@ type
|
|||||||
procedure SetChecked(Value: Boolean); override;
|
procedure SetChecked(Value: Boolean); override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
//{$define UseThemes}
|
||||||
|
|
||||||
{ TCustomSpeedButton }
|
{ TCustomSpeedButton }
|
||||||
|
|
||||||
@ -290,7 +291,11 @@ type
|
|||||||
FFlat: Boolean;
|
FFlat: Boolean;
|
||||||
FGlyph: TButtonGlyph;
|
FGlyph: TButtonGlyph;
|
||||||
FGroupIndex: Integer;
|
FGroupIndex: Integer;
|
||||||
|
{$ifndef UseThemes}
|
||||||
FLastDrawFlags: integer;
|
FLastDrawFlags: integer;
|
||||||
|
{$else}
|
||||||
|
FLastDrawDetails: TThemedElementDetails;
|
||||||
|
{$endif}
|
||||||
FLayout: TButtonLayout;
|
FLayout: TButtonLayout;
|
||||||
FMargin: integer;
|
FMargin: integer;
|
||||||
FMouseInControl: Boolean;
|
FMouseInControl: Boolean;
|
||||||
@ -333,7 +338,11 @@ type
|
|||||||
procedure RealSetText(const Value: TCaption); override;
|
procedure RealSetText(const Value: TCaption); override;
|
||||||
procedure SetEnabled(NewEnabled: boolean); override;
|
procedure SetEnabled(NewEnabled: boolean); override;
|
||||||
procedure UpdateState(InvalidateOnChange: boolean); virtual;
|
procedure UpdateState(InvalidateOnChange: boolean); virtual;
|
||||||
|
{$ifndef UseThemes}
|
||||||
function GetDrawFlags: integer; virtual;
|
function GetDrawFlags: integer; virtual;
|
||||||
|
{$else}
|
||||||
|
function GetDrawDetails: TThemedElementDetails; virtual;
|
||||||
|
{$endif}
|
||||||
property MouseInControl: Boolean read FMouseInControl;
|
property MouseInControl: Boolean read FMouseInControl;
|
||||||
procedure ActionChange(Sender: TObject; CheckDefaults: Boolean); override;
|
procedure ActionChange(Sender: TObject; CheckDefaults: Boolean); override;
|
||||||
function GetActionLinkClass: TControlActionLinkClass; override;
|
function GetActionLinkClass: TControlActionLinkClass; override;
|
||||||
|
@ -294,8 +294,15 @@ begin
|
|||||||
if (Action is TCustomAction) then
|
if (Action is TCustomAction) then
|
||||||
TCustomAction(Action).Checked := FState=bsDown;
|
TCustomAction(Action).Checked := FState=bsDown;
|
||||||
|
|
||||||
if InvalidateOnChange
|
if InvalidateOnChange and
|
||||||
and ((FState<>OldState) or (FLastDrawFlags<>GetDrawFlags))
|
(
|
||||||
|
(FState<>OldState) or
|
||||||
|
{$ifndef UseThemes}
|
||||||
|
(FLastDrawFlags<>GetDrawFlags)
|
||||||
|
{$else}
|
||||||
|
not ThemedElementDetailsEqual(FLastDrawDetails, GetDrawDetails)
|
||||||
|
{$endif}
|
||||||
|
)
|
||||||
then
|
then
|
||||||
Invalidate;
|
Invalidate;
|
||||||
end;
|
end;
|
||||||
@ -303,6 +310,7 @@ end;
|
|||||||
{------------------------------------------------------------------------------
|
{------------------------------------------------------------------------------
|
||||||
function TCustomSpeedButton.GetDrawFlags: integer;
|
function TCustomSpeedButton.GetDrawFlags: integer;
|
||||||
------------------------------------------------------------------------------}
|
------------------------------------------------------------------------------}
|
||||||
|
{$ifndef UseThemes}
|
||||||
function TCustomSpeedButton.GetDrawFlags: integer;
|
function TCustomSpeedButton.GetDrawFlags: integer;
|
||||||
begin
|
begin
|
||||||
// if flat and not mouse in control and not down, don't draw anything
|
// if flat and not mouse in control and not down, don't draw anything
|
||||||
@ -321,6 +329,57 @@ begin
|
|||||||
inc(Result,DFCS_CHECKED);
|
inc(Result,DFCS_CHECKED);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
{$else}
|
||||||
|
function TCustomSpeedButton.GetDrawDetails: TThemedElementDetails;
|
||||||
|
function ButtonPart: TThemedButton;
|
||||||
|
begin
|
||||||
|
//tbPushButtonNormal, tbPushButtonHot, tbPushButtonPressed, tbPushButtonDisabled, tbPushButtonDefaulted
|
||||||
|
|
||||||
|
// no check states available
|
||||||
|
|
||||||
|
Result := tbPushButtonNormal;
|
||||||
|
if not Enabled then
|
||||||
|
inc(Result, 3)
|
||||||
|
else
|
||||||
|
if FState in [bsDown, bsExclusive] then
|
||||||
|
inc(Result, 2)
|
||||||
|
else
|
||||||
|
if fMouseInControl then
|
||||||
|
inc(Result, 1);
|
||||||
|
end;
|
||||||
|
|
||||||
|
function ToolButtonPart: TThemedToolBar;
|
||||||
|
begin
|
||||||
|
//ttbButtonNormal, ttbButtonHot, ttbButtonPressed, ttbButtonDisabled
|
||||||
|
Result := ttbButtonNormal;
|
||||||
|
if not Enabled then
|
||||||
|
inc(Result, 3)
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
if Down then
|
||||||
|
begin // checked states
|
||||||
|
if fMouseInControl then
|
||||||
|
inc(Result, 5)
|
||||||
|
else
|
||||||
|
inc(Result, 4);
|
||||||
|
end
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
if FState in [bsDown, bsExclusive] then
|
||||||
|
inc(Result, 2) else
|
||||||
|
if fMouseInControl then
|
||||||
|
inc(Result, 1);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
begin
|
||||||
|
if Flat then
|
||||||
|
Result := ThemeServices.GetElementDetails(ToolButtonPart)
|
||||||
|
else
|
||||||
|
Result := ThemeServices.GetElementDetails(ButtonPart)
|
||||||
|
end;
|
||||||
|
{$endif}
|
||||||
|
|
||||||
procedure TCustomSpeedButton.ActionChange(Sender: TObject;
|
procedure TCustomSpeedButton.ActionChange(Sender: TObject;
|
||||||
CheckDefaults: Boolean);
|
CheckDefaults: Boolean);
|
||||||
@ -439,15 +498,18 @@ var
|
|||||||
Offset, OffsetCap: TPoint;
|
Offset, OffsetCap: TPoint;
|
||||||
ClientSize, TotalSize, TextSize, GlyphSize: TSize;
|
ClientSize, TotalSize, TextSize, GlyphSize: TSize;
|
||||||
M, S : integer;
|
M, S : integer;
|
||||||
TXTStyle : TTextStyle;
|
|
||||||
SIndex : Longint;
|
SIndex : Longint;
|
||||||
TMP : String;
|
TMP : String;
|
||||||
|
{$ifndef UseThemes}
|
||||||
|
TXTStyle : TTextStyle;
|
||||||
|
{$endif}
|
||||||
begin
|
begin
|
||||||
UpdateState(false);
|
UpdateState(false);
|
||||||
if FGlyph=nil then exit;
|
if FGlyph=nil then exit;
|
||||||
|
|
||||||
PaintRect:=ClientRect;
|
PaintRect:=ClientRect;
|
||||||
|
|
||||||
|
{$ifndef UseThemes}
|
||||||
FLastDrawFlags:=GetDrawFlags;
|
FLastDrawFlags:=GetDrawFlags;
|
||||||
//DebugLn('TCustomSpeedButton.Paint ',Name,':',ClassName,' Parent.Name=',Parent.Name);
|
//DebugLn('TCustomSpeedButton.Paint ',Name,':',ClassName,' Parent.Name=',Parent.Name);
|
||||||
|
|
||||||
@ -459,7 +521,16 @@ begin
|
|||||||
// ' DFCS_INACTIVE=',FLastDrawFlags and DFCS_INACTIVE,
|
// ' DFCS_INACTIVE=',FLastDrawFlags and DFCS_INACTIVE,
|
||||||
// ' DFCS_FLAT=',FLastDrawFlags and DFCS_FLAT,
|
// ' DFCS_FLAT=',FLastDrawFlags and DFCS_FLAT,
|
||||||
// '']);
|
// '']);
|
||||||
|
{$else}
|
||||||
|
FLastDrawDetails := GetDrawDetails;
|
||||||
|
if not Transparent and ThemeServices.HasTransparentParts(FLastDrawDetails) then
|
||||||
|
begin
|
||||||
|
Canvas.Brush.Color := Color;
|
||||||
|
Canvas.FillRect(PaintRect);
|
||||||
|
end;
|
||||||
|
ThemeServices.DrawElement(Canvas.Handle, FLastDrawDetails, PaintRect);
|
||||||
|
PaintRect := ThemeServices.ContentRect(Canvas.Handle, FLastDrawDetails, PaintRect);
|
||||||
|
{$endif}
|
||||||
GlyphSize := GetGlyphSize(PaintRect);
|
GlyphSize := GetGlyphSize(PaintRect);
|
||||||
GlyphWidth := GlyphSize.CX;
|
GlyphWidth := GlyphSize.CX;
|
||||||
if TButtonGlyph(FGlyph).NumGlyphs > 1 then
|
if TButtonGlyph(FGlyph).NumGlyphs > 1 then
|
||||||
@ -546,9 +617,16 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
// todo: for Themed painting we need imagelist here. Wait for it implementation
|
||||||
DrawGlyph(Canvas, PaintRect, Offset, FState, Transparent, 0);
|
DrawGlyph(Canvas, PaintRect, Offset, FState, Transparent, 0);
|
||||||
if FShowCaption and (Caption <> '') then
|
if FShowCaption and (Caption <> '') then
|
||||||
begin
|
begin
|
||||||
|
with PaintRect, OffsetCap do
|
||||||
|
begin
|
||||||
|
Left := Left + X;
|
||||||
|
Top := Top + Y;
|
||||||
|
end;
|
||||||
|
{$ifndef UseThemes}
|
||||||
TXTStyle := Canvas.TextStyle;
|
TXTStyle := Canvas.TextStyle;
|
||||||
TXTStyle.Opaque := False;
|
TXTStyle.Opaque := False;
|
||||||
TXTStyle.Clipping := True;
|
TXTStyle.Clipping := True;
|
||||||
@ -559,19 +637,16 @@ begin
|
|||||||
Canvas.Font.Color := Font.Color;
|
Canvas.Font.Color := Font.Color;
|
||||||
TXTStyle.SystemFont := Canvas.Font.IsDefault;//Match System Default Style
|
TXTStyle.SystemFont := Canvas.Font.IsDefault;//Match System Default Style
|
||||||
|
|
||||||
With PaintRect, OffsetCap do begin
|
if not Enabled then
|
||||||
Left := Left + X;
|
begin
|
||||||
Top := Top + Y;
|
|
||||||
end;
|
|
||||||
|
|
||||||
If not Enabled then begin
|
|
||||||
Canvas.Font.Color := clBtnHighlight;
|
Canvas.Font.Color := clBtnHighlight;
|
||||||
OffsetRect(PaintRect, 1, 1);
|
OffsetRect(PaintRect, 1, 1);
|
||||||
Canvas.TextRect(PaintRect, PaintRect.Left, PaintRect.Top, Caption, TXTStyle);
|
Canvas.TextRect(PaintRect, PaintRect.Left, PaintRect.Top, Caption, TXTStyle);
|
||||||
Canvas.Font.Color := clBtnShadow;
|
Canvas.Font.Color := clBtnShadow;
|
||||||
OffsetRect(PaintRect, -1, -1);
|
OffsetRect(PaintRect, -1, -1);
|
||||||
end
|
end
|
||||||
else begin
|
else
|
||||||
|
begin
|
||||||
// if pushed, move text 1 pixel right and down
|
// if pushed, move text 1 pixel right and down
|
||||||
if (FLastDrawFlags and DFCS_PUSHED) <>0 then
|
if (FLastDrawFlags and DFCS_PUSHED) <>0 then
|
||||||
begin
|
begin
|
||||||
@ -581,6 +656,10 @@ begin
|
|||||||
end;
|
end;
|
||||||
//DebugLn(['TCustomSpeedButton.Paint PaintRect=',PaintRect.Left,',',PaintRect.TOp,',',PaintRect.Right,',',PaintRect.Bottom,caption,', ', TXTStyle.SystemFont]);
|
//DebugLn(['TCustomSpeedButton.Paint PaintRect=',PaintRect.Left,',',PaintRect.TOp,',',PaintRect.Right,',',PaintRect.Bottom,caption,', ', TXTStyle.SystemFont]);
|
||||||
Canvas.TextRect(PaintRect, PaintRect.Left, PaintRect.Top, Caption, TXTStyle);
|
Canvas.TextRect(PaintRect, PaintRect.Left, PaintRect.Top, Caption, TXTStyle);
|
||||||
|
{$else}
|
||||||
|
ThemeServices.DrawText(Canvas, FLastDrawDetails, Caption, PaintRect,
|
||||||
|
DT_LEFT or DT_TOP, 0);
|
||||||
|
{$endif}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
inherited Paint;
|
inherited Paint;
|
||||||
|
@ -470,7 +470,7 @@ type
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
function ThemeServices: TThemeServices;
|
function ThemeServices: TThemeServices;
|
||||||
|
function ThemedElementDetailsEqual(D1, D2: TThemedElementDetails): Boolean;
|
||||||
//----------------------------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
@ -490,6 +490,11 @@ begin
|
|||||||
Result := WidgetSet.ThemeServices;
|
Result := WidgetSet.ThemeServices;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function ThemedElementDetailsEqual(D1, D2: TThemedElementDetails): Boolean;
|
||||||
|
begin
|
||||||
|
Result := CompareMem(@D1, @D2, SizeOf(TThemedElementDetails));
|
||||||
|
end;
|
||||||
|
|
||||||
//----------------- TThemeServices -------------------------------------------------------------------------------------
|
//----------------- TThemeServices -------------------------------------------------------------------------------------
|
||||||
|
|
||||||
constructor TThemeServices.Create;
|
constructor TThemeServices.Create;
|
||||||
|
Loading…
Reference in New Issue
Block a user