dmime: Don't set DSBCAPS_CTRLPAN together with DSBCAPS_CTRL3D.
[wine.git] / dlls / mshtml / htmlattr.c
blob446cb6f5894c23c14572f6e6472d84aa65488670
1 /*
2 * Copyright 2011 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
20 #include <stdarg.h>
21 #include <assert.h>
23 #define COBJMACROS
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winuser.h"
28 #include "ole2.h"
30 #include "mshtml_private.h"
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
36 static inline HTMLDOMAttribute *impl_from_IHTMLDOMAttribute(IHTMLDOMAttribute *iface)
38 return CONTAINING_RECORD(iface, HTMLDOMAttribute, IHTMLDOMAttribute_iface);
41 static HRESULT WINAPI HTMLDOMAttribute_QueryInterface(IHTMLDOMAttribute *iface,
42 REFIID riid, void **ppv)
44 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute(iface);
46 TRACE("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv);
48 if(IsEqualGUID(&IID_IUnknown, riid)) {
49 *ppv = &This->IHTMLDOMAttribute_iface;
50 }else if(IsEqualGUID(&IID_IHTMLDOMAttribute, riid)) {
51 *ppv = &This->IHTMLDOMAttribute_iface;
52 }else if(IsEqualGUID(&IID_IHTMLDOMAttribute2, riid)) {
53 *ppv = &This->IHTMLDOMAttribute2_iface;
54 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
55 return *ppv ? S_OK : E_NOINTERFACE;
56 }else {
57 WARN("%s not supported\n", debugstr_mshtml_guid(riid));
58 *ppv = NULL;
59 return E_NOINTERFACE;
62 IUnknown_AddRef((IUnknown*)*ppv);
63 return S_OK;
66 static ULONG WINAPI HTMLDOMAttribute_AddRef(IHTMLDOMAttribute *iface)
68 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute(iface);
69 LONG ref = InterlockedIncrement(&This->ref);
71 TRACE("(%p) ref=%d\n", This, ref);
73 return ref;
76 static ULONG WINAPI HTMLDOMAttribute_Release(IHTMLDOMAttribute *iface)
78 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute(iface);
79 LONG ref = InterlockedDecrement(&This->ref);
81 TRACE("(%p) ref=%d\n", This, ref);
83 if(!ref) {
84 assert(!This->elem);
85 release_dispex(&This->dispex);
86 heap_free(This->name);
87 heap_free(This);
90 return ref;
93 static HRESULT WINAPI HTMLDOMAttribute_GetTypeInfoCount(IHTMLDOMAttribute *iface, UINT *pctinfo)
95 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute(iface);
96 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
99 static HRESULT WINAPI HTMLDOMAttribute_GetTypeInfo(IHTMLDOMAttribute *iface, UINT iTInfo,
100 LCID lcid, ITypeInfo **ppTInfo)
102 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute(iface);
103 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
106 static HRESULT WINAPI HTMLDOMAttribute_GetIDsOfNames(IHTMLDOMAttribute *iface, REFIID riid,
107 LPOLESTR *rgszNames, UINT cNames,
108 LCID lcid, DISPID *rgDispId)
110 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute(iface);
111 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
112 lcid, rgDispId);
115 static HRESULT WINAPI HTMLDOMAttribute_Invoke(IHTMLDOMAttribute *iface, DISPID dispIdMember,
116 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
117 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
119 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute(iface);
120 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
121 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
124 static HRESULT WINAPI HTMLDOMAttribute_get_nodeName(IHTMLDOMAttribute *iface, BSTR *p)
126 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute(iface);
128 TRACE("(%p)->(%p)\n", This, p);
130 if(!This->elem) {
131 if(!This->name) {
132 FIXME("No name available\n");
133 return E_FAIL;
136 *p = SysAllocString(This->name);
137 return *p ? S_OK : E_OUTOFMEMORY;
140 return IDispatchEx_GetMemberName(&This->elem->node.event_target.dispex.IDispatchEx_iface, This->dispid, p);
143 static HRESULT WINAPI HTMLDOMAttribute_put_nodeValue(IHTMLDOMAttribute *iface, VARIANT v)
145 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute(iface);
146 DISPID dispidNamed = DISPID_PROPERTYPUT;
147 DISPPARAMS dp = {&v, &dispidNamed, 1, 1};
148 EXCEPINFO ei;
149 VARIANT ret;
151 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
153 if(!This->elem) {
154 FIXME("NULL This->elem\n");
155 return E_UNEXPECTED;
158 memset(&ei, 0, sizeof(ei));
160 return IDispatchEx_InvokeEx(&This->elem->node.event_target.dispex.IDispatchEx_iface, This->dispid, LOCALE_SYSTEM_DEFAULT,
161 DISPATCH_PROPERTYPUT, &dp, &ret, &ei, NULL);
164 static HRESULT WINAPI HTMLDOMAttribute_get_nodeValue(IHTMLDOMAttribute *iface, VARIANT *p)
166 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute(iface);
168 TRACE("(%p)->(%p)\n", This, p);
170 if(!This->elem) {
171 FIXME("NULL This->elem\n");
172 return E_UNEXPECTED;
175 return get_elem_attr_value_by_dispid(This->elem, This->dispid, 0, p);
178 static HRESULT WINAPI HTMLDOMAttribute_get_specified(IHTMLDOMAttribute *iface, VARIANT_BOOL *p)
180 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute(iface);
181 nsIDOMAttr *nsattr;
182 nsAString nsname;
183 BSTR name;
184 nsresult nsres;
185 HRESULT hres;
187 TRACE("(%p)->(%p)\n", This, p);
189 if(!This->elem || !This->elem->nselem) {
190 FIXME("NULL This->elem\n");
191 return E_UNEXPECTED;
194 if(get_dispid_type(This->dispid) != DISPEXPROP_BUILTIN) {
195 *p = VARIANT_TRUE;
196 return S_OK;
199 hres = IDispatchEx_GetMemberName(&This->elem->node.event_target.dispex.IDispatchEx_iface, This->dispid, &name);
200 if(FAILED(hres))
201 return hres;
203 /* FIXME: This is not exactly right, we have some attributes that don't map directly to Gecko attributes. */
204 nsAString_InitDepend(&nsname, name);
205 nsres = nsIDOMHTMLElement_GetAttributeNode(This->elem->nselem, &nsname, &nsattr);
206 nsAString_Finish(&nsname);
207 SysFreeString(name);
208 if(NS_FAILED(nsres))
209 return E_FAIL;
211 /* If the Gecko attribute node can be found, we know that the attribute is specified.
212 There is no point in calling GetSpecified */
213 if(nsattr) {
214 nsIDOMAttr_Release(nsattr);
215 *p = VARIANT_TRUE;
216 }else {
217 *p = VARIANT_FALSE;
219 return S_OK;
222 static const IHTMLDOMAttributeVtbl HTMLDOMAttributeVtbl = {
223 HTMLDOMAttribute_QueryInterface,
224 HTMLDOMAttribute_AddRef,
225 HTMLDOMAttribute_Release,
226 HTMLDOMAttribute_GetTypeInfoCount,
227 HTMLDOMAttribute_GetTypeInfo,
228 HTMLDOMAttribute_GetIDsOfNames,
229 HTMLDOMAttribute_Invoke,
230 HTMLDOMAttribute_get_nodeName,
231 HTMLDOMAttribute_put_nodeValue,
232 HTMLDOMAttribute_get_nodeValue,
233 HTMLDOMAttribute_get_specified
236 static inline HTMLDOMAttribute *impl_from_IHTMLDOMAttribute2(IHTMLDOMAttribute2 *iface)
238 return CONTAINING_RECORD(iface, HTMLDOMAttribute, IHTMLDOMAttribute2_iface);
241 static HRESULT WINAPI HTMLDOMAttribute2_QueryInterface(IHTMLDOMAttribute2 *iface, REFIID riid, void **ppv)
243 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
244 return IHTMLDOMAttribute_QueryInterface(&This->IHTMLDOMAttribute_iface, riid, ppv);
247 static ULONG WINAPI HTMLDOMAttribute2_AddRef(IHTMLDOMAttribute2 *iface)
249 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
250 return IHTMLDOMAttribute_AddRef(&This->IHTMLDOMAttribute_iface);
253 static ULONG WINAPI HTMLDOMAttribute2_Release(IHTMLDOMAttribute2 *iface)
255 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
256 return IHTMLDOMAttribute_Release(&This->IHTMLDOMAttribute_iface);
259 static HRESULT WINAPI HTMLDOMAttribute2_GetTypeInfoCount(IHTMLDOMAttribute2 *iface, UINT *pctinfo)
261 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
262 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
265 static HRESULT WINAPI HTMLDOMAttribute2_GetTypeInfo(IHTMLDOMAttribute2 *iface, UINT iTInfo,
266 LCID lcid, ITypeInfo **ppTInfo)
268 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
269 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
272 static HRESULT WINAPI HTMLDOMAttribute2_GetIDsOfNames(IHTMLDOMAttribute2 *iface, REFIID riid,
273 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
275 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
276 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
277 lcid, rgDispId);
280 static HRESULT WINAPI HTMLDOMAttribute2_Invoke(IHTMLDOMAttribute2 *iface, DISPID dispIdMember,
281 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
282 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
284 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
285 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
286 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
289 static HRESULT WINAPI HTMLDOMAttribute2_get_name(IHTMLDOMAttribute2 *iface, BSTR *p)
291 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
292 FIXME("(%p)->(%p)\n", This, p);
293 return E_NOTIMPL;
296 static HRESULT WINAPI HTMLDOMAttribute2_put_value(IHTMLDOMAttribute2 *iface, BSTR v)
298 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
299 VARIANT var;
301 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
303 V_VT(&var) = VT_BSTR;
304 V_BSTR(&var) = v;
305 return IHTMLDOMAttribute_put_nodeValue(&This->IHTMLDOMAttribute_iface, var);
308 static HRESULT WINAPI HTMLDOMAttribute2_get_value(IHTMLDOMAttribute2 *iface, BSTR *p)
310 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
311 VARIANT val;
312 HRESULT hres;
314 TRACE("(%p)->(%p)\n", This, p);
316 if(!This->elem) {
317 FIXME("NULL This->elem\n");
318 return E_UNEXPECTED;
321 hres = get_elem_attr_value_by_dispid(This->elem, This->dispid, ATTRFLAG_ASSTRING, &val);
322 if(FAILED(hres))
323 return hres;
325 assert(V_VT(&val) == VT_BSTR);
326 *p = V_BSTR(&val);
327 if(!*p && !(*p = SysAllocStringLen(NULL, 0)))
328 return E_OUTOFMEMORY;
329 return S_OK;
332 static HRESULT WINAPI HTMLDOMAttribute2_get_expando(IHTMLDOMAttribute2 *iface, VARIANT_BOOL *p)
334 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
336 TRACE("(%p)->(%p)\n", This, p);
338 *p = get_dispid_type(This->dispid) == DISPEXPROP_BUILTIN ? VARIANT_FALSE : VARIANT_TRUE;
339 return S_OK;
342 static HRESULT WINAPI HTMLDOMAttribute2_get_nodeType(IHTMLDOMAttribute2 *iface, LONG *p)
344 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
345 FIXME("(%p)->(%p)\n", This, p);
346 return E_NOTIMPL;
349 static HRESULT WINAPI HTMLDOMAttribute2_get_parentNode(IHTMLDOMAttribute2 *iface, IHTMLDOMNode **p)
351 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
352 FIXME("(%p)->(%p)\n", This, p);
353 return E_NOTIMPL;
356 static HRESULT WINAPI HTMLDOMAttribute2_get_childNodes(IHTMLDOMAttribute2 *iface, IDispatch **p)
358 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
359 FIXME("(%p)->(%p)\n", This, p);
360 return E_NOTIMPL;
363 static HRESULT WINAPI HTMLDOMAttribute2_get_firstChild(IHTMLDOMAttribute2 *iface, IHTMLDOMNode **p)
365 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
366 FIXME("(%p)->(%p)\n", This, p);
367 return E_NOTIMPL;
370 static HRESULT WINAPI HTMLDOMAttribute2_get_lastChild(IHTMLDOMAttribute2 *iface, IHTMLDOMNode **p)
372 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
373 FIXME("(%p)->(%p)\n", This, p);
374 return E_NOTIMPL;
377 static HRESULT WINAPI HTMLDOMAttribute2_get_previousSibling(IHTMLDOMAttribute2 *iface, IHTMLDOMNode **p)
379 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
380 FIXME("(%p)->(%p)\n", This, p);
381 return E_NOTIMPL;
384 static HRESULT WINAPI HTMLDOMAttribute2_get_nextSibling(IHTMLDOMAttribute2 *iface, IHTMLDOMNode **p)
386 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
387 FIXME("(%p)->(%p)\n", This, p);
388 return E_NOTIMPL;
391 static HRESULT WINAPI HTMLDOMAttribute2_get_attributes(IHTMLDOMAttribute2 *iface, IDispatch **p)
393 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
394 FIXME("(%p)->(%p)\n", This, p);
395 return E_NOTIMPL;
398 static HRESULT WINAPI HTMLDOMAttribute2_get_ownerDocument(IHTMLDOMAttribute2 *iface, IDispatch **p)
400 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
401 FIXME("(%p)->(%p)\n", This, p);
402 return E_NOTIMPL;
405 static HRESULT WINAPI HTMLDOMAttribute2_insertBefore(IHTMLDOMAttribute2 *iface, IHTMLDOMNode *newChild,
406 VARIANT refChild, IHTMLDOMNode **node)
408 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
409 FIXME("(%p)->(%p %s %p)\n", This, newChild, debugstr_variant(&refChild), node);
410 return E_NOTIMPL;
413 static HRESULT WINAPI HTMLDOMAttribute2_replaceChild(IHTMLDOMAttribute2 *iface, IHTMLDOMNode *newChild,
414 IHTMLDOMNode *oldChild, IHTMLDOMNode **node)
416 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
417 FIXME("(%p)->(%p %p %p)\n", This, newChild, oldChild, node);
418 return E_NOTIMPL;
421 static HRESULT WINAPI HTMLDOMAttribute2_removeChild(IHTMLDOMAttribute2 *iface, IHTMLDOMNode *oldChild,
422 IHTMLDOMNode **node)
424 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
425 FIXME("(%p)->(%p %p)\n", This, oldChild, node);
426 return E_NOTIMPL;
429 static HRESULT WINAPI HTMLDOMAttribute2_appendChild(IHTMLDOMAttribute2 *iface, IHTMLDOMNode *newChild,
430 IHTMLDOMNode **node)
432 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
433 FIXME("(%p)->(%p %p)\n", This, newChild, node);
434 return E_NOTIMPL;
437 static HRESULT WINAPI HTMLDOMAttribute2_hasChildNodes(IHTMLDOMAttribute2 *iface, VARIANT_BOOL *fChildren)
439 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
440 FIXME("(%p)->(%p)\n", This, fChildren);
441 return E_NOTIMPL;
444 static HRESULT WINAPI HTMLDOMAttribute2_cloneNode(IHTMLDOMAttribute2 *iface, VARIANT_BOOL fDeep,
445 IHTMLDOMAttribute **clonedNode)
447 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
448 FIXME("(%p)->(%x %p)\n", This, fDeep, clonedNode);
449 return E_NOTIMPL;
452 static const IHTMLDOMAttribute2Vtbl HTMLDOMAttribute2Vtbl = {
453 HTMLDOMAttribute2_QueryInterface,
454 HTMLDOMAttribute2_AddRef,
455 HTMLDOMAttribute2_Release,
456 HTMLDOMAttribute2_GetTypeInfoCount,
457 HTMLDOMAttribute2_GetTypeInfo,
458 HTMLDOMAttribute2_GetIDsOfNames,
459 HTMLDOMAttribute2_Invoke,
460 HTMLDOMAttribute2_get_name,
461 HTMLDOMAttribute2_put_value,
462 HTMLDOMAttribute2_get_value,
463 HTMLDOMAttribute2_get_expando,
464 HTMLDOMAttribute2_get_nodeType,
465 HTMLDOMAttribute2_get_parentNode,
466 HTMLDOMAttribute2_get_childNodes,
467 HTMLDOMAttribute2_get_firstChild,
468 HTMLDOMAttribute2_get_lastChild,
469 HTMLDOMAttribute2_get_previousSibling,
470 HTMLDOMAttribute2_get_nextSibling,
471 HTMLDOMAttribute2_get_attributes,
472 HTMLDOMAttribute2_get_ownerDocument,
473 HTMLDOMAttribute2_insertBefore,
474 HTMLDOMAttribute2_replaceChild,
475 HTMLDOMAttribute2_removeChild,
476 HTMLDOMAttribute2_appendChild,
477 HTMLDOMAttribute2_hasChildNodes,
478 HTMLDOMAttribute2_cloneNode
481 static const tid_t HTMLDOMAttribute_iface_tids[] = {
482 IHTMLDOMAttribute_tid,
483 IHTMLDOMAttribute2_tid,
486 static dispex_static_data_t HTMLDOMAttribute_dispex = {
487 NULL,
488 DispHTMLDOMAttribute_tid,
490 HTMLDOMAttribute_iface_tids
493 HRESULT HTMLDOMAttribute_Create(const WCHAR *name, HTMLElement *elem, DISPID dispid, HTMLDOMAttribute **attr)
495 HTMLAttributeCollection *col;
496 HTMLDOMAttribute *ret;
497 HRESULT hres;
499 ret = heap_alloc_zero(sizeof(*ret));
500 if(!ret)
501 return E_OUTOFMEMORY;
503 ret->IHTMLDOMAttribute_iface.lpVtbl = &HTMLDOMAttributeVtbl;
504 ret->IHTMLDOMAttribute2_iface.lpVtbl = &HTMLDOMAttribute2Vtbl;
505 ret->ref = 1;
506 ret->dispid = dispid;
507 ret->elem = elem;
509 init_dispex(&ret->dispex, (IUnknown*)&ret->IHTMLDOMAttribute_iface,
510 &HTMLDOMAttribute_dispex);
512 /* For attributes attached to an element, (elem,dispid) pair should be valid used for its operation. */
513 if(elem) {
514 hres = HTMLElement_get_attr_col(&elem->node, &col);
515 if(FAILED(hres)) {
516 IHTMLDOMAttribute_Release(&ret->IHTMLDOMAttribute_iface);
517 return hres;
519 IHTMLAttributeCollection_Release(&col->IHTMLAttributeCollection_iface);
521 list_add_tail(&elem->attrs->attrs, &ret->entry);
524 /* For detached attributes we may still do most operations if we have its name available. */
525 if(name) {
526 ret->name = heap_strdupW(name);
527 if(!ret->name) {
528 IHTMLDOMAttribute_Release(&ret->IHTMLDOMAttribute_iface);
529 return E_OUTOFMEMORY;
533 *attr = ret;
534 return S_OK;