From ee3100701b64a1a34e8e5b3069219c7c5a201d8a Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 29 Jun 2015 19:30:51 +0000 Subject: - unified menu creation using wrapper class CMenuItem; - duplicated hLangpack field removed from TMO_IntMenuItem; - code cleaning git-svn-id: http://svn.miranda-ng.org/main/trunk@14440 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/MirLua/src/m_genmenu.cpp | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'plugins/MirLua') diff --git a/plugins/MirLua/src/m_genmenu.cpp b/plugins/MirLua/src/m_genmenu.cpp index f2839d9a82..ac53d9b070 100644 --- a/plugins/MirLua/src/m_genmenu.cpp +++ b/plugins/MirLua/src/m_genmenu.cpp @@ -1,44 +1,41 @@ #include "stdafx.h" -static TMO_MenuItem* MakeMenuItem(lua_State *L) +static void MakeMenuItem(lua_State *L, CMenuItem &mi) { - TMO_MenuItem *pmi = (TMO_MenuItem*)mir_calloc(sizeof(TMO_MenuItem)); - pmi->hLangpack = hScriptsLangpack; + mi.hLangpack = hScriptsLangpack; lua_pushstring(L, "Flags"); lua_gettable(L, -2); - pmi->flags = lua_tointeger(L, -1); + mi.flags = lua_tointeger(L, -1); lua_pop(L, 1); - if (!(pmi->flags & CMIF_UNICODE)) - pmi->flags |= CMIF_UNICODE; + if (!(mi.flags & CMIF_UNICODE)) + mi.flags |= CMIF_UNICODE; lua_pushstring(L, "Name"); lua_gettable(L, -2); - pmi->name.t = mir_utf8decodeT((char*)luaL_checkstring(L, -1)); + mi.name.t = mir_utf8decodeT((char*)luaL_checkstring(L, -1)); lua_pop(L, 1); lua_pushstring(L, "Position"); lua_gettable(L, -2); - pmi->position = lua_tointeger(L, -1); + mi.position = lua_tointeger(L, -1); lua_pop(L, 1); lua_pushstring(L, "Icon"); lua_gettable(L, -2); - pmi->hIcolibItem = (HANDLE)lua_touserdata(L, -1); + mi.hIcolibItem = (HANDLE)lua_touserdata(L, -1); lua_pop(L, 1); lua_pushstring(L, "Service"); lua_gettable(L, -2); - pmi->pszService = (char*)lua_tostring(L, -1); + mi.pszService = (char*)lua_tostring(L, -1); lua_pop(L, 1); lua_pushstring(L, "Parent"); lua_gettable(L, -2); - pmi->root = (HGENMENU)lua_touserdata(L, -1); + mi.root = (HGENMENU)lua_touserdata(L, -1); lua_pop(L, 1); - - return pmi; } static int lua_AddMainMenuItem(lua_State *L) @@ -49,9 +46,10 @@ static int lua_AddMainMenuItem(lua_State *L) return 1; } - mir_ptr pmi(MakeMenuItem(L)); + CMenuItem mi; + MakeMenuItem(L, mi); - HGENMENU res = ::Menu_AddMainMenuItem(pmi, hScriptsLangpack); + HGENMENU res = ::Menu_AddMainMenuItem(&mi); lua_pushlightuserdata(L, res); return 1; @@ -65,9 +63,10 @@ static int lua_AddContactMenuItem(lua_State *L) return 1; } - mir_ptr pmi(MakeMenuItem(L)); + CMenuItem mi; + MakeMenuItem(L, mi); - HGENMENU res = ::Menu_AddContactMenuItem(pmi, NULL, hScriptsLangpack); + HGENMENU res = ::Menu_AddContactMenuItem(&mi, NULL); lua_pushlightuserdata(L, res); return 1; @@ -81,9 +80,10 @@ static int lua_AddTrayMenuItem(lua_State *L) return 1; } - mir_ptr pmi(MakeMenuItem(L)); + CMenuItem mi; + MakeMenuItem(L, mi); - HGENMENU res = (HGENMENU)::CallService("CList/AddTrayMenuItem", 0, (LPARAM)pmi); + HGENMENU res = (HGENMENU)::CallService("CList/AddTrayMenuItem", 0, (LPARAM)&mi); lua_pushlightuserdata(L, res); return 1; -- cgit v1.2.3