Skip to content

Commit

Permalink
Merge pull request #22 from digao-dalpiaz/new-tstrings-final
Browse files Browse the repository at this point in the history
New tstrings final
  • Loading branch information
digao-dalpiaz authored Jul 30, 2020
2 parents 84d2ec9 + 9b10798 commit 4abfad5
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 66 deletions.
51 changes: 37 additions & 14 deletions DzHTMLText.pas
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,14 @@ TDzHTMLText = class(TGraphicControl)
LLinkRef: TDHLinkRefList; //list of links info
LSpoiler: TDHSpoilerList;

FText: String;
FLines: TStrings;
FAutoWidth: Boolean;
FAutoHeight: Boolean;
FMaxWidth: Integer; //max width when using AutoWidth
//FTransparent: Boolean; //not used because of flickering
FAutoOpenLink: Boolean; //link auto-open with ShellExecute

FLines: Integer; //read-only
FLineCount: Integer; //read-only
FTextWidth: Integer; //read-only
FTextHeight: Integer; //read-only

Expand All @@ -188,7 +188,11 @@ TDzHTMLText = class(TGraphicControl)
UpdatingSemaphore: Integer;
InternalResizing: Boolean;

procedure OnLinesChange(Sender: TObject);
procedure SetLines(const Value: TStrings);
function GetText: String;
procedure SetText(const Value: String);

procedure SetAutoHeight(const Value: Boolean);
procedure SetAutoWidth(const Value: Boolean);
procedure SetMaxWidth(const Value: Integer);
Expand Down Expand Up @@ -237,6 +241,8 @@ TDzHTMLText = class(TGraphicControl)
procedure BeginUpdate;
procedure EndUpdate(ForceRepaint: Boolean = True);

property Text: String read GetText write SetText;

class function UnescapeHTMLToText(const aHTML: String): String;
class function EscapeTextToHTML(const aText: String): String;
published
Expand Down Expand Up @@ -271,7 +277,7 @@ TDzHTMLText = class(TGraphicControl)
property OnStartDock;
property OnStartDrag;

property Text: String read FText write SetText;
property Lines: TStrings read FLines write SetLines;
//property Transparent: Boolean read FTransparent write SetTransparent default False;

property AutoWidth: Boolean read FAutoWidth write SetAutoWidth default False;
Expand All @@ -283,7 +289,7 @@ TDzHTMLText = class(TGraphicControl)

property Images: TCustomImageList read FImages write SetImages;

property Lines: Integer read FLines;
property LineCount: Integer read FLineCount;
property TextWidth: Integer read FTextWidth;
property TextHeight: Integer read FTextHeight;

Expand Down Expand Up @@ -443,7 +449,11 @@ constructor TDzHTMLText.Create(AOwner: TComponent);
ControlStyle := ControlStyle + [csOpaque];
//Warning! The use of transparency in the component causes flickering

FAbout := 'Digao Dalpiaz / Version 2.0';
FAbout := 'Digao Dalpiaz / Version 2.1';

FLines := TStringList.Create;
FLines.TrailingLineBreak := False;
TStringList(FLines).OnChange := OnLinesChange;

FStyleLinkNormal := TDHStyleLinkProp.Create(Self, tslpNormal);
FStyleLinkHover := TDHStyleLinkProp.Create(Self, tslpHover);
Expand All @@ -465,6 +475,7 @@ constructor TDzHTMLText.Create(AOwner: TComponent);

destructor TDzHTMLText.Destroy;
begin
FLines.Free;
FStyleLinkNormal.Free;
FStyleLinkHover.Free;
LVisualItem.Free;
Expand Down Expand Up @@ -549,15 +560,25 @@ procedure TDzHTMLText.SetMaxWidth(const Value: Integer);
end;
end;

procedure TDzHTMLText.SetText(const Value: String);
procedure TDzHTMLText.OnLinesChange(Sender: TObject);
begin
if Value<>FText then
begin
FText := Value;
LSpoiler.Clear;
BuildAndPaint;
end;

LSpoiler.Clear;
BuildAndPaint;
end;
procedure TDzHTMLText.SetLines(const Value: TStrings);
begin
FLines.Assign(Value);
end;

function TDzHTMLText.GetText: String;
begin
Result := FLines.Text;
end;

procedure TDzHTMLText.SetText(const Value: String);
begin
FLines.Text := Value;
end;

procedure TDzHTMLText.SetLineVertAlign(const Value: TDHLineVertAlign);
Expand Down Expand Up @@ -1143,7 +1164,7 @@ procedure TBuilder.ReadTokens;
CharIni: Char;
I, Jump: Integer;
begin
Text := Lb.FText;
Text := Lb.FLines.Text;

