-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathDW.VCL.Edit.pas
319 lines (291 loc) · 8.96 KB
/
DW.VCL.Edit.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
unit DW.VCL.Edit;
interface
uses Classes, Winapi.Windows, System.SysUtils, VCL.Themes, VCL.StdCtrls, VCL.Controls, VCL.Graphics,
DW.VCL.Control, DWElementTag, DWUtils;
type
TDWCustomEdit = class(TDWInputControl)
private
FAlignment: TAlignment;
FMaxLength: Integer;
FPasswordChar: Char;
FReadOnly: Boolean;
FCharCase: TEditCharCase;
// FCreating: Boolean;
// FModified: Boolean;
// FInBufferedPrintClient: Boolean;
FOnChange: TNotifyEvent;
// FOldSelLength: Integer;
// FOldSelStart: Integer;
FNumbersOnly: Boolean;
FTextHint: string;
// FSaveReadOnly: Boolean;
// procedure AdjustHeight;
// function GetModified: Boolean;
// function GetCanUndo: Boolean;
function GetReadOnly: Boolean;
procedure SetCharCase(Value: TEditCharCase);
procedure SetMaxLength(Value: Integer);
// procedure SetModified(Value: Boolean);
procedure SetNumbersOnly(Value: Boolean);
procedure SetPasswordChar(Value: Char);
procedure SetReadOnly(Value: Boolean);
procedure SetTextHint(const Value: string);
// procedure UpdateHeight;
protected
procedure Change; dynamic;
procedure SetAlignment(Value: TAlignment);
property CharCase: TEditCharCase read FCharCase write SetCharCase default ecNormal;
property MaxLength: Integer read FMaxLength write SetMaxLength default 0;
property NumbersOnly: Boolean read FNumbersOnly write SetNumbersOnly default False;
property PasswordChar: Char read FPasswordChar write SetPasswordChar default #0;
property ParentColor default False;
property OnChange: TNotifyEvent read FOnChange write FOnChange;
procedure Paint; override;
procedure InternalRenderHTML(var AHTMLTag: TDWElementTag); override;
procedure InternalRenderAsync(const aHTMLName: string); Override;
// Render Control Inline Style
procedure InternalRenderStyle(AStyle: TStringList); Override;
public
constructor Create(AOwner: TComponent); override;
property Alignment: TAlignment read FAlignment write SetAlignment default taLeftJustify;
property ReadOnly: Boolean read GetReadOnly write SetReadOnly default False;
property Text;
property TextHint: string read FTextHint write SetTextHint;
property Canvas;
published
property TabStop default True;
property Caption;
property Font;
property OnAsyncClick;
property OnAsyncChange;
end;
TDWEdit = class(TDWCustomEdit)
published
property Align;
property Alignment;
property Anchors;
// property AutoSelect;
// property AutoSize;
// property BevelEdges;
// property BevelInner;
// property BevelKind default bkNone;
/// property BevelOuter;
// property BevelWidth;
// property BiDiMode;
// property BorderStyle;
property CharCase;
// property Color;
// property Constraints;
// property Ctl3D;
// property DragCursor;
// property DragKind;
// property DragMode;
property Enabled;
property Font;
// property ImeMode;
// property ImeName;
property MaxLength;
property NumbersOnly;
// property ParentBiDiMode;
// property ParentColor;
// property ParentCtl3D;
// property ParentDoubleBuffered;
// property ParentFont;
// property ParentShowHint;
property PasswordChar;
// property PopupMenu;
property ReadOnly;
property ShowHint;
property TabIndex;
property TabStop;
property Text;
property TextHint;
// property Touch;
property Visible;
// property StyleElements;
property OnChange;
// property OnClick;
// property OnContextPopup;
// property OnDblClick;
// property OnDragDrop;
// property OnDragOver;
// property OnEndDock;
// property OnEndDrag;
// property OnEnter;
// property OnExit;
// property OnGesture;
// property OnKeyDown;
// property OnKeyPress;
// property OnKeyUp;
// property OnMouseActivate;
// property OnMouseDown;
// property OnMouseEnter;
// property OnMouseLeave;
// property OnMouseMove;
// property OnMouseUp;
// property OnStartDock;
// property OnStartDrag
end;
implementation
uses DW.VCL.Common, DW.VCL.InputForm;
{ TDWCustomEdit }
procedure TDWCustomEdit.Change;
begin
Invalidate;
if Assigned(FOnChange) then
FOnChange(Self);
end;
constructor TDWCustomEdit.Create(AOwner: TComponent);
const
EditStyle = [csClickEvents, csSetCaption, csDoubleClicks, csFixedHeight, csPannable];
begin
inherited Create(AOwner);
ControlStyle := EditStyle + [csFramed];
Width := 121;
Height := 25;
TabStop := True;
FAlignment := taLeftJustify;
FNumbersOnly := False;
FTextHint := '';
// TipMode := tipOpen;
// ShowAccelChar := True;
end;
function TDWCustomEdit.GetReadOnly: Boolean;
begin
Result := FReadOnly;
end;
procedure TDWCustomEdit.InternalRenderAsync(const aHTMLName: string);
begin
TDWBSCommon.SetAsyncText(aHTMLName, Text, FOldText);
end;
procedure TDWCustomEdit.InternalRenderHTML(var AHTMLTag: TDWElementTag);
begin
FOldText := Text;
AHTMLTag := TDWElementTag.CreateHtmlTag('input');
with AHTMLTag do
begin
AddStringParam('type', 'text');
AddStringParam('class', 'form-control');
AddStringParam('value', FOldText);
end;
AHTMLTag := TDWElementTag.CreateHtmlTag('input');
try
AHTMLTag.AddClassParam(ActiveCss);
AHTMLTag.AddStringParam('id', HTMLName);
AHTMLTag.AddStringParam('name', HTMLName);
AHTMLTag.AddStringParam('type', 'text');
if ShowHint and (Hint <> '') then
AHTMLTag.AddStringParam('title', Hint);
{ if AutoFocus then
AHTMLTag.Add('autofocus'); }
if IsReadOnly then
AHTMLTag.Add('readonly');
if IsDisabled then
AHTMLTag.Add('disabled');
if MaxLength > 0 then
AHTMLTag.AddIntegerParam('maxlength', MaxLength);
AHTMLTag.AddStringParam('value', Text);
{ if Required then
AHTMLTag.Add('required'); }
{ if PlaceHolder <> '' then
AHTMLTag.AddStringParam('placeholder', TextToHTML(PlaceHolder)); }
if TabIndex <> 0 then
AHTMLTag.AddStringParam('tabindex', IntToStr(TabIndex));
{ AHTMLTag.AddStringParam('autocomplete', IfThen(FAutoComplete, 'on', 'off'));
if Validator <> nil then
Validator.RenderValidation(AHTMLTag); }
// AHTMLTag.AddStringParam('style', ActiveStyle);
except
FreeAndNil(AHTMLTag);
raise;
end;
(* if FMask <> '' then
begin
MaskTag:= TDWElementTag.CreateTag('script');
MaskTag.Contents.AddText( '$("#' + HTMLName + '").mask("' + FMask+ '",{placeholder:" "});');
AHTMLTag.Contents.AddTagAsObject(MaskTag);
end; *)
if not(Parent is TDWInputGroup) then
begin
AHTMLTag := DWCreateInputFormGroup(Self, Parent, AHTMLTag, Caption, HTMLName);
// browsers not respect autocomplete "off" in password inputs,
// to solve this, put another input password hidden,
// it elude browser with password change form
{ TODO 1 -oDELCIO -cIMPLEMENT : Create an TEditPassword }
(* if (InputType = bsitPassword) and (not FAutoComplete) then
begin
FakeAutocomp:= TDWElementTag.CreateTag('input');
FakeAutocomp.AddStringParam('style',
'visibility: hidden; height:0; margin:0; border:0; padding:0;display:block;');
FakeAutocomp.AddStringParam('type', 'password');
if Caption <> '' then
AHTMLTag.Contents.Insert(1, FakeAutocomp)
else
AHTMLTag.Contents.Insert(0, FakeAutocomp);
end; *)
end;
end;
procedure TDWCustomEdit.InternalRenderStyle(AStyle: TStringList);
begin
inherited;
end;
procedure TDWCustomEdit.Paint;
begin
inherited;
end;
procedure TDWCustomEdit.SetAlignment(Value: TAlignment);
begin
if FAlignment <> Value then
begin
FAlignment := Value;
Invalidate;
end;
end;
procedure TDWCustomEdit.SetCharCase(Value: TEditCharCase);
begin
if FCharCase <> Value then
begin
FCharCase := Value;
Invalidate;
end;
end;
procedure TDWCustomEdit.SetMaxLength(Value: Integer);
begin
if FMaxLength <> Value then
begin
FMaxLength := Value;
Invalidate;
end;
end;
procedure TDWCustomEdit.SetNumbersOnly(Value: Boolean);
begin
if FNumbersOnly <> Value then
begin
FNumbersOnly := Value;
Invalidate;
end;
end;
procedure TDWCustomEdit.SetPasswordChar(Value: Char);
begin
if FPasswordChar <> Value then
begin
FPasswordChar := Value;
Invalidate;
end;
end;
procedure TDWCustomEdit.SetReadOnly(Value: Boolean);
begin
if FReadOnly <> Value then
begin
Invalidate;
end;
end;
procedure TDWCustomEdit.SetTextHint(const Value: string);
begin
if FTextHint <> Value then
begin
FTextHint := Value;
Invalidate;
end;
end;
end.