-
Notifications
You must be signed in to change notification settings - Fork 33
/
HGM.Controls.PanelCollapsed.pas
283 lines (252 loc) · 7.22 KB
/
HGM.Controls.PanelCollapsed.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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
unit HGM.Controls.PanelCollapsed;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls,
Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls, HGM.Controls.PanelExt, Vcl.Buttons, Vcl.Imaging.pngimage,
HGM.Common;
type
TPanelCollapsed = class(TPanelExt)
private
FCaptionPanel: TPanel;
FCollapsing: Boolean;
FHeight: Integer;
FCollapseButton: TSpeedButton;
// FOnPaint: TNotifyEvent;
FShowSimpleBorder: Boolean;
FSimpleBorderColor: TColor;
FCollapsed: Boolean;
FCapHeight: Integer;
function GetCaption: string;
procedure SetCaption(const Value: string);
function GetShowCaption: Boolean;
procedure SetShowCaption(const Value: Boolean);
function GetFontCaption: TFont;
procedure SetFontCaption(const Value: TFont);
procedure SetAlignment(const Value: TAlignment);
function GetAlignment: TAlignment;
function GetCaptionColor: TColor;
procedure SetCaptionColor(const Value: TColor);
procedure SetShowSimpleBorder(const Value: Boolean);
procedure OnCollapseButtonClick(Sender: TObject);
function GetHeight: Integer;
procedure SetHeight(const Value: Integer);
procedure SetCollapsed(const Value: Boolean);
procedure WMSize(var Msg: TWMSize); message WM_SIZE;
function GetShowCollapseButton: Boolean;
procedure SetShowCollapseButton(const Value: Boolean);
procedure SetCapHeight(const Value: Integer);
public
procedure Paint; override;
published
property ShowCollapseButton: Boolean read GetShowCollapseButton write SetShowCollapseButton;
property Collapsed: Boolean read FCollapsed write SetCollapsed;
property Height: Integer read GetHeight write SetHeight;
property Caption: string read GetCaption write SetCaption;
property Alignment: TAlignment read GetAlignment write SetAlignment default taCenter;
property Font;
property SimpleBorderColor: TColor read FSimpleBorderColor write FSimpleBorderColor;
property CaptionColor: TColor read GetCaptionColor write SetCaptionColor;
property FontCaption: TFont read GetFontCaption write SetFontCaption;
property ShowCaption: Boolean read GetShowCaption write SetShowCaption;
property ShowSimpleBorder: Boolean read FShowSimpleBorder write SetShowSimpleBorder;
property VerticalAlignment;
property CaptionHeight: Integer read FCapHeight write SetCapHeight;
constructor Create(AOwner: TComponent); override;
end;
procedure Register;
implementation
{$R hCollPanel.res}
procedure Register;
begin
RegisterComponents(PackageName, [TPanelCollapsed]);
end;
{ TPanelCollapsed }
constructor TPanelCollapsed.Create(AOwner: TComponent);
var
PNG: TPngImage;
begin
inherited;
inherited ShowCaption := False;
inherited BorderStyle := bsNone;
inherited BevelInner := bvNone;
inherited BevelKind := bkNone;
inherited BevelOuter := bvNone;
inherited ParentBackground := False;
FCollapsing := False;
Height := 300;
FCapHeight := 30;
FCaptionPanel := TPanel.Create(Self);
with FCaptionPanel do
begin
Parent := Self;
Align := alTop;
Height := FCapHeight;
Caption := ' Caption';
ShowCaption := True;
ParentBackground := False;
ParentColor := False;
BorderStyle := bsNone;
BevelInner := bvNone;
BevelKind := bkNone;
BevelOuter := bvNone;
BringToFront;
Color := clGray;
Font.Color := clWhite;
Font.Style := [fsBold];
Font.Size := 10;
Alignment := taLeftJustify;
OnClick := OnCollapseButtonClick;
end;
FCollapseButton := TSpeedButton.Create(FCaptionPanel);
with FCollapseButton do
begin
Parent := FCaptionPanel;
Align := alRight;
AlignWithMargins := True;
PNG := TPngImage.Create;
PNG.LoadFromResourceName(HInstance, 'COLPANEL_HIDE');
Glyph.Assign(PNG);
PNG.Free;
Flat := True;
OnClick := OnCollapseButtonClick;
end;
ShowSimpleBorder := False;
SimpleBorderColor := clSilver;
end;
function TPanelCollapsed.GetAlignment: TAlignment;
begin
Result := FCaptionPanel.Alignment;
end;
function TPanelCollapsed.GetCaption: string;
begin
Result := FCaptionPanel.Caption;
end;
function TPanelCollapsed.GetCaptionColor: TColor;
begin
Result := FCaptionPanel.Color;
end;
function TPanelCollapsed.GetFontCaption: TFont;
begin
Result := FCaptionPanel.Font;
end;
function TPanelCollapsed.GetHeight: Integer;
begin
Result := FHeight;
end;
function TPanelCollapsed.GetShowCaption: Boolean;
begin
Result := FCaptionPanel.ShowCaption;
end;
function TPanelCollapsed.GetShowCollapseButton: Boolean;
begin
Result := FCollapseButton.Visible;
end;
procedure TPanelCollapsed.OnCollapseButtonClick(Sender: TObject);
begin
if not FCollapseButton.Visible then
Exit;
Collapsed := not Collapsed;
end;
procedure TPanelCollapsed.Paint;
begin
inherited;
if FShowSimpleBorder then
begin
with Canvas do
begin
Pen.Color := FSimpleBorderColor;
Brush.Style := bsClear;
Rectangle(ClientRect);
end;
end;
end;
procedure TPanelCollapsed.SetAlignment(const Value: TAlignment);
begin
FCaptionPanel.Alignment := Value;
end;
procedure TPanelCollapsed.SetCapHeight(const Value: Integer);
begin
FCapHeight := Value;
FCaptionPanel.Height := FCapHeight;
end;
procedure TPanelCollapsed.SetCaption(const Value: string);
begin
FCaptionPanel.Caption := Value;
end;
procedure TPanelCollapsed.SetCaptionColor(const Value: TColor);
begin
FCaptionPanel.Color := Value;
end;
procedure TPanelCollapsed.SetCollapsed(const Value: Boolean);
begin
if FCollapsing then
Exit;
FCollapsing := True;
FCollapsed := Value;
if FCollapsed then
begin {
while inherited Height > FCaptionPanel.Height+2 do
begin
inherited Height:=inherited Height - 3;
Application.ProcessMessages;
Sleep(1);
end; }
inherited Height := FCaptionPanel.Height + 2;
end
else
begin {
while inherited Height < FHeight do
begin
inherited Height:=inherited Height + 3;
Application.ProcessMessages;
Sleep(1);
end; }
inherited Height := FHeight;
end;
FCollapsing := False;
end;
procedure TPanelCollapsed.SetFontCaption(const Value: TFont);
begin
FCaptionPanel.Font := Value;
end;
procedure TPanelCollapsed.SetHeight(const Value: Integer);
begin
FHeight := Value;
if not Collapsed then
inherited Height := FHeight;
end;
procedure TPanelCollapsed.SetShowCaption(const Value: Boolean);
begin
FCaptionPanel.ShowCaption := Value;
end;
procedure TPanelCollapsed.SetShowCollapseButton(const Value: Boolean);
begin
FCollapseButton.Visible := Value;
end;
procedure TPanelCollapsed.SetShowSimpleBorder(const Value: Boolean);
begin
FShowSimpleBorder := Value;
if FShowSimpleBorder then
begin
FCaptionPanel.AlignWithMargins := True;
FCaptionPanel.Margins.Left := 1;
FCaptionPanel.Margins.Top := 1;
FCaptionPanel.Margins.Right := 1;
FCaptionPanel.Margins.Bottom := 0;
end
else
begin
FCaptionPanel.AlignWithMargins := False;
FCaptionPanel.Margins.Left := 1;
FCaptionPanel.Margins.Top := 1;
FCaptionPanel.Margins.Right := 1;
FCaptionPanel.Margins.Bottom := 0;
end;
Repaint;
end;
procedure TPanelCollapsed.WMSize(var Msg: TWMSize);
begin
inherited;
//if not FCollapsing then if Collapsed then Collapsed:=False;
end;
end.