-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathDW.VCL.Control.pas
1171 lines (1036 loc) · 39.7 KB
/
DW.VCL.Control.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
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{ *******************************************************************************
DW.VCL(Delphi Web Visual Component Library) is Based on
IWBootsTrap Framework : http://kattunga.github.io/IWBootstrapFramework/
Delphi Web is
Developped by Delcio Sbeghen @ SRP Sistemas
delcio @ eavnet.com.br (remove spaces)
under MIT Licence
}
{ TODO 1 -oDELCIO -cIMPLEMENT : show only TDW components in ToolPalette }
{
Create an separate classgroup, to show only TDW components in ToolPalette
see:
StartClassGroup
GroupDescendantsWith
ActivateClassGroup
Sample:
ActivateClassGroup (TControl) for VCL
ActivateClassGroup (QControls.TControl) for CLX
Source
http://www.devsuperpage.com/search/Articles.asp?ArtID=206781
http://www.devsuperpage.com/search/Articles.aspx?G=2&ArtID=90282
If possible, iherits all TDW from TDWComponent(TComponent descendant)
}
unit DW.VCL.Control;
interface
uses Classes, Dialogs, System.SysUtils, System.Types, VCL.Graphics, VCL.Controls,
Winapi.Windows, DWElementTag, DW.VCL.CustomForm, DWTypes,
DW.VCL.ScriptEvents, DW.VCL.StyleRenderOptions, DW.VCL.Container,
DW.VCL.ScriptParams, DW.VCL.Common, DW.VCL.Interfaces;
type
// TDWControl is the Base for DW Controls
TDWControl = class(TGraphicControl, IDWControl)
private
// Html id of main Tag
// not same as HtmlName because same controls add one main div,
// example Bootstrap FormGroup
FMainID: string;
// Defines whether the control will be fully updated in the next Async Call
FAsyncRefreshControl: boolean;
// define if control already Rendered
FRendered: boolean;
// Additional User defined Style to be render
FStyle: TStringList;
// Corresponds to html tabindex attribute. It will be rendered if tabindex <> 0.
// Set to -1 to disable tabstop
FTabIndex: Integer;
// define if scripts is rendered inside the control tag or new Main tag
// is created and put script on this
FScriptInsideTag: boolean;
// Events
FOnAsyncClick: TDWAsyncProcedure;
FOnAsyncMouseDown: TDWAsyncProcedure;
FOnAsyncDoubleClick: TDWAsyncProcedure;
FOnAsyncMouseMove: TDWAsyncProcedure;
FOnAsyncMouseUp: TDWAsyncProcedure;
FStyleRenderOptions: TDWRenderOptions;
FOnAsyncMouseOut: TDWAsyncProcedure;
FOnAsyncMouseOver: TDWAsyncProcedure;
// The z-index property specifies the stack order of an element in a display browser
// An element with greater stack order is always in front of an element with a lower stack order.
FZIndex: Integer;
// JavaScripts to be executted on browser when especified event occurs
FScriptEvents: TDWScriptEvents;
// property "class" of HTML Element, used for CSS styles
FCss: string;
FScript: TStringList;
FScriptParams: TDWScriptParams;
FOnAfterRender: TNotifyEvent;
FOnRender: TNotifyEvent;
FOnHTMLtag: TDWOnHtmlTagProcedure;
FOnAfterAsyncChange: TNotifyEvent;
FEditable: boolean;
procedure SetScript(const Value: TStringList);
procedure OnScriptChange(ASender: TObject);
procedure SetScriptInsideTag(const Value: boolean);
procedure SetScriptParams(const Value: TDWScriptParams);
procedure OnStyleChange(ASender: TObject);
procedure SetOnAfterRender(const Value: TNotifyEvent);
procedure SetOnRender(const Value: TNotifyEvent);
procedure SetOnHTMLtag(const Value: TDWOnHtmlTagProcedure);
function IsScriptEventsStored: boolean;
procedure SetEditable(const Value: boolean);
function GetScriptInsideTag: boolean;
function GetScriptParams: TDWScriptParams;
procedure DoAsyncMouseDown(aParams: TStringList);
procedure DoAsyncMouseMove(aParams: TStringList);
procedure DoAsyncMouseUp(aParams: TStringList);
procedure DoAsyncDblClick(aParams: TStringList);
procedure DoAsyncMouseOut(aParams: TStringList);
procedure DoAsyncMouseOver(aParams: TStringList);
function GetScript: TStringList;
protected
// Oldxxxx is used to compare values in Async Call,
// to verify updateds property in controls
FOldCss: string;
FOldDisabled: boolean;
FOldReadOnly: boolean;
FOldStyle: string;
FOldVisible: boolean;
// determine if control to be released, if true then control no to be rendered
FReleased: boolean;
// paint the control in ide design mode
procedure Paint; override;
// Render Size Style and add to "style" tag property (See StyleRenderOptions)
function RenderSizeStyle: string; virtual;
// Render Position Style and add to "style" tag property(See StyleRenderOptions)
function RenderPositionStyle: string; virtual;
// Render Text alignament Style and add to "style" tag property
function RenderTextAlignStyle: String; virtual;
// Render Vertical alignament Style and add to "style" tag property
function RenderVerticalAlignStyle: string; virtual;
// Render Backgruound Color Style and add to "style" tag property
function RenderBGColor: string; virtual;
// Render HTML "style" tag property
function RenderStyle: string; virtual;
// Setters for Properties, to description see respective property
procedure SetCss(const Value: string); virtual;
procedure SetOnAsyncClick(const Value: TDWAsyncProcedure); virtual;
procedure SetOnAsyncDoubleClick(const Value: TDWAsyncProcedure); virtual;
procedure SetOnAsyncMouseDown(const Value: TDWAsyncProcedure); virtual;
procedure SetOnAsyncMouseMove(const Value: TDWAsyncProcedure); virtual;
procedure SetOnAsyncMouseOut(const Value: TDWAsyncProcedure); virtual;
procedure SetOnAsyncMouseOver(const Value: TDWAsyncProcedure); virtual;
procedure SetOnAsyncMouseUp(const Value: TDWAsyncProcedure); virtual;
procedure SetScriptEvents(const Value: TDWScriptEvents); virtual;
procedure SetStyle(const Value: TStringList); virtual;
procedure SetStyleRenderOptions(const Value: TDWRenderOptions); virtual;
procedure SetZIndex(const Value: Integer); virtual;
// Execute event OnAsyncClick
procedure DoAsyncClick(aParams: TStringList); virtual;
// return true if control is disabled
function IsDisabled: boolean; virtual;
// return true if Component is ReadOnly
function IsReadOnly: boolean; virtual;
function InputSelector: string; virtual;
// return the Suffix for items of an input EX:
// For RadioGroup the InputSelector is '_INPUT'.
// RadioGroup HtmlName = Radio
// Then to select the RadioGroup, use '$("#' + HtmlName + '")'
// and to select item, use '$("#' + HtmlName + InputSelector + '")'
function InputSuffix: string; virtual;
// used to render HTML in descendant class
procedure InternalRenderHTML(var AHTMLTag: TDWElementTag); virtual;
// used to render XHR on Async Calls in descendant class
procedure InternalRenderAsync(const aHTMLName: string); virtual;
procedure InternalRenderScript(const aHTMLName: string; AScript: TStringList); virtual;
property ActiveCss: string read FOldCss;
property ActiveStyle: string read FOldStyle;
// return true if control is in DWAppplication release list
// and waiting to be released in next DWApplication Loop
function IsReleased: boolean;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
// Free the Control on next thread loop
procedure Release;
function IsDesignMode: boolean;
function IsLoading: boolean;
// used to render "class" attribute on Async Calls in descendant class
procedure InternalRenderCss(var ACss: string); virtual;
// Render HTML "class" tag property
function RenderCSSClass: string; virtual;
// Get Form where Component it is
function Form: TControl;
// Render control on full form load or on FRendered = false
// Return one TDWElementTag with element HTML
function RenderHTML: TDWElementTag; virtual;
// Render control on form Async Calls
// Return one TDWElementXHTMLTag with element XHTML
function RenderAsync: TDWElementXHTMLTag; virtual;
// Render AsyncEvents(ClallBacks)
function RenderAsyncEvents: string; virtual;
// Render Cursor Style and add to "style" tag property
function RenderCursorStyle: string; virtual;
// Render Control Inline Style
procedure InternalRenderStyle(AStyle: TStringList); virtual;
// Invalidate control force control to refresh on Design Mode
// and to be Refreshed(RenderAsync) on form AsyncCalls
procedure Invalidate; override;
// Repaint control in Only in Design Mode
procedure RepaintControl; virtual;
// Force a full refresh of the control during an Async call.
// Usually there is no need to use this method, only if some property changed during async calls is not reflected.
procedure AsyncRefreshControl;
// Cancel AsyncRefreshControl
// Usually there is no need to use this method. It is for internal use.
procedure ResetAsyncRefreshControl;
// Remove a control from html flow. You should execute this when destroying a control durinc async calls before Freeing @br
// If you are destroying a region is enought to execute this in that region, you don't need to execute it in each child control.
procedure AsyncRemoveControl;
// returns a string representing the the JQSelector for this object.
// @preformatted(DWControl.JQSelector > '$(#"htmlname")')
function JQSelector: string;
// get the list of AsyncEvents actives in this control
function AsyncEvents: TDWAsyncEventTypeSet; virtual;
// Return name of element in HTML.
// If RootParent is an TDWCustomForm, HTMLName is same as Name,
// else if RootParent is an TDWFrame, HTMLName is FrameName_ComponentName
// this is necessary because one frame can be placed into one Form,
// and this can cause duplicate names in same HTML Page
function HTMLName: string;
// Return the root container of a component.
// if component is in one TDWCustomForm, this return a Form,
// else if component is in one TDWCustomFrame, this return a Frame
// for compatibility the object returned is an TDWContainer,
// but this never return containers, like a Panels, etc
// the returned element to be casted usin some like this:
// @preformatted(
// if ReturnedObject.InheritsFrom(TDWCustomForm) then //its one Form
// TDWCustomForm(ReturnedObject)."your code here"
// else if ReturnedObject.InheritsFrom(TDWCustomFrame) then //its one Frame
// TDWCustomFrame(ReturnedObject)."your code here")
function RootParent: TDWContainer;
// Return the first Parent Container
function ParentContainer: TDWContainer;
// Set focus on component in an Ajax Callback
procedure SetFocus;
published
property Align;
// Specifies whether the control responds to mouse, keyboard, and timer events.
property Enabled;
// set if the control will be editable or read-only
property Editable: boolean read FEditable write SetEditable default True;
// JavaScripts to be executted on browser when especified event occurs
property ScriptEvents: TDWScriptEvents read FScriptEvents write SetScriptEvents
stored IsScriptEventsStored;
// Set the font of Control (See StyleRenderOptions)
property Font;
// Color of Component
property Color;
// property "class" of HTML Element, used for CSS styles
property Css: string read FCss write SetCss;
// Defines which style properties will be rendered
property StyleRenderOptions: TDWRenderOptions read FStyleRenderOptions
write SetStyleRenderOptions;
// Specifies if the script will be rendered inside the control tag or not. @br
// If true the script will be rendered inside the tag. @br
// If false a new div will be created to surround the control and the script will be rendered in this div, outside the control tag. @br
// this is necessary script can't be placed inside the tag, for example in input controls.
property ScriptInsideTag: boolean read GetScriptInsideTag write SetScriptInsideTag default True;
// Params that will be replaced in scripts and in some controls content, for example in TDWText. @br
// Params are specified in scripts as: {%param%}.
property ScriptParams: TDWScriptParams read GetScriptParams write SetScriptParams;
// List of inline styles in pairs name: value
property Style: TStringList read FStyle write SetStyle;
// The z-index property specifies the stack order of an element.
// An element with greater stack order is always in front of an element with a lower stack order.
// Note: z-index only works on positioned elements (position:absolute, position:relative, or position:fixed).
// see: http://www.w3schools.com/csSref/pr_pos_z-index.asp
property ZIndex: Integer read FZIndex write SetZIndex;
// Corresponds to html tabindex attribute. It will be rendered if tabindex <> 0. Set to -1 to disable tabstop
property TabIndex: Integer read FTabIndex write FTabIndex default 0;
// Specifies user javascript code that will be rendered and executed with this object. @br
// You can define ScriptParams inside the script. ScriptParams are specified in scripts as: {%param%}. @br
// With property ScriptInsideTag you can define if the script will be rendered inside or outside the script.
property Script: TStringList read GetScript write SetScript;
// Events
property OnAsyncClick: TDWAsyncProcedure read FOnAsyncClick write SetOnAsyncClick;
property OnAsyncDoubleClick: TDWAsyncProcedure read FOnAsyncDoubleClick
write SetOnAsyncDoubleClick;
property OnAsyncMouseMove: TDWAsyncProcedure read FOnAsyncMouseMove write SetOnAsyncMouseMove;
property OnAsyncMouseOver: TDWAsyncProcedure read FOnAsyncMouseOver write SetOnAsyncMouseOver;
property OnAsyncMouseOut: TDWAsyncProcedure read FOnAsyncMouseOut write SetOnAsyncMouseOut;
property OnAsyncMouseDown: TDWAsyncProcedure read FOnAsyncMouseDown write SetOnAsyncMouseDown;
property OnAsyncMouseUp: TDWAsyncProcedure read FOnAsyncMouseUp write SetOnAsyncMouseUp;
// Occurs after component is rendered.
property OnAfterRender: TNotifyEvent read FOnAfterRender write SetOnAfterRender;
// Occurs before component is rendered.
property OnRender: TNotifyEvent read FOnRender write SetOnRender;
// Occurs after HTMLTag is created
property OnHTMLtag: TDWOnHtmlTagProcedure read FOnHTMLtag write SetOnHTMLtag;
// 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;
end;
// TDWInputControl is the base for all Controls that accept input
TDWInputControl = class(TDWControl, IDWInput)
private
// Events
FOnAsyncSelect: TDWAsyncProcedure;
FOnAsyncExit: TDWAsyncProcedure;
FOnAsyncKeyPress: TDWAsyncProcedure;
FOnAsyncKeyDown: TDWAsyncProcedure;
FOnAsyncChange: TDWAsyncProcedure;
FOnAsyncEnter: TDWAsyncProcedure;
FOnAsyncKeyUp: TDWAsyncProcedure;
procedure SetTabStop(Value: boolean);
function GetTabStop: boolean;
procedure SetOnAsyncChange(Value: TDWAsyncProcedure);
procedure SetOnAsyncEnter(Value: TDWAsyncProcedure);
procedure SetOnAsyncExit(Value: TDWAsyncProcedure);
procedure SetOnAsyncKeyDown(Value: TDWAsyncProcedure);
procedure SetOnAsyncKeyPress(Value: TDWAsyncProcedure);
procedure SetOnAsyncKeyUp(Value: TDWAsyncProcedure);
procedure SetOnAsyncSelect(Value: TDWAsyncProcedure);
protected
FOldText: string;
// Used to change value on receive async calls
procedure SetValue(const AValue: string); virtual;
procedure DoAsyncCHange(aParams: TStringList); virtual;
procedure DoAsyncSelect(aParams: TStringList); virtual;
procedure DoAsyncExit(aParams: TStringList); virtual;
procedure DoAsyncKeyPress(aParams: TStringList); virtual;
procedure DoAsyncKeyDown(aParams: TStringList); virtual;
procedure DoAsyncEnter(aParams: TStringList); virtual;
procedure DoAsyncKeyUp(aParams: TStringList); virtual;
public
constructor Create(AOwner: TComponent); override;
// get the list of AsyncEvents actives in this control
function AsyncEvents: TDWAsyncEventTypeSet; override;
// Render control on form Async Calls
// Return one TDWElementXHTMLTag with element XHTML
function RenderAsync: TDWElementXHTMLTag; Override;
// Render AsyncEvents(ClallBacks)
function RenderAsyncEvents: string; override;
published
property TabStop: boolean read GetTabStop write SetTabStop default True;
property Text;
property OnAsyncChange: TDWAsyncProcedure read FOnAsyncChange write SetOnAsyncChange;
property OnAsyncEnter: TDWAsyncProcedure read FOnAsyncEnter write SetOnAsyncEnter;
property OnAsyncExit: TDWAsyncProcedure read FOnAsyncExit write SetOnAsyncExit;
property OnAsyncKeyDown: TDWAsyncProcedure read FOnAsyncKeyDown write SetOnAsyncKeyDown;
property OnAsyncKeyUp: TDWAsyncProcedure read FOnAsyncKeyUp write SetOnAsyncKeyUp;
property OnAsyncKeyPress: TDWAsyncProcedure read FOnAsyncKeyPress write SetOnAsyncKeyPress;
property OnAsyncSelect: TDWAsyncProcedure read FOnAsyncSelect write SetOnAsyncSelect;
end;
implementation
uses DWUtils, DW.VCL.CustomInput, DW.VCL.Input;
type
ThackDwControl = class(TDWControl);
{ TDWControl }
function TDWControl.AsyncEvents: TDWAsyncEventTypeSet;
begin
Result := [];
if Assigned(FOnAsyncClick) then
Result := [ae_click];
if Assigned(FOnAsyncMouseDown) then
Include(Result, ae_mousedown);
if Assigned(FOnAsyncDoubleClick) then
Include(Result, ae_dblclick);
if Assigned(FOnAsyncMouseMove) then
Include(Result, ae_mousemove);
if Assigned(FOnAsyncMouseUp) then
Include(Result, ae_mouseup);
if Assigned(FOnAsyncMouseOut) then
Include(Result, ae_mouseout);
if Assigned(FOnAsyncMouseOver) then
Include(Result, ae_mouseover);
end;
procedure TDWControl.AsyncRefreshControl;
begin
FAsyncRefreshControl := True;
Invalidate;
end;
procedure TDWControl.AsyncRemoveControl;
begin
end;
procedure TDWControl.ResetAsyncRefreshControl;
begin
FAsyncRefreshControl := False;
end;
constructor TDWControl.Create(AOwner: TComponent);
begin
inherited;
FReleased := False;
FEditable := True;
Font.Size := 12;
FRendered := False;
FAsyncRefreshControl := True;
FMainID := '';
FTabIndex := 0;
FScript := TStringList.Create;
FScript.OnChange := OnScriptChange;
FScriptInsideTag := True;
FScriptParams := TDWScriptParams.Create;
FScriptParams.OnChange := OnScriptChange;
FScriptEvents := TDWScriptEvents.Create(Self);
FStyle := TStringList.Create;
FStyle.OnChange := OnStyleChange;
FStyle.NameValueSeparator := ':';
FStyleRenderOptions := TDWRenderOptions.Create(Self);
FStyleRenderOptions.SetSubComponent(True);
FStyleRenderOptions.RenderSize := False;
FStyleRenderOptions.RenderPosition := False;
FStyleRenderOptions.RenderFont := False;
FStyleRenderOptions.RenderZIndex := False;
FStyleRenderOptions.RenderVisibility := False;
FStyleRenderOptions.RenderStatus := False;
FStyleRenderOptions.RenderAbsolute := False;
FStyleRenderOptions.RenderPadding := False;
FStyleRenderOptions.RenderBorder := False;
FStyleRenderOptions.UseDisplay := False;
// default parent
if (Parent = nil) and (AOwner <> nil) and (AOwner is TWinControl) then
Parent := TWinControl(AOwner);
// default Name
if name = '' then
name := DWGetUniqueComponentName(Owner, Copy(ClassName, 2, MaxInt));
end;
destructor TDWControl.Destroy;
begin
// FreeAndNil(FCustomAsyncEvents);
// FreeAndNil(FCustomRestEvents);
FreeAndNil(FScript);
FreeAndNil(FScriptParams);
FreeAndNil(FStyle);
FStyleRenderOptions.Free;
inherited;
end;
procedure TDWControl.OnStyleChange(ASender: TObject);
begin
Invalidate;
end;
procedure TDWControl.Paint;
var
LRect, LIcon: TRect;
s, c: string;
LMultiLine: boolean;
begin
LRect := Rect(0, 0, Width, Height);
Canvas.Brush.Color := clWhite;
Canvas.Pen.Color := clGray;
Canvas.Font.Name := CNST_DEFAULTFONTNAME;
Canvas.Font.Size := 10;
Canvas.Font.Color := clBlack;
Canvas.Rectangle(LRect);
Inc(LRect.Top, 2);
Inc(LRect.Left, 2);
Dec(LRect.Bottom, 2);
Dec(LRect.Right, 2);
Canvas.Pen.Color := clLtGray;
Canvas.Rectangle(LRect);
if Self is TDWCustomInput then
begin
LMultiLine := False;
s := TDWCustomInput(Self).DataField;
if Self is TDWCustomTextInput then
begin
if s = '' then
s := TDWInput(Self).Text;
if s = '' then
begin
s := TDWInput(Self).PlaceHolder;
Canvas.Font.Color := clLtGray;
end;
if Self is TDWMemo then
LMultiLine := True;
end
else if Self is TDWSelect then
begin
LMultiLine := TDWSelect(Self).Size <> 1;
if s = '' then
if LMultiLine then
s := TDWSelect(Self).Items.Text
else if TDWSelect(Self).Items.Count > 0 then
s := TDWSelect(Self).Items[0];
if not LMultiLine then
begin
LIcon := Rect(LRect.Right - 18, LRect.Top + 1, LRect.Right - 1, LRect.Bottom - 1);
Canvas.Font.Name := CNST_GLYPHICONSFONT;
Canvas.Brush.Color := clLtGray;
Canvas.Rectangle(LIcon);
c := GetGlyphiconChar('chevron-down', 'V');
if c <> '' then
begin
DrawTextEx(Canvas.Handle, PChar(c), 1, LIcon, DT_CENTER + DT_SINGLELINE +
DT_VCENTER, nil);
Canvas.Font.Name := CNST_DEFAULTFONTNAME;
Canvas.Brush.Color := clWhite;
Dec(LRect.Right, 20);
end;
end;
end;
Inc(LRect.Top, 1);
Inc(LRect.Left, 8);
Dec(LRect.Bottom, 1);
Dec(LRect.Right, 8);
if LMultiLine then
Canvas.TextRect(LRect, s, [])
else
DrawTextEx(Canvas.Handle, PChar(s), Length(s), LRect, DT_SINGLELINE + DT_VCENTER, nil);
end;
end;
function TDWControl.ParentContainer: TDWContainer;
begin
Result := GetParentContainer(Self);
end;
procedure TDWControl.OnScriptChange(ASender: TObject);
begin
AsyncRefreshControl;
end;
procedure TDWControl.DoAsyncClick(aParams: TStringList);
begin
if Assigned(FOnAsyncClick) then
FOnAsyncClick(Self, aParams);
end;
procedure TDWControl.DoAsyncMouseDown(aParams: TStringList);
begin
if Assigned(FOnAsyncMouseDown) then
FOnAsyncMouseDown(Self, aParams);
end;
procedure TDWControl.DoAsyncMouseMove(aParams: TStringList);
begin
if Assigned(FOnAsyncMouseMove) then
FOnAsyncMouseMove(Self, aParams);
end;
procedure TDWControl.DoAsyncMouseUp(aParams: TStringList);
begin
if Assigned(FOnAsyncMouseUp) then
FOnAsyncMouseUp(Self, aParams);
end;
procedure TDWControl.DoAsyncDblClick(aParams: TStringList);
begin
if Assigned(FOnAsyncDoubleClick) then
FOnAsyncDoubleClick(Self, aParams);
end;
procedure TDWControl.DoAsyncMouseOut(aParams: TStringList);
begin
if Assigned(FOnAsyncMouseOut) then
FOnAsyncMouseOut(Self, aParams);
end;
procedure TDWControl.DoAsyncMouseOver(aParams: TStringList);
begin
if Assigned(FOnAsyncMouseOver) then
FOnAsyncMouseOver(Self, aParams);
end;
procedure TDWControl.Release;
begin
DWApplication.ReleaseObject(Self);
FReleased := True;
end;
function TDWControl.RenderAsync: TDWElementXHTMLTag;
var
xHTMLName: string;
xInputSelector: string;
begin
Result := nil;
if FAsyncRefreshControl or not FRendered then
begin
xHTMLName := FMainID;
TDWBSCommon.RenderAsync(xHTMLName, Self);
end
else
begin
xHTMLName := HTMLName;
if InputSelector <> '' then
xInputSelector := FMainID + InputSelector
else
xInputSelector := xHTMLName + InputSuffix;
TDWBSCommon.SetAsyncClass(xHTMLName, RenderCSSClass, FOldCss);
TDWBSCommon.SetAsyncDisabled(xInputSelector, IsDisabled, FOldDisabled);
TDWBSCommon.SetAsyncReadOnly(xInputSelector, IsReadOnly, FOldReadOnly);
TDWBSCommon.SetAsyncStyle(xHTMLName, RenderStyle, FOldStyle);
TDWBSCommon.SetAsyncVisible(FMainID, Visible, FOldVisible);
InternalRenderAsync(xHTMLName);
if Assigned(FOnAfterAsyncChange) then
FOnAfterAsyncChange(Self);
{ TODO 1 -oDELCIO -cIMPLEMENT : Global OnAfterAsyncChange Event }
(* if Assigned(gIWBSOnAfterAsyncChange) then
gIWBSOnAfterAsyncChange(Self, xHTMLName); *)
end;
end;
function TDWControl.RenderAsyncEvents: string;
var
LCallbackName: string;
begin
if Assigned(FOnAsyncClick) then
begin
LCallbackName := DWApplication.RegisterCallBack(Self, ae_click, DoAsyncClick);
Result := JQSelector + '.off("click.DW").on("click.DW", ' + 'function (e) {' +
'executeAjaxCallBack("", ' + JQSelector + '[0], "' + LCallbackName + '");' + '})';
end;
if Assigned(FOnAsyncMouseDown) then
begin
LCallbackName := DWApplication.RegisterCallBack(Self, ae_mousedown, DoAsyncMouseDown);
Result := JQSelector + '.off("mousedown.DW").on("mousedown.DW", ' + 'function (e) {' +
'executeAjaxCallBack("", ' + JQSelector + '[0], "' + LCallbackName + '");' + '})';
end;
if Assigned(FOnAsyncDoubleClick) then
begin
LCallbackName := DWApplication.RegisterCallBack(Self, ae_dblclick, DoAsyncDblClick);
Result := JQSelector + '.off("dblclick.DW").on("dblclick.DW", ' + 'function (e) {' +
'executeAjaxCallBack("", ' + JQSelector + '[0], "' + LCallbackName + '");' + '})';
end;
if Assigned(FOnAsyncMouseMove) then
begin
LCallbackName := DWApplication.RegisterCallBack(Self, ae_mousemove, DoAsyncMouseMove);
Result := JQSelector + '.off("mousemove.DW").on("mousemove.DW", ' + 'function (e) {' +
'executeAjaxCallBack("", ' + JQSelector + '[0], "' + LCallbackName + '");' + '})';
end;
if Assigned(FOnAsyncMouseUp) then
begin
LCallbackName := DWApplication.RegisterCallBack(Self, ae_mouseup, DoAsyncMouseUp);
Result := JQSelector + '.off("mouseup.DW").on("mouseup.DW", ' + 'function (e) {' +
'executeAjaxCallBack("", ' + JQSelector + '[0], "' + LCallbackName + '");' + '})';
end;
if Assigned(FOnAsyncMouseOut) then
begin
LCallbackName := DWApplication.RegisterCallBack(Self, ae_mouseout, DoAsyncMouseOut);
Result := JQSelector + '.off("mouseout.DW").on("mouseout.DW", ' + 'function (e) {' +
'executeAjaxCallBack("", ' + JQSelector + '[0], "' + LCallbackName + '");' + '})';
end;
if Assigned(FOnAsyncMouseOver) then
begin
LCallbackName := DWApplication.RegisterCallBack(Self, ae_mouseover, DoAsyncMouseOver);
Result := JQSelector + '.off("mouseover.DW").on("mouseover.DW", ' + 'function (e) {' +
'executeAjaxCallBack("", ' + JQSelector + '[0], "' + LCallbackName + '");' + '})';
end;
end;
function TDWControl.RenderBGColor: string;
begin
end;
function TDWControl.RenderCSSClass: string;
begin
Result := Css;
InternalRenderCss(Result);
end;
function TDWControl.RenderCursorStyle: string;
begin
{ TODO 1 -oDELCIO -cIMPLEMENT : Rende Cursor Style }
end;
function TDWControl.RenderHTML: TDWElementTag;
begin
Result := nil;
FOldCss := RenderCSSClass;
FOldDisabled := IsDisabled;
FOldReadOnly := IsReadOnly;
FOldStyle := RenderStyle;
FOldVisible := Visible;
InternalRenderHTML(Result);
if Result = nil then
raise Exception.Create('HTML tag not created');
TDWBSCommon.RenderScript(Self, Result);
FMainID := Result.Params.Values['id'];
FAsyncRefreshControl := False;
FRendered := True;
end;
function TDWControl.RenderPositionStyle: string;
begin
end;
function TDWControl.RenderSizeStyle: string;
begin
end;
function TDWControl.RenderStyle: string;
begin
Result := TDWBSCommon.RenderStyle(Self);
end;
function TDWControl.RenderTextAlignStyle: String;
begin
end;
function TDWControl.RenderVerticalAlignStyle: string;
begin
end;
procedure TDWControl.RepaintControl;
begin
end;
function TDWControl.RootParent: TDWContainer;
var
// CompTest: TControl;
LForm: TDWCustomForm;
begin
Result := nil;
{ TODO 1 -oDELCIO -cIMPLEMENT : Find RootParent for Frame }
(* CompTest := self;
while Assigned(CompTest) and (not(CompTest is TDWCustomFrame)) do
CompTest := CompTest.Parent; *)
if Result = nil then
Result := TDWContainer(Form);
end;
procedure TDWControl.SetCss(const Value: string);
begin
FCss := Value;
end;
procedure TDWControl.SetEditable(const Value: boolean);
begin
FEditable := Value;
end;
procedure TDWControl.SetFocus;
begin
end;
procedure TDWControl.SetOnAfterRender(const Value: TNotifyEvent);
begin
FOnAfterRender := Value;
end;
procedure TDWControl.SetOnAsyncClick(const Value: TDWAsyncProcedure);
begin
FOnAsyncClick := Value;
end;
procedure TDWControl.SetOnAsyncDoubleClick(const Value: TDWAsyncProcedure);
begin
FOnAsyncDoubleClick := Value;
end;
procedure TDWControl.SetOnAsyncMouseDown(const Value: TDWAsyncProcedure);
begin
FOnAsyncMouseDown := Value;
end;
procedure TDWControl.SetOnAsyncMouseMove(const Value: TDWAsyncProcedure);
begin
FOnAsyncMouseMove := Value;
end;
procedure TDWControl.SetOnAsyncMouseOut(const Value: TDWAsyncProcedure);
begin
FOnAsyncMouseOut := Value;
end;
procedure TDWControl.SetOnAsyncMouseOver(const Value: TDWAsyncProcedure);
begin
FOnAsyncMouseOver := Value;
end;
procedure TDWControl.SetOnAsyncMouseUp(const Value: TDWAsyncProcedure);
begin
FOnAsyncMouseUp := Value;
end;
procedure TDWControl.SetOnHTMLtag(const Value: TDWOnHtmlTagProcedure);
begin
FOnHTMLtag := Value;
end;
procedure TDWControl.SetOnRender(const Value: TNotifyEvent);
begin
FOnRender := Value;
end;
procedure TDWControl.SetScript(const Value: TStringList);
begin
FScript.Assign(Value);
end;
procedure TDWControl.SetScriptEvents(const Value: TDWScriptEvents);
begin
FScriptEvents := Value;
end;
procedure TDWControl.SetScriptInsideTag(const Value: boolean);
begin
if FScriptInsideTag <> Value then
begin
FScriptInsideTag := Value;
AsyncRefreshControl;
end;
end;
procedure TDWControl.SetScriptParams(const Value: TDWScriptParams);
begin
FScriptParams.Assign(Value);
end;
procedure TDWControl.SetStyle(const Value: TStringList);
begin
FStyle := Value;
end;
procedure TDWControl.SetStyleRenderOptions(const Value: TDWRenderOptions);
begin
FStyleRenderOptions := Value;
end;
procedure TDWControl.SetZIndex(const Value: Integer);
begin
FZIndex := Value;
end;
function TDWControl.Form: TControl;
begin
Result := DWFindParentForm(Self);
end;
function TDWControl.GetScript: TStringList;
begin
Result := FScript;
end;
function TDWControl.GetScriptInsideTag: boolean;
begin
Result := FScriptInsideTag;
end;
function TDWControl.GetScriptParams: TDWScriptParams;
begin
Result := FScriptParams;
end;
function TDWControl.HTMLName: string;
var
LRootParent: TDWContainer;
begin
LRootParent := RootParent;
//
if LRootParent.InheritsFrom(TDWCustomForm) then
HTMLName := Name
else
HTMLName := LRootParent.Name + '_' + Name;
end;
function TDWControl.InputSelector: string;
begin
Result := '';
end;
function TDWControl.InputSuffix: string;
begin
Result := '';
end;
procedure TDWControl.InternalRenderAsync(const aHTMLName: string);
begin
//
end;
procedure TDWControl.InternalRenderCss(var ACss: string);
begin
//
end;
procedure TDWControl.InternalRenderHTML(var AHTMLTag: TDWElementTag);
begin
//
end;
procedure TDWControl.InternalRenderScript(const aHTMLName: string; AScript: TStringList);
begin
//
end;
procedure TDWControl.InternalRenderStyle(AStyle: TStringList);
begin
if StyleRenderOptions.RenderSize then
begin
AStyle.Values['height'] := IntToStr(Height) + 'px';
AStyle.Values['width'] := IntToStr(Width) + 'px';
end;
if StyleRenderOptions.RenderPosition then
begin
AStyle.Values['left'] := IntToStr(Left) + 'px';
AStyle.Values['top'] := IntToStr(Top) + 'px';
end;
if StyleRenderOptions.RenderFont then
begin
AStyle.Values['font-family'] := Font.Name;
AStyle.Values['font-size'] := IntToStr(Font.Size) + 'px';
end;
if StyleRenderOptions.RenderZIndex then
begin
if ZIndex <> 0 then
AStyle.Values['z-index'] := IntToStr(ZIndex);
end;
if StyleRenderOptions.RenderVisibility then
begin
if not Visible then
AStyle.Values['visibility'] := 'hidden';
end;
if StyleRenderOptions.RenderPadding then
begin
{ TODO 1 -oDELCIO -cIMPLEMENT : Render Controls Padding }
end;
if StyleRenderOptions.RenderBorder then
begin
{ TODO 1 -oDELCIO -cIMPLEMENT : Render Controls Border }
end;
if StyleRenderOptions.RenderAbsolute then
begin
{ TODO 1 -oDELCIO -cIMPLEMENT : Render Controls Absolute }
end;
end;
procedure TDWControl.Invalidate;
begin
inherited;
end;
function TDWControl.IsDesignMode: boolean;
begin
Result := (csDesigning in ComponentState) or (csLoading in ComponentState);
end;
function TDWControl.IsDisabled: boolean;
begin
Result := not Enabled;
end;
function TDWControl.IsLoading: boolean;
begin
Result := csLoading in ComponentState;
end;
function TDWControl.IsReadOnly: boolean;
begin
Result := True;
end;
function TDWControl.IsReleased: boolean;
begin
Result := FReleased;
end;
function TDWControl.IsScriptEventsStored: boolean;
begin
Result := FScriptEvents.Count > 0;
end;
function TDWControl.JQSelector: string;
begin
Result := '$("#' + HTMLName + '")';
end;
{ TDWInputControl }
function TDWInputControl.AsyncEvents: TDWAsyncEventTypeSet;
begin
Result := inherited;
if Assigned(FOnAsyncSelect) then
Include(Result, ae_select);
if Assigned(FOnAsyncExit) then
Include(Result, ae_blur);
if Assigned(FOnAsyncKeyPress) then
Include(Result, ae_keypress);
if Assigned(FOnAsyncKeyDown) then
Include(Result, ae_keydown);