Hello. Currently the default behaviour of TCustomGrid is that when you click or drag mouse cursor then the selected cell will become entirely visible by scrolling the control. Sometimes even when the target cell is already fully visible, the grid is scrolled in such a way that it "begins" with a full column, i.e., not in the middle of the column. This is not desired behaviour for me and I wanted to make an option to disable it.
Is it possible to do it without breaking compatibility with existing code? I've attached the changes that I have made so far. I've added a 'goDisableScrollWithMouse' option that is disabled by default (as opposed to 'goScrollWithMouse' that would be enabled by default), so that current code that didn't know about this option will continue to work correctly. I hope this is enough. What should I do with GRIDFILEVERSION? Do I have to increase to 4? It is used in TCustomGrid.LoadContent to determine if the option value has to be read (for example for goSmoothScroll). In the attached diff those are the lines that are commented out. Is it better to do it with a property/variable than a grid option? -- cobines
Index: grids.pas =================================================================== --- grids.pas (wersja 21126) +++ grids.pas (kopia robocza) @@ -103,7 +103,8 @@ goFixedRowNumbering, // Ya goScrollKeepVisible, // keeps focused cell visible while scrolling goHeaderHotTracking, // Header cells change look when mouse is over them - goHeaderPushedLook // Header cells looks pushed when clicked + goHeaderPushedLook, // Header cells looks pushed when clicked + goDisableScrollWithMouse // Don't scroll to cell with mouse click or move ); TGridOptions = set of TGridOption; @@ -894,7 +895,7 @@ procedure MouseDown(Button: TMouseButton; Shift:TShiftState; X,Y:Integer); override; procedure MouseMove(Shift: TShiftState; X,Y: Integer);override; procedure MouseUp(Button: TMouseButton; Shift:TShiftState; X,Y:Integer); override; - function MoveExtend(Relative: Boolean; DCol, DRow: Integer): Boolean; + function MoveExtend(Relative: Boolean; DCol, DRow: Integer; Scroll: Boolean): Boolean; function MoveNextAuto(const Inverse: boolean): boolean; function MoveNextSelectable(Relative:Boolean; DCol, DRow: Integer): Boolean; procedure MoveSelection; virtual; @@ -2438,7 +2439,7 @@ if AValue=FCol then Exit; if not AllowOutboundEvents then CheckLimitsWithError(AValue, FRow); - MoveExtend(False, AValue, FRow); + MoveExtend(False, AValue, FRow, True); Click; end; @@ -2447,7 +2448,7 @@ if AValue=FRow then Exit; if not AllowOutBoundEvents then CheckLimitsWithError(FCol, AValue); - MoveExtend(False, FCol, AValue); + MoveExtend(False, FCol, AValue, True); Click; end; @@ -5116,7 +5117,8 @@ Exit; end; - if not MoveExtend(False, FSplitter.X, FSplitter.Y) then begin + if not MoveExtend(False, FSplitter.X, FSplitter.Y, + not (goDisableScrollWithMouse in Options)) then begin if EditorAlwaysShown then begin SelectEditor; EditorShow(true); @@ -5152,7 +5154,7 @@ P:=MouseToLogcell(Point(X,Y)); if gfNeedsSelectActive in GridFlags then SelectActive := (P.x<>FPivot.x)or(P.y<>FPivot.y); - MoveExtend(False, P.x, P.y); + MoveExtend(False, P.x, P.y, not (goDisableScrollWithMouse in Options)); end; gsColMoving: @@ -5197,7 +5199,7 @@ gsSelecting: begin if SelectActive then - MoveExtend(False, Cur.x, Cur.y) + MoveExtend(False, Cur.x, Cur.y, not (goDisableScrollWithMouse in Options)) else CellClick(cur.x, cur.y); end; @@ -5780,7 +5782,7 @@ end; end; -function TCustomGrid.MoveExtend(Relative: Boolean; DCol, DRow: Integer): Boolean; +function TCustomGrid.MoveExtend(Relative: Boolean; DCol, DRow: Integer; Scroll: Boolean): Boolean; var OldRange: TRect; begin @@ -5806,7 +5808,7 @@ end else FRange:=NormalizarRect(Rect(Fpivot.x,FPivot.y, DCol, DRow)); - if not ScrollToCell(DCol, DRow) then + if (not Scroll) or (not ScrollToCell(DCol, DRow)) then InvalidateMovement(DCol, DRow, OldRange); SwapInt(DCol,FCol); @@ -5879,7 +5881,7 @@ Inc(NRow, RInc); SelOk:=SelectCell(NCol, NRow); end; - Result:=MoveExtend(False, NCol, NRow); + Result:=MoveExtend(False, NCol, NRow, True); // whether or not a movement was valid if goAlwaysShowEditor // is set, editor should pop up. @@ -7015,6 +7017,7 @@ cfg.SetValue(Path+'goRelaxedRowSelect/value', goRelaxedRowSelect in options); cfg.SetValue(Path+'goDblClickAutoSize/value', goDblClickAutoSize in options); Cfg.SetValue(Path+'goSmoothScroll/value', goSmoothScroll in Options); + Cfg.SetValue(Path+'goDisableScrollWithMouse/value', goDisableScrollWithMouse in Options); end; Cfg.SetValue('grid/saveoptions/position', soPosition in SaveOptions); @@ -7099,6 +7102,9 @@ if Version>=2 then begin GetValue('goSmoothScroll',goSmoothScroll); end; + //if Version >= 4 then begin + // GetValue('goDisableScrollWithMouse',goDisableScrollWithMouse); + //end; Options:=Opt; end; @@ -7114,7 +7120,7 @@ j:=Cfg.GetValue('grid/position/row',-1); if (i>=FFixedCols)and(i<=ColCount-1) and (j>=FFixedRows)and(j<=RowCount-1) then begin - MoveExtend(false, i,j); + MoveExtend(False, i, j, True); end; if goRangeSelect in Options then begin FRange.left:=Cfg.getValue('grid/position/selection/left',FCol);
-- _______________________________________________ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus