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_BOLD "cmd_bold"
45 #define NSCMD_ITALIC "cmd_italic"
46 #define NSCMD_UNDERLINE "cmd_underline"
47 #define NSCMD_ALIGN "cmd_align"
48 #define NSCMD_INDENT "cmd_indent"
49 #define NSCMD_OUTDENT "cmd_outdent"
50 #define NSCMD_INSERTHR "cmd_insertHR"
51 #define NSCMD_UL "cmd_ul"
52 #define NSCMD_OL "cmd_ol"
54 #define NSSTATE_ATTRIBUTE "state_attribute"
56 #define NSALIGN_CENTER "center"
57 #define NSALIGN_LEFT "left"
58 #define NSALIGN_RIGHT "right"
60 /**********************************************************
61 * IOleCommandTarget implementation
64 #define CMDTARGET_THIS(iface) DEFINE_THIS(HTMLDocument, OleCommandTarget, iface)
66 static HRESULT
exec_open(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
68 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
72 static HRESULT
exec_new(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
74 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
78 static HRESULT
exec_save(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
80 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
84 static HRESULT
exec_save_as(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
86 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
90 static HRESULT
exec_save_copy_as(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
92 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
96 static nsresult
set_head_text(nsIPrintSettings
*settings
, LPCWSTR
template, BOOL head
, int pos
)
101 return nsIPrintSettings_SetHeaderStrLeft(settings
, template);
103 return nsIPrintSettings_SetHeaderStrRight(settings
, template);
105 return nsIPrintSettings_SetHeaderStrCenter(settings
, template);
110 return nsIPrintSettings_SetFooterStrLeft(settings
, template);
112 return nsIPrintSettings_SetFooterStrRight(settings
, template);
114 return nsIPrintSettings_SetFooterStrCenter(settings
, template);
121 static void set_print_template(nsIPrintSettings
*settings
, LPCWSTR
template, BOOL head
)
123 PRUnichar nstemplate
[200]; /* FIXME: Use dynamic allocation */
124 PRUnichar
*p
= nstemplate
;
125 LPCWSTR ptr
=template;
140 case 'b': /* change align */
143 set_head_text(settings
, nstemplate
, head
, pos
);
147 case 'd': { /* short date */
149 GetLocalTime(&systime
);
150 GetDateFormatW(LOCALE_SYSTEM_DEFAULT
, 0, &systime
, NULL
, p
,
151 sizeof(nstemplate
)-(p
-nstemplate
)*sizeof(WCHAR
));
156 case 'p': /* page number */
161 case 'P': /* page count */
162 *p
++ = '?'; /* FIXME */
171 /* FIXME: set window title */
181 set_head_text(settings
, nstemplate
, head
, pos
);
184 set_head_text(settings
, p
, head
, pos
);
187 static void set_default_templates(nsIPrintSettings
*settings
)
191 static const PRUnichar empty
[] = {0};
193 nsIPrintSettings_SetHeaderStrLeft(settings
, empty
);
194 nsIPrintSettings_SetHeaderStrRight(settings
, empty
);
195 nsIPrintSettings_SetHeaderStrCenter(settings
, empty
);
196 nsIPrintSettings_SetFooterStrLeft(settings
, empty
);
197 nsIPrintSettings_SetFooterStrRight(settings
, empty
);
198 nsIPrintSettings_SetFooterStrCenter(settings
, empty
);
200 if(LoadStringW(get_shdoclc(), IDS_PRINT_HEADER_TEMPLATE
, buf
,
201 sizeof(buf
)/sizeof(WCHAR
)))
202 set_print_template(settings
, buf
, TRUE
);
205 if(LoadStringW(get_shdoclc(), IDS_PRINT_FOOTER_TEMPLATE
, buf
,
206 sizeof(buf
)/sizeof(WCHAR
)))
207 set_print_template(settings
, buf
, FALSE
);
211 static HRESULT
exec_print(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
213 nsIInterfaceRequestor
*iface_req
;
214 nsIWebBrowserPrint
*nsprint
;
215 nsIPrintSettings
*settings
;
218 TRACE("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
221 FIXME("unsupported pvaOut\n");
223 if(!This
->nscontainer
)
226 nsres
= nsIWebBrowser_QueryInterface(This
->nscontainer
->webbrowser
,
227 &IID_nsIInterfaceRequestor
, (void**)&iface_req
);
228 if(NS_FAILED(nsres
)) {
229 ERR("Could not get nsIInterfaceRequestor: %08x\n", nsres
);
233 nsres
= nsIInterfaceRequestor_GetInterface(iface_req
, &IID_nsIWebBrowserPrint
,
235 nsIInterfaceRequestor_Release(iface_req
);
236 if(NS_FAILED(nsres
)) {
237 ERR("Could not get nsIWebBrowserPrint: %08x\n", nsres
);
241 nsres
= nsIWebBrowserPrint_GetGlobalPrintSettings(nsprint
, &settings
);
243 ERR("GetCurrentPrintSettings failed: %08x\n", nsres
);
245 set_default_templates(settings
);
248 switch(V_VT(pvaIn
)) {
249 case VT_BYREF
|VT_ARRAY
: {
253 if(V_ARRAY(pvaIn
)->cDims
!= 1)
254 WARN("cDims = %d\n", V_ARRAY(pvaIn
)->cDims
);
256 SafeArrayAccessData(V_ARRAY(pvaIn
), (void**)&opts
);
257 opts_cnt
= V_ARRAY(pvaIn
)->rgsabound
[0].cElements
;
262 TRACE("setting footer %s\n", debugstr_w(V_BSTR(opts
)));
263 set_print_template(settings
, V_BSTR(opts
), TRUE
);
268 WARN("V_VT(opts) = %d\n", V_VT(opts
));
273 switch(V_VT(opts
+1)) {
275 TRACE("setting footer %s\n", debugstr_w(V_BSTR(opts
+1)));
276 set_print_template(settings
, V_BSTR(opts
+1), FALSE
);
281 WARN("V_VT(opts) = %d\n", V_VT(opts
+1));
286 FIXME("Unsupported opts_cnt %d\n", opts_cnt
);
288 SafeArrayUnaccessData(V_ARRAY(pvaIn
));
292 FIXME("unsupported vt %x\n", V_VT(pvaIn
));
296 nsres
= nsIWebBrowserPrint_Print(nsprint
, settings
, NULL
);
298 ERR("Print failed: %08x\n", nsres
);
300 nsIWebBrowserPrint_Release(nsprint
);
305 static HRESULT
exec_print_preview(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
307 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
311 static HRESULT
exec_page_setup(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
313 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
317 static HRESULT
exec_spell(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
319 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
323 static HRESULT
exec_properties(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
325 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
329 static HRESULT
exec_cut(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
331 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
335 static HRESULT
exec_copy(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
337 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
341 static HRESULT
exec_paste(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
343 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
347 static HRESULT
exec_paste_special(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
349 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
353 static HRESULT
exec_undo(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
355 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
359 static HRESULT
exec_rendo(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
361 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
365 static HRESULT
exec_select_all(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
367 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
371 static HRESULT
exec_clear_selection(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
373 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
377 static HRESULT
exec_zoom(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
379 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
383 static HRESULT
exec_get_zoom_range(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
385 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
389 static HRESULT
exec_refresh(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
391 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
395 static HRESULT
exec_stop(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
397 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
401 static HRESULT
exec_stop_download(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
403 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
407 static HRESULT
exec_delete(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
409 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
413 static HRESULT
exec_enable_interaction(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
415 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
419 static HRESULT
exec_on_unload(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
421 TRACE("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
423 /* Tests show that we have nothing more to do here */
426 V_VT(pvaOut
) = VT_BOOL
;
427 V_BOOL(pvaOut
) = VARIANT_TRUE
;
433 static HRESULT
exec_show_page_setup(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
435 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
439 static HRESULT
exec_show_print(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
441 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
445 static HRESULT
exec_close(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
447 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
451 static HRESULT
exec_set_print_template(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
453 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
457 static HRESULT
exec_get_print_template(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
459 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
463 static HRESULT
query_mshtml_copy(HTMLDocument
*This
, OLECMD
*cmd
)
465 FIXME("(%p)\n", This
);
466 cmd
->cmdf
= OLECMDF_SUPPORTED
|OLECMDF_ENABLED
;
470 static HRESULT
exec_mshtml_copy(HTMLDocument
*This
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
472 TRACE("(%p)->(%08x %p %p)\n", This
, cmdexecopt
, in
, out
);
474 if(This
->usermode
== EDITMODE
)
475 return editor_exec_copy(This
, cmdexecopt
, in
, out
);
477 FIXME("Unimplemented in browse mode\n");
481 static HRESULT
query_mshtml_cut(HTMLDocument
*This
, OLECMD
*cmd
)
483 FIXME("(%p)\n", This
);
484 cmd
->cmdf
= OLECMDF_SUPPORTED
|OLECMDF_ENABLED
;
488 static HRESULT
exec_mshtml_cut(HTMLDocument
*This
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
490 TRACE("(%p)->(%08x %p %p)\n", This
, cmdexecopt
, in
, out
);
492 if(This
->usermode
== EDITMODE
)
493 return editor_exec_cut(This
, cmdexecopt
, in
, out
);
495 FIXME("Unimplemented in browse mode\n");
499 static HRESULT
query_mshtml_paste(HTMLDocument
*This
, OLECMD
*cmd
)
501 FIXME("(%p)\n", This
);
502 cmd
->cmdf
= OLECMDF_SUPPORTED
|OLECMDF_ENABLED
;
506 static HRESULT
exec_mshtml_paste(HTMLDocument
*This
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
508 TRACE("(%p)->(%08x %p %p)\n", This
, cmdexecopt
, in
, out
);
510 if(This
->usermode
== EDITMODE
)
511 return editor_exec_paste(This
, cmdexecopt
, in
, out
);
513 FIXME("Unimplemented in browse mode\n");
517 static HRESULT
exec_browsemode(HTMLDocument
*This
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
519 WARN("(%p)->(%08x %p %p)\n", This
, cmdexecopt
, in
, out
);
522 FIXME("unsupported args\n");
524 This
->usermode
= BROWSEMODE
;
529 static HRESULT
exec_editmode(HTMLDocument
*This
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
534 static const WCHAR wszAboutBlank
[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
536 TRACE("(%p)->(%08x %p %p)\n", This
, cmdexecopt
, in
, out
);
539 FIXME("unsupported args\n");
541 if(This
->usermode
== EDITMODE
)
544 This
->usermode
= EDITMODE
;
547 IOleInPlaceFrame_SetStatusText(This
->frame
, NULL
);
550 IOleCommandTarget
*cmdtrg
;
552 hres
= IOleClientSite_QueryInterface(This
->client
, &IID_IOleCommandTarget
,
554 if(SUCCEEDED(hres
)) {
559 IOleCommandTarget_Exec(cmdtrg
, &CGID_ShellDocView
, 37, 0, &var
, NULL
);
561 IOleCommandTarget_Release(cmdtrg
);
566 DOCHOSTUIINFO hostinfo
;
568 memset(&hostinfo
, 0, sizeof(DOCHOSTUIINFO
));
569 hostinfo
.cbSize
= sizeof(DOCHOSTUIINFO
);
570 hres
= IDocHostUIHandler_GetHostInfo(This
->hostui
, &hostinfo
);
572 /* FIXME: use hostinfo */
573 TRACE("hostinfo = {%u %08x %08x %s %s}\n",
574 hostinfo
.cbSize
, hostinfo
.dwFlags
, hostinfo
.dwDoubleClick
,
575 debugstr_w(hostinfo
.pchHostCss
), debugstr_w(hostinfo
.pchHostNS
));
578 if(This
->nscontainer
)
579 set_ns_editmode(This
->nscontainer
);
581 hres
= CreateURLMoniker(NULL
, wszAboutBlank
, &mon
);
583 FIXME("CreateURLMoniker failed: %08x\n", hres
);
587 update_doc(This
, UPDATE_UI
);
589 return IPersistMoniker_Load(PERSISTMON(This
), TRUE
, mon
, NULL
, 0);
592 static HRESULT
exec_htmleditmode(HTMLDocument
*This
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
594 FIXME("(%p)->(%08x %p %p)\n", This
, cmdexecopt
, in
, out
);
598 static HRESULT
exec_setdirty(HTMLDocument
*This
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
600 FIXME("(%p)->(%08x %p %p)\n", This
, cmdexecopt
, in
, out
);
604 static HRESULT
exec_baselinefont3(HTMLDocument
*This
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
606 FIXME("(%p)->(%08x %p %p)\n", This
, cmdexecopt
, in
, out
);
610 static HRESULT
exec_respectvisibility_indesign(HTMLDocument
*This
, DWORD cmdexecopt
,
611 VARIANT
*in
, VARIANT
*out
)
613 FIXME("(%p)->(%08x %p %p)\n", This
, cmdexecopt
, in
, out
);
617 static HRESULT
query_enabled_stub(HTMLDocument
*This
, OLECMD
*cmd
)
621 FIXME("CGID_MSHTML: IDM_PRINT\n");
622 cmd
->cmdf
= OLECMDF_SUPPORTED
|OLECMDF_ENABLED
;
624 case IDM_BLOCKDIRLTR
:
625 FIXME("CGID_MSHTML: IDM_BLOCKDIRLTR\n");
626 cmd
->cmdf
= OLECMDF_SUPPORTED
|OLECMDF_ENABLED
;
628 case IDM_BLOCKDIRRTL
:
629 FIXME("CGID_MSHTML: IDM_BLOCKDIRRTL\n");
630 cmd
->cmdf
= OLECMDF_SUPPORTED
|OLECMDF_ENABLED
;
637 static const struct {
639 HRESULT (*func
)(HTMLDocument
*,DWORD
,VARIANT
*,VARIANT
*);
640 } exec_table
[OLECMDID_GETPRINTTEMPLATE
+1] = {
642 { OLECMDF_SUPPORTED
, exec_open
}, /* OLECMDID_OPEN */
643 { OLECMDF_SUPPORTED
, exec_new
}, /* OLECMDID_NEW */
644 { OLECMDF_SUPPORTED
, exec_save
}, /* OLECMDID_SAVE */
645 { OLECMDF_SUPPORTED
|OLECMDF_ENABLED
, exec_save_as
}, /* OLECMDID_SAVEAS */
646 { OLECMDF_SUPPORTED
, exec_save_copy_as
}, /* OLECMDID_SAVECOPYAS */
647 { OLECMDF_SUPPORTED
|OLECMDF_ENABLED
, exec_print
}, /* OLECMDID_PRINT */
648 { OLECMDF_SUPPORTED
|OLECMDF_ENABLED
, exec_print_preview
}, /* OLECMDID_PRINTPREVIEW */
649 { OLECMDF_SUPPORTED
|OLECMDF_ENABLED
, exec_page_setup
}, /* OLECMDID_PAGESETUP */
650 { OLECMDF_SUPPORTED
, exec_spell
}, /* OLECMDID_SPELL */
651 { OLECMDF_SUPPORTED
|OLECMDF_ENABLED
, exec_properties
}, /* OLECMDID_PROPERTIES */
652 { OLECMDF_SUPPORTED
, exec_cut
}, /* OLECMDID_CUT */
653 { OLECMDF_SUPPORTED
, exec_copy
}, /* OLECMDID_COPY */
654 { OLECMDF_SUPPORTED
, exec_paste
}, /* OLECMDID_PASTE */
655 { OLECMDF_SUPPORTED
, exec_paste_special
}, /* OLECMDID_PASTESPECIAL */
656 { OLECMDF_SUPPORTED
, exec_undo
}, /* OLECMDID_UNDO */
657 { OLECMDF_SUPPORTED
, exec_rendo
}, /* OLECMDID_REDO */
658 { OLECMDF_SUPPORTED
|OLECMDF_ENABLED
, exec_select_all
}, /* OLECMDID_SELECTALL */
659 { OLECMDF_SUPPORTED
, exec_clear_selection
}, /* OLECMDID_CLEARSELECTION */
660 { OLECMDF_SUPPORTED
, exec_zoom
}, /* OLECMDID_ZOOM */
661 { OLECMDF_SUPPORTED
, exec_get_zoom_range
}, /* OLECMDID_GETZOOMRANGE */
663 { OLECMDF_SUPPORTED
|OLECMDF_ENABLED
, exec_refresh
}, /* OLECMDID_REFRESH */
664 { OLECMDF_SUPPORTED
|OLECMDF_ENABLED
, exec_stop
}, /* OLECMDID_STOP */
665 {0},{0},{0},{0},{0},{0},
666 { OLECMDF_SUPPORTED
, exec_stop_download
}, /* OLECMDID_STOPDOWNLOAD */
668 { OLECMDF_SUPPORTED
, exec_delete
}, /* OLECMDID_DELETE */
670 { OLECMDF_SUPPORTED
, exec_enable_interaction
}, /* OLECMDID_ENABLE_INTERACTION */
671 { OLECMDF_SUPPORTED
, exec_on_unload
}, /* OLECMDID_ONUNLOAD */
673 { OLECMDF_SUPPORTED
, exec_show_page_setup
}, /* OLECMDID_SHOWPAGESETUP */
674 { OLECMDF_SUPPORTED
, exec_show_print
}, /* OLECMDID_SHOWPRINT */
676 { OLECMDF_SUPPORTED
, exec_close
}, /* OLECMDID_CLOSE */
678 { OLECMDF_SUPPORTED
, exec_set_print_template
}, /* OLECMDID_SETPRINTTEMPLATE */
679 { OLECMDF_SUPPORTED
, exec_get_print_template
} /* OLECMDID_GETPRINTTEMPLATE */
682 static const cmdtable_t base_cmds
[] = {
683 {IDM_COPY
, query_mshtml_copy
, exec_mshtml_copy
},
684 {IDM_PASTE
, query_mshtml_paste
, exec_mshtml_paste
},
685 {IDM_CUT
, query_mshtml_cut
, exec_mshtml_cut
},
686 {IDM_BROWSEMODE
, NULL
, exec_browsemode
},
687 {IDM_EDITMODE
, NULL
, exec_editmode
},
688 {IDM_PRINT
, query_enabled_stub
, exec_print
},
689 {IDM_SETDIRTY
, NULL
, exec_setdirty
},
690 {IDM_HTMLEDITMODE
, NULL
, exec_htmleditmode
},
691 {IDM_BASELINEFONT3
, NULL
, exec_baselinefont3
},
692 {IDM_BLOCKDIRLTR
, query_enabled_stub
, NULL
},
693 {IDM_BLOCKDIRRTL
, query_enabled_stub
, NULL
},
694 {IDM_RESPECTVISIBILITY_INDESIGN
, NULL
, exec_respectvisibility_indesign
},
698 static HRESULT WINAPI
OleCommandTarget_QueryInterface(IOleCommandTarget
*iface
, REFIID riid
, void **ppv
)
700 HTMLDocument
*This
= CMDTARGET_THIS(iface
);
701 return IHTMLDocument2_QueryInterface(HTMLDOC(This
), riid
, ppv
);
704 static ULONG WINAPI
OleCommandTarget_AddRef(IOleCommandTarget
*iface
)
706 HTMLDocument
*This
= CMDTARGET_THIS(iface
);
707 return IHTMLDocument2_AddRef(HTMLDOC(This
));
710 static ULONG WINAPI
OleCommandTarget_Release(IOleCommandTarget
*iface
)
712 HTMLDocument
*This
= CMDTARGET_THIS(iface
);
713 return IHTMLDocument_Release(HTMLDOC(This
));
716 static HRESULT
query_from_table(HTMLDocument
*This
, const cmdtable_t
*cmdtable
, OLECMD
*cmd
)
718 const cmdtable_t
*iter
= cmdtable
;
722 while(iter
->id
&& iter
->id
!= cmd
->cmdID
)
725 if(!iter
->id
|| !iter
->query
)
726 return OLECMDERR_E_NOTSUPPORTED
;
728 return iter
->query(This
, cmd
);
731 static HRESULT WINAPI
OleCommandTarget_QueryStatus(IOleCommandTarget
*iface
, const GUID
*pguidCmdGroup
,
732 ULONG cCmds
, OLECMD prgCmds
[], OLECMDTEXT
*pCmdText
)
734 HTMLDocument
*This
= CMDTARGET_THIS(iface
);
735 HRESULT hres
= S_OK
, hr
;
737 TRACE("(%p)->(%s %d %p %p)\n", This
, debugstr_guid(pguidCmdGroup
), cCmds
, prgCmds
, pCmdText
);
742 for(i
=0; i
<cCmds
; i
++) {
743 if(prgCmds
[i
].cmdID
<OLECMDID_OPEN
|| prgCmds
[i
].cmdID
>OLECMDID_GETPRINTTEMPLATE
) {
744 WARN("Unsupported cmdID = %d\n", prgCmds
[i
].cmdID
);
746 hres
= OLECMDERR_E_NOTSUPPORTED
;
748 if(prgCmds
[i
].cmdID
== OLECMDID_OPEN
|| prgCmds
[i
].cmdID
== OLECMDID_NEW
) {
749 IOleCommandTarget
*cmdtrg
= NULL
;
752 prgCmds
[i
].cmdf
= OLECMDF_SUPPORTED
;
754 hr
= IOleClientSite_QueryInterface(This
->client
, &IID_IOleCommandTarget
,
757 olecmd
.cmdID
= prgCmds
[i
].cmdID
;
760 hr
= IOleCommandTarget_QueryStatus(cmdtrg
, NULL
, 1, &olecmd
, NULL
);
761 if(SUCCEEDED(hr
) && olecmd
.cmdf
)
762 prgCmds
[i
].cmdf
= olecmd
.cmdf
;
765 ERR("This->client == NULL, native would crash\n");
768 prgCmds
[i
].cmdf
= exec_table
[prgCmds
[i
].cmdID
].cmdf
;
769 TRACE("cmdID = %d returning %x\n", prgCmds
[i
].cmdID
, prgCmds
[i
].cmdf
);
776 FIXME("Set pCmdText\n");
777 }else if(IsEqualGUID(&CGID_MSHTML
, pguidCmdGroup
)) {
780 for(i
=0; i
<cCmds
; i
++) {
781 HRESULT hres
= query_from_table(This
, base_cmds
, prgCmds
+i
);
782 if(hres
== OLECMDERR_E_NOTSUPPORTED
)
783 hres
= query_from_table(This
, editmode_cmds
, prgCmds
+i
);
784 if(hres
== OLECMDERR_E_NOTSUPPORTED
)
785 FIXME("CGID_MSHTML: unsupported cmdID %d\n", prgCmds
[i
].cmdID
);
788 hres
= prgCmds
[i
-1].cmdf
? S_OK
: OLECMDERR_E_NOTSUPPORTED
;
791 FIXME("Set pCmdText\n");
793 FIXME("Unsupported pguidCmdGroup %s\n", debugstr_guid(pguidCmdGroup
));
794 hres
= OLECMDERR_E_UNKNOWNGROUP
;
800 static HRESULT
exec_from_table(HTMLDocument
*This
, const cmdtable_t
*cmdtable
, DWORD cmdid
,
801 DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
803 const cmdtable_t
*iter
= cmdtable
;
805 while(iter
->id
&& iter
->id
!= cmdid
)
808 if(!iter
->id
|| !iter
->exec
)
809 return OLECMDERR_E_NOTSUPPORTED
;
811 return iter
->exec(This
, cmdexecopt
, in
, out
);
814 static HRESULT WINAPI
OleCommandTarget_Exec(IOleCommandTarget
*iface
, const GUID
*pguidCmdGroup
,
815 DWORD nCmdID
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
817 HTMLDocument
*This
= CMDTARGET_THIS(iface
);
820 if(nCmdID
<OLECMDID_OPEN
|| nCmdID
>OLECMDID_GETPRINTTEMPLATE
|| !exec_table
[nCmdID
].func
) {
821 WARN("Unsupported cmdID = %d\n", nCmdID
);
822 return OLECMDERR_E_NOTSUPPORTED
;
825 return exec_table
[nCmdID
].func(This
, nCmdexecopt
, pvaIn
, pvaOut
);
826 }else if(IsEqualGUID(&CGID_Explorer
, pguidCmdGroup
)) {
827 FIXME("unsupported nCmdID %d of CGID_Explorer group\n", nCmdID
);
828 TRACE("%p %p\n", pvaIn
, pvaOut
);
829 return OLECMDERR_E_NOTSUPPORTED
;
830 }else if(IsEqualGUID(&CGID_ShellDocView
, pguidCmdGroup
)) {
831 FIXME("unsupported nCmdID %d of CGID_ShellDocView group\n", nCmdID
);
832 return OLECMDERR_E_NOTSUPPORTED
;
833 }else if(IsEqualGUID(&CGID_MSHTML
, pguidCmdGroup
)) {
834 HRESULT hres
= exec_from_table(This
, base_cmds
, nCmdID
, nCmdexecopt
, pvaIn
, pvaOut
);
835 if(hres
== OLECMDERR_E_NOTSUPPORTED
)
836 hres
= exec_from_table(This
, editmode_cmds
, nCmdID
,
837 nCmdexecopt
, pvaIn
, pvaOut
);
838 if(hres
== OLECMDERR_E_NOTSUPPORTED
)
839 FIXME("unsupported nCmdID %d of CGID_MSHTML group\n", nCmdID
);
844 FIXME("Unsupported pguidCmdGroup %s\n", debugstr_guid(pguidCmdGroup
));
845 return OLECMDERR_E_UNKNOWNGROUP
;
848 #undef CMDTARGET_THIS
850 static const IOleCommandTargetVtbl OleCommandTargetVtbl
= {
851 OleCommandTarget_QueryInterface
,
852 OleCommandTarget_AddRef
,
853 OleCommandTarget_Release
,
854 OleCommandTarget_QueryStatus
,
855 OleCommandTarget_Exec
858 void show_context_menu(HTMLDocument
*This
, DWORD dwID
, POINT
*ppt
)
860 HMENU menu_res
, menu
;
864 hres
= IDocHostUIHandler_ShowContextMenu(This
->hostui
, dwID
, ppt
,
865 (IUnknown
*)CMDTARGET(This
), (IDispatch
*)HTMLDOC(This
));
869 menu_res
= LoadMenuW(get_shdoclc(), MAKEINTRESOURCEW(IDR_BROWSE_CONTEXT_MENU
));
870 menu
= GetSubMenu(menu_res
, dwID
);
872 cmdid
= TrackPopupMenu(menu
, TPM_LEFTALIGN
| TPM_RIGHTBUTTON
| TPM_RETURNCMD
,
873 ppt
->x
, ppt
->y
, 0, This
->hwnd
, NULL
);
874 DestroyMenu(menu_res
);
876 IOleCommandTarget_Exec(CMDTARGET(This
), &CGID_MSHTML
, cmdid
, 0, NULL
, NULL
);
879 void HTMLDocument_OleCmd_Init(HTMLDocument
*This
)
881 This
->lpOleCommandTargetVtbl
= &OleCommandTargetVtbl
;