summaryrefslogtreecommitdiff
path: root/plugins/Clist_modern/src/modern_extraimage.cpp
blob: 05f0efc970706fcc0781e0993c67e89eeda150f1 (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
145
146
147
#include "hdr/modern_commonheaders.h"
#include "hdr/modern_commonprototypes.h"

#define ExtraImageIconsIndexCount 6

BOOL g_mutex_bSetAllExtraIconsCycle = 0;

static HIMAGELIST hExtraImageList = NULL;
static HIMAGELIST hWideExtraImageList = NULL;

void ExtraImage_SetAllExtraIcons(HWND hwndList,HANDLE hContact);

bool ImageCreated = FALSE;

int ExtraImage_ExtraIDToColumnNum(int extra)
{
	if (extra < 1 || extra > EXTRACOLUMNCOUNT)
		return -1;
	else
		return extra-1;
}

//wparam = hIcon
//return hImage on success,-1 on failure
INT_PTR AddIconToExtraImageList(WPARAM wParam,LPARAM lParam)
{
	if (hExtraImageList == 0 || wParam == 0)
		return -1;

	int res = ((int)ImageList_AddIcon(hExtraImageList,(HICON)wParam));
	return (res > 254) ? -1 : res;
}

void SetNewExtraColumnCount()
{
	db_set_b(NULL, CLUIFrameModule, "EnabledColumnCount", (BYTE)EXTRACOLUMNCOUNT);
	SendMessage(pcli->hwndContactTree,CLM_SETEXTRACOLUMNS, EXTRACOLUMNCOUNT, 0);
}

void ExtraImage_ReloadExtraIcons()
{
	SendMessage(pcli->hwndContactTree,CLM_SETEXTRACOLUMNSSPACE,db_get_b(NULL,"CLUI","ExtraColumnSpace",18),0);
	SendMessage(pcli->hwndContactTree,CLM_SETEXTRAIMAGELIST,0,0);
	if (hExtraImageList)
		ImageList_Destroy(hExtraImageList);
	if (hWideExtraImageList)
		ImageList_Destroy(hWideExtraImageList);

	hExtraImageList = ImageList_Create(GetSystemMetrics(SM_CXSMICON),GetSystemMetrics(SM_CYSMICON),ILC_COLOR32|ILC_MASK,1,256);
	hWideExtraImageList = ImageList_Create(GetSystemMetrics(SM_CXSMICON),GetSystemMetrics(SM_CYSMICON),ILC_COLOR32|ILC_MASK,1,256);

	SendMessage(pcli->hwndContactTree,CLM_SETEXTRAIMAGELIST,(WPARAM)hWideExtraImageList,(LPARAM)hExtraImageList);
	SetNewExtraColumnCount();
	NotifyEventHooks(g_CluiData.hEventExtraImageListRebuilding,0,0);
	ImageCreated = TRUE;
}

void ExtraImage_SetAllExtraIcons(HWND hwndList,HANDLE hContact)
{
	if (pcli->hwndContactTree == 0)
		return;

	g_mutex_bSetAllExtraIconsCycle = 1;
	bool hcontgiven = (hContact != 0);

	if (ImageCreated == FALSE)
		ExtraImage_ReloadExtraIcons();

	SetNewExtraColumnCount();

	if (hContact == NULL)
		hContact = db_find_first();

	do {
		char *szProto = NULL;
		HANDLE hItem = hContact;
		if (hItem == 0)
			continue;
		
		pClcCacheEntry pdnce = (pClcCacheEntry)pcli->pfnGetCacheEntry(hItem);
		if (pdnce == NULL)
			continue;

		szProto = pdnce->m_cache_cszProto;
		NotifyEventHooks(g_CluiData.hEventExtraImageApplying, (WPARAM)hContact, 0);
		if (hcontgiven) break;
		Sleep(0);
	}
		while(hContact = db_find_next(hContact));

	g_mutex_bSetAllExtraIconsCycle = 0;
	CLUI__cliInvalidateRect(hwndList,NULL,FALSE);
	Sleep(0);
}

INT_PTR WideSetIconForExtraColumn(WPARAM wParam,LPARAM lParam)
{
	if (pcli->hwndContactTree == 0 || wParam == 0 || lParam == 0)
		return -1;

	pIconExtraColumn piec = (pIconExtraColumn)lParam;
	if (piec->cbSize != sizeof(IconExtraColumn))
		return -1;

	int icol = ExtraImage_ExtraIDToColumnNum(piec->ColumnType);
	if (icol == -1)
		return -1;

	HANDLE hItem = (HANDLE)SendMessage(pcli->hwndContactTree,CLM_FINDCONTACT,(WPARAM)wParam,0);
	if (hItem == 0)
		return -1;

	if (piec->hImage == (HANDLE)0xFF)
		piec->hImage = (HANDLE)0xFFFF;

	SendMessage(pcli->hwndContactTree,CLM_SETWIDEEXTRAIMAGE,(WPARAM)hItem,MAKELPARAM(icol,piec->hImage));
	return 0;
};

//wparam = hIcon
//return hImage on success,-1 on failure

INT_PTR WideAddIconToExtraImageList(WPARAM wParam,LPARAM lParam)
{
	if (hWideExtraImageList == 0 || wParam == 0){return(-1);};
	int res = ((int)ImageList_AddIcon(hWideExtraImageList,(HICON)wParam));
	if (res == 0xFF)	res = ((int)ImageList_AddIcon(hWideExtraImageList,(HICON)wParam));
	if (res>0xFFFE) return -1;
	return res;
};

static int ehhExtraImage_UnloadModule(WPARAM wParam,LPARAM lParam)
{
	if (hExtraImageList)
		ImageList_Destroy(hExtraImageList);
	if (hWideExtraImageList)
		ImageList_Destroy(hWideExtraImageList);
	return 0;

}
void ExtraImage_LoadModule()
{
	CreateServiceFunction(MS_CLIST_EXTRA_SET_ICON, WideSetIconForExtraColumn);
	CreateServiceFunction(MS_CLIST_EXTRA_ADD_ICON, WideAddIconToExtraImageList);

	HookEvent(ME_SYSTEM_SHUTDOWN, ehhExtraImage_UnloadModule );
};