fpspreadsheet: Extend TsCellCombobox to handle several formatting items - will replace Fontname and FontSize combox. Not working correctly, yet. Update fpsctrls demos.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@3790 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2014-11-26 23:45:09 +00:00
parent 74caad60e4
commit ae6efc0f98
8 changed files with 1483 additions and 900 deletions

File diff suppressed because it is too large Load Diff

View File

@ -6,7 +6,7 @@ interface
uses uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls, Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
ComCtrls, ActnList, Menus, StdActns, ComCtrls, ActnList, Menus, StdActns, //ColorBox, StdCtrls,
fpspreadsheet, fpspreadsheetctrls, fpspreadsheetgrid, fpsActions; fpspreadsheet, fpspreadsheetctrls, fpspreadsheetgrid, fpsActions;
type type
@ -187,6 +187,10 @@ type
AcCellBorderAllVert: TsCellBorderAction; AcCellBorderAllVert: TsCellBorderAction;
FontnameCombo: TsFontnameCombobox; FontnameCombo: TsFontnameCombobox;
AcCopyFormat: TsCopyFormatAction; AcCopyFormat: TsCopyFormatAction;
FontColorCombobox: TsCellCombobox;
BackgroundColorCombobox: TsCellCombobox;
sCellCombobox3: TsCellCombobox;
sCellCombobox4: TsCellCombobox;
sFontSizeCombobox1: TsFontSizeCombobox; sFontSizeCombobox1: TsFontSizeCombobox;
AcMergeCells: TsMergeAction; AcMergeCells: TsMergeAction;
Splitter2: TSplitter; Splitter2: TSplitter;

View File

