mshtml: Fix typo in TRACE.
[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     IHTMLImageElementFactory_tid,
108     IHTMLImgElement_tid,
109     IHTMLInputElement_tid,
110     IHTMLLocation_tid,
111     IHTMLOptionElement_tid,
112     IHTMLSelectElement_tid,
113     IHTMLStyle_tid,
114     IHTMLStyle2_tid,
115     IHTMLStyle3_tid,
116     IHTMLStyle4_tid,
117     IHTMLTable_tid,
118     IHTMLTableRow_tid,
119     IHTMLTextContainer_tid,
120     IHTMLUniqueName_tid,
121     IHTMLWindow2_tid,
122     IHTMLWindow3_tid,
123     IOmNavigator_tid,
124     LAST_tid
125 } tid_t;
126
127 typedef struct dispex_data_t dispex_data_t;
128 typedef struct dispex_dynamic_data_t dispex_dynamic_data_t;
129
130 #define MSHTML_DISPID_CUSTOM_MIN 0x60000000
131 #define MSHTML_DISPID_CUSTOM_MAX 0x6fffffff
132
133 typedef struct {
134     HRESULT (*value)(IUnknown*,LCID,WORD,DISPPARAMS*,VARIANT*,EXCEPINFO*,IServiceProvider*);
135     HRESULT (*get_dispid)(IUnknown*,BSTR,DWORD,DISPID*);
136     HRESULT (*invoke)(IUnknown*,DISPID,LCID,WORD,DISPPARAMS*,VARIANT*,EXCEPINFO*,IServiceProvider*);
137 } dispex_static_data_vtbl_t;
138
139 typedef struct {
140     const dispex_static_data_vtbl_t *vtbl;
141     const tid_t disp_tid;
142     dispex_data_t *data;
143     const tid_t* const iface_tids;
144 } dispex_static_data_t;
145
146 typedef struct {
147     const IDispatchExVtbl  *lpIDispatchExVtbl;
148
149     IUnknown *outer;
150
151     dispex_static_data_t *data;
152     dispex_dynamic_data_t *dynamic_data;
153 } DispatchEx;
154
155 void init_dispex(DispatchEx*,IUnknown*,dispex_static_data_t*);
156 void release_dispex(DispatchEx*);
157 BOOL dispex_query_interface(DispatchEx*,REFIID,void**);
158 HRESULT dispex_get_dprop_ref(DispatchEx*,const WCHAR*,BOOL,VARIANT**);
159
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 typedef struct {
185     DispatchEx dispex;
186     const IHTMLImageElementFactoryVtbl *lpHTMLImageElementFactoryVtbl;
187
188     LONG ref;
189
190     HTMLWindow *window;
191 } HTMLImageElementFactory;
192
193 struct HTMLLocation {
194     DispatchEx dispex;
195     const IHTMLLocationVtbl *lpHTMLLocationVtbl;
196
197     LONG ref;
198
199     HTMLWindow *window;
200 };
201
202 typedef struct {
203     HTMLWindow *window;
204     LONG ref;
205 }  windowref_t;
206
207 struct HTMLWindow {
208     DispatchEx dispex;
209     const IHTMLWindow2Vtbl *lpHTMLWindow2Vtbl;
210     const IHTMLWindow3Vtbl *lpHTMLWindow3Vtbl;
211     const IDispatchExVtbl  *lpIDispatchExVtbl;
212
213     LONG ref;
214
215     windowref_t *window_ref;
216     LONG task_magic;
217
218     HTMLDocumentNode *doc;
219     HTMLDocumentObj *doc_obj;
220     nsIDOMWindow *nswindow;
221     HTMLWindow *parent;
222
223     nsChannelBSC *bscallback;
224     IMoniker *mon;
225     LPOLESTR url;
226
227     event_target_t *event_target;
228     IHTMLEventObj *event;
229     BOOL *event_vector;
230
231     SCRIPTMODE scriptmode;
232     struct list script_hosts;
233
234     HTMLOptionElementFactory *option_factory;
235     HTMLImageElementFactory *image_factory;
236     HTMLLocation *location;
237
238     global_prop_t *global_props;
239     DWORD global_prop_cnt;
240     DWORD global_prop_size;
241
242     struct list children;
243     struct list sibling_entry;
244     struct list entry;
245 };
246
247 typedef enum {
248     UNKNOWN_USERMODE,
249     BROWSEMODE,
250     EDITMODE        
251 } USERMODE;
252
253 typedef struct {
254     const IConnectionPointContainerVtbl  *lpConnectionPointContainerVtbl;
255
256     ConnectionPoint *cp_list;
257     IUnknown *outer;
258 } ConnectionPointContainer;
259
260 struct ConnectionPoint {
261     const IConnectionPointVtbl *lpConnectionPointVtbl;
262
263     IConnectionPointContainer *container;
264
265     union {
266         IUnknown *unk;
267         IDispatch *disp;
268         IPropertyNotifySink *propnotif;
269     } *sinks;
270     DWORD sinks_size;
271
272     const IID *iid;
273
274     ConnectionPoint *next;
275 };
276
277 struct HTMLDocument {
278     const IHTMLDocument2Vtbl              *lpHTMLDocument2Vtbl;
279     const IHTMLDocument3Vtbl              *lpHTMLDocument3Vtbl;
280     const IHTMLDocument4Vtbl              *lpHTMLDocument4Vtbl;
281     const IHTMLDocument5Vtbl              *lpHTMLDocument5Vtbl;
282     const IHTMLDocument6Vtbl              *lpHTMLDocument6Vtbl;
283     const IPersistMonikerVtbl             *lpPersistMonikerVtbl;
284     const IPersistFileVtbl                *lpPersistFileVtbl;
285     const IPersistHistoryVtbl             *lpPersistHistoryVtbl;
286     const IMonikerPropVtbl                *lpMonikerPropVtbl;
287     const IOleObjectVtbl                  *lpOleObjectVtbl;
288     const IOleDocumentVtbl                *lpOleDocumentVtbl;
289     const IOleDocumentViewVtbl            *lpOleDocumentViewVtbl;
290     const IOleInPlaceActiveObjectVtbl     *lpOleInPlaceActiveObjectVtbl;
291     const IViewObject2Vtbl                *lpViewObject2Vtbl;
292     const IOleInPlaceObjectWindowlessVtbl *lpOleInPlaceObjectWindowlessVtbl;
293     const IServiceProviderVtbl            *lpServiceProviderVtbl;
294     const IOleCommandTargetVtbl           *lpOleCommandTargetVtbl;
295     const IOleControlVtbl                 *lpOleControlVtbl;
296     const IHlinkTargetVtbl                *lpHlinkTargetVtbl;
297     const IPersistStreamInitVtbl          *lpPersistStreamInitVtbl;
298     const IDispatchExVtbl                 *lpIDispatchExVtbl;
299     const ISupportErrorInfoVtbl           *lpSupportErrorInfoVtbl;
300
301     IUnknown *unk_impl;
302     IDispatchEx *dispex;
303
304     HTMLDocumentObj *doc_obj;
305     HTMLDocumentNode *doc_node;
306
307     HTMLWindow *window;
308
309     LONG task_magic;
310
311     ConnectionPointContainer cp_container;
312     ConnectionPoint cp_htmldocevents;
313     ConnectionPoint cp_htmldocevents2;
314     ConnectionPoint cp_propnotif;
315 };
316
317 static inline HRESULT htmldoc_query_interface(HTMLDocument *This, REFIID riid, void **ppv)
318 {
319     return IUnknown_QueryInterface(This->unk_impl, riid, ppv);
320 }
321
322 static inline ULONG htmldoc_addref(HTMLDocument *This)
323 {
324     return IUnknown_AddRef(This->unk_impl);
325 }
326
327 static inline ULONG htmldoc_release(HTMLDocument *This)
328 {
329     return IUnknown_Release(This->unk_impl);
330 }
331
332 struct HTMLDocumentObj {
333     HTMLDocument basedoc;
334     DispatchEx dispex;
335     const ICustomDocVtbl  *lpCustomDocVtbl;
336
337     LONG ref;
338
339     NSContainer *nscontainer;
340
341     IOleClientSite *client;
342     IDocHostUIHandler *hostui;
343     IOleInPlaceSite *ipsite;
344     IOleInPlaceFrame *frame;
345     IOleInPlaceUIWindow *ip_window;
346
347     DOCHOSTUIINFO hostinfo;
348
349     IOleUndoManager *undomgr;
350
351     HWND hwnd;
352     HWND tooltips_hwnd;
353
354     BOOL in_place_active;
355     BOOL ui_active;
356     BOOL window_active;
357     BOOL has_key_path;
358     BOOL container_locked;
359     BOOL focus;
360
361     USERMODE usermode;
362     READYSTATE readystate;
363     LPWSTR mime;
364
365     DWORD update;
366 };
367
368 typedef struct {
369     const nsIDOMEventListenerVtbl      *lpDOMEventListenerVtbl;
370     NSContainer *This;
371 } nsEventListener;
372
373 struct NSContainer {
374     const nsIWebBrowserChromeVtbl       *lpWebBrowserChromeVtbl;
375     const nsIContextMenuListenerVtbl    *lpContextMenuListenerVtbl;
376     const nsIURIContentListenerVtbl     *lpURIContentListenerVtbl;
377     const nsIEmbeddingSiteWindowVtbl    *lpEmbeddingSiteWindowVtbl;
378     const nsITooltipListenerVtbl        *lpTooltipListenerVtbl;
379     const nsIInterfaceRequestorVtbl     *lpInterfaceRequestorVtbl;
380     const nsIWeakReferenceVtbl          *lpWeakReferenceVtbl;
381     const nsISupportsWeakReferenceVtbl  *lpSupportsWeakReferenceVtbl;
382
383     nsEventListener blur_listener;
384     nsEventListener focus_listener;
385     nsEventListener keypress_listener;
386     nsEventListener load_listener;
387     nsEventListener htmlevent_listener;
388
389     nsIWebBrowser *webbrowser;
390     nsIWebNavigation *navigation;
391     nsIBaseWindow *window;
392     nsIWebBrowserFocus *focus;
393
394     nsIEditor *editor;
395     nsIController *editor_controller;
396
397     LONG ref;
398
399     NSContainer *parent;
400     HTMLDocumentObj *doc;
401
402     nsIURIContentListener *content_listener;
403
404     HWND hwnd;
405
406     nsChannelBSC *bscallback; /* hack */
407     HWND reset_focus; /* hack */
408 };
409
410 typedef struct {
411     const nsIHttpChannelVtbl *lpHttpChannelVtbl;
412     const nsIUploadChannelVtbl *lpUploadChannelVtbl;
413     const nsIHttpChannelInternalVtbl *lpIHttpChannelInternalVtbl;
414
415     LONG ref;
416
417     nsIChannel *channel;
418     nsIHttpChannel *http_channel;
419     nsIHttpChannelInternal *http_channel_internal;
420     nsIWineURI *uri;
421     nsIInputStream *post_data_stream;
422     nsILoadGroup *load_group;
423     nsIInterfaceRequestor *notif_callback;
424     nsISupports *owner;
425     nsLoadFlags load_flags;
426     nsIURI *original_uri;
427     char *content_type;
428     char *charset;
429     PRUint32 response_status;
430 } nsChannel;
431
432 typedef struct {
433     HRESULT (*qi)(HTMLDOMNode*,REFIID,void**);
434     void (*destructor)(HTMLDOMNode*);
435     event_target_t **(*get_event_target)(HTMLDOMNode*);
436     HRESULT (*call_event)(HTMLDOMNode*,DWORD,BOOL*);
437     HRESULT (*put_disabled)(HTMLDOMNode*,VARIANT_BOOL);
438     HRESULT (*get_disabled)(HTMLDOMNode*,VARIANT_BOOL*);
439 } NodeImplVtbl;
440
441 struct HTMLDOMNode {
442     DispatchEx dispex;
443     const IHTMLDOMNodeVtbl   *lpHTMLDOMNodeVtbl;
444     const IHTMLDOMNode2Vtbl  *lpHTMLDOMNode2Vtbl;
445     const NodeImplVtbl *vtbl;
446
447     LONG ref;
448
449     nsIDOMNode *nsnode;
450     HTMLDocumentNode *doc;
451     event_target_t *event_target;
452
453     HTMLDOMNode *next;
454 };
455
456 typedef struct {
457     HTMLDOMNode node;
458     ConnectionPointContainer cp_container;
459
460     const IHTMLElementVtbl   *lpHTMLElementVtbl;
461     const IHTMLElement2Vtbl  *lpHTMLElement2Vtbl;
462     const IHTMLElement3Vtbl  *lpHTMLElement3Vtbl;
463
464     nsIDOMHTMLElement *nselem;
465 } HTMLElement;
466
467 typedef struct {
468     HTMLElement element;
469
470     const IHTMLTextContainerVtbl *lpHTMLTextContainerVtbl;
471
472     ConnectionPoint cp;
473 } HTMLTextContainer;
474
475 typedef struct _mutation_queue_t {
476     DWORD type;
477     nsISupports *nsiface;
478
479     struct _mutation_queue_t *next;
480 } mutation_queue_t;
481
482 struct HTMLDocumentNode {
483     HTMLDOMNode node;
484     HTMLDocument basedoc;
485
486     const IInternetHostSecurityManagerVtbl *lpIInternetHostSecurityManagerVtbl;
487
488     const nsIDocumentObserverVtbl  *lpIDocumentObserverVtbl;
489     const nsIRunnableVtbl  *lpIRunnableVtbl;
490
491     LONG ref;
492
493     nsIDOMHTMLDocument *nsdoc;
494     HTMLDOMNode *nodes;
495     BOOL content_ready;
496
497     IInternetSecurityManager *secmgr;
498
499     mutation_queue_t *mutation_queue;
500     mutation_queue_t *mutation_queue_tail;
501
502     struct list bindings;
503     struct list selection_list;
504     struct list range_list;
505 };
506
507 #define HTMLWINDOW2(x)   ((IHTMLWindow2*)                 &(x)->lpHTMLWindow2Vtbl)
508 #define HTMLWINDOW3(x)   ((IHTMLWindow3*)                 &(x)->lpHTMLWindow3Vtbl)
509
510 #define HTMLDOC(x)       ((IHTMLDocument2*)               &(x)->lpHTMLDocument2Vtbl)
511 #define HTMLDOC3(x)      ((IHTMLDocument3*)               &(x)->lpHTMLDocument3Vtbl)
512 #define HTMLDOC4(x)      ((IHTMLDocument4*)               &(x)->lpHTMLDocument4Vtbl)
513 #define HTMLDOC5(x)      ((IHTMLDocument5*)               &(x)->lpHTMLDocument5Vtbl)
514 #define HTMLDOC6(x)      ((IHTMLDocument6*)               &(x)->lpHTMLDocument6Vtbl)
515 #define PERSIST(x)       ((IPersist*)                     &(x)->lpPersistFileVtbl)
516 #define PERSISTMON(x)    ((IPersistMoniker*)              &(x)->lpPersistMonikerVtbl)
517 #define PERSISTFILE(x)   ((IPersistFile*)                 &(x)->lpPersistFileVtbl)
518 #define MONPROP(x)       ((IMonikerProp*)                 &(x)->lpMonikerPropVtbl)
519 #define OLEOBJ(x)        ((IOleObject*)                   &(x)->lpOleObjectVtbl)
520 #define OLEDOC(x)        ((IOleDocument*)                 &(x)->lpOleDocumentVtbl)
521 #define DOCVIEW(x)       ((IOleDocumentView*)             &(x)->lpOleDocumentViewVtbl)
522 #define OLEWIN(x)        ((IOleWindow*)                   &(x)->lpOleInPlaceActiveObjectVtbl)
523 #define ACTOBJ(x)        ((IOleInPlaceActiveObject*)      &(x)->lpOleInPlaceActiveObjectVtbl)
524 #define VIEWOBJ(x)       ((IViewObject*)                  &(x)->lpViewObject2Vtbl)
525 #define VIEWOBJ2(x)      ((IViewObject2*)                 &(x)->lpViewObject2Vtbl)
526 #define INPLACEOBJ(x)    ((IOleInPlaceObject*)            &(x)->lpOleInPlaceObjectWindowlessVtbl)
527 #define INPLACEWIN(x)    ((IOleInPlaceObjectWindowless*)  &(x)->lpOleInPlaceObjectWindowlessVtbl)
528 #define SERVPROV(x)      ((IServiceProvider*)             &(x)->lpServiceProviderVtbl)
529 #define CMDTARGET(x)     ((IOleCommandTarget*)            &(x)->lpOleCommandTargetVtbl)
530 #define CONTROL(x)       ((IOleControl*)                  &(x)->lpOleControlVtbl)
531 #define HLNKTARGET(x)    ((IHlinkTarget*)                 &(x)->lpHlinkTargetVtbl)
532 #define CONPTCONT(x)     ((IConnectionPointContainer*)    &(x)->lpConnectionPointContainerVtbl)
533 #define PERSTRINIT(x)    ((IPersistStreamInit*)           &(x)->lpPersistStreamInitVtbl)
534 #define PERSISTHIST(x)   ((IPersistHistory*)              &(x)->lpPersistHistoryVtbl)
535 #define CUSTOMDOC(x)     ((ICustomDoc*)                   &(x)->lpCustomDocVtbl)
536
537 #define NSWBCHROME(x)    ((nsIWebBrowserChrome*)          &(x)->lpWebBrowserChromeVtbl)
538 #define NSCML(x)         ((nsIContextMenuListener*)       &(x)->lpContextMenuListenerVtbl)
539 #define NSURICL(x)       ((nsIURIContentListener*)        &(x)->lpURIContentListenerVtbl)
540 #define NSEMBWNDS(x)     ((nsIEmbeddingSiteWindow*)       &(x)->lpEmbeddingSiteWindowVtbl)
541 #define NSIFACEREQ(x)    ((nsIInterfaceRequestor*)        &(x)->lpInterfaceRequestorVtbl)
542 #define NSTOOLTIP(x)     ((nsITooltipListener*)           &(x)->lpTooltipListenerVtbl)
543 #define NSEVENTLIST(x)   ((nsIDOMEventListener*)          &(x)->lpDOMEventListenerVtbl)
544 #define NSWEAKREF(x)     ((nsIWeakReference*)             &(x)->lpWeakReferenceVtbl)
545 #define NSSUPWEAKREF(x)  ((nsISupportsWeakReference*)     &(x)->lpSupportsWeakReferenceVtbl)
546
547 #define NSDOCOBS(x)      ((nsIDocumentObserver*)          &(x)->lpIDocumentObserverVtbl)
548
549 #define NSRUNNABLE(x)    ((nsIRunnable*)  &(x)->lpIRunnableVtbl)
550
551 #define NSCHANNEL(x)     ((nsIChannel*)        &(x)->lpHttpChannelVtbl)
552 #define NSHTTPCHANNEL(x) ((nsIHttpChannel*)    &(x)->lpHttpChannelVtbl)
553 #define NSUPCHANNEL(x)   ((nsIUploadChannel*)  &(x)->lpUploadChannelVtbl)
554 #define NSHTTPINTERNAL(x) ((nsIHttpChannelInternal*)  &(x)->lpIHttpChannelInternalVtbl)
555
556 #define HTTPNEG(x)       ((IHttpNegotiate2*)              &(x)->lpHttpNegotiate2Vtbl)
557 #define STATUSCLB(x)     ((IBindStatusCallback*)          &(x)->lpBindStatusCallbackVtbl)
558 #define BINDINFO(x)      ((IInternetBindInfo*)            &(x)->lpInternetBindInfoVtbl);
559
560 #define HTMLELEM(x)      ((IHTMLElement*)                 &(x)->lpHTMLElementVtbl)
561 #define HTMLELEM2(x)     ((IHTMLElement2*)                &(x)->lpHTMLElement2Vtbl)
562 #define HTMLELEM3(x)     ((IHTMLElement3*)                &(x)->lpHTMLElement3Vtbl)
563 #define HTMLDOMNODE(x)   ((IHTMLDOMNode*)                 &(x)->lpHTMLDOMNodeVtbl)
564 #define HTMLDOMNODE2(x)  ((IHTMLDOMNode2*)                &(x)->lpHTMLDOMNode2Vtbl)
565
566 #define HTMLTEXTCONT(x)  ((IHTMLTextContainer*)           &(x)->lpHTMLTextContainerVtbl)
567
568 #define HTMLOPTFACTORY(x)  ((IHTMLOptionElementFactory*)  &(x)->lpHTMLOptionElementFactoryVtbl)
569 #define HTMLIMGFACTORY(x)  ((IHTMLImageElementFactory*)  &(x)->lpHTMLImageElementFactoryVtbl)
570 #define HTMLLOCATION(x)  ((IHTMLLocation*) &(x)->lpHTMLLocationVtbl)
571
572 #define DISPATCHEX(x)    ((IDispatchEx*) &(x)->lpIDispatchExVtbl)
573
574 #define SUPPERRINFO(x)   ((ISupportErrorInfo*) &(x)->lpSupportErrorInfoVtbl)
575
576 #define HOSTSECMGR(x)    ((IInternetHostSecurityManager*)  &(x)->lpIInternetHostSecurityManagerVtbl)
577
578 #define DEFINE_THIS2(cls,ifc,iface) ((cls*)((BYTE*)(iface)-offsetof(cls,ifc)))
579 #define DEFINE_THIS(cls,ifc,iface) DEFINE_THIS2(cls,lp ## ifc ## Vtbl,iface)
580
581 HRESULT HTMLDocument_Create(IUnknown*,REFIID,void**);
582 HRESULT HTMLLoadOptions_Create(IUnknown*,REFIID,void**);
583 HRESULT create_doc_from_nsdoc(nsIDOMHTMLDocument*,HTMLDocumentObj*,HTMLWindow*,HTMLDocumentNode**);
584
585 HRESULT HTMLWindow_Create(HTMLDocumentObj*,nsIDOMWindow*,HTMLWindow*,HTMLWindow**);
586 void update_window_doc(HTMLWindow*);
587 HTMLWindow *nswindow_to_window(const nsIDOMWindow*);
588 nsIDOMWindow *get_nsdoc_window(nsIDOMDocument*);
589 HTMLOptionElementFactory *HTMLOptionElementFactory_Create(HTMLWindow*);
590 HTMLImageElementFactory *HTMLImageElementFactory_Create(HTMLWindow*);
591 HRESULT HTMLLocation_Create(HTMLWindow*,HTMLLocation**);
592 IOmNavigator *OmNavigator_Create(void);
593
594 void HTMLDocument_HTMLDocument3_Init(HTMLDocument*);
595 void HTMLDocument_HTMLDocument5_Init(HTMLDocument*);
596 void HTMLDocument_Persist_Init(HTMLDocument*);
597 void HTMLDocument_OleCmd_Init(HTMLDocument*);
598 void HTMLDocument_OleObj_Init(HTMLDocument*);
599 void HTMLDocument_View_Init(HTMLDocument*);
600 void HTMLDocument_Window_Init(HTMLDocument*);
601 void HTMLDocument_Service_Init(HTMLDocument*);
602 void HTMLDocument_Hlink_Init(HTMLDocument*);
603
604 void HTMLDocumentNode_SecMgr_Init(HTMLDocumentNode*);
605
606 HRESULT HTMLCurrentStyle_Create(HTMLElement*,IHTMLCurrentStyle**);
607
608 void ConnectionPoint_Init(ConnectionPoint*,ConnectionPointContainer*,REFIID);
609 void ConnectionPointContainer_Init(ConnectionPointContainer*,IUnknown*);
610 void ConnectionPointContainer_Destroy(ConnectionPointContainer*);
611
612 NSContainer *NSContainer_Create(HTMLDocumentObj*,NSContainer*);
613 void NSContainer_Release(NSContainer*);
614
615 void init_mutation(HTMLDocumentNode*);
616 void release_mutation(HTMLDocumentNode*);
617
618 void HTMLDocument_LockContainer(HTMLDocumentObj*,BOOL);
619 void show_context_menu(HTMLDocumentObj*,DWORD,POINT*,IDispatch*);
620 void notif_focus(HTMLDocumentObj*);
621
622 void show_tooltip(HTMLDocumentObj*,DWORD,DWORD,LPCWSTR);
623 void hide_tooltip(HTMLDocumentObj*);
624 HRESULT get_client_disp_property(IOleClientSite*,DISPID,VARIANT*);
625
626 HRESULT ProtocolFactory_Create(REFCLSID,REFIID,void**);
627
628 BOOL load_gecko(BOOL);
629 void close_gecko(void);
630 void register_nsservice(nsIComponentRegistrar*,nsIServiceManager*);
631 void init_nsio(nsIComponentManager*,nsIComponentRegistrar*);
632 void release_nsio(void);
633 BOOL install_wine_gecko(BOOL);
634
635 HRESULT nsuri_to_url(LPCWSTR,BOOL,BSTR*);
636
637 HRESULT hlink_frame_navigate(HTMLDocument*,LPCWSTR,nsIInputStream*,DWORD);
638 HRESULT navigate_url(HTMLDocumentNode*,OLECHAR*);
639
640 void call_property_onchanged(ConnectionPoint*,DISPID);
641 HRESULT call_set_active_object(IOleInPlaceUIWindow*,IOleInPlaceActiveObject*);
642
643 void *nsalloc(size_t) __WINE_ALLOC_SIZE(1);
644 void nsfree(void*);
645
646 void nsACString_Init(nsACString*,const char*);
647 void nsACString_SetData(nsACString*,const char*);
648 PRUint32 nsACString_GetData(const nsACString*,const char**);
649 void nsACString_Finish(nsACString*);
650
651 void nsAString_Init(nsAString*,const PRUnichar*);
652 void nsAString_SetData(nsAString*,const PRUnichar*);
653 PRUint32 nsAString_GetData(const nsAString*,const PRUnichar**);
654 void nsAString_Finish(nsAString*);
655
656 nsICommandParams *create_nscommand_params(void);
657 HRESULT nsnode_to_nsstring(nsIDOMNode*,nsAString*);
658 void get_editor_controller(NSContainer*);
659 void init_nsevents(NSContainer*);
660 void add_nsevent_listener(HTMLWindow*,LPCWSTR);
661 nsresult get_nsinterface(nsISupports*,REFIID,void**);
662
663 void set_window_bscallback(HTMLWindow*,nsChannelBSC*);
664 void set_current_mon(HTMLWindow*,IMoniker*);
665 HRESULT start_binding(HTMLWindow*,HTMLDocumentNode*,BSCallback*,IBindCtx*);
666 void abort_document_bindings(HTMLDocumentNode*);
667
668 HRESULT bind_mon_to_buffer(HTMLDocumentNode*,IMoniker*,void**,DWORD*);
669
670 nsChannelBSC *create_channelbsc(IMoniker*);
671 HRESULT channelbsc_load_stream(nsChannelBSC*,IStream*);
672 void channelbsc_set_channel(nsChannelBSC*,nsChannel*,nsIStreamListener*,nsISupports*);
673 IMoniker *get_channelbsc_mon(nsChannelBSC*);
674
675 void parse_complete(HTMLDocumentObj*);
676
677 HRESULT HTMLSelectionObject_Create(HTMLDocumentNode*,nsISelection*,IHTMLSelectionObject**);
678 HRESULT HTMLTxtRange_Create(HTMLDocumentNode*,nsIDOMRange*,IHTMLTxtRange**);
679 IHTMLStyle *HTMLStyle_Create(nsIDOMCSSStyleDeclaration*);
680 IHTMLStyleSheet *HTMLStyleSheet_Create(nsIDOMStyleSheet*);
681 IHTMLStyleSheetsCollection *HTMLStyleSheetsCollection_Create(nsIDOMStyleSheetList*);
682
683 void detach_selection(HTMLDocumentNode*);
684 void detach_ranges(HTMLDocumentNode*);
685 HRESULT get_node_text(HTMLDOMNode*,BSTR*);
686
687 HRESULT create_nselem(HTMLDocumentNode*,const WCHAR*,nsIDOMHTMLElement**);
688
689 HTMLDOMNode *HTMLDOMTextNode_Create(HTMLDocumentNode*,nsIDOMNode*);
690
691 HTMLElement *HTMLElement_Create(HTMLDocumentNode*,nsIDOMNode*,BOOL);
692 HTMLElement *HTMLCommentElement_Create(HTMLDocumentNode*,nsIDOMNode*);
693 HTMLElement *HTMLAnchorElement_Create(nsIDOMHTMLElement*);
694 HTMLElement *HTMLBodyElement_Create(nsIDOMHTMLElement*);
695 HTMLElement *HTMLIFrame_Create(nsIDOMHTMLElement*);
696 HTMLElement *HTMLImgElement_Create(nsIDOMHTMLElement*);
697 HTMLElement *HTMLInputElement_Create(nsIDOMHTMLElement*);
698 HTMLElement *HTMLOptionElement_Create(nsIDOMHTMLElement*);
699 HTMLElement *HTMLScriptElement_Create(nsIDOMHTMLElement*);
700 HTMLElement *HTMLSelectElement_Create(nsIDOMHTMLElement*);
701 HTMLElement *HTMLTable_Create(nsIDOMHTMLElement*);
702 HTMLElement *HTMLTableRow_Create(nsIDOMHTMLElement*);
703 HTMLElement *HTMLTextAreaElement_Create(nsIDOMHTMLElement*);
704 HTMLElement *HTMLGenericElement_Create(nsIDOMHTMLElement*);
705
706 void HTMLDOMNode_Init(HTMLDocumentNode*,HTMLDOMNode*,nsIDOMNode*);
707 void HTMLElement_Init(HTMLElement*,dispex_static_data_t*);
708 void HTMLElement2_Init(HTMLElement*);
709 void HTMLElement3_Init(HTMLElement*);
710 void HTMLTextContainer_Init(HTMLTextContainer*,dispex_static_data_t*);
711
712 HRESULT HTMLDOMNode_QI(HTMLDOMNode*,REFIID,void**);
713 void HTMLDOMNode_destructor(HTMLDOMNode*);
714
715 HRESULT HTMLElement_QI(HTMLDOMNode*,REFIID,void**);
716 void HTMLElement_destructor(HTMLDOMNode*);
717
718 HTMLDOMNode *get_node(HTMLDocumentNode*,nsIDOMNode*,BOOL);
719 void release_nodes(HTMLDocumentNode*);
720
721 void release_script_hosts(HTMLWindow*);
722 void connect_scripts(HTMLWindow*);
723 void doc_insert_script(HTMLWindow*,nsIDOMHTMLScriptElement*);
724 IDispatch *script_parse_event(HTMLWindow*,LPCWSTR);
725 void set_script_mode(HTMLWindow*,SCRIPTMODE);
726 BOOL find_global_prop(HTMLWindow*,BSTR,DWORD,ScriptHost**,DISPID*);
727 IDispatch *get_script_disp(ScriptHost*);
728
729 IHTMLElementCollection *create_all_collection(HTMLDOMNode*,BOOL);
730 IHTMLElementCollection *create_collection_from_nodelist(HTMLDocumentNode*,IUnknown*,nsIDOMNodeList*);
731 IHTMLElementCollection *create_collection_from_htmlcol(HTMLDocumentNode*,IUnknown*,nsIDOMHTMLCollection*);
732
733 /* commands */
734 typedef struct {
735     DWORD id;
736     HRESULT (*query)(HTMLDocument*,OLECMD*);
737     HRESULT (*exec)(HTMLDocument*,DWORD,VARIANT*,VARIANT*);
738 } cmdtable_t;
739
740 extern const cmdtable_t editmode_cmds[];
741
742 void do_ns_command(HTMLDocument*,const char*,nsICommandParams*);
743
744 /* timer */
745 #define UPDATE_UI       0x0001
746 #define UPDATE_TITLE    0x0002
747
748 void update_doc(HTMLDocument*,DWORD);
749 void update_title(HTMLDocumentObj*);
750
751 /* editor */
752 void init_editor(HTMLDocument*);
753 void set_ns_editmode(NSContainer*);
754 void handle_edit_event(HTMLDocument*,nsIDOMEvent*);
755 HRESULT editor_exec_copy(HTMLDocument*,DWORD,VARIANT*,VARIANT*);
756 HRESULT editor_exec_cut(HTMLDocument*,DWORD,VARIANT*,VARIANT*);
757 HRESULT editor_exec_paste(HTMLDocument*,DWORD,VARIANT*,VARIANT*);
758 void handle_edit_load(HTMLDocument*);
759 HRESULT editor_is_dirty(HTMLDocument*);
760 void set_dirty(HTMLDocument*,VARIANT_BOOL);
761
762 extern DWORD mshtml_tls;
763
764 typedef struct task_t task_t;
765 typedef void (*task_proc_t)(task_t*);
766
767 struct task_t {
768     LONG target_magic;
769     task_proc_t proc;
770     struct task_t *next;
771 };
772
773 typedef struct {
774     task_t header;
775     HTMLDocumentObj *doc;
776 } docobj_task_t;
777
778 typedef struct {
779     HWND thread_hwnd;
780     task_t *task_queue_head;
781     task_t *task_queue_tail;
782     struct list timer_list;
783 } thread_data_t;
784
785 thread_data_t *get_thread_data(BOOL);
786 HWND get_thread_hwnd(void);
787
788 LONG get_task_target_magic(void);
789 void push_task(task_t*,task_proc_t,LONG);
790 void remove_target_tasks(LONG);
791
792 DWORD set_task_timer(HTMLDocument*,DWORD,BOOL,IDispatch*);
793 HRESULT clear_task_timer(HTMLDocument*,BOOL,DWORD);
794
795 void release_typelib(void);
796 HRESULT call_disp_func(IDispatch*,DISPPARAMS*);
797
798 const char *debugstr_variant(const VARIANT*);
799
800 DEFINE_GUID(CLSID_AboutProtocol, 0x3050F406, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
801 DEFINE_GUID(CLSID_JSProtocol, 0x3050F3B2, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
802 DEFINE_GUID(CLSID_MailtoProtocol, 0x3050F3DA, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
803 DEFINE_GUID(CLSID_ResProtocol, 0x3050F3BC, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
804 DEFINE_GUID(CLSID_SysimageProtocol, 0x76E67A63, 0x06E9, 0x11D2, 0xA8,0x40, 0x00,0x60,0x08,0x05,0x93,0x82);
805
806 DEFINE_GUID(CLSID_CMarkup,0x3050f4fb,0x98b5,0x11cf,0xbb,0x82,0x00,0xaa,0x00,0xbd,0xce,0x0b);
807
808 /* memory allocation functions */
809
810 static inline void * __WINE_ALLOC_SIZE(1) heap_alloc(size_t len)
811 {
812     return HeapAlloc(GetProcessHeap(), 0, len);
813 }
814
815 static inline void * __WINE_ALLOC_SIZE(1) heap_alloc_zero(size_t len)
816 {
817     return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
818 }
819
820 static inline void * __WINE_ALLOC_SIZE(2) heap_realloc(void *mem, size_t len)
821 {
822     return HeapReAlloc(GetProcessHeap(), 0, mem, len);
823 }
824
825 static inline void * __WINE_ALLOC_SIZE(2) heap_realloc_zero(void *mem, size_t len)
826 {
827     return HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, mem, len);
828 }
829
830 static inline BOOL heap_free(void *mem)
831 {
832     return HeapFree(GetProcessHeap(), 0, mem);
833 }
834
835 static inline LPWSTR heap_strdupW(LPCWSTR str)
836 {
837     LPWSTR ret = NULL;
838
839     if(str) {
840         DWORD size;
841
842         size = (strlenW(str)+1)*sizeof(WCHAR);
843         ret = heap_alloc(size);
844         memcpy(ret, str, size);
845     }
846
847     return ret;
848 }
849
850 static inline char *heap_strdupA(const char *str)
851 {
852     char *ret = NULL;
853
854     if(str) {
855         DWORD size;
856
857         size = strlen(str)+1;
858         ret = heap_alloc(size);
859         memcpy(ret, str, size);
860     }
861
862     return ret;
863 }
864
865 static inline WCHAR *heap_strdupAtoW(const char *str)
866 {
867     LPWSTR ret = NULL;
868
869     if(str) {
870         DWORD len;
871
872         len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
873         ret = heap_alloc(len*sizeof(WCHAR));
874         MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
875     }
876
877     return ret;
878 }
879
880 static inline char *heap_strdupWtoA(LPCWSTR str)
881 {
882     char *ret = NULL;
883
884     if(str) {
885         DWORD size = WideCharToMultiByte(CP_ACP, 0, str, -1, NULL, 0, NULL, NULL);
886         ret = heap_alloc(size);
887         WideCharToMultiByte(CP_ACP, 0, str, -1, ret, size, NULL, NULL);
888     }
889
890     return ret;
891 }
892
893 static inline void windowref_addref(windowref_t *ref)
894 {
895     InterlockedIncrement(&ref->ref);
896 }
897
898 static inline void windowref_release(windowref_t *ref)
899 {
900     if(!InterlockedDecrement(&ref->ref))
901         heap_free(ref);
902 }
903
904 HINSTANCE get_shdoclc(void);
905
906 extern HINSTANCE hInst;