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