diff --git a/components/fpspreadsheet/source/visual/fpsactions.pas b/components/fpspreadsheet/source/visual/fpsactions.pas index 208e90d15..1a771e04c 100644 --- a/components/fpspreadsheet/source/visual/fpsactions.pas +++ b/components/fpspreadsheet/source/visual/fpsactions.pas @@ -107,7 +107,7 @@ type end; { Action foz zooming the selected worksheet } - TsWorksheetZoomAction= class(TsWorksheetAction) + TsWorksheetZoomAction = class(TsWorksheetAction) private FZoom: Integer; procedure SetZoom(AValue: Integer); @@ -286,6 +286,21 @@ type property Hint stored false; end; + { TsCellProtectionAction } + TsCellProtectionAction = class(TsAutoFormatAction) + private + FProtection: TsCellProtection; + protected + procedure ApplyFormatToCell(ACell: PCell); override; + procedure ExtractFromCell(ACell: PCell); override; + public + constructor Create(AOwner: TComponent); override; + procedure UpdateTarget(Target: TObject); override; + published + property AutoCheck default true; + property Protection: TsCellProtection read FProtection write FProtection default cpLockCell; + end; + { TsCellBorderAction } TsActionBorder = class(TPersistent) private @@ -555,6 +570,7 @@ begin TsHorAlignmentAction, TsVertAlignmentAction, TsTextRotationAction, TsWordWrapAction, TsNumberFormatAction, TsDecimalsAction, + TsCellProtectionAction, TsCellBorderAction, TsNoCellBordersAction, TsCellCommentAction, TsCellHyperlinkAction, TsMergeAction @@ -1167,6 +1183,48 @@ begin end; +{ TsCellProtectionAction } + +constructor TsCellProtectionAction.Create(AOwner: TComponent); +begin + inherited; + AutoCheck := true; +end; + +procedure TsCellProtectionAction.ApplyFormatToCell(ACell: PCell); +var + p: TsCellProtections; +begin + if not (Worksheet.IsProtected and (spCells in Worksheet.Protection)) then + exit; + + p := Worksheet.ReadCellProtection(ACell); + if Checked then + Include(p, FProtection) + else + Exclude(p, FProtection); + Worksheet.WriteCellProtection(ACell, p); +end; + +procedure TsCellProtectionAction.ExtractFromCell(ACell: PCell); +var + p: TsCellProtections; +begin + if ACell = nil then begin + Checked := FProtection = cpLockCell; + exit; + end; + p := Worksheet.ReadCellProtection(ACell); + Checked := FProtection in p; +end; + +procedure TsCellProtectionAction.UpdateTarget(Target: TObject); +begin + inherited; + Enabled := inherited Enabled and Worksheet.IsProtected and (spCells in Worksheet.Protection); +end; + + { TsCellBorderAction } function TsActionBorder.GetStyle: TsCellBorderStyle; diff --git a/components/fpspreadsheet/source/visual/fpspreadsheetctrls.pas b/components/fpspreadsheet/source/visual/fpspreadsheetctrls.pas index 7c47f007d..51b6204ab 100644 --- a/components/fpspreadsheet/source/visual/fpspreadsheetctrls.pas +++ b/components/fpspreadsheet/source/visual/fpspreadsheetctrls.pas @@ -2010,12 +2010,18 @@ end; procedure TsCellEdit.ShowCell(ACell: PCell); var s: String; + hideformula: Boolean; begin if (FWorkbookSource <> nil) and (ACell <> nil) then begin + hideformula := Worksheet.IsProtected and (spCells in Worksheet.Protection) and + (cpHideFormulas in Worksheet.ReadCellProtection(ACell)); s := Worksheet.ReadFormulaAsString(ACell, true); - if s <> '' then begin - if s[1] <> '=' then s := '=' + s; + if (s <> '') then begin + if hideformula then + s := '(Formula hidden)' + else + if s[1] <> '=' then s := '=' + s; Lines.Text := s; end else case ACell^.ContentType of @@ -2045,7 +2051,7 @@ begin FOldText := Lines.Text; - ReadOnly := Worksheet.IsProtected and + ReadOnly := Worksheet.IsProtected and (spCells in Worksheet.Protection) and (cpLockCell in Worksheet.ReadCellProtection(ACell)); end; @@ -3368,7 +3374,7 @@ begin if (AFormatIndex = -1) then AStrings.Add('Protection=(default)') else begin - if Worksheet.IsProtected then begin + if Worksheet.IsProtected and (spCells in Worksheet.Protection) then begin s := ''; for cp in TsCellProtection do if cp in fmt.Protection then diff --git a/components/fpspreadsheet/source/visual/fpspreadsheetgrid.pas b/components/fpspreadsheet/source/visual/fpspreadsheetgrid.pas index 3bcf45e53..dfc9ef923 100644 --- a/components/fpspreadsheet/source/visual/fpspreadsheetgrid.pas +++ b/components/fpspreadsheet/source/visual/fpspreadsheetgrid.pas @@ -575,7 +575,7 @@ type {@@ inherited from ancestors} property Color; {@@ inherited from ancestors} - property ColCount stored; + property ColCount default 27; //stored; //property Columns; {@@ inherited from ancestors} property Constraints; @@ -622,7 +622,7 @@ type {@@ inherited from ancestors} property PopupMenu; {@@ inherited from ancestors} - property RowCount; + property RowCount default 101; {@@ inherited from ancestors} property ScrollBars; {@@ inherited from ancestors}