fpspreadsheet: Use HTML conversion to enter rich-text in the visual TsCellEdit control

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4271 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2015-08-14 12:44:22 +00:00
parent 55c0c6c4c4
commit f4cb9c14a7
3 changed files with 57 additions and 36 deletions

View File

@@ -988,6 +988,8 @@ begin
// NOTE: This is a simple version: every opened tag is closed afterwards! // NOTE: This is a simple version: every opened tag is closed afterwards!
// In a more advanced version, shared properties should be kept. This is // In a more advanced version, shared properties should be kept. This is
// what FChangedParams was introduced for! // what FChangedParams was introduced for!
if not SameFont(FBaseFont, FFonts[i]) then
begin
if [cfFontName, cfFontSize, cfFontColor] * FChangedparams[i] <> [] then if [cfFontName, cfFontSize, cfFontColor] * FChangedparams[i] <> [] then
begin begin
Result := Result + '<font'; Result := Result + '<font';
@@ -997,6 +999,7 @@ begin
Result := Result + ' size="' + Format('%.gpt', [FFonts[i].Size], FPointSeparatorSettings) + '"'; Result := Result + ' size="' + Format('%.gpt', [FFonts[i].Size], FPointSeparatorSettings) + '"';
if cfFontColor in FChangedParams[i] then if cfFontColor in FChangedParams[i] then
Result := Result + ' color="' + ColorToHTMLColorStr(FFonts[i].Color) + '"'; Result := Result + ' color="' + ColorToHTMLColorStr(FFonts[i].Color) + '"';
Result := Result + '>';
end; end;
if (cfBold in FChangedParams[i]) then if (cfBold in FChangedParams[i]) then
Result := Result + '<b>'; Result := Result + '<b>';
@@ -1011,9 +1014,12 @@ begin
if FFonts[i].Position = fpSuperscript then Result := Result + '<sup>'; if FFonts[i].Position = fpSuperscript then Result := Result + '<sup>';
if FFonts[i].Position = fpSubscript then Result := Result + '<sub>'; if FFonts[i].Position = fpSubscript then Result := Result + '<sub>';
end; end;
end;
// Add the node text // Add the node text
Result := Result + GetTextOfRichTextParam(i); Result := Result + GetTextOfRichTextParam(i);
// Add closing tags (reverse order as opening!) // Add closing tags (reverse order as opening!)
if not SameFont(FBaseFont, FFonts[i]) then
begin
if (cfFontPosition in FChangedParams[i]) then if (cfFontPosition in FChangedParams[i]) then
begin begin
if FFonts[i].Position = fpSubscript then Result := Result + '</sub>'; if FFonts[i].Position = fpSubscript then Result := Result + '</sub>';
@@ -1028,7 +1034,8 @@ begin
if (cfBold in FChangedParams[i]) then if (cfBold in FChangedParams[i]) then
Result := Result + '</b>'; Result := Result + '</b>';
if [cfFontName, cfFontSize, cfFontColor] * FChangedParams[i] <> [] then if [cfFontName, cfFontSize, cfFontColor] * FChangedParams[i] <> [] then
Result := Result + '</font'; Result := Result + '</font>';
end;
end; end;
end; end;

View File

@@ -4183,6 +4183,8 @@ var
numFmtParams: TsNumFormatParams; numFmtParams: TsNumFormatParams;
maxDig: Integer; maxDig: Integer;
isMixed: Boolean; isMixed: Boolean;
rtParams: TsRichTextParams;
plain: String;
begin begin
if ACell = nil then if ACell = nil then
exit; exit;
@@ -4252,7 +4254,8 @@ begin
exit; exit;
end; end;
WriteUTF8Text(ACell, AValue); HTMLToRichText(FWorkbook, ReadcellFont(ACell), AValue, plain, rtParams);
WriteUTF8Text(ACell, plain, rtParams);
end; end;
{@@ ---------------------------------------------------------------------------- {@@ ----------------------------------------------------------------------------

View File

@@ -212,6 +212,7 @@ type
TsCellEdit = class(TMemo, IsSpreadsheetControl) TsCellEdit = class(TMemo, IsSpreadsheetControl)
private private
FWorkbookSource: TsWorkbookSource; FWorkbookSource: TsWorkbookSource;
FShowHTMLText: Boolean;
function GetSelectedCell: PCell; function GetSelectedCell: PCell;
function GetWorkbook: TsWorkbook; function GetWorkbook: TsWorkbook;
function GetWorksheet: TsWorksheet; function GetWorksheet: TsWorksheet;
@@ -234,6 +235,7 @@ type
{@@ Refers to the underlying worksheet to which the edited cell belongs. } {@@ Refers to the underlying worksheet to which the edited cell belongs. }
property Worksheet: TsWorksheet read GetWorksheet; property Worksheet: TsWorksheet read GetWorksheet;
published published
property ShowHTMLText: Boolean read FShowHTMLText write FShowHTMLText default true;
{@@ 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;
end; end;
@@ -462,7 +464,7 @@ implementation
uses uses
Types, Math, TypInfo, LCLType, LCLProc, Dialogs, Forms, Types, Math, TypInfo, LCLType, LCLProc, Dialogs, Forms,
fpsStrings, fpsUtils, fpsNumFormat; fpsStrings, fpsUtils, fpsNumFormat, fpsHTMLUtils;
{@@ ---------------------------------------------------------------------------- {@@ ----------------------------------------------------------------------------
Registers the spreadsheet components in the Lazarus component palette, Registers the spreadsheet components in the Lazarus component palette,
@@ -1577,6 +1579,7 @@ end;
constructor TsCellEdit.Create(AOwner: TComponent); constructor TsCellEdit.Create(AOwner: TComponent);
begin begin
inherited Create(AOwner); inherited Create(AOwner);
FShowHTMLText := True;
WantReturns := false; WantReturns := false;
WantTabs := false; WantTabs := false;
AutoSize := true; AutoSize := true;
@@ -1748,6 +1751,14 @@ begin
Lines.Text := FormatDateTime('ddddd', ACell^.DateTimevalue) Lines.Text := FormatDateTime('ddddd', ACell^.DateTimevalue)
else // both else // both
Lines.Text := FormatDateTime('c', ACell^.DateTimeValue); Lines.Text := FormatDateTime('c', ACell^.DateTimeValue);
cctUTF8String:
if FShowHTMLText then
begin
RichTextToHTML(Workbook, Worksheet.ReadCellFont(ACell),
ACell^.UTF8StringValue, ACell^.RichTextParams, s);
Lines.Text := s;
end else
Lines.Text := ACell^.UTF8StringValue;
else else
Lines.Text := Worksheet.ReadAsUTF8Text(ACell); Lines.Text := Worksheet.ReadAsUTF8Text(ACell);
end; end;