mshtml: COM cleanup for the IDispatchEx iface in DispatchEx.
[wine] / dlls / mshtml / ipwindow.c
1 /*
2  * Copyright 2010 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
23 #define COBJMACROS
24
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winuser.h"
28 #include "ole2.h"
29 #include "shlobj.h"
30
31 #include "mshtml_private.h"
32 #include "pluginhost.h"
33
34 #include "wine/debug.h"
35 #include "wine/unicode.h"
36
37 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
38
39 typedef struct {
40     IOleInPlaceFrame IOleInPlaceFrame_iface;
41     LONG ref;
42 } InPlaceFrame;
43
44 static inline InPlaceFrame *impl_from_IOleInPlaceFrame(IOleInPlaceFrame *iface)
45 {
46     return CONTAINING_RECORD(iface, InPlaceFrame, IOleInPlaceFrame_iface);
47 }
48
49 static HRESULT WINAPI InPlaceFrame_QueryInterface(IOleInPlaceFrame *iface,
50                                                   REFIID riid, void **ppv)
51 {
52     InPlaceFrame *This = impl_from_IOleInPlaceFrame(iface);
53
54     if(IsEqualGUID(&IID_IUnknown, riid)) {
55         TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
56         *ppv = &This->IOleInPlaceFrame_iface;
57     }else if(IsEqualGUID(&IID_IOleWindow, riid)) {
58         TRACE("(%p)->(IID_IOleWindow %p)\n", This, ppv);
59         *ppv = &This->IOleInPlaceFrame_iface;
60     }else if(IsEqualGUID(&IID_IOleInPlaceUIWindow, riid)) {
61         TRACE("(%p)->(IID_IOleInPlaceUIWindow %p)\n", This, ppv);
62         *ppv = &This->IOleInPlaceFrame_iface;
63     }else if(IsEqualGUID(&IID_IOleInPlaceFrame, riid)) {
64         TRACE("(%p)->(IID_IOleInPlaceFrame %p)\n", This, ppv);
65         *ppv = &This->IOleInPlaceFrame_iface;
66     }else {
67         WARN("Unsopported interface %s\n", debugstr_guid(riid));
68         *ppv = NULL;
69         return E_NOINTERFACE;
70     }
71
72     IUnknown_AddRef((IUnknown*)*ppv);
73     return S_OK;
74 }
75
76 static ULONG WINAPI InPlaceFrame_AddRef(IOleInPlaceFrame *iface)
77 {
78     InPlaceFrame *This = impl_from_IOleInPlaceFrame(iface);
79     LONG ref = InterlockedIncrement(&This->ref);
80
81     TRACE("(%p) ref=%d\n", This, ref);
82
83     return ref;
84 }
85
86 static ULONG WINAPI InPlaceFrame_Release(IOleInPlaceFrame *iface)
87 {
88     InPlaceFrame *This = impl_from_IOleInPlaceFrame(iface);
89     LONG ref = InterlockedDecrement(&This->ref);
90
91     TRACE("(%p) ref=%d\n", This, ref);
92
93     if(!ref)
94         heap_free(This);
95
96     return ref;
97 }
98
99 static HRESULT WINAPI InPlaceFrame_GetWindow(IOleInPlaceFrame *iface, HWND *phwnd)
100 {
101     InPlaceFrame *This = impl_from_IOleInPlaceFrame(iface);
102     FIXME("(%p)->(%p)\n", This, phwnd);
103     return E_NOTIMPL;
104 }
105
106 static HRESULT WINAPI InPlaceFrame_ContextSensitiveHelp(IOleInPlaceFrame *iface,
107                                                         BOOL fEnterMode)
108 {
109     InPlaceFrame *This = impl_from_IOleInPlaceFrame(iface);
110     FIXME("(%p)->(%x)\n", This, fEnterMode);
111     return E_NOTIMPL;
112 }
113
114 static HRESULT WINAPI InPlaceFrame_GetBorder(IOleInPlaceFrame *iface, LPRECT lprectBorder)
115 {
116     InPlaceFrame *This = impl_from_IOleInPlaceFrame(iface);
117     FIXME("(%p)->(%p)\n", This, lprectBorder);
118     return E_NOTIMPL;
119 }
120
121 static HRESULT WINAPI InPlaceFrame_RequestBorderSpace(IOleInPlaceFrame *iface,
122                                                       LPCBORDERWIDTHS pborderwidths)
123 {
124     InPlaceFrame *This = impl_from_IOleInPlaceFrame(iface);
125     FIXME("(%p)->(%p)\n", This, pborderwidths);
126     return E_NOTIMPL;
127 }
128
129 static HRESULT WINAPI InPlaceFrame_SetBorderSpace(IOleInPlaceFrame *iface,
130                                                   LPCBORDERWIDTHS pborderwidths)
131 {
132     InPlaceFrame *This = impl_from_IOleInPlaceFrame(iface);
133     FIXME("(%p)->(%p)\n", This, pborderwidths);
134     return E_NOTIMPL;
135 }
136
137 static HRESULT WINAPI InPlaceFrame_SetActiveObject(IOleInPlaceFrame *iface,
138         IOleInPlaceActiveObject *pActiveObject, LPCOLESTR pszObjName)
139 {
140     InPlaceFrame *This = impl_from_IOleInPlaceFrame(iface);
141     FIXME("(%p)->(%p %s)\n", This, pActiveObject, debugstr_w(pszObjName));
142     return E_NOTIMPL;
143 }
144
145 static HRESULT WINAPI InPlaceFrame_InsertMenus(IOleInPlaceFrame *iface, HMENU hmenuShared,
146         LPOLEMENUGROUPWIDTHS lpMenuWidths)
147 {
148     InPlaceFrame *This = impl_from_IOleInPlaceFrame(iface);
149     FIXME("(%p)->(%p %p)\n", This, hmenuShared, lpMenuWidths);
150     return E_NOTIMPL;
151 }
152
153 static HRESULT WINAPI InPlaceFrame_SetMenu(IOleInPlaceFrame *iface, HMENU hmenuShared,
154         HOLEMENU holemenu, HWND hwndActiveObject)
155 {
156     InPlaceFrame *This = impl_from_IOleInPlaceFrame(iface);
157     FIXME("(%p)->(%p %p %p)\n", This, hmenuShared, holemenu, hwndActiveObject);
158     return E_NOTIMPL;
159 }
160
161 static HRESULT WINAPI InPlaceFrame_RemoveMenus(IOleInPlaceFrame *iface, HMENU hmenuShared)
162 {
163     InPlaceFrame *This = impl_from_IOleInPlaceFrame(iface);
164     FIXME("(%p)->(%p)\n", This, hmenuShared);
165     return E_NOTIMPL;
166 }
167
168 static HRESULT WINAPI InPlaceFrame_SetStatusText(IOleInPlaceFrame *iface,
169                                                  LPCOLESTR pszStatusText)
170 {
171     InPlaceFrame *This = impl_from_IOleInPlaceFrame(iface);
172     FIXME("(%p)->(%s)\n", This, debugstr_w(pszStatusText));
173     return E_NOTIMPL;
174 }
175
176 static HRESULT WINAPI InPlaceFrame_EnableModeless(IOleInPlaceFrame *iface, BOOL fEnable)
177 {
178     InPlaceFrame *This = impl_from_IOleInPlaceFrame(iface);
179     FIXME("(%p)->(%x)\n", This, fEnable);
180     return E_NOTIMPL;
181 }
182
183 static HRESULT WINAPI InPlaceFrame_TranslateAccelerator(IOleInPlaceFrame *iface, LPMSG lpmsg,
184                                                         WORD wID)
185 {
186     InPlaceFrame *This = impl_from_IOleInPlaceFrame(iface);
187     FIXME("(%p)->(%p %d)\n", This, lpmsg, wID);
188     return E_NOTIMPL;
189 }
190
191 #undef impl_from_IOleInPlaceFrame
192
193 static const IOleInPlaceFrameVtbl OleInPlaceFrameVtbl = {
194     InPlaceFrame_QueryInterface,
195     InPlaceFrame_AddRef,
196     InPlaceFrame_Release,
197     InPlaceFrame_GetWindow,
198     InPlaceFrame_ContextSensitiveHelp,
199     InPlaceFrame_GetBorder,
200     InPlaceFrame_RequestBorderSpace,
201     InPlaceFrame_SetBorderSpace,
202     InPlaceFrame_SetActiveObject,
203     InPlaceFrame_InsertMenus,
204     InPlaceFrame_SetMenu,
205     InPlaceFrame_RemoveMenus,
206     InPlaceFrame_SetStatusText,
207     InPlaceFrame_EnableModeless,
208     InPlaceFrame_TranslateAccelerator
209 };
210
211 HRESULT create_ip_frame(IOleInPlaceFrame **ret)
212 {
213     InPlaceFrame *frame;
214
215     frame = heap_alloc_zero(sizeof(*frame));
216     if(!frame)
217         return E_OUTOFMEMORY;
218
219     frame->IOleInPlaceFrame_iface.lpVtbl = &OleInPlaceFrameVtbl;
220     frame->ref = 1;
221
222     *ret = &frame->IOleInPlaceFrame_iface;
223     return S_OK;
224 }
225
226 typedef struct {
227     IOleInPlaceUIWindow IOleInPlaceUIWindow_iface;
228     LONG ref;
229 } InPlaceUIWindow;
230
231 static inline InPlaceUIWindow *impl_from_IOleInPlaceUIWindow(IOleInPlaceUIWindow *iface)
232 {
233     return CONTAINING_RECORD(iface, InPlaceUIWindow, IOleInPlaceUIWindow_iface);
234 }
235
236 static HRESULT WINAPI InPlaceUIWindow_QueryInterface(IOleInPlaceUIWindow *iface, REFIID riid, void **ppv)
237 {
238     InPlaceUIWindow *This = impl_from_IOleInPlaceUIWindow(iface);
239
240     if(IsEqualGUID(&IID_IUnknown, riid)) {
241         TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
242         *ppv = &This->IOleInPlaceUIWindow_iface;
243     }else if(IsEqualGUID(&IID_IOleWindow, riid)) {
244         TRACE("(%p)->(IID_IOleWindow %p)\n", This, ppv);
245         *ppv = &This->IOleInPlaceUIWindow_iface;
246     }else if(IsEqualGUID(&IID_IOleInPlaceUIWindow, riid)) {
247         TRACE("(%p)->(IID_IOleInPlaceUIWindow %p)\n", This, ppv);
248         *ppv = &This->IOleInPlaceUIWindow_iface;
249     }else {
250         WARN("Unsopported interface %s\n", debugstr_guid(riid));
251         *ppv = NULL;
252         return E_NOINTERFACE;
253     }
254
255     IUnknown_AddRef((IUnknown*)*ppv);
256     return S_OK;
257 }
258
259 static ULONG WINAPI InPlaceUIWindow_AddRef(IOleInPlaceUIWindow *iface)
260 {
261     InPlaceUIWindow *This = impl_from_IOleInPlaceUIWindow(iface);
262     LONG ref = InterlockedIncrement(&This->ref);
263
264     TRACE("(%p) ref=%d\n", This, ref);
265
266     return ref;
267 }
268
269 static ULONG WINAPI InPlaceUIWindow_Release(IOleInPlaceUIWindow *iface)
270 {
271     InPlaceUIWindow *This = impl_from_IOleInPlaceUIWindow(iface);
272     LONG ref = InterlockedDecrement(&This->ref);
273
274     TRACE("(%p) ref=%d\n", This, ref);
275
276     if(!ref)
277         heap_free(This);
278
279     return ref;
280 }
281
282 static HRESULT WINAPI InPlaceUIWindow_GetWindow(IOleInPlaceUIWindow *iface, HWND *phwnd)
283 {
284     InPlaceUIWindow *This = impl_from_IOleInPlaceUIWindow(iface);
285     FIXME("(%p)->(%p)\n", This, phwnd);
286     return E_NOTIMPL;
287 }
288
289 static HRESULT WINAPI InPlaceUIWindow_ContextSensitiveHelp(IOleInPlaceUIWindow *iface,
290         BOOL fEnterMode)
291 {
292     InPlaceUIWindow *This = impl_from_IOleInPlaceUIWindow(iface);
293     FIXME("(%p)->(%x)\n", This, fEnterMode);
294     return E_NOTIMPL;
295 }
296
297 static HRESULT WINAPI InPlaceUIWindow_GetBorder(IOleInPlaceUIWindow *iface, LPRECT lprectBorder)
298 {
299     InPlaceUIWindow *This = impl_from_IOleInPlaceUIWindow(iface);
300     FIXME("(%p)->(%p)\n", This, lprectBorder);
301     return E_NOTIMPL;
302 }
303
304 static HRESULT WINAPI InPlaceUIWindow_RequestBorderSpace(IOleInPlaceUIWindow *iface,
305         LPCBORDERWIDTHS pborderwidths)
306 {
307     InPlaceUIWindow *This = impl_from_IOleInPlaceUIWindow(iface);
308     FIXME("(%p)->(%p)\n", This, pborderwidths);
309     return E_NOTIMPL;
310 }
311
312 static HRESULT WINAPI InPlaceUIWindow_SetBorderSpace(IOleInPlaceUIWindow *iface,
313         LPCBORDERWIDTHS pborderwidths)
314 {
315     InPlaceUIWindow *This = impl_from_IOleInPlaceUIWindow(iface);
316     FIXME("(%p)->(%p)\n", This, pborderwidths);
317     return E_NOTIMPL;
318 }
319
320 static HRESULT WINAPI InPlaceUIWindow_SetActiveObject(IOleInPlaceUIWindow *iface,
321         IOleInPlaceActiveObject *pActiveObject, LPCOLESTR pszObjName)
322 {
323     InPlaceUIWindow *This = impl_from_IOleInPlaceUIWindow(iface);
324     FIXME("(%p)->(%p %s)\n", This, pActiveObject, debugstr_w(pszObjName));
325     return E_NOTIMPL;
326 }
327
328 static const IOleInPlaceUIWindowVtbl OleInPlaceUIWindowVtbl = {
329     InPlaceUIWindow_QueryInterface,
330     InPlaceUIWindow_AddRef,
331     InPlaceUIWindow_Release,
332     InPlaceUIWindow_GetWindow,
333     InPlaceUIWindow_ContextSensitiveHelp,
334     InPlaceUIWindow_GetBorder,
335     InPlaceUIWindow_RequestBorderSpace,
336     InPlaceUIWindow_SetBorderSpace,
337     InPlaceUIWindow_SetActiveObject,
338 };
339
340 HRESULT create_ip_window(IOleInPlaceUIWindow **ret)
341 {
342     InPlaceUIWindow *uiwindow;
343
344     uiwindow = heap_alloc_zero(sizeof(*uiwindow));
345     if(!uiwindow)
346         return E_OUTOFMEMORY;
347
348     uiwindow->IOleInPlaceUIWindow_iface.lpVtbl = &OleInPlaceUIWindowVtbl;
349     uiwindow->ref = 1;
350
351     *ret = &uiwindow->IOleInPlaceUIWindow_iface;
352     return S_OK;
353 }