include: Define more wuapi interfaces to avoid undefined forward declarations.
[wine] / dlls / mshtml / htmlimg.c
1 /*
2  * Copyright 2008 Jacek Caban for CodeWeavers
3  *
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.
8  *
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.
13  *
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
17  */
18
19 #include <stdarg.h>
20
21 #define COBJMACROS
22
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winuser.h"
26 #include "ole2.h"
27
28 #include "wine/debug.h"
29
30 #include "mshtml_private.h"
31 #include "htmlevent.h"
32
33 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
34
35 typedef struct {
36     HTMLElement element;
37
38     IHTMLImgElement IHTMLImgElement_iface;
39
40     nsIDOMHTMLImageElement *nsimg;
41 } HTMLImgElement;
42
43 static inline HTMLImgElement *impl_from_IHTMLImgElement(IHTMLImgElement *iface)
44 {
45     return CONTAINING_RECORD(iface, HTMLImgElement, IHTMLImgElement_iface);
46 }
47
48 static HRESULT WINAPI HTMLImgElement_QueryInterface(IHTMLImgElement *iface, REFIID riid, void **ppv)
49 {
50     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
51
52     return IHTMLDOMNode_QueryInterface(HTMLDOMNODE(&This->element.node), riid, ppv);
53 }
54
55 static ULONG WINAPI HTMLImgElement_AddRef(IHTMLImgElement *iface)
56 {
57     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
58
59     return IHTMLDOMNode_AddRef(HTMLDOMNODE(&This->element.node));
60 }
61
62 static ULONG WINAPI HTMLImgElement_Release(IHTMLImgElement *iface)
63 {
64     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
65
66     return IHTMLDOMNode_Release(HTMLDOMNODE(&This->element.node));
67 }
68
69 static HRESULT WINAPI HTMLImgElement_GetTypeInfoCount(IHTMLImgElement *iface, UINT *pctinfo)
70 {
71     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
72     return IDispatchEx_GetTypeInfoCount(DISPATCHEX(&This->element.node.dispex), pctinfo);
73 }
74
75 static HRESULT WINAPI HTMLImgElement_GetTypeInfo(IHTMLImgElement *iface, UINT iTInfo,
76                                               LCID lcid, ITypeInfo **ppTInfo)
77 {
78     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
79     return IDispatchEx_GetTypeInfo(DISPATCHEX(&This->element.node.dispex), iTInfo, lcid, ppTInfo);
80 }
81
82 static HRESULT WINAPI HTMLImgElement_GetIDsOfNames(IHTMLImgElement *iface, REFIID riid,
83                                                 LPOLESTR *rgszNames, UINT cNames,
84                                                 LCID lcid, DISPID *rgDispId)
85 {
86     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
87     return IDispatchEx_GetIDsOfNames(DISPATCHEX(&This->element.node.dispex), riid, rgszNames, cNames, lcid, rgDispId);
88 }
89
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)
93 {
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);
97 }
98
99 static HRESULT WINAPI HTMLImgElement_put_isMap(IHTMLImgElement *iface, VARIANT_BOOL v)
100 {
101     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
102     FIXME("(%p)->(%x)\n", This, v);
103     return E_NOTIMPL;
104 }
105
106 static HRESULT WINAPI HTMLImgElement_get_isMap(IHTMLImgElement *iface, VARIANT_BOOL *p)
107 {
108     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
109     FIXME("(%p)->(%p)\n", This, p);
110     return E_NOTIMPL;
111 }
112
113 static HRESULT WINAPI HTMLImgElement_put_useMap(IHTMLImgElement *iface, BSTR v)
114 {
115     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
116     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
117     return E_NOTIMPL;
118 }
119
120 static HRESULT WINAPI HTMLImgElement_get_useMap(IHTMLImgElement *iface, BSTR *p)
121 {
122     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
123     FIXME("(%p)->(%p)\n", This, p);
124     return E_NOTIMPL;
125 }
126
127 static HRESULT WINAPI HTMLImgElement_get_mimeType(IHTMLImgElement *iface, BSTR *p)
128 {
129     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
130     FIXME("(%p)->(%p)\n", This, p);
131     return E_NOTIMPL;
132 }
133
134 static HRESULT WINAPI HTMLImgElement_get_fileSize(IHTMLImgElement *iface, BSTR *p)
135 {
136     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
137     FIXME("(%p)->(%p)\n", This, p);
138     return E_NOTIMPL;
139 }
140
141 static HRESULT WINAPI HTMLImgElement_get_fileCreatedDate(IHTMLImgElement *iface, BSTR *p)
142 {
143     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
144     FIXME("(%p)->(%p)\n", This, p);
145     return E_NOTIMPL;
146 }
147
148 static HRESULT WINAPI HTMLImgElement_get_fileModifiedDate(IHTMLImgElement *iface, BSTR *p)
149 {
150     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
151     FIXME("(%p)->(%p)\n", This, p);
152     return E_NOTIMPL;
153 }
154
155 static HRESULT WINAPI HTMLImgElement_get_fileUpdatedDate(IHTMLImgElement *iface, BSTR *p)
156 {
157     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
158     FIXME("(%p)->(%p)\n", This, p);
159     return E_NOTIMPL;
160 }
161
162 static HRESULT WINAPI HTMLImgElement_get_protocol(IHTMLImgElement *iface, BSTR *p)
163 {
164     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
165     FIXME("(%p)->(%p)\n", This, p);
166     return E_NOTIMPL;
167 }
168
169 static HRESULT WINAPI HTMLImgElement_get_href(IHTMLImgElement *iface, BSTR *p)
170 {
171     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
172     FIXME("(%p)->(%p)\n", This, p);
173     return E_NOTIMPL;
174 }
175
176 static HRESULT WINAPI HTMLImgElement_get_nameProp(IHTMLImgElement *iface, BSTR *p)
177 {
178     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
179     FIXME("(%p)->(%p)\n", This, p);
180     return E_NOTIMPL;
181 }
182
183 static HRESULT WINAPI HTMLImgElement_put_border(IHTMLImgElement *iface, VARIANT v)
184 {
185     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
186     FIXME("(%p)->()\n", This);
187     return E_NOTIMPL;
188 }
189
190 static HRESULT WINAPI HTMLImgElement_get_border(IHTMLImgElement *iface, VARIANT *p)
191 {
192     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
193     FIXME("(%p)->(%p)\n", This, p);
194     return E_NOTIMPL;
195 }
196
197 static HRESULT WINAPI HTMLImgElement_put_vspace(IHTMLImgElement *iface, LONG v)
198 {
199     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
200     FIXME("(%p)->(%d)\n", This, v);
201     return E_NOTIMPL;
202 }
203
204 static HRESULT WINAPI HTMLImgElement_get_vspace(IHTMLImgElement *iface, LONG *p)
205 {
206     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
207     FIXME("(%p)->(%p)\n", This, p);
208     return E_NOTIMPL;
209 }
210
211 static HRESULT WINAPI HTMLImgElement_put_hspace(IHTMLImgElement *iface, LONG v)
212 {
213     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
214     FIXME("(%p)->(%d)\n", This, v);
215     return E_NOTIMPL;
216 }
217
218 static HRESULT WINAPI HTMLImgElement_get_hspace(IHTMLImgElement *iface, LONG *p)
219 {
220     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
221     FIXME("(%p)->(%p)\n", This, p);
222     return E_NOTIMPL;
223 }
224
225 static HRESULT WINAPI HTMLImgElement_put_alt(IHTMLImgElement *iface, BSTR v)
226 {
227     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
228     nsAString alt_str;
229     nsresult nsres;
230
231     TRACE("(%p)->(%s)\n", This, debugstr_w(v));
232
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);
238
239     return S_OK;
240 }
241
242 static HRESULT WINAPI HTMLImgElement_get_alt(IHTMLImgElement *iface, BSTR *p)
243 {
244     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
245     nsAString alt_str;
246     nsresult nsres;
247
248     TRACE("(%p)->(%p)\n", This, p);
249
250     nsAString_Init(&alt_str, NULL);
251     nsres = nsIDOMHTMLImageElement_GetAlt(This->nsimg, &alt_str);
252     if(NS_SUCCEEDED(nsres)) {
253         const PRUnichar *alt;
254
255         nsAString_GetData(&alt_str, &alt);
256         *p = *alt ? SysAllocString(alt) : NULL;
257     }else {
258         ERR("GetAlt failed: %08x\n", nsres);
259     }
260     nsAString_Finish(&alt_str);
261
262     return NS_SUCCEEDED(nsres) ? S_OK : E_FAIL;
263 }
264
265 static HRESULT WINAPI HTMLImgElement_put_src(IHTMLImgElement *iface, BSTR v)
266 {
267     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
268     nsAString src_str;
269     nsresult nsres;
270
271     TRACE("(%p)->(%s)\n", This, debugstr_w(v));
272
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);
278
279     return NS_OK;
280 }
281
282 static HRESULT WINAPI HTMLImgElement_get_src(IHTMLImgElement *iface, BSTR *p)
283 {
284     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
285     const PRUnichar *src;
286     nsAString src_str;
287     nsresult nsres;
288     HRESULT hres;
289
290     TRACE("(%p)->(%p)\n", This, p);
291
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;
297     }
298
299     nsAString_GetData(&src_str, &src);
300     hres = nsuri_to_url(src, TRUE, p);
301     nsAString_Finish(&src_str);
302
303     return hres;
304 }
305
306 static HRESULT WINAPI HTMLImgElement_put_lowsrc(IHTMLImgElement *iface, BSTR v)
307 {
308     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
309     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
310     return E_NOTIMPL;
311 }
312
313 static HRESULT WINAPI HTMLImgElement_get_lowsrc(IHTMLImgElement *iface, BSTR *p)
314 {
315     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
316     FIXME("(%p)->(%p)\n", This, p);
317     return E_NOTIMPL;
318 }
319
320 static HRESULT WINAPI HTMLImgElement_put_vrml(IHTMLImgElement *iface, BSTR v)
321 {
322     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
323     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
324     return E_NOTIMPL;
325 }
326
327 static HRESULT WINAPI HTMLImgElement_get_vrml(IHTMLImgElement *iface, BSTR *p)
328 {
329     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
330     FIXME("(%p)->(%p)\n", This, p);
331     return E_NOTIMPL;
332 }
333
334 static HRESULT WINAPI HTMLImgElement_put_dynsrc(IHTMLImgElement *iface, BSTR v)
335 {
336     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
337     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
338     return E_NOTIMPL;
339 }
340
341 static HRESULT WINAPI HTMLImgElement_get_dynsrc(IHTMLImgElement *iface, BSTR *p)
342 {
343     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
344     FIXME("(%p)->(%p)\n", This, p);
345     return E_NOTIMPL;
346 }
347
348 static HRESULT WINAPI HTMLImgElement_get_readyState(IHTMLImgElement *iface, BSTR *p)
349 {
350     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
351     FIXME("(%p)->(%p)\n", This, p);
352     return E_NOTIMPL;
353 }
354
355 static HRESULT WINAPI HTMLImgElement_get_complete(IHTMLImgElement *iface, VARIANT_BOOL *p)
356 {
357     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
358     FIXME("(%p)->(%p)\n", This, p);
359     return E_NOTIMPL;
360 }
361
362 static HRESULT WINAPI HTMLImgElement_put_loop(IHTMLImgElement *iface, VARIANT v)
363 {
364     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
365     FIXME("(%p)->()\n", This);
366     return E_NOTIMPL;
367 }
368
369 static HRESULT WINAPI HTMLImgElement_get_loop(IHTMLImgElement *iface, VARIANT *p)
370 {
371     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
372     FIXME("(%p)->(%p)\n", This, p);
373     return E_NOTIMPL;
374 }
375
376 static HRESULT WINAPI HTMLImgElement_put_align(IHTMLImgElement *iface, BSTR v)
377 {
378     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
379     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
380     return E_NOTIMPL;
381 }
382
383 static HRESULT WINAPI HTMLImgElement_get_align(IHTMLImgElement *iface, BSTR *p)
384 {
385     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
386     FIXME("(%p)->(%p)\n", This, p);
387     return E_NOTIMPL;
388 }
389
390 static HRESULT WINAPI HTMLImgElement_put_onload(IHTMLImgElement *iface, VARIANT v)
391 {
392     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
393
394     TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
395
396     return set_node_event(&This->element.node, EVENTID_LOAD, &v);
397 }
398
399 static HRESULT WINAPI HTMLImgElement_get_onload(IHTMLImgElement *iface, VARIANT *p)
400 {
401     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
402
403     TRACE("(%p)->(%p)\n", This, p);
404
405     return get_node_event(&This->element.node, EVENTID_LOAD, p);
406 }
407
408 static HRESULT WINAPI HTMLImgElement_put_onerror(IHTMLImgElement *iface, VARIANT v)
409 {
410     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
411     FIXME("(%p)->()\n", This);
412     return E_NOTIMPL;
413 }
414
415 static HRESULT WINAPI HTMLImgElement_get_onerror(IHTMLImgElement *iface, VARIANT *p)
416 {
417     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
418     FIXME("(%p)->(%p)\n", This, p);
419     return E_NOTIMPL;
420 }
421
422 static HRESULT WINAPI HTMLImgElement_put_onabort(IHTMLImgElement *iface, VARIANT v)
423 {
424     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
425     FIXME("(%p)->()\n", This);
426     return E_NOTIMPL;
427 }
428
429 static HRESULT WINAPI HTMLImgElement_get_onabort(IHTMLImgElement *iface, VARIANT *p)
430 {
431     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
432     FIXME("(%p)->(%p)\n", This, p);
433     return E_NOTIMPL;
434 }
435
436 static HRESULT WINAPI HTMLImgElement_put_name(IHTMLImgElement *iface, BSTR v)
437 {
438     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
439     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
440     return E_NOTIMPL;
441 }
442
443 static HRESULT WINAPI HTMLImgElement_get_name(IHTMLImgElement *iface, BSTR *p)
444 {
445     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
446     nsAString strName;
447     nsresult nsres;
448
449     TRACE("(%p)->(%p)\n", This, p);
450
451     nsAString_Init(&strName, NULL);
452     nsres = nsIDOMHTMLImageElement_GetName(This->nsimg, &strName);
453     if(NS_SUCCEEDED(nsres)) {
454         const PRUnichar *str;
455
456         nsAString_GetData(&strName, &str);
457         *p = *str ? SysAllocString(str) : NULL;
458     }else {
459         ERR("GetName failed: %08x\n", nsres);
460     }
461     nsAString_Finish(&strName);
462
463     return NS_SUCCEEDED(nsres) ? S_OK : E_FAIL;
464 }
465
466 static HRESULT WINAPI HTMLImgElement_put_width(IHTMLImgElement *iface, LONG v)
467 {
468     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
469     nsresult nsres;
470
471     TRACE("(%p)->(%d)\n", This, v);
472
473     nsres = nsIDOMHTMLImageElement_SetWidth(This->nsimg, v);
474     if(NS_FAILED(nsres)) {
475         ERR("SetWidth failed: %08x\n", nsres);
476         return E_FAIL;
477     }
478
479     return S_OK;
480 }
481
482 static HRESULT WINAPI HTMLImgElement_get_width(IHTMLImgElement *iface, LONG *p)
483 {
484     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
485     PRInt32 width;
486     nsresult nsres;
487
488     TRACE("(%p)->(%p)\n", This, p);
489
490     nsres = nsIDOMHTMLImageElement_GetWidth(This->nsimg, &width);
491     if(NS_FAILED(nsres)) {
492         ERR("GetWidth failed: %08x\n", nsres);
493         return E_FAIL;
494     }
495
496     *p = width;
497     return S_OK;
498 }
499
500 static HRESULT WINAPI HTMLImgElement_put_height(IHTMLImgElement *iface, LONG v)
501 {
502     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
503     nsresult nsres;
504
505     TRACE("(%p)->(%d)\n", This, v);
506
507     nsres = nsIDOMHTMLImageElement_SetHeight(This->nsimg, v);
508     if(NS_FAILED(nsres)) {
509         ERR("SetHeight failed: %08x\n", nsres);
510         return E_FAIL;
511     }
512
513     return S_OK;
514 }
515
516 static HRESULT WINAPI HTMLImgElement_get_height(IHTMLImgElement *iface, LONG *p)
517 {
518     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
519     PRInt32 height;
520     nsresult nsres;
521
522     TRACE("(%p)->(%p)\n", This, p);
523
524     nsres = nsIDOMHTMLImageElement_GetHeight(This->nsimg, &height);
525     if(NS_FAILED(nsres)) {
526         ERR("GetHeight failed: %08x\n", nsres);
527         return E_FAIL;
528     }
529
530     *p = height;
531     return S_OK;
532 }
533
534 static HRESULT WINAPI HTMLImgElement_put_start(IHTMLImgElement *iface, BSTR v)
535 {
536     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
537     FIXME("(%p)->()\n", This);
538     return E_NOTIMPL;
539 }
540
541 static HRESULT WINAPI HTMLImgElement_get_start(IHTMLImgElement *iface, BSTR *p)
542 {
543     HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
544     FIXME("(%p)->(%p)\n", This, p);
545     return E_NOTIMPL;
546 }
547
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
604 };
605
606 #define HTMLIMG_NODE_THIS(iface) DEFINE_THIS2(HTMLImgElement, element.node, iface)
607
608 static HRESULT HTMLImgElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
609 {
610     HTMLImgElement *This = HTMLIMG_NODE_THIS(iface);
611
612     *ppv = NULL;
613
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);
619     }
620
621     IUnknown_AddRef((IUnknown*)*ppv);
622     return S_OK;
623 }
624
625 static void HTMLImgElement_destructor(HTMLDOMNode *iface)
626 {
627     HTMLImgElement *This = HTMLIMG_NODE_THIS(iface);
628
629     if(This->nsimg)
630         nsIDOMHTMLImageElement_Release(This->nsimg);
631
632     HTMLElement_destructor(&This->element.node);
633 }
634
635 static HRESULT HTMLImgElement_get_readystate(HTMLDOMNode *iface, BSTR *p)
636 {
637     HTMLImgElement *This = HTMLIMG_NODE_THIS(iface);
638
639     return IHTMLImgElement_get_readyState(&This->IHTMLImgElement_iface, p);
640 }
641
642 #undef HTMLIMG_NODE_THIS
643
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
654 };
655
656 static const tid_t HTMLImgElement_iface_tids[] = {
657     HTMLELEMENT_TIDS,
658     IHTMLImgElement_tid,
659     0
660 };
661 static dispex_static_data_t HTMLImgElement_dispex = {
662     NULL,
663     DispHTMLImg_tid,
664     NULL,
665     HTMLImgElement_iface_tids
666 };
667
668 HRESULT HTMLImgElement_Create(HTMLDocumentNode *doc, nsIDOMHTMLElement *nselem, HTMLElement **elem)
669 {
670     HTMLImgElement *ret;
671     nsresult nsres;
672
673     ret = heap_alloc_zero(sizeof(HTMLImgElement));
674     if(!ret)
675         return E_OUTOFMEMORY;
676
677     ret->IHTMLImgElement_iface.lpVtbl = &HTMLImgElementVtbl;
678     ret->element.node.vtbl = &HTMLImgElementImplVtbl;
679
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;
685     }
686
687     HTMLElement_Init(&ret->element, doc, nselem, &HTMLImgElement_dispex);
688
689     *elem = &ret->element;
690     return S_OK;
691 }
692
693 #define HTMLIMGFACTORY_THIS(iface) DEFINE_THIS(HTMLImageElementFactory, HTMLImageElementFactory, iface)
694
695 static HRESULT WINAPI HTMLImageElementFactory_QueryInterface(IHTMLImageElementFactory *iface,
696         REFIID riid, void **ppv)
697 {
698     HTMLImageElementFactory *This = HTMLIMGFACTORY_THIS(iface);
699
700     *ppv = NULL;
701
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;
710
711     if(*ppv) {
712         IUnknown_AddRef((IUnknown*)*ppv);
713         return S_OK;
714     }
715
716     WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
717     return E_NOINTERFACE;
718 }
719
720 static ULONG WINAPI HTMLImageElementFactory_AddRef(IHTMLImageElementFactory *iface)
721 {
722     HTMLImageElementFactory *This = HTMLIMGFACTORY_THIS(iface);
723     LONG ref = InterlockedIncrement(&This->ref);
724
725     TRACE("(%p) ref=%d\n", This, ref);
726
727     return ref;
728 }
729
730 static ULONG WINAPI HTMLImageElementFactory_Release(IHTMLImageElementFactory *iface)
731 {
732     HTMLImageElementFactory *This = HTMLIMGFACTORY_THIS(iface);
733     LONG ref = InterlockedDecrement(&This->ref);
734
735     TRACE("(%p) ref=%d\n", This, ref);
736
737     if(!ref)
738         heap_free(This);
739
740     return ref;
741 }
742
743 static HRESULT WINAPI HTMLImageElementFactory_GetTypeInfoCount(IHTMLImageElementFactory *iface,
744         UINT *pctinfo)
745 {
746     HTMLImageElementFactory *This = HTMLIMGFACTORY_THIS(iface);
747     FIXME("(%p)->(%p)\n", This, pctinfo);
748     return E_NOTIMPL;
749 }
750
751 static HRESULT WINAPI HTMLImageElementFactory_GetTypeInfo(IHTMLImageElementFactory *iface,
752         UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
753 {
754     HTMLImageElementFactory *This = HTMLIMGFACTORY_THIS(iface);
755     FIXME("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
756     return E_NOTIMPL;
757 }
758
759 static HRESULT WINAPI HTMLImageElementFactory_GetIDsOfNames(IHTMLImageElementFactory *iface,
760         REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid,
761         DISPID *rgDispId)
762 {
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;
767 }
768
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)
773 {
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;
778 }
779
780 static LONG var_to_size(const VARIANT *v)
781 {
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;
790
791         hres = VarI4FromStr(V_BSTR(v), 0, 0, &ret);
792         if(FAILED(hres)) {
793             FIXME("VarI4FromStr failed: %08x\n", hres);
794             return 0;
795         }
796         return ret;
797     }
798     default:
799         FIXME("unsupported size %s\n", debugstr_variant(v));
800     }
801     return 0;
802 }
803
804 static HRESULT WINAPI HTMLImageElementFactory_create(IHTMLImageElementFactory *iface,
805         VARIANT width, VARIANT height, IHTMLImgElement **img_elem)
806 {
807     HTMLImageElementFactory *This = HTMLIMGFACTORY_THIS(iface);
808     IHTMLImgElement *img;
809     HTMLElement *elem;
810     nsIDOMHTMLElement *nselem;
811     LONG l;
812     HRESULT hres;
813
814     static const PRUnichar imgW[] = {'I','M','G',0};
815
816     TRACE("(%p)->(%s %s %p)\n", This, debugstr_variant(&width),
817             debugstr_variant(&height), img_elem);
818
819     if(!This->window || !This->window->doc) {
820         WARN("NULL doc\n");
821         return E_UNEXPECTED;
822     }
823
824     *img_elem = NULL;
825
826     hres = create_nselem(This->window->doc, imgW, &nselem);
827     if(FAILED(hres))
828         return hres;
829
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;
835     }
836
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;
841     }
842
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);
849
850     *img_elem = img;
851     return S_OK;
852 }
853
854 static HRESULT HTMLImageElementFactory_value(IUnknown *iface, LCID lcid,
855         WORD flags, DISPPARAMS *params, VARIANT *res, EXCEPINFO *ei,
856         IServiceProvider *caller)
857 {
858     HTMLImageElementFactory *This = HTMLIMGFACTORY_THIS(iface);
859     IHTMLImgElement *img;
860     VARIANT empty, *width, *height;
861     HRESULT hres;
862     int argc = params->cArgs - params->cNamedArgs;
863
864     V_VT(res) = VT_NULL;
865
866     V_VT(&empty) = VT_EMPTY;
867
868     width = argc >= 1 ? params->rgvarg + (params->cArgs - 1) : &empty;
869     height = argc >= 2 ? params->rgvarg + (params->cArgs - 2) : &empty;
870
871     hres = IHTMLImageElementFactory_create(HTMLIMGFACTORY(This), *width, *height, &img);
872     if(FAILED(hres))
873         return hres;
874
875     V_VT(res) = VT_DISPATCH;
876     V_DISPATCH(res) = (IDispatch*)img;
877
878     return S_OK;
879 }
880
881 #undef HTMLIMGFACTORY_THIS
882
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
892 };
893
894 static const tid_t HTMLImageElementFactory_iface_tids[] = {
895     IHTMLImageElementFactory_tid,
896     0
897 };
898
899 static const dispex_static_data_vtbl_t HTMLImageElementFactory_dispex_vtbl = {
900     HTMLImageElementFactory_value,
901     NULL,
902     NULL
903 };
904
905 static dispex_static_data_t HTMLImageElementFactory_dispex = {
906     &HTMLImageElementFactory_dispex_vtbl,
907     IHTMLImageElementFactory_tid,
908     NULL,
909     HTMLImageElementFactory_iface_tids
910 };
911
912 HTMLImageElementFactory *HTMLImageElementFactory_Create(HTMLWindow *window)
913 {
914     HTMLImageElementFactory *ret;
915
916     ret = heap_alloc(sizeof(HTMLImageElementFactory));
917
918     ret->lpHTMLImageElementFactoryVtbl = &HTMLImageElementFactoryVtbl;
919     ret->ref = 1;
920     ret->window = window;
921
922     init_dispex(&ret->dispex, (IUnknown*)HTMLIMGFACTORY(ret), &HTMLImageElementFactory_dispex);
923
924     return ret;
925 }