From 3bd94275ba3d9c5dd47ddb5f57e0554b41c0c84b Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Mon, 17 Nov 2014 22:18:40 +0000 Subject: [PATCH] fpspreadsheet: Fix CopyFormat action. Complete menu of fpsctrls demo. Fix caption and hint assignment in fpspreadsheet standard actions. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@3739 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- .../fpspreadsheet/examples/fpsctrls/main.lfm | 208 +++++++++++++++--- .../fpspreadsheet/examples/fpsctrls/main.pas | 37 ++++ .../examples/fpsctrls_no_install/main.pas | 66 ++++++ components/fpspreadsheet/fpsactions.pas | 180 +-------------- .../fpspreadsheet/fpspreadsheetctrls.pas | 114 +++++++++- .../fpspreadsheet/fpspreadsheetgrid.pas | 7 + 6 files changed, 403 insertions(+), 209 deletions(-) diff --git a/components/fpspreadsheet/examples/fpsctrls/main.lfm b/components/fpspreadsheet/examples/fpsctrls/main.lfm index 776cc4740..1277ab7ad 100644 --- a/components/fpspreadsheet/examples/fpsctrls/main.lfm +++ b/components/fpspreadsheet/examples/fpsctrls/main.lfm @@ -4,15 +4,15 @@ object Form1: TForm1 Top = 214 Width = 922 Caption = 'Form1' - ClientHeight = 575 + ClientHeight = 580 ClientWidth = 922 Menu = MainMenu ShowHint = True LCLVersion = '1.3' object WorkbookTabControl: TsWorkbookTabControl Left = 0 - Height = 490 - Top = 85 + Height = 497 + Top = 83 Width = 669 TabIndex = 0 Tabs.Strings = ( @@ -23,8 +23,8 @@ object Form1: TForm1 WorkbookSource = WorkbookSource object WorksheetGrid: TsWorksheetGrid Left = 2 - Height = 460 - Top = 28 + Height = 472 + Top = 23 Width = 665 FrozenCols = 0 FrozenRows = 0 @@ -78,8 +78,8 @@ object Form1: TForm1 end object InspectorTabControl: TTabControl Left = 674 - Height = 490 - Top = 85 + Height = 497 + Top = 83 Width = 248 OnChange = InspectorTabControlChange TabIndex = 0 @@ -94,8 +94,8 @@ object Form1: TForm1 Visible = False object Inspector: TsSpreadsheetInspector Left = 2 - Height = 460 - Top = 28 + Height = 472 + Top = 23 Width = 244 Align = alClient RowCount = 25 @@ -108,7 +108,7 @@ object Form1: TForm1 'Options=boAutoCalc, boCalcBeforeSaving, boReadFormulas' 'FormatSettings=' ' ThousandSeparator=.' - ' DecimalSeparator=,' + ' DecimalSeparator=.' ' ListSeparator=;' ' DateSeparator=.' ' TimeSeparator=:' @@ -134,22 +134,22 @@ object Form1: TForm1 WorkbookSource = WorkbookSource Mode = imWorkbook ColWidths = ( - 109 - 110 + 111 + 112 ) end end object Splitter1: TSplitter Left = 669 - Height = 490 - Top = 85 + Height = 497 + Top = 83 Width = 5 Align = alRight ResizeAnchor = akRight end object ToolBar1: TToolBar Left = 0 - Height = 28 + Height = 26 Top = 24 Width = 922 AutoSize = True @@ -329,10 +329,10 @@ object Form1: TForm1 end object FontnameCombo: TsFontNameCombobox Left = 54 - Height = 28 + Height = 23 Top = 0 Width = 151 - ItemHeight = 20 + ItemHeight = 15 ItemIndex = 62 Items.Strings = ( '@Arial Unicode MS' @@ -1129,10 +1129,10 @@ object Form1: TForm1 end object sFontSizeCombobox1: TsFontSizeCombobox Left = 205 - Height = 28 + Height = 23 Top = 0 Width = 60 - ItemHeight = 20 + ItemHeight = 15 ItemIndex = 2 Items.Strings = ( '8' @@ -1251,7 +1251,7 @@ object Form1: TForm1 object ToolBar3: TToolBar Left = 0 Height = 28 - Top = 52 + Top = 50 Width = 922 AutoSize = True Caption = 'ToolBar3' @@ -1270,7 +1270,7 @@ object Form1: TForm1 TabOrder = 0 object CellIndicator: TsCellIndicator Left = 0 - Height = 28 + Height = 23 Top = 0 Width = 138 Align = alTop @@ -1281,10 +1281,11 @@ object Form1: TForm1 end object CellEdit: TsCellEdit Left = 144 - Height = 26 + Height = 24 Top = 0 Width = 778 Align = alClient + BorderSpacing.Bottom = 2 TabOrder = 1 WantReturns = False WorkbookSource = WorkbookSource @@ -1300,7 +1301,7 @@ object Form1: TForm1 Cursor = crVSplit Left = 0 Height = 5 - Top = 80 + Top = 78 Width = 922 Align = alTop ResizeAnchor = akTop @@ -1333,7 +1334,7 @@ object Form1: TForm1 object AcDeleteWorksheet: TsWorksheetDeleteAction Category = 'FPSpreadsheet' WorkbookSource = WorkbookSource - Caption = 'Delete' + Caption = 'Delete...' Hint = 'Delete worksheet' ImageIndex = 2 end @@ -1354,7 +1355,7 @@ object Form1: TForm1 Category = 'FPSpreadsheet' WorkbookSource = WorkbookSource Caption = 'Bold' - Hint = 'Bold font' + Hint = 'Bold' ImageIndex = 4 FontStyle = fssBold end @@ -1362,7 +1363,7 @@ object Form1: TForm1 Category = 'FPSpreadsheet' WorkbookSource = WorkbookSource Caption = 'Italic' - Hint = 'Italic font' + Hint = 'Italic' ImageIndex = 5 FontStyle = fssItalic end @@ -1370,7 +1371,7 @@ object Form1: TForm1 Category = 'FPSpreadsheet' WorkbookSource = WorkbookSource Caption = 'Underline' - Hint = 'Underlines font' + Hint = 'Underline' ImageIndex = 6 FontStyle = fssUnderline end @@ -1378,7 +1379,7 @@ object Form1: TForm1 Category = 'FPSpreadsheet' WorkbookSource = WorkbookSource Caption = 'Strikeout' - Hint = 'Strike-out font' + Hint = 'Strikeout' ImageIndex = 7 FontStyle = fssStrikeOut end @@ -1433,14 +1434,14 @@ object Form1: TForm1 object AcWordWrap: TsWordwrapAction Category = 'FPSpreadsheet' WorkbookSource = WorkbookSource - Caption = 'AcWordWrap' + Caption = 'Word-wrap' Hint = 'Word-wrapped text' ImageIndex = 24 end object AcTextRotHor: TsTextRotationAction Category = 'FPSpreadsheet' WorkbookSource = WorkbookSource - Caption = 'AcTextRotHor' + Caption = 'Horizontal text' end object AcTextRot90CW: TsTextRotationAction Category = 'FPSpreadsheet' @@ -1571,19 +1572,21 @@ object Form1: TForm1 object AcIncDecimals: TsDecimalsAction Category = 'FPSpreadsheet' WorkbookSource = WorkbookSource + Caption = 'More decimals' ImageIndex = 21 end object AcDecDecimals: TsDecimalsAction Category = 'FPSpreadsheet' WorkbookSource = WorkbookSource + Caption = 'Less decimals' ImageIndex = 20 Delta = -1 end object AcCellFontDialog: TsFontDialogAction Category = 'FPSpreadsheet' WorkbookSource = WorkbookSource - Caption = 'AcCellFont' - Hint = 'Select cell font' + Caption = 'Cell font...' + Hint = 'Cell font' ImageIndex = 14 Dialog.MinFontSize = 0 Dialog.MaxFontSize = 0 @@ -1591,8 +1594,8 @@ object Form1: TForm1 object AcBackgroundColorDialog: TsBackgroundColorDialogAction Category = 'FPSpreadsheet' WorkbookSource = WorkbookSource - Caption = 'AcBackgroundColor' - Hint = 'Modify background color' + Caption = 'Background color...' + Hint = 'Background color' ImageIndex = 22 Dialog.Color = clBlack Dialog.CustomColors.Strings = ( @@ -2021,7 +2024,7 @@ object Form1: TForm1 Caption = 'Save &as ...' Dialog.Title = 'AcSaveFileAs' Dialog.Filter = 'Excel XML spreadsheet (*.xlsx)|*.xlsx|Excel 97-2003 spreadsheets (*.xls)|*.xls|Excel 5 spreadsheet (*.xls)|*.xls|Excel 2.1 spreadsheets (*.xls)|*.xls|LibreOffice/OpenOffice spreadsheet (*.ods)|*.ods|Comma-delimited files (*.csv)|*.csv|WikiTable (WikiMedia-Format, *.wikitable_wikimedia)|*.wikitable_wikimedia' - Hint = 'Save spreadsheet with a new name' + Hint = 'Save spreadsheet' ImageIndex = 45 OnAccept = AcFileSaveAsAccept end @@ -3843,8 +3846,95 @@ object Form1: TForm1 end object MenuItem9: TMenuItem Caption = 'Cell' + object MenuItem89: TMenuItem + Action = AcBackgroundColorDialog + end + object MenuItem68: TMenuItem + Caption = 'Font' + object MenuItem69: TMenuItem + Action = AcCellFontDialog + end + object MenuItem70: TMenuItem + Caption = '-' + end + object MenuItem71: TMenuItem + Action = AcFontBold + AutoCheck = True + end + object MenuItem72: TMenuItem + Action = AcFontItalic + AutoCheck = True + end + object MenuItem73: TMenuItem + Action = AcFontUnderline + AutoCheck = True + end + object MenuItem74: TMenuItem + Action = AcFontStrikeout + AutoCheck = True + end + end + object MenuItem76: TMenuItem + Caption = 'Text rotation' + object MenuItem77: TMenuItem + Action = AcTextRotHor + AutoCheck = True + end + object MenuItem78: TMenuItem + Caption = '-' + end + object MenuItem79: TMenuItem + Action = AcTextRot90CW + AutoCheck = True + end + object MenuItem80: TMenuItem + Action = AcTextRot90CCW + AutoCheck = True + end + object MenuItem81: TMenuItem + Action = AcTextRotStacked + AutoCheck = True + end + end + object MenuItem75: TMenuItem + Caption = 'Horizontal text alignment' + object MenuItem82: TMenuItem + Action = AcHorAlignLeft + AutoCheck = True + end + object MenuItem83: TMenuItem + Action = AcHorAlignCenter + AutoCheck = True + end + object MenuItem84: TMenuItem + Action = AcHorAlignRight + AutoCheck = True + end + end + object MenuItem85: TMenuItem + Caption = 'Vertical text alignment' + object MenuItem86: TMenuItem + Action = AcVertAlignTop + AutoCheck = True + end + object MenuItem87: TMenuItem + Action = AcVertAlignCenter + AutoCheck = True + end + object MenuItem88: TMenuItem + Action = AcVertAlignBottom + AutoCheck = True + end + end object MenuItem10: TMenuItem Caption = 'Number format' + object MenuItem55: TMenuItem + Action = AcNumFormatGeneral + AutoCheck = True + end + object MenuItem54: TMenuItem + Caption = '-' + end object MenuItem12: TMenuItem Action = AcNumFormatFixed AutoCheck = True @@ -3856,6 +3946,10 @@ object Form1: TForm1 object MenuItem13: TMenuItem Caption = '-' end + object MenuItem53: TMenuItem + Action = AcNumFormatExp + AutoCheck = True + end object MenuItem14: TMenuItem Action = AcNumFormatPercentage AutoCheck = True @@ -3871,6 +3965,50 @@ object Form1: TForm1 Action = AcNumFormatCurrencyRed AutoCheck = True end + object MenuItem56: TMenuItem + Caption = '-' + end + object MenuItem57: TMenuItem + Action = AcNumFormatDateTime + AutoCheck = True + end + object MenuItem58: TMenuItem + Caption = '-' + end + object MenuItem59: TMenuItem + Action = AcNumFormatLongDate + AutoCheck = True + end + object MenuItem60: TMenuItem + Action = AcNumFormatShortDate + AutoCheck = True + end + object MenuItem61: TMenuItem + Caption = '-' + end + object MenuItem62: TMenuItem + Action = AcNumFormatLongTime + AutoCheck = True + end + object MenuItem63: TMenuItem + Action = AcNumFormatShortTime + AutoCheck = True + end + object MenuItem64: TMenuItem + Action = AcNumFormatLongTimeAM + AutoCheck = True + end + object MenuItem65: TMenuItem + Action = AcNumFormatShortTimeAM + AutoCheck = True + end + object MenuItem66: TMenuItem + Caption = '-' + end + object MenuItem67: TMenuItem + Action = AcNumFormatTimeInterval + AutoCheck = True + end end end end diff --git a/components/fpspreadsheet/examples/fpsctrls/main.pas b/components/fpspreadsheet/examples/fpsctrls/main.pas index f510ec7c7..ce35a2190 100644 --- a/components/fpspreadsheet/examples/fpsctrls/main.pas +++ b/components/fpspreadsheet/examples/fpsctrls/main.pas @@ -69,6 +69,43 @@ type MenuItem50: TMenuItem; MenuItem51: TMenuItem; MenuItem52: TMenuItem; + MenuItem53: TMenuItem; + MenuItem54: TMenuItem; + MenuItem55: TMenuItem; + MenuItem56: TMenuItem; + MenuItem57: TMenuItem; + MenuItem58: TMenuItem; + MenuItem59: TMenuItem; + MenuItem60: TMenuItem; + MenuItem61: TMenuItem; + MenuItem62: TMenuItem; + MenuItem63: TMenuItem; + MenuItem64: TMenuItem; + MenuItem65: TMenuItem; + MenuItem66: TMenuItem; + MenuItem67: TMenuItem; + MenuItem68: TMenuItem; + MenuItem69: TMenuItem; + MenuItem70: TMenuItem; + MenuItem71: TMenuItem; + MenuItem72: TMenuItem; + MenuItem73: TMenuItem; + MenuItem74: TMenuItem; + MenuItem75: TMenuItem; + MenuItem76: TMenuItem; + MenuItem77: TMenuItem; + MenuItem78: TMenuItem; + MenuItem79: TMenuItem; + MenuItem80: TMenuItem; + MenuItem81: TMenuItem; + MenuItem82: TMenuItem; + MenuItem83: TMenuItem; + MenuItem84: TMenuItem; + MenuItem85: TMenuItem; + MenuItem86: TMenuItem; + MenuItem87: TMenuItem; + MenuItem88: TMenuItem; + MenuItem89: TMenuItem; MnuView: TMenuItem; MenuItem6: TMenuItem; MenuItem7: TMenuItem; diff --git a/components/fpspreadsheet/examples/fpsctrls_no_install/main.pas b/components/fpspreadsheet/examples/fpsctrls_no_install/main.pas index a0bf6c840..6fde2d2f8 100644 --- a/components/fpspreadsheet/examples/fpsctrls_no_install/main.pas +++ b/components/fpspreadsheet/examples/fpsctrls_no_install/main.pas @@ -203,6 +203,8 @@ begin actn := TsWorksheetAddAction.Create(self); with TsWorksheetAddAction(actn) do begin ActionList := self.ActionList; + Caption := 'Add'; + Hint := 'Add worksheet'; WorkbookSource := Self.WorkbookSource; end; MnuAddWorksheet.Action := actn; @@ -210,6 +212,8 @@ begin actn := TsWorksheetDeleteAction.Create(self); with TsWorksheetDeleteAction(actn) do begin ActionList := self.ActionList; + Caption := 'Delete...'; + Hint := 'Delete worksheet'; WorkbookSource := Self.WorkbookSource; end; MnuDeleteWorksheet.Action := actn; @@ -217,6 +221,8 @@ begin actn := TsWorksheetRenameAction.Create(self); with TsWorksheetRenameAction(actn) do begin ActionList := self.ActionList; + Caption := 'Rename...'; + Hint := 'Rename worksheet'; WorkbookSource := Self.WorkbookSource; end; MnuRenameWorksheet.Action := actn; @@ -231,6 +237,8 @@ begin actn := TsFontStyleAction.Create(self); with TsFontStyleAction(actn) do begin ActionList := Self.ActionList; + Caption := 'Bold'; + Hint := 'Bold'; ImageIndex := 0; WorkbookSource := Self.WorkbookSource; FontStyle := fssBold; @@ -241,6 +249,8 @@ begin actn := TsFontStyleAction.Create(self); with TsFontStyleAction(actn) do begin ActionList := Self.ActionList; + Caption := 'Italic'; + Hint := 'Italic'; ImageIndex := 1; WorkbookSource := Self.WorkbookSource; FontStyle := fssItalic; @@ -251,6 +261,8 @@ begin actn := TsFontStyleAction.Create(self); with TsFontStyleAction(actn) do begin ActionList := Self.ActionList; + Caption := 'Underline'; + Hint := 'Underline'; ImageIndex := 2; WorkbookSource := Self.WorkbookSource; FontStyle := fssUnderline; @@ -261,6 +273,8 @@ begin actn := TsFontStyleAction.Create(self); with TsFontStyleAction(actn) do begin ActionList := Self.ActionList; + Caption := 'Strikeout'; + Hint := 'Strikeout'; ImageIndex := 3; WorkbookSource := Self.WorkbookSource; FontStyle := fssStrikeout; @@ -272,6 +286,8 @@ begin actn := TsHorAlignmentAction.Create(self); with TsHorAlignmentAction(actn) do begin ActionList := self.ActionList; + Caption := 'Left'; + Hint := 'Left-aligned'; ImageIndex := 4; WorkbookSource := Self.WorkbookSource; HorAlignment := haLeft; @@ -282,6 +298,8 @@ begin actn := TsHorAlignmentAction.Create(self); with TsHorAlignmentAction(actn) do begin ActionList := self.ActionList; + Caption := 'Center'; + Hint := 'Centered'; ImageIndex := 5; WorkbookSource := Self.WorkbookSource; HorAlignment := haCenter; @@ -292,6 +310,8 @@ begin actn := TsHorAlignmentAction.Create(self); with TsHorAlignmentAction(actn) do begin ActionList := self.ActionList; + Caption := 'Right'; + Hint := 'Right-aligned'; ImageIndex := 6; WorkbookSource := Self.WorkbookSource; HorAlignment := haRight; @@ -303,6 +323,8 @@ begin actn := TsVertAlignmentAction.Create(self); with TsVertAlignmentAction(actn) do begin ActionList := self.ActionList; + Caption := 'Top'; + Hint := 'Top-aligned'; ImageIndex := 7; WorkbookSource := Self.WorkbookSource; VertAlignment := vaTop; @@ -313,6 +335,8 @@ begin actn := TsVertAlignmentAction.Create(self); with TsVertAlignmentAction(actn) do begin ActionList := self.ActionList; + Caption := 'Middle'; + Hint := 'Middle'; ImageIndex := 8; WorkbookSource := Self.WorkbookSource; VertAlignment := vaCenter; @@ -323,6 +347,8 @@ begin actn := TsVertAlignmentAction.Create(self); with TsVertAlignmentAction(actn) do begin ActionList := self.ActionList; + Caption := 'Bottom'; + Hint := 'Bottom-aligned'; ImageIndex := 9; WorkbookSource := Self.WorkbookSource; VertAlignment := vaBottom; @@ -334,6 +360,8 @@ begin actn := TsTextRotationAction.Create(self); with TsTextRotationAction(actn) do begin ActionList := self.ActionList; + Caption := 'Horizontal'; + Hint := 'Horizontal text'; WorkbookSource := Self.WorkbookSource; TextRotation := trHorizontal; end; @@ -342,6 +370,8 @@ begin actn := TsTextRotationAction.Create(self); with TsTextRotationAction(actn) do begin ActionList := self.ActionList; + Caption := '90° clockwise rotation'; + Hint := '90° clockwise rotated text'; WorkbookSource := Self.WorkbookSource; TextRotation := rt90DegreeClockwiseRotation; end; @@ -350,6 +380,8 @@ begin actn := TsTextRotationAction.Create(self); with TsTextRotationAction(actn) do begin ActionList := self.ActionList; + Caption := '90° couner-clockwise rotation'; + Hint := '90° counter-clockwise rotated text'; WorkbookSource := Self.WorkbookSource; TextRotation := rt90DegreeCounterClockwiseRotation; end; @@ -358,6 +390,8 @@ begin actn := TsTextRotationAction.Create(self); with TsTextRotationAction(actn) do begin ActionList := self.ActionList; + Caption := 'Stacked'; + Hint := 'Stacked text'; WorkbookSource := Self.WorkbookSource; TextRotation := rtStacked; end; @@ -367,6 +401,8 @@ begin actn := TsWordwrapAction.Create(self); with TsWordwrapAction(actn) do begin ActionList := self.ActionList; + Caption := 'Word-wrap'; + Hint := 'Word-wrapped text'; WorkbookSource := Self.WorkbookSource; Wordwrap := false; end; @@ -376,6 +412,8 @@ begin actn := TsNumberFormatAction.Create(self); with TsNumberFormatAction(actn) do begin ActionList := self.ActionList; + Caption := 'General'; + Hint := 'General'; WorkbookSource := Self.WorkbookSource; NumberFormat := nfGeneral; end; @@ -384,6 +422,8 @@ begin actn := TsNumberFormatAction.Create(self); with TsNumberFormatAction(actn) do begin ActionList := self.ActionList; + Caption := 'Fixed'; + Hint := 'Fixed decimals'; WorkbookSource := Self.WorkbookSource; NumberFormat := nfFixed; end; @@ -392,6 +432,8 @@ begin actn := TsNumberFormatAction.Create(self); with TsNumberFormatAction(actn) do begin ActionList := self.ActionList; + Caption := 'Fixed w/Thousand separator'; + Hint := 'Fixed decimals with thousand separator'; WorkbookSource := Self.WorkbookSource; NumberFormat := nfFixedTh; end; @@ -400,6 +442,8 @@ begin actn := TsNumberFormatAction.Create(self); with TsNumberFormatAction(actn) do begin ActionList := self.ActionList; + Caption := 'Exponential'; + Hint := 'Exponential'; WorkbookSource := Self.WorkbookSource; NumberFormat := nfExp; end; @@ -408,6 +452,8 @@ begin actn := TsNumberFormatAction.Create(self); with TsNumberFormatAction(actn) do begin ActionList := self.ActionList; + Caption := 'Percentage'; + Hint := 'Percentage'; WorkbookSource := Self.WorkbookSource; NumberFormat := nfPercentage; end; @@ -416,6 +462,8 @@ begin actn := TsNumberFormatAction.Create(self); with TsNumberFormatAction(actn) do begin ActionList := self.ActionList; + Caption := 'Currency'; + Hint := 'Currency'; WorkbookSource := Self.WorkbookSource; NumberFormat := nfCurrency; end; @@ -424,6 +472,8 @@ begin actn := TsNumberFormatAction.Create(self); with TsNumberFormatAction(actn) do begin ActionList := self.ActionList; + Caption := 'Currency (red)'; + Hint := 'Currency (negative values in red)'; WorkbookSource := Self.WorkbookSource; NumberFormat := nfCurrencyRed; end; @@ -432,6 +482,8 @@ begin actn := TsNumberFormatAction.Create(self); with TsNumberFormatAction(actn) do begin ActionList := self.ActionList; + Caption := 'Date and time'; + Hint := 'Date and time'; WorkbookSource := Self.WorkbookSource; NumberFormat := nfShortDateTime; end; @@ -440,6 +492,8 @@ begin actn := TsNumberFormatAction.Create(self); with TsNumberFormatAction(actn) do begin ActionList := self.ActionList; + Caption := 'Long date'; + Hint := 'Long date'; WorkbookSource := Self.WorkbookSource; NumberFormat := nfLongDate; end; @@ -449,6 +503,8 @@ begin with TsNumberFormatAction(actn) do begin ActionList := self.ActionList; WorkbookSource := Self.WorkbookSource; + Caption := 'Short date'; + Hint := 'Short date'; NumberFormat := nfShortDate; end; MnuNumFormatShortDate.Action := actn; @@ -456,6 +512,8 @@ begin actn := TsNumberFormatAction.Create(self); with TsNumberFormatAction(actn) do begin ActionList := self.ActionList; + Caption := 'Long time'; + Hint := 'Long time'; WorkbookSource := Self.WorkbookSource; NumberFormat := nfLongTime; end; @@ -464,6 +522,8 @@ begin actn := TsNumberFormatAction.Create(self); with TsNumberFormatAction(actn) do begin ActionList := self.ActionList; + Caption := 'Short time'; + Hint := 'Short time'; WorkbookSource := Self.WorkbookSource; NumberFormat := nfShortTime; end; @@ -472,6 +532,8 @@ begin actn := TsNumberFormatAction.Create(self); with TsNumberFormatAction(actn) do begin ActionList := self.ActionList; + Caption := 'Long time AM/PM'; + Hint := 'Long time with AM/PM'; WorkbookSource := Self.WorkbookSource; NumberFormat := nfLongTimeAM; end; @@ -481,6 +543,8 @@ begin with TsNumberFormatAction(actn) do begin ActionList := self.ActionList; WorkbookSource := Self.WorkbookSource; + Caption := 'Short time AM/PM'; + Hint := 'Short time with AM/PM'; NumberFormat := nfShortTimeAM; end; MnuNumFormatShortTimeAM.Action := actn; @@ -489,6 +553,8 @@ begin with TsNumberFormatAction(actn) do begin ActionList := self.ActionList; WorkbookSource := Self.WorkbookSource; + Caption := 'Time interval'; + Hint := 'Time interval'; NumberFormat := nfTimeInterval; end; MnuNumFormatTimeInterval.Action := actn; diff --git a/components/fpspreadsheet/fpsactions.pas b/components/fpspreadsheet/fpsactions.pas index c867ef47f..afb2ccd44 100644 --- a/components/fpspreadsheet/fpsactions.pas +++ b/components/fpspreadsheet/fpsactions.pas @@ -90,7 +90,6 @@ type { Action for deleting selected worksheet } TsWorksheetDeleteAction = class(TsWorksheetAction) public - constructor Create(AOwner: TComponent); override; procedure ExecuteTarget(Target: TObject); override; end; @@ -99,7 +98,6 @@ type private FOnGetWorksheetName: TsWorksheetNameEvent; public - constructor Create(AOwner: TComponent); override; procedure ExecuteTarget(Target: TObject); override; published property OnGetWorksheetName: TsWorksheetNameEvent @@ -118,8 +116,6 @@ type end; TsCopyFormatAction = class(TsSpreadsheetAction) - private - FSource: TsCellRange; public procedure ExecuteTarget(Target: TObject); override; procedure UpdateTarget(Target: TObject); override; @@ -163,22 +159,19 @@ type TsFontStyleAction = class(TsAutoFormatAction) private FFontStyle: TsFontStyle; - procedure SetFontStyle(AValue: TsFontStyle); protected procedure ApplyFormatToCell(ACell: PCell); override; procedure ExtractFromCell(ACell: PCell); override; public constructor Create(AOwner: TComponent); override; published - property FontStyle: TsFontStyle - read FFontStyle write SetFontStyle; + property FontStyle: TsFontStyle read FFontStyle write FFontStyle; end; { TsHorAlignmentAction } TsHorAlignmentAction = class(TsAutoFormatAction) private FHorAlign: TsHorAlignment; - procedure SetHorAlign(AValue: TsHorAlignment); protected procedure ApplyFormatToCell(ACell: PCell); override; procedure ExtractFromCell(ACell: PCell); override; @@ -186,14 +179,13 @@ type constructor Create(AOwner: TComponent); override; published property HorAlignment: TsHorAlignment - read FHorAlign write SetHorAlign default haDefault; + read FHorAlign write FHorAlign default haDefault; end; { TsVertAlignmentAction } TsVertAlignmentAction = class(TsAutoFormatAction) private FVertAlign: TsVertAlignment; - procedure SetVertAlign(AValue: TsVertAlignment); protected procedure ApplyFormatToCell(ACell: PCell); override; procedure ExtractFromCell(ACell: PCell); override; @@ -201,14 +193,13 @@ type constructor Create(AOwner: TComponent); override; published property VertAlignment: TsVertAlignment - read FVertAlign write SetVertAlign default vaDefault; + read FVertAlign write FVertAlign default vaDefault; end; { TsTextRotationAction } TsTextRotationAction = class(TsAutoFormatAction) private FTextRotation: TsTextRotation; - procedure SetTextRotation(AValue: TsTextRotation); protected procedure ApplyFormatToCell(ACell: PCell); override; procedure ExtractFromCell(ACell: PCell); override; @@ -216,7 +207,7 @@ type constructor Create(AOwner: TComponent); override; published property TextRotation: TsTextRotation - read FTextRotation write SetTextRotation default trHorizontal; + read FTextRotation write FTextRotation default trHorizontal; end; { TsWordwrapAction } @@ -239,8 +230,6 @@ type private FNumberFormat: TsNumberFormat; FNumberFormatStr: string; - procedure SetNumberFormat(AValue: TsNumberFormat); - procedure SetNumberFormatStr(AValue: String); protected procedure ApplyFormatToCell(ACell: PCell); override; procedure ExtractFromCell(ACell: PCell); override; @@ -248,9 +237,9 @@ type constructor Create(AOwner: TComponent); override; published property NumberFormat: TsNumberFormat - read FNumberFormat write SetNumberFormat default nfGeneral; + read FNumberFormat write FNumberFormat default nfGeneral; property NumberFormatString: string - read FNumberFormatStr write SetNumberFormatStr; + read FNumberFormatStr write FNumberFormatStr; end; { TsDecimalsAction } @@ -258,16 +247,14 @@ type private FDecimals: Integer; FDelta: Integer; - procedure SetDelta(AValue: Integer); protected procedure ApplyFormatToCell(ACell: PCell); override; procedure ExtractFromCell(ACell: PCell); override; public constructor Create(AOwner: TComponent); override; published - property Caption stored false; property Delta: Integer - read FDelta write SetDelta default +1; + read FDelta write FDelta default +1; property Hint stored false; end; @@ -581,13 +568,11 @@ end; constructor TsWorksheetAddAction.Create(AOwner: TComponent); begin inherited Create(AOwner); - Caption := 'Add'; - Hint := 'Add empty worksheet'; FNameMask := 'Sheet%d'; end; { Helper procedure which creates a default worksheetname by counting a number - up until it provides in the NameMask a unique worksheet name. } + up until - if inserted in the NameMask - it provides a unique worksheet name. } function TsWorksheetAddAction.GetUniqueSheetName: String; var i: Integer; @@ -639,13 +624,6 @@ end; { TsWorksheetDeleteAction } -constructor TsWorksheetDeleteAction.Create(AOwner: TComponent); -begin - inherited Create(AOwner); - Caption := 'Delete...'; - Hint := 'Delete worksheet'; -end; - procedure TsWorksheetDeleteAction.ExecuteTarget(Target: TObject); begin if HandlesTarget(Target) then @@ -674,13 +652,6 @@ end; { TsWorksheetRenameAction } -constructor TsWorksheetRenameAction.Create(AOwner: TComponent); -begin - inherited Create(AOwner); - Caption := 'Rename...'; - Hint := 'Rename worksheet'; -end; - procedure TsWorksheetRenameAction.ExecuteTarget(Target: TObject); var s: String; @@ -716,35 +687,14 @@ end; { TsCopyFormatAction } procedure TsCopyFormatAction.ExecuteTarget(Target: TObject); -var - srcRow, srcCol: Cardinal; // Row and column index of source cell - destRow, destCol: Cardinal; // Row and column index of destination cell - srcCell, destCell: PCell; // Pointers to source and destination cells begin - if (FSource.Row1 = Cardinal(-1)) or (FSource.Row2 = Cardinal(-1)) or - (FSource.Col1 = Cardinal(-1)) or (FSource.Col2 = Cardinal(-1)) - then - exit; - - for srcRow := FSource.Row1 to FSource.Row2 do - begin - destRow := Worksheet.ActiveCellRow + srcRow - FSource.Row1; - for srcCol := FSource.Col1 to FSource.Col2 do begin - destCol := Worksheet.ActiveCellCol + srcCol - FSource.Col1; - srcCell := Worksheet.FindCell(srcRow, srcCol); - destCell := Worksheet.FindCell(destRow, destCol); - Worksheet.CopyFormat(srcCell, destCell); - end; - end; + Checked := true; + WorkbookSource.SetPendingOperation(poCopyFormat, Worksheet.GetSelection); end; procedure TsCopyFormatAction.UpdateTarget(Target: TObject); begin - if (Worksheet = nil) or (Worksheet.GetSelectionCount = 0) then - FSource := TsCellRange(Rect(-1, -1, -1,-1)) - else - FSource := Worksheet.GetSelection[0]; - // Memorize current selection - it will be the source of the copy format operation. + if WorkbookSource.PendingOperation = poNone then Checked := false; end; @@ -806,17 +756,6 @@ begin Checked := false; end; -procedure TsFontStyleAction.SetFontStyle(AValue: TsFontStyle); -begin - FFontStyle := AValue; - case AValue of - fssBold: begin Caption := 'Bold'; Hint := 'Bold font'; end; - fssItalic: begin Caption := 'Italic'; Hint := 'Italic font'; end; - fssUnderline: begin Caption := 'Underline'; Hint := 'Underlines font'; end; - fssStrikeout: begin Caption := 'Strikeout'; Hint := 'Strike-out font'; end; - end; -end; - { TsHorAlignmentAction } @@ -843,17 +782,6 @@ begin Checked := ACell^.HorAlignment = FHorAlign; end; -procedure TsHorAlignmentAction.SetHorAlign(AValue: TsHorAlignment); -begin - FHorAlign := AValue; - case FHorAlign of - haLeft : begin Caption := 'Left'; Hint := 'Left-aligned text'; end; - haCenter : begin Caption := 'Center'; Hint := 'Centered text'; end; - haRight : begin Caption := 'Right'; Hint := 'Right-aligned text'; end; - haDefault: begin Caption := 'Default'; Hint := 'Default horizontal text alignment'; end; - end; -end; - { TsVertAlignmentAction } @@ -880,17 +808,6 @@ begin Checked := ACell^.VertAlignment = FVertAlign; end; -procedure TsVertAlignmentAction.SetVertAlign(AValue: TsVertAlignment); -begin - FVertAlign := AValue; - case FVertAlign of - vaTop : begin Caption := 'Top'; Hint := 'Top-aligned text'; end; - vaCenter : begin Caption := 'Center'; Hint := 'Vertically centered text'; end; - vaBottom : begin Caption := 'Bottom'; Hint := 'Bottom-aligned text'; end; - vaDefault: begin Caption := 'Default'; Hint := 'Default vertical text alignment'; end; - end; -end; - { TsTextRotationAction } @@ -917,21 +834,6 @@ begin Checked := ACell^.TextRotation = FTextRotation; end; -procedure TsTextRotationAction.SetTextRotation(AValue: TsTextRotation); -begin - FTextRotation := AValue; - case FTextRotation of - trHorizontal: - begin Caption := 'Horizontal'; Hint := 'Horizontal text'; end; - rt90DegreeClockwiseRotation: - begin Caption := '90° clockwise'; Hint := '90° clockwise rotated text'; end; - rt90DegreeCounterClockwiseRotation: - begin Caption := '90° counter-clockwise'; Hint := '90° counter-clockwise rotated text'; end; - rtStacked: - begin Caption := 'Stacked'; Hint := 'Vertically stacked horizontal letters'; end; - end; -end; - { TsWordwrapAction } @@ -939,8 +841,6 @@ constructor TsWordwrapAction.Create(AOwner: TComponent); begin inherited Create(AOwner); AutoCheck := true; - Caption := 'Word-wrap'; - Hint := 'Word-wrapped text'; end; procedure TsWordwrapAction.ApplyFormatToCell(ACell: PCell); @@ -971,8 +871,6 @@ begin inherited Create(AOwner); GroupIndex := 1411141258; // Date/time when this was written AutoCheck := true; - Caption := 'Number format'; - Hint := 'Number format'; end; procedure TsNumberFormatAction.ApplyFormatToCell(ACell: PCell); @@ -1004,58 +902,13 @@ begin and (ACell^.NumberFormatStr = FNumberFormatStr); end; -procedure TsNumberFormatAction.SetNumberFormat(AValue: TsNumberFormat); -begin - FNumberFormat := AValue; - case FNumberFormat of - nfGeneral: - begin Caption := 'General'; Hint := 'General format'; end; - nfFixed: - begin Caption := 'Fixed'; Hint := 'Fixed decimals format'; end; - nfFixedTh: - begin Caption := 'Fixed w/thousand separator'; Hint := 'Fixed decimal count with thousand separator'; end; - nfExp: - begin Caption := 'Exponential'; Hint := 'Exponential format'; end; - nfPercentage: - begin Caption := 'Percent'; Hint := 'Percent format'; end; - nfCurrency: - begin Caption := 'Currency'; Hint := 'Currency format'; end; - nfCurrencyRed: - begin Caption := 'Currency (red)'; Hint := 'Currency format (negative values in red)'; end; - nfShortDateTime: - begin Caption := 'Date/time'; Hint := 'Date and time'; end; - nfShortDate: - begin Caption := 'Short date'; Hint := 'Short date format'; end; - nfLongDate: - begin Caption := 'Long date'; Hint := 'Long date format'; end; - nfShortTime: - begin Caption := 'Short time'; Hint := 'Short time format'; end; - nfLongTime: - begin Caption := 'Long time'; Hint := 'Long time foramt'; end; - nfShortTimeAM: - begin Caption := 'Short time AM/PM'; Hint := 'Short 12-hour time format'; end; - nfLongTimeAM: - begin Caption := 'Long time AM/PM'; Hint := 'Long 12-hour time format'; end; - nfTimeInterval: - begin Caption := 'Time interval'; Hint := 'Time interval format'; end; - nfCustom: - begin Caption := 'Custom'; Hint := 'User-defined custom format'; end; - end; -end; - -procedure TsNumberFormatAction.SetNumberFormatStr(AValue: String); -begin - FNumberFormatStr := AValue; -end; - { TsDecimalsAction } constructor TsDecimalsAction.Create(AOwner: TComponent); begin inherited Create(AOwner); - Caption := 'Decimals'; - Delta := +1; + FDelta := +1; end; procedure TsDecimalsAction.ApplyFormatToCell(ACell: PCell); @@ -1097,15 +950,6 @@ begin FDecimals := decs; end; -procedure TsDecimalsAction.SetDelta(AValue: Integer); -begin - FDelta := AValue; - if FDelta > 0 then - Hint := 'More decimal places' - else - Hint := 'Less decimal places'; -end; - { TsCellBorderAction } diff --git a/components/fpspreadsheet/fpspreadsheetctrls.pas b/components/fpspreadsheet/fpspreadsheetctrls.pas index a929871bf..a0b1d7c46 100644 --- a/components/fpspreadsheet/fpspreadsheetctrls.pas +++ b/components/fpspreadsheet/fpspreadsheetctrls.pas @@ -38,11 +38,14 @@ type {@@ Describes during communication between WorkbookSource and visual controls which kind of item has changed: the workbook, the worksheet, a cell value, or a cell formatting } - TsNotificationItem = (lniWorkbook, lniWorksheet, lniCell, lniSelection); + TsNotificationItem = (lniWorkbook, lniWorksheet, lniCell, lniSelection, + lniAbortSelection); {@@ This set accompanies the notification between WorkbookSource and visual controls and describes which items have changed in the spreadsheet. } TsNotificationItems = set of TsNotificationItem; + {@@ Identifier for an operation that will be executed at next cell select } + TsPendingOperation = (poNone, poCopyFormat); { TsWorkbookSource } @@ -56,8 +59,12 @@ type FAutoDetectFormat: Boolean; FFileName: TFileName; FFileFormat: TsSpreadsheetFormat; + FPendingSelection: TsCellRangeArray; + FPendingOperation: TsPendingOperation; FOptions: TsWorkbookOptions; FOnError: TsWorkbookSourceErrorEvent; + + procedure AbortSelection; procedure CellChangedHandler(Sender: TObject; ARow, ACol: Cardinal); procedure CellSelectedHandler(Sender: TObject; ARow, ACol: Cardinal); procedure InternalCreateNewWorkbook; @@ -85,22 +92,31 @@ type public procedure CreateNewWorkbook; + procedure LoadFromSpreadsheetFile(AFileName: string; AFormat: TsSpreadsheetFormat; AWorksheetIndex: Integer = 0); overload; procedure LoadFromSpreadsheetFile(AFileName: string; AWorksheetIndex: Integer = 0); overload; + procedure SaveToSpreadsheetFile(AFileName: string; AOverwriteExisting: Boolean = true); overload; procedure SaveToSpreadsheetFile(AFileName: string; AFormat: TsSpreadsheetFormat; AOverwriteExisting: Boolean = true); overload; + procedure SelectCell(ASheetRow, ASheetCol: Cardinal); procedure SelectWorksheet(AWorkSheet: TsWorksheet); + procedure ExecutePendingOperation; + procedure SetPendingOperation(AOperation: TsPendingOperation; + const ASelection: TsCellRangeArray); + public {@@ Workbook linked to the WorkbookSource } property Workbook: TsWorkbook read FWorkbook; {@@ Currently selected worksheet of the workbook } property Worksheet: TsWorksheet read FWorksheet; + {@@ Indicates that which operation is waiting to be executed at next cell select } + property PendingOperation: TsPendingOperation read FPendingOperation; published {@@ Automatically detects the fileformat when loading the spreadsheet file @@ -327,7 +343,7 @@ procedure Register; implementation uses - Dialogs, Forms, TypInfo, + Types, TypInfo, Dialogs, Forms, fpsStrings, fpsUtils, fpSpreadsheetGrid; @@ -382,6 +398,16 @@ begin inherited Destroy; end; +{@@ ---------------------------------------------------------------------------- + Generates a message to the grid to abort the selection process. + Needed when copying a format (e.g.) cannot be executed due to overlapping + ranges. Without the message, the grid would still be in selection mode. +-------------------------------------------------------------------------------} +procedure TsWorkbookSource.AbortSelection; +begin + NotifyListeners([lniAbortSelection], nil); +end; + {@@ ---------------------------------------------------------------------------- Adds a component to the listener list. All these components are notified of changes in the workbook. @@ -424,6 +450,12 @@ procedure TsWorkbookSource.CellSelectedHandler(Sender: TObject; begin Unused(ARow, ACol); NotifyListeners([lniSelection]); + + if FPendingOperation <> poNone then + begin + ExecutePendingOperation; + FPendingOperation := poNone; + end; end; {@@ ---------------------------------------------------------------------------- @@ -456,6 +488,60 @@ begin MessageDlg(AErrorMsg, mtError, [mbOK], 0); end; +{@@ ---------------------------------------------------------------------------- + Executes a "pending operation" +-------------------------------------------------------------------------------} +procedure TsWorkbookSource.ExecutePendingOperation; +var + destSelection: TsCellRangeArray; + srcCell, destCell: PCell; // Pointers to source and destination cells + i, j, k: Integer; + ofsRow, ofsCol: LongInt; + + function DistinctRanges(R1, R2: TsCellRange): Boolean; + begin + Result := (R2.Col1 > R1.Col2) or (R1.Col1 > R2.Col2) or + (R2.Row1 > R1.Row2) or (R1.Row1 > R2.Row2); + end; + +begin + ofsRow := Worksheet.ActiveCellRow - FPendingSelection[0].Row1; + ofsCol := Worksheet.ActiveCellCol - FPendingSelection[0].Col1; + + // Calculate destination ranges which begin at the active cell + SetLength(destSelection, Length(FPendingSelection)); + for i := 0 to High(FPendingSelection) do + destSelection[i] := TsCellRange(Rect( + FPendingSelection[i].Row1 + ofsRow, + FPendingSelection[i].Col1 + ofsCol, + FPendingSelection[i].Row2 + ofsRow, + FPendingSelection[i].Col2 + ofsCol + )); + + // Check for intersection between source and destination ranges + for i:=0 to High(FPendingSelection) do + for j:=0 to High(FPendingSelection) do + if not DistinctRanges(FPendingSelection[i], destSelection[j]) then + begin + MessageDlg('Source and destination selections are overlapping. Operation aborted.', + mtError, [mbOK], 0); + AbortSelection; + exit; + end; + + // Execute pending operation + for i:=0 to High(FPendingSelection) do + for j:=0 to FPendingSelection[i].Row2-FPendingSelection[i].Row1 do + for k:=0 to FPendingSelection[i].Col2-FPendingSelection[i].Col1 do + begin + srcCell := Worksheet.FindCell(FPendingSelection[i].Row1+j, FPendingSelection[i].Col1+k); + destCell := Worksheet.GetCell(destSelection[i].Row1+j, destSelection[i].Col1+k); + case FPendingOperation of + poCopyFormat: Worksheet.CopyFormat(srcCell, destCell); + end; + end; +end; + {@@ ---------------------------------------------------------------------------- Internal helper method which creates a new workbook without sheets -------------------------------------------------------------------------------} @@ -691,8 +777,10 @@ end; procedure TsWorkbookSource.SelectCell(ASheetRow, ASheetCol: Cardinal); begin if FWorksheet <> nil then + begin FWorksheet.SelectCell(ASheetRow, ASheetCol); - NotifyListeners([lniSelection]); + NotifyListeners([lniSelection]); + end; end; {@@ ---------------------------------------------------------------------------- @@ -748,6 +836,22 @@ begin Workbook.Options := FOptions; end; +{@@ ---------------------------------------------------------------------------- + Defines a "pending operation" which will be executed at next cell select. + Source of the operation is the selection passes as a parameter. +-------------------------------------------------------------------------------} +procedure TsWorkbookSource.SetPendingOperation(AOperation: TsPendingOperation; + const ASelection: TsCellRangeArray); +var + i: Integer; +begin + SetLength(FPendingSelection, Length(ASelection)); + for i:=0 to High(FPendingSelection) do + FPendingSelection[i] := ASelection[i]; + FPendingSelection := ASelection; + FPendingOperation := AOperation; +end; + {@@ ---------------------------------------------------------------------------- Event handler called whenever a new worksheet is added to the workbook @@ -1218,9 +1322,7 @@ procedure TsCellIndicator.ListenerNotification(AChangedItems: TsNotificationItem begin Unused(AData); if (lniSelection in AChangedItems) and (Worksheet <> nil) then - Text := GetCellString(Worksheet.ActiveCellRow, Worksheet.ActiveCellCol) - else - Text := ''; + Text := GetCellString(Worksheet.ActiveCellRow, Worksheet.ActiveCellCol); end; {@@ ---------------------------------------------------------------------------- diff --git a/components/fpspreadsheet/fpspreadsheetgrid.pas b/components/fpspreadsheet/fpspreadsheetgrid.pas index 61f25f4de..efcad9037 100644 --- a/components/fpspreadsheet/fpspreadsheetgrid.pas +++ b/components/fpspreadsheet/fpspreadsheetgrid.pas @@ -3012,6 +3012,13 @@ begin if (grow <> Row) or (gcol <> Col) then MoveExtend(false, gcol, grow); end; + + // Abort selection because of an error + if (lniAbortSelection in AChangedItems) and (Worksheet <> nil) then + begin + MouseUp(mbLeft, [], GCache.ClickMouse.X, GCache.ClickMouse.Y); + // HOW TO DO THIS???? SelectActive not working... + end; end; {@@ ----------------------------------------------------------------------------