From 81608cbd3f6a52d184430eca3edb1bb8d72cceb7 Mon Sep 17 00:00:00 2001 From: "M. Liebmann" Date: Sun, 16 Mar 2014 11:56:53 +0100 Subject: [PATCH] CLuaInstance::ComponentsTextNew: Add 'parent' parameter... ...for the integration of ctext in a parent cwindow --- src/gui/luainstance.cpp | 29 ++++++++++++++++------------- src/gui/luainstance.h | 5 +++-- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/gui/luainstance.cpp b/src/gui/luainstance.cpp index cc9d2a94d..2375a1375 100644 --- a/src/gui/luainstance.cpp +++ b/src/gui/luainstance.cpp @@ -1553,6 +1553,7 @@ int CLuaInstance::ComponentsTextNew(lua_State *L) { lua_assert(lua_istable(L,1)); + CLuaCWindow* parent = NULL; int x=10, y=10, dx=100, dy=100; std::string text = ""; std::string tmpMode = ""; @@ -1564,6 +1565,7 @@ int CLuaInstance::ComponentsTextNew(lua_State *L) lua_Integer color_shadow = (lua_Integer)COL_MENUCONTENTDARK_PLUS_0; std::string tmp1 = "false"; + tableLookup(L, "parent" , (void**)&parent); tableLookup(L, "x" , x); tableLookup(L, "y" , y); tableLookup(L, "dx" , dx); @@ -1602,9 +1604,12 @@ int CLuaInstance::ComponentsTextNew(lua_State *L) htmlEntityDecode(text); } + CComponentsForm* pw = (parent && parent->w) ? parent->w->getBodyObject() : NULL; + CLuaComponentsText **udata = (CLuaComponentsText **) lua_newuserdata(L, sizeof(CLuaComponentsText *)); *udata = new CLuaComponentsText(); - (*udata)->ct = new CComponentsText(x, y, dx, dy, text, mode, g_Font[font_text], NULL, has_shadow, (fb_pixel_t)color_text, (fb_pixel_t)color_frame, (fb_pixel_t)color_body, (fb_pixel_t)color_shadow); + (*udata)->ct = new CComponentsText(x, y, dx, dy, text, mode, g_Font[font_text], pw, has_shadow, (fb_pixel_t)color_text, (fb_pixel_t)color_frame, (fb_pixel_t)color_body, (fb_pixel_t)color_shadow); + (*udata)->parent = pw; luaL_getmetatable(L, "ctext"); lua_setmetatable(L, -2); return 1; @@ -1613,14 +1618,13 @@ int CLuaInstance::ComponentsTextNew(lua_State *L) int CLuaInstance::ComponentsTextPaint(lua_State *L) { lua_assert(lua_istable(L,1)); + CLuaComponentsText *m = ComponentsTextCheck(L, 1); + if (!m) return 0; + std::string tmp = "true"; tableLookup(L, "do_save_bg", tmp); bool do_save_bg = (tmp == "true" || tmp == "1" || tmp == "yes"); - CLuaComponentsText *m = ComponentsTextCheck(L, 1); - if (!m) - return 0; - m->ct->paint(do_save_bg); return 0; } @@ -1628,29 +1632,28 @@ int CLuaInstance::ComponentsTextPaint(lua_State *L) int CLuaInstance::ComponentsTextHide(lua_State *L) { lua_assert(lua_istable(L,1)); + CLuaComponentsText *m = ComponentsTextCheck(L, 1); + if (!m) return 0; + std::string tmp = "false"; tableLookup(L, "no_restore", tmp); bool no_restore = (tmp == "true" || tmp == "1" || tmp == "yes"); - CLuaComponentsText *m = ComponentsTextCheck(L, 1); - if (!m) - return 0; - m->ct->hide(no_restore); + return 0; } int CLuaInstance::ComponentsTextScroll(lua_State *L) { lua_assert(lua_istable(L,1)); + CLuaComponentsText *m = ComponentsTextCheck(L, 1); + if (!m) return 0; + std::string tmp = "true"; tableLookup(L, "dir", tmp); bool scrollDown = (tmp == "down" || tmp == "1"); - CLuaComponentsText *m = ComponentsTextCheck(L, 1); - if (!m) - return 0; - //get the textbox instance from lua object and use CTexBbox scroll methods CTextBox* ctb = m->ct->getCTextBoxObject(); if (ctb) { diff --git a/src/gui/luainstance.h b/src/gui/luainstance.h index 93d66af6e..711a2895c 100644 --- a/src/gui/luainstance.h +++ b/src/gui/luainstance.h @@ -138,8 +138,9 @@ class CLuaComponentsText { public: CComponentsText *ct; - CLuaComponentsText() { ct = NULL; } - ~CLuaComponentsText() { delete ct; } + CComponentsForm *parent; + CLuaComponentsText() { ct = NULL; parent = NULL;} + ~CLuaComponentsText() { if (parent == NULL) delete ct; } };