msvcrt: Use fpclass constants from public header.
[wine/zf.git] / dlls / mshtml / olecmd.c
blob22d350bedd812542d7b9ef2eae70ec6f3ef40cdc
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 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;
241 nsresult nsres;
243 TRACE("(%p)->(%d %s %p)\n", doc, nCmdexecopt, debugstr_variant(pvaIn), pvaOut);
245 if(pvaOut)
246 FIXME("unsupported pvaOut\n");
248 nsres = get_nsinterface((nsISupports*)doc->browser->webbrowser, &IID_nsIWebBrowserPrint,
249 (void**)&nsprint);
250 if(NS_FAILED(nsres)) {
251 ERR("Could not get nsIWebBrowserPrint: %08x\n", nsres);
252 return S_OK;
255 nsres = nsIWebBrowserPrint_GetGlobalPrintSettings(nsprint, &settings);
256 if(NS_FAILED(nsres))
257 ERR("GetCurrentPrintSettings failed: %08x\n", nsres);
259 set_default_templates(settings);
261 if(pvaIn) {
262 switch(V_VT(pvaIn)) {
263 case VT_BYREF|VT_ARRAY: {
264 VARIANT *opts;
265 DWORD opts_cnt;
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;
273 if(opts_cnt >= 1) {
274 switch(V_VT(opts)) {
275 case VT_BSTR:
276 TRACE("setting footer %s\n", debugstr_w(V_BSTR(opts)));
277 set_print_template(settings, V_BSTR(opts), TRUE);
278 break;
279 case VT_NULL:
280 break;
281 default:
282 WARN("opts = %s\n", debugstr_variant(opts));
286 if(opts_cnt >= 2) {
287 switch(V_VT(opts+1)) {
288 case VT_BSTR:
289 TRACE("setting footer %s\n", debugstr_w(V_BSTR(opts+1)));
290 set_print_template(settings, V_BSTR(opts+1), FALSE);
291 break;
292 case VT_NULL:
293 break;
294 default:
295 WARN("opts[1] = %s\n", debugstr_variant(opts+1));
299 if(opts_cnt >= 3)
300 FIXME("Unsupported opts_cnt %d\n", opts_cnt);
302 SafeArrayUnaccessData(V_ARRAY(pvaIn));
303 break;
305 default:
306 FIXME("unsupported arg %s\n", debugstr_variant(pvaIn));
310 nsres = nsIWebBrowserPrint_Print(nsprint, settings, NULL);
311 if(NS_FAILED(nsres))
312 ERR("Print failed: %08x\n", nsres);
314 nsIWebBrowserPrint_Release(nsprint);
316 return S_OK;
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);
322 return E_NOTIMPL;
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);
328 return E_NOTIMPL;
331 static HRESULT exec_spell(HTMLDocumentNode *doc, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
333 FIXME("(%p)->(%d %p %p)\n", doc, nCmdexecopt, pvaIn, pvaOut);
334 return E_NOTIMPL;
337 static HRESULT exec_properties(HTMLDocumentNode *doc, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
339 FIXME("(%p)->(%d %p %p)\n", doc, nCmdexecopt, pvaIn, pvaOut);
340 return E_NOTIMPL;
343 static HRESULT exec_cut(HTMLDocumentNode *doc, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
345 FIXME("(%p)->(%d %p %p)\n", doc, nCmdexecopt, pvaIn, pvaOut);
346 return E_NOTIMPL;
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);
354 return S_OK;
357 static HRESULT exec_paste(HTMLDocumentNode *doc, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
359 FIXME("(%p)->(%d %p %p)\n", doc, nCmdexecopt, pvaIn, pvaOut);
360 return E_NOTIMPL;
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);
366 return E_NOTIMPL;
369 static HRESULT exec_undo(HTMLDocumentNode *doc, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
371 FIXME("(%p)->(%d %p %p)\n", doc, nCmdexecopt, pvaIn, pvaOut);
372 return E_NOTIMPL;
375 static HRESULT exec_rendo(HTMLDocumentNode *doc, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
377 FIXME("(%p)->(%d %p %p)\n", doc, nCmdexecopt, pvaIn, pvaOut);
378 return E_NOTIMPL;
381 static HRESULT exec_select_all(HTMLDocumentNode *doc, DWORD nCmdexecopt, VARIANT *in, VARIANT *out)
383 TRACE("(%p)\n", doc);
385 if(in || out)
386 FIXME("unsupported args\n");
388 if(!doc->browser)
389 return E_UNEXPECTED;
391 do_ns_command(doc, NSCMD_SELECTALL, NULL);
392 update_doc(doc->browser->doc, UPDATE_UI);
393 return S_OK;
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);
399 return E_NOTIMPL;
402 static HRESULT exec_zoom(HTMLDocumentNode *doc, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
404 FIXME("(%p)->(%d %p %p)\n", doc, nCmdexecopt, pvaIn, pvaOut);
405 return E_NOTIMPL;
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);
411 return E_NOTIMPL;
414 typedef struct {
415 task_t header;
416 HTMLOuterWindow *window;
417 }refresh_task_t;
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) {
429 VARIANT var;
431 V_VT(&var) = VT_I4;
432 V_I4(&var) = 0;
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);
444 heap_free(task);
447 static HRESULT exec_refresh(HTMLDocumentNode *doc, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
449 HTMLDocumentObj *doc_obj;
450 refresh_task_t *task;
451 HRESULT hres;
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");
457 return E_NOTIMPL;
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);
468 if(SUCCEEDED(hres))
469 return S_OK;
473 if(!doc->basedoc.window)
474 return E_UNEXPECTED;
476 task = heap_alloc(sizeof(*task));
477 if(!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);
489 return E_NOTIMPL;
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);
495 return E_NOTIMPL;
498 static HRESULT exec_find(HTMLDocumentNode *doc, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
500 FIXME("(%p)->(%d %p %p)\n", doc, nCmdexecopt, pvaIn, pvaOut);
501 return E_NOTIMPL;
504 static HRESULT exec_delete(HTMLDocumentNode *doc, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
506 FIXME("(%p)->(%d %p %p)\n", doc, nCmdexecopt, pvaIn, pvaOut);
507 return E_NOTIMPL;
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);
513 return E_NOTIMPL;
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 */
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(HTMLDocumentNode *doc, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
532 FIXME("(%p)->(%d %p %p)\n", doc, nCmdexecopt, pvaIn, pvaOut);
533 return E_NOTIMPL;
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);
539 return E_NOTIMPL;
542 static HRESULT exec_close(HTMLDocumentNode *doc, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
544 FIXME("(%p)->(%d %p %p)\n", doc, nCmdexecopt, pvaIn, pvaOut);
545 return E_NOTIMPL;
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);
551 return E_NOTIMPL;
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);
557 return E_NOTIMPL;
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));
566 return E_NOTIMPL;
569 if(pvaIn)
570 set_viewer_zoom(doc->browser, (float)V_I4(pvaIn)/100);
571 if(pvaOut) {
572 V_VT(pvaOut) = VT_I4;
573 V_I4(pvaOut) = get_viewer_zoom(doc->browser) * 100;
575 return S_OK;
578 static HRESULT query_mshtml_copy(HTMLDocumentNode *doc, OLECMD *cmd)
580 FIXME("(%p)\n", doc);
581 cmd->cmdf = OLECMDF_SUPPORTED|OLECMDF_ENABLED;
582 return S_OK;
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);
593 return S_OK;
596 static HRESULT query_mshtml_cut(HTMLDocumentNode *doc, OLECMD *cmd)
598 FIXME("(%p)\n", doc);
599 cmd->cmdf = OLECMDF_SUPPORTED|OLECMDF_ENABLED;
600 return S_OK;
603 static HRESULT exec_mshtml_cut(HTMLDocumentNode *doc, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
605 nsIClipboardCommands *clipboard_commands;
606 nsresult nsres;
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)
615 return E_UNEXPECTED;
617 nsres = nsIClipboardCommands_CutSelection(clipboard_commands);
618 nsIClipboardCommands_Release(clipboard_commands);
619 if(NS_FAILED(nsres)) {
620 ERR("Paste failed: %08x\n", nsres);
621 return E_FAIL;
624 return S_OK;
627 static HRESULT query_mshtml_paste(HTMLDocumentNode *doc, OLECMD *cmd)
629 FIXME("(%p)\n", doc);
630 cmd->cmdf = OLECMDF_SUPPORTED|OLECMDF_ENABLED;
631 return S_OK;
634 static HRESULT exec_mshtml_paste(HTMLDocumentNode *doc, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
636 nsIClipboardCommands *clipboard_commands;
637 nsresult nsres;
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)
646 return E_UNEXPECTED;
648 nsres = nsIClipboardCommands_Paste(clipboard_commands);
649 nsIClipboardCommands_Release(clipboard_commands);
650 if(NS_FAILED(nsres)) {
651 ERR("Paste failed: %08x\n", nsres);
652 return E_FAIL;
655 return S_OK;
658 static HRESULT query_selall_status(HTMLDocumentNode *doc, OLECMD *cmd)
660 TRACE("(%p)->(%p)\n", doc, cmd);
662 cmd->cmdf = OLECMDF_SUPPORTED|OLECMDF_ENABLED;
663 return S_OK;
666 static HRESULT exec_browsemode(HTMLDocumentNode *doc, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
668 WARN("(%p)->(%08x %p %p)\n", doc, cmdexecopt, in, out);
670 if(in || out)
671 FIXME("unsupported args\n");
673 doc->browser->usermode = BROWSEMODE;
675 return S_OK;
678 static HRESULT exec_editmode(HTMLDocumentNode *doc, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
680 TRACE("(%p)->(%08x %p %p)\n", doc, cmdexecopt, in, out);
682 if(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);
691 return S_OK;
694 static HRESULT exec_baselinefont3(HTMLDocumentNode *doc, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
696 FIXME("(%p)->(%08x %p %p)\n", doc, cmdexecopt, in, out);
697 return S_OK;
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));
709 return S_OK;
712 static HRESULT query_enabled_stub(HTMLDocumentNode *doc, OLECMD *cmd)
714 switch(cmd->cmdID) {
715 case IDM_PRINT:
716 FIXME("CGID_MSHTML: IDM_PRINT\n");
717 cmd->cmdf = OLECMDF_SUPPORTED|OLECMDF_ENABLED;
718 break;
719 case IDM_BLOCKDIRLTR:
720 FIXME("CGID_MSHTML: IDM_BLOCKDIRLTR\n");
721 cmd->cmdf = OLECMDF_SUPPORTED|OLECMDF_ENABLED;
722 break;
723 case IDM_BLOCKDIRRTL:
724 FIXME("CGID_MSHTML: IDM_BLOCKDIRRTL\n");
725 cmd->cmdf = OLECMDF_SUPPORTED|OLECMDF_ENABLED;
726 break;
729 return S_OK;
732 static const struct {
733 OLECMDF cmdf;
734 HRESULT (*func)(HTMLDocumentNode*,DWORD,VARIANT*,VARIANT*);
735 } exec_table[] = {
736 {0},
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 */
757 {0},
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 */
762 {0},
763 { OLECMDF_SUPPORTED|OLECMDF_ENABLED, exec_find }, /* OLECMDID_FIND */
764 { OLECMDF_SUPPORTED, exec_delete }, /* OLECMDID_DELETE */
765 {0},{0},
766 { OLECMDF_SUPPORTED, exec_enable_interaction }, /* OLECMDID_ENABLE_INTERACTION */
767 { OLECMDF_SUPPORTED, exec_on_unload }, /* OLECMDID_ONUNLOAD */
768 {0},{0},{0},{0},{0},
769 { OLECMDF_SUPPORTED, exec_show_page_setup }, /* OLECMDID_SHOWPAGESETUP */
770 { OLECMDF_SUPPORTED, exec_show_print }, /* OLECMDID_SHOWPRINT */
771 {0},{0},
772 { OLECMDF_SUPPORTED, exec_close }, /* OLECMDID_CLOSE */
773 {0},{0},{0},
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},
793 {0,NULL,NULL}
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;
818 cmd->cmdf = 0;
820 while(iter->id && iter->id != cmd->cmdID)
821 iter++;
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);
833 HRESULT hres;
835 TRACE("(%p)->(%s %d %p %p)\n", This, debugstr_guid(pguidCmdGroup), cCmds, prgCmds, pCmdText);
837 if(pCmdText)
838 FIXME("Unsupported pCmdText\n");
839 if(!This->doc_node->browser)
840 return E_UNEXPECTED;
841 if(!cCmds)
842 return S_OK;
844 if(!pguidCmdGroup) {
845 ULONG i;
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);
850 prgCmds[i].cmdf = 0;
851 }else {
852 if(prgCmds[i].cmdID == OLECMDID_OPEN || prgCmds[i].cmdID == OLECMDID_NEW) {
853 IOleCommandTarget *cmdtrg = NULL;
854 OLECMD olecmd;
856 prgCmds[i].cmdf = OLECMDF_SUPPORTED;
857 if(This->doc_obj->client) {
858 hres = IOleClientSite_QueryInterface(This->doc_obj->client, &IID_IOleCommandTarget,
859 (void**)&cmdtrg);
860 if(SUCCEEDED(hres)) {
861 olecmd.cmdID = prgCmds[i].cmdID;
862 olecmd.cmdf = 0;
864 hres = IOleCommandTarget_QueryStatus(cmdtrg, NULL, 1, &olecmd, NULL);
865 if(SUCCEEDED(hres) && olecmd.cmdf)
866 prgCmds[i].cmdf = olecmd.cmdf;
868 }else {
869 ERR("This->client == NULL, native would crash\n");
871 }else {
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)) {
882 ULONG i;
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)
905 iter++;
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)
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;