LCL: Support AutoSize in TTrackBar with hi-dpi. Revert AutoSize=True from r61473 #8466836623. Issue #35861, patch from Joeny Ang.

git-svn-id: trunk@61676 -
This commit is contained in:
juha 2019-08-09 19:16:56 +00:00
parent 17237b6c07
commit 4bc787b833
3 changed files with 29 additions and 28 deletions

View File

@ -2717,11 +2717,12 @@ type
class function GetControlClassDefaultSize: TSize; override;
procedure InitializeWnd; override;
procedure Loaded; override;
procedure ShouldAutoAdjust(var AWidth, AHeight: Boolean); override;
public
constructor Create(AOwner: TComponent); override;
procedure SetTick(Value: Integer);
published
property AutoSize default true;
property AutoSize;
property Frequency: Integer read FFrequency write SetFrequency default 1;
property LineSize: Integer read FLineSize write SetLineSize default 1;
property Max: Integer read FMax write SetMax default 10;

View File

@ -70,7 +70,6 @@ begin
TabStop := True;
with GetControlClassDefaultSize do
SetInitialBounds(0, 0, CX, CY);
AutoSize := True;
end;
{------------------------------------------------------------------------------
@ -93,6 +92,20 @@ begin
ApplyChanges;
end;
procedure TCustomTrackBar.ShouldAutoAdjust(var AWidth, AHeight: Boolean);
begin
if Orientation = trHorizontal then
begin
AWidth := True;
AHeight := not AutoSize;
end
else
begin
AWidth := not AutoSize;
AHeight := True;
end
end;
{------------------------------------------------------------------------------
Method: TCustomTrackBar.SetTick
Params: Value : new tick

View File

@ -263,7 +263,6 @@ type
class procedure ApplyChanges(const ATrackBar: TCustomTrackBar); override;
class function GetPosition(const ATrackBar: TCustomTrackBar): integer; override;
class procedure SetPosition(const ATrackBar: TCustomTrackBar; const NewPosition: integer); override;
class procedure SetOrientation(const ATrackBar: TCustomTrackBar; const {%H-}AOrientation: TTrackBarOrientation); override;
class procedure GetPreferredSize(const {%H-}AWinControl: TWinControl;
var {%H-}PreferredWidth, PreferredHeight: integer;
{%H-}WithThemeSpace: Boolean); override;
@ -428,23 +427,6 @@ begin
Dec(WidgetInfo^.ChangeLock);
end;
class procedure TGtk2WSTrackBar.SetOrientation(
const ATrackBar: TCustomTrackBar; const AOrientation: TTrackBarOrientation);
var
B: Boolean;
begin
if not WSCheckHandleAllocated(ATrackBar, 'SetOrientation') then
Exit;
B := ATrackBar.Visible;
if B then
ATrackBar.Hide;
try
RecreateWnd(ATrackBar);
finally
if B then
ATrackBar.Show;
end;
end;
class procedure TGtk2WSTrackBar.GetPreferredSize(
const AWinControl: TWinControl; var PreferredWidth, PreferredHeight: integer;
@ -453,20 +435,25 @@ var
TrackBarWidget: PGtkWidget;
Requisition: TGtkRequisition;
begin
if TCustomTrackBar(AWinControl).Orientation = trHorizontal then
TrackBarWidget := GetStyleWidget(lgsHScale)
else
TrackBarWidget := GetStyleWidget(lgsVScale);
TrackBarWidget := {%H-}PGtkWidget(AWinControl.Handle);
// if vertical, measure width without ticks
if TCustomTrackBar(AWinControl).Orientation = trVertical then
gtk_scale_set_draw_value(PGtkScale(TrackBarWidget), False);
// set size to default
gtk_scale_set_draw_value(PGtkScale(TrackBarWidget),
TCustomTrackBar(AWinControl).TickStyle <> tsNone);
gtk_widget_set_size_request(TrackBarWidget, -1, -1);
// ask default size
gtk_widget_size_request(TrackBarWidget, @Requisition);
if TCustomTrackBar(AWinControl).Orientation = trHorizontal then
PreferredHeight := Requisition.height
PreferredHeight := Requisition.Height
else
PreferredWidth := Requisition.width;
begin
// gtk_widget_size_request() always returns size of a HScale,
// so we use the height for the width
PreferredWidth := Requisition.Height;
// restore TickStyle
gtk_scale_set_draw_value(PGtkScale(TrackBarWidget),
TCustomTrackBar(AWinControl).TickStyle <> tsNone);
end;
end;
{ TGtk2WSProgressBar }