View Issue Details

IDProjectCategoryView StatusLast Update
0015917LazarusPatchpublic2013-09-28 19:20
ReporterJosé MejutoAssigned ToJesus Reyes 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Platformi386OSWindowsOS VersionXP SP2
Product Version0.9.29 (SVN)Product Build23660 
Target Version1.2.0Fixed in Version1.2.0 
Summary0015917: Key handling in the grids
DescriptionKeys handled by Grid and DBGrid at least do not produce a KeyPress event, so a key like Enter can not be handled by a simple keypress.
Steps To ReproducePut a stringgrid in a form, handle KeyPress to detect Enter key in order to load some information and enter in edit mode manually. The key never raises the "KeyPress" event.
Additional InformationIn attached patch key information is not destroyed but marked to be not handled further via the "CanGridAcceptKey" function.

In DBGrid also fixed a SIGSEGV pressing page down when no recordset is associated.
Tagsdbgrids, grids
Fixed in Revision42992
LazTarget1.2
WidgetsetWin32/Win64
Attached Files
  • grid_keyhandling_route.patch (12,371 bytes)
    Index: dbgrids.pas
    ===================================================================
    --- dbgrids.pas	(revision 23660)
    +++ dbgrids.pas	(working copy)
    @@ -297,6 +297,7 @@
         FOnPrepareCanvas: TPrepareDbGridCanvasEvent;
         FKeyBookmark: TBookmarkStr;
         FKeySign: Integer;
    +    FKeyHasBeenHandled: Boolean;
         procedure EmptyGrid;
         function GetColumns: TDBGridColumns;
         function GetCurrentColumn: TColumn;
    @@ -356,6 +357,7 @@
         procedure AddAutomaticColumns;
         procedure BeforeMoveSelection(const DCol,DRow: Integer); override;
         procedure BeginLayout;
    +    function CanGridAcceptKey(Key: Word; Shift: TShiftState): Boolean; override;
         procedure CellClick(const aCol,aRow: Integer); override;
         procedure ChangeBounds(ALeft, ATop, AWidth, AHeight: integer); override;
         procedure InvalidateSizes;
    @@ -1807,6 +1809,7 @@
     procedure TCustomDBGrid.KeyDown(var Key: Word; Shift: TShiftState);
     var
       DeltaCol,DeltaRow: Integer;
    +  PreserveKeyCode: Word;
     
       procedure DoOnKeyDown;
       begin
    @@ -1924,6 +1927,12 @@
       end;
     begin
       {$IfDef dbgGrid}DebugLn('DBGrid.KeyDown ',Name,' INIT Key= ',IntToStr(Key));{$Endif}
    +
    +  FKeyHasBeenHandled := false;
    +  //When FKeyHasBeenHandled:=true no further key processing will be
    +  //performed by parent grid class as it checks the "CanGridAcceptKey"
    +  //and it does not destroy the variable "Key" content.
    +  PreserveKeyCode := Key;
       case Key of
     
         VK_TAB:
    @@ -1945,7 +1954,7 @@
                   if (DeltaCol<>0) then
                     Col := Col + DeltaCol;
                 end;
    -            Key := 0;
    +            FKeyHasBeenHandled := true;
               end;
             end;
           end;
    @@ -1954,7 +1963,7 @@
           begin
             doOnKeyDown;
             if Key<>0 then begin
    -          key:=0;
    +          FKeyHasBeenHandled := true;
               if (dgEditing in Options) and not EditorMode then
                 EditorMode:=true
               else begin
    @@ -1978,7 +1987,7 @@
                 (MessageDlg(rsDeleteRecord, mtConfirmation, mbOKCancel, 0 )<>mrCancel)
               then begin
                 doDelete;
    -            key := 0;
    +            FKeyHasBeenHandled := true;
               end;
             end;
           end;
    @@ -1988,7 +1997,7 @@
             DoOnKeyDown;
             if Key<>0 then begin
               doVKDown;
    -          Key := 0;
    +          FKeyHasBeenHandled := true;
             end;
           end;
     
    @@ -1997,27 +2006,31 @@
             doOnKeyDown;
             if Key<>0 then begin
               doVKUp;
    -          key := 0;
    +          FKeyHasBeenHandled := true;
              end;
           end;
     
         VK_NEXT:
           begin
    -        doOnKeyDown;
    -        if Key<>0 then begin
    -          doMoveBy( VisibleRowCount );
    -          ClearSelection(true);
    -          Key := 0;
    +        if ValidDataSet then begin
    +          doOnKeyDown;
    +          if Key<>0 then begin
    +            doMoveBy( VisibleRowCount );
    +            ClearSelection(true);
    +            FKeyHasBeenHandled := true;
    +          end;
             end;
           end;
     
         VK_PRIOR:
           begin
    -        doOnKeyDown;
    -        if Key<>0 then begin
    -          doMoveBy( -VisibleRowCount );
    -          ClearSelection(true);
    -          key := 0;
    +        if ValidDataSet then begin
    +          doOnKeyDown;
    +          if Key<>0 then begin
    +            doMoveBy( -VisibleRowCount );
    +            ClearSelection(true);
    +            FKeyHasBeenHandled := true;
    +          end;
             end;
           end;
     
    @@ -2029,7 +2042,7 @@
                 EditorCancelEditing;
                 if FDatalink.Active and not FDatalink.Dataset.Modified then
                   FDatalink.Modified := False;
    -            Key := 0;
    +            FKeyHasBeenHandled := true;
               end else
                 if FDataLink.Active then
                   doCancel;
    @@ -2042,7 +2055,7 @@
             if Key<>0 then
               if GridCanModify then begin
                 doInsert;
    -            Key:=0;
    +            FKeyHasBeenHandled := true;
               end;
           end;
     
    @@ -2056,7 +2069,7 @@
                 else
                   MoveNextSelectable(False, FixedCols, Row);
                 ClearSelection(true);
    -            Key:=0;
    +            FKeyHasBeenHandled := true;
               end;
             end;
           end;
    @@ -2071,7 +2084,7 @@
                 else
                   MoveNextSelectable(False, ColCount-1, Row);
                 ClearSelection(true);
    -            Key:=0;
    +            FKeyHasBeenHandled := true;
               end;
             end;
           end;
    @@ -2082,7 +2095,7 @@
             if Key<>0 then begin
               if ColumnEditorStyle(Col, SelectedField) = cbsCheckboxColumn then begin
             		SwapCheckBox;
    -            Key:=0;
    +            FKeyHasBeenHandled := true;
               end;
             end;
           end;
    @@ -2093,9 +2106,17 @@
               ToggleSelectedRow;
           end;
     
    -    else
    -      inherited KeyDown(Key, Shift);
       end;
    +  { If the user handles any of the default operational keys he/she will notify
    +    it putting the "Key:=0", but not restoring its value will interfer with
    +    keypress event, so restore it in all cases, and mark as handled }
    +  if Key = 0 then begin
    +    Key := PreserveKeyCode;
    +    FKeyHasBeenHandled := true;
    +  end;
    +
    +  inherited KeyDown(Key, Shift);
    +  FKeyHasBeenHandled := false; //Restore all keys process.
       {$IfDef dbgGrid}DebugLn('DBGrid.KeyDown END Key= ',IntToStr(Key));{$Endif}
     end;
     
    @@ -2260,6 +2281,17 @@
       inc(FLayoutChangedCount);
     end;
     
    +function TCustomDBGrid.CanGridAcceptKey(Key: Word; Shift: TShiftState
    +  ): Boolean;
    +begin
    +  if Inherited CanGridAcceptKey(Key,Shift) then begin
    +    //If inherited can use the key, check if DBGrid has processed it.
    +    Result:=not FKeyHasBeenHandled;
    +  end else begin
    +    Result:=false;
    +  end;
    +end;
    +
     procedure TCustomDBGrid.EditingColumn(aCol: Integer; Ok: Boolean);
     begin
       {$ifdef dbgDBGrid} DebugLn(['DBGrid.EditingColumn INIT aCol=', aCol, ' Ok=', ok]); {$endif}
    Index: grids.pas
    ===================================================================
    --- grids.pas	(revision 23660)
    +++ grids.pas	(working copy)
    @@ -5627,6 +5627,7 @@
       R: TRect;
       Relaxed: Boolean;
       DeltaCol,DeltaRow: Integer;
    +  CheckKey: Boolean;
     
       procedure MoveSel(Rel: Boolean; aCol,aRow: Integer);
       begin
    @@ -5642,116 +5643,117 @@
       {$ifdef dbgGrid}DebugLn('Grid.KeyDown INIT Key=',IntToStr(Key));{$endif}
       inherited KeyDown(Key, Shift);
       //if not FGCache.ValidGrid then Exit;
    -  if not CanGridAcceptKey(Key, Shift) then
    -    Key:=0;  // Allow CanGridAcceptKey to override Key behaviour
    +  CheckKey := CanGridAcceptKey(Key, Shift); // Allow CanGridAcceptKey to override Key behaviour
       Sh:=(ssShift in Shift);
       Relaxed:=not (goRowSelect in Options) or (goRelaxedRowSelect in Options);
     
    -  case Key of
    -    VK_TAB:
    -      begin
    -        if goTabs in Options then begin
    -          if GetDeltaMoveNext(Sh, DeltaCol,DeltaRow) then begin
    -            Sh := False;
    -            MoveSel(True, DeltaCol, DeltaRow);
    +  if CheckKey then begin
    +    case Key of
    +      VK_TAB:
    +        begin
    +          if goTabs in Options then begin
    +            if GetDeltaMoveNext(Sh, DeltaCol,DeltaRow) then begin
    +              Sh := False;
    +              MoveSel(True, DeltaCol, DeltaRow);
    +            end;
    +   //         Key:=0;
    +          end else
    +          if FEditorKey then begin
    +            {$IFDEF dbggrid}
    +            DebugLn('Got TAB, shift=',dbgs(sh));
    +            {$endif}
    +            if sh then
    +              GridFlags := GridFlags + [gfRevEditorTab]
    +            else
    +              GridFlags := GridFlags + [gfEditorTab];
               end;
    -          Key:=0;
    -        end else
    -        if FEditorKey then begin
    -          {$IFDEF dbggrid}
    -          DebugLn('Got TAB, shift=',dbgs(sh));
    -          {$endif}
    -          if sh then
    -            GridFlags := GridFlags + [gfRevEditorTab]
    +        end;
    +      VK_LEFT:
    +        begin
    +          if Relaxed then MoveSel(True,-1, 0)
    +          else            MoveSel(true, 0,-1);
    +        end;
    +      VK_RIGHT:
    +        begin
    +          if Relaxed then MoveSel(True, 1, 0)
    +          else            MoveSel(True, 0, 1);
    +        end;
    +      VK_UP:
    +        begin
    +          MoveSel(True, 0, -1);
    +        end;
    +      VK_DOWN:
    +        begin
    +          MoveSel(True, 0, 1);
    +        end;
    +      VK_PRIOR:
    +        begin
    +          R:=FGCache.Visiblegrid;
    +          MoveSel(True, 0, R.Top-R.Bottom);
    +        end;
    +      VK_NEXT:
    +        begin
    +          R:=FGCache.VisibleGrid;
    +          MoveSel(True, 0, R.Bottom-R.Top);
    +        end;
    +      VK_HOME:
    +        begin
    +          if ssCtrl in Shift then MoveSel(False, FCol, FFixedRows)
               else
    -            GridFlags := GridFlags + [gfEditorTab];
    +            if Relaxed then MoveSel(False, FFixedCols, FRow)
    +            else            MoveSel(False, FCol, FFixedRows);
             end;
    -      end;
    -    VK_LEFT:
    -      begin
    -        if Relaxed then MoveSel(True,-1, 0)
    -        else            MoveSel(true, 0,-1);
    -      end;
    -    VK_RIGHT:
    -      begin
    -        if Relaxed then MoveSel(True, 1, 0)
    -        else            MoveSel(True, 0, 1);
    -      end;
    -    VK_UP:
    -      begin
    -        MoveSel(True, 0, -1);
    -      end;
    -    VK_DOWN:
    -      begin
    -        MoveSel(True, 0, 1);
    -      end;
    -    VK_PRIOR:
    -      begin
    -        R:=FGCache.Visiblegrid;
    -        MoveSel(True, 0, R.Top-R.Bottom);
    -      end;
    -    VK_NEXT:
    -      begin
    -        R:=FGCache.VisibleGrid;
    -        MoveSel(True, 0, R.Bottom-R.Top);
    -      end;
    -    VK_HOME:
    -      begin
    -        if ssCtrl in Shift then MoveSel(False, FCol, FFixedRows)
    -        else
    -          if Relaxed then MoveSel(False, FFixedCols, FRow)
    -          else            MoveSel(False, FCol, FFixedRows);
    -      end;
    -    VK_END:
    -      begin
    -        if ssCtrl in Shift then MoveSel(False, FCol, RowCount-1)
    -        else
    -          if Relaxed then MoveSel(False, ColCount-1, FRow)
    -          else            MoveSel(False, FCol, RowCount-1);
    -      end;
    -    VK_F2:
    -      begin
    -        if not FEditorKey and EditingAllowed(FCol) then begin
    -          EditorShow(False);
    -          Key:=0;
    -        end ;
    -      end;
    -    VK_RETURN:
    -      begin
    -        if not FEditorKey and EditingAllowed(FCol) then begin
    -          EditorShow(True);
    -          Key := 0;
    +      VK_END:
    +        begin
    +          if ssCtrl in Shift then MoveSel(False, FCol, RowCount-1)
    +          else
    +            if Relaxed then MoveSel(False, ColCount-1, FRow)
    +            else            MoveSel(False, FCol, RowCount-1);
             end;
    -      end;
    -    VK_BACK:
    -      begin
    -        // Workaround: LM_CHAR doesnt trigger with BACKSPACE
    -        if not FEditorKey and EditingAllowed(FCol) then begin
    -          EditorShowChar(^H);
    -          key:=0;
    +      VK_F2:
    +        begin
    +          if not FEditorKey and EditingAllowed(FCol) then begin
    +            EditorShow(False);
    +   //         Key:=0;
    +          end ;
             end;
    -      end;
    -    VK_C:
    -      if not FEditorKey then begin
    -        if ssCtrl in Shift then begin
    -//          Key := 0;
    -          doCopyToClipboard;
    +      VK_RETURN:
    +        begin
    +          if not FEditorKey and EditingAllowed(FCol) then begin
    +            EditorShow(True);
    +   //         Key := 0;
    +          end;
             end;
    -      end;
    -    VK_V:
    -      if not FEditorKey then begin
    -        if ssCtrl in Shift then begin
    -//          Key := 0;
    -          doPasteFromClipboard;
    +      VK_BACK:
    +        begin
    +          // Workaround: LM_CHAR doesnt trigger with BACKSPACE
    +          if not FEditorKey and EditingAllowed(FCol) then begin
    +            EditorShowChar(^H);
    +   //         key:=0;
    +          end;
             end;
    -      end;
    -    VK_X:
    -      if not FEditorKey then begin
    -        if ssCtrl in Shift then begin
    -//          Key := 0;
    -          doCutToClipboard;
    +      VK_C:
    +        if not FEditorKey then begin
    +          if ssCtrl in Shift then begin
    +  //          Key := 0;
    +            doCopyToClipboard;
    +          end;
             end;
    -      end;
    +      VK_V:
    +        if not FEditorKey then begin
    +          if ssCtrl in Shift then begin
    +  //          Key := 0;
    +            doPasteFromClipboard;
    +          end;
    +        end;
    +      VK_X:
    +        if not FEditorKey then begin
    +          if ssCtrl in Shift then begin
    +  //          Key := 0;
    +            doCutToClipboard;
    +          end;
    +        end;
    +    end;
       end;
       {$ifdef dbgGrid}DebugLn('Grid.KeyDown END Key=',IntToStr(Key));{$endif}
     end;
    

