From 6ebdea449b9e014ae977e17c2e1f65a557239289 Mon Sep 17 00:00:00 2001 From: Ansgar Becker Date: Mon, 21 Dec 2009 20:05:32 +0000 Subject: [PATCH] Browse to previous cell when pressing Shift+Tab in editing mode. No need to post messages for this logic. Fixes issue #1407. --- source/grideditlinks.pas | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/source/grideditlinks.pas b/source/grideditlinks.pas index b7114020..03c2fdd1 100644 --- a/source/grideditlinks.pas +++ b/source/grideditlinks.pas @@ -21,6 +21,7 @@ type FMainControl: TWinControl; // The editor's most important component FStopping: Boolean; // Set to True when the edit link requests stopping the edit action. FLastKeyDown: Integer; // Set in OnKeyDown on the editor's main control + FLastShiftState: TShiftState; FOldWindowProc: TWndMethod; // Temporary switched to TempWindowProc to be able to catch Tab key procedure TempWindowProc(var Message: TMessage); procedure DoKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); @@ -201,11 +202,41 @@ begin end; destructor TBaseGridEditorLink.Destroy; +var + NewColumn, FirstCol, LastCol: TColumnIndex; + NewNode: PVirtualNode; + DoPrev: Boolean; begin inherited; if FLastKeyDown = VK_TAB then begin - SendMessage(FTree.Handle, WM_KEYDOWN, FLastKeyDown, 0); - SendMessage(FTree.Handle, WM_KEYDOWN, VK_F2, 0); + DoPrev := ssShift in FLastShiftState; + // Advance to next/previous visible column/node. + NewNode := FNode; + NewColumn := FColumn; + FirstCol := FTree.Header.Columns.GetFirstVisibleColumn; + LastCol := FTree.Header.Columns.GetLastVisibleColumn; + while true do begin + // Find a column for the current node which can be focused. + if DoPrev then begin + if NewColumn = FirstCol then begin + NewColumn := LastCol; + NewNode := FTree.GetPreviousVisible(NewNode); + end else + NewColumn := FTree.Header.Columns.GetPreviousColumn(NewColumn); + end else begin + if NewColumn = LastCol then begin + NewColumn := FirstCol; + NewNode := FTree.GetNextVisible(NewNode); + end else + NewColumn := FTree.Header.Columns.GetNextColumn(NewColumn); + end; + if not Assigned(NewNode) then + Break; + FTree.FocusedNode := NewNode; + FTree.FocusedColumn := NewColumn; + if FTree.EditNode(NewNode, NewColumn) then + Break; + end; end; end; @@ -332,6 +363,7 @@ end; procedure TBaseGridEditorLink.DoKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin FLastKeyDown := Key; + FLastShiftState := Shift; case Key of // Cancel by Escape VK_ESCAPE: FTree.CancelEditNode;