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 static const WCHAR wszAboutBlank[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
539 TRACE("(%p)->(%08x %p %p)\n", This, cmdexecopt, in, out);
542 FIXME("unsupported args\n");
544 if(This->usermode == EDITMODE)
547 This->usermode = EDITMODE;
550 IOleInPlaceFrame_SetStatusText(This->frame, NULL);
553 IOleCommandTarget *cmdtrg;
555 hres = IOleClientSite_QueryInterface(This->client, &IID_IOleCommandTarget,
557 if(SUCCEEDED(hres)) {
562 IOleCommandTarget_Exec(cmdtrg, &CGID_ShellDocView, 37, 0, &var, NULL);
564 IOleCommandTarget_Release(cmdtrg);
569 DOCHOSTUIINFO hostinfo;
571 memset(&hostinfo, 0, sizeof(DOCHOSTUIINFO));
572 hostinfo.cbSize = sizeof(DOCHOSTUIINFO);
573 hres = IDocHostUIHandler_GetHostInfo(This->hostui, &hostinfo);
575 /* FIXME: use hostinfo */
576 TRACE("hostinfo = {%u %08x %08x %s %s}\n",
577 hostinfo.cbSize, hostinfo.dwFlags, hostinfo.dwDoubleClick,
578 debugstr_w(hostinfo.pchHostCss), debugstr_w(hostinfo.pchHostNS));
581 if(This->nscontainer)
582 set_ns_editmode(This->nscontainer);
584 hres = CreateURLMoniker(NULL, wszAboutBlank, &mon);
586 FIXME("CreateURLMoniker failed: %08x\n", hres);
590 update_doc(This, UPDATE_UI);
592 hres = IPersistMoniker_Load(PERSISTMON(This), TRUE, mon, NULL, 0);
593 IMoniker_Release(mon);
597 if(This->ui_active) {
598 OLECHAR wszHTMLDocument[30];
602 IOleInPlaceUIWindow_SetActiveObject(This->ip_window, NULL, NULL);
604 IDocHostUIHandler_HideUI(This->hostui);
607 IDocHostUIHandler_ShowUI(This->hostui, DOCHOSTUITYPE_AUTHOR, ACTOBJ(This), CMDTARGET(This),
608 This->frame, This->ip_window);
610 LoadStringW(hInst, IDS_HTMLDOCUMENT, wszHTMLDocument,
611 sizeof(wszHTMLDocument)/sizeof(WCHAR));
614 IOleInPlaceUIWindow_SetActiveObject(This->ip_window, ACTOBJ(This), wszHTMLDocument);
616 memset(&rcBorderWidths, 0, sizeof(rcBorderWidths));
617 IOleInPlaceFrame_SetBorderSpace(This->frame, &rcBorderWidths);
623 static HRESULT exec_htmleditmode(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
625 FIXME("(%p)->(%08x %p %p)\n", This, cmdexecopt, in, out);
629 static HRESULT exec_setdirty(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
631 FIXME("(%p)->(%08x %p %p)\n", This, cmdexecopt, in, out);
635 static HRESULT exec_baselinefont3(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
637 FIXME("(%p)->(%08x %p %p)\n", This, cmdexecopt, in, out);
641 static HRESULT exec_respectvisibility_indesign(HTMLDocument *This, DWORD cmdexecopt,
642 VARIANT *in, VARIANT *out)
644 FIXME("(%p)->(%08x %p %p)\n", This, cmdexecopt, in, out);
648 static HRESULT query_enabled_stub(HTMLDocument *This, OLECMD *cmd)
652 FIXME("CGID_MSHTML: IDM_PRINT\n");
653 cmd->cmdf = OLECMDF_SUPPORTED|OLECMDF_ENABLED;
655 case IDM_BLOCKDIRLTR:
656 FIXME("CGID_MSHTML: IDM_BLOCKDIRLTR\n");
657 cmd->cmdf = OLECMDF_SUPPORTED|OLECMDF_ENABLED;
659 case IDM_BLOCKDIRRTL:
660 FIXME("CGID_MSHTML: IDM_BLOCKDIRRTL\n");
661 cmd->cmdf = OLECMDF_SUPPORTED|OLECMDF_ENABLED;
668 static const struct {
670 HRESULT (*func)(HTMLDocument*,DWORD,VARIANT*,VARIANT*);
671 } exec_table[OLECMDID_GETPRINTTEMPLATE+1] = {
673 { OLECMDF_SUPPORTED, exec_open }, /* OLECMDID_OPEN */
674 { OLECMDF_SUPPORTED, exec_new }, /* OLECMDID_NEW */
675 { OLECMDF_SUPPORTED, exec_save }, /* OLECMDID_SAVE */
676 { OLECMDF_SUPPORTED|OLECMDF_ENABLED, exec_save_as }, /* OLECMDID_SAVEAS */
677 { OLECMDF_SUPPORTED, exec_save_copy_as }, /* OLECMDID_SAVECOPYAS */
678 { OLECMDF_SUPPORTED|OLECMDF_ENABLED, exec_print }, /* OLECMDID_PRINT */
679 { OLECMDF_SUPPORTED|OLECMDF_ENABLED, exec_print_preview }, /* OLECMDID_PRINTPREVIEW */
680 { OLECMDF_SUPPORTED|OLECMDF_ENABLED, exec_page_setup }, /* OLECMDID_PAGESETUP */
681 { OLECMDF_SUPPORTED, exec_spell }, /* OLECMDID_SPELL */
682 { OLECMDF_SUPPORTED|OLECMDF_ENABLED, exec_properties }, /* OLECMDID_PROPERTIES */
683 { OLECMDF_SUPPORTED, exec_cut }, /* OLECMDID_CUT */
684 { OLECMDF_SUPPORTED, exec_copy }, /* OLECMDID_COPY */
685 { OLECMDF_SUPPORTED, exec_paste }, /* OLECMDID_PASTE */
686 { OLECMDF_SUPPORTED, exec_paste_special }, /* OLECMDID_PASTESPECIAL */
687 { OLECMDF_SUPPORTED, exec_undo }, /* OLECMDID_UNDO */
688 { OLECMDF_SUPPORTED, exec_rendo }, /* OLECMDID_REDO */
689 { OLECMDF_SUPPORTED|OLECMDF_ENABLED, exec_select_all }, /* OLECMDID_SELECTALL */
690 { OLECMDF_SUPPORTED, exec_clear_selection }, /* OLECMDID_CLEARSELECTION */
691 { OLECMDF_SUPPORTED, exec_zoom }, /* OLECMDID_ZOOM */
692 { OLECMDF_SUPPORTED, exec_get_zoom_range }, /* OLECMDID_GETZOOMRANGE */
694 { OLECMDF_SUPPORTED|OLECMDF_ENABLED, exec_refresh }, /* OLECMDID_REFRESH */
695 { OLECMDF_SUPPORTED|OLECMDF_ENABLED, exec_stop }, /* OLECMDID_STOP */
696 {0},{0},{0},{0},{0},{0},
697 { OLECMDF_SUPPORTED, exec_stop_download }, /* OLECMDID_STOPDOWNLOAD */
699 { OLECMDF_SUPPORTED|OLECMDF_ENABLED, exec_find }, /* OLECMDID_FIND */
700 { OLECMDF_SUPPORTED, exec_delete }, /* OLECMDID_DELETE */
702 { OLECMDF_SUPPORTED, exec_enable_interaction }, /* OLECMDID_ENABLE_INTERACTION */
703 { OLECMDF_SUPPORTED, exec_on_unload }, /* OLECMDID_ONUNLOAD */
705 { OLECMDF_SUPPORTED, exec_show_page_setup }, /* OLECMDID_SHOWPAGESETUP */
706 { OLECMDF_SUPPORTED, exec_show_print }, /* OLECMDID_SHOWPRINT */
708 { OLECMDF_SUPPORTED, exec_close }, /* OLECMDID_CLOSE */
710 { OLECMDF_SUPPORTED, exec_set_print_template }, /* OLECMDID_SETPRINTTEMPLATE */
711 { OLECMDF_SUPPORTED, exec_get_print_template } /* OLECMDID_GETPRINTTEMPLATE */
714 static const cmdtable_t base_cmds[] = {
715 {IDM_COPY, query_mshtml_copy, exec_mshtml_copy},
716 {IDM_PASTE, query_mshtml_paste, exec_mshtml_paste},
717 {IDM_CUT, query_mshtml_cut, exec_mshtml_cut},
718 {IDM_BROWSEMODE, NULL, exec_browsemode},
719 {IDM_EDITMODE, NULL, exec_editmode},
720 {IDM_PRINT, query_enabled_stub, exec_print},
721 {IDM_SETDIRTY, NULL, exec_setdirty},
722 {IDM_HTMLEDITMODE, NULL, exec_htmleditmode},
723 {IDM_BASELINEFONT3, NULL, exec_baselinefont3},
724 {IDM_BLOCKDIRLTR, query_enabled_stub, NULL},
725 {IDM_BLOCKDIRRTL, query_enabled_stub, NULL},
726 {IDM_RESPECTVISIBILITY_INDESIGN, NULL, exec_respectvisibility_indesign},
730 static HRESULT WINAPI OleCommandTarget_QueryInterface(IOleCommandTarget *iface, REFIID riid, void **ppv)
732 HTMLDocument *This = CMDTARGET_THIS(iface);
733 return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppv);
736 static ULONG WINAPI OleCommandTarget_AddRef(IOleCommandTarget *iface)
738 HTMLDocument *This = CMDTARGET_THIS(iface);
739 return IHTMLDocument2_AddRef(HTMLDOC(This));
742 static ULONG WINAPI OleCommandTarget_Release(IOleCommandTarget *iface)
744 HTMLDocument *This = CMDTARGET_THIS(iface);
745 return IHTMLDocument_Release(HTMLDOC(This));
748 static HRESULT query_from_table(HTMLDocument *This, const cmdtable_t *cmdtable, OLECMD *cmd)
750 const cmdtable_t *iter = cmdtable;
754 while(iter->id && iter->id != cmd->cmdID)
757 if(!iter->id || !iter->query)
758 return OLECMDERR_E_NOTSUPPORTED;
760 return iter->query(This, cmd);
763 static HRESULT WINAPI OleCommandTarget_QueryStatus(IOleCommandTarget *iface, const GUID *pguidCmdGroup,
764 ULONG cCmds, OLECMD prgCmds[], OLECMDTEXT *pCmdText)
766 HTMLDocument *This = CMDTARGET_THIS(iface);
767 HRESULT hres = S_OK, hr;
769 TRACE("(%p)->(%s %d %p %p)\n", This, debugstr_guid(pguidCmdGroup), cCmds, prgCmds, pCmdText);
774 for(i=0; i<cCmds; i++) {
775 if(prgCmds[i].cmdID<OLECMDID_OPEN || prgCmds[i].cmdID>OLECMDID_GETPRINTTEMPLATE) {
776 WARN("Unsupported cmdID = %d\n", prgCmds[i].cmdID);
778 hres = OLECMDERR_E_NOTSUPPORTED;
780 if(prgCmds[i].cmdID == OLECMDID_OPEN || prgCmds[i].cmdID == OLECMDID_NEW) {
781 IOleCommandTarget *cmdtrg = NULL;
784 prgCmds[i].cmdf = OLECMDF_SUPPORTED;
786 hr = IOleClientSite_QueryInterface(This->client, &IID_IOleCommandTarget,
789 olecmd.cmdID = prgCmds[i].cmdID;
792 hr = IOleCommandTarget_QueryStatus(cmdtrg, NULL, 1, &olecmd, NULL);
793 if(SUCCEEDED(hr) && olecmd.cmdf)
794 prgCmds[i].cmdf = olecmd.cmdf;
797 ERR("This->client == NULL, native would crash\n");
800 prgCmds[i].cmdf = exec_table[prgCmds[i].cmdID].cmdf;
801 TRACE("cmdID = %d returning %x\n", prgCmds[i].cmdID, prgCmds[i].cmdf);
808 FIXME("Set pCmdText\n");
809 }else if(IsEqualGUID(&CGID_MSHTML, pguidCmdGroup)) {
812 for(i=0; i<cCmds; i++) {
813 HRESULT hres = query_from_table(This, base_cmds, prgCmds+i);
814 if(hres == OLECMDERR_E_NOTSUPPORTED)
815 hres = query_from_table(This, editmode_cmds, prgCmds+i);
816 if(hres == OLECMDERR_E_NOTSUPPORTED)
817 FIXME("CGID_MSHTML: unsupported cmdID %d\n", prgCmds[i].cmdID);
820 hres = prgCmds[i-1].cmdf ? S_OK : OLECMDERR_E_NOTSUPPORTED;
823 FIXME("Set pCmdText\n");
825 FIXME("Unsupported pguidCmdGroup %s\n", debugstr_guid(pguidCmdGroup));
826 hres = OLECMDERR_E_UNKNOWNGROUP;
832 static HRESULT exec_from_table(HTMLDocument *This, const cmdtable_t *cmdtable, DWORD cmdid,
833 DWORD cmdexecopt, VARIANT *in, VARIANT *out)
835 const cmdtable_t *iter = cmdtable;
837 while(iter->id && iter->id != cmdid)
840 if(!iter->id || !iter->exec)
841 return OLECMDERR_E_NOTSUPPORTED;
843 return iter->exec(This, cmdexecopt, in, out);
846 static HRESULT WINAPI OleCommandTarget_Exec(IOleCommandTarget *iface, const GUID *pguidCmdGroup,
847 DWORD nCmdID, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
849 HTMLDocument *This = CMDTARGET_THIS(iface);
852 if(nCmdID<OLECMDID_OPEN || nCmdID>OLECMDID_GETPRINTTEMPLATE || !exec_table[nCmdID].func) {
853 WARN("Unsupported cmdID = %d\n", nCmdID);
854 return OLECMDERR_E_NOTSUPPORTED;
857 return exec_table[nCmdID].func(This, nCmdexecopt, pvaIn, pvaOut);
858 }else if(IsEqualGUID(&CGID_Explorer, pguidCmdGroup)) {
859 FIXME("unsupported nCmdID %d of CGID_Explorer group\n", nCmdID);
860 TRACE("%p %p\n", pvaIn, pvaOut);
861 return OLECMDERR_E_NOTSUPPORTED;
862 }else if(IsEqualGUID(&CGID_ShellDocView, pguidCmdGroup)) {
863 FIXME("unsupported nCmdID %d of CGID_ShellDocView group\n", nCmdID);
864 return OLECMDERR_E_NOTSUPPORTED;
865 }else if(IsEqualGUID(&CGID_MSHTML, pguidCmdGroup)) {
866 HRESULT hres = exec_from_table(This, base_cmds, nCmdID, nCmdexecopt, pvaIn, pvaOut);
867 if(hres == OLECMDERR_E_NOTSUPPORTED)
868 hres = exec_from_table(This, editmode_cmds, nCmdID,
869 nCmdexecopt, pvaIn, pvaOut);
870 if(hres == OLECMDERR_E_NOTSUPPORTED)
871 FIXME("unsupported nCmdID %d of CGID_MSHTML group\n", nCmdID);
876 FIXME("Unsupported pguidCmdGroup %s\n", debugstr_guid(pguidCmdGroup));
877 return OLECMDERR_E_UNKNOWNGROUP;
880 #undef CMDTARGET_THIS
882 static const IOleCommandTargetVtbl OleCommandTargetVtbl = {
883 OleCommandTarget_QueryInterface,
884 OleCommandTarget_AddRef,
885 OleCommandTarget_Release,
886 OleCommandTarget_QueryStatus,
887 OleCommandTarget_Exec
890 void show_context_menu(HTMLDocument *This, DWORD dwID, POINT *ppt, IDispatch *elem)
892 HMENU menu_res, menu;
896 hres = IDocHostUIHandler_ShowContextMenu(This->hostui, dwID, ppt,
897 (IUnknown*)CMDTARGET(This), elem);
901 menu_res = LoadMenuW(get_shdoclc(), MAKEINTRESOURCEW(IDR_BROWSE_CONTEXT_MENU));
902 menu = GetSubMenu(menu_res, dwID);
904 cmdid = TrackPopupMenu(menu, TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_RETURNCMD,
905 ppt->x, ppt->y, 0, This->hwnd, NULL);
906 DestroyMenu(menu_res);
909 IOleCommandTarget_Exec(CMDTARGET(This), &CGID_MSHTML, cmdid, 0, NULL, NULL);
912 void HTMLDocument_OleCmd_Init(HTMLDocument *This)
914 This->lpOleCommandTargetVtbl = &OleCommandTargetVtbl;