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