You've already forked lazarus-ccr
Manage properly mouse clicks inside and outside the grid for input values
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@2067 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -23,7 +23,7 @@ interface
|
|||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils, LResources, Forms, Controls, Graphics, DB, Grids, DBGrids,
|
Classes, SysUtils, LResources, Forms, Controls, Graphics, DB, Grids, DBGrids,
|
||||||
Dialogs, jdbgridutils;
|
Dialogs, LCLType, jdbgridutils;
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
@ -74,6 +74,9 @@ type
|
|||||||
function GetDefaultEditor(Column: integer): TWinControl; override;
|
function GetDefaultEditor(Column: integer): TWinControl; override;
|
||||||
procedure UpdateData; override;
|
procedure UpdateData; override;
|
||||||
property Columns: TJDBGridColumns read GetColumns write SetColumns;
|
property Columns: TJDBGridColumns read GetColumns write SetColumns;
|
||||||
|
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: integer);
|
||||||
|
override;
|
||||||
|
procedure KeyDown(var Key: word; Shift: TShiftState); override;
|
||||||
public
|
public
|
||||||
{ Public declarations }
|
{ Public declarations }
|
||||||
constructor Create(TheOwner: TComponent); override;
|
constructor Create(TheOwner: TComponent); override;
|
||||||
@ -193,6 +196,22 @@ begin
|
|||||||
inherited UpdateData;
|
inherited UpdateData;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TJDBGridControl.MouseDown(Button: TMouseButton; Shift: TShiftState;
|
||||||
|
X, Y: integer);
|
||||||
|
begin
|
||||||
|
if integerDbGridControl.CanDefocus and doubleDbGridControl.CanDefocus and
|
||||||
|
dateTimeDbGridControl.CanDefocus and stringDbGridControl.CanDefocus and
|
||||||
|
dateDbGridControl.CanDefocus and timeDbGridControl.CanDefocus then
|
||||||
|
inherited MouseDown(Button, Shift, X, Y)
|
||||||
|
else
|
||||||
|
abort;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TJDBGridControl.KeyDown(var Key: word; Shift: TShiftState);
|
||||||
|
begin
|
||||||
|
inherited KeyDown(Key, Shift);
|
||||||
|
end;
|
||||||
|
|
||||||
constructor TJDBGridControl.Create(TheOwner: TComponent);
|
constructor TJDBGridControl.Create(TheOwner: TComponent);
|
||||||
begin
|
begin
|
||||||
inherited Create(TheOwner);
|
inherited Create(TheOwner);
|
||||||
|
@ -46,6 +46,7 @@ type
|
|||||||
constructor Create;
|
constructor Create;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
function Editor(aGrid: TDBGrid; aMaxLength: integer = 0): TStringCellEditor;
|
function Editor(aGrid: TDBGrid; aMaxLength: integer = 0): TStringCellEditor;
|
||||||
|
function CanDefocus: boolean;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TJDbGridDateTimeCtrl }
|
{ TJDbGridDateTimeCtrl }
|
||||||
@ -71,6 +72,7 @@ type
|
|||||||
constructor Create;
|
constructor Create;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
function Editor(aGrid: TDBGrid): TStringCellEditor;
|
function Editor(aGrid: TDBGrid): TStringCellEditor;
|
||||||
|
function CanDefocus: boolean;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TJDbGridTimeCtrl }
|
{ TJDbGridTimeCtrl }
|
||||||
@ -96,6 +98,7 @@ type
|
|||||||
constructor Create;
|
constructor Create;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
function Editor(aGrid: TDBGrid): TStringCellEditor;
|
function Editor(aGrid: TDBGrid): TStringCellEditor;
|
||||||
|
function CanDefocus: boolean;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TJDbGridDateCtrl }
|
{ TJDbGridDateCtrl }
|
||||||
@ -121,6 +124,7 @@ type
|
|||||||
constructor Create;
|
constructor Create;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
function Editor(aGrid: TDBGrid): TStringCellEditor;
|
function Editor(aGrid: TDBGrid): TStringCellEditor;
|
||||||
|
function CanDefocus: boolean;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TJDbGridIntegerCtrl }
|
{ TJDbGridIntegerCtrl }
|
||||||
@ -141,6 +145,7 @@ type
|
|||||||
constructor Create;
|
constructor Create;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
function Editor(aGrid: TDBGrid): TStringCellEditor;
|
function Editor(aGrid: TDBGrid): TStringCellEditor;
|
||||||
|
function CanDefocus: boolean;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TJDbGridDoubleCtrl }
|
{ TJDbGridDoubleCtrl }
|
||||||
@ -166,6 +171,7 @@ type
|
|||||||
constructor Create;
|
constructor Create;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
function Editor(aGrid: TDBGrid; aDecimals: integer = 2): TStringCellEditor;
|
function Editor(aGrid: TDBGrid; aDecimals: integer = 2): TStringCellEditor;
|
||||||
|
function CanDefocus: boolean;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -255,6 +261,11 @@ begin
|
|||||||
Result := CellEditor;
|
Result := CellEditor;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TJDbGridStringCtrl.CanDefocus: boolean;
|
||||||
|
begin
|
||||||
|
Result := True;
|
||||||
|
end;
|
||||||
|
|
||||||
{ TJDbGridDateTimeCtrl }
|
{ TJDbGridDateTimeCtrl }
|
||||||
|
|
||||||
function TJDbGridDateTimeCtrl.getFormat: string;
|
function TJDbGridDateTimeCtrl.getFormat: string;
|
||||||
@ -296,7 +307,8 @@ begin
|
|||||||
if (not updated) then
|
if (not updated) then
|
||||||
begin
|
begin
|
||||||
theValue := StrToDateTime(CellEditor.Caption);
|
theValue := StrToDateTime(CellEditor.Caption);
|
||||||
if FormatDateTime(DisplayFormat, theValue) <> FormatDateTime(DisplayFormat, Field.AsDateTime) then
|
if FormatDateTime(DisplayFormat, theValue) <>
|
||||||
|
FormatDateTime(DisplayFormat, Field.AsDateTime) then
|
||||||
begin
|
begin
|
||||||
Field.DataSet.DisableControls;
|
Field.DataSet.DisableControls;
|
||||||
Field.DataSet.Edit;
|
Field.DataSet.Edit;
|
||||||
@ -416,6 +428,18 @@ begin
|
|||||||
Result := CellEditor;
|
Result := CellEditor;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TJDbGridDateTimeCtrl.CanDefocus: boolean;
|
||||||
|
begin
|
||||||
|
if CellEditor.Focused and (Length(CellEditor.Text) = 0) then
|
||||||
|
Result := True
|
||||||
|
else
|
||||||
|
if CellEditor.Focused and not
|
||||||
|
(IsValidDateTimeString(NormalizeDateTime(CellEditor.Caption, theValue))) then
|
||||||
|
Result := False
|
||||||
|
else
|
||||||
|
Result := True;
|
||||||
|
end;
|
||||||
|
|
||||||
{ TJDbGridTimeCtrl }
|
{ TJDbGridTimeCtrl }
|
||||||
|
|
||||||
function TJDbGridTimeCtrl.getFormat: string;
|
function TJDbGridTimeCtrl.getFormat: string;
|
||||||
@ -457,7 +481,8 @@ begin
|
|||||||
if (not updated) then
|
if (not updated) then
|
||||||
begin
|
begin
|
||||||
theValue := StrToTime(CellEditor.Caption);
|
theValue := StrToTime(CellEditor.Caption);
|
||||||
if FormatDateTime(DisplayFormat, theValue) <> FormatDateTime(DisplayFormat, Field.AsDateTime) then
|
if FormatDateTime(DisplayFormat, theValue) <>
|
||||||
|
FormatDateTime(DisplayFormat, Field.AsDateTime) then
|
||||||
begin
|
begin
|
||||||
Field.DataSet.DisableControls;
|
Field.DataSet.DisableControls;
|
||||||
Field.DataSet.Edit;
|
Field.DataSet.Edit;
|
||||||
@ -575,6 +600,18 @@ begin
|
|||||||
Result := CellEditor;
|
Result := CellEditor;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TJDbGridTimeCtrl.CanDefocus: boolean;
|
||||||
|
begin
|
||||||
|
if CellEditor.Focused and (Length(CellEditor.Text) = 0) then
|
||||||
|
Result := True
|
||||||
|
else
|
||||||
|
if CellEditor.Focused and not
|
||||||
|
(IsValidTimeString(NormalizeTime(CellEditor.Caption, theValue))) then
|
||||||
|
Result := False
|
||||||
|
else
|
||||||
|
Result := True;
|
||||||
|
end;
|
||||||
|
|
||||||
{ TJDbGridDateCtrl }
|
{ TJDbGridDateCtrl }
|
||||||
|
|
||||||
function TJDbGridDateCtrl.getFormat: string;
|
function TJDbGridDateCtrl.getFormat: string;
|
||||||
@ -616,7 +653,8 @@ begin
|
|||||||
if (not updated) then
|
if (not updated) then
|
||||||
begin
|
begin
|
||||||
theValue := StrToDate(CellEditor.Caption);
|
theValue := StrToDate(CellEditor.Caption);
|
||||||
if FormatDateTime(DisplayFormat, theValue) <> FormatDateTime(DisplayFormat, Field.AsDateTime) then
|
if FormatDateTime(DisplayFormat, theValue) <>
|
||||||
|
FormatDateTime(DisplayFormat, Field.AsDateTime) then
|
||||||
begin
|
begin
|
||||||
Field.DataSet.DisableControls;
|
Field.DataSet.DisableControls;
|
||||||
Field.DataSet.Edit;
|
Field.DataSet.Edit;
|
||||||
@ -736,6 +774,18 @@ begin
|
|||||||
Result := CellEditor;
|
Result := CellEditor;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TJDbGridDateCtrl.CanDefocus: boolean;
|
||||||
|
begin
|
||||||
|
if CellEditor.Focused and (Length(CellEditor.Text) = 0) then
|
||||||
|
Result := True
|
||||||
|
else
|
||||||
|
if CellEditor.Focused and not
|
||||||
|
(IsValidDateTimeString(NormalizeDateTime(CellEditor.Caption, theValue))) then
|
||||||
|
Result := False
|
||||||
|
else
|
||||||
|
Result := True;
|
||||||
|
end;
|
||||||
|
|
||||||
{ TJDbGridDoubleCtrl }
|
{ TJDbGridDoubleCtrl }
|
||||||
|
|
||||||
function TJDbGridDoubleCtrl.getDecimals: integer;
|
function TJDbGridDoubleCtrl.getDecimals: integer;
|
||||||
@ -816,7 +866,6 @@ begin
|
|||||||
CellEditor.Text := ''
|
CellEditor.Text := ''
|
||||||
else
|
else
|
||||||
CellEditor.Text := FloatToStr(Field.AsFloat);
|
CellEditor.Text := FloatToStr(Field.AsFloat);
|
||||||
//CellEditor.Text := CurrToStr(redondear(Field.AsCurrency, fDecimals));
|
|
||||||
updated := True;
|
updated := True;
|
||||||
theGrid.SetFocus; // No perder el foco
|
theGrid.SetFocus; // No perder el foco
|
||||||
end
|
end
|
||||||
@ -880,6 +929,14 @@ begin
|
|||||||
Result := CellEditor;
|
Result := CellEditor;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TJDbGridDoubleCtrl.CanDefocus: boolean;
|
||||||
|
begin
|
||||||
|
if CellEditor.Focused then
|
||||||
|
Result := IsValidFloat(CellEditor.Text)
|
||||||
|
else
|
||||||
|
Result := True;
|
||||||
|
end;
|
||||||
|
|
||||||
{ TJDbGridIntegerCtrl }
|
{ TJDbGridIntegerCtrl }
|
||||||
|
|
||||||
procedure TJDbGridIntegerCtrl.myEditOnEnter(Sender: TObject);
|
procedure TJDbGridIntegerCtrl.myEditOnEnter(Sender: TObject);
|
||||||
@ -993,5 +1050,13 @@ begin
|
|||||||
Result := CellEditor;
|
Result := CellEditor;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TJDbGridIntegerCtrl.CanDefocus: boolean;
|
||||||
|
begin
|
||||||
|
if CellEditor.Focused then
|
||||||
|
Result := IsValidInteger(CellEditor.Text)
|
||||||
|
else
|
||||||
|
Result := True;
|
||||||
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user