Activities

2010-03-08 00:03

 

grid_keyhandling_route.patch (12,371 bytes)
Index: dbgrids.pas
===================================================================
--- dbgrids.pas	(revision 23660)
+++ dbgrids.pas	(working copy)
@@ -297,6 +297,7 @@
     FOnPrepareCanvas: TPrepareDbGridCanvasEvent;
     FKeyBookmark: TBookmarkStr;
     FKeySign: Integer;
+    FKeyHasBeenHandled: Boolean;
     procedure EmptyGrid;
     function GetColumns: TDBGridColumns;
     function GetCurrentColumn: TColumn;
@@ -356,6 +357,7 @@
     procedure AddAutomaticColumns;
     procedure BeforeMoveSelection(const DCol,DRow: Integer); override;
     procedure BeginLayout;
+    function CanGridAcceptKey(Key: Word; Shift: TShiftState): Boolean; override;
     procedure CellClick(const aCol,aRow: Integer); override;
     procedure ChangeBounds(ALeft, ATop, AWidth, AHeight: integer); override;
     procedure InvalidateSizes;
@@ -1807,6 +1809,7 @@
 procedure TCustomDBGrid.KeyDown(var Key: Word; Shift: TShiftState);
 var
   DeltaCol,DeltaRow: Integer;
