-
Notifications
You must be signed in to change notification settings - Fork 2
/
bgrathemeradiobutton.pas
174 lines (147 loc) · 3.95 KB
/
bgrathemeradiobutton.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
// SPDX-License-Identifier: LGPL-3.0-only (modified to allow linking)
unit BGRAThemeRadioButton;
{$mode delphi}
interface
uses
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs,
BGRATheme, Types;
type
{ TBGRAThemeRadioButton }
TBGRAThemeRadioButton = class(TCustomControl)
private
FChecked: boolean;
FOnChange: TNotifyEvent;
FTheme: TBGRATheme;
FState: TBGRAThemeButtonState;
procedure SetFChecked(AValue: boolean);
procedure SetFTheme(AValue: TBGRATheme);
protected
class function GetControlClassDefaultSize: TSize; override;
procedure MouseEnter; override;
procedure MouseLeave; override;
procedure MouseDown(Button: TMouseButton; Shift: TShiftState;
X, Y: integer); override;
procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: integer); override;
procedure Click; override;
procedure SetEnabled(Value: boolean); override;
procedure TextChanged; override;
procedure Paint; override;
procedure UncheckOthers;
public
constructor Create(AOwner: TComponent); override;
published
property Caption;
property Checked: boolean read FChecked write SetFChecked;
property Font;
property Enabled;
property Theme: TBGRATheme read FTheme write SetFTheme;
property OnChange: TNotifyEvent read FOnChange write FOnChange;
end;
procedure Register;
implementation
uses BGRABitmapTypes;
procedure Register;
begin
RegisterComponents('BGRA Themes', [TBGRAThemeRadioButton]);
end;
{ TBGRAThemeRadioButton }
procedure TBGRAThemeRadioButton.SetFTheme(AValue: TBGRATheme);
begin
if FTheme = AValue then
Exit;
FTheme := AValue;
Invalidate;
end;
procedure TBGRAThemeRadioButton.SetFChecked(AValue: boolean);
begin
if FChecked = AValue then
Exit;
FChecked := AValue;
if FChecked then
UncheckOthers;
Invalidate;
if Assigned(FOnChange) then FOnChange(Self);
end;
class function TBGRAThemeRadioButton.GetControlClassDefaultSize: TSize;
begin
Result.CX := 165;
Result.CY := 19;
end;
procedure TBGRAThemeRadioButton.MouseEnter;
begin
inherited MouseEnter;
FState := btbsHover;
Invalidate;
end;
procedure TBGRAThemeRadioButton.MouseLeave;
begin
inherited MouseLeave;
FState := btbsNormal;
Invalidate;
end;
procedure TBGRAThemeRadioButton.MouseDown(Button: TMouseButton;
Shift: TShiftState; X, Y: integer);
begin
inherited MouseDown(Button, Shift, X, Y);
FState := btbsActive;
SetFChecked(True);
end;
procedure TBGRAThemeRadioButton.MouseUp(Button: TMouseButton;
Shift: TShiftState; X, Y: integer);
begin
inherited MouseUp(Button, Shift, X, Y);
if ClientRect.Contains(Point(X, Y)) then
FState := btbsHover
else
FState := btbsNormal;
Invalidate;
end;
procedure TBGRAThemeRadioButton.Click;
begin
inherited Click;
end;
procedure TBGRAThemeRadioButton.SetEnabled(Value: boolean);
begin
inherited SetEnabled(Value);
if Value then
FState := btbsNormal
else
FState := btbsDisabled;
Invalidate;
end;
procedure TBGRAThemeRadioButton.TextChanged;
begin
inherited TextChanged;
Invalidate;
end;
procedure TBGRAThemeRadioButton.Paint;
begin
if Assigned(Theme) then
Theme.DrawRadioButton(Caption, FState, Focused, Checked, ClientRect, Canvas)
else
BGRADefaultTheme.DrawRadioButton(Caption, FState, Focused, Checked,
ClientRect, Canvas);
end;
procedure TBGRAThemeRadioButton.UncheckOthers;
var
i: integer;
control: TWinControl;
begin
if Parent is TWinControl then
begin
control := TWinControl(Parent);
for i := 0 to control.ControlCount - 1 do
if (control.Controls[i] <> Self) and (control.Controls[i] is
TBGRAThemeRadioButton) then
TBGRAThemeRadioButton(control.Controls[i]).Checked := False;
end;
end;
constructor TBGRAThemeRadioButton.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FState := btbsNormal;
ControlStyle := ControlStyle + [csParentBackground];
with GetControlClassDefaultSize do
SetInitialBounds(0, 0, CX, CY);
end;
end.