summaryrefslogtreecommitdiff
path: root/plugins/MirLua/src/m_popup.cpp
blob: 2127f70f5f408cb845b147264265e5b2959d1236 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#include "stdafx.h"

static POPUPDATAT* MakePopupData(lua_State *L)
{
	POPUPDATAT *ppd = (POPUPDATAT*)mir_calloc(sizeof(POPUPDATAT));

	lua_pushliteral(L, "ContactName");
	lua_gettable(L, -2);
	mir_tstrcpy(ppd->lptzContactName, ptrT(mir_utf8decodeT(lua_tostring(L, -1))));
	lua_pop(L, 1);

	lua_pushliteral(L, "Text");
	lua_gettable(L, -2);
	mir_tstrcpy(ppd->lptzText, ptrT(mir_utf8decodeT(luaL_checkstring(L, -1))));
	lua_pop(L, 1);

	lua_pushliteral(L, "hContact");
	lua_gettable(L, -2);
	ppd->lchContact = lua_tointeger(L, -1);
	lua_pop(L, 1);

	lua_pushliteral(L, "ColorBack");
	lua_gettable(L, -2);
	ppd->colorBack = lua_tonumber(L, -1);
	lua_pop(L, 1);

	lua_pushliteral(L, "ColorText");
	lua_gettable(L, -2);
	ppd->colorText = lua_tonumber(L, -1);
	lua_pop(L, 1);

	lua_pushliteral(L, "Seconds");
	lua_gettable(L, -2);
	ppd->iSeconds = lua_tointeger(L, -1);
	lua_pop(L, 1);

	return ppd;
}

static int lua_AddPopup(lua_State *L)
{
	if (lua_type(L, 1) != LUA_TTABLE)
	{
		lua_pushlightuserdata(L, 0);
		return 1;
	}

	mir_ptr<POPUPDATAT> ppd(MakePopupData(L));

	INT_PTR res = ::CallService(MS_POPUP_ADDPOPUPT, (WPARAM)ppd, 0);
	lua_pushinteger(L, res);

	return 1;
}

static POPUPDATA2* MakePopupData2(lua_State *L)
{
	POPUPDATA2 *ppd = (POPUPDATA2*)mir_calloc(sizeof(POPUPDATA2));
	ppd->cbSize = sizeof(POPUPDATA2);

	lua_pushliteral(L, "Flags");
	lua_gettable(L, -2);
	ppd->flags = lua_tointeger(L, -1);
	lua_pop(L, 1);

	if (!(ppd->flags & PU2_TCHAR))
		ppd->flags |= PU2_TCHAR;

	lua_pushliteral(L, "Title");
	lua_gettable(L, -2);
	ppd->lptzTitle = mir_utf8decodeT(lua_tostring(L, -1));
	lua_pop(L, 1);

	lua_pushliteral(L, "Text");
	lua_gettable(L, -2);
	ppd->lptzText = mir_utf8decodeT(luaL_checkstring(L, -1));
	lua_pop(L, 1);

	lua_pushliteral(L, "hContact");
	lua_gettable(L, -2);
	ppd->lchContact = lua_tointeger(L, -1);
	lua_pop(L, 1);

	lua_pushliteral(L, "ColorBack");
	lua_gettable(L, -2);
	ppd->colorBack = lua_tonumber(L, -1);
	lua_pop(L, 1);

	lua_pushliteral(L, "ColorText");
	lua_gettable(L, -2);
	ppd->colorText = lua_tonumber(L, -1);
	lua_pop(L, 1);

	lua_pushliteral(L, "hEvent");
	lua_gettable(L, -2);
	ppd->lchEvent = lua_touserdata(L, -1);
	lua_pop(L, 1);

	lua_pushliteral(L, "Timestamp");
	lua_gettable(L, -2);
	ppd->dwTimestamp = lua_tonumber(L, -1);
	lua_pop(L, 1);

	lua_pushliteral(L, "Timeout");
	lua_gettable(L, -2);
	ppd->iSeconds = lua_tointeger(L, -1);
	lua_pop(L, 1);

	return ppd;
}

static int lua_AddPopup2(lua_State *L)
{
	if (lua_type(L, 1) != LUA_TTABLE)
	{
		lua_pushlightuserdata(L, 0);
		return 1;
	}

	mir_ptr<POPUPDATA2> ppd(MakePopupData2(L));

	INT_PTR res = ::CallService(MS_POPUP_ADDPOPUP2, (WPARAM)ppd, 0);
	lua_pushinteger(L, res);

	mir_free(ppd->lptzTitle);
	mir_free(ppd->lptzText);

	return 1;
}

static luaL_Reg popupApi[] =
{
	{ "AddPopup", lua_AddPopup },
	{ "AddPopup2", lua_AddPopup2 },

	{ NULL, NULL }
};

LUAMOD_API int luaopen_m_popup(lua_State *L)
{
	luaL_newlib(L, popupApi);

	return 1;
}