comctl32: Remove some more Nx1 assumptions.
[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 #ifdef INIT_GUID
25 #include "initguid.h"
26 #endif
27
28 #include "nsiface.h"
29
30 #define GENERATE_MSHTML_NS_FAILURE(code) \
31     ((nsresult) ((PRUint32)(1<<31) | ((PRUint32)(0x45+6)<<16) | (PRUint32)(code)))
32
33 #define NS_OK                     ((nsresult)0x00000000L)
34 #define NS_ERROR_FAILURE          ((nsresult)0x80004005L)
35 #define NS_NOINTERFACE            ((nsresult)0x80004002L)
36 #define NS_ERROR_NOT_IMPLEMENTED  ((nsresult)0x80004001L)
37 #define NS_ERROR_INVALID_ARG      ((nsresult)0x80070057L) 
38 #define NS_ERROR_UNEXPECTED       ((nsresult)0x8000ffffL)
39 #define NS_ERROR_UNKNOWN_PROTOCOL ((nsresult)0x804b0012L)
40
41 #define WINE_NS_LOAD_FROM_MONIKER GENERATE_MSHTML_NS_FAILURE(0)
42
43 #define NS_FAILED(res) ((res) & 0x80000000)
44 #define NS_SUCCEEDED(res) (!NS_FAILED(res))
45
46 #define NSAPI WINAPI
47
48 #define NS_ELEMENT_NODE   1
49 #define NS_DOCUMENT_NODE  9
50
51 typedef struct HTMLDOMNode HTMLDOMNode;
52 typedef struct ConnectionPoint ConnectionPoint;
53 typedef struct BSCallback BSCallback;
54
55 typedef enum {
56     UNKNOWN_USERMODE,
57     BROWSEMODE,
58     EDITMODE        
59 } USERMODE;
60
61 struct HTMLDocument {
62     const IHTMLDocument2Vtbl              *lpHTMLDocument2Vtbl;
63     const IHTMLDocument3Vtbl              *lpHTMLDocument3Vtbl;
64     const IPersistMonikerVtbl             *lpPersistMonikerVtbl;
65     const IPersistFileVtbl                *lpPersistFileVtbl;
66     const IMonikerPropVtbl                *lpMonikerPropVtbl;
67     const IOleObjectVtbl                  *lpOleObjectVtbl;
68     const IOleDocumentVtbl                *lpOleDocumentVtbl;
69     const IOleDocumentViewVtbl            *lpOleDocumentViewVtbl;
70     const IOleInPlaceActiveObjectVtbl     *lpOleInPlaceActiveObjectVtbl;
71     const IViewObject2Vtbl                *lpViewObject2Vtbl;
72     const IOleInPlaceObjectWindowlessVtbl *lpOleInPlaceObjectWindowlessVtbl;
73     const IServiceProviderVtbl            *lpServiceProviderVtbl;
74     const IOleCommandTargetVtbl           *lpOleCommandTargetVtbl;
75     const IOleControlVtbl                 *lpOleControlVtbl;
76     const IHlinkTargetVtbl                *lpHlinkTargetVtbl;
77     const IConnectionPointContainerVtbl   *lpConnectionPointContainerVtbl;
78     const IPersistStreamInitVtbl          *lpPersistStreamInitVtbl;
79
80     LONG ref;
81
82     NSContainer *nscontainer;
83
84     IOleClientSite *client;
85     IDocHostUIHandler *hostui;
86     IOleInPlaceSite *ipsite;
87     IOleInPlaceFrame *frame;
88
89     BSCallback *bscallback;
90
91     HWND hwnd;
92     HWND tooltips_hwnd;
93
94     USERMODE usermode;
95     READYSTATE readystate;
96     BOOL in_place_active;
97     BOOL ui_active;
98     BOOL window_active;
99     BOOL has_key_path;
100     BOOL container_locked;
101
102     ConnectionPoint *cp_htmldocevents;
103     ConnectionPoint *cp_htmldocevents2;
104     ConnectionPoint *cp_propnotif;
105
106     HTMLDOMNode *nodes;
107 };
108
109 struct NSContainer {
110     const nsIWebBrowserChromeVtbl       *lpWebBrowserChromeVtbl;
111     const nsIContextMenuListenerVtbl    *lpContextMenuListenerVtbl;
112     const nsIURIContentListenerVtbl     *lpURIContentListenerVtbl;
113     const nsIEmbeddingSiteWindowVtbl    *lpEmbeddingSiteWindowVtbl;
114     const nsITooltipListenerVtbl        *lpTooltipListenerVtbl;
115     const nsIInterfaceRequestorVtbl     *lpInterfaceRequestorVtbl;
116     const nsIWeakReferenceVtbl          *lpWeakReferenceVtbl;
117     const nsISupportsWeakReferenceVtbl  *lpSupportsWeakReferenceVtbl;
118
119     nsIWebBrowser *webbrowser;
120     nsIWebNavigation *navigation;
121     nsIBaseWindow *window;
122     nsIWebBrowserFocus *focus;
123
124     LONG ref;
125
126     NSContainer *parent;
127     HTMLDocument *doc;
128
129     nsIURIContentListener *content_listener;
130
131     HWND hwnd;
132
133     BSCallback *bscallback; /* hack */
134 };
135
136 typedef struct {
137     const nsIHttpChannelVtbl *lpHttpChannelVtbl;
138     const nsIUploadChannelVtbl *lpUploadChannelVtbl;
139
140     LONG ref;
141
142     nsIChannel *channel;
143     nsIHttpChannel *http_channel;
144     nsIWineURI *uri;
145     nsIInputStream *post_data_stream;
146     nsILoadGroup *load_group;
147     nsIInterfaceRequestor *notif_callback;
148     nsLoadFlags load_flags;
149     nsIURI *original_uri;
150     char *content;
151 } nsChannel;
152
153 typedef struct {
154     const nsIInputStreamVtbl *lpInputStreamVtbl;
155
156     LONG ref;
157
158     char buf[1024];
159     DWORD buf_size;
160 } nsProtocolStream;
161
162 struct BSCallback {
163     const IBindStatusCallbackVtbl *lpBindStatusCallbackVtbl;
164     const IServiceProviderVtbl    *lpServiceProviderVtbl;
165     const IHttpNegotiate2Vtbl     *lpHttpNegotiate2Vtbl;
166     const IInternetBindInfoVtbl   *lpInternetBindInfoVtbl;
167
168     LONG ref;
169
170     LPWSTR headers;
171     HGLOBAL post_data;
172     ULONG post_data_len;
173     ULONG readed;
174
175     nsChannel *nschannel;
176     nsIStreamListener *nslistener;
177     nsISupports *nscontext;
178
179     IMoniker *mon;
180     IBinding *binding;
181
182     HTMLDocument *doc;
183
184     nsProtocolStream *nsstream;
185 };
186
187 struct HTMLDOMNode {
188     const IHTMLDOMNodeVtbl *lpHTMLDOMNodeVtbl;
189
190     void (*destructor)(IUnknown*);
191
192     enum {
193         NT_UNKNOWN,
194         NT_HTMLELEM
195     } node_type;
196
197     union {
198         IUnknown *unk;
199         IHTMLElement *elem;
200     } impl;
201
202     nsIDOMNode *nsnode;
203     HTMLDocument *doc;
204
205     HTMLDOMNode *next;
206 };
207
208 typedef struct {
209     const IHTMLElementVtbl *lpHTMLElementVtbl;
210     const IHTMLElement2Vtbl *lpHTMLElement2Vtbl;
211
212     void (*destructor)(IUnknown*);
213
214     nsIDOMHTMLElement *nselem;
215     HTMLDOMNode *node;
216
217     IUnknown *impl;
218 } HTMLElement;
219
220 typedef struct {
221     const IHTMLTextContainerVtbl *lpHTMLTextContainerVtbl;
222
223     HTMLElement *element;
224 } HTMLTextContainer;
225
226 #define HTMLDOC(x)       ((IHTMLDocument2*)               &(x)->lpHTMLDocument2Vtbl)
227 #define HTMLDOC3(x)      ((IHTMLDocument3*)               &(x)->lpHTMLDocument3Vtbl)
228 #define PERSIST(x)       ((IPersist*)                     &(x)->lpPersistFileVtbl)
229 #define PERSISTMON(x)    ((IPersistMoniker*)              &(x)->lpPersistMonikerVtbl)
230 #define PERSISTFILE(x)   ((IPersistFile*)                 &(x)->lpPersistFileVtbl)
231 #define MONPROP(x)       ((IMonikerProp*)                 &(x)->lpMonikerPropVtbl)
232 #define OLEOBJ(x)        ((IOleObject*)                   &(x)->lpOleObjectVtbl)
233 #define OLEDOC(x)        ((IOleDocument*)                 &(x)->lpOleDocumentVtbl)
234 #define DOCVIEW(x)       ((IOleDocumentView*)             &(x)->lpOleDocumentViewVtbl)
235 #define OLEWIN(x)        ((IOleWindow*)                   &(x)->lpOleInPlaceActiveObjectVtbl)
236 #define ACTOBJ(x)        ((IOleInPlaceActiveObject*)      &(x)->lpOleInPlaceActiveObjectVtbl)
237 #define VIEWOBJ(x)       ((IViewObject*)                  &(x)->lpViewObject2Vtbl)
238 #define VIEWOBJ2(x)      ((IViewObject2*)                 &(x)->lpViewObject2Vtbl)
239 #define INPLACEOBJ(x)    ((IOleInPlaceObject*)            &(x)->lpOleInPlaceObjectWindowlessVtbl)
240 #define INPLACEWIN(x)    ((IOleInPlaceObjectWindowless*)  &(x)->lpOleInPlaceObjectWindowlessVtbl)
241 #define SERVPROV(x)      ((IServiceProvider*)             &(x)->lpServiceProviderVtbl)
242 #define CMDTARGET(x)     ((IOleCommandTarget*)            &(x)->lpOleCommandTargetVtbl)
243 #define CONTROL(x)       ((IOleControl*)                  &(x)->lpOleControlVtbl)
244 #define HLNKTARGET(x)    ((IHlinkTarget*)                 &(x)->lpHlinkTargetVtbl)
245 #define CONPTCONT(x)     ((IConnectionPointContainer*)    &(x)->lpConnectionPointContainerVtbl)
246 #define PERSTRINIT(x)    ((IPersistStreamInit*)           &(x)->lpPersistStreamInitVtbl)
247
248 #define NSWBCHROME(x)    ((nsIWebBrowserChrome*)          &(x)->lpWebBrowserChromeVtbl)
249 #define NSCML(x)         ((nsIContextMenuListener*)       &(x)->lpContextMenuListenerVtbl)
250 #define NSURICL(x)       ((nsIURIContentListener*)        &(x)->lpURIContentListenerVtbl)
251 #define NSEMBWNDS(x)     ((nsIEmbeddingSiteWindow*)       &(x)->lpEmbeddingSiteWindowVtbl)
252 #define NSIFACEREQ(x)    ((nsIInterfaceRequestor*)        &(x)->lpInterfaceRequestorVtbl)
253 #define NSTOOLTIP(x)     ((nsITooltipListener*)           &(x)->lpTooltipListenerVtbl)
254 #define NSWEAKREF(x)     ((nsIWeakReference*)             &(x)->lpWeakReferenceVtbl)
255 #define NSSUPWEAKREF(x)  ((nsISupportsWeakReference*)     &(x)->lpSupportsWeakReferenceVtbl)
256
257 #define NSCHANNEL(x)     ((nsIChannel*)        &(x)->lpHttpChannelVtbl)
258 #define NSHTTPCHANNEL(x) ((nsIHttpChannel*)    &(x)->lpHttpChannelVtbl)
259 #define NSUPCHANNEL(x)   ((nsIUploadChannel*)  &(x)->lpUploadChannelVtbl)
260
261 #define HTTPNEG(x)       ((IHttpNegotiate2*)              &(x)->lpHttpNegotiate2Vtbl)
262 #define STATUSCLB(x)     ((IBindStatusCallback*)          &(x)->lpBindStatusCallbackVtbl)
263 #define BINDINFO(x)      ((IInternetBindInfo*)            &(x)->lpInternetBindInfoVtbl);
264
265 #define HTMLELEM(x)      ((IHTMLElement*)                 &(x)->lpHTMLElementVtbl)
266 #define HTMLELEM2(x)     ((IHTMLElement2*)                &(x)->lpHTMLElement2Vtbl)
267 #define HTMLDOMNODE(x)   ((IHTMLDOMNode*)                 &(x)->lpHTMLDOMNodeVtbl)
268
269 #define HTMLTEXTCONT(x)  ((IHTMLTextContainer*)           &(x)->lpHTMLTextContainerVtbl)
270
271 #define DEFINE_THIS(cls,ifc,iface) ((cls*)((BYTE*)(iface)-offsetof(cls,lp ## ifc ## Vtbl)))
272
273 HRESULT HTMLDocument_Create(IUnknown*,REFIID,void**);
274 HRESULT HTMLLoadOptions_Create(IUnknown*,REFIID,void**);
275
276 void HTMLDocument_HTMLDocument3_Init(HTMLDocument*);
277 void HTMLDocument_Persist_Init(HTMLDocument*);
278 void HTMLDocument_OleCmd_Init(HTMLDocument*);
279 void HTMLDocument_OleObj_Init(HTMLDocument*);
280 void HTMLDocument_View_Init(HTMLDocument*);
281 void HTMLDocument_Window_Init(HTMLDocument*);
282 void HTMLDocument_Service_Init(HTMLDocument*);
283 void HTMLDocument_Hlink_Init(HTMLDocument*);
284 void HTMLDocument_ConnectionPoints_Init(HTMLDocument*);
285
286 void HTMLDocument_ConnectionPoints_Destroy(HTMLDocument*);
287
288 NSContainer *NSContainer_Create(HTMLDocument*,NSContainer*);
289 void NSContainer_Release(NSContainer*);
290
291 void HTMLDocument_LockContainer(HTMLDocument*,BOOL);
292 void HTMLDocument_ShowContextMenu(HTMLDocument*,DWORD,POINT*);
293
294 void show_tooltip(HTMLDocument*,DWORD,DWORD,LPCWSTR);
295 void hide_tooltip(HTMLDocument*);
296 HRESULT get_client_disp_property(IOleClientSite*,DISPID,VARIANT*);
297
298 HRESULT ProtocolFactory_Create(REFCLSID,REFIID,void**);
299
300 void close_gecko(void);
301 void register_nsservice(nsIComponentRegistrar*,nsIServiceManager*);
302 void init_nsio(nsIComponentManager*,nsIComponentRegistrar*);
303
304 void hlink_frame_navigate(HTMLDocument*,IHlinkFrame*,LPCWSTR,nsIInputStream*,DWORD);
305
306 void call_property_onchanged(ConnectionPoint*,DISPID);
307
308 void *nsalloc(size_t);
309 void nsfree(void*);
310
311 void nsACString_Init(nsACString*,const char*);
312 PRUint32 nsACString_GetData(const nsACString*,const char**,PRBool*);
313 void nsACString_Finish(nsACString*);
314
315 void nsAString_Init(nsAString*,const PRUnichar*);
316 PRUint32 nsAString_GetData(const nsAString*,const PRUnichar**,PRBool*);
317 void nsAString_Finish(nsAString*);
318
319 nsIInputStream *create_nsstream(const char*,PRInt32);
320 nsICommandParams *create_nscommand_params(void);
321 void nsnode_to_nsstring(nsIDOMNode*,nsAString*);
322
323 BSCallback *create_bscallback(IMoniker*);
324 HRESULT start_binding(BSCallback*);
325 void set_document_bscallback(HTMLDocument*,BSCallback*);
326
327 IHlink *Hlink_Create(void);
328 IHTMLSelectionObject *HTMLSelectionObject_Create(nsISelection*);
329 IHTMLTxtRange *HTMLTxtRange_Create(nsISelection*);
330
331 void HTMLElement_Create(HTMLDOMNode*);
332 void HTMLBodyElement_Create(HTMLElement*);
333 void HTMLInputElement_Create(HTMLElement*);
334 void HTMLSelectElement_Create(HTMLElement*);
335 void HTMLTextAreaElement_Create(HTMLElement*);
336
337 void HTMLElement2_Init(HTMLElement*);
338
339 void HTMLTextContainer_Init(HTMLTextContainer*,HTMLElement*);
340
341 HRESULT HTMLDOMNode_QI(HTMLDOMNode*,REFIID,void**);
342 HRESULT HTMLElement_QI(HTMLElement*,REFIID,void**);
343
344 HTMLDOMNode *get_node(HTMLDocument*,nsIDOMNode*);
345 void release_nodes(HTMLDocument*);
346
347 void install_wine_gecko(void);
348
349 extern DWORD mshtml_tls;
350
351 typedef struct task_t {
352     HTMLDocument *doc;
353
354     enum {
355         TASK_SETDOWNLOADSTATE,
356         TASK_PARSECOMPLETE
357     } task_id;
358
359     struct task_t *next;
360 } task_t;
361
362 typedef struct {
363     HWND thread_hwnd;
364     task_t *task_queue_head;
365     task_t *task_queue_tail;
366 } thread_data_t;
367
368 thread_data_t *get_thread_data(BOOL);
369 HWND get_thread_hwnd(void);
370 void push_task(task_t*);
371 void remove_doc_tasks(HTMLDocument*);
372
373 DEFINE_GUID(CLSID_AboutProtocol, 0x3050F406, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
374 DEFINE_GUID(CLSID_JSProtocol, 0x3050F3B2, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
375 DEFINE_GUID(CLSID_MailtoProtocol, 0x3050F3DA, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
376 DEFINE_GUID(CLSID_ResProtocol, 0x3050F3BC, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
377 DEFINE_GUID(CLSID_SysimageProtocol, 0x76E67A63, 0x06E9, 0x11D2, 0xA8,0x40, 0x00,0x60,0x08,0x05,0x93,0x82);
378
379 DEFINE_GUID(CLSID_CMarkup,0x3050f4fb,0x98b5,0x11cf,0xbb,0x82,0x00,0xaa,0x00,0xbd,0xce,0x0b);
380
381 extern LONG module_ref;
382 #define LOCK_MODULE()   InterlockedIncrement(&module_ref)
383 #define UNLOCK_MODULE() InterlockedDecrement(&module_ref)
384
385 /* memory allocation functions */
386
387 static inline void *mshtml_alloc(size_t len)
388 {
389     return HeapAlloc(GetProcessHeap(), 0, len);
390 }
391
392 static inline void *mshtml_alloc_zero(size_t len)
393 {
394     return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
395 }
396
397 static inline void *mshtml_realloc(void *mem, size_t len)
398 {
399     return HeapReAlloc(GetProcessHeap(), 0, mem, len);
400 }
401
402 static inline BOOL mshtml_free(void *mem)
403 {
404     return HeapFree(GetProcessHeap(), 0, mem);
405 }
406
407 extern HINSTANCE hInst;