-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSpkExpander.inc
More file actions
228 lines (196 loc) · 4.97 KB
/
SpkExpander.inc
File metadata and controls
228 lines (196 loc) · 4.97 KB
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
{%MainUnit SpkCtrls.pp}
(*
TCustomSpkExpander
*)
(*
PROTECTED
*)
function TCustomSpkExpander.AllowUserChangeExpansion(): Boolean;
begin
Result := True;
end;
procedure TCustomSpkExpander.MouseMove(Shift: TShiftState; X,Y: Integer);
begin
if Self.FTitlebar.Contains(X, Y) then
begin
if FButtonRect.Contains(X, Y) then
begin
FButtonState:= bsBtnHottrack;
UpdateAppearance();
end
else
begin
FButtonState := bsIdle;
UpdateAppearance();
end;
end
else
inherited MouseMove(Shift, X,Y);
end;
procedure TCustomSpkExpander.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if (Button = MouseClick) and FButtonRect.Contains(X, Y) then
begin
FButtonState:= bsBtnPressed;
UpdateAppearance();
end
else
inherited MouseDown(Button, Shift, X, Y);
end;
procedure TCustomSpkExpander.MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if (Button = MouseClick) and FButtonRect.Contains(X, Y) then
begin
FButtonState := bsBtnHottrack;
UpdateAppearance();
if Self.AllowUserChangeExpansion() then
SetExpanded( not FExpanded );
end
else
inherited MouseUp(Button, Shift, X, Y);
end;
procedure TCustomSpkExpander.MouseLeave;
begin
if (FButtonState <> bsIdle) then
begin
FButtonState := bsIdle;
UpdateAppearance();
end;
end;
procedure TCustomSpkExpander.DoOnResize;
begin
inherited DoOnResize();
if FExpanded then
FExpandSize := Self.Height;
end;
procedure TCustomSpkExpander.KeyDown(var Key: Word; Shift: TShiftState);
begin
if (Key = SPK_ACTIVATE_KEY) or (Key = SPK_SELECT_KEY) or (Key = SPK_ENTER_KEY) then
Self.Expanded := not Self.Expanded;
end;
procedure TCustomSpkExpander.SetExpanded(const AValue: Boolean);
begin
if (AValue = FExpanded) then
Exit;
if AValue then
DoExpand()
else
DoCollapse();
end;
procedure TCustomSpkExpander.DoCollapse();
begin
FExpanded := False;
Self.Height := FTitle.Bottom + PaneBorderHalfSize;
if Assigned(FOnCollapsed) then
FOnCollapsed(Self);
UpdateAppearance();
end;
procedure TCustomSpkExpander.DoExpand();
begin
Self.Height := FExpandSize;
FExpanded := True;
if Assigned(FOnExpanded) then
FOnExpanded(Self);
UpdateAppearance();
end;
function TCustomSpkExpander.CalcRect(): T2DIntRect;
var
L,H: Integer;
begin
Result := inherited CalcRect();
if Self.IsRightToLeft then
L := PaneBorderSize
else
L := Self.Width - ((2 * DropdownArrowWidth) + (2 * PaneBorderSize));
H := (FTitlebar.Bottom - (2 * DropdownArrowHeight)) div 2;
{$IFDEF EnhancedRecordSupport}
FButtonRect := T2DIntRect.Create(
{$ELSE}
FButtonRect.Create(
{$ENDIF}
L,
H,
L + (2 * DropdownArrowWidth),
H + (2 * DropdownArrowHeight));
end;
procedure TCustomSpkExpander.DoDraw(const ABuffer: TBitmap);
var
fontColor: TColor;
frameColor, innerLightColor, innerDarkColor: TColor;
gradientFromColor, gradientToColor: TColor;
gradientKind: TBackgroundKind;
cornerRadius: Integer;
ClipRect: T2DIntRect;
begin
inherited DoDraw(ABuffer);
if (FToolbar = nil) or (FToolbar.Appearance = nil) then
Exit;
ClipRect := FRect;
case FToolbar.Appearance.Element.Style of
esRounded:
cornerRadius := SmallButtonRadius;
esRectangle:
cornerRadius := 0;
end;
if (FButtonState = bsIdle) and ( (FBorder <> sbNone) or (FBorder <> sbFlat) ) then
begin
FToolbar.Appearance.Element.GetIdleColors(False,
fontColor, frameColor, innerLightColor, innerDarkColor,
gradientFromColor, gradientToColor, gradientKind
);
end else
if (FButtonState = bsBtnHottrack) then
begin
FToolbar.Appearance.Element.GetHotTrackColors(False,
fontColor, frameColor, innerLightColor, innerDarkColor,
gradientFromColor, gradientToColor, gradientKind
);
end else
if (FButtonState = bsBtnPressed) then
begin
FToolbar.Appearance.Element.GetActiveColors(True,
fontColor, frameColor, innerLightColor, innerDarkColor,
gradientFromColor, gradientToColor, gradientKind
);
end;
if (FButtonState <> bsIdle) then
TButtonTools.DrawButton(
ABuffer,
FButtonRect,
frameColor,
innerLightColor,
innerDarkColor,
gradientFromColor,
gradientToColor,
gradientKind,
false,
false,
false,
false,
cornerRadius,
ClipRect
)
else
begin
if FocusOpt and (Screen.ActiveControl = Self) then
TSpkCtrlsAux.DrawControlCustomFocus(Self, ABuffer, FButtonRect.ForWinAPI, fontColor);
end;
TSpkCtrlsAux.DrawUpAndDownArrow(ABuffer, FButtonRect.ForWinAPI, fontColor, FExpanded, 2);
end;
(*
PUBLIC
*)
constructor TCustomSpkExpander.Create(AOwner: TComponent);
begin
FExpanded := True;
inherited Create(AOwner);
FTitleAlign := True;
FOnExpanded := nil;
FOnCollapsed:= nil;
TabStop := True;
end;
procedure TCustomSpkExpander.Collapse();
begin
if FExpanded then
DoCollapse();
end;