spready: Minor improvements of worksheet protection. Add information on required packages to readme.txt.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5816 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2017-03-21 17:43:24 +00:00
parent b736103903
commit cfc27bc84b
5 changed files with 24 additions and 34 deletions

View File

@ -1,2 +1,7 @@
spready is a relatively complex demonstration of the fpspreadsheet library spready is a relatively complex demonstration of the fpspreadsheet library
and its visual controls. and its visual controls.
Requirements:
- fpspreadsheet trunk version (packages laz_fpspreadsheet,
laz_fpspreadsheet_visual and laz_fpspreadsheet_crypto)
- dcpcrypt (needed for laz_fpspreadsheet_crypto)

View File

@ -1901,7 +1901,7 @@ object MainForm: TMainForm
end end
object AcWorksheetProtection: TAction object AcWorksheetProtection: TAction
Category = 'Worksheet' Category = 'Worksheet'
Caption = 'Protect worksheet...' Caption = 'Worksheet protection...'
ImageIndex = 73 ImageIndex = 73
OnExecute = AcWorksheetProtectionExecute OnExecute = AcWorksheetProtectionExecute
OnUpdate = AcWorksheetProtectionUpdate OnUpdate = AcWorksheetProtectionUpdate

View File

@ -882,14 +882,10 @@ end;
procedure TMainForm.AcWorksheetProtectionExecute(Sender: TObject); procedure TMainForm.AcWorksheetProtectionExecute(Sender: TObject);
var var
F: TWorksheetProtectionForm; F: TWorksheetProtectionForm;
begin
if WorkbookSource.Worksheet.IsProtected then
WorkbookSource.Worksheet.Protect(false)
else
begin begin
F := TWorksheetProtectionForm.Create(nil); F := TWorksheetProtectionForm.Create(nil);
try try
F.IsProtected := WorkbookSource.Worksheet.IsProtected; F.IsProtected := not WorkbookSource.Worksheet.IsProtected;
F.Protection := WorkbookSource.Worksheet.Protection; F.Protection := WorkbookSource.Worksheet.Protection;
if F.ShowModal = mrOK then if F.ShowModal = mrOK then
begin begin
@ -900,7 +896,6 @@ begin
F.Free; F.Free;
end; end;
end; end;
end;
procedure TMainForm.AcWorksheetProtectionUpdate(Sender: TObject); procedure TMainForm.AcWorksheetProtectionUpdate(Sender: TObject);
begin begin

View File

@ -37,7 +37,6 @@ object WorksheetProtectionForm: TWorksheetProtectionForm
BorderSpacing.Top = 8 BorderSpacing.Top = 8
BorderSpacing.Bottom = 8 BorderSpacing.Bottom = 8
Caption = 'Protect worksheet and locked cells' Caption = 'Protect worksheet and locked cells'
OnChange = CbProtectChange
TabOrder = 1 TabOrder = 1
end end
object LblProtectionItems: TLabel object LblProtectionItems: TLabel

View File

@ -20,7 +20,6 @@ type
CbSelectUnlockedCells: TCheckBox; CbSelectUnlockedCells: TCheckBox;
LblProtectionItems: TLabel; LblProtectionItems: TLabel;
ItemsPanel: TPanel; ItemsPanel: TPanel;
procedure CbProtectChange(Sender: TObject);
procedure FormCreate(Sender: TObject); procedure FormCreate(Sender: TObject);
private private
function GetProtected: Boolean; function GetProtected: Boolean;
@ -40,16 +39,6 @@ implementation
{$R *.lfm} {$R *.lfm}
procedure TWorksheetProtectionForm.CbProtectChange(Sender: TObject);
var
unlocked: Boolean;
begin
unlocked := not IsProtected;
LblProtectionItems.Enabled := unlocked;
CbSelectLockedCells.Enabled := unlocked;
CbSelectUnlockedCells.Enabled := unlocked;
end;
procedure TWorksheetProtectionForm.FormCreate(Sender: TObject); procedure TWorksheetProtectionForm.FormCreate(Sender: TObject);
begin begin
Constraints.MinHeight := ItemsPanel.Height + CbProtect.Height + Constraints.MinHeight := ItemsPanel.Height + CbProtect.Height +
@ -64,12 +53,14 @@ end;
function TWorksheetProtectionForm.GetProtections: TsWorksheetProtections; function TWorksheetProtectionForm.GetProtections: TsWorksheetProtections;
begin begin
Result := DEFAULT_SHEET_PROTECTION; Result := DEFAULT_SHEET_PROTECTION;
// NOTE: There's negative logic - if an option is checked it is ALLOWED, but
// the set of protections contains the items which are FORBIDDEN.
if CbSelectLockedCells.Checked then if CbSelectLockedCells.Checked then
Include(Result, spSelectLockedCells) else Exclude(Result, spSelectLockedCells) else
Exclude(Result, spSelectLockedCells); Include(Result, spSelectLockedCells);
if CbSelectUnlockedCells.Checked then if CbSelectUnlockedCells.Checked then
Include(Result, spSelectUnlockedCells) else Exclude(Result, spSelectUnlockedCells) else
Exclude(Result, spSelectUnlockedCells); Include(Result, spSelectUnlockedCells);
end; end;
procedure TWorksheetProtectionForm.SetProtected(AValue: Boolean); procedure TWorksheetProtectionForm.SetProtected(AValue: Boolean);
@ -79,8 +70,8 @@ end;
procedure TWorksheetProtectionForm.SetProtections(AValue: TsWorksheetProtections); procedure TWorksheetProtectionForm.SetProtections(AValue: TsWorksheetProtections);
begin begin
CbSelectLockedCells.Checked := spSelectLockedCells in AValue; CbSelectLockedCells.Checked := not (spSelectLockedCells in AValue);
CbSelectUnlockedCells.Checked := spSelectUnlockedCells in AValue; CbSelectUnlockedCells.Checked := not (spSelectUnlockedCells in AValue);
end; end;
end. end.