You've already forked lazarus-ccr
fpspreadsheet: Improved in-place editor of the TsSpreadsheetGrid
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@3742 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -56,6 +56,7 @@ type
|
|||||||
FReadFormulas: Boolean;
|
FReadFormulas: Boolean;
|
||||||
FDrawingCell: PCell;
|
FDrawingCell: PCell;
|
||||||
FTextOverflowing: Boolean;
|
FTextOverflowing: Boolean;
|
||||||
|
FEnhEditMode: Boolean;
|
||||||
function CalcAutoRowHeight(ARow: Integer): Integer;
|
function CalcAutoRowHeight(ARow: Integer): Integer;
|
||||||
function CalcColWidth(AWidth: Single): Integer;
|
function CalcColWidth(AWidth: Single): Integer;
|
||||||
function CalcRowHeight(AHeight: Single): Integer;
|
function CalcRowHeight(AHeight: Single): Integer;
|
||||||
@ -1864,12 +1865,16 @@ begin
|
|||||||
if oldText <> FEditText then
|
if oldText <> FEditText then
|
||||||
begin
|
begin
|
||||||
cell := Worksheet.GetCell(Row-FHeaderCount, Col-FHeaderCount);
|
cell := Worksheet.GetCell(Row-FHeaderCount, Col-FHeaderCount);
|
||||||
|
if (FEditText <> '') and (FEditText[1] = '=') then
|
||||||
|
Worksheet.WriteFormula(cell, Copy(FEditText, 2, Length(FEditText)), true)
|
||||||
|
else
|
||||||
Worksheet.WriteCellValueAsString(cell, FEditText);
|
Worksheet.WriteCellValueAsString(cell, FEditText);
|
||||||
FEditText := '';
|
FEditText := '';
|
||||||
end;
|
end;
|
||||||
inherited EditingDone;
|
inherited EditingDone;
|
||||||
end;
|
end;
|
||||||
FEditing := false;
|
FEditing := false;
|
||||||
|
FEnhEditMode := false;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{@@ ----------------------------------------------------------------------------
|
{@@ ----------------------------------------------------------------------------
|
||||||
@ -2399,8 +2404,30 @@ end;
|
|||||||
@param ARow Grid row index of the grid cell being edited
|
@param ARow Grid row index of the grid cell being edited
|
||||||
@return Text to be passed to the cell editor.
|
@return Text to be passed to the cell editor.
|
||||||
-------------------------------------------------------------------------------}
|
-------------------------------------------------------------------------------}
|
||||||
function TsCustomWorksheetGrid.GetEditText(aCol, aRow: Integer): string;
|
function TsCustomWorksheetGrid.GetEditText(ACol, ARow: Integer): string;
|
||||||
|
var
|
||||||
|
cell: PCell;
|
||||||
begin
|
begin
|
||||||
|
if FEnhEditMode then // Initiated by "F2"
|
||||||
|
begin
|
||||||
|
cell := Worksheet.FindCell(GetWorksheetRow(ARow), GetWorksheetCol(ACol));
|
||||||
|
Result := Worksheet.ReadFormulaAsString(cell, true);
|
||||||
|
if Result <> '' then
|
||||||
|
begin
|
||||||
|
if Result[1] <> '=' then Result := '=' + Result;
|
||||||
|
end else
|
||||||
|
case cell^.ContentType of
|
||||||
|
cctNumber:
|
||||||
|
Result := FloatToStr(cell^.NumberValue);
|
||||||
|
cctDateTime:
|
||||||
|
if cell^.DateTimeValue < 1.0 then
|
||||||
|
Result := FormatDateTime('tt', cell^.DateTimeValue)
|
||||||
|
else
|
||||||
|
Result := FormatDateTime('c', cell^.DateTimeValue);
|
||||||
|
else
|
||||||
|
Result := Worksheet.ReadAsUTF8Text(cell);
|
||||||
|
end;
|
||||||
|
end else
|
||||||
Result := GetCellText(aCol, aRow);
|
Result := GetCellText(aCol, aRow);
|
||||||
if Assigned(OnGetEditText) then OnGetEditText(Self, aCol, aRow, result);
|
if Assigned(OnGetEditText) then OnGetEditText(Self, aCol, aRow, result);
|
||||||
end;
|
end;
|
||||||
@ -2864,6 +2891,9 @@ end;
|
|||||||
-------------------------------------------------------------------------------}
|
-------------------------------------------------------------------------------}
|
||||||
procedure TsCustomWorksheetGrid.KeyDown(var Key : Word; Shift : TShiftState);
|
procedure TsCustomWorksheetGrid.KeyDown(var Key : Word; Shift : TShiftState);
|
||||||
begin
|
begin
|
||||||
|
if (Key = VK_F2) then
|
||||||
|
FEnhEditMode := true
|
||||||
|
else
|
||||||
if (Key = VK_ESCAPE) and FEditing then begin
|
if (Key = VK_ESCAPE) and FEditing then begin
|
||||||
SetEditText(Col, Row, FOldEditText);
|
SetEditText(Col, Row, FOldEditText);
|
||||||
EditorHide;
|
EditorHide;
|
||||||
|
Reference in New Issue
Block a user