rpcrt4: Don't try to bind to a null handle.
[wine] / dlls / mshtml / olewnd.c
1 /*
2  * Copyright 2005 Jacek Caban
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
31 #include "wine/debug.h"
32
33 #include "mshtml_private.h"
34 #include "resource.h"
35
36 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
37
38 /**********************************************************
39  * IOleInPlaceActiveObject implementation
40  */
41
42 static inline HTMLDocument *impl_from_IOleInPlaceActiveObject(IOleInPlaceActiveObject *iface)
43 {
44     return CONTAINING_RECORD(iface, HTMLDocument, IOleInPlaceActiveObject_iface);
45 }
46
47 static HRESULT WINAPI OleInPlaceActiveObject_QueryInterface(IOleInPlaceActiveObject *iface, REFIID riid, void **ppv)
48 {
49     HTMLDocument *This = impl_from_IOleInPlaceActiveObject(iface);
50     return htmldoc_query_interface(This, riid, ppv);
51 }
52
53 static ULONG WINAPI OleInPlaceActiveObject_AddRef(IOleInPlaceActiveObject *iface)
54 {
55     HTMLDocument *This = impl_from_IOleInPlaceActiveObject(iface);
56     return htmldoc_addref(This);
57 }
58
59 static ULONG WINAPI OleInPlaceActiveObject_Release(IOleInPlaceActiveObject *iface)
60 {
61     HTMLDocument *This = impl_from_IOleInPlaceActiveObject(iface);
62     return htmldoc_release(This);
63 }
64
65 static HRESULT WINAPI OleInPlaceActiveObject_GetWindow(IOleInPlaceActiveObject *iface, HWND *phwnd)
66 {
67     HTMLDocument *This = impl_from_IOleInPlaceActiveObject(iface);
68
69     TRACE("(%p)->(%p)\n", This, phwnd);
70
71     if(!phwnd)
72         return E_INVALIDARG;
73
74     if(!This->doc_obj->in_place_active) {
75         *phwnd = NULL;
76         return E_FAIL;
77     }
78
79     *phwnd = This->doc_obj->hwnd;
80     return S_OK;
81 }
82
83 static HRESULT WINAPI OleInPlaceActiveObject_ContextSensitiveHelp(IOleInPlaceActiveObject *iface, BOOL fEnterMode)
84 {
85     HTMLDocument *This = impl_from_IOleInPlaceActiveObject(iface);
86     FIXME("(%p)->(%x)\n", This, fEnterMode);
87     return E_NOTIMPL;
88 }
89
90 static HRESULT WINAPI OleInPlaceActiveObject_TranslateAccelerator(IOleInPlaceActiveObject *iface, LPMSG lpmsg)
91 {
92     HTMLDocument *This = impl_from_IOleInPlaceActiveObject(iface);
93     FIXME("(%p)->(%p)\n", This, lpmsg);
94     return E_NOTIMPL;
95 }
96
97 static HRESULT WINAPI OleInPlaceActiveObject_OnFrameWindowActivate(IOleInPlaceActiveObject *iface,
98         BOOL fActivate)
99 {
100     HTMLDocument *This = impl_from_IOleInPlaceActiveObject(iface);
101
102     TRACE("(%p)->(%x)\n", This, fActivate);
103
104     if(This->doc_obj->hostui)
105         IDocHostUIHandler_OnFrameWindowActivate(This->doc_obj->hostui, fActivate);
106
107     return S_OK;
108 }
109
110 static HRESULT WINAPI OleInPlaceActiveObject_OnDocWindowActivate(IOleInPlaceActiveObject *iface, BOOL fActivate)
111 {
112     HTMLDocument *This = impl_from_IOleInPlaceActiveObject(iface);
113     FIXME("(%p)->(%x)\n", This, fActivate);
114     return E_NOTIMPL;
115 }
116
117 static HRESULT WINAPI OleInPlaceActiveObject_ResizeBorder(IOleInPlaceActiveObject *iface, LPCRECT prcBorder,
118                                                 IOleInPlaceUIWindow *pUIWindow, BOOL fFrameWindow)
119 {
120     HTMLDocument *This = impl_from_IOleInPlaceActiveObject(iface);
121     FIXME("(%p)->(%p %p %x)\n", This, prcBorder, pUIWindow, fFrameWindow);
122     return E_NOTIMPL;
123 }
124
125 static HRESULT WINAPI OleInPlaceActiveObject_EnableModeless(IOleInPlaceActiveObject *iface, BOOL fEnable)
126 {
127     HTMLDocument *This = impl_from_IOleInPlaceActiveObject(iface);
128     FIXME("(%p)->(%x)\n", This, fEnable);
129     return E_NOTIMPL;
130 }
131
132 static const IOleInPlaceActiveObjectVtbl OleInPlaceActiveObjectVtbl = {
133     OleInPlaceActiveObject_QueryInterface,
134     OleInPlaceActiveObject_AddRef,
135     OleInPlaceActiveObject_Release,
136     OleInPlaceActiveObject_GetWindow,
137     OleInPlaceActiveObject_ContextSensitiveHelp,
138     OleInPlaceActiveObject_TranslateAccelerator,
139     OleInPlaceActiveObject_OnFrameWindowActivate,
140     OleInPlaceActiveObject_OnDocWindowActivate,
141     OleInPlaceActiveObject_ResizeBorder,
142     OleInPlaceActiveObject_EnableModeless
143 };
144
145 /**********************************************************
146  * IOleInPlaceObjectWindowless implementation
147  */
148
149 static inline HTMLDocument *impl_from_IOleInPlaceObjectWindowless(IOleInPlaceObjectWindowless *iface)
150 {
151     return CONTAINING_RECORD(iface, HTMLDocument, IOleInPlaceObjectWindowless_iface);
152 }
153
154 static HRESULT WINAPI OleInPlaceObjectWindowless_QueryInterface(IOleInPlaceObjectWindowless *iface,
155         REFIID riid, void **ppv)
156 {
157     HTMLDocument *This = impl_from_IOleInPlaceObjectWindowless(iface);
158     return htmldoc_query_interface(This, riid, ppv);
159 }
160
161 static ULONG WINAPI OleInPlaceObjectWindowless_AddRef(IOleInPlaceObjectWindowless *iface)
162 {
163     HTMLDocument *This = impl_from_IOleInPlaceObjectWindowless(iface);
164     return htmldoc_addref(This);
165 }
166
167 static ULONG WINAPI OleInPlaceObjectWindowless_Release(IOleInPlaceObjectWindowless *iface)
168 {
169     HTMLDocument *This = impl_from_IOleInPlaceObjectWindowless(iface);
170     return htmldoc_release(This);
171 }
172
173 static HRESULT WINAPI OleInPlaceObjectWindowless_GetWindow(IOleInPlaceObjectWindowless *iface,
174         HWND *phwnd)
175 {
176     HTMLDocument *This = impl_from_IOleInPlaceObjectWindowless(iface);
177     return IOleWindow_GetWindow(&This->IOleInPlaceActiveObject_iface, phwnd);
178 }
179
180 static HRESULT WINAPI OleInPlaceObjectWindowless_ContextSensitiveHelp(IOleInPlaceObjectWindowless *iface,
181         BOOL fEnterMode)
182 {
183     HTMLDocument *This = impl_from_IOleInPlaceObjectWindowless(iface);
184     return IOleWindow_ContextSensitiveHelp(&This->IOleInPlaceActiveObject_iface, fEnterMode);
185 }
186
187 static HRESULT WINAPI OleInPlaceObjectWindowless_InPlaceDeactivate(IOleInPlaceObjectWindowless *iface)
188 {
189     HTMLDocument *This = impl_from_IOleInPlaceObjectWindowless(iface);
190
191     TRACE("(%p)\n", This);
192
193     if(This->doc_obj->ui_active)
194         IOleDocumentView_UIActivate(&This->IOleDocumentView_iface, FALSE);
195     This->doc_obj->window_active = FALSE;
196
197     if(!This->doc_obj->in_place_active)
198         return S_OK;
199
200     if(This->doc_obj->frame)
201         IOleInPlaceFrame_Release(This->doc_obj->frame);
202
203     if(This->doc_obj->hwnd) {
204         ShowWindow(This->doc_obj->hwnd, SW_HIDE);
205         SetWindowPos(This->doc_obj->hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
206     }
207
208     This->doc_obj->focus = FALSE;
209     notif_focus(This->doc_obj);
210
211     This->doc_obj->in_place_active = FALSE;
212     if(This->doc_obj->ipsite) {
213         IOleInPlaceSiteEx *ipsiteex;
214         HRESULT hres;
215
216         hres = IOleInPlaceSite_QueryInterface(This->doc_obj->ipsite, &IID_IOleInPlaceSiteEx, (void**)&ipsiteex);
217         if(SUCCEEDED(hres)) {
218             IOleInPlaceSiteEx_OnInPlaceDeactivateEx(ipsiteex, TRUE);
219             IOleInPlaceSiteEx_Release(ipsiteex);
220         }else {
221             IOleInPlaceSite_OnInPlaceDeactivate(This->doc_obj->ipsite);
222         }
223     }
224
225     return S_OK;
226 }
227
228 static HRESULT WINAPI OleInPlaceObjectWindowless_UIDeactivate(IOleInPlaceObjectWindowless *iface)
229 {
230     HTMLDocument *This = impl_from_IOleInPlaceObjectWindowless(iface);
231     FIXME("(%p)\n", This);
232     return E_NOTIMPL;
233 }
234
235 static HRESULT WINAPI OleInPlaceObjectWindowless_SetObjectRects(IOleInPlaceObjectWindowless *iface,
236         LPCRECT lprcPosRect, LPCRECT lprcClipRect)
237 {
238     HTMLDocument *This = impl_from_IOleInPlaceObjectWindowless(iface);
239     FIXME("(%p)->(%p %p)\n", This, lprcPosRect, lprcClipRect);
240     return E_NOTIMPL;
241 }
242
243 static HRESULT WINAPI OleInPlaceObjectWindowless_ReactivateAndUndo(IOleInPlaceObjectWindowless *iface)
244 {
245     HTMLDocument *This = impl_from_IOleInPlaceObjectWindowless(iface);
246     FIXME("(%p)\n", This);
247     return E_NOTIMPL;
248 }
249
250 static HRESULT WINAPI OleInPlaceObjectWindowless_OnWindowMessage(IOleInPlaceObjectWindowless *iface,
251         UINT msg, WPARAM wParam, LPARAM lParam, LRESULT *lpResult)
252 {
253     HTMLDocument *This = impl_from_IOleInPlaceObjectWindowless(iface);
254     FIXME("(%p)->(%u %lu %lu %p)\n", This, msg, wParam, lParam, lpResult);
255     return E_NOTIMPL;
256 }
257
258 static HRESULT WINAPI OleInPlaceObjectWindowless_GetDropTarget(IOleInPlaceObjectWindowless *iface,
259         IDropTarget **ppDropTarget)
260 {
261     HTMLDocument *This = impl_from_IOleInPlaceObjectWindowless(iface);
262     FIXME("(%p)->(%p)\n", This, ppDropTarget);
263     return E_NOTIMPL;
264 }
265
266 static const IOleInPlaceObjectWindowlessVtbl OleInPlaceObjectWindowlessVtbl = {
267     OleInPlaceObjectWindowless_QueryInterface,
268     OleInPlaceObjectWindowless_AddRef,
269     OleInPlaceObjectWindowless_Release,
270     OleInPlaceObjectWindowless_GetWindow,
271     OleInPlaceObjectWindowless_ContextSensitiveHelp,
272     OleInPlaceObjectWindowless_InPlaceDeactivate,
273     OleInPlaceObjectWindowless_UIDeactivate,
274     OleInPlaceObjectWindowless_SetObjectRects,
275     OleInPlaceObjectWindowless_ReactivateAndUndo,
276     OleInPlaceObjectWindowless_OnWindowMessage,
277     OleInPlaceObjectWindowless_GetDropTarget
278 };
279
280 void HTMLDocument_Window_Init(HTMLDocument *This)
281 {
282     This->IOleInPlaceActiveObject_iface.lpVtbl = &OleInPlaceActiveObjectVtbl;
283     This->IOleInPlaceObjectWindowless_iface.lpVtbl = &OleInPlaceObjectWindowlessVtbl;
284 }