ole32: Don't use real synchronous locks for storage synchronization.
[wine.git] / dlls / mshtml / htmllink.c
blob39853e42d80cf8edddd7c76ab5b6b700d03526cc
1 /*
2 * Copyright 2012 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>
20 #include <assert.h>
22 #define COBJMACROS
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winuser.h"
27 #include "ole2.h"
29 #include "wine/debug.h"
31 #include "mshtml_private.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
35 typedef struct {
36 HTMLElement element;
37 IHTMLLinkElement IHTMLLinkElement_iface;
39 nsIDOMHTMLLinkElement *nslink;
40 } HTMLLinkElement;
42 static inline HTMLLinkElement *impl_from_IHTMLLinkElement(IHTMLLinkElement *iface)
44 return CONTAINING_RECORD(iface, HTMLLinkElement, IHTMLLinkElement_iface);
47 static HRESULT WINAPI HTMLLinkElement_QueryInterface(IHTMLLinkElement *iface,
48 REFIID riid, void **ppv)
50 HTMLLinkElement *This = impl_from_IHTMLLinkElement(iface);
52 return IHTMLDOMNode_QueryInterface(&This->element.node.IHTMLDOMNode_iface, riid, ppv);
55 static ULONG WINAPI HTMLLinkElement_AddRef(IHTMLLinkElement *iface)
57 HTMLLinkElement *This = impl_from_IHTMLLinkElement(iface);
59 return IHTMLDOMNode_AddRef(&This->element.node.IHTMLDOMNode_iface);
62 static ULONG WINAPI HTMLLinkElement_Release(IHTMLLinkElement *iface)
64 HTMLLinkElement *This = impl_from_IHTMLLinkElement(iface);
66 return IHTMLDOMNode_Release(&This->element.node.IHTMLDOMNode_iface);
69 static HRESULT WINAPI HTMLLinkElement_GetTypeInfoCount(IHTMLLinkElement *iface, UINT *pctinfo)
71 HTMLLinkElement *This = impl_from_IHTMLLinkElement(iface);
73 return IDispatchEx_GetTypeInfoCount(&This->element.node.dispex.IDispatchEx_iface, pctinfo);
76 static HRESULT WINAPI HTMLLinkElement_GetTypeInfo(IHTMLLinkElement *iface, UINT iTInfo,
77 LCID lcid, ITypeInfo **ppTInfo)
79 HTMLLinkElement *This = impl_from_IHTMLLinkElement(iface);
81 return IDispatchEx_GetTypeInfo(&This->element.node.dispex.IDispatchEx_iface, iTInfo, lcid,
82 ppTInfo);
85 static HRESULT WINAPI HTMLLinkElement_GetIDsOfNames(IHTMLLinkElement *iface, REFIID riid,
86 LPOLESTR *rgszNames, UINT cNames,
87 LCID lcid, DISPID *rgDispId)
89 HTMLLinkElement *This = impl_from_IHTMLLinkElement(iface);
91 return IDispatchEx_GetIDsOfNames(&This->element.node.dispex.IDispatchEx_iface, riid, rgszNames,
92 cNames, lcid, rgDispId);
95 static HRESULT WINAPI HTMLLinkElement_Invoke(IHTMLLinkElement *iface, DISPID dispIdMember,
96 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
97 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
99 HTMLLinkElement *This = impl_from_IHTMLLinkElement(iface);
101 return IDispatchEx_Invoke(&This->element.node.dispex.IDispatchEx_iface, dispIdMember, riid,
102 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
105 static HRESULT WINAPI HTMLLinkElement_put_href(IHTMLLinkElement *iface, BSTR v)
107 HTMLLinkElement *This = impl_from_IHTMLLinkElement(iface);
108 nsAString href_str;
109 nsresult nsres;
111 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
113 nsAString_InitDepend(&href_str, v);
114 nsres = nsIDOMHTMLLinkElement_SetHref(This->nslink, &href_str);
115 nsAString_Finish(&href_str);
117 return NS_SUCCEEDED(nsres) ? S_OK : E_FAIL;
120 static HRESULT WINAPI HTMLLinkElement_get_href(IHTMLLinkElement *iface, BSTR *p)
122 HTMLLinkElement *This = impl_from_IHTMLLinkElement(iface);
123 nsAString href_str;
124 nsresult nsres;
126 TRACE("(%p)->(%p)\n", This, p);
128 nsAString_Init(&href_str, NULL);
129 nsres = nsIDOMHTMLLinkElement_GetHref(This->nslink, &href_str);
130 return return_nsstr(nsres, &href_str, p);
133 static HRESULT WINAPI HTMLLinkElement_put_rel(IHTMLLinkElement *iface, BSTR v)
135 HTMLLinkElement *This = impl_from_IHTMLLinkElement(iface);
136 nsAString rel_str;
137 nsresult nsres;
139 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
141 nsAString_InitDepend(&rel_str, v);
142 nsres = nsIDOMHTMLLinkElement_SetRel(This->nslink, &rel_str);
143 nsAString_Finish(&rel_str);
145 return NS_SUCCEEDED(nsres) ? S_OK : E_FAIL;
148 static HRESULT WINAPI HTMLLinkElement_get_rel(IHTMLLinkElement *iface, BSTR *p)
150 HTMLLinkElement *This = impl_from_IHTMLLinkElement(iface);
151 nsAString rel_str;
152 nsresult nsres;
154 TRACE("(%p)->(%p)\n", This, p);
156 nsAString_Init(&rel_str, NULL);
157 nsres = nsIDOMHTMLLinkElement_GetRel(This->nslink, &rel_str);
158 return return_nsstr(nsres, &rel_str, p);
161 static HRESULT WINAPI HTMLLinkElement_put_rev(IHTMLLinkElement *iface, BSTR v)
163 HTMLLinkElement *This = impl_from_IHTMLLinkElement(iface);
164 nsAString nsstr;
165 nsresult nsres;
167 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
169 nsAString_InitDepend(&nsstr, v);
170 nsres = nsIDOMHTMLLinkElement_SetRev(This->nslink, &nsstr);
171 nsAString_Finish(&nsstr);
172 if(NS_FAILED(nsres)) {
173 ERR("SetRev failed: %08x\n", nsres);
174 return E_FAIL;
177 return S_OK;
180 static HRESULT WINAPI HTMLLinkElement_get_rev(IHTMLLinkElement *iface, BSTR *p)
182 HTMLLinkElement *This = impl_from_IHTMLLinkElement(iface);
183 nsAString nsstr;
184 nsresult nsres;
186 TRACE("(%p)->(%p)\n", This, p);
188 nsAString_Init(&nsstr, NULL);
189 nsres = nsIDOMHTMLLinkElement_GetRev(This->nslink, &nsstr);
190 return return_nsstr(nsres, &nsstr, p);
193 static HRESULT WINAPI HTMLLinkElement_put_type(IHTMLLinkElement *iface, BSTR v)
195 HTMLLinkElement *This = impl_from_IHTMLLinkElement(iface);
196 nsAString type_str;
197 nsresult nsres;
199 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
201 nsAString_InitDepend(&type_str, v);
202 nsres = nsIDOMHTMLLinkElement_SetType(This->nslink, &type_str);
203 nsAString_Finish(&type_str);
205 return NS_SUCCEEDED(nsres) ? S_OK : E_FAIL;
208 static HRESULT WINAPI HTMLLinkElement_get_type(IHTMLLinkElement *iface, BSTR *p)
210 HTMLLinkElement *This = impl_from_IHTMLLinkElement(iface);
211 nsAString type_str;
212 nsresult nsres;
214 TRACE("(%p)->(%p)\n", This, p);
216 nsAString_Init(&type_str, NULL);
217 nsres = nsIDOMHTMLLinkElement_GetType(This->nslink, &type_str);
218 return return_nsstr(nsres, &type_str, p);
221 static HRESULT WINAPI HTMLLinkElement_get_readyState(IHTMLLinkElement *iface, BSTR *p)
223 HTMLLinkElement *This = impl_from_IHTMLLinkElement(iface);
224 FIXME("(%p)->(%p)\n", This, p);
225 return E_NOTIMPL;
228 static HRESULT WINAPI HTMLLinkElement_put_onreadystatechange(IHTMLLinkElement *iface, VARIANT v)
230 HTMLLinkElement *This = impl_from_IHTMLLinkElement(iface);
231 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
232 return E_NOTIMPL;
235 static HRESULT WINAPI HTMLLinkElement_get_onreadystatechange(IHTMLLinkElement *iface, VARIANT *p)
237 HTMLLinkElement *This = impl_from_IHTMLLinkElement(iface);
238 FIXME("(%p)->(%p)\n", This, p);
239 return E_NOTIMPL;
242 static HRESULT WINAPI HTMLLinkElement_put_onload(IHTMLLinkElement *iface, VARIANT v)
244 HTMLLinkElement *This = impl_from_IHTMLLinkElement(iface);
245 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
246 return E_NOTIMPL;
249 static HRESULT WINAPI HTMLLinkElement_get_onload(IHTMLLinkElement *iface, VARIANT *p)
251 HTMLLinkElement *This = impl_from_IHTMLLinkElement(iface);
252 FIXME("(%p)->(%p)\n", This, p);
253 return E_NOTIMPL;
256 static HRESULT WINAPI HTMLLinkElement_put_onerror(IHTMLLinkElement *iface, VARIANT v)
258 HTMLLinkElement *This = impl_from_IHTMLLinkElement(iface);
259 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
260 return E_NOTIMPL;
263 static HRESULT WINAPI HTMLLinkElement_get_onerror(IHTMLLinkElement *iface, VARIANT *p)
265 HTMLLinkElement *This = impl_from_IHTMLLinkElement(iface);
266 FIXME("(%p)->(%p)\n", This, p);
267 return E_NOTIMPL;
270 static HRESULT WINAPI HTMLLinkElement_get_styleSheet(IHTMLLinkElement *iface, IHTMLStyleSheet **p)
272 HTMLLinkElement *This = impl_from_IHTMLLinkElement(iface);
273 FIXME("(%p)->(%p)\n", This, p);
274 return E_NOTIMPL;
277 static HRESULT WINAPI HTMLLinkElement_put_disabled(IHTMLLinkElement *iface, VARIANT_BOOL v)
279 HTMLLinkElement *This = impl_from_IHTMLLinkElement(iface);
280 nsresult nsres;
282 TRACE("(%p)->(%x)\n", This, v);
284 nsres = nsIDOMHTMLLinkElement_SetDisabled(This->nslink, !!v);
285 return SUCCEEDED(nsres) ? S_OK : E_FAIL;
288 static HRESULT WINAPI HTMLLinkElement_get_disabled(IHTMLLinkElement *iface, VARIANT_BOOL *p)
290 HTMLLinkElement *This = impl_from_IHTMLLinkElement(iface);
291 cpp_bool ret;
292 nsresult nsres;
294 TRACE("(%p)->(%p)\n", This, p);
296 nsres = nsIDOMHTMLLinkElement_GetDisabled(This->nslink, &ret);
297 if(NS_FAILED(nsres))
298 return E_FAIL;
300 *p = ret ? VARIANT_TRUE : VARIANT_FALSE;
301 return S_OK;
304 static HRESULT WINAPI HTMLLinkElement_put_media(IHTMLLinkElement *iface, BSTR v)
306 HTMLLinkElement *This = impl_from_IHTMLLinkElement(iface);
307 nsresult nsres;
308 nsAString str;
310 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
312 nsAString_InitDepend(&str, v);
314 nsres = nsIDOMHTMLLinkElement_SetMedia(This->nslink, &str);
315 nsAString_Finish(&str);
317 if(NS_FAILED(nsres)) {
318 ERR("Set Media(%s) failed: %08x\n", debugstr_w(v), nsres);
319 return E_FAIL;
321 return S_OK;
324 static HRESULT WINAPI HTMLLinkElement_get_media(IHTMLLinkElement *iface, BSTR *p)
326 HTMLLinkElement *This = impl_from_IHTMLLinkElement(iface);
327 nsresult nsres;
328 nsAString str;
330 TRACE("(%p)->(%p)\n", This, p);
332 nsAString_Init(&str, NULL);
333 nsres = nsIDOMHTMLLinkElement_GetMedia(This->nslink, &str);
335 return return_nsstr(nsres, &str, p);
338 static const IHTMLLinkElementVtbl HTMLLinkElementVtbl = {
339 HTMLLinkElement_QueryInterface,
340 HTMLLinkElement_AddRef,
341 HTMLLinkElement_Release,
342 HTMLLinkElement_GetTypeInfoCount,
343 HTMLLinkElement_GetTypeInfo,
344 HTMLLinkElement_GetIDsOfNames,
345 HTMLLinkElement_Invoke,
346 HTMLLinkElement_put_href,
347 HTMLLinkElement_get_href,
348 HTMLLinkElement_put_rel,
349 HTMLLinkElement_get_rel,
350 HTMLLinkElement_put_rev,
351 HTMLLinkElement_get_rev,
352 HTMLLinkElement_put_type,
353 HTMLLinkElement_get_type,
354 HTMLLinkElement_get_readyState,
355 HTMLLinkElement_put_onreadystatechange,
356 HTMLLinkElement_get_onreadystatechange,
357 HTMLLinkElement_put_onload,
358 HTMLLinkElement_get_onload,
359 HTMLLinkElement_put_onerror,
360 HTMLLinkElement_get_onerror,
361 HTMLLinkElement_get_styleSheet,
362 HTMLLinkElement_put_disabled,
363 HTMLLinkElement_get_disabled,
364 HTMLLinkElement_put_media,
365 HTMLLinkElement_get_media
368 static inline HTMLLinkElement *impl_from_HTMLDOMNode(HTMLDOMNode *iface)
370 return CONTAINING_RECORD(iface, HTMLLinkElement, element.node);
373 static HRESULT HTMLLinkElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
375 HTMLLinkElement *This = impl_from_HTMLDOMNode(iface);
377 if(IsEqualGUID(&IID_IHTMLLinkElement, riid)) {
378 TRACE("(%p)->(IID_IHTMLLinkElement %p)\n", This, ppv);
379 *ppv = &This->IHTMLLinkElement_iface;
380 }else {
381 return HTMLElement_QI(&This->element.node, riid, ppv);
384 IUnknown_AddRef((IUnknown*)*ppv);
385 return S_OK;
388 static HRESULT HTMLLinkElementImpl_put_disabled(HTMLDOMNode *iface, VARIANT_BOOL v)
390 HTMLLinkElement *This = impl_from_HTMLDOMNode(iface);
391 return IHTMLLinkElement_put_disabled(&This->IHTMLLinkElement_iface, v);
394 static HRESULT HTMLLinkElementImpl_get_disabled(HTMLDOMNode *iface, VARIANT_BOOL *p)
396 HTMLLinkElement *This = impl_from_HTMLDOMNode(iface);
397 return IHTMLLinkElement_get_disabled(&This->IHTMLLinkElement_iface, p);
400 static void HTMLLinkElement_traverse(HTMLDOMNode *iface, nsCycleCollectionTraversalCallback *cb)
402 HTMLLinkElement *This = impl_from_HTMLDOMNode(iface);
404 if(This->nslink)
405 note_cc_edge((nsISupports*)This->nslink, "This->nslink", cb);
408 static void HTMLLinkElement_unlink(HTMLDOMNode *iface)
410 HTMLLinkElement *This = impl_from_HTMLDOMNode(iface);
412 if(This->nslink) {
413 nsIDOMHTMLLinkElement *nslink = This->nslink;
415 This->nslink = NULL;
416 nsIDOMHTMLLinkElement_Release(nslink);
419 static const NodeImplVtbl HTMLLinkElementImplVtbl = {
420 HTMLLinkElement_QI,
421 HTMLElement_destructor,
422 HTMLElement_cpc,
423 HTMLElement_clone,
424 HTMLElement_handle_event,
425 HTMLElement_get_attr_col,
426 NULL,
427 NULL,
428 HTMLLinkElementImpl_put_disabled,
429 HTMLLinkElementImpl_get_disabled,
430 NULL,
431 NULL,
432 NULL,
433 NULL,
434 NULL,
435 HTMLLinkElement_traverse,
436 HTMLLinkElement_unlink
439 static const tid_t HTMLLinkElement_iface_tids[] = {
440 HTMLELEMENT_TIDS,
441 IHTMLLinkElement_tid,
444 static dispex_static_data_t HTMLLinkElement_dispex = {
445 NULL,
446 DispHTMLLinkElement_tid,
447 NULL,
448 HTMLLinkElement_iface_tids
451 HRESULT HTMLLinkElement_Create(HTMLDocumentNode *doc, nsIDOMHTMLElement *nselem, HTMLElement **elem)
453 HTMLLinkElement *ret;
454 nsresult nsres;
456 ret = heap_alloc_zero(sizeof(*ret));
457 if(!ret)
458 return E_OUTOFMEMORY;
460 ret->IHTMLLinkElement_iface.lpVtbl = &HTMLLinkElementVtbl;
461 ret->element.node.vtbl = &HTMLLinkElementImplVtbl;
463 HTMLElement_Init(&ret->element, doc, nselem, &HTMLLinkElement_dispex);
465 nsres = nsIDOMHTMLElement_QueryInterface(nselem, &IID_nsIDOMHTMLLinkElement, (void**)&ret->nslink);
466 assert(nsres == NS_OK);
468 *elem = &ret->element;
469 return S_OK;