From aede5032296f9d2ff9b3de6787c5493254d00e2e Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Sat, 4 Jul 2015 14:18:06 +0000 Subject: MirLua: added module m_message git-svn-id: http://svn.miranda-ng.org/main/trunk@14487 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/MirLua/src/m_message.cpp | 65 +++++++++++++++++++++++++++++++ plugins/MirLua/src/mlua.cpp | 2 +- plugins/MirLua/src/mlua_module_loader.cpp | 3 +- plugins/MirLua/src/stdafx.h | 4 ++ 4 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 plugins/MirLua/src/m_message.cpp (limited to 'plugins/MirLua') diff --git a/plugins/MirLua/src/m_message.cpp b/plugins/MirLua/src/m_message.cpp new file mode 100644 index 0000000000..f788b93f19 --- /dev/null +++ b/plugins/MirLua/src/m_message.cpp @@ -0,0 +1,65 @@ +#include "stdafx.h" + +static int lua_Paste(lua_State *L) +{ + MCONTACT hContect = luaL_checkinteger(L, 1); + ptrT text(mir_utf8decodeT(luaL_checkstring(L, 2))); + + MessageWindowInputData mwid = { sizeof(MessageWindowInputData) }; + mwid.hContact = luaL_checkinteger(L, 1); + mwid.uFlags = MSG_WINDOW_UFLAG_MSG_BOTH; + + MessageWindowData mwd = { sizeof(MessageWindowData) }; + + INT_PTR res = ::CallService(MS_MSG_GETWINDOWDATA, (WPARAM)&mwid, (LPARAM)&mwd); + lua_pushinteger(L, res); + if (res) + return 1; + + HWND hEdit = GetDlgItem(mwd.hwndWindow, 1002 /*IDC_MESSAGE*/); + if (!hEdit) hEdit = GetDlgItem(mwd.hwndWindow, 1009 /*IDC_CHATMESSAGE*/); + + SendMessage(hEdit, EM_REPLACESEL, TRUE, (LPARAM)text); + + return 1; +} + +static int lua_Send(lua_State *L) +{ + MCONTACT hContect = luaL_checkinteger(L, 1); + ptrT text(mir_utf8decodeT(luaL_checkstring(L, 2))); + + MessageWindowInputData mwid = { sizeof(MessageWindowInputData) }; + mwid.hContact = luaL_checkinteger(L, 1); + mwid.uFlags = MSG_WINDOW_UFLAG_MSG_BOTH; + + MessageWindowData mwd = { sizeof(MessageWindowData) }; + + INT_PTR res = ::CallService(MS_MSG_GETWINDOWDATA, (WPARAM)&mwid, (LPARAM)&mwd); + lua_pushinteger(L, res); + if (res) + return 1; + + HWND hEdit = GetDlgItem(mwd.hwndWindow, 1002 /*IDC_MESSAGE*/); + if (!hEdit) hEdit = GetDlgItem(mwd.hwndWindow, 1009 /*IDC_CHATMESSAGE*/); + + SendMessage(hEdit, EM_REPLACESEL, TRUE, (LPARAM)text); + SendMessage(mwd.hwndWindow, WM_COMMAND, IDOK, 0); + + return 1; +} + +static luaL_Reg messageApi[] = +{ + { "Paste", lua_Paste }, + { "Send", lua_Send }, + + { NULL, NULL } +}; + +LUAMOD_API int luaopen_m_message(lua_State *L) +{ + luaL_newlib(L, messageApi); + + return 1; +} diff --git a/plugins/MirLua/src/mlua.cpp b/plugins/MirLua/src/mlua.cpp index 253bd2b64e..0e78810fba 100644 --- a/plugins/MirLua/src/mlua.cpp +++ b/plugins/MirLua/src/mlua.cpp @@ -25,7 +25,7 @@ void CMLua::Load() lua_pop(L, 1); lua_getglobal(L, "_G"); - lua_pushcclosure(L, luaM_print, 0); + lua_pushcclosure(L, luaM_print, 0); lua_setfield(L, -2, "print"); lua_pop(L, 1); diff --git a/plugins/MirLua/src/mlua_module_loader.cpp b/plugins/MirLua/src/mlua_module_loader.cpp index 5be361fce6..386b592831 100644 --- a/plugins/MirLua/src/mlua_module_loader.cpp +++ b/plugins/MirLua/src/mlua_module_loader.cpp @@ -21,8 +21,9 @@ void CLuaModuleLoader::LoadModules() PreloadModule(MLUA_DATABASE, luaopen_m_database); PreloadModule(MLUA_ICOLIB, luaopen_m_icolib); PreloadModule(MLUA_GENMENU, luaopen_m_genmenu); + PreloadModule(MLUA_MESSAGE, luaopen_m_message); PreloadModule(MLUA_MSGBUTTONSBAR, luaopen_m_msg_buttonsbar); - PreloadModule(MLUA_POPUP, luaopen_m_popup); + PreloadModule(MLUA_POPUP, luaopen_m_popup); PreloadModule(MLUA_TOPTOOLBAR, luaopen_m_toptoolbar); PreloadModule(MLUA_VARIABLES, luaopen_m_variables); } diff --git a/plugins/MirLua/src/stdafx.h b/plugins/MirLua/src/stdafx.h index 1b463b564a..6ceb174e11 100644 --- a/plugins/MirLua/src/stdafx.h +++ b/plugins/MirLua/src/stdafx.h @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -72,6 +73,9 @@ LUAMOD_API int (luaopen_m_icolib)(lua_State *L); #include "m_genmenu.h" +#define MLUA_MESSAGE "m_message" +LUAMOD_API int (luaopen_m_message)(lua_State *L); + #define MLUA_MSGBUTTONSBAR "m_msg_buttonsbar" LUAMOD_API int (luaopen_m_msg_buttonsbar)(lua_State *L); -- cgit v1.2.3