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