2 * Copyright 2005-2006 Jacek Caban for CodeWeavers
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
35 #include "wine/debug.h"
37 #include "mshtml_private.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
41 /**********************************************************
42 * IOleCommandTarget implementation
45 #define CMDTARGET_THIS(iface) DEFINE_THIS(HTMLDocument, OleCommandTarget, iface)
47 static HRESULT exec_open(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
49 FIXME("(%p)->(%ld %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
53 static HRESULT exec_new(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
55 FIXME("(%p)->(%ld %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
59 static HRESULT exec_save(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
61 FIXME("(%p)->(%ld %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
65 static HRESULT exec_save_as(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
67 FIXME("(%p)->(%ld %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
71 static HRESULT exec_save_copy_as(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
73 FIXME("(%p)->(%ld %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
77 static HRESULT exec_print(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
79 FIXME("(%p)->(%ld %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
83 static HRESULT exec_print_preview(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
85 FIXME("(%p)->(%ld %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
89 static HRESULT exec_page_setup(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
91 FIXME("(%p)->(%ld %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
95 static HRESULT exec_spell(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
97 FIXME("(%p)->(%ld %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
101 static HRESULT exec_properties(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
103 FIXME("(%p)->(%ld %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
107 static HRESULT exec_cut(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
109 FIXME("(%p)->(%ld %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
113 static HRESULT exec_copy(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
115 FIXME("(%p)->(%ld %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
119 static HRESULT exec_paste(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
121 FIXME("(%p)->(%ld %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
125 static HRESULT exec_paste_special(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
127 FIXME("(%p)->(%ld %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
131 static HRESULT exec_undo(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
133 FIXME("(%p)->(%ld %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
137 static HRESULT exec_rendo(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
139 FIXME("(%p)->(%ld %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
143 static HRESULT exec_select_all(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
145 FIXME("(%p)->(%ld %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
149 static HRESULT exec_clear_selection(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
151 FIXME("(%p)->(%ld %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
155 static HRESULT exec_zoom(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
157 FIXME("(%p)->(%ld %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
161 static HRESULT exec_get_zoom_range(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
163 FIXME("(%p)->(%ld %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
167 static HRESULT exec_refresh(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
169 FIXME("(%p)->(%ld %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
173 static HRESULT exec_stop(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
175 FIXME("(%p)->(%ld %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
179 static HRESULT exec_stop_download(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
181 FIXME("(%p)->(%ld %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
185 static HRESULT exec_delete(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
187 FIXME("(%p)->(%ld %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
191 static HRESULT exec_enable_interaction(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
193 FIXME("(%p)->(%ld %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
197 static HRESULT exec_on_unload(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
199 TRACE("(%p)->(%ld %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
201 /* Tests show that we have nothing more to do here */
204 V_VT(pvaOut) = VT_BOOL;
205 V_BOOL(pvaOut) = VARIANT_TRUE;
211 static HRESULT exec_show_page_setup(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
213 FIXME("(%p)->(%ld %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
217 static HRESULT exec_show_print(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
219 FIXME("(%p)->(%ld %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
223 static HRESULT exec_close(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
225 FIXME("(%p)->(%ld %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
229 static HRESULT exec_set_print_template(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
231 FIXME("(%p)->(%ld %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
235 static HRESULT exec_get_print_template(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
237 FIXME("(%p)->(%ld %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
241 static HRESULT exec_browsemode(HTMLDocument *This)
243 WARN("(%p)\n", This);
245 This->usermode = BROWSEMODE;
250 static void setup_ns_editing(NSContainer *This)
252 nsIInterfaceRequestor *iface_req;
253 nsIEditingSession *editing_session = NULL;
254 nsIURIContentListener *listener = NULL;
255 nsIDOMWindow *dom_window = NULL;
258 nsres = nsIWebBrowser_QueryInterface(This->webbrowser,
259 &IID_nsIInterfaceRequestor, (void**)&iface_req);
260 if(NS_FAILED(nsres)) {
261 ERR("Could not get nsIInterfaceRequestor: %08lx\n", nsres);
265 nsres = nsIInterfaceRequestor_GetInterface(iface_req, &IID_nsIEditingSession,
266 (void**)&editing_session);
267 nsIInterfaceRequestor_Release(iface_req);
268 if(NS_FAILED(nsres)) {
269 ERR("Could not get nsIEditingSession: %08lx\n", nsres);
273 nsres = nsIWebBrowser_GetContentDOMWindow(This->webbrowser, &dom_window);
274 nsIDOMWindow_Release(dom_window);
275 if(NS_FAILED(nsres)) {
276 ERR("Could not get content DOM window: %08lx\n", nsres);
277 nsIEditingSession_Release(editing_session);
281 nsres = nsIEditingSession_MakeWindowEditable(editing_session, dom_window, NULL, FALSE);
282 nsIEditingSession_Release(editing_session);
283 if(NS_FAILED(nsres)) {
284 ERR("MakeWindowEditable failed: %08lx\n", nsres);
288 /* MakeWindowEditable changes WebBrowser's parent URI content listener.
289 * It seams to be a bug in Gecko. To workaround it we set our content
290 * listener again and Gecko's one as its parent.
292 nsIWebBrowser_GetParentURIContentListener(This->webbrowser, &listener);
293 nsIURIContentListener_SetParentContentListener(NSURICL(This), listener);
294 nsIURIContentListener_Release(listener);
295 nsIWebBrowser_SetParentURIContentListener(This->webbrowser, NSURICL(This));
298 static HRESULT exec_editmode(HTMLDocument *This)
302 TRACE("(%p)\n", This);
304 This->usermode = EDITMODE;
307 IOleInPlaceFrame_SetStatusText(This->frame, NULL);
310 IOleCommandTarget *cmdtrg = NULL;
312 hres = IOleClientSite_QueryInterface(This->client, &IID_IOleCommandTarget,
314 if(SUCCEEDED(hres)) {
319 IOleCommandTarget_Exec(cmdtrg, &CGID_ShellDocView, 37, 0, &var, NULL);
324 DOCHOSTUIINFO hostinfo;
326 memset(&hostinfo, 0, sizeof(DOCHOSTUIINFO));
327 hostinfo.cbSize = sizeof(DOCHOSTUIINFO);
328 hres = IDocHostUIHandler_GetHostInfo(This->hostui, &hostinfo);
330 /* FIXME: use hostinfo */
331 TRACE("hostinfo = {%lu %08lx %08lx %s %s}\n",
332 hostinfo.cbSize, hostinfo.dwFlags, hostinfo.dwDoubleClick,
333 debugstr_w(hostinfo.pchHostCss), debugstr_w(hostinfo.pchHostNS));
337 VARIANT silent, offline;
339 hres = get_client_disp_property(This->client, DISPID_AMBIENT_SILENT, &silent);
340 if(SUCCEEDED(hres)) {
341 if(V_VT(&silent) != VT_BOOL)
342 WARN("V_VT(silent) = %d\n", V_VT(&silent));
343 else if(V_BOOL(&silent))
344 FIXME("silent == true\n");
347 hres = get_client_disp_property(This->client,
348 DISPID_AMBIENT_OFFLINEIFNOTCONNECTED, &offline);
349 if(SUCCEEDED(hres)) {
350 if(V_VT(&silent) != VT_BOOL)
351 WARN("V_VT(offline) = %d\n", V_VT(&silent));
352 else if(V_BOOL(&silent))
353 FIXME("offline == true\n");
357 if(This->nscontainer)
358 setup_ns_editing(This->nscontainer);
363 static HRESULT exec_baselinefont3(HTMLDocument *This)
365 FIXME("(%p)\n", This);
369 static const struct {
371 HRESULT (*func)(HTMLDocument*,DWORD,VARIANT*,VARIANT*);
372 } exec_table[OLECMDID_GETPRINTTEMPLATE+1] = {
374 { OLECMDF_SUPPORTED, exec_open }, /* OLECMDID_OPEN */
375 { OLECMDF_SUPPORTED, exec_new }, /* OLECMDID_NEW */
376 { OLECMDF_SUPPORTED, exec_save }, /* OLECMDID_SAVE */
377 { OLECMDF_SUPPORTED|OLECMDF_ENABLED, exec_save_as }, /* OLECMDID_SAVEAS */
378 { OLECMDF_SUPPORTED, exec_save_copy_as }, /* OLECMDID_SAVECOPYAS */
379 { OLECMDF_SUPPORTED|OLECMDF_ENABLED, exec_print }, /* OLECMDID_PRINT */
380 { OLECMDF_SUPPORTED|OLECMDF_ENABLED, exec_print_preview }, /* OLECMDID_PRINTPREVIEW */
381 { OLECMDF_SUPPORTED|OLECMDF_ENABLED, exec_page_setup }, /* OLECMDID_PAGESETUP */
382 { OLECMDF_SUPPORTED, exec_spell }, /* OLECMDID_SPELL */
383 { OLECMDF_SUPPORTED|OLECMDF_ENABLED, exec_properties }, /* OLECMDID_PROPERTIES */
384 { OLECMDF_SUPPORTED, exec_cut }, /* OLECMDID_CUT */
385 { OLECMDF_SUPPORTED, exec_copy }, /* OLECMDID_COPY */
386 { OLECMDF_SUPPORTED, exec_paste }, /* OLECMDID_PASTE */
387 { OLECMDF_SUPPORTED, exec_paste_special }, /* OLECMDID_PASTESPECIAL */
388 { OLECMDF_SUPPORTED, exec_undo }, /* OLECMDID_UNDO */
389 { OLECMDF_SUPPORTED, exec_rendo }, /* OLECMDID_REDO */
390 { OLECMDF_SUPPORTED|OLECMDF_ENABLED, exec_select_all }, /* OLECMDID_SELECTALL */
391 { OLECMDF_SUPPORTED, exec_clear_selection }, /* OLECMDID_CLEARSELECTION */
392 { OLECMDF_SUPPORTED, exec_zoom }, /* OLECMDID_ZOOM */
393 { OLECMDF_SUPPORTED, exec_get_zoom_range }, /* OLECMDID_GETZOOMRANGE */
395 { OLECMDF_SUPPORTED|OLECMDF_ENABLED, exec_refresh }, /* OLECMDID_REFRESH */
396 { OLECMDF_SUPPORTED|OLECMDF_ENABLED, exec_stop }, /* OLECMDID_STOP */
397 {0},{0},{0},{0},{0},{0},
398 { OLECMDF_SUPPORTED, exec_stop_download }, /* OLECMDID_STOPDOWNLOAD */
400 { OLECMDF_SUPPORTED, exec_delete }, /* OLECMDID_DELETE */
402 { OLECMDF_SUPPORTED, exec_enable_interaction }, /* OLECMDID_ENABLE_INTERACTION */
403 { OLECMDF_SUPPORTED, exec_on_unload }, /* OLECMDID_ONUNLOAD */
405 { OLECMDF_SUPPORTED, exec_show_page_setup }, /* OLECMDID_SHOWPAGESETUP */
406 { OLECMDF_SUPPORTED, exec_show_print }, /* OLECMDID_SHOWPRINT */
408 { OLECMDF_SUPPORTED, exec_close }, /* OLECMDID_CLOSE */
410 { OLECMDF_SUPPORTED, exec_set_print_template }, /* OLECMDID_SETPRINTTEMPLATE */
411 { OLECMDF_SUPPORTED, exec_get_print_template } /* OLECMDID_GETPRINTTEMPLATE */
414 static HRESULT WINAPI OleCommandTarget_QueryInterface(IOleCommandTarget *iface, REFIID riid, void **ppv)
416 HTMLDocument *This = CMDTARGET_THIS(iface);
417 return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppv);
420 static ULONG WINAPI OleCommandTarget_AddRef(IOleCommandTarget *iface)
422 HTMLDocument *This = CMDTARGET_THIS(iface);
423 return IHTMLDocument2_AddRef(HTMLDOC(This));
426 static ULONG WINAPI OleCommandTarget_Release(IOleCommandTarget *iface)
428 HTMLDocument *This = CMDTARGET_THIS(iface);
429 return IHTMLDocument_Release(HTMLDOC(This));
432 static HRESULT WINAPI OleCommandTarget_QueryStatus(IOleCommandTarget *iface, const GUID *pguidCmdGroup,
433 ULONG cCmds, OLECMD prgCmds[], OLECMDTEXT *pCmdText)
435 HTMLDocument *This = CMDTARGET_THIS(iface);
436 HRESULT hres = S_OK, hr;
438 TRACE("(%p)->(%s %ld %p %p)\n", This, debugstr_guid(pguidCmdGroup), cCmds, prgCmds, pCmdText);
443 for(i=0; i<cCmds; i++) {
444 if(prgCmds[i].cmdID<OLECMDID_OPEN || prgCmds[i].cmdID>OLECMDID_GETPRINTTEMPLATE) {
445 WARN("Unsupported cmdID = %ld\n", prgCmds[i].cmdID);
447 hres = OLECMDERR_E_NOTSUPPORTED;
449 if(prgCmds[i].cmdID == OLECMDID_OPEN || prgCmds[i].cmdID == OLECMDID_NEW) {
450 IOleCommandTarget *cmdtrg = NULL;
453 prgCmds[i].cmdf = OLECMDF_SUPPORTED;
455 hr = IOleClientSite_QueryInterface(This->client, &IID_IOleCommandTarget,
458 olecmd.cmdID = prgCmds[i].cmdID;
461 hr = IOleCommandTarget_QueryStatus(cmdtrg, NULL, 1, &olecmd, NULL);
462 if(SUCCEEDED(hr) && olecmd.cmdf)
463 prgCmds[i].cmdf = olecmd.cmdf;
466 ERR("This->client == NULL, native would crash\n");
469 prgCmds[i].cmdf = exec_table[prgCmds[i].cmdID].cmdf;
470 TRACE("cmdID = %ld returning %lx\n", prgCmds[i].cmdID, prgCmds[i].cmdf);
477 FIXME("Set pCmdText\n");
479 FIXME("Unsupported pguidCmdGroup %s\n", debugstr_guid(pguidCmdGroup));
480 hres = OLECMDERR_E_UNKNOWNGROUP;
486 static HRESULT WINAPI OleCommandTarget_Exec(IOleCommandTarget *iface, const GUID *pguidCmdGroup,
487 DWORD nCmdID, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
489 HTMLDocument *This = CMDTARGET_THIS(iface);
492 if(nCmdID<OLECMDID_OPEN || nCmdID>OLECMDID_GETPRINTTEMPLATE || !exec_table[nCmdID].func) {
493 WARN("Unsupported cmdID = %ld\n", nCmdID);
494 return OLECMDERR_E_NOTSUPPORTED;
497 return exec_table[nCmdID].func(This, nCmdexecopt, pvaIn, pvaOut);
498 }else if(IsEqualGUID(&CGID_Explorer, pguidCmdGroup)) {
499 FIXME("unsupported nCmdID %ld of CGID_Explorer group\n", nCmdID);
500 TRACE("%p %p\n", pvaIn, pvaOut);
501 return OLECMDERR_E_NOTSUPPORTED;
502 }else if(IsEqualGUID(&CGID_ShellDocView, pguidCmdGroup)) {
503 FIXME("unsupported nCmdID %ld of CGID_ShellDocView group\n", nCmdID);
504 return OLECMDERR_E_NOTSUPPORTED;
505 }else if(IsEqualGUID(&CGID_MSHTML, pguidCmdGroup)) {
508 return exec_browsemode(This);
511 FIXME("unsupported arguments\n");
512 return exec_editmode(This);
513 case IDM_BASELINEFONT3:
514 return exec_baselinefont3(This);
516 FIXME("unsupported nCmdID %ld of CGID_MSHTML group\n", nCmdID);
517 return OLECMDERR_E_NOTSUPPORTED;
521 FIXME("Unsupported pguidCmdGroup %s\n", debugstr_guid(pguidCmdGroup));
522 return OLECMDERR_E_UNKNOWNGROUP;
525 #undef CMDTARGET_THIS
527 static const IOleCommandTargetVtbl OleCommandTargetVtbl = {
528 OleCommandTarget_QueryInterface,
529 OleCommandTarget_AddRef,
530 OleCommandTarget_Release,
531 OleCommandTarget_QueryStatus,
532 OleCommandTarget_Exec
535 void HTMLDocument_OleCmd_Init(HTMLDocument *This)
537 This->lpOleCommandTargetVtbl = &OleCommandTargetVtbl;