From f62d2b35d75d4d9b1dd0e5b68a2165defdc6ce27 Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Wed, 13 Jun 2018 09:20:10 +0000 Subject: [PATCH] fpspreadsheet: Add TsClearFormatAction to clear a cell format. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@6492 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- .../source/common/fpspreadsheet.pas | 5 +++++ .../source/design/fpsvisualreg.pas | 1 + .../fpspreadsheet/source/visual/fpsactions.pas | 18 ++++++++++++++++++ 3 files changed, 24 insertions(+) diff --git a/components/fpspreadsheet/source/common/fpspreadsheet.pas b/components/fpspreadsheet/source/common/fpspreadsheet.pas index 9944d0a72..a32ba7b97 100644 --- a/components/fpspreadsheet/source/common/fpspreadsheet.pas +++ b/components/fpspreadsheet/source/common/fpspreadsheet.pas @@ -9255,6 +9255,11 @@ end; -------------------------------------------------------------------------------} function TsWorkbook.GetPointerToCellFormat(AIndex: Integer): PsCellFormat; begin + if FCellFormatList.Count = 0 then + raise Exception.Create('[TsWorkbook.GetPointerToCellFormat]: No format items.'); + + if (AIndex < 0) or (AIndex >= FCellFormatList.Count) then + AIndex := 0; // 0 is default format Result := FCellFormatList.Items[AIndex]; end; diff --git a/components/fpspreadsheet/source/design/fpsvisualreg.pas b/components/fpspreadsheet/source/design/fpsvisualreg.pas index de8e96156..e7af09da3 100644 --- a/components/fpspreadsheet/source/design/fpsvisualreg.pas +++ b/components/fpspreadsheet/source/design/fpsvisualreg.pas @@ -42,6 +42,7 @@ begin TsWorksheetZoomAction, // Cell or cell range formatting actions TsCopyAction, + TsClearFormatAction, TsFontStyleAction, TsFontDialogAction, TsBackgroundColorDialogAction, TsHorAlignmentAction, TsVertAlignmentAction, TsTextRotationAction, TsWordWrapAction, diff --git a/components/fpspreadsheet/source/visual/fpsactions.pas b/components/fpspreadsheet/source/visual/fpsactions.pas index 286f96b45..001cd117c 100644 --- a/components/fpspreadsheet/source/visual/fpsactions.pas +++ b/components/fpspreadsheet/source/visual/fpsactions.pas @@ -180,6 +180,12 @@ type property Visible; end; + { TsClearFormatAction } + TsClearFormatAction = class(TsAutoFormatAction) + protected + procedure ApplyFormatToCell(ACell: PCell); override; + end; + { TsFontStyleAction } TsFontStyleAction = class(TsAutoFormatAction) private @@ -928,6 +934,18 @@ begin end; +{ TsClearFormatAction } + +procedure TsClearFormatAction.ApplyFormatToCell(ACell: PCell); +begin + if ACell <> nil then + begin + ACell^.FormatIndex := 0; // Default format + Worksheet.ChangedCell(ACell^.Row, ACell^.Col); + end; +end; + + { TsFontStyleAction } constructor TsFontStyleAction.Create(AOwner: TComponent);