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