fpspreadsheet: Add new cell action TsCellProtectionAction.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5812 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2017-03-19 12:38:17 +00:00
parent 203d1907c8
commit a9f7b4fc20
3 changed files with 71 additions and 7 deletions

View File

@ -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;

View File

@ -2010,11 +2010,17 @@ 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 <> '') then begin
if hideformula then
s := '(Formula hidden)'
else
if s[1] <> '=' then s := '=' + s;
Lines.Text := s;
end else
@ -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

View File

@ -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}