+  PreserveKeyCode: Word;
 
   procedure DoOnKeyDown;
   begin
@@ -1924,6 +1927,12 @@
   end;
 begin
   {$IfDef dbgGrid}DebugLn('DBGrid.KeyDown ',Name,' INIT Key= ',IntToStr(Key));{$Endif}
+
+  FKeyHasBeenHandled := false;
+  //When FKeyHasBeenHandled:=true no further key processing will be
+  //performed by parent grid class as it checks the "CanGridAcceptKey"
+  //and it does not destroy the variable "Key" content.
+  PreserveKeyCode := Key;
   case Key of
 
     VK_TAB:
@@ -1945,7 +1954,7 @@
               if (DeltaCol<>0) then
                 Col := Col + DeltaCol;
             end;
-            Key := 0;
+            FKeyHasBeenHandled := true;
           end;
         end;
       end;
@@ -1954,7 +1963,7 @@
       begin
         doOnKeyDown;
         if Key<>0 then begin
-          key:=0;
+          FKeyHasBeenHandled := true;
           if (dgEditing in Options) and not EditorMode then
             EditorMode:=true
           else begin
@@ -1978,7 +1987,7 @@
             (MessageDlg(rsDeleteRecord, mtConfirmation, mbOKCancel, 0 )<>mrCancel)
           then begin
             doDelete;
