fpspreadsheet: TsWorksheetGrid transfers row height and col width changes to underlying Worksheet. Automatic adjustment of row height if font changes in a chell.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@3029 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2014-05-08 21:52:04 +00:00
parent 666f399fb1
commit 72bcfc3a5b
5 changed files with 248 additions and 183 deletions

View File

@ -116,7 +116,7 @@
<WindowIndex Value="0"/> <WindowIndex Value="0"/>
<TopLine Value="1"/> <TopLine Value="1"/>
<CursorPos X="10" Y="7"/> <CursorPos X="10" Y="7"/>
<UsageCount Value="157"/> <UsageCount Value="159"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit0> </Unit0>
<Unit1> <Unit1>
@ -128,34 +128,34 @@
<UnitName Value="mainform"/> <UnitName Value="mainform"/>
<EditorIndex Value="1"/> <EditorIndex Value="1"/>
<WindowIndex Value="0"/> <WindowIndex Value="0"/>
<TopLine Value="411"/> <TopLine Value="313"/>
<CursorPos X="15" Y="417"/> <CursorPos X="3" Y="341"/>
<UsageCount Value="157"/> <UsageCount Value="159"/>
<Bookmarks Count="1">
<Item0 X="17" Y="438" ID="1"/>
</Bookmarks>
<Loaded Value="True"/> <Loaded Value="True"/>
<LoadedDesigner Value="True"/> <LoadedDesigner Value="True"/>
</Unit1> </Unit1>
<Unit2> <Unit2>
<Filename Value="..\..\fpspreadsheet.pas"/> <Filename Value="..\..\fpspreadsheet.pas"/>
<UnitName Value="fpspreadsheet"/> <UnitName Value="fpspreadsheet"/>
<IsVisibleTab Value="True"/>
<EditorIndex Value="5"/> <EditorIndex Value="5"/>
<WindowIndex Value="0"/> <WindowIndex Value="0"/>
<TopLine Value="273"/> <TopLine Value="385"/>
<CursorPos X="15" Y="381"/> <CursorPos X="15" Y="402"/>
<UsageCount Value="73"/> <UsageCount Value="74"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit2> </Unit2>
<Unit3> <Unit3>
<Filename Value="..\..\fpspreadsheetgrid.pas"/> <Filename Value="..\..\fpspreadsheetgrid.pas"/>
<UnitName Value="fpspreadsheetgrid"/> <UnitName Value="fpspreadsheetgrid"/>
<IsVisibleTab Value="True"/>
<EditorIndex Value="3"/> <EditorIndex Value="3"/>
<WindowIndex Value="0"/> <WindowIndex Value="0"/>
<TopLine Value="1021"/> <TopLine Value="1052"/>
<CursorPos X="1" Y="1027"/> <CursorPos X="13" Y="1057"/>
<UsageCount Value="74"/> <UsageCount Value="75"/>
<Bookmarks Count="1">
<Item0 X="10" Y="1065" ID="1"/>
</Bookmarks>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit3> </Unit3>
<Unit4> <Unit4>
@ -224,10 +224,12 @@
<Unit12> <Unit12>
<Filename Value="d:\lazarus-svn\lcl\grids.pas"/> <Filename Value="d:\lazarus-svn\lcl\grids.pas"/>
<UnitName Value="Grids"/> <UnitName Value="Grids"/>
<EditorIndex Value="4"/>
<WindowIndex Value="0"/> <WindowIndex Value="0"/>
<TopLine Value="3429"/> <TopLine Value="6220"/>
<CursorPos X="1" Y="3434"/> <CursorPos X="22" Y="6221"/>
<UsageCount Value="32"/> <UsageCount Value="33"/>
<Loaded Value="True"/>
</Unit12> </Unit12>
<Unit13> <Unit13>
<Filename Value="..\..\fpsutils.pas"/> <Filename Value="..\..\fpsutils.pas"/>
@ -236,7 +238,7 @@
<WindowIndex Value="0"/> <WindowIndex Value="0"/>
<TopLine Value="35"/> <TopLine Value="35"/>
<CursorPos X="1" Y="62"/> <CursorPos X="1" Y="62"/>
<UsageCount Value="49"/> <UsageCount Value="50"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit13> </Unit13>
<Unit14> <Unit14>
@ -266,9 +268,9 @@
<UnitName Value="xlsbiff8"/> <UnitName Value="xlsbiff8"/>
<EditorIndex Value="7"/> <EditorIndex Value="7"/>
<WindowIndex Value="0"/> <WindowIndex Value="0"/>
<TopLine Value="1881"/> <TopLine Value="104"/>
<CursorPos X="24" Y="1898"/> <CursorPos X="15" Y="123"/>
<UsageCount Value="48"/> <UsageCount Value="49"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit17> </Unit17>
<Unit18> <Unit18>
@ -291,9 +293,9 @@
<UnitName Value="xlscommon"/> <UnitName Value="xlscommon"/>
<EditorIndex Value="6"/> <EditorIndex Value="6"/>
<WindowIndex Value="0"/> <WindowIndex Value="0"/>
<TopLine Value="1530"/> <TopLine Value="1269"/>
<CursorPos X="47" Y="1554"/> <CursorPos X="1" Y="1286"/>
<UsageCount Value="44"/> <UsageCount Value="45"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit20> </Unit20>
<Unit21> <Unit21>
@ -303,7 +305,7 @@
<WindowIndex Value="0"/> <WindowIndex Value="0"/>
<TopLine Value="1319"/> <TopLine Value="1319"/>
<CursorPos X="3" Y="1325"/> <CursorPos X="3" Y="1325"/>
<UsageCount Value="31"/> <UsageCount Value="32"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit21> </Unit21>
<Unit22> <Unit22>
@ -313,7 +315,7 @@
<WindowIndex Value="0"/> <WindowIndex Value="0"/>
<TopLine Value="547"/> <TopLine Value="547"/>
<CursorPos X="1" Y="563"/> <CursorPos X="1" Y="563"/>
<UsageCount Value="32"/> <UsageCount Value="33"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit22> </Unit22>
<Unit23> <Unit23>
@ -490,134 +492,132 @@
<Unit45> <Unit45>
<Filename Value="C:\development\lazarus\lcl\grids.pas"/> <Filename Value="C:\development\lazarus\lcl\grids.pas"/>
<UnitName Value="Grids"/> <UnitName Value="Grids"/>
<EditorIndex Value="4"/>
<WindowIndex Value="0"/> <WindowIndex Value="0"/>
<TopLine Value="923"/> <TopLine Value="923"/>
<CursorPos X="15" Y="936"/> <CursorPos X="15" Y="936"/>
<UsageCount Value="10"/> <UsageCount Value="10"/>
<Loaded Value="True"/>
</Unit45> </Unit45>
</Units> </Units>
<JumpHistory Count="30" HistoryIndex="29"> <JumpHistory Count="30" HistoryIndex="29">
<Position1> <Position1>
<Filename Value="mainform.pas"/> <Filename Value="..\..\fpspreadsheet.pas"/>
<Caret Line="121" Column="15" TopLine="107"/> <Caret Line="1766" Column="1" TopLine="1746"/>
</Position1> </Position1>
<Position2> <Position2>
<Filename Value="mainform.pas"/> <Filename Value="..\..\fpspreadsheet.pas"/>
<Caret Line="122" Column="15" TopLine="108"/> <Caret Line="1767" Column="1" TopLine="1746"/>
</Position2> </Position2>
<Position3> <Position3>
<Filename Value="mainform.pas"/> <Filename Value="..\..\fpspreadsheetgrid.pas"/>
<Caret Line="123" Column="15" TopLine="109"/> <Caret Line="1046" Column="1" TopLine="1027"/>
</Position3> </Position3>
<Position4> <Position4>
<Filename Value="mainform.pas"/> <Filename Value="..\..\xlscommon.pas"/>
<Caret Line="124" Column="15" TopLine="110"/> <Caret Line="1277" Column="3" TopLine="1269"/>
</Position4> </Position4>
<Position5> <Position5>
<Filename Value="mainform.pas"/> <Filename Value="..\..\xlscommon.pas"/>
<Caret Line="125" Column="15" TopLine="111"/> <Caret Line="1279" Column="1" TopLine="1269"/>
</Position5> </Position5>
<Position6> <Position6>
<Filename Value="mainform.pas"/> <Filename Value="..\..\xlscommon.pas"/>
<Caret Line="126" Column="15" TopLine="112"/> <Caret Line="1280" Column="1" TopLine="1269"/>
</Position6> </Position6>
<Position7> <Position7>
<Filename Value="mainform.pas"/> <Filename Value="..\..\xlscommon.pas"/>
<Caret Line="127" Column="15" TopLine="113"/> <Caret Line="1281" Column="1" TopLine="1269"/>
</Position7> </Position7>
<Position8> <Position8>
<Filename Value="mainform.pas"/> <Filename Value="..\..\xlscommon.pas"/>
<Caret Line="128" Column="15" TopLine="114"/> <Caret Line="1282" Column="1" TopLine="1269"/>
</Position8> </Position8>
<Position9> <Position9>
<Filename Value="mainform.pas"/> <Filename Value="..\..\xlscommon.pas"/>
<Caret Line="162" Column="18" TopLine="147"/> <Caret Line="1284" Column="1" TopLine="1269"/>
</Position9> </Position9>
<Position10> <Position10>
<Filename Value="mainform.pas"/> <Filename Value="..\..\xlscommon.pas"/>
<Caret Line="165" Column="29" TopLine="150"/> <Caret Line="1285" Column="1" TopLine="1269"/>
</Position10> </Position10>
<Position11> <Position11>
<Filename Value="mainform.pas"/> <Filename Value="..\..\xlscommon.pas"/>
<Caret Line="162" Column="6" TopLine="153"/> <Caret Line="1286" Column="1" TopLine="1269"/>
</Position11> </Position11>
<Position12> <Position12>
<Filename Value="mainform.pas"/> <Filename Value="..\..\fpspreadsheet.pas"/>
<Caret Line="174" Column="19" TopLine="159"/> <Caret Line="376" Column="15" TopLine="359"/>
</Position12> </Position12>
<Position13> <Position13>
<Filename Value="mainform.pas"/> <Filename Value="..\..\fpspreadsheet.pas"/>
<Caret Line="176" Column="46" TopLine="159"/> <Caret Line="337" Column="37" TopLine="304"/>
</Position13> </Position13>
<Position14> <Position14>
<Filename Value="mainform.pas"/> <Filename Value="..\..\fpspreadsheetgrid.pas"/>
<Caret Line="179" Column="18" TopLine="161"/> <Caret Line="353" Column="30" TopLine="353"/>
</Position14> </Position14>
<Position15> <Position15>
<Filename Value="mainform.pas"/> <Filename Value="..\..\fpspreadsheetgrid.pas"/>
<Caret Line="176" Column="41" TopLine="157"/> <Caret Line="1" Column="1" TopLine="1"/>
</Position15> </Position15>
<Position16> <Position16>
<Filename Value="mainform.pas"/> <Filename Value="..\..\fpspreadsheetgrid.pas"/>
<Caret Line="181" Column="46" TopLine="157"/> <Caret Line="333" Column="22" TopLine="328"/>
</Position16> </Position16>
<Position17> <Position17>
<Filename Value="mainform.pas"/> <Filename Value="..\..\fpspreadsheetgrid.pas"/>
<Caret Line="187" Column="84" TopLine="163"/> <Caret Line="35" Column="1" TopLine="33"/>
</Position17> </Position17>
<Position18> <Position18>
<Filename Value="mainform.pas"/> <Filename Value="..\..\fpspreadsheetgrid.pas"/>
<Caret Line="181" Column="19" TopLine="164"/> <Caret Line="38" Column="15" TopLine="19"/>
</Position18> </Position18>
<Position19> <Position19>
<Filename Value="mainform.pas"/> <Filename Value="..\..\fpspreadsheetgrid.pas"/>
<Caret Line="180" Column="27" TopLine="165"/> <Caret Line="354" Column="44" TopLine="322"/>
</Position19> </Position19>
<Position20> <Position20>
<Filename Value="mainform.pas"/> <Filename Value="..\..\fpspreadsheetgrid.pas"/>
<Caret Line="181" Column="30" TopLine="166"/> <Caret Line="1184" Column="52" TopLine="1151"/>
</Position20> </Position20>
<Position21> <Position21>
<Filename Value="mainform.pas"/> <Filename Value="..\..\fpspreadsheetgrid.pas"/>
<Caret Line="425" Column="12" TopLine="410"/> <Caret Line="37" Column="15" TopLine="18"/>
</Position21> </Position21>
<Position22> <Position22>
<Filename Value="..\..\fpspreadsheetgrid.pas"/> <Filename Value="..\..\fpspreadsheetgrid.pas"/>
<Caret Line="52" Column="23" TopLine="11"/> <Caret Line="371" Column="91" TopLine="347"/>
</Position22> </Position22>
<Position23> <Position23>
<Filename Value="C:\development\lazarus\lcl\grids.pas"/> <Filename Value="..\..\fpspreadsheetgrid.pas"/>
<Caret Line="1202" Column="3" TopLine="1199"/> <Caret Line="372" Column="33" TopLine="353"/>
</Position23> </Position23>
<Position24> <Position24>
<Filename Value="C:\development\lazarus\lcl\grids.pas"/> <Filename Value="..\..\fpspreadsheetgrid.pas"/>
<Caret Line="2486" Column="21" TopLine="2461"/> <Caret Line="20" Column="1" TopLine="20"/>
</Position24> </Position24>
<Position25> <Position25>
<Filename Value="C:\development\lazarus\lcl\grids.pas"/> <Filename Value="..\..\fpspreadsheet.pas"/>
<Caret Line="7059" Column="60" TopLine="7035"/> <Caret Line="1480" Column="24" TopLine="1461"/>
</Position25> </Position25>
<Position26> <Position26>
<Filename Value="C:\development\lazarus\lcl\grids.pas"/> <Filename Value="..\..\fpspreadsheet.pas"/>
<Caret Line="7804" Column="26" TopLine="7779"/> <Caret Line="1479" Column="14" TopLine="1461"/>
</Position26> </Position26>
<Position27> <Position27>
<Filename Value="C:\development\lazarus\lcl\grids.pas"/> <Filename Value="..\..\fpspreadsheetgrid.pas"/>
<Caret Line="1028" Column="36" TopLine="1018"/> <Caret Line="1064" Column="10" TopLine="1051"/>
</Position27> </Position27>
<Position28> <Position28>
<Filename Value="C:\development\lazarus\lcl\grids.pas"/> <Filename Value="..\..\fpspreadsheetgrid.pas"/>
<Caret Line="1166" Column="28" TopLine="1153"/> <Caret Line="353" Column="1" TopLine="348"/>
</Position28> </Position28>
<Position29> <Position29>
<Filename Value="C:\development\lazarus\lcl\grids.pas"/> <Filename Value="..\..\fpspreadsheetgrid.pas"/>
<Caret Line="1231" Column="25" TopLine="1515"/> <Caret Line="1070" Column="23" TopLine="1045"/>
</Position29> </Position29>
<Position30> <Position30>
<Filename Value="C:\development\lazarus\lcl\grids.pas"/> <Filename Value="..\..\fpspreadsheetgrid.pas"/>
<Caret Line="1202" Column="3" TopLine="1187"/> <Caret Line="1057" Column="13" TopLine="1052"/>
</Position30> </Position30>
</JumpHistory> </JumpHistory>
</ProjectOptions> </ProjectOptions>

