summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2019-07-12 13:48:39 +0300
committerGeorge Hazan <ghazan@miranda.im>2019-07-12 13:48:39 +0300
commitd0c7ef4f48cdf9f1ad622fc84d10257c21bb91db (patch)
treeb352641bcbaf04acc8a3b1f41d37fa151997baae
parent6632ca13387288f6f2bb58d7f1aa9ea4730d9b43 (diff)
MirLua: interface for extra icons added
-rw-r--r--plugins/MirLua/MirLua.vcxproj.filters4
-rwxr-xr-xplugins/MirLua/Modules/WinAPI/src/winapi.cpp1
-rw-r--r--plugins/MirLua/src/Modules/m_database.cpp2
-rw-r--r--plugins/MirLua/src/Modules/m_extraIcon.cpp84
-rw-r--r--plugins/MirLua/src/module_loader.cpp1
-rw-r--r--plugins/MirLua/src/modules.h34
-rw-r--r--plugins/MirLua/src/stdafx.h1
7 files changed, 108 insertions, 19 deletions
diff --git a/plugins/MirLua/MirLua.vcxproj.filters b/plugins/MirLua/MirLua.vcxproj.filters
index 4109e86555..7016a8c373 100644
--- a/plugins/MirLua/MirLua.vcxproj.filters
+++ b/plugins/MirLua/MirLua.vcxproj.filters
@@ -13,13 +13,13 @@
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\Modules\*.h">
- <Filter>Header Files\Services</Filter>
+ <Filter>Header Files\Modules</Filter>
</ClInclude>
<ClCompile Include="src\*.cpp;src\*.cxx">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\Modules\*.cpp">
- <Filter>Source Files\Services</Filter>
+ <Filter>Source Files\Modules</Filter>
</ClCompile>
<ResourceCompile Include="res\*.rc">
<Filter>Resource Files</Filter>
diff --git a/plugins/MirLua/Modules/WinAPI/src/winapi.cpp b/plugins/MirLua/Modules/WinAPI/src/winapi.cpp
index 8ef0708d7d..0ed52fdcfa 100755
--- a/plugins/MirLua/Modules/WinAPI/src/winapi.cpp
+++ b/plugins/MirLua/Modules/WinAPI/src/winapi.cpp
@@ -37,7 +37,6 @@ static int lua_MessageBox(lua_State *L)
/***********************************************/
static int lua_ShellExecute(lua_State *L)
-{
ptrW command(mir_utf8decodeW(lua_tostring(L, 1)));
ptrW file(mir_utf8decodeW(lua_tostring(L, 2)));
ptrW args(mir_utf8decodeW(lua_tostring(L, 3)));
diff --git a/plugins/MirLua/src/Modules/m_database.cpp b/plugins/MirLua/src/Modules/m_database.cpp
index 78cd494517..c3df7db49e 100644
--- a/plugins/MirLua/src/Modules/m_database.cpp
+++ b/plugins/MirLua/src/Modules/m_database.cpp
@@ -379,7 +379,7 @@ static int db_ModulesIterator(lua_State *L)
LIST<char> &param = *(LIST<char>*)lua_touserdata(L, lua_upvalueindex(2));
if (i < param.getCount()) {
- lua_pushinteger(L, (i + 1));
+ lua_pushinteger(L, i + 1);
lua_replace(L, lua_upvalueindex(1));
lua_pushstring(L, ptrA(mir_utf8encode(param[i])));
mir_free(param[i]);
diff --git a/plugins/MirLua/src/Modules/m_extraIcon.cpp b/plugins/MirLua/src/Modules/m_extraIcon.cpp
new file mode 100644
index 0000000000..da25abbc12
--- /dev/null
+++ b/plugins/MirLua/src/Modules/m_extraIcon.cpp
@@ -0,0 +1,84 @@
+#include "../stdafx.h"
+
+struct EIHook
+{
+ EIHook(lua_State *_p1, int _p2) :
+ L(_p1),
+ ref(_p2)
+ {}
+
+ lua_State *L;
+ int ref;
+};
+
+static int ei_hook(WPARAM hContact, LPARAM slot, LPARAM param)
+{
+ EIHook *pHook = (EIHook *)param;
+ if (pHook) {
+ auto *L = pHook->L;
+ lua_rawgeti(L, LUA_REGISTRYINDEX, pHook->ref);
+
+ lua_pushinteger(L, hContact);
+ lua_pushinteger(L, slot);
+ luaM_pcall(L, 2, 0);
+ }
+ return 0;
+}
+
+static int ei_Register(lua_State *L)
+{
+ const char *name = luaL_checkstring(L, 1);
+ const char *descr = luaL_checkstring(L, 2);
+ HANDLE hIcolib = lua_touserdata(L, 3);
+ luaL_checktype(L, 4, LUA_TFUNCTION);
+
+ lua_pushvalue(L, 4);
+ int ref = luaL_ref(L, LUA_REGISTRYINDEX);
+
+ HANDLE res = ExtraIcon_RegisterIcolib(name, descr, hIcolib, ei_hook, (LPARAM)new EIHook(L, ref));
+ lua_pushlightuserdata(L, res);
+ return 1;
+}
+
+static int ei_SetIcon(lua_State *L)
+{
+ HANDLE hExtraIcon = lua_touserdata(L, 1);
+ int hContact = luaL_checkinteger(L, 2);
+ HANDLE hIcon = lua_touserdata(L, 3);
+ ExtraIcon_SetIcon(hExtraIcon, hContact, hIcon);
+ return 1;
+}
+
+static int ei_SetByName(lua_State *L)
+{
+ HANDLE hExtraIcon = lua_touserdata(L, 1);
+ int hContact = luaL_checkinteger(L, 2);
+ const char *icon = luaL_checkstring(L, 3);
+ ExtraIcon_SetIconByName(hExtraIcon, hContact, icon);
+ return 1;
+}
+
+static int ei_Clear(lua_State *L)
+{
+ HANDLE hExtraIcon = lua_touserdata(L, 1);
+ int hContact = luaL_checkinteger(L, 2);
+ ExtraIcon_Clear(hExtraIcon, hContact);
+ return 1;
+}
+
+static luaL_Reg eiApi[] =
+{
+ { "Register", ei_Register },
+
+ { "SetIcon", ei_SetIcon },
+ { "SetByName", ei_SetByName },
+ { "Clear", ei_Clear },
+
+ { nullptr, nullptr }
+};
+
+LUAMOD_API int luaopen_m_extraIcon(lua_State *L)
+{
+ luaL_newlib(L, eiApi);
+ return 1;
+}
diff --git a/plugins/MirLua/src/module_loader.cpp b/plugins/MirLua/src/module_loader.cpp
index 9b82f8fdcf..2153723a13 100644
--- a/plugins/MirLua/src/module_loader.cpp
+++ b/plugins/MirLua/src/module_loader.cpp
@@ -27,6 +27,7 @@ void CMLuaModuleLoader::LoadModules()
Preload(MLUA_CHAT, luaopen_m_chat);
Preload(MLUA_CLIST, luaopen_m_clist);
Preload(MLUA_DATABASE, luaopen_m_database);
+ Preload(MLUA_EXTRAICON, luaopen_m_extraIcon);
Preload(MLUA_GENMENU, luaopen_m_genmenu);
Preload(MLUA_HOTKEYS, luaopen_m_hotkeys);
Preload(MLUA_HTTP, luaopen_m_http);
diff --git a/plugins/MirLua/src/modules.h b/plugins/MirLua/src/modules.h
index 7aa4402efb..a2add45afb 100644
--- a/plugins/MirLua/src/modules.h
+++ b/plugins/MirLua/src/modules.h
@@ -1,44 +1,48 @@
#pragma once
-#define MLUA_CORE "m_core"
+#define MLUA_CORE "m_core"
LUAMOD_API int (luaopen_m_core)(lua_State *L);
-#define MLUA_CHAT "m_chat"
+#define MLUA_CHAT "m_chat"
LUAMOD_API int (luaopen_m_chat)(lua_State *L);
-#define MLUA_CLIST "m_clist"
+#define MLUA_CLIST "m_clist"
LUAMOD_API int (luaopen_m_clist)(lua_State *L);
-#define MLUA_DATABASE "m_database"
+#define MLUA_DATABASE "m_database"
LUAMOD_API int (luaopen_m_database)(lua_State *L);
-#define MLUA_ICOLIB "m_icolib"
+#define MLUA_EXTRAICON "m_extraIcon"
+LUAMOD_API int (luaopen_m_extraIcon)(lua_State *L);
+
+#define MLUA_ICOLIB "m_icolib"
LUAMOD_API int (luaopen_m_icolib)(lua_State *L);
-#define MLUA_GENMENU "m_genmenu"
+#define MLUA_GENMENU "m_genmenu"
LUAMOD_API int (luaopen_m_genmenu)(lua_State *L);
-#define MLUA_HTTP "m_http"
+#define MLUA_HTTP "m_http"
LUAMOD_API int (luaopen_m_http)(lua_State *L);
-#define MLUA_HOTKEYS "m_hotkeys"
+#define MLUA_HOTKEYS "m_hotkeys"
LUAMOD_API int (luaopen_m_hotkeys)(lua_State *L);
-#define MLUA_JSON "m_json"
+#define MLUA_JSON "m_json"
LUAMOD_API int (luaopen_m_json)(lua_State *L);
-#define MLUA_MESSAGE "m_message"
+#define MLUA_MESSAGE "m_message"
LUAMOD_API int (luaopen_m_message)(lua_State *L);
-#define MLUA_OPTIONS "m_options"
+#define MLUA_OPTIONS "m_options"
LUAMOD_API int (luaopen_m_options)(lua_State *L);
-#define MLUA_PROTOCOLS "m_protocols"
#define MT_PROTOACCOUNT "PROTOACCOUNT"
+
+#define MLUA_PROTOCOLS "m_protocols"
LUAMOD_API int (luaopen_m_protocols)(lua_State *L);
-#define MLUA_SOUNDS "m_sounds"
+#define MLUA_SOUNDS "m_sounds"
LUAMOD_API int (luaopen_m_sounds)(lua_State *L);
-#define MLUA_SRMM "m_srmm"
-LUAMOD_API int (luaopen_m_srmm)(lua_State *L); \ No newline at end of file
+#define MLUA_SRMM "m_srmm"
+LUAMOD_API int (luaopen_m_srmm)(lua_State *L);
diff --git a/plugins/MirLua/src/stdafx.h b/plugins/MirLua/src/stdafx.h
index 9c88b62ad4..d908b7b36a 100644
--- a/plugins/MirLua/src/stdafx.h
+++ b/plugins/MirLua/src/stdafx.h
@@ -13,6 +13,7 @@
#include <m_utils.h>
#include <m_langpack.h>
#include <m_database.h>
+#include <m_extraicons.h>
#include <m_options.h>
#include <m_netlib.h>
#include <m_genmenu.h>