-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathDW.VCL.Labels.pas
436 lines (382 loc) · 12.1 KB
/
DW.VCL.Labels.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
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
unit DW.VCL.Labels;
interface
uses Classes, SysUtils, Db, DW.VCL.DBControl, DW.VCL.Control, DWElementTag;
type
TIWBSLabelStyle = (bslsNone, bslsDefault, bslsPrimary, bslsSuccess, bslsInfo, bslsWarning,
bslsDanger, bslsBadget);
const
aIWBSLabelStyle: array [bslsNone .. bslsBadget] of string = ('', 'default', 'primary', 'success',
'info', 'warning', 'danger', 'badge');
type
TDWLabel = class(TDWCustomDbControl)
private
FCaption: string;
FForControl: TDWInputControl;
FRawText: boolean;
FOldText: string;
FTagType: string;
FLabelStyle: TIWBSLabelStyle;
function RenderLabelText: string;
procedure SetTagType(const Value: string);
function IsTagTypeStored: boolean;
procedure SetLabelStyle(const Value: TIWBSLabelStyle);
procedure SetCaption(const Value: string);
procedure SetRawText(const Value: boolean);
protected
procedure CheckData; override;
procedure InternalRenderAsync(const AHTMLName: string); override;
procedure InternalRenderCss(var ACss: string); override;
procedure InternalRenderHTML(var AHTMLTag: TDWElementTag); override;
procedure SetForControl(const Value: TDWInputControl);
public
constructor Create(AOwner: TComponent); override;
published
property Caption: string read FCaption write SetCaption;
property ForControl: TDWInputControl read FForControl write SetForControl;
property BSLabelStyle: TIWBSLabelStyle read FLabelStyle write SetLabelStyle default bslsNone;
property RawText: boolean read FRawText write SetRawText default False;
property TagType: string read FTagType write SetTagType stored IsTagTypeStored;
end;
TDWText = class(TDWCustomDbControl)
private
FAutoFormGroup: boolean;
FLines: TStringList;
FRawText: boolean;
FOldText: string;
FTagType: string;
function RenderText: string;
procedure OnLinesChange(ASender: TObject);
procedure SetLines(const AValue: TStringList);
function IsTagTypeStored: boolean;
procedure SetTagType(const Value: string);
procedure SetRawText(const Value: boolean);
procedure SetAutoFormGroup(const Value: boolean);
protected
procedure CheckData; override;
procedure InternalRenderAsync(const AHTMLName: string); override;
procedure InternalRenderHTML(var AHTMLTag: TDWElementTag); override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property AutoFormGroup: boolean read FAutoFormGroup write SetAutoFormGroup default False;
property Lines: TStringList read FLines write SetLines;
property RawText: boolean read FRawText write SetRawText default False;
property TagType: string read FTagType write SetTagType stored IsTagTypeStored;
end;
TIWBSGlyphicon = class(TDWControl)
private
FGlyphicon: string;
protected
procedure InternalRenderCss(var ACss: string); override;
procedure InternalRenderHTML(var AHTMLTag: TDWElementTag); override;
public
constructor Create(AOwner: TComponent); override;
published
property BSGlyphicon: string read FGlyphicon write FGlyphicon;
end;
TIWBSFile = class(TDWControl)
private
FMultiple: boolean;
procedure SetMultiple(const Value: boolean);
protected
procedure InternalRenderHTML(var AHTMLTag: TDWElementTag); override;
public
constructor Create(AOwner: TComponent); override;
published
property Multiple: boolean read FMultiple write SetMultiple default False;
end;
implementation
uses
DW.VCL.Common, DW.VCL.List, DW.VCL.Region, DWTypes, DW.VCL.InputForm, DWUtils;
{$REGION 'TIWBSLabel'}
constructor TDWLabel.Create(AOwner: TComponent);
begin
inherited;
FRawText := False;
FTagType := 'span';
Height := 25;
Width := 200;
end;
procedure TDWLabel.SetCaption(const Value: string);
begin
FCaption := Value;
Invalidate;
end;
procedure TDWLabel.SetForControl(const Value: TDWInputControl);
begin
FForControl := Value;
AsyncRefreshControl;
end;
procedure TDWLabel.SetLabelStyle(const Value: TIWBSLabelStyle);
begin
FLabelStyle := Value;
Invalidate;
end;
procedure TDWLabel.SetRawText(const Value: boolean);
begin
FRawText := Value;
Invalidate;
end;
procedure TDWLabel.SetTagType(const Value: string);
begin
TDWBSCommon.ValidateTagName(Value);
FTagType := Value;
AsyncRefreshControl;
end;
function TDWLabel.RenderLabelText: string;
begin
if FRawText then
Result := Caption
else
Result := TDWBSCommon.TextToHTML(Caption);
end;
procedure TDWLabel.InternalRenderAsync(const AHTMLName: string);
begin
inherited;
TDWBSCommon.SetAsyncHtml(AHTMLName, RenderLabelText, FOldText);
end;
procedure TDWLabel.InternalRenderCss(var ACss: string);
begin
inherited;
if FLabelStyle <> bslsNone then
TDWBSCommon.AddCssClass(ACss, aIWBSLabelStyle[FLabelStyle]);
if Parent is TDWList then
begin
TDWBSCommon.AddCssClass(ACss, 'list-group-item');
if FLabelStyle in [bslsSuccess, bslsInfo, bslsWarning, bslsDanger] then
TDWBSCommon.AddCssClass(ACss, 'list-group-item-' + aIWBSLabelStyle[FLabelStyle])
end
else
begin
if FLabelStyle in [bslsDefault .. bslsDanger] then
TDWBSCommon.AddCssClass(ACss, 'label label-' + aIWBSLabelStyle[FLabelStyle])
else if FLabelStyle = bslsBadget then
TDWBSCommon.AddCssClass(ACss, aIWBSLabelStyle[FLabelStyle]);
if Parent is TDWRegion then
begin
if TDWRegion(Parent).BSRegionType = bsrtModalHeader then
TDWBSCommon.AddCssClass(ACss, 'modal-title')
else if TDWRegion(Parent).BSRegionType = bsrtPanelHeading then
TDWBSCommon.AddCssClass(ACss, 'panel-title');
end;
end;
end;
procedure TDWLabel.InternalRenderHTML(var AHTMLTag: TDWElementTag);
begin
inherited;
FOldText := RenderLabelText;
if Assigned(FForControl) then
begin
AHTMLTag := TDWElementTag.CreateHTMLTag('label');
AHTMLTag.AddStringParam('for', ForControl.HTMLName);
end
else if Parent is TDWList then
begin
AHTMLTag := TDWElementTag.CreateHTMLTag('li');
end
else
begin
AHTMLTag := TDWElementTag.CreateHTMLTag(FTagType);
end;
AHTMLTag.AddStringParam('id', HTMLName);
AHTMLTag.AddClassParam(ActiveCss);
AHTMLTag.AddStringParam('style', ActiveStyle);
AHTMLTag.Contents.AddText(FOldText);
if Parent is TDWInputGroup then
AHTMLTag := DWCreateInputGroupAddOn(AHTMLTag, HTMLName, 'addon');
end;
function TDWLabel.IsTagTypeStored: boolean;
begin
Result := FTagType <> 'span';
end;
procedure TDWLabel.CheckData;
var
LField: TField;
begin
if CheckDataSource(DataSource, DataField, LField) then
Caption := LField.DisplayText;
end;
{$ENDREGION}
{$REGION 'TIWBSText'}
constructor TDWText.Create(AOwner: TComponent);
begin
inherited;
FLines := TStringList.Create;
FLines.TrailingLineBreak := False;
FLines.OnChange := OnLinesChange;
FRawText := False;
FTagType := 'div';
Height := 100;
Width := 200;
end;
destructor TDWText.Destroy;
begin
FLines.Free;
inherited;
end;
procedure TDWText.OnLinesChange(ASender: TObject);
begin
Invalidate;
if Script.Count > 0 then
AsyncRefreshControl;
end;
procedure TDWText.SetAutoFormGroup(const Value: boolean);
begin
FAutoFormGroup := Value;
AsyncRefreshControl;
end;
procedure TDWText.SetLines(const AValue: TStringList);
begin
FLines.Assign(AValue);
end;
procedure TDWText.SetRawText(const Value: boolean);
begin
FRawText := Value;
Invalidate;
end;
procedure TDWText.SetTagType(const Value: string);
begin
TDWBSCommon.ValidateTagName(Value);
FTagType := Value;
AsyncRefreshControl;
end;
function TDWText.RenderText: string;
var
i: integer;
LLines: TStringList;
begin
if FRawText then
begin
LLines := TStringList.Create;
try
LLines.Assign(FLines);
// replace params before custom events
LLines.Text := TDWBSCommon.ReplaceParams(Self, LLines.Text);
(*
{ TODO 1 -oDELCIO -cIMPLEMENT : CustomAsyncEvents}
// replace inner events calls
if IsStoredCustomAsyncEvents then
for i := 0 to CustomAsyncEvents.Count-1 do
TIWBSCustomAsyncEvent(CustomAsyncEvents.Items[i]).ParseParam(LLines);
{ TODO 1 -oDELCIO -cIMPLEMENT : CustomRestEvents}
// replace inner events calls
if IsStoredCustomRestEvents then
for i := 0 to CustomRestEvents.Count-1 do
TIWBSCustomRestEvent(CustomRestEvents.Items[i]).ParseParam(LLines);
*)
Result := LLines.Text;
finally
LLines.Free;
end;
end
else
Result := TDWBSCommon.TextToHTML(Lines.Text);
end;
procedure TDWText.InternalRenderAsync(const AHTMLName: string);
begin
inherited;
TDWBSCommon.SetAsyncHtml(AHTMLName, RenderText, FOldText);
end;
procedure TDWText.InternalRenderHTML(var AHTMLTag: TDWElementTag);
begin
inherited;
FOldText := RenderText;
AHTMLTag := TDWElementTag.CreateHTMLTag(FTagType);
AHTMLTag.AddStringParam('id', HTMLName);
AHTMLTag.AddClassParam(ActiveCss);
AHTMLTag.AddStringParam('style', ActiveStyle);
AHTMLTag.Contents.AddText(FOldText);
if FAutoFormGroup and not(Parent is TDWInputGroup) then
AHTMLTag := DWCreateInputFormGroup(Self, Parent, AHTMLTag, Caption, HTMLName);
end;
function TDWText.IsTagTypeStored: boolean;
begin
Result := FTagType <> 'div';
end;
procedure TDWText.CheckData;
var
LField: TField;
begin
if CheckDataSource(DataSource, DataField, LField) then
Lines.Text := LField.DisplayText;
end;
{$ENDREGION}
{$REGION 'TIWBSGlyphicon'}
constructor TIWBSGlyphicon.Create(AOwner: TComponent);
begin
inherited;
Height := 25;
Width := 25;
end;
procedure TIWBSGlyphicon.InternalRenderCss(var ACss: string);
begin
inherited;
if FGlyphicon <> '' then
TDWBSCommon.AddCssClass(ACss, 'glyphicon glyphicon-' + FGlyphicon);
end;
procedure TIWBSGlyphicon.InternalRenderHTML(var AHTMLTag: TDWElementTag);
begin
inherited;
AHTMLTag := TDWElementTag.CreateHTMLTag('span');
try
AHTMLTag.AddStringParam('id', HTMLName);
AHTMLTag.AddClassParam(ActiveCss);
AHTMLTag.AddStringParam('style', ActiveStyle);
if FGlyphicon <> '' then
AHTMLTag.AddBooleanParam('aria-hidden', true)
else
AHTMLTag.Contents.AddText('×');
except
FreeAndNil(AHTMLTag);
raise;
end;
if Parent is TDWInputGroup then
AHTMLTag := DWCreateInputGroupAddOn(AHTMLTag, HTMLName, 'addon');
end;
{$ENDREGION}
{$REGION 'TIWBSFile' }
constructor TIWBSFile.Create(AOwner: TComponent);
begin
inherited;
FMultiple := False;
Height := 25;
Width := 121;
end;
procedure TIWBSFile.InternalRenderHTML(var AHTMLTag: TDWElementTag);
begin
inherited;
AHTMLTag := TDWElementTag.CreateHTMLTag('input');
try
AHTMLTag.AddClassParam(ActiveCss);
AHTMLTag.AddStringParam('id', HTMLName);
AHTMLTag.AddStringParam('name', HTMLName + iif(FMultiple, '[]', ''));
AHTMLTag.AddStringParam('type', 'file');
if ShowHint and (Hint <> '') then
AHTMLTag.AddStringParam('title', Hint);
if FMultiple then
AHTMLTag.Add('multiple');
// if AutoFocus then
// AHTMLTag.Add('autofocus');
// if IsReadOnly then
// AHTMLTag.Add('readonly');
if IsDisabled then
AHTMLTag.Add('disabled');
// AHTMLTag.AddStringParam('value', TextToHTML(FText));
// if Required then
// AHTMLTag.Add('required');
// if PlaceHolder <> '' then
// AHTMLTag.AddStringParam('placeholder', TextToHTML(PlaceHolder));
AHTMLTag.AddStringParam('style', ActiveStyle);
except
FreeAndNil(AHTMLTag);
raise;
end;
AHTMLTag := DWCreateFormGroup(Parent, DWFindParentInputForm(Parent), AHTMLTag, HTMLName, true);
end;
procedure TIWBSFile.SetMultiple(const Value: boolean);
begin
FMultiple := Value;
AsyncRefreshControl;
end;
end.