You've already forked lazarus-ccr
jvcllaz: Make TJvGradientHeaderPanel high-dpi aware. Fix horizontal alignment of label. Add some missing properties (vertical alignment, wordwrap, margins).
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7292 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -30,16 +30,22 @@ unit JvGradientHeaderPanel;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
LMessages,
|
LMessages, LCLVersion,
|
||||||
SysUtils, Classes, Graphics, Controls, StdCtrls,
|
SysUtils, Classes, Graphics, Controls, StdCtrls,
|
||||||
JvGradient, JvTypes, JvComponent;
|
JvGradient, JvTypes, JvComponent;
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
|
{ TJvGradientHeaderPanel }
|
||||||
|
|
||||||
TJvGradientHeaderPanel = class(TJvCustomControl)
|
TJvGradientHeaderPanel = class(TJvCustomControl)
|
||||||
private
|
private
|
||||||
FGradient: TJvGradient;
|
FGradient: TJvGradient;
|
||||||
FLabel: TLabel;
|
FLabel: TLabel;
|
||||||
FLabelLeft: Integer;
|
FLabelLeft: Integer;
|
||||||
|
FLabelTop: Integer;
|
||||||
|
FLabelRight: Integer;
|
||||||
|
FLabelBottom: Integer;
|
||||||
FHint: Boolean;
|
FHint: Boolean;
|
||||||
FOldLabelFontChange: TNotifyEvent;
|
FOldLabelFontChange: TNotifyEvent;
|
||||||
function GetGradientCursor: TCursor;
|
function GetGradientCursor: TCursor;
|
||||||
@ -52,10 +58,10 @@ type
|
|||||||
procedure SetGradientEndColor(Value: TColor);
|
procedure SetGradientEndColor(Value: TColor);
|
||||||
function GetGradientSteps: Integer;
|
function GetGradientSteps: Integer;
|
||||||
procedure SetGradientSteps(Value: Integer);
|
procedure SetGradientSteps(Value: Integer);
|
||||||
function GetLabelLeft: Integer;
|
|
||||||
procedure SetLabelLeft(Value: Integer);
|
procedure SetLabelLeft(Value: Integer);
|
||||||
function GetLabelTop: Integer;
|
|
||||||
procedure SetLabelTop(Value: Integer);
|
procedure SetLabelTop(Value: Integer);
|
||||||
|
procedure SetLabelRight(Value: Integer);
|
||||||
|
procedure SetLabelBottom(Value: Integer);
|
||||||
function GetLabelCursor: TCursor;
|
function GetLabelCursor: TCursor;
|
||||||
procedure SetLabelCursor(Value: TCursor);
|
procedure SetLabelCursor(Value: TCursor);
|
||||||
function GetLabelHint: string;
|
function GetLabelHint: string;
|
||||||
@ -71,13 +77,20 @@ type
|
|||||||
procedure SetGradientStyle(const Value: TJvGradientStyle);
|
procedure SetGradientStyle(const Value: TJvGradientStyle);
|
||||||
function GetLabelAlignment: TAlignment;
|
function GetLabelAlignment: TAlignment;
|
||||||
procedure SetLabelAlignment(const Value: TAlignment);
|
procedure SetLabelAlignment(const Value: TAlignment);
|
||||||
procedure AdjustLabelWidth;
|
function GetLabelLayout: TTextLayout;
|
||||||
|
procedure SetLabelLayout(const Value: TTextLayout);
|
||||||
|
function GetLabelWordwrap: Boolean;
|
||||||
|
procedure SetLabelWordwrap(const Value: Boolean);
|
||||||
procedure WMSize(var Msg: TLMSize); message LM_SIZE;
|
procedure WMSize(var Msg: TLMSize); message LM_SIZE;
|
||||||
protected
|
protected
|
||||||
|
procedure AdjustLabel;
|
||||||
|
procedure DoAutoAdjustLayout(const AMode: TLayoutAdjustmentPolicy;
|
||||||
|
const AXProportion, AYProportion: Double); override;
|
||||||
// function DoEraseBackground(Canvas: TCanvas; Param: LPARAM): Boolean; override;
|
// function DoEraseBackground(Canvas: TCanvas; Param: LPARAM): Boolean; override;
|
||||||
procedure DoLabelFontChange(Sender: TObject);
|
procedure DoLabelFontChange(Sender: TObject);
|
||||||
procedure MouseDown(Button: TMouseButton; Shift: TShiftState;
|
procedure MouseDown(Button: TMouseButton; Shift: TShiftState;
|
||||||
X, Y: Integer); override;
|
X, Y: Integer); override;
|
||||||
|
|
||||||
public
|
public
|
||||||
constructor Create(AOwner: TComponent); override;
|
constructor Create(AOwner: TComponent); override;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
@ -88,8 +101,10 @@ type
|
|||||||
property GradientEndColor: TColor read GetGradientEndColor write SetGradientEndColor default clWhite;
|
property GradientEndColor: TColor read GetGradientEndColor write SetGradientEndColor default clWhite;
|
||||||
property GradientSteps: Integer read GetGradientSteps write SetGradientSteps default 100;
|
property GradientSteps: Integer read GetGradientSteps write SetGradientSteps default 100;
|
||||||
property GradientStyle: TJvGradientStyle read GetGradientStyle write SetGradientStyle default grHorizontal;
|
property GradientStyle: TJvGradientStyle read GetGradientStyle write SetGradientStyle default grHorizontal;
|
||||||
property LabelLeft: Integer read GetLabelLeft write SetLabelLeft default 10;
|
property LabelLeft: Integer read FLabelLeft write SetLabelLeft default 10;
|
||||||
property LabelTop: Integer read GetLabelTop write SetLabelTop default 8;
|
property LabelTop: Integer read FLabelTop write SetLabelTop default 8;
|
||||||
|
property LabelRight: Integer read FLabelRight write SetLabelRight default 10;
|
||||||
|
property LabelBottom: Integer read FLabelBottom write SetLabelBottom default 8;
|
||||||
property LabelCursor: TCursor read GetLabelCursor write SetLabelCursor default crDefault;
|
property LabelCursor: TCursor read GetLabelCursor write SetLabelCursor default crDefault;
|
||||||
property LabelHint: string read GetLabelHint write SetLabelHint;
|
property LabelHint: string read GetLabelHint write SetLabelHint;
|
||||||
property LabelCaption: string read GetLabelCaption write SetLabelCaption;
|
property LabelCaption: string read GetLabelCaption write SetLabelCaption;
|
||||||
@ -97,8 +112,10 @@ type
|
|||||||
// To get a transparent text background, set LabelColor to clNone
|
// To get a transparent text background, set LabelColor to clNone
|
||||||
property LabelColor: TColor read GetLabelColor write SetLabelColor default clNone;
|
property LabelColor: TColor read GetLabelColor write SetLabelColor default clNone;
|
||||||
property LabelFont: TFont read GetLabelFont write SetLabelFont;
|
property LabelFont: TFont read GetLabelFont write SetLabelFont;
|
||||||
|
property LabelAlignment: TAlignment read GetLabelAlignment write SetLabelAlignment default taLeftJustify;
|
||||||
|
property LabelLayout: TTextLayout read GetLabelLayout write SetLabelLayout default tlTop;
|
||||||
|
property LabelWordwrap: Boolean read GetLabelWordwrap write SetLabelWordwrap default false;
|
||||||
property ShowHint: Boolean read FHint write SetShowHint default False;
|
property ShowHint: Boolean read FHint write SetShowHint default False;
|
||||||
property LabelAlignment: TAlignment read GetLabelAlignment write SetLabelAlignment;
|
|
||||||
property Align;
|
property Align;
|
||||||
property Anchors;
|
property Anchors;
|
||||||
property AutoSize;
|
property AutoSize;
|
||||||
@ -172,31 +189,37 @@ begin
|
|||||||
ControlStyle := ControlStyle + [csOpaque, csAcceptsControls];
|
ControlStyle := ControlStyle + [csOpaque, csAcceptsControls];
|
||||||
Self.Width := 285;
|
Self.Width := 285;
|
||||||
Self.Height := 30;
|
Self.Height := 30;
|
||||||
|
FLabelLeft := 10;
|
||||||
|
FLabelTop := 8;
|
||||||
|
FLabelRight := 10;
|
||||||
|
FLabelBottom := 8;
|
||||||
FGradient := TNoEventGradient.Create(Self);
|
FGradient := TNoEventGradient.Create(Self);
|
||||||
FGradient.Parent := Self;
|
FGradient.Parent := Self;
|
||||||
FLabel := TNoEventLabel.Create(Self);
|
FLabel := TNoEventLabel.Create(Self);
|
||||||
FLabel.AutoSize := False;
|
FLabel.AutoSize := true;
|
||||||
|
// FLabel.AutoSize := False; // wp
|
||||||
|
FLabel.Align := alClient;
|
||||||
FLabel.Parent := Self;
|
FLabel.Parent := Self;
|
||||||
FGradient.Left := 0;
|
//FGradient.Left := 0;
|
||||||
FGradient.Top := 0;
|
//FGradient.Top := 0;
|
||||||
FGradient.StartColor := clBlack;
|
FGradient.StartColor := clBlack;
|
||||||
FGradient.EndColor := clWhite;
|
FGradient.EndColor := clWhite;
|
||||||
FGradient.Steps := 100;
|
FGradient.Steps := 100;
|
||||||
LabelLeft := 10;
|
|
||||||
FLabel.Top := 8;
|
|
||||||
LabelColor := clNone;
|
LabelColor := clNone;
|
||||||
FOldLabelFontChange := FLabel.Font.OnChange;
|
FOldLabelFontChange := FLabel.Font.OnChange;
|
||||||
FLabel.Font.OnChange := @DoLabelFontChange;
|
FLabel.Font.OnChange := @DoLabelFontChange;
|
||||||
FLabel.Font.Color := clWhite;
|
FLabel.Font.Color := clWhite;
|
||||||
FLabel.Caption := RsYourTextHereCaption;
|
FLabel.Caption := RsYourTextHereCaption;
|
||||||
|
FLabel.BorderSpacing.Left := FLabelLeft;;
|
||||||
|
FLabel.BorderSpacing.Top := FLabelTop;
|
||||||
FHint := False;
|
FHint := False;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
destructor TJvGradientHeaderPanel.Destroy;
|
destructor TJvGradientHeaderPanel.Destroy;
|
||||||
begin
|
begin
|
||||||
FGradient.Free;
|
// FGradient.Free;
|
||||||
// FLabel.OnChange := FOldLabelFontChange;
|
// FLabel.OnChange := FOldLabelFontChange;
|
||||||
FLabel.Free;
|
// FLabel.Free;
|
||||||
inherited Destroy;
|
inherited Destroy;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -250,33 +273,46 @@ begin
|
|||||||
FGradient.Steps := Value;
|
FGradient.Steps := Value;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TJvGradientHeaderPanel.GetLabelLeft: Integer;
|
|
||||||
begin
|
|
||||||
Result := FLabelLeft;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TJvGradientHeaderPanel.SetLabelLeft(Value: Integer);
|
procedure TJvGradientHeaderPanel.SetLabelLeft(Value: Integer);
|
||||||
begin
|
begin
|
||||||
if FLabel.Left <> Value then
|
if FLabelLeft <> Value then
|
||||||
begin
|
begin
|
||||||
if Value < 0 then
|
if Value < 0 then
|
||||||
Value := 0;
|
FLabelLeft := 0
|
||||||
FLabel.Left := Value;
|
else
|
||||||
FLabelLeft := Value;
|
FLabelLeft := Value;
|
||||||
AdjustLabelWidth;
|
AdjustLabel;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TJvGradientHeaderPanel.GetLabelTop: Integer;
|
procedure TJvGradientHeaderPanel.SetLabelRight(Value: Integer);
|
||||||
begin
|
begin
|
||||||
Result := FLabel.Top;
|
if FLabelRight <> Value then
|
||||||
|
begin
|
||||||
|
if Value < 0 then
|
||||||
|
FLabelRight := 0
|
||||||
|
else
|
||||||
|
FLabelRight := Value;
|
||||||
|
AdjustLabel;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TJvGradientHeaderPanel.SetLabelTop(Value: Integer);
|
procedure TJvGradientHeaderPanel.SetLabelTop(Value: Integer);
|
||||||
begin
|
begin
|
||||||
if Value < 0 then
|
if Value < 0 then
|
||||||
Value := 0;
|
FLabelTop := 0
|
||||||
FLabel.Top := Value;
|
else
|
||||||
|
FLabelTop := Value;
|
||||||
|
AdjustLabel;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TJvGradientHeaderPanel.SetLabelBottom(Value: Integer);
|
||||||
|
begin
|
||||||
|
if Value < 0 then
|
||||||
|
FLabelBottom := 0
|
||||||
|
else
|
||||||
|
FLabelBottom := Value;
|
||||||
|
AdjustLabel;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TJvGradientHeaderPanel.GetLabelCursor: TCursor;
|
function TJvGradientHeaderPanel.GetLabelCursor: TCursor;
|
||||||
@ -307,7 +343,7 @@ end;
|
|||||||
procedure TJvGradientHeaderPanel.SetLabelCaption(const Value: string);
|
procedure TJvGradientHeaderPanel.SetLabelCaption(const Value: string);
|
||||||
begin
|
begin
|
||||||
FLabel.Caption := Value;
|
FLabel.Caption := Value;
|
||||||
AdjustLabelWidth;
|
AdjustLabel;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TJvGradientHeaderPanel.GetLabelColor: TColor;
|
function TJvGradientHeaderPanel.GetLabelColor: TColor;
|
||||||
@ -336,7 +372,7 @@ end;
|
|||||||
procedure TJvGradientHeaderPanel.SetLabelFont(const Value: TFont);
|
procedure TJvGradientHeaderPanel.SetLabelFont(const Value: TFont);
|
||||||
begin
|
begin
|
||||||
FLabel.Font := Value;
|
FLabel.Font := Value;
|
||||||
AdjustLabelWidth;
|
AdjustLabel;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TJvGradientHeaderPanel.GetGradientStyle: TJvGradientStyle;
|
function TJvGradientHeaderPanel.GetGradientStyle: TJvGradientStyle;
|
||||||
@ -357,38 +393,66 @@ end;
|
|||||||
procedure TJvGradientHeaderPanel.SetLabelAlignment(const Value: TAlignment);
|
procedure TJvGradientHeaderPanel.SetLabelAlignment(const Value: TAlignment);
|
||||||
begin
|
begin
|
||||||
FLabel.Alignment := Value;
|
FLabel.Alignment := Value;
|
||||||
AdjustLabelWidth;
|
AdjustLabel;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TJvGradientHeaderPanel.GetLabelLayout: TTextLayout;
|
||||||
|
begin
|
||||||
|
Result := FLabel.Layout;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TJvGradientHeaderPanel.SetLabelLayout(const Value: TTextLayout);
|
||||||
|
begin
|
||||||
|
FLabel.Layout := Value;
|
||||||
|
AdjustLabel;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TJvGradientHeaderPanel.GetLabelWordWrap: Boolean;
|
||||||
|
begin
|
||||||
|
Result := FLabel.WordWrap;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TJvGradientHeaderPanel.SetLabelWordwrap(const Value: Boolean);
|
||||||
|
begin
|
||||||
|
FLabel.WordWrap := Value;
|
||||||
|
Invalidate;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TJvGradientHeaderPanel.WMSize(var Msg: TLMSize);
|
procedure TJvGradientHeaderPanel.WMSize(var Msg: TLMSize);
|
||||||
begin
|
begin
|
||||||
inherited;
|
inherited;
|
||||||
AdjustLabelWidth;
|
// AdjustLabel;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TJvGradientHeaderPanel.AdjustLabel;
|
||||||
|
begin
|
||||||
|
FLabel.BorderSpacing.Left := FLabelLeft;
|
||||||
|
FLabel.BorderSpacing.Right := FLabelRight;
|
||||||
|
FLabel.BorderSpacing.Top := FLabelTop;
|
||||||
|
FLabel.BorderSpacing.Bottom := FLabelBottom;
|
||||||
|
if FLabel.Alignment = taCenter then
|
||||||
|
begin
|
||||||
|
FLabel.BorderSpacing.Left := 0;
|
||||||
|
FLabel.BorderSpacing.Right := 0;
|
||||||
|
end;
|
||||||
|
if FLabel.Layout = tlCenter then
|
||||||
|
begin
|
||||||
|
FLabel.BorderSpacing.Top := 0;
|
||||||
|
FLabel.BorderSpacing.Bottom := 0;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TJvGradientHeaderPanel.AdjustLabelWidth;
|
procedure TJvGradientHeaderPanel.DoAutoAdjustLayout(
|
||||||
var
|
const AMode: TLayoutAdjustmentPolicy; const AXProportion, AYProportion: Double
|
||||||
W, L: Integer;
|
);
|
||||||
begin
|
begin
|
||||||
L := FLabel.Left;
|
inherited;
|
||||||
// make as large as we need:
|
if AMode in [lapAutoAdjustWithoutHorizontalScrolling, lapAutoAdjustForDPI] then
|
||||||
FLabel.AutoSize := True;
|
|
||||||
FLabel.AutoSize := False;
|
|
||||||
FLabel.Left := L;
|
|
||||||
W := FGradient.Width - FLabelLeft - FLabelLeft;
|
|
||||||
// make bigger if there's room
|
|
||||||
if W > FLabel.Width then
|
|
||||||
begin
|
begin
|
||||||
FLabel.Width := W;
|
FLabelLeft := round(FLabelLeft * AXProportion);
|
||||||
FLabel.Left := FLabelLeft;
|
FLabelTop := round(FLabelTop * AYProportion);
|
||||||
end
|
FLabelRight := round(FLabelRight * AXProportion);
|
||||||
else
|
FLabelBottom := round(FLabelBottom * AYProportion);
|
||||||
if W < FLabel.Width then // otherwise, just center
|
|
||||||
begin
|
|
||||||
FLabel.Left := (Width - FLabel.Width) div 2;
|
|
||||||
// if (FLabelLeft > FLabel.Left) and then
|
|
||||||
// FLabelLeft := FLabel.Left;
|
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -396,7 +460,7 @@ procedure TJvGradientHeaderPanel.DoLabelFontChange(Sender: TObject);
|
|||||||
begin
|
begin
|
||||||
if Assigned(FOldLabelFontChange) then
|
if Assigned(FOldLabelFontChange) then
|
||||||
FOldLabelFontChange(Sender);
|
FOldLabelFontChange(Sender);
|
||||||
AdjustLabelWidth;
|
AdjustLabel;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TJvGradientHeaderPanel.MouseDown(Button: TMouseButton;
|
procedure TJvGradientHeaderPanel.MouseDown(Button: TMouseButton;
|
||||||
@ -407,13 +471,14 @@ begin
|
|||||||
SetFocus;
|
SetFocus;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
(*
|
{
|
||||||
function TJvGradientHeaderPanel.DoEraseBackground(Canvas: TCanvas; Param: LPARAM): Boolean;
|
function TJvGradientHeaderPanel.DoEraseBackground(Canvas: TCanvas; Param: LPARAM): Boolean;
|
||||||
begin
|
begin
|
||||||
{ Reduce flickering FGradient completely fills the TJvGradientHeaderPanel }
|
{ Reduce flickering FGradient completely fills the TJvGradientHeaderPanel }
|
||||||
Result := True;
|
Result := True;
|
||||||
end;
|
end;
|
||||||
*)
|
}
|
||||||
|
|
||||||
|
|
||||||
//=== { TNoEventLabel } ======================================================
|
//=== { TNoEventLabel } ======================================================
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user