2 * Copyright 2005-2007 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
36 #include "wine/debug.h"
37 #include "wine/unicode.h"
39 #include "mshtml_private.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
44 #define NSCMD_COPY "cmd_copy"
46 void do_ns_command(NSContainer *This, const char *cmd, nsICommandParams *nsparam)
48 nsICommandManager *cmdmgr;
51 TRACE("(%p)\n", This);
53 nsres = get_nsinterface((nsISupports*)This->webbrowser, &IID_nsICommandManager, (void**)&cmdmgr);
54 if(NS_FAILED(nsres)) {
55 ERR("Could not get nsICommandManager: %08x\n", nsres);
59 nsres = nsICommandManager_DoCommand(cmdmgr, cmd, nsparam, NULL);
61 ERR("DoCommand(%s) failed: %08x\n", debugstr_a(cmd), nsres);
63 nsICommandManager_Release(cmdmgr);
66 /**********************************************************
67 * IOleCommandTarget implementation
70 #define CMDTARGET_THIS(iface) DEFINE_THIS(HTMLDocument, OleCommandTarget, iface)
72 static HRESULT exec_open(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
74 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
78 static HRESULT exec_new(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
80 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
84 static HRESULT exec_save(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
86 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
90 static HRESULT exec_save_as(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
92 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
96 static HRESULT exec_save_copy_as(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
98 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
102 static nsresult set_head_text(nsIPrintSettings *settings, LPCWSTR template, BOOL head, int pos)
107 return nsIPrintSettings_SetHeaderStrLeft(settings, template);
109 return nsIPrintSettings_SetHeaderStrRight(settings, template);
111 return nsIPrintSettings_SetHeaderStrCenter(settings, template);
116 return nsIPrintSettings_SetFooterStrLeft(settings, template);
118 return nsIPrintSettings_SetFooterStrRight(settings, template);
120 return nsIPrintSettings_SetFooterStrCenter(settings, template);
127 static void set_print_template(nsIPrintSettings *settings, LPCWSTR template, BOOL head)
129 PRUnichar nstemplate[200]; /* FIXME: Use dynamic allocation */
130 PRUnichar *p = nstemplate;
131 LPCWSTR ptr=template;
146 case 'b': /* change align */
149 set_head_text(settings, nstemplate, head, pos);
153 case 'd': { /* short date */
155 GetLocalTime(&systime);
156 GetDateFormatW(LOCALE_SYSTEM_DEFAULT, 0, &systime, NULL, p,
157 sizeof(nstemplate)-(p-nstemplate)*sizeof(WCHAR));
162 case 'p': /* page number */
167 case 'P': /* page count */
168 *p++ = '?'; /* FIXME */
177 /* FIXME: set window title */
187 set_head_text(settings, nstemplate, head, pos);
190 set_head_text(settings, p, head, pos);
193 static void set_default_templates(nsIPrintSettings *settings)
197 static const PRUnichar empty[] = {0};
199 nsIPrintSettings_SetHeaderStrLeft(settings, empty);
200 nsIPrintSettings_SetHeaderStrRight(settings, empty);
201 nsIPrintSettings_SetHeaderStrCenter(settings, empty);
202 nsIPrintSettings_SetFooterStrLeft(settings, empty);
203 nsIPrintSettings_SetFooterStrRight(settings, empty);
204 nsIPrintSettings_SetFooterStrCenter(settings, empty);
206 if(LoadStringW(get_shdoclc(), IDS_PRINT_HEADER_TEMPLATE, buf,
207 sizeof(buf)/sizeof(WCHAR)))
208 set_print_template(settings, buf, TRUE);
211 if(LoadStringW(get_shdoclc(), IDS_PRINT_FOOTER_TEMPLATE, buf,
212 sizeof(buf)/sizeof(WCHAR)))
213 set_print_template(settings, buf, FALSE);
217 static HRESULT exec_print(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
219 nsIWebBrowserPrint *nsprint;
220 nsIPrintSettings *settings;
223 TRACE("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
226 FIXME("unsupported pvaOut\n");
228 if(!This->nscontainer)
231 nsres = get_nsinterface((nsISupports*)This->nscontainer->webbrowser, &IID_nsIWebBrowserPrint,
233 if(NS_FAILED(nsres)) {
234 ERR("Could not get nsIWebBrowserPrint: %08x\n", nsres);
238 nsres = nsIWebBrowserPrint_GetGlobalPrintSettings(nsprint, &settings);
240 ERR("GetCurrentPrintSettings failed: %08x\n", nsres);
242 set_default_templates(settings);
245 switch(V_VT(pvaIn)) {
246 case VT_BYREF|VT_ARRAY: {
250 if(V_ARRAY(pvaIn)->cDims != 1)
251 WARN("cDims = %d\n", V_ARRAY(pvaIn)->cDims);
253 SafeArrayAccessData(V_ARRAY(pvaIn), (void**)&opts);
254 opts_cnt = V_ARRAY(pvaIn)->rgsabound[0].cElements;
259 TRACE("setting footer %s\n", debugstr_w(V_BSTR(opts)));
260 set_print_template(settings, V_BSTR(opts), TRUE);
265 WARN("V_VT(opts) = %d\n", V_VT(opts));
270 switch(V_VT(opts+1)) {
272 TRACE("setting footer %s\n", debugstr_w(V_BSTR(opts+1)));
273 set_print_template(settings, V_BSTR(opts+1), FALSE);
278 WARN("V_VT(opts) = %d\n", V_VT(opts+1));
283 FIXME("Unsupported opts_cnt %d\n", opts_cnt);
285 SafeArrayUnaccessData(V_ARRAY(pvaIn));
289 FIXME("unsupported vt %x\n", V_VT(pvaIn));
293 nsres = nsIWebBrowserPrint_Print(nsprint, settings, NULL);
295 ERR("Print failed: %08x\n", nsres);
297 nsIWebBrowserPrint_Release(nsprint);
302 static HRESULT exec_print_preview(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
304 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
308 static HRESULT exec_page_setup(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
310 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
314 static HRESULT exec_spell(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
316 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
320 static HRESULT exec_properties(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
322 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
326 static HRESULT exec_cut(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
328 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
332 static HRESULT exec_copy(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
334 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
338 static HRESULT exec_paste(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
340 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
344 static HRESULT exec_paste_special(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
346 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
350 static HRESULT exec_undo(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
352 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
356 static HRESULT exec_rendo(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
358 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
362 static HRESULT exec_select_all(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
364 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
368 static HRESULT exec_clear_selection(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
370 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
374 static HRESULT exec_zoom(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
376 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
380 static HRESULT exec_get_zoom_range(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
382 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
386 static HRESULT exec_refresh(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
388 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
392 static HRESULT exec_stop(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
394 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
398 static HRESULT exec_stop_download(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
400 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
404 static HRESULT exec_find(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
406 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
410 static HRESULT exec_delete(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
412 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
416 static HRESULT exec_enable_interaction(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
418 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
422 static HRESULT exec_on_unload(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
424 TRACE("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
426 /* Tests show that we have nothing more to do here */
429 V_VT(pvaOut) = VT_BOOL;
430 V_BOOL(pvaOut) = VARIANT_TRUE;
436 static HRESULT exec_show_page_setup(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
438 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
442 static HRESULT exec_show_print(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
444 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
448 static HRESULT exec_close(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
450 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
454 static HRESULT exec_set_print_template(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
456 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
460 static HRESULT exec_get_print_template(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
462 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
466 static HRESULT query_mshtml_copy(HTMLDocument *This, OLECMD *cmd)
468 FIXME("(%p)\n", This);
469 cmd->cmdf = OLECMDF_SUPPORTED|OLECMDF_ENABLED;
473 static HRESULT exec_mshtml_copy(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
475 TRACE("(%p)->(%08x %p %p)\n", This, cmdexecopt, in, out);
477 if(This->usermode == EDITMODE)
478 return editor_exec_copy(This, cmdexecopt, in, out);
480 do_ns_command(This->nscontainer, NSCMD_COPY, NULL);
484 static HRESULT query_mshtml_cut(HTMLDocument *This, OLECMD *cmd)
486 FIXME("(%p)\n", This);
487 cmd->cmdf = OLECMDF_SUPPORTED|OLECMDF_ENABLED;
491 static HRESULT exec_mshtml_cut(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
493 TRACE("(%p)->(%08x %p %p)\n", This, cmdexecopt, in, out);
495 if(This->usermode == EDITMODE)
496 return editor_exec_cut(This, cmdexecopt, in, out);
498 FIXME("Unimplemented in browse mode\n");
502 static HRESULT query_mshtml_paste(HTMLDocument *This, OLECMD *cmd)
504 FIXME("(%p)\n", This);
505 cmd->cmdf = OLECMDF_SUPPORTED|OLECMDF_ENABLED;
509 static HRESULT exec_mshtml_paste(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
511 TRACE("(%p)->(%08x %p %p)\n", This, cmdexecopt, in, out);
513 if(This->usermode == EDITMODE)
514 return editor_exec_paste(This, cmdexecopt, in, out);
516 FIXME("Unimplemented in browse mode\n");
520 static HRESULT exec_browsemode(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
522 WARN("(%p)->(%08x %p %p)\n", This, cmdexecopt, in, out);
525 FIXME("unsupported args\n");
527 This->usermode = BROWSEMODE;
532 static HRESULT exec_editmode(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
537 TRACE("(%p)->(%08x %p %p)\n", This, cmdexecopt, in, out);
540 FIXME("unsupported args\n");
542 if(This->usermode == EDITMODE)
545 This->usermode = EDITMODE;
548 CLSID clsid = IID_NULL;
549 hres = IMoniker_GetClassID(This->mon, &clsid);
550 if(SUCCEEDED(hres)) {
551 /* We should use IMoniker::Save here */
552 FIXME("Use CLSID %s\n", debugstr_guid(&clsid));
557 IOleInPlaceFrame_SetStatusText(This->frame, NULL);
559 This->readystate = READYSTATE_UNINITIALIZED;
562 IOleCommandTarget *cmdtrg;
564 hres = IOleClientSite_QueryInterface(This->client, &IID_IOleCommandTarget,
566 if(SUCCEEDED(hres)) {
571 IOleCommandTarget_Exec(cmdtrg, &CGID_ShellDocView, 37, 0, &var, NULL);
573 IOleCommandTarget_Release(cmdtrg);
578 DOCHOSTUIINFO hostinfo;
580 memset(&hostinfo, 0, sizeof(DOCHOSTUIINFO));
581 hostinfo.cbSize = sizeof(DOCHOSTUIINFO);
582 hres = IDocHostUIHandler_GetHostInfo(This->hostui, &hostinfo);
584 /* FIXME: use hostinfo */
585 TRACE("hostinfo = {%u %08x %08x %s %s}\n",
586 hostinfo.cbSize, hostinfo.dwFlags, hostinfo.dwDoubleClick,
587 debugstr_w(hostinfo.pchHostCss), debugstr_w(hostinfo.pchHostNS));
590 if(This->nscontainer)
591 set_ns_editmode(This->nscontainer);
593 update_doc(This, UPDATE_UI);
596 /* FIXME: We should find nicer way to do this */
597 remove_doc_tasks(This);
600 IMoniker_AddRef(mon);
602 static const WCHAR about_blankW[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
604 hres = CreateURLMoniker(NULL, about_blankW, &mon);
606 FIXME("CreateURLMoniker failed: %08x\n", hres);
611 hres = IPersistMoniker_Load(PERSISTMON(This), TRUE, mon, NULL, 0);
612 IMoniker_Release(mon);
616 if(This->ui_active) {
620 call_set_active_object(This->ip_window, NULL);
622 IDocHostUIHandler_HideUI(This->hostui);
625 IDocHostUIHandler_ShowUI(This->hostui, DOCHOSTUITYPE_AUTHOR, ACTOBJ(This), CMDTARGET(This),
626 This->frame, This->ip_window);
629 call_set_active_object(This->ip_window, ACTOBJ(This));
631 memset(&rcBorderWidths, 0, sizeof(rcBorderWidths));
633 IOleInPlaceFrame_SetBorderSpace(This->frame, &rcBorderWidths);
639 static HRESULT exec_htmleditmode(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
641 FIXME("(%p)->(%08x %p %p)\n", This, cmdexecopt, in, out);
645 static HRESULT exec_baselinefont3(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
647 FIXME("(%p)->(%08x %p %p)\n", This, cmdexecopt, in, out);
651 static HRESULT exec_respectvisibility_indesign(HTMLDocument *This, DWORD cmdexecopt,
652 VARIANT *in, VARIANT *out)
654 FIXME("(%p)->(%08x %p %p)\n", This, cmdexecopt, in, out);
658 static HRESULT query_enabled_stub(HTMLDocument *This, OLECMD *cmd)
662 FIXME("CGID_MSHTML: IDM_PRINT\n");
663 cmd->cmdf = OLECMDF_SUPPORTED|OLECMDF_ENABLED;
665 case IDM_BLOCKDIRLTR:
666 FIXME("CGID_MSHTML: IDM_BLOCKDIRLTR\n");
667 cmd->cmdf = OLECMDF_SUPPORTED|OLECMDF_ENABLED;
669 case IDM_BLOCKDIRRTL:
670 FIXME("CGID_MSHTML: IDM_BLOCKDIRRTL\n");
671 cmd->cmdf = OLECMDF_SUPPORTED|OLECMDF_ENABLED;
678 static const struct {
680 HRESULT (*func)(HTMLDocument*,DWORD,VARIANT*,VARIANT*);
681 } exec_table[OLECMDID_GETPRINTTEMPLATE+1] = {
683 { OLECMDF_SUPPORTED, exec_open }, /* OLECMDID_OPEN */
684 { OLECMDF_SUPPORTED, exec_new }, /* OLECMDID_NEW */
685 { OLECMDF_SUPPORTED, exec_save }, /* OLECMDID_SAVE */
686 { OLECMDF_SUPPORTED|OLECMDF_ENABLED, exec_save_as }, /* OLECMDID_SAVEAS */
687 { OLECMDF_SUPPORTED, exec_save_copy_as }, /* OLECMDID_SAVECOPYAS */
688 { OLECMDF_SUPPORTED|OLECMDF_ENABLED, exec_print }, /* OLECMDID_PRINT */
689 { OLECMDF_SUPPORTED|OLECMDF_ENABLED, exec_print_preview }, /* OLECMDID_PRINTPREVIEW */
690 { OLECMDF_SUPPORTED|OLECMDF_ENABLED, exec_page_setup }, /* OLECMDID_PAGESETUP */
691 { OLECMDF_SUPPORTED, exec_spell }, /* OLECMDID_SPELL */
692 { OLECMDF_SUPPORTED|OLECMDF_ENABLED, exec_properties }, /* OLECMDID_PROPERTIES */
693 { OLECMDF_SUPPORTED, exec_cut }, /* OLECMDID_CUT */
694 { OLECMDF_SUPPORTED, exec_copy }, /* OLECMDID_COPY */
695 { OLECMDF_SUPPORTED, exec_paste }, /* OLECMDID_PASTE */
696 { OLECMDF_SUPPORTED, exec_paste_special }, /* OLECMDID_PASTESPECIAL */
697 { OLECMDF_SUPPORTED, exec_undo }, /* OLECMDID_UNDO */
698 { OLECMDF_SUPPORTED, exec_rendo }, /* OLECMDID_REDO */
699 { OLECMDF_SUPPORTED|OLECMDF_ENABLED, exec_select_all }, /* OLECMDID_SELECTALL */
700 { OLECMDF_SUPPORTED, exec_clear_selection }, /* OLECMDID_CLEARSELECTION */
701 { OLECMDF_SUPPORTED, exec_zoom }, /* OLECMDID_ZOOM */
702 { OLECMDF_SUPPORTED, exec_get_zoom_range }, /* OLECMDID_GETZOOMRANGE */
704 { OLECMDF_SUPPORTED|OLECMDF_ENABLED, exec_refresh }, /* OLECMDID_REFRESH */
705 { OLECMDF_SUPPORTED|OLECMDF_ENABLED, exec_stop }, /* OLECMDID_STOP */
706 {0},{0},{0},{0},{0},{0},
707 { OLECMDF_SUPPORTED, exec_stop_download }, /* OLECMDID_STOPDOWNLOAD */
709 { OLECMDF_SUPPORTED|OLECMDF_ENABLED, exec_find }, /* OLECMDID_FIND */
710 { OLECMDF_SUPPORTED, exec_delete }, /* OLECMDID_DELETE */
712 { OLECMDF_SUPPORTED, exec_enable_interaction }, /* OLECMDID_ENABLE_INTERACTION */
713 { OLECMDF_SUPPORTED, exec_on_unload }, /* OLECMDID_ONUNLOAD */
715 { OLECMDF_SUPPORTED, exec_show_page_setup }, /* OLECMDID_SHOWPAGESETUP */
716 { OLECMDF_SUPPORTED, exec_show_print }, /* OLECMDID_SHOWPRINT */
718 { OLECMDF_SUPPORTED, exec_close }, /* OLECMDID_CLOSE */
720 { OLECMDF_SUPPORTED, exec_set_print_template }, /* OLECMDID_SETPRINTTEMPLATE */
721 { OLECMDF_SUPPORTED, exec_get_print_template } /* OLECMDID_GETPRINTTEMPLATE */
724 static const cmdtable_t base_cmds[] = {
725 {IDM_COPY, query_mshtml_copy, exec_mshtml_copy},
726 {IDM_PASTE, query_mshtml_paste, exec_mshtml_paste},
727 {IDM_CUT, query_mshtml_cut, exec_mshtml_cut},
728 {IDM_BROWSEMODE, NULL, exec_browsemode},
729 {IDM_EDITMODE, NULL, exec_editmode},
730 {IDM_PRINT, query_enabled_stub, exec_print},
731 {IDM_HTMLEDITMODE, NULL, exec_htmleditmode},
732 {IDM_BASELINEFONT3, NULL, exec_baselinefont3},
733 {IDM_BLOCKDIRLTR, query_enabled_stub, NULL},
734 {IDM_BLOCKDIRRTL, query_enabled_stub, NULL},
735 {IDM_RESPECTVISIBILITY_INDESIGN, NULL, exec_respectvisibility_indesign},
739 static HRESULT WINAPI OleCommandTarget_QueryInterface(IOleCommandTarget *iface, REFIID riid, void **ppv)
741 HTMLDocument *This = CMDTARGET_THIS(iface);
742 return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppv);
745 static ULONG WINAPI OleCommandTarget_AddRef(IOleCommandTarget *iface)
747 HTMLDocument *This = CMDTARGET_THIS(iface);
748 return IHTMLDocument2_AddRef(HTMLDOC(This));
751 static ULONG WINAPI OleCommandTarget_Release(IOleCommandTarget *iface)
753 HTMLDocument *This = CMDTARGET_THIS(iface);
754 return IHTMLDocument_Release(HTMLDOC(This));
757 static HRESULT query_from_table(HTMLDocument *This, const cmdtable_t *cmdtable, OLECMD *cmd)
759 const cmdtable_t *iter = cmdtable;
763 while(iter->id && iter->id != cmd->cmdID)
766 if(!iter->id || !iter->query)
767 return OLECMDERR_E_NOTSUPPORTED;
769 return iter->query(This, cmd);
772 static HRESULT WINAPI OleCommandTarget_QueryStatus(IOleCommandTarget *iface, const GUID *pguidCmdGroup,
773 ULONG cCmds, OLECMD prgCmds[], OLECMDTEXT *pCmdText)
775 HTMLDocument *This = CMDTARGET_THIS(iface);
776 HRESULT hres = S_OK, hr;
778 TRACE("(%p)->(%s %d %p %p)\n", This, debugstr_guid(pguidCmdGroup), cCmds, prgCmds, pCmdText);
783 for(i=0; i<cCmds; i++) {
784 if(prgCmds[i].cmdID<OLECMDID_OPEN || prgCmds[i].cmdID>OLECMDID_GETPRINTTEMPLATE) {
785 WARN("Unsupported cmdID = %d\n", prgCmds[i].cmdID);
787 hres = OLECMDERR_E_NOTSUPPORTED;
789 if(prgCmds[i].cmdID == OLECMDID_OPEN || prgCmds[i].cmdID == OLECMDID_NEW) {
790 IOleCommandTarget *cmdtrg = NULL;
793 prgCmds[i].cmdf = OLECMDF_SUPPORTED;
795 hr = IOleClientSite_QueryInterface(This->client, &IID_IOleCommandTarget,
798 olecmd.cmdID = prgCmds[i].cmdID;
801 hr = IOleCommandTarget_QueryStatus(cmdtrg, NULL, 1, &olecmd, NULL);
802 if(SUCCEEDED(hr) && olecmd.cmdf)
803 prgCmds[i].cmdf = olecmd.cmdf;
806 ERR("This->client == NULL, native would crash\n");
809 prgCmds[i].cmdf = exec_table[prgCmds[i].cmdID].cmdf;
810 TRACE("cmdID = %d returning %x\n", prgCmds[i].cmdID, prgCmds[i].cmdf);
817 FIXME("Set pCmdText\n");
818 }else if(IsEqualGUID(&CGID_MSHTML, pguidCmdGroup)) {
821 for(i=0; i<cCmds; i++) {
822 HRESULT hres = query_from_table(This, base_cmds, prgCmds+i);
823 if(hres == OLECMDERR_E_NOTSUPPORTED)
824 hres = query_from_table(This, editmode_cmds, prgCmds+i);
825 if(hres == OLECMDERR_E_NOTSUPPORTED)
826 FIXME("CGID_MSHTML: unsupported cmdID %d\n", prgCmds[i].cmdID);
829 hres = prgCmds[i-1].cmdf ? S_OK : OLECMDERR_E_NOTSUPPORTED;
832 FIXME("Set pCmdText\n");
834 FIXME("Unsupported pguidCmdGroup %s\n", debugstr_guid(pguidCmdGroup));
835 hres = OLECMDERR_E_UNKNOWNGROUP;
841 static HRESULT exec_from_table(HTMLDocument *This, const cmdtable_t *cmdtable, DWORD cmdid,
842 DWORD cmdexecopt, VARIANT *in, VARIANT *out)
844 const cmdtable_t *iter = cmdtable;
846 while(iter->id && iter->id != cmdid)
849 if(!iter->id || !iter->exec)
850 return OLECMDERR_E_NOTSUPPORTED;
852 return iter->exec(This, cmdexecopt, in, out);
855 static HRESULT WINAPI OleCommandTarget_Exec(IOleCommandTarget *iface, const GUID *pguidCmdGroup,
856 DWORD nCmdID, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
858 HTMLDocument *This = CMDTARGET_THIS(iface);
861 if(nCmdID<OLECMDID_OPEN || nCmdID>OLECMDID_GETPRINTTEMPLATE || !exec_table[nCmdID].func) {
862 WARN("Unsupported cmdID = %d\n", nCmdID);
863 return OLECMDERR_E_NOTSUPPORTED;
866 return exec_table[nCmdID].func(This, nCmdexecopt, pvaIn, pvaOut);
867 }else if(IsEqualGUID(&CGID_Explorer, pguidCmdGroup)) {
868 FIXME("unsupported nCmdID %d of CGID_Explorer group\n", nCmdID);
869 TRACE("%p %p\n", pvaIn, pvaOut);
870 return OLECMDERR_E_NOTSUPPORTED;
871 }else if(IsEqualGUID(&CGID_ShellDocView, pguidCmdGroup)) {
872 FIXME("unsupported nCmdID %d of CGID_ShellDocView group\n", nCmdID);
873 return OLECMDERR_E_NOTSUPPORTED;
874 }else if(IsEqualGUID(&CGID_MSHTML, pguidCmdGroup)) {
875 HRESULT hres = exec_from_table(This, base_cmds, nCmdID, nCmdexecopt, pvaIn, pvaOut);
876 if(hres == OLECMDERR_E_NOTSUPPORTED)
877 hres = exec_from_table(This, editmode_cmds, nCmdID,
878 nCmdexecopt, pvaIn, pvaOut);
879 if(hres == OLECMDERR_E_NOTSUPPORTED)
880 FIXME("unsupported nCmdID %d of CGID_MSHTML group\n", nCmdID);
885 FIXME("Unsupported pguidCmdGroup %s\n", debugstr_guid(pguidCmdGroup));
886 return OLECMDERR_E_UNKNOWNGROUP;
889 #undef CMDTARGET_THIS
891 static const IOleCommandTargetVtbl OleCommandTargetVtbl = {
892 OleCommandTarget_QueryInterface,
893 OleCommandTarget_AddRef,
894 OleCommandTarget_Release,
895 OleCommandTarget_QueryStatus,
896 OleCommandTarget_Exec
899 void show_context_menu(HTMLDocument *This, DWORD dwID, POINT *ppt, IDispatch *elem)
901 HMENU menu_res, menu;
905 hres = IDocHostUIHandler_ShowContextMenu(This->hostui, dwID, ppt,
906 (IUnknown*)CMDTARGET(This), elem);
910 menu_res = LoadMenuW(get_shdoclc(), MAKEINTRESOURCEW(IDR_BROWSE_CONTEXT_MENU));
911 menu = GetSubMenu(menu_res, dwID);
913 cmdid = TrackPopupMenu(menu, TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_RETURNCMD,
914 ppt->x, ppt->y, 0, This->hwnd, NULL);
915 DestroyMenu(menu_res);
918 IOleCommandTarget_Exec(CMDTARGET(This), &CGID_MSHTML, cmdid, 0, NULL, NULL);
921 void HTMLDocument_OleCmd_Init(HTMLDocument *This)
923 This->lpOleCommandTargetVtbl = &OleCommandTargetVtbl;