mshtml: Added setTimeout implementation.
[wine] / dlls / mshtml / mshtml_private.h
1 /*
2  * Copyright 2005-2006 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 "mshtml.h"
22 #include "mshtmhst.h"
23 #include "hlink.h"
24 #include "dispex.h"
25
26 #include "wine/list.h"
27 #include "wine/unicode.h"
28
29 #ifdef INIT_GUID
30 #include "initguid.h"
31 #endif
32
33 #include "nsiface.h"
34
35 #define GENERATE_MSHTML_NS_FAILURE(code) \
36     ((nsresult) ((PRUint32)(1<<31) | ((PRUint32)(0x45+6)<<16) | (PRUint32)(code)))
37
38 #define NS_OK                     ((nsresult)0x00000000L)
39 #define NS_ERROR_FAILURE          ((nsresult)0x80004005L)
40 #define NS_NOINTERFACE            ((nsresult)0x80004002L)
41 #define NS_ERROR_NOT_IMPLEMENTED  ((nsresult)0x80004001L)
42 #define NS_ERROR_INVALID_ARG      ((nsresult)0x80070057L) 
43 #define NS_ERROR_UNEXPECTED       ((nsresult)0x8000ffffL)
44 #define NS_ERROR_UNKNOWN_PROTOCOL ((nsresult)0x804b0012L)
45
46 #define WINE_NS_LOAD_FROM_MONIKER GENERATE_MSHTML_NS_FAILURE(0)
47
48 #define NS_FAILED(res) ((res) & 0x80000000)
49 #define NS_SUCCEEDED(res) (!NS_FAILED(res))
50
51 #define NSAPI WINAPI
52
53 #define MSHTML_E_NODOC    0x800a025c
54
55 typedef struct HTMLDOMNode HTMLDOMNode;
56 typedef struct ConnectionPoint ConnectionPoint;
57 typedef struct BSCallback BSCallback;
58 typedef struct nsChannelBSC nsChannelBSC;
59 typedef struct event_target_t event_target_t;
60
61 /* NOTE: make sure to keep in sync with dispex.c */
62 typedef enum {
63     NULL_tid,
64     DispHTMLWindow2_tid,
65     IHTMLWindow2_tid,
66     IHTMLWindow3_tid,
67     IOmNavigator_tid,
68     LAST_tid
69 } tid_t;
70
71 typedef struct dispex_data_t dispex_data_t;
72
73 typedef struct {
74     const tid_t disp_tid;
75     dispex_data_t *data;
76     const tid_t iface_tids[];
77 } dispex_static_data_t;
78
79 typedef struct {
80     const IDispatchExVtbl  *lpIDispatchExVtbl;
81
82     IUnknown *outer;
83
84     dispex_static_data_t *data;
85 } DispatchEx;
86
87 void init_dispex(DispatchEx*,IUnknown*,dispex_static_data_t*);
88
89 typedef struct {
90     DispatchEx dispex;
91     const IHTMLWindow2Vtbl *lpHTMLWindow2Vtbl;
92     const IHTMLWindow3Vtbl *lpHTMLWindow3Vtbl;
93     const IDispatchExVtbl  *lpIDispatchExVtbl;
94
95     LONG ref;
96
97     HTMLDocument *doc;
98     nsIDOMWindow *nswindow;
99
100     IHTMLEventObj *event;
101
102     struct list entry;
103 } HTMLWindow;
104
105 typedef enum {
106     UNKNOWN_USERMODE,
107     BROWSEMODE,
108     EDITMODE        
109 } USERMODE;
110
111 typedef struct {
112     const IConnectionPointContainerVtbl  *lpConnectionPointContainerVtbl;
113
114     ConnectionPoint *cp_list;
115     IUnknown *outer;
116 } ConnectionPointContainer;
117
118 struct ConnectionPoint {
119     const IConnectionPointVtbl *lpConnectionPointVtbl;
120
121     IConnectionPointContainer *container;
122
123     union {
124         IUnknown *unk;
125         IDispatch *disp;
126         IPropertyNotifySink *propnotif;
127     } *sinks;
128     DWORD sinks_size;
129
130     const IID *iid;
131
132     ConnectionPoint *next;
133 };
134
135 typedef struct {
136     const IHTMLLocationVtbl *lpHTMLLocationVtbl;
137
138     LONG ref;
139
140     HTMLDocument *doc;
141 } HTMLLocation;
142
143 typedef struct {
144     const IHTMLOptionElementFactoryVtbl *lpHTMLOptionElementFactoryVtbl;
145
146     LONG ref;
147
148     HTMLDocument *doc;
149 } HTMLOptionElementFactory;
150
151 struct HTMLDocument {
152     const IHTMLDocument2Vtbl              *lpHTMLDocument2Vtbl;
153     const IHTMLDocument3Vtbl              *lpHTMLDocument3Vtbl;
154     const IHTMLDocument4Vtbl              *lpHTMLDocument4Vtbl;
155     const IHTMLDocument5Vtbl              *lpHTMLDocument5Vtbl;
156     const IPersistMonikerVtbl             *lpPersistMonikerVtbl;
157     const IPersistFileVtbl                *lpPersistFileVtbl;
158     const IMonikerPropVtbl                *lpMonikerPropVtbl;
159     const IOleObjectVtbl                  *lpOleObjectVtbl;
160     const IOleDocumentVtbl                *lpOleDocumentVtbl;
161     const IOleDocumentViewVtbl            *lpOleDocumentViewVtbl;
162     const IOleInPlaceActiveObjectVtbl     *lpOleInPlaceActiveObjectVtbl;
163     const IViewObject2Vtbl                *lpViewObject2Vtbl;
164     const IOleInPlaceObjectWindowlessVtbl *lpOleInPlaceObjectWindowlessVtbl;
165     const IServiceProviderVtbl            *lpServiceProviderVtbl;
166     const IOleCommandTargetVtbl           *lpOleCommandTargetVtbl;
167     const IOleControlVtbl                 *lpOleControlVtbl;
168     const IHlinkTargetVtbl                *lpHlinkTargetVtbl;
169     const IPersistStreamInitVtbl          *lpPersistStreamInitVtbl;
170     const ICustomDocVtbl                  *lpCustomDocVtbl;
171
172     LONG ref;
173
174     NSContainer *nscontainer;
175     HTMLWindow *window;
176
177     IOleClientSite *client;
178     IDocHostUIHandler *hostui;
179     IOleInPlaceSite *ipsite;
180     IOleInPlaceFrame *frame;
181     IOleInPlaceUIWindow *ip_window;
182
183     IOleUndoManager *undomgr;
184
185     nsChannelBSC *bscallback;
186     IMoniker *mon;
187     LPOLESTR url;
188     struct list bindings;
189
190     struct list script_hosts;
191
192     HWND hwnd;
193     HWND tooltips_hwnd;
194
195     DOCHOSTUIINFO hostinfo;
196
197     USERMODE usermode;
198     READYSTATE readystate;
199     BOOL in_place_active;
200     BOOL ui_active;
201     BOOL window_active;
202     BOOL has_key_path;
203     BOOL container_locked;
204     BOOL focus;
205     LPWSTR mime;
206
207     DWORD update;
208
209     ConnectionPointContainer cp_container;
210     ConnectionPoint cp_htmldocevents;
211     ConnectionPoint cp_htmldocevents2;
212     ConnectionPoint cp_propnotif;
213
214     HTMLOptionElementFactory *option_factory;
215     HTMLLocation *location;
216
217     struct list selection_list;
218     struct list range_list;
219
220     HTMLDOMNode *nodes;
221 };
222
223 typedef struct {
224     const nsIDOMEventListenerVtbl      *lpDOMEventListenerVtbl;
225     NSContainer *This;
226 } nsEventListener;
227
228 struct NSContainer {
229     const nsIWebBrowserChromeVtbl       *lpWebBrowserChromeVtbl;
230     const nsIContextMenuListenerVtbl    *lpContextMenuListenerVtbl;
231     const nsIURIContentListenerVtbl     *lpURIContentListenerVtbl;
232     const nsIEmbeddingSiteWindowVtbl    *lpEmbeddingSiteWindowVtbl;
233     const nsITooltipListenerVtbl        *lpTooltipListenerVtbl;
234     const nsIInterfaceRequestorVtbl     *lpInterfaceRequestorVtbl;
235     const nsIWeakReferenceVtbl          *lpWeakReferenceVtbl;
236     const nsISupportsWeakReferenceVtbl  *lpSupportsWeakReferenceVtbl;
237
238     nsEventListener blur_listener;
239     nsEventListener focus_listener;
240     nsEventListener keypress_listener;
241     nsEventListener load_listener;
242     nsEventListener node_insert_listener;
243
244     nsIWebBrowser *webbrowser;
245     nsIWebNavigation *navigation;
246     nsIBaseWindow *window;
247     nsIWebBrowserFocus *focus;
248
249     nsIEditor *editor;
250     nsIController *editor_controller;
251
252     LONG ref;
253
254     NSContainer *parent;
255     HTMLDocument *doc;
256
257     nsIURIContentListener *content_listener;
258
259     HWND hwnd;
260
261     nsChannelBSC *bscallback; /* hack */
262     HWND reset_focus; /* hack */
263 };
264
265 typedef struct {
266     const nsIHttpChannelVtbl *lpHttpChannelVtbl;
267     const nsIUploadChannelVtbl *lpUploadChannelVtbl;
268
269     LONG ref;
270
271     nsIChannel *channel;
272     nsIHttpChannel *http_channel;
273     nsIWineURI *uri;
274     nsIInputStream *post_data_stream;
275     nsILoadGroup *load_group;
276     nsIInterfaceRequestor *notif_callback;
277     nsLoadFlags load_flags;
278     nsIURI *original_uri;
279     char *content_type;
280     char *charset;
281 } nsChannel;
282
283 typedef struct {
284     HRESULT (*qi)(HTMLDOMNode*,REFIID,void**);
285     void (*destructor)(HTMLDOMNode*);
286 } NodeImplVtbl;
287
288 struct HTMLDOMNode {
289     const IHTMLDOMNodeVtbl *lpHTMLDOMNodeVtbl;
290     const NodeImplVtbl *vtbl;
291
292     LONG ref;
293
294     nsIDOMNode *nsnode;
295     HTMLDocument *doc;
296     event_target_t *event_target;
297
298     HTMLDOMNode *next;
299 };
300
301 typedef struct {
302     HTMLDOMNode node;
303     ConnectionPointContainer cp_container;
304
305     const IHTMLElementVtbl   *lpHTMLElementVtbl;
306     const IHTMLElement2Vtbl  *lpHTMLElement2Vtbl;
307
308     nsIDOMHTMLElement *nselem;
309 } HTMLElement;
310
311 typedef struct {
312     HTMLElement element;
313
314     const IHTMLTextContainerVtbl *lpHTMLTextContainerVtbl;
315
316     ConnectionPoint cp;
317 } HTMLTextContainer;
318
319 #define HTMLWINDOW2(x)   ((IHTMLWindow2*)                 &(x)->lpHTMLWindow2Vtbl)
320 #define HTMLWINDOW3(x)   ((IHTMLWindow3*)                 &(x)->lpHTMLWindow3Vtbl)
321
322 #define HTMLDOC(x)       ((IHTMLDocument2*)               &(x)->lpHTMLDocument2Vtbl)
323 #define HTMLDOC3(x)      ((IHTMLDocument3*)               &(x)->lpHTMLDocument3Vtbl)
324 #define HTMLDOC4(x)      ((IHTMLDocument4*)               &(x)->lpHTMLDocument4Vtbl)
325 #define HTMLDOC5(x)      ((IHTMLDocument5*)               &(x)->lpHTMLDocument5Vtbl)
326 #define PERSIST(x)       ((IPersist*)                     &(x)->lpPersistFileVtbl)
327 #define PERSISTMON(x)    ((IPersistMoniker*)              &(x)->lpPersistMonikerVtbl)
328 #define PERSISTFILE(x)   ((IPersistFile*)                 &(x)->lpPersistFileVtbl)
329 #define MONPROP(x)       ((IMonikerProp*)                 &(x)->lpMonikerPropVtbl)
330 #define OLEOBJ(x)        ((IOleObject*)                   &(x)->lpOleObjectVtbl)
331 #define OLEDOC(x)        ((IOleDocument*)                 &(x)->lpOleDocumentVtbl)
332 #define DOCVIEW(x)       ((IOleDocumentView*)             &(x)->lpOleDocumentViewVtbl)
333 #define OLEWIN(x)        ((IOleWindow*)                   &(x)->lpOleInPlaceActiveObjectVtbl)
334 #define ACTOBJ(x)        ((IOleInPlaceActiveObject*)      &(x)->lpOleInPlaceActiveObjectVtbl)
335 #define VIEWOBJ(x)       ((IViewObject*)                  &(x)->lpViewObject2Vtbl)
336 #define VIEWOBJ2(x)      ((IViewObject2*)                 &(x)->lpViewObject2Vtbl)
337 #define INPLACEOBJ(x)    ((IOleInPlaceObject*)            &(x)->lpOleInPlaceObjectWindowlessVtbl)
338 #define INPLACEWIN(x)    ((IOleInPlaceObjectWindowless*)  &(x)->lpOleInPlaceObjectWindowlessVtbl)
339 #define SERVPROV(x)      ((IServiceProvider*)             &(x)->lpServiceProviderVtbl)
340 #define CMDTARGET(x)     ((IOleCommandTarget*)            &(x)->lpOleCommandTargetVtbl)
341 #define CONTROL(x)       ((IOleControl*)                  &(x)->lpOleControlVtbl)
342 #define HLNKTARGET(x)    ((IHlinkTarget*)                 &(x)->lpHlinkTargetVtbl)
343 #define CONPTCONT(x)     ((IConnectionPointContainer*)    &(x)->lpConnectionPointContainerVtbl)
344 #define PERSTRINIT(x)    ((IPersistStreamInit*)           &(x)->lpPersistStreamInitVtbl)
345 #define CUSTOMDOC(x)     ((ICustomDoc*)                   &(x)->lpCustomDocVtbl)
346
347 #define NSWBCHROME(x)    ((nsIWebBrowserChrome*)          &(x)->lpWebBrowserChromeVtbl)
348 #define NSCML(x)         ((nsIContextMenuListener*)       &(x)->lpContextMenuListenerVtbl)
349 #define NSURICL(x)       ((nsIURIContentListener*)        &(x)->lpURIContentListenerVtbl)
350 #define NSEMBWNDS(x)     ((nsIEmbeddingSiteWindow*)       &(x)->lpEmbeddingSiteWindowVtbl)
351 #define NSIFACEREQ(x)    ((nsIInterfaceRequestor*)        &(x)->lpInterfaceRequestorVtbl)
352 #define NSTOOLTIP(x)     ((nsITooltipListener*)           &(x)->lpTooltipListenerVtbl)
353 #define NSEVENTLIST(x)   ((nsIDOMEventListener*)          &(x)->lpDOMEventListenerVtbl)
354 #define NSWEAKREF(x)     ((nsIWeakReference*)             &(x)->lpWeakReferenceVtbl)
355 #define NSSUPWEAKREF(x)  ((nsISupportsWeakReference*)     &(x)->lpSupportsWeakReferenceVtbl)
356
357 #define NSCHANNEL(x)     ((nsIChannel*)        &(x)->lpHttpChannelVtbl)
358 #define NSHTTPCHANNEL(x) ((nsIHttpChannel*)    &(x)->lpHttpChannelVtbl)
359 #define NSUPCHANNEL(x)   ((nsIUploadChannel*)  &(x)->lpUploadChannelVtbl)
360
361 #define HTTPNEG(x)       ((IHttpNegotiate2*)              &(x)->lpHttpNegotiate2Vtbl)
362 #define STATUSCLB(x)     ((IBindStatusCallback*)          &(x)->lpBindStatusCallbackVtbl)
363 #define BINDINFO(x)      ((IInternetBindInfo*)            &(x)->lpInternetBindInfoVtbl);
364
365 #define HTMLELEM(x)      ((IHTMLElement*)                 &(x)->lpHTMLElementVtbl)
366 #define HTMLELEM2(x)     ((IHTMLElement2*)                &(x)->lpHTMLElement2Vtbl)
367 #define HTMLDOMNODE(x)   ((IHTMLDOMNode*)                 &(x)->lpHTMLDOMNodeVtbl)
368
369 #define HTMLTEXTCONT(x)  ((IHTMLTextContainer*)           &(x)->lpHTMLTextContainerVtbl)
370
371 #define HTMLOPTFACTORY(x)  ((IHTMLOptionElementFactory*)  &(x)->lpHTMLOptionElementFactoryVtbl)
372 #define HTMLLOCATION(x)  ((IHTMLLocation*) &(x)->lpHTMLLocationVtbl)
373
374 #define DISPATCHEX(x)    ((IDispatchEx*) &(x)->lpIDispatchExVtbl)
375
376 #define DEFINE_THIS2(cls,ifc,iface) ((cls*)((BYTE*)(iface)-offsetof(cls,ifc)))
377 #define DEFINE_THIS(cls,ifc,iface) DEFINE_THIS2(cls,lp ## ifc ## Vtbl,iface)
378
379 HRESULT HTMLDocument_Create(IUnknown*,REFIID,void**);
380 HRESULT HTMLLoadOptions_Create(IUnknown*,REFIID,void**);
381
382 HTMLWindow *HTMLWindow_Create(HTMLDocument*);
383 HTMLWindow *nswindow_to_window(const nsIDOMWindow*);
384 HTMLOptionElementFactory *HTMLOptionElementFactory_Create(HTMLDocument*);
385 HTMLLocation *HTMLLocation_Create(HTMLDocument*);
386 IOmNavigator *OmNavigator_Create(void);
387 void setup_nswindow(HTMLWindow*);
388
389 void HTMLDocument_HTMLDocument3_Init(HTMLDocument*);
390 void HTMLDocument_HTMLDocument5_Init(HTMLDocument*);
391 void HTMLDocument_Persist_Init(HTMLDocument*);
392 void HTMLDocument_OleCmd_Init(HTMLDocument*);
393 void HTMLDocument_OleObj_Init(HTMLDocument*);
394 void HTMLDocument_View_Init(HTMLDocument*);
395 void HTMLDocument_Window_Init(HTMLDocument*);
396 void HTMLDocument_Service_Init(HTMLDocument*);
397 void HTMLDocument_Hlink_Init(HTMLDocument*);
398
399 void ConnectionPoint_Init(ConnectionPoint*,ConnectionPointContainer*,REFIID);
400 void ConnectionPointContainer_Init(ConnectionPointContainer*,IUnknown*);
401 void ConnectionPointContainer_Destroy(ConnectionPointContainer*);
402
403 NSContainer *NSContainer_Create(HTMLDocument*,NSContainer*);
404 void NSContainer_Release(NSContainer*);
405
406 void HTMLDocument_LockContainer(HTMLDocument*,BOOL);
407 void show_context_menu(HTMLDocument*,DWORD,POINT*,IDispatch*);
408 void notif_focus(HTMLDocument*);
409
410 void show_tooltip(HTMLDocument*,DWORD,DWORD,LPCWSTR);
411 void hide_tooltip(HTMLDocument*);
412 HRESULT get_client_disp_property(IOleClientSite*,DISPID,VARIANT*);
413
414 HRESULT ProtocolFactory_Create(REFCLSID,REFIID,void**);
415
416 BOOL load_gecko(BOOL);
417 void close_gecko(void);
418 void register_nsservice(nsIComponentRegistrar*,nsIServiceManager*);
419 void init_nsio(nsIComponentManager*,nsIComponentRegistrar*);
420 BOOL install_wine_gecko(BOOL);
421
422 void hlink_frame_navigate(HTMLDocument*,IHlinkFrame*,LPCWSTR,nsIInputStream*,DWORD);
423
424 void call_property_onchanged(ConnectionPoint*,DISPID);
425 HRESULT call_set_active_object(IOleInPlaceUIWindow*,IOleInPlaceActiveObject*);
426
427 void *nsalloc(size_t);
428 void nsfree(void*);
429
430 void nsACString_Init(nsACString*,const char*);
431 void nsACString_SetData(nsACString*,const char*);
432 PRUint32 nsACString_GetData(const nsACString*,const char**);
433 void nsACString_Finish(nsACString*);
434
435 void nsAString_Init(nsAString*,const PRUnichar*);
436 void nsAString_SetData(nsAString*,const PRUnichar*);
437 PRUint32 nsAString_GetData(const nsAString*,const PRUnichar**);
438 void nsAString_Finish(nsAString*);
439
440 nsIInputStream *create_nsstream(const char*,PRInt32);
441 nsICommandParams *create_nscommand_params(void);
442 nsIMutableArray *create_nsarray(void);
443 nsIWritableVariant *create_nsvariant(void);
444 void nsnode_to_nsstring(nsIDOMNode*,nsAString*);
445 void get_editor_controller(NSContainer*);
446 void init_nsevents(NSContainer*);
447 nsresult get_nsinterface(nsISupports*,REFIID,void**);
448
449 typedef enum {
450     EVENTID_LOAD,
451     EVENTID_LAST
452 } eventid_t;
453
454 void check_event_attr(HTMLDocument*,nsIDOMElement*);
455 void release_event_target(event_target_t*);
456 void fire_event(HTMLDocument*,eventid_t,nsIDOMNode*);
457
458 void set_document_bscallback(HTMLDocument*,nsChannelBSC*);
459 void set_current_mon(HTMLDocument*,IMoniker*);
460 HRESULT start_binding(HTMLDocument*,BSCallback*,IBindCtx*);
461
462 HRESULT bind_mon_to_buffer(HTMLDocument*,IMoniker*,void**,DWORD*);
463
464 nsChannelBSC *create_channelbsc(IMoniker*);
465 HRESULT channelbsc_load_stream(nsChannelBSC*,IStream*);
466 void channelbsc_set_channel(nsChannelBSC*,nsChannel*,nsIStreamListener*,nsISupports*);
467 IMoniker *get_channelbsc_mon(nsChannelBSC*);
468
469 IHTMLSelectionObject *HTMLSelectionObject_Create(HTMLDocument*,nsISelection*);
470 IHTMLTxtRange *HTMLTxtRange_Create(HTMLDocument*,nsIDOMRange*);
471 IHTMLStyle *HTMLStyle_Create(nsIDOMCSSStyleDeclaration*);
472 IHTMLStyleSheet *HTMLStyleSheet_Create(nsIDOMStyleSheet*);
473 IHTMLStyleSheetsCollection *HTMLStyleSheetsCollection_Create(nsIDOMStyleSheetList*);
474
475 void detach_selection(HTMLDocument*);
476 void detach_ranges(HTMLDocument*);
477
478 HTMLElement *HTMLElement_Create(nsIDOMNode*);
479 HTMLElement *HTMLAnchorElement_Create(nsIDOMHTMLElement*);
480 HTMLElement *HTMLBodyElement_Create(nsIDOMHTMLElement*);
481 HTMLElement *HTMLInputElement_Create(nsIDOMHTMLElement*);
482 HTMLElement *HTMLOptionElement_Create(nsIDOMHTMLElement*);
483 HTMLElement *HTMLScriptElement_Create(nsIDOMHTMLElement*);
484 HTMLElement *HTMLSelectElement_Create(nsIDOMHTMLElement*);
485 HTMLElement *HTMLTable_Create(nsIDOMHTMLElement*);
486 HTMLElement *HTMLTextAreaElement_Create(nsIDOMHTMLElement*);
487
488 void HTMLElement_Init(HTMLElement*);
489 void HTMLElement2_Init(HTMLElement*);
490 void HTMLTextContainer_Init(HTMLTextContainer*);
491
492 HRESULT HTMLDOMNode_QI(HTMLDOMNode*,REFIID,void**);
493 void HTMLDOMNode_destructor(HTMLDOMNode*);
494
495 HRESULT HTMLElement_QI(HTMLDOMNode*,REFIID,void**);
496 void HTMLElement_destructor(HTMLDOMNode*);
497
498 HTMLDOMNode *get_node(HTMLDocument*,nsIDOMNode*,BOOL);
499 void release_nodes(HTMLDocument*);
500
501 void release_script_hosts(HTMLDocument*);
502 void connect_scripts(HTMLDocument*);
503 void doc_insert_script(HTMLDocument*,nsIDOMHTMLScriptElement*);
504 IDispatch *script_parse_event(HTMLDocument*,LPCWSTR);
505
506 IHTMLElementCollection *create_all_collection(HTMLDOMNode*);
507
508 /* commands */
509 typedef struct {
510     DWORD id;
511     HRESULT (*query)(HTMLDocument*,OLECMD*);
512     HRESULT (*exec)(HTMLDocument*,DWORD,VARIANT*,VARIANT*);
513 } cmdtable_t;
514
515 extern const cmdtable_t editmode_cmds[];
516
517 void do_ns_command(NSContainer*,const char*,nsICommandParams*);
518
519 /* timer */
520 #define UPDATE_UI       0x0001
521 #define UPDATE_TITLE    0x0002
522
523 void update_doc(HTMLDocument *This, DWORD flags);
524 void update_title(HTMLDocument*);
525
526 /* editor */
527 void init_editor(HTMLDocument*);
528 void set_ns_editmode(NSContainer*);
529 void handle_edit_event(HTMLDocument*,nsIDOMEvent*);
530 HRESULT editor_exec_copy(HTMLDocument*,DWORD,VARIANT*,VARIANT*);
531 HRESULT editor_exec_cut(HTMLDocument*,DWORD,VARIANT*,VARIANT*);
532 HRESULT editor_exec_paste(HTMLDocument*,DWORD,VARIANT*,VARIANT*);
533 void handle_edit_load(HTMLDocument*);
534 HRESULT editor_is_dirty(HTMLDocument*);
535 void set_dirty(HTMLDocument*,VARIANT_BOOL);
536
537 extern DWORD mshtml_tls;
538
539 typedef struct task_t {
540     HTMLDocument *doc;
541
542     enum {
543         TASK_SETDOWNLOADSTATE,
544         TASK_PARSECOMPLETE,
545         TASK_SETPROGRESS,
546         TASK_START_BINDING
547     } task_id;
548
549     nsChannelBSC *bscallback;
550
551     struct task_t *next;
552 } task_t;
553
554 typedef struct {
555     HWND thread_hwnd;
556     task_t *task_queue_head;
557     task_t *task_queue_tail;
558     struct list timer_list;
559 } thread_data_t;
560
561 thread_data_t *get_thread_data(BOOL);
562 HWND get_thread_hwnd(void);
563 void push_task(task_t*);
564 void remove_doc_tasks(const HTMLDocument*);
565 DWORD set_task_timer(HTMLDocument*,DWORD,IDispatch*);
566
567 HRESULT get_typeinfo(tid_t,ITypeInfo**);
568 void release_typelib(void);
569 void call_disp_func(HTMLDocument*,IDispatch*);
570
571 DEFINE_GUID(CLSID_AboutProtocol, 0x3050F406, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
572 DEFINE_GUID(CLSID_JSProtocol, 0x3050F3B2, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
573 DEFINE_GUID(CLSID_MailtoProtocol, 0x3050F3DA, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
574 DEFINE_GUID(CLSID_ResProtocol, 0x3050F3BC, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
575 DEFINE_GUID(CLSID_SysimageProtocol, 0x76E67A63, 0x06E9, 0x11D2, 0xA8,0x40, 0x00,0x60,0x08,0x05,0x93,0x82);
576
577 DEFINE_GUID(CLSID_CMarkup,0x3050f4fb,0x98b5,0x11cf,0xbb,0x82,0x00,0xaa,0x00,0xbd,0xce,0x0b);
578
579 extern LONG module_ref;
580 #define LOCK_MODULE()   InterlockedIncrement(&module_ref)
581 #define UNLOCK_MODULE() InterlockedDecrement(&module_ref)
582
583 /* memory allocation functions */
584
585 static inline void *heap_alloc(size_t len)
586 {
587     return HeapAlloc(GetProcessHeap(), 0, len);
588 }
589
590 static inline void *heap_alloc_zero(size_t len)
591 {
592     return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
593 }
594
595 static inline void *heap_realloc(void *mem, size_t len)
596 {
597     return HeapReAlloc(GetProcessHeap(), 0, mem, len);
598 }
599
600 static inline BOOL heap_free(void *mem)
601 {
602     return HeapFree(GetProcessHeap(), 0, mem);
603 }
604
605 static inline LPWSTR heap_strdupW(LPCWSTR str)
606 {
607     LPWSTR ret = NULL;
608
609     if(str) {
610         DWORD size;
611
612         size = (strlenW(str)+1)*sizeof(WCHAR);
613         ret = heap_alloc(size);
614         memcpy(ret, str, size);
615     }
616
617     return ret;
618 }
619
620 static inline char *heap_strdupA(const char *str)
621 {
622     char *ret = NULL;
623
624     if(str) {
625         DWORD size;
626
627         size = strlen(str)+1;
628         ret = heap_alloc(size);
629         memcpy(ret, str, size);
630     }
631
632     return ret;
633 }
634
635 static inline WCHAR *heap_strdupAtoW(const char *str)
636 {
637     LPWSTR ret = NULL;
638
639     if(str) {
640         DWORD len;
641
642         len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
643         ret = heap_alloc(len*sizeof(WCHAR));
644         MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
645     }
646
647     return ret;
648 }
649
650 static inline char *heap_strdupWtoA(LPCWSTR str)
651 {
652     char *ret = NULL;
653
654     if(str) {
655         DWORD size = WideCharToMultiByte(CP_ACP, 0, str, -1, NULL, 0, NULL, NULL);
656         ret = heap_alloc(size);
657         WideCharToMultiByte(CP_ACP, 0, str, -1, ret, size, NULL, NULL);
658     }
659
660     return ret;
661 }
662
663 HINSTANCE get_shdoclc(void);
664
665 extern HINSTANCE hInst;