forked from dstd/HtmlayoutDelphi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHtmlElement.pas
3773 lines (3204 loc) · 158 KB
/
HtmlElement.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
unit HtmlElement;
(*
HTMLayout License terms could be found here http://www.terrainformatica.com/htmlayout/prices.whtm
SDK - http://www.terrainformatica.com/htmlayout/HTMLayoutSDK.zip
Delphi binding of HTMLayout published under LGPL. Visit https://github.com/Keksov/HtmlayoutDelphi
This file contains classes for manipulating DOM and handling events.
*)
interface
{$IFDEF USER_DEFINES_INC}{$I user_defines.inc}{$ENDIF}
uses Windows, sysutils, Contnrs, graphics
, HtmlTypes
, HtmlBehaviorH
, HtmlLayoutH
, HtmlLayoutDomH
, HtmlValueH
, HtmlValue
, unisSVG
, htmlConst
;
const
INSERT_AT_END = $7FFFFFF;
type
THtmlHElement = class;
{---------------------------- THtmlHElement -----------------------------------}
RParentInfo = record
index : cardinal;
parent : HELEMENT;
children_count : cardinal;
end;
HTMLayoutHElementCallback = function( he : HELEMENT; sParams : POINTER ) : boolean of object;
RSelectHandler = record
callback : HTMLayoutHElementCallback;
params : Pointer;
end;
PRSelectHandler = ^RSelectHandler;
{***************************************************************************
* THtmlHElement
***************************************************************************}
THtmlHElement = class( TInterfacedObject )
private
Fhandler : HELEMENT;
FlastError : HLDOM_RESULT;
Funused : boolean;
Fvalue : THtmlValue;
private
procedure setHandler( const aHandler : HELEMENT );
function getParentInfo() : RParentInfo;
procedure setStyleAsInt( const aAttrIndex : integer; const aValue : integer );
function getStyleAsInt( const aAttrIndex : integer ) : integer;
procedure setStyleAsString( const aAttrIndex : integer; const aValue : string );
function getStyleAsString( const aAttrIndex : integer ) : string;
function getId() : widestring;
procedure setId( const aId : widestring );
function getOuterHtml() : string;
procedure setOuterHtml( const aHtml : string );
function getInnerHtml() : string;
procedure setInnerHtml( const aHtml : string );
function getIndex() : cardinal;
function getAttributeByIndex( const aAttrIndex : cardinal ) : widestring;
procedure setAttributeByIndex( const aAttrIndex : cardinal; const aValue : widestring );
function getAttributeByName( const aAttrName : string ) : widestring;
function getAttributeInt( const aAttrName : string ) : integer;
procedure setAttributeInt( const aAttrName : string; const aValue : integer );
function getAttrExists( const aAttrName : string ) : boolean;
function getAttributeIndex( const aAttrName : string ) : integer;
function getInnerText() : string;
procedure setInnerText( const aUtf8bytes: string );
function getInnerText16() : widestring;
procedure setInnerText16( const aUtf16words: widestring );
function getLocation() : TRect;
function getStates() : cardinal;
procedure setStates( aBits : cardinal );
function getState( aBit : cardinal ) : boolean;
procedure setState( aBit : cardinal; aState : boolean );
function getNamedState( aBit : integer ) : boolean;
procedure setNamedState( aBit : integer; aState : boolean );
function getValue() : THtmlValue;
protected
function getChild( const aIndex : integer ) : HELEMENT;
function getChildHandler( const aHandler : HELEMENT; const aIndex : integer ) : HELEMENT;
function getParentHandler() : HELEMENT;
function cloneHandler() : HELEMENT;
function getFirstSiblingHandler() : HELEMENT;
function getLastSiblingHandler() : HELEMENT;
function getNextSiblingHandler() : HELEMENT;
function getPrevSiblingHandler() : HELEMENT;
function getHandlerById( const aId : string ) : HELEMENT;
function getRootHandler() : HELEMENT;
function getElementUid( const aHandler : HELEMENT ) : UINT;
function getChildrenCount( const aHandler : HELEMENT ) : cardinal;
function internalUse() : boolean;
function internalUnuse() : boolean;
procedure freeResources(); virtual;
procedure internalSetHandler( const aHandler : HELEMENT ); virtual;
public
constructor Create(); overload; virtual;
constructor Create( const aHandler : HELEMENT ); overload;
constructor Create( const aHElement : THtmlHElement ); overload;
constructor Create( const aTag : string; const aText : widestring = '' ); overload;
destructor Destroy(); override;
function use() : boolean;
function unuse() : boolean;
function clone() : HELEMENT;
function get_element_by_id( const aId : string ) : HELEMENT;
function next_sibling() : HELEMENT;
function prev_sibling() : HELEMENT;
function first_sibling() : HELEMENT;
function last_sibling() : HELEMENT;
procedure insert( const aHandler : HELEMENT; const index : cardinal );
procedure append( const aHandler : HELEMENT );
procedure delete(); // delete DOM element given by Fhandler from html
function is_valid() : boolean; overload;
function is_valid( const aHandler : HELEMENT ) : boolean; overload;
function children_count() : cardinal;
function get_attribute_count() : cardinal;
function get_attribute( const aAttrIndex : cardinal ) : widestring; overload;
function get_attribute( const aAttrName : string ) : widestring; overload;
function get_attribute_name( const aAttrIndex : cardinal ) : widestring;
procedure set_attribute( const aAttrName : string; const aValue : widestring );
function get_attribute_int( const aAttrName : string; aDefaultValue : integer = 0 ) : integer;
procedure remove_attribute( const aAttrName : string );
function get_style_attribute( const aAttrName : string ) : widestring;
procedure set_style_attribute( const aAttrName : string; const aValue : widestring );
procedure set_capture();
procedure select( aCallback : HTMLayoutElementCallback; const aSelector : string; const aParams : POINTER = nil ); overload;
procedure select( aCallback : HTMLayoutHElementCallback; const aSelector : string; const aParams : POINTER = nil ); overload;
procedure select( aCallback : HTMLayoutElementCallback; const aParams : POINTER = nil; const aTag : string = ''; const aAttrName : string = ''; const aAttrValue : widestring = ''; aDepth : integer = 0 ); overload;
procedure select( aCallback : HTMLayoutHElementCallback; const aParams : POINTER = nil; const aTag : string = ''; const aAttrName : string = ''; const aAttrValue : widestring = ''; aDepth : integer = 0 ); overload;
procedure select( const aSelector : string; var aResult : HELEMENT ); overload; virtual;
procedure update( const render_now : boolean = false ); overload;
// aMode - bitwise combination of UPDATE_ELEMENT_FLAGS
procedure update( const aMode : integer ); overload;
procedure redraw();
function get_location( const aArea : HTMLAYOUT_ELEMENT_AREAS = ROOT_RELATIVE ) : TRect; virtual;
function is_inside( const client_pt : TPOINT ) : boolean;
procedure scroll_to_view( toTopOfView : boolean = false; smooth : boolean = false );
function get_element_type() : string;
function get_value() : RHtmlValue; // this is low level API call of HTMLayoutControlGetValue, use 'value' property instead ( see. THtmlValue )
procedure set_value( var aValue : RHtmlValue ); // this is low level API call of HTMLayoutControlSetValue, use 'value' property instead ( see. THtmlValue )
function get_element_hwnd( const root_window : boolean ) : HWND;
function get_element_uid() : UINT;
function combine_url( const inURL : widestring ) : widestring;
procedure set_html( const html : string; where : HTMLayoutSetHTMLWhere = SIH_REPLACE_CONTENT );
procedure clear();
function get_state( bits : cardinal ) : boolean;
procedure set_state( bitsToSet : cardinal; bitsToClear : cardinal = 0; update : boolean = true );
function enabled() : boolean;
function visible() : boolean;
procedure detach(); overload;
function send_event( event_code : cardinal; reason : cardinal = 0; heSource : HELEMENT = nil ) : boolean;
procedure post_event( event_code : cardinal; reason : cardinal = 0; heSource : HELEMENT = nil );
{** move element to new location given by x_view_rel, y_view_rel - view relative coordinates.
* Method defines local styles, so to "stick" it back to the original location you
* should call element::clear_all_style_attributes().
**}
procedure move( x_view_rel, y_view_rel : integer ); overload;
procedure move( x_view_rel, y_view_rel, aWidth, aHeight : integer ); overload;
procedure attach( pevth : HTMLayoutElementEventProc; tag : Pointer = nil; subscription : UINT = HANDLE_ALL );
procedure detach( pevth : HTMLayoutElementEventProc; tag : Pointer = nil; subscription : UINT = HANDLE_ALL ); overload;
function render( aHBmp : HBITMAP; aDstRect : TRect ) : boolean; overload;
function render( aBitmap : TBitmap ) : boolean; overload;
class procedure release_capture();
class function cleanHtml( const aHtml : string ) : string; // remove 0xD, 0xA, 0x9 from string
public // property
property id : widestring read getId write setId;
property tag : string read get_element_type; // div, span, p, etc.
property uid : UINT read get_element_uid;
property states : cardinal read getStates write setStates;
property state[ aState : cardinal ] : boolean read getState write setState;
property lastError : HLDOM_RESULT read FlastError;
property handler : HELEMENT read Fhandler write setHandler;
property root : HELEMENT read getRootHandler;
property parent : HELEMENT read getParentHandler;
property child[ const aIndex : integer ] : HELEMENT read getChild;
property outerHtml : string read getOuterHtml write setOuterHtml;
property innerHtml : string read getInnerHtml write setInnerHtml;
property childrenCount : cardinal read children_count;
property index : cardinal read getIndex;
property attributeCount : cardinal read get_attribute_count;
property attributeByIndex[ const aAttrIndex : cardinal ] : widestring read getAttributeByIndex write setAttributeByIndex;
property attribute[ const aAttrName : string ] : widestring read getAttributeByName write set_attribute; default;
property attributeName[ const aIndex : cardinal ] : widestring read get_attribute_name;
property attributeIndex[ const aAttrName : string ] : integer read getAttributeIndex;
property attrAsInt[ const aAttrName : string ] : integer read getAttributeInt write setAttributeInt;
property attrExists[ const aAttrName : string ] : boolean read getAttrExists;
property style[ const aAttrName : string ] : widestring read get_style_attribute write set_style_attribute;
property innerText : string read getInnerText write setInnerText;
property innerText16 : widestring read getInnerText16 write setInnerText16;
property location : TRect read getLocation;
public // property: CSS shorcuts, fill free to extend it.
property pxWidth : integer index STYLE_ATTR_WIDTH read getStyleAsInt write setStyleAsInt;
property pxHeight : integer index STYLE_ATTR_HEIGHT read getStyleAsInt write setStyleAsInt;
property pxLeft : integer index STYLE_ATTR_LEFT read getStyleAsInt write setStyleAsInt;
property pxTop : integer index STYLE_ATTR_TOP read getStyleAsInt write setStyleAsInt;
property backgroundColor : string index STYLE_ATTR_BACKGROUND_COLOR read getStyleAsString write setStyleAsString;
property color : string index STYLE_ATTR_COLOR read getStyleAsString write setStyleAsString;
property visibility : string index STYLE_ATTR_VISIBILITY read getStyleAsString write setStyleAsString;
property value : THtmlValue read getValue;
public // property|: predefined states, same as state[ aState : cardinal ] but with more readable names
// more info on states could be found here http://www.terrainformatica.com/htmlayout/csss!-dom-object.htm
property link : boolean index STATE_LINK read getNamedState write setNamedState; // any element having href attribute
property hover : boolean index STATE_HOVER read getNamedState write setNamedState; // element is under the cursor, mouse hover
property active : boolean index STATE_ACTIVE read getNamedState write setNamedState; // element is activated, e.g. pressed
property focus : boolean index STATE_FOCUS read getNamedState write setNamedState; // element is in focus
property visited : boolean index STATE_VISITED read getNamedState write setNamedState; // aux flag - not used internally now
property current : boolean index STATE_CURRENT read getNamedState write setNamedState; // current (hot) item in collection, e.g. current <option> in <select>
property checked : boolean index STATE_CHECKED read getNamedState write setNamedState; // element is checked (or selected), e.g. check box or itme in multiselect
property disabled : boolean index STATE_DISABLED read getNamedState write setNamedState; // element is disabled, behavior related flag.
property readonly : boolean index STATE_READONLY read getNamedState write setNamedState; // readonly input element, behavior related flag
property expanded : boolean index STATE_EXPANDED read getNamedState write setNamedState; // expanded state - nodes in tree view e.g. <options> in <select>
property collapsed : boolean index STATE_COLLAPSED read getNamedState write setNamedState; // collapsed state - nodes in tree view - mutually exclusive with EXPANDED
property incomplete : boolean index STATE_INCOMPLETE read getNamedState write setNamedState; // element has (back/fore/bullet) images requested but not delivered
property animating : boolean index STATE_ANIMATING read getNamedState write setNamedState; // is animating currently
property focusable : boolean index STATE_FOCUSABLE read getNamedState write setNamedState; // shall accept focus
property anchor : boolean index STATE_ANCHOR read getNamedState write setNamedState; // first element in selection (<select miltiple>), :CURRENT is the current
property synthetic : boolean index STATE_SYNTHETIC read getNamedState write setNamedState; // synthesized DOM elements - don't emit it's head/tail, e.g. all missed cells in tables (<td>) are getting this flag
property owns_popup : boolean index STATE_OWNS_POPUP read getNamedState write setNamedState; // anchor(owner) element of visible popup.
property tab_focus : boolean index STATE_TABFOCUS read getNamedState write setNamedState; // element got focus by tab traversal. engine set it together with :focus.
property empty : boolean index STATE_EMPTY read getNamedState write setNamedState; // element is empty.
property busy : boolean index STATE_BUSY read getNamedState write setNamedState; // element is busy; loading. HTMLayoutRequestElementData will set this flag if external data was requested for the element. When data will be delivered engine will reset this flag on the element.
property drag_over : boolean index STATE_DRAG_OVER read getNamedState write setNamedState; // drag over the block that can accept it (so is current drop target). Flag is set for the drop target block. At any given moment of time it can be only one such block.
property drop_target : boolean index STATE_DROP_TARGET read getNamedState write setNamedState; // active drop target. Multiple elements can have this flag when D&D is active.
property moving : boolean index STATE_MOVING read getNamedState write setNamedState; // dragging/moving - the flag is set for the moving element (copy of the drag-source).
property copying : boolean index STATE_COPYING read getNamedState write setNamedState; // dragging/copying - the flag is set for the copying element (copy of the drag-source).
property drag_source : boolean index STATE_DRAG_SOURCE read getNamedState write setNamedState; // is set in element that is being dragged (element that is a drag source)
property drop_marker : boolean index STATE_DROP_MARKER read getNamedState write setNamedState; // element is drop marker
property pressed : boolean index STATE_PRESSED read getNamedState write setNamedState; // pressed - close to active but has wider life span - e.g. in MOUSE_UP it is still on, so behavior can check it in MOUSE_UP to discover CLICK condition.
property popup : boolean index STATE_POPUP read getNamedState write setNamedState; // this element is in popup state and presented to the user - out of flow now
property ltr : boolean index STATE_IS_LTR read getNamedState write setNamedState; // the element or one of its nearest container has @dir and that dir has "ltr" value
property rtl : boolean index STATE_IS_RTL read getNamedState write setNamedState; // the element or one of its nearest container has @dir and that dir has "rtl" value.
end;
{------------------------------- THtmlElement ---------------------------------}
THtmlElement = class;
CHtmlElement = class of THtmlElement;
HTMLElementProcEventHandler = function( aElement : THtmlElement; aEventGroup : UINT; aEventParams : Pointer; aTag : Pointer ) : boolean;
HTMLElementMethodEventHandler = function( aElement : THtmlElement; aEventGroup : UINT; aEventParams : Pointer; aTag : Pointer ) : boolean of object;
HTMLElementInitializationEventHandler = function( const aSender : THtmlElement; const aParams : PHTMLayoutInitializationParams; aTag : Pointer ) : boolean of object;
HTMLElementMouseEventHandler = function( const aSender : THtmlElement; const aParams : PHTMLayoutMouseParams; aTag : Pointer ) : boolean of object;
HTMLElementKeyEventHandler = function( const aSender : THtmlElement; const aParams : PHTMLayoutKeyParams; aTag : Pointer ) : boolean of object;
HTMLElementFocusEventHandler = function( const aSender : THtmlElement; const aParams : PHTMLayoutFocusParams; aTag : Pointer ) : boolean of object;
HTMLElementScrollEventHandler = function( const aSender : THtmlElement; const aParams : PHTMLayoutScrollParams; aTag : Pointer ) : boolean of object;
HTMLElementTimerEventHandler = function( const aSender : THtmlElement; const aParams : PHTMLayoutTimerParams; aTag : Pointer ) : boolean of object;
HTMLElementSizeEventHandler = function( const aSender : THtmlElement; aTag : Pointer ) : boolean of object;
HTMLElementDrawEventHandler = function( const aSender : THtmlElement; const aParams : PHTMLayoutDrawParams; aTag : Pointer ) : boolean of object;
HTMLElementDataArrivedEventHandler = function( const aSender : THtmlElement; const aParams : PHTMLayoutDataArrivedParams; aTag : Pointer ) : boolean of object;
HTMLElementBehaviorEventHandler = function( const aSender : THtmlElement; const aParams : PHTMLayoutBehaviorEventParams; aTag : Pointer ) : boolean of object;
HTMLElementExchangeEventHandler = function( const aSender : THtmlElement; const aParams : PHTMLayoutExchangeParams; aTag : Pointer ) : boolean of object;
HTMLElementGestureEventHandler = function( const aSender : THtmlElement; const aParams : PHTMLayoutGestureParams; aTag : Pointer ) : boolean of object;
{***************************************************************************
* TEventHandlerParams
***************************************************************************}
TEventHandlerParams = class
protected
Felement : THtmlElement;
Ftag : Pointer;
Fsubscription : UINT;
protected
function compare( aTag : Pointer; aSubscription : UINT ) : boolean;
function call( aEventGroup : UINT; aEventParams : Pointer ) : boolean; virtual; abstract;
public
constructor Create( aElement : THtmlElement ); overload; virtual;
constructor Create( aElement : THtmlElement; aTag : Pointer ); overload; virtual;
constructor Create( aElement : THtmlElement; aTag : Pointer; aSubscription : UINT ); overload; virtual;
end;
{***************************************************************************
* TProcHandlerParams
***************************************************************************}
TProcHandlerParams = class( TEventHandlerParams )
protected
Fcallback : HTMLElementProcEventHandler;
protected
function compare( aCallback : HTMLElementProcEventHandler; aTag : Pointer; aSubscription : UINT ) : boolean;
function call( aEventGroup : UINT; aEventParams : Pointer ) : boolean; override;
public
constructor Create( aElement : THtmlElement; aCallback : HTMLElementProcEventHandler; aTag : Pointer = nil; aSubscription : UINT = HANDLE_ALL or DISABLE_INITIALIZATION );
end;
{***************************************************************************
* TMethodHandlerParams
***************************************************************************}
TMethodHandlerParams = class( TEventHandlerParams )
protected
Fcallback : TMethod;
protected
function compare( aCallback : TMethod; aTag : Pointer; aSubscription : UINT ) : boolean;
function call( aEventGroup : UINT; aEventParams : Pointer ) : boolean; override;
public
constructor Create( aElement : THtmlElement; aCallback : TMethod; aTag : Pointer = nil; aSubscription : UINT = HANDLE_ALL or DISABLE_INITIALIZATION );
end;
{***************************************************************************
* THtmlCmdEventParams
***************************************************************************}
THtmlCmdEventParams = class( TMethodHandlerParams )
protected
Fcmd : UINT;
public
constructor Create( aElement : THtmlElement; aCallback : TMethod; aTag : Pointer; aSubscription : UINT = HANDLE_ALL or DISABLE_INITIALIZATION ); overload;
constructor Create( aElement : THtmlElement; aCmd : UINT; aCallback : TMethod; aTag : Pointer = nil; aSubscription : UINT = HANDLE_ALL or DISABLE_INITIALIZATION ); overload;
function compare( aCmd : UINT; aCallback : TMethod; aTag : Pointer; aSubscription : UINT ) : boolean;
end;
{***************************************************************************
* TEventHandlers
***************************************************************************}
TEventHandlers = class( TObjectList )
protected
function getHandlerIndex( aCallback : HTMLElementProcEventHandler; aTag : Pointer; aSubscription : UINT ) : integer; overload;
function getHandler( aCallback : HTMLElementProcEventHandler; aTag : Pointer; aSubscription : UINT ) : TProcHandlerParams; overload;
procedure removeHandler( aCallback : HTMLElementProcEventHandler; aTag : Pointer; aSubscription : UINT ); overload;
function getHandlerIndex( aCallback : TMethod; aTag : Pointer; aSubscription : UINT ) : integer; overload;
function getHandler( aCallback : TMethod; aTag : Pointer; aSubscription : UINT ) : TMethodHandlerParams; overload;
procedure removeHandler( aCallback : TMethod; aTag : Pointer; aSubscription : UINT ); overload;
function getHandlerIndex( aCmd : UINT; aCallback : TMethod; aTag : Pointer; aSubscription : UINT ) : integer; overload;
function getHandler( aCmd : UINT; aCallback : TMethod; aTag : Pointer; aSubscription : UINT ) : THtmlCmdEventParams; overload;
procedure removeHandler( aCmd : UINT; aCallback : TMethod; aTag : Pointer; aSubscription : UINT ); overload;
end;
{***************************************************************************
* TElementHolder
***************************************************************************}
TElementHolder = class
protected
FhitCount : integer;
Fhandler : HELEMENT;
Felement : THtmlElement;
FelementClass : CHtmlElement;
protected
function getElement() : THtmlElement;
public
constructor Create( aElementClass : CHtmlElement; aHandler : HELEMENT );
destructor Destroy(); override;
end;
{***************************************************************************
* TElementHolders
***************************************************************************}
TElementHolders = class( TObjectList )
protected
FelementClass : CHtmlElement;
public
destructor Destroy(); override;
procedure AfterConstruction(); override;
protected
function addElement( aHandler : HELEMENT ) : THtmlElement;
function getIndex( aHandler : HELEMENT ) : integer;
end;
{***************************************************************************
* THtmlElementList
***************************************************************************}
THtmlElementList = class( TObjectList )
protected
Fowner : THtmlElement;
FautoFreeMemory : boolean;
private
function getElementByIndex( aIndex : integer ) : THtmlElement;
function addElement( he : HELEMENT ) : integer;
protected // events setters and handlers
procedure attachInitialization( aCmd : integer; aEventHandler : HTMLElementInitializationEventHandler );
procedure attachMouse( aCmd : integer; aEventHandler : HTMLElementMouseEventHandler );
procedure attachKey( aCmd : integer; aEventHandler : HTMLElementKeyEventHandler );
procedure attachFocus( aCmd : integer; aEventHandler : HTMLElementFocusEventHandler );
procedure attachScroll( aCmd : integer; aEventHandler : HTMLElementScrollEventHandler );
procedure attachTimer( aEventHandler : HTMLElementTimerEventHandler );
procedure attachSize( aEventHandler : HTMLElementSizeEventHandler );
procedure attachDraw( aCmd : integer; aEventHandler : HTMLElementDrawEventHandler );
procedure attachDataArrived( aEventHandler : HTMLElementDataArrivedEventHandler );
procedure attachExchange( aCmd : integer; aEventHandler : HTMLElementExchangeEventHandler );
procedure attachGesture( aCmd : integer; aEventHandler : HTMLElementGestureEventHandler );
procedure attachBehavior( aCmd : integer; aEventHandler : HTMLElementBehaviorEventHandler );
public
procedure AfterConstruction(); override;
public // property
property elements[ aIndex : integer ] : THtmlElement read getElementByIndex; default;
public // events
// INITIALIZATION
property onInitialization : HTMLElementInitializationEventHandler index INITIALIZATION_ALL write attachInitialization; // All INITIALIZATION events
property onBehaviorDetach : HTMLElementInitializationEventHandler index BEHAVIOR_DETACH write attachInitialization;
property onBehaviorAttach : HTMLElementInitializationEventHandler index BEHAVIOR_ATTACH write attachInitialization;
// MOUSE
property onMouse : HTMLElementMouseEventHandler index MOUSE_ALL write attachMouse; // All MOUSE events
property onMouseEnter : HTMLElementMouseEventHandler index MOUSE_ENTER write attachMouse;
property onMouseLeave : HTMLElementMouseEventHandler index MOUSE_LEAVE write attachMouse;
property onMouseMove : HTMLElementMouseEventHandler index MOUSE_MOVE write attachMouse;
property onMouseUp : HTMLElementMouseEventHandler index MOUSE_UP write attachMouse;
property onMouseDown : HTMLElementMouseEventHandler index MOUSE_DOWN write attachMouse;
property onMouseClick : HTMLElementMouseEventHandler index MOUSE_CLICK write attachMouse;
property onClick : HTMLElementMouseEventHandler index MOUSE_CLICK write attachMouse;
property onMouseDClick : HTMLElementMouseEventHandler index MOUSE_DCLICK write attachMouse;
property onDblClick : HTMLElementMouseEventHandler index MOUSE_DCLICK write attachMouse;
property onMouseWheel : HTMLElementMouseEventHandler index MOUSE_WHEEL write attachMouse;
property onWheel : HTMLElementMouseEventHandler index MOUSE_WHEEL write attachMouse;
property onMouseTick : HTMLElementMouseEventHandler index MOUSE_TICK write attachMouse;
property onMouseIdle : HTMLElementMouseEventHandler index MOUSE_IDLE write attachMouse;
property onDrop : HTMLElementMouseEventHandler index DROP write attachMouse;
property onDragEnter : HTMLElementMouseEventHandler index DRAG_ENTER write attachMouse;
property onDragLeave : HTMLElementMouseEventHandler index DRAG_LEAVE write attachMouse;
property onDragRequest : HTMLElementMouseEventHandler index DRAG_REQUEST write attachMouse;
property onMouseDraggingEnter : HTMLElementMouseEventHandler index MOUSE_ENTER or DRAGGING write attachMouse;
property onMouseDraggingLeave : HTMLElementMouseEventHandler index MOUSE_LEAVE or DRAGGING write attachMouse;
property onMouseDraggingMove : HTMLElementMouseEventHandler index MOUSE_MOVE or DRAGGING write attachMouse;
property onMouseDraggingUp : HTMLElementMouseEventHandler index MOUSE_UP or DRAGGING write attachMouse;
property onMouseDraggingDown : HTMLElementMouseEventHandler index MOUSE_DOWN or DRAGGING write attachMouse;
// KEY
property onKey : HTMLElementKeyEventHandler index KEY_ALL write attachKey; // All KEY events
property onKeyDown : HTMLElementKeyEventHandler index KEY_DOWN write attachKey;
property onKeyUp : HTMLElementKeyEventHandler index KEY_UP write attachKey;
property onKeyChar : HTMLElementKeyEventHandler index KEY_CHAR write attachKey;
// FOCUS
property onFocus : HTMLElementFocusEventHandler index FOCUS_ALL write attachFocus; // All KEY events
property onFocusLost : HTMLElementFocusEventHandler index FOCUS_LOST write attachFocus;
property onFocusGot : HTMLElementFocusEventHandler index FOCUS_GOT write attachFocus;
// SCROLL
property onScroll : HTMLElementScrollEventHandler index SCROLL_ALL write attachScroll; // All SCROLL events
property onScrollHome : HTMLElementScrollEventHandler index SCROLL_HOME write attachScroll;
property onScrollEnd : HTMLElementScrollEventHandler index SCROLL_END write attachScroll;
property onScrollStepPlus : HTMLElementScrollEventHandler index SCROLL_STEP_PLUS write attachScroll;
property onScrollStepMinus : HTMLElementScrollEventHandler index SCROLL_STEP_MINUS write attachScroll;
property onScrollPagePlus : HTMLElementScrollEventHandler index SCROLL_PAGE_PLUS write attachScroll;
property onScrollPageMinus : HTMLElementScrollEventHandler index SCROLL_PAGE_MINUS write attachScroll;
property onScrollPos : HTMLElementScrollEventHandler index SCROLL_POS write attachScroll;
property onScrollSliderReleased : HTMLElementScrollEventHandler index SCROLL_SLIDER_RELEASED write attachScroll;
// TIMER
property onTimer : HTMLElementTimerEventHandler write attachTimer;
// SIZE
property onSize : HTMLElementSizeEventHandler write attachSize;
// DRAW
property onDraw : HTMLElementDrawEventHandler index DRAW_ALL write attachDraw; // All DRAW events
property onDrawBackground : HTMLElementDrawEventHandler index DRAW_BACKGROUND write attachDraw;
property onDrawContent : HTMLElementDrawEventHandler index DRAW_CONTENT write attachDraw;
property onDrawForeground : HTMLElementDrawEventHandler index DRAW_FOREGROUND write attachDraw;
// HANDLE_DATA_ARRIVED
property onDataArrived : HTMLElementDataArrivedEventHandler write attachDataArrived;
// EXCHANGE
property onExchange : HTMLElementExchangeEventHandler index EXC_ALL write attachExchange; // All EXCHANGE events
property onExchangeNone : HTMLElementExchangeEventHandler index EXC_NONE write attachExchange;
property onExchangeCopy : HTMLElementExchangeEventHandler index EXC_COPY write attachExchange;
property onExchangeMove : HTMLElementExchangeEventHandler index EXC_MOVE write attachExchange;
property onExchangeLink : HTMLElementExchangeEventHandler index EXC_LINK write attachExchange;
// GESTURE
property onGesture : HTMLElementGestureEventHandler index GESTURE_ALL write attachGesture; // All GESTURE events
property onGestureRequest : HTMLElementGestureEventHandler index GESTURE_REQUEST write attachGesture;
property onGestureZoom : HTMLElementGestureEventHandler index GESTURE_ZOOM write attachGesture;
property onGesturePan : HTMLElementGestureEventHandler index GESTURE_PAN write attachGesture;
property onGestureRotate : HTMLElementGestureEventHandler index GESTURE_ROTATE write attachGesture;
property onGestureTap1 : HTMLElementGestureEventHandler index GESTURE_TAP1 write attachGesture;
property onGestureTap2 : HTMLElementGestureEventHandler index GESTURE_TAP2 write attachGesture;
// BEHAVIOR_EVENT
property onButtonClick : HTMLElementBehaviorEventHandler index BUTTON_CLICK write attachBehavior;
property onButtonPress : HTMLElementBehaviorEventHandler index BUTTON_PRESS write attachBehavior;
property onButtonStateChanged : HTMLElementBehaviorEventHandler index BUTTON_STATE_CHANGED write attachBehavior;
property onEditValueChanging : HTMLElementBehaviorEventHandler index EDIT_VALUE_CHANGING write attachBehavior;
property onEditValueChanged : HTMLElementBehaviorEventHandler index EDIT_VALUE_CHANGED write attachBehavior;
property onSelectSelectionChanged : HTMLElementBehaviorEventHandler index SELECT_SELECTION_CHANGED write attachBehavior;
property onSelectStateChanged : HTMLElementBehaviorEventHandler index SELECT_STATE_CHANGED write attachBehavior;
property onPopupRequest : HTMLElementBehaviorEventHandler index POPUP_REQUEST write attachBehavior;
property onPopupReady : HTMLElementBehaviorEventHandler index POPUP_READY write attachBehavior;
property onPopupDismissed : HTMLElementBehaviorEventHandler index POPUP_DISMISSED write attachBehavior;
property onMenuItemActive : HTMLElementBehaviorEventHandler index MENU_ITEM_ACTIVE write attachBehavior;
property onMenuItemClick : HTMLElementBehaviorEventHandler index MENU_ITEM_CLICK write attachBehavior;
property onContextMenuSetup : HTMLElementBehaviorEventHandler index CONTEXT_MENU_SETUP write attachBehavior;
property onContextMenuRequest : HTMLElementBehaviorEventHandler index CONTEXT_MENU_REQUEST write attachBehavior;
property onVisiualStatusChanged : HTMLElementBehaviorEventHandler index VISIUAL_STATUS_CHANGED write attachBehavior;
property onDisabledStatusChanged : HTMLElementBehaviorEventHandler index DISABLED_STATUS_CHANGED write attachBehavior;
property onPopupDismissing : HTMLElementBehaviorEventHandler index POPUP_DISMISSING write attachBehavior;
// "grey" event codes - notfications from behaviors from this SDK
property onHyperLinkClick : HTMLElementBehaviorEventHandler index HYPERLINK_CLICK write attachBehavior;
property onTableHeaderClick : HTMLElementBehaviorEventHandler index TABLE_HEADER_CLICK write attachBehavior;
property onTableRowClick : HTMLElementBehaviorEventHandler index TABLE_ROW_CLICK write attachBehavior;
property onTableRowDblClick : HTMLElementBehaviorEventHandler index TABLE_ROW_DBL_CLICK write attachBehavior;
property onElementCollapsed : HTMLElementBehaviorEventHandler index ELEMENT_COLLAPSED write attachBehavior;
property onElementExpanded : HTMLElementBehaviorEventHandler index ELEMENT_EXPANDED write attachBehavior;
property onActivateChild : HTMLElementBehaviorEventHandler index ACTIVATE_CHILD write attachBehavior;
property onDoSwitchTab : HTMLElementBehaviorEventHandler index DO_SWITCH_TAB write attachBehavior;
property onInitDataView : HTMLElementBehaviorEventHandler index INIT_DATA_VIEW write attachBehavior;
property onRowsDataRequest : HTMLElementBehaviorEventHandler index ROWS_DATA_REQUEST write attachBehavior;
property onUiStateChanged : HTMLElementBehaviorEventHandler index UI_STATE_CHANGED write attachBehavior;
property onFormSubmit : HTMLElementBehaviorEventHandler index FORM_SUBMIT write attachBehavior;
property onFormReset : HTMLElementBehaviorEventHandler index FORM_RESET write attachBehavior;
property onDocumentComplete : HTMLElementBehaviorEventHandler index DOCUMENT_COMPLETE write attachBehavior;
property onHistoryPush : HTMLElementBehaviorEventHandler index HISTORY_PUSH write attachBehavior;
property onHistoryDrop : HTMLElementBehaviorEventHandler index HISTORY_DROP write attachBehavior;
property onHistoryPrior : HTMLElementBehaviorEventHandler index HISTORY_PRIOR write attachBehavior;
property onHistoryNext : HTMLElementBehaviorEventHandler index HISTORY_NEXT write attachBehavior;
property onHistoryStateChanged : HTMLElementBehaviorEventHandler index HISTORY_STATE_CHANGED write attachBehavior;
property onClosePopup : HTMLElementBehaviorEventHandler index CLOSE_POPUP write attachBehavior;
property onRequestTooltip : HTMLElementBehaviorEventHandler index REQUEST_TOOLTIP write attachBehavior;
property onAnimation : HTMLElementBehaviorEventHandler index ANIMATION write attachBehavior;
end;
{***************************************************************************
* THtmlElement
***************************************************************************}
THtmlElement = class( THtmlHElement )
private
Froot : TElementHolder;
Fparent : TElementHolder;
FeventHandlers : TEventHandlers;
FownElements : TElementHolders;
protected
FelementClass : CHtmlElement;
private
function getRoot() : THtmlElement;
function getParent() : THtmlElement;
function getChild( const aIndex : integer ) : THtmlElement;
function getEventHandlers() : TEventHandlers;
function getOwnElements() : TElementHolders;
function getElementsBySelector( const aSelector : string ) : THtmlElementList;
private // events setters and handlers
procedure attachInitialization( const aCmd : integer; const aEventHandler : HTMLElementInitializationEventHandler );
procedure attachMouse( const aCmd : integer; const aEventHandler : HTMLElementMouseEventHandler );
procedure attachKey( const aCmd : integer; const aEventHandler : HTMLElementKeyEventHandler );
procedure attachFocus( const aCmd : integer; const aEventHandler : HTMLElementFocusEventHandler );
procedure attachScroll( const aCmd : integer; const aEventHandler : HTMLElementScrollEventHandler );
procedure attachTimer( const aEventHandler : HTMLElementTimerEventHandler );
procedure attachSize( const aEventHandler : HTMLElementSizeEventHandler );
procedure attachDraw( const aCmd : integer; const aEventHandler : HTMLElementDrawEventHandler );
procedure attachDataArrived( const aEventHandler : HTMLElementDataArrivedEventHandler );
procedure attachExchange( const aCmd : integer; const aEventHandler : HTMLElementExchangeEventHandler );
procedure attachGesture( const aCmd : integer; const aEventHandler : HTMLElementGestureEventHandler );
procedure attachBehavior( const aCmd : integer; const aEventHandler : HTMLElementBehaviorEventHandler );
protected
procedure freeResources(); override;
private // property
property eventHandlers : TEventHandlers read getEventHandlers;
property ownElements : TElementHolders read getOwnElements;
public
constructor Create(); override;
destructor Destroy(); override;
function use() : THtmlElement;
function clone() : THtmlElement;
function get_element_by_id( const aId : string ) : THtmlElement;
function get_element_by_handler( const aHandler : HELEMENT ) : THtmlElement;
function update( const render_now : boolean = false ) : THtmlElement; overload;
function update( const aMode : integer ) : THtmlElement; overload;
function redraw() : THtmlElement;
function next_sibling() : THtmlElement;
function prev_sibling() : THtmlElement;
function first_sibling() : THtmlElement;
function last_sibling() : THtmlElement;
function scroll_to_view( toTopOfView : boolean = false; smooth : boolean = false ) : THtmlElement;
function set_state( const bitsToSet : cardinal; const bitsToClear : cardinal = 0; update : boolean = true ) : THtmlElement;
function insert( const element : THtmlHElement; const index : cardinal ) : THtmlElement;
function append( const element : THtmlHElement ) : THtmlElement;
function detach() : THtmlElement; overload;
procedure attach( aEventParams : TEventHandlerParams; aEventHandler : HTMLayoutElementEventProc ); overload;
procedure detach( aEventParams : TEventHandlerParams; aEventHandler : HTMLayoutElementEventProc ); overload;
procedure attach( aEventParams : TEventHandlerParams ); overload;
procedure detach( aEventParams : TEventHandlerParams ); overload;
function attach( aEventHandler : HTMLElementProcEventHandler; aTag : Pointer = nil; aSubscription : UINT = HANDLE_ALL or DISABLE_INITIALIZATION ) : TProcHandlerParams; overload;
procedure detach( aEventHandler : HTMLElementProcEventHandler; aTag : Pointer = nil; aSubscription : UINT = HANDLE_ALL or DISABLE_INITIALIZATION ); overload;
function attach( aEventHandler : HTMLElementMethodEventHandler; aTag : Pointer = nil; aSubscription : UINT = HANDLE_ALL or DISABLE_INITIALIZATION ) : TMethodHandlerParams; overload;
procedure detach( aEventHandler : HTMLElementMethodEventHandler; aTag : Pointer = nil; aSubscription : UINT = HANDLE_ALL or DISABLE_INITIALIZATION ); overload;
public // Event Handlers
procedure attach( aEventParams : THtmlCmdEventParams ); overload;
procedure detach( const aEventHandler : TMethod; const aCmd : integer = ALL_CMD; aTag : Pointer = nil; aSubscription : UINT = HANDLE_ALL or DISABLE_INITIALIZATION ); overload;
// INITIALIZATION
function attach( const aEventHandler : HTMLElementInitializationEventHandler; const aCmd : integer = INITIALIZATION_ALL; aTag : Pointer = nil ) : THtmlCmdEventParams; overload;
procedure detach( const aEventHandler : HTMLElementInitializationEventHandler; const aCmd : integer = INITIALIZATION_ALL; aTag : Pointer = nil ); overload;
// MOUSE
function attach( const aEventHandler : HTMLElementMouseEventHandler; const aCmd : integer = MOUSE_ALL; aTag : Pointer = nil; aSubscription : UINT = HANDLE_MOUSE or DISABLE_INITIALIZATION ) : THtmlCmdEventParams; overload;
procedure detach( const aEventHandler : HTMLElementMouseEventHandler; const aCmd : integer = MOUSE_ALL; aTag : Pointer = nil; aSubscription : UINT = HANDLE_MOUSE or DISABLE_INITIALIZATION ); overload;
// KEY
function attach( const aEventHandler : HTMLElementKeyEventHandler; const aCmd : integer = KEY_ALL; aTag : Pointer = nil; aSubscription : UINT = HANDLE_KEY or DISABLE_INITIALIZATION ) : THtmlCmdEventParams; overload;
procedure detach( const aEventHandler : HTMLElementKeyEventHandler; const aCmd : integer = KEY_ALL; aTag : Pointer = nil; aSubscription : UINT = HANDLE_KEY or DISABLE_INITIALIZATION ); overload;
// FOCUS
function attach( const aEventHandler : HTMLElementFocusEventHandler; const aCmd : integer = FOCUS_ALL; aTag : Pointer = nil; aSubscription : UINT = HANDLE_KEY or DISABLE_INITIALIZATION ) : THtmlCmdEventParams; overload;
procedure detach( const aEventHandler : HTMLElementFocusEventHandler; const aCmd : integer = FOCUS_ALL; aTag : Pointer = nil; aSubscription : UINT = HANDLE_KEY or DISABLE_INITIALIZATION ); overload;
// SCROLL
function attach( const aEventHandler : HTMLElementScrollEventHandler; const aCmd : integer = SCROLL_ALL; aTag : Pointer = nil; aSubscription : UINT = HANDLE_SCROLL or DISABLE_INITIALIZATION ) : THtmlCmdEventParams; overload;
procedure detach( const aEventHandler : HTMLElementScrollEventHandler; const aCmd : integer = SCROLL_ALL; aTag : Pointer = nil; aSubscription : UINT = HANDLE_SCROLL or DISABLE_INITIALIZATION ); overload;
// TIMER
function attach( const aEventHandler : HTMLElementTimerEventHandler; aTag : Pointer = nil; aSubscription : UINT = HANDLE_TIMER or DISABLE_INITIALIZATION ) : THtmlCmdEventParams; overload;
procedure detach( const aEventHandler : HTMLElementTimerEventHandler; aTag : Pointer = nil; aSubscription : UINT = HANDLE_TIMER or DISABLE_INITIALIZATION ); overload;
// SIZE
function attach( const aEventHandler : HTMLElementSizeEventHandler; aTag : Pointer = nil; aSubscription : UINT = HANDLE_SIZE or DISABLE_INITIALIZATION ) : THtmlCmdEventParams; overload;
procedure detach( const aEventHandler : HTMLElementSizeEventHandler; aTag : Pointer = nil; aSubscription : UINT = HANDLE_SIZE or DISABLE_INITIALIZATION ); overload;
// DRAW
function attach( const aEventHandler : HTMLElementDrawEventHandler; const aCmd : integer = DRAW_ALL; aTag : Pointer = nil; aSubscription : UINT = HANDLE_DRAW or DISABLE_INITIALIZATION ) : THtmlCmdEventParams; overload;
procedure detach( const aEventHandler : HTMLElementDrawEventHandler; const aCmd : integer = DRAW_ALL; aTag : Pointer = nil; aSubscription : UINT = HANDLE_DRAW or DISABLE_INITIALIZATION ); overload;
// DATA_ARRIVED
function attach( const aEventHandler : HTMLElementDataArrivedEventHandler; aTag : Pointer = nil; aSubscription : UINT = HANDLE_DATA_ARRIVED or DISABLE_INITIALIZATION ) : THtmlCmdEventParams; overload;
procedure detach( const aEventHandler : HTMLElementDataArrivedEventHandler; aTag : Pointer = nil; aSubscription : UINT = HANDLE_DATA_ARRIVED or DISABLE_INITIALIZATION ); overload;
// EXCHANGE
function attach( const aEventHandler : HTMLElementExchangeEventHandler; const aCmd : integer = EXC_ALL; aTag : Pointer = nil; aSubscription : UINT = HANDLE_EXCHANGE or DISABLE_INITIALIZATION ) : THtmlCmdEventParams; overload;
procedure detach( const aEventHandler : HTMLElementExchangeEventHandler; const aCmd : integer = EXC_ALL; aTag : Pointer = nil; aSubscription : UINT = HANDLE_EXCHANGE or DISABLE_INITIALIZATION ); overload;
// GESTURE
function attach( const aEventHandler : HTMLElementGestureEventHandler; const aCmd : integer = GESTURE_ALL; aTag : Pointer = nil; aSubscription : UINT = HANDLE_GESTURE or DISABLE_INITIALIZATION ) : THtmlCmdEventParams; overload;
procedure detach( const aEventHandler : HTMLElementGestureEventHandler; const aCmd : integer = GESTURE_ALL; aTag : Pointer = nil; aSubscription : UINT = HANDLE_GESTURE or DISABLE_INITIALIZATION ); overload;
// BEHAVIOR_EVENT
function attach( const aEventHandler : HTMLElementBehaviorEventHandler; const aCmd : integer = BEHAVIOR_ALL; aTag : Pointer = nil; aSubscription : UINT = HANDLE_BEHAVIOR_EVENT or DISABLE_INITIALIZATION ) : THtmlCmdEventParams; overload;
procedure detach( const aEventHandler : HTMLElementBehaviorEventHandler; const aCmd : integer = BEHAVIOR_ALL; aTag : Pointer = nil; aSubscription : UINT = HANDLE_BEHAVIOR_EVENT or DISABLE_INITIALIZATION ); overload;
public // property
property root : THtmlElement read getRoot;
property parent : THtmlElement read getParent;
property child[ const aIndex : integer ] : THtmlElement read getChild;
property nextSibling : THtmlElement read next_sibling;
property prevSibling : THtmlElement read prev_sibling;
property firstSibling : THtmlElement read first_sibling;
property lastSibling : THtmlElement read last_sibling;
property elements[ const aSelector : string ] : THtmlElementList read getElementsBySelector;
public // events
// INITIALIZATION
property onInitialization : HTMLElementInitializationEventHandler index INITIALIZATION_ALL write attachInitialization; // All INITIALIZATION events
property onBehaviorDetach : HTMLElementInitializationEventHandler index BEHAVIOR_DETACH write attachInitialization;
property onBehaviorAttach : HTMLElementInitializationEventHandler index BEHAVIOR_ATTACH write attachInitialization;
// MOUSE
property onMouse : HTMLElementMouseEventHandler index MOUSE_ALL write attachMouse; // All MOUSE events
property onMouseEnter : HTMLElementMouseEventHandler index MOUSE_ENTER write attachMouse;
property onMouseLeave : HTMLElementMouseEventHandler index MOUSE_LEAVE write attachMouse;
property onMouseMove : HTMLElementMouseEventHandler index MOUSE_MOVE write attachMouse;
property onMouseUp : HTMLElementMouseEventHandler index MOUSE_UP write attachMouse;
property onMouseDown : HTMLElementMouseEventHandler index MOUSE_DOWN write attachMouse;
property onMouseClick : HTMLElementMouseEventHandler index MOUSE_CLICK write attachMouse;
property onClick : HTMLElementMouseEventHandler index MOUSE_CLICK write attachMouse;
property onMouseDClick : HTMLElementMouseEventHandler index MOUSE_DCLICK write attachMouse;
property onDblClick : HTMLElementMouseEventHandler index MOUSE_DCLICK write attachMouse;
property onMouseWheel : HTMLElementMouseEventHandler index MOUSE_WHEEL write attachMouse;
property onWheel : HTMLElementMouseEventHandler index MOUSE_WHEEL write attachMouse;
property onMouseTick : HTMLElementMouseEventHandler index MOUSE_TICK write attachMouse;
property onMouseIdle : HTMLElementMouseEventHandler index MOUSE_IDLE write attachMouse;
property onDrop : HTMLElementMouseEventHandler index DROP write attachMouse;
property onDragEnter : HTMLElementMouseEventHandler index DRAG_ENTER write attachMouse;
property onDragLeave : HTMLElementMouseEventHandler index DRAG_LEAVE write attachMouse;
property onDragRequest : HTMLElementMouseEventHandler index DRAG_REQUEST write attachMouse;
property onMouseDraggingEnter : HTMLElementMouseEventHandler index MOUSE_ENTER or DRAGGING write attachMouse;
property onMouseDraggingLeave : HTMLElementMouseEventHandler index MOUSE_LEAVE or DRAGGING write attachMouse;
property onMouseDraggingMove : HTMLElementMouseEventHandler index MOUSE_MOVE or DRAGGING write attachMouse;
property onMouseDraggingUp : HTMLElementMouseEventHandler index MOUSE_UP or DRAGGING write attachMouse;
property onMouseDraggingDown : HTMLElementMouseEventHandler index MOUSE_DOWN or DRAGGING write attachMouse;
// KEY
property onKey : HTMLElementKeyEventHandler index KEY_ALL write attachKey; // All KEY events
property onKeyDown : HTMLElementKeyEventHandler index KEY_DOWN write attachKey;
property onKeyUp : HTMLElementKeyEventHandler index KEY_UP write attachKey;
property onKeyChar : HTMLElementKeyEventHandler index KEY_CHAR write attachKey;
// FOCUS
property onFocus : HTMLElementFocusEventHandler index FOCUS_ALL write attachFocus; // All KEY events
property onFocusLost : HTMLElementFocusEventHandler index FOCUS_LOST write attachFocus;
property onFocusGot : HTMLElementFocusEventHandler index FOCUS_GOT write attachFocus;
// SCROLL
property onScroll : HTMLElementScrollEventHandler index SCROLL_ALL write attachScroll; // All SCROLL events
property onScrollHome : HTMLElementScrollEventHandler index SCROLL_HOME write attachScroll;
property onScrollEnd : HTMLElementScrollEventHandler index SCROLL_END write attachScroll;
property onScrollStepPlus : HTMLElementScrollEventHandler index SCROLL_STEP_PLUS write attachScroll;
property onScrollStepMinus : HTMLElementScrollEventHandler index SCROLL_STEP_MINUS write attachScroll;
property onScrollPagePlus : HTMLElementScrollEventHandler index SCROLL_PAGE_PLUS write attachScroll;
property onScrollPageMinus : HTMLElementScrollEventHandler index SCROLL_PAGE_MINUS write attachScroll;
property onScrollPos : HTMLElementScrollEventHandler index SCROLL_POS write attachScroll;
property onScrollSliderReleased : HTMLElementScrollEventHandler index SCROLL_SLIDER_RELEASED write attachScroll;
// TIMER
property onTimer : HTMLElementTimerEventHandler write attachTimer;
// SIZE
property onSize : HTMLElementSizeEventHandler write attachSize;
// DRAW
property onDraw : HTMLElementDrawEventHandler index DRAW_ALL write attachDraw; // All DRAW events
property onDrawBackground : HTMLElementDrawEventHandler index DRAW_BACKGROUND write attachDraw;
property onDrawContent : HTMLElementDrawEventHandler index DRAW_CONTENT write attachDraw;
property onDrawForeground : HTMLElementDrawEventHandler index DRAW_FOREGROUND write attachDraw;
// HANDLE_DATA_ARRIVED
property onDataArrived : HTMLElementDataArrivedEventHandler write attachDataArrived;
// EXCHANGE
property onExchange : HTMLElementExchangeEventHandler index EXC_ALL write attachExchange; // All EXCHANGE events
property onExchangeNone : HTMLElementExchangeEventHandler index EXC_NONE write attachExchange;
property onExchangeCopy : HTMLElementExchangeEventHandler index EXC_COPY write attachExchange;
property onExchangeMove : HTMLElementExchangeEventHandler index EXC_MOVE write attachExchange;
property onExchangeLink : HTMLElementExchangeEventHandler index EXC_LINK write attachExchange;
// GESTURE
property onGesture : HTMLElementGestureEventHandler index GESTURE_ALL write attachGesture; // All GESTURE events
property onGestureResuest : HTMLElementGestureEventHandler index GESTURE_REQUEST write attachGesture;
property onGestureZoom : HTMLElementGestureEventHandler index GESTURE_ZOOM write attachGesture;
property onGesturePan : HTMLElementGestureEventHandler index GESTURE_PAN write attachGesture;
property onGestureRotate : HTMLElementGestureEventHandler index GESTURE_ROTATE write attachGesture;
property onGestureTap1 : HTMLElementGestureEventHandler index GESTURE_TAP1 write attachGesture;
property onGestureTap2 : HTMLElementGestureEventHandler index GESTURE_TAP2 write attachGesture;
// BEHAVIOR_EVENT
property onButtonClick : HTMLElementBehaviorEventHandler index BUTTON_CLICK write attachBehavior;
property onButtonPress : HTMLElementBehaviorEventHandler index BUTTON_PRESS write attachBehavior;
property onButtonStateChanged : HTMLElementBehaviorEventHandler index BUTTON_STATE_CHANGED write attachBehavior;
property onEditValueChanging : HTMLElementBehaviorEventHandler index EDIT_VALUE_CHANGING write attachBehavior;
property onEditValueChanged : HTMLElementBehaviorEventHandler index EDIT_VALUE_CHANGED write attachBehavior;
property onSelectSelectionChanged : HTMLElementBehaviorEventHandler index SELECT_SELECTION_CHANGED write attachBehavior;
property onSelectStateChanged : HTMLElementBehaviorEventHandler index SELECT_STATE_CHANGED write attachBehavior;
property onPopupRequest : HTMLElementBehaviorEventHandler index POPUP_REQUEST write attachBehavior;
property onPopupReady : HTMLElementBehaviorEventHandler index POPUP_READY write attachBehavior;
property onPopupDismissed : HTMLElementBehaviorEventHandler index POPUP_DISMISSED write attachBehavior;
property onMenuItemActive : HTMLElementBehaviorEventHandler index MENU_ITEM_ACTIVE write attachBehavior;
property onMenuItemClick : HTMLElementBehaviorEventHandler index MENU_ITEM_CLICK write attachBehavior;
property onContextMenuSetup : HTMLElementBehaviorEventHandler index CONTEXT_MENU_SETUP write attachBehavior;
property onContextMenuRequest : HTMLElementBehaviorEventHandler index CONTEXT_MENU_REQUEST write attachBehavior;
property onVisiualStatusChanged : HTMLElementBehaviorEventHandler index VISIUAL_STATUS_CHANGED write attachBehavior;
property onDisabledStatusChanged : HTMLElementBehaviorEventHandler index DISABLED_STATUS_CHANGED write attachBehavior;
property onPopupDismissing : HTMLElementBehaviorEventHandler index POPUP_DISMISSING write attachBehavior;
// "grey" event codes - notfications from behaviors from this SDK
property onHyperLinkClick : HTMLElementBehaviorEventHandler index HYPERLINK_CLICK write attachBehavior;
property onTableHeaderClick : HTMLElementBehaviorEventHandler index TABLE_HEADER_CLICK write attachBehavior;
property onTableRowClick : HTMLElementBehaviorEventHandler index TABLE_ROW_CLICK write attachBehavior;
property onTableRowDblClick : HTMLElementBehaviorEventHandler index TABLE_ROW_DBL_CLICK write attachBehavior;
property onElementCollapsed : HTMLElementBehaviorEventHandler index ELEMENT_COLLAPSED write attachBehavior;
property onElementExpanded : HTMLElementBehaviorEventHandler index ELEMENT_EXPANDED write attachBehavior;
property onActivateChild : HTMLElementBehaviorEventHandler index ACTIVATE_CHILD write attachBehavior;
property onDoSwitchTab : HTMLElementBehaviorEventHandler index DO_SWITCH_TAB write attachBehavior;
property onInitDataView : HTMLElementBehaviorEventHandler index INIT_DATA_VIEW write attachBehavior;
property onRowsDataRequest : HTMLElementBehaviorEventHandler index ROWS_DATA_REQUEST write attachBehavior;
property onUiStateChanged : HTMLElementBehaviorEventHandler index UI_STATE_CHANGED write attachBehavior;
property onFormSubmit : HTMLElementBehaviorEventHandler index FORM_SUBMIT write attachBehavior;
property onFormReset : HTMLElementBehaviorEventHandler index FORM_RESET write attachBehavior;
property onDocumentComplete : HTMLElementBehaviorEventHandler index DOCUMENT_COMPLETE write attachBehavior;
property onHistoryPush : HTMLElementBehaviorEventHandler index HISTORY_PUSH write attachBehavior;
property onHistoryDrop : HTMLElementBehaviorEventHandler index HISTORY_DROP write attachBehavior;
property onHistoryPrior : HTMLElementBehaviorEventHandler index HISTORY_PRIOR write attachBehavior;
property onHistoryNext : HTMLElementBehaviorEventHandler index HISTORY_NEXT write attachBehavior;
property onHistoryStateChanged : HTMLElementBehaviorEventHandler index HISTORY_STATE_CHANGED write attachBehavior;
property onClosePopup : HTMLElementBehaviorEventHandler index CLOSE_POPUP write attachBehavior;
property onRequestTooltip : HTMLElementBehaviorEventHandler index REQUEST_TOOLTIP write attachBehavior;
property onAnimation : HTMLElementBehaviorEventHandler index ANIMATION write attachBehavior;
end;
{***************************************************************************
* THtmlShim
***************************************************************************}
THtmlShim = class( THtmlHElement )
private
function getRoot() : THtmlShim;
function getParent() : THtmlShim;
function getChild( const aIndex : integer ) : THtmlShim;
function getNextSibling() : THtmlShim;
function getPrevSibling() : THtmlShim;
function getFirstSibling() : THtmlShim;
function getLastSibling() : THtmlShim;
protected
//function createElement( const aHandler : HELEMENT ) : THtmlElement; override;
public
function clone() : THtmlShim;
function get_element_by_id( const aId : string ) : THtmlShim;
function update( const render_now : boolean = false ) : THtmlShim; overload;
function update( const aMode : integer ) : THtmlShim; overload;
function redraw() : THtmlShim;
function next_sibling() : THtmlShim;
function prev_sibling() : THtmlShim;
function first_sibling() : THtmlShim;
function last_sibling() : THtmlShim;
function scroll_to_view( toTopOfView : boolean = false; smooth : boolean = false ) : THtmlShim;
function set_state( const bitsToSet : cardinal; const bitsToClear : cardinal = 0; update : boolean = true ) : THtmlShim;
function insert( const element : THtmlHElement; const index : cardinal ) : THtmlShim;
function append( const element : THtmlHElement ) : THtmlShim;
function detach() : THtmlShim; overload;
class function get( aHandler : HELEMENT ) : THtmlShim; overload;
class function get( aElement : THtmlElement ) : THtmlShim; overload;
class function get( aHwnd : HWND ) : THtmlShim; overload;
class function getId( aHandler : HELEMENT ) : widestring;
public // property
property root : THtmlShim read getRoot;
property child[ const aIndex : integer ] : THtmlShim read getChild;
property parent : THtmlShim read getParent;
property nextSibling : THtmlShim read getNextSibling;
property prevSibling : THtmlShim read getPrevSibling;
property firstSibling : THtmlShim read getFirstSibling;
property lastSibling : THtmlShim read getLastSibling;
end;
implementation
uses HtmlEvents;
//type
// PROnSelectCallback = record
// elemen
// end;
var
GlobalShim : THtmlShim;
{------------------------------ TEventHandlerParams ---------------------------}
{*******************************************************************************
* Create
*******************************************************************************}
constructor TEventHandlerParams.Create( aElement : THtmlElement );
begin
Felement := aElement;
Ftag := nil;
Fsubscription := HANDLE_ALL or DISABLE_INITIALIZATION;
end;
{*******************************************************************************
* Create
*******************************************************************************}
constructor TEventHandlerParams.Create( aElement : THtmlElement; aTag : Pointer );
begin
Create( aElement );
Ftag := aTag;
end;
{*******************************************************************************
* Create
*******************************************************************************}
constructor TEventHandlerParams.Create( aElement : THtmlElement; aTag : Pointer; aSubscription : UINT );
begin
Create( aElement, aTag );
Fsubscription := aSubscription;
end;
{*******************************************************************************
* compare
*******************************************************************************}
function TEventHandlerParams.compare( aTag : Pointer; aSubscription : UINT ) : boolean;
begin
Result := ( Fsubscription = aSubscription ) and ( Ftag = aTag );
end;
{------------------------------ TProcHandlerParams ----------------------------}
{*******************************************************************************
* Create
*******************************************************************************}
constructor TProcHandlerParams.Create( aElement : THtmlElement; aCallback : HTMLElementProcEventHandler; aTag : Pointer = nil; aSubscription : UINT = HANDLE_ALL or DISABLE_INITIALIZATION );
begin
inherited Create( aElement, aTag, aSubscription );
Fcallback := aCallback;
end;
{*******************************************************************************
* compare
*******************************************************************************}
function TProcHandlerParams.compare( aCallback : HTMLElementProcEventHandler; aTag : Pointer; aSubscription : UINT ) : boolean;
begin
Result := inherited compare( aTag, aSubscription )
and ( Addr( Fcallback ) = Addr( aCallback ) );
end;
{*******************************************************************************
* TProcHandlerParams
*******************************************************************************}
function TProcHandlerParams.call( aEventGroup : UINT; aEventParams : Pointer ) : boolean;
begin
Result := Fcallback( Felement, aEventGroup, aEventParams, Ftag );
end;
{---------------------------- TMethodHandlerParams ----------------------------}
{*******************************************************************************
* Create
*******************************************************************************}
constructor TMethodHandlerParams.Create( aElement : THtmlElement; aCallback : TMethod; aTag : Pointer = nil; aSubscription : UINT = HANDLE_ALL or DISABLE_INITIALIZATION );
begin
inherited Create( aElement, aTag, aSubscription );
Fcallback := aCallback;
end;
{*******************************************************************************
* compare
*******************************************************************************}
function TMethodHandlerParams.compare( aCallback : TMethod; aTag : Pointer; aSubscription : UINT ) : boolean;
begin
Result := inherited compare( aTag, aSubscription )
and ( TMethod( Fcallback ).Code = TMethod( aCallback ).Code )
and ( TMethod( Fcallback ).Data = TMethod( aCallback ).Data );
end;
{*******************************************************************************
* call
*******************************************************************************}
function TMethodHandlerParams.call( aEventGroup : UINT; aEventParams : Pointer ) : boolean;
begin
Result := HTMLElementMethodEventHandler( Fcallback )( Felement, aEventGroup, aEventParams, Ftag );
end;
{------------------------------- THtmlCmdEventParams -----------------------------}
{*******************************************************************************
* Create
*******************************************************************************}
constructor THtmlCmdEventParams.Create( aElement : THtmlElement; aCallback : TMethod; aTag : Pointer; aSubscription : UINT = HANDLE_ALL or DISABLE_INITIALIZATION );
begin
inherited Create( aElement, aCallback, aTag, aSubscription );
Fcmd := ALL_CMD;
end;
{*******************************************************************************
* Create
*******************************************************************************}
constructor THtmlCmdEventParams.Create( aElement : THtmlElement; aCmd : UINT; aCallback : TMethod; aTag : Pointer = nil; aSubscription : UINT = HANDLE_ALL or DISABLE_INITIALIZATION );
begin
Create( aElement, aCallback, aTag, aSubscription );
Fcmd := aCmd;
end;