mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-11-23 03:29:48 +01:00
Gtk2: scrollbar - fixed pagesize calculation, fixes #16001
git-svn-id: trunk@24188 -
This commit is contained in:
parent
311af64daa
commit
7e24823c22
@ -122,33 +122,17 @@ function Gtk2RangeScrollCB(ARange: PGtkRange; AScrollType: TGtkScrollType;
|
||||
var
|
||||
Msg: TLMVScroll;
|
||||
MaxValue: gdouble;
|
||||
ScrolledBeyondMaximum: Boolean;
|
||||
begin
|
||||
Result := CallBackDefaultReturn;
|
||||
|
||||
ScrolledBeyondMaximum:=false;
|
||||
if (ARange^.adjustment<>nil) then begin
|
||||
MaxValue:=ARange^.adjustment^.upper-Max(ARange^.adjustment^.page_size-1,0);
|
||||
//debugln(['Gtk2RangeScrollCB AValue=',AValue,' MaxValue=',MaxValue]);
|
||||
if AValue>MaxValue then begin
|
||||
// limit to maximum
|
||||
ScrolledBeyondMaximum:=true;
|
||||
AValue:=MaxValue;
|
||||
if AValue=ARange^.adjustment^.value then begin
|
||||
// already at maximum
|
||||
Result:=not Result;
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
//Assert(False, Format('Trace:[Gtk2RangeScrollCB] Value: %d', [RoundToInt(AValue)]));
|
||||
if G_OBJECT_TYPE(ARange) = gtk_hscrollbar_get_type then
|
||||
Msg.Msg := LM_HSCROLL
|
||||
else
|
||||
Msg.Msg := LM_VSCROLL;
|
||||
|
||||
with Msg do begin
|
||||
with Msg do
|
||||
begin
|
||||
Pos := Round(AValue);
|
||||
if Pos < High(SmallPos) then
|
||||
SmallPos := Pos
|
||||
@ -159,18 +143,6 @@ begin
|
||||
ScrollCode := GtkScrollTypeToScrollCode(AScrollType);
|
||||
end;
|
||||
Result := DeliverMessage(AWidgetInfo^.LCLObject, Msg) <> 0;
|
||||
|
||||
if (Result=CallBackDefaultReturn) and ScrolledBeyondMaximum
|
||||
and (ARange^.adjustment<>nil) then begin
|
||||
// scroll to maximum
|
||||
// otherwise when dragging fast with the mouse the bar will not reach the maximum
|
||||
MaxValue:=ARange^.adjustment^.upper-Max(ARange^.adjustment^.page_size-1,0);
|
||||
if ARange^.adjustment^.value<>MaxValue then begin
|
||||
ARange^.adjustment^.value:=MaxValue;
|
||||
gtk_adjustment_changed(ARange^.adjustment);
|
||||
end;
|
||||
Result:=not Result;
|
||||
end;
|
||||
end;
|
||||
|
||||
function Gtk2ScrolledWindowScrollCB(AScrollWindow: PGtkScrolledWindow; AEvent: PGdkEventScroll; AWidgetInfo: PWidgetInfo): gboolean; cdecl;
|
||||
|
||||
@ -74,6 +74,7 @@ type
|
||||
published
|
||||
class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override;
|
||||
class procedure SetParams(const AScrollBar: TCustomScrollBar); override;
|
||||
class procedure ShowHide(const AWinControl: TWinControl); override;
|
||||
end;
|
||||
|
||||
{ TGtk2WSCustomGroupBox }
|
||||
@ -2112,11 +2113,13 @@ var
|
||||
begin
|
||||
with TScrollBar(AWinControl) do
|
||||
begin
|
||||
{ Adjustment := GTK_ADJPgtkAdjustment(
|
||||
gtk_adjustment_new(1, Min, Max, SmallChange, LargeChange,
|
||||
Pagesize));
|
||||
{We use Max + PageSize because the GTK scrollbar is meant to scroll from
|
||||
min to max-pagesize which would be different from the behaviour on other
|
||||
widgetsets.}
|
||||
Adjustment := PGtkAdjustment(gtk_adjustment_new(Position, Min,
|
||||
Max + PageSize, SmallChange, LargeChange, PageSize));
|
||||
|
||||
} if (Kind = sbHorizontal) then
|
||||
if (Kind = sbHorizontal) then
|
||||
Widget := gtk_hscrollbar_new(Adjustment)
|
||||
else
|
||||
Widget := gtk_vscrollbar_new(Adjustment);
|
||||
@ -2135,12 +2138,31 @@ class procedure TGtk2WSScrollBar.SetParams(const AScrollBar: TCustomScrollBar);
|
||||
var
|
||||
Range: PGtkRange;
|
||||
begin
|
||||
Range := GTK_RANGE(Pointer(AScrollBar.Handle));
|
||||
//set properties for the range
|
||||
// Note: gtk only allows: Min < Max
|
||||
gtk_range_set_range (Range, AScrollBar.Min, Max(AScrollBar.Min+1,AScrollBar.Max));
|
||||
gtk_range_set_increments(Range, AScrollBar.SmallChange, AScrollBar.LargeChange);
|
||||
gtk_range_set_value (Range, AScrollBar.Position);
|
||||
with AScrollBar do
|
||||
begin
|
||||
Range := GTK_RANGE(Pointer(Handle));
|
||||
{for gtk >= 2.14 use gtk_adjustment_configure}
|
||||
with Range^.adjustment^ do
|
||||
begin
|
||||
value := Position;
|
||||
lower := Min;
|
||||
upper := Max + PageSize;
|
||||
step_increment := SmallChange;
|
||||
page_increment := LargeChange;
|
||||
page_size := PageSize;
|
||||
end;
|
||||
gtk_adjustment_changed(Range^.adjustment);
|
||||
end;
|
||||
end;
|
||||
|
||||
class procedure TGtk2WSScrollBar.ShowHide(const AWinControl: TWinControl);
|
||||
begin
|
||||
if not AWinControl.HandleAllocated then
|
||||
exit;
|
||||
if AWinControl.HandleObjectShouldBeVisible then
|
||||
SetParams(TCustomScrollBar(AWinControl));
|
||||
Gtk2WidgetSet.SetVisible(AWinControl,
|
||||
AWinControl.HandleObjectShouldBeVisible);
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user