diff --git a/lcl/dbgrids.pas b/lcl/dbgrids.pas index b2d2655556..060f45baa3 100644 --- a/lcl/dbgrids.pas +++ b/lcl/dbgrids.pas @@ -1748,7 +1748,6 @@ end; procedure TCustomDBGrid.KeyDown(var Key: Word; Shift: TShiftState); var DeltaCol,DeltaRow: Integer; - WasCancelled: boolean; procedure DoOnKeyDown; begin @@ -1801,24 +1800,26 @@ var if InsertCancelable then begin if IsEOF then - //exit - else + result:=true + else begin doCancel; - result := true; + result := false; + end; end else begin + result:=false; doMoveBySmall(1); - if GridCanModify and FDataLink.EOF then + if GridCanModify and FDataLink.EOF then begin doAppend; - result := false; + end; end; end; function DoVKUP: boolean; begin - Result := InsertCancelable and IsEOF; - if Result then + if InsertCancelable and IsEOF then doCancel else doMoveBySmall(-1); + result := FDatalink.DataSet.BOF; end; begin {$IfDef dbgGrid}DebugLn('DBGrid.KeyDown INIT Key= ',IntToStr(Key));{$Endif} @@ -1832,15 +1833,16 @@ begin GetDeltaMoveNext(ssShift in Shift, DeltaCol, DeltaRow); - if DeltaRow > 0 then - WasCancelled := doVkDown - else - if DeltaRow < 0 then - WasCancelled := doVKUp - else - WasCancelled := false; + if DeltaRow > 0 then begin + if doVKDown then + //DeltaCol:=0; // tochk: strict? already in EOF, don't change column + end else + if DeltaRow < 0 then begin + if doVKUP then + //DeltaCol:=0; // tochk: strict? already in BOF, don't change column + end; - if not WasCancelled and (DeltaCol<>0) then + if (DeltaCol<>0) then Col := Col + DeltaCol; Key := 0; diff --git a/lcl/grids.pas b/lcl/grids.pas index 364569ad6a..96ba06897e 100644 --- a/lcl/grids.pas +++ b/lcl/grids.pas @@ -118,7 +118,8 @@ type TGridZone = (gzNormal, gzFixedCols, gzFixedRows, gzFixedCells, gzInvalid); TUpdateOption = (uoNone, uoQuick, uoFull); - TAutoAdvance = (aaNone,aaDown,aaRight,aaLeft, aaRightDown, aaLeftDown); + TAutoAdvance = (aaNone,aaDown,aaRight,aaLeft, aaRightDown, aaLeftDown, + aaRightUp, aaLeftUp); TItemType = (itNormal,itCell,itColumn,itRow,itFixed,itFixedColumn,itFixedRow,itSelected); @@ -5682,17 +5683,31 @@ end; function TCustomGrid.GetDeltaMoveNext(const Inverse: boolean; var ACol, ARow: Integer): boolean; var - aa: TAutoAdvance; + DeltaCol,DeltaRow: Integer; function CalcNextStep: boolean; var + aa: TAutoAdvance; cCol,cRow: Integer; begin DeltaCol := 0; DeltaRow := 0; - + + // invert direction if necessary + // + aa := FAutoAdvance; + if Inverse then + case FAutoAdvance of + aaRight: aa := aaLeft; + aaLeft: aa := aaRight; + aaRightDown: aa := aaLeftUp; + aaLeftDown: aa := aaRightUp; + aaRightUP: aa := aaLeftDown; + aaLeftUP: aa := aaRightDown; + end; + case aa of aaRight: DeltaCol := 1; @@ -5710,7 +5725,23 @@ var DeltaCol := FixedCols-ACol; DeltaRow := 1; end; - + + aaRightUP: + if AColFixedCols then + DeltaCol := -1 + else begin + DeltaCol := ColCount-1-ACol; + DeltaRow := -1; + end; + aaLeftDown: if ACol>FixedCols then DeltaCol := -1 @@ -5738,20 +5769,6 @@ begin if FAutoAdvance=aaNone then exit; // quick case, no auto movement allowed - // invert direction if necessary - // - // TODO: inverse of aaRightDown is aaLeftUP - // inverse of aaLeftDown is aaRightUP - // move this to CalcNextStep - aa := FAutoAdvance; - if Inverse then - case FAutoAdvance of - aaRight: aa := aaLeft; - aaLeft: aa := aaRight; - aaRightDown: aa := aaLeftDown; - aaLeftDown: aa := aaRightDown; - end; - // browse the grid in autoadvance order while CalcNextStep do begin ACol := ACol + DeltaCol; @@ -5767,9 +5784,9 @@ begin ACol := ACol - FCol; ARow := ARow - FRow; end else begin - // no available next cell, return current - ACol := FCol; - ARow := FRow; + // no available next cell, return delta anyway + ACol := DeltaCol; + ARow := DeltaRow; end; end;