mshtml: Added history update notification support.
[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     IHTMLWindow6       IHTMLWindow6_iface;
295     IHTMLPrivateWindow IHTMLPrivateWindow_iface;
296     IDispatchEx        IDispatchEx_iface;
297     IServiceProvider   IServiceProvider_iface;
298     ITravelLogClient   ITravelLogClient_iface;
299
300     LONG ref;
301
302     windowref_t *window_ref;
303     LONG task_magic;
304
305     HTMLDocumentNode *doc;
306     HTMLDocumentObj *doc_obj;
307     nsIDOMWindow *nswindow;
308     HTMLWindow *parent;
309     HTMLFrameBase *frame_element;
310     READYSTATE readystate;
311
312     nsChannelBSC *bscallback;
313     IMoniker *mon;
314     IUri *uri;
315     BSTR url;
316
317     IHTMLEventObj *event;
318
319     SCRIPTMODE scriptmode;
320     struct list script_hosts;
321
322     IInternetSecurityManager *secmgr;
323
324     HTMLOptionElementFactory *option_factory;
325     HTMLImageElementFactory *image_factory;
326     HTMLLocation *location;
327     IHTMLScreen *screen;
328
329     global_prop_t *global_props;
330     DWORD global_prop_cnt;
331     DWORD global_prop_size;
332
333     struct list children;
334     struct list sibling_entry;
335     struct list entry;
336 };
337
338 typedef enum {
339     UNKNOWN_USERMODE,
340     BROWSEMODE,
341     EDITMODE        
342 } USERMODE;
343
344 typedef struct _cp_static_data_t {
345     tid_t tid;
346     void (*on_advise)(IUnknown*,struct _cp_static_data_t*);
347     DWORD id_cnt;
348     DISPID *ids;
349 } cp_static_data_t;
350
351 typedef struct ConnectionPointContainer {
352     IConnectionPointContainer IConnectionPointContainer_iface;
353
354     ConnectionPoint *cp_list;
355     IUnknown *outer;
356     struct ConnectionPointContainer *forward_container;
357 } ConnectionPointContainer;
358
359 struct ConnectionPoint {
360     IConnectionPoint IConnectionPoint_iface;
361
362     ConnectionPointContainer *container;
363
364     union {
365         IUnknown *unk;
366         IDispatch *disp;
367         IPropertyNotifySink *propnotif;
368     } *sinks;
369     DWORD sinks_size;
370
371     const IID *iid;
372     cp_static_data_t *data;
373
374     ConnectionPoint *next;
375 };
376
377 struct HTMLDocument {
378     IHTMLDocument2              IHTMLDocument2_iface;
379     IHTMLDocument3              IHTMLDocument3_iface;
380     IHTMLDocument4              IHTMLDocument4_iface;
381     IHTMLDocument5              IHTMLDocument5_iface;
382     IHTMLDocument6              IHTMLDocument6_iface;
383     IPersistMoniker             IPersistMoniker_iface;
384     IPersistFile                IPersistFile_iface;
385     IPersistHistory             IPersistHistory_iface;
386     IMonikerProp                IMonikerProp_iface;
387     IOleObject                  IOleObject_iface;
388     IOleDocument                IOleDocument_iface;
389     IOleDocumentView            IOleDocumentView_iface;
390     IOleInPlaceActiveObject     IOleInPlaceActiveObject_iface;
391     IViewObjectEx               IViewObjectEx_iface;
392     IOleInPlaceObjectWindowless IOleInPlaceObjectWindowless_iface;
393     IServiceProvider            IServiceProvider_iface;
394     IOleCommandTarget           IOleCommandTarget_iface;
395     IOleControl                 IOleControl_iface;
396     IHlinkTarget                IHlinkTarget_iface;
397     IPersistStreamInit          IPersistStreamInit_iface;
398     IDispatchEx                 IDispatchEx_iface;
399     ISupportErrorInfo           ISupportErrorInfo_iface;
400     IObjectWithSite             IObjectWithSite_iface;
401     IOleContainer               IOleContainer_iface;
402     IObjectSafety               IObjectSafety_iface;
403     IProvideClassInfo           IProvideClassInfo_iface;
404
405     IUnknown *unk_impl;
406     IDispatchEx *dispex;
407
408     HTMLDocumentObj *doc_obj;
409     HTMLDocumentNode *doc_node;
410
411     HTMLWindow *window;
412
413     LONG task_magic;
414
415     ConnectionPointContainer cp_container;
416     ConnectionPoint cp_htmldocevents;
417     ConnectionPoint cp_htmldocevents2;
418     ConnectionPoint cp_propnotif;
419     ConnectionPoint cp_dispatch;
420
421     IOleAdviseHolder *advise_holder;
422 };
423
424 static inline HRESULT htmldoc_query_interface(HTMLDocument *This, REFIID riid, void **ppv)
425 {
426     return IUnknown_QueryInterface(This->unk_impl, riid, ppv);
427 }
428
429 static inline ULONG htmldoc_addref(HTMLDocument *This)
430 {
431     return IUnknown_AddRef(This->unk_impl);
432 }
433
434 static inline ULONG htmldoc_release(HTMLDocument *This)
435 {
436     return IUnknown_Release(This->unk_impl);
437 }
438
439 struct HTMLDocumentObj {
440     HTMLDocument basedoc;
441     DispatchEx dispex;
442     ICustomDoc ICustomDoc_iface;
443     ITargetContainer ITargetContainer_iface;
444
445     LONG ref;
446
447     NSContainer *nscontainer;
448
449     IOleClientSite *client;
450     IDocHostUIHandler *hostui;
451     BOOL custom_hostui;
452     IOleInPlaceSite *ipsite;
453     IOleInPlaceFrame *frame;
454     IOleInPlaceUIWindow *ip_window;
455     IAdviseSink *view_sink;
456     IDocObjectService *doc_object_service;
457
458     DOCHOSTUIINFO hostinfo;
459
460     IOleUndoManager *undomgr;
461
462     HWND hwnd;
463     HWND tooltips_hwnd;
464
465     BOOL request_uiactivate;
466     BOOL in_place_active;
467     BOOL ui_active;
468     BOOL window_active;
469     BOOL hostui_setup;
470     BOOL is_webbrowser;
471     BOOL container_locked;
472     BOOL focus;
473     BOOL has_popup;
474     INT download_state;
475
476     USERMODE usermode;
477     LPWSTR mime;
478
479     DWORD update;
480 };
481
482 typedef struct nsWeakReference nsWeakReference;
483
484 struct NSContainer {
485     nsIWebBrowserChrome      nsIWebBrowserChrome_iface;
486     nsIContextMenuListener   nsIContextMenuListener_iface;
487     nsIURIContentListener    nsIURIContentListener_iface;
488     nsIEmbeddingSiteWindow   nsIEmbeddingSiteWindow_iface;
489     nsITooltipListener       nsITooltipListener_iface;
490     nsIInterfaceRequestor    nsIInterfaceRequestor_iface;
491     nsISupportsWeakReference nsISupportsWeakReference_iface;
492
493     nsIWebBrowser *webbrowser;
494     nsIWebNavigation *navigation;
495     nsIBaseWindow *window;
496     nsIWebBrowserFocus *focus;
497
498     nsIEditor *editor;
499     nsIController *editor_controller;
500
501     LONG ref;
502
503     nsWeakReference *weak_reference;
504
505     NSContainer *parent;
506     HTMLDocumentObj *doc;
507
508     nsIURIContentListener *content_listener;
509
510     HWND hwnd;
511 };
512
513 typedef struct {
514     HRESULT (*qi)(HTMLDOMNode*,REFIID,void**);
515     void (*destructor)(HTMLDOMNode*);
516     HRESULT (*clone)(HTMLDOMNode*,nsIDOMNode*,HTMLDOMNode**);
517     HRESULT (*get_attr_col)(HTMLDOMNode*,HTMLAttributeCollection**);
518     event_target_t **(*get_event_target)(HTMLDOMNode*);
519     HRESULT (*fire_event)(HTMLDOMNode*,DWORD,BOOL*);
520     HRESULT (*handle_event)(HTMLDOMNode*,DWORD,BOOL*);
521     HRESULT (*put_disabled)(HTMLDOMNode*,VARIANT_BOOL);
522     HRESULT (*get_disabled)(HTMLDOMNode*,VARIANT_BOOL*);
523     HRESULT (*get_document)(HTMLDOMNode*,IDispatch**);
524     HRESULT (*get_readystate)(HTMLDOMNode*,BSTR*);
525     HRESULT (*get_dispid)(HTMLDOMNode*,BSTR,DWORD,DISPID*);
526     HRESULT (*invoke)(HTMLDOMNode*,DISPID,LCID,WORD,DISPPARAMS*,VARIANT*,EXCEPINFO*,IServiceProvider*);
527     HRESULT (*bind_to_tree)(HTMLDOMNode*);
528 } NodeImplVtbl;
529
530 struct HTMLDOMNode {
531     DispatchEx dispex;
532     IHTMLDOMNode  IHTMLDOMNode_iface;
533     IHTMLDOMNode2 IHTMLDOMNode2_iface;
534     const NodeImplVtbl *vtbl;
535
536     LONG ref;
537
538     nsIDOMNode *nsnode;
539     HTMLDocumentNode *doc;
540     event_target_t *event_target;
541     ConnectionPointContainer *cp_container;
542
543     HTMLDOMNode *next;
544 };
545
546 typedef struct {
547     HTMLDOMNode node;
548     ConnectionPointContainer cp_container;
549
550     IHTMLElement  IHTMLElement_iface;
551     IHTMLElement2 IHTMLElement2_iface;
552     IHTMLElement3 IHTMLElement3_iface;
553     IHTMLElement4 IHTMLElement4_iface;
554
555     nsIDOMHTMLElement *nselem;
556     HTMLStyle *style;
557     HTMLAttributeCollection *attrs;
558 } HTMLElement;
559
560 #define HTMLELEMENT_TIDS    \
561     IHTMLDOMNode_tid,       \
562     IHTMLDOMNode2_tid,      \
563     IHTMLElement_tid,       \
564     IHTMLElement2_tid,      \
565     IHTMLElement3_tid,      \
566     IHTMLElement4_tid
567
568 typedef struct {
569     HTMLElement element;
570
571     IHTMLTextContainer IHTMLTextContainer_iface;
572
573     ConnectionPoint cp;
574 } HTMLTextContainer;
575
576 struct HTMLFrameBase {
577     HTMLElement element;
578
579     IHTMLFrameBase  IHTMLFrameBase_iface;
580     IHTMLFrameBase2 IHTMLFrameBase2_iface;
581
582     HTMLWindow *content_window;
583
584     nsIDOMHTMLFrameElement *nsframe;
585     nsIDOMHTMLIFrameElement *nsiframe;
586 };
587
588 typedef struct nsDocumentEventListener nsDocumentEventListener;
589
590 struct HTMLDocumentNode {
591     HTMLDOMNode node;
592     HTMLDocument basedoc;
593
594     IInternetHostSecurityManager IInternetHostSecurityManager_iface;
595
596     nsIDocumentObserver          nsIDocumentObserver_iface;
597
598     LONG ref;
599
600     nsIDOMHTMLDocument *nsdoc;
601     HTMLDOMNode *nodes;
602     BOOL content_ready;
603     event_target_t *body_event_target;
604
605     ICatInformation *catmgr;
606     nsDocumentEventListener *nsevent_listener;
607     BOOL *event_vector;
608
609     WCHAR **elem_vars;
610     unsigned elem_vars_size;
611     unsigned elem_vars_cnt;
612
613     BOOL skip_mutation_notif;
614
615     struct list bindings;
616     struct list selection_list;
617     struct list range_list;
618     struct list plugin_hosts;
619 };
620
621 HRESULT HTMLDocument_Create(IUnknown*,REFIID,void**) DECLSPEC_HIDDEN;
622 HRESULT HTMLLoadOptions_Create(IUnknown*,REFIID,void**) DECLSPEC_HIDDEN;
623 HRESULT create_doc_from_nsdoc(nsIDOMHTMLDocument*,HTMLDocumentObj*,HTMLWindow*,HTMLDocumentNode**) DECLSPEC_HIDDEN;
624 HRESULT create_document_fragment(nsIDOMNode*,HTMLDocumentNode*,HTMLDocumentNode**) DECLSPEC_HIDDEN;
625
626 HRESULT HTMLWindow_Create(HTMLDocumentObj*,nsIDOMWindow*,HTMLWindow*,HTMLWindow**) DECLSPEC_HIDDEN;
627 void update_window_doc(HTMLWindow*) DECLSPEC_HIDDEN;
628 HTMLWindow *nswindow_to_window(const nsIDOMWindow*) DECLSPEC_HIDDEN;
629 HTMLOptionElementFactory *HTMLOptionElementFactory_Create(HTMLWindow*) DECLSPEC_HIDDEN;
630 HTMLImageElementFactory *HTMLImageElementFactory_Create(HTMLWindow*) DECLSPEC_HIDDEN;
631 HRESULT HTMLLocation_Create(HTMLWindow*,HTMLLocation**) DECLSPEC_HIDDEN;
632 IOmNavigator *OmNavigator_Create(void) DECLSPEC_HIDDEN;
633 HRESULT HTMLScreen_Create(IHTMLScreen**) DECLSPEC_HIDDEN;
634
635 void HTMLDocument_HTMLDocument3_Init(HTMLDocument*) DECLSPEC_HIDDEN;
636 void HTMLDocument_HTMLDocument5_Init(HTMLDocument*) DECLSPEC_HIDDEN;
637 void HTMLDocument_Persist_Init(HTMLDocument*) DECLSPEC_HIDDEN;
638 void HTMLDocument_OleCmd_Init(HTMLDocument*) DECLSPEC_HIDDEN;
639 void HTMLDocument_OleObj_Init(HTMLDocument*) DECLSPEC_HIDDEN;
640 void HTMLDocument_View_Init(HTMLDocument*) DECLSPEC_HIDDEN;
641 void HTMLDocument_Window_Init(HTMLDocument*) DECLSPEC_HIDDEN;
642 void HTMLDocument_Service_Init(HTMLDocument*) DECLSPEC_HIDDEN;
643 void HTMLDocument_Hlink_Init(HTMLDocument*) DECLSPEC_HIDDEN;
644
645 void TargetContainer_Init(HTMLDocumentObj*) DECLSPEC_HIDDEN;
646
647 void HTMLDocumentNode_SecMgr_Init(HTMLDocumentNode*) DECLSPEC_HIDDEN;
648
649 HRESULT HTMLCurrentStyle_Create(HTMLElement*,IHTMLCurrentStyle**) DECLSPEC_HIDDEN;
650
651 void ConnectionPoint_Init(ConnectionPoint*,ConnectionPointContainer*,REFIID,cp_static_data_t*) DECLSPEC_HIDDEN;
652 void ConnectionPointContainer_Init(ConnectionPointContainer*,IUnknown*) DECLSPEC_HIDDEN;
653 void ConnectionPointContainer_Destroy(ConnectionPointContainer*) DECLSPEC_HIDDEN;
654
655 HRESULT create_nscontainer(HTMLDocumentObj*,NSContainer*,NSContainer**) DECLSPEC_HIDDEN;
656 void NSContainer_Release(NSContainer*) DECLSPEC_HIDDEN;
657 nsresult create_chrome_window(nsIWebBrowserChrome*,nsIWebBrowserChrome**) DECLSPEC_HIDDEN;
658
659 void init_mutation(nsIComponentManager*) DECLSPEC_HIDDEN;
660 void init_document_mutation(HTMLDocumentNode*) DECLSPEC_HIDDEN;
661 void release_document_mutation(HTMLDocumentNode*) DECLSPEC_HIDDEN;
662
663 void HTMLDocument_LockContainer(HTMLDocumentObj*,BOOL) DECLSPEC_HIDDEN;
664 void show_context_menu(HTMLDocumentObj*,DWORD,POINT*,IDispatch*) DECLSPEC_HIDDEN;
665 void notif_focus(HTMLDocumentObj*) DECLSPEC_HIDDEN;
666
667 void show_tooltip(HTMLDocumentObj*,DWORD,DWORD,LPCWSTR) DECLSPEC_HIDDEN;
668 void hide_tooltip(HTMLDocumentObj*) DECLSPEC_HIDDEN;
669 HRESULT get_client_disp_property(IOleClientSite*,DISPID,VARIANT*) DECLSPEC_HIDDEN;
670
671 HRESULT ProtocolFactory_Create(REFCLSID,REFIID,void**) DECLSPEC_HIDDEN;
672
673 BOOL load_gecko(BOOL) DECLSPEC_HIDDEN;
674 void close_gecko(void) DECLSPEC_HIDDEN;
675 void register_nsservice(nsIComponentRegistrar*,nsIServiceManager*) DECLSPEC_HIDDEN;
676 void init_nsio(nsIComponentManager*,nsIComponentRegistrar*) DECLSPEC_HIDDEN;
677 void release_nsio(void) DECLSPEC_HIDDEN;
678 BOOL is_gecko_path(const char*) DECLSPEC_HIDDEN;
679
680 HRESULT nsuri_to_url(LPCWSTR,BOOL,BSTR*) DECLSPEC_HIDDEN;
681 BOOL compare_ignoring_frag(IUri*,IUri*) DECLSPEC_HIDDEN;
682
683 HRESULT navigate_url(HTMLWindow*,const WCHAR*,const WCHAR*) DECLSPEC_HIDDEN;
684 HRESULT set_frame_doc(HTMLFrameBase*,nsIDOMDocument*) DECLSPEC_HIDDEN;
685
686 void call_property_onchanged(ConnectionPoint*,DISPID) DECLSPEC_HIDDEN;
687 HRESULT call_set_active_object(IOleInPlaceUIWindow*,IOleInPlaceActiveObject*) DECLSPEC_HIDDEN;
688
689 void *nsalloc(size_t) __WINE_ALLOC_SIZE(1) DECLSPEC_HIDDEN;
690 void nsfree(void*) DECLSPEC_HIDDEN;
691
692 void nsACString_InitDepend(nsACString*,const char*) DECLSPEC_HIDDEN;
693 void nsACString_SetData(nsACString*,const char*) DECLSPEC_HIDDEN;
694 PRUint32 nsACString_GetData(const nsACString*,const char**) DECLSPEC_HIDDEN;
695 void nsACString_Finish(nsACString*) DECLSPEC_HIDDEN;
696
697 BOOL nsAString_Init(nsAString*,const PRUnichar*) DECLSPEC_HIDDEN;
698 void nsAString_InitDepend(nsAString*,const PRUnichar*) DECLSPEC_HIDDEN;
699 void nsAString_SetData(nsAString*,const PRUnichar*) DECLSPEC_HIDDEN;
700 PRUint32 nsAString_GetData(const nsAString*,const PRUnichar**) DECLSPEC_HIDDEN;
701 void nsAString_Finish(nsAString*) DECLSPEC_HIDDEN;
702 HRESULT return_nsstr(nsresult,nsAString*,BSTR*) DECLSPEC_HIDDEN;
703
704 nsICommandParams *create_nscommand_params(void) DECLSPEC_HIDDEN;
705 HRESULT nsnode_to_nsstring(nsIDOMNode*,nsAString*) DECLSPEC_HIDDEN;
706 void get_editor_controller(NSContainer*) DECLSPEC_HIDDEN;
707 nsresult get_nsinterface(nsISupports*,REFIID,void**) DECLSPEC_HIDDEN;
708
709 void set_window_bscallback(HTMLWindow*,nsChannelBSC*) DECLSPEC_HIDDEN;
710 void set_current_mon(HTMLWindow*,IMoniker*) DECLSPEC_HIDDEN;
711 void set_current_uri(HTMLWindow*,IUri*) DECLSPEC_HIDDEN;
712 HRESULT start_binding(HTMLWindow*,HTMLDocumentNode*,BSCallback*,IBindCtx*) DECLSPEC_HIDDEN;
713 HRESULT async_start_doc_binding(HTMLWindow*,nsChannelBSC*) DECLSPEC_HIDDEN;
714 void abort_document_bindings(HTMLDocumentNode*) DECLSPEC_HIDDEN;
715 void set_download_state(HTMLDocumentObj*,int) DECLSPEC_HIDDEN;
716
717 HRESULT bind_mon_to_buffer(HTMLDocumentNode*,IMoniker*,void**,DWORD*) DECLSPEC_HIDDEN;
718
719 void set_ready_state(HTMLWindow*,READYSTATE) DECLSPEC_HIDDEN;
720
721 HRESULT HTMLSelectionObject_Create(HTMLDocumentNode*,nsISelection*,IHTMLSelectionObject**) DECLSPEC_HIDDEN;
722 HRESULT HTMLTxtRange_Create(HTMLDocumentNode*,nsIDOMRange*,IHTMLTxtRange**) DECLSPEC_HIDDEN;
723 HRESULT HTMLStyle_Create(nsIDOMCSSStyleDeclaration*,HTMLStyle**) DECLSPEC_HIDDEN;
724 IHTMLStyleSheet *HTMLStyleSheet_Create(nsIDOMStyleSheet*) DECLSPEC_HIDDEN;
725 IHTMLStyleSheetsCollection *HTMLStyleSheetsCollection_Create(nsIDOMStyleSheetList*) DECLSPEC_HIDDEN;
726
727 void detach_selection(HTMLDocumentNode*) DECLSPEC_HIDDEN;
728 void detach_ranges(HTMLDocumentNode*) DECLSPEC_HIDDEN;
729 HRESULT get_node_text(HTMLDOMNode*,BSTR*) DECLSPEC_HIDDEN;
730 HRESULT replace_node_by_html(nsIDOMHTMLDocument*,nsIDOMNode*,const WCHAR*) DECLSPEC_HIDDEN;
731
732 HRESULT create_nselem(HTMLDocumentNode*,const WCHAR*,nsIDOMHTMLElement**) DECLSPEC_HIDDEN;
733
734 HRESULT HTMLDOMTextNode_Create(HTMLDocumentNode*,nsIDOMNode*,HTMLDOMNode**) DECLSPEC_HIDDEN;
735
736 struct HTMLAttributeCollection {
737     DispatchEx dispex;
738     IHTMLAttributeCollection IHTMLAttributeCollection_iface;
739     IHTMLAttributeCollection2 IHTMLAttributeCollection2_iface;
740     IHTMLAttributeCollection3 IHTMLAttributeCollection3_iface;
741
742     LONG ref;
743
744     HTMLElement *elem;
745     struct list attrs;
746 };
747
748 typedef struct {
749     DispatchEx dispex;
750     IHTMLDOMAttribute IHTMLDOMAttribute_iface;
751
752     LONG ref;
753
754     DISPID dispid;
755     HTMLElement *elem;
756     struct list entry;
757 } HTMLDOMAttribute;
758
759 HRESULT HTMLDOMAttribute_Create(HTMLElement*,DISPID,HTMLDOMAttribute**) DECLSPEC_HIDDEN;
760
761 HRESULT HTMLElement_Create(HTMLDocumentNode*,nsIDOMNode*,BOOL,HTMLElement**) DECLSPEC_HIDDEN;
762 HRESULT HTMLCommentElement_Create(HTMLDocumentNode*,nsIDOMNode*,HTMLElement**) DECLSPEC_HIDDEN;
763 HRESULT HTMLAnchorElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**) DECLSPEC_HIDDEN;
764 HRESULT HTMLBodyElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**) DECLSPEC_HIDDEN;
765 HRESULT HTMLEmbedElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**) DECLSPEC_HIDDEN;
766 HRESULT HTMLFormElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**) DECLSPEC_HIDDEN;
767 HRESULT HTMLFrameElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**) DECLSPEC_HIDDEN;
768 HRESULT HTMLHeadElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**) DECLSPEC_HIDDEN;
769 HRESULT HTMLIFrame_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**) DECLSPEC_HIDDEN;
770 HRESULT HTMLStyleElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**) DECLSPEC_HIDDEN;
771 HRESULT HTMLImgElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**) DECLSPEC_HIDDEN;
772 HRESULT HTMLInputElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**) DECLSPEC_HIDDEN;
773 HRESULT HTMLObjectElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**) DECLSPEC_HIDDEN;
774 HRESULT HTMLOptionElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**) DECLSPEC_HIDDEN;
775 HRESULT HTMLScriptElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**) DECLSPEC_HIDDEN;
776 HRESULT HTMLSelectElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**) DECLSPEC_HIDDEN;
777 HRESULT HTMLTable_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**) DECLSPEC_HIDDEN;
778 HRESULT HTMLTableRow_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**) DECLSPEC_HIDDEN;
779 HRESULT HTMLTextAreaElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**) DECLSPEC_HIDDEN;
780 HRESULT HTMLTitleElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**) DECLSPEC_HIDDEN;
781 HRESULT HTMLGenericElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**) DECLSPEC_HIDDEN;
782
783 void HTMLDOMNode_Init(HTMLDocumentNode*,HTMLDOMNode*,nsIDOMNode*) DECLSPEC_HIDDEN;
784 void HTMLElement_Init(HTMLElement*,HTMLDocumentNode*,nsIDOMHTMLElement*,dispex_static_data_t*) DECLSPEC_HIDDEN;
785 void HTMLElement2_Init(HTMLElement*) DECLSPEC_HIDDEN;
786 void HTMLElement3_Init(HTMLElement*) DECLSPEC_HIDDEN;
787 void HTMLTextContainer_Init(HTMLTextContainer*,HTMLDocumentNode*,nsIDOMHTMLElement*,dispex_static_data_t*) DECLSPEC_HIDDEN;
788 void HTMLFrameBase_Init(HTMLFrameBase*,HTMLDocumentNode*,nsIDOMHTMLElement*,dispex_static_data_t*) DECLSPEC_HIDDEN;
789
790 HRESULT HTMLDOMNode_QI(HTMLDOMNode*,REFIID,void**) DECLSPEC_HIDDEN;
791 void HTMLDOMNode_destructor(HTMLDOMNode*) DECLSPEC_HIDDEN;
792
793 HRESULT HTMLElement_QI(HTMLDOMNode*,REFIID,void**) DECLSPEC_HIDDEN;
794 void HTMLElement_destructor(HTMLDOMNode*) DECLSPEC_HIDDEN;
795 HRESULT HTMLElement_clone(HTMLDOMNode*,nsIDOMNode*,HTMLDOMNode**) DECLSPEC_HIDDEN;
796 HRESULT HTMLElement_get_attr_col(HTMLDOMNode*,HTMLAttributeCollection**) DECLSPEC_HIDDEN;
797
798 HRESULT HTMLFrameBase_QI(HTMLFrameBase*,REFIID,void**) DECLSPEC_HIDDEN;
799 void HTMLFrameBase_destructor(HTMLFrameBase*) DECLSPEC_HIDDEN;
800
801 HRESULT get_node(HTMLDocumentNode*,nsIDOMNode*,BOOL,HTMLDOMNode**) DECLSPEC_HIDDEN;
802 void release_nodes(HTMLDocumentNode*) DECLSPEC_HIDDEN;
803
804 void release_script_hosts(HTMLWindow*) DECLSPEC_HIDDEN;
805 void connect_scripts(HTMLWindow*) DECLSPEC_HIDDEN;
806 void doc_insert_script(HTMLWindow*,nsIDOMHTMLScriptElement*) DECLSPEC_HIDDEN;
807 IDispatch *script_parse_event(HTMLWindow*,LPCWSTR) DECLSPEC_HIDDEN;
808 HRESULT exec_script(HTMLWindow*,const WCHAR*,const WCHAR*,VARIANT*) DECLSPEC_HIDDEN;
809 void set_script_mode(HTMLWindow*,SCRIPTMODE) DECLSPEC_HIDDEN;
810 BOOL find_global_prop(HTMLWindow*,BSTR,DWORD,ScriptHost**,DISPID*) DECLSPEC_HIDDEN;
811 IDispatch *get_script_disp(ScriptHost*) DECLSPEC_HIDDEN;
812 HRESULT search_window_props(HTMLWindow*,BSTR,DWORD,DISPID*) DECLSPEC_HIDDEN;
813
814 HRESULT wrap_iface(IUnknown*,IUnknown*,IUnknown**) DECLSPEC_HIDDEN;
815
816 IHTMLElementCollection *create_all_collection(HTMLDOMNode*,BOOL) DECLSPEC_HIDDEN;
817 IHTMLElementCollection *create_collection_from_nodelist(HTMLDocumentNode*,IUnknown*,nsIDOMNodeList*) DECLSPEC_HIDDEN;
818 IHTMLElementCollection *create_collection_from_htmlcol(HTMLDocumentNode*,IUnknown*,nsIDOMHTMLCollection*) DECLSPEC_HIDDEN;
819
820 /* commands */
821 typedef struct {
822     DWORD id;
823     HRESULT (*query)(HTMLDocument*,OLECMD*);
824     HRESULT (*exec)(HTMLDocument*,DWORD,VARIANT*,VARIANT*);
825 } cmdtable_t;
826
827 extern const cmdtable_t editmode_cmds[] DECLSPEC_HIDDEN;
828
829 void do_ns_command(HTMLDocument*,const char*,nsICommandParams*) DECLSPEC_HIDDEN;
830
831 /* timer */
832 #define UPDATE_UI       0x0001
833 #define UPDATE_TITLE    0x0002
834
835 void update_doc(HTMLDocument*,DWORD) DECLSPEC_HIDDEN;
836 void update_title(HTMLDocumentObj*) DECLSPEC_HIDDEN;
837
838 HRESULT do_query_service(IUnknown*,REFGUID,REFIID,void**) DECLSPEC_HIDDEN;
839
840 /* editor */
841 void init_editor(HTMLDocument*) DECLSPEC_HIDDEN;
842 void handle_edit_event(HTMLDocument*,nsIDOMEvent*) DECLSPEC_HIDDEN;
843 HRESULT editor_exec_copy(HTMLDocument*,DWORD,VARIANT*,VARIANT*) DECLSPEC_HIDDEN;
844 HRESULT editor_exec_cut(HTMLDocument*,DWORD,VARIANT*,VARIANT*) DECLSPEC_HIDDEN;
845 HRESULT editor_exec_paste(HTMLDocument*,DWORD,VARIANT*,VARIANT*) DECLSPEC_HIDDEN;
846 void handle_edit_load(HTMLDocument*) DECLSPEC_HIDDEN;
847 HRESULT editor_is_dirty(HTMLDocument*) DECLSPEC_HIDDEN;
848 void set_dirty(HTMLDocument*,VARIANT_BOOL) DECLSPEC_HIDDEN;
849
850 extern DWORD mshtml_tls DECLSPEC_HIDDEN;
851
852 typedef struct task_t task_t;
853 typedef void (*task_proc_t)(task_t*);
854
855 struct task_t {
856     LONG target_magic;
857     task_proc_t proc;
858     task_proc_t destr;
859     struct task_t *next;
860 };
861
862 typedef struct {
863     task_t header;
864     HTMLDocumentObj *doc;
865 } docobj_task_t;
866
867 typedef struct {
868     HWND thread_hwnd;
869     task_t *task_queue_head;
870     task_t *task_queue_tail;
871     struct list timer_list;
872 } thread_data_t;
873
874 thread_data_t *get_thread_data(BOOL) DECLSPEC_HIDDEN;
875 HWND get_thread_hwnd(void) DECLSPEC_HIDDEN;
876
877 LONG get_task_target_magic(void) DECLSPEC_HIDDEN;
878 void push_task(task_t*,task_proc_t,task_proc_t,LONG) DECLSPEC_HIDDEN;
879 void remove_target_tasks(LONG) DECLSPEC_HIDDEN;
880
881 DWORD set_task_timer(HTMLDocument*,DWORD,BOOL,IDispatch*) DECLSPEC_HIDDEN;
882 HRESULT clear_task_timer(HTMLDocument*,BOOL,DWORD) DECLSPEC_HIDDEN;
883
884 const char *debugstr_variant(const VARIANT*) DECLSPEC_HIDDEN;
885
886 DEFINE_GUID(CLSID_AboutProtocol, 0x3050F406, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
887 DEFINE_GUID(CLSID_JSProtocol, 0x3050F3B2, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
888 DEFINE_GUID(CLSID_MailtoProtocol, 0x3050F3DA, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
889 DEFINE_GUID(CLSID_ResProtocol, 0x3050F3BC, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
890 DEFINE_GUID(CLSID_SysimageProtocol, 0x76E67A63, 0x06E9, 0x11D2, 0xA8,0x40, 0x00,0x60,0x08,0x05,0x93,0x82);
891
892 DEFINE_GUID(CLSID_CMarkup,0x3050f4fb,0x98b5,0x11cf,0xbb,0x82,0x00,0xaa,0x00,0xbd,0xce,0x0b);
893
894 DEFINE_OLEGUID(CGID_DocHostCmdPriv, 0x000214D4L, 0, 0);
895
896 /* memory allocation functions */
897
898 static inline void * __WINE_ALLOC_SIZE(1) heap_alloc(size_t len)
899 {
900     return HeapAlloc(GetProcessHeap(), 0, len);
901 }
902
903 static inline void * __WINE_ALLOC_SIZE(1) heap_alloc_zero(size_t len)
904 {
905     return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
906 }
907
908 static inline void * __WINE_ALLOC_SIZE(2) heap_realloc(void *mem, size_t len)
909 {
910     return HeapReAlloc(GetProcessHeap(), 0, mem, len);
911 }
912
913 static inline void * __WINE_ALLOC_SIZE(2) heap_realloc_zero(void *mem, size_t len)
914 {
915     return HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, mem, len);
916 }
917
918 static inline BOOL heap_free(void *mem)
919 {
920     return HeapFree(GetProcessHeap(), 0, mem);
921 }
922
923 static inline LPWSTR heap_strdupW(LPCWSTR str)
924 {
925     LPWSTR ret = NULL;
926
927     if(str) {
928         DWORD size;
929
930         size = (strlenW(str)+1)*sizeof(WCHAR);
931         ret = heap_alloc(size);
932         memcpy(ret, str, size);
933     }
934
935     return ret;
936 }
937
938 static inline LPWSTR heap_strndupW(LPCWSTR str, unsigned len)
939 {
940     LPWSTR ret = NULL;
941
942     if(str) {
943         ret = heap_alloc((len+1)*sizeof(WCHAR));
944         memcpy(ret, str, len*sizeof(WCHAR));
945         ret[len] = 0;
946     }
947
948     return ret;
949 }
950
951 static inline char *heap_strdupA(const char *str)
952 {
953     char *ret = NULL;
954
955     if(str) {
956         DWORD size;
957
958         size = strlen(str)+1;
959         ret = heap_alloc(size);
960         memcpy(ret, str, size);
961     }
962
963     return ret;
964 }
965
966 static inline WCHAR *heap_strdupAtoW(const char *str)
967 {
968     LPWSTR ret = NULL;
969
970     if(str) {
971         DWORD len;
972
973         len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
974         ret = heap_alloc(len*sizeof(WCHAR));
975         MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
976     }
977
978     return ret;
979 }
980
981 static inline char *heap_strdupWtoA(LPCWSTR str)
982 {
983     char *ret = NULL;
984
985     if(str) {
986         DWORD size = WideCharToMultiByte(CP_ACP, 0, str, -1, NULL, 0, NULL, NULL);
987         ret = heap_alloc(size);
988         WideCharToMultiByte(CP_ACP, 0, str, -1, ret, size, NULL, NULL);
989     }
990
991     return ret;
992 }
993
994 static inline void windowref_addref(windowref_t *ref)
995 {
996     InterlockedIncrement(&ref->ref);
997 }
998
999 static inline void windowref_release(windowref_t *ref)
1000 {
1001     if(!InterlockedDecrement(&ref->ref))
1002         heap_free(ref);
1003 }
1004
1005 HDC get_display_dc(void) DECLSPEC_HIDDEN;
1006 HINSTANCE get_shdoclc(void) DECLSPEC_HIDDEN;
1007 void set_statustext(HTMLDocumentObj*,INT,LPCWSTR) DECLSPEC_HIDDEN;
1008
1009 extern HINSTANCE hInst DECLSPEC_HIDDEN;