summaryrefslogtreecommitdiff
path: root/plugins/SecureIM/src/crypt_icons.cpp
blob: d660c514798c0f7225a9c347cebf027823e08b7e (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
#include "commonheaders.h"

struct ICON_CACHE
{
	ICON_CACHE::~ICON_CACHE() {
		::DestroyIcon(icon);
	}

	HICON  icon;
	HANDLE hCLIcon;
	SHORT  mode;
};

OBJLIST<ICON_CACHE> arIcoList(10);

// преобразует mode в HICON который НЕ НУЖНО разрушать в конце
static ICON_CACHE& getCacheItem(int mode, int type)
{
	int m = mode & 0x0f, s = (mode & SECURED) >> 4, i; // разобрали на части - режим и состояние
	HICON icon;

	for (auto &it : arIcoList)
		if (it->mode == ((type << 8) | mode))
			return *it;

	i = s;
	switch (type) {
	case 1: i += IEC_CL_DIS; break;
	case 2: i += ICO_CM_DIS; break;
	case 3: i += ICO_MW_DIS; break;
	}

	if (type == 1)
		icon = BindOverlayIcon(g_hIEC[i], g_hICO[ICO_OV_NAT + m]);
	else
		icon = BindOverlayIcon(g_hICO[i], g_hICO[ICO_OV_NAT + m]);

	ICON_CACHE *p = new ICON_CACHE;
	p->icon = icon;
	p->mode = (type << 8) | mode;
	p->hCLIcon = nullptr;
	arIcoList.insert(p);

	return *p;
}

HICON mode2icon(int mode, int type)
{
	return getCacheItem(mode, type).icon;
}

HANDLE mode2clicon(int mode, int type)
{
	if (!bASI && !(mode & SECURED))
		return INVALID_HANDLE_VALUE;

	ICON_CACHE &p = getCacheItem(mode, type);
	if (p.hCLIcon == nullptr)
		p.hCLIcon = ExtraIcon_AddIcon(p.icon);

	return p.hCLIcon;
}

// обновляет иконки в clist и в messagew
void ShowStatusIcon(MCONTACT hContact, int mode)
{
	MCONTACT hMC = db_mc_getMeta(hContact);

	// обновить иконки в clist
	if (mode != -1) {
		HANDLE hIcon = mode2clicon(mode, 1);
		ExtraIcon_SetIcon(g_hCLIcon, hContact, hIcon);
		if (hMC)
			ExtraIcon_SetIcon(g_hCLIcon, hMC, hIcon);
	}
	else {
		ExtraIcon_Clear(g_hCLIcon, hContact);
		if (hMC)
			ExtraIcon_Clear(g_hCLIcon, hMC);
	}

	for (int i = MODE_NATIVE; i < MODE_CNT; i++) {
		int flags = (mode & SECURED) ? 0 : MBF_DISABLED;
		if (mode == -1 || (mode & 0x0f) != i || isChatRoom(hContact))
			flags |= MBF_HIDDEN;  // отключаем все ненужные иконки
		Srmm_SetIconFlags(hContact, MODULENAME, i, flags);
		if (hMC)
			Srmm_SetIconFlags(hMC, MODULENAME, i, flags);
	}
}

void ShowStatusIcon(MCONTACT hContact)
{
	ShowStatusIcon(hContact, isContactSecured(hContact));
}

void ShowStatusIconNotify(MCONTACT hContact)
{
	uint8_t mode = isContactSecured(hContact);
	NotifyEventHooks(g_hEvent[(mode&SECURED) != 0], hContact, 0);
	ShowStatusIcon(hContact, mode);
}

void RefreshContactListIcons(void)
{
	for (auto &it : arIcoList)
		it->hCLIcon = nullptr;

	for (auto &hContact : Contacts())
		if (isSecureProtocol(hContact))
			ShowStatusIcon(hContact);
}