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
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
|
#include "_globals.h"
#include "mu_common.h"
#include <map>
#include <set>
namespace mu
{
/*
* clist
*/
namespace clist
{
HANDLE addMainMenuItem(const mu_text* pszName, DWORD flags, int position, HICON hIcon, const mu_ansi* pszService, const mu_text* pszPopupName /* = NULL */, int popupPosition /* = 0 */, DWORD hotKey /* = 0 */)
{
// TODO: support for unicode-core with unicode-aware CList
CLISTMENUITEM mi;
ZeroMemory(&mi, sizeof(mi));
mi.cbSize = sizeof(mi);
mi.pszName = MU_DO_BOTH(const_cast<mu_ansi*>(pszName), wideToAnsiDup(pszName));
mi.flags = flags;
mi.position = position;
mi.hIcon = hIcon;
mi.pszService = const_cast<mu_ansi*>(pszService);
mi.pszPopupName = MU_DO_BOTH(const_cast<mu_ansi*>(pszPopupName), wideToAnsiDup(pszPopupName));
mi.popupPosition = popupPosition;
mi.hotKey = hotKey;
HANDLE res = Menu_AddMainMenuItem(&mi);
MU_DO_WIDE(freeAnsi(mi.pszName));
MU_DO_WIDE(freeAnsi(mi.pszPopupName));
return res;
}
HANDLE addContactMenuItem(const mu_text* pszName, DWORD flags, int position, HICON hIcon, const mu_ansi* pszService, DWORD hotKey /* = 0 */, const mu_ansi* pszContactOwner /* = NULL */)
{
// TODO: support for unicode-core with unicode-aware CList
CLISTMENUITEM mi;
ZeroMemory(&mi, sizeof(mi));
mi.cbSize = sizeof(mi);
mi.pszName = MU_DO_BOTH(const_cast<mu_ansi*>(pszName), wideToAnsiDup(pszName));
mi.flags = flags;
mi.position = position;
mi.hIcon = hIcon;
mi.pszService = const_cast<mu_ansi*>(pszService);
mi.hotKey = hotKey;
mi.pszContactOwner = const_cast<mu_ansi*>(pszContactOwner);
HANDLE res = Menu_AddContactMenuItem(&mi);
MU_DO_WIDE(freeAnsi(mi.pszName));
return res;
}
int modifyMenuItem(HANDLE hMenuItem, DWORD toModify, const mu_text* pszName /* = NULL */, DWORD flags /* = 0 */, HICON hIcon /* = NULL */, DWORD hotKey /* = 0 */)
{
// TODO: support for unicode-core with unicode-aware CList
CLISTMENUITEM mi;
ZeroMemory(&mi, sizeof(mi));
mi.cbSize = sizeof(mi);
mi.pszName = MU_DO_BOTH(const_cast<mu_ansi*>(pszName), wideToAnsiDup(pszName));
mi.flags = toModify | flags;
mi.hIcon = hIcon;
mi.hotKey = hotKey;
int res = CallService(MS_CLIST_MODIFYMENUITEM, reinterpret_cast<WPARAM>(hMenuItem), reinterpret_cast<LPARAM>(&mi));
MU_DO_WIDE(freeAnsi(mi.pszName));
return res;
}
const mu_text* getContactDisplayName(MCONTACT hContact)
{
return reinterpret_cast<const mu_text*>(CallService(MS_CLIST_GETCONTACTDISPLAYNAME, hContact, GCDNF_UNICODE));
}
const mu_text* getStatusModeDescription(int nStatusMode)
{
return reinterpret_cast<const mu_text*>(CallService(MS_CLIST_GETSTATUSMODEDESCRIPTION, static_cast<WPARAM>(nStatusMode), GSMDF_UNICODE));
}
}
/*
* db
*/
namespace db
{
int getProfilePath(int cbName, mu_text* pszName)
{
// TODO: support for unicode core (if supported)
#if defined(MU_WIDE)
mu_ansi* pszNameAnsi = new mu_ansi[cbName];
int ret = CallService(MS_DB_GETPROFILEPATH, cbName, reinterpret_cast<LPARAM>(pszNameAnsi));
if (ret == 0)
{
ansiToWide(pszNameAnsi, pszName, cbName);
}
delete pszNameAnsi;
return ret;
#else // MU_WIDE
return CallService(MS_DB_GETPROFILEPATH, cbName, reinterpret_cast<LPARAM>(pszName));
#endif // MU_WIDE
}
int getProfileName(int cbName, mu_text* pszName)
{
// TODO: support for unicode core (if supported)
#if defined(MU_WIDE)
mu_ansi* pszNameAnsi = new mu_ansi[cbName];
int ret = CallService(MS_DB_GETPROFILENAME, cbName, reinterpret_cast<LPARAM>(pszNameAnsi));
if (ret == 0)
{
ansiToWide(pszNameAnsi, pszName, cbName);
}
delete pszNameAnsi;
return ret;
#else // MU_WIDE
return CallService(MS_DB_GETPROFILENAME, cbName, reinterpret_cast<LPARAM>(pszName));
#endif // MU_WIDE
}
void setSafetyMode(bool safetyMode)
{
CallService(MS_DB_SETSAFETYMODE, BOOL_(safetyMode), 0);
}
}
/*
* db_time
*/
namespace db_contact
{
int enumSettings(MCONTACT hContact, const mu_ansi* szModule, DBSETTINGENUMPROC pEnumProc, LPARAM lProcParam)
{
DBCONTACTENUMSETTINGS dbces;
dbces.pfnEnumProc = pEnumProc;
dbces.lParam = lProcParam;
dbces.szModule = szModule;
dbces.ofsSettings = 0;
return CallService(MS_DB_CONTACT_ENUMSETTINGS, hContact, reinterpret_cast<LPARAM>(&dbces));
}
}
namespace db_time
{
DWORD timestampToLocal(DWORD timestamp)
{
return static_cast<DWORD>(CallService(MS_DB_TIME_TIMESTAMPTOLOCAL, static_cast<WPARAM>(timestamp), 0));
}
}
/*
* icolib
*/
namespace icolib
{
bool _available()
{
return true;
}
void addIcon(const mu_text* szSection, const mu_text* szDescription, const mu_ansi* szIconName, const mu_ansi* szDefaultFile, int iDefaultIndex, int cx /* = 16 */, int cy /* = 16 */)
{
SKINICONDESC sid;
sid.cbSize = sizeof(sid);
sid.ptszSection = const_cast<mu_text*>(szSection);
sid.ptszDescription = const_cast<mu_text*>(szDescription);
sid.pszName = const_cast<mu_ansi*>(szIconName);
sid.pszDefaultFile = const_cast<mu_ansi*>(szDefaultFile);
sid.iDefaultIndex = iDefaultIndex;
sid.hDefaultIcon = NULL;
sid.cx = cx;
sid.cy = cy;
sid.flags = MU_DO_BOTH(0, SIDF_UNICODE);
Skin_AddIcon(&sid);
}
void addIcon(const mu_text* szSection, const mu_text* szDescription, const mu_ansi* szIconName, HICON hDefaultIcon, int cx /* = 16 */, int cy /* = 16 */)
{
SKINICONDESC sid;
sid.cbSize = sizeof(sid);
sid.ptszSection = const_cast<mu_text*>(szSection);
sid.ptszDescription = const_cast<mu_text*>(szDescription);
sid.pszName = const_cast<mu_ansi*>(szIconName);
sid.pszDefaultFile = NULL;
sid.iDefaultIndex = 0;
sid.hDefaultIcon = hDefaultIcon;
sid.cx = cx;
sid.cy = cy;
sid.flags = MU_DO_BOTH(0, SIDF_UNICODE);
Skin_AddIcon(&sid);
}
HICON getIcon(const mu_ansi* szIconName)
{
return reinterpret_cast<HICON>(CallService(MS_SKIN2_GETICON, 0, reinterpret_cast<LPARAM>(szIconName)));
}
}
/*
* langpack
*/
namespace langpack
{
const mu_text* translateString(const mu_text* szEnglish)
{
return reinterpret_cast<const mu_text*>(CallService(MS_LANGPACK_TRANSLATESTRING, MU_DO_BOTH(0, LANG_UNICODE), reinterpret_cast<LPARAM>(szEnglish)));
}
UINT getCodePage()
{
static UINT CodePage = -1;
if (CodePage == -1)
{
CodePage = ServiceExists(MS_LANGPACK_GETCODEPAGE) ? CallService(MS_LANGPACK_GETCODEPAGE, 0, 0) : CP_ACP;
}
return CodePage;
}
}
/*
* metacontacts [external]
*/
namespace metacontacts
{
bool _available()
{
return true;
}
int getNumContacts(MCONTACT hMetaContact)
{
return CallService(MS_MC_GETNUMCONTACTS, hMetaContact, 0);
}
MCONTACT getSubContact(MCONTACT hMetaContact, int iContactNumber)
{
return CallService(MS_MC_GETSUBCONTACT, hMetaContact, iContactNumber);
}
}
/*
* opt
*/
namespace opt
{
void addPage(WPARAM addInfo, const mu_text* pszGroup, const mu_text* pszTitle, const mu_text* pszTab, DLGPROC pfnDlgProc, const mu_ansi* pszTemplate, HINSTANCE hInstance, DWORD flags /* = ODPF_BOLDGROUPS */)
{
OPTIONSDIALOGPAGE odp = { sizeof(odp) };
odp.ptszTitle = const_cast<mu_text*>(pszTitle);
odp.pfnDlgProc = pfnDlgProc;
odp.pszTemplate = const_cast<mu_ansi*>(pszTemplate);
odp.hInstance = hInstance;
odp.ptszGroup = const_cast<mu_text*>(pszGroup);
odp.flags = flags | MU_DO_BOTH(0, ODPF_UNICODE);
odp.ptszTab = const_cast<mu_text*>(pszTab);
Options_AddPage(addInfo, &odp);
}
}
/*
* png
*/
namespace png
{
bool _available()
{
return
true &&
ServiceExists(MS_DIB2PNG);
}
bool dibToPng(const BITMAPINFOHEADER* pBMIH, const BYTE* pDIData, BYTE* pImageData, long* pImageLen)
{
DIB2PNG info;
info.pbmi = const_cast<BITMAPINFO*>(reinterpret_cast<const BITMAPINFO*>(pBMIH));
info.pDiData = const_cast<BYTE*>(pDIData);
info.pResult = pImageData;
info.pResultLen = pImageLen;
return bool_(CallService(MS_DIB2PNG, 0, reinterpret_cast<LPARAM>(&info)));
}
}
/*
* proto
*/
namespace proto
{
int enumProtocols(int* numProtocols, PROTOACCOUNT*** ppProtoDescriptors)
{
return ProtoEnumAccounts(numProtocols, ppProtoDescriptors);
}
const mu_ansi* getContactBaseProto(MCONTACT hContact)
{
return reinterpret_cast<const mu_ansi*>(CallService(MS_PROTO_GETCONTACTBASEPROTO, hContact, 0));
}
}
/*
* protosvc
*/
namespace protosvc
{
DWORD getCaps(const mu_ansi* szProto, int flagNum)
{
return (DWORD)CallProtoService(szProto, PS_GETCAPS, static_cast<WPARAM>(flagNum), 0);
}
int getName(const mu_ansi* szProto, int cchName, mu_text* szName)
{
return CallProtoService(szProto, PS_GETNAME, static_cast<WPARAM>(cchName), reinterpret_cast<LPARAM>(szName));
}
HICON loadIcon(const mu_ansi* szProto, int whichIcon)
{
return reinterpret_cast<HICON>(CallProtoService(szProto, PS_LOADICON, static_cast<WPARAM>(whichIcon), 0));
}
}
/*
* skin
*/
namespace skin
{
HICON loadIcon(int id)
{
return reinterpret_cast<HICON>(CallService(MS_SKIN_LOADICON, id, 0));
}
}
/*
* system
*/
namespace system
{
DWORD getVersion()
{
return static_cast<DWORD>(CallService(MS_SYSTEM_GETVERSION, 0, 0));
}
int getVersionText(int cchVersion, mu_ansi* szVersion)
{
return CallService(MS_SYSTEM_GETVERSIONTEXT, cchVersion, reinterpret_cast<LPARAM>(szVersion));
}
int terminated()
{
return CallService(MS_SYSTEM_TERMINATED, 0, 0);
}
}
/*
* utils
*/
namespace utils
{
int pathToRelative(const mu_text* pszPath, mu_text* pszNewPath)
{
return CallService(MU_DO_BOTH(MS_UTILS_PATHTORELATIVE, MS_UTILS_PATHTORELATIVEW), reinterpret_cast<WPARAM>(pszPath), reinterpret_cast<LPARAM>(pszNewPath));
}
int pathToAbsolute(const mu_text* pszPath, mu_text* pszNewPath)
{
return CallService(MU_DO_BOTH(MS_UTILS_PATHTOABSOLUTE, MS_UTILS_PATHTOABSOLUTEW), reinterpret_cast<WPARAM>(pszPath), reinterpret_cast<LPARAM>(pszNewPath));
}
}
/*
* core interface functions
*/
bool load()
{
// check for version
if (!isMirandaVersionOk(system::getVersion()))
return false;
return true;
}
void unload()
{
}
DWORD getMinimalMirandaVersion()
{
// MEMO: version dependency check
return PLUGIN_MAKE_VERSION(0, 6, 7, 0);
}
bool isMirandaVersionOk(DWORD version)
{
return (version >= getMinimalMirandaVersion());
}
bool isMirandaUnicode()
{
if (system::getVersion() < PLUGIN_MAKE_VERSION(0, 4, 3, 33))
{
return false;
}
mu_ansi szVersion[256] = { 0 };
if (system::getVersionText(256, szVersion) != 0)
{
return false;
}
if (!strstr(szVersion, muA("Unicode")))
{
return false;
}
return true;
}
/*
* string handling
*/
mu_ansi* wideToAnsiDup(const mu_wide* pszWide, UINT uCP /* = CP_ACP */)
{
if (!pszWide)
{
return NULL;
}
int len = WideCharToMultiByte(uCP, 0, pszWide, -1, NULL, 0, NULL, NULL);
mu_ansi* result = reinterpret_cast<mu_ansi*>(malloc(sizeof(mu_ansi) * len));
if (!result)
{
return NULL;
}
WideCharToMultiByte(uCP, 0, pszWide, -1, result, len, NULL, NULL);
result[len - 1] = 0;
return result;
}
mu_wide* ansiToWideDup(const mu_ansi* pszAnsi, UINT uCP /* = CP_ACP */)
{
if (!pszAnsi)
{
return NULL;
}
int len = MultiByteToWideChar(uCP, 0, pszAnsi, -1, NULL, 0);
mu_wide* result = reinterpret_cast<mu_wide*>(malloc(sizeof(mu_wide) * len));
if (!result)
{
return NULL;
}
MultiByteToWideChar(uCP, 0, pszAnsi, -1, result, len);
result[len - 1] = 0;
return result;
}
mu_ansi* wideToAnsi(const mu_wide* pszWide, mu_ansi* pszRes, int maxLen, UINT uCP /* = CP_ACP */)
{
if (!pszWide)
{
return NULL;
}
WideCharToMultiByte(uCP, 0, pszWide, -1, pszRes, maxLen, NULL, NULL);
return pszRes;
}
mu_wide* ansiToWide(const mu_ansi* pszAnsi, mu_wide* pszRes, int maxLen, UINT uCP /* = CP_ACP */)
{
if (!pszAnsi)
{
return NULL;
}
MultiByteToWideChar(uCP, 0, pszAnsi, -1, pszRes, maxLen);
return pszRes;
}
}
|