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