-            key := 0;
+            FKeyHasBeenHandled := true;
           end;
         end;
       end;
@@ -1988,7 +1997,7 @@
         DoOnKeyDown;
         if Key<>0 then begin
           doVKDown;
-          Key := 0;
+          FKeyHasBeenHandled := true;
         end;
       end;
 
@@ -1997,27 +2006,31 @@
         doOnKeyDown;
         if Key<>0 then begin
           doVKUp;
-          key := 0;
+          FKeyHasBeenHandled := true;
          end;
       end;
 
     VK_NEXT:
       begin
-        doOnKeyDown;
-        if Key<>0 then begin
-          doMoveBy( VisibleRowCount );
-          ClearSelection(true);
-          Key := 0;
+        if ValidDataSet then begin
+          doOnKeyDown;
+          if Key<>0 then begin
+            doMoveBy( VisibleRowCount );
+            ClearSelection(true);
+            FKeyHasBeenHandled := true;
+          end;
         end;
       end;
 
     VK_PRIOR:
       begin
-        doOnKeyDown;
-        if Key<>0 then begin
-          doMoveBy( -VisibleRowCount );
-          ClearSelection(true);
-          key := 0;
+        if ValidDataSet then begin
+          doOnKeyDown;
+          if Key<>0 then begin
+            doMoveBy( -VisibleRowCount );
+            ClearSelection(true);
+            FKeyHasBeenHandled := true;
+          end;
         end;
       end;
 
