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
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
;
71 TRACE("(%p)->(%p)\n", This
, pClientSite
);
74 IOleClientSite_Release(This
->client
);
77 IDocHostUIHandler_Release(This
->hostui
);
84 hres
= IOleObject_QueryInterface(pClientSite
, &IID_IDocHostUIHandler
, (void**)&pDocHostUIHandler
);
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
);
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
) {
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). */
129 IOleWindow
*pOleWindow
= NULL
;
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
;
146 static HRESULT WINAPI
OleObject_GetClientSite(IOleObject
*iface
, IOleClientSite
**ppClientSite
)
148 HTMLDocument
*This
= OLEOBJ_THIS(iface
);
150 TRACE("(%p)->(%p)\n", This
, ppClientSite
);
156 IOleClientSite_AddRef(This
->client
);
157 *ppClientSite
= This
->client
;
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
));
169 static HRESULT WINAPI
OleObject_Close(IOleObject
*iface
, DWORD dwSaveOption
)
171 HTMLDocument
*This
= OLEOBJ_THIS(iface
);
174 FIXME("(%p)->(%08lx)\n", This
, dwSaveOption
);
177 IOleContainer
*container
;
178 hres
= IOleClientSite_GetContainer(This
->client
, &container
);
179 if(SUCCEEDED(hres
)) {
180 IOleContainer_LockContainer(container
, FALSE
);
181 IOleContainer_Release(container
);
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
);
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
);
202 static HRESULT WINAPI
OleObject_InitFromData(IOleObject
*iface
, IDataObject
*pDataObject
, BOOL fCreation
,
205 HTMLDocument
*This
= OLEOBJ_THIS(iface
);
206 FIXME("(%p)->(%p %x %ld)\n", This
, pDataObject
, fCreation
, dwReserved
);
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
);
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
;
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
);
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
);
246 hres
= IOleDocumentView_UIActivate(DOCVIEW(This
), TRUE
);
247 if(SUCCEEDED(hres
)) {
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
);
260 static HRESULT WINAPI
OleObject_EnumVerbs(IOleObject
*iface
, IEnumOLEVERB
**ppEnumOleVerb
)
262 HTMLDocument
*This
= OLEOBJ_THIS(iface
);
263 FIXME("(%p)->(%p)\n", This
, ppEnumOleVerb
);
267 static HRESULT WINAPI
OleObject_Update(IOleObject
*iface
)
269 HTMLDocument
*This
= OLEOBJ_THIS(iface
);
270 FIXME("(%p)\n", This
);
274 static HRESULT WINAPI
OleObject_IsUpToDate(IOleObject
*iface
)
276 HTMLDocument
*This
= OLEOBJ_THIS(iface
);
277 FIXME("(%p)\n", This
);
281 static HRESULT WINAPI
OleObject_GetUserClassID(IOleObject
*iface
, CLSID
*pClsid
)
283 HTMLDocument
*This
= OLEOBJ_THIS(iface
);
285 TRACE("(%p)->(%p)\n", This
, pClsid
);
290 memcpy(pClsid
, &CLSID_HTMLDocument
, sizeof(GUID
));
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
);
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
);
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
);
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
);
322 static HRESULT WINAPI
OleObject_Unadvise(IOleObject
*iface
, DWORD dwConnection
)
324 HTMLDocument
*This
= OLEOBJ_THIS(iface
);
325 FIXME("(%p)->(%ld)\n", This
, dwConnection
);
329 static HRESULT WINAPI
OleObject_EnumAdvise(IOleObject
*iface
, IEnumSTATDATA
**ppenumAdvise
)
331 HTMLDocument
*This
= OLEOBJ_THIS(iface
);
332 FIXME("(%p)->(%p)\n", This
, ppenumAdvise
);
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
);
343 static HRESULT WINAPI
OleObject_SetColorScheme(IOleObject
*iface
, LOGPALETTE
*pLogpal
)
345 HTMLDocument
*This
= OLEOBJ_THIS(iface
);
346 FIXME("(%p)->(%p)\n", This
, pLogpal
);
352 static const IOleObjectVtbl OleObjectVtbl
= {
353 OleObject_QueryInterface
,
356 OleObject_SetClientSite
,
357 OleObject_GetClientSite
,
358 OleObject_SetHostNames
,
360 OleObject_SetMoniker
,
361 OleObject_GetMoniker
,
362 OleObject_InitFromData
,
363 OleObject_GetClipboardData
,
367 OleObject_IsUpToDate
,
368 OleObject_GetUserClassID
,
369 OleObject_GetUserType
,
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
);
409 TRACE("(%p)->(%p %p %ld %p)\n", This
, pIPSite
, pstm
, dwReserved
, ppView
);
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.
422 hres
= IOleDocumentView_SetInPlaceSite(DOCVIEW(This
), pIPSite
);
428 FIXME("pstm is not supported\n");
430 IOleDocumentView_AddRef(DOCVIEW(This
));
431 *ppView
= DOCVIEW(This
);
435 static HRESULT WINAPI
OleDocument_GetDocMiscStatus(IOleDocument
*iface
, DWORD
*pdwStatus
)
437 HTMLDocument
*This
= OLEDOC_THIS(iface
);
438 FIXME("(%p)->(%p)\n", This
, pdwStatus
);
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
);
452 static const IOleDocumentVtbl OleDocumentVtbl
= {
453 OleDocument_QueryInterface
,
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 */
493 OLECMDF_SUPPORTED
, /* OLECMDID_STOPDOWNLOAD */
495 OLECMDF_SUPPORTED
, /* OLECMDID_DELETE */
497 OLECMDF_SUPPORTED
, /* OLECMDID_ENABLE_INTERACTION */
498 OLECMDF_SUPPORTED
, /* OLECMDID_ONUNLOAD */
500 OLECMDF_SUPPORTED
, /* OLECMDID_SHOWPAGESETUP */
501 OLECMDF_SUPPORTED
, /* OLECMDID_SHOWPRINT */
503 OLECMDF_SUPPORTED
, /* OLECMDID_CLOSE */
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
);
533 TRACE("(%p)->(%s %ld %p %p)\n", This
, debugstr_guid(pguidCmdGroup
), cCmds
, prgCmds
, pCmdText
);
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
);
542 hres
= OLECMDERR_E_NOTSUPPORTED
;
544 prgCmds
[i
].cmdf
= status_table
[prgCmds
[i
].cmdID
];
545 TRACE("cmdID = %ld returning %lx\n", prgCmds
[i
].cmdID
, prgCmds
[i
].cmdID
);
551 FIXME("Set pCmdText\n");
553 FIXME("Unsupported pguidCmdGroup %s\n", debugstr_guid(pguidCmdGroup
));
554 hres
= OLECMDERR_E_UNKNOWNGROUP
;
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
,
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
;
586 This
->has_key_path
= FALSE
;