From e74181dee038f7cbcf96ff3b51a91d43d3f78921 Mon Sep 17 00:00:00 2001 From: Thilo Graf Date: Sun, 8 Sep 2019 16:41:07 +0200 Subject: [PATCH] lua_messagbox.cpp: add parameter for text allign --- src/gui/lua/lua_api_version.h | 2 +- src/gui/lua/lua_messagebox.cpp | 32 +++++++++++++++++++++++++++++--- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/gui/lua/lua_api_version.h b/src/gui/lua/lua_api_version.h index ba4235c6b..c7f79df4a 100644 --- a/src/gui/lua/lua_api_version.h +++ b/src/gui/lua/lua_api_version.h @@ -4,4 +4,4 @@ * to luainstance.h changes */ #define LUA_API_VERSION_MAJOR 1 -#define LUA_API_VERSION_MINOR 80 +#define LUA_API_VERSION_MINOR 81 diff --git a/src/gui/lua/lua_messagebox.cpp b/src/gui/lua/lua_messagebox.cpp index f3fd051bc..8d226f624 100644 --- a/src/gui/lua/lua_messagebox.cpp +++ b/src/gui/lua/lua_messagebox.cpp @@ -27,6 +27,7 @@ #include #include +#include #include #include @@ -62,14 +63,15 @@ int CLuaInstMessagebox::MessageboxExec(lua_State *L) { lua_assert(lua_istable(L,1)); - std::string name, text, icon = std::string(NEUTRINO_ICON_INFO); + std::string name, text, icon = std::string(NEUTRINO_ICON_INFO), txtMode = ""; tableLookup(L, "name", name) || tableLookup(L, "title", name) || tableLookup(L, "caption", name); tableLookup(L, "text", text); tableLookup(L, "icon", icon); - lua_Integer timeout = -1, width = MSGBOX_MIN_WIDTH, return_default_on_timeout = 0, show_buttons = 0, default_button = 0; + lua_Integer timeout = -1, width = MSGBOX_MIN_WIDTH, return_default_on_timeout = 0, show_buttons = 0, default_button = 0, text_mode = 0; tableLookup(L, "timeout", timeout); tableLookup(L, "width", width); tableLookup(L, "return_default_on_timeout", return_default_on_timeout); + tableLookup(L, "text_mode", txtMode); std::string tmp; if (tableLookup(L, "align", tmp)) { @@ -127,7 +129,31 @@ int CLuaInstMessagebox::MessageboxExec(lua_State *L) } } - int res = ShowMsg(name, text, (CMsgBox::msg_result_t) default_button, (CMsgBox::button_define_t) show_buttons, icon.empty() ? NULL : icon.c_str(), width, timeout, return_default_on_timeout); + if (!txtMode.empty()) { + table_key txt_align[] = { + { "ALIGN_AUTO_WIDTH", CTextBox::AUTO_WIDTH }, + { "ALIGN_AUTO_HIGH", CTextBox::AUTO_HIGH }, + { "ALIGN_SCROLL", CTextBox::SCROLL }, + { "ALIGN_CENTER", CTextBox::CENTER }, + { "ALIGN_RIGHT", CTextBox::RIGHT }, + { "ALIGN_TOP", CTextBox::TOP }, + { "ALIGN_BOTTOM", CTextBox::BOTTOM }, + { "ALIGN_NO_AUTO_LINEBREAK", CTextBox::NO_AUTO_LINEBREAK }, + { "DECODE_HTML", 0 }, + { NULL, 0 } + }; + for (int i = 0; txt_align[i].name; i++) { + if (txtMode.find(txt_align[i].name) != std::string::npos){ + text_mode |= txt_align[i].code; + } + } + if (txtMode.find("DECODE_HTML") != std::string::npos) + htmlEntityDecode(text); + } + else + text_mode = DEFAULT_MSGBOX_TEXT_MODE; + + int res = ShowMsg(name, text, (CMsgBox::msg_result_t) default_button, (CMsgBox::button_define_t) show_buttons, icon.empty() ? NULL : icon.c_str(), width, timeout, return_default_on_timeout, text_mode); tmp = "cancel"; for (int i = 0; mbr[i].name; i++)