@@ -2029,7 +2042,7 @@
             EditorCancelEditing;
             if FDatalink.Active and not FDatalink.Dataset.Modified then
               FDatalink.Modified := False;
-            Key := 0;
+            FKeyHasBeenHandled := true;
           end else
             if FDataLink.Active then
               doCancel;
@@ -2042,7 +2055,7 @@
         if Key<>0 then
           if GridCanModify then begin
             doInsert;
-            Key:=0;
+            FKeyHasBeenHandled := true;
           end;
       end;
 
@@ -2056,7 +2069,7 @@
             else
               MoveNextSelectable(False, FixedCols, Row);
             ClearSelection(true);
-            Key:=0;
+            FKeyHasBeenHandled := true;
           end;
         end;
       end;
@@ -2071,7 +2084,7 @@
             else
               MoveNextSelectable(False, ColCount-1, Row);
             ClearSelection(true);
-            Key:=0;
+            FKeyHasBeenHandled := true;
           end;
         end;
       end;
@@ -2082,7 +2095,7 @@
         if Key<>0 then begin
           if ColumnEditorStyle(Col, SelectedField) = cbsCheckboxColumn then begin
         		SwapCheckBox;
-            Key:=0;
+            FKeyHasBeenHandled := true;
           end;
         end;
       end;
