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