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>
<Filename Value="unit1.pas"/>
<IsPartOfProject Value="True"/>
<ComponentName Value="Form1"/>
<ComponentName Value="MainForm"/>
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
<UnitName Value="Unit1"/>

View File

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

View File

@ -1,11 +1,11 @@
object Form1: TForm1
Left = 256
object MainForm: TMainForm
Left = 369
Height = 468
Top = 122
Width = 582
Top = 219
Width = 575
Caption = 'JvHTControls'
ClientHeight = 468
ClientWidth = 582
ClientWidth = 575
OnCreate = FormCreate
OnShow = FormShow
LCLVersion = '2.1.0.0'
@ -13,7 +13,7 @@ object Form1: TForm1
Left = 0
Height = 422
Top = 0
Width = 582
Width = 575
ActivePage = TabSheet1
Align = alClient
TabIndex = 0
@ -21,10 +21,10 @@ object Form1: TForm1
object TabSheet1: TTabSheet
Caption = 'TJvHTLabel'
ClientHeight = 394
ClientWidth = 574
ClientWidth = 567
object JvHTLabel1: TJvHTLabel
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>'
Top = 8
Width = 120
@ -36,10 +36,10 @@ object Form1: TForm1
end
object Memo1: TMemo
Left = 0
Height = 122
Height = 123
Hint = '<b>HTML</b><br>'#13#10'<i>Enter HTML content</i>'
Top = 272
Width = 574
Top = 271
Width = 567
Align = alBottom
Lines.Strings = (
'HTLabel with:<br>'
@ -62,8 +62,8 @@ object Form1: TForm1
Cursor = crVSplit
Left = 0
Height = 5
Top = 267
Width = 574
Top = 266
Width = 567
Align = alBottom
ResizeAnchor = akBottom
end
@ -235,7 +235,7 @@ object Form1: TForm1
Left = 6
Height = 34
Top = 428
Width = 570
Width = 563
OKButton.Name = 'OKButton'
OKButton.DefaultCaption = True
HelpButton.Name = 'HelpButton'

View File

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

View File

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