From 4958934c982cada1dc6b4abe17a7e53fde114632 Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Thu, 16 Jun 2016 07:09:26 +0000 Subject: MirLua: added forgotten file git-svn-id: http://svn.miranda-ng.org/main/trunk@16986 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/MirLua/src/m_options.cpp | 114 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 plugins/MirLua/src/m_options.cpp (limited to 'plugins/MirLua/src/m_options.cpp') diff --git a/plugins/MirLua/src/m_options.cpp b/plugins/MirLua/src/m_options.cpp new file mode 100644 index 0000000000..0ecce9c864 --- /dev/null +++ b/plugins/MirLua/src/m_options.cpp @@ -0,0 +1,114 @@ +#include "stdafx.h" + +class CMLuaScriptOptionPage : public CDlgBase +{ +private: + CMLuaScript *script; + int onInitDialogRef; + int onApplyRef; + +public: + CMLuaScriptOptionPage(CMLuaScript *script, int onInitDialogRef, int onApplyRef) + : CDlgBase(g_hInstance, IDD_SCRIPTOPTIONSPAGE), script(script), + onInitDialogRef(onInitDialogRef), onApplyRef(onApplyRef) + { + } + +protected: + void OnInitDialog() + { + if (onInitDialogRef) + { + lua_rawgeti(script->L, LUA_REGISTRYINDEX, onInitDialogRef); + + lua_pushlightuserdata(script->L, (void*)this->GetHwnd()); + luaM_pcall(script->L, 1, 0); + } + } + + void OnApply() + { + if (onApplyRef) + { + lua_rawgeti(script->L, LUA_REGISTRYINDEX, onApplyRef); + + lua_pushlightuserdata(script->L, (void*)this->GetHwnd()); + luaM_pcall(script->L, 1, 0); + } + } +}; + +void MakeOptionDialogPage(lua_State *L, OPTIONSDIALOGPAGE &odp) +{ + CMLuaScript *script = CMLuaScript::GetScriptFromEnviroment(L); + + odp.hInstance = g_hInstance; + odp.hLangpack = script->GetId(); + + lua_getfield(L, -1, "Flags"); + odp.flags = luaL_optinteger(L, -1, ODPF_BOLDGROUPS | ODPF_TCHAR | ODPF_DONTTRANSLATE); + lua_pop(L, 1); + + if (!(odp.flags & ODPF_TCHAR)) + odp.flags |= ODPF_TCHAR; + + lua_getfield(L, -1, "Group"); + odp.ptszGroup = mir_utf8decodeT((char*)lua_tostring(L, -1)); + lua_pop(L, 1); + + lua_getfield(L, -1, "Title"); + odp.ptszTitle = mir_utf8decodeT((char*)luaL_checkstring(L, -1)); + lua_pop(L, 1); + + lua_getfield(L, -1, "Tab"); + odp.ptszTab = mir_utf8decodeT((char*)lua_tostring(L, -1)); + lua_pop(L, 1); + + int onInitDialogRef = 0; + lua_getfield(L, -1, "OnInitDialog"); + if (lua_isfunction(L, -1)) + onInitDialogRef = luaL_ref(L, LUA_REGISTRYINDEX); + else + lua_pop(L, 1); + + int onApplyRef = 0; + lua_getfield(L, -1, "OnApply"); + if (lua_isfunction(L, -1)) + onApplyRef = luaL_ref(L, LUA_REGISTRYINDEX); + else + lua_pop(L, 1); + + odp.pDialog = new CMLuaScriptOptionPage(script, onInitDialogRef, onApplyRef); +} + +int opt_AddPage(lua_State *L) +{ + luaL_checktype(L, 1, LUA_TLIGHTUSERDATA); + WPARAM wParam = (WPARAM)lua_touserdata(L, 1); + + OPTIONSDIALOGPAGE odp = { 0 }; + MakeOptionDialogPage(L, odp); + + INT_PTR res = Options_AddPage(wParam, &odp); + lua_pushboolean(L, !res); + + mir_free(odp.ptszGroup); + mir_free(odp.ptszTitle); + mir_free(odp.ptszTab); + + return 1; +} + +static luaL_Reg optionsApi[] = +{ + { "AddPage", opt_AddPage }, + + { NULL, NULL } +}; + +LUAMOD_API int luaopen_m_options(lua_State *L) +{ + luaL_newlib(L, optionsApi); + + return 1; +} \ No newline at end of file -- cgit v1.2.3