mshtml: Implement IHTMLStyle get/put wordSpacing.
[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         heap_free(This);
86     }
87
88     return ref;
89 }
90
91 static HRESULT WINAPI HTMLLocation_GetTypeInfoCount(IHTMLLocation *iface, UINT *pctinfo)
92 {
93     HTMLLocation *This = HTMLLOCATION_THIS(iface);
94     return IDispatchEx_GetTypeInfoCount(DISPATCHEX(&This->dispex), pctinfo);
95 }
96
97 static HRESULT WINAPI HTMLLocation_GetTypeInfo(IHTMLLocation *iface, UINT iTInfo,
98                                               LCID lcid, ITypeInfo **ppTInfo)
99 {
100     HTMLLocation *This = HTMLLOCATION_THIS(iface);
101     return IDispatchEx_GetTypeInfo(DISPATCHEX(&This->dispex), iTInfo, lcid, ppTInfo);
102 }
103
104 static HRESULT WINAPI HTMLLocation_GetIDsOfNames(IHTMLLocation *iface, REFIID riid,
105                                                 LPOLESTR *rgszNames, UINT cNames,
106                                                 LCID lcid, DISPID *rgDispId)
107 {
108     HTMLLocation *This = HTMLLOCATION_THIS(iface);
109     return IDispatchEx_GetIDsOfNames(DISPATCHEX(&This->dispex), riid, rgszNames, cNames, lcid, rgDispId);
110 }
111
112 static HRESULT WINAPI HTMLLocation_Invoke(IHTMLLocation *iface, DISPID dispIdMember,
113                             REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
114                             VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
115 {
116     HTMLLocation *This = HTMLLOCATION_THIS(iface);
117     return IDispatchEx_Invoke(DISPATCHEX(&This->dispex), dispIdMember, riid, lcid,
118             wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
119 }
120
121 static HRESULT WINAPI HTMLLocation_put_href(IHTMLLocation *iface, BSTR v)
122 {
123     HTMLLocation *This = HTMLLOCATION_THIS(iface);
124     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
125     return E_NOTIMPL;
126 }
127
128 static HRESULT WINAPI HTMLLocation_get_href(IHTMLLocation *iface, BSTR *p)
129 {
130     HTMLLocation *This = HTMLLOCATION_THIS(iface);
131
132     TRACE("(%p)->(%p)\n", This, p);
133
134     if(!p)
135         return E_POINTER;
136
137     if(!This->doc || !This->doc->url) {
138         FIXME("No current URL\n");
139         return E_NOTIMPL;
140     }
141
142     *p = SysAllocString(This->doc->url);
143
144     return S_OK;
145 }
146
147 static HRESULT WINAPI HTMLLocation_put_protocol(IHTMLLocation *iface, BSTR v)
148 {
149     HTMLLocation *This = HTMLLOCATION_THIS(iface);
150     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
151     return E_NOTIMPL;
152 }
153
154 static HRESULT WINAPI HTMLLocation_get_protocol(IHTMLLocation *iface, BSTR *p)
155 {
156     HTMLLocation *This = HTMLLOCATION_THIS(iface);
157     FIXME("(%p)->(%p)\n", This, p);
158     return E_NOTIMPL;
159 }
160
161 static HRESULT WINAPI HTMLLocation_put_host(IHTMLLocation *iface, BSTR v)
162 {
163     HTMLLocation *This = HTMLLOCATION_THIS(iface);
164     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
165     return E_NOTIMPL;
166 }
167
168 static HRESULT WINAPI HTMLLocation_get_host(IHTMLLocation *iface, BSTR *p)
169 {
170     HTMLLocation *This = HTMLLOCATION_THIS(iface);
171     FIXME("(%p)->(%p)\n", This, p);
172     return E_NOTIMPL;
173 }
174
175 static HRESULT WINAPI HTMLLocation_put_hostname(IHTMLLocation *iface, BSTR v)
176 {
177     HTMLLocation *This = HTMLLOCATION_THIS(iface);
178     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
179     return E_NOTIMPL;
180 }
181
182 static HRESULT WINAPI HTMLLocation_get_hostname(IHTMLLocation *iface, BSTR *p)
183 {
184     HTMLLocation *This = HTMLLOCATION_THIS(iface);
185     FIXME("(%p)->(%p)\n", This, p);
186     return E_NOTIMPL;
187 }
188
189 static HRESULT WINAPI HTMLLocation_put_port(IHTMLLocation *iface, BSTR v)
190 {
191     HTMLLocation *This = HTMLLOCATION_THIS(iface);
192     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
193     return E_NOTIMPL;
194 }
195
196 static HRESULT WINAPI HTMLLocation_get_port(IHTMLLocation *iface, BSTR *p)
197 {
198     HTMLLocation *This = HTMLLOCATION_THIS(iface);
199     FIXME("(%p)->(%p)\n", This, p);
200     return E_NOTIMPL;
201 }
202
203 static HRESULT WINAPI HTMLLocation_put_pathname(IHTMLLocation *iface, BSTR v)
204 {
205     HTMLLocation *This = HTMLLOCATION_THIS(iface);
206     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
207     return E_NOTIMPL;
208 }
209
210 static HRESULT WINAPI HTMLLocation_get_pathname(IHTMLLocation *iface, BSTR *p)
211 {
212     HTMLLocation *This = HTMLLOCATION_THIS(iface);
213     WCHAR buf[INTERNET_MAX_PATH_LENGTH];
214     URL_COMPONENTSW url = {sizeof(url)};
215     DWORD size = 0;
216     HRESULT hres;
217
218     TRACE("(%p)->(%p)\n", This, p);
219
220     if(!This->doc || !This->doc->url) {
221         FIXME("No current URL\n");
222         return E_NOTIMPL;
223     }
224
225     hres = CoInternetParseUrl(This->doc->url, PARSE_PATH_FROM_URL, 0, buf, sizeof(buf), &size, 0);
226     if(SUCCEEDED(hres)) {
227         *p = SysAllocString(buf);
228         if(!*p)
229             return E_OUTOFMEMORY;
230         return S_OK;
231     }
232
233     url.dwUrlPathLength = 1;
234     if(!InternetCrackUrlW(This->doc->url, 0, 0, &url)) {
235         FIXME("InternetCrackUrl failed\n");
236         return E_FAIL;
237     }
238
239     if(!url.dwUrlPathLength) {
240         *p = NULL;
241         return S_OK;
242     }
243
244     *p = SysAllocStringLen(url.lpszUrlPath, url.dwUrlPathLength);
245     if(!*p)
246         return E_OUTOFMEMORY;
247     return S_OK;
248 }
249
250 static HRESULT WINAPI HTMLLocation_put_search(IHTMLLocation *iface, BSTR v)
251 {
252     HTMLLocation *This = HTMLLOCATION_THIS(iface);
253     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
254     return E_NOTIMPL;
255 }
256
257 static HRESULT WINAPI HTMLLocation_get_search(IHTMLLocation *iface, BSTR *p)
258 {
259     HTMLLocation *This = HTMLLOCATION_THIS(iface);
260     FIXME("(%p)->(%p)\n", This, p);
261     return E_NOTIMPL;
262 }
263
264 static HRESULT WINAPI HTMLLocation_put_hash(IHTMLLocation *iface, BSTR v)
265 {
266     HTMLLocation *This = HTMLLOCATION_THIS(iface);
267     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
268     return E_NOTIMPL;
269 }
270
271 static HRESULT WINAPI HTMLLocation_get_hash(IHTMLLocation *iface, BSTR *p)
272 {
273     HTMLLocation *This = HTMLLOCATION_THIS(iface);
274     FIXME("(%p)->(%p)\n", This, p);
275     return E_NOTIMPL;
276 }
277
278 static HRESULT WINAPI HTMLLocation_reload(IHTMLLocation *iface, VARIANT_BOOL flag)
279 {
280     HTMLLocation *This = HTMLLOCATION_THIS(iface);
281     FIXME("(%p)->(%x)\n", This, flag);
282     return E_NOTIMPL;
283 }
284
285 static HRESULT WINAPI HTMLLocation_replace(IHTMLLocation *iface, BSTR bstr)
286 {
287     HTMLLocation *This = HTMLLOCATION_THIS(iface);
288     FIXME("(%p)->(%s)\n", This, debugstr_w(bstr));
289     return E_NOTIMPL;
290 }
291
292 static HRESULT WINAPI HTMLLocation_assign(IHTMLLocation *iface, BSTR bstr)
293 {
294     HTMLLocation *This = HTMLLOCATION_THIS(iface);
295     FIXME("(%p)->(%s)\n", This, debugstr_w(bstr));
296     return E_NOTIMPL;
297 }
298
299 static HRESULT WINAPI HTMLLocation_toString(IHTMLLocation *iface, BSTR *String)
300 {
301     HTMLLocation *This = HTMLLOCATION_THIS(iface);
302     FIXME("(%p)->(%p)\n", This, String);
303     return E_NOTIMPL;
304 }
305
306 #undef HTMLLOCATION_THIS
307
308 static const IHTMLLocationVtbl HTMLLocationVtbl = {
309     HTMLLocation_QueryInterface,
310     HTMLLocation_AddRef,
311     HTMLLocation_Release,
312     HTMLLocation_GetTypeInfoCount,
313     HTMLLocation_GetTypeInfo,
314     HTMLLocation_GetIDsOfNames,
315     HTMLLocation_Invoke,
316     HTMLLocation_put_href,
317     HTMLLocation_get_href,
318     HTMLLocation_put_protocol,
319     HTMLLocation_get_protocol,
320     HTMLLocation_put_host,
321     HTMLLocation_get_host,
322     HTMLLocation_put_hostname,
323     HTMLLocation_get_hostname,
324     HTMLLocation_put_port,
325     HTMLLocation_get_port,
326     HTMLLocation_put_pathname,
327     HTMLLocation_get_pathname,
328     HTMLLocation_put_search,
329     HTMLLocation_get_search,
330     HTMLLocation_put_hash,
331     HTMLLocation_get_hash,
332     HTMLLocation_reload,
333     HTMLLocation_replace,
334     HTMLLocation_assign,
335     HTMLLocation_toString
336 };
337
338 static const tid_t HTMLLocation_iface_tids[] = {
339     IHTMLLocation_tid,
340     0
341 };
342 static dispex_static_data_t HTMLLocation_dispex = {
343     NULL,
344     DispHTMLLocation_tid,
345     NULL,
346     HTMLLocation_iface_tids
347 };
348
349
350 HTMLLocation *HTMLLocation_Create(HTMLDocument *doc)
351 {
352     HTMLLocation *ret = heap_alloc(sizeof(*ret));
353
354     ret->lpHTMLLocationVtbl = &HTMLLocationVtbl;
355     ret->ref = 1;
356     ret->doc = doc;
357
358     init_dispex(&ret->dispex, (IUnknown*)HTMLLOCATION(ret),  &HTMLLocation_dispex);
359
360     return ret;
361 }