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
36 #include "wine/debug.h"
37 #include "wine/unicode.h"
39 #include "mshtml_private.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
44 #define NSCMD_BOLD "cmd_bold"
45 #define NSCMD_ITALIC "cmd_italic"
46 #define NSCMD_UNDERLINE "cmd_underline"
47 #define NSCMD_FONTCOLOR "cmd_fontColor"
48 #define NSCMD_ALIGN "cmd_align"
49 #define NSCMD_FONTFACE "cmd_fontFace"
50 #define NSCMD_INDENT "cmd_indent"
51 #define NSCMD_OUTDENT "cmd_outdent"
52 #define NSCMD_INSERTHR "cmd_insertHR"
53 #define NSCMD_UL "cmd_ul"
54 #define NSCMD_OL "cmd_ol"
56 #define NSSTATE_ATTRIBUTE "state_attribute"
57 #define NSSTATE_ALL "state_all"
59 #define NSALIGN_CENTER "center"
60 #define NSALIGN_LEFT "left"
61 #define NSALIGN_RIGHT "right"
63 /**********************************************************
64 * IOleCommandTarget implementation
67 #define CMDTARGET_THIS(iface) DEFINE_THIS(HTMLDocument, OleCommandTarget, iface)
69 static HRESULT exec_open(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
71 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
75 static HRESULT exec_new(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
77 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
81 static HRESULT exec_save(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
83 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
87 static HRESULT exec_save_as(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
89 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
93 static HRESULT exec_save_copy_as(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
95 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
99 static nsresult set_head_text(nsIPrintSettings *settings, LPCWSTR template, BOOL head, int pos)
104 return nsIPrintSettings_SetHeaderStrLeft(settings, template);
106 return nsIPrintSettings_SetHeaderStrRight(settings, template);
108 return nsIPrintSettings_SetHeaderStrCenter(settings, template);
113 return nsIPrintSettings_SetFooterStrLeft(settings, template);
115 return nsIPrintSettings_SetFooterStrRight(settings, template);
117 return nsIPrintSettings_SetFooterStrCenter(settings, template);
124 static void set_print_template(nsIPrintSettings *settings, LPCWSTR template, BOOL head)
126 PRUnichar nstemplate[200]; /* FIXME: Use dynamic allocation */
127 PRUnichar *p = nstemplate;
128 LPCWSTR ptr=template;
143 case 'b': /* change align */
146 set_head_text(settings, nstemplate, head, pos);
150 case 'd': { /* short date */
152 GetLocalTime(&systime);
153 GetDateFormatW(LOCALE_SYSTEM_DEFAULT, 0, &systime, NULL, p,
154 sizeof(nstemplate)-(p-nstemplate)*sizeof(WCHAR));
159 case 'p': /* page number */
164 case 'P': /* page count */
165 *p++ = '?'; /* FIXME */
174 /* FIXME: set window title */
184 set_head_text(settings, nstemplate, head, pos);
187 set_head_text(settings, p, head, pos);
190 static void set_default_templates(nsIPrintSettings *settings)
194 static const PRUnichar empty[] = {0};
196 nsIPrintSettings_SetHeaderStrLeft(settings, empty);
197 nsIPrintSettings_SetHeaderStrRight(settings, empty);
198 nsIPrintSettings_SetHeaderStrCenter(settings, empty);
199 nsIPrintSettings_SetFooterStrLeft(settings, empty);
200 nsIPrintSettings_SetFooterStrRight(settings, empty);
201 nsIPrintSettings_SetFooterStrCenter(settings, empty);
203 if(LoadStringW(get_shdoclc(), IDS_PRINT_HEADER_TEMPLATE, buf,
204 sizeof(buf)/sizeof(WCHAR)))
205 set_print_template(settings, buf, TRUE);
208 if(LoadStringW(get_shdoclc(), IDS_PRINT_FOOTER_TEMPLATE, buf,
209 sizeof(buf)/sizeof(WCHAR)))
210 set_print_template(settings, buf, FALSE);
214 static HRESULT exec_print(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
216 nsIInterfaceRequestor *iface_req;
217 nsIWebBrowserPrint *nsprint;
218 nsIPrintSettings *settings;
221 TRACE("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
224 FIXME("unsupported pvaOut\n");
226 if(!This->nscontainer)
229 nsres = nsIWebBrowser_QueryInterface(This->nscontainer->webbrowser,
230 &IID_nsIInterfaceRequestor, (void**)&iface_req);
231 if(NS_FAILED(nsres)) {
232 ERR("Could not get nsIInterfaceRequestor: %08x\n", nsres);
236 nsres = nsIInterfaceRequestor_GetInterface(iface_req, &IID_nsIWebBrowserPrint,
238 nsIInterfaceRequestor_Release(iface_req);
239 if(NS_FAILED(nsres)) {
240 ERR("Could not get nsIWebBrowserPrint: %08x\n", nsres);
244 nsres = nsIWebBrowserPrint_GetGlobalPrintSettings(nsprint, &settings);
246 ERR("GetCurrentPrintSettings failed: %08x\n", nsres);
248 set_default_templates(settings);
251 switch(V_VT(pvaIn)) {
252 case VT_BYREF|VT_ARRAY: {
256 if(V_ARRAY(pvaIn)->cDims != 1)
257 WARN("cDims = %d\n", V_ARRAY(pvaIn)->cDims);
259 SafeArrayAccessData(V_ARRAY(pvaIn), (void**)&opts);
260 opts_cnt = V_ARRAY(pvaIn)->rgsabound[0].cElements;
265 TRACE("setting footer %s\n", debugstr_w(V_BSTR(opts)));
266 set_print_template(settings, V_BSTR(opts), TRUE);
271 WARN("V_VT(opts) = %d\n", V_VT(opts));
276 switch(V_VT(opts+1)) {
278 TRACE("setting footer %s\n", debugstr_w(V_BSTR(opts+1)));
279 set_print_template(settings, V_BSTR(opts+1), FALSE);
284 WARN("V_VT(opts) = %d\n", V_VT(opts+1));
289 FIXME("Unsupported opts_cnt %d\n", opts_cnt);
291 SafeArrayUnaccessData(V_ARRAY(pvaIn));
295 FIXME("unsupported vt %x\n", V_VT(pvaIn));
299 nsres = nsIWebBrowserPrint_Print(nsprint, settings, NULL);
301 ERR("Print failed: %08x\n", nsres);
303 nsIWebBrowserPrint_Release(nsprint);
308 static HRESULT exec_print_preview(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
310 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
314 static HRESULT exec_page_setup(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
316 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
320 static HRESULT exec_spell(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
322 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
326 static HRESULT exec_properties(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
328 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
332 static HRESULT exec_cut(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
334 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
338 static HRESULT exec_copy(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
340 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
344 static HRESULT exec_paste(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
346 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
350 static HRESULT exec_paste_special(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
352 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
356 static HRESULT exec_undo(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
358 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
362 static HRESULT exec_rendo(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
364 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
368 static HRESULT exec_select_all(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
370 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
374 static HRESULT exec_clear_selection(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
376 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
380 static HRESULT exec_zoom(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
382 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
386 static HRESULT exec_get_zoom_range(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
388 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
392 static HRESULT exec_refresh(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
394 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
398 static HRESULT exec_stop(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
400 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
404 static HRESULT exec_stop_download(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 void do_ns_command(NSContainer *This, const char *cmd, nsICommandParams *nsparam)
468 nsICommandManager *cmdmgr;
469 nsIInterfaceRequestor *iface_req;
472 TRACE("(%p)\n", This);
474 nsres = nsIWebBrowser_QueryInterface(This->webbrowser,
475 &IID_nsIInterfaceRequestor, (void**)&iface_req);
476 if(NS_FAILED(nsres)) {
477 ERR("Could not get nsIInterfaceRequestor: %08x\n", nsres);
481 nsres = nsIInterfaceRequestor_GetInterface(iface_req, &IID_nsICommandManager,
483 nsIInterfaceRequestor_Release(iface_req);
484 if(NS_FAILED(nsres)) {
485 ERR("Could not get nsICommandManager: %08x\n", nsres);
489 nsres = nsICommandManager_DoCommand(cmdmgr, cmd, nsparam, NULL);
491 ERR("DoCommand(%s) failed: %08x\n", debugstr_a(cmd), nsres);
493 nsICommandManager_Release(cmdmgr);
496 static nsresult get_ns_command_state(NSContainer *This, const char *cmd, nsICommandParams *nsparam)
498 nsICommandManager *cmdmgr;
499 nsIInterfaceRequestor *iface_req;
502 nsres = nsIWebBrowser_QueryInterface(This->webbrowser,
503 &IID_nsIInterfaceRequestor, (void**)&iface_req);
504 if(NS_FAILED(nsres)) {
505 ERR("Could not get nsIInterfaceRequestor: %08x\n", nsres);
509 nsres = nsIInterfaceRequestor_GetInterface(iface_req, &IID_nsICommandManager,
511 nsIInterfaceRequestor_Release(iface_req);
512 if(NS_FAILED(nsres)) {
513 ERR("Could not get nsICommandManager: %08x\n", nsres);
517 nsres = nsICommandManager_GetCommandState(cmdmgr, cmd, NULL, nsparam);
519 ERR("GetCommandState(%s) failed: %08x\n", debugstr_a(cmd), nsres);
521 nsICommandManager_Release(cmdmgr);
525 static DWORD query_edit_status(HTMLDocument *This, const char *nscmd)
527 nsICommandParams *nsparam;
530 if(This->usermode != EDITMODE || This->readystate < READYSTATE_INTERACTIVE)
531 return OLECMDF_SUPPORTED;
533 if(This->nscontainer && nscmd) {
534 nsparam = create_nscommand_params();
535 get_ns_command_state(This->nscontainer, nscmd, nsparam);
537 nsICommandParams_GetBooleanValue(nsparam, NSSTATE_ALL, &b);
539 nsICommandParams_Release(nsparam);
542 return OLECMDF_SUPPORTED | OLECMDF_ENABLED | (b ? OLECMDF_LATCHED : 0);
545 static DWORD query_align_status(HTMLDocument *This, const char *align_str)
547 nsICommandParams *nsparam;
550 if(This->usermode != EDITMODE || This->readystate < READYSTATE_INTERACTIVE)
551 return OLECMDF_SUPPORTED;
553 if(This->nscontainer) {
554 nsparam = create_nscommand_params();
555 get_ns_command_state(This->nscontainer, NSCMD_ALIGN, nsparam);
557 nsICommandParams_GetCStringValue(nsparam, NSSTATE_ATTRIBUTE, &align);
559 nsICommandParams_Release(nsparam);
562 return OLECMDF_SUPPORTED | OLECMDF_ENABLED | (align && !strcmp(align_str, align) ? OLECMDF_LATCHED : 0);
565 static void set_ns_align(HTMLDocument *This, const char *align_str)
567 nsICommandParams *nsparam;
569 if(!This->nscontainer)
572 nsparam = create_nscommand_params();
573 nsICommandParams_SetCStringValue(nsparam, NSSTATE_ATTRIBUTE, align_str);
575 do_ns_command(This->nscontainer, NSCMD_ALIGN, nsparam);
577 nsICommandParams_Release(nsparam);
580 static HRESULT exec_fontname(HTMLDocument *This, VARIANT *in, VARIANT *out)
582 TRACE("(%p)->(%p %p)\n", This, in, out);
584 if(!This->nscontainer)
588 nsICommandParams *nsparam = create_nscommand_params();
592 if(V_VT(in) != VT_BSTR) {
593 FIXME("Unsupported vt=%d\n", V_VT(out));
597 len = WideCharToMultiByte(CP_ACP, 0, V_BSTR(in), -1, NULL, 0, NULL, NULL);
598 stra = mshtml_alloc(len);
599 WideCharToMultiByte(CP_ACP, 0, V_BSTR(in), -1, stra, -1, NULL, NULL);
600 nsICommandParams_SetCStringValue(nsparam, NSSTATE_ATTRIBUTE, stra);
603 do_ns_command(This->nscontainer, NSCMD_FONTFACE, nsparam);
605 nsICommandParams_Release(nsparam);
609 nsICommandParams *nsparam;
615 if(V_VT(out) != VT_BSTR) {
616 FIXME("Unsupported vt=%d\n", V_VT(out));
620 nsparam = create_nscommand_params();
622 nsres = get_ns_command_state(This->nscontainer, NSCMD_FONTFACE, nsparam);
626 nsICommandParams_GetCStringValue(nsparam, NSSTATE_ATTRIBUTE, &stra);
627 nsICommandParams_Release(nsparam);
629 len = MultiByteToWideChar(CP_ACP, 0, stra, -1, NULL, 0);
630 strw = mshtml_alloc(len*sizeof(WCHAR));
631 MultiByteToWideChar(CP_ACP, 0, stra, -1, strw, -1);
634 V_BSTR(out) = SysAllocString(strw);
641 static HRESULT exec_forecolor(HTMLDocument *This, VARIANT *in, VARIANT *out)
643 TRACE("(%p)->(%p %p)\n", This, in, out);
646 if(V_VT(in) == VT_I4) {
647 nsICommandParams *nsparam = create_nscommand_params();
650 sprintf(color_str, "#%02x%02x%02x",
651 V_I4(in)&0xff, (V_I4(in)>>8)&0xff, (V_I4(in)>>16)&0xff);
653 nsICommandParams_SetCStringValue(nsparam, NSSTATE_ATTRIBUTE, color_str);
654 do_ns_command(This->nscontainer, NSCMD_FONTCOLOR, nsparam);
656 nsICommandParams_Release(nsparam);
658 FIXME("unsupported in vt=%d\n", V_VT(in));
663 FIXME("unsupported out\n");
670 static HRESULT exec_fontsize(HTMLDocument *This, VARIANT *in, VARIANT *out)
672 TRACE("(%p)->(%p %p)\n", This, in, out);
679 get_font_size(This, val);
680 V_I4(out) = strtolW(val, NULL, 10);
683 get_font_size(This, val);
684 V_BSTR(out) = SysAllocString(val);
687 FIXME("unsupported vt %d\n", V_VT(out));
695 static const WCHAR format[] = {'%','d',0};
696 wsprintfW(size, format, V_I4(in));
697 set_font_size(This, size);
701 set_font_size(This, V_BSTR(in));
704 FIXME("unsupported vt %d\n", V_VT(in));
711 static HRESULT exec_bold(HTMLDocument *This)
713 TRACE("(%p)\n", This);
715 if(This->nscontainer)
716 do_ns_command(This->nscontainer, NSCMD_BOLD, NULL);
721 static HRESULT exec_italic(HTMLDocument *This)
723 TRACE("(%p)\n", This);
725 if(This->nscontainer)
726 do_ns_command(This->nscontainer, NSCMD_ITALIC, NULL);
731 static HRESULT exec_justifycenter(HTMLDocument *This)
733 TRACE("(%p)\n", This);
734 set_ns_align(This, NSALIGN_CENTER);
738 static HRESULT exec_justifyleft(HTMLDocument *This)
740 TRACE("(%p)\n", This);
741 set_ns_align(This, NSALIGN_LEFT);
745 static HRESULT exec_justifyright(HTMLDocument *This)
747 TRACE("(%p)\n", This);
748 set_ns_align(This, NSALIGN_RIGHT);
752 static HRESULT exec_underline(HTMLDocument *This)
754 TRACE("(%p)\n", This);
756 if(This->nscontainer)
757 do_ns_command(This->nscontainer, NSCMD_UNDERLINE, NULL);
762 static HRESULT exec_browsemode(HTMLDocument *This)
764 WARN("(%p)\n", This);
766 This->usermode = BROWSEMODE;
771 static void setup_ns_editing(NSContainer *This)
773 nsIInterfaceRequestor *iface_req;
774 nsIEditingSession *editing_session = NULL;
775 nsIURIContentListener *listener = NULL;
776 nsIDOMWindow *dom_window = NULL;
779 nsres = nsIWebBrowser_QueryInterface(This->webbrowser,
780 &IID_nsIInterfaceRequestor, (void**)&iface_req);
781 if(NS_FAILED(nsres)) {
782 ERR("Could not get nsIInterfaceRequestor: %08x\n", nsres);
786 nsres = nsIInterfaceRequestor_GetInterface(iface_req, &IID_nsIEditingSession,
787 (void**)&editing_session);
788 nsIInterfaceRequestor_Release(iface_req);
789 if(NS_FAILED(nsres)) {
790 ERR("Could not get nsIEditingSession: %08x\n", nsres);
794 nsres = nsIWebBrowser_GetContentDOMWindow(This->webbrowser, &dom_window);
795 if(NS_FAILED(nsres)) {
796 ERR("Could not get content DOM window: %08x\n", nsres);
797 nsIEditingSession_Release(editing_session);
801 nsres = nsIEditingSession_MakeWindowEditable(editing_session, dom_window, NULL, FALSE);
802 nsIEditingSession_Release(editing_session);
803 nsIDOMWindow_Release(dom_window);
804 if(NS_FAILED(nsres)) {
805 ERR("MakeWindowEditable failed: %08x\n", nsres);
809 /* MakeWindowEditable changes WebBrowser's parent URI content listener.
810 * It seams to be a bug in Gecko. To workaround it we set our content
811 * listener again and Gecko's one as its parent.
813 nsIWebBrowser_GetParentURIContentListener(This->webbrowser, &listener);
814 nsIURIContentListener_SetParentContentListener(NSURICL(This), listener);
815 nsIURIContentListener_Release(listener);
816 nsIWebBrowser_SetParentURIContentListener(This->webbrowser, NSURICL(This));
819 static HRESULT exec_editmode(HTMLDocument *This)
824 static const WCHAR wszAboutBlank[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
826 TRACE("(%p)\n", This);
828 This->usermode = EDITMODE;
831 IOleInPlaceFrame_SetStatusText(This->frame, NULL);
834 DOCHOSTUIINFO hostinfo;
836 memset(&hostinfo, 0, sizeof(DOCHOSTUIINFO));
837 hostinfo.cbSize = sizeof(DOCHOSTUIINFO);
838 hres = IDocHostUIHandler_GetHostInfo(This->hostui, &hostinfo);
840 /* FIXME: use hostinfo */
841 TRACE("hostinfo = {%u %08x %08x %s %s}\n",
842 hostinfo.cbSize, hostinfo.dwFlags, hostinfo.dwDoubleClick,
843 debugstr_w(hostinfo.pchHostCss), debugstr_w(hostinfo.pchHostNS));
846 if(This->nscontainer)
847 setup_ns_editing(This->nscontainer);
849 hres = CreateURLMoniker(NULL, wszAboutBlank, &mon);
851 FIXME("CreateURLMoniker failed: %08x\n", hres);
855 return IPersistMoniker_Load(PERSISTMON(This), TRUE, mon, NULL, 0);
858 static HRESULT exec_baselinefont3(HTMLDocument *This)
860 FIXME("(%p)\n", This);
864 static HRESULT exec_horizontalline(HTMLDocument *This)
866 TRACE("(%p)\n", This);
868 if(This->nscontainer)
869 do_ns_command(This->nscontainer, NSCMD_INSERTHR, NULL);
874 static HRESULT exec_orderlist(HTMLDocument *This)
876 TRACE("(%p)\n", This);
878 if(This->nscontainer)
879 do_ns_command(This->nscontainer, NSCMD_OL, NULL);
884 static HRESULT exec_unorderlist(HTMLDocument *This)
886 TRACE("(%p)\n", This);
888 if(This->nscontainer)
889 do_ns_command(This->nscontainer, NSCMD_UL, NULL);
894 static HRESULT exec_indent(HTMLDocument *This)
896 TRACE("(%p)\n", This);
898 if(This->nscontainer)
899 do_ns_command(This->nscontainer, NSCMD_INDENT, NULL);
904 static HRESULT exec_outdent(HTMLDocument *This)
906 TRACE("(%p)\n", This);
908 if(This->nscontainer)
909 do_ns_command(This->nscontainer, NSCMD_OUTDENT, NULL);
914 static HRESULT exec_htmleditmode(HTMLDocument *This)
916 FIXME("(%p)\n", This);
920 static HRESULT exec_composesettings(HTMLDocument *This, VARIANT *in)
922 if(!in || V_VT(in) != VT_BSTR) {
923 WARN("invalid arg\n");
927 FIXME("%s\n", debugstr_w(V_BSTR(in)));
932 static const struct {
934 HRESULT (*func)(HTMLDocument*,DWORD,VARIANT*,VARIANT*);
935 } exec_table[OLECMDID_GETPRINTTEMPLATE+1] = {
937 { OLECMDF_SUPPORTED, exec_open }, /* OLECMDID_OPEN */
938 { OLECMDF_SUPPORTED, exec_new }, /* OLECMDID_NEW */
939 { OLECMDF_SUPPORTED, exec_save }, /* OLECMDID_SAVE */
940 { OLECMDF_SUPPORTED|OLECMDF_ENABLED, exec_save_as }, /* OLECMDID_SAVEAS */
941 { OLECMDF_SUPPORTED, exec_save_copy_as }, /* OLECMDID_SAVECOPYAS */
942 { OLECMDF_SUPPORTED|OLECMDF_ENABLED, exec_print }, /* OLECMDID_PRINT */
943 { OLECMDF_SUPPORTED|OLECMDF_ENABLED, exec_print_preview }, /* OLECMDID_PRINTPREVIEW */
944 { OLECMDF_SUPPORTED|OLECMDF_ENABLED, exec_page_setup }, /* OLECMDID_PAGESETUP */
945 { OLECMDF_SUPPORTED, exec_spell }, /* OLECMDID_SPELL */
946 { OLECMDF_SUPPORTED|OLECMDF_ENABLED, exec_properties }, /* OLECMDID_PROPERTIES */
947 { OLECMDF_SUPPORTED, exec_cut }, /* OLECMDID_CUT */
948 { OLECMDF_SUPPORTED, exec_copy }, /* OLECMDID_COPY */
949 { OLECMDF_SUPPORTED, exec_paste }, /* OLECMDID_PASTE */
950 { OLECMDF_SUPPORTED, exec_paste_special }, /* OLECMDID_PASTESPECIAL */
951 { OLECMDF_SUPPORTED, exec_undo }, /* OLECMDID_UNDO */
952 { OLECMDF_SUPPORTED, exec_rendo }, /* OLECMDID_REDO */
953 { OLECMDF_SUPPORTED|OLECMDF_ENABLED, exec_select_all }, /* OLECMDID_SELECTALL */
954 { OLECMDF_SUPPORTED, exec_clear_selection }, /* OLECMDID_CLEARSELECTION */
955 { OLECMDF_SUPPORTED, exec_zoom }, /* OLECMDID_ZOOM */
956 { OLECMDF_SUPPORTED, exec_get_zoom_range }, /* OLECMDID_GETZOOMRANGE */
958 { OLECMDF_SUPPORTED|OLECMDF_ENABLED, exec_refresh }, /* OLECMDID_REFRESH */
959 { OLECMDF_SUPPORTED|OLECMDF_ENABLED, exec_stop }, /* OLECMDID_STOP */
960 {0},{0},{0},{0},{0},{0},
961 { OLECMDF_SUPPORTED, exec_stop_download }, /* OLECMDID_STOPDOWNLOAD */
963 { OLECMDF_SUPPORTED, exec_delete }, /* OLECMDID_DELETE */
965 { OLECMDF_SUPPORTED, exec_enable_interaction }, /* OLECMDID_ENABLE_INTERACTION */
966 { OLECMDF_SUPPORTED, exec_on_unload }, /* OLECMDID_ONUNLOAD */
968 { OLECMDF_SUPPORTED, exec_show_page_setup }, /* OLECMDID_SHOWPAGESETUP */
969 { OLECMDF_SUPPORTED, exec_show_print }, /* OLECMDID_SHOWPRINT */
971 { OLECMDF_SUPPORTED, exec_close }, /* OLECMDID_CLOSE */
973 { OLECMDF_SUPPORTED, exec_set_print_template }, /* OLECMDID_SETPRINTTEMPLATE */
974 { OLECMDF_SUPPORTED, exec_get_print_template } /* OLECMDID_GETPRINTTEMPLATE */
977 static HRESULT WINAPI OleCommandTarget_QueryInterface(IOleCommandTarget *iface, REFIID riid, void **ppv)
979 HTMLDocument *This = CMDTARGET_THIS(iface);
980 return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppv);
983 static ULONG WINAPI OleCommandTarget_AddRef(IOleCommandTarget *iface)
985 HTMLDocument *This = CMDTARGET_THIS(iface);
986 return IHTMLDocument2_AddRef(HTMLDOC(This));
989 static ULONG WINAPI OleCommandTarget_Release(IOleCommandTarget *iface)
991 HTMLDocument *This = CMDTARGET_THIS(iface);
992 return IHTMLDocument_Release(HTMLDOC(This));
995 static HRESULT WINAPI OleCommandTarget_QueryStatus(IOleCommandTarget *iface, const GUID *pguidCmdGroup,
996 ULONG cCmds, OLECMD prgCmds[], OLECMDTEXT *pCmdText)
998 HTMLDocument *This = CMDTARGET_THIS(iface);
999 HRESULT hres = S_OK, hr;
1001 TRACE("(%p)->(%s %d %p %p)\n", This, debugstr_guid(pguidCmdGroup), cCmds, prgCmds, pCmdText);
1003 if(!pguidCmdGroup) {
1006 for(i=0; i<cCmds; i++) {
1007 if(prgCmds[i].cmdID<OLECMDID_OPEN || prgCmds[i].cmdID>OLECMDID_GETPRINTTEMPLATE) {
1008 WARN("Unsupported cmdID = %d\n", prgCmds[i].cmdID);
1009 prgCmds[i].cmdf = 0;
1010 hres = OLECMDERR_E_NOTSUPPORTED;
1012 if(prgCmds[i].cmdID == OLECMDID_OPEN || prgCmds[i].cmdID == OLECMDID_NEW) {
1013 IOleCommandTarget *cmdtrg = NULL;
1016 prgCmds[i].cmdf = OLECMDF_SUPPORTED;
1018 hr = IOleClientSite_QueryInterface(This->client, &IID_IOleCommandTarget,
1021 olecmd.cmdID = prgCmds[i].cmdID;
1024 hr = IOleCommandTarget_QueryStatus(cmdtrg, NULL, 1, &olecmd, NULL);
1025 if(SUCCEEDED(hr) && olecmd.cmdf)
1026 prgCmds[i].cmdf = olecmd.cmdf;
1029 ERR("This->client == NULL, native would crash\n");
1032 prgCmds[i].cmdf = exec_table[prgCmds[i].cmdID].cmdf;
1033 TRACE("cmdID = %d returning %x\n", prgCmds[i].cmdID, prgCmds[i].cmdf);
1040 FIXME("Set pCmdText\n");
1041 }else if(IsEqualGUID(&CGID_MSHTML, pguidCmdGroup)) {
1044 for(i=0; i<cCmds; i++) {
1045 switch(prgCmds[i].cmdID) {
1047 FIXME("CGID_MSHTML: IDM_COPY\n");
1048 prgCmds[i].cmdf = OLECMDF_SUPPORTED|OLECMDF_ENABLED;
1051 FIXME("CGID_MSHTML: IDM_CUT\n");
1052 prgCmds[i].cmdf = OLECMDF_SUPPORTED|OLECMDF_ENABLED;
1055 TRACE("CGID_MSHTML: IDM_FONTNAME\n");
1056 prgCmds[i].cmdf = query_edit_status(This, NULL);
1059 TRACE("CGID_MSHTML: IDM_FONTSIZE\n");
1060 prgCmds[i].cmdf = query_edit_status(This, NULL);
1063 FIXME("CGID_MSHTML: IDM_PRINT\n");
1064 prgCmds[i].cmdf = OLECMDF_SUPPORTED|OLECMDF_ENABLED;
1067 FIXME("CGID_MSHTML: IDM_PASTE\n");
1068 prgCmds[i].cmdf = OLECMDF_SUPPORTED|OLECMDF_ENABLED;
1071 TRACE("CGID_MSHTML: IDM_BOLD\n");
1072 prgCmds[i].cmdf = query_edit_status(This, NSCMD_BOLD);
1075 TRACE("CGID_MSHTML: IDM_FORECOLOR\n");
1076 prgCmds[i].cmdf = query_edit_status(This, NULL);
1079 TRACE("CGID_MSHTML: IDM_ITALIC\n");
1080 prgCmds[i].cmdf = query_edit_status(This, NSCMD_ITALIC);
1082 case IDM_JUSTIFYCENTER:
1083 TRACE("CGID_MSHTML: IDM_JUSTIFYCENTER\n");
1084 prgCmds[i].cmdf = query_align_status(This, NSALIGN_CENTER);
1086 case IDM_JUSTIFYLEFT:
1087 TRACE("CGID_MSHTML: IDM_JUSTIFYLEFT\n");
1088 prgCmds[i].cmdf = query_align_status(This, NSALIGN_LEFT);
1090 case IDM_JUSTIFYRIGHT:
1091 TRACE("CGID_MSHTML: IDM_JUSTIFYRIGHT\n");
1092 prgCmds[i].cmdf = query_align_status(This, NSALIGN_RIGHT);
1095 TRACE("CGID_MSHTML: IDM_UNDERLINE\n");
1096 prgCmds[i].cmdf = query_edit_status(This, NSCMD_UNDERLINE);
1098 case IDM_HORIZONTALLINE:
1099 TRACE("CGID_MSHTML: IDM_HORIZONTALLINE\n");
1100 prgCmds[i].cmdf = query_edit_status(This, NULL);
1103 TRACE("CGID_MSHTML: IDM_ORDERLIST\n");
1104 prgCmds[i].cmdf = query_edit_status(This, NSCMD_OL);
1106 case IDM_UNORDERLIST:
1107 TRACE("CGID_MSHTML: IDM_HORIZONTALLINE\n");
1108 prgCmds[i].cmdf = query_edit_status(This, NSCMD_UL);
1111 TRACE("CGID_MSHTML: IDM_INDENT\n");
1112 prgCmds[i].cmdf = query_edit_status(This, NULL);
1115 TRACE("CGID_MSHTML: IDM_OUTDENT\n");
1116 prgCmds[i].cmdf = query_edit_status(This, NULL);
1118 case IDM_BLOCKDIRLTR:
1119 FIXME("CGID_MSHTML: IDM_BLOCKDIRLTR\n");
1120 prgCmds[i].cmdf = OLECMDF_SUPPORTED|OLECMDF_ENABLED;
1122 case IDM_BLOCKDIRRTL:
1123 FIXME("CGID_MSHTML: IDM_BLOCKDIRRTL\n");
1124 prgCmds[i].cmdf = OLECMDF_SUPPORTED|OLECMDF_ENABLED;
1127 FIXME("CGID_MSHTML: unsupported cmdID %d\n", prgCmds[i].cmdID);
1128 prgCmds[i].cmdf = 0;
1132 hres = prgCmds[i-1].cmdf ? S_OK : OLECMDERR_E_NOTSUPPORTED;
1135 FIXME("Set pCmdText\n");
1137 FIXME("Unsupported pguidCmdGroup %s\n", debugstr_guid(pguidCmdGroup));
1138 hres = OLECMDERR_E_UNKNOWNGROUP;
1144 static HRESULT WINAPI OleCommandTarget_Exec(IOleCommandTarget *iface, const GUID *pguidCmdGroup,
1145 DWORD nCmdID, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
1147 HTMLDocument *This = CMDTARGET_THIS(iface);
1149 if(!pguidCmdGroup) {
1150 if(nCmdID<OLECMDID_OPEN || nCmdID>OLECMDID_GETPRINTTEMPLATE || !exec_table[nCmdID].func) {
1151 WARN("Unsupported cmdID = %d\n", nCmdID);
1152 return OLECMDERR_E_NOTSUPPORTED;
1155 return exec_table[nCmdID].func(This, nCmdexecopt, pvaIn, pvaOut);
1156 }else if(IsEqualGUID(&CGID_Explorer, pguidCmdGroup)) {
1157 FIXME("unsupported nCmdID %d of CGID_Explorer group\n", nCmdID);
1158 TRACE("%p %p\n", pvaIn, pvaOut);
1159 return OLECMDERR_E_NOTSUPPORTED;
1160 }else if(IsEqualGUID(&CGID_ShellDocView, pguidCmdGroup)) {
1161 FIXME("unsupported nCmdID %d of CGID_ShellDocView group\n", nCmdID);
1162 return OLECMDERR_E_NOTSUPPORTED;
1163 }else if(IsEqualGUID(&CGID_MSHTML, pguidCmdGroup)) {
1166 return exec_fontname(This, pvaIn, pvaOut);
1168 return exec_fontsize(This, pvaIn, pvaOut);
1170 return exec_print(This, nCmdexecopt, pvaIn, pvaOut);
1173 FIXME("unsupported arguments\n");
1174 return exec_bold(This);
1176 return exec_forecolor(This, pvaIn, pvaOut);
1179 FIXME("unsupported arguments\n");
1180 return exec_italic(This);
1181 case IDM_JUSTIFYCENTER:
1183 FIXME("unsupported arguments\n");
1184 return exec_justifycenter(This);
1185 case IDM_JUSTIFYLEFT:
1187 FIXME("unsupported arguments\n");
1188 return exec_justifyleft(This);
1189 case IDM_JUSTIFYRIGHT:
1191 FIXME("unsupported arguments\n");
1192 return exec_justifyright(This);
1195 FIXME("unsupported arguments\n");
1196 return exec_underline(This);
1197 case IDM_BROWSEMODE:
1199 FIXME("unsupported arguments\n");
1200 return exec_browsemode(This);
1203 FIXME("unsupported arguments\n");
1204 return exec_editmode(This);
1205 case IDM_BASELINEFONT3:
1206 return exec_baselinefont3(This);
1207 case IDM_HORIZONTALLINE:
1209 FIXME("unsupported arguments\n");
1210 return exec_horizontalline(This);
1213 FIXME("unsupported arguments\n");
1214 return exec_orderlist(This);
1215 case IDM_UNORDERLIST:
1217 FIXME("unsupported arguments\n");
1218 return exec_unorderlist(This);
1221 FIXME("unsupported arguments\n");
1222 return exec_indent(This);
1225 FIXME("unsupported arguments\n");
1226 return exec_outdent(This);
1227 case IDM_HTMLEDITMODE:
1229 FIXME("unsupported arguments\n");
1230 return exec_htmleditmode(This);
1231 case IDM_COMPOSESETTINGS:
1233 FIXME("unsupported arguments\n");
1234 return exec_composesettings(This, pvaIn);
1236 FIXME("unsupported nCmdID %d of CGID_MSHTML group\n", nCmdID);
1237 return OLECMDERR_E_NOTSUPPORTED;
1241 FIXME("Unsupported pguidCmdGroup %s\n", debugstr_guid(pguidCmdGroup));
1242 return OLECMDERR_E_UNKNOWNGROUP;
1245 #undef CMDTARGET_THIS
1247 static const IOleCommandTargetVtbl OleCommandTargetVtbl = {
1248 OleCommandTarget_QueryInterface,
1249 OleCommandTarget_AddRef,
1250 OleCommandTarget_Release,
1251 OleCommandTarget_QueryStatus,
1252 OleCommandTarget_Exec
1255 void HTMLDocument_OleCmd_Init(HTMLDocument *This)
1257 This->lpOleCommandTargetVtbl = &OleCommandTargetVtbl;