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