mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-21 12:59:14 +02:00
gtk2: simplify gtk2 progress bar code, don't set position on widget creation (#0011382)
git-svn-id: trunk@15285 -
This commit is contained in:
parent
813ed4a6bf
commit
6fd5dc9d3d
@ -368,10 +368,10 @@ begin
|
|||||||
begin
|
begin
|
||||||
if BarShowText then
|
if BarShowText then
|
||||||
begin
|
begin
|
||||||
wText := Format('%d from [%d-%d] (%%p%%%%)', [AProgressBar.Position, Min, Max]);
|
wText := Format('%d from [%d-%d] (%%p%%%%)', [Position, Min, Max]);
|
||||||
gtk_progress_set_format_string (GTK_PROGRESS(Pointer(Handle)), PChar(wText));
|
gtk_progress_set_format_string(PGtkProgress(Handle), PChar(wText));
|
||||||
end;
|
end;
|
||||||
gtk_progress_set_show_text (GTK_PROGRESS(Pointer(Handle)), BarShowText);
|
gtk_progress_set_show_text(PGtkProgress(Handle), BarShowText);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -380,41 +380,42 @@ class function TGtk2WSProgressBar.CreateHandle(const AWinControl: TWinControl;
|
|||||||
var
|
var
|
||||||
Widget: PGtkWidget;
|
Widget: PGtkWidget;
|
||||||
WidgetInfo: PWidgetInfo;
|
WidgetInfo: PWidgetInfo;
|
||||||
AProgressBar: TCustomProgressBar;
|
|
||||||
begin
|
begin
|
||||||
AProgressBar := TCustomProgressBar(AWinControl);
|
|
||||||
Widget := gtk_progress_bar_new;
|
Widget := gtk_progress_bar_new;
|
||||||
Result := TLCLIntfHandle(PtrUInt(Widget));
|
Result := TLCLIntfHandle(PtrUInt(Widget));
|
||||||
WidgetInfo := CreateWidgetInfo(Pointer(Result), AWinControl, AParams);
|
WidgetInfo := CreateWidgetInfo(Pointer(Result), AWinControl, AParams);
|
||||||
Set_RC_Name(AWinControl, Widget);
|
Set_RC_Name(AWinControl, Widget);
|
||||||
|
|
||||||
SetPosition(AProgressBar, AProgressBar.Position);
|
|
||||||
|
|
||||||
TGtkWSWinControl.SetCallbacks(PGtkObject(Widget), TComponent(WidgetInfo^.LCLObject));
|
TGtkWSWinControl.SetCallbacks(PGtkObject(Widget), TComponent(WidgetInfo^.LCLObject));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class procedure TGtk2WSProgressBar.ApplyChanges(
|
class procedure TGtk2WSProgressBar.ApplyChanges(const AProgressBar: TCustomProgressBar);
|
||||||
const AProgressBar: TCustomProgressBar);
|
const
|
||||||
|
OrientationMap: array[TProgressBarOrientation] of TGtkProgressBarOrientation =
|
||||||
|
(
|
||||||
|
{ pbHorizontal } GTK_PROGRESS_LEFT_TO_RIGHT,
|
||||||
|
{ pbVertical, } GTK_PROGRESS_BOTTOM_TO_TOP,
|
||||||
|
{ pbRightToLeft } GTK_PROGRESS_RIGHT_TO_LEFT,
|
||||||
|
{ pbTopDown } GTK_PROGRESS_TOP_TO_BOTTOM
|
||||||
|
);
|
||||||
|
|
||||||
|
SmoothMap: array[Boolean] of TGtkProgressBarStyle =
|
||||||
|
(
|
||||||
|
{ False } GTK_PROGRESS_DISCRETE,
|
||||||
|
{ True } GTK_PROGRESS_CONTINUOUS
|
||||||
|
);
|
||||||
|
|
||||||
var
|
var
|
||||||
wHandle: Pointer;
|
Progress: PGtkProgressBar;
|
||||||
wOrientation: TGtkProgressBarOrientation;
|
|
||||||
begin
|
begin
|
||||||
wHandle := Pointer(AProgressBar.Handle);
|
if not WSCheckHandleAllocated(AProgressBar, 'TGtk2WSProgressBar.ApplyChanges') then
|
||||||
|
Exit;
|
||||||
|
Progress := PGtkProgressBar(AProgressBar.Handle);
|
||||||
|
|
||||||
with AProgressBar do
|
with AProgressBar do
|
||||||
begin
|
begin
|
||||||
gtk_progress_bar_set_bar_style (GTK_PROGRESS_BAR(wHandle),
|
gtk_progress_bar_set_bar_style(Progress, SmoothMap[Smooth]);
|
||||||
TGtkProgressBarStyle(Ord(Smooth = False)));
|
gtk_progress_bar_set_orientation(Progress, OrientationMap[Orientation]);
|
||||||
// 0 = Smooth
|
|
||||||
// 1 = not Smooth :) (AH)
|
|
||||||
case Orientation of
|
|
||||||
pbHorizontal : wOrientation := GTK_PROGRESS_LEFT_TO_RIGHT;
|
|
||||||
pbVertical : wOrientation := GTK_PROGRESS_BOTTOM_TO_TOP;
|
|
||||||
pbRightToLeft: wOrientation := GTK_PROGRESS_RIGHT_TO_LEFT;
|
|
||||||
pbTopDown : wOrientation := GTK_PROGRESS_TOP_TO_BOTTOM;
|
|
||||||
end;
|
|
||||||
gtk_progress_bar_set_orientation(GTK_PROGRESS_BAR(wHandle), wOrientation);
|
|
||||||
|
|
||||||
UpdateProgressBarText(AProgressBar);
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// The posision also needs to be updated at ApplyChanges
|
// The posision also needs to be updated at ApplyChanges
|
||||||
@ -424,16 +425,17 @@ end;
|
|||||||
class procedure TGtk2WSProgressBar.SetPosition(
|
class procedure TGtk2WSProgressBar.SetPosition(
|
||||||
const AProgressBar: TCustomProgressBar; const NewPosition: integer);
|
const AProgressBar: TCustomProgressBar; const NewPosition: integer);
|
||||||
begin
|
begin
|
||||||
|
if not WSCheckHandleAllocated(AProgressBar, 'TGtk2WSProgressBar.SetPosition') then
|
||||||
|
Exit;
|
||||||
|
|
||||||
// Gtk2 wishes the position in a floating-point value between
|
// Gtk2 wishes the position in a floating-point value between
|
||||||
// 0.0 and 1.0, and we calculate that with:
|
// 0.0 and 1.0, and we calculate that with:
|
||||||
// (Pos - Min) / (Max - Min)
|
// (Pos - Min) / (Max - Min)
|
||||||
// regardless if any of them is negative the result is correct
|
// regardless if any of them is negative the result is correct
|
||||||
gtk_progress_bar_set_fraction(
|
gtk_progress_bar_set_fraction(PGtkProgressBar(AProgressBar.Handle),
|
||||||
GTK_PROGRESS_BAR(Pointer(AProgressBar.Handle)),
|
|
||||||
(NewPosition - AProgressBar.Min) /
|
(NewPosition - AProgressBar.Min) /
|
||||||
(AProgressBar.Max - AProgressBar.Min));
|
(AProgressBar.Max - AProgressBar.Min));
|
||||||
|
|
||||||
if AProgressBar.BarShowText then
|
|
||||||
UpdateProgressBarText(AProgressBar);
|
UpdateProgressBarText(AProgressBar);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user