comctl32/monthcal: Simplify WM_MOUSEMOVE handler.
[wine.git] / dlls / mshtml / htmllocation.c
blob45899b43379cf54515f135d4c24a597d0b1e99e1
1 /*
2 * Copyright 2008 Jacek Caban for CodeWeavers
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.
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.
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
19 #include <stdarg.h>
21 #define COBJMACROS
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"
31 #include "wine/debug.h"
33 #include "mshtml_private.h"
34 #include "resource.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
38 static HRESULT get_url(HTMLLocation *This, const WCHAR **ret)
40 if(!This->window || !This->window->doc_obj || !This->window->doc_obj->url) {
41 FIXME("No current URL\n");
42 return E_NOTIMPL;
45 *ret = This->window->doc_obj->url;
46 return S_OK;
50 #define HTMLLOCATION_THIS(iface) DEFINE_THIS(HTMLLocation, HTMLLocation, iface)
52 static HRESULT WINAPI HTMLLocation_QueryInterface(IHTMLLocation *iface, REFIID riid, void **ppv)
54 HTMLLocation *This = HTMLLOCATION_THIS(iface);
56 *ppv = NULL;
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;
68 if(*ppv) {
69 IUnknown_AddRef((IUnknown*)*ppv);
70 return S_OK;
73 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
74 return E_NOINTERFACE;
77 static ULONG WINAPI HTMLLocation_AddRef(IHTMLLocation *iface)
79 HTMLLocation *This = HTMLLOCATION_THIS(iface);
80 LONG ref = InterlockedIncrement(&This->ref);
82 TRACE("(%p) ref=%d\n", This, ref);
84 return ref;
87 static ULONG WINAPI HTMLLocation_Release(IHTMLLocation *iface)
89 HTMLLocation *This = HTMLLOCATION_THIS(iface);
90 LONG ref = InterlockedDecrement(&This->ref);
92 TRACE("(%p) ref=%d\n", This, ref);
94 if(!ref) {
95 if(This->window)
96 This->window->location = NULL;
97 release_dispex(&This->dispex);
98 heap_free(This);
101 return ref;
104 static HRESULT WINAPI HTMLLocation_GetTypeInfoCount(IHTMLLocation *iface, UINT *pctinfo)
106 HTMLLocation *This = HTMLLOCATION_THIS(iface);
107 return IDispatchEx_GetTypeInfoCount(DISPATCHEX(&This->dispex), pctinfo);
110 static HRESULT WINAPI HTMLLocation_GetTypeInfo(IHTMLLocation *iface, UINT iTInfo,
111 LCID lcid, ITypeInfo **ppTInfo)
113 HTMLLocation *This = HTMLLOCATION_THIS(iface);
114 return IDispatchEx_GetTypeInfo(DISPATCHEX(&This->dispex), iTInfo, lcid, ppTInfo);
117 static HRESULT WINAPI HTMLLocation_GetIDsOfNames(IHTMLLocation *iface, REFIID riid,
118 LPOLESTR *rgszNames, UINT cNames,
119 LCID lcid, DISPID *rgDispId)
121 HTMLLocation *This = HTMLLOCATION_THIS(iface);
122 return IDispatchEx_GetIDsOfNames(DISPATCHEX(&This->dispex), riid, rgszNames, cNames, lcid, rgDispId);
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)
129 HTMLLocation *This = HTMLLOCATION_THIS(iface);
130 return IDispatchEx_Invoke(DISPATCHEX(&This->dispex), dispIdMember, riid, lcid,
131 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
134 static HRESULT WINAPI HTMLLocation_put_href(IHTMLLocation *iface, BSTR v)
136 HTMLLocation *This = HTMLLOCATION_THIS(iface);
137 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
138 return E_NOTIMPL;
141 static HRESULT WINAPI HTMLLocation_get_href(IHTMLLocation *iface, BSTR *p)
143 HTMLLocation *This = HTMLLOCATION_THIS(iface);
144 const WCHAR *url;
145 HRESULT hres;
147 TRACE("(%p)->(%p)\n", This, p);
149 if(!p)
150 return E_POINTER;
152 hres = get_url(This, &url);
153 if(FAILED(hres))
154 return hres;
156 *p = SysAllocString(url);
157 return *p ? S_OK : E_OUTOFMEMORY;
160 static HRESULT WINAPI HTMLLocation_put_protocol(IHTMLLocation *iface, BSTR v)
162 HTMLLocation *This = HTMLLOCATION_THIS(iface);
163 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
164 return E_NOTIMPL;
167 static HRESULT WINAPI HTMLLocation_get_protocol(IHTMLLocation *iface, BSTR *p)
169 HTMLLocation *This = HTMLLOCATION_THIS(iface);
170 FIXME("(%p)->(%p)\n", This, p);
172 if(!p)
173 return E_POINTER;
175 return E_NOTIMPL;
178 static HRESULT WINAPI HTMLLocation_put_host(IHTMLLocation *iface, BSTR v)
180 HTMLLocation *This = HTMLLOCATION_THIS(iface);
181 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
182 return E_NOTIMPL;
185 static HRESULT WINAPI HTMLLocation_get_host(IHTMLLocation *iface, BSTR *p)
187 HTMLLocation *This = HTMLLOCATION_THIS(iface);
188 FIXME("(%p)->(%p)\n", This, p);
190 if(!p)
191 return E_POINTER;
193 return E_NOTIMPL;
196 static HRESULT WINAPI HTMLLocation_put_hostname(IHTMLLocation *iface, BSTR v)
198 HTMLLocation *This = HTMLLOCATION_THIS(iface);
199 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
200 return E_NOTIMPL;
203 static HRESULT WINAPI HTMLLocation_get_hostname(IHTMLLocation *iface, BSTR *p)
205 HTMLLocation *This = HTMLLOCATION_THIS(iface);
206 FIXME("(%p)->(%p)\n", This, p);
208 if(!p)
209 return E_POINTER;
211 return E_NOTIMPL;
214 static HRESULT WINAPI HTMLLocation_put_port(IHTMLLocation *iface, BSTR v)
216 HTMLLocation *This = HTMLLOCATION_THIS(iface);
217 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
218 return E_NOTIMPL;
221 static HRESULT WINAPI HTMLLocation_get_port(IHTMLLocation *iface, BSTR *p)
223 HTMLLocation *This = HTMLLOCATION_THIS(iface);
224 FIXME("(%p)->(%p)\n", This, p);
226 if(!p)
227 return E_POINTER;
229 return E_NOTIMPL;
232 static HRESULT WINAPI HTMLLocation_put_pathname(IHTMLLocation *iface, BSTR v)
234 HTMLLocation *This = HTMLLOCATION_THIS(iface);
235 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
236 return E_NOTIMPL;
239 static HRESULT WINAPI HTMLLocation_get_pathname(IHTMLLocation *iface, BSTR *p)
241 HTMLLocation *This = HTMLLOCATION_THIS(iface);
242 WCHAR buf[INTERNET_MAX_PATH_LENGTH];
243 URL_COMPONENTSW url = {sizeof(url)};
244 const WCHAR *doc_url;
245 DWORD size = 0;
246 HRESULT hres;
248 TRACE("(%p)->(%p)\n", This, p);
250 if(!p)
251 return E_POINTER;
253 hres = get_url(This, &doc_url);
254 if(FAILED(hres))
255 return hres;
257 hres = CoInternetParseUrl(doc_url, PARSE_PATH_FROM_URL, 0, buf, sizeof(buf), &size, 0);
258 if(SUCCEEDED(hres)) {
259 *p = SysAllocString(buf);
260 if(!*p)
261 return E_OUTOFMEMORY;
262 return S_OK;
265 url.dwUrlPathLength = 1;
266 if(!InternetCrackUrlW(doc_url, 0, 0, &url)) {
267 FIXME("InternetCrackUrl failed\n");
268 return E_FAIL;
271 if(!url.dwUrlPathLength) {
272 *p = NULL;
273 return S_OK;
276 *p = SysAllocStringLen(url.lpszUrlPath, url.dwUrlPathLength);
277 if(!*p)
278 return E_OUTOFMEMORY;
279 return S_OK;
282 static HRESULT WINAPI HTMLLocation_put_search(IHTMLLocation *iface, BSTR v)
284 HTMLLocation *This = HTMLLOCATION_THIS(iface);
285 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
286 return E_NOTIMPL;
289 static HRESULT WINAPI HTMLLocation_get_search(IHTMLLocation *iface, BSTR *p)
291 HTMLLocation *This = HTMLLOCATION_THIS(iface);
292 FIXME("(%p)->(%p)\n", This, p);
294 if(!p)
295 return E_POINTER;
297 return E_NOTIMPL;
300 static HRESULT WINAPI HTMLLocation_put_hash(IHTMLLocation *iface, BSTR v)
302 HTMLLocation *This = HTMLLOCATION_THIS(iface);
303 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
304 return E_NOTIMPL;
307 static HRESULT WINAPI HTMLLocation_get_hash(IHTMLLocation *iface, BSTR *p)
309 HTMLLocation *This = HTMLLOCATION_THIS(iface);
310 FIXME("(%p)->(%p)\n", This, p);
312 if(!p)
313 return E_POINTER;
315 return E_NOTIMPL;
318 static HRESULT WINAPI HTMLLocation_reload(IHTMLLocation *iface, VARIANT_BOOL flag)
320 HTMLLocation *This = HTMLLOCATION_THIS(iface);
321 FIXME("(%p)->(%x)\n", This, flag);
322 return E_NOTIMPL;
325 static HRESULT WINAPI HTMLLocation_replace(IHTMLLocation *iface, BSTR bstr)
327 HTMLLocation *This = HTMLLOCATION_THIS(iface);
328 FIXME("(%p)->(%s)\n", This, debugstr_w(bstr));
329 return E_NOTIMPL;
332 static HRESULT WINAPI HTMLLocation_assign(IHTMLLocation *iface, BSTR bstr)
334 HTMLLocation *This = HTMLLOCATION_THIS(iface);
335 FIXME("(%p)->(%s)\n", This, debugstr_w(bstr));
336 return E_NOTIMPL;
339 static HRESULT WINAPI HTMLLocation_toString(IHTMLLocation *iface, BSTR *String)
341 HTMLLocation *This = HTMLLOCATION_THIS(iface);
342 FIXME("(%p)->(%p)\n", This, String);
343 return E_NOTIMPL;
346 #undef HTMLLOCATION_THIS
348 static const IHTMLLocationVtbl HTMLLocationVtbl = {
349 HTMLLocation_QueryInterface,
350 HTMLLocation_AddRef,
351 HTMLLocation_Release,
352 HTMLLocation_GetTypeInfoCount,
353 HTMLLocation_GetTypeInfo,
354 HTMLLocation_GetIDsOfNames,
355 HTMLLocation_Invoke,
356 HTMLLocation_put_href,
357 HTMLLocation_get_href,
358 HTMLLocation_put_protocol,
359 HTMLLocation_get_protocol,
360 HTMLLocation_put_host,
361 HTMLLocation_get_host,
362 HTMLLocation_put_hostname,
363 HTMLLocation_get_hostname,
364 HTMLLocation_put_port,
365 HTMLLocation_get_port,
366 HTMLLocation_put_pathname,
367 HTMLLocation_get_pathname,
368 HTMLLocation_put_search,
369 HTMLLocation_get_search,
370 HTMLLocation_put_hash,
371 HTMLLocation_get_hash,
372 HTMLLocation_reload,
373 HTMLLocation_replace,
374 HTMLLocation_assign,
375 HTMLLocation_toString
378 static const tid_t HTMLLocation_iface_tids[] = {
379 IHTMLLocation_tid,
382 static dispex_static_data_t HTMLLocation_dispex = {
383 NULL,
384 DispHTMLLocation_tid,
385 NULL,
386 HTMLLocation_iface_tids
390 HRESULT HTMLLocation_Create(HTMLWindow *window, HTMLLocation **ret)
392 HTMLLocation *location;
394 location = heap_alloc(sizeof(*location));
395 if(!location)
396 return E_OUTOFMEMORY;
398 location->lpHTMLLocationVtbl = &HTMLLocationVtbl;
399 location->ref = 1;
400 location->window = window;
402 init_dispex(&location->dispex, (IUnknown*)HTMLLOCATION(location), &HTMLLocation_dispex);
404 *ret = location;
405 return S_OK;