This repository has been archived by the owner on Nov 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathEvilWorks.Vcl.MarkupControl.pas
146 lines (118 loc) · 2.73 KB
/
EvilWorks.Vcl.MarkupControl.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
//
// Supported elements:
// <b>Bold text</b>
// <i>Italic text</i>
// <u>Underlined text<u>
// <s>Strinkeout text</s>
// <font name="Segoe UI" size="10pt" color="#FF0000">Defines a font</font>
// <a href="http://www.example.com>Link text</a>
// <p>Paragraph</p>
// <br>Line break
//
unit EvilWorks.Vcl.MarkupControl;
interface
uses
Winapi.Windows,
WinApi.Messages,
System.SysUtils,
System.Classes,
System.Math,
Vcl.Graphics,
Vcl.Controls,
EvilWorks.System.StrUtils;
type
{ TMarkupCell }
TMarkupCell = class
private
FRect: TRect;
public
property Rect: TRect read FRect write FRect;
end;
{ TMarkupControl }
TMarkupControl = class(TCustomControl)
private
FText : string;
procedure SetText(const Value: string);
function GetTransparent: Boolean;
procedure SetTransparent(const Value: Boolean);
protected
procedure ParseMarkup;
procedure CreateParams(var aParams: TCreateParams); override;
procedure Resize; override;
procedure Paint; override;
procedure CMFontChanged(var aMsg: TMessage); message CM_FONTCHANGED;
public
constructor Create(aOwner: TComponent); override;
destructor Destroy; override;
procedure Assign(aSource: TPersistent); override;
published
property Anchors;
property Align;
property DoubleBuffered;
property Font;
property Text : string read FText write SetText;
property Transparent: Boolean read GetTransparent write SetTransparent default True;
end;
implementation
{ TMarkupControl }
constructor TMarkupControl.Create(aOwner: TComponent);
begin
inherited;
ControlStyle := ControlStyle - [csOpaque];
end;
destructor TMarkupControl.Destroy;
begin
inherited;
end;
procedure TMarkupControl.CreateParams(var aParams: TCreateParams);
begin
inherited CreateParams(aParams);
if (Transparent) then
aParams.ExStyle := aParams.ExStyle or WS_EX_TRANSPARENT;
end;
procedure TMarkupControl.Assign(aSource: TPersistent);
begin
inherited;
if (aSource is TMarkupControl) then
begin
Text := TMarkupControl(aSource).Text;
end;
end;
procedure TMarkupControl.Resize;
begin
inherited;
end;
procedure TMarkupControl.Paint;
begin
inherited;
end;
procedure TMarkupControl.ParseMarkup;
begin
if (FText = '') then
Exit;
end;
procedure TMarkupControl.SetText(const Value: string);
begin
if (FText = Value) then
Exit;
FText := Value;
ParseMarkup;
Invalidate;
end;
function TMarkupControl.GetTransparent: Boolean;
begin
Result := not (csOpaque in ControlStyle);
end;
procedure TMarkupControl.SetTransparent(const Value: Boolean);
begin
if (Value) then
ControlStyle := ControlStyle - [csOpaque]
else
ControlStyle := ControlStyle + [csOpaque];
RecreateWnd;
end;
procedure TMarkupControl.CMFontChanged(var aMsg: TMessage);
begin
Canvas.Font.Assign(Font);
end;
end.