reg/tests: Test import with non-standard registry file headers.
[wine.git] / dlls / mshtml / olecmd.c
blob93dab71d2cd7ad84d2c3a506b6b18898436a4cd3
1 /*
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
19 #include <stdarg.h>
21 #define COBJMACROS
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winuser.h"
26 #include "ole2.h"
27 #include "shlguid.h"
28 #include "mshtmdid.h"
29 #include "idispids.h"
30 #include "mshtmcid.h"
32 #include "wine/debug.h"
34 #include "mshtml_private.h"
35 #include "binding.h"
36 #include "resource.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;
46 nsresult nsres;
48 TRACE("(%p)\n", This);
50 if(!This->doc_obj || !This->doc_obj->nscontainer)
51 return;
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);
56 return;
59 nsres = nsICommandManager_DoCommand(cmdmgr, cmd, nsparam, This->window->window_proxy);
60 if(NS_FAILED(nsres))
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;
70 nsresult nsres;
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");
75 return NULL;
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");
82 return NULL;
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);
100 return E_NOTIMPL;
103 static HRESULT exec_new(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
105 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
106 return E_NOTIMPL;
109 static HRESULT exec_save(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
111 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
112 return E_NOTIMPL;
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);
118 return E_NOTIMPL;
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);
124 return E_NOTIMPL;
127 static nsresult set_head_text(nsIPrintSettings *settings, LPCWSTR template, BOOL head, int pos)
129 if(head) {
130 switch(pos) {
131 case 0:
132 return nsIPrintSettings_SetHeaderStrLeft(settings, template);
133 case 1:
134 return nsIPrintSettings_SetHeaderStrRight(settings, template);
135 case 2:
136 return nsIPrintSettings_SetHeaderStrCenter(settings, template);
138 }else {
139 switch(pos) {
140 case 0:
141 return nsIPrintSettings_SetFooterStrLeft(settings, template);
142 case 1:
143 return nsIPrintSettings_SetFooterStrRight(settings, template);
144 case 2:
145 return nsIPrintSettings_SetFooterStrCenter(settings, template);
149 return NS_OK;
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;
157 int pos=0;
159 while(*ptr) {
160 if(*ptr != '&') {
161 *p++ = *ptr++;
162 continue;
165 switch(*++ptr) {
166 case '&':
167 *p++ = '&';
168 *p++ = '&';
169 ptr++;
170 break;
171 case 'b': /* change align */
172 ptr++;
173 *p = 0;
174 set_head_text(settings, nstemplate, head, pos);
175 p = nstemplate;
176 pos++;
177 break;
178 case 'd': { /* short date */
179 SYSTEMTIME systime;
180 GetLocalTime(&systime);
181 GetDateFormatW(LOCALE_SYSTEM_DEFAULT, 0, &systime, NULL, p,
182 sizeof(nstemplate)-(p-nstemplate)*sizeof(WCHAR));
183 p += strlenW(p);
184 ptr++;
185 break;
187 case 'p': /* page number */
188 *p++ = '&';
189 *p++ = 'P';
190 ptr++;
191 break;
192 case 'P': /* page count */
193 *p++ = '?'; /* FIXME */
194 ptr++;
195 break;
196 case 'u':
197 *p++ = '&';
198 *p++ = 'U';
199 ptr++;
200 break;
201 case 'w':
202 /* FIXME: set window title */
203 ptr++;
204 break;
205 default:
206 *p++ = '&';
207 *p++ = *ptr++;
211 *p = 0;
212 set_head_text(settings, nstemplate, head, pos);
214 while(++pos < 3)
215 set_head_text(settings, p, head, pos);
218 static void set_default_templates(nsIPrintSettings *settings)
220 WCHAR buf[64];
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;
246 nsresult nsres;
248 TRACE("(%p)->(%d %s %p)\n", This, nCmdexecopt, debugstr_variant(pvaIn), pvaOut);
250 if(pvaOut)
251 FIXME("unsupported pvaOut\n");
253 if(!This->doc_obj->nscontainer)
254 return S_OK;
256 nsres = get_nsinterface((nsISupports*)This->doc_obj->nscontainer->webbrowser, &IID_nsIWebBrowserPrint,
257 (void**)&nsprint);
258 if(NS_FAILED(nsres)) {
259 ERR("Could not get nsIWebBrowserPrint: %08x\n", nsres);
260 return S_OK;
263 nsres = nsIWebBrowserPrint_GetGlobalPrintSettings(nsprint, &settings);
264 if(NS_FAILED(nsres))
265 ERR("GetCurrentPrintSettings failed: %08x\n", nsres);
267 set_default_templates(settings);
269 if(pvaIn) {
270 switch(V_VT(pvaIn)) {
271 case VT_BYREF|VT_ARRAY: {
272 VARIANT *opts;
273 DWORD opts_cnt;
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;
281 if(opts_cnt >= 1) {
282 switch(V_VT(opts)) {
283 case VT_BSTR:
284 TRACE("setting footer %s\n", debugstr_w(V_BSTR(opts)));
285 set_print_template(settings, V_BSTR(opts), TRUE);
286 break;
287 case VT_NULL:
288 break;
289 default:
290 WARN("opts = %s\n", debugstr_variant(opts));
294 if(opts_cnt >= 2) {
295 switch(V_VT(opts+1)) {
296 case VT_BSTR:
297 TRACE("setting footer %s\n", debugstr_w(V_BSTR(opts+1)));
298 set_print_template(settings, V_BSTR(opts+1), FALSE);
299 break;
300 case VT_NULL:
301 break;
302 default:
303 WARN("opts[1] = %s\n", debugstr_variant(opts+1));
307 if(opts_cnt >= 3)
308 FIXME("Unsupported opts_cnt %d\n", opts_cnt);
310 SafeArrayUnaccessData(V_ARRAY(pvaIn));
311 break;
313 default:
314 FIXME("unsupported arg %s\n", debugstr_variant(pvaIn));
318 nsres = nsIWebBrowserPrint_Print(nsprint, settings, NULL);
319 if(NS_FAILED(nsres))
320 ERR("Print failed: %08x\n", nsres);
322 nsIWebBrowserPrint_Release(nsprint);
324 return S_OK;
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);
330 return E_NOTIMPL;
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);
336 return E_NOTIMPL;
339 static HRESULT exec_spell(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
341 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
342 return E_NOTIMPL;
345 static HRESULT exec_properties(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
347 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
348 return E_NOTIMPL;
351 static HRESULT exec_cut(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
353 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
354 return E_NOTIMPL;
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);
362 return S_OK;
365 static HRESULT exec_paste(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
367 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
368 return E_NOTIMPL;
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);
374 return E_NOTIMPL;
377 static HRESULT exec_undo(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
379 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
380 return E_NOTIMPL;
383 static HRESULT exec_rendo(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
385 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
386 return E_NOTIMPL;
389 static HRESULT exec_select_all(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *in, VARIANT *out)
391 TRACE("(%p)\n", This);
393 if(in || out)
394 FIXME("unsupported args\n");
396 if(This->doc_obj->nscontainer)
397 do_ns_command(This, NSCMD_SELECTALL, NULL);
399 update_doc(This, UPDATE_UI);
400 return S_OK;
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);
406 return E_NOTIMPL;
409 static HRESULT exec_zoom(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
411 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
412 return E_NOTIMPL;
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);
418 return E_NOTIMPL;
421 typedef struct {
422 task_t header;
423 HTMLOuterWindow *window;
424 }refresh_task_t;
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) {
436 VARIANT var;
438 V_VT(&var) = VT_I4;
439 V_I4(&var) = 0;
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);
451 heap_free(task);
454 static HRESULT exec_refresh(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
456 refresh_task_t *task;
457 HRESULT hres;
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);
468 if(SUCCEEDED(hres))
469 return S_OK;
473 if(!This->window)
474 return E_UNEXPECTED;
476 task = heap_alloc(sizeof(*task));
477 if(!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);
489 return E_NOTIMPL;
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);
495 return E_NOTIMPL;
498 static HRESULT exec_find(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
500 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
501 return E_NOTIMPL;
504 static HRESULT exec_delete(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
506 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
507 return E_NOTIMPL;
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);
513 return E_NOTIMPL;
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 */
522 if(pvaOut) {
523 V_VT(pvaOut) = VT_BOOL;
524 V_BOOL(pvaOut) = VARIANT_TRUE;
527 return S_OK;
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);
533 return E_NOTIMPL;
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);
539 return E_NOTIMPL;
542 static HRESULT exec_close(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
544 FIXME("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
545 return E_NOTIMPL;
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);
551 return E_NOTIMPL;
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);
557 return E_NOTIMPL;
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));
566 return E_NOTIMPL;
569 set_viewer_zoom(This->doc_obj->nscontainer, (float)V_I4(pvaIn)/100);
570 return S_OK;
573 static HRESULT query_mshtml_copy(HTMLDocument *This, OLECMD *cmd)
575 FIXME("(%p)\n", This);
576 cmd->cmdf = OLECMDF_SUPPORTED|OLECMDF_ENABLED;
577 return S_OK;
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);
588 return S_OK;
591 static HRESULT query_mshtml_cut(HTMLDocument *This, OLECMD *cmd)
593 FIXME("(%p)\n", This);
594 cmd->cmdf = OLECMDF_SUPPORTED|OLECMDF_ENABLED;
595 return S_OK;
598 static HRESULT exec_mshtml_cut(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
600 nsIClipboardCommands *clipboard_commands;
601 nsresult nsres;
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)
610 return E_UNEXPECTED;
612 nsres = nsIClipboardCommands_CutSelection(clipboard_commands);
613 nsIClipboardCommands_Release(clipboard_commands);
614 if(NS_FAILED(nsres)) {
615 ERR("Paste failed: %08x\n", nsres);
616 return E_FAIL;
619 return S_OK;
622 static HRESULT query_mshtml_paste(HTMLDocument *This, OLECMD *cmd)
624 FIXME("(%p)\n", This);
625 cmd->cmdf = OLECMDF_SUPPORTED|OLECMDF_ENABLED;
626 return S_OK;
629 static HRESULT exec_mshtml_paste(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
631 nsIClipboardCommands *clipboard_commands;
632 nsresult nsres;
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)
641 return E_UNEXPECTED;
643 nsres = nsIClipboardCommands_Paste(clipboard_commands);
644 nsIClipboardCommands_Release(clipboard_commands);
645 if(NS_FAILED(nsres)) {
646 ERR("Paste failed: %08x\n", nsres);
647 return E_FAIL;
650 return S_OK;
653 static HRESULT query_selall_status(HTMLDocument *This, OLECMD *cmd)
655 TRACE("(%p)->(%p)\n", This, cmd);
657 cmd->cmdf = OLECMDF_SUPPORTED|OLECMDF_ENABLED;
658 return S_OK;
661 static HRESULT exec_browsemode(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
663 WARN("(%p)->(%08x %p %p)\n", This, cmdexecopt, in, out);
665 if(in || out)
666 FIXME("unsupported args\n");
668 This->doc_obj->usermode = BROWSEMODE;
670 return S_OK;
673 static HRESULT exec_editmode(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
675 TRACE("(%p)->(%08x %p %p)\n", This, cmdexecopt, in, out);
677 if(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);
686 return S_OK;
689 static HRESULT exec_baselinefont3(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
691 FIXME("(%p)->(%08x %p %p)\n", This, cmdexecopt, in, out);
692 return S_OK;
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));
704 return S_OK;
707 static HRESULT query_enabled_stub(HTMLDocument *This, OLECMD *cmd)
709 switch(cmd->cmdID) {
710 case IDM_PRINT:
711 FIXME("CGID_MSHTML: IDM_PRINT\n");
712 cmd->cmdf = OLECMDF_SUPPORTED|OLECMDF_ENABLED;
713 break;
714 case IDM_BLOCKDIRLTR:
715 FIXME("CGID_MSHTML: IDM_BLOCKDIRLTR\n");
716 cmd->cmdf = OLECMDF_SUPPORTED|OLECMDF_ENABLED;
717 break;
718 case IDM_BLOCKDIRRTL:
719 FIXME("CGID_MSHTML: IDM_BLOCKDIRRTL\n");
720 cmd->cmdf = OLECMDF_SUPPORTED|OLECMDF_ENABLED;
721 break;
724 return S_OK;
727 static const struct {
728 OLECMDF cmdf;
729 HRESULT (*func)(HTMLDocument*,DWORD,VARIANT*,VARIANT*);
730 } exec_table[] = {
731 {0},
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 */
752 {0},
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 */
757 {0},
758 { OLECMDF_SUPPORTED|OLECMDF_ENABLED, exec_find }, /* OLECMDID_FIND */
759 { OLECMDF_SUPPORTED, exec_delete }, /* OLECMDID_DELETE */
760 {0},{0},
761 { OLECMDF_SUPPORTED, exec_enable_interaction }, /* OLECMDID_ENABLE_INTERACTION */
762 { OLECMDF_SUPPORTED, exec_on_unload }, /* OLECMDID_ONUNLOAD */
763 {0},{0},{0},{0},{0},
764 { OLECMDF_SUPPORTED, exec_show_page_setup }, /* OLECMDID_SHOWPAGESETUP */
765 { OLECMDF_SUPPORTED, exec_show_print }, /* OLECMDID_SHOWPRINT */
766 {0},{0},
767 { OLECMDF_SUPPORTED, exec_close }, /* OLECMDID_CLOSE */
768 {0},{0},{0},
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},
788 {0,NULL,NULL}
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;
813 cmd->cmdf = 0;
815 while(iter->id && iter->id != cmd->cmdID)
816 iter++;
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);
828 HRESULT hres;
830 TRACE("(%p)->(%s %d %p %p)\n", This, debugstr_guid(pguidCmdGroup), cCmds, prgCmds, pCmdText);
832 if(pCmdText)
833 FIXME("Unsupported pCmdText\n");
834 if(!cCmds)
835 return S_OK;
837 if(!pguidCmdGroup) {
838 ULONG i;
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);
843 prgCmds[i].cmdf = 0;
844 }else {
845 if(prgCmds[i].cmdID == OLECMDID_OPEN || prgCmds[i].cmdID == OLECMDID_NEW) {
846 IOleCommandTarget *cmdtrg = NULL;
847 OLECMD olecmd;
849 prgCmds[i].cmdf = OLECMDF_SUPPORTED;
850 if(This->doc_obj->client) {
851 hres = IOleClientSite_QueryInterface(This->doc_obj->client, &IID_IOleCommandTarget,
852 (void**)&cmdtrg);
853 if(SUCCEEDED(hres)) {
854 olecmd.cmdID = prgCmds[i].cmdID;
855 olecmd.cmdf = 0;
857 hres = IOleCommandTarget_QueryStatus(cmdtrg, NULL, 1, &olecmd, NULL);
858 if(SUCCEEDED(hres) && olecmd.cmdf)
859 prgCmds[i].cmdf = olecmd.cmdf;
861 }else {
862 ERR("This->client == NULL, native would crash\n");
864 }else {
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)) {
875 ULONG i;
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)
898 iter++;
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);
911 if(!pguidCmdGroup) {
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);
933 return hres;
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;
951 DWORD cmdid;
953 if(This->hostui && S_OK == IDocHostUIHandler_ShowContextMenu(This->hostui,
954 dwID, ppt, (IUnknown*)&This->basedoc.IOleCommandTarget_iface, elem))
955 return;
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);
964 if(cmdid)
965 IOleCommandTarget_Exec(&This->basedoc.IOleCommandTarget_iface, &CGID_MSHTML, cmdid, 0,
966 NULL, NULL);
969 void HTMLDocument_OleCmd_Init(HTMLDocument *This)
971 This->IOleCommandTarget_iface.lpVtbl = &OleCommandTargetVtbl;