From e1110157f8c2989a58aa12ddeef91669525d188f Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Mon, 4 Apr 2016 08:39:22 +0000 Subject: MirLua: m_toptoolbar moved to separate project git-svn-id: http://svn.miranda-ng.org/main/trunk@16583 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/ExternalAPI/m_lua.h | 43 ++++++++ .../Modules/m_toptoolbar/m_toptoolbar.vcxproj | 28 +++++ plugins/MirLua/Modules/m_toptoolbar/src/main.cpp | 103 ++++++++++++++++++ plugins/MirLua/Modules/m_toptoolbar/src/stdafx.cxx | 1 + plugins/MirLua/Modules/m_toptoolbar/src/stdafx.h | 16 +++ plugins/MirLua/src/m_toptoolbar.cpp | 119 --------------------- plugins/MirLua/src/m_toptoolbar.h | 9 -- plugins/MirLua/src/mlua.cpp | 1 - plugins/MirLua/src/mlua_module_loader.cpp | 2 - plugins/MirLua/src/mlua_utils.cpp | 37 ------- plugins/MirLua/src/stdafx.h | 6 +- 11 files changed, 192 insertions(+), 173 deletions(-) create mode 100644 plugins/ExternalAPI/m_lua.h create mode 100644 plugins/MirLua/Modules/m_toptoolbar/m_toptoolbar.vcxproj create mode 100644 plugins/MirLua/Modules/m_toptoolbar/src/main.cpp create mode 100644 plugins/MirLua/Modules/m_toptoolbar/src/stdafx.cxx create mode 100644 plugins/MirLua/Modules/m_toptoolbar/src/stdafx.h delete mode 100644 plugins/MirLua/src/m_toptoolbar.cpp delete mode 100644 plugins/MirLua/src/m_toptoolbar.h diff --git a/plugins/ExternalAPI/m_lua.h b/plugins/ExternalAPI/m_lua.h new file mode 100644 index 0000000000..6bf0ccc051 --- /dev/null +++ b/plugins/ExternalAPI/m_lua.h @@ -0,0 +1,43 @@ +#ifndef _M_LUA_H_ +#define _M_LUA_H_ + +#include + +static __inline WPARAM luaM_towparam(lua_State *L, int idx) +{ + switch (lua_type(L, idx)) + { + case LUA_TBOOLEAN: + return lua_toboolean(L, idx); + case LUA_TNUMBER: + return lua_tonumber(L, idx); + case LUA_TSTRING: + return (WPARAM)lua_tostring(L, idx); + break; + case LUA_TUSERDATA: + case LUA_TLIGHTUSERDATA: + return (WPARAM)lua_touserdata(L, idx); + default: + return NULL; + } +} + +static __inline LPARAM luaM_tolparam(lua_State *L, int idx) +{ + switch (lua_type(L, idx)) + { + case LUA_TBOOLEAN: + return lua_toboolean(L, idx); + case LUA_TNUMBER: + return lua_tonumber(L, idx); + case LUA_TSTRING: + return (LPARAM)lua_tostring(L, idx); + case LUA_TUSERDATA: + case LUA_TLIGHTUSERDATA: + return (LPARAM)lua_touserdata(L, idx); + default: + return NULL; + } +} + +#endif //_M_LUA_H_ diff --git a/plugins/MirLua/Modules/m_toptoolbar/m_toptoolbar.vcxproj b/plugins/MirLua/Modules/m_toptoolbar/m_toptoolbar.vcxproj new file mode 100644 index 0000000000..e05f3c25a9 --- /dev/null +++ b/plugins/MirLua/Modules/m_toptoolbar/m_toptoolbar.vcxproj @@ -0,0 +1,28 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + m_toptoolbar + {277E433F-7D71-4247-8AAA-CC5FB1AA7A67} + + + + + diff --git a/plugins/MirLua/Modules/m_toptoolbar/src/main.cpp b/plugins/MirLua/Modules/m_toptoolbar/src/main.cpp new file mode 100644 index 0000000000..6e488ca8c7 --- /dev/null +++ b/plugins/MirLua/Modules/m_toptoolbar/src/main.cpp @@ -0,0 +1,103 @@ +#include "stdafx.h" + +int hLangpack; + +static TTBButton* MakeTBButton(lua_State *L) +{ + TTBButton *tbb = (TTBButton*)mir_calloc(sizeof(TTBButton)); + tbb->dwFlags = TTBBF_ISLBUTTON; + + lua_getfield(L, -1, "Name"); + tbb->name = mir_utf8decodeA(luaL_checkstring(L, -1)); + lua_pop(L, 1); + + lua_getfield(L, -1, "Service"); + tbb->pszService = (char*)lua_tostring(L, -1); + lua_pop(L, 1); + + lua_getfield(L, -1, "Flags"); + tbb->dwFlags = lua_tointeger(L, -1); + lua_pop(L, 1); + + // up state + lua_getfield(L, -1, "IconUp"); + tbb->hIconHandleUp = (HANDLE)lua_touserdata(L, -1); + lua_pop(L, 1); + + lua_getfield(L, -1, "TooltipUp"); + tbb->pszTooltipUp = mir_utf8decodeA(lua_tostring(L, -1)); + lua_pop(L, 1); + + lua_getfield(L, -1, "wParamUp"); + tbb->wParamUp = luaM_towparam(L, -1); + lua_pop(L, 1); + + lua_getfield(L, -1, "lParamUp"); + tbb->lParamUp = luaM_tolparam(L, -1); + lua_pop(L, 1); + + // dn state + lua_getfield(L, -1, "IconDown"); + tbb->hIconHandleDn = (HANDLE)lua_touserdata(L, -1); + lua_pop(L, 1); + + lua_getfield(L, -1, "TooltipDown"); + tbb->pszTooltipDn = mir_utf8decodeA(lua_tostring(L, -1)); + lua_pop(L, 1); + + lua_getfield(L, -1, "wParamDown"); + tbb->wParamDown = luaM_towparam(L, -1); + lua_pop(L, 1); + + lua_getfield(L, -1, "lParamDown"); + tbb->lParamDown = luaM_tolparam(L, -1); + lua_pop(L, 1); + + return tbb; +} + +static int lua_AddButton(lua_State *L) +{ + if (lua_type(L, 1) != LUA_TTABLE) + { + lua_pushlightuserdata(L, 0); + return 1; + } + + TTBButton* tbb = MakeTBButton(L); + + HANDLE res = ::TopToolbar_AddButton(tbb); + lua_pushlightuserdata(L, res); + + mir_free(tbb->name); + mir_free(tbb->pszTooltipUp); + mir_free(tbb->pszTooltipDn); + mir_free(tbb); + + return 1; +} + +static int lua_RemoveButton(lua_State *L) +{ + HANDLE hTTButton = (HANDLE)lua_touserdata(L, 1); + + INT_PTR res = ::CallService(MS_TTB_REMOVEBUTTON, (WPARAM)hTTButton, 0); + lua_pushinteger(L, res); + + return 1; +} + +static luaL_Reg toptoolbarApi[] = +{ + { "AddButton", lua_AddButton }, + { "RemoveButton", lua_RemoveButton }, + + { NULL, NULL } +}; + +LUAMOD_API int luaopen_m_toptoolbar(lua_State *L) +{ + luaL_newlib(L, toptoolbarApi); + + return 1; +} diff --git a/plugins/MirLua/Modules/m_toptoolbar/src/stdafx.cxx b/plugins/MirLua/Modules/m_toptoolbar/src/stdafx.cxx new file mode 100644 index 0000000000..fd4f341c7b --- /dev/null +++ b/plugins/MirLua/Modules/m_toptoolbar/src/stdafx.cxx @@ -0,0 +1 @@ +#include "stdafx.h" diff --git a/plugins/MirLua/Modules/m_toptoolbar/src/stdafx.h b/plugins/MirLua/Modules/m_toptoolbar/src/stdafx.h new file mode 100644 index 0000000000..b45173f207 --- /dev/null +++ b/plugins/MirLua/Modules/m_toptoolbar/src/stdafx.h @@ -0,0 +1,16 @@ +#ifndef _COMMON_H_ +#define _COMMON_H_ + +#include + +#include +#include +#include +#include + +#define MLUA_TOPTOOLBAR "m_toptoolbar" +LUAMOD_API int (luaopen_m_toptoolbar)(lua_State *L); + +void KillModuleTTBButton(); + +#endif //_COMMON_H_ \ No newline at end of file diff --git a/plugins/MirLua/src/m_toptoolbar.cpp b/plugins/MirLua/src/m_toptoolbar.cpp deleted file mode 100644 index 310243e734..0000000000 --- a/plugins/MirLua/src/m_toptoolbar.cpp +++ /dev/null @@ -1,119 +0,0 @@ -#include "stdafx.h" - -static LIST TBButtons(1, PtrKeySortT); - -void KillModuleTTBButton() -{ - while (TBButtons.getCount()) - { - HANDLE hTTButton = TBButtons[0]; - ::CallService(MS_TTB_REMOVEBUTTON, (WPARAM)hTTButton, 0); - TBButtons.remove(0); - } -} - -static TTBButton* MakeTBButton(lua_State *L) -{ - TTBButton *tbb = (TTBButton*)mir_calloc(sizeof(TTBButton)); - tbb->dwFlags = TTBBF_ISLBUTTON; - - lua_getfield(L, -1, "Name"); - tbb->name = mir_utf8decodeA(luaL_checkstring(L, -1)); - lua_pop(L, 1); - - lua_getfield(L, -1, "Service"); - tbb->pszService = (char*)lua_tostring(L, -1); - lua_pop(L, 1); - - lua_getfield(L, -1, "Flags"); - tbb->dwFlags = lua_tointeger(L, -1); - lua_pop(L, 1); - - // up state - lua_getfield(L, -1, "IconUp"); - tbb->hIconHandleUp = (HANDLE)lua_touserdata(L, -1); - lua_pop(L, 1); - - lua_getfield(L, -1, "TooltipUp"); - tbb->pszTooltipUp = mir_utf8decodeA(lua_tostring(L, -1)); - lua_pop(L, 1); - - lua_getfield(L, -1, "wParamUp"); - tbb->wParamUp = luaM_towparam(L, -1); - lua_pop(L, 1); - - lua_getfield(L, -1, "lParamUp"); - tbb->lParamUp = luaM_tolparam(L, -1); - lua_pop(L, 1); - - // dn state - lua_getfield(L, -1, "IconDown"); - tbb->hIconHandleDn = (HANDLE)lua_touserdata(L, -1); - lua_pop(L, 1); - - lua_getfield(L, -1, "TooltipDown"); - tbb->pszTooltipDn = mir_utf8decodeA(lua_tostring(L, -1)); - lua_pop(L, 1); - - lua_getfield(L, -1, "wParamDown"); - tbb->wParamDown = luaM_towparam(L, -1); - lua_pop(L, 1); - - lua_getfield(L, -1, "lParamDown"); - tbb->lParamDown = luaM_tolparam(L, -1); - lua_pop(L, 1); - - return tbb; -} - -static int lua_AddButton(lua_State *L) -{ - if (lua_type(L, 1) != LUA_TTABLE) - { - lua_pushlightuserdata(L, 0); - return 1; - } - - TTBButton* tbb = MakeTBButton(L); - - HANDLE res = ::TopToolbar_AddButton(tbb); - lua_pushlightuserdata(L, res); - - if (res != INVALID_HANDLE_VALUE) - TBButtons.insert(res); - - mir_free(tbb->name); - mir_free(tbb->pszTooltipUp); - mir_free(tbb->pszTooltipDn); - mir_free(tbb); - - return 1; -} - -static int lua_RemoveButton(lua_State *L) -{ - HANDLE hTTButton = (HANDLE)lua_touserdata(L, 1); - - INT_PTR res = ::CallService(MS_TTB_REMOVEBUTTON, (WPARAM)hTTButton, 0); - lua_pushinteger(L, res); - - if (!res) - TBButtons.remove(hTTButton); - - return 1; -} - -static luaL_Reg toptoolbarApi[] = -{ - { "AddButton", lua_AddButton }, - { "RemoveButton", lua_RemoveButton }, - - { NULL, NULL } -}; - -LUAMOD_API int luaopen_m_toptoolbar(lua_State *L) -{ - luaL_newlib(L, toptoolbarApi); - - return 1; -} diff --git a/plugins/MirLua/src/m_toptoolbar.h b/plugins/MirLua/src/m_toptoolbar.h deleted file mode 100644 index 945fde68a3..0000000000 --- a/plugins/MirLua/src/m_toptoolbar.h +++ /dev/null @@ -1,9 +0,0 @@ -#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 9aab05a3a6..8c0d99d689 100644 --- a/plugins/MirLua/src/mlua.cpp +++ b/plugins/MirLua/src/mlua.cpp @@ -72,7 +72,6 @@ void CMLua::Unload() } KillModuleScheduleTasks(); - KillModuleTTBButton(); KillModuleIcons(hMLuaLangpack); KillModuleSounds(hMLuaLangpack); diff --git a/plugins/MirLua/src/mlua_module_loader.cpp b/plugins/MirLua/src/mlua_module_loader.cpp index ef0c7572e3..fb54e33573 100644 --- a/plugins/MirLua/src/mlua_module_loader.cpp +++ b/plugins/MirLua/src/mlua_module_loader.cpp @@ -37,8 +37,6 @@ void CLuaModuleLoader::LoadModules() Preload(MLUA_PROTOCOLS, luaopen_m_protocols); Preload(MLUA_SCHEDULE, luaopen_m_schedule); Preload(MLUA_SOUNDS, luaopen_m_sounds); - // regirter delay loading of other modules - Preload(MLUA_TOPTOOLBAR, luaopen_m_toptoolbar); } void CLuaModuleLoader::Load(lua_State *L) diff --git a/plugins/MirLua/src/mlua_utils.cpp b/plugins/MirLua/src/mlua_utils.cpp index 8a69605b32..7bd46d4db2 100644 --- a/plugins/MirLua/src/mlua_utils.cpp +++ b/plugins/MirLua/src/mlua_utils.cpp @@ -121,43 +121,6 @@ bool luaM_toboolean(lua_State *L, int idx) return lua_toboolean(L, idx) > 0; } -WPARAM luaM_towparam(lua_State *L, int idx) -{ - switch (lua_type(L, idx)) - { - case LUA_TBOOLEAN: - return lua_toboolean(L, idx); - case LUA_TNUMBER: - return lua_tonumber(L, idx); - case LUA_TSTRING: - return (WPARAM)lua_tostring(L, idx); - break; - case LUA_TUSERDATA: - case LUA_TLIGHTUSERDATA: - return (WPARAM)lua_touserdata(L, idx); - default: - return NULL; - } -} - -LPARAM luaM_tolparam(lua_State *L, int idx) -{ - switch (lua_type(L, idx)) - { - case LUA_TBOOLEAN: - return lua_toboolean(L, idx); - case LUA_TNUMBER: - return lua_tonumber(L, idx); - case LUA_TSTRING: - return (LPARAM)lua_tostring(L, idx); - case LUA_TUSERDATA: - case LUA_TLIGHTUSERDATA: - return (LPARAM)lua_touserdata(L, idx); - default: - return NULL; - } -} - int luaM_totable(lua_State *L) { const char *tname = luaL_checkstring(L, 2); diff --git a/plugins/MirLua/src/stdafx.h b/plugins/MirLua/src/stdafx.h index a6c84dd1e8..32e1d27506 100644 --- a/plugins/MirLua/src/stdafx.h +++ b/plugins/MirLua/src/stdafx.h @@ -33,7 +33,7 @@ #include #include -#include +#include #include "version.h" #include "resource.h" @@ -95,8 +95,6 @@ LUAMOD_API int (luaopen_m_message)(lua_State *L); #define MLUA_SOUNDS "m_sounds" LUAMOD_API int (luaopen_m_sounds)(lua_State *L); -#include "m_toptoolbar.h" - /* utils */ extern HANDLE hNetlib; @@ -116,8 +114,6 @@ int luaM_ptr2number(lua_State *L); int luaM_totable(lua_State *L); bool luaM_toboolean(lua_State *L, int idx); -WPARAM luaM_towparam(lua_State *L, int idx); -LPARAM luaM_tolparam(lua_State *L, int idx); void InitIcons(); HICON GetIcon(int iconId); -- cgit v1.2.3