@@ -2093,9 +2106,17 @@
           ToggleSelectedRow;
       end;
 
-    else
-      inherited KeyDown(Key, Shift);
   end;
+  { If the user handles any of the default operational keys he/she will notify
+    it putting the "Key:=0", but not restoring its value will interfer with
+    keypress event, so restore it in all cases, and mark as handled }
+  if Key = 0 then begin
+    Key := PreserveKeyCode;
+    FKeyHasBeenHandled := true;
+  end;
+
+  inherited KeyDown(Key, Shift);
+  FKeyHasBeenHandled := false; //Restore all keys process.
   {$IfDef dbgGrid}DebugLn('DBGrid.KeyDown END Key= ',IntToStr(Key));{$Endif}
 end;
 
@@ -2260,6 +2281,17 @@
   inc(FLayoutChangedCount);
 end;
 
+function TCustomDBGrid.CanGridAcceptKey(Key: Word; Shift: TShiftState
+  ): Boolean;
+begin
+  if Inherited CanGridAcceptKey(Key,Shift) then begin
+    //If inherited can use the key, check if DBGrid has processed it.
+    Result:=not FKeyHasBeenHandled;
+  end else begin
+    Result:=false;
+  end;
+end;
+
 procedure TCustomDBGrid.EditingColumn(aCol: Integer; Ok: Boolean);
 begin
   {$ifdef dbgDBGrid} DebugLn(['DBGrid.EditingColumn INIT aCol=', aCol, ' Ok=', ok]); {$endif}
Index: grids.pas
===================================================================
--- grids.pas	(revision 23660)
+++ grids.pas	(working copy)
@@ -5627,6 +5627,7 @@
   R: TRect;
   Relaxed: Boolean;
   DeltaCol,DeltaRow: Integer;
+  CheckKey: Boolean;
 
   procedure MoveSel(Rel: Boolean; aCol,aRow: Integer);
   begin
@@ -5642,116 +5643,117 @@
   {$ifdef dbgGrid}DebugLn('Grid.KeyDown INIT Key=',IntToStr(Key));{$endif}
   inherited KeyDown(Key, Shift);
   //if not FGCache.ValidGrid then Exit;
-  if not CanGridAcceptKey(Key, Shift) then
-    Key:=0;  // Allow CanGridAcceptKey to override Key behaviour
+  CheckKey := CanGridAcceptKey(Key, Shift); // Allow CanGridAcceptKey to override Key behaviour
   Sh:=(ssShift in Shift);
   Relaxed:=not (goRowSelect in Options) or (goRelaxedRowSelect in Options);
 