View File

@ -4,7 +4,7 @@ object Form1: TForm1
Top = 258 Top = 258
Width = 636 Width = 636
Caption = 'fpsGrid' Caption = 'fpsGrid'
ClientHeight = 381 ClientHeight = 386
ClientWidth = 636 ClientWidth = 636
Menu = MainMenu1 Menu = MainMenu1
OnActivate = FormActivate OnActivate = FormActivate
@ -14,7 +14,7 @@ object Form1: TForm1
object Panel1: TPanel object Panel1: TPanel
Left = 0 Left = 0
Height = 73 Height = 73
Top = 308 Top = 313
Width = 636 Width = 636
Align = alBottom Align = alBottom
BevelOuter = bvNone BevelOuter = bvNone
@ -23,9 +23,9 @@ object Form1: TForm1
TabOrder = 0 TabOrder = 0
object CbShowHeaders: TCheckBox object CbShowHeaders: TCheckBox
Left = 8 Left = 8
Height = 24 Height = 19
Top = 11 Top = 11
Width = 116 Width = 93
Caption = 'Show headers' Caption = 'Show headers'
Checked = True Checked = True
OnClick = CbShowHeadersClick OnClick = CbShowHeadersClick
@ -34,9 +34,9 @@ object Form1: TForm1
end end
object CbShowGridLines: TCheckBox object CbShowGridLines: TCheckBox
Left = 8 Left = 8
Height = 24 Height = 19
Top = 36 Top = 36
Width = 125 Width = 100
Caption = 'Show grid lines' Caption = 'Show grid lines'
Checked = True Checked = True
OnClick = CbShowGridLinesClick OnClick = CbShowGridLinesClick
@ -45,7 +45,7 @@ object Form1: TForm1
end end
object EdFrozenCols: TSpinEdit object EdFrozenCols: TSpinEdit
Left = 238 Left = 238
Height = 28 Height = 23
Top = 8 Top = 8
Width = 52 Width = 52
OnChange = EdFrozenColsChange OnChange = EdFrozenColsChange
@ -53,7 +53,7 @@ object Form1: TForm1
end end
object EdFrozenRows: TSpinEdit object EdFrozenRows: TSpinEdit
Left = 238 Left = 238
Height = 28 Height = 23
Top = 39 Top = 39
Width = 52 Width = 52
OnChange = EdFrozenRowsChange OnChange = EdFrozenRowsChange
@ -61,18 +61,18 @@ object Form1: TForm1
end end
object Label1: TLabel object Label1: TLabel
Left = 152 Left = 152
Height = 20 Height = 15
Top = 13 Top = 13
Width = 77 Width = 62
Caption = 'Frozen cols:' Caption = 'Frozen cols:'
FocusControl = EdFrozenCols FocusControl = EdFrozenCols
ParentColor = False ParentColor = False
end end
object Label2: TLabel object Label2: TLabel
Left = 153 Left = 153
Height = 20 Height = 15
Top = 40 Top = 40
Width = 82 Width = 66
Caption = 'Frozen rows:' Caption = 'Frozen rows:'
FocusControl = EdFrozenRows FocusControl = EdFrozenRows
ParentColor = False ParentColor = False
@ -80,7 +80,7 @@ object Form1: TForm1
end end
object PageControl1: TPageControl object PageControl1: TPageControl
Left = 0 Left = 0
Height = 250 Height = 255
Top = 58 Top = 58
Width = 636 Width = 636
ActivePage = TabSheet1 ActivePage = TabSheet1
@ -90,11 +90,11 @@ object Form1: TForm1
OnChange = PageControl1Change OnChange = PageControl1Change
object TabSheet1: TTabSheet object TabSheet1: TTabSheet
Caption = 'Sheet1' Caption = 'Sheet1'
ClientHeight = 217 ClientHeight = 227
ClientWidth = 628 ClientWidth = 628
object sWorksheetGrid1: TsWorksheetGrid object sWorksheetGrid1: TsWorksheetGrid
Left = 0 Left = 0
Height = 217 Height = 227
Top = 0 Top = 0
Width = 628 Width = 628
FrozenCols = 0 FrozenCols = 0
@ -108,7 +108,7 @@ object Form1: TForm1
TitleStyle = tsNative TitleStyle = tsNative
OnSelectCell = sWorksheetGrid1SelectCell OnSelectCell = sWorksheetGrid1SelectCell
ColWidths = ( ColWidths = (
56 42
64 64
) )
end end
@ -184,19 +184,19 @@ object Form1: TForm1
end end
object FontComboBox: TComboBox object FontComboBox: TComboBox
Left = 1 Left = 1
Height = 28 Height = 23
Top = 2 Top = 2
Width = 127 Width = 127
ItemHeight = 20 ItemHeight = 15
OnSelect = FontComboBoxSelect OnSelect = FontComboBoxSelect
TabOrder = 0 TabOrder = 0
end end
object FontSizeComboBox: TComboBox object FontSizeComboBox: TComboBox
Left = 128 Left = 128
Height = 28 Height = 23
Top = 2 Top = 2
Width = 48 Width = 48
ItemHeight = 20 ItemHeight = 15
Items.Strings = ( Items.Strings = (
'8' '8'
'9' '9'

View File

@ -2,74 +2,74 @@
LazarusResources.Add('TForm1','FORMDATA',[ LazarusResources.Add('TForm1','FORMDATA',[
'TPF0'#6'TForm1'#5'Form1'#4'Left'#3'r'#1#6'Height'#3#150#1#3'Top'#3#2#1#5'Wid' 'TPF0'#6'TForm1'#5'Form1'#4'Left'#3'r'#1#6'Height'#3#150#1#3'Top'#3#2#1#5'Wid'
+'th'#3'|'#2#7'Caption'#6#7'fpsGrid'#12'ClientHeight'#3'}'#1#11'ClientWidth'#3 +'th'#3'|'#2#7'Caption'#6#7'fpsGrid'#12'ClientHeight'#3#130#1#11'ClientWidth'
+'|'#2#4'Menu'#7#9'MainMenu1'#10'OnActivate'#7#12'FormActivate'#8'OnCreate'#7 +#3'|'#2#4'Menu'#7#9'MainMenu1'#10'OnActivate'#7#12'FormActivate'#8'OnCreate'
+#10'FormCreate'#8'ShowHint'#9#10'LCLVersion'#6#3'1.3'#0#6'TPanel'#6'Panel1'#4 +#7#10'FormCreate'#8'ShowHint'#9#10'LCLVersion'#6#3'1.3'#0#6'TPanel'#6'Panel1'
+'Left'#2#0#6'Height'#2'I'#3'Top'#3'4'#1#5'Width'#3'|'#2#5'Align'#7#8'alBotto' +#4'Left'#2#0#6'Height'#2'I'#3'Top'#3'9'#1#5'Width'#3'|'#2#5'Align'#7#8'alBot'
+'m'#10'BevelOuter'#7#6'bvNone'#12'ClientHeight'#2'I'#11'ClientWidth'#3'|'#2#8 +'tom'#10'BevelOuter'#7#6'bvNone'#12'ClientHeight'#2'I'#11'ClientWidth'#3'|'#2
+'TabOrder'#2#0#0#9'TCheckBox'#13'CbShowHeaders'#4'Left'#2#8#6'Height'#2#24#3 +#8'TabOrder'#2#0#0#9'TCheckBox'#13'CbShowHeaders'#4'Left'#2#8#6'Height'#2#19
+'Top'#2#11#5'Width'#2't'#7'Caption'#6#12'Show headers'#7'Checked'#9#7'OnClic' +#3'Top'#2#11#5'Width'#2']'#7'Caption'#6#12'Show headers'#7'Checked'#9#7'OnCl'
+'k'#7#18'CbShowHeadersClick'#5'State'#7#9'cbChecked'#8'TabOrder'#2#0#0#0#9'T' +'ick'#7#18'CbShowHeadersClick'#5'State'#7#9'cbChecked'#8'TabOrder'#2#0#0#0#9
+'CheckBox'#15'CbShowGridLines'#4'Left'#2#8#6'Height'#2#24#3'Top'#2'$'#5'Widt' +'TCheckBox'#15'CbShowGridLines'#4'Left'#2#8#6'Height'#2#19#3'Top'#2'$'#5'Wid'
+'h'#2'}'#7'Caption'#6#15'Show grid lines'#7'Checked'#9#7'OnClick'#7#20'CbSho' +'th'#2'd'#7'Caption'#6#15'Show grid lines'#7'Checked'#9#7'OnClick'#7#20'CbSh'
+'wGridLinesClick'#5'State'#7#9'cbChecked'#8'TabOrder'#2#1#0#0#9'TSpinEdit'#12 +'owGridLinesClick'#5'State'#7#9'cbChecked'#8'TabOrder'#2#1#0#0#9'TSpinEdit'
+'EdFrozenCols'#4'Left'#3#238#0#6'Height'#2#28#3'Top'#2#8#5'Width'#2'4'#8'OnC' +#12'EdFrozenCols'#4'Left'#3#238#0#6'Height'#2#23#3'Top'#2#8#5'Width'#2'4'#8
+'hange'#7#18'EdFrozenColsChange'#8'TabOrder'#2#2#0#0#9'TSpinEdit'#12'EdFroze' +'OnChange'#7#18'EdFrozenColsChange'#8'TabOrder'#2#2#0#0#9'TSpinEdit'#12'EdFr'
+'nRows'#4'Left'#3#238#0#6'Height'#2#28#3'Top'#2''''#5'Width'#2'4'#8'OnChange' +'ozenRows'#4'Left'#3#238#0#6'Height'#2#23#3'Top'#2''''#5'Width'#2'4'#8'OnCha'
+#7#18'EdFrozenRowsChange'#8'TabOrder'#2#3#0#0#6'TLabel'#6'Label1'#4'Left'#3 +'nge'#7#18'EdFrozenRowsChange'#8'TabOrder'#2#3#0#0#6'TLabel'#6'Label1'#4'Lef'
+#152#0#6'Height'#2#20#3'Top'#2#13#5'Width'#2'M'#7'Caption'#6#12'Frozen cols:' +'t'#3#152#0#6'Height'#2#15#3'Top'#2#13#5'Width'#2'>'#7'Caption'#6#12'Frozen '
+#12'FocusControl'#7#12'EdFrozenCols'#11'ParentColor'#8#0#0#6'TLabel'#6'Label' +'cols:'#12'FocusControl'#7#12'EdFrozenCols'#11'ParentColor'#8#0#0#6'TLabel'#6
+'2'#4'Left'#3#153#0#6'Height'#2#20#3'Top'#2'('#5'Width'#2'R'#7'Caption'#6#12 +'Label2'#4'Left'#3#153#0#6'Height'#2#15#3'Top'#2'('#5'Width'#2'B'#7'Caption'
+'Frozen rows:'#12'FocusControl'#7#12'EdFrozenRows'#11'ParentColor'#8#0#0#0#12 +#6#12'Frozen rows:'#12'FocusControl'#7#12'EdFrozenRows'#11'ParentColor'#8#0#0
+'TPageControl'#12'PageControl1'#4'Left'#2#0#6'Height'#3#250#0#3'Top'#2':'#5 +#0#12'TPageControl'#12'PageControl1'#4'Left'#2#0#6'Height'#3#255#0#3'Top'#2
+'Width'#3'|'#2#10'ActivePage'#7#9'TabSheet1'#5'Align'#7#8'alClient'#8'TabInd' +':'#5'Width'#3'|'#2#10'ActivePage'#7#9'TabSheet1'#5'Align'#7#8'alClient'#8'T'
+'ex'#2#0#8'TabOrder'#2#1#8'OnChange'#7#18'PageControl1Change'#0#9'TTabSheet' +'abIndex'#2#0#8'TabOrder'#2#1#8'OnChange'#7#18'PageControl1Change'#0#9'TTabS'
+#9'TabSheet1'#7'Caption'#6#6'Sheet1'#12'ClientHeight'#3#217#0#11'ClientWidth' +'heet'#9'TabSheet1'#7'Caption'#6#6'Sheet1'#12'ClientHeight'#3#227#0#11'Clien'
+#3't'#2#0#15'TsWorksheetGrid'#15'sWorksheetGrid1'#4'Left'#2#0#6'Height'#3#217 +'tWidth'#3't'#2#0#15'TsWorksheetGrid'#15'sWorksheetGrid1'#4'Left'#2#0#6'Heig'
+#0#3'Top'#2#0#5'Width'#3't'#2#10'FrozenCols'#2#0#10'FrozenRows'#2#0#5'Align' +'ht'#3#227#0#3'Top'#2#0#5'Width'#3't'#2#10'FrozenCols'#2#0#10'FrozenRows'#2#0
+#7#8'alClient'#8'ColCount'#2#2#14'ExtendedSelect'#8#7'Options'#11#15'goFixed' +#5'Align'#7#8'alClient'#8'ColCount'#2#2#14'ExtendedSelect'#8#7'Options'#11#15
+'VertLine'#15'goFixedHorzLine'#10'goVertLine'#10'goHorzLine'#13'goRangeSelec' +'goFixedVertLine'#15'goFixedHorzLine'#10'goVertLine'#10'goHorzLine'#13'goRan'
+'t'#11'goRowSizing'#11'goColSizing'#15'goThumbTracking'#14'goSmoothScroll'#16 +'geSelect'#11'goRowSizing'#11'goColSizing'#15'goThumbTracking'#14'goSmoothSc'
+'goFixedColSizing'#0#8'RowCount'#2#2#8'TabOrder'#2#0#10'TitleStyle'#7#8'tsNa' +'roll'#16'goFixedColSizing'#0#8'RowCount'#2#2#8'TabOrder'#2#0#10'TitleStyle'
+'tive'#12'OnSelectCell'#7#25'sWorksheetGrid1SelectCell'#9'ColWidths'#1#2'8'#2 +#7#8'tsNative'#12'OnSelectCell'#7#25'sWorksheetGrid1SelectCell'#9'ColWidths'
+'@'#0#0#0#0#0#8'TToolBar'#8'ToolBar1'#4'Left'#2#0#6'Height'#2#26#3'Top'#2#0#5 +#1#2'*'#2'@'#0#0#0#0#0#8'TToolBar'#8'ToolBar1'#4'Left'#2#0#6'Height'#2#26#3
+'Width'#3'|'#2#12'ButtonHeight'#2#24#7'Caption'#6#8'ToolBar1'#11'EdgeBorders' +'Top'#2#0#5'Width'#3'|'#2#12'ButtonHeight'#2#24#7'Caption'#6#8'ToolBar1'#11
+#11#0#6'Images'#7#10'ImageList1'#8'TabOrder'#2#2#0#11'TToolButton'#11'ToolBu' +'EdgeBorders'#11#0#6'Images'#7#10'ImageList1'#8'TabOrder'#2#2#0#11'TToolButt'
+'tton1'#4'Left'#2#1#3'Top'#2#0#6'Action'#7#6'AcOpen'#0#0#11'TToolButton'#11 +'on'#11'ToolButton1'#4'Left'#2#1#3'Top'#2#0#6'Action'#7#6'AcOpen'#0#0#11'TTo'
+'ToolButton2'#4'Left'#2#24#3'Top'#2#0#6'Action'#7#8'AcSaveAs'#0#0#11'TToolBu' +'olButton'#11'ToolButton2'#4'Left'#2#24#3'Top'#2#0#6'Action'#7#8'AcSaveAs'#0
+'tton'#11'ToolButton3'#4'Left'#2'P'#3'Top'#2#0#6'Action'#7#6'AcQuit'#0#0#11 +#0#11'TToolButton'#11'ToolButton3'#4'Left'#2'P'#3'Top'#2#0#6'Action'#7#6'AcQ'
+'TToolButton'#11'ToolButton5'#4'Left'#2'/'#3'Top'#2#0#5'Width'#2#5#7'Caption' +'uit'#0#0#11'TToolButton'#11'ToolButton5'#4'Left'#2'/'#3'Top'#2#0#5'Width'#2
+#6#11'ToolButton5'#5'Style'#7#10'tbsDivider'#0#0#11'TToolButton'#11'ToolButt' +#5#7'Caption'#6#11'ToolButton5'#5'Style'#7#10'tbsDivider'#0#0#11'TToolButton'
+'on4'#4'Left'#2'4'#3'Top'#2#0#6'Action'#7#6'AcEdit'#0#0#11'TToolButton'#11'T' +#11'ToolButton4'#4'Left'#2'4'#3'Top'#2#0#6'Action'#7#6'AcEdit'#0#0#11'TToolB'
+'oolButton6'#4'Left'#2'K'#3'Top'#2#0#5'Width'#2#5#7'Caption'#6#11'ToolButton' +'utton'#11'ToolButton6'#4'Left'#2'K'#3'Top'#2#0#5'Width'#2#5#7'Caption'#6#11
+'6'#5'Style'#7#10'tbsDivider'#0#0#0#8'TToolBar'#13'FormatToolBar'#4'Left'#2#0 +'ToolButton6'#5'Style'#7#10'tbsDivider'#0#0#0#8'TToolBar'#13'FormatToolBar'#4
+#3'Top'#2#26#5'Width'#3'|'#2#12'ButtonHeight'#2#28#7'Caption'#6#13'FormatToo' +'Left'#2#0#3'Top'#2#26#5'Width'#3'|'#2#12'ButtonHeight'#2#28#7'Caption'#6#13
+'lBar'#6'Images'#7#10'ImageList1'#8'TabOrder'#2#3#0#11'TToolButton'#12'ToolB' +'FormatToolBar'#6'Images'#7#10'ImageList1'#8'TabOrder'#2#3#0#11'TToolButton'
+'utton10'#4'Left'#3#17#1#3'Top'#2#2#6'Action'#7#11'AcLeftAlign'#0#0#11'TTool' +#12'ToolButton10'#4'Left'#3#17#1#3'Top'#2#2#6'Action'#7#11'AcLeftAlign'#0#0
+'Button'#12'ToolButton12'#4'Left'#3'('#1#3'Top'#2#2#6'Action'#7#16'AcHorCent' +#11'TToolButton'#12'ToolButton12'#4'Left'#3'('#1#3'Top'#2#2#6'Action'#7#16'A'
+'erAlign'#0#0#11'TToolButton'#12'ToolButton13'#4'Left'#3'?'#1#3'Top'#2#2#6'A' +'cHorCenterAlign'#0#0#11'TToolButton'#12'ToolButton13'#4'Left'#3'?'#1#3'Top'
+'ction'#7#12'AcRightAlign'#0#0#9'TComboBox'#12'FontComboBox'#4'Left'#2#1#6'H' +#2#2#6'Action'#7#12'AcRightAlign'#0#0#9'TComboBox'#12'FontComboBox'#4'Left'#2
+'eight'#2#28#3'Top'#2#2#5'Width'#2#127#10'ItemHeight'#2#20#8'OnSelect'#7#18 +#1#6'Height'#2#23#3'Top'#2#2#5'Width'#2#127#10'ItemHeight'#2#15#8'OnSelect'#7
+'FontComboBoxSelect'#8'TabOrder'#2#0#0#0#9'TComboBox'#16'FontSizeComboBox'#4 +#18'FontComboBoxSelect'#8'TabOrder'#2#0#0#0#9'TComboBox'#16'FontSizeComboBox'
+'Left'#3#128#0#6'Height'#2#28#3'Top'#2#2#5'Width'#2'0'#10'ItemHeight'#2#20#13 +#4'Left'#3#128#0#6'Height'#2#23#3'Top'#2#2#5'Width'#2'0'#10'ItemHeight'#2#15
+'Items.Strings'#1#6#1'8'#6#1'9'#6#2'10'#6#2'11'#6#2'12'#6#2'14'#6#2'16'#6#2 +#13'Items.Strings'#1#6#1'8'#6#1'9'#6#2'10'#6#2'11'#6#2'12'#6#2'14'#6#2'16'#6
+'18'#6#2'20'#6#2'24'#0#8'OnSelect'#7#18'FontComboBoxSelect'#8'TabOrder'#2#1#0 +#2'18'#6#2'20'#6#2'24'#0#8'OnSelect'#7#18'FontComboBoxSelect'#8'TabOrder'#2#1
+#0#11'TToolButton'#11'ToolButton7'#4'Left'#3#176#0#3'Top'#2#2#6'Action'#7#10 +#0#0#11'TToolButton'#11'ToolButton7'#4'Left'#3#176#0#3'Top'#2#2#6'Action'#7
+'AcFontBold'#0#0#11'TToolButton'#11'ToolButton8'#4'Left'#3#199#0#3'Top'#2#2#6 +#10'AcFontBold'#0#0#11'TToolButton'#11'ToolButton8'#4'Left'#3#199#0#3'Top'#2
+'Action'#7#12'AcFontItalic'#0#0#11'TToolButton'#11'ToolButton9'#4'Left'#3#222 +#2#6'Action'#7#12'AcFontItalic'#0#0#11'TToolButton'#11'ToolButton9'#4'Left'#3
+#0#3'Top'#2#2#6'Action'#7#15'AcFontUnderline'#0#0#11'TToolButton'#12'ToolBut' +#222#0#3'Top'#2#2#6'Action'#7#15'AcFontUnderline'#0#0#11'TToolButton'#12'Too'
+'ton11'#4'Left'#3#245#0#3'Top'#2#2#6'Action'#7#15'AcFontStrikeout'#0#0#11'TT' +'lButton11'#4'Left'#3#245#0#3'Top'#2#2#6'Action'#7#15'AcFontStrikeout'#0#0#11
+'oolButton'#12'ToolButton14'#4'Left'#3#12#1#3'Top'#2#2#5'Width'#2#5#7'Captio' +'TToolButton'#12'ToolButton14'#4'Left'#3#12#1#3'Top'#2#2#5'Width'#2#5#7'Capt'
+'n'#6#12'ToolButton14'#5'Style'#7#10'tbsDivider'#0#0#11'TToolButton'#12'Tool' +'ion'#6#12'ToolButton14'#5'Style'#7#10'tbsDivider'#0#0#11'TToolButton'#12'To'
+'Button15'#4'Left'#3'V'#1#3'Top'#2#2#5'Width'#2#5#7'Caption'#6#12'ToolButton' +'olButton15'#4'Left'#3'V'#1#3'Top'#2#2#5'Width'#2#5#7'Caption'#6#12'ToolButt'
+'15'#5'Style'#7#10'tbsDivider'#0#0#11'TToolButton'#12'ToolButton16'#4'Left'#3 +'on15'#5'Style'#7#10'tbsDivider'#0#0#11'TToolButton'#12'ToolButton16'#4'Left'
+'['#1#3'Top'#2#2#6'Action'#7#11'AcVAlignTop'#0#0#11'TToolButton'#12'ToolButt' +#3'['#1#3'Top'#2#2#6'Action'#7#11'AcVAlignTop'#0#0#11'TToolButton'#12'ToolBu'
+'on17'#4'Left'#3'r'#1#3'Top'#2#2#6'Action'#7#14'AcVAlignCenter'#0#0#11'TTool' +'tton17'#4'Left'#3'r'#1#3'Top'#2#2#6'Action'#7#14'AcVAlignCenter'#0#0#11'TTo'
,'Button'#12'ToolButton18'#4'Left'#3#137#1#3'Top'#2#2#6'Action'#7#14'AcVAlign' ,'olButton'#12'ToolButton18'#4'Left'#3#137#1#3'Top'#2#2#6'Action'#7#14'AcVAli'
+'Bottom'#0#0#11'TToolButton'#12'ToolButton19'#4'Left'#3#160#1#3'Top'#2#2#5'W' +'gnBottom'#0#0#11'TToolButton'#12'ToolButton19'#4'Left'#3#160#1#3'Top'#2#2#5
+'idth'#2#5#7'Caption'#6#12'ToolButton19'#5'Style'#7#10'tbsDivider'#0#0#11'TT' +'Width'#2#5#7'Caption'#6#12'ToolButton19'#5'Style'#7#10'tbsDivider'#0#0#11'T'
+'oolButton'#12'ToolButton20'#4'Left'#3#165#1#3'Top'#2#2#6'Action'#7#12'AcBor' +'ToolButton'#12'ToolButton20'#4'Left'#3#165#1#3'Top'#2#2#6'Action'#7#12'AcBo'
+'derLeft'#0#0#11'TToolButton'#12'ToolButton21'#4'Left'#3#188#1#3'Top'#2#2#6 +'rderLeft'#0#0#11'TToolButton'#12'ToolButton21'#4'Left'#3#188#1#3'Top'#2#2#6
+'Action'#7#11'AcBorderTop'#0#0#11'TToolButton'#12'ToolButton22'#4'Left'#3#211 +'Action'#7#11'AcBorderTop'#0#0#11'TToolButton'#12'ToolButton22'#4'Left'#3#211
+#1#3'Top'#2#2#6'Action'#7#14'AcBorderBottom'#0#0#11'TToolButton'#12'ToolButt' +#1#3'Top'#2#2#6'Action'#7#14'AcBorderBottom'#0#0#11'TToolButton'#12'ToolButt'
+'on23'#4'Left'#3#234#1#3'Top'#2#2#6'Action'#7#17'AcBorderBottomDbl'#0#0#11'T' +'on23'#4'Left'#3#234#1#3'Top'#2#2#6'Action'#7#17'AcBorderBottomDbl'#0#0#11'T'

View File

@ -330,9 +330,11 @@ type
FTopPaneHeight: Integer; FTopPaneHeight: Integer;
FOptions: TsSheetOptions; FOptions: TsSheetOptions;
FOnChangeCell: TsCellEvent; FOnChangeCell: TsCellEvent;
FOnChangeFont: TsCellEvent;
procedure RemoveCallback(data, arg: pointer); procedure RemoveCallback(data, arg: pointer);
protected protected
procedure ChangedCell(ARow, ACol: Cardinal); procedure ChangedCell(ARow, ACol: Cardinal);
procedure ChangedFont(ARow, ACol: Cardinal);
public public
Name: string; Name: string;
{ Base methods } { Base methods }
@ -410,6 +412,7 @@ type
property LeftPaneWidth: Integer read FLeftPaneWidth write FLeftPaneWidth; property LeftPaneWidth: Integer read FLeftPaneWidth write FLeftPaneWidth;
property TopPaneHeight: Integer read FTopPaneHeight write FTopPaneHeight; property TopPaneHeight: Integer read FTopPaneHeight write FTopPaneHeight;
property OnChangeCell: TsCellEvent read FOnChangeCell write FOnChangeCell; property OnChangeCell: TsCellEvent read FOnChangeCell write FOnChangeCell;
property OnChangeFont: TsCellEvent read FOnChangeFont write FOnChangeFont;
end; end;
@ -870,6 +873,13 @@ begin
if Assigned(FOnChangeCell) then FOnChangeCell(Self, ARow, ACol); if Assigned(FOnChangeCell) then FOnChangeCell(Self, ARow, ACol);
end; end;
{ Is called whenever a font height changes. Event can be caught by the grid
to update the row height. }
procedure TsWorksheet.ChangedFont(ARow, ACol: Cardinal);
begin
if Assigned(FonChangeFont) then FOnChangeFont(Self, ARow, ACol);
end;
procedure TsWorksheet.CopyCell(AFromRow, AFromCol, AToRow, AToCol: Cardinal; procedure TsWorksheet.CopyCell(AFromRow, AFromCol, AToRow, AToCol: Cardinal;
AFromWorksheet: TsWorksheet); AFromWorksheet: TsWorksheet);
var var
@ -1466,7 +1476,7 @@ begin
if Result = -1 then if Result = -1 then
result := FWorkbook.AddFont(AFontName, AFontSize, AFontStyle, AFontColor); result := FWorkbook.AddFont(AFontName, AFontSize, AFontStyle, AFontColor);
lCell^.FontIndex := Result; lCell^.FontIndex := Result;
ChangedCell(ARow, ACol); ChangedFont(ARow, ACol);
end; end;
procedure TsWorksheet.WriteFont(ARow, ACol: Cardinal; AFontIndex: Integer); procedure TsWorksheet.WriteFont(ARow, ACol: Cardinal; AFontIndex: Integer);
@ -1479,7 +1489,7 @@ begin
lCell := GetCell(ARow, ACol); lCell := GetCell(ARow, ACol);
Include(lCell^.UsedFormattingFields, uffFont); Include(lCell^.UsedFormattingFields, uffFont);
lCell^.FontIndex := AFontIndex; lCell^.FontIndex := AFontIndex;
ChangedCell(ARow, ACol); ChangedFont(ARow, ACol);
end else end else
raise Exception.Create(lpInvalidFontIndex); raise Exception.Create(lpInvalidFontIndex);
end; end;
@ -1532,7 +1542,7 @@ begin
ACell := GetCell(ARow, ACol); ACell := GetCell(ARow, ACol);
Include(ACell^.UsedFormattingFields, uffTextRotation); Include(ACell^.UsedFormattingFields, uffTextRotation);
ACell^.TextRotation := ARotation; ACell^.TextRotation := ARotation;
ChangedCell(ARow, ACol); ChangedFont(ARow, ACol);
end; end;
procedure TsWorksheet.WriteUsedFormatting(ARow, ACol: Cardinal; procedure TsWorksheet.WriteUsedFormatting(ARow, ACol: Cardinal;

View File

@ -35,6 +35,7 @@ type
function CalcColWidth(AWidth: Single): Integer; function CalcColWidth(AWidth: Single): Integer;
function CalcRowHeight(AHeight: Single): Integer; function CalcRowHeight(AHeight: Single): Integer;
procedure ChangedCellHandler(ASender: TObject; ARow, ACol: Cardinal); procedure ChangedCellHandler(ASender: TObject; ARow, ACol: Cardinal);
procedure ChangedFontHandler(ASender: TObject; ARow, ACol: Cardinal);
function GetShowGridLines: Boolean; function GetShowGridLines: Boolean;
function GetShowHeaders: Boolean; function GetShowHeaders: Boolean;
procedure SetFrozenCols(AValue: Integer); procedure SetFrozenCols(AValue: Integer);
@ -51,6 +52,7 @@ type
function GetCellHeight(ACol, ARow: Integer): Integer; function GetCellHeight(ACol, ARow: Integer): Integer;
function GetCellText(ACol, ARow: Integer): String; function GetCellText(ACol, ARow: Integer): String;
function GetEditText(ACol, ARow: Integer): String; override; function GetEditText(ACol, ARow: Integer): String; override;
procedure HeaderSized(IsColumn: Boolean; index: Integer); override;
procedure KeyDown(var Key : Word; Shift : TShiftState); override; procedure KeyDown(var Key : Word; Shift : TShiftState); override;
procedure Loaded; override; procedure Loaded; override;
procedure LoadFromWorksheet(AWorksheet: TsWorksheet); procedure LoadFromWorksheet(AWorksheet: TsWorksheet);
@ -314,19 +316,21 @@ begin
inc(FLockCount); inc(FLockCount);
end; end;
// Converts the column width, given in "characters", to pixels // Converts the column width, given in "characters" of the default font, to pixels
// All chars are assumed to have the same width defined by the "0". // All chars are assumed to have the same width defined by the "0".
// Therefore, this calculation is only approximate. // Therefore, this calculation is only approximate.
function TsCustomWorksheetGrid.CalcColWidth(AWidth: Single): Integer; function TsCustomWorksheetGrid.CalcColWidth(AWidth: Single): Integer;
var var
w0: Integer; w0: Integer;
begin begin
Convert_sFont_to_Font(FWorkbook.GetFont(0), Canvas.Font);
w0 := Canvas.TextWidth('0'); w0 := Canvas.TextWidth('0');
Result := Round(AWidth * w0); Result := Round(AWidth * w0);
end; end;
{ Finds the max cell height per row and uses this to define the RowHeights[]. { Finds the max cell height per row and uses this to define the RowHeights[].
Returns DefaultRowHeight if the row does not contain any cells. } Returns DefaultRowHeight if the row does not contain any cells.
ARow is a grid row index. }
function TsCustomWorksheetGrid.CalcAutoRowHeight(ARow: Integer): Integer; function TsCustomWorksheetGrid.CalcAutoRowHeight(ARow: Integer): Integer;
var var
c: Integer; c: Integer;
@ -352,6 +356,26 @@ begin
if FLockCount = 0 then Invalidate; if FLockCount = 0 then Invalidate;
end; end;
{ Handler for the event that the font has changed in a given cell.
As a consequence, the row height may have to be adapted.
Row/Col coordinates are in worksheet units here! }
procedure TsCustomWorksheetGrid.ChangedFontHandler(ASender: TObject; ARow, ACol: Cardinal);
var
h: Integer;
lRow: PRow;
begin
if (FWorksheet <> nil) then begin
lRow := FWorksheet.FindRow(ARow);
if lRow = nil then begin
// There is no row record --> row height changes according to font height
// Otherwise the row height would be fixed according to the value in the row record.
ARow := ARow + FHeaderCount; // convert row index to grid units
RowHeights[ARow] := CalcAutoRowHeight(ARow);
end;
Invalidate;
end;
end;
{ Converts a spreadsheet font to a font used for painting (TCanvas.Font). } { Converts a spreadsheet font to a font used for painting (TCanvas.Font). }
procedure TsCustomWorksheetGrid.Convert_sFont_to_Font(sFont: TsFont; AFont: TFont); procedure TsCustomWorksheetGrid.Convert_sFont_to_Font(sFont: TsFont; AFont: TFont);
begin begin
@ -880,7 +904,7 @@ begin
end; end;
{ Returns the height (in pixels) of the cell at ACol/ARow. } { Returns the height (in pixels) of the cell at ACol/ARow (of the grid). }
function TsCustomWorksheetGrid.GetCellHeight(ACol, ARow: Integer): Integer; function TsCustomWorksheetGrid.GetCellHeight(ACol, ARow: Integer): Integer;
var var
lCell: PCell; lCell: PCell;
@ -1009,16 +1033,46 @@ begin
Result := FHeaderCount <> 0; Result := FHeaderCount <> 0;
end; end;
{ Calculates the index of the worksheet column that is displayed in the
given column of the grid. If the sheet headers are turned on, both numbers
differ by 1, otherwise they are equal. Saves an "if" in cases. }
function TsCustomWorksheetGrid.GetWorksheetCol(AGridCol: Integer): cardinal; function TsCustomWorksheetGrid.GetWorksheetCol(AGridCol: Integer): cardinal;
begin begin
Result := AGridCol - FHeaderCount; Result := AGridCol - FHeaderCount;
end; end;
{ Calculates the index of the worksheet row that is displayed in the
given row of the grid. If the sheet headers are turned on, both numbers
differ by 1, otherwise they are equal. Save an "if" in cases. }
function TsCustomWorksheetGrid.GetWorksheetRow(AGridRow: Integer): Cardinal; function TsCustomWorksheetGrid.GetWorksheetRow(AGridRow: Integer): Cardinal;
begin begin
Result := AGridRow - FHeaderCount; Result := AGridRow - FHeaderCount;
end; end;
{ Column width or row heights have changed. Stores the new number in the
worksheet. }
procedure TsCustomWorksheetGrid.HeaderSized(IsColumn: Boolean; index: Integer);
var
w0: Integer;
h: Single;
begin
if FWorksheet = nil then
exit;
Convert_sFont_to_Font(FWorkbook.GetFont(0), Canvas.Font);
if IsColumn then begin
// The grid's column width is in "pixels", the worksheet's column width is
// in "characters".
w0 := Canvas.TextWidth('0');
FWorksheet.WriteColWidth(GetWorksheetCol(Index), ColWidths[Index] div w0);
end else begin
// The grid's row heights are in "pixels", the worksheet's row heights are
// in millimeters.
h := (RowHeights[Index] - 2*constCellPadding) / Screen.PixelsPerInch * 25.4;
FWorksheet.WriteRowHeight(GetWorksheetRow(Index), h);
end;
end;
{ Catches the ESC key during editing in order to restore the old cell text } { Catches the ESC key during editing in order to restore the old cell text }
procedure TsCustomWorksheetGrid.KeyDown(var Key : Word; Shift : TShiftState); procedure TsCustomWorksheetGrid.KeyDown(var Key : Word; Shift : TShiftState);
begin begin
@ -1034,8 +1088,8 @@ begin
Setup; Setup;
end; end;
{ Is called when editing starts. Stores the old text just in case the user { Is called when editing starts. Stores the old text just for the case that
presses ESC to cancel editing. } the user presses ESC to cancel editing. }
procedure TsCustomWorksheetGrid.SelectEditor; procedure TsCustomWorksheetGrid.SelectEditor;
begin begin
FOldEditText := GetCellText(Col, Row); FOldEditText := GetCellText(Col, Row);
@ -1134,6 +1188,7 @@ begin
FWorksheet := AWorksheet; FWorksheet := AWorksheet;
if FWorksheet <> nil then begin if FWorksheet <> nil then begin
FWorksheet.OnChangeCell := @ChangedCellHandler; FWorksheet.OnChangeCell := @ChangedCellHandler;
FWorksheet.OnChangeFont := @ChangedFontHandler;
ShowHeaders := (soShowHeaders in FWorksheet.Options); ShowHeaders := (soShowHeaders in FWorksheet.Options);
ShowGridLines := (soShowGridLines in FWorksheet.Options); ShowGridLines := (soShowGridLines in FWorksheet.Options);
if (soHasFrozenPanes in FWorksheet.Options) then begin if (soHasFrozenPanes in FWorksheet.Options) then begin