jvcllaz: Fix line-breaks in JvHTControls' HTML texts.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@6967 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2019-05-28 21:13:32 +00:00
parent 988fb4f578
commit edb953f150
5 changed files with 36 additions and 32 deletions

View File

@ -49,7 +49,7 @@
<Unit1> <Unit1>
<Filename Value="unit1.pas"/> <Filename Value="unit1.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<ComponentName Value="Form1"/> <ComponentName Value="MainForm"/>
<HasResources Value="True"/> <HasResources Value="True"/>
<ResourceBaseClass Value="Form"/> <ResourceBaseClass Value="Form"/>
<UnitName Value="Unit1"/> <UnitName Value="Unit1"/>

View File

@ -15,7 +15,7 @@ uses
begin begin
RequireDerivedFormResource:=True; RequireDerivedFormResource:=True;
Application.Initialize; Application.Initialize;
Application.CreateForm(TForm1, Form1); Application.CreateForm(TMainForm, MainForm);
Application.Run; Application.Run;
end. end.

View File

@ -1,11 +1,11 @@
object Form1: TForm1 object MainForm: TMainForm
Left = 256 Left = 369
Height = 468 Height = 468
Top = 122 Top = 219
Width = 582 Width = 575
Caption = 'JvHTControls' Caption = 'JvHTControls'
ClientHeight = 468 ClientHeight = 468
ClientWidth = 582 ClientWidth = 575
OnCreate = FormCreate OnCreate = FormCreate
OnShow = FormShow OnShow = FormShow
LCLVersion = '2.1.0.0' LCLVersion = '2.1.0.0'
@ -13,7 +13,7 @@ object Form1: TForm1
Left = 0 Left = 0
Height = 422 Height = 422
Top = 0 Top = 0
Width = 582 Width = 575
ActivePage = TabSheet1 ActivePage = TabSheet1
Align = alClient Align = alClient
TabIndex = 0 TabIndex = 0
@ -21,10 +21,10 @@ object Form1: TForm1
object TabSheet1: TTabSheet object TabSheet1: TTabSheet
Caption = 'TJvHTLabel' Caption = 'TJvHTLabel'
ClientHeight = 394 ClientHeight = 394
ClientWidth = 574 ClientWidth = 567
object JvHTLabel1: TJvHTLabel object JvHTLabel1: TJvHTLabel
Left = 8 Left = 8
Height = 106 Height = 196
Hint = 'HTLabel with:<br />'#13#10'<b>bold</b><br>'#13#10'<i>italic</i><br>'#13#10'<u>underline</u><br>'#13#10'<s>strikeout</s><br>'#13#10'<font color="Red">c</font><font color="blue">o</font><font color="Green">l</font><font color="Fuchsia">o</font><font color="Maroon">r</font><br>'#13#10'<a href="http://www.freepascal.org/">Links</a> and <a href="custom">custom links</a>' Hint = 'HTLabel with:<br />'#13#10'<b>bold</b><br>'#13#10'<i>italic</i><br>'#13#10'<u>underline</u><br>'#13#10'<s>strikeout</s><br>'#13#10'<font color="Red">c</font><font color="blue">o</font><font color="Green">l</font><font color="Fuchsia">o</font><font color="Maroon">r</font><br>'#13#10'<a href="http://www.freepascal.org/">Links</a> and <a href="custom">custom links</a>'
Top = 8 Top = 8
Width = 120 Width = 120
@ -36,10 +36,10 @@ object Form1: TForm1
end end
object Memo1: TMemo object Memo1: TMemo
Left = 0 Left = 0
Height = 122 Height = 123
Hint = '<b>HTML</b><br>'#13#10'<i>Enter HTML content</i>' Hint = '<b>HTML</b><br>'#13#10'<i>Enter HTML content</i>'
Top = 272 Top = 271
Width = 574 Width = 567
Align = alBottom Align = alBottom
Lines.Strings = ( Lines.Strings = (
'HTLabel with:<br>' 'HTLabel with:<br>'
@ -62,8 +62,8 @@ object Form1: TForm1
Cursor = crVSplit Cursor = crVSplit
Left = 0 Left = 0
Height = 5 Height = 5
Top = 267 Top = 266
Width = 574 Width = 567
Align = alBottom Align = alBottom
ResizeAnchor = akBottom ResizeAnchor = akBottom
end end
@ -235,7 +235,7 @@ object Form1: TForm1
Left = 6 Left = 6
Height = 34 Height = 34
Top = 428 Top = 428
Width = 570 Width = 563
OKButton.Name = 'OKButton' OKButton.Name = 'OKButton'
OKButton.DefaultCaption = True OKButton.DefaultCaption = True
HelpButton.Name = 'HelpButton' HelpButton.Name = 'HelpButton'

View File

@ -11,9 +11,9 @@ uses
type type
{ TForm1 } { TMainForm }
TForm1 = class(TForm) TMainForm = class(TForm)
Button1: TButton; Button1: TButton;
Button2: TButton; Button2: TButton;
ButtonPanel1: TButtonPanel; ButtonPanel1: TButtonPanel;
@ -50,31 +50,31 @@ type
end; end;
var var
Form1: TForm1; MainForm: TMainForm;
implementation implementation
{$R *.lfm} {$R *.lfm}
{ TForm1 } { TMainForm }
procedure TForm1.Memo1Change(Sender: TObject); procedure TMainForm.Memo1Change(Sender: TObject);
begin begin
JvHTLabel1.Caption := Memo1.Text; JvHTLabel1.Caption := Memo1.Text;
JvHTLabel1.Hint := Memo1.Text; JvHTLabel1.Hint := Memo1.Text;
end; end;
procedure TForm1.Memo3Change(Sender: TObject); procedure TMainForm.Memo3Change(Sender: TObject);
begin begin
JvDBHTLabel1.Mask := Memo3.Text; JvDBHTLabel1.Mask := Memo3.Text;
end; end;
procedure TForm1.FormCreate(Sender: TObject); procedure TMainForm.FormCreate(Sender: TObject);
begin begin
RegisterHtHints; RegisterHtHints;
end; end;
procedure TForm1.FormShow(Sender: TObject); procedure TMainForm.FormShow(Sender: TObject);
begin begin
MemDataset1.AppendRecord([1, 'asdfxc', 'wertfx']); MemDataset1.AppendRecord([1, 'asdfxc', 'wertfx']);
MemDataset1.AppendRecord([2, 'brdrgrsdgx', 'sdfwetrcx']); MemDataset1.AppendRecord([2, 'brdrgrsdgx', 'sdfwetrcx']);
@ -83,29 +83,29 @@ begin
MemDataset1.AppendRecord([5, 'trcbxg', 'her4fekg']); MemDataset1.AppendRecord([5, 'trcbxg', 'her4fekg']);
end; end;
procedure TForm1.JvDBHTLabel1HyperLinkClick(Sender: TObject; LinkName: string); procedure TMainForm.JvDBHTLabel1HyperLinkClick(Sender: TObject; LinkName: string);
begin begin
MessageDlg('TJvDBHTLabel', 'Hyperlink: ' + LinkName, mtInformation, [mbOK], 0); MessageDlg('TJvDBHTLabel', 'Hyperlink: ' + LinkName, mtInformation, [mbOK], 0);
end; end;
procedure TForm1.Button1Click(Sender: TObject); procedure TMainForm.Button1Click(Sender: TObject);
begin begin
JvHTListBox1.Items.Add(Memo2.Text); JvHTListBox1.Items.Add(Memo2.Text);
JvHTComboBox1.Items.Add(Memo2.Text); JvHTComboBox1.Items.Add(Memo2.Text);
end; end;
procedure TForm1.Button2Click(Sender: TObject); procedure TMainForm.Button2Click(Sender: TObject);
begin begin
JvHTComboBox1.Items.Clear; JvHTComboBox1.Items.Clear;
JvHTListBox1.Items.Clear; JvHTListBox1.Items.Clear;
end; end;
procedure TForm1.JvHTLabel1HyperLinkClick(Sender: TObject; LinkName: string); procedure TMainForm.JvHTLabel1HyperLinkClick(Sender: TObject; LinkName: string);
begin begin
MessageDlg('TJvHTLabel', 'Hyperlink: ' + LinkName, mtInformation, [mbOK], 0); MessageDlg('TJvHTLabel', 'Hyperlink: ' + LinkName, mtInformation, [mbOK], 0);
end; end;
procedure TForm1.JvHTListBox1HyperLinkClick(Sender: TObject; LinkName: string); procedure TMainForm.JvHTListBox1HyperLinkClick(Sender: TObject; LinkName: string);
begin begin
MessageDlg('JvHTListBox', 'Hyperlink: ' + LinkName, mtInformation, [mbOK], 0); MessageDlg('JvHTListBox', 'Hyperlink: ' + LinkName, mtInformation, [mbOK], 0);
end; end;

View File

@ -7081,6 +7081,7 @@ end;
const const
cBR = '<BR>'; cBR = '<BR>';
cBR2 = '<BR/>';
cHR = '<HR>'; cHR = '<HR>';
cTagBegin = '<'; cTagBegin = '<';
cTagEnd = '>'; cTagEnd = '>';
@ -7117,8 +7118,9 @@ begin
Result := Text; Result := Text;
for I := Low(Conversions) to High(Conversions) do for I := Low(Conversions) to High(Conversions) do
Result := StringReplace(Result, Conversions[I].Html, Utf8ToAnsi(Conversions[I].Text), [rfReplaceAll, rfIgnoreCase]); Result := StringReplace(Result, Conversions[I].Html, Utf8ToAnsi(Conversions[I].Text), [rfReplaceAll, rfIgnoreCase]);
Result := StringReplace(Result, sLineBreak, '', [rfReplaceAll, rfIgnoreCase]); // only <BR> can be new line Result := StringReplace(Result, sLineBreak, '', [rfReplaceAll, rfIgnoreCase]); // only <BR> can be new line
Result := StringReplace(Result, cBR, sLineBreak, [rfReplaceAll, rfIgnoreCase]); Result := StringReplace(Result, cBR, sLineBreak, [rfReplaceAll, rfIgnoreCase]);
Result := StringReplace(Result, cBR2, sLineBreak, [rfReplaceAll, rfIgnoreCase]); // Fixes <BR/>, but not <BR />!
Result := StringReplace(Result, cHR, cHR + sLineBreak, [rfReplaceAll, rfIgnoreCase]); // fixed <HR><BR> Result := StringReplace(Result, cHR, cHR + sLineBreak, [rfReplaceAll, rfIgnoreCase]); // fixed <HR><BR>
end; end;
@ -7367,13 +7369,14 @@ begin
RemBrushColor := Canvas.Brush.Color; RemBrushColor := Canvas.Brush.Color;
RemFontSize := Canvas.Font.size; RemFontSize := Canvas.Font.size;
end; end;
vStr := TStringList.Create; vStr := TStringList.Create;
try try
Alignment := taLeftJustify; Alignment := taLeftJustify;
IsLink := False; IsLink := False;
MouseOnLink := False; MouseOnLink := False;
vText := Text; vText := Text;
vStr.Text := vText; vStr.Text := HTMLPrepareText(vText);
LinkName := ''; LinkName := '';
TempLink := ''; TempLink := '';
ScriptPosition := spNormal; ScriptPosition := spNormal;
@ -7387,7 +7390,8 @@ begin
vM := ''; vM := '';
for vCount := 0 to vStr.Count - 1 do for vCount := 0 to vStr.Count - 1 do
begin begin
vText := HTMLPrepareText(vStr[vCount]); // vText := HTMLPrepareText(vStr[vCount]);
vText := vStr[vCount];
CurLeft := CalcPos(vText); CurLeft := CalcPos(vText);
while vText <> '' do while vText <> '' do
begin begin