17b6cceac958ff9cdc36cef08707064bca73c474
[reactos.git] / reactos / dll / win32 / 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
32 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
33
34 typedef struct {
35 HTMLElement element;
36
37 const IHTMLImgElementVtbl *lpHTMLImgElementVtbl;
38
39 nsIDOMHTMLImageElement *nsimg;
40 } HTMLImgElement;
41
42 #define HTMLIMG(x) ((IHTMLImgElement*) &(x)->lpHTMLImgElementVtbl)
43
44 #define HTMLIMG_THIS(iface) DEFINE_THIS(HTMLImgElement, HTMLImgElement, iface)
45
46 static HRESULT WINAPI HTMLImgElement_QueryInterface(IHTMLImgElement *iface, REFIID riid, void **ppv)
47 {
48 HTMLImgElement *This = HTMLIMG_THIS(iface);
49
50 return IHTMLDOMNode_QueryInterface(HTMLDOMNODE(&This->element.node), riid, ppv);
51 }
52
53 static ULONG WINAPI HTMLImgElement_AddRef(IHTMLImgElement *iface)
54 {
55 HTMLImgElement *This = HTMLIMG_THIS(iface);
56
57 return IHTMLDOMNode_AddRef(HTMLDOMNODE(&This->element.node));
58 }
59
60 static ULONG WINAPI HTMLImgElement_Release(IHTMLImgElement *iface)
61 {
62 HTMLImgElement *This = HTMLIMG_THIS(iface);
63
64 return IHTMLDOMNode_Release(HTMLDOMNODE(&This->element.node));
65 }
66
67 static HRESULT WINAPI HTMLImgElement_GetTypeInfoCount(IHTMLImgElement *iface, UINT *pctinfo)
68 {
69 HTMLImgElement *This = HTMLIMG_THIS(iface);
70 return IDispatchEx_GetTypeInfoCount(DISPATCHEX(&This->element.node.dispex), pctinfo);
71 }
72
73 static HRESULT WINAPI HTMLImgElement_GetTypeInfo(IHTMLImgElement *iface, UINT iTInfo,
74 LCID lcid, ITypeInfo **ppTInfo)
75 {
76 HTMLImgElement *This = HTMLIMG_THIS(iface);
77 return IDispatchEx_GetTypeInfo(DISPATCHEX(&This->element.node.dispex), iTInfo, lcid, ppTInfo);
78 }
79
80 static HRESULT WINAPI HTMLImgElement_GetIDsOfNames(IHTMLImgElement *iface, REFIID riid,
81 LPOLESTR *rgszNames, UINT cNames,
82 LCID lcid, DISPID *rgDispId)
83 {
84 HTMLImgElement *This = HTMLIMG_THIS(iface);
85 return IDispatchEx_GetIDsOfNames(DISPATCHEX(&This->element.node.dispex), riid, rgszNames, cNames, lcid, rgDispId);
86 }
87
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)
91 {
92 HTMLImgElement *This = HTMLIMG_THIS(iface);
93 return IDispatchEx_Invoke(DISPATCHEX(&This->element.node.dispex), dispIdMember, riid, lcid, wFlags, pDispParams,
94 pVarResult, pExcepInfo, puArgErr);
95 }
96
97 static HRESULT WINAPI HTMLImgElement_put_isMap(IHTMLImgElement *iface, VARIANT_BOOL v)
98 {
99 HTMLImgElement *This = HTMLIMG_THIS(iface);
100 FIXME("(%p)->(%x)\n", This, v);
101 return E_NOTIMPL;
102 }
103
104 static HRESULT WINAPI HTMLImgElement_get_isMap(IHTMLImgElement *iface, VARIANT_BOOL *p)
105 {
106 HTMLImgElement *This = HTMLIMG_THIS(iface);
107 FIXME("(%p)->(%p)\n", This, p);
108 return E_NOTIMPL;
109 }
110
111 static HRESULT WINAPI HTMLImgElement_put_useMap(IHTMLImgElement *iface, BSTR v)
112 {
113 HTMLImgElement *This = HTMLIMG_THIS(iface);
114 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
115 return E_NOTIMPL;
116 }
117
118 static HRESULT WINAPI HTMLImgElement_get_useMap(IHTMLImgElement *iface, BSTR *p)
119 {
120 HTMLImgElement *This = HTMLIMG_THIS(iface);
121 FIXME("(%p)->(%p)\n", This, p);
122 return E_NOTIMPL;
123 }
124
125 static HRESULT WINAPI HTMLImgElement_get_mimeType(IHTMLImgElement *iface, BSTR *p)
126 {
127 HTMLImgElement *This = HTMLIMG_THIS(iface);
128 FIXME("(%p)->(%p)\n", This, p);
129 return E_NOTIMPL;
130 }
131
132 static HRESULT WINAPI HTMLImgElement_get_fileSize(IHTMLImgElement *iface, BSTR *p)
133 {
134 HTMLImgElement *This = HTMLIMG_THIS(iface);
135 FIXME("(%p)->(%p)\n", This, p);
136 return E_NOTIMPL;
137 }
138
139 static HRESULT WINAPI HTMLImgElement_get_fileCreatedDate(IHTMLImgElement *iface, BSTR *p)
140 {
141 HTMLImgElement *This = HTMLIMG_THIS(iface);
142 FIXME("(%p)->(%p)\n", This, p);
143 return E_NOTIMPL;
144 }
145
146 static HRESULT WINAPI HTMLImgElement_get_fileModifiedDate(IHTMLImgElement *iface, BSTR *p)
147 {
148 HTMLImgElement *This = HTMLIMG_THIS(iface);
149 FIXME("(%p)->(%p)\n", This, p);
150 return E_NOTIMPL;
151 }
152
153 static HRESULT WINAPI HTMLImgElement_get_fileUpdatedDate(IHTMLImgElement *iface, BSTR *p)
154 {
155 HTMLImgElement *This = HTMLIMG_THIS(iface);
156 FIXME("(%p)->(%p)\n", This, p);
157 return E_NOTIMPL;
158 }
159
160 static HRESULT WINAPI HTMLImgElement_get_protocol(IHTMLImgElement *iface, BSTR *p)
161 {
162 HTMLImgElement *This = HTMLIMG_THIS(iface);
163 FIXME("(%p)->(%p)\n", This, p);
164 return E_NOTIMPL;
165 }
166
167 static HRESULT WINAPI HTMLImgElement_get_href(IHTMLImgElement *iface, BSTR *p)
168 {
169 HTMLImgElement *This = HTMLIMG_THIS(iface);
170 FIXME("(%p)->(%p)\n", This, p);
171 return E_NOTIMPL;
172 }
173
174 static HRESULT WINAPI HTMLImgElement_get_nameProp(IHTMLImgElement *iface, BSTR *p)
175 {
176 HTMLImgElement *This = HTMLIMG_THIS(iface);
177 FIXME("(%p)->(%p)\n", This, p);
178 return E_NOTIMPL;
179 }
180
181 static HRESULT WINAPI HTMLImgElement_put_border(IHTMLImgElement *iface, VARIANT v)
182 {
183 HTMLImgElement *This = HTMLIMG_THIS(iface);
184 FIXME("(%p)->()\n", This);
185 return E_NOTIMPL;
186 }
187
188 static HRESULT WINAPI HTMLImgElement_get_border(IHTMLImgElement *iface, VARIANT *p)
189 {
190 HTMLImgElement *This = HTMLIMG_THIS(iface);
191 FIXME("(%p)->(%p)\n", This, p);
192 return E_NOTIMPL;
193 }
194
195 static HRESULT WINAPI HTMLImgElement_put_vspace(IHTMLImgElement *iface, LONG v)
196 {
197 HTMLImgElement *This = HTMLIMG_THIS(iface);
198 FIXME("(%p)->(%d)\n", This, v);
199 return E_NOTIMPL;
200 }
201
202 static HRESULT WINAPI HTMLImgElement_get_vspace(IHTMLImgElement *iface, LONG *p)
203 {
204 HTMLImgElement *This = HTMLIMG_THIS(iface);
205 FIXME("(%p)->(%p)\n", This, p);
206 return E_NOTIMPL;
207 }
208
209 static HRESULT WINAPI HTMLImgElement_put_hspace(IHTMLImgElement *iface, LONG v)
210 {
211 HTMLImgElement *This = HTMLIMG_THIS(iface);
212 FIXME("(%p)->(%d)\n", This, v);
213 return E_NOTIMPL;
214 }
215
216 static HRESULT WINAPI HTMLImgElement_get_hspace(IHTMLImgElement *iface, LONG *p)
217 {
218 HTMLImgElement *This = HTMLIMG_THIS(iface);
219 FIXME("(%p)->(%p)\n", This, p);
220 return E_NOTIMPL;
221 }
222
223 static HRESULT WINAPI HTMLImgElement_put_alt(IHTMLImgElement *iface, BSTR v)
224 {
225 HTMLImgElement *This = HTMLIMG_THIS(iface);
226 nsAString alt_str;
227 nsresult nsres;
228
229 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
230
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);
236
237 return S_OK;
238 }
239
240 static HRESULT WINAPI HTMLImgElement_get_alt(IHTMLImgElement *iface, BSTR *p)
241 {
242 HTMLImgElement *This = HTMLIMG_THIS(iface);
243 nsAString alt_str;
244 nsresult nsres;
245
246 TRACE("(%p)->(%p)\n", This, p);
247
248 nsAString_Init(&alt_str, NULL);
249 nsres = nsIDOMHTMLImageElement_GetAlt(This->nsimg, &alt_str);
250 if(NS_SUCCEEDED(nsres)) {
251 const PRUnichar *alt;
252
253 nsAString_GetData(&alt_str, &alt);
254 *p = *alt ? SysAllocString(alt) : NULL;
255 }else {
256 ERR("GetAlt failed: %08x\n", nsres);
257 }
258 nsAString_Finish(&alt_str);
259
260 return NS_SUCCEEDED(nsres) ? S_OK : E_FAIL;
261 }
262
263 static HRESULT WINAPI HTMLImgElement_put_src(IHTMLImgElement *iface, BSTR v)
264 {
265 HTMLImgElement *This = HTMLIMG_THIS(iface);
266 nsAString src_str;
267 nsresult nsres;
268
269 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
270
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);
276
277 return NS_OK;
278 }
279
280 static HRESULT WINAPI HTMLImgElement_get_src(IHTMLImgElement *iface, BSTR *p)
281 {
282 HTMLImgElement *This = HTMLIMG_THIS(iface);
283 const PRUnichar *src;
284 nsAString src_str;
285 nsresult nsres;
286 HRESULT hres;
287
288 TRACE("(%p)->(%p)\n", This, p);
289
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;
295 }
296
297 nsAString_GetData(&src_str, &src);
298 hres = nsuri_to_url(src, TRUE, p);
299 nsAString_Finish(&src_str);
300
301 return hres;
302 }
303
304 static HRESULT WINAPI HTMLImgElement_put_lowsrc(IHTMLImgElement *iface, BSTR v)
305 {
306 HTMLImgElement *This = HTMLIMG_THIS(iface);
307 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
308 return E_NOTIMPL;
309 }
310
311 static HRESULT WINAPI HTMLImgElement_get_lowsrc(IHTMLImgElement *iface, BSTR *p)
312 {
313 HTMLImgElement *This = HTMLIMG_THIS(iface);
314 FIXME("(%p)->(%p)\n", This, p);
315 return E_NOTIMPL;
316 }
317
318 static HRESULT WINAPI HTMLImgElement_put_vrml(IHTMLImgElement *iface, BSTR v)
319 {
320 HTMLImgElement *This = HTMLIMG_THIS(iface);
321 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
322 return E_NOTIMPL;
323 }
324
325 static HRESULT WINAPI HTMLImgElement_get_vrml(IHTMLImgElement *iface, BSTR *p)
326 {
327 HTMLImgElement *This = HTMLIMG_THIS(iface);
328 FIXME("(%p)->(%p)\n", This, p);
329 return E_NOTIMPL;
330 }
331
332 static HRESULT WINAPI HTMLImgElement_put_dynsrc(IHTMLImgElement *iface, BSTR v)
333 {
334 HTMLImgElement *This = HTMLIMG_THIS(iface);
335 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
336 return E_NOTIMPL;
337 }
338
339 static HRESULT WINAPI HTMLImgElement_get_dynsrc(IHTMLImgElement *iface, BSTR *p)
340 {
341 HTMLImgElement *This = HTMLIMG_THIS(iface);
342 FIXME("(%p)->(%p)\n", This, p);
343 return E_NOTIMPL;
344 }
345
346 static HRESULT WINAPI HTMLImgElement_get_readyState(IHTMLImgElement *iface, BSTR *p)
347 {
348 HTMLImgElement *This = HTMLIMG_THIS(iface);
349 FIXME("(%p)->(%p)\n", This, p);
350 return E_NOTIMPL;
351 }
352
353 static HRESULT WINAPI HTMLImgElement_get_complete(IHTMLImgElement *iface, VARIANT_BOOL *p)
354 {
355 HTMLImgElement *This = HTMLIMG_THIS(iface);
356 FIXME("(%p)->(%p)\n", This, p);
357 return E_NOTIMPL;
358 }
359
360 static HRESULT WINAPI HTMLImgElement_put_loop(IHTMLImgElement *iface, VARIANT v)
361 {
362 HTMLImgElement *This = HTMLIMG_THIS(iface);
363 FIXME("(%p)->()\n", This);
364 return E_NOTIMPL;
365 }
366
367 static HRESULT WINAPI HTMLImgElement_get_loop(IHTMLImgElement *iface, VARIANT *p)
368 {
369 HTMLImgElement *This = HTMLIMG_THIS(iface);
370 FIXME("(%p)->(%p)\n", This, p);
371 return E_NOTIMPL;
372 }
373
374 static HRESULT WINAPI HTMLImgElement_put_align(IHTMLImgElement *iface, BSTR v)
375 {
376 HTMLImgElement *This = HTMLIMG_THIS(iface);
377 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
378 return E_NOTIMPL;
379 }
380
381 static HRESULT WINAPI HTMLImgElement_get_align(IHTMLImgElement *iface, BSTR *p)
382 {
383 HTMLImgElement *This = HTMLIMG_THIS(iface);
384 FIXME("(%p)->(%p)\n", This, p);
385 return E_NOTIMPL;
386 }
387
388 static HRESULT WINAPI HTMLImgElement_put_onload(IHTMLImgElement *iface, VARIANT v)
389 {
390 HTMLImgElement *This = HTMLIMG_THIS(iface);
391 FIXME("(%p)->()\n", This);
392 return E_NOTIMPL;
393 }
394
395 static HRESULT WINAPI HTMLImgElement_get_onload(IHTMLImgElement *iface, VARIANT *p)
396 {
397 HTMLImgElement *This = HTMLIMG_THIS(iface);
398 FIXME("(%p)->(%p)\n", This, p);
399 return E_NOTIMPL;
400 }
401
402 static HRESULT WINAPI HTMLImgElement_put_onerror(IHTMLImgElement *iface, VARIANT v)
403 {
404 HTMLImgElement *This = HTMLIMG_THIS(iface);
405 FIXME("(%p)->()\n", This);
406 return E_NOTIMPL;
407 }
408
409 static HRESULT WINAPI HTMLImgElement_get_onerror(IHTMLImgElement *iface, VARIANT *p)
410 {
411 HTMLImgElement *This = HTMLIMG_THIS(iface);
412 FIXME("(%p)->(%p)\n", This, p);
413 return E_NOTIMPL;
414 }
415
416 static HRESULT WINAPI HTMLImgElement_put_onabort(IHTMLImgElement *iface, VARIANT v)
417 {
418 HTMLImgElement *This = HTMLIMG_THIS(iface);
419 FIXME("(%p)->()\n", This);
420 return E_NOTIMPL;
421 }
422
423 static HRESULT WINAPI HTMLImgElement_get_onabort(IHTMLImgElement *iface, VARIANT *p)
424 {
425 HTMLImgElement *This = HTMLIMG_THIS(iface);
426 FIXME("(%p)->(%p)\n", This, p);
427 return E_NOTIMPL;
428 }
429
430 static HRESULT WINAPI HTMLImgElement_put_name(IHTMLImgElement *iface, BSTR v)
431 {
432 HTMLImgElement *This = HTMLIMG_THIS(iface);
433 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
434 return E_NOTIMPL;
435 }
436
437 static HRESULT WINAPI HTMLImgElement_get_name(IHTMLImgElement *iface, BSTR *p)
438 {
439 HTMLImgElement *This = HTMLIMG_THIS(iface);
440 nsAString strName;
441 nsresult nsres;
442
443 TRACE("(%p)->(%p)\n", This, p);
444
445 nsAString_Init(&strName, NULL);
446 nsres = nsIDOMHTMLImageElement_GetName(This->nsimg, &strName);
447 if(NS_SUCCEEDED(nsres)) {
448 const PRUnichar *str;
449
450 nsAString_GetData(&strName, &str);
451 *p = *str ? SysAllocString(str) : NULL;
452 }else {
453 ERR("GetName failed: %08x\n", nsres);
454 }
455 nsAString_Finish(&strName);
456
457 return NS_SUCCEEDED(nsres) ? S_OK : E_FAIL;
458 }
459
460 static HRESULT WINAPI HTMLImgElement_put_width(IHTMLImgElement *iface, LONG v)
461 {
462 HTMLImgElement *This = HTMLIMG_THIS(iface);
463 nsresult nsres;
464
465 TRACE("(%p)->(%d)\n", This, v);
466
467 nsres = nsIDOMHTMLImageElement_SetWidth(This->nsimg, v);
468 if(NS_FAILED(nsres)) {
469 ERR("SetWidth failed: %08x\n", nsres);
470 return E_FAIL;
471 }
472
473 return S_OK;
474 }
475
476 static HRESULT WINAPI HTMLImgElement_get_width(IHTMLImgElement *iface, LONG *p)
477 {
478 HTMLImgElement *This = HTMLIMG_THIS(iface);
479 PRInt32 width;
480 nsresult nsres;
481
482 TRACE("(%p)->(%p)\n", This, p);
483
484 nsres = nsIDOMHTMLImageElement_GetWidth(This->nsimg, &width);
485 if(NS_FAILED(nsres)) {
486 ERR("GetWidth failed: %08x\n", nsres);
487 return E_FAIL;
488 }
489
490 *p = width;
491 return S_OK;
492 }
493
494 static HRESULT WINAPI HTMLImgElement_put_height(IHTMLImgElement *iface, LONG v)
495 {
496 HTMLImgElement *This = HTMLIMG_THIS(iface);
497 nsresult nsres;
498
499 TRACE("(%p)->(%d)\n", This, v);
500
501 nsres = nsIDOMHTMLImageElement_SetHeight(This->nsimg, v);
502 if(NS_FAILED(nsres)) {
503 ERR("SetHeight failed: %08x\n", nsres);
504 return E_FAIL;
505 }
506
507 return S_OK;
508 }
509
510 static HRESULT WINAPI HTMLImgElement_get_height(IHTMLImgElement *iface, LONG *p)
511 {
512 HTMLImgElement *This = HTMLIMG_THIS(iface);
513 PRInt32 height;
514 nsresult nsres;
515
516 TRACE("(%p)->(%p)\n", This, p);
517
518 nsres = nsIDOMHTMLImageElement_GetHeight(This->nsimg, &height);
519 if(NS_FAILED(nsres)) {
520 ERR("GetHeight failed: %08x\n", nsres);
521 return E_FAIL;
522 }
523
524 *p = height;
525 return S_OK;
526 }
527
528 static HRESULT WINAPI HTMLImgElement_put_start(IHTMLImgElement *iface, BSTR v)
529 {
530 HTMLImgElement *This = HTMLIMG_THIS(iface);
531 FIXME("(%p)->()\n", This);
532 return E_NOTIMPL;
533 }
534
535 static HRESULT WINAPI HTMLImgElement_get_start(IHTMLImgElement *iface, BSTR *p)
536 {
537 HTMLImgElement *This = HTMLIMG_THIS(iface);
538 FIXME("(%p)->(%p)\n", This, p);
539 return E_NOTIMPL;
540 }
541
542 #undef HTMLIMG_THIS
543
544 static const IHTMLImgElementVtbl HTMLImgElementVtbl = {
545 HTMLImgElement_QueryInterface,
546 HTMLImgElement_AddRef,
547 HTMLImgElement_Release,
548 HTMLImgElement_GetTypeInfoCount,
549 HTMLImgElement_GetTypeInfo,
550 HTMLImgElement_GetIDsOfNames,
551 HTMLImgElement_Invoke,
552 HTMLImgElement_put_isMap,
553 HTMLImgElement_get_isMap,
554 HTMLImgElement_put_useMap,
555 HTMLImgElement_get_useMap,
556 HTMLImgElement_get_mimeType,
557 HTMLImgElement_get_fileSize,
558 HTMLImgElement_get_fileCreatedDate,
559 HTMLImgElement_get_fileModifiedDate,
560 HTMLImgElement_get_fileUpdatedDate,
561 HTMLImgElement_get_protocol,
562 HTMLImgElement_get_href,
563 HTMLImgElement_get_nameProp,
564 HTMLImgElement_put_border,
565 HTMLImgElement_get_border,
566 HTMLImgElement_put_vspace,
567 HTMLImgElement_get_vspace,
568 HTMLImgElement_put_hspace,
569 HTMLImgElement_get_hspace,
570 HTMLImgElement_put_alt,
571 HTMLImgElement_get_alt,
572 HTMLImgElement_put_src,
573 HTMLImgElement_get_src,
574 HTMLImgElement_put_lowsrc,
575 HTMLImgElement_get_lowsrc,
576 HTMLImgElement_put_vrml,
577 HTMLImgElement_get_vrml,
578 HTMLImgElement_put_dynsrc,
579 HTMLImgElement_get_dynsrc,
580 HTMLImgElement_get_readyState,
581 HTMLImgElement_get_complete,
582 HTMLImgElement_put_loop,
583 HTMLImgElement_get_loop,
584 HTMLImgElement_put_align,
585 HTMLImgElement_get_align,
586 HTMLImgElement_put_onload,
587 HTMLImgElement_get_onload,
588 HTMLImgElement_put_onerror,
589 HTMLImgElement_get_onerror,
590 HTMLImgElement_put_onabort,
591 HTMLImgElement_get_onabort,
592 HTMLImgElement_put_name,
593 HTMLImgElement_get_name,
594 HTMLImgElement_put_width,
595 HTMLImgElement_get_width,
596 HTMLImgElement_put_height,
597 HTMLImgElement_get_height,
598 HTMLImgElement_put_start,
599 HTMLImgElement_get_start
600 };
601
602 #define HTMLIMG_NODE_THIS(iface) DEFINE_THIS2(HTMLImgElement, element.node, iface)
603
604 static HRESULT HTMLImgElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
605 {
606 HTMLImgElement *This = HTMLIMG_NODE_THIS(iface);
607
608 *ppv = NULL;
609
610 if(IsEqualGUID(&IID_IHTMLImgElement, riid)) {
611 TRACE("(%p)->(IID_IHTMLImgElement %p)\n", This, ppv);
612 *ppv = HTMLIMG(This);
613 }else {
614 return HTMLElement_QI(&This->element.node, riid, ppv);
615 }
616
617 IUnknown_AddRef((IUnknown*)*ppv);
618 return S_OK;
619 }
620
621 static void HTMLImgElement_destructor(HTMLDOMNode *iface)
622 {
623 HTMLImgElement *This = HTMLIMG_NODE_THIS(iface);
624
625 if(This->nsimg)
626 nsIDOMHTMLImageElement_Release(This->nsimg);
627
628 HTMLElement_destructor(&This->element.node);
629 }
630
631 static HRESULT HTMLImgElement_get_readystate(HTMLDOMNode *iface, BSTR *p)
632 {
633 HTMLImgElement *This = HTMLIMG_NODE_THIS(iface);
634
635 return IHTMLImgElement_get_readyState(HTMLIMG(This), p);
636 }
637
638 #undef HTMLIMG_NODE_THIS
639
640 static const NodeImplVtbl HTMLImgElementImplVtbl = {
641 HTMLImgElement_QI,
642 HTMLImgElement_destructor,
643 NULL,
644 NULL,
645 NULL,
646 NULL,
647 NULL,
648 HTMLImgElement_get_readystate
649 };
650
651 static const tid_t HTMLImgElement_iface_tids[] = {
652 HTMLELEMENT_TIDS,
653 IHTMLImgElement_tid,
654 0
655 };
656 static dispex_static_data_t HTMLImgElement_dispex = {
657 NULL,
658 DispHTMLImg_tid,
659 NULL,
660 HTMLImgElement_iface_tids
661 };
662
663 HTMLElement *HTMLImgElement_Create(HTMLDocumentNode *doc, nsIDOMHTMLElement *nselem)
664 {
665 HTMLImgElement *ret = heap_alloc_zero(sizeof(HTMLImgElement));
666 nsresult nsres;
667
668 ret->lpHTMLImgElementVtbl = &HTMLImgElementVtbl;
669 ret->element.node.vtbl = &HTMLImgElementImplVtbl;
670
671 nsres = nsIDOMHTMLElement_QueryInterface(nselem, &IID_nsIDOMHTMLImageElement, (void**)&ret->nsimg);
672 if(NS_FAILED(nsres))
673 ERR("Could not get nsIDOMHTMLImageElement: %08x\n", nsres);
674
675 HTMLElement_Init(&ret->element, doc, nselem, &HTMLImgElement_dispex);
676
677 return &ret->element;
678 }
679
680 #define HTMLIMGFACTORY_THIS(iface) DEFINE_THIS(HTMLImageElementFactory, HTMLImageElementFactory, iface)
681
682 static HRESULT WINAPI HTMLImageElementFactory_QueryInterface(IHTMLImageElementFactory *iface,
683 REFIID riid, void **ppv)
684 {
685 HTMLImageElementFactory *This = HTMLIMGFACTORY_THIS(iface);
686
687 *ppv = NULL;
688
689 if(IsEqualGUID(&IID_IUnknown, riid)) {
690 TRACE("(%p)->(IID_Unknown %p)\n", This, ppv);
691 *ppv = HTMLIMGFACTORY(This);
692 }else if(IsEqualGUID(&IID_IHTMLImageElementFactory, riid)) {
693 TRACE("(%p)->(IID_IHTMLImageElementFactory %p)\n", This, ppv);
694 *ppv = HTMLIMGFACTORY(This);
695 }else if(dispex_query_interface(&This->dispex, riid, ppv))
696 return *ppv ? S_OK : E_NOINTERFACE;
697
698 if(*ppv) {
699 IUnknown_AddRef((IUnknown*)*ppv);
700 return S_OK;
701 }
702
703 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
704 return E_NOINTERFACE;
705 }
706
707 static ULONG WINAPI HTMLImageElementFactory_AddRef(IHTMLImageElementFactory *iface)
708 {
709 HTMLImageElementFactory *This = HTMLIMGFACTORY_THIS(iface);
710 LONG ref = InterlockedIncrement(&This->ref);
711
712 TRACE("(%p) ref=%d\n", This, ref);
713
714 return ref;
715 }
716
717 static ULONG WINAPI HTMLImageElementFactory_Release(IHTMLImageElementFactory *iface)
718 {
719 HTMLImageElementFactory *This = HTMLIMGFACTORY_THIS(iface);
720 LONG ref = InterlockedDecrement(&This->ref);
721
722 TRACE("(%p) ref=%d\n", This, ref);
723
724 if(!ref)
725 heap_free(This);
726
727 return ref;
728 }
729
730 static HRESULT WINAPI HTMLImageElementFactory_GetTypeInfoCount(IHTMLImageElementFactory *iface,
731 UINT *pctinfo)
732 {
733 HTMLImageElementFactory *This = HTMLIMGFACTORY_THIS(iface);
734 FIXME("(%p)->(%p)\n", This, pctinfo);
735 return E_NOTIMPL;
736 }
737
738 static HRESULT WINAPI HTMLImageElementFactory_GetTypeInfo(IHTMLImageElementFactory *iface,
739 UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
740 {
741 HTMLImageElementFactory *This = HTMLIMGFACTORY_THIS(iface);
742 FIXME("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
743 return E_NOTIMPL;
744 }
745
746 static HRESULT WINAPI HTMLImageElementFactory_GetIDsOfNames(IHTMLImageElementFactory *iface,
747 REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid,
748 DISPID *rgDispId)
749 {
750 HTMLImageElementFactory *This = HTMLIMGFACTORY_THIS(iface);
751 FIXME("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames,
752 cNames, lcid, rgDispId);
753 return E_NOTIMPL;
754 }
755
756 static HRESULT WINAPI HTMLImageElementFactory_Invoke(IHTMLImageElementFactory *iface,
757 DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags,
758 DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo,
759 UINT *puArgErr)
760 {
761 HTMLImageElementFactory *This = HTMLIMGFACTORY_THIS(iface);
762 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
763 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
764 return E_NOTIMPL;
765 }
766
767 static LONG var_to_size(const VARIANT *v)
768 {
769 switch(V_VT(v)) {
770 case VT_EMPTY:
771 return 0;
772 case VT_I4:
773 return V_I4(v);
774 case VT_BSTR: {
775 LONG ret;
776 HRESULT hres;
777
778 hres = VarI4FromStr(V_BSTR(v), 0, 0, &ret);
779 if(FAILED(hres)) {
780 FIXME("VarI4FromStr failed: %08x\n", hres);
781 return 0;
782 }
783 return ret;
784 }
785 default:
786 FIXME("unsupported size %s\n", debugstr_variant(v));
787 }
788 return 0;
789 }
790
791 static HRESULT WINAPI HTMLImageElementFactory_create(IHTMLImageElementFactory *iface,
792 VARIANT width, VARIANT height, IHTMLImgElement **img_elem)
793 {
794 HTMLImageElementFactory *This = HTMLIMGFACTORY_THIS(iface);
795 IHTMLImgElement *img;
796 HTMLElement *elem;
797 nsIDOMHTMLElement *nselem;
798 LONG l;
799 HRESULT hres;
800
801 static const PRUnichar imgW[] = {'I','M','G',0};
802
803 TRACE("(%p)->(%s %s %p)\n", This, debugstr_variant(&width),
804 debugstr_variant(&height), img_elem);
805
806 if(!This->window || !This->window->doc) {
807 WARN("NULL doc\n");
808 return E_UNEXPECTED;
809 }
810
811 *img_elem = NULL;
812
813 hres = create_nselem(This->window->doc, imgW, &nselem);
814 if(FAILED(hres))
815 return hres;
816
817 elem = HTMLElement_Create(This->window->doc, (nsIDOMNode*)nselem, FALSE);
818 if(!elem) {
819 ERR("HTMLElement_Create failed\n");
820 return E_FAIL;
821 }
822
823 hres = IHTMLElement_QueryInterface(HTMLELEM(elem), &IID_IHTMLImgElement, (void**)&img);
824 if(FAILED(hres)) {
825 ERR("IHTMLElement_QueryInterface failed: 0x%08x\n", hres);
826 return hres;
827 }
828
829 nsIDOMHTMLElement_Release(nselem);
830
831 l = var_to_size(&width);
832 if(l)
833 IHTMLImgElement_put_width(img, l);
834 l = var_to_size(&height);
835 if(l)
836 IHTMLImgElement_put_height(img, l);
837
838 *img_elem = img;
839 return S_OK;
840 }
841
842 static HRESULT HTMLImageElementFactory_value(IUnknown *iface, LCID lcid,
843 WORD flags, DISPPARAMS *params, VARIANT *res, EXCEPINFO *ei,
844 IServiceProvider *caller)
845 {
846 HTMLImageElementFactory *This = HTMLIMGFACTORY_THIS(iface);
847 IHTMLImgElement *img;
848 VARIANT empty, *width, *height;
849 HRESULT hres;
850 int argc = params->cArgs - params->cNamedArgs;
851
852 V_VT(res) = VT_NULL;
853
854 V_VT(&empty) = VT_EMPTY;
855
856 width = argc >= 1 ? params->rgvarg + (params->cArgs - 1) : &empty;
857 height = argc >= 2 ? params->rgvarg + (params->cArgs - 2) : &empty;
858
859 hres = IHTMLImageElementFactory_create(HTMLIMGFACTORY(This), *width, *height, &img);
860 if(FAILED(hres))
861 return hres;
862
863 V_VT(res) = VT_DISPATCH;
864 V_DISPATCH(res) = (IDispatch*)img;
865
866 return S_OK;
867 }
868
869 #undef HTMLIMGFACTORY_THIS
870
871 static const IHTMLImageElementFactoryVtbl HTMLImageElementFactoryVtbl = {
872 HTMLImageElementFactory_QueryInterface,
873 HTMLImageElementFactory_AddRef,
874 HTMLImageElementFactory_Release,
875 HTMLImageElementFactory_GetTypeInfoCount,
876 HTMLImageElementFactory_GetTypeInfo,
877 HTMLImageElementFactory_GetIDsOfNames,
878 HTMLImageElementFactory_Invoke,
879 HTMLImageElementFactory_create
880 };
881
882 static const tid_t HTMLImageElementFactory_iface_tids[] = {
883 IHTMLImageElementFactory_tid,
884 0
885 };
886
887 static const dispex_static_data_vtbl_t HTMLImageElementFactory_dispex_vtbl = {
888 HTMLImageElementFactory_value,
889 NULL,
890 NULL
891 };
892
893 static dispex_static_data_t HTMLImageElementFactory_dispex = {
894 &HTMLImageElementFactory_dispex_vtbl,
895 IHTMLImageElementFactory_tid,
896 NULL,
897 HTMLImageElementFactory_iface_tids
898 };
899
900 HTMLImageElementFactory *HTMLImageElementFactory_Create(HTMLWindow *window)
901 {
902 HTMLImageElementFactory *ret;
903
904 ret = heap_alloc(sizeof(HTMLImageElementFactory));
905
906 ret->lpHTMLImageElementFactoryVtbl = &HTMLImageElementFactoryVtbl;
907 ret->ref = 1;
908 ret->window = window;
909
910 init_dispex(&ret->dispex, (IUnknown*)HTMLIMGFACTORY(ret), &HTMLImageElementFactory_dispex);
911
912 return ret;
913 }