More -Wmissing-declarations and -Wwrite-strings warning fixes.
[wine] / dlls / mshtml / oleobj.c
1 /*
2  * Copyright 2005 Jacek Caban
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  */
18
19 #include "config.h"
20
21 #include <stdarg.h>
22 #include <stdio.h>
23
24 #define COBJMACROS
25
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winuser.h"
29 #include "ole2.h"
30 #include "docobj.h"
31
32 #include "mshtml.h"
33
34 #include "wine/debug.h"
35
36 #include "mshtml_private.h"
37
38 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
39
40 /**********************************************************
41  * IOleObject implementation
42  */
43
44 #define OLEOBJ_THIS \
45     HTMLDocument* const This=(HTMLDocument*)((char*)(iface)-offsetof(HTMLDocument,lpOleObjectVtbl));
46
47 static HRESULT WINAPI OleObject_QueryInterface(IOleObject *iface, REFIID riid, void **ppvObject)
48 {
49     OLEOBJ_THIS
50     return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppvObject);
51 }
52
53 static ULONG WINAPI OleObject_AddRef(IOleObject *iface)
54 {
55     OLEOBJ_THIS
56     return IHTMLDocument2_AddRef(HTMLDOC(This));
57 }
58
59 static ULONG WINAPI OleObject_Release(IOleObject *iface)
60 {
61     OLEOBJ_THIS
62     return IHTMLDocument2_Release(HTMLDOC(This));
63 }
64
65 static HRESULT WINAPI OleObject_SetClientSite(IOleObject *iface, IOleClientSite *pClientSite)
66 {
67     OLEOBJ_THIS
68     TRACE("(%p)->(%p)\n", This, pClientSite);
69
70     if(This->client)
71         IOleClientSite_Release(This->client);
72     if(pClientSite)
73         IOleClientSite_AddRef(pClientSite);
74     This->client = pClientSite;
75
76     return S_OK;
77 }
78
79 static HRESULT WINAPI OleObject_GetClientSite(IOleObject *iface, IOleClientSite **ppClientSite)
80 {
81     OLEOBJ_THIS
82     TRACE("(%p)->(%p)\n", This, ppClientSite);
83
84     if(!ppClientSite)
85         return E_INVALIDARG;
86
87     if(This->client)
88         IOleClientSite_AddRef(This->client);
89     *ppClientSite = This->client;
90
91     return S_OK;
92 }
93
94 static HRESULT WINAPI OleObject_SetHostNames(IOleObject *iface, LPCOLESTR szContainerApp, LPCOLESTR szContainerObj)
95 {
96     OLEOBJ_THIS
97     FIXME("(%p)->(%s %s)\n", This, debugstr_w(szContainerApp), debugstr_w(szContainerObj));
98     return E_NOTIMPL;
99 }
100
101 static HRESULT WINAPI OleObject_Close(IOleObject *iface, DWORD dwSaveOption)
102 {
103     OLEOBJ_THIS
104     FIXME("(%p)->(%08lx)\n", This, dwSaveOption);
105     return E_NOTIMPL;
106 }
107
108 static HRESULT WINAPI OleObject_SetMoniker(IOleObject *iface, DWORD dwWhichMoniker, IMoniker *pmk)
109 {
110     OLEOBJ_THIS
111     FIXME("(%p %ld %p)->()\n", This, dwWhichMoniker, pmk);
112     return E_NOTIMPL;
113 }
114
115 static HRESULT WINAPI OleObject_GetMoniker(IOleObject *iface, DWORD dwAssign, DWORD dwWhichMoniker, IMoniker **ppmk)
116 {
117     OLEOBJ_THIS
118     FIXME("(%p)->(%ld %ld %p)\n", This, dwAssign, dwWhichMoniker, ppmk);
119     return E_NOTIMPL;
120 }
121
122 static HRESULT WINAPI OleObject_InitFromData(IOleObject *iface, IDataObject *pDataObject, BOOL fCreation,
123                                         DWORD dwReserved)
124 {
125     OLEOBJ_THIS
126     FIXME("(%p)->(%p %x %ld)\n", This, pDataObject, fCreation, dwReserved);
127     return E_NOTIMPL;
128 }
129
130 static HRESULT WINAPI OleObject_GetClipboardData(IOleObject *iface, DWORD dwReserved, IDataObject **ppDataObject)
131 {
132     OLEOBJ_THIS
133     FIXME("(%p)->(%ld %p)\n", This, dwReserved, ppDataObject);
134     return E_NOTIMPL;
135 }
136
137 static HRESULT WINAPI OleObject_DoVerb(IOleObject *iface, LONG iVerb, LPMSG lpmsg, IOleClientSite *pActiveSite,
138                                         LONG lindex, HWND hwndParent, LPCRECT lprcPosRect)
139 {
140     OLEOBJ_THIS
141     IOleDocumentSite *pDocSite;
142     HRESULT hres;
143
144     TRACE("(%p)->(%ld %p %p %ld %p %p)\n", This, iVerb, lpmsg, pActiveSite, lindex, hwndParent, lprcPosRect);
145
146     if(iVerb != OLEIVERB_SHOW && iVerb != OLEIVERB_UIACTIVATE) {
147         FIXME("iVerb = %ld not supported\n", iVerb);
148         return E_NOTIMPL;
149     }
150
151     if(!pActiveSite)
152         pActiveSite = This->client;
153
154     hres = IOleClientSite_QueryInterface(pActiveSite, &IID_IOleDocumentSite, (void**)&pDocSite);
155     if(SUCCEEDED(hres)) {
156         IOleContainer *pContainer;
157         hres = IOleClientSite_GetContainer(pActiveSite, &pContainer);
158         if(SUCCEEDED(hres)) {
159             IOleContainer_LockContainer(pContainer, TRUE);
160             /* FIXME: Create new IOleDocumentView. See CreateView for more info. */
161             hres = IOleDocumentSite_ActivateMe(pDocSite, DOCVIEW(This));
162             IOleContainer_Release(pContainer);
163         }
164         IOleDocumentSite_Release(pDocSite);
165     }else {
166         hres = IOleDocumentView_UIActivate(DOCVIEW(This), TRUE);
167         if(SUCCEEDED(hres)) {
168             if(lprcPosRect) {
169                 RECT rect; /* We need to pass rect as not const pointer */
170                 memcpy(&rect, lprcPosRect, sizeof(RECT));
171                 IOleDocumentView_SetRect(DOCVIEW(This), &rect);
172             }
173             IOleDocumentView_Show(DOCVIEW(This), TRUE);
174         }
175     }
176
177     return hres;
178 }
179
180 static HRESULT WINAPI OleObject_EnumVerbs(IOleObject *iface, IEnumOLEVERB **ppEnumOleVerb)
181 {
182     OLEOBJ_THIS
183     FIXME("(%p)->(%p)\n", This, ppEnumOleVerb);
184     return E_NOTIMPL;
185 }
186
187 static HRESULT WINAPI OleObject_Update(IOleObject *iface)
188 {
189     OLEOBJ_THIS
190     FIXME("(%p)\n", This);
191     return E_NOTIMPL;
192 }
193
194 static HRESULT WINAPI OleObject_IsUpToDate(IOleObject *iface)
195 {
196     OLEOBJ_THIS
197     FIXME("(%p)\n", This);
198     return E_NOTIMPL;
199 }
200
201 static HRESULT WINAPI OleObject_GetUserClassID(IOleObject *iface, CLSID *pClsid)
202 {
203     OLEOBJ_THIS
204     TRACE("(%p)->(%p)\n", This, pClsid);
205
206     if(!pClsid)
207         return E_INVALIDARG;
208
209     memcpy(pClsid, &CLSID_HTMLDocument, sizeof(GUID));
210     return S_OK;
211 }
212
213 static HRESULT WINAPI OleObject_GetUserType(IOleObject *iface, DWORD dwFormOfType, LPOLESTR *pszUserType)
214 {
215     OLEOBJ_THIS
216     FIXME("(%p)->(%ld %p)\n", This, dwFormOfType, pszUserType);
217     return E_NOTIMPL;
218 }
219
220 static HRESULT WINAPI OleObject_SetExtent(IOleObject *iface, DWORD dwDrawAspect, SIZEL *psizel)
221 {
222     OLEOBJ_THIS
223     FIXME("(%p)->(%ld %p)\n", This, dwDrawAspect, psizel);
224     return E_NOTIMPL;
225 }
226
227 static HRESULT WINAPI OleObject_GetExtent(IOleObject *iface, DWORD dwDrawAspect, SIZEL *psizel)
228 {
229     OLEOBJ_THIS
230     FIXME("(%p)->(%ld %p)\n", This, dwDrawAspect, psizel);
231     return E_NOTIMPL;
232 }
233
234 static HRESULT WINAPI OleObject_Advise(IOleObject *iface, IAdviseSink *pAdvSink, DWORD *pdwConnection)
235 {
236     OLEOBJ_THIS
237     FIXME("(%p)->(%p %p)\n", This, pAdvSink, pdwConnection);
238     return E_NOTIMPL;
239 }
240
241 static HRESULT WINAPI OleObject_Unadvise(IOleObject *iface, DWORD dwConnection)
242 {
243     OLEOBJ_THIS
244     FIXME("(%p)->(%ld)\n", This, dwConnection);
245     return E_NOTIMPL;
246 }
247
248 static HRESULT WINAPI OleObject_EnumAdvise(IOleObject *iface, IEnumSTATDATA **ppenumAdvise)
249 {
250     OLEOBJ_THIS
251     FIXME("(%p)->(%p)\n", This, ppenumAdvise);
252     return E_NOTIMPL;
253 }
254
255 static HRESULT WINAPI OleObject_GetMiscStatus(IOleObject *iface, DWORD dwAspect, DWORD *pdwStatus)
256 {
257     OLEOBJ_THIS
258     FIXME("(%p)->(%ld %p)\n", This, dwAspect, pdwStatus);
259     return E_NOTIMPL;
260 }
261
262 static HRESULT WINAPI OleObject_SetColorScheme(IOleObject *iface, LOGPALETTE *pLogpal)
263 {
264     OLEOBJ_THIS
265     FIXME("(%p)->(%p)\n", This, pLogpal);
266     return E_NOTIMPL;
267 }
268
269 static IOleObjectVtbl OleObjectVtbl = {
270     OleObject_QueryInterface,
271     OleObject_AddRef,
272     OleObject_Release,
273     OleObject_SetClientSite,
274     OleObject_GetClientSite,
275     OleObject_SetHostNames,
276     OleObject_Close,
277     OleObject_SetMoniker,
278     OleObject_GetMoniker,
279     OleObject_InitFromData,
280     OleObject_GetClipboardData,
281     OleObject_DoVerb,
282     OleObject_EnumVerbs,
283     OleObject_Update,
284     OleObject_IsUpToDate,
285     OleObject_GetUserClassID,
286     OleObject_GetUserType,
287     OleObject_SetExtent,
288     OleObject_GetExtent,
289     OleObject_Advise,
290     OleObject_Unadvise,
291     OleObject_EnumAdvise,
292     OleObject_GetMiscStatus,
293     OleObject_SetColorScheme
294 };
295
296 /**********************************************************
297  * IOleDocument implementation
298  */
299
300 #define OLEDOC_THIS \
301     HTMLDocument* const This=(HTMLDocument*)((char*)(iface)-offsetof(HTMLDocument,lpOleDocumentVtbl));
302
303 static HRESULT WINAPI OleDocument_QueryInterface(IOleDocument *iface, REFIID riid, void **ppvObject)
304 {
305     OLEDOC_THIS
306     return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppvObject);
307 }
308
309 static ULONG WINAPI OleDocument_AddRef(IOleDocument *iface)
310 {
311     OLEDOC_THIS
312     return IHTMLDocument2_AddRef(HTMLDOC(This));
313 }
314
315 static ULONG WINAPI OleDocument_Release(IOleDocument *iface)
316 {
317     OLEDOC_THIS
318     return IHTMLDocument2_Release(HTMLDOC(This));
319 }
320
321 static HRESULT WINAPI OleDocument_CreateView(IOleDocument *iface, IOleInPlaceSite *pIPSite, IStream *pstm,
322                                    DWORD dwReserved, IOleDocumentView **ppView)
323 {
324     OLEDOC_THIS
325     HRESULT hres;
326
327     TRACE("(%p)->(%p %p %ld %p)\n", This, pIPSite, pstm, dwReserved, ppView);
328
329     if(!ppView)
330         return E_INVALIDARG;
331
332     /* FIXME:
333      * Windows implementation creates new IOleDocumentView when function is called for the
334      * first time and returns E_FAIL when it is called for the second time, but it doesn't matter
335      * if the application uses returned interfaces, passed to ActivateMe or returned by
336      * QueryInterface, so there is no reason to create new interface. This needs more testing.
337      */
338
339     if(pIPSite) {
340         hres = IOleDocumentView_SetInPlaceSite(DOCVIEW(This), pIPSite);
341         if(FAILED(hres))
342             return hres;
343     }
344
345     if(pstm)
346         FIXME("pstm is not supported\n");
347
348     IOleDocumentView_AddRef(DOCVIEW(This));
349     *ppView = DOCVIEW(This);
350     return S_OK;
351 }
352
353 static HRESULT WINAPI OleDocument_GetDocMiscStatus(IOleDocument *iface, DWORD *pdwStatus)
354 {
355     OLEDOC_THIS
356     FIXME("(%p)->(%p)\n", This, pdwStatus);
357     return E_NOTIMPL;
358 }
359
360 static HRESULT WINAPI OleDocument_EnumViews(IOleDocument *iface, IEnumOleDocumentViews **ppEnum,
361                                    IOleDocumentView **ppView)
362 {
363     OLEDOC_THIS
364     FIXME("(%p)->(%p %p)\n", This, ppEnum, ppView);
365     return E_NOTIMPL;
366 }
367
368 static IOleDocumentVtbl OleDocumentVtbl = {
369     OleDocument_QueryInterface,
370     OleDocument_AddRef,
371     OleDocument_Release,
372     OleDocument_CreateView,
373     OleDocument_GetDocMiscStatus,
374     OleDocument_EnumViews
375 };
376
377 /**********************************************************
378  * IOleInPlaceActiveObject implementation
379  */
380
381 #define ACTOBJ_THIS \
382     HTMLDocument* const This=(HTMLDocument*)((char*)(iface)-offsetof(HTMLDocument,lpOleInPlaceActiveObjectVtbl));
383
384 static HRESULT WINAPI OleInPlaceActiveObject_QueryInterface(IOleInPlaceActiveObject *iface, REFIID riid, void **ppvObject)
385 {
386     ACTOBJ_THIS
387     return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppvObject);
388 }
389
390 static ULONG WINAPI OleInPlaceActiveObject_AddRef(IOleInPlaceActiveObject *iface)
391 {
392     ACTOBJ_THIS
393     return IHTMLDocument2_AddRef(HTMLDOC(This));
394 }
395
396 static ULONG WINAPI OleInPlaceActiveObject_Release(IOleInPlaceActiveObject *iface)
397 {
398     ACTOBJ_THIS
399     return IHTMLDocument2_Release(HTMLDOC(This));
400 }
401
402 static HRESULT WINAPI OleInPlaceActiveObject_GetWindow(IOleInPlaceActiveObject *iface, HWND *phwnd)
403 {
404     ACTOBJ_THIS
405     TRACE("(%p)->(%p)\n", This, phwnd);
406
407     if(!phwnd)
408         return E_INVALIDARG;
409
410     *phwnd = This->hwnd;
411     return S_OK;
412 }
413
414 static HRESULT WINAPI OleInPlaceActiveObject_ContextSensitiveHelp(IOleInPlaceActiveObject *iface, BOOL fEnterMode)
415 {
416     ACTOBJ_THIS
417     FIXME("(%p)->(%x)\n", This, fEnterMode);
418     return E_NOTIMPL;
419 }
420
421 static HRESULT WINAPI OleInPlaceActiveObject_TranslateAccelerator(IOleInPlaceActiveObject *iface, LPMSG lpmsg)
422 {
423     ACTOBJ_THIS
424     FIXME("(%p)->(%p)\n", This, lpmsg);
425     return E_NOTIMPL;
426 }
427
428 static HRESULT WINAPI OleInPlaceActiveObject_OnFrameWindowActivate(IOleInPlaceActiveObject *iface, BOOL fActivate)
429 {
430     ACTOBJ_THIS
431     FIXME("(%p)->(%x)\n", This, fActivate);
432     return E_NOTIMPL;
433 }
434
435 static HRESULT WINAPI OleInPlaceActiveObject_OnDocWindowActivate(IOleInPlaceActiveObject *iface, BOOL fActivate)
436 {
437     ACTOBJ_THIS
438     FIXME("(%p)->(%x)\n", This, fActivate);
439     return E_NOTIMPL;
440 }
441
442 static HRESULT WINAPI OleInPlaceActiveObject_ResizeBorder(IOleInPlaceActiveObject *iface, LPCRECT prcBorder,
443                                                 IOleInPlaceUIWindow *pUIWindow, BOOL fFrameWindow)
444 {
445     ACTOBJ_THIS
446     FIXME("(%p)->(%p %p %x)\n", This, prcBorder, pUIWindow, fFrameWindow);
447     return E_NOTIMPL;
448 }
449
450 static HRESULT WINAPI OleInPlaceActiveObject_EnableModeless(IOleInPlaceActiveObject *iface, BOOL fEnable)
451 {
452     ACTOBJ_THIS
453     FIXME("(%p)->(%x)\n", This, fEnable);
454     return E_NOTIMPL;
455 }
456
457 static IOleInPlaceActiveObjectVtbl OleInPlaceActiveObjectVtbl = {
458     OleInPlaceActiveObject_QueryInterface,
459     OleInPlaceActiveObject_AddRef,
460     OleInPlaceActiveObject_Release,
461     OleInPlaceActiveObject_GetWindow,
462     OleInPlaceActiveObject_ContextSensitiveHelp,
463     OleInPlaceActiveObject_TranslateAccelerator,
464     OleInPlaceActiveObject_OnFrameWindowActivate,
465     OleInPlaceActiveObject_OnDocWindowActivate,
466     OleInPlaceActiveObject_ResizeBorder,
467     OleInPlaceActiveObject_EnableModeless
468 };
469
470 void HTMLDocument_OleObj_Init(HTMLDocument *This)
471 {
472     This->lpOleObjectVtbl = &OleObjectVtbl;
473     This->lpOleDocumentVtbl = &OleDocumentVtbl;
474     This->lpOleInPlaceActiveObjectVtbl = &OleInPlaceActiveObjectVtbl;
475
476     This->client = NULL;
477 }