From 7e24823c22b645c795b71d064a738f90605d925c Mon Sep 17 00:00:00 2001 From: zeljko Date: Wed, 24 Mar 2010 11:16:24 +0000 Subject: [PATCH] Gtk2: scrollbar - fixed pagesize calculation, fixes #16001 git-svn-id: trunk@24188 - --- lcl/interfaces/gtk2/gtk2wscontrols.pp | 32 ++------------------ lcl/interfaces/gtk2/gtk2wsstdctrls.pp | 42 ++++++++++++++++++++------- 2 files changed, 34 insertions(+), 40 deletions(-) diff --git a/lcl/interfaces/gtk2/gtk2wscontrols.pp b/lcl/interfaces/gtk2/gtk2wscontrols.pp index e76c66926d..c8cd721b2e 100644 --- a/lcl/interfaces/gtk2/gtk2wscontrols.pp +++ b/lcl/interfaces/gtk2/gtk2wscontrols.pp @@ -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; diff --git a/lcl/interfaces/gtk2/gtk2wsstdctrls.pp b/lcl/interfaces/gtk2/gtk2wsstdctrls.pp index 75d0bda981..d9b515a99d 100644 --- a/lcl/interfaces/gtk2/gtk2wsstdctrls.pp +++ b/lcl/interfaces/gtk2/gtk2wsstdctrls.pp @@ -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.