-  case Key of
-    VK_TAB:
-      begin
-        if goTabs in Options then begin
-          if GetDeltaMoveNext(Sh, DeltaCol,DeltaRow) then begin
-            Sh := False;
-            MoveSel(True, DeltaCol, DeltaRow);
+  if CheckKey then begin
+    case Key of
+      VK_TAB:
+        begin
+          if goTabs in Options then begin
+            if GetDeltaMoveNext(Sh, DeltaCol,DeltaRow) then begin
+              Sh := False;
+              MoveSel(True, DeltaCol, DeltaRow);
+            end;
+   //         Key:=0;
+          end else
+          if FEditorKey then begin
+            {$IFDEF dbggrid}
+            DebugLn('Got TAB, shift=',dbgs(sh));
+            {$endif}
+            if sh then
+              GridFlags := GridFlags + [gfRevEditorTab]
+            else
+              GridFlags := GridFlags + [gfEditorTab];
           end;
-          Key:=0;
-        end else
-        if FEditorKey then begin
-          {$IFDEF dbggrid}
-          DebugLn('Got TAB, shift=',dbgs(sh));
-          {$endif}
-          if sh then
-            GridFlags := GridFlags + [gfRevEditorTab]
+        end;
+      VK_LEFT:
+        begin
+          if Relaxed then MoveSel(True,-1, 0)
+          else            MoveSel(true, 0,-1);
+        end;
+      VK_RIGHT:
+        begin
+          if Relaxed then MoveSel(True, 1, 0)
+          else            MoveSel(True, 0, 1);
+        end;
+      VK_UP:
+        begin
+          MoveSel(True, 0, -1);
+        end;
+      VK_DOWN:
+        begin
+          MoveSel(True, 0, 1);
+        end;
+      VK_PRIOR:
+        begin
+          R:=FGCache.Visiblegrid;
+          MoveSel(True, 0, R.Top-R.Bottom);
+        end;
+      VK_NEXT:
+        begin
+          R:=FGCache.VisibleGrid;
+          MoveSel(True, 0, R.Bottom-R.Top);
+        end;
+      VK_HOME:
+        begin
+          if ssCtrl in Shift then MoveSel(False, FCol, FFixedRows)
           else
-            GridFlags := GridFlags + [gfEditorTab];
+            if Relaxed then MoveSel(False, FFixedCols, FRow)
+            else            MoveSel(False, FCol, FFixedRows);
         end;
-      end;
-    VK_LEFT:
-      begin
-        if Relaxed then MoveSel(True,-1, 0)
-        else            MoveSel(true, 0,-1);
-      end;
-    VK_RIGHT:
-      begin
-        if Relaxed then MoveSel(True, 1, 0)
-        else            MoveSel(True, 0, 1);
-      end;
-    VK_UP:
-      begin
-        MoveSel(True, 0, -1);
-      end;
-    VK_DOWN:
-      begin
-        MoveSel(True, 0, 1);
-      end;
-    VK_PRIOR:
-      begin
-        R:=FGCache.Visiblegrid;
-        MoveSel(True, 0, R.Top-R.Bottom);
-      end;
-    VK_NEXT:
-      begin
-        R:=FGCache.VisibleGrid;
-        MoveSel(True, 0, R.Bottom-R.Top);
-      end;
-    VK_HOME:
-      begin
-        if ssCtrl in Shift then MoveSel(False, FCol, FFixedRows)
-        else
-          if Relaxed then MoveSel(False, FFixedCols, FRow)
-          else            MoveSel(False, FCol, FFixedRows);
-      end;
-    VK_END:
-      begin
-        if ssCtrl in Shift then MoveSel(False, FCol, RowCount-1)
-        else
-          if Relaxed then MoveSel(False, ColCount-1, FRow)
-          else            MoveSel(False, FCol, RowCount-1);
-      end;
-    VK_F2:
-      begin
-        if not FEditorKey and EditingAllowed(FCol) then begin
-          EditorShow(False);
-          Key:=0;
-        end ;
-      end;
-    VK_RETURN:
-      begin
-        if not FEditorKey and EditingAllowed(FCol) then begin
-          EditorShow(True);
-          Key := 0;
+      VK_END:
+        begin
+          if ssCtrl in Shift then MoveSel(False, FCol, RowCount-1)
+          else
+            if Relaxed then MoveSel(False, ColCount-1, FRow)
+            else            MoveSel(False, FCol, RowCount-1);
         end;
