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(HTMLDocumentNode
*doc
, const char *cmd
, nsICommandParams
*nsparam
)
45 nsICommandManager
*cmdmgr
;
50 if(!doc
->browser
|| !doc
->window
)
53 nsres
= get_nsinterface((nsISupports
*)doc
->browser
->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
, doc
->window
->base
.outer_window
->window_proxy
);
61 ERR("DoCommand(%s) failed: %08x\n", debugstr_a(cmd
), nsres
);
63 nsICommandManager_Release(cmdmgr
);
66 static nsIClipboardCommands
*get_clipboard_commands(HTMLDocumentNode
*doc
)
68 nsIClipboardCommands
*clipboard_commands
;
69 nsIDocShell
*doc_shell
;
72 nsres
= get_nsinterface((nsISupports
*)doc
->basedoc
.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(HTMLDocumentNode
*doc
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
99 FIXME("(%p)->(%d %p %p)\n", doc
, nCmdexecopt
, pvaIn
, pvaOut
);
103 static HRESULT
exec_new(HTMLDocumentNode
*doc
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
105 FIXME("(%p)->(%d %p %p)\n", doc
, nCmdexecopt
, pvaIn
, pvaOut
);
109 static HRESULT
exec_save(HTMLDocumentNode
*doc
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
111 FIXME("(%p)->(%d %p %p)\n", doc
, nCmdexecopt
, pvaIn
, pvaOut
);
115 static HRESULT
exec_save_as(HTMLDocumentNode
*doc
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
117 FIXME("(%p)->(%d %p %p)\n", doc
, nCmdexecopt
, pvaIn
, pvaOut
);
121 static HRESULT
exec_save_copy_as(HTMLDocumentNode
*doc
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
123 FIXME("(%p)->(%d %p %p)\n", doc
, 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
, ARRAY_SIZE(buf
)))
232 set_print_template(settings
, buf
, TRUE
);
234 if(LoadStringW(get_shdoclc(), IDS_PRINT_FOOTER_TEMPLATE
, buf
, ARRAY_SIZE(buf
)))
235 set_print_template(settings
, buf
, FALSE
);
239 static HRESULT
exec_print(HTMLDocumentNode
*doc
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
241 nsIWebBrowserPrint
*nsprint
;
242 nsIPrintSettings
*settings
;
245 TRACE("(%p)->(%d %s %p)\n", doc
, nCmdexecopt
, debugstr_variant(pvaIn
), pvaOut
);
248 FIXME("unsupported pvaOut\n");
250 nsres
= get_nsinterface((nsISupports
*)doc
->browser
->webbrowser
, &IID_nsIWebBrowserPrint
,
252 if(NS_FAILED(nsres
)) {
253 ERR("Could not get nsIWebBrowserPrint: %08x\n", nsres
);
257 nsres
= nsIWebBrowserPrint_GetGlobalPrintSettings(nsprint
, &settings
);
259 ERR("GetCurrentPrintSettings failed: %08x\n", nsres
);
261 set_default_templates(settings
);
264 switch(V_VT(pvaIn
)) {
265 case VT_BYREF
|VT_ARRAY
: {
269 if(V_ARRAY(pvaIn
)->cDims
!= 1)
270 WARN("cDims = %d\n", V_ARRAY(pvaIn
)->cDims
);
272 SafeArrayAccessData(V_ARRAY(pvaIn
), (void**)&opts
);
273 opts_cnt
= V_ARRAY(pvaIn
)->rgsabound
[0].cElements
;
278 TRACE("setting footer %s\n", debugstr_w(V_BSTR(opts
)));
279 set_print_template(settings
, V_BSTR(opts
), TRUE
);
284 WARN("opts = %s\n", debugstr_variant(opts
));
289 switch(V_VT(opts
+1)) {
291 TRACE("setting footer %s\n", debugstr_w(V_BSTR(opts
+1)));
292 set_print_template(settings
, V_BSTR(opts
+1), FALSE
);
297 WARN("opts[1] = %s\n", debugstr_variant(opts
+1));
302 FIXME("Unsupported opts_cnt %d\n", opts_cnt
);
304 SafeArrayUnaccessData(V_ARRAY(pvaIn
));
308 FIXME("unsupported arg %s\n", debugstr_variant(pvaIn
));
312 nsres
= nsIWebBrowserPrint_Print(nsprint
, settings
, NULL
);
314 ERR("Print failed: %08x\n", nsres
);
316 nsIWebBrowserPrint_Release(nsprint
);
321 static HRESULT
exec_print_preview(HTMLDocumentNode
*doc
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
323 FIXME("(%p)->(%d %p %p)\n", doc
, nCmdexecopt
, pvaIn
, pvaOut
);
327 static HRESULT
exec_page_setup(HTMLDocumentNode
*doc
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
329 FIXME("(%p)->(%d %p %p)\n", doc
, nCmdexecopt
, pvaIn
, pvaOut
);
333 static HRESULT
exec_spell(HTMLDocumentNode
*doc
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
335 FIXME("(%p)->(%d %p %p)\n", doc
, nCmdexecopt
, pvaIn
, pvaOut
);
339 static HRESULT
exec_properties(HTMLDocumentNode
*doc
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
341 FIXME("(%p)->(%d %p %p)\n", doc
, nCmdexecopt
, pvaIn
, pvaOut
);
345 static HRESULT
exec_cut(HTMLDocumentNode
*doc
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
347 FIXME("(%p)->(%d %p %p)\n", doc
, nCmdexecopt
, pvaIn
, pvaOut
);
351 static HRESULT
exec_copy(HTMLDocumentNode
*doc
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
353 TRACE("(%p)->(%d %s %p)\n", doc
, nCmdexecopt
, debugstr_variant(pvaIn
), pvaOut
);
355 do_ns_command(doc
, NSCMD_COPY
, NULL
);
359 static HRESULT
exec_paste(HTMLDocumentNode
*doc
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
361 FIXME("(%p)->(%d %p %p)\n", doc
, nCmdexecopt
, pvaIn
, pvaOut
);
365 static HRESULT
exec_paste_special(HTMLDocumentNode
*doc
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
367 FIXME("(%p)->(%d %p %p)\n", doc
, nCmdexecopt
, pvaIn
, pvaOut
);
371 static HRESULT
exec_undo(HTMLDocumentNode
*doc
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
373 FIXME("(%p)->(%d %p %p)\n", doc
, nCmdexecopt
, pvaIn
, pvaOut
);
377 static HRESULT
exec_rendo(HTMLDocumentNode
*doc
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
379 FIXME("(%p)->(%d %p %p)\n", doc
, nCmdexecopt
, pvaIn
, pvaOut
);
383 static HRESULT
exec_select_all(HTMLDocumentNode
*doc
, DWORD nCmdexecopt
, VARIANT
*in
, VARIANT
*out
)
385 TRACE("(%p)\n", doc
);
388 FIXME("unsupported args\n");
393 do_ns_command(doc
, NSCMD_SELECTALL
, NULL
);
394 update_doc(doc
->browser
->doc
, UPDATE_UI
);
398 static HRESULT
exec_clear_selection(HTMLDocumentNode
*doc
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
400 FIXME("(%p)->(%d %p %p)\n", doc
, nCmdexecopt
, pvaIn
, pvaOut
);
404 static HRESULT
exec_zoom(HTMLDocumentNode
*doc
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
406 FIXME("(%p)->(%d %p %p)\n", doc
, nCmdexecopt
, pvaIn
, pvaOut
);
410 static HRESULT
exec_get_zoom_range(HTMLDocumentNode
*doc
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
412 FIXME("(%p)->(%d %p %p)\n", doc
, nCmdexecopt
, pvaIn
, pvaOut
);
418 HTMLOuterWindow
*window
;
421 static void refresh_proc(task_t
*_task
)
423 refresh_task_t
*task
= (refresh_task_t
*)_task
;
424 HTMLOuterWindow
*window
= task
->window
;
426 TRACE("%p\n", window
);
428 window
->readystate
= READYSTATE_UNINITIALIZED
;
430 if(window
->browser
&& window
->browser
->doc
->client_cmdtrg
) {
435 IOleCommandTarget_Exec(window
->browser
->doc
->client_cmdtrg
, &CGID_ShellDocView
, 37, 0, &var
, NULL
);
438 load_uri(task
->window
, task
->window
->uri
, BINDING_REFRESH
|BINDING_NOFRAG
);
441 static void refresh_destr(task_t
*_task
)
443 refresh_task_t
*task
= (refresh_task_t
*)_task
;
445 IHTMLWindow2_Release(&task
->window
->base
.IHTMLWindow2_iface
);
449 static HRESULT
exec_refresh(HTMLDocumentNode
*doc
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
451 HTMLDocumentObj
*doc_obj
;
452 refresh_task_t
*task
;
455 TRACE("(%p)->(%d %s %p)\n", doc
, nCmdexecopt
, debugstr_variant(pvaIn
), pvaOut
);
457 if(doc
!= doc
->browser
->doc
->basedoc
.doc_node
) {
458 FIXME("Unsupported on frame documents\n");
461 doc_obj
= doc
->browser
->doc
;
463 if(doc_obj
->client
) {
464 IOleCommandTarget
*olecmd
;
466 hres
= IOleClientSite_QueryInterface(doc_obj
->client
, &IID_IOleCommandTarget
, (void**)&olecmd
);
467 if(SUCCEEDED(hres
)) {
468 hres
= IOleCommandTarget_Exec(olecmd
, &CGID_DocHostCommandHandler
, 2300, nCmdexecopt
, pvaIn
, pvaOut
);
469 IOleCommandTarget_Release(olecmd
);
475 if(!doc
->basedoc
.window
)
478 task
= heap_alloc(sizeof(*task
));
480 return E_OUTOFMEMORY
;
482 IHTMLWindow2_AddRef(&doc
->basedoc
.window
->base
.IHTMLWindow2_iface
);
483 task
->window
= doc
->basedoc
.window
;
485 return push_task(&task
->header
, refresh_proc
, refresh_destr
, doc
->basedoc
.window
->task_magic
);
488 static HRESULT
exec_stop(HTMLDocumentNode
*doc
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
490 FIXME("(%p)->(%d %p %p)\n", doc
, nCmdexecopt
, pvaIn
, pvaOut
);
494 static HRESULT
exec_stop_download(HTMLDocumentNode
*doc
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
496 FIXME("(%p)->(%d %p %p)\n", doc
, nCmdexecopt
, pvaIn
, pvaOut
);
500 static HRESULT
exec_find(HTMLDocumentNode
*doc
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
502 FIXME("(%p)->(%d %p %p)\n", doc
, nCmdexecopt
, pvaIn
, pvaOut
);
506 static HRESULT
exec_delete(HTMLDocumentNode
*doc
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
508 FIXME("(%p)->(%d %p %p)\n", doc
, nCmdexecopt
, pvaIn
, pvaOut
);
512 static HRESULT
exec_enable_interaction(HTMLDocumentNode
*doc
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
514 FIXME("(%p)->(%d %p %p)\n", doc
, nCmdexecopt
, pvaIn
, pvaOut
);
518 static HRESULT
exec_on_unload(HTMLDocumentNode
*doc
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
520 TRACE("(%p)->(%d %p %p)\n", doc
, nCmdexecopt
, pvaIn
, pvaOut
);
522 /* Tests show that we have nothing more to do here */
525 V_VT(pvaOut
) = VT_BOOL
;
526 V_BOOL(pvaOut
) = VARIANT_TRUE
;
532 static HRESULT
exec_show_page_setup(HTMLDocumentNode
*doc
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
534 FIXME("(%p)->(%d %p %p)\n", doc
, nCmdexecopt
, pvaIn
, pvaOut
);
538 static HRESULT
exec_show_print(HTMLDocumentNode
*doc
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
540 FIXME("(%p)->(%d %p %p)\n", doc
, nCmdexecopt
, pvaIn
, pvaOut
);
544 static HRESULT
exec_close(HTMLDocumentNode
*doc
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
546 FIXME("(%p)->(%d %p %p)\n", doc
, nCmdexecopt
, pvaIn
, pvaOut
);
550 static HRESULT
exec_set_print_template(HTMLDocumentNode
*doc
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
552 FIXME("(%p)->(%d %p %p)\n", doc
, nCmdexecopt
, pvaIn
, pvaOut
);
556 static HRESULT
exec_get_print_template(HTMLDocumentNode
*doc
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
558 FIXME("(%p)->(%d %p %p)\n", doc
, nCmdexecopt
, pvaIn
, pvaOut
);
562 static HRESULT
exec_optical_zoom(HTMLDocumentNode
*doc
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
564 TRACE("(%p)->(%d %s %p)\n", doc
, nCmdexecopt
, debugstr_variant(pvaIn
), pvaOut
);
566 if(pvaIn
&& V_VT(pvaIn
) != VT_I4
) {
567 FIXME("Unsupported argument %s\n", debugstr_variant(pvaIn
));
572 set_viewer_zoom(doc
->browser
, (float)V_I4(pvaIn
)/100);
574 V_VT(pvaOut
) = VT_I4
;
575 V_I4(pvaOut
) = get_viewer_zoom(doc
->browser
) * 100;
580 static HRESULT
query_mshtml_copy(HTMLDocumentNode
*doc
, OLECMD
*cmd
)
582 FIXME("(%p)\n", doc
);
583 cmd
->cmdf
= OLECMDF_SUPPORTED
|OLECMDF_ENABLED
;
587 static HRESULT
exec_mshtml_copy(HTMLDocumentNode
*doc
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
589 TRACE("(%p)->(%08x %p %p)\n", doc
, cmdexecopt
, in
, out
);
591 if(doc
->browser
->usermode
== EDITMODE
)
592 return editor_exec_copy(doc
, cmdexecopt
, in
, out
);
594 do_ns_command(doc
, NSCMD_COPY
, NULL
);
598 static HRESULT
query_mshtml_cut(HTMLDocumentNode
*doc
, OLECMD
*cmd
)
600 FIXME("(%p)\n", doc
);
601 cmd
->cmdf
= OLECMDF_SUPPORTED
|OLECMDF_ENABLED
;
605 static HRESULT
exec_mshtml_cut(HTMLDocumentNode
*doc
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
607 nsIClipboardCommands
*clipboard_commands
;
610 TRACE("(%p)->(%08x %p %p)\n", doc
, cmdexecopt
, in
, out
);
612 if(doc
->browser
->usermode
== EDITMODE
)
613 return editor_exec_cut(doc
, cmdexecopt
, in
, out
);
615 clipboard_commands
= get_clipboard_commands(doc
);
616 if(!clipboard_commands
)
619 nsres
= nsIClipboardCommands_CutSelection(clipboard_commands
);
620 nsIClipboardCommands_Release(clipboard_commands
);
621 if(NS_FAILED(nsres
)) {
622 ERR("Paste failed: %08x\n", nsres
);
629 static HRESULT
query_mshtml_paste(HTMLDocumentNode
*doc
, OLECMD
*cmd
)
631 FIXME("(%p)\n", doc
);
632 cmd
->cmdf
= OLECMDF_SUPPORTED
|OLECMDF_ENABLED
;
636 static HRESULT
exec_mshtml_paste(HTMLDocumentNode
*doc
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
638 nsIClipboardCommands
*clipboard_commands
;
641 TRACE("(%p)->(%08x %p %p)\n", doc
, cmdexecopt
, in
, out
);
643 if(doc
->browser
->usermode
== EDITMODE
)
644 return editor_exec_paste(doc
, cmdexecopt
, in
, out
);
646 clipboard_commands
= get_clipboard_commands(doc
);
647 if(!clipboard_commands
)
650 nsres
= nsIClipboardCommands_Paste(clipboard_commands
);
651 nsIClipboardCommands_Release(clipboard_commands
);
652 if(NS_FAILED(nsres
)) {
653 ERR("Paste failed: %08x\n", nsres
);
660 static HRESULT
query_selall_status(HTMLDocumentNode
*doc
, OLECMD
*cmd
)
662 TRACE("(%p)->(%p)\n", doc
, cmd
);
664 cmd
->cmdf
= OLECMDF_SUPPORTED
|OLECMDF_ENABLED
;
668 static HRESULT
exec_browsemode(HTMLDocumentNode
*doc
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
670 WARN("(%p)->(%08x %p %p)\n", doc
, cmdexecopt
, in
, out
);
673 FIXME("unsupported args\n");
675 doc
->browser
->usermode
= BROWSEMODE
;
680 static HRESULT
exec_editmode(HTMLDocumentNode
*doc
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
682 TRACE("(%p)->(%08x %p %p)\n", doc
, cmdexecopt
, in
, out
);
685 FIXME("unsupported args\n");
687 return setup_edit_mode(doc
->browser
->doc
);
690 static HRESULT
exec_htmleditmode(HTMLDocumentNode
*doc
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
692 FIXME("(%p)->(%08x %p %p)\n", doc
, cmdexecopt
, in
, out
);
696 static HRESULT
exec_baselinefont3(HTMLDocumentNode
*doc
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
698 FIXME("(%p)->(%08x %p %p)\n", doc
, cmdexecopt
, in
, out
);
702 static HRESULT
exec_respectvisibility_indesign(HTMLDocumentNode
*doc
, DWORD cmdexecopt
,
703 VARIANT
*in
, VARIANT
*out
)
705 TRACE("(%p)->(%x %s %p)\n", doc
, cmdexecopt
, debugstr_variant(in
), out
);
707 /* This is turned on by default in Gecko. */
708 if(!in
|| V_VT(in
) != VT_BOOL
|| !V_BOOL(in
))
709 FIXME("Unsupported argument %s\n", debugstr_variant(in
));
714 static HRESULT
query_enabled_stub(HTMLDocumentNode
*doc
, OLECMD
*cmd
)
718 FIXME("CGID_MSHTML: IDM_PRINT\n");
719 cmd
->cmdf
= OLECMDF_SUPPORTED
|OLECMDF_ENABLED
;
721 case IDM_BLOCKDIRLTR
:
722 FIXME("CGID_MSHTML: IDM_BLOCKDIRLTR\n");
723 cmd
->cmdf
= OLECMDF_SUPPORTED
|OLECMDF_ENABLED
;
725 case IDM_BLOCKDIRRTL
:
726 FIXME("CGID_MSHTML: IDM_BLOCKDIRRTL\n");
727 cmd
->cmdf
= OLECMDF_SUPPORTED
|OLECMDF_ENABLED
;
734 static const struct {
736 HRESULT (*func
)(HTMLDocumentNode
*,DWORD
,VARIANT
*,VARIANT
*);
739 { OLECMDF_SUPPORTED
, exec_open
}, /* OLECMDID_OPEN */
740 { OLECMDF_SUPPORTED
, exec_new
}, /* OLECMDID_NEW */
741 { OLECMDF_SUPPORTED
, exec_save
}, /* OLECMDID_SAVE */
742 { OLECMDF_SUPPORTED
|OLECMDF_ENABLED
, exec_save_as
}, /* OLECMDID_SAVEAS */
743 { OLECMDF_SUPPORTED
, exec_save_copy_as
}, /* OLECMDID_SAVECOPYAS */
744 { OLECMDF_SUPPORTED
|OLECMDF_ENABLED
, exec_print
}, /* OLECMDID_PRINT */
745 { OLECMDF_SUPPORTED
|OLECMDF_ENABLED
, exec_print_preview
}, /* OLECMDID_PRINTPREVIEW */
746 { OLECMDF_SUPPORTED
|OLECMDF_ENABLED
, exec_page_setup
}, /* OLECMDID_PAGESETUP */
747 { OLECMDF_SUPPORTED
, exec_spell
}, /* OLECMDID_SPELL */
748 { OLECMDF_SUPPORTED
|OLECMDF_ENABLED
, exec_properties
}, /* OLECMDID_PROPERTIES */
749 { OLECMDF_SUPPORTED
, exec_cut
}, /* OLECMDID_CUT */
750 { OLECMDF_SUPPORTED
, exec_copy
}, /* OLECMDID_COPY */
751 { OLECMDF_SUPPORTED
, exec_paste
}, /* OLECMDID_PASTE */
752 { OLECMDF_SUPPORTED
, exec_paste_special
}, /* OLECMDID_PASTESPECIAL */
753 { OLECMDF_SUPPORTED
, exec_undo
}, /* OLECMDID_UNDO */
754 { OLECMDF_SUPPORTED
, exec_rendo
}, /* OLECMDID_REDO */
755 { OLECMDF_SUPPORTED
|OLECMDF_ENABLED
, exec_select_all
}, /* OLECMDID_SELECTALL */
756 { OLECMDF_SUPPORTED
, exec_clear_selection
}, /* OLECMDID_CLEARSELECTION */
757 { OLECMDF_SUPPORTED
, exec_zoom
}, /* OLECMDID_ZOOM */
758 { OLECMDF_SUPPORTED
, exec_get_zoom_range
}, /* OLECMDID_GETZOOMRANGE */
760 { OLECMDF_SUPPORTED
|OLECMDF_ENABLED
, exec_refresh
}, /* OLECMDID_REFRESH */
761 { OLECMDF_SUPPORTED
|OLECMDF_ENABLED
, exec_stop
}, /* OLECMDID_STOP */
762 {0},{0},{0},{0},{0},{0},
763 { OLECMDF_SUPPORTED
, exec_stop_download
}, /* OLECMDID_STOPDOWNLOAD */
765 { OLECMDF_SUPPORTED
|OLECMDF_ENABLED
, exec_find
}, /* OLECMDID_FIND */
766 { OLECMDF_SUPPORTED
, exec_delete
}, /* OLECMDID_DELETE */
768 { OLECMDF_SUPPORTED
, exec_enable_interaction
}, /* OLECMDID_ENABLE_INTERACTION */
769 { OLECMDF_SUPPORTED
, exec_on_unload
}, /* OLECMDID_ONUNLOAD */
771 { OLECMDF_SUPPORTED
, exec_show_page_setup
}, /* OLECMDID_SHOWPAGESETUP */
772 { OLECMDF_SUPPORTED
, exec_show_print
}, /* OLECMDID_SHOWPRINT */
774 { OLECMDF_SUPPORTED
, exec_close
}, /* OLECMDID_CLOSE */
776 { OLECMDF_SUPPORTED
, exec_set_print_template
}, /* OLECMDID_SETPRINTTEMPLATE */
777 { OLECMDF_SUPPORTED
, exec_get_print_template
}, /* OLECMDID_GETPRINTTEMPLATE */
778 {0},{0},{0},{0},{0},{0},{0},{0},{0},{0},
779 { 0, /* not reported as supported */ exec_optical_zoom
} /* OLECMDID_OPTICAL_ZOOM */
782 static const cmdtable_t base_cmds
[] = {
783 {IDM_COPY
, query_mshtml_copy
, exec_mshtml_copy
},
784 {IDM_PASTE
, query_mshtml_paste
, exec_mshtml_paste
},
785 {IDM_CUT
, query_mshtml_cut
, exec_mshtml_cut
},
786 {IDM_SELECTALL
, query_selall_status
, exec_select_all
},
787 {IDM_BROWSEMODE
, NULL
, exec_browsemode
},
788 {IDM_EDITMODE
, NULL
, exec_editmode
},
789 {IDM_PRINT
, query_enabled_stub
, exec_print
},
790 {IDM_HTMLEDITMODE
, NULL
, exec_htmleditmode
},
791 {IDM_BASELINEFONT3
, NULL
, exec_baselinefont3
},
792 {IDM_BLOCKDIRLTR
, query_enabled_stub
, NULL
},
793 {IDM_BLOCKDIRRTL
, query_enabled_stub
, NULL
},
794 {IDM_RESPECTVISIBILITY_INDESIGN
, NULL
, exec_respectvisibility_indesign
},
798 static HRESULT WINAPI
OleCommandTarget_QueryInterface(IOleCommandTarget
*iface
, REFIID riid
, void **ppv
)
800 HTMLDocument
*This
= impl_from_IOleCommandTarget(iface
);
801 return htmldoc_query_interface(This
, riid
, ppv
);
804 static ULONG WINAPI
OleCommandTarget_AddRef(IOleCommandTarget
*iface
)
806 HTMLDocument
*This
= impl_from_IOleCommandTarget(iface
);
807 return htmldoc_addref(This
);
810 static ULONG WINAPI
OleCommandTarget_Release(IOleCommandTarget
*iface
)
812 HTMLDocument
*This
= impl_from_IOleCommandTarget(iface
);
813 return htmldoc_release(This
);
816 static HRESULT
query_from_table(HTMLDocumentNode
*doc
, const cmdtable_t
*cmdtable
, OLECMD
*cmd
)
818 const cmdtable_t
*iter
= cmdtable
;
822 while(iter
->id
&& iter
->id
!= cmd
->cmdID
)
825 if(!iter
->id
|| !iter
->query
)
826 return OLECMDERR_E_NOTSUPPORTED
;
828 return iter
->query(doc
, cmd
);
831 static HRESULT WINAPI
OleCommandTarget_QueryStatus(IOleCommandTarget
*iface
, const GUID
*pguidCmdGroup
,
832 ULONG cCmds
, OLECMD prgCmds
[], OLECMDTEXT
*pCmdText
)
834 HTMLDocument
*This
= impl_from_IOleCommandTarget(iface
);
837 TRACE("(%p)->(%s %d %p %p)\n", This
, debugstr_guid(pguidCmdGroup
), cCmds
, prgCmds
, pCmdText
);
840 FIXME("Unsupported pCmdText\n");
841 if(!This
->doc_node
->browser
)
849 for(i
=0; i
<cCmds
; i
++) {
850 if(prgCmds
[i
].cmdID
< OLECMDID_OPEN
|| prgCmds
[i
].cmdID
>= ARRAY_SIZE(exec_table
)) {
851 WARN("Unsupported cmdID = %d\n", prgCmds
[i
].cmdID
);
854 if(prgCmds
[i
].cmdID
== OLECMDID_OPEN
|| prgCmds
[i
].cmdID
== OLECMDID_NEW
) {
855 IOleCommandTarget
*cmdtrg
= NULL
;
858 prgCmds
[i
].cmdf
= OLECMDF_SUPPORTED
;
859 if(This
->doc_obj
->client
) {
860 hres
= IOleClientSite_QueryInterface(This
->doc_obj
->client
, &IID_IOleCommandTarget
,
862 if(SUCCEEDED(hres
)) {
863 olecmd
.cmdID
= prgCmds
[i
].cmdID
;
866 hres
= IOleCommandTarget_QueryStatus(cmdtrg
, NULL
, 1, &olecmd
, NULL
);
867 if(SUCCEEDED(hres
) && olecmd
.cmdf
)
868 prgCmds
[i
].cmdf
= olecmd
.cmdf
;
871 ERR("This->client == NULL, native would crash\n");
874 prgCmds
[i
].cmdf
= exec_table
[prgCmds
[i
].cmdID
].cmdf
;
875 TRACE("cmdID = %d returning %x\n", prgCmds
[i
].cmdID
, prgCmds
[i
].cmdf
);
880 return (prgCmds
[cCmds
-1].cmdf
& OLECMDF_SUPPORTED
) ? S_OK
: OLECMDERR_E_NOTSUPPORTED
;
883 if(IsEqualGUID(&CGID_MSHTML
, pguidCmdGroup
)) {
886 for(i
=0; i
<cCmds
; i
++) {
887 hres
= query_from_table(This
->doc_node
, base_cmds
, prgCmds
+i
);
888 if(hres
== OLECMDERR_E_NOTSUPPORTED
)
889 hres
= query_from_table(This
->doc_node
, editmode_cmds
, prgCmds
+i
);
890 if(hres
== OLECMDERR_E_NOTSUPPORTED
)
891 FIXME("CGID_MSHTML: unsupported cmdID %d\n", prgCmds
[i
].cmdID
);
894 return (prgCmds
[cCmds
-1].cmdf
& OLECMDF_SUPPORTED
) ? S_OK
: OLECMDERR_E_NOTSUPPORTED
;
897 FIXME("Unsupported pguidCmdGroup %s\n", debugstr_guid(pguidCmdGroup
));
898 return OLECMDERR_E_UNKNOWNGROUP
;
901 static HRESULT
exec_from_table(HTMLDocumentNode
*doc
, const cmdtable_t
*cmdtable
, DWORD cmdid
,
902 DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
904 const cmdtable_t
*iter
= cmdtable
;
906 while(iter
->id
&& iter
->id
!= cmdid
)
909 if(!iter
->id
|| !iter
->exec
)
910 return OLECMDERR_E_NOTSUPPORTED
;
912 return iter
->exec(doc
, cmdexecopt
, in
, out
);
915 static HRESULT WINAPI
OleCommandTarget_Exec(IOleCommandTarget
*iface
, const GUID
*pguidCmdGroup
,
916 DWORD nCmdID
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
918 HTMLDocument
*This
= impl_from_IOleCommandTarget(iface
);
920 if(!This
->doc_node
->browser
)
924 if(nCmdID
< OLECMDID_OPEN
|| nCmdID
>= ARRAY_SIZE(exec_table
) || !exec_table
[nCmdID
].func
) {
925 WARN("Unsupported cmdID = %d\n", nCmdID
);
926 return OLECMDERR_E_NOTSUPPORTED
;
929 return exec_table
[nCmdID
].func(This
->doc_node
, nCmdexecopt
, pvaIn
, pvaOut
);
930 }else if(IsEqualGUID(&CGID_Explorer
, pguidCmdGroup
)) {
931 FIXME("unsupported nCmdID %d of CGID_Explorer group\n", nCmdID
);
932 TRACE("%p %p\n", pvaIn
, pvaOut
);
933 return OLECMDERR_E_NOTSUPPORTED
;
934 }else if(IsEqualGUID(&CGID_ShellDocView
, pguidCmdGroup
)) {
935 FIXME("unsupported nCmdID %d of CGID_ShellDocView group\n", nCmdID
);
936 return OLECMDERR_E_NOTSUPPORTED
;
937 }else if(IsEqualGUID(&CGID_MSHTML
, pguidCmdGroup
)) {
938 HRESULT hres
= exec_from_table(This
->doc_node
, base_cmds
, nCmdID
, nCmdexecopt
, pvaIn
, pvaOut
);
939 if(hres
== OLECMDERR_E_NOTSUPPORTED
)
940 hres
= exec_from_table(This
->doc_node
, editmode_cmds
, nCmdID
,
941 nCmdexecopt
, pvaIn
, pvaOut
);
942 if(hres
== OLECMDERR_E_NOTSUPPORTED
)
943 FIXME("unsupported nCmdID %d of CGID_MSHTML group\n", nCmdID
);
948 FIXME("Unsupported pguidCmdGroup %s\n", debugstr_guid(pguidCmdGroup
));
949 return OLECMDERR_E_UNKNOWNGROUP
;
952 static const IOleCommandTargetVtbl OleCommandTargetVtbl
= {
953 OleCommandTarget_QueryInterface
,
954 OleCommandTarget_AddRef
,
955 OleCommandTarget_Release
,
956 OleCommandTarget_QueryStatus
,
957 OleCommandTarget_Exec
960 void show_context_menu(HTMLDocumentObj
*This
, DWORD dwID
, POINT
*ppt
, IDispatch
*elem
)
962 HMENU menu_res
, menu
;
965 if(This
->hostui
&& S_OK
== IDocHostUIHandler_ShowContextMenu(This
->hostui
,
966 dwID
, ppt
, (IUnknown
*)&This
->basedoc
.IOleCommandTarget_iface
, elem
))
969 menu_res
= LoadMenuW(get_shdoclc(), MAKEINTRESOURCEW(IDR_BROWSE_CONTEXT_MENU
));
970 menu
= GetSubMenu(menu_res
, dwID
);
972 cmdid
= TrackPopupMenu(menu
, TPM_LEFTALIGN
| TPM_RIGHTBUTTON
| TPM_RETURNCMD
,
973 ppt
->x
, ppt
->y
, 0, This
->hwnd
, NULL
);
974 DestroyMenu(menu_res
);
977 IOleCommandTarget_Exec(&This
->basedoc
.IOleCommandTarget_iface
, &CGID_MSHTML
, cmdid
, 0,
981 void HTMLDocument_OleCmd_Init(HTMLDocument
*This
)
983 This
->IOleCommandTarget_iface
.lpVtbl
= &OleCommandTargetVtbl
;