ntoskrnl: Initialize structure size.
[wine] / dlls / mshtml / mshtml_private.h
1 /*
2  * Copyright 2005-2009 Jacek Caban for CodeWeavers
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17  */
18
19 #include "wingdi.h"
20 #include "docobj.h"
21 #include "mshtml.h"
22 #include "mshtmhst.h"
23 #include "hlink.h"
24 #include "perhist.h"
25 #include "dispex.h"
26
27 #include "wine/list.h"
28 #include "wine/unicode.h"
29
30 #ifdef INIT_GUID
31 #include "initguid.h"
32 #endif
33
34 #include "nsiface.h"
35
36 #define NS_OK                     ((nsresult)0x00000000L)
37 #define NS_ERROR_FAILURE          ((nsresult)0x80004005L)
38 #define NS_NOINTERFACE            ((nsresult)0x80004002L)
39 #define NS_ERROR_NOT_IMPLEMENTED  ((nsresult)0x80004001L)
40 #define NS_ERROR_INVALID_ARG      ((nsresult)0x80070057L) 
41 #define NS_ERROR_UNEXPECTED       ((nsresult)0x8000ffffL)
42 #define NS_ERROR_UNKNOWN_PROTOCOL ((nsresult)0x804b0012L)
43
44 #define NS_FAILED(res) ((res) & 0x80000000)
45 #define NS_SUCCEEDED(res) (!NS_FAILED(res))
46
47 #define NSAPI WINAPI
48
49 #define MSHTML_E_NODOC    0x800a025c
50
51 typedef struct HTMLDOMNode HTMLDOMNode;
52 typedef struct ConnectionPoint ConnectionPoint;
53 typedef struct BSCallback BSCallback;
54 typedef struct nsChannelBSC nsChannelBSC;
55 typedef struct event_target_t event_target_t;
56
57 /* NOTE: make sure to keep in sync with dispex.c */
58 typedef enum {
59     NULL_tid,
60     DispCEventObj_tid,
61     DispDOMChildrenCollection_tid,
62     DispHTMLAnchorElement_tid,
63     DispHTMLBody_tid,
64     DispHTMLCommentElement_tid,
65     DispHTMLCurrentStyle_tid,
66     DispHTMLDocument_tid,
67     DispHTMLDOMTextNode_tid,
68     DispHTMLElementCollection_tid,
69     DispHTMLGenericElement_tid,
70     DispHTMLIFrame_tid,
71     DispHTMLImg_tid,
72     DispHTMLInputElement_tid,
73     DispHTMLLocation_tid,
74     DispHTMLNavigator_tid,
75     DispHTMLOptionElement_tid,
76     DispHTMLSelectElement_tid,
77     DispHTMLStyle_tid,
78     DispHTMLTable_tid,
79     DispHTMLTableRow_tid,
80     DispHTMLUnknownElement_tid,
81     DispHTMLWindow2_tid,
82     IHTMLAnchorElement_tid,
83     IHTMLBodyElement_tid,
84     IHTMLBodyElement2_tid,
85     IHTMLCommentElement_tid,
86     IHTMLCurrentStyle_tid,
87     IHTMLCurrentStyle2_tid,
88     IHTMLCurrentStyle3_tid,
89     IHTMLCurrentStyle4_tid,
90     IHTMLDocument2_tid,
91     IHTMLDocument3_tid,
92     IHTMLDocument4_tid,
93     IHTMLDocument5_tid,
94     IHTMLDOMChildrenCollection_tid,
95     IHTMLDOMNode_tid,
96     IHTMLDOMNode2_tid,
97     IHTMLDOMTextNode_tid,
98     IHTMLElement_tid,
99     IHTMLElement2_tid,
100     IHTMLElement3_tid,
101     IHTMLElement4_tid,
102     IHTMLElementCollection_tid,
103     IHTMLEventObj_tid,
104     IHTMLFrameBase_tid,
105     IHTMLFrameBase2_tid,
106     IHTMLGenericElement_tid,
107     IHTMLImgElement_tid,
108     IHTMLInputElement_tid,
109     IHTMLLocation_tid,
110     IHTMLOptionElement_tid,
111     IHTMLSelectElement_tid,
112     IHTMLStyle_tid,
113     IHTMLStyle2_tid,
114     IHTMLStyle3_tid,
115     IHTMLStyle4_tid,
116     IHTMLTable_tid,
117     IHTMLTableRow_tid,
118     IHTMLTextContainer_tid,
119     IHTMLUniqueName_tid,
120     IHTMLWindow2_tid,
121     IHTMLWindow3_tid,
122     IOmNavigator_tid,
123     LAST_tid
124 } tid_t;
125
126 typedef struct dispex_data_t dispex_data_t;
127 typedef struct dispex_dynamic_data_t dispex_dynamic_data_t;
128
129 #define MSHTML_DISPID_CUSTOM_MIN 0x60000000
130 #define MSHTML_DISPID_CUSTOM_MAX 0x6fffffff
131
132 typedef struct {
133     HRESULT (*value)(IUnknown*,LCID,WORD,DISPPARAMS*,VARIANT*,EXCEPINFO*,IServiceProvider*);
134     HRESULT (*get_dispid)(IUnknown*,BSTR,DWORD,DISPID*);
135     HRESULT (*invoke)(IUnknown*,DISPID,LCID,WORD,DISPPARAMS*,VARIANT*,EXCEPINFO*,IServiceProvider*);
136 } dispex_static_data_vtbl_t;
137
138 typedef struct {
139     const dispex_static_data_vtbl_t *vtbl;
140     const tid_t disp_tid;
141     dispex_data_t *data;
142     const tid_t* const iface_tids;
143 } dispex_static_data_t;
144
145 typedef struct {
146     const IDispatchExVtbl  *lpIDispatchExVtbl;
147
148     IUnknown *outer;
149
150     dispex_static_data_t *data;
151     dispex_dynamic_data_t *dynamic_data;
152 } DispatchEx;
153
154 void init_dispex(DispatchEx*,IUnknown*,dispex_static_data_t*);
155 void release_dispex(DispatchEx*);
156 BOOL dispex_query_interface(DispatchEx*,REFIID,void**);
157 HRESULT dispex_get_dprop_ref(DispatchEx*,const WCHAR*,BOOL,VARIANT**);
158
159 typedef struct HTMLWindow HTMLWindow;
160 typedef struct HTMLDocumentNode HTMLDocumentNode;
161 typedef struct HTMLDocumentObj HTMLDocumentObj;
162
163 typedef enum {
164     SCRIPTMODE_GECKO,
165     SCRIPTMODE_ACTIVESCRIPT
166 } SCRIPTMODE;
167
168 typedef struct ScriptHost ScriptHost;
169
170 typedef struct {
171     WCHAR *name;
172     ScriptHost *script_host;
173     DISPID id;
174 } global_prop_t;
175
176 typedef struct {
177     const IHTMLOptionElementFactoryVtbl *lpHTMLOptionElementFactoryVtbl;
178
179     LONG ref;
180
181     HTMLWindow *window;
182 } HTMLOptionElementFactory;
183
184 struct HTMLLocation {
185     DispatchEx dispex;
186     const IHTMLLocationVtbl *lpHTMLLocationVtbl;
187
188     LONG ref;
189
190     HTMLWindow *window;
191 };
192
193 struct HTMLWindow {
194     DispatchEx dispex;
195     const IHTMLWindow2Vtbl *lpHTMLWindow2Vtbl;
196     const IHTMLWindow3Vtbl *lpHTMLWindow3Vtbl;
197     const IDispatchExVtbl  *lpIDispatchExVtbl;
198
199     LONG ref;
200
201     HTMLDocumentNode *doc;
202     HTMLDocumentObj *doc_obj;
203     nsIDOMWindow *nswindow;
204
205     event_target_t *event_target;
206     IHTMLEventObj *event;
207     BOOL *event_vector;
208
209     SCRIPTMODE scriptmode;
210     struct list script_hosts;
211
212     HTMLOptionElementFactory *option_factory;
213     HTMLLocation *location;
214
215     global_prop_t *global_props;
216     DWORD global_prop_cnt;
217     DWORD global_prop_size;
218
219     struct list entry;
220 };
221
222 typedef enum {
223     UNKNOWN_USERMODE,
224     BROWSEMODE,
225     EDITMODE        
226 } USERMODE;
227
228 typedef struct {
229     const IConnectionPointContainerVtbl  *lpConnectionPointContainerVtbl;
230
231     ConnectionPoint *cp_list;
232     IUnknown *outer;
233 } ConnectionPointContainer;
234
235 struct ConnectionPoint {
236     const IConnectionPointVtbl *lpConnectionPointVtbl;
237
238     IConnectionPointContainer *container;
239
240     union {
241         IUnknown *unk;
242         IDispatch *disp;
243         IPropertyNotifySink *propnotif;
244     } *sinks;
245     DWORD sinks_size;
246
247     const IID *iid;
248
249     ConnectionPoint *next;
250 };
251
252 struct HTMLDocument {
253     const IHTMLDocument2Vtbl              *lpHTMLDocument2Vtbl;
254     const IHTMLDocument3Vtbl              *lpHTMLDocument3Vtbl;
255     const IHTMLDocument4Vtbl              *lpHTMLDocument4Vtbl;
256     const IHTMLDocument5Vtbl              *lpHTMLDocument5Vtbl;
257     const IHTMLDocument6Vtbl              *lpHTMLDocument6Vtbl;
258     const IPersistMonikerVtbl             *lpPersistMonikerVtbl;
259     const IPersistFileVtbl                *lpPersistFileVtbl;
260     const IPersistHistoryVtbl             *lpPersistHistoryVtbl;
261     const IMonikerPropVtbl                *lpMonikerPropVtbl;
262     const IOleObjectVtbl                  *lpOleObjectVtbl;
263     const IOleDocumentVtbl                *lpOleDocumentVtbl;
264     const IOleDocumentViewVtbl            *lpOleDocumentViewVtbl;
265     const IOleInPlaceActiveObjectVtbl     *lpOleInPlaceActiveObjectVtbl;
266     const IViewObject2Vtbl                *lpViewObject2Vtbl;
267     const IOleInPlaceObjectWindowlessVtbl *lpOleInPlaceObjectWindowlessVtbl;
268     const IServiceProviderVtbl            *lpServiceProviderVtbl;
269     const IOleCommandTargetVtbl           *lpOleCommandTargetVtbl;
270     const IOleControlVtbl                 *lpOleControlVtbl;
271     const IHlinkTargetVtbl                *lpHlinkTargetVtbl;
272     const IPersistStreamInitVtbl          *lpPersistStreamInitVtbl;
273     const IDispatchExVtbl                 *lpIDispatchExVtbl;
274     const ISupportErrorInfoVtbl           *lpSupportErrorInfoVtbl;
275
276     IUnknown *unk_impl;
277     IDispatchEx *dispex;
278
279     HTMLDocumentObj *doc_obj;
280     HTMLDocumentNode *doc_node;
281
282     HTMLWindow *window;
283     nsIDOMHTMLDocument *nsdoc;
284
285     ConnectionPointContainer cp_container;
286     ConnectionPoint cp_htmldocevents;
287     ConnectionPoint cp_htmldocevents2;
288     ConnectionPoint cp_propnotif;
289 };
290
291 static inline HRESULT htmldoc_query_interface(HTMLDocument *This, REFIID riid, void **ppv)
292 {
293     return IUnknown_QueryInterface(This->unk_impl, riid, ppv);
294 }
295
296 static inline ULONG htmldoc_addref(HTMLDocument *This)
297 {
298     return IUnknown_AddRef(This->unk_impl);
299 }
300
301 static inline ULONG htmldoc_release(HTMLDocument *This)
302 {
303     return IUnknown_Release(This->unk_impl);
304 }
305
306 struct HTMLDocumentObj {
307     HTMLDocument basedoc;
308     DispatchEx dispex;
309     const ICustomDocVtbl  *lpCustomDocVtbl;
310
311     LONG ref;
312
313     NSContainer *nscontainer;
314
315     IOleClientSite *client;
316     IDocHostUIHandler *hostui;
317     IOleInPlaceSite *ipsite;
318     IOleInPlaceFrame *frame;
319     IOleInPlaceUIWindow *ip_window;
320
321     DOCHOSTUIINFO hostinfo;
322
323     IOleUndoManager *undomgr;
324
325     HWND hwnd;
326     HWND tooltips_hwnd;
327
328     BOOL in_place_active;
329     BOOL ui_active;
330     BOOL window_active;
331     BOOL has_key_path;
332     BOOL container_locked;
333     BOOL focus;
334
335     USERMODE usermode;
336     READYSTATE readystate;
337     LPWSTR mime;
338
339     DWORD update;
340
341     /* FIXME: probably should be in document node object */
342     nsChannelBSC *bscallback;
343     IMoniker *mon;
344     LPOLESTR url;
345     struct list bindings;
346 };
347
348 typedef struct {
349     const nsIDOMEventListenerVtbl      *lpDOMEventListenerVtbl;
350     NSContainer *This;
351 } nsEventListener;
352
353 typedef struct _mutation_queue_t {
354     DWORD type;
355     nsISupports *nsiface;
356
357     struct _mutation_queue_t *next;
358 } mutation_queue_t;
359
360 struct NSContainer {
361     const nsIWebBrowserChromeVtbl       *lpWebBrowserChromeVtbl;
362     const nsIContextMenuListenerVtbl    *lpContextMenuListenerVtbl;
363     const nsIURIContentListenerVtbl     *lpURIContentListenerVtbl;
364     const nsIEmbeddingSiteWindowVtbl    *lpEmbeddingSiteWindowVtbl;
365     const nsITooltipListenerVtbl        *lpTooltipListenerVtbl;
366     const nsIInterfaceRequestorVtbl     *lpInterfaceRequestorVtbl;
367     const nsIWeakReferenceVtbl          *lpWeakReferenceVtbl;
368     const nsISupportsWeakReferenceVtbl  *lpSupportsWeakReferenceVtbl;
369
370     const nsIDocumentObserverVtbl       *lpDocumentObserverVtbl;
371
372     const nsIRunnableVtbl  *lpRunnableVtbl;
373
374     nsEventListener blur_listener;
375     nsEventListener focus_listener;
376     nsEventListener keypress_listener;
377     nsEventListener load_listener;
378     nsEventListener htmlevent_listener;
379
380     nsIWebBrowser *webbrowser;
381     nsIWebNavigation *navigation;
382     nsIBaseWindow *window;
383     nsIWebBrowserFocus *focus;
384
385     nsIEditor *editor;
386     nsIController *editor_controller;
387
388     LONG ref;
389
390     NSContainer *parent;
391     HTMLDocumentObj *doc;
392
393     nsIURIContentListener *content_listener;
394
395     HWND hwnd;
396
397     mutation_queue_t *mutation_queue;
398     mutation_queue_t *mutation_queue_tail;
399
400     nsChannelBSC *bscallback; /* hack */
401     HWND reset_focus; /* hack */
402 };
403
404 typedef struct {
405     const nsIHttpChannelVtbl *lpHttpChannelVtbl;
406     const nsIUploadChannelVtbl *lpUploadChannelVtbl;
407     const nsIHttpChannelInternalVtbl *lpIHttpChannelInternalVtbl;
408
409     LONG ref;
410
411     nsIChannel *channel;
412     nsIHttpChannel *http_channel;
413     nsIHttpChannelInternal *http_channel_internal;
414     nsIWineURI *uri;
415     nsIInputStream *post_data_stream;
416     nsILoadGroup *load_group;
417     nsIInterfaceRequestor *notif_callback;
418     nsISupports *owner;
419     nsLoadFlags load_flags;
420     nsIURI *original_uri;
421     char *content_type;
422     char *charset;
423     PRUint32 response_status;
424 } nsChannel;
425
426 typedef struct {
427     HRESULT (*qi)(HTMLDOMNode*,REFIID,void**);
428     void (*destructor)(HTMLDOMNode*);
429     event_target_t **(*get_event_target)(HTMLDOMNode*);
430     HRESULT (*call_event)(HTMLDOMNode*,DWORD,BOOL*);
431     HRESULT (*put_disabled)(HTMLDOMNode*,VARIANT_BOOL);
432     HRESULT (*get_disabled)(HTMLDOMNode*,VARIANT_BOOL*);
433 } NodeImplVtbl;
434
435 struct HTMLDOMNode {
436     DispatchEx dispex;
437     const IHTMLDOMNodeVtbl   *lpHTMLDOMNodeVtbl;
438     const IHTMLDOMNode2Vtbl  *lpHTMLDOMNode2Vtbl;
439     const NodeImplVtbl *vtbl;
440
441     LONG ref;
442
443     nsIDOMNode *nsnode;
444     HTMLDocumentNode *doc;
445     event_target_t *event_target;
446
447     HTMLDOMNode *next;
448 };
449
450 typedef struct {
451     HTMLDOMNode node;
452     ConnectionPointContainer cp_container;
453
454     const IHTMLElementVtbl   *lpHTMLElementVtbl;
455     const IHTMLElement2Vtbl  *lpHTMLElement2Vtbl;
456     const IHTMLElement3Vtbl  *lpHTMLElement3Vtbl;
457
458     nsIDOMHTMLElement *nselem;
459 } HTMLElement;
460
461 typedef struct {
462     HTMLElement element;
463
464     const IHTMLTextContainerVtbl *lpHTMLTextContainerVtbl;
465
466     ConnectionPoint cp;
467 } HTMLTextContainer;
468
469 struct HTMLDocumentNode {
470     HTMLDOMNode node;
471     HTMLDocument basedoc;
472
473     const IInternetHostSecurityManagerVtbl *lpIInternetHostSecurityManagerVtbl;
474
475     LONG ref;
476
477     HTMLDOMNode *nodes;
478     BOOL content_ready;
479
480     IInternetSecurityManager *secmgr;
481
482     struct list selection_list;
483     struct list range_list;
484 };
485
486 #define HTMLWINDOW2(x)   ((IHTMLWindow2*)                 &(x)->lpHTMLWindow2Vtbl)
487 #define HTMLWINDOW3(x)   ((IHTMLWindow3*)                 &(x)->lpHTMLWindow3Vtbl)
488
489 #define HTMLDOC(x)       ((IHTMLDocument2*)               &(x)->lpHTMLDocument2Vtbl)
490 #define HTMLDOC3(x)      ((IHTMLDocument3*)               &(x)->lpHTMLDocument3Vtbl)
491 #define HTMLDOC4(x)      ((IHTMLDocument4*)               &(x)->lpHTMLDocument4Vtbl)
492 #define HTMLDOC5(x)      ((IHTMLDocument5*)               &(x)->lpHTMLDocument5Vtbl)
493 #define HTMLDOC6(x)      ((IHTMLDocument6*)               &(x)->lpHTMLDocument6Vtbl)
494 #define PERSIST(x)       ((IPersist*)                     &(x)->lpPersistFileVtbl)
495 #define PERSISTMON(x)    ((IPersistMoniker*)              &(x)->lpPersistMonikerVtbl)
496 #define PERSISTFILE(x)   ((IPersistFile*)                 &(x)->lpPersistFileVtbl)
497 #define MONPROP(x)       ((IMonikerProp*)                 &(x)->lpMonikerPropVtbl)
498 #define OLEOBJ(x)        ((IOleObject*)                   &(x)->lpOleObjectVtbl)
499 #define OLEDOC(x)        ((IOleDocument*)                 &(x)->lpOleDocumentVtbl)
500 #define DOCVIEW(x)       ((IOleDocumentView*)             &(x)->lpOleDocumentViewVtbl)
501 #define OLEWIN(x)        ((IOleWindow*)                   &(x)->lpOleInPlaceActiveObjectVtbl)
502 #define ACTOBJ(x)        ((IOleInPlaceActiveObject*)      &(x)->lpOleInPlaceActiveObjectVtbl)
503 #define VIEWOBJ(x)       ((IViewObject*)                  &(x)->lpViewObject2Vtbl)
504 #define VIEWOBJ2(x)      ((IViewObject2*)                 &(x)->lpViewObject2Vtbl)
505 #define INPLACEOBJ(x)    ((IOleInPlaceObject*)            &(x)->lpOleInPlaceObjectWindowlessVtbl)
506 #define INPLACEWIN(x)    ((IOleInPlaceObjectWindowless*)  &(x)->lpOleInPlaceObjectWindowlessVtbl)
507 #define SERVPROV(x)      ((IServiceProvider*)             &(x)->lpServiceProviderVtbl)
508 #define CMDTARGET(x)     ((IOleCommandTarget*)            &(x)->lpOleCommandTargetVtbl)
509 #define CONTROL(x)       ((IOleControl*)                  &(x)->lpOleControlVtbl)
510 #define HLNKTARGET(x)    ((IHlinkTarget*)                 &(x)->lpHlinkTargetVtbl)
511 #define CONPTCONT(x)     ((IConnectionPointContainer*)    &(x)->lpConnectionPointContainerVtbl)
512 #define PERSTRINIT(x)    ((IPersistStreamInit*)           &(x)->lpPersistStreamInitVtbl)
513 #define PERSISTHIST(x)   ((IPersistHistory*)              &(x)->lpPersistHistoryVtbl)
514 #define CUSTOMDOC(x)     ((ICustomDoc*)                   &(x)->lpCustomDocVtbl)
515
516 #define NSWBCHROME(x)    ((nsIWebBrowserChrome*)          &(x)->lpWebBrowserChromeVtbl)
517 #define NSCML(x)         ((nsIContextMenuListener*)       &(x)->lpContextMenuListenerVtbl)
518 #define NSURICL(x)       ((nsIURIContentListener*)        &(x)->lpURIContentListenerVtbl)
519 #define NSEMBWNDS(x)     ((nsIEmbeddingSiteWindow*)       &(x)->lpEmbeddingSiteWindowVtbl)
520 #define NSIFACEREQ(x)    ((nsIInterfaceRequestor*)        &(x)->lpInterfaceRequestorVtbl)
521 #define NSTOOLTIP(x)     ((nsITooltipListener*)           &(x)->lpTooltipListenerVtbl)
522 #define NSEVENTLIST(x)   ((nsIDOMEventListener*)          &(x)->lpDOMEventListenerVtbl)
523 #define NSWEAKREF(x)     ((nsIWeakReference*)             &(x)->lpWeakReferenceVtbl)
524 #define NSSUPWEAKREF(x)  ((nsISupportsWeakReference*)     &(x)->lpSupportsWeakReferenceVtbl)
525
526 #define NSDOCOBS(x)      ((nsIDocumentObserver*)          &(x)->lpDocumentObserverVtbl)
527
528 #define NSRUNNABLE(x)    ((nsIRunnable*)  &(x)->lpRunnableVtbl)
529
530 #define NSCHANNEL(x)     ((nsIChannel*)        &(x)->lpHttpChannelVtbl)
531 #define NSHTTPCHANNEL(x) ((nsIHttpChannel*)    &(x)->lpHttpChannelVtbl)
532 #define NSUPCHANNEL(x)   ((nsIUploadChannel*)  &(x)->lpUploadChannelVtbl)
533 #define NSHTTPINTERNAL(x) ((nsIHttpChannelInternal*)  &(x)->lpIHttpChannelInternalVtbl)
534
535 #define HTTPNEG(x)       ((IHttpNegotiate2*)              &(x)->lpHttpNegotiate2Vtbl)
536 #define STATUSCLB(x)     ((IBindStatusCallback*)          &(x)->lpBindStatusCallbackVtbl)
537 #define BINDINFO(x)      ((IInternetBindInfo*)            &(x)->lpInternetBindInfoVtbl);
538
539 #define HTMLELEM(x)      ((IHTMLElement*)                 &(x)->lpHTMLElementVtbl)
540 #define HTMLELEM2(x)     ((IHTMLElement2*)                &(x)->lpHTMLElement2Vtbl)
541 #define HTMLELEM3(x)     ((IHTMLElement3*)                &(x)->lpHTMLElement3Vtbl)
542 #define HTMLDOMNODE(x)   ((IHTMLDOMNode*)                 &(x)->lpHTMLDOMNodeVtbl)
543 #define HTMLDOMNODE2(x)  ((IHTMLDOMNode2*)                &(x)->lpHTMLDOMNode2Vtbl)
544
545 #define HTMLTEXTCONT(x)  ((IHTMLTextContainer*)           &(x)->lpHTMLTextContainerVtbl)
546
547 #define HTMLOPTFACTORY(x)  ((IHTMLOptionElementFactory*)  &(x)->lpHTMLOptionElementFactoryVtbl)
548 #define HTMLLOCATION(x)  ((IHTMLLocation*) &(x)->lpHTMLLocationVtbl)
549
550 #define DISPATCHEX(x)    ((IDispatchEx*) &(x)->lpIDispatchExVtbl)
551
552 #define SUPPERRINFO(x)   ((ISupportErrorInfo*) &(x)->lpSupportErrorInfoVtbl)
553
554 #define HOSTSECMGR(x)    ((IInternetHostSecurityManager*)  &(x)->lpIInternetHostSecurityManagerVtbl)
555
556 #define DEFINE_THIS2(cls,ifc,iface) ((cls*)((BYTE*)(iface)-offsetof(cls,ifc)))
557 #define DEFINE_THIS(cls,ifc,iface) DEFINE_THIS2(cls,lp ## ifc ## Vtbl,iface)
558
559 HRESULT HTMLDocument_Create(IUnknown*,REFIID,void**);
560 HRESULT HTMLLoadOptions_Create(IUnknown*,REFIID,void**);
561 HRESULT create_doc_from_nsdoc(nsIDOMHTMLDocument*,HTMLDocumentObj*,HTMLWindow*,HTMLDocumentNode**);
562
563 HRESULT HTMLWindow_Create(HTMLDocumentObj*,nsIDOMWindow*,HTMLWindow**);
564 void window_set_docnode(HTMLWindow*,HTMLDocumentNode*);
565 HTMLWindow *nswindow_to_window(const nsIDOMWindow*);
566 HTMLOptionElementFactory *HTMLOptionElementFactory_Create(HTMLWindow*);
567 HRESULT HTMLLocation_Create(HTMLWindow*,HTMLLocation**);
568 IOmNavigator *OmNavigator_Create(void);
569
570 void HTMLDocument_HTMLDocument3_Init(HTMLDocument*);
571 void HTMLDocument_HTMLDocument5_Init(HTMLDocument*);
572 void HTMLDocument_Persist_Init(HTMLDocument*);
573 void HTMLDocument_OleCmd_Init(HTMLDocument*);
574 void HTMLDocument_OleObj_Init(HTMLDocument*);
575 void HTMLDocument_View_Init(HTMLDocument*);
576 void HTMLDocument_Window_Init(HTMLDocument*);
577 void HTMLDocument_Service_Init(HTMLDocument*);
578 void HTMLDocument_Hlink_Init(HTMLDocument*);
579
580 void HTMLDocumentNode_SecMgr_Init(HTMLDocumentNode*);
581
582 HRESULT HTMLCurrentStyle_Create(HTMLElement*,IHTMLCurrentStyle**);
583
584 void ConnectionPoint_Init(ConnectionPoint*,ConnectionPointContainer*,REFIID);
585 void ConnectionPointContainer_Init(ConnectionPointContainer*,IUnknown*);
586 void ConnectionPointContainer_Destroy(ConnectionPointContainer*);
587
588 NSContainer *NSContainer_Create(HTMLDocumentObj*,NSContainer*);
589 void NSContainer_Release(NSContainer*);
590
591 void init_mutation(NSContainer*);
592 void set_mutation_observer(NSContainer*,nsIDOMHTMLDocument*);
593 void remove_mutation_observer(NSContainer*,nsIDOMHTMLDocument*);
594
595 void HTMLDocument_LockContainer(HTMLDocumentObj*,BOOL);
596 void show_context_menu(HTMLDocumentObj*,DWORD,POINT*,IDispatch*);
597 void notif_focus(HTMLDocumentObj*);
598
599 void show_tooltip(HTMLDocumentObj*,DWORD,DWORD,LPCWSTR);
600 void hide_tooltip(HTMLDocumentObj*);
601 HRESULT get_client_disp_property(IOleClientSite*,DISPID,VARIANT*);
602
603 HRESULT ProtocolFactory_Create(REFCLSID,REFIID,void**);
604
605 BOOL load_gecko(BOOL);
606 void close_gecko(void);
607 void register_nsservice(nsIComponentRegistrar*,nsIServiceManager*);
608 void init_nsio(nsIComponentManager*,nsIComponentRegistrar*);
609 void release_nsio(void);
610 BOOL install_wine_gecko(BOOL);
611
612 HRESULT nsuri_to_url(LPCWSTR,BOOL,BSTR*);
613
614 HRESULT hlink_frame_navigate(HTMLDocument*,LPCWSTR,nsIInputStream*,DWORD);
615 HRESULT navigate_url(HTMLDocumentNode*,OLECHAR*);
616
617 void call_property_onchanged(ConnectionPoint*,DISPID);
618 HRESULT call_set_active_object(IOleInPlaceUIWindow*,IOleInPlaceActiveObject*);
619
620 void *nsalloc(size_t) __WINE_ALLOC_SIZE(1);
621 void nsfree(void*);
622
623 void nsACString_Init(nsACString*,const char*);
624 void nsACString_SetData(nsACString*,const char*);
625 PRUint32 nsACString_GetData(const nsACString*,const char**);
626 void nsACString_Finish(nsACString*);
627
628 void nsAString_Init(nsAString*,const PRUnichar*);
629 void nsAString_SetData(nsAString*,const PRUnichar*);
630 PRUint32 nsAString_GetData(const nsAString*,const PRUnichar**);
631 void nsAString_Finish(nsAString*);
632
633 nsICommandParams *create_nscommand_params(void);
634 HRESULT nsnode_to_nsstring(nsIDOMNode*,nsAString*);
635 void get_editor_controller(NSContainer*);
636 void init_nsevents(NSContainer*);
637 void add_nsevent_listener(HTMLWindow*,LPCWSTR);
638 nsresult get_nsinterface(nsISupports*,REFIID,void**);
639 void update_nsdocument(HTMLDocumentObj*);
640
641 void set_document_bscallback(HTMLDocument*,nsChannelBSC*);
642 void set_current_mon(HTMLDocument*,IMoniker*);
643 HRESULT start_binding(HTMLDocument*,BSCallback*,IBindCtx*);
644
645 HRESULT bind_mon_to_buffer(HTMLDocument*,IMoniker*,void**,DWORD*);
646
647 nsChannelBSC *create_channelbsc(IMoniker*);
648 HRESULT channelbsc_load_stream(nsChannelBSC*,IStream*);
649 void channelbsc_set_channel(nsChannelBSC*,nsChannel*,nsIStreamListener*,nsISupports*);
650 IMoniker *get_channelbsc_mon(nsChannelBSC*);
651
652 HRESULT HTMLSelectionObject_Create(HTMLDocumentNode*,nsISelection*,IHTMLSelectionObject**);
653 HRESULT HTMLTxtRange_Create(HTMLDocumentNode*,nsIDOMRange*,IHTMLTxtRange**);
654 IHTMLStyle *HTMLStyle_Create(nsIDOMCSSStyleDeclaration*);
655 IHTMLStyleSheet *HTMLStyleSheet_Create(nsIDOMStyleSheet*);
656 IHTMLStyleSheetsCollection *HTMLStyleSheetsCollection_Create(nsIDOMStyleSheetList*);
657
658 void detach_selection(HTMLDocumentNode*);
659 void detach_ranges(HTMLDocumentNode*);
660 HRESULT get_node_text(HTMLDOMNode*,BSTR*);
661
662 HTMLDOMNode *HTMLDOMTextNode_Create(HTMLDocumentNode*,nsIDOMNode*);
663
664 HTMLElement *HTMLElement_Create(HTMLDocumentNode*,nsIDOMNode*,BOOL);
665 HTMLElement *HTMLCommentElement_Create(HTMLDocumentNode*,nsIDOMNode*);
666 HTMLElement *HTMLAnchorElement_Create(nsIDOMHTMLElement*);
667 HTMLElement *HTMLBodyElement_Create(nsIDOMHTMLElement*);
668 HTMLElement *HTMLIFrame_Create(nsIDOMHTMLElement*);
669 HTMLElement *HTMLImgElement_Create(nsIDOMHTMLElement*);
670 HTMLElement *HTMLInputElement_Create(nsIDOMHTMLElement*);
671 HTMLElement *HTMLOptionElement_Create(nsIDOMHTMLElement*);
672 HTMLElement *HTMLScriptElement_Create(nsIDOMHTMLElement*);
673 HTMLElement *HTMLSelectElement_Create(nsIDOMHTMLElement*);
674 HTMLElement *HTMLTable_Create(nsIDOMHTMLElement*);
675 HTMLElement *HTMLTableRow_Create(nsIDOMHTMLElement*);
676 HTMLElement *HTMLTextAreaElement_Create(nsIDOMHTMLElement*);
677 HTMLElement *HTMLGenericElement_Create(nsIDOMHTMLElement*);
678
679 void HTMLDOMNode_Init(HTMLDocumentNode*,HTMLDOMNode*,nsIDOMNode*);
680 void HTMLElement_Init(HTMLElement*,dispex_static_data_t*);
681 void HTMLElement2_Init(HTMLElement*);
682 void HTMLElement3_Init(HTMLElement*);
683 void HTMLTextContainer_Init(HTMLTextContainer*,dispex_static_data_t*);
684
685 HRESULT HTMLDOMNode_QI(HTMLDOMNode*,REFIID,void**);
686 void HTMLDOMNode_destructor(HTMLDOMNode*);
687
688 HRESULT HTMLElement_QI(HTMLDOMNode*,REFIID,void**);
689 void HTMLElement_destructor(HTMLDOMNode*);
690
691 HTMLDOMNode *get_node(HTMLDocumentNode*,nsIDOMNode*,BOOL);
692 void release_nodes(HTMLDocumentNode*);
693
694 void release_script_hosts(HTMLWindow*);
695 void connect_scripts(HTMLWindow*);
696 void doc_insert_script(HTMLWindow*,nsIDOMHTMLScriptElement*);
697 IDispatch *script_parse_event(HTMLWindow*,LPCWSTR);
698 void set_script_mode(HTMLWindow*,SCRIPTMODE);
699 BOOL find_global_prop(HTMLWindow*,BSTR,DWORD,ScriptHost**,DISPID*);
700 IDispatch *get_script_disp(ScriptHost*);
701
702 IHTMLElementCollection *create_all_collection(HTMLDOMNode*,BOOL);
703 IHTMLElementCollection *create_collection_from_nodelist(HTMLDocumentNode*,IUnknown*,nsIDOMNodeList*);
704 IHTMLElementCollection *create_collection_from_htmlcol(HTMLDocumentNode*,IUnknown*,nsIDOMHTMLCollection*);
705
706 /* commands */
707 typedef struct {
708     DWORD id;
709     HRESULT (*query)(HTMLDocument*,OLECMD*);
710     HRESULT (*exec)(HTMLDocument*,DWORD,VARIANT*,VARIANT*);
711 } cmdtable_t;
712
713 extern const cmdtable_t editmode_cmds[];
714
715 void do_ns_command(HTMLDocument*,const char*,nsICommandParams*);
716
717 /* timer */
718 #define UPDATE_UI       0x0001
719 #define UPDATE_TITLE    0x0002
720
721 void update_doc(HTMLDocument*,DWORD);
722 void update_title(HTMLDocumentObj*);
723
724 /* editor */
725 void init_editor(HTMLDocument*);
726 void set_ns_editmode(NSContainer*);
727 void handle_edit_event(HTMLDocument*,nsIDOMEvent*);
728 HRESULT editor_exec_copy(HTMLDocument*,DWORD,VARIANT*,VARIANT*);
729 HRESULT editor_exec_cut(HTMLDocument*,DWORD,VARIANT*,VARIANT*);
730 HRESULT editor_exec_paste(HTMLDocument*,DWORD,VARIANT*,VARIANT*);
731 void handle_edit_load(HTMLDocument*);
732 HRESULT editor_is_dirty(HTMLDocument*);
733 void set_dirty(HTMLDocument*,VARIANT_BOOL);
734
735 extern DWORD mshtml_tls;
736
737 typedef struct task_t {
738     HTMLDocument *doc;
739
740     enum {
741         TASK_SETDOWNLOADSTATE,
742         TASK_PARSECOMPLETE,
743         TASK_SETPROGRESS,
744         TASK_START_BINDING
745     } task_id;
746
747     nsChannelBSC *bscallback;
748
749     struct task_t *next;
750 } task_t;
751
752 typedef struct {
753     HWND thread_hwnd;
754     task_t *task_queue_head;
755     task_t *task_queue_tail;
756     struct list timer_list;
757 } thread_data_t;
758
759 thread_data_t *get_thread_data(BOOL);
760 HWND get_thread_hwnd(void);
761 void push_task(task_t*);
762 void remove_doc_tasks(const HTMLDocument*);
763 DWORD set_task_timer(HTMLDocument*,DWORD,BOOL,IDispatch*);
764 HRESULT clear_task_timer(HTMLDocument*,BOOL,DWORD);
765
766 void release_typelib(void);
767 HRESULT call_disp_func(IDispatch*,DISPPARAMS*);
768
769 const char *debugstr_variant(const VARIANT*);
770
771 DEFINE_GUID(CLSID_AboutProtocol, 0x3050F406, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
772 DEFINE_GUID(CLSID_JSProtocol, 0x3050F3B2, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
773 DEFINE_GUID(CLSID_MailtoProtocol, 0x3050F3DA, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
774 DEFINE_GUID(CLSID_ResProtocol, 0x3050F3BC, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
775 DEFINE_GUID(CLSID_SysimageProtocol, 0x76E67A63, 0x06E9, 0x11D2, 0xA8,0x40, 0x00,0x60,0x08,0x05,0x93,0x82);
776
777 DEFINE_GUID(CLSID_CMarkup,0x3050f4fb,0x98b5,0x11cf,0xbb,0x82,0x00,0xaa,0x00,0xbd,0xce,0x0b);
778
779 /* memory allocation functions */
780
781 static inline void * __WINE_ALLOC_SIZE(1) heap_alloc(size_t len)
782 {
783     return HeapAlloc(GetProcessHeap(), 0, len);
784 }
785
786 static inline void * __WINE_ALLOC_SIZE(1) heap_alloc_zero(size_t len)
787 {
788     return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
789 }
790
791 static inline void * __WINE_ALLOC_SIZE(2) heap_realloc(void *mem, size_t len)
792 {
793     return HeapReAlloc(GetProcessHeap(), 0, mem, len);
794 }
795
796 static inline void * __WINE_ALLOC_SIZE(2) heap_realloc_zero(void *mem, size_t len)
797 {
798     return HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, mem, len);
799 }
800
801 static inline BOOL heap_free(void *mem)
802 {
803     return HeapFree(GetProcessHeap(), 0, mem);
804 }
805
806 static inline LPWSTR heap_strdupW(LPCWSTR str)
807 {
808     LPWSTR ret = NULL;
809
810     if(str) {
811         DWORD size;
812
813         size = (strlenW(str)+1)*sizeof(WCHAR);
814         ret = heap_alloc(size);
815         memcpy(ret, str, size);
816     }
817
818     return ret;
819 }
820
821 static inline char *heap_strdupA(const char *str)
822 {
823     char *ret = NULL;
824
825     if(str) {
826         DWORD size;
827
828         size = strlen(str)+1;
829         ret = heap_alloc(size);
830         memcpy(ret, str, size);
831     }
832
833     return ret;
834 }
835
836 static inline WCHAR *heap_strdupAtoW(const char *str)
837 {
838     LPWSTR ret = NULL;
839
840     if(str) {
841         DWORD len;
842
843         len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
844         ret = heap_alloc(len*sizeof(WCHAR));
845         MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
846     }
847
848     return ret;
849 }
850
851 static inline char *heap_strdupWtoA(LPCWSTR str)
852 {
853     char *ret = NULL;
854
855     if(str) {
856         DWORD size = WideCharToMultiByte(CP_ACP, 0, str, -1, NULL, 0, NULL, NULL);
857         ret = heap_alloc(size);
858         WideCharToMultiByte(CP_ACP, 0, str, -1, ret, size, NULL, NULL);
859     }
860
861     return ret;
862 }
863
864 HINSTANCE get_shdoclc(void);
865
866 extern HINSTANCE hInst;