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"
34 #include "mshtml_private.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(mshtml
);
40 #define NSCMD_COPY "cmd_copy"
41 #define NSCMD_SELECTALL "cmd_selectAll"
43 void do_ns_command(HTMLDocument
*This
, const char *cmd
, nsICommandParams
*nsparam
)
45 nsICommandManager
*cmdmgr
;
48 TRACE("(%p)\n", This
);
50 if(!This
->doc_obj
|| !This
->doc_obj
->nscontainer
)
53 nsres
= get_nsinterface((nsISupports
*)This
->doc_obj
->nscontainer
->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
, This
->window
->window_proxy
);
61 ERR("DoCommand(%s) failed: %08x\n", debugstr_a(cmd
), nsres
);
63 nsICommandManager_Release(cmdmgr
);
66 static nsIClipboardCommands
*get_clipboard_commands(HTMLDocument
*doc
)
68 nsIClipboardCommands
*clipboard_commands
;
69 nsIDocShell
*doc_shell
;
72 nsres
= get_nsinterface((nsISupports
*)doc
->window
->nswindow
, &IID_nsIDocShell
, (void**)&doc_shell
);
73 if(NS_FAILED(nsres
)) {
74 ERR("Could not get nsIDocShell interface\n");
78 nsres
= nsIDocShell_QueryInterface(doc_shell
, &IID_nsIClipboardCommands
, (void**)&clipboard_commands
);
79 nsIDocShell_Release(doc_shell
);
80 if(NS_FAILED(nsres
)) {
81 ERR("Could not get nsIClipboardCommands interface\n");
85 return clipboard_commands
;
88 /**********************************************************
89 * IOleCommandTarget implementation
92 static inline HTMLDocument
*impl_from_IOleCommandTarget(IOleCommandTarget
*iface
)
94 return CONTAINING_RECORD(iface
, HTMLDocument
, IOleCommandTarget_iface
);
97 static HRESULT
exec_open(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
99 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
103 static HRESULT
exec_new(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
105 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
109 static HRESULT
exec_save(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
111 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
115 static HRESULT
exec_save_as(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
117 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
121 static HRESULT
exec_save_copy_as(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
123 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
127 static nsresult
set_head_text(nsIPrintSettings
*settings
, LPCWSTR
template, BOOL head
, int pos
)
132 return nsIPrintSettings_SetHeaderStrLeft(settings
, template);
134 return nsIPrintSettings_SetHeaderStrRight(settings
, template);
136 return nsIPrintSettings_SetHeaderStrCenter(settings
, template);
141 return nsIPrintSettings_SetFooterStrLeft(settings
, template);
143 return nsIPrintSettings_SetFooterStrRight(settings
, template);
145 return nsIPrintSettings_SetFooterStrCenter(settings
, template);
152 static void set_print_template(nsIPrintSettings
*settings
, LPCWSTR
template, BOOL head
)
154 PRUnichar nstemplate
[200]; /* FIXME: Use dynamic allocation */
155 PRUnichar
*p
= nstemplate
;
156 LPCWSTR ptr
=template;
171 case 'b': /* change align */
174 set_head_text(settings
, nstemplate
, head
, pos
);
178 case 'd': { /* short date */
180 GetLocalTime(&systime
);
181 GetDateFormatW(LOCALE_SYSTEM_DEFAULT
, 0, &systime
, NULL
, p
,
182 sizeof(nstemplate
)-(p
-nstemplate
)*sizeof(WCHAR
));
187 case 'p': /* page number */
192 case 'P': /* page count */
193 *p
++ = '?'; /* FIXME */
202 /* FIXME: set window title */
212 set_head_text(settings
, nstemplate
, head
, pos
);
215 set_head_text(settings
, p
, head
, pos
);
218 static void set_default_templates(nsIPrintSettings
*settings
)
222 static const PRUnichar empty
[] = {0};
224 nsIPrintSettings_SetHeaderStrLeft(settings
, empty
);
225 nsIPrintSettings_SetHeaderStrRight(settings
, empty
);
226 nsIPrintSettings_SetHeaderStrCenter(settings
, empty
);
227 nsIPrintSettings_SetFooterStrLeft(settings
, empty
);
228 nsIPrintSettings_SetFooterStrRight(settings
, empty
);
229 nsIPrintSettings_SetFooterStrCenter(settings
, empty
);
231 if(LoadStringW(get_shdoclc(), IDS_PRINT_HEADER_TEMPLATE
, buf
,
232 sizeof(buf
)/sizeof(WCHAR
)))
233 set_print_template(settings
, buf
, TRUE
);
236 if(LoadStringW(get_shdoclc(), IDS_PRINT_FOOTER_TEMPLATE
, buf
,
237 sizeof(buf
)/sizeof(WCHAR
)))
238 set_print_template(settings
, buf
, FALSE
);
242 static HRESULT
exec_print(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
244 nsIWebBrowserPrint
*nsprint
;
245 nsIPrintSettings
*settings
;
248 TRACE("(%p)->(%d %s %p)\n", This
, nCmdexecopt
, debugstr_variant(pvaIn
), pvaOut
);
251 FIXME("unsupported pvaOut\n");
253 if(!This
->doc_obj
->nscontainer
)
256 nsres
= get_nsinterface((nsISupports
*)This
->doc_obj
->nscontainer
->webbrowser
, &IID_nsIWebBrowserPrint
,
258 if(NS_FAILED(nsres
)) {
259 ERR("Could not get nsIWebBrowserPrint: %08x\n", nsres
);
263 nsres
= nsIWebBrowserPrint_GetGlobalPrintSettings(nsprint
, &settings
);
265 ERR("GetCurrentPrintSettings failed: %08x\n", nsres
);
267 set_default_templates(settings
);
270 switch(V_VT(pvaIn
)) {
271 case VT_BYREF
|VT_ARRAY
: {
275 if(V_ARRAY(pvaIn
)->cDims
!= 1)
276 WARN("cDims = %d\n", V_ARRAY(pvaIn
)->cDims
);
278 SafeArrayAccessData(V_ARRAY(pvaIn
), (void**)&opts
);
279 opts_cnt
= V_ARRAY(pvaIn
)->rgsabound
[0].cElements
;
284 TRACE("setting footer %s\n", debugstr_w(V_BSTR(opts
)));
285 set_print_template(settings
, V_BSTR(opts
), TRUE
);
290 WARN("opts = %s\n", debugstr_variant(opts
));
295 switch(V_VT(opts
+1)) {
297 TRACE("setting footer %s\n", debugstr_w(V_BSTR(opts
+1)));
298 set_print_template(settings
, V_BSTR(opts
+1), FALSE
);
303 WARN("opts[1] = %s\n", debugstr_variant(opts
+1));
308 FIXME("Unsupported opts_cnt %d\n", opts_cnt
);
310 SafeArrayUnaccessData(V_ARRAY(pvaIn
));
314 FIXME("unsupported arg %s\n", debugstr_variant(pvaIn
));
318 nsres
= nsIWebBrowserPrint_Print(nsprint
, settings
, NULL
);
320 ERR("Print failed: %08x\n", nsres
);
322 nsIWebBrowserPrint_Release(nsprint
);
327 static HRESULT
exec_print_preview(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
329 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
333 static HRESULT
exec_page_setup(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
335 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
339 static HRESULT
exec_spell(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
341 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
345 static HRESULT
exec_properties(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
347 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
351 static HRESULT
exec_cut(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
353 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
357 static HRESULT
exec_copy(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
359 TRACE("(%p)->(%d %s %p)\n", This
, nCmdexecopt
, debugstr_variant(pvaIn
), pvaOut
);
361 do_ns_command(This
, NSCMD_COPY
, NULL
);
365 static HRESULT
exec_paste(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
367 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
371 static HRESULT
exec_paste_special(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
373 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
377 static HRESULT
exec_undo(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
379 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
383 static HRESULT
exec_rendo(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
385 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
389 static HRESULT
exec_select_all(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*in
, VARIANT
*out
)
391 TRACE("(%p)\n", This
);
394 FIXME("unsupported args\n");
396 if(This
->doc_obj
->nscontainer
)
397 do_ns_command(This
, NSCMD_SELECTALL
, NULL
);
399 update_doc(This
->doc_obj
, UPDATE_UI
);
403 static HRESULT
exec_clear_selection(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
405 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
409 static HRESULT
exec_zoom(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
411 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
415 static HRESULT
exec_get_zoom_range(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
417 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
423 HTMLOuterWindow
*window
;
426 static void refresh_proc(task_t
*_task
)
428 refresh_task_t
*task
= (refresh_task_t
*)_task
;
429 HTMLOuterWindow
*window
= task
->window
;
431 TRACE("%p\n", window
);
433 window
->readystate
= READYSTATE_UNINITIALIZED
;
435 if(window
->doc_obj
&& window
->doc_obj
->client_cmdtrg
) {
440 IOleCommandTarget_Exec(window
->doc_obj
->client_cmdtrg
, &CGID_ShellDocView
, 37, 0, &var
, NULL
);
443 load_uri(task
->window
, task
->window
->uri
, BINDING_REFRESH
|BINDING_NOFRAG
);
446 static void refresh_destr(task_t
*_task
)
448 refresh_task_t
*task
= (refresh_task_t
*)_task
;
450 IHTMLWindow2_Release(&task
->window
->base
.IHTMLWindow2_iface
);
454 static HRESULT
exec_refresh(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
456 refresh_task_t
*task
;
459 TRACE("(%p)->(%d %s %p)\n", This
, nCmdexecopt
, debugstr_variant(pvaIn
), pvaOut
);
461 if(This
->doc_obj
->client
) {
462 IOleCommandTarget
*olecmd
;
464 hres
= IOleClientSite_QueryInterface(This
->doc_obj
->client
, &IID_IOleCommandTarget
, (void**)&olecmd
);
465 if(SUCCEEDED(hres
)) {
466 hres
= IOleCommandTarget_Exec(olecmd
, &CGID_DocHostCommandHandler
, 2300, nCmdexecopt
, pvaIn
, pvaOut
);
467 IOleCommandTarget_Release(olecmd
);
476 task
= heap_alloc(sizeof(*task
));
478 return E_OUTOFMEMORY
;
480 IHTMLWindow2_AddRef(&This
->window
->base
.IHTMLWindow2_iface
);
481 task
->window
= This
->window
;
483 return push_task(&task
->header
, refresh_proc
, refresh_destr
, This
->window
->task_magic
);
486 static HRESULT
exec_stop(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
488 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
492 static HRESULT
exec_stop_download(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
494 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
498 static HRESULT
exec_find(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
500 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
504 static HRESULT
exec_delete(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
506 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
510 static HRESULT
exec_enable_interaction(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
512 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
516 static HRESULT
exec_on_unload(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
518 TRACE("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
520 /* Tests show that we have nothing more to do here */
523 V_VT(pvaOut
) = VT_BOOL
;
524 V_BOOL(pvaOut
) = VARIANT_TRUE
;
530 static HRESULT
exec_show_page_setup(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
532 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
536 static HRESULT
exec_show_print(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
538 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
542 static HRESULT
exec_close(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
544 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
548 static HRESULT
exec_set_print_template(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
550 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
554 static HRESULT
exec_get_print_template(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
556 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
560 static HRESULT
exec_optical_zoom(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
562 TRACE("(%p)->(%d %s %p)\n", This
, nCmdexecopt
, debugstr_variant(pvaIn
), pvaOut
);
564 if(!pvaIn
|| V_VT(pvaIn
) != VT_I4
) {
565 FIXME("Unsupported argument %s\n", debugstr_variant(pvaIn
));
569 set_viewer_zoom(This
->doc_obj
->nscontainer
, (float)V_I4(pvaIn
)/100);
573 static HRESULT
query_mshtml_copy(HTMLDocument
*This
, OLECMD
*cmd
)
575 FIXME("(%p)\n", This
);
576 cmd
->cmdf
= OLECMDF_SUPPORTED
|OLECMDF_ENABLED
;
580 static HRESULT
exec_mshtml_copy(HTMLDocument
*This
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
582 TRACE("(%p)->(%08x %p %p)\n", This
, cmdexecopt
, in
, out
);
584 if(This
->doc_obj
->usermode
== EDITMODE
)
585 return editor_exec_copy(This
, cmdexecopt
, in
, out
);
587 do_ns_command(This
, NSCMD_COPY
, NULL
);
591 static HRESULT
query_mshtml_cut(HTMLDocument
*This
, OLECMD
*cmd
)
593 FIXME("(%p)\n", This
);
594 cmd
->cmdf
= OLECMDF_SUPPORTED
|OLECMDF_ENABLED
;
598 static HRESULT
exec_mshtml_cut(HTMLDocument
*This
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
600 nsIClipboardCommands
*clipboard_commands
;
603 TRACE("(%p)->(%08x %p %p)\n", This
, cmdexecopt
, in
, out
);
605 if(This
->doc_obj
->usermode
== EDITMODE
)
606 return editor_exec_cut(This
, cmdexecopt
, in
, out
);
608 clipboard_commands
= get_clipboard_commands(This
);
609 if(!clipboard_commands
)
612 nsres
= nsIClipboardCommands_CutSelection(clipboard_commands
);
613 nsIClipboardCommands_Release(clipboard_commands
);
614 if(NS_FAILED(nsres
)) {
615 ERR("Paste failed: %08x\n", nsres
);
622 static HRESULT
query_mshtml_paste(HTMLDocument
*This
, OLECMD
*cmd
)
624 FIXME("(%p)\n", This
);
625 cmd
->cmdf
= OLECMDF_SUPPORTED
|OLECMDF_ENABLED
;
629 static HRESULT
exec_mshtml_paste(HTMLDocument
*This
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
631 nsIClipboardCommands
*clipboard_commands
;
634 TRACE("(%p)->(%08x %p %p)\n", This
, cmdexecopt
, in
, out
);
636 if(This
->doc_obj
->usermode
== EDITMODE
)
637 return editor_exec_paste(This
, cmdexecopt
, in
, out
);
639 clipboard_commands
= get_clipboard_commands(This
);
640 if(!clipboard_commands
)
643 nsres
= nsIClipboardCommands_Paste(clipboard_commands
);
644 nsIClipboardCommands_Release(clipboard_commands
);
645 if(NS_FAILED(nsres
)) {
646 ERR("Paste failed: %08x\n", nsres
);
653 static HRESULT
query_selall_status(HTMLDocument
*This
, OLECMD
*cmd
)
655 TRACE("(%p)->(%p)\n", This
, cmd
);
657 cmd
->cmdf
= OLECMDF_SUPPORTED
|OLECMDF_ENABLED
;
661 static HRESULT
exec_browsemode(HTMLDocument
*This
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
663 WARN("(%p)->(%08x %p %p)\n", This
, cmdexecopt
, in
, out
);
666 FIXME("unsupported args\n");
668 This
->doc_obj
->usermode
= BROWSEMODE
;
673 static HRESULT
exec_editmode(HTMLDocument
*This
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
675 TRACE("(%p)->(%08x %p %p)\n", This
, cmdexecopt
, in
, out
);
678 FIXME("unsupported args\n");
680 return setup_edit_mode(This
->doc_obj
);
683 static HRESULT
exec_htmleditmode(HTMLDocument
*This
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
685 FIXME("(%p)->(%08x %p %p)\n", This
, cmdexecopt
, in
, out
);
689 static HRESULT
exec_baselinefont3(HTMLDocument
*This
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
691 FIXME("(%p)->(%08x %p %p)\n", This
, cmdexecopt
, in
, out
);
695 static HRESULT
exec_respectvisibility_indesign(HTMLDocument
*This
, DWORD cmdexecopt
,
696 VARIANT
*in
, VARIANT
*out
)
698 TRACE("(%p)->(%x %s %p)\n", This
, cmdexecopt
, debugstr_variant(in
), out
);
700 /* This is turned on by default in Gecko. */
701 if(!in
|| V_VT(in
) != VT_BOOL
|| !V_BOOL(in
))
702 FIXME("Unsupported argument %s\n", debugstr_variant(in
));
707 static HRESULT
query_enabled_stub(HTMLDocument
*This
, OLECMD
*cmd
)
711 FIXME("CGID_MSHTML: IDM_PRINT\n");
712 cmd
->cmdf
= OLECMDF_SUPPORTED
|OLECMDF_ENABLED
;
714 case IDM_BLOCKDIRLTR
:
715 FIXME("CGID_MSHTML: IDM_BLOCKDIRLTR\n");
716 cmd
->cmdf
= OLECMDF_SUPPORTED
|OLECMDF_ENABLED
;
718 case IDM_BLOCKDIRRTL
:
719 FIXME("CGID_MSHTML: IDM_BLOCKDIRRTL\n");
720 cmd
->cmdf
= OLECMDF_SUPPORTED
|OLECMDF_ENABLED
;
727 static const struct {
729 HRESULT (*func
)(HTMLDocument
*,DWORD
,VARIANT
*,VARIANT
*);
732 { OLECMDF_SUPPORTED
, exec_open
}, /* OLECMDID_OPEN */
733 { OLECMDF_SUPPORTED
, exec_new
}, /* OLECMDID_NEW */
734 { OLECMDF_SUPPORTED
, exec_save
}, /* OLECMDID_SAVE */
735 { OLECMDF_SUPPORTED
|OLECMDF_ENABLED
, exec_save_as
}, /* OLECMDID_SAVEAS */
736 { OLECMDF_SUPPORTED
, exec_save_copy_as
}, /* OLECMDID_SAVECOPYAS */
737 { OLECMDF_SUPPORTED
|OLECMDF_ENABLED
, exec_print
}, /* OLECMDID_PRINT */
738 { OLECMDF_SUPPORTED
|OLECMDF_ENABLED
, exec_print_preview
}, /* OLECMDID_PRINTPREVIEW */
739 { OLECMDF_SUPPORTED
|OLECMDF_ENABLED
, exec_page_setup
}, /* OLECMDID_PAGESETUP */
740 { OLECMDF_SUPPORTED
, exec_spell
}, /* OLECMDID_SPELL */
741 { OLECMDF_SUPPORTED
|OLECMDF_ENABLED
, exec_properties
}, /* OLECMDID_PROPERTIES */
742 { OLECMDF_SUPPORTED
, exec_cut
}, /* OLECMDID_CUT */
743 { OLECMDF_SUPPORTED
, exec_copy
}, /* OLECMDID_COPY */
744 { OLECMDF_SUPPORTED
, exec_paste
}, /* OLECMDID_PASTE */
745 { OLECMDF_SUPPORTED
, exec_paste_special
}, /* OLECMDID_PASTESPECIAL */
746 { OLECMDF_SUPPORTED
, exec_undo
}, /* OLECMDID_UNDO */
747 { OLECMDF_SUPPORTED
, exec_rendo
}, /* OLECMDID_REDO */
748 { OLECMDF_SUPPORTED
|OLECMDF_ENABLED
, exec_select_all
}, /* OLECMDID_SELECTALL */
749 { OLECMDF_SUPPORTED
, exec_clear_selection
}, /* OLECMDID_CLEARSELECTION */
750 { OLECMDF_SUPPORTED
, exec_zoom
}, /* OLECMDID_ZOOM */
751 { OLECMDF_SUPPORTED
, exec_get_zoom_range
}, /* OLECMDID_GETZOOMRANGE */
753 { OLECMDF_SUPPORTED
|OLECMDF_ENABLED
, exec_refresh
}, /* OLECMDID_REFRESH */
754 { OLECMDF_SUPPORTED
|OLECMDF_ENABLED
, exec_stop
}, /* OLECMDID_STOP */
755 {0},{0},{0},{0},{0},{0},
756 { OLECMDF_SUPPORTED
, exec_stop_download
}, /* OLECMDID_STOPDOWNLOAD */
758 { OLECMDF_SUPPORTED
|OLECMDF_ENABLED
, exec_find
}, /* OLECMDID_FIND */
759 { OLECMDF_SUPPORTED
, exec_delete
}, /* OLECMDID_DELETE */
761 { OLECMDF_SUPPORTED
, exec_enable_interaction
}, /* OLECMDID_ENABLE_INTERACTION */
762 { OLECMDF_SUPPORTED
, exec_on_unload
}, /* OLECMDID_ONUNLOAD */
764 { OLECMDF_SUPPORTED
, exec_show_page_setup
}, /* OLECMDID_SHOWPAGESETUP */
765 { OLECMDF_SUPPORTED
, exec_show_print
}, /* OLECMDID_SHOWPRINT */
767 { OLECMDF_SUPPORTED
, exec_close
}, /* OLECMDID_CLOSE */
769 { OLECMDF_SUPPORTED
, exec_set_print_template
}, /* OLECMDID_SETPRINTTEMPLATE */
770 { OLECMDF_SUPPORTED
, exec_get_print_template
}, /* OLECMDID_GETPRINTTEMPLATE */
771 {0},{0},{0},{0},{0},{0},{0},{0},{0},{0},
772 { 0, /* not reported as supported */ exec_optical_zoom
} /* OLECMDID_OPTICAL_ZOOM */
775 static const cmdtable_t base_cmds
[] = {
776 {IDM_COPY
, query_mshtml_copy
, exec_mshtml_copy
},
777 {IDM_PASTE
, query_mshtml_paste
, exec_mshtml_paste
},
778 {IDM_CUT
, query_mshtml_cut
, exec_mshtml_cut
},
779 {IDM_SELECTALL
, query_selall_status
, exec_select_all
},
780 {IDM_BROWSEMODE
, NULL
, exec_browsemode
},
781 {IDM_EDITMODE
, NULL
, exec_editmode
},
782 {IDM_PRINT
, query_enabled_stub
, exec_print
},
783 {IDM_HTMLEDITMODE
, NULL
, exec_htmleditmode
},
784 {IDM_BASELINEFONT3
, NULL
, exec_baselinefont3
},
785 {IDM_BLOCKDIRLTR
, query_enabled_stub
, NULL
},
786 {IDM_BLOCKDIRRTL
, query_enabled_stub
, NULL
},
787 {IDM_RESPECTVISIBILITY_INDESIGN
, NULL
, exec_respectvisibility_indesign
},
791 static HRESULT WINAPI
OleCommandTarget_QueryInterface(IOleCommandTarget
*iface
, REFIID riid
, void **ppv
)
793 HTMLDocument
*This
= impl_from_IOleCommandTarget(iface
);
794 return htmldoc_query_interface(This
, riid
, ppv
);
797 static ULONG WINAPI
OleCommandTarget_AddRef(IOleCommandTarget
*iface
)
799 HTMLDocument
*This
= impl_from_IOleCommandTarget(iface
);
800 return htmldoc_addref(This
);
803 static ULONG WINAPI
OleCommandTarget_Release(IOleCommandTarget
*iface
)
805 HTMLDocument
*This
= impl_from_IOleCommandTarget(iface
);
806 return htmldoc_release(This
);
809 static HRESULT
query_from_table(HTMLDocument
*This
, const cmdtable_t
*cmdtable
, OLECMD
*cmd
)
811 const cmdtable_t
*iter
= cmdtable
;
815 while(iter
->id
&& iter
->id
!= cmd
->cmdID
)
818 if(!iter
->id
|| !iter
->query
)
819 return OLECMDERR_E_NOTSUPPORTED
;
821 return iter
->query(This
, cmd
);
824 static HRESULT WINAPI
OleCommandTarget_QueryStatus(IOleCommandTarget
*iface
, const GUID
*pguidCmdGroup
,
825 ULONG cCmds
, OLECMD prgCmds
[], OLECMDTEXT
*pCmdText
)
827 HTMLDocument
*This
= impl_from_IOleCommandTarget(iface
);
830 TRACE("(%p)->(%s %d %p %p)\n", This
, debugstr_guid(pguidCmdGroup
), cCmds
, prgCmds
, pCmdText
);
833 FIXME("Unsupported pCmdText\n");
840 for(i
=0; i
<cCmds
; i
++) {
841 if(prgCmds
[i
].cmdID
< OLECMDID_OPEN
|| prgCmds
[i
].cmdID
>= sizeof(exec_table
)/sizeof(*exec_table
)) {
842 WARN("Unsupported cmdID = %d\n", prgCmds
[i
].cmdID
);
845 if(prgCmds
[i
].cmdID
== OLECMDID_OPEN
|| prgCmds
[i
].cmdID
== OLECMDID_NEW
) {
846 IOleCommandTarget
*cmdtrg
= NULL
;
849 prgCmds
[i
].cmdf
= OLECMDF_SUPPORTED
;
850 if(This
->doc_obj
->client
) {
851 hres
= IOleClientSite_QueryInterface(This
->doc_obj
->client
, &IID_IOleCommandTarget
,
853 if(SUCCEEDED(hres
)) {
854 olecmd
.cmdID
= prgCmds
[i
].cmdID
;
857 hres
= IOleCommandTarget_QueryStatus(cmdtrg
, NULL
, 1, &olecmd
, NULL
);
858 if(SUCCEEDED(hres
) && olecmd
.cmdf
)
859 prgCmds
[i
].cmdf
= olecmd
.cmdf
;
862 ERR("This->client == NULL, native would crash\n");
865 prgCmds
[i
].cmdf
= exec_table
[prgCmds
[i
].cmdID
].cmdf
;
866 TRACE("cmdID = %d returning %x\n", prgCmds
[i
].cmdID
, prgCmds
[i
].cmdf
);
871 return (prgCmds
[cCmds
-1].cmdf
& OLECMDF_SUPPORTED
) ? S_OK
: OLECMDERR_E_NOTSUPPORTED
;
874 if(IsEqualGUID(&CGID_MSHTML
, pguidCmdGroup
)) {
877 for(i
=0; i
<cCmds
; i
++) {
878 hres
= query_from_table(This
, base_cmds
, prgCmds
+i
);
879 if(hres
== OLECMDERR_E_NOTSUPPORTED
)
880 hres
= query_from_table(This
, editmode_cmds
, prgCmds
+i
);
881 if(hres
== OLECMDERR_E_NOTSUPPORTED
)
882 FIXME("CGID_MSHTML: unsupported cmdID %d\n", prgCmds
[i
].cmdID
);
885 return (prgCmds
[cCmds
-1].cmdf
& OLECMDF_SUPPORTED
) ? S_OK
: OLECMDERR_E_NOTSUPPORTED
;
888 FIXME("Unsupported pguidCmdGroup %s\n", debugstr_guid(pguidCmdGroup
));
889 return OLECMDERR_E_UNKNOWNGROUP
;
892 static HRESULT
exec_from_table(HTMLDocument
*This
, const cmdtable_t
*cmdtable
, DWORD cmdid
,
893 DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
895 const cmdtable_t
*iter
= cmdtable
;
897 while(iter
->id
&& iter
->id
!= cmdid
)
900 if(!iter
->id
|| !iter
->exec
)
901 return OLECMDERR_E_NOTSUPPORTED
;
903 return iter
->exec(This
, cmdexecopt
, in
, out
);
906 static HRESULT WINAPI
OleCommandTarget_Exec(IOleCommandTarget
*iface
, const GUID
*pguidCmdGroup
,
907 DWORD nCmdID
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
909 HTMLDocument
*This
= impl_from_IOleCommandTarget(iface
);
912 if(nCmdID
< OLECMDID_OPEN
|| nCmdID
>= sizeof(exec_table
)/sizeof(*exec_table
) || !exec_table
[nCmdID
].func
) {
913 WARN("Unsupported cmdID = %d\n", nCmdID
);
914 return OLECMDERR_E_NOTSUPPORTED
;
917 return exec_table
[nCmdID
].func(This
, nCmdexecopt
, pvaIn
, pvaOut
);
918 }else if(IsEqualGUID(&CGID_Explorer
, pguidCmdGroup
)) {
919 FIXME("unsupported nCmdID %d of CGID_Explorer group\n", nCmdID
);
920 TRACE("%p %p\n", pvaIn
, pvaOut
);
921 return OLECMDERR_E_NOTSUPPORTED
;
922 }else if(IsEqualGUID(&CGID_ShellDocView
, pguidCmdGroup
)) {
923 FIXME("unsupported nCmdID %d of CGID_ShellDocView group\n", nCmdID
);
924 return OLECMDERR_E_NOTSUPPORTED
;
925 }else if(IsEqualGUID(&CGID_MSHTML
, pguidCmdGroup
)) {
926 HRESULT hres
= exec_from_table(This
, base_cmds
, nCmdID
, nCmdexecopt
, pvaIn
, pvaOut
);
927 if(hres
== OLECMDERR_E_NOTSUPPORTED
)
928 hres
= exec_from_table(This
, editmode_cmds
, nCmdID
,
929 nCmdexecopt
, pvaIn
, pvaOut
);
930 if(hres
== OLECMDERR_E_NOTSUPPORTED
)
931 FIXME("unsupported nCmdID %d of CGID_MSHTML group\n", nCmdID
);
936 FIXME("Unsupported pguidCmdGroup %s\n", debugstr_guid(pguidCmdGroup
));
937 return OLECMDERR_E_UNKNOWNGROUP
;
940 static const IOleCommandTargetVtbl OleCommandTargetVtbl
= {
941 OleCommandTarget_QueryInterface
,
942 OleCommandTarget_AddRef
,
943 OleCommandTarget_Release
,
944 OleCommandTarget_QueryStatus
,
945 OleCommandTarget_Exec
948 void show_context_menu(HTMLDocumentObj
*This
, DWORD dwID
, POINT
*ppt
, IDispatch
*elem
)
950 HMENU menu_res
, menu
;
953 if(This
->hostui
&& S_OK
== IDocHostUIHandler_ShowContextMenu(This
->hostui
,
954 dwID
, ppt
, (IUnknown
*)&This
->basedoc
.IOleCommandTarget_iface
, elem
))
957 menu_res
= LoadMenuW(get_shdoclc(), MAKEINTRESOURCEW(IDR_BROWSE_CONTEXT_MENU
));
958 menu
= GetSubMenu(menu_res
, dwID
);
960 cmdid
= TrackPopupMenu(menu
, TPM_LEFTALIGN
| TPM_RIGHTBUTTON
| TPM_RETURNCMD
,
961 ppt
->x
, ppt
->y
, 0, This
->hwnd
, NULL
);
962 DestroyMenu(menu_res
);
965 IOleCommandTarget_Exec(&This
->basedoc
.IOleCommandTarget_iface
, &CGID_MSHTML
, cmdid
, 0,
969 void HTMLDocument_OleCmd_Init(HTMLDocument
*This
)
971 This
->IOleCommandTarget_iface
.lpVtbl
= &OleCommandTargetVtbl
;