@ -155,7 +155,8 @@ var
actn: TCustomAction; actn: TCustomAction;
begin begin
WorkbookSource := TsWorkbookSource.Create(self); WorkbookSource := TsWorkbookSource.Create(self);
with WorkbookSource do begin with WorkbookSource do
begin
Options := [boReadFormulas, boAutoCalc]; Options := [boReadFormulas, boAutoCalc];
end; end;
@ -178,7 +179,8 @@ begin
end; end;
CellIndicator := TsCellIndicator.Create(self); CellIndicator := TsCellIndicator.Create(self);
with CellIndicator do begin with CellIndicator do
begin
Parent := Panel1; Parent := Panel1;
Left := BtnLoad.Left + BtnLoad.Width + 24; Left := BtnLoad.Left + BtnLoad.Width + 24;
Top := BtnLoad.Top; Top := BtnLoad.Top;
@ -186,7 +188,8 @@ begin
end; end;
CellEdit := TsCellEdit.Create(self); CellEdit := TsCellEdit.Create(self);
with CellEdit do begin with CellEdit do
begin
Parent := Panel1; Parent := Panel1;
Left := CellIndicator.Left + CellIndicator.Width + 24; Left := CellIndicator.Left + CellIndicator.Width + 24;
Top := CellIndicator.Top; Top := CellIndicator.Top;
@ -194,14 +197,16 @@ begin
end; end;
Inspector := TsSpreadsheetInspector.Create(self); Inspector := TsSpreadsheetInspector.Create(self);
with Inspector do begin with Inspector do
begin
Parent := InspectorTabControl; Parent := InspectorTabControl;
Align := alClient; Align := alClient;
WorkbookSource := Self.WorkbookSource; WorkbookSource := Self.WorkbookSource;
end; end;
actn := TsWorksheetAddAction.Create(self); actn := TsWorksheetAddAction.Create(self);
with TsWorksheetAddAction(actn) do begin with TsWorksheetAddAction(actn) do
begin
ActionList := self.ActionList; ActionList := self.ActionList;
Caption := 'Add'; Caption := 'Add';
Hint := 'Add worksheet'; Hint := 'Add worksheet';
@ -210,7 +215,8 @@ begin
MnuAddWorksheet.Action := actn; MnuAddWorksheet.Action := actn;
actn := TsWorksheetDeleteAction.Create(self); actn := TsWorksheetDeleteAction.Create(self);
with TsWorksheetDeleteAction(actn) do begin with TsWorksheetDeleteAction(actn) do
begin
ActionList := self.ActionList; ActionList := self.ActionList;
Caption := 'Delete...'; Caption := 'Delete...';
Hint := 'Delete worksheet'; Hint := 'Delete worksheet';
@ -219,7 +225,8 @@ begin
MnuDeleteWorksheet.Action := actn; MnuDeleteWorksheet.Action := actn;
actn := TsWorksheetRenameAction.Create(self); actn := TsWorksheetRenameAction.Create(self);
with TsWorksheetRenameAction(actn) do begin with TsWorksheetRenameAction(actn) do
begin
ActionList := self.ActionList; ActionList := self.ActionList;
Caption := 'Rename...'; Caption := 'Rename...';
Hint := 'Rename worksheet'; Hint := 'Rename worksheet';
@ -228,14 +235,37 @@ begin
MnuRenameWorksheet.Action := actn; MnuRenameWorksheet.Action := actn;
{ Font names } { Font names }
with TsFontnameCombobox.Create(self) do begin with TsCellCombobox.Create(self) do
begin
// with TsFontnameCombobox.Create(self) do begin
Parent := Toolbar1; Parent := Toolbar1;
WorkbookSource := Self.WorkbookSource; WorkbookSource := Self.WorkbookSource;
Width := 160;
CellFormatItem := cfiFontName;
end;
{ Font size }
with TsCellCombobox.Create(self) do
begin
Parent := Toolbar1;
WorkbookSource := Self.WorkbookSource;
Width := 50;
CellFormatItem := cfiFontSize;
end;
{ Font color }
with TsCellCombobox.Create(self) do
begin
Parent := Toolbar1;
WorkbookSource := Self.WorkbookSource;
Width := 120;
CellFormatItem := cfiFontColor;
end; end;
{ Font styles } { Font styles }
actn := TsFontStyleAction.Create(self); actn := TsFontStyleAction.Create(self);
with TsFontStyleAction(actn) do begin with TsFontStyleAction(actn) do
begin
ActionList := Self.ActionList; ActionList := Self.ActionList;
Caption := 'Bold'; Caption := 'Bold';
Hint := 'Bold'; Hint := 'Bold';
@ -247,7 +277,8 @@ begin
tbBold.Action := actn; tbBold.Action := actn;
actn := TsFontStyleAction.Create(self); actn := TsFontStyleAction.Create(self);
with TsFontStyleAction(actn) do begin with TsFontStyleAction(actn) do
begin
ActionList := Self.ActionList; ActionList := Self.ActionList;
Caption := 'Italic'; Caption := 'Italic';
Hint := 'Italic'; Hint := 'Italic';
@ -259,7 +290,8 @@ begin
TbItalic.Action := actn; TbItalic.Action := actn;
actn := TsFontStyleAction.Create(self); actn := TsFontStyleAction.Create(self);
with TsFontStyleAction(actn) do begin with TsFontStyleAction(actn) do
begin
ActionList := Self.ActionList; ActionList := Self.ActionList;
Caption := 'Underline'; Caption := 'Underline';
Hint := 'Underline'; Hint := 'Underline';
@ -271,7 +303,8 @@ begin
TbUnderline.Action := actn; TbUnderline.Action := actn;
actn := TsFontStyleAction.Create(self); actn := TsFontStyleAction.Create(self);
with TsFontStyleAction(actn) do begin with TsFontStyleAction(actn) do
begin
ActionList := Self.ActionList; ActionList := Self.ActionList;
Caption := 'Strikeout'; Caption := 'Strikeout';
Hint := 'Strikeout'; Hint := 'Strikeout';
@ -284,7 +317,8 @@ begin
{ Horizontal alignments } { Horizontal alignments }
actn := TsHorAlignmentAction.Create(self); actn := TsHorAlignmentAction.Create(self);
with TsHorAlignmentAction(actn) do begin with TsHorAlignmentAction(actn) do
begin
ActionList := self.ActionList; ActionList := self.ActionList;
Caption := 'Left'; Caption := 'Left';
Hint := 'Left-aligned'; Hint := 'Left-aligned';
@ -296,7 +330,8 @@ begin
TbHorAlignLeft.Action := actn; TbHorAlignLeft.Action := actn;
actn := TsHorAlignmentAction.Create(self); actn := TsHorAlignmentAction.Create(self);
with TsHorAlignmentAction(actn) do begin with TsHorAlignmentAction(actn) do
begin
ActionList := self.ActionList; ActionList := self.ActionList;
Caption := 'Center'; Caption := 'Center';
Hint := 'Centered'; Hint := 'Centered';
@ -308,7 +343,8 @@ begin
TbHorAlignCenter.Action := actn; TbHorAlignCenter.Action := actn;
actn := TsHorAlignmentAction.Create(self); actn := TsHorAlignmentAction.Create(self);
with TsHorAlignmentAction(actn) do begin with TsHorAlignmentAction(actn) do
begin
ActionList := self.ActionList; ActionList := self.ActionList;
Caption := 'Right'; Caption := 'Right';
Hint := 'Right-aligned'; Hint := 'Right-aligned';
@ -321,7 +357,8 @@ begin
{ Vertical alignments } { Vertical alignments }
actn := TsVertAlignmentAction.Create(self); actn := TsVertAlignmentAction.Create(self);
with TsVertAlignmentAction(actn) do begin with TsVertAlignmentAction(actn) do
begin
ActionList := self.ActionList; ActionList := self.ActionList;
Caption := 'Top'; Caption := 'Top';
Hint := 'Top-aligned'; Hint := 'Top-aligned';
@ -333,7 +370,8 @@ begin
TbVertAlignTop.Action := actn; TbVertAlignTop.Action := actn;
actn := TsVertAlignmentAction.Create(self); actn := TsVertAlignmentAction.Create(self);
with TsVertAlignmentAction(actn) do begin with TsVertAlignmentAction(actn) do
begin
ActionList := self.ActionList; ActionList := self.ActionList;
Caption := 'Middle'; Caption := 'Middle';
Hint := 'Middle'; Hint := 'Middle';
@ -345,7 +383,8 @@ begin
TbVertAlignCenter.Action := actn; TbVertAlignCenter.Action := actn;
actn := TsVertAlignmentAction.Create(self); actn := TsVertAlignmentAction.Create(self);
with TsVertAlignmentAction(actn) do begin with TsVertAlignmentAction(actn) do
begin
ActionList := self.ActionList; ActionList := self.ActionList;
Caption := 'Bottom'; Caption := 'Bottom';
Hint := 'Bottom-aligned'; Hint := 'Bottom-aligned';
@ -358,7 +397,8 @@ begin
{ Text rotation } { Text rotation }
actn := TsTextRotationAction.Create(self); actn := TsTextRotationAction.Create(self);
with TsTextRotationAction(actn) do begin with TsTextRotationAction(actn) do
begin
ActionList := self.ActionList; ActionList := self.ActionList;
Caption := 'Horizontal'; Caption := 'Horizontal';
Hint := 'Horizontal text'; Hint := 'Horizontal text';
@ -368,7 +408,8 @@ begin
MnuTextRotHor.Action := actn; MnuTextRotHor.Action := actn;
actn := TsTextRotationAction.Create(self); actn := TsTextRotationAction.Create(self);
with TsTextRotationAction(actn) do begin with TsTextRotationAction(actn) do
begin
ActionList := self.ActionList; ActionList := self.ActionList;
Caption := '90° clockwise rotation'; Caption := '90° clockwise rotation';
Hint := '90° clockwise rotated text'; Hint := '90° clockwise rotated text';
@ -378,7 +419,8 @@ begin
MnuTextRot90CW.Action := actn; MnuTextRot90CW.Action := actn;
actn := TsTextRotationAction.Create(self); actn := TsTextRotationAction.Create(self);
with TsTextRotationAction(actn) do begin with TsTextRotationAction(actn) do
begin
ActionList := self.ActionList; ActionList := self.ActionList;
Caption := '90° couner-clockwise rotation'; Caption := '90° couner-clockwise rotation';
Hint := '90° counter-clockwise rotated text'; Hint := '90° counter-clockwise rotated text';
@ -388,7 +430,8 @@ begin
MnuTextRot90CCW.Action := actn; MnuTextRot90CCW.Action := actn;
actn := TsTextRotationAction.Create(self); actn := TsTextRotationAction.Create(self);
with TsTextRotationAction(actn) do begin with TsTextRotationAction(actn) do
begin
ActionList := self.ActionList; ActionList := self.ActionList;
Caption := 'Stacked'; Caption := 'Stacked';
Hint := 'Stacked text'; Hint := 'Stacked text';
@ -399,7 +442,8 @@ begin
{ Word wrap } { Word wrap }
actn := TsWordwrapAction.Create(self); actn := TsWordwrapAction.Create(self);
with TsWordwrapAction(actn) do begin with TsWordwrapAction(actn) do
begin
ActionList := self.ActionList; ActionList := self.ActionList;
Caption := 'Word-wrap'; Caption := 'Word-wrap';
Hint := 'Word-wrapped text'; Hint := 'Word-wrapped text';
@ -410,7 +454,8 @@ begin
{ Number format } { Number format }
actn := TsNumberFormatAction.Create(self); actn := TsNumberFormatAction.Create(self);
with TsNumberFormatAction(actn) do begin with TsNumberFormatAction(actn) do
begin
ActionList := self.ActionList; ActionList := self.ActionList;
Caption := 'General'; Caption := 'General';
Hint := 'General'; Hint := 'General';
@ -420,7 +465,8 @@ begin
MnuNumFormatGeneral.Action := actn; MnuNumFormatGeneral.Action := actn;
actn := TsNumberFormatAction.Create(self); actn := TsNumberFormatAction.Create(self);
with TsNumberFormatAction(actn) do begin with TsNumberFormatAction(actn) do
begin
ActionList := self.ActionList; ActionList := self.ActionList;
Caption := 'Fixed'; Caption := 'Fixed';
Hint := 'Fixed decimals'; Hint := 'Fixed decimals';
@ -430,7 +476,8 @@ begin
MnuNumFormatFixed.Action := actn; MnuNumFormatFixed.Action := actn;
actn := TsNumberFormatAction.Create(self); actn := TsNumberFormatAction.Create(self);
with TsNumberFormatAction(actn) do begin with TsNumberFormatAction(actn) do
begin
ActionList := self.ActionList; ActionList := self.ActionList;
Caption := 'Fixed w/Thousand separator'; Caption := 'Fixed w/Thousand separator';
Hint := 'Fixed decimals with thousand separator'; Hint := 'Fixed decimals with thousand separator';
@ -440,7 +487,8 @@ begin
MnuNumFormatFixedTh.Action := actn; MnuNumFormatFixedTh.Action := actn;
actn := TsNumberFormatAction.Create(self); actn := TsNumberFormatAction.Create(self);
with TsNumberFormatAction(actn) do begin with TsNumberFormatAction(actn) do
begin
ActionList := self.ActionList; ActionList := self.ActionList;
Caption := 'Exponential'; Caption := 'Exponential';
Hint := 'Exponential'; Hint := 'Exponential';
@ -450,7 +498,8 @@ begin
MnuNumFormatExp.Action := actn; MnuNumFormatExp.Action := actn;
actn := TsNumberFormatAction.Create(self); actn := TsNumberFormatAction.Create(self);
with TsNumberFormatAction(actn) do begin with TsNumberFormatAction(actn) do
begin
ActionList := self.ActionList; ActionList := self.ActionList;
Caption := 'Percentage'; Caption := 'Percentage';
Hint := 'Percentage'; Hint := 'Percentage';
@ -460,7 +509,8 @@ begin
MnuNumFormatPercentage.Action := actn; MnuNumFormatPercentage.Action := actn;
actn := TsNumberFormatAction.Create(self); actn := TsNumberFormatAction.Create(self);
with TsNumberFormatAction(actn) do begin with TsNumberFormatAction(actn) do
begin
ActionList := self.ActionList; ActionList := self.ActionList;
Caption := 'Currency'; Caption := 'Currency';
Hint := 'Currency'; Hint := 'Currency';
@ -470,7 +520,8 @@ begin
MnuNumFormatCurrency.Action := actn; MnuNumFormatCurrency.Action := actn;
actn := TsNumberFormatAction.Create(self); actn := TsNumberFormatAction.Create(self);
with TsNumberFormatAction(actn) do begin with TsNumberFormatAction(actn) do
begin
ActionList := self.ActionList; ActionList := self.ActionList;
Caption := 'Currency (red)'; Caption := 'Currency (red)';
Hint := 'Currency (negative values in red)'; Hint := 'Currency (negative values in red)';
@ -480,7 +531,8 @@ begin
MnuNumFormatCurrencyRed.Action := actn; MnuNumFormatCurrencyRed.Action := actn;
actn := TsNumberFormatAction.Create(self); actn := TsNumberFormatAction.Create(self);
with TsNumberFormatAction(actn) do begin with TsNumberFormatAction(actn) do
begin
ActionList := self.ActionList; ActionList := self.ActionList;
Caption := 'Date and time'; Caption := 'Date and time';
Hint := 'Date and time'; Hint := 'Date and time';
@ -490,7 +542,8 @@ begin
MnuNumFormatShortDateTime.Action := actn; MnuNumFormatShortDateTime.Action := actn;
actn := TsNumberFormatAction.Create(self); actn := TsNumberFormatAction.Create(self);
with TsNumberFormatAction(actn) do begin with TsNumberFormatAction(actn) do
begin
ActionList := self.ActionList; ActionList := self.ActionList;
Caption := 'Long date'; Caption := 'Long date';
Hint := 'Long date'; Hint := 'Long date';
@ -500,7 +553,8 @@ begin
MnuNumFormatLongDate.Action := actn; MnuNumFormatLongDate.Action := actn;
actn := TsNumberFormatAction.Create(self); actn := TsNumberFormatAction.Create(self);
with TsNumberFormatAction(actn) do begin with TsNumberFormatAction(actn) do
begin
ActionList := self.ActionList; ActionList := self.ActionList;
WorkbookSource := Self.WorkbookSource; WorkbookSource := Self.WorkbookSource;
Caption := 'Short date'; Caption := 'Short date';
@ -510,7 +564,8 @@ begin
MnuNumFormatShortDate.Action := actn; MnuNumFormatShortDate.Action := actn;
actn := TsNumberFormatAction.Create(self); actn := TsNumberFormatAction.Create(self);
with TsNumberFormatAction(actn) do begin with TsNumberFormatAction(actn) do
begin
ActionList := self.ActionList; ActionList := self.ActionList;
Caption := 'Long time'; Caption := 'Long time';
Hint := 'Long time'; Hint := 'Long time';
@ -520,7 +575,8 @@ begin
MnuNumFormatLongTime.Action := actn; MnuNumFormatLongTime.Action := actn;
actn := TsNumberFormatAction.Create(self); actn := TsNumberFormatAction.Create(self);
with TsNumberFormatAction(actn) do begin with TsNumberFormatAction(actn) do
begin
ActionList := self.ActionList; ActionList := self.ActionList;
Caption := 'Short time'; Caption := 'Short time';
Hint := 'Short time'; Hint := 'Short time';
@ -530,7 +586,8 @@ begin
MnuNumFormatShortTime.Action := actn; MnuNumFormatShortTime.Action := actn;
actn := TsNumberFormatAction.Create(self); actn := TsNumberFormatAction.Create(self);
with TsNumberFormatAction(actn) do begin with TsNumberFormatAction(actn) do
begin
ActionList := self.ActionList; ActionList := self.ActionList;
Caption := 'Long time AM/PM'; Caption := 'Long time AM/PM';
Hint := 'Long time with AM/PM'; Hint := 'Long time with AM/PM';
@ -540,7 +597,8 @@ begin
MnuNumFormatLongTimeAM.Action := actn; MnuNumFormatLongTimeAM.Action := actn;
actn := TsNumberFormatAction.Create(self); actn := TsNumberFormatAction.Create(self);
with TsNumberFormatAction(actn) do begin with TsNumberFormatAction(actn) do
begin
ActionList := self.ActionList; ActionList := self.ActionList;
WorkbookSource := Self.WorkbookSource; WorkbookSource := Self.WorkbookSource;
Caption := 'Short time AM/PM'; Caption := 'Short time AM/PM';
@ -550,7 +608,8 @@ begin
MnuNumFormatShortTimeAM.Action := actn; MnuNumFormatShortTimeAM.Action := actn;
actn := TsNumberFormatAction.Create(self); actn := TsNumberFormatAction.Create(self);
with TsNumberFormatAction(actn) do begin with TsNumberFormatAction(actn) do
begin
ActionList := self.ActionList; ActionList := self.ActionList;
WorkbookSource := Self.WorkbookSource; WorkbookSource := Self.WorkbookSource;
Caption := 'Time interval'; Caption := 'Time interval';

