LCL, fix dbgrid scrollbar jumping issue #19615

git-svn-id: trunk@31369 -
This commit is contained in:
jesus 2011-06-24 21:08:05 +00:00
parent fe54d8652c
commit 74c3742e3e
2 changed files with 24 additions and 56 deletions

View File

@ -417,7 +417,7 @@ type
function GridCanModify: boolean;
procedure GetSBVisibility(out HsbVisible,VsbVisible:boolean);override;
procedure GetSBRanges(const HsbVisible,VsbVisible: boolean;
out HsbRange,VsbRange, HsbPage, VsbPage:Integer); override;
out HsbRange,VsbRange,HsbPage,VsbPage,HsbPos,VsbPos:Integer); override;
procedure HeaderClick(IsColumn: Boolean; index: Integer); override;
procedure HeaderSized(IsColumn: Boolean; Index: Integer); override;
function IsValidChar(AField: TField; AChar: TUTF8Char): boolean;
@ -2568,16 +2568,15 @@ begin
end;
procedure TCustomDBGrid.GetSBRanges(const HsbVisible, VsbVisible: boolean; out
HsbRange, VsbRange, HsbPage, VsbPage: Integer);
var
aPos: Integer;
HsbRange, VsbRange, HsbPage, VsbPage, HsbPos, VsbPos: Integer);
begin
inherited GetSBRanges(HsbVisible, VsbVisible, HsbRange, VsbRange, HsbPage, VsbPage);
inherited GetSBRanges(HsbVisible, VsbVisible, HsbRange, VsbRange, HsbPage, VsbPage, HsbPos, VsbPos);
if VSbVisible then
GetScrollbarParams(VsbRange, VsbPage, aPos)
GetScrollbarParams(VsbRange, VsbPage, VsbPos)
else begin
VsbRange := 0;
VsbPage := 0;
VsbPos := 0;
end;
end;

View File

