From b9df429d5bb26fa36cd68b76841ade4fd85dd7ba Mon Sep 17 00:00:00 2001 From: jujibo Date: Wed, 21 May 2014 09:58:26 +0000 Subject: [PATCH] Fix: Editing while mouse events git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@3071 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- components/jujiboutils/src/jdbgridcontrol.pas | 2 +- components/jujiboutils/src/jdbgridutils.pas | 36 +++++++++++++------ 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/components/jujiboutils/src/jdbgridcontrol.pas b/components/jujiboutils/src/jdbgridcontrol.pas index 64200c904..0e1b3871d 100644 --- a/components/jujiboutils/src/jdbgridcontrol.pas +++ b/components/jujiboutils/src/jdbgridcontrol.pas @@ -205,7 +205,7 @@ end; procedure TJDBGridControl.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: integer); begin - if (Button = mbLeft) and not (integerDbGridControl.CanDefocus and + if not (integerDbGridControl.CanDefocus and doubleDbGridControl.CanDefocus and dateTimeDbGridControl.CanDefocus and stringDbGridControl.CanDefocus and dateDbGridControl.CanDefocus and timeDbGridControl.CanDefocus) then diff --git a/components/jujiboutils/src/jdbgridutils.pas b/components/jujiboutils/src/jdbgridutils.pas index ca51d27e8..297e988f3 100644 --- a/components/jujiboutils/src/jdbgridutils.pas +++ b/components/jujiboutils/src/jdbgridutils.pas @@ -233,6 +233,7 @@ begin Field.DataSet.Edit; Field.AsString := CellEditor.Text; field.DataSet.EnableControls; + updated := True; end; end; end; @@ -293,7 +294,11 @@ end; function TJDbGridStringCtrl.CanDefocus: boolean; begin Result := True; - myEditOnEditingDone(nil); + if not CellEditor.Focused then + exit; + if Result and Assigned(Field) and Assigned(Field.Dataset) and + (Field.DataSet.State in dsEditModes) then + myEditOnEditingDone(nil); end; { TJDbGridDateTimeCtrl } @@ -361,6 +366,7 @@ begin Field.DataSet.Edit; Field.AsDateTime := theValue; Field.DataSet.EnableControls; + updated := True; end; end; end @@ -531,8 +537,9 @@ begin begin ShowMessage(Format(SInvalidDateTime, [CellEditor.Text])); CellEditor.Text := EditText; - end - else + end; + if Result and Assigned(Field) and Assigned(Field.Dataset) and + (Field.DataSet.State in dsEditModes) then myEditOnEditingDone(nil); end; @@ -592,6 +599,7 @@ begin Field.DataSet.Edit; Field.Text := NormalizeTime(CellEditor.Caption, Field.AsDateTime); Field.DataSet.EnableControls; + updated := True; end; end; end @@ -723,8 +731,9 @@ begin begin ShowMessage(Format(SInvalidTime, [CellEditor.Text])); CellEditor.Text := Field.AsString; - end - else + end; + if Result and Assigned(Field) and Assigned(Field.Dataset) and + (Field.DataSet.State in dsEditModes) then myEditOnEditingDone(nil); end; @@ -784,6 +793,7 @@ begin Field.DataSet.Edit; Field.AsDateTime := theValue; field.DataSet.EnableControls; + updated := True; end; end; end @@ -954,8 +964,9 @@ begin begin ShowMessage(Format(SInvalidDate, [CellEditor.Text])); CellEditor.Text := Field.AsString; - end - else + end; + if Result and Assigned(Field) and Assigned(Field.Dataset) and + (Field.DataSet.State in dsEditModes) then myEditOnEditingDone(nil); end; @@ -1004,6 +1015,7 @@ begin theValue := ScaleTo(theValue, fDecimals); Field.Value := theValue; Field.DataSet.EnableControls; + updated := True; end; end; end @@ -1130,8 +1142,9 @@ begin CellEditor.Text := FormatFloat(fEFormat, Field.AsFloat) else CellEditor.Text := Field.AsString; - end - else + end; + if Result and Assigned(Field) and Assigned(Field.Dataset) and + (Field.DataSet.State in dsEditModes) then myEditOnEditingDone(nil); end; @@ -1264,8 +1277,9 @@ begin begin ShowMessage(Format(SInvalidNumber, [CellEditor.Text])); CellEditor.Text := Field.AsString; - end - else + end; + if Result and Assigned(Field) and Assigned(Field.Dataset) and + (Field.DataSet.State in dsEditModes) then myEditOnEditingDone(nil); end;