mshtml: Set default original uri in NewChannelFromURI.
[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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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, BOOL fActivate)
95 {
96     HTMLDocument *This = ACTOBJ_THIS(iface);
97     FIXME("(%p)->(%x)\n", This, fActivate);
98     return E_NOTIMPL;
99 }
100
101 static HRESULT WINAPI OleInPlaceActiveObject_OnDocWindowActivate(IOleInPlaceActiveObject *iface, BOOL fActivate)
102 {
103     HTMLDocument *This = ACTOBJ_THIS(iface);
104     FIXME("(%p)->(%x)\n", This, fActivate);
105     return E_NOTIMPL;
106 }
107
108 static HRESULT WINAPI OleInPlaceActiveObject_ResizeBorder(IOleInPlaceActiveObject *iface, LPCRECT prcBorder,
109                                                 IOleInPlaceUIWindow *pUIWindow, BOOL fFrameWindow)
110 {
111     HTMLDocument *This = ACTOBJ_THIS(iface);
112     FIXME("(%p)->(%p %p %x)\n", This, prcBorder, pUIWindow, fFrameWindow);
113     return E_NOTIMPL;
114 }
115
116 static HRESULT WINAPI OleInPlaceActiveObject_EnableModeless(IOleInPlaceActiveObject *iface, BOOL fEnable)
117 {
118     HTMLDocument *This = ACTOBJ_THIS(iface);
119     FIXME("(%p)->(%x)\n", This, fEnable);
120     return E_NOTIMPL;
121 }
122
123 static const IOleInPlaceActiveObjectVtbl OleInPlaceActiveObjectVtbl = {
124     OleInPlaceActiveObject_QueryInterface,
125     OleInPlaceActiveObject_AddRef,
126     OleInPlaceActiveObject_Release,
127     OleInPlaceActiveObject_GetWindow,
128     OleInPlaceActiveObject_ContextSensitiveHelp,
129     OleInPlaceActiveObject_TranslateAccelerator,
130     OleInPlaceActiveObject_OnFrameWindowActivate,
131     OleInPlaceActiveObject_OnDocWindowActivate,
132     OleInPlaceActiveObject_ResizeBorder,
133     OleInPlaceActiveObject_EnableModeless
134 };
135
136 #undef ACTOBJ_THIS
137
138 /**********************************************************
139  * IOleInPlaceObjectWindowless implementation
140  */
141
142 #define OLEINPLACEWND_THIS(iface) DEFINE_THIS(HTMLDocument, OleInPlaceObjectWindowless, iface)
143
144 static HRESULT WINAPI OleInPlaceObjectWindowless_QueryInterface(IOleInPlaceObjectWindowless *iface,
145         REFIID riid, void **ppvObject)
146 {
147     HTMLDocument *This = OLEINPLACEWND_THIS(iface);
148     return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppvObject);
149 }
150
151 static ULONG WINAPI OleInPlaceObjectWindowless_AddRef(IOleInPlaceObjectWindowless *iface)
152 {
153     HTMLDocument *This = OLEINPLACEWND_THIS(iface);
154     return IHTMLDocument2_AddRef(HTMLDOC(This));
155 }
156
157 static ULONG WINAPI OleInPlaceObjectWindowless_Release(IOleInPlaceObjectWindowless *iface)
158 {
159     HTMLDocument *This = OLEINPLACEWND_THIS(iface);
160     return IHTMLDocument2_Release(HTMLDOC(This));
161 }
162
163 static HRESULT WINAPI OleInPlaceObjectWindowless_GetWindow(IOleInPlaceObjectWindowless *iface,
164         HWND *phwnd)
165 {
166     HTMLDocument *This = OLEINPLACEWND_THIS(iface);
167     return IOleWindow_GetWindow(OLEWIN(This), phwnd);
168 }
169
170 static HRESULT WINAPI OleInPlaceObjectWindowless_ContextSensitiveHelp(IOleInPlaceObjectWindowless *iface,
171         BOOL fEnterMode)
172 {
173     HTMLDocument *This = OLEINPLACEWND_THIS(iface);
174     return IOleWindow_ContextSensitiveHelp(OLEWIN(This), fEnterMode);
175 }
176
177 static HRESULT WINAPI OleInPlaceObjectWindowless_InPlaceDeactivate(IOleInPlaceObjectWindowless *iface)
178 {
179     HTMLDocument *This = OLEINPLACEWND_THIS(iface);
180
181     TRACE("(%p)\n", This);
182
183     if(This->ui_active)
184         IOleDocumentView_UIActivate(DOCVIEW(This), FALSE);
185     This->window_active = FALSE;
186
187     if(!This->in_place_active)
188         return S_OK;
189
190     if(This->frame)
191         IOleInPlaceFrame_Release(This->frame);
192
193     if(This->hwnd) {
194         ShowWindow(This->hwnd, SW_HIDE);
195         SetWindowPos(This->hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
196     }
197
198     This->in_place_active = FALSE;
199     if(This->ipsite)
200         IOleInPlaceSite_OnInPlaceDeactivate(This->ipsite);
201
202     return S_OK;
203 }
204
205 static HRESULT WINAPI OleInPlaceObjectWindowless_UIDeactivate(IOleInPlaceObjectWindowless *iface)
206 {
207     HTMLDocument *This = OLEINPLACEWND_THIS(iface);
208     FIXME("(%p)\n", This);
209     return E_NOTIMPL;
210 }
211
212 static HRESULT WINAPI OleInPlaceObjectWindowless_SetObjectRects(IOleInPlaceObjectWindowless *iface,
213         LPCRECT lprcPosRect, LPCRECT lprcClipRect)
214 {
215     HTMLDocument *This = OLEINPLACEWND_THIS(iface);
216     FIXME("(%p)->(%p %p)\n", This, lprcPosRect, lprcClipRect);
217     return E_NOTIMPL;
218 }
219
220 static HRESULT WINAPI OleInPlaceObjectWindowless_ReactivateAndUndo(IOleInPlaceObjectWindowless *iface)
221 {
222     HTMLDocument *This = OLEINPLACEWND_THIS(iface);
223     FIXME("(%p)\n", This);
224     return E_NOTIMPL;
225 }
226
227 static HRESULT WINAPI OleInPlaceObjectWindowless_OnWindowMessage(IOleInPlaceObjectWindowless *iface,
228         UINT msg, WPARAM wParam, LPARAM lParam, LRESULT *lpResult)
229 {
230     HTMLDocument *This = OLEINPLACEWND_THIS(iface);
231     FIXME("(%p)->(%u %u %lu %p)\n", This, msg, wParam, lParam, lpResult);
232     return E_NOTIMPL;
233 }
234
235 static HRESULT WINAPI OleInPlaceObjectWindowless_GetDropTarget(IOleInPlaceObjectWindowless *iface,
236         IDropTarget **ppDropTarget)
237 {
238     HTMLDocument *This = OLEINPLACEWND_THIS(iface);
239     FIXME("(%p)->(%p)\n", This, ppDropTarget);
240     return E_NOTIMPL;
241 }
242
243 static const IOleInPlaceObjectWindowlessVtbl OleInPlaceObjectWindowlessVtbl = {
244     OleInPlaceObjectWindowless_QueryInterface,
245     OleInPlaceObjectWindowless_AddRef,
246     OleInPlaceObjectWindowless_Release,
247     OleInPlaceObjectWindowless_GetWindow,
248     OleInPlaceObjectWindowless_ContextSensitiveHelp,
249     OleInPlaceObjectWindowless_InPlaceDeactivate,
250     OleInPlaceObjectWindowless_UIDeactivate,
251     OleInPlaceObjectWindowless_SetObjectRects,
252     OleInPlaceObjectWindowless_ReactivateAndUndo,
253     OleInPlaceObjectWindowless_OnWindowMessage,
254     OleInPlaceObjectWindowless_GetDropTarget
255 };
256
257 #undef INPLACEWIN_THIS
258
259 void HTMLDocument_ShowContextMenu(HTMLDocument *This, DWORD dwID, POINT *ppt)
260 {
261     HMENU menu_res, menu;
262     HRESULT hres;
263
264     hres = IDocHostUIHandler_ShowContextMenu(This->hostui, dwID, ppt,
265             (IUnknown*)CMDTARGET(This), (IDispatch*)HTMLDOC(This));
266     if(hres == S_OK)
267         return;
268
269     menu_res = LoadMenuW(hInst, MAKEINTRESOURCEW(IDR_BROWSE_CONTEXT_MENU));
270     menu = GetSubMenu(menu_res, dwID);
271
272     TrackPopupMenu(menu, TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_RETURNCMD,
273             ppt->x, ppt->y, 0, This->hwnd, NULL);
274
275     DestroyMenu(menu_res);
276 }
277
278 void HTMLDocument_Window_Init(HTMLDocument *This)
279 {
280     This->lpOleInPlaceActiveObjectVtbl = &OleInPlaceActiveObjectVtbl;
281     This->lpOleInPlaceObjectWindowlessVtbl = &OleInPlaceObjectWindowlessVtbl;
282 }