-      end;
-    VK_BACK:
-      begin
-        // Workaround: LM_CHAR doesnt trigger with BACKSPACE
-        if not FEditorKey and EditingAllowed(FCol) then begin
-          EditorShowChar(^H);
-          key:=0;
+      VK_F2:
+        begin
+          if not FEditorKey and EditingAllowed(FCol) then begin
+            EditorShow(False);
+   //         Key:=0;
+          end ;
         end;
-      end;
-    VK_C:
-      if not FEditorKey then begin
-        if ssCtrl in Shift then begin
-//          Key := 0;
-          doCopyToClipboard;
+      VK_RETURN:
+        begin
+          if not FEditorKey and EditingAllowed(FCol) then begin
+            EditorShow(True);
+   //         Key := 0;
+          end;
         end;
-      end;
-    VK_V:
-      if not FEditorKey then begin
-        if ssCtrl in Shift then begin
-//          Key := 0;
-          doPasteFromClipboard;
+      VK_BACK:
+        begin
+          // Workaround: LM_CHAR doesnt trigger with BACKSPACE
+          if not FEditorKey and EditingAllowed(FCol) then begin
+            EditorShowChar(^H);
+   //         key:=0;
+          end;
         end;
-      end;
-    VK_X:
-      if not FEditorKey then begin
-        if ssCtrl in Shift then begin
-//          Key := 0;
-          doCutToClipboard;
+      VK_C:
+        if not FEditorKey then begin
+          if ssCtrl in Shift then begin
+  //          Key := 0;
+            doCopyToClipboard;
+          end;
         end;
-      end;
+      VK_V:
+        if not FEditorKey then begin
+          if ssCtrl in Shift then begin
+  //          Key := 0;
+            doPasteFromClipboard;
+          end;
+        end;
+      VK_X:
+        if not FEditorKey then begin
+          if ssCtrl in Shift then begin
+  //          Key := 0;
+            doCutToClipboard;
+          end;
+        end;
+    end;
   end;
   {$ifdef dbgGrid}DebugLn('Grid.KeyDown END Key=',IntToStr(Key));{$endif}
 end;

Jesus Reyes

2013-09-27 20:42

developer   ~0070407

The RETURN key is now routed through keypress

Issue History

Date Modified Username Field Change
2010-03-08 00:02 José Mejuto New Issue
2010-03-08 00:02 José Mejuto Widgetset => Win32/Win64
2010-03-08 00:03 José Mejuto File Added: grid_keyhandling_route.patch
2010-03-08 01:55 Jesus Reyes Status new => assigned
2010-03-08 01:55 Jesus Reyes Assigned To => Jesus Reyes
2010-03-15 02:28 Jesus Reyes Tag Attached: dbgrids
2010-03-15 02:28 Jesus Reyes Tag Attached: grids
2013-09-27 20:42 Jesus Reyes Fixed in Revision => 42992
2013-09-27 20:42 Jesus Reyes LazTarget => 1.2
2013-09-27 20:42 Jesus Reyes Note Added: 0070407
2013-09-27 20:42 Jesus Reyes Status assigned => resolved
2013-09-27 20:42 Jesus Reyes Fixed in Version => 1.2.0
2013-09-27 20:42 Jesus Reyes Resolution open => fixed
2013-09-27 20:42 Jesus Reyes Target Version => 1.2.0
2013-09-28 19:20 José Mejuto Status resolved => closed