From 203d1907c8e7fe8fdcdffaddd9e664a3e507d149 Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Sat, 18 Mar 2017 22:43:13 +0000 Subject: [PATCH] fpspreadsheet: WorksheetGrid and CellEditor respect worksheet and cell protection git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5811 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- .../source/visual/fpspreadsheetctrls.pas | 4 ++++ .../source/visual/fpspreadsheetgrid.pas | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/components/fpspreadsheet/source/visual/fpspreadsheetctrls.pas b/components/fpspreadsheet/source/visual/fpspreadsheetctrls.pas index 31a028c6c..7c47f007d 100644 --- a/components/fpspreadsheet/source/visual/fpspreadsheetctrls.pas +++ b/components/fpspreadsheet/source/visual/fpspreadsheetctrls.pas @@ -2042,7 +2042,11 @@ begin end; end else Clear; + FOldText := Lines.Text; + + ReadOnly := Worksheet.IsProtected and + (cpLockCell in Worksheet.ReadCellProtection(ACell)); end; diff --git a/components/fpspreadsheet/source/visual/fpspreadsheetgrid.pas b/components/fpspreadsheet/source/visual/fpspreadsheetgrid.pas index e9da7cc06..3bcf45e53 100644 --- a/components/fpspreadsheet/source/visual/fpspreadsheetgrid.pas +++ b/components/fpspreadsheet/source/visual/fpspreadsheetgrid.pas @@ -91,6 +91,7 @@ type FRowHeightLock: Integer; FActiveCellLock: Integer; FTopLeft: TPoint; + FReadOnly: Boolean; FOnClickHyperlink: TsHyperlinkClickEvent; function CalcAutoRowHeight(ARow: Integer): Integer; function CalcColWidthFromSheet(AWidth: Single): Integer; @@ -206,6 +207,7 @@ type function CalcTopLeft(AHeaderOnly: Boolean): TPoint; function CalcWorksheetColWidth(AValue: Integer): Single; function CalcWorksheetRowHeight(AValue: Integer): Single; + function CanEditShow: boolean; override; function CellOverflow(ACol, ARow: Integer; AState: TGridDrawState; out ACol1, ACol2: Integer; var ARect: TRect): Boolean; procedure ColRowMoved(IsColumn: Boolean; FromIndex,ToIndex: Integer); override; @@ -1356,6 +1358,10 @@ begin end; end; +function TsCustomWorksheetGrid.CanEditShow: Boolean; +begin + Result := inherited and (not FReadOnly); +end; {@@ ---------------------------------------------------------------------------- Looks for overflowing cells: if the text of the given cell is longer than @@ -4488,6 +4494,12 @@ begin AutoExpandToCol(gcol, aeNavigation); if (grow <> Row) or (gcol <> Col) then MoveExtend(false, gcol, grow); + if Worksheet.IsProtected then + begin + cell := Worksheet.FindCell(Worksheet.ActiveCellRow, Worksheet.ActiveCellCol); + FReadOnly := (cell = nil) or (cpLockCell in Worksheet.ReadCellProtection(cell)); + end else + FReadOnly := false; end; // Abort selection because of an error