18 #include "precompiled.h"
34 "GUIObject", JSCLASS_HAS_PRIVATE,
35 JS_PropertyStub, JS_PropertyStub,
37 JS_EnumerateStub, JS_ResolveStub,
38 JS_ConvertStub, JS_FinalizeStub,
63 if (!JS_IdToValue(cx,
id, &idval))
75 if (propName ==
"constructor" ||
76 propName ==
"prototype" ||
77 propName ==
"toString" ||
78 propName ==
"toJSON" ||
79 propName ==
"focus" ||
81 propName ==
"getComputedSize"
86 if (propName.substr(0, 2) ==
"on")
88 CStr eventName (CStr(propName.substr(2)).LowerCase());
89 std::map<CStr, JSObject**>::iterator it = e->
m_ScriptHandlers.find(eventName);
93 *vp = OBJECT_TO_JSVAL(*(it->second));
99 if (propName ==
"parent")
115 else if (propName ==
"name")
117 *vp = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, e->
GetName().c_str()));
127 JS_ReportError(cx,
"Invalid GUIObject property '%s'", propName.c_str());
138 *vp = value ? JSVAL_TRUE : JSVAL_FALSE;
146 *vp = INT_TO_JSVAL(value);
155 return JS_NewNumberValue(cx, value, vp);
163 *vp = OBJECT_TO_JSVAL(obj);
167 #define P(x) if (!JS_NewNumberValue(cx, colour.x, &c)) return JS_FALSE; JS_SetProperty(cx, obj, #x, &c)
177 case GUIST_CClientArea:
182 *vp = OBJECT_TO_JSVAL(obj);
185 #define P(x, y, z) g_ScriptingHost.SetObjectProperty_Double(obj, #z, area.x.y)
186 P(pixel, left, left);
188 P(pixel, right, right);
189 P(pixel, bottom, bottom);
190 P(percent, left, rleft);
191 P(percent, top, rtop);
192 P(percent, right, rright);
193 P(percent, bottom, rbottom);
205 case GUIST_CGUIString:
229 case GUIST_CGUISpriteInstance:
247 default:
debug_warn(L
"Invalid EAlign!"); word =
"error";
break;
263 default:
debug_warn(L
"Invalid EVAlign!"); word =
"error";
break;
274 JSObject *obj = JS_NewArrayObject(cx, 0, NULL);
275 *vp = OBJECT_TO_JSVAL(obj);
277 for (
size_t i = 0; i < value.
m_Items.size(); ++i)
280 JS_SetElement(cx, obj, (jsint)i, &val);
287 JS_ReportError(cx,
"Setting '%s' uses an unimplemented type", propName.c_str());
303 if (!JS_IdToValue(cx,
id, &idval))
306 std::string propName;
310 if (propName ==
"name")
320 if (propName.substr(0, 2) ==
"on")
322 if (!JSVAL_IS_OBJECT(*vp) || !JS_ObjectIsFunction(cx, JSVAL_TO_OBJECT(*vp)))
324 JS_ReportError(cx,
"on- event-handlers must be functions");
328 CStr eventName (CStr(propName.substr(2)).LowerCase());
338 JS_ReportError(cx,
"Invalid setting '%s'", propName.c_str());
365 case GUIST_CGUISpriteInstance:
375 case GUIST_CGUIString:
396 else if (value ==
"center" || value ==
"centre") a =
EAlign_Center;
399 JS_ReportError(cx,
"Invalid alignment (should be 'left', 'right' or 'center')");
415 else if (value ==
"center" || value ==
"centre") a =
EVAlign_Center;
418 JS_ReportError(cx,
"Invalid alignment (should be 'top', 'bottom' or 'center')");
428 if (JS_ValueToInt32(cx, *vp, &value) == JS_TRUE)
432 JS_ReportError(cx,
"Cannot convert value to int");
441 if (JS_ValueToNumber(cx, *vp, &value) == JS_TRUE)
445 JS_ReportError(cx,
"Cannot convert value to float");
454 if (JS_ValueToBoolean(cx, *vp, &value) == JS_TRUE)
458 JS_ReportError(cx,
"Cannot convert value to bool");
464 case GUIST_CClientArea:
466 if (JSVAL_IS_STRING(*vp))
474 JS_ReportError(cx,
"Invalid value for setting '%s'", propName.c_str());
483 JSObject* obj = JSVAL_TO_OBJECT(*vp);
484 #define P(x, y, z) area.x.y = (float)g_ScriptingHost.GetObjectProperty_Double(obj, #z)
485 P(pixel, left, left);
487 P(pixel, right, right);
488 P(pixel, bottom, bottom);
489 P(percent, left, rleft);
490 P(percent, top, rtop);
491 P(percent, right, rright);
492 P(percent, bottom, rbottom);
499 JS_ReportError(cx,
"Size only accepts strings or GUISize objects");
507 if (JSVAL_IS_STRING(*vp))
515 JS_ReportError(cx,
"Invalid value for setting '%s'", propName.c_str());
522 JSObject* obj = JSVAL_TO_OBJECT(*vp);
524 #define PROP(x) JS_GetProperty(cx, obj, #x, &t); \
525 JS_ValueToNumber(cx, t, &s); \
534 JS_ReportError(cx,
"Color only accepts strings or GUIColor objects");
542 JSObject* obj = JSVAL_TO_OBJECT(*vp);
544 if (JSVAL_IS_OBJECT(*vp) && JS_GetArrayLength(cx, obj, &length) == JS_TRUE)
548 for (
int i=0; i<(int)length; ++i)
551 if (! JS_GetElement(cx, obj, i, &element))
553 JS_ReportError(cx,
"Failed to get list element");
571 JS_ReportError(cx,
"List only accepts a GUIList object");
580 JS_ReportError(cx,
"Setting '%s' uses an unimplemented type", propName.c_str());
584 return !JS_IsExceptionPending(cx);
592 JS_ReportError(cx,
"GUIObject has no default constructor");
600 JS_SetPrivate(cx, obj, guiObject);
602 JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj));
620 snprintf(buffer, 256,
"[GUIObject: %s]", e->
GetName().c_str());
622 JS_SET_RVAL(cx, vp, STRING_TO_JSVAL(JS_NewStringCopyZ(cx, buffer)));
636 JS_SET_RVAL(cx, vp, JSVAL_VOID);
650 JS_SET_RVAL(cx, vp, JSVAL_VOID);
665 JSObject* obj = JS_NewObject(cx, NULL, NULL, NULL);
679 JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj));
JSPropertySpec JSI_props[]
JSBool blur(JSContext *cx, uintN argc, jsval *vp)
#define UNUSED(param)
mark a function parameter as unused and avoid the corresponding compiler warning. ...
JSFunctionSpec JSI_methods[]
void SetScriptHandler(const CStr &Action, JSObject *Function)
const PSRETURN PSRETURN_OK
JSBool getProperty(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
float left
Returning CPos representing each corner.
static PSRETURN GetSetting(const IGUIObject *pObject, const CStr &Setting, T &Value)
Retrieves a setting by name from object pointer.
const CStr & GetName() const
Get object name, name is unique.
Base settings, all objects possess these settings in their m_BaseSettings Instructions can be found i...
JSBool toString(JSContext *cx, uintN argc, jsval *vp)
static bool FromJSVal(JSContext *cx, jsval val, T &ret)
Convert a jsval to a C++ type.
virtual void UpdateCachedSize()
All sizes are relative to resolution, and the calculation is not wanted in real time, therefore it is cached, update the cached size with this function.
JSObject * GetJSObject()
Retrieves the JSObject representing this GUI object.
#define UNUSED2(param)
mark a function local variable or parameter as unused and avoid the corresponding compiler warning...
IGUIObject * GetParent() const
NOTE! This will not just return m_pParent, when that is need use it! There is one exception to it...
JSFunctionSpec JSI_methods[]
std::vector< CGUIString > m_Items
List of items (as text), the post-processed result is stored in the IGUITextOwner structure of this c...
static jsval ToJSVal(JSContext *cx, T const &val)
Convert a C++ type to a jsval.
JSBool setProperty(JSContext *cx, JSObject *obj, jsid id, JSBool strict, jsval *vp)
void SetName(const CStr &Name)
Get object name.
void SetValue(const CStrW &str)
Set the value, the string will automatically be parsed when set.
CRect m_CachedActualSize
Cached size, real size m_Size is actually dependent on resolution and can have different real outcome...
#define DEBUG_WARN_ERR(status)
display the error dialog with text corresponding to the given error code.
JSBool construct(JSContext *cx, uintN argc, jsval *vp)
JSBool getComputedSize(JSContext *cx, uintN argc, jsval *vp)
PSRETURN GetSettingType(const CStr &Setting, EGUISettingType &Type) const
Retrieves the type of a named setting.
PSRETURN SetSetting(const CStr &Setting, const CStrW &Value, const bool &SkipMessage=false)
Set a setting by string, regardless of what type it is.
static PSRETURN SetSetting(IGUIObject *pObject, const CStr &Setting, const T &Value, const bool &SkipMessage=false)
Sets a value by name using a real datatype as input.
std::map< CStr, JSObject ** > m_ScriptHandlers
#define debug_warn(expr)
display the error dialog with the given text.
JSBool focus(JSContext *cx, uintN argc, jsval *vp)
JSPropertySpec JSI_props[]
const CStrW & GetOriginalString() const
Get String, with tags.
String class, substitute for CStr, but that parses the tags and builds up a list of all text that wil...
JSBool construct(JSContext *cx, uintN argc, jsval *vp)
void SetFocusedObject(IGUIObject *pObject)
Change focus to new object.
static PSRETURN GetSettingPointer(const IGUIObject *pObject, const CStr &Setting, T *&Value)
Rectangle class used for screen rectangles.
Client Area is a rectangle relative to a parent rectangle.