comctl32: Fix signedness of two variables.
[wine/multimedia.git] / dlls / mshtml / htmlevent.c
blobf98e3a15c53dcf131bee010e0f5755e720def510
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 "mshtml_private.h"
30 #include "wine/debug.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
34 struct event_target_t {
35 IDispatch *event_table[EVENTID_LAST];
38 static const WCHAR changeW[] = {'c','h','a','n','g','e',0};
39 static const WCHAR onchangeW[] = {'o','n','c','h','a','n','g','e',0};
41 static const WCHAR clickW[] = {'c','l','i','c','k',0};
42 static const WCHAR onclickW[] = {'o','n','c','l','i','c','k',0};
44 static const WCHAR keyupW[] = {'k','e','y','u','p',0};
45 static const WCHAR onkeyupW[] = {'o','n','k','e','y','u','p',0};
47 static const WCHAR loadW[] = {'l','o','a','d',0};
48 static const WCHAR onloadW[] = {'o','n','l','o','a','d',0};
50 typedef struct {
51 LPCWSTR name;
52 LPCWSTR attr_name;
53 DWORD flags;
54 } event_info_t;
56 #define EVENT_DEFAULTLISTENER 0x0001
58 static const event_info_t event_info[] = {
59 {changeW, onchangeW, EVENT_DEFAULTLISTENER},
60 {clickW, onclickW, EVENT_DEFAULTLISTENER},
61 {keyupW, onkeyupW, EVENT_DEFAULTLISTENER},
62 {loadW, onloadW, 0}
65 eventid_t str_to_eid(LPCWSTR str)
67 int i;
69 for(i=0; i < sizeof(event_info)/sizeof(event_info[0]); i++) {
70 if(!strcmpW(event_info[i].name, str))
71 return i;
74 ERR("unknown type %s\n", debugstr_w(str));
75 return EVENTID_LAST;
78 typedef struct {
79 const IHTMLEventObjVtbl *lpIHTMLEventObjVtbl;
80 LONG ref;
81 } HTMLEventObj;
83 #define HTMLEVENTOBJ(x) ((IHTMLEventObj*) &(x)->lpIHTMLEventObjVtbl)
85 #define HTMLEVENTOBJ_THIS(iface) DEFINE_THIS(HTMLEventObj, IHTMLEventObj, iface)
87 static HRESULT WINAPI HTMLEventObj_QueryInterface(IHTMLEventObj *iface, REFIID riid, void **ppv)
89 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
91 *ppv = NULL;
93 if(IsEqualGUID(&IID_IUnknown, riid)) {
94 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
95 *ppv = HTMLEVENTOBJ(This);
96 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
97 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
98 *ppv = HTMLEVENTOBJ(This);
99 }else if(IsEqualGUID(&IID_IHTMLEventObj, riid)) {
100 TRACE("(%p)->(IID_IHTMLEventObj %p)\n", This, ppv);
101 *ppv = HTMLEVENTOBJ(This);
104 if(*ppv) {
105 IUnknown_AddRef((IUnknown*)*ppv);
106 return S_OK;
109 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
110 return E_NOINTERFACE;
113 static ULONG WINAPI HTMLEventObj_AddRef(IHTMLEventObj *iface)
115 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
116 LONG ref = InterlockedIncrement(&This->ref);
118 TRACE("(%p) ref=%d\n", This, ref);
120 return ref;
123 static ULONG WINAPI HTMLEventObj_Release(IHTMLEventObj *iface)
125 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
126 LONG ref = InterlockedDecrement(&This->ref);
128 TRACE("(%p) ref=%d\n", This, ref);
130 if(!ref)
131 heap_free(This);
133 return ref;
136 static HRESULT WINAPI HTMLEventObj_GetTypeInfoCount(IHTMLEventObj *iface, UINT *pctinfo)
138 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
139 FIXME("(%p)->(%p)\n", This, pctinfo);
140 return E_NOTIMPL;
143 static HRESULT WINAPI HTMLEventObj_GetTypeInfo(IHTMLEventObj *iface, UINT iTInfo,
144 LCID lcid, ITypeInfo **ppTInfo)
146 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
147 FIXME("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
148 return E_NOTIMPL;
151 static HRESULT WINAPI HTMLEventObj_GetIDsOfNames(IHTMLEventObj *iface, REFIID riid,
152 LPOLESTR *rgszNames, UINT cNames,
153 LCID lcid, DISPID *rgDispId)
155 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
156 FIXME("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
157 lcid, rgDispId);
158 return E_NOTIMPL;
161 static HRESULT WINAPI HTMLEventObj_Invoke(IHTMLEventObj *iface, DISPID dispIdMember,
162 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
163 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
165 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
166 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
167 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
168 return E_NOTIMPL;
171 static HRESULT WINAPI HTMLEventObj_get_srcElement(IHTMLEventObj *iface, IHTMLElement **p)
173 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
174 FIXME("(%p)->(%p)\n", This, p);
175 return E_NOTIMPL;
178 static HRESULT WINAPI HTMLEventObj_get_altKey(IHTMLEventObj *iface, VARIANT_BOOL *p)
180 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
181 FIXME("(%p)->(%p)\n", This, p);
182 return E_NOTIMPL;
185 static HRESULT WINAPI HTMLEventObj_get_ctrlKey(IHTMLEventObj *iface, VARIANT_BOOL *p)
187 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
188 FIXME("(%p)->(%p)\n", This, p);
189 return E_NOTIMPL;
192 static HRESULT WINAPI HTMLEventObj_get_shiftKey(IHTMLEventObj *iface, VARIANT_BOOL *p)
194 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
195 FIXME("(%p)->(%p)\n", This, p);
196 return E_NOTIMPL;
199 static HRESULT WINAPI HTMLEventObj_put_returnValue(IHTMLEventObj *iface, VARIANT v)
201 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
202 FIXME("(%p)->()\n", This);
203 return E_NOTIMPL;
206 static HRESULT WINAPI HTMLEventObj_get_returnValue(IHTMLEventObj *iface, VARIANT *p)
208 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
209 FIXME("(%p)->(%p)\n", This, p);
210 return E_NOTIMPL;
213 static HRESULT WINAPI HTMLEventObj_put_cancelBubble(IHTMLEventObj *iface, VARIANT_BOOL v)
215 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
216 FIXME("(%p)->(%x)\n", This, v);
217 return E_NOTIMPL;
220 static HRESULT WINAPI HTMLEventObj_get_cancelBubble(IHTMLEventObj *iface, VARIANT_BOOL *p)
222 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
223 FIXME("(%p)->(%p)\n", This, p);
224 return E_NOTIMPL;
227 static HRESULT WINAPI HTMLEventObj_get_fromElement(IHTMLEventObj *iface, IHTMLElement **p)
229 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
230 FIXME("(%p)->(%p)\n", This, p);
231 return E_NOTIMPL;
234 static HRESULT WINAPI HTMLEventObj_get_toElement(IHTMLEventObj *iface, IHTMLElement **p)
236 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
237 FIXME("(%p)->(%p)\n", This, p);
238 return E_NOTIMPL;
241 static HRESULT WINAPI HTMLEventObj_put_keyCode(IHTMLEventObj *iface, long v)
243 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
244 FIXME("(%p)->(%ld)\n", This, v);
245 return E_NOTIMPL;
248 static HRESULT WINAPI HTMLEventObj_get_keyCode(IHTMLEventObj *iface, long *p)
250 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
251 FIXME("(%p)->(%p)\n", This, p);
252 return E_NOTIMPL;
255 static HRESULT WINAPI HTMLEventObj_get_button(IHTMLEventObj *iface, long *p)
257 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
258 FIXME("(%p)->(%p)\n", This, p);
259 return E_NOTIMPL;
262 static HRESULT WINAPI HTMLEventObj_get_type(IHTMLEventObj *iface, BSTR *p)
264 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
265 FIXME("(%p)->(%p)\n", This, p);
266 return E_NOTIMPL;
269 static HRESULT WINAPI HTMLEventObj_get_qualifier(IHTMLEventObj *iface, BSTR *p)
271 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
272 FIXME("(%p)->(%p)\n", This, p);
273 return E_NOTIMPL;
276 static HRESULT WINAPI HTMLEventObj_get_reason(IHTMLEventObj *iface, long *p)
278 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
279 FIXME("(%p)->(%p)\n", This, p);
280 return E_NOTIMPL;
283 static HRESULT WINAPI HTMLEventObj_get_x(IHTMLEventObj *iface, long *p)
285 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
286 FIXME("(%p)->(%p)\n", This, p);
287 return E_NOTIMPL;
290 static HRESULT WINAPI HTMLEventObj_get_y(IHTMLEventObj *iface, long *p)
292 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
293 FIXME("(%p)->(%p)\n", This, p);
294 return E_NOTIMPL;
297 static HRESULT WINAPI HTMLEventObj_get_clientX(IHTMLEventObj *iface, long *p)
299 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
300 FIXME("(%p)->(%p)\n", This, p);
301 return E_NOTIMPL;
304 static HRESULT WINAPI HTMLEventObj_get_clientY(IHTMLEventObj *iface, long *p)
306 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
307 FIXME("(%p)->(%p)\n", This, p);
308 return E_NOTIMPL;
311 static HRESULT WINAPI HTMLEventObj_get_offsetX(IHTMLEventObj *iface, long *p)
313 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
314 FIXME("(%p)->(%p)\n", This, p);
315 return E_NOTIMPL;
318 static HRESULT WINAPI HTMLEventObj_get_offsetY(IHTMLEventObj *iface, long *p)
320 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
321 FIXME("(%p)->(%p)\n", This, p);
322 return E_NOTIMPL;
325 static HRESULT WINAPI HTMLEventObj_get_screenX(IHTMLEventObj *iface, long *p)
327 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
328 FIXME("(%p)->(%p)\n", This, p);
329 return E_NOTIMPL;
332 static HRESULT WINAPI HTMLEventObj_get_screenY(IHTMLEventObj *iface, long *p)
334 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
335 FIXME("(%p)->(%p)\n", This, p);
336 return E_NOTIMPL;
339 static HRESULT WINAPI HTMLEventObj_get_srcFilter(IHTMLEventObj *iface, IDispatch **p)
341 HTMLEventObj *This = HTMLEVENTOBJ_THIS(iface);
342 FIXME("(%p)->(%p)\n", This, p);
343 return E_NOTIMPL;
346 #undef HTMLEVENTOBJ_THIS
348 static const IHTMLEventObjVtbl HTMLEventObjVtbl = {
349 HTMLEventObj_QueryInterface,
350 HTMLEventObj_AddRef,
351 HTMLEventObj_Release,
352 HTMLEventObj_GetTypeInfoCount,
353 HTMLEventObj_GetTypeInfo,
354 HTMLEventObj_GetIDsOfNames,
355 HTMLEventObj_Invoke,
356 HTMLEventObj_get_srcElement,
357 HTMLEventObj_get_altKey,
358 HTMLEventObj_get_ctrlKey,
359 HTMLEventObj_get_shiftKey,
360 HTMLEventObj_put_returnValue,
361 HTMLEventObj_get_returnValue,
362 HTMLEventObj_put_cancelBubble,
363 HTMLEventObj_get_cancelBubble,
364 HTMLEventObj_get_fromElement,
365 HTMLEventObj_get_toElement,
366 HTMLEventObj_put_keyCode,
367 HTMLEventObj_get_keyCode,
368 HTMLEventObj_get_button,
369 HTMLEventObj_get_type,
370 HTMLEventObj_get_qualifier,
371 HTMLEventObj_get_reason,
372 HTMLEventObj_get_x,
373 HTMLEventObj_get_y,
374 HTMLEventObj_get_clientX,
375 HTMLEventObj_get_clientY,
376 HTMLEventObj_get_offsetX,
377 HTMLEventObj_get_offsetY,
378 HTMLEventObj_get_screenX,
379 HTMLEventObj_get_screenY,
380 HTMLEventObj_get_srcFilter
383 static IHTMLEventObj *create_event(void)
385 HTMLEventObj *ret;
387 ret = heap_alloc(sizeof(*ret));
388 ret->lpIHTMLEventObjVtbl = &HTMLEventObjVtbl;
389 ret->ref = 1;
391 return HTMLEVENTOBJ(ret);
394 void fire_event(HTMLDocument *doc, eventid_t eid, nsIDOMNode *target)
396 HTMLDOMNode *node;
398 node = get_node(doc, target, FALSE);
399 if(!node)
400 return;
402 if(node->event_target && node->event_target->event_table[eid]) {
403 doc->window->event = create_event();
405 TRACE("%s >>>\n", debugstr_w(event_info[eid].name));
406 call_disp_func(doc, node->event_target->event_table[eid]);
407 TRACE("%s <<<\n", debugstr_w(event_info[eid].name));
409 IHTMLEventObj_Release(doc->window->event);
410 doc->window->event = NULL;
414 static HRESULT set_node_event_disp(HTMLDOMNode *node, eventid_t eid, IDispatch *disp)
416 if(!node->event_target)
417 node->event_target = heap_alloc_zero(sizeof(event_target_t));
418 else if(node->event_target->event_table[eid])
419 IDispatch_Release(node->event_target->event_table[eid]);
421 IDispatch_AddRef(disp);
422 node->event_target->event_table[eid] = disp;
424 if((event_info[eid].flags & EVENT_DEFAULTLISTENER) && !node->doc->nscontainer->event_vector[eid]) {
425 node->doc->nscontainer->event_vector[eid] = TRUE;
426 add_nsevent_listener(node->doc->nscontainer, event_info[eid].name);
429 return S_OK;
432 HRESULT set_node_event(HTMLDOMNode *node, eventid_t eid, VARIANT *var)
434 switch(V_VT(var)) {
435 case VT_DISPATCH:
436 return set_node_event_disp(node, eid, V_DISPATCH(var));
438 default:
439 FIXME("not supported vt=%d\n", V_VT(var));
442 return E_NOTIMPL;
445 void check_event_attr(HTMLDocument *doc, nsIDOMElement *nselem)
447 const PRUnichar *attr_value;
448 nsAString attr_name_str, attr_value_str;
449 IDispatch *disp;
450 HTMLDOMNode *node;
451 int i;
452 nsresult nsres;
454 nsAString_Init(&attr_value_str, NULL);
455 nsAString_Init(&attr_name_str, NULL);
457 for(i=0; i < EVENTID_LAST; i++) {
458 nsAString_SetData(&attr_name_str, event_info[i].attr_name);
459 nsres = nsIDOMElement_GetAttribute(nselem, &attr_name_str, &attr_value_str);
460 if(NS_SUCCEEDED(nsres)) {
461 nsAString_GetData(&attr_value_str, &attr_value);
462 if(!*attr_value)
463 continue;
465 TRACE("%p.%s = %s\n", nselem, debugstr_w(event_info[i].attr_name), debugstr_w(attr_value));
467 disp = script_parse_event(doc, attr_value);
468 if(disp) {
469 node = get_node(doc, (nsIDOMNode*)nselem, TRUE);
470 set_node_event_disp(node, i, disp);
471 IDispatch_Release(disp);
476 nsAString_Finish(&attr_value_str);
477 nsAString_Finish(&attr_name_str);
480 void release_event_target(event_target_t *event_target)
482 int i;
484 for(i=0; i < EVENTID_LAST; i++) {
485 if(event_target->event_table[i])
486 IDispatch_Release(event_target->event_table[i]);
489 heap_free(event_target);