mshtml: Store editor controller in NSContainer.
[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 struct HTMLDocument {
75     const IHTMLDocument2Vtbl              *lpHTMLDocument2Vtbl;
76     const IHTMLDocument3Vtbl              *lpHTMLDocument3Vtbl;
77     const IPersistMonikerVtbl             *lpPersistMonikerVtbl;
78     const IPersistFileVtbl                *lpPersistFileVtbl;
79     const IMonikerPropVtbl                *lpMonikerPropVtbl;
80     const IOleObjectVtbl                  *lpOleObjectVtbl;
81     const IOleDocumentVtbl                *lpOleDocumentVtbl;
82     const IOleDocumentViewVtbl            *lpOleDocumentViewVtbl;
83     const IOleInPlaceActiveObjectVtbl     *lpOleInPlaceActiveObjectVtbl;
84     const IViewObject2Vtbl                *lpViewObject2Vtbl;
85     const IOleInPlaceObjectWindowlessVtbl *lpOleInPlaceObjectWindowlessVtbl;
86     const IServiceProviderVtbl            *lpServiceProviderVtbl;
87     const IOleCommandTargetVtbl           *lpOleCommandTargetVtbl;
88     const IOleControlVtbl                 *lpOleControlVtbl;
89     const IHlinkTargetVtbl                *lpHlinkTargetVtbl;
90     const IConnectionPointContainerVtbl   *lpConnectionPointContainerVtbl;
91     const IPersistStreamInitVtbl          *lpPersistStreamInitVtbl;
92
93     LONG ref;
94
95     NSContainer *nscontainer;
96     HTMLWindow *window;
97
98     IOleClientSite *client;
99     IDocHostUIHandler *hostui;
100     IOleInPlaceSite *ipsite;
101     IOleInPlaceFrame *frame;
102
103     BSCallback *bscallback;
104
105     HWND hwnd;
106     HWND tooltips_hwnd;
107
108     DOCHOSTUIINFO hostinfo;
109
110     USERMODE usermode;
111     READYSTATE readystate;
112     BOOL in_place_active;
113     BOOL ui_active;
114     BOOL window_active;
115     BOOL has_key_path;
116     BOOL container_locked;
117
118     DWORD update;
119
120     ConnectionPoint *cp_htmldocevents;
121     ConnectionPoint *cp_htmldocevents2;
122     ConnectionPoint *cp_propnotif;
123
124     HTMLDOMNode *nodes;
125 };
126
127 struct NSContainer {
128     const nsIWebBrowserChromeVtbl       *lpWebBrowserChromeVtbl;
129     const nsIContextMenuListenerVtbl    *lpContextMenuListenerVtbl;
130     const nsIURIContentListenerVtbl     *lpURIContentListenerVtbl;
131     const nsIEmbeddingSiteWindowVtbl    *lpEmbeddingSiteWindowVtbl;
132     const nsITooltipListenerVtbl        *lpTooltipListenerVtbl;
133     const nsIInterfaceRequestorVtbl     *lpInterfaceRequestorVtbl;
134     const nsIWeakReferenceVtbl          *lpWeakReferenceVtbl;
135     const nsISupportsWeakReferenceVtbl  *lpSupportsWeakReferenceVtbl;
136     const nsIDOMEventListenerVtbl       *lpDOMEventListenerVtbl;
137
138     nsIWebBrowser *webbrowser;
139     nsIWebNavigation *navigation;
140     nsIBaseWindow *window;
141     nsIWebBrowserFocus *focus;
142
143     nsIController *editor_controller;
144
145     LONG ref;
146
147     NSContainer *parent;
148     HTMLDocument *doc;
149
150     nsIURIContentListener *content_listener;
151
152     HWND hwnd;
153
154     BSCallback *bscallback; /* hack */
155 };
156
157 typedef struct {
158     const nsIHttpChannelVtbl *lpHttpChannelVtbl;
159     const nsIUploadChannelVtbl *lpUploadChannelVtbl;
160
161     LONG ref;
162
163     nsIChannel *channel;
164     nsIHttpChannel *http_channel;
165     nsIWineURI *uri;
166     nsIInputStream *post_data_stream;
167     nsILoadGroup *load_group;
168     nsIInterfaceRequestor *notif_callback;
169     nsLoadFlags load_flags;
170     nsIURI *original_uri;
171     char *content;
172     char *charset;
173 } nsChannel;
174
175 typedef struct {
176     const nsIInputStreamVtbl *lpInputStreamVtbl;
177
178     LONG ref;
179
180     char buf[1024];
181     DWORD buf_size;
182 } nsProtocolStream;
183
184 struct BSCallback {
185     const IBindStatusCallbackVtbl *lpBindStatusCallbackVtbl;
186     const IServiceProviderVtbl    *lpServiceProviderVtbl;
187     const IHttpNegotiate2Vtbl     *lpHttpNegotiate2Vtbl;
188     const IInternetBindInfoVtbl   *lpInternetBindInfoVtbl;
189
190     LONG ref;
191
192     LPWSTR headers;
193     HGLOBAL post_data;
194     ULONG post_data_len;
195     ULONG readed;
196
197     nsChannel *nschannel;
198     nsIStreamListener *nslistener;
199     nsISupports *nscontext;
200
201     IMoniker *mon;
202     IBinding *binding;
203
204     HTMLDocument *doc;
205
206     nsProtocolStream *nsstream;
207 };
208
209 struct HTMLDOMNode {
210     const IHTMLDOMNodeVtbl *lpHTMLDOMNodeVtbl;
211
212     void (*destructor)(IUnknown*);
213
214     enum {
215         NT_UNKNOWN,
216         NT_HTMLELEM
217     } node_type;
218
219     union {
220         IUnknown *unk;
221         IHTMLElement *elem;
222     } impl;
223
224     nsIDOMNode *nsnode;
225     HTMLDocument *doc;
226
227     HTMLDOMNode *next;
228 };
229
230 typedef struct {
231     const IHTMLElementVtbl *lpHTMLElementVtbl;
232     const IHTMLElement2Vtbl *lpHTMLElement2Vtbl;
233
234     void (*destructor)(IUnknown*);
235
236     nsIDOMHTMLElement *nselem;
237     HTMLDOMNode *node;
238
239     IUnknown *impl;
240 } HTMLElement;
241
242 typedef struct {
243     const IHTMLTextContainerVtbl *lpHTMLTextContainerVtbl;
244
245     HTMLElement *element;
246 } HTMLTextContainer;
247
248 #define HTMLWINDOW2(x)   ((IHTMLWindow2*)                 &(x)->lpHTMLWindow2Vtbl)
249
250 #define HTMLDOC(x)       ((IHTMLDocument2*)               &(x)->lpHTMLDocument2Vtbl)
251 #define HTMLDOC3(x)      ((IHTMLDocument3*)               &(x)->lpHTMLDocument3Vtbl)
252 #define PERSIST(x)       ((IPersist*)                     &(x)->lpPersistFileVtbl)
253 #define PERSISTMON(x)    ((IPersistMoniker*)              &(x)->lpPersistMonikerVtbl)
254 #define PERSISTFILE(x)   ((IPersistFile*)                 &(x)->lpPersistFileVtbl)
255 #define MONPROP(x)       ((IMonikerProp*)                 &(x)->lpMonikerPropVtbl)
256 #define OLEOBJ(x)        ((IOleObject*)                   &(x)->lpOleObjectVtbl)
257 #define OLEDOC(x)        ((IOleDocument*)                 &(x)->lpOleDocumentVtbl)
258 #define DOCVIEW(x)       ((IOleDocumentView*)             &(x)->lpOleDocumentViewVtbl)
259 #define OLEWIN(x)        ((IOleWindow*)                   &(x)->lpOleInPlaceActiveObjectVtbl)
260 #define ACTOBJ(x)        ((IOleInPlaceActiveObject*)      &(x)->lpOleInPlaceActiveObjectVtbl)
261 #define VIEWOBJ(x)       ((IViewObject*)                  &(x)->lpViewObject2Vtbl)
262 #define VIEWOBJ2(x)      ((IViewObject2*)                 &(x)->lpViewObject2Vtbl)
263 #define INPLACEOBJ(x)    ((IOleInPlaceObject*)            &(x)->lpOleInPlaceObjectWindowlessVtbl)
264 #define INPLACEWIN(x)    ((IOleInPlaceObjectWindowless*)  &(x)->lpOleInPlaceObjectWindowlessVtbl)
265 #define SERVPROV(x)      ((IServiceProvider*)             &(x)->lpServiceProviderVtbl)
266 #define CMDTARGET(x)     ((IOleCommandTarget*)            &(x)->lpOleCommandTargetVtbl)
267 #define CONTROL(x)       ((IOleControl*)                  &(x)->lpOleControlVtbl)
268 #define HLNKTARGET(x)    ((IHlinkTarget*)                 &(x)->lpHlinkTargetVtbl)
269 #define CONPTCONT(x)     ((IConnectionPointContainer*)    &(x)->lpConnectionPointContainerVtbl)
270 #define PERSTRINIT(x)    ((IPersistStreamInit*)           &(x)->lpPersistStreamInitVtbl)
271
272 #define NSWBCHROME(x)    ((nsIWebBrowserChrome*)          &(x)->lpWebBrowserChromeVtbl)
273 #define NSCML(x)         ((nsIContextMenuListener*)       &(x)->lpContextMenuListenerVtbl)
274 #define NSURICL(x)       ((nsIURIContentListener*)        &(x)->lpURIContentListenerVtbl)
275 #define NSEMBWNDS(x)     ((nsIEmbeddingSiteWindow*)       &(x)->lpEmbeddingSiteWindowVtbl)
276 #define NSIFACEREQ(x)    ((nsIInterfaceRequestor*)        &(x)->lpInterfaceRequestorVtbl)
277 #define NSTOOLTIP(x)     ((nsITooltipListener*)           &(x)->lpTooltipListenerVtbl)
278 #define NSEVENTLIST(x)   ((nsIDOMEventListener*)          &(x)->lpDOMEventListenerVtbl)
279 #define NSWEAKREF(x)     ((nsIWeakReference*)             &(x)->lpWeakReferenceVtbl)
280 #define NSSUPWEAKREF(x)  ((nsISupportsWeakReference*)     &(x)->lpSupportsWeakReferenceVtbl)
281
282 #define NSCHANNEL(x)     ((nsIChannel*)        &(x)->lpHttpChannelVtbl)
283 #define NSHTTPCHANNEL(x) ((nsIHttpChannel*)    &(x)->lpHttpChannelVtbl)
284 #define NSUPCHANNEL(x)   ((nsIUploadChannel*)  &(x)->lpUploadChannelVtbl)
285
286 #define HTTPNEG(x)       ((IHttpNegotiate2*)              &(x)->lpHttpNegotiate2Vtbl)
287 #define STATUSCLB(x)     ((IBindStatusCallback*)          &(x)->lpBindStatusCallbackVtbl)
288 #define BINDINFO(x)      ((IInternetBindInfo*)            &(x)->lpInternetBindInfoVtbl);
289
290 #define HTMLELEM(x)      ((IHTMLElement*)                 &(x)->lpHTMLElementVtbl)
291 #define HTMLELEM2(x)     ((IHTMLElement2*)                &(x)->lpHTMLElement2Vtbl)
292 #define HTMLDOMNODE(x)   ((IHTMLDOMNode*)                 &(x)->lpHTMLDOMNodeVtbl)
293
294 #define HTMLTEXTCONT(x)  ((IHTMLTextContainer*)           &(x)->lpHTMLTextContainerVtbl)
295
296 #define DEFINE_THIS(cls,ifc,iface) ((cls*)((BYTE*)(iface)-offsetof(cls,lp ## ifc ## Vtbl)))
297
298 HRESULT HTMLDocument_Create(IUnknown*,REFIID,void**);
299 HRESULT HTMLLoadOptions_Create(IUnknown*,REFIID,void**);
300
301 HTMLWindow *HTMLWindow_Create(HTMLDocument*);
302 HTMLWindow *nswindow_to_window(const nsIDOMWindow*);
303
304 void HTMLDocument_HTMLDocument3_Init(HTMLDocument*);
305 void HTMLDocument_Persist_Init(HTMLDocument*);
306 void HTMLDocument_OleCmd_Init(HTMLDocument*);
307 void HTMLDocument_OleObj_Init(HTMLDocument*);
308 void HTMLDocument_View_Init(HTMLDocument*);
309 void HTMLDocument_Window_Init(HTMLDocument*);
310 void HTMLDocument_Service_Init(HTMLDocument*);
311 void HTMLDocument_Hlink_Init(HTMLDocument*);
312 void HTMLDocument_ConnectionPoints_Init(HTMLDocument*);
313
314 void HTMLDocument_ConnectionPoints_Destroy(HTMLDocument*);
315
316 NSContainer *NSContainer_Create(HTMLDocument*,NSContainer*);
317 void NSContainer_Release(NSContainer*);
318
319 void HTMLDocument_LockContainer(HTMLDocument*,BOOL);
320 void show_context_menu(HTMLDocument*,DWORD,POINT*);
321
322 void show_tooltip(HTMLDocument*,DWORD,DWORD,LPCWSTR);
323 void hide_tooltip(HTMLDocument*);
324 HRESULT get_client_disp_property(IOleClientSite*,DISPID,VARIANT*);
325
326 HRESULT ProtocolFactory_Create(REFCLSID,REFIID,void**);
327
328 void close_gecko(void);
329 void register_nsservice(nsIComponentRegistrar*,nsIServiceManager*);
330 void init_nsio(nsIComponentManager*,nsIComponentRegistrar*);
331
332 void hlink_frame_navigate(HTMLDocument*,IHlinkFrame*,LPCWSTR,nsIInputStream*,DWORD);
333
334 void call_property_onchanged(ConnectionPoint*,DISPID);
335
336 void *nsalloc(size_t);
337 void nsfree(void*);
338
339 void nsACString_Init(nsACString*,const char*);
340 void nsACString_SetData(nsACString*,const char*);
341 PRUint32 nsACString_GetData(const nsACString*,const char**,PRBool*);
342 void nsACString_Finish(nsACString*);
343
344 void nsAString_Init(nsAString*,const PRUnichar*);
345 PRUint32 nsAString_GetData(const nsAString*,const PRUnichar**,PRBool*);
346 void nsAString_Finish(nsAString*);
347
348 nsIInputStream *create_nsstream(const char*,PRInt32);
349 nsICommandParams *create_nscommand_params(void);
350 void nsnode_to_nsstring(nsIDOMNode*,nsAString*);
351
352 BSCallback *create_bscallback(IMoniker*);
353 HRESULT start_binding(BSCallback*);
354 HRESULT load_stream(BSCallback*,IStream*);
355 void set_document_bscallback(HTMLDocument*,BSCallback*);
356
357 IHlink *Hlink_Create(void);
358 IHTMLSelectionObject *HTMLSelectionObject_Create(nsISelection*);
359 IHTMLTxtRange *HTMLTxtRange_Create(nsIDOMRange*);
360 IHTMLStyle *HTMLStyle_Create(nsIDOMCSSStyleDeclaration*);
361 IHTMLStyleSheet *HTMLStyleSheet_Create(void);
362
363 void HTMLElement_Create(HTMLDOMNode*);
364 void HTMLBodyElement_Create(HTMLElement*);
365 void HTMLInputElement_Create(HTMLElement*);
366 void HTMLSelectElement_Create(HTMLElement*);
367 void HTMLTextAreaElement_Create(HTMLElement*);
368
369 void HTMLElement2_Init(HTMLElement*);
370
371 void HTMLTextContainer_Init(HTMLTextContainer*,HTMLElement*);
372
373 HRESULT HTMLDOMNode_QI(HTMLDOMNode*,REFIID,void**);
374 HRESULT HTMLElement_QI(HTMLElement*,REFIID,void**);
375
376 HTMLDOMNode *get_node(HTMLDocument*,nsIDOMNode*);
377 void release_nodes(HTMLDocument*);
378
379 BOOL install_wine_gecko(void);
380
381 /* commands */
382 typedef struct {
383     DWORD id;
384     HRESULT (*query)(HTMLDocument*,OLECMD*);
385     HRESULT (*exec)(HTMLDocument*,DWORD,VARIANT*,VARIANT*);
386 } cmdtable_t;
387
388 extern const cmdtable_t editmode_cmds[];
389
390 /* timer */
391 #define UPDATE_UI       0x0001
392 #define UPDATE_TITLE    0x0002
393
394 void update_doc(HTMLDocument *This, DWORD flags);
395 void update_title(HTMLDocument*);
396
397 /* editor */
398 void init_editor(HTMLDocument*);
399 void set_ns_editmode(NSContainer*);
400 void handle_edit_event(HTMLDocument*,nsIDOMEvent*);
401
402 extern DWORD mshtml_tls;
403
404 typedef struct task_t {
405     HTMLDocument *doc;
406
407     enum {
408         TASK_SETDOWNLOADSTATE,
409         TASK_PARSECOMPLETE,
410         TASK_SETPROGRESS,
411         TASK_START_BINDING
412     } task_id;
413
414     BSCallback *bscallback;
415
416     struct task_t *next;
417 } task_t;
418
419 typedef struct {
420     HWND thread_hwnd;
421     task_t *task_queue_head;
422     task_t *task_queue_tail;
423 } thread_data_t;
424
425 thread_data_t *get_thread_data(BOOL);
426 HWND get_thread_hwnd(void);
427 void push_task(task_t*);
428 void remove_doc_tasks(const HTMLDocument*);
429
430 DEFINE_GUID(CLSID_AboutProtocol, 0x3050F406, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
431 DEFINE_GUID(CLSID_JSProtocol, 0x3050F3B2, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
432 DEFINE_GUID(CLSID_MailtoProtocol, 0x3050F3DA, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
433 DEFINE_GUID(CLSID_ResProtocol, 0x3050F3BC, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
434 DEFINE_GUID(CLSID_SysimageProtocol, 0x76E67A63, 0x06E9, 0x11D2, 0xA8,0x40, 0x00,0x60,0x08,0x05,0x93,0x82);
435
436 DEFINE_GUID(CLSID_CMarkup,0x3050f4fb,0x98b5,0x11cf,0xbb,0x82,0x00,0xaa,0x00,0xbd,0xce,0x0b);
437
438 extern LONG module_ref;
439 #define LOCK_MODULE()   InterlockedIncrement(&module_ref)
440 #define UNLOCK_MODULE() InterlockedDecrement(&module_ref)
441
442 /* memory allocation functions */
443
444 static inline void *mshtml_alloc(size_t len)
445 {
446     return HeapAlloc(GetProcessHeap(), 0, len);
447 }
448
449 static inline void *mshtml_alloc_zero(size_t len)
450 {
451     return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
452 }
453
454 static inline void *mshtml_realloc(void *mem, size_t len)
455 {
456     return HeapReAlloc(GetProcessHeap(), 0, mem, len);
457 }
458
459 static inline BOOL mshtml_free(void *mem)
460 {
461     return HeapFree(GetProcessHeap(), 0, mem);
462 }
463
464 HINSTANCE get_shdoclc(void);
465
466 extern HINSTANCE hInst;