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
32 #include "wine/debug.h"
33 #include "wine/unicode.h"
35 #include "mshtml_private.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
40 #define NSCMD_COPY "cmd_copy"
42 void do_ns_command(NSContainer *This, const char *cmd, nsICommandParams *nsparam)
44 nsICommandManager *cmdmgr;
47 TRACE("(%p)\n", This);
49 nsres = get_nsinterface((nsISupports*)This->webbrowser, &IID_nsICommandManager, (void**)&cmdmgr);
50 if(NS_FAILED(nsres)) {
51 ERR("Could not get nsICommandManager: %08x\n", nsres);
55 nsres = nsICommandManager_DoCommand(cmdmgr, cmd, nsparam, This->doc->window->nswindow);
57 ERR("DoCommand(%s) failed: %08x\n", debugstr_a(cmd), nsres);
59 nsICommandManager_Release(cmdmgr);
62 /**********************************************************
63 * IOleCommandTarget implementation
66 #define CMDTARGET_THIS(iface) DEFINE_THIS(HTMLDocument, OleCommandTarget, iface)
68 static HRESULT exec_open(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
70 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
74 static HRESULT exec_new(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
76 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
80 static HRESULT exec_save(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
82 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
86 static HRESULT exec_save_as(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
88 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
92 static HRESULT exec_save_copy_as(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
94 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
98 static nsresult set_head_text(nsIPrintSettings *settings, LPCWSTR template, BOOL head, int pos)
103 return nsIPrintSettings_SetHeaderStrLeft(settings, template);
105 return nsIPrintSettings_SetHeaderStrRight(settings, template);
107 return nsIPrintSettings_SetHeaderStrCenter(settings, template);
112 return nsIPrintSettings_SetFooterStrLeft(settings, template);
114 return nsIPrintSettings_SetFooterStrRight(settings, template);
116 return nsIPrintSettings_SetFooterStrCenter(settings, template);
123 static void set_print_template(nsIPrintSettings *settings, LPCWSTR template, BOOL head)
125 PRUnichar nstemplate[200]; /* FIXME: Use dynamic allocation */
126 PRUnichar *p = nstemplate;
127 LPCWSTR ptr=template;
142 case 'b': /* change align */
145 set_head_text(settings, nstemplate, head, pos);
149 case 'd': { /* short date */
151 GetLocalTime(&systime);
152 GetDateFormatW(LOCALE_SYSTEM_DEFAULT, 0, &systime, NULL, p,
153 sizeof(nstemplate)-(p-nstemplate)*sizeof(WCHAR));
158 case 'p': /* page number */
163 case 'P': /* page count */
164 *p++ = '?'; /* FIXME */
173 /* FIXME: set window title */
183 set_head_text(settings, nstemplate, head, pos);
186 set_head_text(settings, p, head, pos);
189 static void set_default_templates(nsIPrintSettings *settings)
193 static const PRUnichar empty[] = {0};
195 nsIPrintSettings_SetHeaderStrLeft(settings, empty);
196 nsIPrintSettings_SetHeaderStrRight(settings, empty);
197 nsIPrintSettings_SetHeaderStrCenter(settings, empty);
198 nsIPrintSettings_SetFooterStrLeft(settings, empty);
199 nsIPrintSettings_SetFooterStrRight(settings, empty);
200 nsIPrintSettings_SetFooterStrCenter(settings, empty);
202 if(LoadStringW(get_shdoclc(), IDS_PRINT_HEADER_TEMPLATE, buf,
203 sizeof(buf)/sizeof(WCHAR)))
204 set_print_template(settings, buf, TRUE);
207 if(LoadStringW(get_shdoclc(), IDS_PRINT_FOOTER_TEMPLATE, buf,
208 sizeof(buf)/sizeof(WCHAR)))
209 set_print_template(settings, buf, FALSE);
213 static HRESULT exec_print(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
215 nsIWebBrowserPrint *nsprint;
216 nsIPrintSettings *settings;
219 TRACE("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
222 FIXME("unsupported pvaOut\n");
224 if(!This->nscontainer)
227 nsres = get_nsinterface((nsISupports*)This->nscontainer->webbrowser, &IID_nsIWebBrowserPrint,
229 if(NS_FAILED(nsres)) {
230 ERR("Could not get nsIWebBrowserPrint: %08x\n", nsres);
234 nsres = nsIWebBrowserPrint_GetGlobalPrintSettings(nsprint, &settings);
236 ERR("GetCurrentPrintSettings failed: %08x\n", nsres);
238 set_default_templates(settings);
241 switch(V_VT(pvaIn)) {
242 case VT_BYREF|VT_ARRAY: {
246 if(V_ARRAY(pvaIn)->cDims != 1)
247 WARN("cDims = %d\n", V_ARRAY(pvaIn)->cDims);
249 SafeArrayAccessData(V_ARRAY(pvaIn), (void**)&opts);
250 opts_cnt = V_ARRAY(pvaIn)->rgsabound[0].cElements;
255 TRACE("setting footer %s\n", debugstr_w(V_BSTR(opts)));
256 set_print_template(settings, V_BSTR(opts), TRUE);
261 WARN("V_VT(opts) = %d\n", V_VT(opts));
266 switch(V_VT(opts+1)) {
268 TRACE("setting footer %s\n", debugstr_w(V_BSTR(opts+1)));
269 set_print_template(settings, V_BSTR(opts+1), FALSE);
274 WARN("V_VT(opts) = %d\n", V_VT(opts+1));
279 FIXME("Unsupported opts_cnt %d\n", opts_cnt);
281 SafeArrayUnaccessData(V_ARRAY(pvaIn));
285 FIXME("unsupported vt %x\n", V_VT(pvaIn));
289 nsres = nsIWebBrowserPrint_Print(nsprint, settings, NULL);
291 ERR("Print failed: %08x\n", nsres);
293 nsIWebBrowserPrint_Release(nsprint);
298 static HRESULT exec_print_preview(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
300 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
304 static HRESULT exec_page_setup(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
306 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
310 static HRESULT exec_spell(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
312 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
316 static HRESULT exec_properties(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
318 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
322 static HRESULT exec_cut(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
324 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
328 static HRESULT exec_copy(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
330 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
334 static HRESULT exec_paste(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
336 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
340 static HRESULT exec_paste_special(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
342 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
346 static HRESULT exec_undo(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
348 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
352 static HRESULT exec_rendo(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
354 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
358 static HRESULT exec_select_all(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
360 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
364 static HRESULT exec_clear_selection(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
366 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
370 static HRESULT exec_zoom(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
372 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
376 static HRESULT exec_get_zoom_range(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
378 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
382 static HRESULT exec_refresh(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
384 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
388 static HRESULT exec_stop(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
390 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
394 static HRESULT exec_stop_download(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
396 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
400 static HRESULT exec_find(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
402 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
406 static HRESULT exec_delete(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
408 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
412 static HRESULT exec_enable_interaction(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
414 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
418 static HRESULT exec_on_unload(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
420 TRACE("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
422 /* Tests show that we have nothing more to do here */
425 V_VT(pvaOut) = VT_BOOL;
426 V_BOOL(pvaOut) = VARIANT_TRUE;
432 static HRESULT exec_show_page_setup(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
434 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
438 static HRESULT exec_show_print(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
440 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
444 static HRESULT exec_close(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
446 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
450 static HRESULT exec_set_print_template(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
452 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
456 static HRESULT exec_get_print_template(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
458 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
462 static HRESULT query_mshtml_copy(HTMLDocument *This, OLECMD *cmd)
464 FIXME("(%p)\n", This);
465 cmd->cmdf = OLECMDF_SUPPORTED|OLECMDF_ENABLED;
469 static HRESULT exec_mshtml_copy(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
471 TRACE("(%p)->(%08x %p %p)\n", This, cmdexecopt, in, out);
473 if(This->usermode == EDITMODE)
474 return editor_exec_copy(This, cmdexecopt, in, out);
476 do_ns_command(This->nscontainer, NSCMD_COPY, NULL);
480 static HRESULT query_mshtml_cut(HTMLDocument *This, OLECMD *cmd)
482 FIXME("(%p)\n", This);
483 cmd->cmdf = OLECMDF_SUPPORTED|OLECMDF_ENABLED;
487 static HRESULT exec_mshtml_cut(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
489 TRACE("(%p)->(%08x %p %p)\n", This, cmdexecopt, in, out);
491 if(This->usermode == EDITMODE)
492 return editor_exec_cut(This, cmdexecopt, in, out);
494 FIXME("Unimplemented in browse mode\n");
498 static HRESULT query_mshtml_paste(HTMLDocument *This, OLECMD *cmd)
500 FIXME("(%p)\n", This);
501 cmd->cmdf = OLECMDF_SUPPORTED|OLECMDF_ENABLED;
505 static HRESULT exec_mshtml_paste(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
507 TRACE("(%p)->(%08x %p %p)\n", This, cmdexecopt, in, out);
509 if(This->usermode == EDITMODE)
510 return editor_exec_paste(This, cmdexecopt, in, out);
512 FIXME("Unimplemented in browse mode\n");
516 static HRESULT exec_browsemode(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
518 WARN("(%p)->(%08x %p %p)\n", This, cmdexecopt, in, out);
521 FIXME("unsupported args\n");
523 This->usermode = BROWSEMODE;
528 static HRESULT exec_editmode(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
533 TRACE("(%p)->(%08x %p %p)\n", This, cmdexecopt, in, out);
536 FIXME("unsupported args\n");
538 if(This->usermode == EDITMODE)
541 This->usermode = EDITMODE;
544 CLSID clsid = IID_NULL;
545 hres = IMoniker_GetClassID(This->mon, &clsid);
546 if(SUCCEEDED(hres)) {
547 /* We should use IMoniker::Save here */
548 FIXME("Use CLSID %s\n", debugstr_guid(&clsid));
553 IOleInPlaceFrame_SetStatusText(This->frame, NULL);
555 This->readystate = READYSTATE_UNINITIALIZED;
558 IOleCommandTarget *cmdtrg;
560 hres = IOleClientSite_QueryInterface(This->client, &IID_IOleCommandTarget,
562 if(SUCCEEDED(hres)) {
567 IOleCommandTarget_Exec(cmdtrg, &CGID_ShellDocView, 37, 0, &var, NULL);
569 IOleCommandTarget_Release(cmdtrg);
574 DOCHOSTUIINFO hostinfo;
576 memset(&hostinfo, 0, sizeof(DOCHOSTUIINFO));
577 hostinfo.cbSize = sizeof(DOCHOSTUIINFO);
578 hres = IDocHostUIHandler_GetHostInfo(This->hostui, &hostinfo);
580 /* FIXME: use hostinfo */
581 TRACE("hostinfo = {%u %08x %08x %s %s}\n",
582 hostinfo.cbSize, hostinfo.dwFlags, hostinfo.dwDoubleClick,
583 debugstr_w(hostinfo.pchHostCss), debugstr_w(hostinfo.pchHostNS));
586 if(This->nscontainer)
587 set_ns_editmode(This->nscontainer);
589 update_doc(This, UPDATE_UI);
592 /* FIXME: We should find nicer way to do this */
593 remove_doc_tasks(This);
596 IMoniker_AddRef(mon);
598 static const WCHAR about_blankW[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
600 hres = CreateURLMoniker(NULL, about_blankW, &mon);
602 FIXME("CreateURLMoniker failed: %08x\n", hres);
607 hres = IPersistMoniker_Load(PERSISTMON(This), TRUE, mon, NULL, 0);
608 IMoniker_Release(mon);
612 if(This->ui_active) {
616 call_set_active_object(This->ip_window, NULL);
618 IDocHostUIHandler_HideUI(This->hostui);
621 IDocHostUIHandler_ShowUI(This->hostui, DOCHOSTUITYPE_AUTHOR, ACTOBJ(This), CMDTARGET(This),
622 This->frame, This->ip_window);
625 call_set_active_object(This->ip_window, ACTOBJ(This));
627 memset(&rcBorderWidths, 0, sizeof(rcBorderWidths));
629 IOleInPlaceFrame_SetBorderSpace(This->frame, &rcBorderWidths);
635 static HRESULT exec_htmleditmode(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
637 FIXME("(%p)->(%08x %p %p)\n", This, cmdexecopt, in, out);
641 static HRESULT exec_baselinefont3(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
643 FIXME("(%p)->(%08x %p %p)\n", This, cmdexecopt, in, out);
647 static HRESULT exec_respectvisibility_indesign(HTMLDocument *This, DWORD cmdexecopt,
648 VARIANT *in, VARIANT *out)
650 FIXME("(%p)->(%08x %p %p)\n", This, cmdexecopt, in, out);
654 static HRESULT query_enabled_stub(HTMLDocument *This, OLECMD *cmd)
658 FIXME("CGID_MSHTML: IDM_PRINT\n");
659 cmd->cmdf = OLECMDF_SUPPORTED|OLECMDF_ENABLED;
661 case IDM_BLOCKDIRLTR:
662 FIXME("CGID_MSHTML: IDM_BLOCKDIRLTR\n");
663 cmd->cmdf = OLECMDF_SUPPORTED|OLECMDF_ENABLED;
665 case IDM_BLOCKDIRRTL:
666 FIXME("CGID_MSHTML: IDM_BLOCKDIRRTL\n");
667 cmd->cmdf = OLECMDF_SUPPORTED|OLECMDF_ENABLED;
674 static const struct {
676 HRESULT (*func)(HTMLDocument*,DWORD,VARIANT*,VARIANT*);
677 } exec_table[OLECMDID_GETPRINTTEMPLATE+1] = {
679 { OLECMDF_SUPPORTED, exec_open }, /* OLECMDID_OPEN */
680 { OLECMDF_SUPPORTED, exec_new }, /* OLECMDID_NEW */
681 { OLECMDF_SUPPORTED, exec_save }, /* OLECMDID_SAVE */
682 { OLECMDF_SUPPORTED|OLECMDF_ENABLED, exec_save_as }, /* OLECMDID_SAVEAS */
683 { OLECMDF_SUPPORTED, exec_save_copy_as }, /* OLECMDID_SAVECOPYAS */
684 { OLECMDF_SUPPORTED|OLECMDF_ENABLED, exec_print }, /* OLECMDID_PRINT */
685 { OLECMDF_SUPPORTED|OLECMDF_ENABLED, exec_print_preview }, /* OLECMDID_PRINTPREVIEW */
686 { OLECMDF_SUPPORTED|OLECMDF_ENABLED, exec_page_setup }, /* OLECMDID_PAGESETUP */
687 { OLECMDF_SUPPORTED, exec_spell }, /* OLECMDID_SPELL */
688 { OLECMDF_SUPPORTED|OLECMDF_ENABLED, exec_properties }, /* OLECMDID_PROPERTIES */
689 { OLECMDF_SUPPORTED, exec_cut }, /* OLECMDID_CUT */
690 { OLECMDF_SUPPORTED, exec_copy }, /* OLECMDID_COPY */
691 { OLECMDF_SUPPORTED, exec_paste }, /* OLECMDID_PASTE */
692 { OLECMDF_SUPPORTED, exec_paste_special }, /* OLECMDID_PASTESPECIAL */
693 { OLECMDF_SUPPORTED, exec_undo }, /* OLECMDID_UNDO */
694 { OLECMDF_SUPPORTED, exec_rendo }, /* OLECMDID_REDO */
695 { OLECMDF_SUPPORTED|OLECMDF_ENABLED, exec_select_all }, /* OLECMDID_SELECTALL */
696 { OLECMDF_SUPPORTED, exec_clear_selection }, /* OLECMDID_CLEARSELECTION */
697 { OLECMDF_SUPPORTED, exec_zoom }, /* OLECMDID_ZOOM */
698 { OLECMDF_SUPPORTED, exec_get_zoom_range }, /* OLECMDID_GETZOOMRANGE */
700 { OLECMDF_SUPPORTED|OLECMDF_ENABLED, exec_refresh }, /* OLECMDID_REFRESH */
701 { OLECMDF_SUPPORTED|OLECMDF_ENABLED, exec_stop }, /* OLECMDID_STOP */
702 {0},{0},{0},{0},{0},{0},
703 { OLECMDF_SUPPORTED, exec_stop_download }, /* OLECMDID_STOPDOWNLOAD */
705 { OLECMDF_SUPPORTED|OLECMDF_ENABLED, exec_find }, /* OLECMDID_FIND */
706 { OLECMDF_SUPPORTED, exec_delete }, /* OLECMDID_DELETE */
708 { OLECMDF_SUPPORTED, exec_enable_interaction }, /* OLECMDID_ENABLE_INTERACTION */
709 { OLECMDF_SUPPORTED, exec_on_unload }, /* OLECMDID_ONUNLOAD */
711 { OLECMDF_SUPPORTED, exec_show_page_setup }, /* OLECMDID_SHOWPAGESETUP */
712 { OLECMDF_SUPPORTED, exec_show_print }, /* OLECMDID_SHOWPRINT */
714 { OLECMDF_SUPPORTED, exec_close }, /* OLECMDID_CLOSE */
716 { OLECMDF_SUPPORTED, exec_set_print_template }, /* OLECMDID_SETPRINTTEMPLATE */
717 { OLECMDF_SUPPORTED, exec_get_print_template } /* OLECMDID_GETPRINTTEMPLATE */
720 static const cmdtable_t base_cmds[] = {
721 {IDM_COPY, query_mshtml_copy, exec_mshtml_copy},
722 {IDM_PASTE, query_mshtml_paste, exec_mshtml_paste},
723 {IDM_CUT, query_mshtml_cut, exec_mshtml_cut},
724 {IDM_BROWSEMODE, NULL, exec_browsemode},
725 {IDM_EDITMODE, NULL, exec_editmode},
726 {IDM_PRINT, query_enabled_stub, exec_print},
727 {IDM_HTMLEDITMODE, NULL, exec_htmleditmode},
728 {IDM_BASELINEFONT3, NULL, exec_baselinefont3},
729 {IDM_BLOCKDIRLTR, query_enabled_stub, NULL},
730 {IDM_BLOCKDIRRTL, query_enabled_stub, NULL},
731 {IDM_RESPECTVISIBILITY_INDESIGN, NULL, exec_respectvisibility_indesign},
735 static HRESULT WINAPI OleCommandTarget_QueryInterface(IOleCommandTarget *iface, REFIID riid, void **ppv)
737 HTMLDocument *This = CMDTARGET_THIS(iface);
738 return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppv);
741 static ULONG WINAPI OleCommandTarget_AddRef(IOleCommandTarget *iface)
743 HTMLDocument *This = CMDTARGET_THIS(iface);
744 return IHTMLDocument2_AddRef(HTMLDOC(This));
747 static ULONG WINAPI OleCommandTarget_Release(IOleCommandTarget *iface)
749 HTMLDocument *This = CMDTARGET_THIS(iface);
750 return IHTMLDocument_Release(HTMLDOC(This));
753 static HRESULT query_from_table(HTMLDocument *This, const cmdtable_t *cmdtable, OLECMD *cmd)
755 const cmdtable_t *iter = cmdtable;
759 while(iter->id && iter->id != cmd->cmdID)
762 if(!iter->id || !iter->query)
763 return OLECMDERR_E_NOTSUPPORTED;
765 return iter->query(This, cmd);
768 static HRESULT WINAPI OleCommandTarget_QueryStatus(IOleCommandTarget *iface, const GUID *pguidCmdGroup,
769 ULONG cCmds, OLECMD prgCmds[], OLECMDTEXT *pCmdText)
771 HTMLDocument *This = CMDTARGET_THIS(iface);
772 HRESULT hres = S_OK, hr;
774 TRACE("(%p)->(%s %d %p %p)\n", This, debugstr_guid(pguidCmdGroup), cCmds, prgCmds, pCmdText);
779 for(i=0; i<cCmds; i++) {
780 if(prgCmds[i].cmdID<OLECMDID_OPEN || prgCmds[i].cmdID>OLECMDID_GETPRINTTEMPLATE) {
781 WARN("Unsupported cmdID = %d\n", prgCmds[i].cmdID);
783 hres = OLECMDERR_E_NOTSUPPORTED;
785 if(prgCmds[i].cmdID == OLECMDID_OPEN || prgCmds[i].cmdID == OLECMDID_NEW) {
786 IOleCommandTarget *cmdtrg = NULL;
789 prgCmds[i].cmdf = OLECMDF_SUPPORTED;
791 hr = IOleClientSite_QueryInterface(This->client, &IID_IOleCommandTarget,
794 olecmd.cmdID = prgCmds[i].cmdID;
797 hr = IOleCommandTarget_QueryStatus(cmdtrg, NULL, 1, &olecmd, NULL);
798 if(SUCCEEDED(hr) && olecmd.cmdf)
799 prgCmds[i].cmdf = olecmd.cmdf;
802 ERR("This->client == NULL, native would crash\n");
805 prgCmds[i].cmdf = exec_table[prgCmds[i].cmdID].cmdf;
806 TRACE("cmdID = %d returning %x\n", prgCmds[i].cmdID, prgCmds[i].cmdf);
813 FIXME("Set pCmdText\n");
814 }else if(IsEqualGUID(&CGID_MSHTML, pguidCmdGroup)) {
817 for(i=0; i<cCmds; i++) {
818 HRESULT hres = query_from_table(This, base_cmds, prgCmds+i);
819 if(hres == OLECMDERR_E_NOTSUPPORTED)
820 hres = query_from_table(This, editmode_cmds, prgCmds+i);
821 if(hres == OLECMDERR_E_NOTSUPPORTED)
822 FIXME("CGID_MSHTML: unsupported cmdID %d\n", prgCmds[i].cmdID);
825 hres = prgCmds[i-1].cmdf ? S_OK : OLECMDERR_E_NOTSUPPORTED;
828 FIXME("Set pCmdText\n");
830 FIXME("Unsupported pguidCmdGroup %s\n", debugstr_guid(pguidCmdGroup));
831 hres = OLECMDERR_E_UNKNOWNGROUP;
837 static HRESULT exec_from_table(HTMLDocument *This, const cmdtable_t *cmdtable, DWORD cmdid,
838 DWORD cmdexecopt, VARIANT *in, VARIANT *out)
840 const cmdtable_t *iter = cmdtable;
842 while(iter->id && iter->id != cmdid)
845 if(!iter->id || !iter->exec)
846 return OLECMDERR_E_NOTSUPPORTED;
848 return iter->exec(This, cmdexecopt, in, out);
851 static HRESULT WINAPI OleCommandTarget_Exec(IOleCommandTarget *iface, const GUID *pguidCmdGroup,
852 DWORD nCmdID, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
854 HTMLDocument *This = CMDTARGET_THIS(iface);
857 if(nCmdID<OLECMDID_OPEN || nCmdID>OLECMDID_GETPRINTTEMPLATE || !exec_table[nCmdID].func) {
858 WARN("Unsupported cmdID = %d\n", nCmdID);
859 return OLECMDERR_E_NOTSUPPORTED;
862 return exec_table[nCmdID].func(This, nCmdexecopt, pvaIn, pvaOut);
863 }else if(IsEqualGUID(&CGID_Explorer, pguidCmdGroup)) {
864 FIXME("unsupported nCmdID %d of CGID_Explorer group\n", nCmdID);
865 TRACE("%p %p\n", pvaIn, pvaOut);
866 return OLECMDERR_E_NOTSUPPORTED;
867 }else if(IsEqualGUID(&CGID_ShellDocView, pguidCmdGroup)) {
868 FIXME("unsupported nCmdID %d of CGID_ShellDocView group\n", nCmdID);
869 return OLECMDERR_E_NOTSUPPORTED;
870 }else if(IsEqualGUID(&CGID_MSHTML, pguidCmdGroup)) {
871 HRESULT hres = exec_from_table(This, base_cmds, nCmdID, nCmdexecopt, pvaIn, pvaOut);
872 if(hres == OLECMDERR_E_NOTSUPPORTED)
873 hres = exec_from_table(This, editmode_cmds, nCmdID,
874 nCmdexecopt, pvaIn, pvaOut);
875 if(hres == OLECMDERR_E_NOTSUPPORTED)
876 FIXME("unsupported nCmdID %d of CGID_MSHTML group\n", nCmdID);
881 FIXME("Unsupported pguidCmdGroup %s\n", debugstr_guid(pguidCmdGroup));
882 return OLECMDERR_E_UNKNOWNGROUP;
885 #undef CMDTARGET_THIS
887 static const IOleCommandTargetVtbl OleCommandTargetVtbl = {
888 OleCommandTarget_QueryInterface,
889 OleCommandTarget_AddRef,
890 OleCommandTarget_Release,
891 OleCommandTarget_QueryStatus,
892 OleCommandTarget_Exec
895 void show_context_menu(HTMLDocument *This, DWORD dwID, POINT *ppt, IDispatch *elem)
897 HMENU menu_res, menu;
901 hres = IDocHostUIHandler_ShowContextMenu(This->hostui, dwID, ppt,
902 (IUnknown*)CMDTARGET(This), elem);
906 menu_res = LoadMenuW(get_shdoclc(), MAKEINTRESOURCEW(IDR_BROWSE_CONTEXT_MENU));
907 menu = GetSubMenu(menu_res, dwID);
909 cmdid = TrackPopupMenu(menu, TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_RETURNCMD,
910 ppt->x, ppt->y, 0, This->hwnd, NULL);
911 DestroyMenu(menu_res);
914 IOleCommandTarget_Exec(CMDTARGET(This), &CGID_MSHTML, cmdid, 0, NULL, NULL);
917 void HTMLDocument_OleCmd_Init(HTMLDocument *This)
919 This->lpOleCommandTargetVtbl = &OleCommandTargetVtbl;