2019-01-13 08:37:41 -08:00
|
|
|
/* Copyright (C) 2019 Wildfire Games.
|
2009-04-18 10:00:33 -07:00
|
|
|
* This file is part of 0 A.D.
|
|
|
|
|
*
|
|
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
2004-07-08 08:23:47 -07:00
|
|
|
#include "precompiled.h"
|
|
|
|
|
|
|
|
|
|
#include "JSInterface_IGUIObject.h"
|
|
|
|
|
|
2004-12-21 05:37:24 -08:00
|
|
|
#include "gui/CGUI.h"
|
2019-07-26 11:57:28 -07:00
|
|
|
#include "gui/CGUIColor.h"
|
2005-04-23 16:23:06 -07:00
|
|
|
#include "gui/CList.h"
|
2009-12-03 12:17:22 -08:00
|
|
|
#include "gui/GUIManager.h"
|
2019-07-26 11:57:28 -07:00
|
|
|
#include "gui/IGUIObject.h"
|
|
|
|
|
#include "gui/IGUIScrollBar.h"
|
|
|
|
|
#include "gui/scripting/JSInterface_GUITypes.h"
|
2005-04-23 16:23:06 -07:00
|
|
|
#include "ps/CLogger.h"
|
2016-09-02 09:23:44 -07:00
|
|
|
#include "scriptinterface/ScriptExtraHeaders.h"
|
2019-07-26 11:57:28 -07:00
|
|
|
#include "scriptinterface/ScriptInterface.h"
|
2004-09-06 04:28:30 -07:00
|
|
|
|
2004-07-08 08:23:47 -07:00
|
|
|
JSClass JSI_IGUIObject::JSI_class = {
|
|
|
|
|
"GUIObject", JSCLASS_HAS_PRIVATE,
|
2016-09-02 09:26:54 -07:00
|
|
|
nullptr, nullptr,
|
2004-07-08 08:23:47 -07:00
|
|
|
JSI_IGUIObject::getProperty, JSI_IGUIObject::setProperty,
|
2016-09-02 09:26:54 -07:00
|
|
|
nullptr, nullptr, nullptr, nullptr,
|
2019-07-22 18:24:49 -07:00
|
|
|
nullptr, nullptr, nullptr, nullptr
|
2004-07-08 08:23:47 -07:00
|
|
|
};
|
|
|
|
|
|
2014-03-28 13:26:32 -07:00
|
|
|
JSFunctionSpec JSI_IGUIObject::JSI_methods[] =
|
2004-07-08 08:23:47 -07:00
|
|
|
{
|
2019-01-13 08:37:41 -08:00
|
|
|
JS_FN("toString", JSI_IGUIObject::toString, 0, 0),
|
|
|
|
|
JS_FN("focus", JSI_IGUIObject::focus, 0, 0),
|
|
|
|
|
JS_FN("blur", JSI_IGUIObject::blur, 0, 0),
|
|
|
|
|
JS_FN("getComputedSize", JSI_IGUIObject::getComputedSize, 0, 0),
|
2019-03-18 15:15:40 -07:00
|
|
|
JS_FN("getTextSize", JSI_IGUIObject::getTextSize, 0, 0),
|
2014-03-28 13:26:32 -07:00
|
|
|
JS_FS_END
|
2004-07-08 08:23:47 -07:00
|
|
|
};
|
|
|
|
|
|
2015-01-24 06:46:52 -08:00
|
|
|
bool JSI_IGUIObject::getProperty(JSContext* cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp)
|
2004-07-08 08:23:47 -07:00
|
|
|
{
|
2014-07-12 12:08:39 -07:00
|
|
|
JSAutoRequest rq(cx);
|
2014-07-13 08:31:48 -07:00
|
|
|
ScriptInterface* pScriptInterface = ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface;
|
|
|
|
|
|
2010-11-16 15:00:52 -08:00
|
|
|
IGUIObject* e = (IGUIObject*)JS_GetInstancePrivate(cx, obj, &JSI_IGUIObject::JSI_class, NULL);
|
|
|
|
|
if (!e)
|
2015-01-24 06:46:52 -08:00
|
|
|
return false;
|
2010-11-16 15:00:52 -08:00
|
|
|
|
2014-07-12 12:08:39 -07:00
|
|
|
JS::RootedValue idval(cx);
|
2015-01-24 06:46:52 -08:00
|
|
|
if (!JS_IdToValue(cx, id, &idval))
|
|
|
|
|
return false;
|
2010-11-16 15:00:52 -08:00
|
|
|
|
|
|
|
|
std::string propName;
|
|
|
|
|
if (!ScriptInterface::FromJSVal(cx, idval, propName))
|
2015-01-24 06:46:52 -08:00
|
|
|
return false;
|
2004-07-08 08:23:47 -07:00
|
|
|
|
2019-07-22 18:24:49 -07:00
|
|
|
// Skip registered functions and inherited properties
|
2004-12-15 13:24:46 -08:00
|
|
|
if (propName == "constructor" ||
|
|
|
|
|
propName == "prototype" ||
|
2010-08-11 14:04:09 -07:00
|
|
|
propName == "toString" ||
|
2013-03-07 05:49:49 -08:00
|
|
|
propName == "toJSON" ||
|
2010-08-13 06:50:03 -07:00
|
|
|
propName == "focus" ||
|
2011-08-20 10:17:53 -07:00
|
|
|
propName == "blur" ||
|
2019-03-18 15:15:40 -07:00
|
|
|
propName == "getTextSize" ||
|
2011-08-20 10:17:53 -07:00
|
|
|
propName == "getComputedSize"
|
2004-07-08 08:23:47 -07:00
|
|
|
)
|
2015-01-24 06:46:52 -08:00
|
|
|
return true;
|
2004-07-08 08:23:47 -07:00
|
|
|
|
2005-03-29 14:04:38 -08:00
|
|
|
// Use onWhatever to access event handlers
|
2010-11-16 15:00:52 -08:00
|
|
|
if (propName.substr(0, 2) == "on")
|
2005-03-29 14:04:38 -08:00
|
|
|
{
|
2015-08-21 10:08:41 -07:00
|
|
|
CStr eventName(CStr(propName.substr(2)).LowerCase());
|
2016-01-12 16:42:55 -08:00
|
|
|
std::map<CStr, JS::Heap<JSObject*>>::iterator it = e->m_ScriptHandlers.find(eventName);
|
2005-03-29 14:04:38 -08:00
|
|
|
if (it == e->m_ScriptHandlers.end())
|
2015-01-24 06:46:52 -08:00
|
|
|
vp.setNull();
|
2005-03-29 14:04:38 -08:00
|
|
|
else
|
2015-01-24 06:46:52 -08:00
|
|
|
vp.setObject(*it->second.get());
|
|
|
|
|
return true;
|
2005-03-29 14:04:38 -08:00
|
|
|
}
|
|
|
|
|
|
2004-12-15 13:24:46 -08:00
|
|
|
if (propName == "parent")
|
2004-07-08 08:23:47 -07:00
|
|
|
{
|
|
|
|
|
IGUIObject* parent = e->GetParent();
|
2016-06-02 15:49:28 -07:00
|
|
|
|
2004-07-08 08:23:47 -07:00
|
|
|
if (parent)
|
2014-03-28 13:26:32 -07:00
|
|
|
vp.set(JS::ObjectValue(*parent->GetJSObject()));
|
2004-07-08 08:23:47 -07:00
|
|
|
else
|
2014-03-28 13:26:32 -07:00
|
|
|
vp.set(JS::NullValue());
|
2016-06-02 15:49:28 -07:00
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else if (propName == "children")
|
|
|
|
|
{
|
2019-07-22 12:35:14 -07:00
|
|
|
pScriptInterface->CreateArray(vp);
|
2016-06-02 15:49:28 -07:00
|
|
|
|
|
|
|
|
for (size_t i = 0; i < e->m_Children.size(); ++i)
|
2019-07-22 12:35:14 -07:00
|
|
|
pScriptInterface->SetPropertyInt(vp, i, e->m_Children[i]);
|
2016-06-02 15:49:28 -07:00
|
|
|
|
2015-01-24 06:46:52 -08:00
|
|
|
return true;
|
2004-07-08 08:23:47 -07:00
|
|
|
}
|
2004-12-15 13:24:46 -08:00
|
|
|
else if (propName == "name")
|
2004-07-08 08:23:47 -07:00
|
|
|
{
|
2019-07-22 12:35:14 -07:00
|
|
|
ScriptInterface::ToJSVal(cx, vp, e->GetName());
|
2015-01-24 06:46:52 -08:00
|
|
|
return true;
|
2004-07-08 08:23:47 -07:00
|
|
|
}
|
2019-07-29 07:46:29 -07:00
|
|
|
else if (e->SettingExists(propName))
|
2004-07-08 08:23:47 -07:00
|
|
|
{
|
2019-07-29 07:46:29 -07:00
|
|
|
e->m_Settings[propName].m_ToJSVal(cx, vp);
|
2015-01-24 06:46:52 -08:00
|
|
|
return true;
|
2004-07-08 08:23:47 -07:00
|
|
|
}
|
2019-07-29 07:46:29 -07:00
|
|
|
|
|
|
|
|
JS_ReportError(cx, "Property '%s' does not exist!", propName.c_str());
|
|
|
|
|
return false;
|
2004-07-08 08:23:47 -07:00
|
|
|
}
|
|
|
|
|
|
2015-01-24 06:46:52 -08:00
|
|
|
bool JSI_IGUIObject::setProperty(JSContext* cx, JS::HandleObject obj, JS::HandleId id, bool UNUSED(strict), JS::MutableHandleValue vp)
|
2004-07-08 08:23:47 -07:00
|
|
|
{
|
2010-11-16 15:00:52 -08:00
|
|
|
IGUIObject* e = (IGUIObject*)JS_GetInstancePrivate(cx, obj, &JSI_IGUIObject::JSI_class, NULL);
|
|
|
|
|
if (!e)
|
2015-01-24 06:46:52 -08:00
|
|
|
return false;
|
2010-11-16 15:00:52 -08:00
|
|
|
|
2014-07-12 12:08:39 -07:00
|
|
|
JSAutoRequest rq(cx);
|
|
|
|
|
JS::RootedValue idval(cx);
|
2015-01-24 06:46:52 -08:00
|
|
|
if (!JS_IdToValue(cx, id, &idval))
|
|
|
|
|
return false;
|
2010-11-16 15:00:52 -08:00
|
|
|
|
|
|
|
|
std::string propName;
|
|
|
|
|
if (!ScriptInterface::FromJSVal(cx, idval, propName))
|
2015-01-24 06:46:52 -08:00
|
|
|
return false;
|
2010-11-16 15:00:52 -08:00
|
|
|
|
2004-12-15 13:24:46 -08:00
|
|
|
if (propName == "name")
|
2004-07-08 08:23:47 -07:00
|
|
|
{
|
2010-11-16 15:00:52 -08:00
|
|
|
std::string value;
|
2014-03-28 13:26:32 -07:00
|
|
|
if (!ScriptInterface::FromJSVal(cx, vp, value))
|
2015-01-24 06:46:52 -08:00
|
|
|
return false;
|
2010-11-16 15:00:52 -08:00
|
|
|
e->SetName(value);
|
2015-01-24 06:46:52 -08:00
|
|
|
return true;
|
2004-07-08 08:23:47 -07:00
|
|
|
}
|
2004-12-13 04:07:12 -08:00
|
|
|
|
2015-08-02 07:40:51 -07:00
|
|
|
JS::RootedObject vpObj(cx);
|
|
|
|
|
if (vp.isObject())
|
|
|
|
|
vpObj = &vp.toObject();
|
|
|
|
|
|
2005-03-29 14:04:38 -08:00
|
|
|
// Use onWhatever to set event handlers
|
2010-11-16 15:00:52 -08:00
|
|
|
if (propName.substr(0, 2) == "on")
|
2005-03-29 14:04:38 -08:00
|
|
|
{
|
2014-03-28 13:26:32 -07:00
|
|
|
if (vp.isPrimitive() || vp.isNull() || !JS_ObjectIsFunction(cx, &vp.toObject()))
|
2005-03-29 14:04:38 -08:00
|
|
|
{
|
|
|
|
|
JS_ReportError(cx, "on- event-handlers must be functions");
|
2015-01-24 06:46:52 -08:00
|
|
|
return false;
|
2005-03-29 14:04:38 -08:00
|
|
|
}
|
|
|
|
|
|
2015-08-21 10:08:41 -07:00
|
|
|
CStr eventName(CStr(propName.substr(2)).LowerCase());
|
2014-08-08 06:41:47 -07:00
|
|
|
e->SetScriptHandler(eventName, vpObj);
|
2005-03-29 15:34:58 -08:00
|
|
|
|
2015-01-24 06:46:52 -08:00
|
|
|
return true;
|
2005-03-29 14:04:38 -08:00
|
|
|
}
|
|
|
|
|
|
2019-07-29 07:46:29 -07:00
|
|
|
if (e->SettingExists(propName))
|
|
|
|
|
return e->m_Settings[propName].m_FromJSVal(cx, vp);
|
2004-12-13 04:07:12 -08:00
|
|
|
|
2019-07-29 07:46:29 -07:00
|
|
|
JS_ReportError(cx, "Property '%s' does not exist!", propName.c_str());
|
|
|
|
|
return false;
|
2004-07-08 08:23:47 -07:00
|
|
|
}
|
|
|
|
|
|
2014-01-04 02:14:53 -08:00
|
|
|
void JSI_IGUIObject::init(ScriptInterface& scriptInterface)
|
2004-07-08 08:23:47 -07:00
|
|
|
{
|
2019-07-22 18:24:49 -07:00
|
|
|
scriptInterface.DefineCustomObjectType(&JSI_class, nullptr, 1, nullptr, JSI_methods, nullptr, nullptr);
|
2004-07-08 08:23:47 -07:00
|
|
|
}
|
|
|
|
|
|
2017-08-28 03:27:36 -07:00
|
|
|
bool JSI_IGUIObject::toString(JSContext* cx, uint UNUSED(argc), JS::Value* vp)
|
2004-07-08 08:23:47 -07:00
|
|
|
{
|
2014-07-26 15:33:16 -07:00
|
|
|
JSAutoRequest rq(cx);
|
2014-07-12 09:55:09 -07:00
|
|
|
JS::CallReceiver rec = JS::CallReceiverFromVp(vp);
|
2010-11-16 15:00:52 -08:00
|
|
|
|
2014-08-08 06:41:47 -07:00
|
|
|
JS::RootedObject thisObj(cx, JS_THIS_OBJECT(cx, vp));
|
2015-08-21 10:08:41 -07:00
|
|
|
|
2014-08-08 06:41:47 -07:00
|
|
|
IGUIObject* e = (IGUIObject*)JS_GetInstancePrivate(cx, thisObj, &JSI_IGUIObject::JSI_class, NULL);
|
2010-11-16 15:00:52 -08:00
|
|
|
if (!e)
|
2015-01-24 06:46:52 -08:00
|
|
|
return false;
|
2004-07-08 08:23:47 -07:00
|
|
|
|
2019-07-23 08:17:35 -07:00
|
|
|
ScriptInterface::ToJSVal(cx, rec.rval(), "[GUIObject: " + e->GetName() + "]");
|
2015-01-24 06:46:52 -08:00
|
|
|
return true;
|
2004-07-08 08:23:47 -07:00
|
|
|
}
|
2010-08-11 14:04:09 -07:00
|
|
|
|
2017-08-28 03:27:36 -07:00
|
|
|
bool JSI_IGUIObject::focus(JSContext* cx, uint UNUSED(argc), JS::Value* vp)
|
2010-08-11 14:04:09 -07:00
|
|
|
{
|
2014-07-26 15:33:16 -07:00
|
|
|
JSAutoRequest rq(cx);
|
2014-07-12 09:55:09 -07:00
|
|
|
JS::CallReceiver rec = JS::CallReceiverFromVp(vp);
|
2010-11-16 15:00:52 -08:00
|
|
|
|
2014-08-08 06:41:47 -07:00
|
|
|
JS::RootedObject thisObj(cx, JS_THIS_OBJECT(cx, vp));
|
2015-08-21 10:08:41 -07:00
|
|
|
|
2014-08-08 06:41:47 -07:00
|
|
|
IGUIObject* e = (IGUIObject*)JS_GetInstancePrivate(cx, thisObj, &JSI_IGUIObject::JSI_class, NULL);
|
2010-11-16 15:00:52 -08:00
|
|
|
if (!e)
|
2015-01-24 06:46:52 -08:00
|
|
|
return false;
|
2010-08-11 14:04:09 -07:00
|
|
|
|
2010-08-13 06:50:03 -07:00
|
|
|
e->GetGUI()->SetFocusedObject(e);
|
2010-11-16 15:00:52 -08:00
|
|
|
|
2014-07-12 09:55:09 -07:00
|
|
|
rec.rval().setUndefined();
|
2015-01-24 06:46:52 -08:00
|
|
|
return true;
|
2010-08-13 06:50:03 -07:00
|
|
|
}
|
|
|
|
|
|
2017-08-28 03:27:36 -07:00
|
|
|
bool JSI_IGUIObject::blur(JSContext* cx, uint UNUSED(argc), JS::Value* vp)
|
2010-08-13 06:50:03 -07:00
|
|
|
{
|
2014-07-26 15:33:16 -07:00
|
|
|
JSAutoRequest rq(cx);
|
2014-07-12 09:55:09 -07:00
|
|
|
JS::CallReceiver rec = JS::CallReceiverFromVp(vp);
|
2010-11-16 15:00:52 -08:00
|
|
|
|
2014-08-08 06:41:47 -07:00
|
|
|
JS::RootedObject thisObj(cx, JS_THIS_OBJECT(cx, vp));
|
2015-08-21 10:08:41 -07:00
|
|
|
|
2014-08-08 06:41:47 -07:00
|
|
|
IGUIObject* e = (IGUIObject*)JS_GetInstancePrivate(cx, thisObj, &JSI_IGUIObject::JSI_class, NULL);
|
2010-11-16 15:00:52 -08:00
|
|
|
if (!e)
|
2015-01-24 06:46:52 -08:00
|
|
|
return false;
|
2010-08-13 06:50:03 -07:00
|
|
|
|
|
|
|
|
e->GetGUI()->SetFocusedObject(NULL);
|
2010-11-16 15:00:52 -08:00
|
|
|
|
2014-07-12 09:55:09 -07:00
|
|
|
rec.rval().setUndefined();
|
2015-01-24 06:46:52 -08:00
|
|
|
return true;
|
2010-08-11 14:04:09 -07:00
|
|
|
}
|
2011-08-20 10:17:53 -07:00
|
|
|
|
2019-03-18 15:15:40 -07:00
|
|
|
bool JSI_IGUIObject::getTextSize(JSContext* cx, uint argc, JS::Value* vp)
|
|
|
|
|
{
|
|
|
|
|
JSAutoRequest rq(cx);
|
|
|
|
|
JS::CallReceiver rec = JS::CallReceiverFromVp(vp);
|
|
|
|
|
|
|
|
|
|
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
|
|
|
|
JS::RootedObject thisObj(cx, &args.thisv().toObject());
|
|
|
|
|
|
|
|
|
|
IGUIObject* obj = (IGUIObject*)JS_GetInstancePrivate(cx, thisObj, &JSI_IGUIObject::JSI_class, NULL);
|
|
|
|
|
|
|
|
|
|
if (!obj || !obj->SettingExists("caption"))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
CStrW font;
|
|
|
|
|
if (GUI<CStrW>::GetSetting(obj, "font", font) != PSRETURN_OK || font.empty())
|
|
|
|
|
font = L"default";
|
|
|
|
|
|
|
|
|
|
CGUIString caption;
|
|
|
|
|
EGUISettingType Type;
|
|
|
|
|
obj->GetSettingType("caption", Type);
|
|
|
|
|
if (Type == GUIST_CGUIString)
|
|
|
|
|
// CText, CButton, CCheckBox, CRadioButton
|
|
|
|
|
GUI<CGUIString>::GetSetting(obj, "caption", caption);
|
|
|
|
|
else if (Type == GUIST_CStrW)
|
|
|
|
|
{
|
|
|
|
|
// CInput
|
|
|
|
|
CStrW captionStr;
|
|
|
|
|
GUI<CStrW>::GetSetting(obj, "caption", captionStr);
|
|
|
|
|
caption.SetValue(captionStr);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
obj->UpdateCachedSize();
|
|
|
|
|
float width = obj->m_CachedActualSize.GetWidth();
|
|
|
|
|
|
|
|
|
|
if (obj->SettingExists("scrollbar"))
|
|
|
|
|
{
|
|
|
|
|
bool scrollbar;
|
|
|
|
|
GUI<bool>::GetSetting(obj, "scrollbar", scrollbar);
|
|
|
|
|
if (scrollbar)
|
|
|
|
|
{
|
|
|
|
|
CStr scrollbar_style;
|
|
|
|
|
GUI<CStr>::GetSetting(obj, "scrollbar_style", scrollbar_style);
|
|
|
|
|
const SGUIScrollBarStyle* scrollbar_style_object = obj->GetGUI()->GetScrollBarStyle(scrollbar_style);
|
|
|
|
|
if (scrollbar_style_object)
|
|
|
|
|
width -= scrollbar_style_object->m_Width;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float buffer_zone = 0.f;
|
|
|
|
|
GUI<float>::GetSetting(obj, "buffer_zone", buffer_zone);
|
|
|
|
|
SGUIText text = obj->GetGUI()->GenerateText(caption, font, width, buffer_zone, obj);
|
|
|
|
|
|
2019-07-22 12:35:14 -07:00
|
|
|
JS::RootedValue objVal(cx);
|
2019-03-18 15:15:40 -07:00
|
|
|
try
|
|
|
|
|
{
|
2019-07-22 12:35:14 -07:00
|
|
|
ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface->CreateObject(
|
|
|
|
|
&objVal,
|
|
|
|
|
"width", text.m_Size.cx,
|
|
|
|
|
"height", text.m_Size.cy);
|
2019-03-18 15:15:40 -07:00
|
|
|
}
|
|
|
|
|
catch (PSERROR_Scripting_ConversionFailed&)
|
|
|
|
|
{
|
|
|
|
|
debug_warn(L"Error creating size object!");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rec.rval().set(objVal);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-28 03:27:36 -07:00
|
|
|
bool JSI_IGUIObject::getComputedSize(JSContext* cx, uint UNUSED(argc), JS::Value* vp)
|
2011-08-20 10:17:53 -07:00
|
|
|
{
|
2014-07-26 15:33:16 -07:00
|
|
|
JSAutoRequest rq(cx);
|
2014-07-12 09:55:09 -07:00
|
|
|
JS::CallReceiver rec = JS::CallReceiverFromVp(vp);
|
2015-08-21 10:08:41 -07:00
|
|
|
|
2014-08-08 06:41:47 -07:00
|
|
|
JS::RootedObject thisObj(cx, JS_THIS_OBJECT(cx, vp));
|
2015-08-21 10:08:41 -07:00
|
|
|
|
2014-08-08 06:41:47 -07:00
|
|
|
IGUIObject* e = (IGUIObject*)JS_GetInstancePrivate(cx, thisObj, &JSI_IGUIObject::JSI_class, NULL);
|
2011-08-20 10:17:53 -07:00
|
|
|
if (!e)
|
2015-01-24 06:46:52 -08:00
|
|
|
return false;
|
2011-08-20 10:17:53 -07:00
|
|
|
|
|
|
|
|
e->UpdateCachedSize();
|
|
|
|
|
CRect size = e->m_CachedActualSize;
|
|
|
|
|
|
2019-07-22 12:35:14 -07:00
|
|
|
JS::RootedValue objVal(cx);
|
2011-08-20 10:17:53 -07:00
|
|
|
try
|
|
|
|
|
{
|
2019-07-22 12:35:14 -07:00
|
|
|
ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface->CreateObject(
|
|
|
|
|
&objVal,
|
|
|
|
|
"left", size.left,
|
|
|
|
|
"right", size.right,
|
|
|
|
|
"top", size.top,
|
|
|
|
|
"bottom", size.bottom);
|
2011-08-20 10:17:53 -07:00
|
|
|
}
|
2013-05-22 15:27:53 -07:00
|
|
|
catch (PSERROR_Scripting_ConversionFailed&)
|
2011-08-20 10:17:53 -07:00
|
|
|
{
|
|
|
|
|
debug_warn(L"Error creating size object!");
|
2015-01-24 06:46:52 -08:00
|
|
|
return false;
|
2011-08-20 10:17:53 -07:00
|
|
|
}
|
|
|
|
|
|
2014-07-12 09:55:09 -07:00
|
|
|
rec.rval().set(objVal);
|
2015-01-24 06:46:52 -08:00
|
|
|
return true;
|
2011-08-20 10:17:53 -07:00
|
|
|
}
|