@ -677,7 +677,6 @@ type
FDragDx: Integer;
FMoveLast: TPoint;
FUpdateCount: Integer;
FUpdateScrollBarsCount: Integer;
FGCache: TGridDataCache;
FOptions: TGridOptions;
FOnDrawCell: TOnDrawcell;
@ -809,7 +808,6 @@ type
function StartColSizing(const X, Y: Integer): boolean;
procedure ChangeCursor(ACursor: Integer = MAXINT);
procedure TryScrollTo(aCol,aRow: integer);
procedure UpdateScrollBarPos(Which: TScrollStyle);
procedure UpdateCachedSizes;
procedure UpdateSBVisibility;
procedure UpdateSizes;
@ -928,7 +926,7 @@ type
function GetScrollBarPosition(Which: integer): Integer;
procedure GetSBVisibility(out HsbVisible,VsbVisible:boolean);virtual;
procedure GetSBRanges(const HsbVisible,VsbVisible: boolean;
out HsbRange,VsbRange, HsbPage, VsbPage:Integer); virtual;
out HsbRange,VsbRange,HsbPage,VsbPage,HsbPos,VsbPos:Integer); virtual;
procedure GetSelectedState(AState: TGridDrawState; out IsSelected:boolean); virtual;
function GetEditMask(ACol, ARow: Longint): string; virtual;
function GetEditText(ACol, ARow: Longint): string; virtual;
@ -975,7 +973,7 @@ type
procedure ResizeRow(aRow, aHeight: Integer);
procedure RowHeightsChanged; virtual;
procedure SaveContent(cfg: TXMLConfig); virtual;
procedure ScrollBarRange(Which:Integer; aRange,aPage: Integer);
procedure ScrollBarRange(Which:Integer; aRange,aPage,aPos: Integer);
procedure ScrollBarPosition(Which, Value: integer);
function ScrollBarIsVisible(Which:Integer): Boolean;
procedure ScrollBarPage(Which: Integer; aPage: Integer);
@ -996,9 +994,9 @@ type
procedure TopLeftChanged; virtual;
function TryMoveSelection(Relative: Boolean; var DCol, DRow: Integer): Boolean;
procedure UnLockEditor;
procedure UpdateHorzScrollBar(const aVisible: boolean; const aRange,aPage: Integer); virtual;
procedure UpdateHorzScrollBar(const aVisible: boolean; const aRange,aPage,aPos: Integer); virtual;
procedure UpdateSelectionRange;
procedure UpdateVertScrollbar(const aVisible: boolean; const aRange,aPage: Integer); virtual;
procedure UpdateVertScrollbar(const aVisible: boolean; const aRange,aPage,aPos: Integer); virtual;
procedure UpdateBorderStyle;
function ValidateEntry(const ACol,ARow:Integer; const OldValue:string; var NewValue:string): boolean; virtual;
procedure VisualChange; virtual;
@ -2837,7 +2835,6 @@ procedure TCustomGrid.doTopleftChange(dimChg: Boolean);
begin
TopLeftChanged;
VisualChange;
updateScrollBarPos(ssBoth);
end;
procedure TCustomGrid.DrawXORVertLine(X: Integer);
@ -2927,13 +2924,14 @@ procedure TCustomGrid.ResetSizes;
HsbVisible, VsbVisible: boolean;
HsbRange,VsbRange: Integer;
HsbPage, VsbPage: Integer;
HsbPos, VsbPos: Integer;
begin
with FGCache do begin
// Horizontal scrollbar
GetSBVisibility(HsbVisible, VsbVisible);
GetSBRanges(HsbVisible,VsbVisible,HsbRange,VsbRange,HsbPage,VsbPage);
UpdateVertScrollBar(VsbVisible, VsbRange, VsbPage);
UpdateHorzScrollBar(HsbVisible, HsbRange, HsbPage);
GetSBRanges(HsbVisible,VsbVisible,HsbRange,VsbRange,HsbPage,VsbPage,HsbPos,VsbPos);
UpdateVertScrollBar(VsbVisible, VsbRange, VsbPage, VsbPos);
UpdateHorzScrollBar(HsbVisible, HsbRange, HsbPage, HsbPos);
{$ifdef DbgScroll}
DebugLn('VRange=',dbgs(VsbRange),' Visible=',dbgs(VSbVisible));
DebugLn('HRange=',dbgs(HsbRange),' Visible=',dbgs(HSbVisible));
@ -2964,7 +2962,6 @@ begin
DebugLn(' MaxTopLeft',dbgs(FGCache.MaxTopLeft));
{$Endif}
CalcScrollBarsRange;
updateScrollBarPos(ssBoth);
end;
procedure TCustomGrid.CreateParams(var Params: TCreateParams);
@ -2985,7 +2982,7 @@ begin
inherited Click;
end;
procedure TCustomGrid.ScrollBarRange(Which: Integer; aRange,aPage: Integer);
procedure TCustomGrid.ScrollBarRange(Which: Integer; aRange,aPage,aPos: Integer);
var
ScrollInfo: TScrollInfo;
begin
@ -2995,7 +2992,7 @@ begin
{$endif}
FillChar(ScrollInfo, SizeOf(ScrollInfo), 0);
ScrollInfo.cbSize := SizeOf(ScrollInfo);
ScrollInfo.fMask := SIF_RANGE or SIF_PAGE or SIF_DISABLENOSCROLL;
ScrollInfo.fMask := SIF_RANGE or SIF_POS or SIF_PAGE or SIF_DISABLENOSCROLL;
{$ifdef Unix}
ScrollInfo.fMask := ScrollInfo.fMask or SIF_UPDATEPOLICY;
if goThumbTracking in Options then
@ -3004,7 +3001,8 @@ begin
ScrollInfo.ntrackPos := SB_POLICY_DISCONTINUOUS;
{$endif}
ScrollInfo.nMin := 0;
ScrollInfo.nMax := ARange;
ScrollInfo.nMax := aRange;
ScrollInfo.nPos := aPos;
if APage<0 then
APage := 0;
ScrollInfo.nPage := APage;
@ -3452,8 +3450,6 @@ begin
if ChkRow or ChkCol then begin
CacheVisibleGrid;
Invalidate;
if ChkCol then updateScrollBarPos(ssHorizontal);
if ChkRow then updateScrollBarPos(ssVertical);
end;
end;
end;
@ -4167,9 +4163,7 @@ begin
FGCache.TLColOff:=0;
if TL<>FTopLeft.X then begin
Inc(FUpdateScrollBarsCount);
TryScrollTo(Tl, FTopLeft.Y);
Dec(FUpdateScrollBarsCount);
end else
if goSmoothScroll in Options then begin
CacheVisibleGrid;
@ -4273,9 +4267,7 @@ begin
FGCache.TLRowOff:=0;
if TL<>FTopLeft.Y then begin
Inc(FUpdateScrollBarsCount);
TryScrollTo(FTopLeft.X, Tl);
Dec(FUpdateScrollBarsCount);
end else
if goSmoothScroll in Options then begin
CacheVisibleGrid;
@ -4405,31 +4397,6 @@ begin
Invalidate;
end;
{ Reposition the scrollbars according to the current TopLeft }
procedure TCustomGrid.UpdateScrollbarPos(Which: TScrollStyle);
begin
// Adjust ScrollBar Positions
// Special condition only When scrolling by draging
// the scrollbars see: WMHScroll and WVHScroll
if (FUpdateScrollBarsCount=0) and not FixedGrid then begin
if Which in [ssHorizontal, ssBoth] then begin
if FScrollBars in [ssHorizontal,ssBoth,ssAutoHorizontal,ssAutoBoth] then begin
with FGCache do
ScrollBarPosition(SB_HORZ,
integer(PtrUInt(AccumWidth[FTopLeft.x]))-TLColOff-FixedWidth );
end;
end;
if Which in [ssVertical, ssBoth] then begin
if FScrollBars in [ssVertical,ssBoth,ssAutoVertical,ssAutoBoth] then begin
with FGCache do
ScrollBarPosition(SB_VERT,
integer(PtrUInt(AccumHeight[FTopLeft.y]))-TLRowOff-FixedHeight);
end;
end;
end; {if FUpd...}
end;
procedure TCustomGrid.UpdateCachedSizes;
var
i: Integer;
@ -4524,7 +4491,7 @@ begin
end;
procedure TCustomGrid.GetSBRanges(const HsbVisible, VsbVisible: boolean; out
HsbRange, VsbRange, HsbPage, VSbPage: Integer);
HsbRange,VsbRange,HsbPage,VSbPage,HsbPos,VsbPos: Integer);
var
Tw, Th: Integer;
begin
@ -4535,6 +4502,7 @@ begin
TW:= integer(PtrUInt(AccumWidth[MaxTopLeft.X]))-(HsbRange-ClientWidth);
HsbRange:=HsbRange + TW - FixedWidth + 1;
end;
HsbPos := integer(PtrUInt(AccumWidth[FTopLeft.x]))-TLColOff-FixedWidth;
end else
HsbRange:=0;
@ -4544,6 +4512,7 @@ begin
TH:= integer(PtrUInt(accumHeight[MaxTopLeft.Y]))-(VsbRange-ClientHeight);
VsbRange:=VsbRange + TH -FixedHeight + 1;
end;
VsbPos := integer(PtrUInt(AccumHeight[FTopLeft.y]))-TLRowOff-FixedHeight;
end else
VsbRange:= 0;
@ -6735,7 +6704,7 @@ begin
end;
procedure TCustomGrid.UpdateHorzScrollBar(const aVisible: boolean;
const aRange,aPage: Integer);
const aRange,aPage,aPos: Integer);
begin
{$ifdef DbgScroll}
DebugLn('TCustomGrid.UpdateHorzScrollbar: Vis=',dbgs(aVisible),
@ -6743,11 +6712,11 @@ begin
{$endif}
ScrollBarShow(SB_HORZ, aVisible);
if aVisible then
ScrollBarRange(SB_HORZ, aRange, aPage);
ScrollBarRange(SB_HORZ, aRange, aPage, aPos);
end;
procedure TCustomGrid.UpdateVertScrollbar(const aVisible: boolean;
const aRange,aPage: Integer);
const aRange,aPage,aPos: Integer);
begin
{$ifdef DbgScroll}
DebugLn('TCustomGrid.UpdateVertScrollbar: Vis=',dbgs(aVisible),
@ -6755,7 +6724,7 @@ begin
{$endif}
ScrollBarShow(SB_VERT, aVisible);
if aVisible then
ScrollbarRange(SB_VERT, aRange, aPage );
ScrollbarRange(SB_VERT, aRange, aPage, aPos );
end;
procedure TCustomGrid.UpdateBorderStyle;