-
Notifications
You must be signed in to change notification settings - Fork 33
/
HGM.Controls.EditPanel.pas
384 lines (336 loc) · 8.92 KB
/
HGM.Controls.EditPanel.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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
unit HGM.Controls.EditPanel;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.StdCtrls,
Vcl.ExtCtrls, HGM.Common;
type
TOnPressEnter = procedure(Sender: TObject; var AllowNext: Boolean) of object;
TEditPanel = class(TPanel)
private
FEdit: TEdit;
FLabel: TLabel;
FEnterColor: TColor;
FLeaveColor: TColor;
FEnter: Boolean;
FErrorColor: TColor;
FOnPressEnter: TOnPressEnter;
procedure EditKeyPress(Sender: TObject; var Key: Char);
procedure EditKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure OnPanelEnter(Sender: TObject);
procedure OnPanelExit(Sender: TObject);
procedure WMSize(var Message: TWMSize); message WM_SIZE;
procedure EditMouseEnter(Sender: TObject);
procedure EditMouseLeave(Sender: TObject);
procedure SetEnterColor(const Value: TColor);
procedure UpdateColor;
function GetEditWidth: Integer;
procedure SetEditWidth(const Value: Integer);
procedure UpdateLableSise;
function GetCaption: string;
procedure SetCaption(const Value: string);
procedure SetupInternalLabel;
procedure SetupInternalEdit;
function GetLabelWidth: Integer;
procedure SetLabelWidth(const Value: Integer);
function GetLabelFont: TFont;
procedure SetLabelFont(const Value: TFont);
function GetText: string;
procedure SetText(const Value: string);
function GetTextHint: string;
procedure SetTextHint(const Value: string);
function GetEditFont: TFont;
procedure SetEditFont(const Value: TFont);
procedure SetLeaveColor(const Value: TColor);
function GetAlignment: TAlignment;
procedure SetAlignment(const Value: TAlignment);
function GetLayout: TTextLayout;
procedure SetLayout(const Value: TTextLayout);
protected
procedure SetParent(AParent: TWinControl); override;
// property ShowCaption:Boolean; reintroduce;
public
constructor Create(AOwner: TComponent); override;
procedure ErrorFlash;
published
property Caption: string read GetCaption write SetCaption;
property EnterColor: TColor read FEnterColor write SetEnterColor;
property LeaveColor: TColor read FLeaveColor write SetLeaveColor;
property EditWidth: Integer read GetEditWidth write SetEditWidth;
property LebelWidth: Integer read GetLabelWidth write SetLabelWidth;
property LabelFont: TFont read GetLabelFont write SetLabelFont;
property EditFont: TFont read GetEditFont write SetEditFont;
property Text: string read GetText write SetText;
property TextHint: string read GetTextHint write SetTextHint;
property OnPressEnter: TOnPressEnter read FOnPressEnter write FOnPressEnter;
property Alignment: TAlignment read GetAlignment write SetAlignment;
property VerticalAlignment: TTextLayout read GetLayout write SetLayout;
property ErrorColor: TColor read FErrorColor write FErrorColor;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents(PackageName, [TEditPanel]);
end;
{ TEditPanel }
procedure TEditPanel.EditKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
var
Frm: TCustomForm;
begin
if Key in [VK_UP] then
begin
Key := 0;
Frm := GetParentForm(TCustomForm(Self));
if not (Frm = nil) then
SendMessage(Frm.Handle, WM_NEXTDLGCTL, 1, 0);
end
else if Key in [VK_DOWN] then
begin
Key := 0;
Frm := GetParentForm(Self);
if not (Frm = nil) then
SendMessage(Frm.Handle, WM_NEXTDLGCTL, 0, 0);
end;
end;
procedure TEditPanel.EditKeyPress(Sender: TObject; var Key: Char);
var
AllowNext: Boolean;
var
Frm: TCustomForm;
begin
if Key = #13 then
begin
Key := #0;
AllowNext := True;
if Assigned(FOnPressEnter) then
FOnPressEnter(Sender, AllowNext);
if AllowNext then
begin
Frm := GetParentForm(Self);
if not (Frm = nil) then
SendMessage(Frm.Handle, WM_NEXTDLGCTL, 0, 0);
end;
end;
end;
procedure TEditPanel.SetupInternalEdit;
begin
//if Assigned(FEdit) then Exit;
FEdit := TEdit.Create(Self);
FEdit.Parent := Self;
FEdit.AutoSize := False;
FEdit.Width := 200;
FEdit.AlignWithMargins := True;
FEdit.Margins.Left := 5;
FEdit.Margins.Top := 10;
FEdit.Margins.Right := 10;
FEdit.Margins.Bottom := 10;
FEdit.Align := alNone;
FEdit.Name := Name + 'FEdit';
FEdit.Text := 'Òåêñò';
FEdit.OnKeyDown := EditKeyDown;
FEdit.OnKeyPress := EditKeyPress;
FEdit.OnEnter := EditMouseEnter;
FEdit.OnExit := EditMouseLeave;
FEdit.Visible := True;
end;
procedure TEditPanel.SetupInternalLabel;
begin
//if Assigned(FLabel) then Exit;
FLabel := TLabel.Create(Self);
FLabel.Parent := Self;
FLabel.AutoSize := False;
FLabel.AlignWithMargins := True;
FLabel.Margins.Left := 5;
FLabel.Margins.Top := 10;
FLabel.Margins.Right := 0;
FLabel.Margins.Bottom := 10;
FLabel.Align := alNone;
FLabel.Alignment := taLeftJustify;
FLabel.WordWrap := True;
FLabel.Font.Color := clGray;
FLabel.Layout := tlCenter;
FLabel.Name := Name + 'FLabel';
FLabel.Caption := 'Çàãîëîâîê';
FLabel.OnClick := OnPanelEnter;
FLabel.Width := 200;
FLabel.Visible := True;
end;
constructor TEditPanel.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FEdit := nil;
FLabel := nil;
FErrorColor := $000033CC;
Color := clWhite;
FEnter := False;
FEnterColor := $0095E7FA;
FLeaveColor := Color;
UpdateColor;
Width := 420;
BevelOuter := bvNone;
ShowCaption := False;
ParentBackground := False;
OnEnter := OnPanelEnter;
OnClick := OnPanelEnter;
OnExit := OnPanelExit;
SetupInternalLabel;
SetupInternalEdit;
VerticalAlignment := tlCenter;
Alignment := taLeftJustify;
Caption := 'Çàãîëîâîê';
Text := '';
TextHint := '';
UpdateLableSise;
end;
procedure TEditPanel.SetParent(AParent: TWinControl);
begin
inherited SetParent(AParent);
end;
procedure TEditPanel.SetText(const Value: string);
begin
FEdit.Text := Value;
end;
procedure TEditPanel.SetTextHint(const Value: string);
begin
FEdit.TextHint := Value;
end;
procedure TEditPanel.EditMouseEnter(Sender: TObject);
begin
FEnter := True;
UpdateColor;
end;
procedure TEditPanel.EditMouseLeave(Sender: TObject);
begin
FEnter := False;
UpdateColor;
end;
procedure TEditPanel.ErrorFlash;
var
DefColor: TColor;
begin
DefColor := Color;
Color := FErrorColor;
Repaint;
Sleep(70);
Color := DefColor;
Repaint;
Sleep(70);
Color := FErrorColor;
Repaint;
Sleep(70);
Color := DefColor;
Repaint;
end;
function TEditPanel.GetAlignment: TAlignment;
begin
Result := FLabel.Alignment;
end;
function TEditPanel.GetCaption: string;
begin
Result := FLabel.Caption;
end;
function TEditPanel.GetEditFont: TFont;
begin
Result := FEdit.Font;
end;
function TEditPanel.GetEditWidth: Integer;
begin
Result := FEdit.Width;
end;
function TEditPanel.GetLabelFont: TFont;
begin
Result := FLabel.Font;
end;
function TEditPanel.GetLabelWidth: Integer;
begin
Result := FLabel.Width;
end;
function TEditPanel.GetLayout: TTextLayout;
begin
Result := FLabel.Layout;
end;
function TEditPanel.GetText: string;
begin
Result := FEdit.Text;
end;
function TEditPanel.GetTextHint: string;
begin
Result := FEdit.TextHint;
end;
procedure TEditPanel.OnPanelEnter(Sender: TObject);
begin
EditMouseEnter(Sender);
FEdit.SetFocus;
end;
procedure TEditPanel.OnPanelExit(Sender: TObject);
begin
EditMouseLeave(Sender);
end;
procedure TEditPanel.SetAlignment(const Value: TAlignment);
begin
FLabel.Alignment := Value;
UpdateLableSise;
end;
procedure TEditPanel.SetCaption(const Value: string);
begin
FLabel.Caption := Value;
end;
procedure TEditPanel.SetEditFont(const Value: TFont);
begin
FEdit.Font := Value;
end;
procedure TEditPanel.SetEditWidth(const Value: Integer);
begin
FEdit.Width := Value;
UpdateLableSise;
end;
procedure TEditPanel.SetEnterColor(const Value: TColor);
begin
FEnterColor := Value;
UpdateColor;
end;
procedure TEditPanel.SetLabelFont(const Value: TFont);
begin
FLabel.Font := Value;
end;
procedure TEditPanel.SetLabelWidth(const Value: Integer);
begin
FLabel.Width := Value;
UpdateLableSise;
end;
procedure TEditPanel.SetLayout(const Value: TTextLayout);
begin
FLabel.Layout := Value;
end;
procedure TEditPanel.SetLeaveColor(const Value: TColor);
begin
FLeaveColor := Value;
UpdateColor;
end;
procedure TEditPanel.UpdateColor;
begin
case FEnter of
True:
Color := FEnterColor;
False:
Color := FLeaveColor;
end;
end;
procedure TEditPanel.UpdateLableSise;
begin
if (not Assigned(FLabel)) or (not Assigned(FEdit)) then
Exit;
FLabel.Top := FLabel.Margins.Top;
FLabel.Height := Height - (FLabel.Margins.Top + FLabel.Margins.Bottom);
FLabel.Left := FLabel.Margins.Left;
FEdit.Left := FLabel.Left + FLabel.Width + FEdit.Margins.Left;
FEdit.Top := FEdit.Margins.Top;
FEdit.Height := Self.Height - (FEdit.Margins.Top + FEdit.Margins.Bottom);
Refresh;
end;
procedure TEditPanel.WMSize(var Message: TWMSize);
begin
UpdateLableSise;
end;
end.