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