View File

@ -1031,7 +1031,7 @@ type
{ Color handling } { Color handling }
function AddColorToPalette(AColorValue: TsColorValue): TsColor; function AddColorToPalette(AColorValue: TsColorValue): TsColor;
function FindClosestColor(AColorValue: TsColorValue; function FindClosestColor(AColorValue: TsColorValue;
AMaxPaletteCount: Integer): TsColor; AMaxPaletteCount: Integer = -1): TsColor;
function FPSColorToHexString(AColor: TsColor; ARGBColor: TFPColor): String; function FPSColorToHexString(AColor: TsColor; ARGBColor: TFPColor): String;
function GetColorName(AColorIndex: TsColor): string; overload; function GetColorName(AColorIndex: TsColor): string; overload;
procedure GetColorName(AColorValue: TsColorValue; out AName: String); overload; procedure GetColorName(AColorValue: TsColorValue; out AName: String); overload;
@ -2973,12 +2973,12 @@ end;
function TsWorksheet.ReadBackgroundColor(ACell: PCell): TsColor; function TsWorksheet.ReadBackgroundColor(ACell: PCell): TsColor;
begin begin
if ACell = nil then if ACell = nil then
begin Result := scNotDefined
Result := scNotDefined; else
Exit; if (uffBackgroundColor in ACell^.UsedFormattingFields) then
end; Result := ACell^.BackgroundColor
else
Result := ACell^.BackgroundColor; Result := scTransparent;
end; end;
{@@ ---------------------------------------------------------------------------- {@@ ----------------------------------------------------------------------------
@ -7370,7 +7370,7 @@ end;
@return Palette index of the color closest to AColorValue @return Palette index of the color closest to AColorValue
--------------------------------------------------------------------------------} --------------------------------------------------------------------------------}
function TsWorkbook.FindClosestColor(AColorValue: TsColorValue; function TsWorkbook.FindClosestColor(AColorValue: TsColorValue;
AMaxPaletteCount: Integer): TsColor; AMaxPaletteCount: Integer = -1): TsColor;
type type
TRGBA = record r,g,b, a: Byte end; TRGBA = record r,g,b, a: Byte end;
var var
@ -7383,7 +7383,10 @@ var
begin begin
Result := scNotDefined; Result := scNotDefined;
minDist := 1E108; minDist := 1E108;
n := Min(Length(FPalette), AMaxPaletteCount); if AMaxPaletteCount = -1 then
n := Length(FPalette)
else
n := Min(Length(FPalette), AMaxPaletteCount);
for i:=0 to n-1 do for i:=0 to n-1 do
begin begin
rgb := TRGBA(GetPaletteColor(i)); rgb := TRGBA(GetPaletteColor(i));

