include/mscvpdb.h: Use flexible array members for the rest of structures.
[wine.git] / dlls / mshtml / htmllink.c
blob805ec0312275c96d90f7701fd45e8c59fd3e551f
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>
21 #define COBJMACROS
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winuser.h"
26 #include "ole2.h"
28 #include "wine/debug.h"
30 #include "mshtml_private.h"
31 #include "htmlevent.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
35 struct HTMLLinkElement {
36 HTMLElement element;
37 IHTMLLinkElement IHTMLLinkElement_iface;
39 nsIDOMHTMLLinkElement *nslink;
42 static inline HTMLLinkElement *impl_from_IHTMLLinkElement(IHTMLLinkElement *iface)
44 return CONTAINING_RECORD(iface, HTMLLinkElement, IHTMLLinkElement_iface);
47 DISPEX_IDISPATCH_IMPL(HTMLLinkElement, IHTMLLinkElement,
48 impl_from_IHTMLLinkElement(iface)->element.node.event_target.dispex)
50 static HRESULT WINAPI HTMLLinkElement_put_href(IHTMLLinkElement *iface, BSTR v)
52 HTMLLinkElement *This = impl_from_IHTMLLinkElement(iface);
53 nsAString href_str;
54 nsresult nsres;
56 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
58 nsAString_InitDepend(&href_str, v);
59 nsres = nsIDOMHTMLLinkElement_SetHref(This->nslink, &href_str);
60 nsAString_Finish(&href_str);
62 return NS_SUCCEEDED(nsres) ? S_OK : E_FAIL;
65 static HRESULT WINAPI HTMLLinkElement_get_href(IHTMLLinkElement *iface, BSTR *p)
67 HTMLLinkElement *This = impl_from_IHTMLLinkElement(iface);
68 nsAString href_str;
69 nsresult nsres;
71 TRACE("(%p)->(%p)\n", This, p);
73 nsAString_Init(&href_str, NULL);
74 nsres = nsIDOMHTMLLinkElement_GetHref(This->nslink, &href_str);
75 return return_nsstr(nsres, &href_str, p);
78 static HRESULT WINAPI HTMLLinkElement_put_rel(IHTMLLinkElement *iface, BSTR v)
80 HTMLLinkElement *This = impl_from_IHTMLLinkElement(iface);
81 nsAString rel_str;
82 nsresult nsres;
84 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
86 nsAString_InitDepend(&rel_str, v);
87 nsres = nsIDOMHTMLLinkElement_SetRel(This->nslink, &rel_str);
88 nsAString_Finish(&rel_str);
90 return NS_SUCCEEDED(nsres) ? S_OK : E_FAIL;
93 static HRESULT WINAPI HTMLLinkElement_get_rel(IHTMLLinkElement *iface, BSTR *p)
95 HTMLLinkElement *This = impl_from_IHTMLLinkElement(iface);
96 nsAString rel_str;
97 nsresult nsres;
99 TRACE("(%p)->(%p)\n", This, p);
101 nsAString_Init(&rel_str, NULL);
102 nsres = nsIDOMHTMLLinkElement_GetRel(This->nslink, &rel_str);
103 return return_nsstr(nsres, &rel_str, p);
106 static HRESULT WINAPI HTMLLinkElement_put_rev(IHTMLLinkElement *iface, BSTR v)
108 HTMLLinkElement *This = impl_from_IHTMLLinkElement(iface);
109 nsAString nsstr;
110 nsresult nsres;
112 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
114 nsAString_InitDepend(&nsstr, v);
115 nsres = nsIDOMHTMLLinkElement_SetRev(This->nslink, &nsstr);
116 nsAString_Finish(&nsstr);
117 if(NS_FAILED(nsres)) {
118 ERR("SetRev failed: %08lx\n", nsres);
119 return E_FAIL;
122 return S_OK;
125 static HRESULT WINAPI HTMLLinkElement_get_rev(IHTMLLinkElement *iface, BSTR *p)
127 HTMLLinkElement *This = impl_from_IHTMLLinkElement(iface);
128 nsAString nsstr;
129 nsresult nsres;
131 TRACE("(%p)->(%p)\n", This, p);
133 nsAString_Init(&nsstr, NULL);
134 nsres = nsIDOMHTMLLinkElement_GetRev(This->nslink, &nsstr);
135 return return_nsstr(nsres, &nsstr, p);
138 static HRESULT WINAPI HTMLLinkElement_put_type(IHTMLLinkElement *iface, BSTR v)
140 HTMLLinkElement *This = impl_from_IHTMLLinkElement(iface);
141 nsAString type_str;
142 nsresult nsres;
144 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
146 nsAString_InitDepend(&type_str, v);
147 nsres = nsIDOMHTMLLinkElement_SetType(This->nslink, &type_str);
148 nsAString_Finish(&type_str);
150 return NS_SUCCEEDED(nsres) ? S_OK : E_FAIL;
153 static HRESULT WINAPI HTMLLinkElement_get_type(IHTMLLinkElement *iface, BSTR *p)
155 HTMLLinkElement *This = impl_from_IHTMLLinkElement(iface);
156 nsAString type_str;
157 nsresult nsres;
159 TRACE("(%p)->(%p)\n", This, p);
161 nsAString_Init(&type_str, NULL);
162 nsres = nsIDOMHTMLLinkElement_GetType(This->nslink, &type_str);
163 return return_nsstr(nsres, &type_str, p);
166 static HRESULT WINAPI HTMLLinkElement_get_readyState(IHTMLLinkElement *iface, BSTR *p)
168 HTMLLinkElement *This = impl_from_IHTMLLinkElement(iface);
169 FIXME("(%p)->(%p)\n", This, p);
170 return E_NOTIMPL;
173 static HRESULT WINAPI HTMLLinkElement_put_onreadystatechange(IHTMLLinkElement *iface, VARIANT v)
175 HTMLLinkElement *This = impl_from_IHTMLLinkElement(iface);
176 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
177 return E_NOTIMPL;
180 static HRESULT WINAPI HTMLLinkElement_get_onreadystatechange(IHTMLLinkElement *iface, VARIANT *p)
182 HTMLLinkElement *This = impl_from_IHTMLLinkElement(iface);
183 FIXME("(%p)->(%p)\n", This, p);
184 return E_NOTIMPL;
187 static HRESULT WINAPI HTMLLinkElement_put_onload(IHTMLLinkElement *iface, VARIANT v)
189 HTMLLinkElement *This = impl_from_IHTMLLinkElement(iface);
191 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
193 return set_node_event(&This->element.node, EVENTID_LOAD, &v);
196 static HRESULT WINAPI HTMLLinkElement_get_onload(IHTMLLinkElement *iface, VARIANT *p)
198 HTMLLinkElement *This = impl_from_IHTMLLinkElement(iface);
200 TRACE("(%p)->(%p)\n", This, p);
202 return get_node_event(&This->element.node, EVENTID_LOAD, p);
205 static HRESULT WINAPI HTMLLinkElement_put_onerror(IHTMLLinkElement *iface, VARIANT v)
207 HTMLLinkElement *This = impl_from_IHTMLLinkElement(iface);
208 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
209 return E_NOTIMPL;
212 static HRESULT WINAPI HTMLLinkElement_get_onerror(IHTMLLinkElement *iface, VARIANT *p)
214 HTMLLinkElement *This = impl_from_IHTMLLinkElement(iface);
215 FIXME("(%p)->(%p)\n", This, p);
216 return E_NOTIMPL;
219 static HRESULT WINAPI HTMLLinkElement_get_styleSheet(IHTMLLinkElement *iface, IHTMLStyleSheet **p)
221 HTMLLinkElement *This = impl_from_IHTMLLinkElement(iface);
222 FIXME("(%p)->(%p)\n", This, p);
223 return E_NOTIMPL;
226 static HRESULT WINAPI HTMLLinkElement_put_disabled(IHTMLLinkElement *iface, VARIANT_BOOL v)
228 HTMLLinkElement *This = impl_from_IHTMLLinkElement(iface);
229 nsresult nsres;
231 TRACE("(%p)->(%x)\n", This, v);
233 nsres = nsIDOMHTMLLinkElement_SetDisabled(This->nslink, !!v);
234 return SUCCEEDED(nsres) ? S_OK : E_FAIL;
237 static HRESULT WINAPI HTMLLinkElement_get_disabled(IHTMLLinkElement *iface, VARIANT_BOOL *p)
239 HTMLLinkElement *This = impl_from_IHTMLLinkElement(iface);
240 cpp_bool ret;
241 nsresult nsres;
243 TRACE("(%p)->(%p)\n", This, p);
245 nsres = nsIDOMHTMLLinkElement_GetDisabled(This->nslink, &ret);
246 if(NS_FAILED(nsres))
247 return E_FAIL;
249 *p = variant_bool(ret);
250 return S_OK;
253 static HRESULT WINAPI HTMLLinkElement_put_media(IHTMLLinkElement *iface, BSTR v)
255 HTMLLinkElement *This = impl_from_IHTMLLinkElement(iface);
256 nsresult nsres;
257 nsAString str;
259 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
261 nsAString_InitDepend(&str, v);
263 nsres = nsIDOMHTMLLinkElement_SetMedia(This->nslink, &str);
264 nsAString_Finish(&str);
266 if(NS_FAILED(nsres)) {
267 ERR("Set Media(%s) failed: %08lx\n", debugstr_w(v), nsres);
268 return E_FAIL;
270 return S_OK;
273 static HRESULT WINAPI HTMLLinkElement_get_media(IHTMLLinkElement *iface, BSTR *p)
275 HTMLLinkElement *This = impl_from_IHTMLLinkElement(iface);
276 nsresult nsres;
277 nsAString str;
279 TRACE("(%p)->(%p)\n", This, p);
281 nsAString_Init(&str, NULL);
282 nsres = nsIDOMHTMLLinkElement_GetMedia(This->nslink, &str);
284 return return_nsstr(nsres, &str, p);
287 static const IHTMLLinkElementVtbl HTMLLinkElementVtbl = {
288 HTMLLinkElement_QueryInterface,
289 HTMLLinkElement_AddRef,
290 HTMLLinkElement_Release,
291 HTMLLinkElement_GetTypeInfoCount,
292 HTMLLinkElement_GetTypeInfo,
293 HTMLLinkElement_GetIDsOfNames,
294 HTMLLinkElement_Invoke,
295 HTMLLinkElement_put_href,
296 HTMLLinkElement_get_href,
297 HTMLLinkElement_put_rel,
298 HTMLLinkElement_get_rel,
299 HTMLLinkElement_put_rev,
300 HTMLLinkElement_get_rev,
301 HTMLLinkElement_put_type,
302 HTMLLinkElement_get_type,
303 HTMLLinkElement_get_readyState,
304 HTMLLinkElement_put_onreadystatechange,
305 HTMLLinkElement_get_onreadystatechange,
306 HTMLLinkElement_put_onload,
307 HTMLLinkElement_get_onload,
308 HTMLLinkElement_put_onerror,
309 HTMLLinkElement_get_onerror,
310 HTMLLinkElement_get_styleSheet,
311 HTMLLinkElement_put_disabled,
312 HTMLLinkElement_get_disabled,
313 HTMLLinkElement_put_media,
314 HTMLLinkElement_get_media
317 static inline HTMLLinkElement *impl_from_HTMLDOMNode(HTMLDOMNode *iface)
319 return CONTAINING_RECORD(iface, HTMLLinkElement, element.node);
322 static HRESULT HTMLLinkElementImpl_put_disabled(HTMLDOMNode *iface, VARIANT_BOOL v)
324 HTMLLinkElement *This = impl_from_HTMLDOMNode(iface);
325 return IHTMLLinkElement_put_disabled(&This->IHTMLLinkElement_iface, v);
328 static HRESULT HTMLLinkElementImpl_get_disabled(HTMLDOMNode *iface, VARIANT_BOOL *p)
330 HTMLLinkElement *This = impl_from_HTMLDOMNode(iface);
331 return IHTMLLinkElement_get_disabled(&This->IHTMLLinkElement_iface, p);
334 static inline HTMLLinkElement *impl_from_DispatchEx(DispatchEx *iface)
336 return CONTAINING_RECORD(iface, HTMLLinkElement, element.node.event_target.dispex);
339 static void *HTMLLinkElement_query_interface(DispatchEx *dispex, REFIID riid)
341 HTMLLinkElement *This = impl_from_DispatchEx(dispex);
343 if(IsEqualGUID(&IID_IHTMLLinkElement, riid))
344 return &This->IHTMLLinkElement_iface;
346 return HTMLElement_query_interface(&This->element.node.event_target.dispex, riid);
349 static void HTMLLinkElement_traverse(DispatchEx *dispex, nsCycleCollectionTraversalCallback *cb)
351 HTMLLinkElement *This = impl_from_DispatchEx(dispex);
352 HTMLElement_traverse(dispex, cb);
354 if(This->nslink)
355 note_cc_edge((nsISupports*)This->nslink, "nslink", cb);
358 static void HTMLLinkElement_unlink(DispatchEx *dispex)
360 HTMLLinkElement *This = impl_from_DispatchEx(dispex);
361 HTMLElement_unlink(dispex);
362 unlink_ref(&This->nslink);
364 static const NodeImplVtbl HTMLLinkElementImplVtbl = {
365 .clsid = &CLSID_HTMLLinkElement,
366 .cpc_entries = HTMLElement_cpc,
367 .clone = HTMLElement_clone,
368 .get_attr_col = HTMLElement_get_attr_col,
369 .put_disabled = HTMLLinkElementImpl_put_disabled,
370 .get_disabled = HTMLLinkElementImpl_get_disabled,
373 static const event_target_vtbl_t HTMLLinkElement_event_target_vtbl = {
375 HTMLELEMENT_DISPEX_VTBL_ENTRIES,
376 .query_interface= HTMLLinkElement_query_interface,
377 .destructor = HTMLElement_destructor,
378 .traverse = HTMLLinkElement_traverse,
379 .unlink = HTMLLinkElement_unlink
381 HTMLELEMENT_EVENT_TARGET_VTBL_ENTRIES,
382 .handle_event = HTMLElement_handle_event
385 static const tid_t HTMLLinkElement_iface_tids[] = {
386 HTMLELEMENT_TIDS,
387 IHTMLLinkElement_tid,
390 static dispex_static_data_t HTMLLinkElement_dispex = {
391 "HTMLLinkElement",
392 &HTMLLinkElement_event_target_vtbl.dispex_vtbl,
393 DispHTMLLinkElement_tid,
394 HTMLLinkElement_iface_tids,
395 HTMLElement_init_dispex_info
398 HRESULT HTMLLinkElement_Create(HTMLDocumentNode *doc, nsIDOMElement *nselem, HTMLElement **elem)
400 HTMLLinkElement *ret;
401 nsresult nsres;
403 ret = calloc(1, sizeof(*ret));
404 if(!ret)
405 return E_OUTOFMEMORY;
407 ret->IHTMLLinkElement_iface.lpVtbl = &HTMLLinkElementVtbl;
408 ret->element.node.vtbl = &HTMLLinkElementImplVtbl;
410 HTMLElement_Init(&ret->element, doc, nselem, &HTMLLinkElement_dispex);
412 nsres = nsIDOMElement_QueryInterface(nselem, &IID_nsIDOMHTMLLinkElement, (void**)&ret->nslink);
413 assert(nsres == NS_OK);
415 *elem = &ret->element;
416 return S_OK;