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"
33 #include "wine/unicode.h"
35 #include "mshtml_private.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(mshtml
);
40 #define NSCMD_COPY "cmd_copy"
42 void do_ns_command(HTMLDocument
*This
, const char *cmd
, nsICommandParams
*nsparam
)
44 nsICommandManager
*cmdmgr
;
47 TRACE("(%p)\n", This
);
49 if(!This
->doc_obj
|| !This
->doc_obj
->nscontainer
)
52 nsres
= get_nsinterface((nsISupports
*)This
->doc_obj
->nscontainer
->webbrowser
, &IID_nsICommandManager
, (void**)&cmdmgr
);
53 if(NS_FAILED(nsres
)) {
54 ERR("Could not get nsICommandManager: %08x\n", nsres
);
58 nsres
= nsICommandManager_DoCommand(cmdmgr
, cmd
, nsparam
, This
->window
->nswindow
);
60 ERR("DoCommand(%s) failed: %08x\n", debugstr_a(cmd
), nsres
);
62 nsICommandManager_Release(cmdmgr
);
65 /**********************************************************
66 * IOleCommandTarget implementation
69 #define CMDTARGET_THIS(iface) DEFINE_THIS(HTMLDocument, OleCommandTarget, iface)
71 static HRESULT
exec_open(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
73 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
77 static HRESULT
exec_new(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
79 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
83 static HRESULT
exec_save(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
85 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
89 static HRESULT
exec_save_as(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
91 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
95 static HRESULT
exec_save_copy_as(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
97 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
101 static nsresult
set_head_text(nsIPrintSettings
*settings
, LPCWSTR
template, BOOL head
, int pos
)
106 return nsIPrintSettings_SetHeaderStrLeft(settings
, template);
108 return nsIPrintSettings_SetHeaderStrRight(settings
, template);
110 return nsIPrintSettings_SetHeaderStrCenter(settings
, template);
115 return nsIPrintSettings_SetFooterStrLeft(settings
, template);
117 return nsIPrintSettings_SetFooterStrRight(settings
, template);
119 return nsIPrintSettings_SetFooterStrCenter(settings
, template);
126 static void set_print_template(nsIPrintSettings
*settings
, LPCWSTR
template, BOOL head
)
128 PRUnichar nstemplate
[200]; /* FIXME: Use dynamic allocation */
129 PRUnichar
*p
= nstemplate
;
130 LPCWSTR ptr
=template;
145 case 'b': /* change align */
148 set_head_text(settings
, nstemplate
, head
, pos
);
152 case 'd': { /* short date */
154 GetLocalTime(&systime
);
155 GetDateFormatW(LOCALE_SYSTEM_DEFAULT
, 0, &systime
, NULL
, p
,
156 sizeof(nstemplate
)-(p
-nstemplate
)*sizeof(WCHAR
));
161 case 'p': /* page number */
166 case 'P': /* page count */
167 *p
++ = '?'; /* FIXME */
176 /* FIXME: set window title */
186 set_head_text(settings
, nstemplate
, head
, pos
);
189 set_head_text(settings
, p
, head
, pos
);
192 static void set_default_templates(nsIPrintSettings
*settings
)
196 static const PRUnichar empty
[] = {0};
198 nsIPrintSettings_SetHeaderStrLeft(settings
, empty
);
199 nsIPrintSettings_SetHeaderStrRight(settings
, empty
);
200 nsIPrintSettings_SetHeaderStrCenter(settings
, empty
);
201 nsIPrintSettings_SetFooterStrLeft(settings
, empty
);
202 nsIPrintSettings_SetFooterStrRight(settings
, empty
);
203 nsIPrintSettings_SetFooterStrCenter(settings
, empty
);
205 if(LoadStringW(get_shdoclc(), IDS_PRINT_HEADER_TEMPLATE
, buf
,
206 sizeof(buf
)/sizeof(WCHAR
)))
207 set_print_template(settings
, buf
, TRUE
);
210 if(LoadStringW(get_shdoclc(), IDS_PRINT_FOOTER_TEMPLATE
, buf
,
211 sizeof(buf
)/sizeof(WCHAR
)))
212 set_print_template(settings
, buf
, FALSE
);
216 static HRESULT
exec_print(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
218 nsIWebBrowserPrint
*nsprint
;
219 nsIPrintSettings
*settings
;
222 TRACE("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
225 FIXME("unsupported pvaOut\n");
227 if(!This
->doc_obj
->nscontainer
)
230 nsres
= get_nsinterface((nsISupports
*)This
->doc_obj
->nscontainer
->webbrowser
, &IID_nsIWebBrowserPrint
,
232 if(NS_FAILED(nsres
)) {
233 ERR("Could not get nsIWebBrowserPrint: %08x\n", nsres
);
237 nsres
= nsIWebBrowserPrint_GetGlobalPrintSettings(nsprint
, &settings
);
239 ERR("GetCurrentPrintSettings failed: %08x\n", nsres
);
241 set_default_templates(settings
);
244 switch(V_VT(pvaIn
)) {
245 case VT_BYREF
|VT_ARRAY
: {
249 if(V_ARRAY(pvaIn
)->cDims
!= 1)
250 WARN("cDims = %d\n", V_ARRAY(pvaIn
)->cDims
);
252 SafeArrayAccessData(V_ARRAY(pvaIn
), (void**)&opts
);
253 opts_cnt
= V_ARRAY(pvaIn
)->rgsabound
[0].cElements
;
258 TRACE("setting footer %s\n", debugstr_w(V_BSTR(opts
)));
259 set_print_template(settings
, V_BSTR(opts
), TRUE
);
264 WARN("V_VT(opts) = %d\n", V_VT(opts
));
269 switch(V_VT(opts
+1)) {
271 TRACE("setting footer %s\n", debugstr_w(V_BSTR(opts
+1)));
272 set_print_template(settings
, V_BSTR(opts
+1), FALSE
);
277 WARN("V_VT(opts) = %d\n", V_VT(opts
+1));
282 FIXME("Unsupported opts_cnt %d\n", opts_cnt
);
284 SafeArrayUnaccessData(V_ARRAY(pvaIn
));
288 FIXME("unsupported vt %x\n", V_VT(pvaIn
));
292 nsres
= nsIWebBrowserPrint_Print(nsprint
, settings
, NULL
);
294 ERR("Print failed: %08x\n", nsres
);
296 nsIWebBrowserPrint_Release(nsprint
);
301 static HRESULT
exec_print_preview(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
303 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
307 static HRESULT
exec_page_setup(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
309 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
313 static HRESULT
exec_spell(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
315 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
319 static HRESULT
exec_properties(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
321 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
325 static HRESULT
exec_cut(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
327 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
331 static HRESULT
exec_copy(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
333 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
337 static HRESULT
exec_paste(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
339 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
343 static HRESULT
exec_paste_special(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
345 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
349 static HRESULT
exec_undo(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
351 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
355 static HRESULT
exec_rendo(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
357 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
361 static HRESULT
exec_select_all(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
363 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
367 static HRESULT
exec_clear_selection(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
369 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
373 static HRESULT
exec_zoom(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
375 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
379 static HRESULT
exec_get_zoom_range(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
381 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
385 static HRESULT
exec_refresh(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
387 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
391 static HRESULT
exec_stop(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
393 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
397 static HRESULT
exec_stop_download(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
399 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
403 static HRESULT
exec_find(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
405 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
409 static HRESULT
exec_delete(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
411 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
415 static HRESULT
exec_enable_interaction(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
417 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
421 static HRESULT
exec_on_unload(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
423 TRACE("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
425 /* Tests show that we have nothing more to do here */
428 V_VT(pvaOut
) = VT_BOOL
;
429 V_BOOL(pvaOut
) = VARIANT_TRUE
;
435 static HRESULT
exec_show_page_setup(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
437 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
441 static HRESULT
exec_show_print(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
443 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
447 static HRESULT
exec_close(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
449 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
453 static HRESULT
exec_set_print_template(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
455 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
459 static HRESULT
exec_get_print_template(HTMLDocument
*This
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
461 FIXME("(%p)->(%d %p %p)\n", This
, nCmdexecopt
, pvaIn
, pvaOut
);
465 static HRESULT
query_mshtml_copy(HTMLDocument
*This
, OLECMD
*cmd
)
467 FIXME("(%p)\n", This
);
468 cmd
->cmdf
= OLECMDF_SUPPORTED
|OLECMDF_ENABLED
;
472 static HRESULT
exec_mshtml_copy(HTMLDocument
*This
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
474 TRACE("(%p)->(%08x %p %p)\n", This
, cmdexecopt
, in
, out
);
476 if(This
->doc_obj
->usermode
== EDITMODE
)
477 return editor_exec_copy(This
, cmdexecopt
, in
, out
);
479 do_ns_command(This
, NSCMD_COPY
, NULL
);
483 static HRESULT
query_mshtml_cut(HTMLDocument
*This
, OLECMD
*cmd
)
485 FIXME("(%p)\n", This
);
486 cmd
->cmdf
= OLECMDF_SUPPORTED
|OLECMDF_ENABLED
;
490 static HRESULT
exec_mshtml_cut(HTMLDocument
*This
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
492 TRACE("(%p)->(%08x %p %p)\n", This
, cmdexecopt
, in
, out
);
494 if(This
->doc_obj
->usermode
== EDITMODE
)
495 return editor_exec_cut(This
, cmdexecopt
, in
, out
);
497 FIXME("Unimplemented in browse mode\n");
501 static HRESULT
query_mshtml_paste(HTMLDocument
*This
, OLECMD
*cmd
)
503 FIXME("(%p)\n", This
);
504 cmd
->cmdf
= OLECMDF_SUPPORTED
|OLECMDF_ENABLED
;
508 static HRESULT
exec_mshtml_paste(HTMLDocument
*This
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
510 TRACE("(%p)->(%08x %p %p)\n", This
, cmdexecopt
, in
, out
);
512 if(This
->doc_obj
->usermode
== EDITMODE
)
513 return editor_exec_paste(This
, cmdexecopt
, in
, out
);
515 FIXME("Unimplemented in browse mode\n");
519 static HRESULT
exec_browsemode(HTMLDocument
*This
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
521 WARN("(%p)->(%08x %p %p)\n", This
, cmdexecopt
, in
, out
);
524 FIXME("unsupported args\n");
526 This
->doc_obj
->usermode
= BROWSEMODE
;
531 static HRESULT
exec_editmode(HTMLDocument
*This
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
536 TRACE("(%p)->(%08x %p %p)\n", This
, cmdexecopt
, in
, out
);
539 FIXME("unsupported args\n");
541 if(This
->doc_obj
->usermode
== EDITMODE
)
544 This
->doc_obj
->usermode
= EDITMODE
;
546 if(This
->window
->mon
) {
547 CLSID clsid
= IID_NULL
;
548 hres
= IMoniker_GetClassID(This
->window
->mon
, &clsid
);
549 if(SUCCEEDED(hres
)) {
550 /* We should use IMoniker::Save here */
551 FIXME("Use CLSID %s\n", debugstr_guid(&clsid
));
555 if(This
->doc_obj
->frame
)
556 IOleInPlaceFrame_SetStatusText(This
->doc_obj
->frame
, NULL
);
558 This
->window
->readystate
= READYSTATE_UNINITIALIZED
;
560 if(This
->doc_obj
->client
) {
561 IOleCommandTarget
*cmdtrg
;
563 hres
= IOleClientSite_QueryInterface(This
->doc_obj
->client
, &IID_IOleCommandTarget
,
565 if(SUCCEEDED(hres
)) {
570 IOleCommandTarget_Exec(cmdtrg
, &CGID_ShellDocView
, 37, 0, &var
, NULL
);
572 IOleCommandTarget_Release(cmdtrg
);
576 if(This
->doc_obj
->hostui
) {
577 DOCHOSTUIINFO hostinfo
;
579 memset(&hostinfo
, 0, sizeof(DOCHOSTUIINFO
));
580 hostinfo
.cbSize
= sizeof(DOCHOSTUIINFO
);
581 hres
= IDocHostUIHandler_GetHostInfo(This
->doc_obj
->hostui
, &hostinfo
);
583 /* FIXME: use hostinfo */
584 TRACE("hostinfo = {%u %08x %08x %s %s}\n",
585 hostinfo
.cbSize
, hostinfo
.dwFlags
, hostinfo
.dwDoubleClick
,
586 debugstr_w(hostinfo
.pchHostCss
), debugstr_w(hostinfo
.pchHostNS
));
589 update_doc(This
, UPDATE_UI
);
591 if(This
->window
->mon
) {
592 /* FIXME: We should find nicer way to do this */
593 remove_target_tasks(This
->task_magic
);
595 mon
= This
->window
->mon
;
596 IMoniker_AddRef(mon
);
598 static const WCHAR about_blankW
[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
600 hres
= CreateURLMoniker(NULL
, about_blankW
, &mon
);
602 FIXME("CreateURLMoniker failed: %08x\n", hres
);
607 hres
= IPersistMoniker_Load(PERSISTMON(This
), TRUE
, mon
, NULL
, 0);
608 IMoniker_Release(mon
);
612 if(This
->doc_obj
->ui_active
) {
613 if(This
->doc_obj
->ip_window
)
614 call_set_active_object(This
->doc_obj
->ip_window
, NULL
);
615 if(This
->doc_obj
->hostui
)
616 IDocHostUIHandler_HideUI(This
->doc_obj
->hostui
);
619 if(This
->doc_obj
->nscontainer
)
620 set_ns_editmode(This
->doc_obj
->nscontainer
);
622 if(This
->doc_obj
->ui_active
) {
625 if(This
->doc_obj
->hostui
)
626 IDocHostUIHandler_ShowUI(This
->doc_obj
->hostui
, DOCHOSTUITYPE_AUTHOR
, ACTOBJ(This
), CMDTARGET(This
),
627 This
->doc_obj
->frame
, This
->doc_obj
->ip_window
);
629 if(This
->doc_obj
->ip_window
)
630 call_set_active_object(This
->doc_obj
->ip_window
, ACTOBJ(This
));
632 memset(&rcBorderWidths
, 0, sizeof(rcBorderWidths
));
633 if(This
->doc_obj
->frame
)
634 IOleInPlaceFrame_SetBorderSpace(This
->doc_obj
->frame
, &rcBorderWidths
);
640 static HRESULT
exec_htmleditmode(HTMLDocument
*This
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
642 FIXME("(%p)->(%08x %p %p)\n", This
, cmdexecopt
, in
, out
);
646 static HRESULT
exec_baselinefont3(HTMLDocument
*This
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
648 FIXME("(%p)->(%08x %p %p)\n", This
, cmdexecopt
, in
, out
);
652 static HRESULT
exec_respectvisibility_indesign(HTMLDocument
*This
, DWORD cmdexecopt
,
653 VARIANT
*in
, VARIANT
*out
)
655 FIXME("(%p)->(%08x %p %p)\n", This
, cmdexecopt
, in
, out
);
659 static HRESULT
query_enabled_stub(HTMLDocument
*This
, OLECMD
*cmd
)
663 FIXME("CGID_MSHTML: IDM_PRINT\n");
664 cmd
->cmdf
= OLECMDF_SUPPORTED
|OLECMDF_ENABLED
;
666 case IDM_BLOCKDIRLTR
:
667 FIXME("CGID_MSHTML: IDM_BLOCKDIRLTR\n");
668 cmd
->cmdf
= OLECMDF_SUPPORTED
|OLECMDF_ENABLED
;
670 case IDM_BLOCKDIRRTL
:
671 FIXME("CGID_MSHTML: IDM_BLOCKDIRRTL\n");
672 cmd
->cmdf
= OLECMDF_SUPPORTED
|OLECMDF_ENABLED
;
679 static const struct {
681 HRESULT (*func
)(HTMLDocument
*,DWORD
,VARIANT
*,VARIANT
*);
682 } exec_table
[OLECMDID_GETPRINTTEMPLATE
+1] = {
684 { OLECMDF_SUPPORTED
, exec_open
}, /* OLECMDID_OPEN */
685 { OLECMDF_SUPPORTED
, exec_new
}, /* OLECMDID_NEW */
686 { OLECMDF_SUPPORTED
, exec_save
}, /* OLECMDID_SAVE */
687 { OLECMDF_SUPPORTED
|OLECMDF_ENABLED
, exec_save_as
}, /* OLECMDID_SAVEAS */
688 { OLECMDF_SUPPORTED
, exec_save_copy_as
}, /* OLECMDID_SAVECOPYAS */
689 { OLECMDF_SUPPORTED
|OLECMDF_ENABLED
, exec_print
}, /* OLECMDID_PRINT */
690 { OLECMDF_SUPPORTED
|OLECMDF_ENABLED
, exec_print_preview
}, /* OLECMDID_PRINTPREVIEW */
691 { OLECMDF_SUPPORTED
|OLECMDF_ENABLED
, exec_page_setup
}, /* OLECMDID_PAGESETUP */
692 { OLECMDF_SUPPORTED
, exec_spell
}, /* OLECMDID_SPELL */
693 { OLECMDF_SUPPORTED
|OLECMDF_ENABLED
, exec_properties
}, /* OLECMDID_PROPERTIES */
694 { OLECMDF_SUPPORTED
, exec_cut
}, /* OLECMDID_CUT */
695 { OLECMDF_SUPPORTED
, exec_copy
}, /* OLECMDID_COPY */
696 { OLECMDF_SUPPORTED
, exec_paste
}, /* OLECMDID_PASTE */
697 { OLECMDF_SUPPORTED
, exec_paste_special
}, /* OLECMDID_PASTESPECIAL */
698 { OLECMDF_SUPPORTED
, exec_undo
}, /* OLECMDID_UNDO */
699 { OLECMDF_SUPPORTED
, exec_rendo
}, /* OLECMDID_REDO */
700 { OLECMDF_SUPPORTED
|OLECMDF_ENABLED
, exec_select_all
}, /* OLECMDID_SELECTALL */
701 { OLECMDF_SUPPORTED
, exec_clear_selection
}, /* OLECMDID_CLEARSELECTION */
702 { OLECMDF_SUPPORTED
, exec_zoom
}, /* OLECMDID_ZOOM */
703 { OLECMDF_SUPPORTED
, exec_get_zoom_range
}, /* OLECMDID_GETZOOMRANGE */
705 { OLECMDF_SUPPORTED
|OLECMDF_ENABLED
, exec_refresh
}, /* OLECMDID_REFRESH */
706 { OLECMDF_SUPPORTED
|OLECMDF_ENABLED
, exec_stop
}, /* OLECMDID_STOP */
707 {0},{0},{0},{0},{0},{0},
708 { OLECMDF_SUPPORTED
, exec_stop_download
}, /* OLECMDID_STOPDOWNLOAD */
710 { OLECMDF_SUPPORTED
|OLECMDF_ENABLED
, exec_find
}, /* OLECMDID_FIND */
711 { OLECMDF_SUPPORTED
, exec_delete
}, /* OLECMDID_DELETE */
713 { OLECMDF_SUPPORTED
, exec_enable_interaction
}, /* OLECMDID_ENABLE_INTERACTION */
714 { OLECMDF_SUPPORTED
, exec_on_unload
}, /* OLECMDID_ONUNLOAD */
716 { OLECMDF_SUPPORTED
, exec_show_page_setup
}, /* OLECMDID_SHOWPAGESETUP */
717 { OLECMDF_SUPPORTED
, exec_show_print
}, /* OLECMDID_SHOWPRINT */
719 { OLECMDF_SUPPORTED
, exec_close
}, /* OLECMDID_CLOSE */
721 { OLECMDF_SUPPORTED
, exec_set_print_template
}, /* OLECMDID_SETPRINTTEMPLATE */
722 { OLECMDF_SUPPORTED
, exec_get_print_template
} /* OLECMDID_GETPRINTTEMPLATE */
725 static const cmdtable_t base_cmds
[] = {
726 {IDM_COPY
, query_mshtml_copy
, exec_mshtml_copy
},
727 {IDM_PASTE
, query_mshtml_paste
, exec_mshtml_paste
},
728 {IDM_CUT
, query_mshtml_cut
, exec_mshtml_cut
},
729 {IDM_BROWSEMODE
, NULL
, exec_browsemode
},
730 {IDM_EDITMODE
, NULL
, exec_editmode
},
731 {IDM_PRINT
, query_enabled_stub
, exec_print
},
732 {IDM_HTMLEDITMODE
, NULL
, exec_htmleditmode
},
733 {IDM_BASELINEFONT3
, NULL
, exec_baselinefont3
},
734 {IDM_BLOCKDIRLTR
, query_enabled_stub
, NULL
},
735 {IDM_BLOCKDIRRTL
, query_enabled_stub
, NULL
},
736 {IDM_RESPECTVISIBILITY_INDESIGN
, NULL
, exec_respectvisibility_indesign
},
740 static HRESULT WINAPI
OleCommandTarget_QueryInterface(IOleCommandTarget
*iface
, REFIID riid
, void **ppv
)
742 HTMLDocument
*This
= CMDTARGET_THIS(iface
);
743 return IHTMLDocument2_QueryInterface(HTMLDOC(This
), riid
, ppv
);
746 static ULONG WINAPI
OleCommandTarget_AddRef(IOleCommandTarget
*iface
)
748 HTMLDocument
*This
= CMDTARGET_THIS(iface
);
749 return IHTMLDocument2_AddRef(HTMLDOC(This
));
752 static ULONG WINAPI
OleCommandTarget_Release(IOleCommandTarget
*iface
)
754 HTMLDocument
*This
= CMDTARGET_THIS(iface
);
755 return IHTMLDocument_Release(HTMLDOC(This
));
758 static HRESULT
query_from_table(HTMLDocument
*This
, const cmdtable_t
*cmdtable
, OLECMD
*cmd
)
760 const cmdtable_t
*iter
= cmdtable
;
764 while(iter
->id
&& iter
->id
!= cmd
->cmdID
)
767 if(!iter
->id
|| !iter
->query
)
768 return OLECMDERR_E_NOTSUPPORTED
;
770 return iter
->query(This
, cmd
);
773 static HRESULT WINAPI
OleCommandTarget_QueryStatus(IOleCommandTarget
*iface
, const GUID
*pguidCmdGroup
,
774 ULONG cCmds
, OLECMD prgCmds
[], OLECMDTEXT
*pCmdText
)
776 HTMLDocument
*This
= CMDTARGET_THIS(iface
);
777 HRESULT hres
= S_OK
, hr
;
779 TRACE("(%p)->(%s %d %p %p)\n", This
, debugstr_guid(pguidCmdGroup
), cCmds
, prgCmds
, pCmdText
);
784 for(i
=0; i
<cCmds
; i
++) {
785 if(prgCmds
[i
].cmdID
<OLECMDID_OPEN
|| prgCmds
[i
].cmdID
>OLECMDID_GETPRINTTEMPLATE
) {
786 WARN("Unsupported cmdID = %d\n", prgCmds
[i
].cmdID
);
788 hres
= OLECMDERR_E_NOTSUPPORTED
;
790 if(prgCmds
[i
].cmdID
== OLECMDID_OPEN
|| prgCmds
[i
].cmdID
== OLECMDID_NEW
) {
791 IOleCommandTarget
*cmdtrg
= NULL
;
794 prgCmds
[i
].cmdf
= OLECMDF_SUPPORTED
;
795 if(This
->doc_obj
->client
) {
796 hr
= IOleClientSite_QueryInterface(This
->doc_obj
->client
, &IID_IOleCommandTarget
,
799 olecmd
.cmdID
= prgCmds
[i
].cmdID
;
802 hr
= IOleCommandTarget_QueryStatus(cmdtrg
, NULL
, 1, &olecmd
, NULL
);
803 if(SUCCEEDED(hr
) && olecmd
.cmdf
)
804 prgCmds
[i
].cmdf
= olecmd
.cmdf
;
807 ERR("This->client == NULL, native would crash\n");
810 prgCmds
[i
].cmdf
= exec_table
[prgCmds
[i
].cmdID
].cmdf
;
811 TRACE("cmdID = %d returning %x\n", prgCmds
[i
].cmdID
, prgCmds
[i
].cmdf
);
818 FIXME("Set pCmdText\n");
819 }else if(IsEqualGUID(&CGID_MSHTML
, pguidCmdGroup
)) {
822 for(i
=0; i
<cCmds
; i
++) {
823 HRESULT hres
= query_from_table(This
, base_cmds
, prgCmds
+i
);
824 if(hres
== OLECMDERR_E_NOTSUPPORTED
)
825 hres
= query_from_table(This
, editmode_cmds
, prgCmds
+i
);
826 if(hres
== OLECMDERR_E_NOTSUPPORTED
)
827 FIXME("CGID_MSHTML: unsupported cmdID %d\n", prgCmds
[i
].cmdID
);
830 hres
= prgCmds
[i
-1].cmdf
? S_OK
: OLECMDERR_E_NOTSUPPORTED
;
833 FIXME("Set pCmdText\n");
835 FIXME("Unsupported pguidCmdGroup %s\n", debugstr_guid(pguidCmdGroup
));
836 hres
= OLECMDERR_E_UNKNOWNGROUP
;
842 static HRESULT
exec_from_table(HTMLDocument
*This
, const cmdtable_t
*cmdtable
, DWORD cmdid
,
843 DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
845 const cmdtable_t
*iter
= cmdtable
;
847 while(iter
->id
&& iter
->id
!= cmdid
)
850 if(!iter
->id
|| !iter
->exec
)
851 return OLECMDERR_E_NOTSUPPORTED
;
853 return iter
->exec(This
, cmdexecopt
, in
, out
);
856 static HRESULT WINAPI
OleCommandTarget_Exec(IOleCommandTarget
*iface
, const GUID
*pguidCmdGroup
,
857 DWORD nCmdID
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
859 HTMLDocument
*This
= CMDTARGET_THIS(iface
);
862 if(nCmdID
<OLECMDID_OPEN
|| nCmdID
>OLECMDID_GETPRINTTEMPLATE
|| !exec_table
[nCmdID
].func
) {
863 WARN("Unsupported cmdID = %d\n", nCmdID
);
864 return OLECMDERR_E_NOTSUPPORTED
;
867 return exec_table
[nCmdID
].func(This
, nCmdexecopt
, pvaIn
, pvaOut
);
868 }else if(IsEqualGUID(&CGID_Explorer
, pguidCmdGroup
)) {
869 FIXME("unsupported nCmdID %d of CGID_Explorer group\n", nCmdID
);
870 TRACE("%p %p\n", pvaIn
, pvaOut
);
871 return OLECMDERR_E_NOTSUPPORTED
;
872 }else if(IsEqualGUID(&CGID_ShellDocView
, pguidCmdGroup
)) {
873 FIXME("unsupported nCmdID %d of CGID_ShellDocView group\n", nCmdID
);
874 return OLECMDERR_E_NOTSUPPORTED
;
875 }else if(IsEqualGUID(&CGID_MSHTML
, pguidCmdGroup
)) {
876 HRESULT hres
= exec_from_table(This
, base_cmds
, nCmdID
, nCmdexecopt
, pvaIn
, pvaOut
);
877 if(hres
== OLECMDERR_E_NOTSUPPORTED
)
878 hres
= exec_from_table(This
, editmode_cmds
, nCmdID
,
879 nCmdexecopt
, pvaIn
, pvaOut
);
880 if(hres
== OLECMDERR_E_NOTSUPPORTED
)
881 FIXME("unsupported nCmdID %d of CGID_MSHTML group\n", nCmdID
);
886 FIXME("Unsupported pguidCmdGroup %s\n", debugstr_guid(pguidCmdGroup
));
887 return OLECMDERR_E_UNKNOWNGROUP
;
890 #undef CMDTARGET_THIS
892 static const IOleCommandTargetVtbl OleCommandTargetVtbl
= {
893 OleCommandTarget_QueryInterface
,
894 OleCommandTarget_AddRef
,
895 OleCommandTarget_Release
,
896 OleCommandTarget_QueryStatus
,
897 OleCommandTarget_Exec
900 void show_context_menu(HTMLDocumentObj
*This
, DWORD dwID
, POINT
*ppt
, IDispatch
*elem
)
902 HMENU menu_res
, menu
;
906 hres
= IDocHostUIHandler_ShowContextMenu(This
->hostui
, dwID
, ppt
,
907 (IUnknown
*)CMDTARGET(&This
->basedoc
), elem
);
911 menu_res
= LoadMenuW(get_shdoclc(), MAKEINTRESOURCEW(IDR_BROWSE_CONTEXT_MENU
));
912 menu
= GetSubMenu(menu_res
, dwID
);
914 cmdid
= TrackPopupMenu(menu
, TPM_LEFTALIGN
| TPM_RIGHTBUTTON
| TPM_RETURNCMD
,
915 ppt
->x
, ppt
->y
, 0, This
->hwnd
, NULL
);
916 DestroyMenu(menu_res
);
919 IOleCommandTarget_Exec(CMDTARGET(&This
->basedoc
), &CGID_MSHTML
, cmdid
, 0, NULL
, NULL
);
922 void HTMLDocument_OleCmd_Init(HTMLDocument
*This
)
924 This
->lpOleCommandTargetVtbl
= &OleCommandTargetVtbl
;