summaryrefslogtreecommitdiff
path: root/protocols/Tox/src/tox_icons.cpp
blob: 756fc13bad8fefd7467a372e0f522f7975d2c315 (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
#include "stdafx.h"

IconInfo CToxProto::Icons[] =
{
	{ LPGENT("Protocol icon"),			"main",				IDI_TOX			},
	{ LPGENT("Audio call"),				"audio_call",		IDI_AUDIO_CALL	},
	{ LPGENT("Audio ring"),				"audio_ring",		IDI_AUDIO_RING	},
	{ LPGENT("Audio start"),			"audio_start",		IDI_AUDIO_START	},
	{ LPGENT("Audio end"),				"audio_end",		IDI_AUDIO_END	},
};

void CToxProto::InitIcons()
{
	TCHAR szFile[MAX_PATH];
	GetModuleFileName(g_hInstance, szFile, MAX_PATH);

	char szSettingName[100];
	TCHAR szSectionName[100];

	SKINICONDESC sid = { 0 };
	sid.flags = SIDF_ALL_TCHAR;
	sid.defaultFile.t = szFile;
	sid.pszName = szSettingName;
	sid.section.t = szSectionName;

	mir_sntprintf(szSectionName, _T("%s/%s"), LPGENT("Protocols"), LPGENT(MODULE));
	for (int i = 0; i < _countof(Icons); i++)
	{
		mir_snprintf(szSettingName, "%s_%s", MODULE, Icons[i].Name);

		sid.description.t = Icons[i].Description;
		sid.iDefaultIndex = -Icons[i].IconId;
		Icons[i].Handle = IcoLib_AddIcon(&sid);
	}
}

HICON CToxProto::GetIcon(const char *name, bool size)
{
	for (size_t i = 0; i < _countof(Icons); i++)
		if (mir_strcmpi(Icons[i].Name, name) == 0)
			return IcoLib_GetIconByHandle(Icons[i].Handle, size);

	return NULL;
}

HANDLE CToxProto::GetIconHandle(const char *name)
{
	for (size_t i = 0; i < _countof(Icons); i++)
		if (mir_strcmpi(Icons[i].Name, name) == 0)
			return Icons[i].Handle;

	return NULL;
}

HANDLE CToxProto::Skin_GetIconHandle(const char *name)
{
	char iconName[100];
	mir_snprintf(iconName, "%s_%s", MODULE, name);
	HANDLE hIcon = IcoLib_GetIconHandle(iconName);
	if (hIcon == NULL)
		hIcon = GetIconHandle(name);

	return hIcon;
}

void CToxProto::UninitIcons()
{
	for (size_t i = 0; i < _countof(Icons); i++)
		IcoLib_RemoveIcon(Icons[i].Name);
}