Added QueryStatus implementation.
[wine/multimedia.git] / dlls / mshtml / oleobj.c
blobd798befa3eba9dd82aed2941b06f501985c5e799
1 /*
2 * Copyright 2005 Jacek Caban
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.
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.
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
19 #include "config.h"
21 #include <stdarg.h>
22 #include <stdio.h>
24 #define COBJMACROS
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winuser.h"
29 #include "ole2.h"
30 #include "docobj.h"
32 #include "mshtml.h"
33 #include "mshtmhst.h"
35 #include "wine/debug.h"
37 #include "mshtml_private.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
41 /**********************************************************
42 * IOleObject implementation
45 #define OLEOBJ_THIS(iface) DEFINE_THIS(HTMLDocument, OleObject, iface)
47 static HRESULT WINAPI OleObject_QueryInterface(IOleObject *iface, REFIID riid, void **ppvObject)
49 HTMLDocument *This = OLEOBJ_THIS(iface);
50 return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppvObject);
53 static ULONG WINAPI OleObject_AddRef(IOleObject *iface)
55 HTMLDocument *This = OLEOBJ_THIS(iface);
56 return IHTMLDocument2_AddRef(HTMLDOC(This));
59 static ULONG WINAPI OleObject_Release(IOleObject *iface)
61 HTMLDocument *This = OLEOBJ_THIS(iface);
62 return IHTMLDocument2_Release(HTMLDOC(This));
65 static HRESULT WINAPI OleObject_SetClientSite(IOleObject *iface, IOleClientSite *pClientSite)
67 HTMLDocument *This = OLEOBJ_THIS(iface);
68 IDocHostUIHandler *pDocHostUIHandler = NULL;
69 HRESULT hres;
71 TRACE("(%p)->(%p)\n", This, pClientSite);
73 if(This->client)
74 IOleClientSite_Release(This->client);
76 if(This->hostui)
77 IDocHostUIHandler_Release(This->hostui);
79 if(!pClientSite) {
80 This->client = NULL;
81 return S_OK;
84 hres = IOleObject_QueryInterface(pClientSite, &IID_IDocHostUIHandler, (void**)&pDocHostUIHandler);
85 if(SUCCEEDED(hres)) {
86 DOCHOSTUIINFO hostinfo;
87 LPOLESTR key_path = NULL, override_key_path = NULL;
88 IDocHostUIHandler2 *pDocHostUIHandler2;
90 memset(&hostinfo, 0, sizeof(DOCHOSTUIINFO));
91 hostinfo.cbSize = sizeof(DOCHOSTUIINFO);
92 hres = IDocHostUIHandler_GetHostInfo(pDocHostUIHandler, &hostinfo);
93 if(SUCCEEDED(hres))
94 /* FIXME: use hostinfo */
95 TRACE("hostinfo = {%lu %08lx %08lx %s %s}\n",
96 hostinfo.cbSize, hostinfo.dwFlags, hostinfo.dwDoubleClick,
97 debugstr_w(hostinfo.pchHostCss), debugstr_w(hostinfo.pchHostNS));
99 if(!This->has_key_path) {
100 hres = IDocHostUIHandler_GetOptionKeyPath(pDocHostUIHandler, &key_path, 0);
101 if(hres == S_OK && key_path) {
102 if(key_path[0]) {
103 /* FIXME: use key_path */
104 TRACE("key_path = %s\n", debugstr_w(key_path));
106 CoTaskMemFree(key_path);
109 hres = IDocHostUIHandler_QueryInterface(pDocHostUIHandler, &IID_IDocHostUIHandler2,
110 (void**)&pDocHostUIHandler2);
111 if(SUCCEEDED(hres)) {
112 hres = IDocHostUIHandler2_GetOverrideKeyPath(pDocHostUIHandler2, &override_key_path, 0);
113 if(hres == S_OK && override_key_path && override_key_path[0]) {
114 if(override_key_path[0]) {
115 /*FIXME: use override_key_path */
116 TRACE("override_key_path = %s\n", debugstr_w(override_key_path));
118 CoTaskMemFree(override_key_path);
122 This->has_key_path = TRUE;
126 /* Native calls here GetWindow. What is it for?
127 * We don't have anything to do with it here (yet). */
128 if(pClientSite) {
129 IOleWindow *pOleWindow = NULL;
130 HWND hwnd;
132 hres = IOleClientSite_QueryInterface(pClientSite, &IID_IOleWindow, (void**)&pOleWindow);
133 if(SUCCEEDED(hres)) {
134 IOleWindow_GetWindow(pOleWindow, &hwnd);
135 IOleWindow_Release(pOleWindow);
139 IOleClientSite_AddRef(pClientSite);
140 This->client = pClientSite;
141 This->hostui = pDocHostUIHandler;
143 return S_OK;
146 static HRESULT WINAPI OleObject_GetClientSite(IOleObject *iface, IOleClientSite **ppClientSite)
148 HTMLDocument *This = OLEOBJ_THIS(iface);
150 TRACE("(%p)->(%p)\n", This, ppClientSite);
152 if(!ppClientSite)
153 return E_INVALIDARG;
155 if(This->client)
156 IOleClientSite_AddRef(This->client);
157 *ppClientSite = This->client;
159 return S_OK;
162 static HRESULT WINAPI OleObject_SetHostNames(IOleObject *iface, LPCOLESTR szContainerApp, LPCOLESTR szContainerObj)
164 HTMLDocument *This = OLEOBJ_THIS(iface);
165 FIXME("(%p)->(%s %s)\n", This, debugstr_w(szContainerApp), debugstr_w(szContainerObj));
166 return E_NOTIMPL;
169 static HRESULT WINAPI OleObject_Close(IOleObject *iface, DWORD dwSaveOption)
171 HTMLDocument *This = OLEOBJ_THIS(iface);
172 HRESULT hres;
174 FIXME("(%p)->(%08lx)\n", This, dwSaveOption);
176 if(This->client) {
177 IOleContainer *container;
178 hres = IOleClientSite_GetContainer(This->client, &container);
179 if(SUCCEEDED(hres)) {
180 IOleContainer_LockContainer(container, FALSE);
181 IOleContainer_Release(container);
185 return S_OK;
188 static HRESULT WINAPI OleObject_SetMoniker(IOleObject *iface, DWORD dwWhichMoniker, IMoniker *pmk)
190 HTMLDocument *This = OLEOBJ_THIS(iface);
191 FIXME("(%p %ld %p)->()\n", This, dwWhichMoniker, pmk);
192 return E_NOTIMPL;
195 static HRESULT WINAPI OleObject_GetMoniker(IOleObject *iface, DWORD dwAssign, DWORD dwWhichMoniker, IMoniker **ppmk)
197 HTMLDocument *This = OLEOBJ_THIS(iface);
198 FIXME("(%p)->(%ld %ld %p)\n", This, dwAssign, dwWhichMoniker, ppmk);
199 return E_NOTIMPL;
202 static HRESULT WINAPI OleObject_InitFromData(IOleObject *iface, IDataObject *pDataObject, BOOL fCreation,
203 DWORD dwReserved)
205 HTMLDocument *This = OLEOBJ_THIS(iface);
206 FIXME("(%p)->(%p %x %ld)\n", This, pDataObject, fCreation, dwReserved);
207 return E_NOTIMPL;
210 static HRESULT WINAPI OleObject_GetClipboardData(IOleObject *iface, DWORD dwReserved, IDataObject **ppDataObject)
212 HTMLDocument *This = OLEOBJ_THIS(iface);
213 FIXME("(%p)->(%ld %p)\n", This, dwReserved, ppDataObject);
214 return E_NOTIMPL;
217 static HRESULT WINAPI OleObject_DoVerb(IOleObject *iface, LONG iVerb, LPMSG lpmsg, IOleClientSite *pActiveSite,
218 LONG lindex, HWND hwndParent, LPCRECT lprcPosRect)
220 HTMLDocument *This = OLEOBJ_THIS(iface);
221 IOleDocumentSite *pDocSite;
222 HRESULT hres;
224 TRACE("(%p)->(%ld %p %p %ld %p %p)\n", This, iVerb, lpmsg, pActiveSite, lindex, hwndParent, lprcPosRect);
226 if(iVerb != OLEIVERB_SHOW && iVerb != OLEIVERB_UIACTIVATE) {
227 FIXME("iVerb = %ld not supported\n", iVerb);
228 return E_NOTIMPL;
231 if(!pActiveSite)
232 pActiveSite = This->client;
234 hres = IOleClientSite_QueryInterface(pActiveSite, &IID_IOleDocumentSite, (void**)&pDocSite);
235 if(SUCCEEDED(hres)) {
236 IOleContainer *pContainer;
237 hres = IOleClientSite_GetContainer(pActiveSite, &pContainer);
238 if(SUCCEEDED(hres)) {
239 IOleContainer_LockContainer(pContainer, TRUE);
240 IOleContainer_Release(pContainer);
242 /* FIXME: Create new IOleDocumentView. See CreateView for more info. */
243 hres = IOleDocumentSite_ActivateMe(pDocSite, DOCVIEW(This));
244 IOleDocumentSite_Release(pDocSite);
245 }else {
246 hres = IOleDocumentView_UIActivate(DOCVIEW(This), TRUE);
247 if(SUCCEEDED(hres)) {
248 if(lprcPosRect) {
249 RECT rect; /* We need to pass rect as not const pointer */
250 memcpy(&rect, lprcPosRect, sizeof(RECT));
251 IOleDocumentView_SetRect(DOCVIEW(This), &rect);
253 IOleDocumentView_Show(DOCVIEW(This), TRUE);
257 return hres;
260 static HRESULT WINAPI OleObject_EnumVerbs(IOleObject *iface, IEnumOLEVERB **ppEnumOleVerb)
262 HTMLDocument *This = OLEOBJ_THIS(iface);
263 FIXME("(%p)->(%p)\n", This, ppEnumOleVerb);
264 return E_NOTIMPL;
267 static HRESULT WINAPI OleObject_Update(IOleObject *iface)
269 HTMLDocument *This = OLEOBJ_THIS(iface);
270 FIXME("(%p)\n", This);
271 return E_NOTIMPL;
274 static HRESULT WINAPI OleObject_IsUpToDate(IOleObject *iface)
276 HTMLDocument *This = OLEOBJ_THIS(iface);
277 FIXME("(%p)\n", This);
278 return E_NOTIMPL;
281 static HRESULT WINAPI OleObject_GetUserClassID(IOleObject *iface, CLSID *pClsid)
283 HTMLDocument *This = OLEOBJ_THIS(iface);
285 TRACE("(%p)->(%p)\n", This, pClsid);
287 if(!pClsid)
288 return E_INVALIDARG;
290 memcpy(pClsid, &CLSID_HTMLDocument, sizeof(GUID));
291 return S_OK;
294 static HRESULT WINAPI OleObject_GetUserType(IOleObject *iface, DWORD dwFormOfType, LPOLESTR *pszUserType)
296 HTMLDocument *This = OLEOBJ_THIS(iface);
297 FIXME("(%p)->(%ld %p)\n", This, dwFormOfType, pszUserType);
298 return E_NOTIMPL;
301 static HRESULT WINAPI OleObject_SetExtent(IOleObject *iface, DWORD dwDrawAspect, SIZEL *psizel)
303 HTMLDocument *This = OLEOBJ_THIS(iface);
304 FIXME("(%p)->(%ld %p)\n", This, dwDrawAspect, psizel);
305 return E_NOTIMPL;
308 static HRESULT WINAPI OleObject_GetExtent(IOleObject *iface, DWORD dwDrawAspect, SIZEL *psizel)
310 HTMLDocument *This = OLEOBJ_THIS(iface);
311 FIXME("(%p)->(%ld %p)\n", This, dwDrawAspect, psizel);
312 return E_NOTIMPL;
315 static HRESULT WINAPI OleObject_Advise(IOleObject *iface, IAdviseSink *pAdvSink, DWORD *pdwConnection)
317 HTMLDocument *This = OLEOBJ_THIS(iface);
318 FIXME("(%p)->(%p %p)\n", This, pAdvSink, pdwConnection);
319 return E_NOTIMPL;
322 static HRESULT WINAPI OleObject_Unadvise(IOleObject *iface, DWORD dwConnection)
324 HTMLDocument *This = OLEOBJ_THIS(iface);
325 FIXME("(%p)->(%ld)\n", This, dwConnection);
326 return E_NOTIMPL;
329 static HRESULT WINAPI OleObject_EnumAdvise(IOleObject *iface, IEnumSTATDATA **ppenumAdvise)
331 HTMLDocument *This = OLEOBJ_THIS(iface);
332 FIXME("(%p)->(%p)\n", This, ppenumAdvise);
333 return E_NOTIMPL;
336 static HRESULT WINAPI OleObject_GetMiscStatus(IOleObject *iface, DWORD dwAspect, DWORD *pdwStatus)
338 HTMLDocument *This = OLEOBJ_THIS(iface);
339 FIXME("(%p)->(%ld %p)\n", This, dwAspect, pdwStatus);
340 return E_NOTIMPL;
343 static HRESULT WINAPI OleObject_SetColorScheme(IOleObject *iface, LOGPALETTE *pLogpal)
345 HTMLDocument *This = OLEOBJ_THIS(iface);
346 FIXME("(%p)->(%p)\n", This, pLogpal);
347 return E_NOTIMPL;
350 #undef OLEPBJ_THIS
352 static const IOleObjectVtbl OleObjectVtbl = {
353 OleObject_QueryInterface,
354 OleObject_AddRef,
355 OleObject_Release,
356 OleObject_SetClientSite,
357 OleObject_GetClientSite,
358 OleObject_SetHostNames,
359 OleObject_Close,
360 OleObject_SetMoniker,
361 OleObject_GetMoniker,
362 OleObject_InitFromData,
363 OleObject_GetClipboardData,
364 OleObject_DoVerb,
365 OleObject_EnumVerbs,
366 OleObject_Update,
367 OleObject_IsUpToDate,
368 OleObject_GetUserClassID,
369 OleObject_GetUserType,
370 OleObject_SetExtent,
371 OleObject_GetExtent,
372 OleObject_Advise,
373 OleObject_Unadvise,
374 OleObject_EnumAdvise,
375 OleObject_GetMiscStatus,
376 OleObject_SetColorScheme
379 /**********************************************************
380 * IOleDocument implementation
383 #define OLEDOC_THIS(iface) DEFINE_THIS(HTMLDocument, OleDocument, iface)
385 static HRESULT WINAPI OleDocument_QueryInterface(IOleDocument *iface, REFIID riid, void **ppvObject)
387 HTMLDocument *This = OLEDOC_THIS(iface);
388 return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppvObject);
391 static ULONG WINAPI OleDocument_AddRef(IOleDocument *iface)
393 HTMLDocument *This = OLEDOC_THIS(iface);
394 return IHTMLDocument2_AddRef(HTMLDOC(This));
397 static ULONG WINAPI OleDocument_Release(IOleDocument *iface)
399 HTMLDocument *This = OLEDOC_THIS(iface);
400 return IHTMLDocument2_Release(HTMLDOC(This));
403 static HRESULT WINAPI OleDocument_CreateView(IOleDocument *iface, IOleInPlaceSite *pIPSite, IStream *pstm,
404 DWORD dwReserved, IOleDocumentView **ppView)
406 HTMLDocument *This = OLEDOC_THIS(iface);
407 HRESULT hres;
409 TRACE("(%p)->(%p %p %ld %p)\n", This, pIPSite, pstm, dwReserved, ppView);
411 if(!ppView)
412 return E_INVALIDARG;
414 /* FIXME:
415 * Windows implementation creates new IOleDocumentView when function is called for the
416 * first time and returns E_FAIL when it is called for the second time, but it doesn't matter
417 * if the application uses returned interfaces, passed to ActivateMe or returned by
418 * QueryInterface, so there is no reason to create new interface. This needs more testing.
421 if(pIPSite) {
422 hres = IOleDocumentView_SetInPlaceSite(DOCVIEW(This), pIPSite);
423 if(FAILED(hres))
424 return hres;
427 if(pstm)
428 FIXME("pstm is not supported\n");
430 IOleDocumentView_AddRef(DOCVIEW(This));
431 *ppView = DOCVIEW(This);
432 return S_OK;
435 static HRESULT WINAPI OleDocument_GetDocMiscStatus(IOleDocument *iface, DWORD *pdwStatus)
437 HTMLDocument *This = OLEDOC_THIS(iface);
438 FIXME("(%p)->(%p)\n", This, pdwStatus);
439 return E_NOTIMPL;
442 static HRESULT WINAPI OleDocument_EnumViews(IOleDocument *iface, IEnumOleDocumentViews **ppEnum,
443 IOleDocumentView **ppView)
445 HTMLDocument *This = OLEDOC_THIS(iface);
446 FIXME("(%p)->(%p %p)\n", This, ppEnum, ppView);
447 return E_NOTIMPL;
450 #undef OLEDOC_THIS
452 static const IOleDocumentVtbl OleDocumentVtbl = {
453 OleDocument_QueryInterface,
454 OleDocument_AddRef,
455 OleDocument_Release,
456 OleDocument_CreateView,
457 OleDocument_GetDocMiscStatus,
458 OleDocument_EnumViews
461 /**********************************************************
462 * IOleCommandTarget implementation
465 #define CMDTARGET_THIS(iface) DEFINE_THIS(HTMLDocument, OleCommandTarget, iface)
467 static const OLECMDF status_table[OLECMDID_GETPRINTTEMPLATE+1] = {
469 OLECMDF_SUPPORTED, /* OLECMDID_OPEN */
470 OLECMDF_SUPPORTED, /* OLECMDID_NEW */
471 OLECMDF_SUPPORTED, /* OLECMDID_SAVE */
472 OLECMDF_SUPPORTED|OLECMDF_ENABLED, /* OLECMDID_SAVEAS */
473 OLECMDF_SUPPORTED, /* OLECMDID_SAVECOPYAS */
474 OLECMDF_SUPPORTED|OLECMDF_ENABLED, /* OLECMDID_PRINT */
475 OLECMDF_SUPPORTED|OLECMDF_ENABLED, /* OLECMDID_PRINTPREVIEW */
476 OLECMDF_SUPPORTED|OLECMDF_ENABLED, /* OLECMDID_PAGESETUP */
477 OLECMDF_SUPPORTED, /* OLECMDID_SPELL */
478 OLECMDF_SUPPORTED|OLECMDF_ENABLED, /* OLECMDID_PROPERTIES */
479 OLECMDF_SUPPORTED, /* OLECMDID_CUT */
480 OLECMDF_SUPPORTED, /* OLECMDID_COPY */
481 OLECMDF_SUPPORTED, /* OLECMDID_PASTE */
482 OLECMDF_SUPPORTED, /* OLECMDID_PASTESPECIAL */
483 OLECMDF_SUPPORTED, /* OLECMDID_UNDO */
484 OLECMDF_SUPPORTED, /* OLECMDID_RENDO */
485 OLECMDF_SUPPORTED|OLECMDF_ENABLED, /* OLECMDID_SELECTALL */
486 OLECMDF_SUPPORTED, /* OLECMDID_CLEARSELECTION */
487 OLECMDF_SUPPORTED, /* OLECMDID_ZOOM */
488 OLECMDF_SUPPORTED, /* OLECMDID_GETZOOMRANGE */
490 OLECMDF_SUPPORTED|OLECMDF_ENABLED, /* OLECMDID_REFRESH */
491 OLECMDF_SUPPORTED|OLECMDF_ENABLED, /* OLECMDID_STOP */
492 0,0,0,0,0,0,
493 OLECMDF_SUPPORTED, /* OLECMDID_STOPDOWNLOAD */
494 0,0,
495 OLECMDF_SUPPORTED, /* OLECMDID_DELETE */
496 0,0,
497 OLECMDF_SUPPORTED, /* OLECMDID_ENABLE_INTERACTION */
498 OLECMDF_SUPPORTED, /* OLECMDID_ONUNLOAD */
499 0,0,0,0,0,
500 OLECMDF_SUPPORTED, /* OLECMDID_SHOWPAGESETUP */
501 OLECMDF_SUPPORTED, /* OLECMDID_SHOWPRINT */
502 0,0,
503 OLECMDF_SUPPORTED, /* OLECMDID_CLOSE */
504 0,0,0,
505 OLECMDF_SUPPORTED, /* OLECMDID_SETPRINTTEMPLATE */
506 OLECMDF_SUPPORTED /* OLECMDID_GETPRINTTEMPLATE */
509 static HRESULT WINAPI OleCommandTarget_QueryInterface(IOleCommandTarget *iface, REFIID riid, void **ppv)
511 HTMLDocument *This = CMDTARGET_THIS(iface);
512 return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppv);
515 static ULONG WINAPI OleCommandTarget_AddRef(IOleCommandTarget *iface)
517 HTMLDocument *This = CMDTARGET_THIS(iface);
518 return IHTMLDocument2_AddRef(HTMLDOC(This));
521 static ULONG WINAPI OleCommandTarget_Release(IOleCommandTarget *iface)
523 HTMLDocument *This = CMDTARGET_THIS(iface);
524 return IHTMLDocument_Release(HTMLDOC(This));
527 static HRESULT WINAPI OleCommandTarget_QueryStatus(IOleCommandTarget *iface, const GUID *pguidCmdGroup,
528 ULONG cCmds, OLECMD prgCmds[], OLECMDTEXT *pCmdText)
530 HTMLDocument *This = CMDTARGET_THIS(iface);
531 HRESULT hres = S_OK;
533 TRACE("(%p)->(%s %ld %p %p)\n", This, debugstr_guid(pguidCmdGroup), cCmds, prgCmds, pCmdText);
535 if(!pguidCmdGroup) {
536 ULONG i;
538 for(i=0; i<cCmds; i++) {
539 if(prgCmds[i].cmdID<OLECMDID_OPEN || prgCmds[i].cmdID>OLECMDID_GETPRINTTEMPLATE) {
540 WARN("Unsupported cmdID = %ld\n", prgCmds[i].cmdID);
541 prgCmds[i].cmdf = 0;
542 hres = OLECMDERR_E_NOTSUPPORTED;
543 }else {
544 prgCmds[i].cmdf = status_table[prgCmds[i].cmdID];
545 TRACE("cmdID = %ld returning %lx\n", prgCmds[i].cmdID, prgCmds[i].cmdID);
546 hres = S_OK;
550 if(pguidCmdGroup)
551 FIXME("Set pCmdText\n");
552 }else {
553 FIXME("Unsupported pguidCmdGroup %s\n", debugstr_guid(pguidCmdGroup));
554 hres = OLECMDERR_E_UNKNOWNGROUP;
557 return hres;
560 static HRESULT WINAPI OleCommandTarget_Exec(IOleCommandTarget *iface, const GUID *pguidCmdGroup,
561 DWORD nCmdID, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
563 HTMLDocument *This = CMDTARGET_THIS(iface);
564 FIXME("(%p)->(%s %ld %ld %p %p)\n", This, debugstr_guid(pguidCmdGroup), nCmdID, nCmdexecopt,
565 pvaIn, pvaOut);
566 return E_NOTIMPL;
569 static const IOleCommandTargetVtbl OleCommandTargetVtbl = {
570 OleCommandTarget_QueryInterface,
571 OleCommandTarget_AddRef,
572 OleCommandTarget_Release,
573 OleCommandTarget_QueryStatus,
574 OleCommandTarget_Exec
577 void HTMLDocument_OleObj_Init(HTMLDocument *This)
579 This->lpOleObjectVtbl = &OleObjectVtbl;
580 This->lpOleDocumentVtbl = &OleDocumentVtbl;
581 This->lpOleCommandTargetVtbl = &OleCommandTargetVtbl;
583 This->client = NULL;
584 This->hostui = NULL;
586 This->has_key_path = FALSE;