dinput: When handling axes, ignore the ABS_HAT.* as they are handled as POV.
[wine] / dlls / mshtml / olecmd.c
1 /*
2  * Copyright 2005-2006 Jacek Caban for CodeWeavers
3  *
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.
8  *
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.
13  *
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
17  */
18
19 #include "config.h"
20
21 #include <stdarg.h>
22 #include <stdio.h>
23
24 #define COBJMACROS
25
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winuser.h"
29 #include "ole2.h"
30 #include "shlguid.h"
31 #include "mshtmdid.h"
32 #include "idispids.h"
33 #include "mshtmcid.h"
34
35 #include "wine/debug.h"
36
37 #include "mshtml_private.h"
38
39 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
40
41 /**********************************************************
42  * IOleCommandTarget implementation
43  */
44
45 #define CMDTARGET_THIS(iface) DEFINE_THIS(HTMLDocument, OleCommandTarget, iface)
46
47 static HRESULT exec_open(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
48 {
49     FIXME("(%p)->(%ld %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
50     return E_NOTIMPL;
51 }
52
53 static HRESULT exec_new(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
54 {
55     FIXME("(%p)->(%ld %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
56     return E_NOTIMPL;
57 }
58
59 static HRESULT exec_save(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
60 {
61     FIXME("(%p)->(%ld %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
62     return E_NOTIMPL;
63 }
64
65 static HRESULT exec_save_as(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
66 {
67     FIXME("(%p)->(%ld %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
68     return E_NOTIMPL;
69 }
70
71 static HRESULT exec_save_copy_as(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
72 {
73     FIXME("(%p)->(%ld %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
74     return E_NOTIMPL;
75 }
76
77 static HRESULT exec_print(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
78 {
79     FIXME("(%p)->(%ld %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
80     return E_NOTIMPL;
81 }
82
83 static HRESULT exec_print_preview(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
84 {
85     FIXME("(%p)->(%ld %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
86     return E_NOTIMPL;
87 }
88
89 static HRESULT exec_page_setup(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
90 {
91     FIXME("(%p)->(%ld %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
92     return E_NOTIMPL;
93 }
94
95 static HRESULT exec_spell(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
96 {
97     FIXME("(%p)->(%ld %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
98     return E_NOTIMPL;
99 }
100
101 static HRESULT exec_properties(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
102 {
103     FIXME("(%p)->(%ld %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
104     return E_NOTIMPL;
105 }
106
107 static HRESULT exec_cut(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
108 {
109     FIXME("(%p)->(%ld %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
110     return E_NOTIMPL;
111 }
112
113 static HRESULT exec_copy(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
114 {
115     FIXME("(%p)->(%ld %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
116     return E_NOTIMPL;
117 }
118
119 static HRESULT exec_paste(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
120 {
121     FIXME("(%p)->(%ld %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
122     return E_NOTIMPL;
123 }
124
125 static HRESULT exec_paste_special(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
126 {
127     FIXME("(%p)->(%ld %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
128     return E_NOTIMPL;
129 }
130
131 static HRESULT exec_undo(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
132 {
133     FIXME("(%p)->(%ld %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
134     return E_NOTIMPL;
135 }
136
137 static HRESULT exec_rendo(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
138 {
139     FIXME("(%p)->(%ld %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
140     return E_NOTIMPL;
141 }
142
143 static HRESULT exec_select_all(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
144 {
145     FIXME("(%p)->(%ld %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
146     return E_NOTIMPL;
147 }
148
149 static HRESULT exec_clear_selection(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
150 {
151     FIXME("(%p)->(%ld %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
152     return E_NOTIMPL;
153 }
154
155 static HRESULT exec_zoom(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
156 {
157     FIXME("(%p)->(%ld %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
158     return E_NOTIMPL;
159 }
160
161 static HRESULT exec_get_zoom_range(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
162 {
163     FIXME("(%p)->(%ld %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
164     return E_NOTIMPL;
165 }
166
167 static HRESULT exec_refresh(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
168 {
169     FIXME("(%p)->(%ld %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
170     return E_NOTIMPL;
171 }
172
173 static HRESULT exec_stop(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
174 {
175     FIXME("(%p)->(%ld %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
176     return E_NOTIMPL;
177 }
178
179 static HRESULT exec_stop_download(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
180 {
181     FIXME("(%p)->(%ld %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
182     return E_NOTIMPL;
183 }
184
185 static HRESULT exec_delete(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
186 {
187     FIXME("(%p)->(%ld %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
188     return E_NOTIMPL;
189 }
190
191 static HRESULT exec_enable_interaction(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
192 {
193     FIXME("(%p)->(%ld %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
194     return E_NOTIMPL;
195 }
196
197 static HRESULT exec_on_unload(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
198 {
199     TRACE("(%p)->(%ld %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
200
201     /* Tests show that we have nothing more to do here */
202
203     if(pvaOut) {
204         V_VT(pvaOut) = VT_BOOL;
205         V_BOOL(pvaOut) = VARIANT_TRUE;
206     }
207
208     return S_OK;
209 }
210
211 static HRESULT exec_show_page_setup(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
212 {
213     FIXME("(%p)->(%ld %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
214     return E_NOTIMPL;
215 }
216
217 static HRESULT exec_show_print(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
218 {
219     FIXME("(%p)->(%ld %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
220     return E_NOTIMPL;
221 }
222
223 static HRESULT exec_close(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
224 {
225     FIXME("(%p)->(%ld %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
226     return E_NOTIMPL;
227 }
228
229 static HRESULT exec_set_print_template(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
230 {
231     FIXME("(%p)->(%ld %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
232     return E_NOTIMPL;
233 }
234
235 static HRESULT exec_get_print_template(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
236 {
237     FIXME("(%p)->(%ld %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
238     return E_NOTIMPL;
239 }
240
241 static HRESULT exec_browsemode(HTMLDocument *This)
242 {
243     WARN("(%p)\n", This);
244
245     This->usermode = BROWSEMODE;
246
247     return S_OK;
248 }
249
250 static HRESULT exec_baselinefont3(HTMLDocument *This)
251 {
252     FIXME("(%p)\n", This);
253     return S_OK;
254 }
255
256 static const struct {
257     OLECMDF cmdf;
258     HRESULT (*func)(HTMLDocument*,DWORD,VARIANT*,VARIANT*);
259 } exec_table[OLECMDID_GETPRINTTEMPLATE+1] = {
260     {0},
261     { OLECMDF_SUPPORTED,                  exec_open                 }, /* OLECMDID_OPEN */
262     { OLECMDF_SUPPORTED,                  exec_new                  }, /* OLECMDID_NEW */
263     { OLECMDF_SUPPORTED,                  exec_save                 }, /* OLECMDID_SAVE */
264     { OLECMDF_SUPPORTED|OLECMDF_ENABLED,  exec_save_as              }, /* OLECMDID_SAVEAS */
265     { OLECMDF_SUPPORTED,                  exec_save_copy_as         }, /* OLECMDID_SAVECOPYAS */
266     { OLECMDF_SUPPORTED|OLECMDF_ENABLED,  exec_print                }, /* OLECMDID_PRINT */
267     { OLECMDF_SUPPORTED|OLECMDF_ENABLED,  exec_print_preview        }, /* OLECMDID_PRINTPREVIEW */
268     { OLECMDF_SUPPORTED|OLECMDF_ENABLED,  exec_page_setup           }, /* OLECMDID_PAGESETUP */
269     { OLECMDF_SUPPORTED,                  exec_spell                }, /* OLECMDID_SPELL */
270     { OLECMDF_SUPPORTED|OLECMDF_ENABLED,  exec_properties           }, /* OLECMDID_PROPERTIES */
271     { OLECMDF_SUPPORTED,                  exec_cut                  }, /* OLECMDID_CUT */
272     { OLECMDF_SUPPORTED,                  exec_copy                 }, /* OLECMDID_COPY */
273     { OLECMDF_SUPPORTED,                  exec_paste                }, /* OLECMDID_PASTE */
274     { OLECMDF_SUPPORTED,                  exec_paste_special        }, /* OLECMDID_PASTESPECIAL */
275     { OLECMDF_SUPPORTED,                  exec_undo                 }, /* OLECMDID_UNDO */
276     { OLECMDF_SUPPORTED,                  exec_rendo                }, /* OLECMDID_REDO */
277     { OLECMDF_SUPPORTED|OLECMDF_ENABLED,  exec_select_all           }, /* OLECMDID_SELECTALL */
278     { OLECMDF_SUPPORTED,                  exec_clear_selection      }, /* OLECMDID_CLEARSELECTION */
279     { OLECMDF_SUPPORTED,                  exec_zoom                 }, /* OLECMDID_ZOOM */
280     { OLECMDF_SUPPORTED,                  exec_get_zoom_range       }, /* OLECMDID_GETZOOMRANGE */
281     {0},
282     { OLECMDF_SUPPORTED|OLECMDF_ENABLED,  exec_refresh              }, /* OLECMDID_REFRESH */
283     { OLECMDF_SUPPORTED|OLECMDF_ENABLED,  exec_stop                 }, /* OLECMDID_STOP */
284     {0},{0},{0},{0},{0},{0},
285     { OLECMDF_SUPPORTED,                  exec_stop_download        }, /* OLECMDID_STOPDOWNLOAD */
286     {0},{0},
287     { OLECMDF_SUPPORTED,                  exec_delete               }, /* OLECMDID_DELETE */
288     {0},{0},
289     { OLECMDF_SUPPORTED,                  exec_enable_interaction   }, /* OLECMDID_ENABLE_INTERACTION */
290     { OLECMDF_SUPPORTED,                  exec_on_unload            }, /* OLECMDID_ONUNLOAD */
291     {0},{0},{0},{0},{0},
292     { OLECMDF_SUPPORTED,                  exec_show_page_setup      }, /* OLECMDID_SHOWPAGESETUP */
293     { OLECMDF_SUPPORTED,                  exec_show_print           }, /* OLECMDID_SHOWPRINT */
294     {0},{0},
295     { OLECMDF_SUPPORTED,                  exec_close                }, /* OLECMDID_CLOSE */
296     {0},{0},{0},
297     { OLECMDF_SUPPORTED,                  exec_set_print_template   }, /* OLECMDID_SETPRINTTEMPLATE */
298     { OLECMDF_SUPPORTED,                  exec_get_print_template   }  /* OLECMDID_GETPRINTTEMPLATE */
299 };
300
301 static HRESULT WINAPI OleCommandTarget_QueryInterface(IOleCommandTarget *iface, REFIID riid, void **ppv)
302 {
303     HTMLDocument *This = CMDTARGET_THIS(iface);
304     return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppv);
305 }
306
307 static ULONG WINAPI OleCommandTarget_AddRef(IOleCommandTarget *iface)
308 {
309     HTMLDocument *This = CMDTARGET_THIS(iface);
310     return IHTMLDocument2_AddRef(HTMLDOC(This));
311 }
312
313 static ULONG WINAPI OleCommandTarget_Release(IOleCommandTarget *iface)
314 {
315     HTMLDocument *This = CMDTARGET_THIS(iface);
316     return IHTMLDocument_Release(HTMLDOC(This));
317 }
318
319 static HRESULT WINAPI OleCommandTarget_QueryStatus(IOleCommandTarget *iface, const GUID *pguidCmdGroup,
320         ULONG cCmds, OLECMD prgCmds[], OLECMDTEXT *pCmdText)
321 {
322     HTMLDocument *This = CMDTARGET_THIS(iface);
323     HRESULT hres = S_OK, hr;
324
325     TRACE("(%p)->(%s %ld %p %p)\n", This, debugstr_guid(pguidCmdGroup), cCmds, prgCmds, pCmdText);
326
327     if(!pguidCmdGroup) {
328         ULONG i;
329
330         for(i=0; i<cCmds; i++) {
331             if(prgCmds[i].cmdID<OLECMDID_OPEN || prgCmds[i].cmdID>OLECMDID_GETPRINTTEMPLATE) {
332                 WARN("Unsupported cmdID = %ld\n", prgCmds[i].cmdID);
333                 prgCmds[i].cmdf = 0;
334                 hres = OLECMDERR_E_NOTSUPPORTED;
335             }else {
336                 if(prgCmds[i].cmdID == OLECMDID_OPEN || prgCmds[i].cmdID == OLECMDID_NEW) {
337                     IOleCommandTarget *cmdtrg = NULL;
338                     OLECMD olecmd;
339
340                     prgCmds[i].cmdf = OLECMDF_SUPPORTED;
341                     if(This->client) {
342                         hr = IOleClientSite_QueryInterface(This->client, &IID_IOleCommandTarget,
343                                 (void**)&cmdtrg);
344                         if(SUCCEEDED(hr)) {
345                             olecmd.cmdID = prgCmds[i].cmdID;
346                             olecmd.cmdf = 0;
347
348                             hr = IOleCommandTarget_QueryStatus(cmdtrg, NULL, 1, &olecmd, NULL);
349                             if(SUCCEEDED(hr) && olecmd.cmdf)
350                                 prgCmds[i].cmdf = olecmd.cmdf;
351                         }
352                     }else {
353                         ERR("This->client == NULL, native would crash\n");
354                     }
355                 }else {
356                     prgCmds[i].cmdf = exec_table[prgCmds[i].cmdID].cmdf;
357                     TRACE("cmdID = %ld  returning %lx\n", prgCmds[i].cmdID, prgCmds[i].cmdf);
358                 }
359                 hres = S_OK;
360             }
361         }
362
363         if(pCmdText)
364             FIXME("Set pCmdText\n");
365     }else {
366         FIXME("Unsupported pguidCmdGroup %s\n", debugstr_guid(pguidCmdGroup));
367         hres = OLECMDERR_E_UNKNOWNGROUP;
368     }
369
370     return hres;
371 }
372
373 static HRESULT WINAPI OleCommandTarget_Exec(IOleCommandTarget *iface, const GUID *pguidCmdGroup,
374         DWORD nCmdID, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
375 {
376     HTMLDocument *This = CMDTARGET_THIS(iface);
377
378     if(!pguidCmdGroup) {
379         if(nCmdID<OLECMDID_OPEN || nCmdID>OLECMDID_GETPRINTTEMPLATE || !exec_table[nCmdID].func) {
380             WARN("Unsupported cmdID = %ld\n", nCmdID);
381             return OLECMDERR_E_NOTSUPPORTED;
382         }
383
384         return exec_table[nCmdID].func(This, nCmdexecopt, pvaIn, pvaOut);
385     }else if(IsEqualGUID(&CGID_Explorer, pguidCmdGroup)) {
386         FIXME("unsupported nCmdID %ld of CGID_Explorer group\n", nCmdID);
387         TRACE("%p %p\n", pvaIn, pvaOut);
388         return OLECMDERR_E_NOTSUPPORTED;
389     }else if(IsEqualGUID(&CGID_ShellDocView, pguidCmdGroup)) {
390         FIXME("unsupported nCmdID %ld of CGID_ShellDocView group\n", nCmdID);
391         return OLECMDERR_E_NOTSUPPORTED;
392     }else if(IsEqualGUID(&CGID_MSHTML, pguidCmdGroup)) {
393         switch(nCmdID) {
394         case IDM_BROWSEMODE:
395             return exec_browsemode(This);
396         case IDM_BASELINEFONT3:
397             return exec_baselinefont3(This);
398         default:
399             FIXME("unsupported nCmdID %ld of CGID_MSHTML group\n", nCmdID);
400             return OLECMDERR_E_NOTSUPPORTED;
401         }
402     }
403
404     FIXME("Unsupported pguidCmdGroup %s\n", debugstr_guid(pguidCmdGroup));
405     return OLECMDERR_E_UNKNOWNGROUP;
406 }
407
408 #undef CMDTARGET_THIS
409
410 static const IOleCommandTargetVtbl OleCommandTargetVtbl = {
411     OleCommandTarget_QueryInterface,
412     OleCommandTarget_AddRef,
413     OleCommandTarget_Release,
414     OleCommandTarget_QueryStatus,
415     OleCommandTarget_Exec
416 };
417
418 void HTMLDocument_OleCmd_Init(HTMLDocument *This)
419 {
420     This->lpOleCommandTargetVtbl = &OleCommandTargetVtbl;
421 }