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