summaryrefslogtreecommitdiff
path: root/plugins/MirLua
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/MirLua')
-rw-r--r--plugins/MirLua/src/m_toptoolbar.cpp60
-rw-r--r--plugins/MirLua/src/m_toptoolbar.h9
-rw-r--r--plugins/MirLua/src/mlua.cpp3
-rw-r--r--plugins/MirLua/src/stdafx.h3
4 files changed, 68 insertions, 7 deletions
diff --git a/plugins/MirLua/src/m_toptoolbar.cpp b/plugins/MirLua/src/m_toptoolbar.cpp
index 0a17afa9cd..fcc5208bef 100644
--- a/plugins/MirLua/src/m_toptoolbar.cpp
+++ b/plugins/MirLua/src/m_toptoolbar.cpp
@@ -1,12 +1,37 @@
#include "stdafx.h"
+struct HandleTBBParam
+{
+ HANDLE h;
+ TTBButton* tbb;
+ HandleTBBParam(HANDLE h, TTBButton* tbb) : h(h), tbb(tbb) { }
+};
+
+static LIST<void> TBButtons(1, HandleKeySortT);
+
+void KillModuleTTBButton()
+{
+ while (TBButtons.getCount())
+ {
+ HandleTBBParam* param = (HandleTBBParam*)TBButtons[0];
+ ::CallService(MS_TTB_REMOVEBUTTON, (WPARAM)param->h, 0);
+ TBButtons.remove(0);
+ mir_free(param->tbb->name);
+ mir_free(param->tbb->pszTooltipUp);
+ mir_free(param->tbb->pszTooltipDn);
+ mir_free(param->tbb);
+ delete param;
+ }
+}
+
static TTBButton* MakeTBButton(lua_State *L)
{
TTBButton *tbb = (TTBButton*)mir_calloc(sizeof(TTBButton));
+ tbb->dwFlags = TTBBF_ISLBUTTON;
lua_pushliteral(L, "Name");
lua_gettable(L, -2);
- tbb->name = mir_utf8decode((char*)luaL_checkstring(L, -1), NULL);
+ tbb->name = mir_utf8decodeA(luaL_checkstring(L, -1));
lua_pop(L, 1);
lua_pushliteral(L, "Service");
@@ -19,6 +44,9 @@ static TTBButton* MakeTBButton(lua_State *L)
tbb->dwFlags = lua_tointeger(L, -1);
lua_pop(L, 1);
+ if (!(tbb->dwFlags & TTBBF_ISLBUTTON))
+ tbb->dwFlags |= TTBBF_ISLBUTTON;
+
// up state
lua_pushliteral(L, "IconUp");
lua_gettable(L, -2);
@@ -27,7 +55,7 @@ static TTBButton* MakeTBButton(lua_State *L)
lua_pushliteral(L, "TooltipUp");
lua_gettable(L, -2);
- tbb->pszTooltipUp = mir_utf8decode((char*)lua_tostring(L, -1), NULL);
+ tbb->pszTooltipUp = mir_utf8decodeA(lua_tostring(L, -1));
lua_pop(L, 1);
lua_pushliteral(L, "wParamUp");
@@ -48,7 +76,7 @@ static TTBButton* MakeTBButton(lua_State *L)
lua_pushliteral(L, "TooltipDown");
lua_gettable(L, -2);
- tbb->pszTooltipDn = mir_utf8decode((char*)lua_tostring(L, -1), NULL);
+ tbb->pszTooltipDn = mir_utf8decodeA(lua_tostring(L, -1));
lua_pop(L, 1);
lua_pushliteral(L, "wParamDown");
@@ -72,11 +100,21 @@ static int lua_AddButton(lua_State *L)
return 1;
}
- mir_ptr<TTBButton> tbb(MakeTBButton(L));
+ TTBButton* tbb = MakeTBButton(L);
HANDLE res = ::TopToolbar_AddButton(tbb);
lua_pushlightuserdata(L, res);
+ if (res != INVALID_HANDLE_VALUE)
+ TBButtons.insert(new HandleTBBParam(res, tbb));
+ else
+ {
+ mir_free(tbb->name);
+ mir_free(tbb->pszTooltipUp);
+ mir_free(tbb->pszTooltipDn);
+ mir_free(tbb);
+ }
+
return 1;
}
@@ -87,6 +125,20 @@ static int lua_RemoveButton(lua_State *L)
INT_PTR res = ::CallService(MS_TTB_REMOVEBUTTON, (WPARAM)hTTButton, 0);
lua_pushinteger(L, res);
+ if (!res)
+ {
+ HandleTBBParam* param = (HandleTBBParam*)TBButtons.find(&hTTButton);
+ if (param)
+ {
+ TBButtons.remove(param);
+ mir_free(param->tbb->name);
+ mir_free(param->tbb->pszTooltipUp);
+ mir_free(param->tbb->pszTooltipDn);
+ mir_free(param->tbb);
+ delete param;
+ }
+ }
+
return 1;
}
diff --git a/plugins/MirLua/src/m_toptoolbar.h b/plugins/MirLua/src/m_toptoolbar.h
new file mode 100644
index 0000000000..945fde68a3
--- /dev/null
+++ b/plugins/MirLua/src/m_toptoolbar.h
@@ -0,0 +1,9 @@
+#ifndef _LUA_M_TOPTOOLBAR_H_
+#define _LUA_M_TOPTOOLBAR_H_
+
+#define MLUA_TOPTOOLBAR "m_toptoolbar"
+LUAMOD_API int (luaopen_m_toptoolbar)(lua_State *L);
+
+void KillModuleTTBButton();
+
+#endif //_LUA_M_TOPTOOLBAR_H_ \ No newline at end of file
diff --git a/plugins/MirLua/src/mlua.cpp b/plugins/MirLua/src/mlua.cpp
index e65ad4c8b9..6da603358d 100644
--- a/plugins/MirLua/src/mlua.cpp
+++ b/plugins/MirLua/src/mlua.cpp
@@ -66,7 +66,8 @@ void CMLua::Unload()
}
::KillModuleMBButtons();
-
+ ::KillModuleTTBButton();
+
::KillModuleIcons(hScriptsLangpack);
::KillModuleMenus(hScriptsLangpack);
::KillModuleHotkeys(hScriptsLangpack);
diff --git a/plugins/MirLua/src/stdafx.h b/plugins/MirLua/src/stdafx.h
index 232d1eeef3..4e3f764cb9 100644
--- a/plugins/MirLua/src/stdafx.h
+++ b/plugins/MirLua/src/stdafx.h
@@ -91,8 +91,7 @@ LUAMOD_API int (luaopen_m_popup)(lua_State *L);
#define MLUA_PROTOCOLS "m_protocols"
LUAMOD_API int (luaopen_m_protocols)(lua_State *L);
-#define MLUA_TOPTOOLBAR "m_toptoolbar"
-LUAMOD_API int (luaopen_m_toptoolbar)(lua_State *L);
+#include "m_toptoolbar.h"
#define MLUA_VARIABLES "m_variables"
LUAMOD_API int (luaopen_m_variables)(lua_State *L);