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