Text := StringReplace(Text, #13#10'<NBR>', EmptyStr, [rfReplaceAll, rfIgnoreCase]); //ignore next break
Text := StringReplace(Text, #13#10, '<BR>', [rfReplaceAll]);
Expand Down Expand Up @@ -1849,6 +1870,8 @@ type TSizes = record

if not InFloat then Inc(LineCount);
BreakGroupAndLineCtrl(True, TPoint.Create(FloatRect.Left, Y+Max.LineHeight));
//if line is empty, there is no visual item to check overall height
if Y>Max.OverallHeight then Max.OverallHeight := Y;

if (Z is TPreObj_Break) then
begin
Expand Down Expand Up @@ -1883,7 +1906,7 @@ type TSizes = record
Builder.CalcWidth := Max.OverallWidth;
Builder.CalcHeight := Max.OverallHeight;

Lb.FLines := LineCount;
Lb.FLineCount := LineCount;
end;

procedure TTokensProcess.Publish;
Expand Down
71 changes: 45 additions & 26 deletions Example/UFrmExample.dfm
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,21 @@ object Form1: TForm1
Font.Style = []
ParentColor = False
ParentFont = False
Text =
'<imgres:LOGO><fc:clGreen> Welcome to my app!</fc>'#13#10#13#10'<b>This is ' +
'an important text</b> and <i>this is italic text</i>.<br><u>But ' +
'we have underline too</u>, and <s>strike-out</s> if you want.<br' +
'><br>You can change the <fn:Courier New>font name</fn> and the <' +
'fs:14>font size</fs><br>The <fc:clRed>colors</fc> are <bc:clYell' +
'ow>allowed</bc> too! <img:0> <i>and images</i> <img:1><br><br><c' +
'>Alignment, we have!</c><br><r>This is great</r>'#13#10#13#10'Click <a:www' +
'.google.com.br>here</a> to open Google.'#13#10'This is an image from r' +
'esource: <a:INFO_ABOUT><imgres:about> About the program</a>'
Lines.Strings = (
'<imgres:LOGO><fc:clGreen> Welcome to my app!</fc>'
''

'<b>This is an important text</b> and <i>this is italic text</i>.' +
'<br><u>But we have underline too</u>, and <s>strike-out</s> if y' +
'ou want.<br><br>You can change the <fn:Courier New>font name</fn' +
'> and the <fs:14>font size</fs><br>The <fc:clRed>colors</fc> are' +
' <bc:clYellow>allowed</bc> too! <img:0> <i>and images</i> <img:1' +
'><br><br><c>Alignment, we have!</c><br><r>This is great</r>'
''
'Click <a:www.google.com.br>here</a> to open Google.'

'This is an image from resource: <a:INFO_ABOUT><imgres:about> Abo' +
'ut the program</a>')
Images = MyImages
OnLinkClick = LbLinkClick
OnRetrieveImgRes = LbRetrieveImgRes
Expand All @@ -57,17 +62,30 @@ object Form1: TForm1
Font.Style = []
ParentColor = False
ParentFont = False
Text =
'You can use tab align too:<fc:$EF7769>'#13#10'<t:10>1<t:30>JHON<t:100>' +
'<r>100,000</r><t:150>'#13#10'<t:10>2<t:30>SARAH<t:100><r>1,150,000</r>' +
'<t:150>'#13#10'<t:10>3<t:30>ERIC<t:100><r>180,000</r><t:150></fc>'#13#10#13#10'H' +
'TML Lists:<fc:$2768EF>'#13#10'<nbr><ul>'#13#10'<li>Item 1</li>'#13#10'<li>Item 2</' +
'li>'#13#10'<nbr><ol>'#13#10'<li>Sub item 1</li>'#13#10'<li>Sub item 2</li>'#13#10'<nbr><' +
'ol>'#13#10'<li><i>Detail 2.1</i></li>'#13#10'<li><i>Detail 2.2</i></li>'#13#10'<nb' +
'r></ol>'#13#10'<li>Sub item 3</li>'#13#10'<nbr></ol>'#13#10'<li>Item 3</li>'#13#10'<nbr>' +
'</ul></fc>'#13#10'<nbr><float:200,100,120><c>This is a <b>floating are' +
'a</b>, where you can write any text and even use tags!!!<c></flo' +
'at>'
Lines.Strings = (
'You can use tab align too:<fc:$EF7769>'
'<t:10>1<t:30>JHON<t:100><r>100,000</r><t:150>'
'<t:10>2<t:30>SARAH<t:100><r>1,150,000</r><t:150>'
'<t:10>3<t:30>ERIC<t:100><r>180,000</r><t:150></fc>'
''
'HTML Lists:<fc:$2768EF>'
'<nbr><ul>'
'<li>Item 1</li>'
'<li>Item 2</li>'
'<nbr><ol>'
'<li>Sub item 1</li>'
'<li>Sub item 2</li>'
'<nbr><ol>'
'<li><i>Detail 2.1</i></li>'
'<li><i>Detail 2.2</i></li>'
'<nbr></ol>'
'<li>Sub item 3</li>'
'<nbr></ol>'
'<li>Item 3</li>'
'<nbr></ul></fc>'

'<nbr><float:200,100,120><c>This is a <b>floating area</b>, where' +
' you can write any text and even use tags!!!<c></float>')
LineVertAlign = vaCenter
end
object Lb3: TDzHTMLText
Expand All @@ -81,11 +99,12 @@ object Form1: TForm1
Font.Name = 'Segoe UI'
Font.Style = [fsItalic]
ParentFont = False
Text =
'<c>Please note that components above have <b>White</b> backgound' +
' only because I want to show the bounds, to understand line brea' +
'ks and alignments. Of course you can use parent backgound (defau' +
'lt), like this.<c>'
Lines.Strings = (

'<c>Please note that components above have <b>White</b> backgound' +
' only because I want to show the bounds, to understand line brea' +
'ks and alignments. Of course you can use parent backgound (defau' +
'lt), like this.<c>')
end
object MyImages: TImageList
Height = 24
Expand Down
36 changes: 32 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,30 @@

## What's New

- 07/30/2020 (Version 2.1)

- Implemented new Lines (TStrings) property and removed Text published property. :warning:
- Implemented Text (String) public property as a shortcut to new Lines property. :warning:
- Changed Lines (Integer) property name to LineCount. :warning:

| :exclamation: Component property change. Risk of data loss! |
|-------------------------------------------------------------|

In order to keep TDzHTMLText Text string property content of your projects, you'll need to manually change property on DFM file, before opening projects in Delphi.
Open the DFM files (using a text editor) that contains TDzHTMLText objects and replace as in the example:

```delphi
object DzHTMLText1: TDzHTMLText
//FROM:
Text = 'Line 1'#13#10'Line 2'#13#10'Line 3'
//TO:
Lines.Strings = (
'Line 1'#13#10'Line 2'#13#10'Line 3')
end
```
If you want to keep old Text property, please download the older version here: [TDzHTMLText v2.0](https://github.com/digao-dalpiaz/DzHTMLText/releases/tag/v2.0)
- 07/27/2020 (Version 2.0)
- Refactoring in all the methods that process the tokens.
Expand Down Expand Up @@ -190,7 +214,11 @@ This property calls ShellExecute method.
`Images: TCustomImageList` = When using `<img>` tag, you should set this property to specify the ImageList where the images are stored.
`Lines: Integer` = Returns the total lines of text, according to the bounds of control. This property is read-only.
`LineCount: Integer` = Returns the total lines of text, according to the bounds of control. This property is read-only.
`Lines: TStrings` = The text you want to show at label control. You can use `<BR>` tag to break lines. The Windows default Line Break (#13#10) breaks lines either.
> The component automatically converts #13#10 sequence into a line break. Because of this behavior, all typed line breaks will appear as a real line break. If you don't want the line break in a specific sequence, you can use the `<NBR>` tag after #13#10 characters. This will tell the component to not consider the sequence as a line break (Please check this tag at Example project).
`LineVertAlign: TDHLineVertAlign (vaTop, vaCenter, vaBottom)` = Allows you to specify the vertical alignment of each element in the line. This property only take effects when the elements have different heights. Default is `vaTop`.
Expand All @@ -202,9 +230,7 @@ This property calls ShellExecute method.
`StyleLinkHover: TDHStyleLinkProp` = Properties to format a link when is selected by mouse.
`Text: String` = The text you want to show at label control. You can use `<BR>` tag to break lines. The Windows default Line Break (#13#10) breaks lines either.

> The component automatically converts #13#10 sequence into a line break. Because of this behavior, all typed line breaks will appear as a real line break. If you don't want the line break in a specific sequence, you can use the `<NBR>` tag after #13#10 characters. This will tell the component to not consider the sequence as a line break (Please check this tag at Example project).
`Text: String` (public) = This property is a shortcut to `Lines` property. At run-time, you can read and write this property directly, but the component will store the text at `Lines` property.
`TextHeight: Integer` = Returns the total text height. This property is read-only.
Expand Down Expand Up @@ -299,6 +325,8 @@ finally
end;
```

> Do not use `Lines.BeginUpdate/Lines.EndUpdate`. These methods are not controlled by the component.
## Link Reference Tag

There are two ways to use link tag:
Expand Down
58 changes: 36 additions & 22 deletions Test/UFrmMain.dfm
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ object FrmMain: TFrmMain
Font.Style = []
ParentColor = False
ParentFont = False
Text = 'text spacing test'
Lines.Strings = (
'text spacing test')
end
object DzHTMLText2: TDzHTMLText
Left = 8
Expand All @@ -41,9 +42,10 @@ object FrmMain: TFrmMain
Font.Style = []
ParentColor = False
ParentFont = False
Text =
'<bc:clyellow>text<bc:clblue> </bc><bc:clred> </bc><bc:clgreen> <' +
'/bc>spacing test</bc>'
Lines.Strings = (

'<bc:clyellow>text<bc:clblue> </bc><bc:clred> </bc><bc:clgreen> <' +
'/bc>spacing test</bc>')
end
object DzHTMLText3: TDzHTMLText
Left = 168
Expand All @@ -58,12 +60,15 @@ object FrmMain: TFrmMain
Font.Style = []
ParentColor = False
ParentFont = False
Text =
'floating test:'#13#10'<nbr><float:200,20,60><c>my test panel 1234</c><' +
'/float>'#13#10'Text after floating.'#13#10'<nbr><float:100,65,80><r><bc:clsi' +
'lver>And here a new floating panel abc'#13#10'Break <fs:20>BIG</fs></b' +
'c></r></float>'#13#10'<bc:clyellow>Text <fs:18>after</fs> second panel' +
'</bc>'
Lines.Strings = (
'floating test:'
'<nbr><float:200,20,60><c>my test panel 1234</c></float>'
'Text after floating.'

'<nbr><float:100,65,80><r><bc:clsilver>And here a new floating pa' +
'nel abc'
'Break <fs:20>BIG</fs></bc></r></float>'
'<bc:clyellow>Text <fs:18>after</fs> second panel</bc>')
LineVertAlign = vaCenter
end
object DzHTMLText4: TDzHTMLText
Expand All @@ -79,9 +84,10 @@ object FrmMain: TFrmMain
Font.Style = []
ParentColor = False
ParentFont = False
Text =
'<r><bc:clyellow>text<bc:clblue> </bc><bc:clred> </bc><bc:clgreen' +
'> </bc>spacing test</bc></r>'
Lines.Strings = (

'<r><bc:clyellow>text<bc:clblue> </bc><bc:clred> </bc><bc:clgreen' +
'> </bc>spacing test</bc></r>')
end
object DzHTMLText5: TDzHTMLText
Left = 8
Expand All @@ -96,7 +102,8 @@ object FrmMain: TFrmMain
Font.Style = []
ParentColor = False
ParentFont = False
Text = '<r>text spacing test</r>'
Lines.Strings = (
'<r>text spacing test</r>')
end
object DzHTMLText6: TDzHTMLText
Left = 168
Expand All @@ -111,13 +118,20 @@ object FrmMain: TFrmMain
Font.Style = []
ParentColor = False
ParentFont = False
Text =
'<b>Spoiler Test:</b>'#13#10'<spoiler:sp1>Click here for details</spoil' +
'er><sdetail:sp1>'#13#10' Some detailed info about this spoiler.'#13#10'<s' +
'poiler:sp2>'#13#10' Click here for sub-details</spoiler><sdetail:sp' +
'2>'#13#10' Some detailed info about this sub-spoiler.</sdetail>' +
'</sdetail>'#13#10#13#10'You can open first spoiler <spoiler:sp1>here</spoi' +
'ler> too.'#13#10#13#10'<sdetail:sp1><i>This is more info about the first s' +
'poiler</i></sdetail>'
Lines.Strings = (
'<b>Spoiler Test:</b>'
'<spoiler:sp1>Click here for details</spoiler><sdetail:sp1>'
' Some detailed info about this spoiler.'
'<spoiler:sp2>'
' Click here for sub-details</spoiler><sdetail:sp2>'

' Some detailed info about this sub-spoiler.</sdetail></sd' +
'etail>'
''
'You can open first spoiler <spoiler:sp1>here</spoiler> too.'
''

'<sdetail:sp1><i>This is more info about the first spoiler</i></s' +
'detail>')
end
end

0 comments on commit 4abfad5

Please sign in to comment.