forked from kmerlotti/FGX-FireMonkey
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FmGX.LinkedLabel.pas
194 lines (169 loc) · 4.58 KB
/
FmGX.LinkedLabel.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
{*********************************************************************
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* Autor: Brovin Y.D.
* E-mail: [email protected]
*
********************************************************************}
unit FmGX.LinkedLabel;
interface
uses
System.Classes, System.UITypes, FMX.StdCtrls, FMX.Controls, FMX.Objects, FMX.Types, FmGX.Consts;
type
{ TfgLinkedLabel }
IFGXLaunchService = interface;
TfgCustomLinkedLabel = class(TLabel)
public const
DefaultCursor = crHandPoint;
DefaultColor = TAlphaColorRec.Black;
DefaultColorHover = TAlphaColorRec.Blue;
DefaultColorVisited = TAlphaColorRec.Magenta;
DefaultVisited = False;
private const
IndexColor = 0;
IndexHoverColor = 1;
IndexVisitedColor = 2;
private
FLaunchService: IFGXLaunchService;
FUrl: string;
FVisited: Boolean;
FColor: TAlphaColor;
FHoverColor: TAlphaColor;
FVisitedColor: TAlphaColor;
procedure SetColor(const Index: Integer; const Value: TAlphaColor);
procedure SetVisited(const Value: Boolean);
protected
{ Styles }
function GetDefaultStyleLookupName: string; override;
{ Painting }
procedure Paint; override;
{ Mouse events }
procedure DoMouseEnter; override;
procedure DoMouseLeave; override;
procedure Click; override;
procedure UpdateColor;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
public
property Color: TAlphaColor index IndexColor read FColor write SetColor default DefaultColor;
property HoverColor: TAlphaColor index IndexHoverColor read FHoverColor write SetColor default DefaultColorHover;
property Url: string read FUrl write FUrl;
property Cursor default DefaultCursor;
property Visited: Boolean read FVisited write SetVisited default DefaultVisited;
property VisitedColor: TAlphaColor index IndexVisitedColor read FVisitedColor write SetColor default DefaultColorVisited;
end;
[ComponentPlatformsAttribute(fgAllPlatform)]
TfgLinkedLabel = class(TfgCustomLinkedLabel)
published
property Cursor;
property Color;
property HoverColor;
property Url;
property VisitedColor;
property Visited;
end;
{ IFMXLaunchService }
IFGXLaunchService = interface
['{5BFFA845-EB02-480C-AFE9-EB15DE06AF10}']
function OpenURL(const AUrl: string): Boolean;
end;
implementation
uses
FMX.Platform
{$IFDEF MSWINDOWS}
, FmGX.LinkedLabel.Win
{$ENDIF}
{$IFDEF IOS}
, FmGX.LinkedLabel.iOS
{$ELSE}
{$IFDEF MACOS}
, FmGX.LinkedLabel.Mac
{$ENDIF}
{$ENDIF}
{$IFDEF ANDROID}
, FmGX.LinkedLabel.Android
{$ENDIF}
;
{ TLinkedLabel }
procedure TfgCustomLinkedLabel.Click;
begin
if FLaunchService <> nil then
begin
FVisited := True;
Repaint;
FLaunchService.OpenURL(Url);
end;
end;
constructor TfgCustomLinkedLabel.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
HitTest := True;
Font.Style := [TFontStyle.fsUnderline];
StyledSettings := [];
Cursor := DefaultCursor;
FVisited := DefaultVisited;
FColor := DefaultColor;
FHoverColor := DefaultColorHover;
FVisitedColor := DefaultColorVisited;
TPlatformServices.Current.SupportsPlatformService(IFGXLaunchService, FLaunchService);
end;
destructor TfgCustomLinkedLabel.Destroy;
begin
FLaunchService := nil;
inherited Destroy;
end;
procedure TfgCustomLinkedLabel.DoMouseEnter;
begin
inherited DoMouseEnter;
Repaint;
end;
procedure TfgCustomLinkedLabel.DoMouseLeave;
begin
inherited DoMouseLeave;
Repaint;
end;
function TfgCustomLinkedLabel.GetDefaultStyleLookupName: string;
begin
Result := 'LabelStyle';
end;
procedure TfgCustomLinkedLabel.Paint;
begin
UpdateColor;
inherited Paint;
end;
procedure TfgCustomLinkedLabel.SetColor(const Index: Integer; const Value: TAlphaColor);
begin
case Index of
IndexColor: FColor := Value;
IndexHoverColor: FHoverColor := Value;
IndexVisitedColor: FVisitedColor := Value;
end;
Repaint;
end;
procedure TfgCustomLinkedLabel.SetVisited(const Value: Boolean);
begin
if Visited <> Value then
begin
FVisited := Value;
UpdateColor;
end;
end;
procedure TfgCustomLinkedLabel.UpdateColor;
begin
if IsMouseOver then
TextSettings.FontColor := FHoverColor
else if FVisited then
TextSettings.FontColor := FVisitedColor
else
TextSettings.FontColor := Color;
end;
initialization
RegisterFmxClasses([TfgCustomLinkedLabel, TfgLinkedLabel]);
RegisterService;
finalization
UnregisterService;
end.