diff --git a/source/gui/ObjectTypes/CList.cpp b/source/gui/ObjectTypes/CList.cpp index c9cafa05fb..5736c81572 100644 --- a/source/gui/ObjectTypes/CList.cpp +++ b/source/gui/ObjectTypes/CList.cpp @@ -43,6 +43,7 @@ CList::CList(CGUI& pGUI) m_Font(), m_ScrollBar(), m_ScrollBarStyle(), + m_ScrollBottom(false), m_SoundDisabled(), m_SoundSelected(), m_Sprite(), @@ -102,8 +103,6 @@ void CList::SetupText(bool append) { m_Modified = true; - m_ItemsYPositions.resize(m_List.m_Items.size() + 1); - if (!append) // Delete all generated texts. // TODO: try to be cleverer if we want to update items before the end. @@ -125,7 +124,9 @@ void CList::SetupText(bool append) float buffered_y = 0.f; if (append) - buffered_y = m_ItemsYPositions[m_List.m_Items.size() - 1]; + buffered_y = m_ItemsYPositions.back(); + + m_ItemsYPositions.resize(m_List.m_Items.size() + 1); for (size_t i = append ? m_List.m_Items.size() - 1 : 0; i < m_List.m_Items.size(); ++i) { @@ -406,8 +407,7 @@ void CList::AddItem(const CGUIString& str, const CGUIString& data) m_List.m_Items.push_back(str); m_ListData.m_Items.push_back(data); - // TODO Temp - SetupText(); + SetupText(true); } bool CList::HandleAdditionalChildren(const XMBElement& child, CXeromyces* pFile) @@ -515,18 +515,3 @@ void CList::CreateJSObject() js::SetProxyReservedSlot(m_JSObject, 0, data); } -bool CList::Script_AddItem(JSContext* cx, uint argc, JS::Value* vp) -{ - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - CList* e = static_cast(js::GetProxyPrivate(args.thisv().toObjectOrNull()).toPrivate()); - if (!e) - return false; - - ScriptInterface& scriptInterface = *ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface; - ScriptRequest rq(scriptInterface); - CGUIString text; - if (!ScriptInterface::FromJSVal(rq, args.get(0), text)) - return false; - e->AddItem(text, text); - return true; -} diff --git a/source/gui/ObjectTypes/CList.h b/source/gui/ObjectTypes/CList.h index dbf1896ad1..9ab086c091 100644 --- a/source/gui/ObjectTypes/CList.h +++ b/source/gui/ObjectTypes/CList.h @@ -60,9 +60,6 @@ public: virtual void AddItem(const CGUIString& str, const CGUIString& data); protected: - - static bool Script_AddItem(JSContext* cx, uint argc, JS::Value* vp); - /** * Sets up text, should be called every time changes has been * made that can change the visual. diff --git a/source/gui/Scripting/JSInterface_CList.cpp b/source/gui/Scripting/JSInterface_CList.cpp index b198653ee2..cd15199922 100644 --- a/source/gui/Scripting/JSInterface_CList.cpp +++ b/source/gui/Scripting/JSInterface_CList.cpp @@ -32,19 +32,36 @@ // Include the definition of the generic templates. #include "JSInterface_GUIProxy_impl.h" -namespace { - struct SData - { - JS::PersistentRootedObject m_ToString; - JS::PersistentRootedObject m_Focus; - JS::PersistentRootedObject m_Blur; - JS::PersistentRootedObject m_GetComputedSize; - JS::PersistentRootedObject m_AddItem; - }; +namespace +{ +struct SData +{ + JS::PersistentRootedObject m_ToString; + JS::PersistentRootedObject m_Focus; + JS::PersistentRootedObject m_Blur; + JS::PersistentRootedObject m_GetComputedSize; + JS::PersistentRootedObject m_AddItem; +}; + +bool CList_AddItem(JSContext* cx, uint argc, JS::Value* vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + CList* e = static_cast(js::GetProxyPrivate(args.thisv().toObjectOrNull()).toPrivate()); + if (!e) + return false; + + ScriptInterface& scriptInterface = *ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface; + ScriptRequest rq(scriptInterface); + CGUIString text; + if (!ScriptInterface::FromJSVal(rq, args.get(0), text)) + return false; + e->AddItem(text, text); + return true; +} } template <> -bool JSI_GUIProxy::funcGetter(JS::HandleObject proxy, const std::string& propName, JS::MutableHandleValue vp) const +bool JSI_GUIProxy::FuncGetter(JS::HandleObject proxy, const std::string& propName, JS::MutableHandleValue vp) const { const SData& data = *static_cast(js::GetProxyReservedSlot(proxy, 0).toPrivate()); if (propName == "toString") @@ -72,7 +89,7 @@ std::pair JSI_GUIProxy::CreateData(Sc data->m_Blur.init(rq.cx, JS_GetFunctionObject(JS_NewFunction(rq.cx, func(IGUIObject, blur), 0, 0, "blur"))); data->m_GetComputedSize.init(rq.cx, JS_GetFunctionObject(JS_NewFunction(rq.cx, func(IGUIObject, getComputedSize), 0, 0, "getComputedSize"))); #undef func - data->m_AddItem.init(rq.cx, JS_GetFunctionObject(JS_NewFunction(rq.cx, CList::Script_AddItem, 0, 0, "addItem"))); + data->m_AddItem.init(rq.cx, JS_GetFunctionObject(JS_NewFunction(rq.cx, CList_AddItem, 1, 0, "addItem"))); return { &Singleton(), data }; } diff --git a/source/gui/Scripting/JSInterface_CText.cpp b/source/gui/Scripting/JSInterface_CText.cpp index 2e94d4df04..203c14aa82 100644 --- a/source/gui/Scripting/JSInterface_CText.cpp +++ b/source/gui/Scripting/JSInterface_CText.cpp @@ -32,19 +32,20 @@ // Include the definition of the generic templates. #include "JSInterface_GUIProxy_impl.h" -namespace { - struct SData - { - JS::PersistentRootedObject m_ToString; - JS::PersistentRootedObject m_Focus; - JS::PersistentRootedObject m_Blur; - JS::PersistentRootedObject m_GetComputedSize; - JS::PersistentRootedObject m_GetTextSize; - }; +namespace +{ +struct SData +{ + JS::PersistentRootedObject m_ToString; + JS::PersistentRootedObject m_Focus; + JS::PersistentRootedObject m_Blur; + JS::PersistentRootedObject m_GetComputedSize; + JS::PersistentRootedObject m_GetTextSize; +}; } template <> -bool JSI_GUIProxy::funcGetter(JS::HandleObject proxy, const std::string& propName, JS::MutableHandleValue vp) const +bool JSI_GUIProxy::FuncGetter(JS::HandleObject proxy, const std::string& propName, JS::MutableHandleValue vp) const { const SData& data = *static_cast(js::GetProxyReservedSlot(proxy, 0).toPrivate()); if (propName == "toString") diff --git a/source/gui/Scripting/JSInterface_GUIProxy.h b/source/gui/Scripting/JSInterface_GUIProxy.h index bc22f2753e..07763fe202 100644 --- a/source/gui/Scripting/JSInterface_GUIProxy.h +++ b/source/gui/Scripting/JSInterface_GUIProxy.h @@ -64,7 +64,7 @@ protected: // This handles returning function properties. // Specialize this. - bool funcGetter(JS::HandleObject proxy, const std::string& propName, JS::MutableHandleValue vp) const; + bool FuncGetter(JS::HandleObject proxy, const std::string& propName, JS::MutableHandleValue vp) const; protected: // BaseProxyHandler interface below diff --git a/source/gui/Scripting/JSInterface_GUIProxy_impl.h b/source/gui/Scripting/JSInterface_GUIProxy_impl.h index a7ce2f5d9b..1e4cf49d87 100644 --- a/source/gui/Scripting/JSInterface_GUIProxy_impl.h +++ b/source/gui/Scripting/JSInterface_GUIProxy_impl.h @@ -66,7 +66,7 @@ bool JSI_GUIProxy::get(JSContext* cx, JS::HandleObject proxy, JS::HandleValue return false; // Return function properties. Specializable. - if (funcGetter(proxy, propName, vp)) + if (FuncGetter(proxy, propName, vp)) return true; // Use onWhatever to access event handlers diff --git a/source/gui/Scripting/JSInterface_IGUIObject.cpp b/source/gui/Scripting/JSInterface_IGUIObject.cpp index dfe0300cef..3b9458bafc 100644 --- a/source/gui/Scripting/JSInterface_IGUIObject.cpp +++ b/source/gui/Scripting/JSInterface_IGUIObject.cpp @@ -32,18 +32,19 @@ // Include the definition of the generic templates. #include "JSInterface_GUIProxy_impl.h" -namespace { - struct SData - { - JS::PersistentRootedObject m_ToString; - JS::PersistentRootedObject m_Focus; - JS::PersistentRootedObject m_Blur; - JS::PersistentRootedObject m_GetComputedSize; - }; +namespace +{ +struct SData +{ + JS::PersistentRootedObject m_ToString; + JS::PersistentRootedObject m_Focus; + JS::PersistentRootedObject m_Blur; + JS::PersistentRootedObject m_GetComputedSize; +}; } template <> -bool JSI_GUIProxy::funcGetter(JS::HandleObject proxy, const std::string& propName, JS::MutableHandleValue vp) const +bool JSI_GUIProxy::FuncGetter(JS::HandleObject proxy, const std::string& propName, JS::MutableHandleValue vp) const { const SData& data = *static_cast(js::GetProxyReservedSlot(proxy, 0).toPrivate()); if (propName == "toString")