From 8c406aebce15a05f136ac8e38397306a7d8d3976 Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Sun, 26 Jul 2015 13:52:16 +0000 Subject: MirLua will remove toolbar buttons on script reloading git-svn-id: http://svn.miranda-ng.org/main/trunk@14729 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/MirLua/src/m_toptoolbar.cpp | 60 ++++++++++++++++++++++++++++++++++--- 1 file changed, 56 insertions(+), 4 deletions(-) (limited to 'plugins/MirLua/src/m_toptoolbar.cpp') 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 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 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; } -- cgit v1.2.3