-
Notifications
You must be signed in to change notification settings - Fork 7
/
HtmlCtrl.pas
158 lines (136 loc) · 3.92 KB
/
HtmlCtrl.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
unit HtmlCtrl;
interface
uses
Windows, Messages, SysUtils, Classes, Controls, HtmlConst, HtmlTypes, HtmlDll, HtmlDOM;
type
THtmlControl = class;
THtmlLoadData = function (Sender: THtmlControl; Uri: PWideChar; element: HtmlElement): LRESULT of Object;
THtmlDocumentComplete = procedure (Sender: THtmlControl) of Object;
THtmlControl = class(TWinControl)
private
FOnLoadData: THtmlLoadData;
FOnDocumentComplete: THtmlDocumentComplete;
function HtmlCallback(uMsg: UINT; wParam: WPARAM; lParam: LPARAM): LRESULT;
protected
procedure CreateParams(var Params: TCreateParams); override;
procedure WndProc(var Message: TMessage); override;
public
constructor Create(AOwner: TComponent); override;
procedure LoadHtml(pHtml: PByte; cb: Cardinal); overload;
procedure LoadHtml(filename: widestring); overload;
function GetRootElement(): HtmlElement;
function OnDataReady(uri: PWideChar; data: Pointer; length: Cardinal): Boolean;
published
property Action;
property Align;
property Anchors;
property BiDiMode;
property Caption;
property Constraints;
property DragCursor;
property DragKind;
property DragMode;
property Enabled;
property Font;
property ParentBiDiMode;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ShowHint;
property TabOrder;
property TabStop default True;
property Visible;
property OnClick;
property OnContextPopup;
property OnDragDrop;
property OnDragOver;
property OnEndDock;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnLoadData: THtmlLoadData read FOnLoadData write FOnLoadData;
property OnDocumentComplete: THtmlDocumentComplete read FOnDocumentComplete write FOnDocumentComplete;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
// property OnMouseActivate;
property OnMouseDown;
// property OnMouseEnter;
// property OnMouseLeave;
property OnMouseMove;
property OnMouseUp;
property OnStartDock;
property OnStartDrag;
end;
implementation
{ THtmlControl }
constructor THtmlControl.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
end;
procedure THtmlControl.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
end;
procedure THtmlControl.LoadHtml(pHtml: PByte; cb: Cardinal);
begin
end;
procedure THtmlControl.LoadHtml(filename: widestring);
begin
HTMLayoutLoadFile(Handle, PWideChar(filename));
end;
function AHtmlCallbackProxy(uMsg: UINT; wParam: WPARAM; lParam: LPARAM; vParam: Pointer): LRESULT; stdcall;
begin
if vParam <> nil then
Result := THtmlControl(vParam).HtmlCallback(uMsg, wParam, lParam)
else
Result := 0;
end;
procedure THtmlControl.WndProc(var Message: TMessage);
var
Handled: BOOL;
res: LRESULT;
begin
res := HTMLayoutProcND(Handle, Message.Msg, Message.WParam, Message.LParam, Handled);
if Handled then
begin
Message.Result := res;
Exit;
end;
case Message.Msg of
WM_CREATE:
begin
HTMLayoutSetCallback(Handle, @AHtmlCallbackProxy, Self);
end;
end;
inherited WndProc(Message);
end;
function THtmlControl.HtmlCallback(uMsg: UINT; wParam: WPARAM; lParam: LPARAM): LRESULT;
var
nmhdr: pNMHDR;
begin
nmhdr := pNMHDR(lParam);
case nmhdr^.code of
HLN_LOAD_DATA:
begin
if Assigned(FOnLoadData) then
Result := FOnLoadData(Self, pNMHL_LOAD_DATA(lParam)^.uri, pNMHL_LOAD_DATA(lParam)^.principal)
else
Result := LOAD_OK;
Exit;
end;
HLN_DOCUMENT_COMPLETE:
if Assigned(FOnLoadData) then
FOnDocumentComplete(Self);
end;
Result := 0;
end;
function THtmlControl.GetRootElement: HtmlElement;
begin
Result := HTMLayoutGetRootElement(Handle);
end;
function THtmlControl.OnDataReady(uri: PWideChar; data: Pointer; length: Cardinal): Boolean;
begin
Result := HTMLayoutDataReady(Handle, uri, data, length);
end;
end.