-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathEMLinkLabel.pas
210 lines (174 loc) · 4.89 KB
/
EMLinkLabel.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
{***************************************************************
*
* Unit Name: EMLinkLabel
* Purpose: Link Label
* Author: Eugen Mihailescu
* Company: EM Quicksoft Romania SRL
* Copyright: 1998,2002 © All rights reserved.
* Web Site: http://www.em-quicksoft.com
* Support: [email protected]
* History: 03/19/2000
*
* Disclaimer: The objectives of this program is only educational.
* You MUST NOT use it without getting any material benefit on it
* You have the right to share this code with others without removing
* the copyright and/or disclaimer notice.
* You are allowed to include its code in your application
* only if it was designed for non commercial purpose,
* otherwise we claim $10 for each copy of your
* application which contains this code inside.
****************************************************************}
unit EMLinkLabel;
interface
uses
Windows,
Messages,
SysUtils,
Classes,
Graphics,
Controls,
Forms,
Dialogs,
StdCtrls,
Shellapi,
MMSystem;
Type
TLinkLabel = class(TLabel)
private
FLinkDestination: string;
FLinkColor: TColor;
FLinkColorMouseMove: TColor;
FLinkSound: Boolean;
FTabOrder: TTabOrder;
protected
procedure SetLinkDestination(const Value: string);
procedure Click; override;
procedure CMMouseEnter(var Msg: TMessage); message CM_MOUSEENTER;
procedure CMMouseLeave(var Msg: TMessage); message CM_MOUSELEAVE;
procedure CMFontChanged(var Msg: TMessage); message CM_FONTCHANGED;
procedure SetLinkColor(Value: TColor);
public
constructor Create(AOwner: TComponent); override;
published
property LinkDestination: string read FLinkDestination write SetLinkDestination;
property LinkColor: TColor read FLinkColor write SetLinkColor;
property LinkColorMouseMove: TColor read FLinkColorMouseMove write FLinkColorMouseMove;
property TabOrder: TTabOrder read FTabOrder write FTabOrder default -1;
end;
{$IF declared(TLinkLabel)}
{$ELSE}
procedure Register;
{$ENDIF}
implementation
uses
System.UITypes;
//******************* TLinkLabel.Create *************************
constructor TLinkLabel.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
LinkDestination:= 'http://';
Cursor:= crHandPoint;
Font.Color:= clBlue;
Font.Style:= Font.Style + [fsUnderline];
FLinkColor:= clBlue;
FLinkColorMouseMove:= clRed;
FTabOrder:= -1;
end;
//******************* TLinkLabel.SetLinkDestination *************************
procedure TLinkLabel.SetLinkDestination(const Value: string);
var
p: Integer;
begin
if Value <> FLinkDestination then begin
FLinkDestination:= AnsiLowerCase(Value);
end;
end;
//******************* TLinkLabel.Click *************************
procedure TLinkLabel.Click;
begin
if FLinkDestination <> '' then begin
ShellExecute(TWinControl(Owner).Handle, 'open', PChar(LinkDestination), nil, nil, SW_SHOW);
end;
inherited Click;
end;
//******************* TLinkLabel.CMMouseEnter *************************
procedure TLinkLabel.CMMouseEnter(var Msg: TMessage);
begin
Font.Color:= FLinkColorMouseMove;
Refresh;
end;
//******************* TLinkLabel.CMMouseLeave *************************
procedure TLinkLabel.CMMouseLeave(var Msg: TMessage);
begin
Font.Color:= FLinkColor;
Refresh;
end;
//******************* TLinkLabel.SetLinkColor *************************
procedure TLinkLabel.SetLinkColor(Value: TColor);
begin
if Value <> FLinkColor then begin
FLinkColor:= Value;
Font.Color:= FLinkColor;
Refresh;
end;
end;
//******************* TLinkLabel.CMFontChanged *************************
procedure TLinkLabel.CMFontChanged(var Msg: TMessage);
begin
if csDesigning In ComponentState then begin
FLinkColor:= Font.Color;
Refresh;
end;
end;
{$IF declared(TLinkLabel)}
{$ELSE}
procedure Register;
begin
RegisterComponents('EM-Quicksoft', [TLinkLabel]);
end;
{$ENDIF}
procedure TLinkLabel.ChangeColors;
begin
if FAutoColors then
if FVisited then Font.Color:=clVisited else Font.Color:=clUnvisited
else
if FVisited then Font.Color:=FColorVisited else Font.Color:=FColorUnvisited
end;
procedure TLinkLabel.SetAutoColors(AutoCol : Boolean);
begin
if AutoCol<>FAutoColors then begin
FAutoColors:=AutoCol;
ChangeColors;
end;
end;
procedure TLinkLabel.SetColorUnvisited(Col : TColor);
begin
if FColorUnvisited<>Col then begin
FColorUnvisited:=Col;
if not FAutoColors then ChangeColors;
end;
end;
procedure TLinkLabel.SetColorVisited(Col : TColor);
begin
if FColorVisited<>Col then begin
FColorVisited:=Col;
if not FAutoColors then ChangeColors;
end;
end;
procedure TLinkLabel.SetVisited(Vis : Boolean);
begin
if FVisited<>Vis then begin
FVisited:=Vis;
ChangeColors;
end;
end;
procedure TLinkLabel.WMClick(var Msg : TMessage);
begin
inherited;
ShellExecute(0, 'open', PChar(FHREF), '', '', SW_SHOW);
end;
procedure Register;
begin
RegisterComponents('Additional', [TLinkLabel]);
end;
end.