-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathDW.VCL.CustomRegion.pas
468 lines (406 loc) · 14.8 KB
/
DW.VCL.CustomRegion.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
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
unit DW.VCL.CustomRegion;
interface
uses Classes, Controls, System.SysUtils, System.Types, VCL.Graphics, System.StrUtils,
DW.VCL.Container, DW.VCL.Common, DWTypes, DWElementTag,
DW.VCL.ScriptParams;
type
// base for all Regions
// exclude DWForms, DWFrames
TDWCustomRegion = class(TDWContainer)
private
// FCustomAsyncEvents: TIWBSCustomAsyncEvents; -> future implementation
// FCustomRestEvents: TIWBSCustomRestEvents; -> future implementation
FGridOptions: TDWGridOptions;
// FScript: TStringList; -> in parent
// FScriptInsideTag: boolean; -> in Parent
// FScriptParams: TDWScriptParams; -> in parent
// FStyle: TStringList; -> in Parent
FText: string;
FCollapseVisible: boolean;
FCollapse: boolean;
FRawText: boolean;
FOnAfterRender: TNotifyEvent;
FOnAfterAsyncChange: TNotifyEvent;
// function IsScriptEventsStored: Boolean; virtual; -> in parent class
function RegionDiv: TDWElementTag;
function RenderText: string;
// procedure OnScriptChange(ASender : TObject); -> in Parent Class
// procedure OnStyleChange(ASender : TObject); -> in parent class
// function GetCustomAsyncEvents: TIWBSCustomAsyncEvents; -> future implementation
// procedure SetCustomAsyncEvents(const Value: TIWBSCustomAsyncEvents); -> future implementation
// function GetCustomRestEvents: TIWBSCustomRestEvents; -> future implementation
// procedure SetCustomRestEvents(const Value: TIWBSCustomRestEvents); -> future implementation
procedure SetGridOptions(const AValue: TDWGridOptions);
// function GetScript: TStringList; -> in parent class
// procedure SetScript(const AValue: TStringList); -> in parent class
// function GetScriptParams: TDWScriptParams;
// procedure SetScriptParams(const AValue: TDWScriptParams);
// function GetStyle: TStringList; -> in parent class
// procedure SetStyle(const AValue: TStringList); -> in parent class
// function GetScriptInsideTag: boolean; -> in parent class
// procedure SetScriptInsideTag(const Value: boolean); -> in parent class
// function get_ScriptEvents: TIWScriptEvents; -> in parent class
function GetAfterRender: TNotifyEvent;
// procedure set_ScriptEvents(const Value: TIWScriptEvents); -> in parent class
procedure SetAfterRender(const Value: TNotifyEvent);
procedure SetCollapse(const Value: boolean);
procedure SetCollapseVisible(const Value: boolean);
procedure SetRawText(const Value: boolean);
procedure SetText(const Value: string);
// procedure SetCss(const Value: string); //-> in parent class
protected
FOldCss: string;
FOldStyle: string;
FOldVisible: boolean;
FRegionDiv: TDWElementTag;
FTagName: string;
{$HINTS off}
// function get_Visible: Boolean; override; --> Not necessary
// procedure set_Visible(Value: Boolean); override; --> Not necessary
// procedure SetParent(AParent: TWinControl); override; --> Not necessary
{$HINTS on}
// paint the control in ide design mode
procedure Paint; override;
// function ContainerPrefix: string; override;
procedure InternalRenderCss(var ACss: string); override;
procedure InternalRenderScript(const AHTMLName: string; AScript: TStringList); override;
procedure InternalRenderStyle(AStyle: TStringList); override;
function RenderAsync: TDWElementXHTMLTag; override;
procedure RenderComponents(aTagParent: TDWElementTag); override;
function RenderCSSClass: string; override;
function RenderHTML: TDWElementTag; override;
// procedure RenderScripts; override;
function RenderStyle: string; override;
function SupportsInput: boolean;
// procedure InternalBeforeRenderControls(var aRenderStream: ); virtual;
// procedure InternalAfterRenderControls(var aRenderStream: ); virtual;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
// Render AsyncEvents(ClallBacks)
function RenderAsyncEvents: string; Override;
// Let you destroy the region inside a self event handler
// procedure Release; -> verify if need to add in parent class
// procedure AsyncRefreshControl; -> in parent class
// procedure ResetAsyncRefreshControl; -> in parent class
// procedure AsyncRemoveControl;
// procedure ApplyAsyncChanges;
// return the Role Attribute
function GetRoleString: string; virtual;
function GetCssString: string;
// function IsStoredCustomAsyncEvents: Boolean; -> future implementation
// function IsStoredCustomRestEvents: Boolean; -> future implementation
function JQSelector: string;
procedure SetFocus; override;
property TagType: string read FTagName;
published
property Align;
property BSGridOptions: TDWGridOptions read FGridOptions write SetGridOptions;
// property ClipRegion default False;
// property CustomAsyncEvents: TIWBSCustomAsyncEvents read GetCustomAsyncEvents write SetCustomAsyncEvents stored IsStoredCustomAsyncEvents; -> future implementation
// property CustomRestEvents: TIWBSCustomRestEvents read GetCustomRestEvents write SetCustomRestEvents stored IsStoredCustomRestEvents; -> future implementation
// property Css: string read FCss write SetCss; //-> in parent class
property Collapse: boolean read FCollapse write SetCollapse default False;
property CollapseVisible: boolean read FCollapseVisible write SetCollapseVisible default False;
{ TODO 1 -oDELCIO -cIMPLEMENT : ExtraTagParams }
// property ExtraTagParams;
// property LayoutMgr;
property RawText: boolean read FRawText write SetRawText default False;
// property RenderInvisibleControls default True; -> in parent class
// property ScriptEvents: TIWScriptEvents read get_ScriptEvents write set_ScriptEvents stored IsScriptEventsStored; -> in parent class
// property Script: TStringList read GetScript write SetScript; -> in parent class
// property ScriptInsideTag: boolean read GetScriptInsideTag write SetScriptInsideTag default True; -> in parent class
// property ScriptParams: TIWBSScriptParams read GetScriptParams write SetScriptParams; -> in parent class
// property Style: TStringList read GetStyle write SetStyle; -> in parent class
property Text: string read FText write SetText;
// property ZIndex default 0; -> in parent class
// Occurs after component is rendered.
property OnAfterRender: TNotifyEvent read GetAfterRender write SetAfterRender;
// Occurs after component is changed on an Asyn call, it doesn't occurs if the control is fully rendered
property OnAfterAsyncChange: TNotifyEvent read FOnAfterAsyncChange write FOnAfterAsyncChange;
property OnHTMLTag;
end;
implementation
uses
DWUtils, DW.VCL.Region, DW.VCL.InputForm;
constructor TDWCustomRegion.Create(AOwner: TComponent);
begin
inherited;
FAsyncRefreshControl := False;
// FCustomAsyncEvents := nil;
// FCustomRestEvents := nil;
FGridOptions := TDWGridOptions.Create(Self);
FTagName := 'div';
// ClipRegion := False;
end;
destructor TDWCustomRegion.Destroy;
begin
// FreeAndNil(FCustomAsyncEvents);
// FreeAndNil(FCustomRestEvents);
FreeAndNil(FGridOptions);
// FreeAndNil(FScript);
// FreeAndNil(FScriptParams);
// FreeAndNil(FStyle);
inherited;
end;
procedure TDWCustomRegion.SetRawText(const Value: boolean);
begin
FRawText := Value;
AsyncRefreshControl;
end;
function TDWCustomRegion.JQSelector: string;
begin
Result := '$("#' + HTMLName + '")';
end;
procedure TDWCustomRegion.Paint;
var
LRect: TRect;
s: string;
w: integer;
LLines: string;
LScript: string;
begin
LRect := Rect(0, 0, Self.Width, Self.Height);
Canvas.Brush.Color := clWhite;
Canvas.Pen.Color := clGray;
Canvas.Rectangle(LRect);
with TDWCustomRegion(Self) do
begin
Canvas.Font.Name := CNST_PROPORTIONALFONT;
Canvas.Font.Size := 10;
Canvas.Font.Color := clGray;
Canvas.Font.Style := [];
// draw css classes
s := GetCssString;
if Self is TDWFormControl then
begin
if s <> '' then
s := ' ' + s;
s := 'form-Self' + s;
end;
s := '[' + s + ']';
if not RawText then
s := '<' + TagType + '> ' + s;
s := Name + ' ' + s;
w := Canvas.TextWidth(s);
LRect := Rect(Self.ClientWidth - w - 10, 2, Self.Width, Self.Height);
Canvas.TextRect(LRect, s, []);
// draw embeded text and script
LLines := Text;
if RawText then
begin
Canvas.Font.Name := CNST_PROPORTIONALFONT;
if Script.Count > 0 then
LScript := #13#10'<script>'#13#10 + Script.Text + '</script>'
else
LScript := '';
LLines := '<' + TagType + '>' + IfThen(LLines <> '', #13#10 + LLines);
if ScriptInsideTag then
LLines := LLines + LScript;
LLines := LLines + #13#10'</' + TagType + '>';
if not ScriptInsideTag then
LLines := LLines + LScript;
end
else
begin
Canvas.Font.Name := CNST_DEFAULTFONTNAME;
if Self is TDWRegion then
case TDWRegion(Self).TagType of
bsttDiv, bsttP:
Canvas.Font.Height := -12;
bsttH1:
Canvas.Font.Height := -36;
bsttH2:
Canvas.Font.Height := -30;
bsttH3:
Canvas.Font.Height := -24;
bsttH4:
Canvas.Font.Height := -18;
bsttH5:
Canvas.Font.Height := -14;
bsttH6:
Canvas.Font.Height := -12;
end;
end;
if LLines <> '' then
begin
LRect := Rect(10, 18, Self.Width - 10, Self.Height - 3);
Canvas.Font.Color := clBlack;
Canvas.TextRect(LRect, LLines, []);
end;
end;
end;
procedure TDWCustomRegion.SetFocus;
begin
// IWBSExecuteAsyncJScript(JQSelector+'.focus()');
DWApplication.CallBackResp.AddScriptToExecute(JQSelector + '.focus()');
end;
function TDWCustomRegion.GetRoleString: string;
begin
Result := '';
end;
procedure TDWCustomRegion.SetGridOptions(const AValue: TDWGridOptions);
begin
FGridOptions.Assign(AValue);
Invalidate;
end;
function TDWCustomRegion.GetAfterRender: TNotifyEvent;
begin
Result := FOnAfterRender;
end;
function TDWCustomRegion.GetCssString: string;
begin
Result := RenderCSSClass;
end;
procedure TDWCustomRegion.SetAfterRender(const Value: TNotifyEvent);
begin
FOnAfterRender := Value;
end;
procedure TDWCustomRegion.SetCollapse(const Value: boolean);
begin
FCollapse := Value;
Invalidate;
end;
procedure TDWCustomRegion.SetCollapseVisible(const Value: boolean);
begin
FCollapseVisible := Value;
Invalidate;
end;
procedure TDWCustomRegion.SetText(const Value: string);
begin
FText := TrimRight(Value);
AsyncRefreshControl;
end;
function TDWCustomRegion.RegionDiv: TDWElementTag;
begin
Result := FRegionDiv;
end;
function TDWCustomRegion.SupportsInput: boolean;
begin
Result := False;
end;
(* procedure TIWBSCustomRegion.InternalAfterRenderControls(
begin
// Occurs before render Child Controls
end; *)
(* procedure TIWBSCustomRegion.InternalBeforeRenderControls(
begin
// Occurs after render Child Controls
end; *)
procedure TDWCustomRegion.InternalRenderCss(var ACss: string);
begin
if FCollapse then
begin
TDWBSCommon.AddCssClass(ACss, 'collapse');
if FCollapseVisible then
TDWBSCommon.AddCssClass(ACss, 'in');
end;
end;
procedure TDWCustomRegion.InternalRenderScript(const AHTMLName: string; AScript: TStringList);
begin
//
end;
procedure TDWCustomRegion.InternalRenderStyle(AStyle: TStringList);
begin
//
end;
function TDWCustomRegion.RenderAsync: TDWElementXHTMLTag;
var
xHTMLName: string;
begin
Result := nil;
xHTMLName := HTMLName;
if FAsyncRefreshControl or not FRendered then
begin
TDWRegionCommon.CancelChildAsyncRender(Self);
TDWBSCommon.RenderAsync(xHTMLName, Self);
end
else
begin
TDWBSCommon.SetAsyncClass(xHTMLName, RenderCSSClass, FOldCss);
TDWBSCommon.SetAsyncStyle(xHTMLName, RenderStyle, FOldStyle);
TDWBSCommon.SetAsyncVisible(FMainID, Visible, FOldVisible);
if Assigned(FOnAfterAsyncChange) then
FOnAfterAsyncChange(Self);
{ TODO 1 -oDELCIO -cIMPLEMENT : Global event OnAfterAsyncChange }
{ if Assigned(gIWBSOnAfterAsyncChange) then
gIWBSOnAfterAsyncChange(Self, xHTMLName); }
end;
end;
function TDWCustomRegion.RenderAsyncEvents: string;
begin
//
end;
procedure TDWCustomRegion.RenderComponents(aTagParent: TDWElementTag);
begin
TDWRegionCommon.RenderComponents(Self, aTagParent);
end;
function TDWCustomRegion.RenderCSSClass: string;
begin
Result := FGridOptions.GetClassString;
if Css <> '' then
begin
if Result <> '' then
Result := Result + ' ';
Result := Result + Css;
end;
InternalRenderCss(Result);
end;
function TDWCustomRegion.RenderHTML: TDWElementTag;
begin
inherited RenderHTML; // <--- to fire OnRender Event
FOldCss := RenderCSSClass;
FOldStyle := RenderStyle;
FOldVisible := Visible;
FRegionDiv := TDWElementTag.CreateHTMLTag(FTagName);
FRegionDiv.AddStringParam('id', HTMLName);
FRegionDiv.AddClassParam(FOldCss);
FRegionDiv.AddStringParam('role', GetRoleString);
FRegionDiv.AddStringParam('style', RenderStyle);
if FText <> '' then
FRegionDiv.Contents.AddText(RenderText);
// render child components
RenderComponents(FRegionDiv);
TDWBSCommon.RenderScript(Self, FRegionDiv);
FMainID := FRegionDiv.Params.Values['id'];
{ TODO 1 -oDELCIO -cIMPLEMENT : Global Render custom attribute with name of component }
(* if gIWBSAttributeCmpName <> '' then
FRegionDiv.Params.Values[gIWBSAttributeCmpName] := name; *)
Result := FRegionDiv;
FAsyncRefreshControl := False;
FRendered := True;
end;
function TDWCustomRegion.RenderStyle: string;
begin
Result := TDWBSCommon.RenderStyle(Self);
end;
function TDWCustomRegion.RenderText: string;
var
LLines: TStringList;
begin
if RawText then
begin
LLines := TStringList.Create;
try
LLines.Text := FText;
// replace params before custom events
LLines.Text := TDWBSCommon.ReplaceParams(Self, LLines.Text);
{ TODO 1 -oDELCIO -cIMPLEMENT : Custom Async Events }
(* // 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 : Custom Rest Events }
// 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(FText);
end;
end.