diff options
-rw-r--r-- | plugins/MirLua/docs/examples/popup.lua | 19 | ||||
-rw-r--r-- | plugins/MirLua/docs/examples/toptoolbar.lua | 2 | ||||
-rw-r--r-- | plugins/MirLua/src/m_genmenu.cpp | 10 | ||||
-rw-r--r-- | plugins/MirLua/src/m_popup.cpp | 77 | ||||
-rw-r--r-- | plugins/MirLua/src/mlua.cpp | 1 | ||||
-rw-r--r-- | plugins/MirLua/src/stdafx.h | 7 |
6 files changed, 109 insertions, 7 deletions
diff --git a/plugins/MirLua/docs/examples/popup.lua b/plugins/MirLua/docs/examples/popup.lua new file mode 100644 index 0000000000..395f650267 --- /dev/null +++ b/plugins/MirLua/docs/examples/popup.lua @@ -0,0 +1,19 @@ +--- include m_popup module +local popup = require('m_popup') +--- include m_genmenu module +local genmenu = require('m_genmenu') + +m.CreateServiceFunction('MirLua/ShowPopup', function() + local popupData = + { + Title = 'Title', + Text = 'Popup content', + hContact = 0, + Flags = 1 + } + popup.AddPopup(popupData) + end) + +m.OnModulesLoaded(function() + genmenu.AddMainMenuItem({ Name = "Show lua popup", Service = 'MirLua/ShowPopup' }) +end) diff --git a/plugins/MirLua/docs/examples/toptoolbar.lua b/plugins/MirLua/docs/examples/toptoolbar.lua index ea24ec31e1..d942927fd5 100644 --- a/plugins/MirLua/docs/examples/toptoolbar.lua +++ b/plugins/MirLua/docs/examples/toptoolbar.lua @@ -3,7 +3,7 @@ local ttb = require('m_toptoolbar') --- include m_icolib module local icolib = require('m_icolib') -local TTBBF_VISIBLE = tonumber("0x0002", 16) +local TTBBF_VISIBLE = tonumber("0002", 16) m.OnModulesLoaded(function() ttb.OnTopToolBarLoaded(function() diff --git a/plugins/MirLua/src/m_genmenu.cpp b/plugins/MirLua/src/m_genmenu.cpp index 2e4445d71d..fb651b1515 100644 --- a/plugins/MirLua/src/m_genmenu.cpp +++ b/plugins/MirLua/src/m_genmenu.cpp @@ -5,6 +5,11 @@ static CLISTMENUITEM* MakeMenuItem(lua_State *L) CLISTMENUITEM *pmi = (CLISTMENUITEM*)mir_calloc(sizeof(CLISTMENUITEM));
pmi->cbSize = sizeof(CLISTMENUITEM);
+ lua_pushstring(L, "Flags");
+ lua_gettable(L, -2);
+ pmi->flags = lua_tointeger(L, -1);
+ lua_pop(L, 1);
+
lua_pushstring(L, "Name");
lua_gettable(L, -2);
if (!(pmi->flags & CMIF_UNICODE))
@@ -13,11 +18,6 @@ static CLISTMENUITEM* MakeMenuItem(lua_State *L) pmi->ptszName = mir_utf8decodeT((char*)luaL_checkstring(L, -1));
lua_pop(L, 1);
- lua_pushstring(L, "Flags");
- lua_gettable(L, -2);
- pmi->flags = lua_tointeger(L, -1);
- lua_pop(L, 1);
-
lua_pushstring(L, "Position");
lua_gettable(L, -2);
pmi->position = lua_tointeger(L, -1);
diff --git a/plugins/MirLua/src/m_popup.cpp b/plugins/MirLua/src/m_popup.cpp new file mode 100644 index 0000000000..8f32889f4f --- /dev/null +++ b/plugins/MirLua/src/m_popup.cpp @@ -0,0 +1,77 @@ +#include "stdafx.h"
+
+static POPUPDATA2* MakePopupData(lua_State *L)
+{
+ POPUPDATA2 *ppd = (POPUPDATA2*)mir_calloc(sizeof(POPUPDATA2));
+ ppd->cbSize = sizeof(POPUPDATA2);
+
+ lua_pushstring(L, "Flags");
+ lua_gettable(L, -2);
+ ppd->flags = lua_tointeger(L, -1);
+ lua_pop(L, 1);
+
+ if (!(ppd->flags & PU2_TCHAR))
+ ppd->flags | PU2_TCHAR;
+
+ lua_pushstring(L, "Title");
+ lua_gettable(L, -2);
+ ppd->lptzTitle = mir_utf8decodeT((char*)lua_tostring(L, -1));
+ lua_pop(L, 1);
+
+ lua_pushstring(L, "Text");
+ lua_gettable(L, -2);
+ ppd->lptzText = mir_utf8decodeT((char*)luaL_checkstring(L, -1));
+ lua_pop(L, 1);
+
+ lua_pushstring(L, "hContact");
+ lua_gettable(L, -2);
+ ppd->lchContact = lua_tointeger(L, -1);
+ lua_pop(L, 1);
+
+ lua_pushstring(L, "hEvent");
+ lua_gettable(L, -2);
+ ppd->lchEvent = lua_touserdata(L, -1);
+ lua_pop(L, 1);
+
+ lua_pushstring(L, "Timestamp");
+ lua_gettable(L, -2);
+ ppd->dwTimestamp = lua_tonumber(L, -1);
+ lua_pop(L, 1);
+
+ lua_pushstring(L, "Timeout");
+ lua_gettable(L, -2);
+ ppd->iSeconds = lua_tointeger(L, -1);
+ lua_pop(L, 1);
+
+ return ppd;
+}
+
+static int lua_AddPoput(lua_State *L)
+{
+ if (lua_type(L, 1) != LUA_TTABLE)
+ {
+ lua_pushlightuserdata(L, 0);
+ return 1;
+ }
+
+ mir_ptr<POPUPDATA2> ppd(MakePopupData(L));
+
+ INT_PTR res = ::CallService(MS_POPUP_ADDPOPUP2, (WPARAM)ppd, 0);
+ lua_pushinteger(L, res);
+
+ return 1;
+}
+
+static luaL_Reg popupApi[] =
+{
+ { "AddPopup", lua_AddPoput },
+
+ { NULL, NULL }
+};
+
+LUAMOD_API int luaopen_m_popup(lua_State *L)
+{
+ luaL_newlib(L, popupApi);
+
+ return 1;
+}
diff --git a/plugins/MirLua/src/mlua.cpp b/plugins/MirLua/src/mlua.cpp index cf3562bedc..9c5f9a8906 100644 --- a/plugins/MirLua/src/mlua.cpp +++ b/plugins/MirLua/src/mlua.cpp @@ -21,6 +21,7 @@ CMLua::CMLua() : L(NULL) Preload(MLUA_ICOLIB, luaopen_m_icolib);
Preload(MLUA_GENMENU, luaopen_m_genmenu);
Preload(MLUA_MSGBUTTONSBAR, luaopen_m_msg_buttonsbar);
+ Preload(MLUA_POPUP, luaopen_m_popup);
Preload(MLUA_TOPTOOLBAR, luaopen_m_toptoolbar);
Preload(MLUA_VARIABLES, luaopen_m_variables);
}
diff --git a/plugins/MirLua/src/stdafx.h b/plugins/MirLua/src/stdafx.h index 778b6a1185..f31ee69800 100644 --- a/plugins/MirLua/src/stdafx.h +++ b/plugins/MirLua/src/stdafx.h @@ -17,8 +17,9 @@ #include <m_icolib.h>
#include <m_folders.h>
-#include <m_toptoolbar.h>
#include <m_msg_buttonsbar.h>
+#include <m_popup.h>
+#include <m_toptoolbar.h>
#include <m_variables.h>
extern "C"
@@ -63,10 +64,14 @@ LUAMOD_API int (luaopen_m_genmenu)(lua_State *L); #define MLUA_MSGBUTTONSBAR "m_msg_buttonsbar"
LUAMOD_API int (luaopen_m_msg_buttonsbar)(lua_State *L);
+#define MLUA_POPUP "m_popup"
+LUAMOD_API int (luaopen_m_popup)(lua_State *L);
+
#define MLUA_TOPTOOLBAR "m_toptoolbar"
LUAMOD_API int (luaopen_m_toptoolbar)(lua_State *L);
#define MLUA_VARIABLES "m_variables"
LUAMOD_API int (luaopen_m_variables)(lua_State *L);
+
#endif //_COMMON_H_
|