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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
|
#include "../commonheaders.h"
extern int DefaultImageListColorDepth;
int EnabledColumnCount = 0;
boolean visar[EXTRACOLUMNCOUNT];
#define ExtraImageIconsIndexCount 3
int ExtraImageIconsIndex[ExtraImageIconsIndexCount];
static HANDLE hExtraImageListRebuilding,hExtraImageApplying;
HANDLE hExtraImageClick;
static HIMAGELIST hExtraImageList;
extern HINSTANCE g_hInst;
extern HIMAGELIST hCListImages;
extern int ClcIconsChanged(WPARAM,LPARAM);
void SetAllExtraIcons(HWND hwndList,HANDLE hContact);
void LoadExtraImageFunc();
HICON LoadIconFromExternalFile(char*, int, boolean, boolean, char*, char*, char*, int, HICON = NULL);
boolean ImageCreated = FALSE;
void ReloadExtraIcons();
BYTE ExtraOrder[] =
{
0, // EXTRA_ICON_EMAIL
1, // EXTRA_ICON_PROTO
2, // EXTRA_ICON_SMS
3, // EXTRA_ICON_ADV1
4, // EXTRA_ICON_ADV2
5, // EXTRA_ICON_WEB
6, // EXTRA_ICON_CLIENT
7, // EXTRA_ICON_ADV3
8, // EXTRA_ICON_ADV4
};
BOOL HasExtraIconsService()
{
return ServiceExists("ExtraIcon/Register");
}
boolean isColumnVisible(int extra)
{
int i = 0;
if (HasExtraIconsService())
return TRUE;
for (i = 0; i<sizeof(ExtraOrder)/sizeof(ExtraOrder[0]); i++)
if (ExtraOrder[i] == extra)
{
switch(i+1)
{
case EXTRA_ICON_EMAIL: return(DBGetContactSettingByte(NULL,CLUIFrameModule,"EXTRA_ICON_EMAIL",1));
case EXTRA_ICON_PROTO: return(DBGetContactSettingByte(NULL,CLUIFrameModule,"EXTRA_ICON_PROTO",1));
case EXTRA_ICON_SMS: return(DBGetContactSettingByte(NULL,CLUIFrameModule,"EXTRA_ICON_SMS",1));
case EXTRA_ICON_ADV1: return(DBGetContactSettingByte(NULL,CLUIFrameModule,"EXTRA_ICON_ADV1",1));
case EXTRA_ICON_ADV2: return(DBGetContactSettingByte(NULL,CLUIFrameModule,"EXTRA_ICON_ADV2",1));
case EXTRA_ICON_WEB: return(DBGetContactSettingByte(NULL,CLUIFrameModule,"EXTRA_ICON_WEB",1));
case EXTRA_ICON_CLIENT: return(DBGetContactSettingByte(NULL,CLUIFrameModule,"EXTRA_ICON_CLIENT",1));
case EXTRA_ICON_ADV3: return(DBGetContactSettingByte(NULL,CLUIFrameModule,"EXTRA_ICON_ADV3",0));
case EXTRA_ICON_ADV4: return(DBGetContactSettingByte(NULL,CLUIFrameModule,"EXTRA_ICON_ADV4",0));
}
break;
}
return(FALSE);
}
void GetVisColumns()
{
visar[0] = isColumnVisible(0);
visar[1] = isColumnVisible(1);
visar[2] = isColumnVisible(2);
visar[3] = isColumnVisible(3);
visar[4] = isColumnVisible(4);
visar[5] = isColumnVisible(5);
visar[6] = isColumnVisible(6);
visar[7] = isColumnVisible(7);
visar[8] = isColumnVisible(8);
};
__inline int bti(boolean b)
{
return(b?1:0);
};
int colsum(int from,int to)
{
int i,sum;
if (from<0||from>=EXTRACOLUMNCOUNT){return(-1);};
if (to<0||to>=EXTRACOLUMNCOUNT){return(-1);};
if (to<from){return(-1);};
sum = 0;
for (i = from;i<=to;i++)
{
sum += bti(visar[i]);
};
return(sum);
};
int ExtraToColumnNum(int extra)
{
if (HasExtraIconsService())
{
if (extra < 1 || extra > EXTRACOLUMNCOUNT)
return -1;
else
return extra-1;
}
else
{
int cnt = EnabledColumnCount;
int extracnt = EXTRACOLUMNCOUNT-1;
int ord = ExtraOrder[extra-1];
if (!visar[ord]) return -1;
return (colsum(0,ord)-1);
}
};
int ColumnNumToExtra(int column)
{
int i;
if (HasExtraIconsService())
return column+1;
for (i = 0; i<sizeof(ExtraOrder)/sizeof(ExtraOrder[0]); i++)
if (ExtraOrder[i] == column)
return i+1;
return -1;
}
INT_PTR SetIconForExtraColumn(WPARAM wParam,LPARAM lParam)
{
pIconExtraColumn piec;
int icol;
HANDLE hItem;
if (pcli->hwndContactTree == 0){return(-1);};
if (wParam == 0||lParam == 0){return(-1);};
piec = (pIconExtraColumn)lParam;
if (piec->cbSize != sizeof(IconExtraColumn)){return(-1);};
icol = ExtraToColumnNum(piec->ColumnType);
if (icol == -1){return(-1);};
hItem = (HANDLE)SendMessage(pcli->hwndContactTree,CLM_FINDCONTACT,(WPARAM)wParam,0);
if (hItem == 0){return(-1);};
SendMessage(pcli->hwndContactTree,CLM_SETEXTRAIMAGE,(WPARAM)hItem,MAKELPARAM(icol,piec->hImage));
return 0;
};
//wparam = hIcon
//return hImage on success,-1 on failure
INT_PTR AddIconToExtraImageList(WPARAM wParam,LPARAM lParam)
{
if (hExtraImageList == 0||wParam == 0){return(-1);};
return((int)ImageList_AddIcon(hExtraImageList,(HICON)wParam));
}
int OnIconLibIconChanged(WPARAM wParam,LPARAM lParam)
{
HICON hicon;
hicon = LoadIconFromExternalFile("clisticons.dll",0,TRUE,FALSE,"Email","Contact List","Email Icon",-IDI_EMAIL);
ExtraImageIconsIndex[0] = ImageList_ReplaceIcon(hExtraImageList,ExtraImageIconsIndex[0],hicon );
hicon = LoadIconFromExternalFile("clisticons.dll",1,TRUE,FALSE,"Sms","Contact List","Sms Icon",-IDI_SMS);
ExtraImageIconsIndex[1] = ImageList_ReplaceIcon(hExtraImageList,ExtraImageIconsIndex[1],hicon );
hicon = LoadIconFromExternalFile("clisticons.dll",4,TRUE,FALSE,"Web","Contact List","Web Icon",-IDI_GLOBUS);
ExtraImageIconsIndex[2] = ImageList_ReplaceIcon(hExtraImageList,ExtraImageIconsIndex[2],hicon );
pcli->pfnClcBroadcast( INTM_INVALIDATE,0,0);
return 0;
}
void ReloadExtraIcons()
{
int count,i;
PROTOACCOUNT **accs;
HICON hicon;
SendMessage(pcli->hwndContactTree,CLM_SETEXTRACOLUMNSSPACE,DBGetContactSettingByte(NULL,"CLUI","ExtraColumnSpace",18),0);
SendMessage(pcli->hwndContactTree,CLM_SETEXTRAIMAGELIST,0,0);
if (hExtraImageList){ImageList_Destroy(hExtraImageList);};
hExtraImageList = ImageList_Create(GetSystemMetrics(SM_CXSMICON),GetSystemMetrics(SM_CYSMICON),ILC_COLOR32|ILC_MASK,1,256);
if (!HasExtraIconsService())
{
//loading icons
hicon = LoadIconFromExternalFile("clisticons.dll",0,TRUE,TRUE,"Email","Contact List","Email Icon",-IDI_EMAIL);
if (!hicon) hicon = LoadIcon(g_hInst, MAKEINTRESOURCE(IDI_EMAIL));
ExtraImageIconsIndex[0] = ImageList_AddIcon(hExtraImageList,hicon );
hicon = LoadIconFromExternalFile("clisticons.dll",1,TRUE,TRUE,"Sms","Contact List","Sms Icon",-IDI_SMS);
if (!hicon) hicon = LoadIcon(g_hInst, MAKEINTRESOURCE(IDI_SMS));
ExtraImageIconsIndex[1] = ImageList_AddIcon(hExtraImageList,hicon );
hicon = LoadIconFromExternalFile("clisticons.dll",4,TRUE,TRUE,"Web","Contact List","Web Icon",-IDI_GLOBUS);
if (!hicon) hicon = LoadIcon(g_hInst, MAKEINTRESOURCE(IDI_GLOBUS));
ExtraImageIconsIndex[2] = ImageList_AddIcon(hExtraImageList,hicon );
//calc only needed protocols
ProtoEnumAccounts( &count, &accs );
for ( i = 0; i < count; i++ )
if ( IsAccountEnabled( accs[i] ) && CallProtoService( accs[i]->szModuleName, PS_GETCAPS, PFLAGNUM_2, 0 ))
ImageList_AddIcon( hExtraImageList, LoadSkinnedProtoIcon( accs[i]->szModuleName, ID_STATUS_ONLINE ));
}
SendMessage(pcli->hwndContactTree,CLM_SETEXTRAIMAGELIST,0,(LPARAM)hExtraImageList);
SendMessage(pcli->hwndContactTree,CLM_SETEXTRACOLUMNS,EnabledColumnCount,0);
NotifyEventHooks(hExtraImageListRebuilding,0,0);
ImageCreated = TRUE;
}
void ClearExtraIcons();
void ReAssignExtraIcons()
{
ClearExtraIcons();
SendMessage(pcli->hwndContactTree,CLM_SETEXTRACOLUMNS, EXTRACOLUMNCOUNT, 0);
SetAllExtraIcons(pcli->hwndContactTree,0);
SendMessage(pcli->hwndContactTree,CLM_AUTOREBUILD,0,0);
}
void ClearExtraIcons()
{
int i;
HANDLE hContact,hItem;
SendMessage(pcli->hwndContactTree,CLM_SETEXTRACOLUMNS, EXTRACOLUMNCOUNT, 0);
hContact = db_find_first();
do {
hItem = (HANDLE)SendMessage(pcli->hwndContactTree,CLM_FINDCONTACT,(WPARAM)hContact,0);
if (hItem == 0){continue;};
for (i = 0;i<EnabledColumnCount;i++)
{
SendMessage(pcli->hwndContactTree,CLM_SETEXTRAIMAGE,(WPARAM)hItem,MAKELPARAM(i,0xFF));
};
} while(hContact = db_find_next(hContact));
};
void SetAllExtraIcons(HWND hwndList,HANDLE hContact)
{
HANDLE hItem;
boolean hcontgiven = FALSE;
char *szProto;
char *ImgIndex[64];
int maxpr,count,i;
PROTOACCOUNT **accs;
pClcCacheEntry pdnce;
int em,pr,sms,a1,a2,w1,c1;
int tick = 0;
BOOL hasExtraIconsService;
hcontgiven = (hContact != 0);
if (pcli->hwndContactTree == 0){return;};
tick = GetTickCount();
if (ImageCreated == FALSE) ReloadExtraIcons();
SendMessage(pcli->hwndContactTree,CLM_SETEXTRACOLUMNS, EXTRACOLUMNCOUNT, 0);
hasExtraIconsService = HasExtraIconsService();
if (!hasExtraIconsService) {
em = ExtraToColumnNum(EXTRA_ICON_EMAIL);
pr = ExtraToColumnNum(EXTRA_ICON_PROTO);
sms = ExtraToColumnNum(EXTRA_ICON_SMS);
a1 = ExtraToColumnNum(EXTRA_ICON_ADV1);
a2 = ExtraToColumnNum(EXTRA_ICON_ADV2);
w1 = ExtraToColumnNum(EXTRA_ICON_WEB);
c1 = ExtraToColumnNum(EXTRA_ICON_CLIENT);
memset(ImgIndex,0,sizeof(ImgIndex));
ProtoEnumAccounts( &count, &accs );
maxpr = 0;
//calc only needed protocols
for ( i = 0; i < count; i++ ) {
if ( !IsAccountEnabled( accs[i] ) || CallProtoService( accs[i]->szModuleName, PS_GETCAPS, PFLAGNUM_2, 0 ) == 0 )
continue;
ImgIndex[maxpr] = accs[i]->szModuleName;
maxpr++;
}
}
if ( hContact == NULL )
hContact = db_find_first();
do {
szProto = NULL;
hItem = hContact;
if (hItem == 0){continue;};
pdnce = (pClcCacheEntry)pcli->pfnGetCacheEntry(hItem);
if (pdnce == NULL) {continue;};
// szProto = (char*)CallService(MS_PROTO_GETCONTACTBASEPROTO,(WPARAM)hContact,0);
szProto = pdnce->szProto;
if (!hasExtraIconsService)
{
if (ExtraToColumnNum(EXTRA_ICON_WEB) != -1)
{
boolean showweb = FALSE;
if (szProto != NULL)
{
char *homepage;
homepage = DBGetStringA(pdnce->hContact,"UserInfo", "Homepage");
if (!homepage)
homepage = DBGetStringA(pdnce->hContact,pdnce->szProto, "Homepage");
if (homepage != NULL)
{
showweb = TRUE;
mir_free(homepage);
}
}
SendMessage(hwndList,CLM_SETEXTRAIMAGE,(WPARAM)hItem,MAKELPARAM(ExtraToColumnNum(EXTRA_ICON_WEB),(showweb)?2:0xFF));
}
if (ExtraToColumnNum(EXTRA_ICON_EMAIL) != -1)
{
DBVARIANT dbv = {0};
boolean showemail = TRUE;
if (szProto == NULL || DBGetContactSettingString(hContact, szProto, "e-mail",&dbv))
{
DBFreeVariant(&dbv);
if (DBGetContactSettingString(hContact, "UserInfo", "Mye-mail0", &dbv))
showemail = FALSE;
}
DBFreeVariant(&dbv);
SendMessage(hwndList,CLM_SETEXTRAIMAGE,(WPARAM)hItem,MAKELPARAM(ExtraToColumnNum(EXTRA_ICON_EMAIL),(showemail)?0:0xFF));
}
if (ExtraToColumnNum(EXTRA_ICON_SMS) != -1)
{
DBVARIANT dbv = {0};
boolean showsms = TRUE;
if (szProto == NULL || DBGetContactSettingString(hContact, szProto, "Cellular",&dbv)) {
DBFreeVariant(&dbv);
if (DBGetContactSettingString(hContact, "UserInfo", "MyPhone0", &dbv))
showsms = FALSE;
}
SendMessage(hwndList,CLM_SETEXTRAIMAGE,(WPARAM)hItem,MAKELPARAM(ExtraToColumnNum(EXTRA_ICON_SMS),(showsms)?1:0xFF));
DBFreeVariant(&dbv);
}
if (ExtraToColumnNum(EXTRA_ICON_PROTO) != -1)
{
for (i = 0;i<maxpr;i++)
{
if (!MyStrCmp(ImgIndex[i],szProto))
{
SendMessage(hwndList,CLM_SETEXTRAIMAGE,(WPARAM)hItem,MAKELPARAM(ExtraToColumnNum(EXTRA_ICON_PROTO),i+3));
break;
}
}
}
}
NotifyEventHooks(hExtraImageApplying,(WPARAM)hContact,0);
if (hcontgiven) break;
Sleep(0);
}
while(hContact = db_find_next(hContact));
tick = GetTickCount()-tick;
InvalidateRect(hwndList,NULL,FALSE);
Sleep(0);
}
void LoadExtraImageFunc()
{
CreateServiceFunction(MS_CLIST_EXTRA_SET_ICON,SetIconForExtraColumn);
CreateServiceFunction(MS_CLIST_EXTRA_ADD_ICON,AddIconToExtraImageList);
hExtraImageListRebuilding = CreateHookableEvent(ME_CLIST_EXTRA_LIST_REBUILD);
hExtraImageApplying = CreateHookableEvent(ME_CLIST_EXTRA_IMAGE_APPLY);
hExtraImageClick = CreateHookableEvent(ME_CLIST_EXTRA_CLICK);
HookEvent(ME_SKIN2_ICONSCHANGED,OnIconLibIconChanged);
}
|