makefiles: Don't use standard libs for programs that specify -nodefaultlibs.
[wine/zf.git] / dlls / mshtml / olecmd.c
blob43f9285e8f5b066e6eec70adf7c0a238cb74f3cf
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(HTMLDocumentNode *doc, const char *cmd, nsICommandParams *nsparam)
45 nsICommandManager *cmdmgr;
46 nsresult nsres;
48 TRACE("(%p)\n", doc);
50 if(!doc->browser || !doc->window)
51 return;
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);
56 return;
59 nsres = nsICommandManager_DoCommand(cmdmgr, cmd, nsparam, doc->window->base.outer_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(HTMLDocumentNode *doc)
68 nsIClipboardCommands *clipboard_commands;
69 nsIDocShell *doc_shell;
70 nsresult nsres;
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");
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(HTMLDocumentNode *doc, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
99 FIXME("(%p)->(%d %p %p)\n", doc, nCmdexecopt, pvaIn, pvaOut);
100 return E_NOTIMPL;
103 static HRESULT exec_new(HTMLDocumentNode *doc, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
105 FIXME("(%p)->(%d %p %p)\n", doc, nCmdexecopt, pvaIn, pvaOut);
106 return E_NOTIMPL;
109 static HRESULT exec_save(HTMLDocumentNode *doc, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
111 FIXME("(%p)->(%d %p %p)\n", doc, nCmdexecopt, pvaIn, pvaOut);
112 return E_NOTIMPL;
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);
118 return E_NOTIMPL;
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);
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 += lstrlenW(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, 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;
243 nsresult nsres;
245 TRACE("(%p)->(%d %s %p)\n", doc, nCmdexecopt, debugstr_variant(pvaIn), pvaOut);
247 if(pvaOut)
248 FIXME("unsupported pvaOut\n");
250 nsres = get_nsinterface((nsISupports*)doc->browser->webbrowser, &IID_nsIWebBrowserPrint,
251 (void**)&nsprint);
252 if(NS_FAILED(nsres)) {
253 ERR("Could not get nsIWebBrowserPrint: %08x\n", nsres);
254 return S_OK;
257 nsres = nsIWebBrowserPrint_GetGlobalPrintSettings(nsprint, &settings);
258 if(NS_FAILED(nsres))
259 ERR("GetCurrentPrintSettings failed: %08x\n", nsres);
261 set_default_templates(settings);
263 if(pvaIn) {
264 switch(V_VT(pvaIn)) {
265 case VT_BYREF|VT_ARRAY: {
266 VARIANT *opts;
267 DWORD opts_cnt;
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;
275 if(opts_cnt >= 1) {
276 switch(V_VT(opts)) {
277 case VT_BSTR:
278 TRACE("setting footer %s\n", debugstr_w(V_BSTR(opts)));
279 set_print_template(settings, V_BSTR(opts), TRUE);
280 break;
281 case VT_NULL:
282 break;
283 default:
284 WARN("opts = %s\n", debugstr_variant(opts));
288 if(opts_cnt >= 2) {
289 switch(V_VT(opts+1)) {
290 case VT_BSTR:
291 TRACE("setting footer %s\n", debugstr_w(V_BSTR(opts+1)));
292 set_print_template(settings, V_BSTR(opts+1), FALSE);
293 break;
294 case VT_NULL:
295 break;
296 default:
297 WARN("opts[1] = %s\n", debugstr_variant(opts+1));
301 if(opts_cnt >= 3)
302 FIXME("Unsupported opts_cnt %d\n", opts_cnt);
304 SafeArrayUnaccessData(V_ARRAY(pvaIn));
305 break;
307 default:
308 FIXME("unsupported arg %s\n", debugstr_variant(pvaIn));
312 nsres = nsIWebBrowserPrint_Print(nsprint, settings, NULL);
313 if(NS_FAILED(nsres))
314 ERR("Print failed: %08x\n", nsres);
316 nsIWebBrowserPrint_Release(nsprint);
318 return S_OK;
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);
324 return E_NOTIMPL;
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);
330 return E_NOTIMPL;
333 static HRESULT exec_spell(HTMLDocumentNode *doc, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
335 FIXME("(%p)->(%d %p %p)\n", doc, nCmdexecopt, pvaIn, pvaOut);
336 return E_NOTIMPL;
339 static HRESULT exec_properties(HTMLDocumentNode *doc, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
341 FIXME("(%p)->(%d %p %p)\n", doc, nCmdexecopt, pvaIn, pvaOut);
342 return E_NOTIMPL;
345 static HRESULT exec_cut(HTMLDocumentNode *doc, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
347 FIXME("(%p)->(%d %p %p)\n", doc, nCmdexecopt, pvaIn, pvaOut);
348 return E_NOTIMPL;
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);
356 return S_OK;
359 static HRESULT exec_paste(HTMLDocumentNode *doc, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
361 FIXME("(%p)->(%d %p %p)\n", doc, nCmdexecopt, pvaIn, pvaOut);
362 return E_NOTIMPL;
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);
368 return E_NOTIMPL;
371 static HRESULT exec_undo(HTMLDocumentNode *doc, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
373 FIXME("(%p)->(%d %p %p)\n", doc, nCmdexecopt, pvaIn, pvaOut);
374 return E_NOTIMPL;
377 static HRESULT exec_rendo(HTMLDocumentNode *doc, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
379 FIXME("(%p)->(%d %p %p)\n", doc, nCmdexecopt, pvaIn, pvaOut);
380 return E_NOTIMPL;
383 static HRESULT exec_select_all(HTMLDocumentNode *doc, DWORD nCmdexecopt, VARIANT *in, VARIANT *out)
385 TRACE("(%p)\n", doc);
387 if(in || out)
388 FIXME("unsupported args\n");
390 if(!doc->browser)
391 return E_UNEXPECTED;
393 do_ns_command(doc, NSCMD_SELECTALL, NULL);
394 update_doc(doc->browser->doc, UPDATE_UI);
395 return S_OK;
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);
401 return E_NOTIMPL;
404 static HRESULT exec_zoom(HTMLDocumentNode *doc, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
406 FIXME("(%p)->(%d %p %p)\n", doc, nCmdexecopt, pvaIn, pvaOut);
407 return E_NOTIMPL;
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);
413 return E_NOTIMPL;
416 typedef struct {
417 task_t header;
418 HTMLOuterWindow *window;
419 }refresh_task_t;
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) {
431 VARIANT var;
433 V_VT(&var) = VT_I4;
434 V_I4(&var) = 0;
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);
446 heap_free(task);
449 static HRESULT exec_refresh(HTMLDocumentNode *doc, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
451 HTMLDocumentObj *doc_obj;
452 refresh_task_t *task;
453 HRESULT hres;
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");
459 return E_NOTIMPL;
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);
470 if(SUCCEEDED(hres))
471 return S_OK;
475 if(!doc->basedoc.window)
476 return E_UNEXPECTED;
478 task = heap_alloc(sizeof(*task));
479 if(!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);
491 return E_NOTIMPL;
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);
497 return E_NOTIMPL;
500 static HRESULT exec_find(HTMLDocumentNode *doc, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
502 FIXME("(%p)->(%d %p %p)\n", doc, nCmdexecopt, pvaIn, pvaOut);
503 return E_NOTIMPL;
506 static HRESULT exec_delete(HTMLDocumentNode *doc, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
508 FIXME("(%p)->(%d %p %p)\n", doc, nCmdexecopt, pvaIn, pvaOut);
509 return E_NOTIMPL;
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);
515 return E_NOTIMPL;
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 */
524 if(pvaOut) {
525 V_VT(pvaOut) = VT_BOOL;
526 V_BOOL(pvaOut) = VARIANT_TRUE;
529 return S_OK;
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);
535 return E_NOTIMPL;
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);
541 return E_NOTIMPL;
544 static HRESULT exec_close(HTMLDocumentNode *doc, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
546 FIXME("(%p)->(%d %p %p)\n", doc, nCmdexecopt, pvaIn, pvaOut);
547 return E_NOTIMPL;
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);
553 return E_NOTIMPL;
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);
559 return E_NOTIMPL;
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));
568 return E_NOTIMPL;
571 if(pvaIn)
572 set_viewer_zoom(doc->browser, (float)V_I4(pvaIn)/100);
573 if(pvaOut) {
574 V_VT(pvaOut) = VT_I4;
575 V_I4(pvaOut) = get_viewer_zoom(doc->browser) * 100;
577 return S_OK;
580 static HRESULT query_mshtml_copy(HTMLDocumentNode *doc, OLECMD *cmd)
582 FIXME("(%p)\n", doc);
583 cmd->cmdf = OLECMDF_SUPPORTED|OLECMDF_ENABLED;
584 return S_OK;
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);
595 return S_OK;
598 static HRESULT query_mshtml_cut(HTMLDocumentNode *doc, OLECMD *cmd)
600 FIXME("(%p)\n", doc);
601 cmd->cmdf = OLECMDF_SUPPORTED|OLECMDF_ENABLED;
602 return S_OK;
605 static HRESULT exec_mshtml_cut(HTMLDocumentNode *doc, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
607 nsIClipboardCommands *clipboard_commands;
608 nsresult nsres;
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)
617 return E_UNEXPECTED;
619 nsres = nsIClipboardCommands_CutSelection(clipboard_commands);
620 nsIClipboardCommands_Release(clipboard_commands);
621 if(NS_FAILED(nsres)) {
622 ERR("Paste failed: %08x\n", nsres);
623 return E_FAIL;
626 return S_OK;
629 static HRESULT query_mshtml_paste(HTMLDocumentNode *doc, OLECMD *cmd)
631 FIXME("(%p)\n", doc);
632 cmd->cmdf = OLECMDF_SUPPORTED|OLECMDF_ENABLED;
633 return S_OK;
636 static HRESULT exec_mshtml_paste(HTMLDocumentNode *doc, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
638 nsIClipboardCommands *clipboard_commands;
639 nsresult nsres;
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)
648 return E_UNEXPECTED;
650 nsres = nsIClipboardCommands_Paste(clipboard_commands);
651 nsIClipboardCommands_Release(clipboard_commands);
652 if(NS_FAILED(nsres)) {
653 ERR("Paste failed: %08x\n", nsres);
654 return E_FAIL;
657 return S_OK;
660 static HRESULT query_selall_status(HTMLDocumentNode *doc, OLECMD *cmd)
662 TRACE("(%p)->(%p)\n", doc, cmd);
664 cmd->cmdf = OLECMDF_SUPPORTED|OLECMDF_ENABLED;
665 return S_OK;
668 static HRESULT exec_browsemode(HTMLDocumentNode *doc, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
670 WARN("(%p)->(%08x %p %p)\n", doc, cmdexecopt, in, out);
672 if(in || out)
673 FIXME("unsupported args\n");
675 doc->browser->usermode = BROWSEMODE;
677 return S_OK;
680 static HRESULT exec_editmode(HTMLDocumentNode *doc, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
682 TRACE("(%p)->(%08x %p %p)\n", doc, cmdexecopt, in, out);
684 if(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);
693 return S_OK;
696 static HRESULT exec_baselinefont3(HTMLDocumentNode *doc, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
698 FIXME("(%p)->(%08x %p %p)\n", doc, cmdexecopt, in, out);
699 return S_OK;
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));
711 return S_OK;
714 static HRESULT query_enabled_stub(HTMLDocumentNode *doc, OLECMD *cmd)
716 switch(cmd->cmdID) {
717 case IDM_PRINT:
718 FIXME("CGID_MSHTML: IDM_PRINT\n");
719 cmd->cmdf = OLECMDF_SUPPORTED|OLECMDF_ENABLED;
720 break;
721 case IDM_BLOCKDIRLTR:
722 FIXME("CGID_MSHTML: IDM_BLOCKDIRLTR\n");
723 cmd->cmdf = OLECMDF_SUPPORTED|OLECMDF_ENABLED;
724 break;
725 case IDM_BLOCKDIRRTL:
726 FIXME("CGID_MSHTML: IDM_BLOCKDIRRTL\n");
727 cmd->cmdf = OLECMDF_SUPPORTED|OLECMDF_ENABLED;
728 break;
731 return S_OK;
734 static const struct {
735 OLECMDF cmdf;
736 HRESULT (*func)(HTMLDocumentNode*,DWORD,VARIANT*,VARIANT*);
737 } exec_table[] = {
738 {0},
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 */
759 {0},
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 */
764 {0},
765 { OLECMDF_SUPPORTED|OLECMDF_ENABLED, exec_find }, /* OLECMDID_FIND */
766 { OLECMDF_SUPPORTED, exec_delete }, /* OLECMDID_DELETE */
767 {0},{0},
768 { OLECMDF_SUPPORTED, exec_enable_interaction }, /* OLECMDID_ENABLE_INTERACTION */
769 { OLECMDF_SUPPORTED, exec_on_unload }, /* OLECMDID_ONUNLOAD */
770 {0},{0},{0},{0},{0},
771 { OLECMDF_SUPPORTED, exec_show_page_setup }, /* OLECMDID_SHOWPAGESETUP */
772 { OLECMDF_SUPPORTED, exec_show_print }, /* OLECMDID_SHOWPRINT */
773 {0},{0},
774 { OLECMDF_SUPPORTED, exec_close }, /* OLECMDID_CLOSE */
775 {0},{0},{0},
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},
795 {0,NULL,NULL}
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;
820 cmd->cmdf = 0;
822 while(iter->id && iter->id != cmd->cmdID)
823 iter++;
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);
835 HRESULT hres;
837 TRACE("(%p)->(%s %d %p %p)\n", This, debugstr_guid(pguidCmdGroup), cCmds, prgCmds, pCmdText);
839 if(pCmdText)
840 FIXME("Unsupported pCmdText\n");
841 if(!This->doc_node->browser)
842 return E_UNEXPECTED;
843 if(!cCmds)
844 return S_OK;
846 if(!pguidCmdGroup) {
847 ULONG i;
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);
852 prgCmds[i].cmdf = 0;
853 }else {
854 if(prgCmds[i].cmdID == OLECMDID_OPEN || prgCmds[i].cmdID == OLECMDID_NEW) {
855 IOleCommandTarget *cmdtrg = NULL;
856 OLECMD olecmd;
858 prgCmds[i].cmdf = OLECMDF_SUPPORTED;
859 if(This->doc_obj->client) {
860 hres = IOleClientSite_QueryInterface(This->doc_obj->client, &IID_IOleCommandTarget,
861 (void**)&cmdtrg);
862 if(SUCCEEDED(hres)) {
863 olecmd.cmdID = prgCmds[i].cmdID;
864 olecmd.cmdf = 0;
866 hres = IOleCommandTarget_QueryStatus(cmdtrg, NULL, 1, &olecmd, NULL);
867 if(SUCCEEDED(hres) && olecmd.cmdf)
868 prgCmds[i].cmdf = olecmd.cmdf;
870 }else {
871 ERR("This->client == NULL, native would crash\n");
873 }else {
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)) {
884 ULONG i;
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)
907 iter++;
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)
921 return E_UNEXPECTED;
923 if(!pguidCmdGroup) {
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);
945 return hres;
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;
963 DWORD cmdid;
965 if(This->hostui && S_OK == IDocHostUIHandler_ShowContextMenu(This->hostui,
966 dwID, ppt, (IUnknown*)&This->basedoc.IOleCommandTarget_iface, elem))
967 return;
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);
976 if(cmdid)
977 IOleCommandTarget_Exec(&This->basedoc.IOleCommandTarget_iface, &CGID_MSHTML, cmdid, 0,
978 NULL, NULL);
981 void HTMLDocument_OleCmd_Init(HTMLDocument *This)
983 This->IOleCommandTarget_iface.lpVtbl = &OleCommandTargetVtbl;