d3d8: Add a separate function for surface initialization.
[wine] / dlls / mshtml / htmllocation.c
1 /*
2  * Copyright 2008 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 <stdarg.h>
20
21 #define COBJMACROS
22
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winuser.h"
26 #include "winreg.h"
27 #include "ole2.h"
28 #include "wininet.h"
29 #include "shlwapi.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 #define HTMLLOCATION_THIS(iface) DEFINE_THIS(HTMLLocation, HTMLLocation, iface)
39
40 static HRESULT WINAPI HTMLLocation_QueryInterface(IHTMLLocation *iface, REFIID riid, void **ppv)
41 {
42     HTMLLocation *This = HTMLLOCATION_THIS(iface);
43
44     *ppv = NULL;
45
46     if(IsEqualGUID(&IID_IUnknown, riid)) {
47         TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
48         *ppv = HTMLLOCATION(This);
49     }else if(IsEqualGUID(&IID_IHTMLLocation, riid)) {
50         TRACE("(%p)->(IID_IHTMLLocation %p)\n", This, ppv);
51         *ppv = HTMLLOCATION(This);
52     }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
53         return *ppv ? S_OK : E_NOINTERFACE;
54     }
55
56     if(*ppv) {
57         IUnknown_AddRef((IUnknown*)*ppv);
58         return S_OK;
59     }
60
61     WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
62     return E_NOINTERFACE;
63 }
64
65 static ULONG WINAPI HTMLLocation_AddRef(IHTMLLocation *iface)
66 {
67     HTMLLocation *This = HTMLLOCATION_THIS(iface);
68     LONG ref = InterlockedIncrement(&This->ref);
69
70     TRACE("(%p) ref=%d\n", This, ref);
71
72     return ref;
73 }
74
75 static ULONG WINAPI HTMLLocation_Release(IHTMLLocation *iface)
76 {
77     HTMLLocation *This = HTMLLOCATION_THIS(iface);
78     LONG ref = InterlockedDecrement(&This->ref);
79
80     TRACE("(%p) ref=%d\n", This, ref);
81
82     if(!ref) {
83         if(This->doc && This->doc->location == This)
84             This->doc->location = NULL;
85         release_dispex(&This->dispex);
86         heap_free(This);
87     }
88
89     return ref;
90 }
91
92 static HRESULT WINAPI HTMLLocation_GetTypeInfoCount(IHTMLLocation *iface, UINT *pctinfo)
93 {
94     HTMLLocation *This = HTMLLOCATION_THIS(iface);
95     return IDispatchEx_GetTypeInfoCount(DISPATCHEX(&This->dispex), pctinfo);
96 }
97
98 static HRESULT WINAPI HTMLLocation_GetTypeInfo(IHTMLLocation *iface, UINT iTInfo,
99                                               LCID lcid, ITypeInfo **ppTInfo)
100 {
101     HTMLLocation *This = HTMLLOCATION_THIS(iface);
102     return IDispatchEx_GetTypeInfo(DISPATCHEX(&This->dispex), iTInfo, lcid, ppTInfo);
103 }
104
105 static HRESULT WINAPI HTMLLocation_GetIDsOfNames(IHTMLLocation *iface, REFIID riid,
106                                                 LPOLESTR *rgszNames, UINT cNames,
107                                                 LCID lcid, DISPID *rgDispId)
108 {
109     HTMLLocation *This = HTMLLOCATION_THIS(iface);
110     return IDispatchEx_GetIDsOfNames(DISPATCHEX(&This->dispex), riid, rgszNames, cNames, lcid, rgDispId);
111 }
112
113 static HRESULT WINAPI HTMLLocation_Invoke(IHTMLLocation *iface, DISPID dispIdMember,
114                             REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
115                             VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
116 {
117     HTMLLocation *This = HTMLLOCATION_THIS(iface);
118     return IDispatchEx_Invoke(DISPATCHEX(&This->dispex), dispIdMember, riid, lcid,
119             wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
120 }
121
122 static HRESULT WINAPI HTMLLocation_put_href(IHTMLLocation *iface, BSTR v)
123 {
124     HTMLLocation *This = HTMLLOCATION_THIS(iface);
125     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
126     return E_NOTIMPL;
127 }
128
129 static HRESULT WINAPI HTMLLocation_get_href(IHTMLLocation *iface, BSTR *p)
130 {
131     HTMLLocation *This = HTMLLOCATION_THIS(iface);
132
133     TRACE("(%p)->(%p)\n", This, p);
134
135     if(!p)
136         return E_POINTER;
137
138     if(!This->doc || !This->doc->url) {
139         FIXME("No current URL\n");
140         return E_NOTIMPL;
141     }
142
143     *p = SysAllocString(This->doc->url);
144
145     return S_OK;
146 }
147
148 static HRESULT WINAPI HTMLLocation_put_protocol(IHTMLLocation *iface, BSTR v)
149 {
150     HTMLLocation *This = HTMLLOCATION_THIS(iface);
151     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
152     return E_NOTIMPL;
153 }
154
155 static HRESULT WINAPI HTMLLocation_get_protocol(IHTMLLocation *iface, BSTR *p)
156 {
157     HTMLLocation *This = HTMLLOCATION_THIS(iface);
158     FIXME("(%p)->(%p)\n", This, p);
159     return E_NOTIMPL;
160 }
161
162 static HRESULT WINAPI HTMLLocation_put_host(IHTMLLocation *iface, BSTR v)
163 {
164     HTMLLocation *This = HTMLLOCATION_THIS(iface);
165     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
166     return E_NOTIMPL;
167 }
168
169 static HRESULT WINAPI HTMLLocation_get_host(IHTMLLocation *iface, BSTR *p)
170 {
171     HTMLLocation *This = HTMLLOCATION_THIS(iface);
172     FIXME("(%p)->(%p)\n", This, p);
173     return E_NOTIMPL;
174 }
175
176 static HRESULT WINAPI HTMLLocation_put_hostname(IHTMLLocation *iface, BSTR v)
177 {
178     HTMLLocation *This = HTMLLOCATION_THIS(iface);
179     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
180     return E_NOTIMPL;
181 }
182
183 static HRESULT WINAPI HTMLLocation_get_hostname(IHTMLLocation *iface, BSTR *p)
184 {
185     HTMLLocation *This = HTMLLOCATION_THIS(iface);
186     FIXME("(%p)->(%p)\n", This, p);
187     return E_NOTIMPL;
188 }
189
190 static HRESULT WINAPI HTMLLocation_put_port(IHTMLLocation *iface, BSTR v)
191 {
192     HTMLLocation *This = HTMLLOCATION_THIS(iface);
193     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
194     return E_NOTIMPL;
195 }
196
197 static HRESULT WINAPI HTMLLocation_get_port(IHTMLLocation *iface, BSTR *p)
198 {
199     HTMLLocation *This = HTMLLOCATION_THIS(iface);
200     FIXME("(%p)->(%p)\n", This, p);
201     return E_NOTIMPL;
202 }
203
204 static HRESULT WINAPI HTMLLocation_put_pathname(IHTMLLocation *iface, BSTR v)
205 {
206     HTMLLocation *This = HTMLLOCATION_THIS(iface);
207     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
208     return E_NOTIMPL;
209 }
210
211 static HRESULT WINAPI HTMLLocation_get_pathname(IHTMLLocation *iface, BSTR *p)
212 {
213     HTMLLocation *This = HTMLLOCATION_THIS(iface);
214     WCHAR buf[INTERNET_MAX_PATH_LENGTH];
215     URL_COMPONENTSW url = {sizeof(url)};
216     DWORD size = 0;
217     HRESULT hres;
218
219     TRACE("(%p)->(%p)\n", This, p);
220
221     if(!This->doc || !This->doc->url) {
222         FIXME("No current URL\n");
223         return E_NOTIMPL;
224     }
225
226     hres = CoInternetParseUrl(This->doc->url, PARSE_PATH_FROM_URL, 0, buf, sizeof(buf), &size, 0);
227     if(SUCCEEDED(hres)) {
228         *p = SysAllocString(buf);
229         if(!*p)
230             return E_OUTOFMEMORY;
231         return S_OK;
232     }
233
234     url.dwUrlPathLength = 1;
235     if(!InternetCrackUrlW(This->doc->url, 0, 0, &url)) {
236         FIXME("InternetCrackUrl failed\n");
237         return E_FAIL;
238     }
239
240     if(!url.dwUrlPathLength) {
241         *p = NULL;
242         return S_OK;
243     }
244
245     *p = SysAllocStringLen(url.lpszUrlPath, url.dwUrlPathLength);
246     if(!*p)
247         return E_OUTOFMEMORY;
248     return S_OK;
249 }
250
251 static HRESULT WINAPI HTMLLocation_put_search(IHTMLLocation *iface, BSTR v)
252 {
253     HTMLLocation *This = HTMLLOCATION_THIS(iface);
254     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
255     return E_NOTIMPL;
256 }
257
258 static HRESULT WINAPI HTMLLocation_get_search(IHTMLLocation *iface, BSTR *p)
259 {
260     HTMLLocation *This = HTMLLOCATION_THIS(iface);
261     FIXME("(%p)->(%p)\n", This, p);
262     return E_NOTIMPL;
263 }
264
265 static HRESULT WINAPI HTMLLocation_put_hash(IHTMLLocation *iface, BSTR v)
266 {
267     HTMLLocation *This = HTMLLOCATION_THIS(iface);
268     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
269     return E_NOTIMPL;
270 }
271
272 static HRESULT WINAPI HTMLLocation_get_hash(IHTMLLocation *iface, BSTR *p)
273 {
274     HTMLLocation *This = HTMLLOCATION_THIS(iface);
275     FIXME("(%p)->(%p)\n", This, p);
276     return E_NOTIMPL;
277 }
278
279 static HRESULT WINAPI HTMLLocation_reload(IHTMLLocation *iface, VARIANT_BOOL flag)
280 {
281     HTMLLocation *This = HTMLLOCATION_THIS(iface);
282     FIXME("(%p)->(%x)\n", This, flag);
283     return E_NOTIMPL;
284 }
285
286 static HRESULT WINAPI HTMLLocation_replace(IHTMLLocation *iface, BSTR bstr)
287 {
288     HTMLLocation *This = HTMLLOCATION_THIS(iface);
289     FIXME("(%p)->(%s)\n", This, debugstr_w(bstr));
290     return E_NOTIMPL;
291 }
292
293 static HRESULT WINAPI HTMLLocation_assign(IHTMLLocation *iface, BSTR bstr)
294 {
295     HTMLLocation *This = HTMLLOCATION_THIS(iface);
296     FIXME("(%p)->(%s)\n", This, debugstr_w(bstr));
297     return E_NOTIMPL;
298 }
299
300 static HRESULT WINAPI HTMLLocation_toString(IHTMLLocation *iface, BSTR *String)
301 {
302     HTMLLocation *This = HTMLLOCATION_THIS(iface);
303     FIXME("(%p)->(%p)\n", This, String);
304     return E_NOTIMPL;
305 }
306
307 static HRESULT HTMLLocation_value(IUnknown *iface, LCID lcid, WORD flags, DISPPARAMS *params,
308         VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
309 {
310     HTMLLocation *This = HTMLLOCATION_THIS(iface);
311     HRESULT hres;
312
313     TRACE("(%p)\n", This);
314
315     switch(flags) {
316     case DISPATCH_PROPERTYGET: {
317         BSTR str;
318
319         hres = IHTMLLocation_get_href(HTMLLOCATION(This), &str);
320         if(FAILED(hres))
321             return hres;
322
323         V_VT(res) = VT_BSTR;
324         V_BSTR(res) = str;
325         break;
326     }
327     default:
328         FIXME("unimplemented flags %x\n", flags);
329         return E_NOTIMPL;
330     }
331
332     return S_OK;
333 }
334
335 #undef HTMLLOCATION_THIS
336
337 static const IHTMLLocationVtbl HTMLLocationVtbl = {
338     HTMLLocation_QueryInterface,
339     HTMLLocation_AddRef,
340     HTMLLocation_Release,
341     HTMLLocation_GetTypeInfoCount,
342     HTMLLocation_GetTypeInfo,
343     HTMLLocation_GetIDsOfNames,
344     HTMLLocation_Invoke,
345     HTMLLocation_put_href,
346     HTMLLocation_get_href,
347     HTMLLocation_put_protocol,
348     HTMLLocation_get_protocol,
349     HTMLLocation_put_host,
350     HTMLLocation_get_host,
351     HTMLLocation_put_hostname,
352     HTMLLocation_get_hostname,
353     HTMLLocation_put_port,
354     HTMLLocation_get_port,
355     HTMLLocation_put_pathname,
356     HTMLLocation_get_pathname,
357     HTMLLocation_put_search,
358     HTMLLocation_get_search,
359     HTMLLocation_put_hash,
360     HTMLLocation_get_hash,
361     HTMLLocation_reload,
362     HTMLLocation_replace,
363     HTMLLocation_assign,
364     HTMLLocation_toString
365 };
366
367 static const dispex_static_data_vtbl_t HTMLLocation_dispex_vtbl = {
368     HTMLLocation_value,
369     NULL,
370     NULL
371 };
372
373 static const tid_t HTMLLocation_iface_tids[] = {
374     IHTMLLocation_tid,
375     0
376 };
377 static dispex_static_data_t HTMLLocation_dispex = {
378     &HTMLLocation_dispex_vtbl,
379     DispHTMLLocation_tid,
380     NULL,
381     HTMLLocation_iface_tids
382 };
383
384
385 HTMLLocation *HTMLLocation_Create(HTMLDocument *doc)
386 {
387     HTMLLocation *ret = heap_alloc(sizeof(*ret));
388
389     ret->lpHTMLLocationVtbl = &HTMLLocationVtbl;
390     ret->ref = 1;
391     ret->doc = doc;
392
393     init_dispex(&ret->dispex, (IUnknown*)HTMLLOCATION(ret),  &HTMLLocation_dispex);
394
395     return ret;
396 }