You've already forked lazarus-ccr
fpspreadsheet: Fix inconsistent built-in worksheetgrid cell editor or TsCellEdit selection behavior in the case of an error in edited formula.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@6530 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -243,6 +243,7 @@ type
|
|||||||
FFormulaError: Boolean;
|
FFormulaError: Boolean;
|
||||||
FRefocusing: TObject;
|
FRefocusing: TObject;
|
||||||
FRefocusingCol, FRefocusingRow: Cardinal;
|
FRefocusingCol, FRefocusingRow: Cardinal;
|
||||||
|
FRefocusingSelStart: Integer;
|
||||||
function GetSelectedCell: PCell;
|
function GetSelectedCell: PCell;
|
||||||
function GetWorkbook: TsWorkbook;
|
function GetWorkbook: TsWorkbook;
|
||||||
function GetWorksheet: TsWorksheet;
|
function GetWorksheet: TsWorksheet;
|
||||||
@ -1934,6 +1935,7 @@ begin
|
|||||||
// ... as well as currently selected cell.
|
// ... as well as currently selected cell.
|
||||||
FRefocusingRow := Worksheet.ActiveCellRow;
|
FRefocusingRow := Worksheet.ActiveCellRow;
|
||||||
FRefocusingCol := Worksheet.ActiveCellCol;
|
FRefocusingCol := Worksheet.ActiveCellCol;
|
||||||
|
FRefocusingSelStart := SelStart;
|
||||||
// Initiate validation of current input
|
// Initiate validation of current input
|
||||||
PostMessage(Handle, UM_VALIDATEINPUT, 0, LParam(Self));
|
PostMessage(Handle, UM_VALIDATEINPUT, 0, LParam(Self));
|
||||||
end;
|
end;
|
||||||
@ -1953,7 +1955,7 @@ begin
|
|||||||
if not Result then begin
|
if not Result then begin
|
||||||
Worksheet.SelectCell(FRefocusingRow, FRefocusingCol);
|
Worksheet.SelectCell(FRefocusingRow, FRefocusingCol);
|
||||||
Text := AText; // restore orig text lost by interaction with grid
|
Text := AText; // restore orig text lost by interaction with grid
|
||||||
SelectAll;
|
SelStart := FRefocusingSelStart;
|
||||||
MessageDlg(err, mtError, [mbOK], 0);
|
MessageDlg(err, mtError, [mbOK], 0);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
@ -152,6 +152,8 @@ type
|
|||||||
FGetRowHeaderText: TsGetCellTextEvent;
|
FGetRowHeaderText: TsGetCellTextEvent;
|
||||||
FGetColHeaderText: TsGetCellTextEvent;
|
FGetColHeaderText: TsGetCellTextEvent;
|
||||||
FRefocusing: TObject;
|
FRefocusing: TObject;
|
||||||
|
FRefocusingSelStart: Integer;
|
||||||
|
FFormulaError: Boolean;
|
||||||
function CalcAutoRowHeight(ARow: Integer): Integer;
|
function CalcAutoRowHeight(ARow: Integer): Integer;
|
||||||
function CalcColWidthFromSheet(AWidth: Single): Integer;
|
function CalcColWidthFromSheet(AWidth: Single): Integer;
|
||||||
function CalcRowHeightFromSheet(AHeight: Single): Integer;
|
function CalcRowHeightFromSheet(AHeight: Single): Integer;
|
||||||
@ -324,6 +326,7 @@ type
|
|||||||
AOverrideTextColor: TColor; ARichTextParams: TsRichTextParams;
|
AOverrideTextColor: TColor; ARichTextParams: TsRichTextParams;
|
||||||
AIsRightToLeft: Boolean);
|
AIsRightToLeft: Boolean);
|
||||||
procedure KeyDown(var Key : Word; Shift : TShiftState); override;
|
procedure KeyDown(var Key : Word; Shift : TShiftState); override;
|
||||||
|
procedure KeyUp(var Key : Word; Shift : TShiftState); override;
|
||||||
procedure MouseDown(Button: TMouseButton; Shift:TShiftState; X,Y:Integer); override;
|
procedure MouseDown(Button: TMouseButton; Shift:TShiftState; X,Y:Integer); override;
|
||||||
procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
|
procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
|
||||||
function MouseOnCellBorder(const APoint: TPoint;
|
function MouseOnCellBorder(const APoint: TPoint;
|
||||||
@ -2286,11 +2289,17 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TsCustomWorksheetGrid.DoExit;
|
procedure TsCustomWorksheetGrid.DoExit;
|
||||||
|
var
|
||||||
|
ed: TWinControl;
|
||||||
begin
|
begin
|
||||||
{ Post a message to myself which indicates it's time to validate the input.
|
{ Post a message to myself which indicates it's time to validate the input.
|
||||||
Pass the grid instance (Self) as the message lParam. }
|
Pass the grid instance (Self) as the message lParam. }
|
||||||
if FRefocusing = nil then
|
if FRefocusing = nil then begin
|
||||||
|
ed := EditorByStyle(cbsAuto);
|
||||||
|
if ed is TCustomEdit then
|
||||||
|
FRefocusingSelStart := TCustomEdit(ed).SelStart;
|
||||||
PostMessage(Handle, um_ValidateInput, 0, LParam(Self));
|
PostMessage(Handle, um_ValidateInput, 0, LParam(Self));
|
||||||
|
end;
|
||||||
FGridState := gsNormal;
|
FGridState := gsNormal;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -3562,13 +3571,6 @@ end;
|
|||||||
|
|
||||||
function TsCustomWorksheetGrid.EditorByStyle(Style: TColumnButtonStyle): TWinControl;
|
function TsCustomWorksheetGrid.EditorByStyle(Style: TColumnButtonStyle): TWinControl;
|
||||||
begin
|
begin
|
||||||
(*
|
|
||||||
if (Style = cbsAuto) then
|
|
||||||
case FLineMode of
|
|
||||||
elmSingleLine : Result := FSingleLineStringEditor;
|
|
||||||
elmMultiLine : Result := FMultiLineStringEditor ;
|
|
||||||
end
|
|
||||||
*)
|
|
||||||
if (Style = cbsAuto) and (FLineMode = elmMultiLine) then
|
if (Style = cbsAuto) and (FLineMode = elmMultiLine) then
|
||||||
Result := FMultiLineStringEditor
|
Result := FMultiLineStringEditor
|
||||||
else
|
else
|
||||||
@ -4936,6 +4938,7 @@ var
|
|||||||
R: TRect;
|
R: TRect;
|
||||||
msg: String;
|
msg: String;
|
||||||
begin
|
begin
|
||||||
|
FFormulaError := false;
|
||||||
// Check validity for formula before navigating to another cell.
|
// Check validity for formula before navigating to another cell.
|
||||||
case Key of
|
case Key of
|
||||||
VK_RETURN,
|
VK_RETURN,
|
||||||
@ -4945,6 +4948,7 @@ begin
|
|||||||
VK_PRIOR, VK_NEXT,
|
VK_PRIOR, VK_NEXT,
|
||||||
VK_END, VK_HOME:
|
VK_END, VK_HOME:
|
||||||
if not ValidFormula(FEditText, msg) then begin
|
if not ValidFormula(FEditText, msg) then begin
|
||||||
|
FFormulaError := true;
|
||||||
MessageDlg(msg, mtError, [mbOK], 0);
|
MessageDlg(msg, mtError, [mbOK], 0);
|
||||||
Key := 0;
|
Key := 0;
|
||||||
end;
|
end;
|
||||||
@ -4983,6 +4987,14 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TsCustomWorksheetGrid.KeyUp(var Key : Word; Shift : TShiftState);
|
||||||
|
begin
|
||||||
|
if FFormulaError and (Key = VK_RETURN) then
|
||||||
|
Key := 0;
|
||||||
|
inherited;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
(*
|
(*
|
||||||
{@@ ----------------------------------------------------------------------------
|
{@@ ----------------------------------------------------------------------------
|
||||||
Loads the worksheet into the grid and displays its contents.
|
Loads the worksheet into the grid and displays its contents.
|
||||||
@ -7321,6 +7333,7 @@ procedure TsCustomWorksheetGrid.ValidateInput(var Msg: TLMessage);
|
|||||||
var
|
var
|
||||||
grid: TsCustomWorksheetGrid;
|
grid: TsCustomWorksheetGrid;
|
||||||
errmsg: String;
|
errmsg: String;
|
||||||
|
ed: TWinControl;
|
||||||
begin
|
begin
|
||||||
if TObject(Msg.lParam) is TsCustomWorksheetGrid then begin
|
if TObject(Msg.lParam) is TsCustomWorksheetGrid then begin
|
||||||
grid := TsCustomWorksheetGrid(Msg.lParam);
|
grid := TsCustomWorksheetGrid(Msg.lParam);
|
||||||
@ -7328,6 +7341,10 @@ begin
|
|||||||
MessageDlg(errmsg, mtError, [mbOK], 0);
|
MessageDlg(errmsg, mtError, [mbOK], 0);
|
||||||
FRefocusing := grid; // Avoid an endless loop
|
FRefocusing := grid; // Avoid an endless loop
|
||||||
grid.SetFocus; // Set focus back
|
grid.SetFocus; // Set focus back
|
||||||
|
if grid.EditorMode then begin
|
||||||
|
ed := grid.EditorByStyle(cbsAuto);
|
||||||
|
if ed is TCustomEdit then TCustomEdit(ed).SelStart := FRefocusingSelStart;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
Reference in New Issue
Block a user