mshtml: Added IHTMLImgElement::width property implementation.
[wine/multimedia.git] / dlls / mshtml / htmlimg.c
blob8fbfcae0cda6d64d3d507b380a02f27797c9ef5c
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"
32 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
34 typedef struct {
35 HTMLElement element;
37 const IHTMLImgElementVtbl *lpHTMLImgElementVtbl;
39 nsIDOMHTMLImageElement *nsimg;
40 } HTMLImgElement;
42 #define HTMLIMG(x) ((IHTMLImgElement*) &(x)->lpHTMLImgElementVtbl)
44 #define HTMLIMG_THIS(iface) DEFINE_THIS(HTMLImgElement, HTMLImgElement, iface)
46 static HRESULT WINAPI HTMLImgElement_QueryInterface(IHTMLImgElement *iface, REFIID riid, void **ppv)
48 HTMLImgElement *This = HTMLIMG_THIS(iface);
50 return IHTMLDOMNode_QueryInterface(HTMLDOMNODE(&This->element.node), riid, ppv);
53 static ULONG WINAPI HTMLImgElement_AddRef(IHTMLImgElement *iface)
55 HTMLImgElement *This = HTMLIMG_THIS(iface);
57 return IHTMLDOMNode_AddRef(HTMLDOMNODE(&This->element.node));
60 static ULONG WINAPI HTMLImgElement_Release(IHTMLImgElement *iface)
62 HTMLImgElement *This = HTMLIMG_THIS(iface);
64 return IHTMLDOMNode_Release(HTMLDOMNODE(&This->element.node));
67 static HRESULT WINAPI HTMLImgElement_GetTypeInfoCount(IHTMLImgElement *iface, UINT *pctinfo)
69 HTMLImgElement *This = HTMLIMG_THIS(iface);
70 return IDispatchEx_GetTypeInfoCount(DISPATCHEX(&This->element.node.dispex), pctinfo);
73 static HRESULT WINAPI HTMLImgElement_GetTypeInfo(IHTMLImgElement *iface, UINT iTInfo,
74 LCID lcid, ITypeInfo **ppTInfo)
76 HTMLImgElement *This = HTMLIMG_THIS(iface);
77 return IDispatchEx_GetTypeInfo(DISPATCHEX(&This->element.node.dispex), iTInfo, lcid, ppTInfo);
80 static HRESULT WINAPI HTMLImgElement_GetIDsOfNames(IHTMLImgElement *iface, REFIID riid,
81 LPOLESTR *rgszNames, UINT cNames,
82 LCID lcid, DISPID *rgDispId)
84 HTMLImgElement *This = HTMLIMG_THIS(iface);
85 return IDispatchEx_GetIDsOfNames(DISPATCHEX(&This->element.node.dispex), riid, rgszNames, cNames, lcid, rgDispId);
88 static HRESULT WINAPI HTMLImgElement_Invoke(IHTMLImgElement *iface, DISPID dispIdMember,
89 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
90 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
92 HTMLImgElement *This = HTMLIMG_THIS(iface);
93 return IDispatchEx_Invoke(DISPATCHEX(&This->element.node.dispex), dispIdMember, riid, lcid, wFlags, pDispParams,
94 pVarResult, pExcepInfo, puArgErr);
97 static HRESULT WINAPI HTMLImgElement_put_isMap(IHTMLImgElement *iface, VARIANT_BOOL v)
99 HTMLImgElement *This = HTMLIMG_THIS(iface);
100 FIXME("(%p)->(%x)\n", This, v);
101 return E_NOTIMPL;
104 static HRESULT WINAPI HTMLImgElement_get_isMap(IHTMLImgElement *iface, VARIANT_BOOL *p)
106 HTMLImgElement *This = HTMLIMG_THIS(iface);
107 FIXME("(%p)->(%p)\n", This, p);
108 return E_NOTIMPL;
111 static HRESULT WINAPI HTMLImgElement_put_useMap(IHTMLImgElement *iface, BSTR v)
113 HTMLImgElement *This = HTMLIMG_THIS(iface);
114 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
115 return E_NOTIMPL;
118 static HRESULT WINAPI HTMLImgElement_get_useMap(IHTMLImgElement *iface, BSTR *p)
120 HTMLImgElement *This = HTMLIMG_THIS(iface);
121 FIXME("(%p)->(%p)\n", This, p);
122 return E_NOTIMPL;
125 static HRESULT WINAPI HTMLImgElement_get_mimeType(IHTMLImgElement *iface, BSTR *p)
127 HTMLImgElement *This = HTMLIMG_THIS(iface);
128 FIXME("(%p)->(%p)\n", This, p);
129 return E_NOTIMPL;
132 static HRESULT WINAPI HTMLImgElement_get_fileSize(IHTMLImgElement *iface, BSTR *p)
134 HTMLImgElement *This = HTMLIMG_THIS(iface);
135 FIXME("(%p)->(%p)\n", This, p);
136 return E_NOTIMPL;
139 static HRESULT WINAPI HTMLImgElement_get_fileCreatedDate(IHTMLImgElement *iface, BSTR *p)
141 HTMLImgElement *This = HTMLIMG_THIS(iface);
142 FIXME("(%p)->(%p)\n", This, p);
143 return E_NOTIMPL;
146 static HRESULT WINAPI HTMLImgElement_get_fileModifiedDate(IHTMLImgElement *iface, BSTR *p)
148 HTMLImgElement *This = HTMLIMG_THIS(iface);
149 FIXME("(%p)->(%p)\n", This, p);
150 return E_NOTIMPL;
153 static HRESULT WINAPI HTMLImgElement_get_fileUpdatedDate(IHTMLImgElement *iface, BSTR *p)
155 HTMLImgElement *This = HTMLIMG_THIS(iface);
156 FIXME("(%p)->(%p)\n", This, p);
157 return E_NOTIMPL;
160 static HRESULT WINAPI HTMLImgElement_get_protocol(IHTMLImgElement *iface, BSTR *p)
162 HTMLImgElement *This = HTMLIMG_THIS(iface);
163 FIXME("(%p)->(%p)\n", This, p);
164 return E_NOTIMPL;
167 static HRESULT WINAPI HTMLImgElement_get_href(IHTMLImgElement *iface, BSTR *p)
169 HTMLImgElement *This = HTMLIMG_THIS(iface);
170 FIXME("(%p)->(%p)\n", This, p);
171 return E_NOTIMPL;
174 static HRESULT WINAPI HTMLImgElement_get_nameProp(IHTMLImgElement *iface, BSTR *p)
176 HTMLImgElement *This = HTMLIMG_THIS(iface);
177 FIXME("(%p)->(%p)\n", This, p);
178 return E_NOTIMPL;
181 static HRESULT WINAPI HTMLImgElement_put_border(IHTMLImgElement *iface, VARIANT v)
183 HTMLImgElement *This = HTMLIMG_THIS(iface);
184 FIXME("(%p)->()\n", This);
185 return E_NOTIMPL;
188 static HRESULT WINAPI HTMLImgElement_get_border(IHTMLImgElement *iface, VARIANT *p)
190 HTMLImgElement *This = HTMLIMG_THIS(iface);
191 FIXME("(%p)->(%p)\n", This, p);
192 return E_NOTIMPL;
195 static HRESULT WINAPI HTMLImgElement_put_vspace(IHTMLImgElement *iface, LONG v)
197 HTMLImgElement *This = HTMLIMG_THIS(iface);
198 FIXME("(%p)->(%d)\n", This, v);
199 return E_NOTIMPL;
202 static HRESULT WINAPI HTMLImgElement_get_vspace(IHTMLImgElement *iface, LONG *p)
204 HTMLImgElement *This = HTMLIMG_THIS(iface);
205 FIXME("(%p)->(%p)\n", This, p);
206 return E_NOTIMPL;
209 static HRESULT WINAPI HTMLImgElement_put_hspace(IHTMLImgElement *iface, LONG v)
211 HTMLImgElement *This = HTMLIMG_THIS(iface);
212 FIXME("(%p)->(%d)\n", This, v);
213 return E_NOTIMPL;
216 static HRESULT WINAPI HTMLImgElement_get_hspace(IHTMLImgElement *iface, LONG *p)
218 HTMLImgElement *This = HTMLIMG_THIS(iface);
219 FIXME("(%p)->(%p)\n", This, p);
220 return E_NOTIMPL;
223 static HRESULT WINAPI HTMLImgElement_put_alt(IHTMLImgElement *iface, BSTR v)
225 HTMLImgElement *This = HTMLIMG_THIS(iface);
226 nsAString alt_str;
227 nsresult nsres;
229 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
231 nsAString_InitDepend(&alt_str, v);
232 nsres = nsIDOMHTMLImageElement_SetAlt(This->nsimg, &alt_str);
233 nsAString_Finish(&alt_str);
234 if(NS_FAILED(nsres))
235 ERR("SetAlt failed: %08x\n", nsres);
237 return S_OK;
240 static HRESULT WINAPI HTMLImgElement_get_alt(IHTMLImgElement *iface, BSTR *p)
242 HTMLImgElement *This = HTMLIMG_THIS(iface);
243 nsAString alt_str;
244 nsresult nsres;
246 TRACE("(%p)->(%p)\n", This, p);
248 nsAString_Init(&alt_str, NULL);
249 nsres = nsIDOMHTMLImageElement_GetAlt(This->nsimg, &alt_str);
250 if(NS_SUCCEEDED(nsres)) {
251 const PRUnichar *alt;
253 nsAString_GetData(&alt_str, &alt);
254 *p = *alt ? SysAllocString(alt) : NULL;
255 }else {
256 ERR("GetAlt failed: %08x\n", nsres);
258 nsAString_Finish(&alt_str);
260 return NS_SUCCEEDED(nsres) ? S_OK : E_FAIL;
263 static HRESULT WINAPI HTMLImgElement_put_src(IHTMLImgElement *iface, BSTR v)
265 HTMLImgElement *This = HTMLIMG_THIS(iface);
266 nsAString src_str;
267 nsresult nsres;
269 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
271 nsAString_InitDepend(&src_str, v);
272 nsres = nsIDOMHTMLImageElement_SetSrc(This->nsimg, &src_str);
273 nsAString_Finish(&src_str);
274 if(NS_FAILED(nsres))
275 ERR("SetSrc failed: %08x\n", nsres);
277 return NS_OK;
280 static HRESULT WINAPI HTMLImgElement_get_src(IHTMLImgElement *iface, BSTR *p)
282 HTMLImgElement *This = HTMLIMG_THIS(iface);
283 const PRUnichar *src;
284 nsAString src_str;
285 nsresult nsres;
286 HRESULT hres;
288 TRACE("(%p)->(%p)\n", This, p);
290 nsAString_Init(&src_str, NULL);
291 nsres = nsIDOMHTMLImageElement_GetSrc(This->nsimg, &src_str);
292 if(NS_FAILED(nsres)) {
293 ERR("GetSrc failed: %08x\n", nsres);
294 return E_FAIL;
297 nsAString_GetData(&src_str, &src);
298 hres = nsuri_to_url(src, TRUE, p);
299 nsAString_Finish(&src_str);
301 return hres;
304 static HRESULT WINAPI HTMLImgElement_put_lowsrc(IHTMLImgElement *iface, BSTR v)
306 HTMLImgElement *This = HTMLIMG_THIS(iface);
307 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
308 return E_NOTIMPL;
311 static HRESULT WINAPI HTMLImgElement_get_lowsrc(IHTMLImgElement *iface, BSTR *p)
313 HTMLImgElement *This = HTMLIMG_THIS(iface);
314 FIXME("(%p)->(%p)\n", This, p);
315 return E_NOTIMPL;
318 static HRESULT WINAPI HTMLImgElement_put_vrml(IHTMLImgElement *iface, BSTR v)
320 HTMLImgElement *This = HTMLIMG_THIS(iface);
321 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
322 return E_NOTIMPL;
325 static HRESULT WINAPI HTMLImgElement_get_vrml(IHTMLImgElement *iface, BSTR *p)
327 HTMLImgElement *This = HTMLIMG_THIS(iface);
328 FIXME("(%p)->(%p)\n", This, p);
329 return E_NOTIMPL;
332 static HRESULT WINAPI HTMLImgElement_put_dynsrc(IHTMLImgElement *iface, BSTR v)
334 HTMLImgElement *This = HTMLIMG_THIS(iface);
335 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
336 return E_NOTIMPL;
339 static HRESULT WINAPI HTMLImgElement_get_dynsrc(IHTMLImgElement *iface, BSTR *p)
341 HTMLImgElement *This = HTMLIMG_THIS(iface);
342 FIXME("(%p)->(%p)\n", This, p);
343 return E_NOTIMPL;
346 static HRESULT WINAPI HTMLImgElement_get_readyState(IHTMLImgElement *iface, BSTR *p)
348 HTMLImgElement *This = HTMLIMG_THIS(iface);
349 FIXME("(%p)->(%p)\n", This, p);
350 return E_NOTIMPL;
353 static HRESULT WINAPI HTMLImgElement_get_complete(IHTMLImgElement *iface, VARIANT_BOOL *p)
355 HTMLImgElement *This = HTMLIMG_THIS(iface);
356 FIXME("(%p)->(%p)\n", This, p);
357 return E_NOTIMPL;
360 static HRESULT WINAPI HTMLImgElement_put_loop(IHTMLImgElement *iface, VARIANT v)
362 HTMLImgElement *This = HTMLIMG_THIS(iface);
363 FIXME("(%p)->()\n", This);
364 return E_NOTIMPL;
367 static HRESULT WINAPI HTMLImgElement_get_loop(IHTMLImgElement *iface, VARIANT *p)
369 HTMLImgElement *This = HTMLIMG_THIS(iface);
370 FIXME("(%p)->(%p)\n", This, p);
371 return E_NOTIMPL;
374 static HRESULT WINAPI HTMLImgElement_put_align(IHTMLImgElement *iface, BSTR v)
376 HTMLImgElement *This = HTMLIMG_THIS(iface);
377 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
378 return E_NOTIMPL;
381 static HRESULT WINAPI HTMLImgElement_get_align(IHTMLImgElement *iface, BSTR *p)
383 HTMLImgElement *This = HTMLIMG_THIS(iface);
384 FIXME("(%p)->(%p)\n", This, p);
385 return E_NOTIMPL;
388 static HRESULT WINAPI HTMLImgElement_put_onload(IHTMLImgElement *iface, VARIANT v)
390 HTMLImgElement *This = HTMLIMG_THIS(iface);
391 FIXME("(%p)->()\n", This);
392 return E_NOTIMPL;
395 static HRESULT WINAPI HTMLImgElement_get_onload(IHTMLImgElement *iface, VARIANT *p)
397 HTMLImgElement *This = HTMLIMG_THIS(iface);
398 FIXME("(%p)->(%p)\n", This, p);
399 return E_NOTIMPL;
402 static HRESULT WINAPI HTMLImgElement_put_onerror(IHTMLImgElement *iface, VARIANT v)
404 HTMLImgElement *This = HTMLIMG_THIS(iface);
405 FIXME("(%p)->()\n", This);
406 return E_NOTIMPL;
409 static HRESULT WINAPI HTMLImgElement_get_onerror(IHTMLImgElement *iface, VARIANT *p)
411 HTMLImgElement *This = HTMLIMG_THIS(iface);
412 FIXME("(%p)->(%p)\n", This, p);
413 return E_NOTIMPL;
416 static HRESULT WINAPI HTMLImgElement_put_onabort(IHTMLImgElement *iface, VARIANT v)
418 HTMLImgElement *This = HTMLIMG_THIS(iface);
419 FIXME("(%p)->()\n", This);
420 return E_NOTIMPL;
423 static HRESULT WINAPI HTMLImgElement_get_onabort(IHTMLImgElement *iface, VARIANT *p)
425 HTMLImgElement *This = HTMLIMG_THIS(iface);
426 FIXME("(%p)->(%p)\n", This, p);
427 return E_NOTIMPL;
430 static HRESULT WINAPI HTMLImgElement_put_name(IHTMLImgElement *iface, BSTR v)
432 HTMLImgElement *This = HTMLIMG_THIS(iface);
433 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
434 return E_NOTIMPL;
437 static HRESULT WINAPI HTMLImgElement_get_name(IHTMLImgElement *iface, BSTR *p)
439 HTMLImgElement *This = HTMLIMG_THIS(iface);
440 nsAString strName;
441 nsresult nsres;
443 TRACE("(%p)->(%p)\n", This, p);
445 nsAString_Init(&strName, NULL);
446 nsres = nsIDOMHTMLImageElement_GetName(This->nsimg, &strName);
447 if(NS_SUCCEEDED(nsres)) {
448 const PRUnichar *str;
450 nsAString_GetData(&strName, &str);
451 *p = *str ? SysAllocString(str) : NULL;
452 }else {
453 ERR("GetName failed: %08x\n", nsres);
455 nsAString_Finish(&strName);
457 return NS_SUCCEEDED(nsres) ? S_OK : E_FAIL;
460 static HRESULT WINAPI HTMLImgElement_put_width(IHTMLImgElement *iface, LONG v)
462 HTMLImgElement *This = HTMLIMG_THIS(iface);
463 nsresult nsres;
465 TRACE("(%p)->(%d)\n", This, v);
467 nsres = nsIDOMHTMLImageElement_SetWidth(This->nsimg, v);
468 if(NS_FAILED(nsres)) {
469 ERR("SetWidth failed: %08x\n", nsres);
470 return E_FAIL;
473 return S_OK;
476 static HRESULT WINAPI HTMLImgElement_get_width(IHTMLImgElement *iface, LONG *p)
478 HTMLImgElement *This = HTMLIMG_THIS(iface);
479 PRInt32 width;
480 nsresult nsres;
482 TRACE("(%p)->(%p)\n", This, p);
484 nsres = nsIDOMHTMLImageElement_GetWidth(This->nsimg, &width);
485 if(NS_FAILED(nsres)) {
486 ERR("GetWidth failed: %08x\n", nsres);
487 return E_FAIL;
490 *p = width;
491 return S_OK;
494 static HRESULT WINAPI HTMLImgElement_put_height(IHTMLImgElement *iface, LONG v)
496 HTMLImgElement *This = HTMLIMG_THIS(iface);
497 FIXME("(%p)->(%d)\n", This, v);
498 return E_NOTIMPL;
501 static HRESULT WINAPI HTMLImgElement_get_height(IHTMLImgElement *iface, LONG *p)
503 HTMLImgElement *This = HTMLIMG_THIS(iface);
504 FIXME("(%p)->(%p)\n", This, p);
505 return E_NOTIMPL;
508 static HRESULT WINAPI HTMLImgElement_put_start(IHTMLImgElement *iface, BSTR v)
510 HTMLImgElement *This = HTMLIMG_THIS(iface);
511 FIXME("(%p)->()\n", This);
512 return E_NOTIMPL;
515 static HRESULT WINAPI HTMLImgElement_get_start(IHTMLImgElement *iface, BSTR *p)
517 HTMLImgElement *This = HTMLIMG_THIS(iface);
518 FIXME("(%p)->(%p)\n", This, p);
519 return E_NOTIMPL;
522 #undef HTMLIMG_THIS
524 static const IHTMLImgElementVtbl HTMLImgElementVtbl = {
525 HTMLImgElement_QueryInterface,
526 HTMLImgElement_AddRef,
527 HTMLImgElement_Release,
528 HTMLImgElement_GetTypeInfoCount,
529 HTMLImgElement_GetTypeInfo,
530 HTMLImgElement_GetIDsOfNames,
531 HTMLImgElement_Invoke,
532 HTMLImgElement_put_isMap,
533 HTMLImgElement_get_isMap,
534 HTMLImgElement_put_useMap,
535 HTMLImgElement_get_useMap,
536 HTMLImgElement_get_mimeType,
537 HTMLImgElement_get_fileSize,
538 HTMLImgElement_get_fileCreatedDate,
539 HTMLImgElement_get_fileModifiedDate,
540 HTMLImgElement_get_fileUpdatedDate,
541 HTMLImgElement_get_protocol,
542 HTMLImgElement_get_href,
543 HTMLImgElement_get_nameProp,
544 HTMLImgElement_put_border,
545 HTMLImgElement_get_border,
546 HTMLImgElement_put_vspace,
547 HTMLImgElement_get_vspace,
548 HTMLImgElement_put_hspace,
549 HTMLImgElement_get_hspace,
550 HTMLImgElement_put_alt,
551 HTMLImgElement_get_alt,
552 HTMLImgElement_put_src,
553 HTMLImgElement_get_src,
554 HTMLImgElement_put_lowsrc,
555 HTMLImgElement_get_lowsrc,
556 HTMLImgElement_put_vrml,
557 HTMLImgElement_get_vrml,
558 HTMLImgElement_put_dynsrc,
559 HTMLImgElement_get_dynsrc,
560 HTMLImgElement_get_readyState,
561 HTMLImgElement_get_complete,
562 HTMLImgElement_put_loop,
563 HTMLImgElement_get_loop,
564 HTMLImgElement_put_align,
565 HTMLImgElement_get_align,
566 HTMLImgElement_put_onload,
567 HTMLImgElement_get_onload,
568 HTMLImgElement_put_onerror,
569 HTMLImgElement_get_onerror,
570 HTMLImgElement_put_onabort,
571 HTMLImgElement_get_onabort,
572 HTMLImgElement_put_name,
573 HTMLImgElement_get_name,
574 HTMLImgElement_put_width,
575 HTMLImgElement_get_width,
576 HTMLImgElement_put_height,
577 HTMLImgElement_get_height,
578 HTMLImgElement_put_start,
579 HTMLImgElement_get_start
582 #define HTMLIMG_NODE_THIS(iface) DEFINE_THIS2(HTMLImgElement, element.node, iface)
584 static HRESULT HTMLImgElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
586 HTMLImgElement *This = HTMLIMG_NODE_THIS(iface);
588 *ppv = NULL;
590 if(IsEqualGUID(&IID_IHTMLImgElement, riid)) {
591 TRACE("(%p)->(IID_IHTMLImgElement %p)\n", This, ppv);
592 *ppv = HTMLIMG(This);
593 }else {
594 return HTMLElement_QI(&This->element.node, riid, ppv);
597 IUnknown_AddRef((IUnknown*)*ppv);
598 return S_OK;
601 static void HTMLImgElement_destructor(HTMLDOMNode *iface)
603 HTMLImgElement *This = HTMLIMG_NODE_THIS(iface);
605 if(This->nsimg)
606 nsIDOMHTMLImageElement_Release(This->nsimg);
608 HTMLElement_destructor(&This->element.node);
611 static HRESULT HTMLImgElement_get_readystate(HTMLDOMNode *iface, BSTR *p)
613 HTMLImgElement *This = HTMLIMG_NODE_THIS(iface);
615 return IHTMLImgElement_get_readyState(HTMLIMG(This), p);
618 #undef HTMLIMG_NODE_THIS
620 static const NodeImplVtbl HTMLImgElementImplVtbl = {
621 HTMLImgElement_QI,
622 HTMLImgElement_destructor,
623 NULL,
624 NULL,
625 NULL,
626 NULL,
627 NULL,
628 HTMLImgElement_get_readystate
631 static const tid_t HTMLImgElement_iface_tids[] = {
632 HTMLELEMENT_TIDS,
633 IHTMLImgElement_tid,
636 static dispex_static_data_t HTMLImgElement_dispex = {
637 NULL,
638 DispHTMLImg_tid,
639 NULL,
640 HTMLImgElement_iface_tids
643 HTMLElement *HTMLImgElement_Create(HTMLDocumentNode *doc, nsIDOMHTMLElement *nselem)
645 HTMLImgElement *ret = heap_alloc_zero(sizeof(HTMLImgElement));
646 nsresult nsres;
648 ret->lpHTMLImgElementVtbl = &HTMLImgElementVtbl;
649 ret->element.node.vtbl = &HTMLImgElementImplVtbl;
651 nsres = nsIDOMHTMLElement_QueryInterface(nselem, &IID_nsIDOMHTMLImageElement, (void**)&ret->nsimg);
652 if(NS_FAILED(nsres))
653 ERR("Could not get nsIDOMHTMLImageElement: %08x\n", nsres);
655 HTMLElement_Init(&ret->element, doc, nselem, &HTMLImgElement_dispex);
657 return &ret->element;
660 #define HTMLIMGFACTORY_THIS(iface) DEFINE_THIS(HTMLImageElementFactory, HTMLImageElementFactory, iface)
662 static HRESULT WINAPI HTMLImageElementFactory_QueryInterface(IHTMLImageElementFactory *iface,
663 REFIID riid, void **ppv)
665 HTMLImageElementFactory *This = HTMLIMGFACTORY_THIS(iface);
667 *ppv = NULL;
669 if(IsEqualGUID(&IID_IUnknown, riid)) {
670 TRACE("(%p)->(IID_Unknown %p)\n", This, ppv);
671 *ppv = HTMLIMGFACTORY(This);
672 }else if(IsEqualGUID(&IID_IHTMLImageElementFactory, riid)) {
673 TRACE("(%p)->(IID_IHTMLImageElementFactory %p)\n", This, ppv);
674 *ppv = HTMLIMGFACTORY(This);
675 }else if(dispex_query_interface(&This->dispex, riid, ppv))
676 return *ppv ? S_OK : E_NOINTERFACE;
678 if(*ppv) {
679 IUnknown_AddRef((IUnknown*)*ppv);
680 return S_OK;
683 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
684 return E_NOINTERFACE;
687 static ULONG WINAPI HTMLImageElementFactory_AddRef(IHTMLImageElementFactory *iface)
689 HTMLImageElementFactory *This = HTMLIMGFACTORY_THIS(iface);
690 LONG ref = InterlockedIncrement(&This->ref);
692 TRACE("(%p) ref=%d\n", This, ref);
694 return ref;
697 static ULONG WINAPI HTMLImageElementFactory_Release(IHTMLImageElementFactory *iface)
699 HTMLImageElementFactory *This = HTMLIMGFACTORY_THIS(iface);
700 LONG ref = InterlockedDecrement(&This->ref);
702 TRACE("(%p) ref=%d\n", This, ref);
704 if(!ref)
705 heap_free(This);
707 return ref;
710 static HRESULT WINAPI HTMLImageElementFactory_GetTypeInfoCount(IHTMLImageElementFactory *iface,
711 UINT *pctinfo)
713 HTMLImageElementFactory *This = HTMLIMGFACTORY_THIS(iface);
714 FIXME("(%p)->(%p)\n", This, pctinfo);
715 return E_NOTIMPL;
718 static HRESULT WINAPI HTMLImageElementFactory_GetTypeInfo(IHTMLImageElementFactory *iface,
719 UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
721 HTMLImageElementFactory *This = HTMLIMGFACTORY_THIS(iface);
722 FIXME("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
723 return E_NOTIMPL;
726 static HRESULT WINAPI HTMLImageElementFactory_GetIDsOfNames(IHTMLImageElementFactory *iface,
727 REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid,
728 DISPID *rgDispId)
730 HTMLImageElementFactory *This = HTMLIMGFACTORY_THIS(iface);
731 FIXME("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames,
732 cNames, lcid, rgDispId);
733 return E_NOTIMPL;
736 static HRESULT WINAPI HTMLImageElementFactory_Invoke(IHTMLImageElementFactory *iface,
737 DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags,
738 DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo,
739 UINT *puArgErr)
741 HTMLImageElementFactory *This = HTMLIMGFACTORY_THIS(iface);
742 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
743 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
744 return E_NOTIMPL;
747 static LONG var_to_size(const VARIANT *v)
749 switch(V_VT(v)) {
750 case VT_EMPTY:
751 return 0;
752 case VT_I4:
753 return V_I4(v);
754 case VT_BSTR: {
755 LONG ret;
756 HRESULT hres;
758 hres = VarI4FromStr(V_BSTR(v), 0, 0, &ret);
759 if(FAILED(hres)) {
760 FIXME("VarI4FromStr failed: %08x\n", hres);
761 return 0;
763 return ret;
765 default:
766 FIXME("unsupported size %s\n", debugstr_variant(v));
768 return 0;
771 static HRESULT WINAPI HTMLImageElementFactory_create(IHTMLImageElementFactory *iface,
772 VARIANT width, VARIANT height, IHTMLImgElement **img_elem)
774 HTMLImageElementFactory *This = HTMLIMGFACTORY_THIS(iface);
775 IHTMLImgElement *img;
776 HTMLElement *elem;
777 nsIDOMHTMLElement *nselem;
778 LONG l;
779 HRESULT hres;
781 static const PRUnichar imgW[] = {'I','M','G',0};
783 TRACE("(%p)->(%s %s %p)\n", This, debugstr_variant(&width),
784 debugstr_variant(&height), img_elem);
786 if(!This->window || !This->window->doc) {
787 WARN("NULL doc\n");
788 return E_UNEXPECTED;
791 *img_elem = NULL;
793 hres = create_nselem(This->window->doc, imgW, &nselem);
794 if(FAILED(hres))
795 return hres;
797 elem = HTMLElement_Create(This->window->doc, (nsIDOMNode*)nselem, FALSE);
798 if(!elem) {
799 ERR("HTMLElement_Create failed\n");
800 return E_FAIL;
803 hres = IHTMLElement_QueryInterface(HTMLELEM(elem), &IID_IHTMLImgElement, (void**)&img);
804 if(FAILED(hres)) {
805 ERR("IHTMLElement_QueryInterface failed: 0x%08x\n", hres);
806 return hres;
809 nsIDOMHTMLElement_Release(nselem);
811 l = var_to_size(&width);
812 if(l)
813 IHTMLImgElement_put_width(img, l);
814 l = var_to_size(&height);
815 if(l)
816 IHTMLImgElement_put_height(img, l);
818 *img_elem = img;
819 return S_OK;
822 static HRESULT HTMLImageElementFactory_value(IUnknown *iface, LCID lcid,
823 WORD flags, DISPPARAMS *params, VARIANT *res, EXCEPINFO *ei,
824 IServiceProvider *caller)
826 HTMLImageElementFactory *This = HTMLIMGFACTORY_THIS(iface);
827 IHTMLImgElement *img;
828 VARIANT empty, *width, *height;
829 HRESULT hres;
830 int argc = params->cArgs - params->cNamedArgs;
832 V_VT(res) = VT_NULL;
834 V_VT(&empty) = VT_EMPTY;
836 width = argc >= 1 ? params->rgvarg + (params->cArgs - 1) : &empty;
837 height = argc >= 2 ? params->rgvarg + (params->cArgs - 2) : &empty;
839 hres = IHTMLImageElementFactory_create(HTMLIMGFACTORY(This), *width, *height, &img);
840 if(FAILED(hres))
841 return hres;
843 V_VT(res) = VT_DISPATCH;
844 V_DISPATCH(res) = (IDispatch*)img;
846 return S_OK;
849 #undef HTMLIMGFACTORY_THIS
851 static const IHTMLImageElementFactoryVtbl HTMLImageElementFactoryVtbl = {
852 HTMLImageElementFactory_QueryInterface,
853 HTMLImageElementFactory_AddRef,
854 HTMLImageElementFactory_Release,
855 HTMLImageElementFactory_GetTypeInfoCount,
856 HTMLImageElementFactory_GetTypeInfo,
857 HTMLImageElementFactory_GetIDsOfNames,
858 HTMLImageElementFactory_Invoke,
859 HTMLImageElementFactory_create
862 static const tid_t HTMLImageElementFactory_iface_tids[] = {
863 IHTMLImageElementFactory_tid,
867 static const dispex_static_data_vtbl_t HTMLImageElementFactory_dispex_vtbl = {
868 HTMLImageElementFactory_value,
869 NULL,
870 NULL
873 static dispex_static_data_t HTMLImageElementFactory_dispex = {
874 &HTMLImageElementFactory_dispex_vtbl,
875 IHTMLImageElementFactory_tid,
876 NULL,
877 HTMLImageElementFactory_iface_tids
880 HTMLImageElementFactory *HTMLImageElementFactory_Create(HTMLWindow *window)
882 HTMLImageElementFactory *ret;
884 ret = heap_alloc(sizeof(HTMLImageElementFactory));
886 ret->lpHTMLImageElementFactoryVtbl = &HTMLImageElementFactoryVtbl;
887 ret->ref = 1;
888 ret->window = window;
890 init_dispex(&ret->dispex, (IUnknown*)HTMLIMGFACTORY(ret), &HTMLImageElementFactory_dispex);
892 return ret;