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