urlmon: Fix return value from QueryService.
[wine.git] / dlls / mshtml / htmlimg.c
blob413f02c428dc49ad1833c51fc63a5aa83a0f505f
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 "ole2.h"
28 #include "wine/debug.h"
30 #include "mshtml_private.h"
31 #include "htmlevent.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
35 typedef struct {
36 HTMLElement element;
38 IHTMLImgElement IHTMLImgElement_iface;
40 nsIDOMHTMLImageElement *nsimg;
41 } HTMLImgElement;
43 static inline HTMLImgElement *impl_from_IHTMLImgElement(IHTMLImgElement *iface)
45 return CONTAINING_RECORD(iface, HTMLImgElement, IHTMLImgElement_iface);
48 static HRESULT WINAPI HTMLImgElement_QueryInterface(IHTMLImgElement *iface, REFIID riid, void **ppv)
50 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
52 return IHTMLDOMNode_QueryInterface(HTMLDOMNODE(&This->element.node), riid, ppv);
55 static ULONG WINAPI HTMLImgElement_AddRef(IHTMLImgElement *iface)
57 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
59 return IHTMLDOMNode_AddRef(HTMLDOMNODE(&This->element.node));
62 static ULONG WINAPI HTMLImgElement_Release(IHTMLImgElement *iface)
64 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
66 return IHTMLDOMNode_Release(HTMLDOMNODE(&This->element.node));
69 static HRESULT WINAPI HTMLImgElement_GetTypeInfoCount(IHTMLImgElement *iface, UINT *pctinfo)
71 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
72 return IDispatchEx_GetTypeInfoCount(DISPATCHEX(&This->element.node.dispex), pctinfo);
75 static HRESULT WINAPI HTMLImgElement_GetTypeInfo(IHTMLImgElement *iface, UINT iTInfo,
76 LCID lcid, ITypeInfo **ppTInfo)
78 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
79 return IDispatchEx_GetTypeInfo(DISPATCHEX(&This->element.node.dispex), iTInfo, lcid, ppTInfo);
82 static HRESULT WINAPI HTMLImgElement_GetIDsOfNames(IHTMLImgElement *iface, REFIID riid,
83 LPOLESTR *rgszNames, UINT cNames,
84 LCID lcid, DISPID *rgDispId)
86 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
87 return IDispatchEx_GetIDsOfNames(DISPATCHEX(&This->element.node.dispex), riid, rgszNames, cNames, lcid, rgDispId);
90 static HRESULT WINAPI HTMLImgElement_Invoke(IHTMLImgElement *iface, DISPID dispIdMember,
91 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
92 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
94 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
95 return IDispatchEx_Invoke(DISPATCHEX(&This->element.node.dispex), dispIdMember, riid, lcid, wFlags, pDispParams,
96 pVarResult, pExcepInfo, puArgErr);
99 static HRESULT WINAPI HTMLImgElement_put_isMap(IHTMLImgElement *iface, VARIANT_BOOL v)
101 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
102 FIXME("(%p)->(%x)\n", This, v);
103 return E_NOTIMPL;
106 static HRESULT WINAPI HTMLImgElement_get_isMap(IHTMLImgElement *iface, VARIANT_BOOL *p)
108 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
109 FIXME("(%p)->(%p)\n", This, p);
110 return E_NOTIMPL;
113 static HRESULT WINAPI HTMLImgElement_put_useMap(IHTMLImgElement *iface, BSTR v)
115 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
116 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
117 return E_NOTIMPL;
120 static HRESULT WINAPI HTMLImgElement_get_useMap(IHTMLImgElement *iface, BSTR *p)
122 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
123 FIXME("(%p)->(%p)\n", This, p);
124 return E_NOTIMPL;
127 static HRESULT WINAPI HTMLImgElement_get_mimeType(IHTMLImgElement *iface, BSTR *p)
129 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
130 FIXME("(%p)->(%p)\n", This, p);
131 return E_NOTIMPL;
134 static HRESULT WINAPI HTMLImgElement_get_fileSize(IHTMLImgElement *iface, BSTR *p)
136 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
137 FIXME("(%p)->(%p)\n", This, p);
138 return E_NOTIMPL;
141 static HRESULT WINAPI HTMLImgElement_get_fileCreatedDate(IHTMLImgElement *iface, BSTR *p)
143 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
144 FIXME("(%p)->(%p)\n", This, p);
145 return E_NOTIMPL;
148 static HRESULT WINAPI HTMLImgElement_get_fileModifiedDate(IHTMLImgElement *iface, BSTR *p)
150 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
151 FIXME("(%p)->(%p)\n", This, p);
152 return E_NOTIMPL;
155 static HRESULT WINAPI HTMLImgElement_get_fileUpdatedDate(IHTMLImgElement *iface, BSTR *p)
157 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
158 FIXME("(%p)->(%p)\n", This, p);
159 return E_NOTIMPL;
162 static HRESULT WINAPI HTMLImgElement_get_protocol(IHTMLImgElement *iface, BSTR *p)
164 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
165 FIXME("(%p)->(%p)\n", This, p);
166 return E_NOTIMPL;
169 static HRESULT WINAPI HTMLImgElement_get_href(IHTMLImgElement *iface, BSTR *p)
171 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
172 FIXME("(%p)->(%p)\n", This, p);
173 return E_NOTIMPL;
176 static HRESULT WINAPI HTMLImgElement_get_nameProp(IHTMLImgElement *iface, BSTR *p)
178 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
179 FIXME("(%p)->(%p)\n", This, p);
180 return E_NOTIMPL;
183 static HRESULT WINAPI HTMLImgElement_put_border(IHTMLImgElement *iface, VARIANT v)
185 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
186 FIXME("(%p)->()\n", This);
187 return E_NOTIMPL;
190 static HRESULT WINAPI HTMLImgElement_get_border(IHTMLImgElement *iface, VARIANT *p)
192 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
193 FIXME("(%p)->(%p)\n", This, p);
194 return E_NOTIMPL;
197 static HRESULT WINAPI HTMLImgElement_put_vspace(IHTMLImgElement *iface, LONG v)
199 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
200 FIXME("(%p)->(%d)\n", This, v);
201 return E_NOTIMPL;
204 static HRESULT WINAPI HTMLImgElement_get_vspace(IHTMLImgElement *iface, LONG *p)
206 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
207 FIXME("(%p)->(%p)\n", This, p);
208 return E_NOTIMPL;
211 static HRESULT WINAPI HTMLImgElement_put_hspace(IHTMLImgElement *iface, LONG v)
213 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
214 FIXME("(%p)->(%d)\n", This, v);
215 return E_NOTIMPL;
218 static HRESULT WINAPI HTMLImgElement_get_hspace(IHTMLImgElement *iface, LONG *p)
220 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
221 FIXME("(%p)->(%p)\n", This, p);
222 return E_NOTIMPL;
225 static HRESULT WINAPI HTMLImgElement_put_alt(IHTMLImgElement *iface, BSTR v)
227 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
228 nsAString alt_str;
229 nsresult nsres;
231 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
233 nsAString_InitDepend(&alt_str, v);
234 nsres = nsIDOMHTMLImageElement_SetAlt(This->nsimg, &alt_str);
235 nsAString_Finish(&alt_str);
236 if(NS_FAILED(nsres))
237 ERR("SetAlt failed: %08x\n", nsres);
239 return S_OK;
242 static HRESULT WINAPI HTMLImgElement_get_alt(IHTMLImgElement *iface, BSTR *p)
244 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
245 nsAString alt_str;
246 nsresult nsres;
248 TRACE("(%p)->(%p)\n", This, p);
250 nsAString_Init(&alt_str, NULL);
251 nsres = nsIDOMHTMLImageElement_GetAlt(This->nsimg, &alt_str);
252 if(NS_SUCCEEDED(nsres)) {
253 const PRUnichar *alt;
255 nsAString_GetData(&alt_str, &alt);
256 *p = *alt ? SysAllocString(alt) : NULL;
257 }else {
258 ERR("GetAlt failed: %08x\n", nsres);
260 nsAString_Finish(&alt_str);
262 return NS_SUCCEEDED(nsres) ? S_OK : E_FAIL;
265 static HRESULT WINAPI HTMLImgElement_put_src(IHTMLImgElement *iface, BSTR v)
267 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
268 nsAString src_str;
269 nsresult nsres;
271 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
273 nsAString_InitDepend(&src_str, v);
274 nsres = nsIDOMHTMLImageElement_SetSrc(This->nsimg, &src_str);
275 nsAString_Finish(&src_str);
276 if(NS_FAILED(nsres))
277 ERR("SetSrc failed: %08x\n", nsres);
279 return NS_OK;
282 static HRESULT WINAPI HTMLImgElement_get_src(IHTMLImgElement *iface, BSTR *p)
284 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
285 const PRUnichar *src;
286 nsAString src_str;
287 nsresult nsres;
288 HRESULT hres;
290 TRACE("(%p)->(%p)\n", This, p);
292 nsAString_Init(&src_str, NULL);
293 nsres = nsIDOMHTMLImageElement_GetSrc(This->nsimg, &src_str);
294 if(NS_FAILED(nsres)) {
295 ERR("GetSrc failed: %08x\n", nsres);
296 return E_FAIL;
299 nsAString_GetData(&src_str, &src);
300 hres = nsuri_to_url(src, TRUE, p);
301 nsAString_Finish(&src_str);
303 return hres;
306 static HRESULT WINAPI HTMLImgElement_put_lowsrc(IHTMLImgElement *iface, BSTR v)
308 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
309 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
310 return E_NOTIMPL;
313 static HRESULT WINAPI HTMLImgElement_get_lowsrc(IHTMLImgElement *iface, BSTR *p)
315 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
316 FIXME("(%p)->(%p)\n", This, p);
317 return E_NOTIMPL;
320 static HRESULT WINAPI HTMLImgElement_put_vrml(IHTMLImgElement *iface, BSTR v)
322 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
323 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
324 return E_NOTIMPL;
327 static HRESULT WINAPI HTMLImgElement_get_vrml(IHTMLImgElement *iface, BSTR *p)
329 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
330 FIXME("(%p)->(%p)\n", This, p);
331 return E_NOTIMPL;
334 static HRESULT WINAPI HTMLImgElement_put_dynsrc(IHTMLImgElement *iface, BSTR v)
336 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
337 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
338 return E_NOTIMPL;
341 static HRESULT WINAPI HTMLImgElement_get_dynsrc(IHTMLImgElement *iface, BSTR *p)
343 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
344 FIXME("(%p)->(%p)\n", This, p);
345 return E_NOTIMPL;
348 static HRESULT WINAPI HTMLImgElement_get_readyState(IHTMLImgElement *iface, BSTR *p)
350 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
351 FIXME("(%p)->(%p)\n", This, p);
352 return E_NOTIMPL;
355 static HRESULT WINAPI HTMLImgElement_get_complete(IHTMLImgElement *iface, VARIANT_BOOL *p)
357 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
358 FIXME("(%p)->(%p)\n", This, p);
359 return E_NOTIMPL;
362 static HRESULT WINAPI HTMLImgElement_put_loop(IHTMLImgElement *iface, VARIANT v)
364 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
365 FIXME("(%p)->()\n", This);
366 return E_NOTIMPL;
369 static HRESULT WINAPI HTMLImgElement_get_loop(IHTMLImgElement *iface, VARIANT *p)
371 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
372 FIXME("(%p)->(%p)\n", This, p);
373 return E_NOTIMPL;
376 static HRESULT WINAPI HTMLImgElement_put_align(IHTMLImgElement *iface, BSTR v)
378 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
379 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
380 return E_NOTIMPL;
383 static HRESULT WINAPI HTMLImgElement_get_align(IHTMLImgElement *iface, BSTR *p)
385 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
386 FIXME("(%p)->(%p)\n", This, p);
387 return E_NOTIMPL;
390 static HRESULT WINAPI HTMLImgElement_put_onload(IHTMLImgElement *iface, VARIANT v)
392 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
394 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
396 return set_node_event(&This->element.node, EVENTID_LOAD, &v);
399 static HRESULT WINAPI HTMLImgElement_get_onload(IHTMLImgElement *iface, VARIANT *p)
401 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
403 TRACE("(%p)->(%p)\n", This, p);
405 return get_node_event(&This->element.node, EVENTID_LOAD, p);
408 static HRESULT WINAPI HTMLImgElement_put_onerror(IHTMLImgElement *iface, VARIANT v)
410 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
411 FIXME("(%p)->()\n", This);
412 return E_NOTIMPL;
415 static HRESULT WINAPI HTMLImgElement_get_onerror(IHTMLImgElement *iface, VARIANT *p)
417 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
418 FIXME("(%p)->(%p)\n", This, p);
419 return E_NOTIMPL;
422 static HRESULT WINAPI HTMLImgElement_put_onabort(IHTMLImgElement *iface, VARIANT v)
424 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
425 FIXME("(%p)->()\n", This);
426 return E_NOTIMPL;
429 static HRESULT WINAPI HTMLImgElement_get_onabort(IHTMLImgElement *iface, VARIANT *p)
431 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
432 FIXME("(%p)->(%p)\n", This, p);
433 return E_NOTIMPL;
436 static HRESULT WINAPI HTMLImgElement_put_name(IHTMLImgElement *iface, BSTR v)
438 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
439 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
440 return E_NOTIMPL;
443 static HRESULT WINAPI HTMLImgElement_get_name(IHTMLImgElement *iface, BSTR *p)
445 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
446 nsAString strName;
447 nsresult nsres;
449 TRACE("(%p)->(%p)\n", This, p);
451 nsAString_Init(&strName, NULL);
452 nsres = nsIDOMHTMLImageElement_GetName(This->nsimg, &strName);
453 if(NS_SUCCEEDED(nsres)) {
454 const PRUnichar *str;
456 nsAString_GetData(&strName, &str);
457 *p = *str ? SysAllocString(str) : NULL;
458 }else {
459 ERR("GetName failed: %08x\n", nsres);
461 nsAString_Finish(&strName);
463 return NS_SUCCEEDED(nsres) ? S_OK : E_FAIL;
466 static HRESULT WINAPI HTMLImgElement_put_width(IHTMLImgElement *iface, LONG v)
468 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
469 nsresult nsres;
471 TRACE("(%p)->(%d)\n", This, v);
473 nsres = nsIDOMHTMLImageElement_SetWidth(This->nsimg, v);
474 if(NS_FAILED(nsres)) {
475 ERR("SetWidth failed: %08x\n", nsres);
476 return E_FAIL;
479 return S_OK;
482 static HRESULT WINAPI HTMLImgElement_get_width(IHTMLImgElement *iface, LONG *p)
484 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
485 PRInt32 width;
486 nsresult nsres;
488 TRACE("(%p)->(%p)\n", This, p);
490 nsres = nsIDOMHTMLImageElement_GetWidth(This->nsimg, &width);
491 if(NS_FAILED(nsres)) {
492 ERR("GetWidth failed: %08x\n", nsres);
493 return E_FAIL;
496 *p = width;
497 return S_OK;
500 static HRESULT WINAPI HTMLImgElement_put_height(IHTMLImgElement *iface, LONG v)
502 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
503 nsresult nsres;
505 TRACE("(%p)->(%d)\n", This, v);
507 nsres = nsIDOMHTMLImageElement_SetHeight(This->nsimg, v);
508 if(NS_FAILED(nsres)) {
509 ERR("SetHeight failed: %08x\n", nsres);
510 return E_FAIL;
513 return S_OK;
516 static HRESULT WINAPI HTMLImgElement_get_height(IHTMLImgElement *iface, LONG *p)
518 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
519 PRInt32 height;
520 nsresult nsres;
522 TRACE("(%p)->(%p)\n", This, p);
524 nsres = nsIDOMHTMLImageElement_GetHeight(This->nsimg, &height);
525 if(NS_FAILED(nsres)) {
526 ERR("GetHeight failed: %08x\n", nsres);
527 return E_FAIL;
530 *p = height;
531 return S_OK;
534 static HRESULT WINAPI HTMLImgElement_put_start(IHTMLImgElement *iface, BSTR v)
536 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
537 FIXME("(%p)->()\n", This);
538 return E_NOTIMPL;
541 static HRESULT WINAPI HTMLImgElement_get_start(IHTMLImgElement *iface, BSTR *p)
543 HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
544 FIXME("(%p)->(%p)\n", This, p);
545 return E_NOTIMPL;
548 static const IHTMLImgElementVtbl HTMLImgElementVtbl = {
549 HTMLImgElement_QueryInterface,
550 HTMLImgElement_AddRef,
551 HTMLImgElement_Release,
552 HTMLImgElement_GetTypeInfoCount,
553 HTMLImgElement_GetTypeInfo,
554 HTMLImgElement_GetIDsOfNames,
555 HTMLImgElement_Invoke,
556 HTMLImgElement_put_isMap,
557 HTMLImgElement_get_isMap,
558 HTMLImgElement_put_useMap,
559 HTMLImgElement_get_useMap,
560 HTMLImgElement_get_mimeType,
561 HTMLImgElement_get_fileSize,
562 HTMLImgElement_get_fileCreatedDate,
563 HTMLImgElement_get_fileModifiedDate,
564 HTMLImgElement_get_fileUpdatedDate,
565 HTMLImgElement_get_protocol,
566 HTMLImgElement_get_href,
567 HTMLImgElement_get_nameProp,
568 HTMLImgElement_put_border,
569 HTMLImgElement_get_border,
570 HTMLImgElement_put_vspace,
571 HTMLImgElement_get_vspace,
572 HTMLImgElement_put_hspace,
573 HTMLImgElement_get_hspace,
574 HTMLImgElement_put_alt,
575 HTMLImgElement_get_alt,
576 HTMLImgElement_put_src,
577 HTMLImgElement_get_src,
578 HTMLImgElement_put_lowsrc,
579 HTMLImgElement_get_lowsrc,
580 HTMLImgElement_put_vrml,
581 HTMLImgElement_get_vrml,
582 HTMLImgElement_put_dynsrc,
583 HTMLImgElement_get_dynsrc,
584 HTMLImgElement_get_readyState,
585 HTMLImgElement_get_complete,
586 HTMLImgElement_put_loop,
587 HTMLImgElement_get_loop,
588 HTMLImgElement_put_align,
589 HTMLImgElement_get_align,
590 HTMLImgElement_put_onload,
591 HTMLImgElement_get_onload,
592 HTMLImgElement_put_onerror,
593 HTMLImgElement_get_onerror,
594 HTMLImgElement_put_onabort,
595 HTMLImgElement_get_onabort,
596 HTMLImgElement_put_name,
597 HTMLImgElement_get_name,
598 HTMLImgElement_put_width,
599 HTMLImgElement_get_width,
600 HTMLImgElement_put_height,
601 HTMLImgElement_get_height,
602 HTMLImgElement_put_start,
603 HTMLImgElement_get_start
606 #define HTMLIMG_NODE_THIS(iface) DEFINE_THIS2(HTMLImgElement, element.node, iface)
608 static HRESULT HTMLImgElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
610 HTMLImgElement *This = HTMLIMG_NODE_THIS(iface);
612 *ppv = NULL;
614 if(IsEqualGUID(&IID_IHTMLImgElement, riid)) {
615 TRACE("(%p)->(IID_IHTMLImgElement %p)\n", This, ppv);
616 *ppv = &This->IHTMLImgElement_iface;
617 }else {
618 return HTMLElement_QI(&This->element.node, riid, ppv);
621 IUnknown_AddRef((IUnknown*)*ppv);
622 return S_OK;
625 static void HTMLImgElement_destructor(HTMLDOMNode *iface)
627 HTMLImgElement *This = HTMLIMG_NODE_THIS(iface);
629 if(This->nsimg)
630 nsIDOMHTMLImageElement_Release(This->nsimg);
632 HTMLElement_destructor(&This->element.node);
635 static HRESULT HTMLImgElement_get_readystate(HTMLDOMNode *iface, BSTR *p)
637 HTMLImgElement *This = HTMLIMG_NODE_THIS(iface);
639 return IHTMLImgElement_get_readyState(&This->IHTMLImgElement_iface, p);
642 #undef HTMLIMG_NODE_THIS
644 static const NodeImplVtbl HTMLImgElementImplVtbl = {
645 HTMLImgElement_QI,
646 HTMLImgElement_destructor,
647 HTMLElement_clone,
648 NULL,
649 NULL,
650 NULL,
651 NULL,
652 NULL,
653 HTMLImgElement_get_readystate
656 static const tid_t HTMLImgElement_iface_tids[] = {
657 HTMLELEMENT_TIDS,
658 IHTMLImgElement_tid,
661 static dispex_static_data_t HTMLImgElement_dispex = {
662 NULL,
663 DispHTMLImg_tid,
664 NULL,
665 HTMLImgElement_iface_tids
668 HRESULT HTMLImgElement_Create(HTMLDocumentNode *doc, nsIDOMHTMLElement *nselem, HTMLElement **elem)
670 HTMLImgElement *ret;
671 nsresult nsres;
673 ret = heap_alloc_zero(sizeof(HTMLImgElement));
674 if(!ret)
675 return E_OUTOFMEMORY;
677 ret->IHTMLImgElement_iface.lpVtbl = &HTMLImgElementVtbl;
678 ret->element.node.vtbl = &HTMLImgElementImplVtbl;
680 nsres = nsIDOMHTMLElement_QueryInterface(nselem, &IID_nsIDOMHTMLImageElement, (void**)&ret->nsimg);
681 if(NS_FAILED(nsres)) {
682 ERR("Could not get nsIDOMHTMLImageElement: %08x\n", nsres);
683 heap_free(ret);
684 return E_FAIL;
687 HTMLElement_Init(&ret->element, doc, nselem, &HTMLImgElement_dispex);
689 *elem = &ret->element;
690 return S_OK;
693 #define HTMLIMGFACTORY_THIS(iface) DEFINE_THIS(HTMLImageElementFactory, HTMLImageElementFactory, iface)
695 static HRESULT WINAPI HTMLImageElementFactory_QueryInterface(IHTMLImageElementFactory *iface,
696 REFIID riid, void **ppv)
698 HTMLImageElementFactory *This = HTMLIMGFACTORY_THIS(iface);
700 *ppv = NULL;
702 if(IsEqualGUID(&IID_IUnknown, riid)) {
703 TRACE("(%p)->(IID_Unknown %p)\n", This, ppv);
704 *ppv = HTMLIMGFACTORY(This);
705 }else if(IsEqualGUID(&IID_IHTMLImageElementFactory, riid)) {
706 TRACE("(%p)->(IID_IHTMLImageElementFactory %p)\n", This, ppv);
707 *ppv = HTMLIMGFACTORY(This);
708 }else if(dispex_query_interface(&This->dispex, riid, ppv))
709 return *ppv ? S_OK : E_NOINTERFACE;
711 if(*ppv) {
712 IUnknown_AddRef((IUnknown*)*ppv);
713 return S_OK;
716 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
717 return E_NOINTERFACE;
720 static ULONG WINAPI HTMLImageElementFactory_AddRef(IHTMLImageElementFactory *iface)
722 HTMLImageElementFactory *This = HTMLIMGFACTORY_THIS(iface);
723 LONG ref = InterlockedIncrement(&This->ref);
725 TRACE("(%p) ref=%d\n", This, ref);
727 return ref;
730 static ULONG WINAPI HTMLImageElementFactory_Release(IHTMLImageElementFactory *iface)
732 HTMLImageElementFactory *This = HTMLIMGFACTORY_THIS(iface);
733 LONG ref = InterlockedDecrement(&This->ref);
735 TRACE("(%p) ref=%d\n", This, ref);
737 if(!ref)
738 heap_free(This);
740 return ref;
743 static HRESULT WINAPI HTMLImageElementFactory_GetTypeInfoCount(IHTMLImageElementFactory *iface,
744 UINT *pctinfo)
746 HTMLImageElementFactory *This = HTMLIMGFACTORY_THIS(iface);
747 FIXME("(%p)->(%p)\n", This, pctinfo);
748 return E_NOTIMPL;
751 static HRESULT WINAPI HTMLImageElementFactory_GetTypeInfo(IHTMLImageElementFactory *iface,
752 UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
754 HTMLImageElementFactory *This = HTMLIMGFACTORY_THIS(iface);
755 FIXME("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
756 return E_NOTIMPL;
759 static HRESULT WINAPI HTMLImageElementFactory_GetIDsOfNames(IHTMLImageElementFactory *iface,
760 REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid,
761 DISPID *rgDispId)
763 HTMLImageElementFactory *This = HTMLIMGFACTORY_THIS(iface);
764 FIXME("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames,
765 cNames, lcid, rgDispId);
766 return E_NOTIMPL;
769 static HRESULT WINAPI HTMLImageElementFactory_Invoke(IHTMLImageElementFactory *iface,
770 DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags,
771 DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo,
772 UINT *puArgErr)
774 HTMLImageElementFactory *This = HTMLIMGFACTORY_THIS(iface);
775 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
776 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
777 return E_NOTIMPL;
780 static LONG var_to_size(const VARIANT *v)
782 switch(V_VT(v)) {
783 case VT_EMPTY:
784 return 0;
785 case VT_I4:
786 return V_I4(v);
787 case VT_BSTR: {
788 LONG ret;
789 HRESULT hres;
791 hres = VarI4FromStr(V_BSTR(v), 0, 0, &ret);
792 if(FAILED(hres)) {
793 FIXME("VarI4FromStr failed: %08x\n", hres);
794 return 0;
796 return ret;
798 default:
799 FIXME("unsupported size %s\n", debugstr_variant(v));
801 return 0;
804 static HRESULT WINAPI HTMLImageElementFactory_create(IHTMLImageElementFactory *iface,
805 VARIANT width, VARIANT height, IHTMLImgElement **img_elem)
807 HTMLImageElementFactory *This = HTMLIMGFACTORY_THIS(iface);
808 IHTMLImgElement *img;
809 HTMLElement *elem;
810 nsIDOMHTMLElement *nselem;
811 LONG l;
812 HRESULT hres;
814 static const PRUnichar imgW[] = {'I','M','G',0};
816 TRACE("(%p)->(%s %s %p)\n", This, debugstr_variant(&width),
817 debugstr_variant(&height), img_elem);
819 if(!This->window || !This->window->doc) {
820 WARN("NULL doc\n");
821 return E_UNEXPECTED;
824 *img_elem = NULL;
826 hres = create_nselem(This->window->doc, imgW, &nselem);
827 if(FAILED(hres))
828 return hres;
830 hres = HTMLElement_Create(This->window->doc, (nsIDOMNode*)nselem, FALSE, &elem);
831 nsIDOMHTMLElement_Release(nselem);
832 if(FAILED(hres)) {
833 ERR("HTMLElement_Create failed\n");
834 return hres;
837 hres = IHTMLElement_QueryInterface(HTMLELEM(elem), &IID_IHTMLImgElement, (void**)&img);
838 if(FAILED(hres)) {
839 ERR("IHTMLElement_QueryInterface failed: 0x%08x\n", hres);
840 return hres;
843 l = var_to_size(&width);
844 if(l)
845 IHTMLImgElement_put_width(img, l);
846 l = var_to_size(&height);
847 if(l)
848 IHTMLImgElement_put_height(img, l);
850 *img_elem = img;
851 return S_OK;
854 static HRESULT HTMLImageElementFactory_value(IUnknown *iface, LCID lcid,
855 WORD flags, DISPPARAMS *params, VARIANT *res, EXCEPINFO *ei,
856 IServiceProvider *caller)
858 HTMLImageElementFactory *This = HTMLIMGFACTORY_THIS(iface);
859 IHTMLImgElement *img;
860 VARIANT empty, *width, *height;
861 HRESULT hres;
862 int argc = params->cArgs - params->cNamedArgs;
864 V_VT(res) = VT_NULL;
866 V_VT(&empty) = VT_EMPTY;
868 width = argc >= 1 ? params->rgvarg + (params->cArgs - 1) : &empty;
869 height = argc >= 2 ? params->rgvarg + (params->cArgs - 2) : &empty;
871 hres = IHTMLImageElementFactory_create(HTMLIMGFACTORY(This), *width, *height, &img);
872 if(FAILED(hres))
873 return hres;
875 V_VT(res) = VT_DISPATCH;
876 V_DISPATCH(res) = (IDispatch*)img;
878 return S_OK;
881 #undef HTMLIMGFACTORY_THIS
883 static const IHTMLImageElementFactoryVtbl HTMLImageElementFactoryVtbl = {
884 HTMLImageElementFactory_QueryInterface,
885 HTMLImageElementFactory_AddRef,
886 HTMLImageElementFactory_Release,
887 HTMLImageElementFactory_GetTypeInfoCount,
888 HTMLImageElementFactory_GetTypeInfo,
889 HTMLImageElementFactory_GetIDsOfNames,
890 HTMLImageElementFactory_Invoke,
891 HTMLImageElementFactory_create
894 static const tid_t HTMLImageElementFactory_iface_tids[] = {
895 IHTMLImageElementFactory_tid,
899 static const dispex_static_data_vtbl_t HTMLImageElementFactory_dispex_vtbl = {
900 HTMLImageElementFactory_value,
901 NULL,
902 NULL
905 static dispex_static_data_t HTMLImageElementFactory_dispex = {
906 &HTMLImageElementFactory_dispex_vtbl,
907 IHTMLImageElementFactory_tid,
908 NULL,
909 HTMLImageElementFactory_iface_tids
912 HTMLImageElementFactory *HTMLImageElementFactory_Create(HTMLWindow *window)
914 HTMLImageElementFactory *ret;
916 ret = heap_alloc(sizeof(HTMLImageElementFactory));
918 ret->lpHTMLImageElementFactoryVtbl = &HTMLImageElementFactoryVtbl;
919 ret->ref = 1;
920 ret->window = window;
922 init_dispex(&ret->dispex, (IUnknown*)HTMLIMGFACTORY(ret), &HTMLImageElementFactory_dispex);
924 return ret;