Allowed JS access to GUI object event handlers, via object.onPress etc.

Stopped crashes when ordering entities without bounding boxes.

This was SVN commit r2079.
This commit is contained in:
Ykkrosh
2005-03-29 22:04:38 +00:00
parent 22dd4dd67b
commit 249aaf436f
3 changed files with 72 additions and 40 deletions
@@ -49,6 +49,19 @@ JSBool JSI_IGUIObject::getProperty(JSContext* cx, JSObject* obj, jsval id, jsval
IGUIObject* e = (IGUIObject*)JS_GetPrivate(cx, obj);
// Use onWhatever to access event handlers
if (propName.Left(2) == "on")
{
CStr eventName (CStr(propName.substr(2)).LowerCase());
std::map<CStr, JSFunction*>::iterator it = e->m_ScriptHandlers.find(eventName);
if (it == e->m_ScriptHandlers.end())
*vp = JSVAL_NULL;
else
*vp = OBJECT_TO_JSVAL(JS_GetFunctionObject(it->second));
return JS_TRUE;
}
// Handle the "parent" property specially
if (propName == "parent")
{
@@ -248,6 +261,20 @@ JSBool JSI_IGUIObject::setProperty(JSContext* cx, JSObject* obj, jsval id, jsval
return JS_TRUE;
}
// Use onWhatever to set event handlers
if (propName.Left(2) == "on")
{
JSFunction* func = JS_ValueToFunction(cx, *vp);
if (! func)
{
JS_ReportError(cx, "on- event-handlers must be functions");
return JS_FALSE;
}
CStr eventName (CStr(propName.substr(2)).LowerCase());
e->m_ScriptHandlers[eventName] = func;
}
// Retrieve the setting's type (and make sure it actually exists)
EGUISettingType Type;
if (e->GetSettingType(propName, Type) != PS_OK)