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