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:
parent
ddc1b15861
commit
12b16151cc
@ -23,7 +23,7 @@ interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, LResources, Forms, Controls, Graphics, DB, Grids, DBGrids,
|
||||
Dialogs, jdbgridutils;
|
||||
Dialogs, LCLType, jdbgridutils;
|
||||
|
||||
type
|
||||
|
||||
@ -74,6 +74,9 @@ type
|
||||
function GetDefaultEditor(Column: integer): TWinControl; override;
|
||||
procedure UpdateData; override;
|
||||
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 declarations }
|
||||
constructor Create(TheOwner: TComponent); override;
|
||||
@ -193,6 +196,22 @@ begin
|
||||
inherited UpdateData;
|
||||
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);
|
||||
begin
|
||||
inherited Create(TheOwner);
|
||||
|
@ -46,6 +46,7 @@ type
|
||||
constructor Create;
|
||||
destructor Destroy; override;
|
||||
function Editor(aGrid: TDBGrid; aMaxLength: integer = 0): TStringCellEditor;
|
||||
function CanDefocus: boolean;
|
||||
end;
|
||||
|
||||
{ TJDbGridDateTimeCtrl }
|
||||
@ -71,6 +72,7 @@ type
|
||||
constructor Create;
|
||||
destructor Destroy; override;
|
||||
function Editor(aGrid: TDBGrid): TStringCellEditor;
|
||||
function CanDefocus: boolean;
|
||||
end;
|
||||
|
||||
{ TJDbGridTimeCtrl }
|
||||
@ -96,6 +98,7 @@ type
|
||||
constructor Create;
|
||||
destructor Destroy; override;
|
||||
function Editor(aGrid: TDBGrid): TStringCellEditor;
|
||||
function CanDefocus: boolean;
|
||||
end;
|
||||
|
||||
{ TJDbGridDateCtrl }
|
||||
@ -121,6 +124,7 @@ type
|
||||
constructor Create;
|
||||
destructor Destroy; override;
|
||||
function Editor(aGrid: TDBGrid): TStringCellEditor;
|
||||
function CanDefocus: boolean;
|
||||
end;
|
||||
|
||||
{ TJDbGridIntegerCtrl }
|
||||
@ -141,6 +145,7 @@ type
|
||||
constructor Create;
|
||||
destructor Destroy; override;
|
||||
function Editor(aGrid: TDBGrid): TStringCellEditor;
|
||||
function CanDefocus: boolean;
|
||||
end;
|
||||
|
||||
{ TJDbGridDoubleCtrl }
|
||||
@ -166,6 +171,7 @@ type
|
||||
constructor Create;
|
||||
destructor Destroy; override;
|
||||
function Editor(aGrid: TDBGrid; aDecimals: integer = 2): TStringCellEditor;
|
||||
function CanDefocus: boolean;
|
||||
end;
|
||||
|
||||
|
||||
@ -255,6 +261,11 @@ begin
|
||||
Result := CellEditor;
|
||||
end;
|
||||
|
||||
function TJDbGridStringCtrl.CanDefocus: boolean;
|
||||
begin
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
{ TJDbGridDateTimeCtrl }
|
||||
|
||||
function TJDbGridDateTimeCtrl.getFormat: string;
|
||||
@ -296,7 +307,8 @@ begin
|
||||
if (not updated) then
|
||||
begin
|
||||
theValue := StrToDateTime(CellEditor.Caption);
|
||||
if FormatDateTime(DisplayFormat, theValue) <> FormatDateTime(DisplayFormat, Field.AsDateTime) then
|
||||
if FormatDateTime(DisplayFormat, theValue) <>
|
||||
FormatDateTime(DisplayFormat, Field.AsDateTime) then
|
||||
begin
|
||||
Field.DataSet.DisableControls;
|
||||
Field.DataSet.Edit;
|
||||
@ -416,6 +428,18 @@ begin
|
||||
Result := CellEditor;
|
||||
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 }
|
||||
|
||||
function TJDbGridTimeCtrl.getFormat: string;
|
||||
@ -457,7 +481,8 @@ begin
|
||||
if (not updated) then
|
||||
begin
|
||||
theValue := StrToTime(CellEditor.Caption);
|
||||
if FormatDateTime(DisplayFormat, theValue) <> FormatDateTime(DisplayFormat, Field.AsDateTime) then
|
||||
if FormatDateTime(DisplayFormat, theValue) <>
|
||||
FormatDateTime(DisplayFormat, Field.AsDateTime) then
|
||||
begin
|
||||
Field.DataSet.DisableControls;
|
||||
Field.DataSet.Edit;
|
||||
@ -575,6 +600,18 @@ begin
|
||||
Result := CellEditor;
|
||||
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 }
|
||||
|
||||
function TJDbGridDateCtrl.getFormat: string;
|
||||
@ -616,7 +653,8 @@ begin
|
||||
if (not updated) then
|
||||
begin
|
||||
theValue := StrToDate(CellEditor.Caption);
|
||||
if FormatDateTime(DisplayFormat, theValue) <> FormatDateTime(DisplayFormat, Field.AsDateTime) then
|
||||
if FormatDateTime(DisplayFormat, theValue) <>
|
||||
FormatDateTime(DisplayFormat, Field.AsDateTime) then
|
||||
begin
|
||||
Field.DataSet.DisableControls;
|
||||
Field.DataSet.Edit;
|
||||
@ -736,6 +774,18 @@ begin
|
||||
Result := CellEditor;
|
||||
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 }
|
||||
|
||||
function TJDbGridDoubleCtrl.getDecimals: integer;
|
||||
@ -816,7 +866,6 @@ begin
|
||||
CellEditor.Text := ''
|
||||
else
|
||||
CellEditor.Text := FloatToStr(Field.AsFloat);
|
||||
//CellEditor.Text := CurrToStr(redondear(Field.AsCurrency, fDecimals));
|
||||
updated := True;
|
||||
theGrid.SetFocus; // No perder el foco
|
||||
end
|
||||
@ -880,6 +929,14 @@ begin
|
||||
Result := CellEditor;
|
||||
end;
|
||||
|
||||
function TJDbGridDoubleCtrl.CanDefocus: boolean;
|
||||
begin
|
||||
if CellEditor.Focused then
|
||||
Result := IsValidFloat(CellEditor.Text)
|
||||
else
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
{ TJDbGridIntegerCtrl }
|
||||
|
||||
procedure TJDbGridIntegerCtrl.myEditOnEnter(Sender: TObject);
|
||||
@ -993,5 +1050,13 @@ begin
|
||||
Result := CellEditor;
|
||||
end;
|
||||
|
||||
function TJDbGridIntegerCtrl.CanDefocus: boolean;
|
||||
begin
|
||||
if CellEditor.Focused then
|
||||
Result := IsValidInteger(CellEditor.Text)
|
||||
else
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user