dinput: BuildActionMap and SetActionMap stubs for generic joystick.
[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 "docobjectservice.h"
22 #include "comcat.h"
23 #include "mshtml.h"
24 #include "mshtmhst.h"
25 #include "hlink.h"
26 #include "perhist.h"
27 #include "dispex.h"
28 #include "objsafe.h"
29
30 #include "wine/list.h"
31 #include "wine/unicode.h"
32
33 #ifdef INIT_GUID
34 #include "initguid.h"
35 #endif
36
37 #include "nsiface.h"
38
39 #define NS_ERROR_GENERATE_FAILURE(module,code) \
40     ((nsresult) (((PRUint32)(1<<31)) | ((PRUint32)(module+0x45)<<16) | ((PRUint32)(code))))
41
42 #define NS_OK                     ((nsresult)0x00000000L)
43 #define NS_ERROR_FAILURE          ((nsresult)0x80004005L)
44 #define NS_ERROR_OUT_OF_MEMORY    ((nsresult)0x8007000EL)
45 #define NS_ERROR_NOT_IMPLEMENTED  ((nsresult)0x80004001L)
46 #define NS_NOINTERFACE            ((nsresult)0x80004002L)
47 #define NS_ERROR_INVALID_POINTER  ((nsresult)0x80004003L)
48 #define NS_ERROR_NULL_POINTER     NS_ERROR_INVALID_POINTER
49 #define NS_ERROR_NOT_AVAILABLE    ((nsresult)0x80040111L)
50 #define NS_ERROR_INVALID_ARG      ((nsresult)0x80070057L) 
51 #define NS_ERROR_UNEXPECTED       ((nsresult)0x8000ffffL)
52
53 #define NS_ERROR_MODULE_NETWORK    6
54
55 #define NS_BINDING_ABORTED         NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 2)
56 #define NS_ERROR_UNKNOWN_PROTOCOL  NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 18)
57
58 #define NS_FAILED(res) ((res) & 0x80000000)
59 #define NS_SUCCEEDED(res) (!NS_FAILED(res))
60
61 #define NSAPI WINAPI
62
63 #define MSHTML_E_NODOC    0x800a025c
64
65 typedef struct HTMLDOMNode HTMLDOMNode;
66 typedef struct ConnectionPoint ConnectionPoint;
67 typedef struct BSCallback BSCallback;
68 typedef struct event_target_t event_target_t;
69
70 #define TID_LIST \
71     XIID(NULL) \
72     XDIID(DispCEventObj) \
73     XDIID(DispCPlugins) \
74     XDIID(DispDOMChildrenCollection) \
75     XDIID(DispHTMLAnchorElement) \
76     XDIID(DispHTMLBody) \
77     XDIID(DispHTMLCommentElement) \
78     XDIID(DispHTMLCurrentStyle) \
79     XDIID(DispHTMLDocument) \
80     XDIID(DispHTMLDOMAttribute) \
81     XDIID(DispHTMLDOMTextNode) \
82     XDIID(DispHTMLElementCollection) \
83     XDIID(DispHTMLEmbed) \
84     XDIID(DispHTMLFormElement) \
85     XDIID(DispHTMLGenericElement) \
86     XDIID(DispHTMLFrameElement) \
87     XDIID(DispHTMLHeadElement) \
88     XDIID(DispHTMLIFrame) \
89     XDIID(DispHTMLImg) \
90     XDIID(DispHTMLInputElement) \
91     XDIID(DispHTMLLocation) \
92     XDIID(DispHTMLNavigator) \
93     XDIID(DispHTMLObjectElement) \
94     XDIID(DispHTMLOptionElement) \
95     XDIID(DispHTMLScreen) \
96     XDIID(DispHTMLScriptElement) \
97     XDIID(DispHTMLSelectElement) \
98     XDIID(DispHTMLStyle) \
99     XDIID(DispHTMLStyleElement) \
100     XDIID(DispHTMLStyleSheetsCollection) \
101     XDIID(DispHTMLTable) \
102     XDIID(DispHTMLTableRow) \
103     XDIID(DispHTMLTextAreaElement) \
104     XDIID(DispHTMLTitleElement) \
105     XDIID(DispHTMLUnknownElement) \
106     XDIID(DispHTMLWindow2) \
107     XDIID(HTMLDocumentEvents) \
108     XIID(IHTMLAnchorElement) \
109     XIID(IHTMLBodyElement) \
110     XIID(IHTMLBodyElement2) \
111     XIID(IHTMLCommentElement) \
112     XIID(IHTMLCurrentStyle) \
113     XIID(IHTMLCurrentStyle2) \
114     XIID(IHTMLCurrentStyle3) \
115     XIID(IHTMLCurrentStyle4) \
116     XIID(IHTMLDocument2) \
117     XIID(IHTMLDocument3) \
118     XIID(IHTMLDocument4) \
119     XIID(IHTMLDocument5) \
120     XIID(IHTMLDOMAttribute) \
121     XIID(IHTMLDOMChildrenCollection) \
122     XIID(IHTMLDOMNode) \
123     XIID(IHTMLDOMNode2) \
124     XIID(IHTMLDOMTextNode) \
125     XIID(IHTMLElement) \
126     XIID(IHTMLElement2) \
127     XIID(IHTMLElement3) \
128     XIID(IHTMLElement4) \
129     XIID(IHTMLElementCollection) \
130     XIID(IHTMLEmbedElement) \
131     XIID(IHTMLEventObj) \
132     XIID(IHTMLFiltersCollection) \
133     XIID(IHTMLFormElement) \
134     XIID(IHTMLFrameBase) \
135     XIID(IHTMLFrameBase2) \
136     XIID(IHTMLFrameElement3) \
137     XIID(IHTMLGenericElement) \
138     XIID(IHTMLHeadElement) \
139     XIID(IHTMLIFrameElement) \
140     XIID(IHTMLImageElementFactory) \
141     XIID(IHTMLImgElement) \
142     XIID(IHTMLInputElement) \
143     XIID(IHTMLLocation) \
144     XIID(IHTMLMimeTypesCollection) \
145     XIID(IHTMLObjectElement) \
146     XIID(IHTMLOptionElement) \
147     XIID(IHTMLPluginsCollection) \
148     XIID(IHTMLRect) \
149     XIID(IHTMLScreen) \
150     XIID(IHTMLScriptElement) \
151     XIID(IHTMLSelectElement) \
152     XIID(IHTMLStyle) \
153     XIID(IHTMLStyle2) \
154     XIID(IHTMLStyle3) \
155     XIID(IHTMLStyle4) \
156     XIID(IHTMLStyleElement) \
157     XIID(IHTMLStyleSheetsCollection) \
158     XIID(IHTMLTable) \
159     XIID(IHTMLTableRow) \
160     XIID(IHTMLTextAreaElement) \
161     XIID(IHTMLTextContainer) \
162     XIID(IHTMLTitleElement) \
163     XIID(IHTMLUniqueName) \
164     XIID(IHTMLWindow2) \
165     XIID(IHTMLWindow3) \
166     XIID(IHTMLWindow4) \
167     XIID(IOmNavigator)
168
169 typedef enum {
170 #define XIID(iface) iface ## _tid,
171 #define XDIID(iface) iface ## _tid,
172 TID_LIST
173 #undef XIID
174 #undef XDIID
175     LAST_tid
176 } tid_t;
177
178 typedef struct dispex_data_t dispex_data_t;
179 typedef struct dispex_dynamic_data_t dispex_dynamic_data_t;
180
181 #define MSHTML_DISPID_CUSTOM_MIN 0x60000000
182 #define MSHTML_DISPID_CUSTOM_MAX 0x6fffffff
183 #define MSHTML_CUSTOM_DISPID_CNT (MSHTML_DISPID_CUSTOM_MAX-MSHTML_DISPID_CUSTOM_MIN)
184
185 typedef struct DispatchEx DispatchEx;
186
187 typedef struct {
188     HRESULT (*value)(DispatchEx*,LCID,WORD,DISPPARAMS*,VARIANT*,EXCEPINFO*,IServiceProvider*);
189     HRESULT (*get_dispid)(DispatchEx*,BSTR,DWORD,DISPID*);
190     HRESULT (*invoke)(DispatchEx*,DISPID,LCID,WORD,DISPPARAMS*,VARIANT*,EXCEPINFO*,IServiceProvider*);
191 } dispex_static_data_vtbl_t;
192
193 typedef struct {
194     const dispex_static_data_vtbl_t *vtbl;
195     const tid_t disp_tid;
196     dispex_data_t *data;
197     const tid_t* const iface_tids;
198 } dispex_static_data_t;
199
200 struct DispatchEx {
201     IDispatchEx IDispatchEx_iface;
202
203     IUnknown *outer;
204
205     dispex_static_data_t *data;
206     dispex_dynamic_data_t *dynamic_data;
207 };
208
209 void init_dispex(DispatchEx*,IUnknown*,dispex_static_data_t*) DECLSPEC_HIDDEN;
210 void release_dispex(DispatchEx*) DECLSPEC_HIDDEN;
211 BOOL dispex_query_interface(DispatchEx*,REFIID,void**) DECLSPEC_HIDDEN;
212 HRESULT dispex_get_dprop_ref(DispatchEx*,const WCHAR*,BOOL,VARIANT**) DECLSPEC_HIDDEN;
213 HRESULT get_dispids(tid_t,DWORD*,DISPID**) DECLSPEC_HIDDEN;
214 HRESULT remove_prop(DispatchEx*,BSTR,VARIANT_BOOL*) DECLSPEC_HIDDEN;
215 void release_typelib(void) DECLSPEC_HIDDEN;
216
217 typedef struct HTMLWindow HTMLWindow;
218 typedef struct HTMLDocumentNode HTMLDocumentNode;
219 typedef struct HTMLDocumentObj HTMLDocumentObj;
220 typedef struct HTMLFrameBase HTMLFrameBase;
221 typedef struct NSContainer NSContainer;
222
223 typedef enum {
224     SCRIPTMODE_GECKO,
225     SCRIPTMODE_ACTIVESCRIPT
226 } SCRIPTMODE;
227
228 typedef struct ScriptHost ScriptHost;
229
230 typedef enum {
231     GLOBAL_SCRIPTVAR,
232     GLOBAL_ELEMENTVAR
233 } global_prop_type_t;
234
235 typedef struct {
236     global_prop_type_t type;
237     WCHAR *name;
238     ScriptHost *script_host;
239     DISPID id;
240 } global_prop_t;
241
242 typedef struct {
243     IHTMLOptionElementFactory IHTMLOptionElementFactory_iface;
244
245     LONG ref;
246
247     HTMLWindow *window;
248 } HTMLOptionElementFactory;
249
250 typedef struct {
251     DispatchEx dispex;
252     IHTMLImageElementFactory IHTMLImageElementFactory_iface;
253
254     LONG ref;
255
256     HTMLWindow *window;
257 } HTMLImageElementFactory;
258
259 struct HTMLLocation {
260     DispatchEx dispex;
261     IHTMLLocation IHTMLLocation_iface;
262
263     LONG ref;
264
265     HTMLWindow *window;
266 };
267
268 typedef struct {
269     HTMLWindow *window;
270     LONG ref;
271 }  windowref_t;
272
273 typedef struct nsChannelBSC nsChannelBSC;
274
275 struct HTMLWindow {
276     DispatchEx dispex;
277     IHTMLWindow2       IHTMLWindow2_iface;
278     IHTMLWindow3       IHTMLWindow3_iface;
279     IHTMLWindow4       IHTMLWindow4_iface;
280     IHTMLPrivateWindow IHTMLPrivateWindow_iface;
281     IDispatchEx        IDispatchEx_iface;
282     IServiceProvider   IServiceProvider_iface;
283
284     LONG ref;
285
286     windowref_t *window_ref;
287     LONG task_magic;
288
289     HTMLDocumentNode *doc;
290     HTMLDocumentObj *doc_obj;
291     nsIDOMWindow *nswindow;
292     HTMLWindow *parent;
293     HTMLFrameBase *frame_element;
294     READYSTATE readystate;
295
296     nsChannelBSC *bscallback;
297     IMoniker *mon;
298     LPOLESTR url;
299
300     IHTMLEventObj *event;
301
302     SCRIPTMODE scriptmode;
303     struct list script_hosts;
304
305     IInternetSecurityManager *secmgr;
306
307     HTMLOptionElementFactory *option_factory;
308     HTMLImageElementFactory *image_factory;
309     HTMLLocation *location;
310     IHTMLScreen *screen;
311
312     global_prop_t *global_props;
313     DWORD global_prop_cnt;
314     DWORD global_prop_size;
315
316     struct list children;
317     struct list sibling_entry;
318     struct list entry;
319 };
320
321 typedef enum {
322     UNKNOWN_USERMODE,
323     BROWSEMODE,
324     EDITMODE        
325 } USERMODE;
326
327 typedef struct _cp_static_data_t {
328     tid_t tid;
329     void (*on_advise)(IUnknown*,struct _cp_static_data_t*);
330     DWORD id_cnt;
331     DISPID *ids;
332 } cp_static_data_t;
333
334 typedef struct ConnectionPointContainer {
335     IConnectionPointContainer IConnectionPointContainer_iface;
336
337     ConnectionPoint *cp_list;
338     IUnknown *outer;
339     struct ConnectionPointContainer *forward_container;
340 } ConnectionPointContainer;
341
342 struct ConnectionPoint {
343     IConnectionPoint IConnectionPoint_iface;
344
345     ConnectionPointContainer *container;
346
347     union {
348         IUnknown *unk;
349         IDispatch *disp;
350         IPropertyNotifySink *propnotif;
351     } *sinks;
352     DWORD sinks_size;
353
354     const IID *iid;
355     cp_static_data_t *data;
356
357     ConnectionPoint *next;
358 };
359
360 struct HTMLDocument {
361     IHTMLDocument2              IHTMLDocument2_iface;
362     IHTMLDocument3              IHTMLDocument3_iface;
363     IHTMLDocument4              IHTMLDocument4_iface;
364     IHTMLDocument5              IHTMLDocument5_iface;
365     IHTMLDocument6              IHTMLDocument6_iface;
366     IPersistMoniker             IPersistMoniker_iface;
367     IPersistFile                IPersistFile_iface;
368     IPersistHistory             IPersistHistory_iface;
369     IMonikerProp                IMonikerProp_iface;
370     IOleObject                  IOleObject_iface;
371     IOleDocument                IOleDocument_iface;
372     IOleDocumentView            IOleDocumentView_iface;
373     IOleInPlaceActiveObject     IOleInPlaceActiveObject_iface;
374     IViewObjectEx               IViewObjectEx_iface;
375     IOleInPlaceObjectWindowless IOleInPlaceObjectWindowless_iface;
376     IServiceProvider            IServiceProvider_iface;
377     IOleCommandTarget           IOleCommandTarget_iface;
378     IOleControl                 IOleControl_iface;
379     IHlinkTarget                IHlinkTarget_iface;
380     IPersistStreamInit          IPersistStreamInit_iface;
381     IDispatchEx                 IDispatchEx_iface;
382     ISupportErrorInfo           ISupportErrorInfo_iface;
383     IObjectWithSite             IObjectWithSite_iface;
384     IOleContainer               IOleContainer_iface;
385     IObjectSafety               IObjectSafety_iface;
386
387     IUnknown *unk_impl;
388     IDispatchEx *dispex;
389
390     HTMLDocumentObj *doc_obj;
391     HTMLDocumentNode *doc_node;
392
393     HTMLWindow *window;
394
395     LONG task_magic;
396
397     ConnectionPointContainer cp_container;
398     ConnectionPoint cp_htmldocevents;
399     ConnectionPoint cp_htmldocevents2;
400     ConnectionPoint cp_propnotif;
401     ConnectionPoint cp_dispatch;
402
403     IOleAdviseHolder *advise_holder;
404 };
405
406 static inline HRESULT htmldoc_query_interface(HTMLDocument *This, REFIID riid, void **ppv)
407 {
408     return IUnknown_QueryInterface(This->unk_impl, riid, ppv);
409 }
410
411 static inline ULONG htmldoc_addref(HTMLDocument *This)
412 {
413     return IUnknown_AddRef(This->unk_impl);
414 }
415
416 static inline ULONG htmldoc_release(HTMLDocument *This)
417 {
418     return IUnknown_Release(This->unk_impl);
419 }
420
421 struct HTMLDocumentObj {
422     HTMLDocument basedoc;
423     DispatchEx dispex;
424     ICustomDoc ICustomDoc_iface;
425
426     LONG ref;
427
428     NSContainer *nscontainer;
429
430     IOleClientSite *client;
431     IDocHostUIHandler *hostui;
432     BOOL custom_hostui;
433     IOleInPlaceSite *ipsite;
434     IOleInPlaceFrame *frame;
435     IOleInPlaceUIWindow *ip_window;
436     IAdviseSink *view_sink;
437     IDocObjectService *doc_object_service;
438
439     DOCHOSTUIINFO hostinfo;
440
441     IOleUndoManager *undomgr;
442
443     HWND hwnd;
444     HWND tooltips_hwnd;
445
446     BOOL request_uiactivate;
447     BOOL in_place_active;
448     BOOL ui_active;
449     BOOL window_active;
450     BOOL hostui_setup;
451     BOOL container_locked;
452     BOOL focus;
453     INT download_state;
454
455     USERMODE usermode;
456     LPWSTR mime;
457
458     DWORD update;
459 };
460
461 typedef struct nsWeakReference nsWeakReference;
462
463 struct NSContainer {
464     nsIWebBrowserChrome      nsIWebBrowserChrome_iface;
465     nsIContextMenuListener   nsIContextMenuListener_iface;
466     nsIURIContentListener    nsIURIContentListener_iface;
467     nsIEmbeddingSiteWindow   nsIEmbeddingSiteWindow_iface;
468     nsITooltipListener       nsITooltipListener_iface;
469     nsIInterfaceRequestor    nsIInterfaceRequestor_iface;
470     nsISupportsWeakReference nsISupportsWeakReference_iface;
471
472     nsIWebBrowser *webbrowser;
473     nsIWebNavigation *navigation;
474     nsIBaseWindow *window;
475     nsIWebBrowserFocus *focus;
476
477     nsIEditor *editor;
478     nsIController *editor_controller;
479
480     LONG ref;
481
482     nsWeakReference *weak_reference;
483
484     NSContainer *parent;
485     HTMLDocumentObj *doc;
486
487     nsIURIContentListener *content_listener;
488
489     HWND hwnd;
490 };
491
492 typedef struct nsWineURI nsWineURI;
493
494 nsresult on_start_uri_open(NSContainer*,nsIURI*,PRBool*) DECLSPEC_HIDDEN;
495
496 /* Keep sync with request_method_strings in nsio.c */
497 typedef enum {
498     METHOD_GET,
499     METHOD_PUT,
500     METHOD_POST
501 } REQUEST_METHOD;
502
503 typedef struct {
504     nsIHttpChannel         nsIHttpChannel_iface;
505     nsIUploadChannel       nsIUploadChannel_iface;
506     nsIHttpChannelInternal nsIHttpChannelInternal_iface;
507
508     LONG ref;
509
510     nsWineURI *uri;
511     nsIInputStream *post_data_stream;
512     BOOL post_data_contains_headers;
513     nsILoadGroup *load_group;
514     nsIInterfaceRequestor *notif_callback;
515     nsISupports *owner;
516     nsLoadFlags load_flags;
517     nsIURI *original_uri;
518     nsIURI *referrer;
519     char *content_type;
520     char *charset;
521     PRUint32 response_status;
522     REQUEST_METHOD request_method;
523     struct list response_headers;
524     struct list request_headers;
525     UINT url_scheme;
526 } nsChannel;
527
528 typedef struct {
529     struct list entry;
530     WCHAR *header;
531     WCHAR *data;
532 } http_header_t;
533
534 HRESULT set_http_header(struct list*,const WCHAR*,int,const WCHAR*,int) DECLSPEC_HIDDEN;
535 HRESULT create_redirect_nschannel(const WCHAR*,nsChannel*,nsChannel**) DECLSPEC_HIDDEN;
536
537 typedef struct {
538     HRESULT (*qi)(HTMLDOMNode*,REFIID,void**);
539     void (*destructor)(HTMLDOMNode*);
540     HRESULT (*clone)(HTMLDOMNode*,nsIDOMNode*,HTMLDOMNode**);
541     event_target_t **(*get_event_target)(HTMLDOMNode*);
542     HRESULT (*call_event)(HTMLDOMNode*,DWORD,BOOL*);
543     HRESULT (*put_disabled)(HTMLDOMNode*,VARIANT_BOOL);
544     HRESULT (*get_disabled)(HTMLDOMNode*,VARIANT_BOOL*);
545     HRESULT (*get_document)(HTMLDOMNode*,IDispatch**);
546     HRESULT (*get_readystate)(HTMLDOMNode*,BSTR*);
547     HRESULT (*get_dispid)(HTMLDOMNode*,BSTR,DWORD,DISPID*);
548     HRESULT (*invoke)(HTMLDOMNode*,DISPID,LCID,WORD,DISPPARAMS*,VARIANT*,EXCEPINFO*,IServiceProvider*);
549     HRESULT (*bind_to_tree)(HTMLDOMNode*);
550 } NodeImplVtbl;
551
552 struct HTMLDOMNode {
553     DispatchEx dispex;
554     IHTMLDOMNode  IHTMLDOMNode_iface;
555     IHTMLDOMNode2 IHTMLDOMNode2_iface;
556     const NodeImplVtbl *vtbl;
557
558     LONG ref;
559
560     nsIDOMNode *nsnode;
561     HTMLDocumentNode *doc;
562     event_target_t *event_target;
563     ConnectionPointContainer *cp_container;
564
565     HTMLDOMNode *next;
566 };
567
568 typedef struct {
569     HTMLDOMNode node;
570     ConnectionPointContainer cp_container;
571
572     IHTMLElement  IHTMLElement_iface;
573     IHTMLElement2 IHTMLElement2_iface;
574     IHTMLElement3 IHTMLElement3_iface;
575     IHTMLElement4 IHTMLElement4_iface;
576
577     nsIDOMHTMLElement *nselem;
578     HTMLStyle *style;
579     struct list attrs;
580 } HTMLElement;
581
582 #define HTMLELEMENT_TIDS    \
583     IHTMLDOMNode_tid,       \
584     IHTMLDOMNode2_tid,      \
585     IHTMLElement_tid,       \
586     IHTMLElement2_tid,      \
587     IHTMLElement3_tid,      \
588     IHTMLElement4_tid
589
590 typedef struct {
591     HTMLElement element;
592
593     IHTMLTextContainer IHTMLTextContainer_iface;
594
595     ConnectionPoint cp;
596 } HTMLTextContainer;
597
598 struct HTMLFrameBase {
599     HTMLElement element;
600
601     IHTMLFrameBase  IHTMLFrameBase_iface;
602     IHTMLFrameBase2 IHTMLFrameBase2_iface;
603
604     HTMLWindow *content_window;
605
606     nsIDOMHTMLFrameElement *nsframe;
607     nsIDOMHTMLIFrameElement *nsiframe;
608 };
609
610 typedef struct nsDocumentEventListener nsDocumentEventListener;
611
612 struct HTMLDocumentNode {
613     HTMLDOMNode node;
614     HTMLDocument basedoc;
615
616     IInternetHostSecurityManager IInternetHostSecurityManager_iface;
617
618     nsIDocumentObserver          nsIDocumentObserver_iface;
619
620     LONG ref;
621
622     nsIDOMHTMLDocument *nsdoc;
623     HTMLDOMNode *nodes;
624     BOOL content_ready;
625     event_target_t *body_event_target;
626
627     ICatInformation *catmgr;
628     nsDocumentEventListener *nsevent_listener;
629     BOOL *event_vector;
630
631     WCHAR **elem_vars;
632     unsigned elem_vars_size;
633     unsigned elem_vars_cnt;
634
635     BOOL skip_mutation_notif;
636
637     struct list bindings;
638     struct list selection_list;
639     struct list range_list;
640     struct list plugin_hosts;
641 };
642
643 HRESULT HTMLDocument_Create(IUnknown*,REFIID,void**) DECLSPEC_HIDDEN;
644 HRESULT HTMLLoadOptions_Create(IUnknown*,REFIID,void**) DECLSPEC_HIDDEN;
645 HRESULT create_doc_from_nsdoc(nsIDOMHTMLDocument*,HTMLDocumentObj*,HTMLWindow*,HTMLDocumentNode**) DECLSPEC_HIDDEN;
646 HRESULT create_document_fragment(nsIDOMNode*,HTMLDocumentNode*,HTMLDocumentNode**) DECLSPEC_HIDDEN;
647
648 HRESULT HTMLWindow_Create(HTMLDocumentObj*,nsIDOMWindow*,HTMLWindow*,HTMLWindow**) DECLSPEC_HIDDEN;
649 void update_window_doc(HTMLWindow*) DECLSPEC_HIDDEN;
650 HTMLWindow *nswindow_to_window(const nsIDOMWindow*) DECLSPEC_HIDDEN;
651 nsIDOMWindow *get_nsdoc_window(nsIDOMDocument*) DECLSPEC_HIDDEN;
652 HTMLOptionElementFactory *HTMLOptionElementFactory_Create(HTMLWindow*) DECLSPEC_HIDDEN;
653 HTMLImageElementFactory *HTMLImageElementFactory_Create(HTMLWindow*) DECLSPEC_HIDDEN;
654 HRESULT HTMLLocation_Create(HTMLWindow*,HTMLLocation**) DECLSPEC_HIDDEN;
655 IOmNavigator *OmNavigator_Create(void) DECLSPEC_HIDDEN;
656 HRESULT HTMLScreen_Create(IHTMLScreen**) DECLSPEC_HIDDEN;
657
658 void HTMLDocument_HTMLDocument3_Init(HTMLDocument*) DECLSPEC_HIDDEN;
659 void HTMLDocument_HTMLDocument5_Init(HTMLDocument*) DECLSPEC_HIDDEN;
660 void HTMLDocument_Persist_Init(HTMLDocument*) DECLSPEC_HIDDEN;
661 void HTMLDocument_OleCmd_Init(HTMLDocument*) DECLSPEC_HIDDEN;
662 void HTMLDocument_OleObj_Init(HTMLDocument*) DECLSPEC_HIDDEN;
663 void HTMLDocument_View_Init(HTMLDocument*) DECLSPEC_HIDDEN;
664 void HTMLDocument_Window_Init(HTMLDocument*) DECLSPEC_HIDDEN;
665 void HTMLDocument_Service_Init(HTMLDocument*) DECLSPEC_HIDDEN;
666 void HTMLDocument_Hlink_Init(HTMLDocument*) DECLSPEC_HIDDEN;
667
668 void HTMLDocumentNode_SecMgr_Init(HTMLDocumentNode*) DECLSPEC_HIDDEN;
669
670 HRESULT HTMLCurrentStyle_Create(HTMLElement*,IHTMLCurrentStyle**) DECLSPEC_HIDDEN;
671
672 void ConnectionPoint_Init(ConnectionPoint*,ConnectionPointContainer*,REFIID,cp_static_data_t*) DECLSPEC_HIDDEN;
673 void ConnectionPointContainer_Init(ConnectionPointContainer*,IUnknown*) DECLSPEC_HIDDEN;
674 void ConnectionPointContainer_Destroy(ConnectionPointContainer*) DECLSPEC_HIDDEN;
675
676 NSContainer *NSContainer_Create(HTMLDocumentObj*,NSContainer*) DECLSPEC_HIDDEN;
677 void NSContainer_Release(NSContainer*) DECLSPEC_HIDDEN;
678 nsresult create_chrome_window(nsIWebBrowserChrome*,nsIWebBrowserChrome**) DECLSPEC_HIDDEN;
679
680 void init_mutation(nsIComponentManager*) DECLSPEC_HIDDEN;
681 void init_document_mutation(HTMLDocumentNode*) DECLSPEC_HIDDEN;
682 void release_document_mutation(HTMLDocumentNode*) DECLSPEC_HIDDEN;
683
684 void HTMLDocument_LockContainer(HTMLDocumentObj*,BOOL) DECLSPEC_HIDDEN;
685 void show_context_menu(HTMLDocumentObj*,DWORD,POINT*,IDispatch*) DECLSPEC_HIDDEN;
686 void notif_focus(HTMLDocumentObj*) DECLSPEC_HIDDEN;
687
688 void show_tooltip(HTMLDocumentObj*,DWORD,DWORD,LPCWSTR) DECLSPEC_HIDDEN;
689 void hide_tooltip(HTMLDocumentObj*) DECLSPEC_HIDDEN;
690 HRESULT get_client_disp_property(IOleClientSite*,DISPID,VARIANT*) DECLSPEC_HIDDEN;
691
692 HRESULT ProtocolFactory_Create(REFCLSID,REFIID,void**) DECLSPEC_HIDDEN;
693
694 BOOL load_gecko(BOOL) DECLSPEC_HIDDEN;
695 void close_gecko(void) DECLSPEC_HIDDEN;
696 void register_nsservice(nsIComponentRegistrar*,nsIServiceManager*) DECLSPEC_HIDDEN;
697 void init_nsio(nsIComponentManager*,nsIComponentRegistrar*) DECLSPEC_HIDDEN;
698 void release_nsio(void) DECLSPEC_HIDDEN;
699 BOOL is_gecko_path(const char*) DECLSPEC_HIDDEN;
700
701 HRESULT nsuri_to_url(LPCWSTR,BOOL,BSTR*) DECLSPEC_HIDDEN;
702 HRESULT create_doc_uri(HTMLWindow*,WCHAR*,nsWineURI**) DECLSPEC_HIDDEN;
703 HRESULT load_nsuri(HTMLWindow*,nsWineURI*,nsChannelBSC*,DWORD) DECLSPEC_HIDDEN;
704
705 HRESULT hlink_frame_navigate(HTMLDocument*,LPCWSTR,nsChannel*,DWORD,BOOL*) DECLSPEC_HIDDEN;
706 HRESULT navigate_url(HTMLWindow*,const WCHAR*,const WCHAR*) DECLSPEC_HIDDEN;
707 HRESULT set_frame_doc(HTMLFrameBase*,nsIDOMDocument*) DECLSPEC_HIDDEN;
708 HRESULT set_moniker(HTMLDocument*,IMoniker*,IBindCtx*,nsChannelBSC*,BOOL) DECLSPEC_HIDDEN;
709
710 void call_property_onchanged(ConnectionPoint*,DISPID) DECLSPEC_HIDDEN;
711 HRESULT call_set_active_object(IOleInPlaceUIWindow*,IOleInPlaceActiveObject*) DECLSPEC_HIDDEN;
712
713 void *nsalloc(size_t) __WINE_ALLOC_SIZE(1) DECLSPEC_HIDDEN;
714 void nsfree(void*) DECLSPEC_HIDDEN;
715
716 void nsACString_InitDepend(nsACString*,const char*) DECLSPEC_HIDDEN;
717 void nsACString_SetData(nsACString*,const char*) DECLSPEC_HIDDEN;
718 PRUint32 nsACString_GetData(const nsACString*,const char**) DECLSPEC_HIDDEN;
719 void nsACString_Finish(nsACString*) DECLSPEC_HIDDEN;
720
721 BOOL nsAString_Init(nsAString*,const PRUnichar*) DECLSPEC_HIDDEN;
722 void nsAString_InitDepend(nsAString*,const PRUnichar*) DECLSPEC_HIDDEN;
723 void nsAString_SetData(nsAString*,const PRUnichar*) DECLSPEC_HIDDEN;
724 PRUint32 nsAString_GetData(const nsAString*,const PRUnichar**) DECLSPEC_HIDDEN;
725 void nsAString_Finish(nsAString*) DECLSPEC_HIDDEN;
726 HRESULT return_nsstr(nsresult,nsAString*,BSTR*) DECLSPEC_HIDDEN;
727
728 nsICommandParams *create_nscommand_params(void) DECLSPEC_HIDDEN;
729 HRESULT nsnode_to_nsstring(nsIDOMNode*,nsAString*) DECLSPEC_HIDDEN;
730 void get_editor_controller(NSContainer*) DECLSPEC_HIDDEN;
731 nsresult get_nsinterface(nsISupports*,REFIID,void**) DECLSPEC_HIDDEN;
732
733 void init_nsevents(HTMLDocumentNode*) DECLSPEC_HIDDEN;
734 void release_nsevents(HTMLDocumentNode*) DECLSPEC_HIDDEN;
735 void add_nsevent_listener(HTMLDocumentNode*,nsIDOMNode*,LPCWSTR) DECLSPEC_HIDDEN;
736
737 void set_window_bscallback(HTMLWindow*,nsChannelBSC*) DECLSPEC_HIDDEN;
738 void set_current_mon(HTMLWindow*,IMoniker*) DECLSPEC_HIDDEN;
739 HRESULT start_binding(HTMLWindow*,HTMLDocumentNode*,BSCallback*,IBindCtx*) DECLSPEC_HIDDEN;
740 HRESULT async_start_doc_binding(HTMLWindow*,nsChannelBSC*) DECLSPEC_HIDDEN;
741 void abort_document_bindings(HTMLDocumentNode*) DECLSPEC_HIDDEN;
742
743 HRESULT bind_mon_to_buffer(HTMLDocumentNode*,IMoniker*,void**,DWORD*) DECLSPEC_HIDDEN;
744
745 HRESULT create_channelbsc(IMoniker*,WCHAR*,BYTE*,DWORD,nsChannelBSC**) DECLSPEC_HIDDEN;
746 HRESULT channelbsc_load_stream(nsChannelBSC*,IStream*) DECLSPEC_HIDDEN;
747 void channelbsc_set_channel(nsChannelBSC*,nsChannel*,nsIStreamListener*,nsISupports*) DECLSPEC_HIDDEN;
748
749 void set_ready_state(HTMLWindow*,READYSTATE) DECLSPEC_HIDDEN;
750
751 HRESULT HTMLSelectionObject_Create(HTMLDocumentNode*,nsISelection*,IHTMLSelectionObject**) DECLSPEC_HIDDEN;
752 HRESULT HTMLTxtRange_Create(HTMLDocumentNode*,nsIDOMRange*,IHTMLTxtRange**) DECLSPEC_HIDDEN;
753 HRESULT HTMLStyle_Create(nsIDOMCSSStyleDeclaration*,HTMLStyle**) DECLSPEC_HIDDEN;
754 IHTMLStyleSheet *HTMLStyleSheet_Create(nsIDOMStyleSheet*) DECLSPEC_HIDDEN;
755 IHTMLStyleSheetsCollection *HTMLStyleSheetsCollection_Create(nsIDOMStyleSheetList*) DECLSPEC_HIDDEN;
756
757 void detach_selection(HTMLDocumentNode*) DECLSPEC_HIDDEN;
758 void detach_ranges(HTMLDocumentNode*) DECLSPEC_HIDDEN;
759 HRESULT get_node_text(HTMLDOMNode*,BSTR*) DECLSPEC_HIDDEN;
760 HRESULT replace_node_by_html(nsIDOMHTMLDocument*,nsIDOMNode*,const WCHAR*);
761
762 HRESULT create_nselem(HTMLDocumentNode*,const WCHAR*,nsIDOMHTMLElement**) DECLSPEC_HIDDEN;
763
764 HRESULT HTMLDOMTextNode_Create(HTMLDocumentNode*,nsIDOMNode*,HTMLDOMNode**) DECLSPEC_HIDDEN;
765
766 typedef struct {
767     DispatchEx dispex;
768     IHTMLDOMAttribute IHTMLDOMAttribute_iface;
769
770     LONG ref;
771
772     DISPID dispid;
773     HTMLElement *elem;
774     struct list entry;
775 } HTMLDOMAttribute;
776
777 HRESULT HTMLDOMAttribute_Create(HTMLElement*,DISPID,HTMLDOMAttribute**) DECLSPEC_HIDDEN;
778
779 HRESULT HTMLElement_Create(HTMLDocumentNode*,nsIDOMNode*,BOOL,HTMLElement**) DECLSPEC_HIDDEN;
780 HRESULT HTMLCommentElement_Create(HTMLDocumentNode*,nsIDOMNode*,HTMLElement**) DECLSPEC_HIDDEN;
781 HRESULT HTMLAnchorElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**) DECLSPEC_HIDDEN;
782 HRESULT HTMLBodyElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**) DECLSPEC_HIDDEN;
783 HRESULT HTMLEmbedElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**) DECLSPEC_HIDDEN;
784 HRESULT HTMLFormElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**) DECLSPEC_HIDDEN;
785 HRESULT HTMLFrameElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**) DECLSPEC_HIDDEN;
786 HRESULT HTMLHeadElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**) DECLSPEC_HIDDEN;
787 HRESULT HTMLIFrame_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**) DECLSPEC_HIDDEN;
788 HRESULT HTMLStyleElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**) DECLSPEC_HIDDEN;
789 HRESULT HTMLImgElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**) DECLSPEC_HIDDEN;
790 HRESULT HTMLInputElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**) DECLSPEC_HIDDEN;
791 HRESULT HTMLObjectElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**) DECLSPEC_HIDDEN;
792 HRESULT HTMLOptionElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**) DECLSPEC_HIDDEN;
793 HRESULT HTMLScriptElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**) DECLSPEC_HIDDEN;
794 HRESULT HTMLSelectElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**) DECLSPEC_HIDDEN;
795 HRESULT HTMLTable_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**) DECLSPEC_HIDDEN;
796 HRESULT HTMLTableRow_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**) DECLSPEC_HIDDEN;
797 HRESULT HTMLTextAreaElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**) DECLSPEC_HIDDEN;
798 HRESULT HTMLTitleElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**) DECLSPEC_HIDDEN;
799 HRESULT HTMLGenericElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**) DECLSPEC_HIDDEN;
800
801 void HTMLDOMNode_Init(HTMLDocumentNode*,HTMLDOMNode*,nsIDOMNode*) DECLSPEC_HIDDEN;
802 void HTMLElement_Init(HTMLElement*,HTMLDocumentNode*,nsIDOMHTMLElement*,dispex_static_data_t*) DECLSPEC_HIDDEN;
803 void HTMLElement2_Init(HTMLElement*) DECLSPEC_HIDDEN;
804 void HTMLElement3_Init(HTMLElement*) DECLSPEC_HIDDEN;
805 void HTMLTextContainer_Init(HTMLTextContainer*,HTMLDocumentNode*,nsIDOMHTMLElement*,dispex_static_data_t*) DECLSPEC_HIDDEN;
806 void HTMLFrameBase_Init(HTMLFrameBase*,HTMLDocumentNode*,nsIDOMHTMLElement*,dispex_static_data_t*) DECLSPEC_HIDDEN;
807
808 HRESULT HTMLDOMNode_QI(HTMLDOMNode*,REFIID,void**) DECLSPEC_HIDDEN;
809 void HTMLDOMNode_destructor(HTMLDOMNode*) DECLSPEC_HIDDEN;
810
811 HRESULT HTMLElement_QI(HTMLDOMNode*,REFIID,void**) DECLSPEC_HIDDEN;
812 void HTMLElement_destructor(HTMLDOMNode*) DECLSPEC_HIDDEN;
813 HRESULT HTMLElement_clone(HTMLDOMNode*,nsIDOMNode*,HTMLDOMNode**) DECLSPEC_HIDDEN;
814
815 HRESULT HTMLFrameBase_QI(HTMLFrameBase*,REFIID,void**) DECLSPEC_HIDDEN;
816 void HTMLFrameBase_destructor(HTMLFrameBase*) DECLSPEC_HIDDEN;
817
818 HRESULT get_node(HTMLDocumentNode*,nsIDOMNode*,BOOL,HTMLDOMNode**) DECLSPEC_HIDDEN;
819 void release_nodes(HTMLDocumentNode*) DECLSPEC_HIDDEN;
820
821 void release_script_hosts(HTMLWindow*) DECLSPEC_HIDDEN;
822 void connect_scripts(HTMLWindow*) DECLSPEC_HIDDEN;
823 void doc_insert_script(HTMLWindow*,nsIDOMHTMLScriptElement*) DECLSPEC_HIDDEN;
824 IDispatch *script_parse_event(HTMLWindow*,LPCWSTR) DECLSPEC_HIDDEN;
825 HRESULT exec_script(HTMLWindow*,const WCHAR*,const WCHAR*,VARIANT*) DECLSPEC_HIDDEN;
826 void set_script_mode(HTMLWindow*,SCRIPTMODE) DECLSPEC_HIDDEN;
827 BOOL find_global_prop(HTMLWindow*,BSTR,DWORD,ScriptHost**,DISPID*) DECLSPEC_HIDDEN;
828 IDispatch *get_script_disp(ScriptHost*) DECLSPEC_HIDDEN;
829 HRESULT search_window_props(HTMLWindow*,BSTR,DWORD,DISPID*) DECLSPEC_HIDDEN;
830
831 IHTMLElementCollection *create_all_collection(HTMLDOMNode*,BOOL) DECLSPEC_HIDDEN;
832 IHTMLElementCollection *create_collection_from_nodelist(HTMLDocumentNode*,IUnknown*,nsIDOMNodeList*) DECLSPEC_HIDDEN;
833 IHTMLElementCollection *create_collection_from_htmlcol(HTMLDocumentNode*,IUnknown*,nsIDOMHTMLCollection*) DECLSPEC_HIDDEN;
834
835 /* commands */
836 typedef struct {
837     DWORD id;
838     HRESULT (*query)(HTMLDocument*,OLECMD*);
839     HRESULT (*exec)(HTMLDocument*,DWORD,VARIANT*,VARIANT*);
840 } cmdtable_t;
841
842 extern const cmdtable_t editmode_cmds[] DECLSPEC_HIDDEN;
843
844 void do_ns_command(HTMLDocument*,const char*,nsICommandParams*) DECLSPEC_HIDDEN;
845
846 /* timer */
847 #define UPDATE_UI       0x0001
848 #define UPDATE_TITLE    0x0002
849
850 void update_doc(HTMLDocument*,DWORD) DECLSPEC_HIDDEN;
851 void update_title(HTMLDocumentObj*) DECLSPEC_HIDDEN;
852
853 /* editor */
854 void init_editor(HTMLDocument*) DECLSPEC_HIDDEN;
855 void handle_edit_event(HTMLDocument*,nsIDOMEvent*) DECLSPEC_HIDDEN;
856 HRESULT editor_exec_copy(HTMLDocument*,DWORD,VARIANT*,VARIANT*) DECLSPEC_HIDDEN;
857 HRESULT editor_exec_cut(HTMLDocument*,DWORD,VARIANT*,VARIANT*) DECLSPEC_HIDDEN;
858 HRESULT editor_exec_paste(HTMLDocument*,DWORD,VARIANT*,VARIANT*) DECLSPEC_HIDDEN;
859 void handle_edit_load(HTMLDocument*) DECLSPEC_HIDDEN;
860 HRESULT editor_is_dirty(HTMLDocument*) DECLSPEC_HIDDEN;
861 void set_dirty(HTMLDocument*,VARIANT_BOOL) DECLSPEC_HIDDEN;
862
863 extern DWORD mshtml_tls DECLSPEC_HIDDEN;
864
865 typedef struct task_t task_t;
866 typedef void (*task_proc_t)(task_t*);
867
868 struct task_t {
869     LONG target_magic;
870     task_proc_t proc;
871     struct task_t *next;
872 };
873
874 typedef struct {
875     task_t header;
876     HTMLDocumentObj *doc;
877 } docobj_task_t;
878
879 typedef struct {
880     HWND thread_hwnd;
881     task_t *task_queue_head;
882     task_t *task_queue_tail;
883     struct list timer_list;
884 } thread_data_t;
885
886 thread_data_t *get_thread_data(BOOL) DECLSPEC_HIDDEN;
887 HWND get_thread_hwnd(void) DECLSPEC_HIDDEN;
888
889 LONG get_task_target_magic(void) DECLSPEC_HIDDEN;
890 void push_task(task_t*,task_proc_t,LONG) DECLSPEC_HIDDEN;
891 void remove_target_tasks(LONG) DECLSPEC_HIDDEN;
892
893 DWORD set_task_timer(HTMLDocument*,DWORD,BOOL,IDispatch*) DECLSPEC_HIDDEN;
894 HRESULT clear_task_timer(HTMLDocument*,BOOL,DWORD) DECLSPEC_HIDDEN;
895
896 const char *debugstr_variant(const VARIANT*) DECLSPEC_HIDDEN;
897
898 DEFINE_GUID(CLSID_AboutProtocol, 0x3050F406, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
899 DEFINE_GUID(CLSID_JSProtocol, 0x3050F3B2, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
900 DEFINE_GUID(CLSID_MailtoProtocol, 0x3050F3DA, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
901 DEFINE_GUID(CLSID_ResProtocol, 0x3050F3BC, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
902 DEFINE_GUID(CLSID_SysimageProtocol, 0x76E67A63, 0x06E9, 0x11D2, 0xA8,0x40, 0x00,0x60,0x08,0x05,0x93,0x82);
903
904 DEFINE_GUID(CLSID_CMarkup,0x3050f4fb,0x98b5,0x11cf,0xbb,0x82,0x00,0xaa,0x00,0xbd,0xce,0x0b);
905
906 DEFINE_OLEGUID(CGID_DocHostCmdPriv, 0x000214D4L, 0, 0);
907
908 /* memory allocation functions */
909
910 static inline void * __WINE_ALLOC_SIZE(1) heap_alloc(size_t len)
911 {
912     return HeapAlloc(GetProcessHeap(), 0, len);
913 }
914
915 static inline void * __WINE_ALLOC_SIZE(1) heap_alloc_zero(size_t len)
916 {
917     return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
918 }
919
920 static inline void * __WINE_ALLOC_SIZE(2) heap_realloc(void *mem, size_t len)
921 {
922     return HeapReAlloc(GetProcessHeap(), 0, mem, len);
923 }
924
925 static inline void * __WINE_ALLOC_SIZE(2) heap_realloc_zero(void *mem, size_t len)
926 {
927     return HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, mem, len);
928 }
929
930 static inline BOOL heap_free(void *mem)
931 {
932     return HeapFree(GetProcessHeap(), 0, mem);
933 }
934
935 static inline LPWSTR heap_strdupW(LPCWSTR str)
936 {
937     LPWSTR ret = NULL;
938
939     if(str) {
940         DWORD size;
941
942         size = (strlenW(str)+1)*sizeof(WCHAR);
943         ret = heap_alloc(size);
944         memcpy(ret, str, size);
945     }
946
947     return ret;
948 }
949
950 static inline LPWSTR heap_strndupW(LPCWSTR str, unsigned len)
951 {
952     LPWSTR ret = NULL;
953
954     if(str) {
955         ret = heap_alloc((len+1)*sizeof(WCHAR));
956         memcpy(ret, str, len*sizeof(WCHAR));
957         ret[len] = 0;
958     }
959
960     return ret;
961 }
962
963 static inline char *heap_strdupA(const char *str)
964 {
965     char *ret = NULL;
966
967     if(str) {
968         DWORD size;
969
970         size = strlen(str)+1;
971         ret = heap_alloc(size);
972         memcpy(ret, str, size);
973     }
974
975     return ret;
976 }
977
978 static inline WCHAR *heap_strdupAtoW(const char *str)
979 {
980     LPWSTR ret = NULL;
981
982     if(str) {
983         DWORD len;
984
985         len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
986         ret = heap_alloc(len*sizeof(WCHAR));
987         MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
988     }
989
990     return ret;
991 }
992
993 static inline char *heap_strdupWtoA(LPCWSTR str)
994 {
995     char *ret = NULL;
996
997     if(str) {
998         DWORD size = WideCharToMultiByte(CP_ACP, 0, str, -1, NULL, 0, NULL, NULL);
999         ret = heap_alloc(size);
1000         WideCharToMultiByte(CP_ACP, 0, str, -1, ret, size, NULL, NULL);
1001     }
1002
1003     return ret;
1004 }
1005
1006 static inline void windowref_addref(windowref_t *ref)
1007 {
1008     InterlockedIncrement(&ref->ref);
1009 }
1010
1011 static inline void windowref_release(windowref_t *ref)
1012 {
1013     if(!InterlockedDecrement(&ref->ref))
1014         heap_free(ref);
1015 }
1016
1017 HDC get_display_dc(void) DECLSPEC_HIDDEN;
1018 HINSTANCE get_shdoclc(void) DECLSPEC_HIDDEN;
1019 void set_statustext(HTMLDocumentObj*,INT,LPCWSTR) DECLSPEC_HIDDEN;
1020
1021 extern HINSTANCE hInst DECLSPEC_HIDDEN;