View File

@ -167,6 +167,42 @@ LazarusResources.Add('TSCELLINDICATOR','PNG',[
+'Z*u'#230#249'>'#0'74'#141#153#236'M'#0#254#1#147#1'M'#220#4#245'Q'#0#0#0#0#0 +'Z*u'#230#249'>'#0'74'#141#153#236'M'#0#254#1#147#1'M'#220#4#245'Q'#0#0#0#0#0
+'IEND'#174'B`'#130 +'IEND'#174'B`'#130
]); ]);
LazarusResources.Add('TSCELLCOMBOBOX','PNG',[
#137'PNG'#13#10#26#10#0#0#0#13'IHDR'#0#0#0#24#0#0#0#24#8#6#0#0#0#224'w='#248#0
+#0#0#9'pHYs'#0#0#14#196#0#0#14#196#1#149'+'#14#27#0#0#0#7'tIME'#7#222#11#26
+#23#4'-'#148'N}'#145#0#0#0#7'tEXtAuthor'#0#169#174#204'H'#0#0#0#10'tEXtCopyr'
+'ight'#0#172#15#204':'#0#0#0#14'tEXtCreation time'#0'5'#247#15#9#0#0#0#9'tEX'
+'tSoftware'#0']p'#255':'#0#0#0#11'tEXtDisclaimer'#0#183#192#180#143#0#0#0#8
+'tEXtWarning'#0#192#27#230#135#0#0#0#7'tEXtSource'#0#245#255#131#235#0#0#0#8
+'tEXtComment'#0#246#204#150#191#0#0#0#6'tEXtTitle'#0#168#238#210''''#0#0#2'g'
+'IDATH'#137#181#149'QHSQ'#24#199#127'g'#155#137'h'#140#156#169#144#17'2B'#232
+'A1'#139#5'Y'#129#198#194#196#30#10'}'#176#151'F'#209#160'(j'#164'w'#190'E'
+#16#204#22#190#248'f'#193#237'eA'#134'/'#3'['#248' N'#5'_'#162'p'#132#15#134
+#141'HJ%)mdQ'#247#158#30#134'k'#186#187#155'['#249#135#203#189#231';'#223#249
+'~'#231';'#247#156#239#8')%'#219')'#203#182'F'#7'l'#0'~'#127#255#127'K#'#16
+#184'&2'#0'I'#200#249'<'#130#133'6'#140#155#142#205#224#247#247#203't'#136'-'
+'}@S'#147'{'#203#193'GGGR'#223'eeeh'#186'dll'#2#128#232#248#164'<q'#188'Qd'#0
+#210#7#229'"E'#233#193'n'#183#27#246#217#12#173'9h:6'#131#251'TK'#214#254#20
+' '#16#8#165#140'V'#235#194#22#195'W'#18'y'#246#202#212#195#150#12#254#231
+#167#248#253#253#210'lF'#127#211'f'#160#225#18#213#213#30#216'^'#192#186#242
+#221'U['#6#228#187#171#210#149's'#169'H'#252'X'#205#201#223'0'#131#151'/'#140
+'w'#198#187#213'Y'#238'L]'#161#176#0#164'L>?5x'#224#30#193'",xCm'#0#12#169
+#128#138#212#145#230'Kt'#171'['#201'46'#195#13#143#143#165#196'<'#229'%U'#244
+#14#244#209#173#244#240#181'n'#134'3'#173#181')'#183#240'p'#140'9uM'#152#2
+#238#223#235#205#176'}'#254#254#137#219#143#188'\'#189'p'#17#0'Og'#7#131#5#17
+#142#238#222#191'!'#248#27#245'[f'#169'X'#215#193'C'#245'f\'#154#27#223'R'
+#127#215#129'r'#217'GyI'#21#29#237'-'#168#143#7'9'#187#215'Ex8'#198'C'#207#8
+#213']'#194#26#15'J'#237#159'J'#197'Rb~C{'#249#253'Z'#242#189#182'@<('#181
+#172#25#172#203#236#28#236#162#1'U>E'#241#222'd)1'#143#167#179#157#208'`'#152
+'s'#21'A'#28'E'#149')'#191#188#206#129'.5\'#190'} $'#189#3'}x:;'#0'A'#235#225
+#6#158'L]'#167#133#9's@z'#225'3'#210#208#162#130#203'Y'#131#173'X'''#250'!'
+#198#242#202'"'#14'{'#5'ZiA'#134#175'0'#186#244#163#227#147'Y'#175#208'K'#170
+#27#151#179'&9'#187'b'#29#128#241#143#175'i;}'#12#135#189#130#229#149'E'#194
+#195'Q'#226'A)'#178#2#178#201#233')'#146#22#132'a_'#225#30#157#230#147'GR'
+#237#200#243'If'#3#191'DN'#0#128#234'.'#225#140#7#229#220'&'#155#221'j'#177
+'|'#209#244'dF;'#172'VJKv'#2#240#27#31#144#219'n'#231#139#204#3#0#0#0#0'IEND'
+#174'B`'#130
]);
LazarusResources.Add('TSSPREADSHEETINSPECTOR','PNG',[ LazarusResources.Add('TSSPREADSHEETINSPECTOR','PNG',[
#137'PNG'#13#10#26#10#0#0#0#13'IHDR'#0#0#0#24#0#0#0#24#8#6#0#0#0#224'w='#248#0 #137'PNG'#13#10#26#10#0#0#0#13'IHDR'#0#0#0#24#0#0#0#24#8#6#0#0#0#224'w='#248#0
+#0#0#9'pHYs'#0#0#14#196#0#0#14#196#1#149'+'#14#27#0#0#0#7'tIME'#7#222#11#24 +#0#0#9'pHYs'#0#0#14#196#0#0#14#196#1#149'+'#14#27#0#0#0#7'tIME'#7#222#11#24

View File

@ -26,7 +26,7 @@ unit fpspreadsheetctrls;
interface interface
uses uses
Classes, SysUtils, Controls, StdCtrls, ComCtrls, ValEdit, ActnList, Classes, Graphics, SysUtils, Controls, StdCtrls, ComCtrls, ValEdit, ActnList,
LResources, LResources,
fpspreadsheet, {%H-}fpsAllFormats; fpspreadsheet, {%H-}fpsAllFormats;
@ -239,21 +239,38 @@ type
end; end;
{ TsCellFormatItem }
TsCellFormatItem = (cfiFontName, cfiFontSize, cfiFontColor, cfiBackgroundColor,
cfiBorderColor);
{ TsCellCombobox } { TsCellCombobox }
{@@ TsCellCombobox is the ancestor of TsFontNameCombobox and TsFontSizeCombobox } {@@ TsCellCombobox is a multi-purpose combobox for selection of formatting
TsCellCombobox = class(TCombobox) items of a cell }
TsCellCombobox = class(TCustomCombobox)
private private
FWorkbookSource: TsWorkbookSource; FWorkbookSource: TsWorkbookSource;
FFormatItem: TsCellFormatItem;
FColorRectWidth: Integer;
function GetWorkbook: TsWorkbook; function GetWorkbook: TsWorkbook;
function GetWorksheet: TsWorksheet; function GetWorksheet: TsWorksheet;
procedure SetColorRectWidth(AValue: Integer);
procedure SetFormatItem(AValue: TsCellFormatItem);
procedure SetWorkbookSource(AValue: TsWorkbookSource); procedure SetWorkbookSource(AValue: TsWorkbookSource);
// procedure UpdateCombo;
protected protected
procedure ApplyFormatToCell(ACell: PCell); virtual; procedure ApplyFormatToCell(ACell: PCell); virtual;
procedure DrawItem(AIndex: Integer; ARect: TRect;
AState: TOwnerDrawState); override;
procedure ExtractFromCell(ACell: PCell); virtual; procedure ExtractFromCell(ACell: PCell); virtual;
function GetActiveCell: PCell;
// function GetItemHeight: Integer; override;
procedure Loaded; override;
procedure Notification(AComponent: TComponent; Operation: TOperation); override; procedure Notification(AComponent: TComponent; Operation: TOperation); override;
procedure Populate; virtual; procedure Populate; virtual;
procedure Select; override; procedure Select; override;
property Items stored false;
public public
constructor Create(AOwner: TComponent); override; constructor Create(AOwner: TComponent); override;
destructor Destroy; override; destructor Destroy; override;
@ -264,8 +281,82 @@ type
{@@ Refers to the underlying worksheet containing the displayed cell } {@@ Refers to the underlying worksheet containing the displayed cell }
property Worksheet: TsWorksheet read GetWorksheet; property Worksheet: TsWorksheet read GetWorksheet;
published published
{@@ Identifies the cell format property to be used in the combobox }
property CellFormatItem: TsCellFormatItem read FFormatItem write SetFormatItem;
{@@ Width of the color box shown for the color-related format items }
property ColorRectWidth: Integer read FColorRectWidth write SetColorRectWidth default 10;
{@@ Link to the WorkbookSource which provides the workbook and worksheet. } {@@ Link to the WorkbookSource which provides the workbook and worksheet. }
property WorkbookSource: TsWorkbookSource read FWorkbookSource write SetWorkbookSource; property WorkbookSource: TsWorkbookSource read FWorkbookSource write SetWorkbookSource;
{ inherited properties }
property Align;
property Anchors;
property ArrowKeysTraverseList;
property AutoComplete;
property AutoCompleteText;
property AutoDropDown;
property AutoSelect;
property AutoSize;// Note: windows has a fixed height in some styles
property BidiMode;
property BorderSpacing;
property BorderStyle;
property CharCase;
property Color;
property Constraints;
property DragCursor;
property DragKind;
property DragMode;
property DropDownCount;
property Enabled;
property Font;
property ItemHeight;
property ItemIndex;
// property Items;
property ItemWidth;
property MaxLength;
property OnChange;
property OnChangeBounds;
property OnClick;
property OnCloseUp;
property OnContextPopup;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnDrawItem;
property OnEndDrag;
property OnDropDown;
property OnEditingDone;
property OnEnter;
property OnExit;
property OnGetItems;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMeasureItem;
property OnMouseDown;
property OnMouseEnter;
property OnMouseLeave;
property OnMouseMove;
property OnMouseUp;
property OnMouseWheel;
property OnMouseWheelDown;
property OnMouseWheelUp;
property OnSelect;
property OnStartDrag;
property OnUTF8KeyPress;
property ParentBidiMode;
property ParentColor;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ReadOnly;
property ShowHint;
property Sorted;
// property Style;
property TabOrder;
property TabStop;
property Text;
property Visible;
end; end;
@ -275,6 +366,76 @@ type
TsCellFontCombobox = class(TsCellCombobox) TsCellFontCombobox = class(TsCellCombobox)
protected protected
function GetCellFont(ACell: PCell): TsFont; function GetCellFont(ACell: PCell): TsFont;
published
{ inherited properties }
property Align;
property Anchors;
property ArrowKeysTraverseList;
property AutoComplete;
property AutoCompleteText;
property AutoDropDown;
property AutoSelect;
property AutoSize;// Note: windows has a fixed height in some styles
property BidiMode;
property BorderSpacing;
property BorderStyle;
property CharCase;
property Color;
property Constraints;
property DragCursor;
property DragKind;
property DragMode;
property DropDownCount;
property Enabled;
property Font;
property ItemHeight;
property ItemIndex;
// property Items;
property ItemWidth;
property MaxLength;
property OnChange;
property OnChangeBounds;
property OnClick;
property OnCloseUp;
property OnContextPopup;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnDrawItem;
property OnEndDrag;
property OnDropDown;
property OnEditingDone;
property OnEnter;
property OnExit;
property OnGetItems;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMeasureItem;
property OnMouseDown;
property OnMouseEnter;
property OnMouseLeave;
property OnMouseMove;
property OnMouseUp;
property OnMouseWheel;
property OnMouseWheelDown;
property OnMouseWheelUp;
property OnSelect;
property OnStartDrag;
property OnUTF8KeyPress;
property ParentBidiMode;
property ParentColor;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ReadOnly;
property ShowHint;
property Sorted;
// property Style;
property TabOrder;
property TabStop;
property Text;
property Visible;
end; end;
@ -357,7 +518,7 @@ procedure Register;
implementation implementation
uses uses
Types, TypInfo, Dialogs, Forms, Types, TypInfo, LCLType, Dialogs, Forms,
fpsStrings, fpsUtils, fpSpreadsheetGrid; fpsStrings, fpsUtils, fpSpreadsheetGrid;
@ -369,7 +530,8 @@ procedure Register;
begin begin
RegisterComponents('FPSpreadsheet', [ RegisterComponents('FPSpreadsheet', [
TsWorkbookSource, TsWorkbookTabControl, TsWorksheetGrid, TsWorkbookSource, TsWorkbookTabControl, TsWorksheetGrid,
TsCellEdit, TsCellIndicator, TsFontNameCombobox, TsFontSizeCombobox, TsCellEdit, TsCellIndicator, TsCellCombobox,
TsFontNameCombobox, TsFontSizeCombobox,
TsSpreadsheetInspector TsSpreadsheetInspector
]); ]);
end; end;
@ -1401,6 +1563,7 @@ end;
constructor TsCellCombobox.Create(AOwner: TComponent); constructor TsCellCombobox.Create(AOwner: TComponent);
begin begin
inherited Create(AOwner); inherited Create(AOwner);
FColorRectWidth := 10;
Populate; Populate;
end; end;
@ -1419,8 +1582,102 @@ end;
which the combobox is responsible. which the combobox is responsible.
-------------------------------------------------------------------------------} -------------------------------------------------------------------------------}
procedure TsCellCombobox.ApplyFormatToCell(ACell: PCell); procedure TsCellCombobox.ApplyFormatToCell(ACell: PCell);
var
fnt: TsFont;
clr: TColor;
sclr: TsColor;
begin begin
Unused(ACell); if (ItemIndex = -1) or (Worksheet = nil) then
exit;
case FFormatItem of
cfiFontName:
begin
fnt := Worksheet.ReadCellFont(ACell);
Worksheet.WriteFont(ACell, Items[ItemIndex], fnt.Size, fnt.Style, fnt.Color);
end;
cfiFontSize:
begin
fnt := Worksheet.ReadCellFont(ACell);
Worksheet.WriteFont(ACell, fnt.FontName, StrToFloat(Items[ItemIndex]), fnt.Style, fnt.Color);
end;
cfiFontColor:
begin
fnt := Worksheet.ReadCellFont(ACell);
clr := TsColor(PtrInt(Items.Objects[ItemIndex]));
sclr := Workbook.FindClosestColor(clr);
Worksheet.WriteFont(ACell, fnt.FontName, fnt.Size, fnt.Style, clr);
end;
cfiBackgroundColor:
if ItemIndex = 0 then
Worksheet.WriteBackgroundColor(ACell, scTransparent)
else
begin
clr := TsColor(PtrInt(Items.Objects[ItemIndex]));
sclr := Workbook.FindClosestColor(clr);
Worksheet.WriteBackgroundColor(ACell, sclr);
end;
cfiBorderColor:
;
else
raise Exception.Create('[TsCellFormatCombobox.ApplyFormatToCell] Unknown format item');
end;
end;
{@@ ----------------------------------------------------------------------------
Customdraws an item in the combobox. This is overridden to paint a color box
for the color-related format items.
------------------------------------------------------------------------------}
procedure TsCellCombobox.DrawItem(AIndex: Integer; ARect: TRect;
AState: TOwnerDrawState);
{ This code is adapted from colorbox.pas}
var
r: TRect;
brushColor, penColor, newColor: TColor;
noFill: Boolean;
begin
if AIndex = -1 then
Exit;
r.Top := ARect.Top + 2;
r.Bottom := ARect.Bottom - 2;
r.Left := ARect.Left + 2;
r.Right := r.Left + FColorRectWidth;
Exclude(AState, odPainted);
noFill := false;
with Canvas do
begin
FillRect(ARect);
brushColor := Brush.Color;
penColor := Pen.Color;
newColor := TColor(Items.Objects[AIndex]);
if newColor = clNone then
noFill := true;
Brush.Color := newColor;
Pen.Color := clBlack;
r := BiDiFlipRect(r, ARect, UseRightToLeftAlignment);
Rectangle(r);
if noFill then
begin
Line(r.Left, r.Top, r.Right-1, r.Bottom-1);
Line(r.Left, r.Bottom-1, r.Right-1, r.Top);
end;
Brush.Color := brushColor;
Pen.Color := penColor;
end;
r := ARect;
inc(r.Left, FColorRectWidth + 4);
inherited DrawItem(AIndex, BidiFlipRect(r, ARect, UseRightToLeftAlignment), AState);
end; end;
{@@ ---------------------------------------------------------------------------- {@@ ----------------------------------------------------------------------------
@ -1428,10 +1685,80 @@ end;
selectes the corresponding combobox item. selectes the corresponding combobox item.
-------------------------------------------------------------------------------} -------------------------------------------------------------------------------}
procedure TsCellCombobox.ExtractFromCell(ACell: PCell); procedure TsCellCombobox.ExtractFromCell(ACell: PCell);
var
fnt: TsFont;
sclr: TsColor;
clr: TColor;
begin begin
Unused(ACell); case FFormatItem of
cfiFontName:
begin
fnt := Worksheet.ReadCellFont(ACell);
// No check for nil required because fnt is at least DefaultFont
ItemIndex := Items.IndexOf(fnt.FontName);
end;
cfiFontSize:
begin
fnt := Worksheet.ReadCellFont(ACell);
ItemIndex := Items.IndexOf(Format('%.0f', [fnt.Size]));
end;
cfiFontColor:
begin
fnt := Worksheet.ReadCellFont(ACell);
ItemIndex := Items.IndexOfObject(TObject(PtrInt(fnt.Color)));
end;
cfiBackgroundColor:
begin
if Worksheet = nil then
clr := clNone
else
begin
sclr := Worksheet.ReadBackgroundColor(ACell);
if (sclr = scNotDefined) or (sclr = scTransparent) then
clr := clNone
else
clr := Workbook.GetPaletteColor(sclr);
end;
ItemIndex := Items.IndexOfObject(TObject(PtrInt(clr)));
end;
cfiBorderColor:
;
else
raise Exception.Create('[TsCellFormatItem.ExtractFromCell] Unknown format item');
end;
end; end;
{@@ ----------------------------------------------------------------------------
Returns the currently active cell of the worksheet
-------------------------------------------------------------------------------}
function TsCellCombobox.GetActiveCell: PCell;
begin
if FWorkbookSource <> nil then
Result := Worksheet.FindCell(Worksheet.ActiveCellRow, Worksheet.ActiveCellCol)
else
Result := nil;
end;
(*
function TsCellCombobox.GetItemHeight: Integer;
begin
Result := TWSCustomComboboxClass(WidgetSetClass).GetItemHeight(Self);
if inherited ItemHeight = 0 then
inherited ItemHeight := Result;
{
// FItemHeight is not initialized at class creating. we can, but with what value?
// so, if it still uninitialized (=0), then we ask widgetset
if (FStyle in [csOwnerDrawFixed, csOwnerDrawVariable]) and (FItemHeight > 0) or not HandleAllocated then
begin
Result := FItemHeight
end else
begin
Result := TWSCustomComboBoxClass(WidgetSetClass).GetItemHeight(Self);
if (FItemHeight = 0) then
FItemHeight := Result;
end;
}
end;
*)
{@@ ---------------------------------------------------------------------------- {@@ ----------------------------------------------------------------------------
Getter method for the property Workbook which is currently loaded by the Getter method for the property Workbook which is currently loaded by the
WorkbookSource WorkbookSource
@ -1474,13 +1801,23 @@ begin
if (Worksheet = nil) or ([lniCell, lniSelection]*AChangedItems = []) then if (Worksheet = nil) or ([lniCell, lniSelection]*AChangedItems = []) then
exit; exit;
activeCell := Worksheet.FindCell(Worksheet.ActiveCellRow, Worksheet.ActiveCellCol); activeCell := GetActiveCell;
if ((lniCell in AChangedItems) and (PCell(AData) = activeCell)) or if ((lniCell in AChangedItems) and (PCell(AData) = activeCell)) or
(lniSelection in AChangedItems) (lniSelection in AChangedItems)
then then
ExtractFromCell(activeCell); ExtractFromCell(activeCell);
end; end;
{@@ ----------------------------------------------------------------------------
Standard method. Overridden to populate combobox since items are not stored
in lfm file.
-------------------------------------------------------------------------------}
procedure TsCellCombobox.Loaded;
begin
inherited;
Populate;
end;
{@@ ---------------------------------------------------------------------------- {@@ ----------------------------------------------------------------------------
Standard component notification method called when the WorkbookSource Standard component notification method called when the WorkbookSource
is deleted. is deleted.
@ -1497,7 +1834,32 @@ end;
Descendants override this method to populate the items of the combobox. Descendants override this method to populate the items of the combobox.
-------------------------------------------------------------------------------} -------------------------------------------------------------------------------}
procedure TsCellCombobox.Populate; procedure TsCellCombobox.Populate;
var
i: Integer;
begin begin
if Workbook = nil then
exit;
case FFormatItem of
cfiFontName:
Items.Assign(Screen.Fonts);
cfiFontSize:
Items.CommaText := '8,9,10,11,12,13,14,16,18,20,22,24,26,28,32,36,48,72';
cfiFontColor:
for i:=0 to Workbook.GetPaletteSize-1 do
Items.AddObject(Workbook.GetColorName(i), TObject(Workbook.GetPaletteColor(i)));
cfiBackgroundColor:
begin
Items.AddObject('(none)', TObject(clNone));
for i:=0 to Workbook.GetPaletteSize-1 do
Items.AddObject(Workbook.GetColorName(i), TObject(Workbook.GetPaletteColor(i)));
end;
cfiBorderColor:
for i:=0 to Workbook.GetPaletteSize-1 do
Items.AddObject(Workbook.GetColorName(i), TObject(Workbook.GetPaletteColor(i)));
else
raise Exception.Create('[TsCellCombobox.Populate] Unknown cell format item.');
end;
end; end;
{@@ ---------------------------------------------------------------------------- {@@ ----------------------------------------------------------------------------
@ -1512,6 +1874,8 @@ var
cell: PCell; cell: PCell;
begin begin
inherited Select; inherited Select;
// UpdateCombo;
if Worksheet = nil then if Worksheet = nil then
exit; exit;
sel := Worksheet.GetSelection; sel := Worksheet.GetSelection;
@ -1524,6 +1888,33 @@ begin
end; end;
end; end;
{@@ ----------------------------------------------------------------------------
Setter method for the ColorRectWidth property
-------------------------------------------------------------------------------}
procedure TsCellCombobox.SetColorRectWidth(AValue: Integer);
begin
if FColorRectWidth = AValue then
exit;
FColorRectWidth := AValue;
Invalidate;
end;
{@@ ----------------------------------------------------------------------------
Setter method for the FormatItem property
-------------------------------------------------------------------------------}
procedure TsCellCombobox.SetFormatItem(AValue: TsCellFormatItem);
begin
FFormatItem := AValue;
if FFormatItem in [cfiFontColor, cfiBackgroundColor, cfiBorderColor] then
inherited Style := csOwnerDrawFixed
else
inherited Style := csDropdown;
Populate;
if FWorkbookSource <> nil then
ExtractFromCell(GetActiveCell);
end;
{@@ ---------------------------------------------------------------------------- {@@ ----------------------------------------------------------------------------
Setter method for the WorkbookSource Setter method for the WorkbookSource
-------------------------------------------------------------------------------} -------------------------------------------------------------------------------}
@ -1539,7 +1930,35 @@ begin
Text := ''; Text := '';
ListenerNotification([lniSelection]); ListenerNotification([lniSelection]);
end; end;
(*
procedure TsCellCombobox.UpdateCombo;
var
c: integer;
begin
if HandleAllocated then
Invalidate;
{
begin
for c := Ord(cbCustomColor in Style) to Items.Count - 1 do
begin
if Colors[c] = FSelected then
begin
ItemIndex := c;
Exit;
end;
end;
if cbCustomColor in Style then
begin
Items.Objects[0] := TObject(PtrInt(FSelected));
ItemIndex := 0;
Invalidate;
end
else
ItemIndex := -1;
end;
}
end;
*)
{------------------------------------------------------------------------------} {------------------------------------------------------------------------------}
{ TsCellFontCombobox } { TsCellFontCombobox }

Binary file not shown.

After

Width:  |  Height:  |  Size: 900 B