mshtml: Added ICustomDoc stub implementation.
[wine] / dlls / mshtml / mshtml_private.h
1 /*
2  * Copyright 2005-2006 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 "docobj.h"
20 #include "mshtml.h"
21 #include "mshtmhst.h"
22 #include "hlink.h"
23
24 #include "wine/list.h"
25
26 #ifdef INIT_GUID
27 #include "initguid.h"
28 #endif
29
30 #include "nsiface.h"
31
32 #define GENERATE_MSHTML_NS_FAILURE(code) \
33     ((nsresult) ((PRUint32)(1<<31) | ((PRUint32)(0x45+6)<<16) | (PRUint32)(code)))
34
35 #define NS_OK                     ((nsresult)0x00000000L)
36 #define NS_ERROR_FAILURE          ((nsresult)0x80004005L)
37 #define NS_NOINTERFACE            ((nsresult)0x80004002L)
38 #define NS_ERROR_NOT_IMPLEMENTED  ((nsresult)0x80004001L)
39 #define NS_ERROR_INVALID_ARG      ((nsresult)0x80070057L) 
40 #define NS_ERROR_UNEXPECTED       ((nsresult)0x8000ffffL)
41 #define NS_ERROR_UNKNOWN_PROTOCOL ((nsresult)0x804b0012L)
42
43 #define WINE_NS_LOAD_FROM_MONIKER GENERATE_MSHTML_NS_FAILURE(0)
44
45 #define NS_FAILED(res) ((res) & 0x80000000)
46 #define NS_SUCCEEDED(res) (!NS_FAILED(res))
47
48 #define NSAPI WINAPI
49
50 #define NS_ELEMENT_NODE   1
51 #define NS_DOCUMENT_NODE  9
52
53 typedef struct HTMLDOMNode HTMLDOMNode;
54 typedef struct ConnectionPoint ConnectionPoint;
55 typedef struct BSCallback BSCallback;
56
57 typedef struct {
58     const IHTMLWindow2Vtbl *lpHTMLWindow2Vtbl;
59
60     LONG ref;
61
62     HTMLDocument *doc;
63     nsIDOMWindow *nswindow;
64
65     struct list entry;
66 } HTMLWindow;
67
68 typedef enum {
69     UNKNOWN_USERMODE,
70     BROWSEMODE,
71     EDITMODE        
72 } USERMODE;
73
74 typedef struct {
75     const IConnectionPointContainerVtbl  *lpConnectionPointContainerVtbl;
76
77     ConnectionPoint *cp_list;
78     IUnknown *outer;
79 } ConnectionPointContainer;
80
81 struct ConnectionPoint {
82     const IConnectionPointVtbl *lpConnectionPointVtbl;
83
84     IConnectionPointContainer *container;
85
86     union {
87         IUnknown *unk;
88         IDispatch *disp;
89         IPropertyNotifySink *propnotif;
90     } *sinks;
91     DWORD sinks_size;
92
93     IID iid;
94
95     ConnectionPoint *next;
96 };
97
98 struct HTMLDocument {
99     const IHTMLDocument2Vtbl              *lpHTMLDocument2Vtbl;
100     const IHTMLDocument3Vtbl              *lpHTMLDocument3Vtbl;
101     const IPersistMonikerVtbl             *lpPersistMonikerVtbl;
102     const IPersistFileVtbl                *lpPersistFileVtbl;
103     const IMonikerPropVtbl                *lpMonikerPropVtbl;
104     const IOleObjectVtbl                  *lpOleObjectVtbl;
105     const IOleDocumentVtbl                *lpOleDocumentVtbl;
106     const IOleDocumentViewVtbl            *lpOleDocumentViewVtbl;
107     const IOleInPlaceActiveObjectVtbl     *lpOleInPlaceActiveObjectVtbl;
108     const IViewObject2Vtbl                *lpViewObject2Vtbl;
109     const IOleInPlaceObjectWindowlessVtbl *lpOleInPlaceObjectWindowlessVtbl;
110     const IServiceProviderVtbl            *lpServiceProviderVtbl;
111     const IOleCommandTargetVtbl           *lpOleCommandTargetVtbl;
112     const IOleControlVtbl                 *lpOleControlVtbl;
113     const IHlinkTargetVtbl                *lpHlinkTargetVtbl;
114     const IPersistStreamInitVtbl          *lpPersistStreamInitVtbl;
115     const ICustomDocVtbl                  *lpCustomDocVtbl;
116
117     LONG ref;
118
119     NSContainer *nscontainer;
120     HTMLWindow *window;
121
122     IOleClientSite *client;
123     IDocHostUIHandler *hostui;
124     IOleInPlaceSite *ipsite;
125     IOleInPlaceFrame *frame;
126     IOleInPlaceUIWindow *ip_window;
127
128     BSCallback *bscallback;
129     IMoniker *mon;
130     BSTR url;
131
132     HWND hwnd;
133     HWND tooltips_hwnd;
134
135     DOCHOSTUIINFO hostinfo;
136
137     USERMODE usermode;
138     READYSTATE readystate;
139     BOOL in_place_active;
140     BOOL ui_active;
141     BOOL window_active;
142     BOOL has_key_path;
143     BOOL container_locked;
144     BOOL focus;
145
146     DWORD update;
147
148     ConnectionPointContainer cp_container;
149     ConnectionPoint cp_htmldocevents;
150     ConnectionPoint cp_htmldocevents2;
151     ConnectionPoint cp_propnotif;
152
153     HTMLDOMNode *nodes;
154 };
155
156 typedef struct {
157     const nsIDOMEventListenerVtbl      *lpDOMEventListenerVtbl;
158     NSContainer *This;
159 } nsEventListener;
160
161 struct NSContainer {
162     const nsIWebBrowserChromeVtbl       *lpWebBrowserChromeVtbl;
163     const nsIContextMenuListenerVtbl    *lpContextMenuListenerVtbl;
164     const nsIURIContentListenerVtbl     *lpURIContentListenerVtbl;
165     const nsIEmbeddingSiteWindowVtbl    *lpEmbeddingSiteWindowVtbl;
166     const nsITooltipListenerVtbl        *lpTooltipListenerVtbl;
167     const nsIInterfaceRequestorVtbl     *lpInterfaceRequestorVtbl;
168     const nsIWeakReferenceVtbl          *lpWeakReferenceVtbl;
169     const nsISupportsWeakReferenceVtbl  *lpSupportsWeakReferenceVtbl;
170
171     nsEventListener blur_listener;
172     nsEventListener focus_listener;
173     nsEventListener keypress_listener;
174     nsEventListener load_listener;
175
176     nsIWebBrowser *webbrowser;
177     nsIWebNavigation *navigation;
178     nsIBaseWindow *window;
179     nsIWebBrowserFocus *focus;
180
181     nsIController *editor_controller;
182
183     LONG ref;
184
185     NSContainer *parent;
186     HTMLDocument *doc;
187
188     nsIURIContentListener *content_listener;
189
190     HWND hwnd;
191
192     BSCallback *bscallback; /* hack */
193 };
194
195 typedef struct {
196     const nsIHttpChannelVtbl *lpHttpChannelVtbl;
197     const nsIUploadChannelVtbl *lpUploadChannelVtbl;
198
199     LONG ref;
200
201     nsIChannel *channel;
202     nsIHttpChannel *http_channel;
203     nsIWineURI *uri;
204     nsIInputStream *post_data_stream;
205     nsILoadGroup *load_group;
206     nsIInterfaceRequestor *notif_callback;
207     nsLoadFlags load_flags;
208     nsIURI *original_uri;
209     char *content;
210     char *charset;
211 } nsChannel;
212
213 typedef struct {
214     const nsIInputStreamVtbl *lpInputStreamVtbl;
215
216     LONG ref;
217
218     char buf[1024];
219     DWORD buf_size;
220 } nsProtocolStream;
221
222 struct BSCallback {
223     const IBindStatusCallbackVtbl *lpBindStatusCallbackVtbl;
224     const IServiceProviderVtbl    *lpServiceProviderVtbl;
225     const IHttpNegotiate2Vtbl     *lpHttpNegotiate2Vtbl;
226     const IInternetBindInfoVtbl   *lpInternetBindInfoVtbl;
227
228     LONG ref;
229
230     LPWSTR headers;
231     HGLOBAL post_data;
232     ULONG post_data_len;
233     ULONG readed;
234
235     nsChannel *nschannel;
236     nsIStreamListener *nslistener;
237     nsISupports *nscontext;
238
239     IMoniker *mon;
240     IBinding *binding;
241
242     HTMLDocument *doc;
243
244     nsProtocolStream *nsstream;
245 };
246
247 struct HTMLDOMNode {
248     const IHTMLDOMNodeVtbl *lpHTMLDOMNodeVtbl;
249
250     void (*destructor)(IUnknown*);
251
252     enum {
253         NT_UNKNOWN,
254         NT_HTMLELEM
255     } node_type;
256
257     union {
258         IUnknown *unk;
259         IHTMLElement *elem;
260     } impl;
261
262     nsIDOMNode *nsnode;
263     HTMLDocument *doc;
264
265     HTMLDOMNode *next;
266 };
267
268 typedef struct {
269     const IHTMLElementVtbl *lpHTMLElementVtbl;
270     const IHTMLElement2Vtbl *lpHTMLElement2Vtbl;
271
272     void (*destructor)(IUnknown*);
273
274     nsIDOMHTMLElement *nselem;
275     HTMLDOMNode *node;
276
277     IUnknown *impl;
278 } HTMLElement;
279
280 typedef struct {
281     const IHTMLTextContainerVtbl *lpHTMLTextContainerVtbl;
282
283     HTMLElement *element;
284 } HTMLTextContainer;
285
286 #define HTMLWINDOW2(x)   ((IHTMLWindow2*)                 &(x)->lpHTMLWindow2Vtbl)
287
288 #define HTMLDOC(x)       ((IHTMLDocument2*)               &(x)->lpHTMLDocument2Vtbl)
289 #define HTMLDOC3(x)      ((IHTMLDocument3*)               &(x)->lpHTMLDocument3Vtbl)
290 #define PERSIST(x)       ((IPersist*)                     &(x)->lpPersistFileVtbl)
291 #define PERSISTMON(x)    ((IPersistMoniker*)              &(x)->lpPersistMonikerVtbl)
292 #define PERSISTFILE(x)   ((IPersistFile*)                 &(x)->lpPersistFileVtbl)
293 #define MONPROP(x)       ((IMonikerProp*)                 &(x)->lpMonikerPropVtbl)
294 #define OLEOBJ(x)        ((IOleObject*)                   &(x)->lpOleObjectVtbl)
295 #define OLEDOC(x)        ((IOleDocument*)                 &(x)->lpOleDocumentVtbl)
296 #define DOCVIEW(x)       ((IOleDocumentView*)             &(x)->lpOleDocumentViewVtbl)
297 #define OLEWIN(x)        ((IOleWindow*)                   &(x)->lpOleInPlaceActiveObjectVtbl)
298 #define ACTOBJ(x)        ((IOleInPlaceActiveObject*)      &(x)->lpOleInPlaceActiveObjectVtbl)
299 #define VIEWOBJ(x)       ((IViewObject*)                  &(x)->lpViewObject2Vtbl)
300 #define VIEWOBJ2(x)      ((IViewObject2*)                 &(x)->lpViewObject2Vtbl)
301 #define INPLACEOBJ(x)    ((IOleInPlaceObject*)            &(x)->lpOleInPlaceObjectWindowlessVtbl)
302 #define INPLACEWIN(x)    ((IOleInPlaceObjectWindowless*)  &(x)->lpOleInPlaceObjectWindowlessVtbl)
303 #define SERVPROV(x)      ((IServiceProvider*)             &(x)->lpServiceProviderVtbl)
304 #define CMDTARGET(x)     ((IOleCommandTarget*)            &(x)->lpOleCommandTargetVtbl)
305 #define CONTROL(x)       ((IOleControl*)                  &(x)->lpOleControlVtbl)
306 #define HLNKTARGET(x)    ((IHlinkTarget*)                 &(x)->lpHlinkTargetVtbl)
307 #define CONPTCONT(x)     ((IConnectionPointContainer*)    &(x)->lpConnectionPointContainerVtbl)
308 #define PERSTRINIT(x)    ((IPersistStreamInit*)           &(x)->lpPersistStreamInitVtbl)
309 #define CUSTOMDOC(x)     ((ICustomDoc*)                   &(x)->lpCustomDocVtbl)
310
311 #define NSWBCHROME(x)    ((nsIWebBrowserChrome*)          &(x)->lpWebBrowserChromeVtbl)
312 #define NSCML(x)         ((nsIContextMenuListener*)       &(x)->lpContextMenuListenerVtbl)
313 #define NSURICL(x)       ((nsIURIContentListener*)        &(x)->lpURIContentListenerVtbl)
314 #define NSEMBWNDS(x)     ((nsIEmbeddingSiteWindow*)       &(x)->lpEmbeddingSiteWindowVtbl)
315 #define NSIFACEREQ(x)    ((nsIInterfaceRequestor*)        &(x)->lpInterfaceRequestorVtbl)
316 #define NSTOOLTIP(x)     ((nsITooltipListener*)           &(x)->lpTooltipListenerVtbl)
317 #define NSEVENTLIST(x)   ((nsIDOMEventListener*)          &(x)->lpDOMEventListenerVtbl)
318 #define NSWEAKREF(x)     ((nsIWeakReference*)             &(x)->lpWeakReferenceVtbl)
319 #define NSSUPWEAKREF(x)  ((nsISupportsWeakReference*)     &(x)->lpSupportsWeakReferenceVtbl)
320
321 #define NSCHANNEL(x)     ((nsIChannel*)        &(x)->lpHttpChannelVtbl)
322 #define NSHTTPCHANNEL(x) ((nsIHttpChannel*)    &(x)->lpHttpChannelVtbl)
323 #define NSUPCHANNEL(x)   ((nsIUploadChannel*)  &(x)->lpUploadChannelVtbl)
324
325 #define HTTPNEG(x)       ((IHttpNegotiate2*)              &(x)->lpHttpNegotiate2Vtbl)
326 #define STATUSCLB(x)     ((IBindStatusCallback*)          &(x)->lpBindStatusCallbackVtbl)
327 #define BINDINFO(x)      ((IInternetBindInfo*)            &(x)->lpInternetBindInfoVtbl);
328
329 #define HTMLELEM(x)      ((IHTMLElement*)                 &(x)->lpHTMLElementVtbl)
330 #define HTMLELEM2(x)     ((IHTMLElement2*)                &(x)->lpHTMLElement2Vtbl)
331 #define HTMLDOMNODE(x)   ((IHTMLDOMNode*)                 &(x)->lpHTMLDOMNodeVtbl)
332
333 #define HTMLTEXTCONT(x)  ((IHTMLTextContainer*)           &(x)->lpHTMLTextContainerVtbl)
334
335 #define DEFINE_THIS(cls,ifc,iface) ((cls*)((BYTE*)(iface)-offsetof(cls,lp ## ifc ## Vtbl)))
336
337 HRESULT HTMLDocument_Create(IUnknown*,REFIID,void**);
338 HRESULT HTMLLoadOptions_Create(IUnknown*,REFIID,void**);
339
340 HTMLWindow *HTMLWindow_Create(HTMLDocument*);
341 HTMLWindow *nswindow_to_window(const nsIDOMWindow*);
342
343 void HTMLDocument_HTMLDocument3_Init(HTMLDocument*);
344 void HTMLDocument_Persist_Init(HTMLDocument*);
345 void HTMLDocument_OleCmd_Init(HTMLDocument*);
346 void HTMLDocument_OleObj_Init(HTMLDocument*);
347 void HTMLDocument_View_Init(HTMLDocument*);
348 void HTMLDocument_Window_Init(HTMLDocument*);
349 void HTMLDocument_Service_Init(HTMLDocument*);
350 void HTMLDocument_Hlink_Init(HTMLDocument*);
351
352 void ConnectionPoint_Init(ConnectionPoint*,IConnectionPointContainer*,REFIID,ConnectionPoint*);
353 void ConnectionPointContainer_Init(ConnectionPointContainer*,ConnectionPoint*,IUnknown*);
354 void ConnectionPointContainer_Destroy(ConnectionPointContainer*);
355
356 NSContainer *NSContainer_Create(HTMLDocument*,NSContainer*);
357 void NSContainer_Release(NSContainer*);
358
359 void HTMLDocument_LockContainer(HTMLDocument*,BOOL);
360 void show_context_menu(HTMLDocument*,DWORD,POINT*);
361 void notif_focus(HTMLDocument*);
362
363 void show_tooltip(HTMLDocument*,DWORD,DWORD,LPCWSTR);
364 void hide_tooltip(HTMLDocument*);
365 HRESULT get_client_disp_property(IOleClientSite*,DISPID,VARIANT*);
366
367 HRESULT ProtocolFactory_Create(REFCLSID,REFIID,void**);
368
369 void close_gecko(void);
370 void register_nsservice(nsIComponentRegistrar*,nsIServiceManager*);
371 void init_nsio(nsIComponentManager*,nsIComponentRegistrar*);
372
373 void hlink_frame_navigate(HTMLDocument*,IHlinkFrame*,LPCWSTR,nsIInputStream*,DWORD);
374
375 void call_property_onchanged(ConnectionPoint*,DISPID);
376
377 void *nsalloc(size_t);
378 void nsfree(void*);
379
380 void nsACString_Init(nsACString*,const char*);
381 void nsACString_SetData(nsACString*,const char*);
382 PRUint32 nsACString_GetData(const nsACString*,const char**,PRBool*);
383 void nsACString_Finish(nsACString*);
384
385 void nsAString_Init(nsAString*,const PRUnichar*);
386 PRUint32 nsAString_GetData(const nsAString*,const PRUnichar**,PRBool*);
387 void nsAString_Finish(nsAString*);
388
389 nsIInputStream *create_nsstream(const char*,PRInt32);
390 nsICommandParams *create_nscommand_params(void);
391 void nsnode_to_nsstring(nsIDOMNode*,nsAString*);
392 nsIController *get_editor_controller(NSContainer*);
393 void init_nsevents(NSContainer*);
394
395 BSCallback *create_bscallback(IMoniker*);
396 HRESULT start_binding(BSCallback*);
397 HRESULT load_stream(BSCallback*,IStream*);
398 void set_document_bscallback(HTMLDocument*,BSCallback*);
399 void set_current_mon(HTMLDocument*,IMoniker*);
400
401 IHTMLSelectionObject *HTMLSelectionObject_Create(nsISelection*);
402 IHTMLTxtRange *HTMLTxtRange_Create(nsIDOMRange*);
403 IHTMLStyle *HTMLStyle_Create(nsIDOMCSSStyleDeclaration*);
404 IHTMLStyleSheet *HTMLStyleSheet_Create(void);
405
406 void HTMLElement_Create(HTMLDOMNode*);
407 void HTMLBodyElement_Create(HTMLElement*);
408 void HTMLInputElement_Create(HTMLElement*);
409 void HTMLSelectElement_Create(HTMLElement*);
410 void HTMLTextAreaElement_Create(HTMLElement*);
411
412 void HTMLElement2_Init(HTMLElement*);
413
414 void HTMLTextContainer_Init(HTMLTextContainer*,HTMLElement*);
415
416 HRESULT HTMLDOMNode_QI(HTMLDOMNode*,REFIID,void**);
417 HRESULT HTMLElement_QI(HTMLElement*,REFIID,void**);
418
419 HTMLDOMNode *get_node(HTMLDocument*,nsIDOMNode*);
420 void release_nodes(HTMLDocument*);
421
422 BOOL install_wine_gecko(void);
423
424 /* commands */
425 typedef struct {
426     DWORD id;
427     HRESULT (*query)(HTMLDocument*,OLECMD*);
428     HRESULT (*exec)(HTMLDocument*,DWORD,VARIANT*,VARIANT*);
429 } cmdtable_t;
430
431 extern const cmdtable_t editmode_cmds[];
432
433 /* timer */
434 #define UPDATE_UI       0x0001
435 #define UPDATE_TITLE    0x0002
436
437 void update_doc(HTMLDocument *This, DWORD flags);
438 void update_title(HTMLDocument*);
439
440 /* editor */
441 void init_editor(HTMLDocument*);
442 void set_ns_editmode(NSContainer*);
443 void handle_edit_event(HTMLDocument*,nsIDOMEvent*);
444 HRESULT editor_exec_copy(HTMLDocument*,DWORD,VARIANT*,VARIANT*);
445 HRESULT editor_exec_cut(HTMLDocument*,DWORD,VARIANT*,VARIANT*);
446 HRESULT editor_exec_paste(HTMLDocument*,DWORD,VARIANT*,VARIANT*);
447 void handle_edit_load(HTMLDocument *This);
448
449 extern DWORD mshtml_tls;
450
451 typedef struct task_t {
452     HTMLDocument *doc;
453
454     enum {
455         TASK_SETDOWNLOADSTATE,
456         TASK_PARSECOMPLETE,
457         TASK_SETPROGRESS,
458         TASK_START_BINDING
459     } task_id;
460
461     BSCallback *bscallback;
462
463     struct task_t *next;
464 } task_t;
465
466 typedef struct {
467     HWND thread_hwnd;
468     task_t *task_queue_head;
469     task_t *task_queue_tail;
470 } thread_data_t;
471
472 thread_data_t *get_thread_data(BOOL);
473 HWND get_thread_hwnd(void);
474 void push_task(task_t*);
475 void remove_doc_tasks(const HTMLDocument*);
476
477 /* typelibs */
478 enum tid_t {
479     IHTMLWindow2_tid,
480     LAST_tid
481 };
482
483 HRESULT get_typeinfo(enum tid_t, ITypeInfo**);
484
485 DEFINE_GUID(CLSID_AboutProtocol, 0x3050F406, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
486 DEFINE_GUID(CLSID_JSProtocol, 0x3050F3B2, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
487 DEFINE_GUID(CLSID_MailtoProtocol, 0x3050F3DA, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
488 DEFINE_GUID(CLSID_ResProtocol, 0x3050F3BC, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
489 DEFINE_GUID(CLSID_SysimageProtocol, 0x76E67A63, 0x06E9, 0x11D2, 0xA8,0x40, 0x00,0x60,0x08,0x05,0x93,0x82);
490
491 DEFINE_GUID(CLSID_CMarkup,0x3050f4fb,0x98b5,0x11cf,0xbb,0x82,0x00,0xaa,0x00,0xbd,0xce,0x0b);
492
493 extern LONG module_ref;
494 #define LOCK_MODULE()   InterlockedIncrement(&module_ref)
495 #define UNLOCK_MODULE() InterlockedDecrement(&module_ref)
496
497 /* memory allocation functions */
498
499 static inline void *mshtml_alloc(size_t len)
500 {
501     return HeapAlloc(GetProcessHeap(), 0, len);
502 }
503
504 static inline void *mshtml_alloc_zero(size_t len)
505 {
506     return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
507 }
508
509 static inline void *mshtml_realloc(void *mem, size_t len)
510 {
511     return HeapReAlloc(GetProcessHeap(), 0, mem, len);
512 }
513
514 static inline BOOL mshtml_free(void *mem)
515 {
516     return HeapFree(GetProcessHeap(), 0, mem);
517 }
518
519 HINSTANCE get_shdoclc(void);
520
521 extern HINSTANCE hInst;