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 nsIPrintSettings_SetHeaderStrLeft(settings
, L
"");
223 nsIPrintSettings_SetHeaderStrRight(settings
, L
"");
224 nsIPrintSettings_SetHeaderStrCenter(settings
, L
"");
225 nsIPrintSettings_SetFooterStrLeft(settings
, L
"");
226 nsIPrintSettings_SetFooterStrRight(settings
, L
"");
227 nsIPrintSettings_SetFooterStrCenter(settings
, L
"");
229 if(LoadStringW(get_shdoclc(), IDS_PRINT_HEADER_TEMPLATE
, buf
, ARRAY_SIZE(buf
)))
230 set_print_template(settings
, buf
, TRUE
);
232 if(LoadStringW(get_shdoclc(), IDS_PRINT_FOOTER_TEMPLATE
, buf
, ARRAY_SIZE(buf
)))
233 set_print_template(settings
, buf
, FALSE
);
237 static HRESULT
exec_print(HTMLDocumentNode
*doc
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
239 nsIWebBrowserPrint
*nsprint
;
240 nsIPrintSettings
*settings
;
243 TRACE("(%p)->(%d %s %p)\n", doc
, nCmdexecopt
, debugstr_variant(pvaIn
), pvaOut
);
246 FIXME("unsupported pvaOut\n");
248 nsres
= get_nsinterface((nsISupports
*)doc
->browser
->webbrowser
, &IID_nsIWebBrowserPrint
,
250 if(NS_FAILED(nsres
)) {
251 ERR("Could not get nsIWebBrowserPrint: %08x\n", nsres
);
255 nsres
= nsIWebBrowserPrint_GetGlobalPrintSettings(nsprint
, &settings
);
257 ERR("GetCurrentPrintSettings failed: %08x\n", nsres
);
259 set_default_templates(settings
);
262 switch(V_VT(pvaIn
)) {
263 case VT_BYREF
|VT_ARRAY
: {
267 if(V_ARRAY(pvaIn
)->cDims
!= 1)
268 WARN("cDims = %d\n", V_ARRAY(pvaIn
)->cDims
);
270 SafeArrayAccessData(V_ARRAY(pvaIn
), (void**)&opts
);
271 opts_cnt
= V_ARRAY(pvaIn
)->rgsabound
[0].cElements
;
276 TRACE("setting footer %s\n", debugstr_w(V_BSTR(opts
)));
277 set_print_template(settings
, V_BSTR(opts
), TRUE
);
282 WARN("opts = %s\n", debugstr_variant(opts
));
287 switch(V_VT(opts
+1)) {
289 TRACE("setting footer %s\n", debugstr_w(V_BSTR(opts
+1)));
290 set_print_template(settings
, V_BSTR(opts
+1), FALSE
);
295 WARN("opts[1] = %s\n", debugstr_variant(opts
+1));
300 FIXME("Unsupported opts_cnt %d\n", opts_cnt
);
302 SafeArrayUnaccessData(V_ARRAY(pvaIn
));
306 FIXME("unsupported arg %s\n", debugstr_variant(pvaIn
));
310 nsres
= nsIWebBrowserPrint_Print(nsprint
, settings
, NULL
);
312 ERR("Print failed: %08x\n", nsres
);
314 nsIWebBrowserPrint_Release(nsprint
);
319 static HRESULT
exec_print_preview(HTMLDocumentNode
*doc
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
321 FIXME("(%p)->(%d %p %p)\n", doc
, nCmdexecopt
, pvaIn
, pvaOut
);
325 static HRESULT
exec_page_setup(HTMLDocumentNode
*doc
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
327 FIXME("(%p)->(%d %p %p)\n", doc
, nCmdexecopt
, pvaIn
, pvaOut
);
331 static HRESULT
exec_spell(HTMLDocumentNode
*doc
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
333 FIXME("(%p)->(%d %p %p)\n", doc
, nCmdexecopt
, pvaIn
, pvaOut
);
337 static HRESULT
exec_properties(HTMLDocumentNode
*doc
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
339 FIXME("(%p)->(%d %p %p)\n", doc
, nCmdexecopt
, pvaIn
, pvaOut
);
343 static HRESULT
exec_cut(HTMLDocumentNode
*doc
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
345 FIXME("(%p)->(%d %p %p)\n", doc
, nCmdexecopt
, pvaIn
, pvaOut
);
349 static HRESULT
exec_copy(HTMLDocumentNode
*doc
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
351 TRACE("(%p)->(%d %s %p)\n", doc
, nCmdexecopt
, debugstr_variant(pvaIn
), pvaOut
);
353 do_ns_command(doc
, NSCMD_COPY
, NULL
);
357 static HRESULT
exec_paste(HTMLDocumentNode
*doc
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
359 FIXME("(%p)->(%d %p %p)\n", doc
, nCmdexecopt
, pvaIn
, pvaOut
);
363 static HRESULT
exec_paste_special(HTMLDocumentNode
*doc
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
365 FIXME("(%p)->(%d %p %p)\n", doc
, nCmdexecopt
, pvaIn
, pvaOut
);
369 static HRESULT
exec_undo(HTMLDocumentNode
*doc
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
371 FIXME("(%p)->(%d %p %p)\n", doc
, nCmdexecopt
, pvaIn
, pvaOut
);
375 static HRESULT
exec_rendo(HTMLDocumentNode
*doc
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
377 FIXME("(%p)->(%d %p %p)\n", doc
, nCmdexecopt
, pvaIn
, pvaOut
);
381 static HRESULT
exec_select_all(HTMLDocumentNode
*doc
, DWORD nCmdexecopt
, VARIANT
*in
, VARIANT
*out
)
383 TRACE("(%p)\n", doc
);
386 FIXME("unsupported args\n");
391 do_ns_command(doc
, NSCMD_SELECTALL
, NULL
);
392 update_doc(doc
->browser
->doc
, UPDATE_UI
);
396 static HRESULT
exec_clear_selection(HTMLDocumentNode
*doc
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
398 FIXME("(%p)->(%d %p %p)\n", doc
, nCmdexecopt
, pvaIn
, pvaOut
);
402 static HRESULT
exec_zoom(HTMLDocumentNode
*doc
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
404 FIXME("(%p)->(%d %p %p)\n", doc
, nCmdexecopt
, pvaIn
, pvaOut
);
408 static HRESULT
exec_get_zoom_range(HTMLDocumentNode
*doc
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
410 FIXME("(%p)->(%d %p %p)\n", doc
, nCmdexecopt
, pvaIn
, pvaOut
);
416 HTMLOuterWindow
*window
;
419 static void refresh_proc(task_t
*_task
)
421 refresh_task_t
*task
= (refresh_task_t
*)_task
;
422 HTMLOuterWindow
*window
= task
->window
;
424 TRACE("%p\n", window
);
426 window
->readystate
= READYSTATE_UNINITIALIZED
;
428 if(window
->browser
&& window
->browser
->doc
->client_cmdtrg
) {
433 IOleCommandTarget_Exec(window
->browser
->doc
->client_cmdtrg
, &CGID_ShellDocView
, 37, 0, &var
, NULL
);
436 load_uri(task
->window
, task
->window
->uri
, BINDING_REFRESH
|BINDING_NOFRAG
);
439 static void refresh_destr(task_t
*_task
)
441 refresh_task_t
*task
= (refresh_task_t
*)_task
;
443 IHTMLWindow2_Release(&task
->window
->base
.IHTMLWindow2_iface
);
447 static HRESULT
exec_refresh(HTMLDocumentNode
*doc
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
449 HTMLDocumentObj
*doc_obj
;
450 refresh_task_t
*task
;
453 TRACE("(%p)->(%d %s %p)\n", doc
, nCmdexecopt
, debugstr_variant(pvaIn
), pvaOut
);
455 if(doc
!= doc
->browser
->doc
->basedoc
.doc_node
) {
456 FIXME("Unsupported on frame documents\n");
459 doc_obj
= doc
->browser
->doc
;
461 if(doc_obj
->client
) {
462 IOleCommandTarget
*olecmd
;
464 hres
= IOleClientSite_QueryInterface(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
);
473 if(!doc
->basedoc
.window
)
476 task
= heap_alloc(sizeof(*task
));
478 return E_OUTOFMEMORY
;
480 IHTMLWindow2_AddRef(&doc
->basedoc
.window
->base
.IHTMLWindow2_iface
);
481 task
->window
= doc
->basedoc
.window
;
483 return push_task(&task
->header
, refresh_proc
, refresh_destr
, doc
->basedoc
.window
->task_magic
);
486 static HRESULT
exec_stop(HTMLDocumentNode
*doc
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
488 FIXME("(%p)->(%d %p %p)\n", doc
, nCmdexecopt
, pvaIn
, pvaOut
);
492 static HRESULT
exec_stop_download(HTMLDocumentNode
*doc
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
494 FIXME("(%p)->(%d %p %p)\n", doc
, nCmdexecopt
, pvaIn
, pvaOut
);
498 static HRESULT
exec_find(HTMLDocumentNode
*doc
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
500 FIXME("(%p)->(%d %p %p)\n", doc
, nCmdexecopt
, pvaIn
, pvaOut
);
504 static HRESULT
exec_delete(HTMLDocumentNode
*doc
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
506 FIXME("(%p)->(%d %p %p)\n", doc
, nCmdexecopt
, pvaIn
, pvaOut
);
510 static HRESULT
exec_enable_interaction(HTMLDocumentNode
*doc
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
512 FIXME("(%p)->(%d %p %p)\n", doc
, nCmdexecopt
, pvaIn
, pvaOut
);
516 static HRESULT
exec_on_unload(HTMLDocumentNode
*doc
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
518 TRACE("(%p)->(%d %p %p)\n", doc
, 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(HTMLDocumentNode
*doc
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
532 FIXME("(%p)->(%d %p %p)\n", doc
, nCmdexecopt
, pvaIn
, pvaOut
);
536 static HRESULT
exec_show_print(HTMLDocumentNode
*doc
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
538 FIXME("(%p)->(%d %p %p)\n", doc
, nCmdexecopt
, pvaIn
, pvaOut
);
542 static HRESULT
exec_close(HTMLDocumentNode
*doc
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
544 FIXME("(%p)->(%d %p %p)\n", doc
, nCmdexecopt
, pvaIn
, pvaOut
);
548 static HRESULT
exec_set_print_template(HTMLDocumentNode
*doc
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
550 FIXME("(%p)->(%d %p %p)\n", doc
, nCmdexecopt
, pvaIn
, pvaOut
);
554 static HRESULT
exec_get_print_template(HTMLDocumentNode
*doc
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
556 FIXME("(%p)->(%d %p %p)\n", doc
, nCmdexecopt
, pvaIn
, pvaOut
);
560 static HRESULT
exec_optical_zoom(HTMLDocumentNode
*doc
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
562 TRACE("(%p)->(%d %s %p)\n", doc
, nCmdexecopt
, debugstr_variant(pvaIn
), pvaOut
);
564 if(pvaIn
&& V_VT(pvaIn
) != VT_I4
) {
565 FIXME("Unsupported argument %s\n", debugstr_variant(pvaIn
));
570 set_viewer_zoom(doc
->browser
, (float)V_I4(pvaIn
)/100);
572 V_VT(pvaOut
) = VT_I4
;
573 V_I4(pvaOut
) = get_viewer_zoom(doc
->browser
) * 100;
578 static HRESULT
query_mshtml_copy(HTMLDocumentNode
*doc
, OLECMD
*cmd
)
580 FIXME("(%p)\n", doc
);
581 cmd
->cmdf
= OLECMDF_SUPPORTED
|OLECMDF_ENABLED
;
585 static HRESULT
exec_mshtml_copy(HTMLDocumentNode
*doc
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
587 TRACE("(%p)->(%08x %p %p)\n", doc
, cmdexecopt
, in
, out
);
589 if(doc
->browser
->usermode
== EDITMODE
)
590 return editor_exec_copy(doc
, cmdexecopt
, in
, out
);
592 do_ns_command(doc
, NSCMD_COPY
, NULL
);
596 static HRESULT
query_mshtml_cut(HTMLDocumentNode
*doc
, OLECMD
*cmd
)
598 FIXME("(%p)\n", doc
);
599 cmd
->cmdf
= OLECMDF_SUPPORTED
|OLECMDF_ENABLED
;
603 static HRESULT
exec_mshtml_cut(HTMLDocumentNode
*doc
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
605 nsIClipboardCommands
*clipboard_commands
;
608 TRACE("(%p)->(%08x %p %p)\n", doc
, cmdexecopt
, in
, out
);
610 if(doc
->browser
->usermode
== EDITMODE
)
611 return editor_exec_cut(doc
, cmdexecopt
, in
, out
);
613 clipboard_commands
= get_clipboard_commands(doc
);
614 if(!clipboard_commands
)
617 nsres
= nsIClipboardCommands_CutSelection(clipboard_commands
);
618 nsIClipboardCommands_Release(clipboard_commands
);
619 if(NS_FAILED(nsres
)) {
620 ERR("Paste failed: %08x\n", nsres
);
627 static HRESULT
query_mshtml_paste(HTMLDocumentNode
*doc
, OLECMD
*cmd
)
629 FIXME("(%p)\n", doc
);
630 cmd
->cmdf
= OLECMDF_SUPPORTED
|OLECMDF_ENABLED
;
634 static HRESULT
exec_mshtml_paste(HTMLDocumentNode
*doc
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
636 nsIClipboardCommands
*clipboard_commands
;
639 TRACE("(%p)->(%08x %p %p)\n", doc
, cmdexecopt
, in
, out
);
641 if(doc
->browser
->usermode
== EDITMODE
)
642 return editor_exec_paste(doc
, cmdexecopt
, in
, out
);
644 clipboard_commands
= get_clipboard_commands(doc
);
645 if(!clipboard_commands
)
648 nsres
= nsIClipboardCommands_Paste(clipboard_commands
);
649 nsIClipboardCommands_Release(clipboard_commands
);
650 if(NS_FAILED(nsres
)) {
651 ERR("Paste failed: %08x\n", nsres
);
658 static HRESULT
query_selall_status(HTMLDocumentNode
*doc
, OLECMD
*cmd
)
660 TRACE("(%p)->(%p)\n", doc
, cmd
);
662 cmd
->cmdf
= OLECMDF_SUPPORTED
|OLECMDF_ENABLED
;
666 static HRESULT
exec_browsemode(HTMLDocumentNode
*doc
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
668 WARN("(%p)->(%08x %p %p)\n", doc
, cmdexecopt
, in
, out
);
671 FIXME("unsupported args\n");
673 doc
->browser
->usermode
= BROWSEMODE
;
678 static HRESULT
exec_editmode(HTMLDocumentNode
*doc
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
680 TRACE("(%p)->(%08x %p %p)\n", doc
, cmdexecopt
, in
, out
);
683 FIXME("unsupported args\n");
685 return setup_edit_mode(doc
->browser
->doc
);
688 static HRESULT
exec_htmleditmode(HTMLDocumentNode
*doc
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
690 FIXME("(%p)->(%08x %p %p)\n", doc
, cmdexecopt
, in
, out
);
694 static HRESULT
exec_baselinefont3(HTMLDocumentNode
*doc
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
696 FIXME("(%p)->(%08x %p %p)\n", doc
, cmdexecopt
, in
, out
);
700 static HRESULT
exec_respectvisibility_indesign(HTMLDocumentNode
*doc
, DWORD cmdexecopt
,
701 VARIANT
*in
, VARIANT
*out
)
703 TRACE("(%p)->(%x %s %p)\n", doc
, cmdexecopt
, debugstr_variant(in
), out
);
705 /* This is turned on by default in Gecko. */
706 if(!in
|| V_VT(in
) != VT_BOOL
|| !V_BOOL(in
))
707 FIXME("Unsupported argument %s\n", debugstr_variant(in
));
712 static HRESULT
query_enabled_stub(HTMLDocumentNode
*doc
, OLECMD
*cmd
)
716 FIXME("CGID_MSHTML: IDM_PRINT\n");
717 cmd
->cmdf
= OLECMDF_SUPPORTED
|OLECMDF_ENABLED
;
719 case IDM_BLOCKDIRLTR
:
720 FIXME("CGID_MSHTML: IDM_BLOCKDIRLTR\n");
721 cmd
->cmdf
= OLECMDF_SUPPORTED
|OLECMDF_ENABLED
;
723 case IDM_BLOCKDIRRTL
:
724 FIXME("CGID_MSHTML: IDM_BLOCKDIRRTL\n");
725 cmd
->cmdf
= OLECMDF_SUPPORTED
|OLECMDF_ENABLED
;
732 static const struct {
734 HRESULT (*func
)(HTMLDocumentNode
*,DWORD
,VARIANT
*,VARIANT
*);
737 { OLECMDF_SUPPORTED
, exec_open
}, /* OLECMDID_OPEN */
738 { OLECMDF_SUPPORTED
, exec_new
}, /* OLECMDID_NEW */
739 { OLECMDF_SUPPORTED
, exec_save
}, /* OLECMDID_SAVE */
740 { OLECMDF_SUPPORTED
|OLECMDF_ENABLED
, exec_save_as
}, /* OLECMDID_SAVEAS */
741 { OLECMDF_SUPPORTED
, exec_save_copy_as
}, /* OLECMDID_SAVECOPYAS */
742 { OLECMDF_SUPPORTED
|OLECMDF_ENABLED
, exec_print
}, /* OLECMDID_PRINT */
743 { OLECMDF_SUPPORTED
|OLECMDF_ENABLED
, exec_print_preview
}, /* OLECMDID_PRINTPREVIEW */
744 { OLECMDF_SUPPORTED
|OLECMDF_ENABLED
, exec_page_setup
}, /* OLECMDID_PAGESETUP */
745 { OLECMDF_SUPPORTED
, exec_spell
}, /* OLECMDID_SPELL */
746 { OLECMDF_SUPPORTED
|OLECMDF_ENABLED
, exec_properties
}, /* OLECMDID_PROPERTIES */
747 { OLECMDF_SUPPORTED
, exec_cut
}, /* OLECMDID_CUT */
748 { OLECMDF_SUPPORTED
, exec_copy
}, /* OLECMDID_COPY */
749 { OLECMDF_SUPPORTED
, exec_paste
}, /* OLECMDID_PASTE */
750 { OLECMDF_SUPPORTED
, exec_paste_special
}, /* OLECMDID_PASTESPECIAL */
751 { OLECMDF_SUPPORTED
, exec_undo
}, /* OLECMDID_UNDO */
752 { OLECMDF_SUPPORTED
, exec_rendo
}, /* OLECMDID_REDO */
753 { OLECMDF_SUPPORTED
|OLECMDF_ENABLED
, exec_select_all
}, /* OLECMDID_SELECTALL */
754 { OLECMDF_SUPPORTED
, exec_clear_selection
}, /* OLECMDID_CLEARSELECTION */
755 { OLECMDF_SUPPORTED
, exec_zoom
}, /* OLECMDID_ZOOM */
756 { OLECMDF_SUPPORTED
, exec_get_zoom_range
}, /* OLECMDID_GETZOOMRANGE */
758 { OLECMDF_SUPPORTED
|OLECMDF_ENABLED
, exec_refresh
}, /* OLECMDID_REFRESH */
759 { OLECMDF_SUPPORTED
|OLECMDF_ENABLED
, exec_stop
}, /* OLECMDID_STOP */
760 {0},{0},{0},{0},{0},{0},
761 { OLECMDF_SUPPORTED
, exec_stop_download
}, /* OLECMDID_STOPDOWNLOAD */
763 { OLECMDF_SUPPORTED
|OLECMDF_ENABLED
, exec_find
}, /* OLECMDID_FIND */
764 { OLECMDF_SUPPORTED
, exec_delete
}, /* OLECMDID_DELETE */
766 { OLECMDF_SUPPORTED
, exec_enable_interaction
}, /* OLECMDID_ENABLE_INTERACTION */
767 { OLECMDF_SUPPORTED
, exec_on_unload
}, /* OLECMDID_ONUNLOAD */
769 { OLECMDF_SUPPORTED
, exec_show_page_setup
}, /* OLECMDID_SHOWPAGESETUP */
770 { OLECMDF_SUPPORTED
, exec_show_print
}, /* OLECMDID_SHOWPRINT */
772 { OLECMDF_SUPPORTED
, exec_close
}, /* OLECMDID_CLOSE */
774 { OLECMDF_SUPPORTED
, exec_set_print_template
}, /* OLECMDID_SETPRINTTEMPLATE */
775 { OLECMDF_SUPPORTED
, exec_get_print_template
}, /* OLECMDID_GETPRINTTEMPLATE */
776 {0},{0},{0},{0},{0},{0},{0},{0},{0},{0},
777 { 0, /* not reported as supported */ exec_optical_zoom
} /* OLECMDID_OPTICAL_ZOOM */
780 static const cmdtable_t base_cmds
[] = {
781 {IDM_COPY
, query_mshtml_copy
, exec_mshtml_copy
},
782 {IDM_PASTE
, query_mshtml_paste
, exec_mshtml_paste
},
783 {IDM_CUT
, query_mshtml_cut
, exec_mshtml_cut
},
784 {IDM_SELECTALL
, query_selall_status
, exec_select_all
},
785 {IDM_BROWSEMODE
, NULL
, exec_browsemode
},
786 {IDM_EDITMODE
, NULL
, exec_editmode
},
787 {IDM_PRINT
, query_enabled_stub
, exec_print
},
788 {IDM_HTMLEDITMODE
, NULL
, exec_htmleditmode
},
789 {IDM_BASELINEFONT3
, NULL
, exec_baselinefont3
},
790 {IDM_BLOCKDIRLTR
, query_enabled_stub
, NULL
},
791 {IDM_BLOCKDIRRTL
, query_enabled_stub
, NULL
},
792 {IDM_RESPECTVISIBILITY_INDESIGN
, NULL
, exec_respectvisibility_indesign
},
796 static HRESULT WINAPI
OleCommandTarget_QueryInterface(IOleCommandTarget
*iface
, REFIID riid
, void **ppv
)
798 HTMLDocument
*This
= impl_from_IOleCommandTarget(iface
);
799 return htmldoc_query_interface(This
, riid
, ppv
);
802 static ULONG WINAPI
OleCommandTarget_AddRef(IOleCommandTarget
*iface
)
804 HTMLDocument
*This
= impl_from_IOleCommandTarget(iface
);
805 return htmldoc_addref(This
);
808 static ULONG WINAPI
OleCommandTarget_Release(IOleCommandTarget
*iface
)
810 HTMLDocument
*This
= impl_from_IOleCommandTarget(iface
);
811 return htmldoc_release(This
);
814 static HRESULT
query_from_table(HTMLDocumentNode
*doc
, const cmdtable_t
*cmdtable
, OLECMD
*cmd
)
816 const cmdtable_t
*iter
= cmdtable
;
820 while(iter
->id
&& iter
->id
!= cmd
->cmdID
)
823 if(!iter
->id
|| !iter
->query
)
824 return OLECMDERR_E_NOTSUPPORTED
;
826 return iter
->query(doc
, cmd
);
829 static HRESULT WINAPI
OleCommandTarget_QueryStatus(IOleCommandTarget
*iface
, const GUID
*pguidCmdGroup
,
830 ULONG cCmds
, OLECMD prgCmds
[], OLECMDTEXT
*pCmdText
)
832 HTMLDocument
*This
= impl_from_IOleCommandTarget(iface
);
835 TRACE("(%p)->(%s %d %p %p)\n", This
, debugstr_guid(pguidCmdGroup
), cCmds
, prgCmds
, pCmdText
);
838 FIXME("Unsupported pCmdText\n");
839 if(!This
->doc_node
->browser
)
847 for(i
=0; i
<cCmds
; i
++) {
848 if(prgCmds
[i
].cmdID
< OLECMDID_OPEN
|| prgCmds
[i
].cmdID
>= ARRAY_SIZE(exec_table
)) {
849 WARN("Unsupported cmdID = %d\n", prgCmds
[i
].cmdID
);
852 if(prgCmds
[i
].cmdID
== OLECMDID_OPEN
|| prgCmds
[i
].cmdID
== OLECMDID_NEW
) {
853 IOleCommandTarget
*cmdtrg
= NULL
;
856 prgCmds
[i
].cmdf
= OLECMDF_SUPPORTED
;
857 if(This
->doc_obj
->client
) {
858 hres
= IOleClientSite_QueryInterface(This
->doc_obj
->client
, &IID_IOleCommandTarget
,
860 if(SUCCEEDED(hres
)) {
861 olecmd
.cmdID
= prgCmds
[i
].cmdID
;
864 hres
= IOleCommandTarget_QueryStatus(cmdtrg
, NULL
, 1, &olecmd
, NULL
);
865 if(SUCCEEDED(hres
) && olecmd
.cmdf
)
866 prgCmds
[i
].cmdf
= olecmd
.cmdf
;
869 ERR("This->client == NULL, native would crash\n");
872 prgCmds
[i
].cmdf
= exec_table
[prgCmds
[i
].cmdID
].cmdf
;
873 TRACE("cmdID = %d returning %x\n", prgCmds
[i
].cmdID
, prgCmds
[i
].cmdf
);
878 return (prgCmds
[cCmds
-1].cmdf
& OLECMDF_SUPPORTED
) ? S_OK
: OLECMDERR_E_NOTSUPPORTED
;
881 if(IsEqualGUID(&CGID_MSHTML
, pguidCmdGroup
)) {
884 for(i
=0; i
<cCmds
; i
++) {
885 hres
= query_from_table(This
->doc_node
, base_cmds
, prgCmds
+i
);
886 if(hres
== OLECMDERR_E_NOTSUPPORTED
)
887 hres
= query_from_table(This
->doc_node
, editmode_cmds
, prgCmds
+i
);
888 if(hres
== OLECMDERR_E_NOTSUPPORTED
)
889 FIXME("CGID_MSHTML: unsupported cmdID %d\n", prgCmds
[i
].cmdID
);
892 return (prgCmds
[cCmds
-1].cmdf
& OLECMDF_SUPPORTED
) ? S_OK
: OLECMDERR_E_NOTSUPPORTED
;
895 FIXME("Unsupported pguidCmdGroup %s\n", debugstr_guid(pguidCmdGroup
));
896 return OLECMDERR_E_UNKNOWNGROUP
;
899 static HRESULT
exec_from_table(HTMLDocumentNode
*doc
, const cmdtable_t
*cmdtable
, DWORD cmdid
,
900 DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
902 const cmdtable_t
*iter
= cmdtable
;
904 while(iter
->id
&& iter
->id
!= cmdid
)
907 if(!iter
->id
|| !iter
->exec
)
908 return OLECMDERR_E_NOTSUPPORTED
;
910 return iter
->exec(doc
, cmdexecopt
, in
, out
);
913 static HRESULT WINAPI
OleCommandTarget_Exec(IOleCommandTarget
*iface
, const GUID
*pguidCmdGroup
,
914 DWORD nCmdID
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
916 HTMLDocument
*This
= impl_from_IOleCommandTarget(iface
);
918 TRACE("(%p)->(%s %d %d %s %p)\n", This
, debugstr_guid(pguidCmdGroup
), nCmdID
, nCmdexecopt
, wine_dbgstr_variant(pvaIn
), pvaOut
);
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
;