From f72590c226e1bf34db4c0e856754be5a6eb56236 Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Wed, 19 Nov 2014 08:48:07 +0000 Subject: [PATCH] fpspreadsheet: FPSpreadsheetGrid enters "enhanced edit mode" (remove formatting, show formulas) also by mouse click into cell (in addition to F2). Editing of cell content now seems to be consistent with Excel. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@3750 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- .../fpspreadsheet/examples/fpsctrls/main.lfm | 45 ++++++++++--------- .../fpspreadsheet/fpspreadsheetgrid.pas | 19 +++++++- 2 files changed, 40 insertions(+), 24 deletions(-) diff --git a/components/fpspreadsheet/examples/fpsctrls/main.lfm b/components/fpspreadsheet/examples/fpsctrls/main.lfm index 39090d974..8dd5f3024 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 = 580 + ClientHeight = 575 ClientWidth = 922 Menu = MainMenu ShowHint = True LCLVersion = '1.3' object WorkbookTabControl: TsWorkbookTabControl Left = 0 - Height = 497 - Top = 83 + Height = 490 + Top = 85 Width = 669 TabIndex = 0 Tabs.Strings = ( @@ -23,8 +23,8 @@ object Form1: TForm1 WorkbookSource = WorkbookSource object WorksheetGrid: TsWorksheetGrid Left = 2 - Height = 472 - Top = 23 + Height = 460 + Top = 28 Width = 665 FrozenCols = 0 FrozenRows = 0 @@ -78,8 +78,8 @@ object Form1: TForm1 end object InspectorTabControl: TTabControl Left = 674 - Height = 497 - Top = 83 + Height = 490 + Top = 85 Width = 248 OnChange = InspectorTabControlChange TabIndex = 0 @@ -94,8 +94,8 @@ object Form1: TForm1 Visible = False object Inspector: TsSpreadsheetInspector Left = 2 - Height = 472 - Top = 23 + Height = 460 + Top = 28 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 = ( - 111 - 112 + 109 + 110 ) end end object Splitter1: TSplitter Left = 669 - Height = 497 - Top = 83 + Height = 490 + Top = 85 Width = 5 Align = alRight ResizeAnchor = akRight end object ToolBar1: TToolBar Left = 0 - Height = 26 + Height = 28 Top = 24 Width = 922 AutoSize = True @@ -329,10 +329,10 @@ object Form1: TForm1 end object FontnameCombo: TsFontNameCombobox Left = 54 - Height = 23 + Height = 28 Top = 0 Width = 151 - ItemHeight = 15 + ItemHeight = 20 ItemIndex = 62 Items.Strings = ( '@Arial Unicode MS' @@ -1129,10 +1129,10 @@ object Form1: TForm1 end object sFontSizeCombobox1: TsFontSizeCombobox Left = 205 - Height = 23 + Height = 28 Top = 0 Width = 60 - ItemHeight = 15 + ItemHeight = 20 ItemIndex = 2 Items.Strings = ( '8' @@ -1287,7 +1287,7 @@ object Form1: TForm1 object ToolBar3: TToolBar Left = 0 Height = 28 - Top = 50 + Top = 52 Width = 922 AutoSize = True Caption = 'ToolBar3' @@ -1306,7 +1306,7 @@ object Form1: TForm1 TabOrder = 0 object CellIndicator: TsCellIndicator Left = 0 - Height = 23 + Height = 28 Top = 0 Width = 138 Align = alTop @@ -1337,7 +1337,7 @@ object Form1: TForm1 Cursor = crVSplit Left = 0 Height = 5 - Top = 78 + Top = 80 Width = 922 Align = alTop ResizeAnchor = akTop @@ -4066,6 +4066,7 @@ object Form1: TForm1 } end object MainMenu: TMainMenu + Images = ImageList left = 176 top = 376 object MnuFile: TMenuItem diff --git a/components/fpspreadsheet/fpspreadsheetgrid.pas b/components/fpspreadsheet/fpspreadsheetgrid.pas index 67ce7a913..7b0ca0352 100644 --- a/components/fpspreadsheet/fpspreadsheetgrid.pas +++ b/components/fpspreadsheet/fpspreadsheetgrid.pas @@ -155,6 +155,7 @@ type procedure KeyDown(var Key : Word; Shift : TShiftState); override; procedure Loaded; override; procedure LoadFromWorksheet(AWorksheet: TsWorksheet); + procedure MouseDown(Button: TMouseButton; Shift:TShiftState; X,Y:Integer); override; procedure MouseMove(Shift: TShiftState; X, Y: Integer); override; procedure MoveSelection; override; procedure Notification(AComponent: TComponent; Operation: TOperation); override; @@ -2416,6 +2417,7 @@ begin begin if Result[1] <> '=' then Result := '=' + Result; end else + if cell <> nil then case cell^.ContentType of cctNumber: Result := FloatToStr(cell^.NumberValue); @@ -2426,10 +2428,12 @@ begin Result := FormatDateTime('c', cell^.DateTimeValue); else Result := Worksheet.ReadAsUTF8Text(cell); - end; + end + else + Result := ''; end else Result := GetCellText(aCol, aRow); - if Assigned(OnGetEditText) then OnGetEditText(Self, aCol, aRow, result); + if Assigned(OnGetEditText) then OnGetEditText(Self, aCol, aRow, Result); end; {@@ ---------------------------------------------------------------------------- @@ -3066,6 +3070,17 @@ begin ); end; +{@@ ---------------------------------------------------------------------------- + Standard mouse down handler. Is overridden here to enter "enhanced edit mode" + which removes formatting from the values and presents formulas for editing. +-------------------------------------------------------------------------------} +procedure TsCustomWorksheetGrid.MouseDown(Button: TMouseButton; + Shift: TShiftState; X, Y: Integer); +begin + inherited; + FEnhEditMode := true; +end; + {@@ ---------------------------------------------------------------------------- Standard mouse move handler. Is overridden because, if TextOverflow is active, overflown cell may be erased when the mouse leaves them; repaints entire