summaryrefslogtreecommitdiff
path: root/plugins/MirLua/src/m_options.cpp
diff options
context:
space:
mode:
authorAlexander Lantsev <aunsane@gmail.com>2016-06-16 07:09:26 +0000
committerAlexander Lantsev <aunsane@gmail.com>2016-06-16 07:09:26 +0000
commit4958934c982cada1dc6b4abe17a7e53fde114632 (patch)
treec8f28b822c12c636c8e07c0941cb6179870887e9 /plugins/MirLua/src/m_options.cpp
parent90615025c28328bd566de8624c1aa224c3216d22 (diff)
MirLua: added forgotten file
git-svn-id: http://svn.miranda-ng.org/main/trunk@16986 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/MirLua/src/m_options.cpp')
-rw-r--r--plugins/MirLua/src/m_options.cpp114
1 files changed, 114 insertions, 0 deletions
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