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
|
#include "stdafx.h"
static HGENMENU hDisableMenu = nullptr;
static MWindowList hPopupsList = nullptr;
static uint8_t OnePopup;
static uint8_t StartDisabled;
static uint8_t StopDisabled;
static uint8_t ColorMode;
static uint8_t TimeoutMode;
static uint8_t TimeoutMode2;
static int Timeout;
static int Timeout2;
static HANDLE hntfStarted = nullptr;
static HANDLE hntfStopped = nullptr;
struct
{
int res;
char desc[10];
COLORREF color;
}
static colorPicker[4] =
{
{ IDC_TYPEON_BG, "ON_BG", RGB(255, 255, 255) },
{ IDC_TYPEON_TX, "ON_TX", RGB(0, 0, 0) },
{ IDC_TYPEOFF_BG, "OFF_BG", RGB(255, 255, 255) },
{ IDC_TYPEOFF_TX, "OFF_TX", RGB(0, 0, 0) }
};
static LRESULT CALLBACK PopupDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message) {
case WM_COMMAND:
if (HIWORD(wParam) == STN_CLICKED) {
CallService(MS_MSG_SENDMESSAGEW, (WPARAM)PUGetContact(hWnd), 0);
PUDeletePopup(hWnd);
return 1;
}
break;
case WM_CONTEXTMENU:
PUDeletePopup(hWnd);
return 1;
case UM_INITPOPUP:
WindowList_Add(hPopupsList, hWnd, PUGetContact(hWnd));
return 1;
case UM_FREEPLUGINDATA:
WindowList_Remove(hPopupsList, hWnd);
return 1;
}
return DefWindowProc(hWnd, message, wParam, lParam);
}
void TN_TypingMessage(MCONTACT hContact, int iMode)
{
// hidden & ignored contacts check
if (Contact::IsHidden(hContact) || (db_get_dw(hContact, "Ignore", "Mask1", 0) & 1)) // 9 - online notification
return;
if (!Contact::OnList(hContact) && !g_plugin.bTypingUnknown)
return;
if (!g_plugin.bPopups)
return;
wchar_t *szContactName = Clist_GetContactDisplayName(hContact);
if (OnePopup) {
HWND hPopupWnd = WindowList_Find(hPopupsList, hContact);
while (hPopupWnd) {
PUDeletePopup(hPopupWnd);
hPopupWnd = WindowList_Find(hPopupsList, hContact);
}
}
int notyping;
POPUPDATAW ppd;
if (iMode == PROTOTYPE_CONTACTTYPING_OFF) {
if (StopDisabled)
return;
wcsncpy_s(ppd.lpwzContactName, szContactName, _TRUNCATE);
wcsncpy_s(ppd.lpwzText, TranslateT("...has stopped typing."), _TRUNCATE);
ppd.hNotification = hntfStopped;
notyping = 1;
}
else {
if (StartDisabled)
return;
wcsncpy_s(ppd.lpwzContactName, szContactName, _TRUNCATE);
wcsncpy_s(ppd.lpwzText, TranslateT("...is typing a message."), _TRUNCATE);
ppd.hNotification = hntfStarted;
notyping = 0;
}
switch (ColorMode) {
case COLOR_OWN:
ppd.colorBack = colorPicker[2 * notyping].color;
ppd.colorText = colorPicker[2 * notyping + 1].color;
break;
case COLOR_WINDOWS:
ppd.colorBack = GetSysColor(COLOR_BTNFACE);
ppd.colorText = GetSysColor(COLOR_WINDOWTEXT);
break;
case COLOR_POPUP:
default:
ppd.colorBack = ppd.colorText = 0;
break;
}
if (notyping)
switch (TimeoutMode2) {
case TIMEOUT_CUSTOM:
ppd.iSeconds = Timeout2;
break;
case TIMEOUT_PERMANENT:
ppd.iSeconds = -1;
break;
case TIMEOUT_POPUP:
default:
ppd.iSeconds = 0;
break;
}
else
switch (TimeoutMode) {
case TIMEOUT_CUSTOM:
ppd.iSeconds = Timeout;
break;
case TIMEOUT_PROTO:
ppd.iSeconds = iMode;
break;
case TIMEOUT_PERMANENT:
ppd.iSeconds = -1;
break;
case TIMEOUT_POPUP:
default:
ppd.iSeconds = 0;
break;
}
ppd.lchIcon = PluginConfig.g_buttonBarIcons[ICON_DEFAULT_TYPING];
ppd.lchContact = hContact;
ppd.PluginWindowProc = PopupDlgProc;
PUAddPopupW(&ppd);
}
class CTypingOpts : public CDlgBase
{
int newTimeout, newTimeout2;
uint8_t newTimeoutMode, newTimeoutMode2, newColorMode;
CCtrlEdit value1, value2;
CCtrlCheck chkWinColors, chkPopupColors;
CCtrlCheck chkPopup, chkCustom, chkPermanent, chkProto;
CCtrlCheck chkPopup2, chkCustom2, chkPermanent2;
CCtrlButton btnPreview;
public:
CTypingOpts() :
CDlgBase(g_plugin, IDD_OPT_TYPINGNOTIFYPOPUP),
btnPreview(this, IDC_PREVIEW),
value1(this, IDC_TIMEOUT_VALUE),
value2(this, IDC_TIMEOUT_VALUE2),
chkProto(this, IDC_TIMEOUT_PROTO),
chkPopup(this, IDC_TIMEOUT_POPUP),
chkPopup2(this, IDC_TIMEOUT_POPUP2),
chkCustom(this, IDC_TIMEOUT_CUSTOM),
chkCustom2(this, IDC_TIMEOUT_CUSTOM2),
chkPermanent(this, IDC_TIMEOUT_PERMANENT),
chkPermanent2(this, IDC_TIMEOUT_PERMANENT2),
chkWinColors(this, IDC_USEWINCOLORS),
chkPopupColors(this, IDC_USEPOPUPCOLORS)
{
btnPreview.OnClick = Callback(this, &CTypingOpts::onClick_Preview);
value1.OnChange = value2.OnChange = Callback(this, &CTypingOpts::onChange_Value);
chkPopup.OnChange = Callback(this, &CTypingOpts::onChange_Popup);
chkProto.OnChange = Callback(this, &CTypingOpts::onChange_Proto);
chkCustom.OnChange = Callback(this, &CTypingOpts::onChange_Custom);
chkPermanent.OnChange = Callback(this, &CTypingOpts::onChange_Permanent);
chkPopup2.OnChange = Callback(this, &CTypingOpts::onChange_Popup2);
chkCustom2.OnChange = Callback(this, &CTypingOpts::onChange_Custom2);
chkPermanent2.OnChange = Callback(this, &CTypingOpts::onChange_Permanent2);
chkWinColors.OnChange = Callback(this, &CTypingOpts::onChange_UseWinColors);
chkPopupColors.OnChange = Callback(this, &CTypingOpts::onChange_UsePopupColors);
}
bool OnInitDialog() override
{
bool bWindows = (ColorMode == COLOR_WINDOWS);
chkWinColors.SetState(bWindows);
chkWinColors.Enable(bWindows);
chkPopupColors.SetState(!bWindows);
chkPopupColors.Enable(!bWindows);
for (auto &it : colorPicker) {
SendDlgItemMessage(m_hwnd, it.res, CPM_SETCOLOUR, 0, it.color);
Utils::enableDlgControl(m_hwnd, it.res, (ColorMode == COLOR_OWN));
}
chkPopup.SetState(TimeoutMode == TIMEOUT_POPUP);
chkProto.SetState(TimeoutMode == TIMEOUT_PROTO);
chkCustom.SetState(TimeoutMode == TIMEOUT_CUSTOM);
chkPermanent.SetState(TimeoutMode == TIMEOUT_PERMANENT);
value1.SetInt(Timeout);
Utils::enableDlgControl(m_hwnd, IDC_TIMEOUT_VALUE, TimeoutMode == TIMEOUT_CUSTOM);
chkPopup2.SetState(TimeoutMode2 == TIMEOUT_POPUP);
chkCustom2.SetState(TimeoutMode2 == TIMEOUT_CUSTOM);
chkPermanent2.SetState(TimeoutMode2 == TIMEOUT_PERMANENT);
value2.SetInt(Timeout2);
Utils::enableDlgControl(m_hwnd, IDC_TIMEOUT_VALUE2, TimeoutMode2 == TIMEOUT_CUSTOM);
CheckDlgButton(m_hwnd, IDC_START, (StartDisabled) ? BST_UNCHECKED : BST_CHECKED);
CheckDlgButton(m_hwnd, IDC_STOP, (StopDisabled) ? BST_UNCHECKED : BST_CHECKED);
CheckDlgButton(m_hwnd, IDC_ONEPOPUP, (OnePopup) ? BST_CHECKED : BST_UNCHECKED);
newTimeout = Timeout;
newTimeoutMode = TimeoutMode;
newTimeout2 = Timeout2;
newTimeoutMode2 = TimeoutMode2;
newColorMode = ColorMode;
return true;
}
bool OnApply() override
{
for (int i = 0; i < sizeof(colorPicker) / sizeof(colorPicker[0]); i++) {
colorPicker[i].color = SendDlgItemMessage(m_hwnd, colorPicker[i].res, CPM_GETCOLOUR, 0, 0);
db_set_dw(0, TypingModule, colorPicker[i].desc, colorPicker[i].color);
}
Timeout = newTimeout; TimeoutMode = newTimeoutMode;
Timeout2 = newTimeout2; TimeoutMode2 = newTimeoutMode2;
ColorMode = newColorMode;
StartDisabled = IsDlgButtonChecked(m_hwnd, IDC_START) ? 0 : 2;
StopDisabled = IsDlgButtonChecked(m_hwnd, IDC_STOP) ? 0 : 4;
OnePopup = IsDlgButtonChecked(m_hwnd, IDC_ONEPOPUP);
db_set_b(0, TypingModule, SET_ONEPOPUP, OnePopup);
db_set_b(0, TypingModule, SET_DISABLED, (uint8_t)(StartDisabled | StopDisabled));
db_set_b(0, TypingModule, SET_COLOR_MODE, ColorMode);
db_set_b(0, TypingModule, SET_TIMEOUT_MODE, TimeoutMode);
db_set_b(0, TypingModule, SET_TIMEOUT, (uint8_t)Timeout);
db_set_b(0, TypingModule, SET_TIMEOUT_MODE2, TimeoutMode2);
db_set_b(0, TypingModule, SET_TIMEOUT2, (uint8_t)Timeout2);
return true;
}
void onChange_UseWinColors(CCtrlCheck *pCheck)
{
bool bEnableOthers;
if (pCheck->IsChecked()) {
newColorMode = COLOR_WINDOWS;
bEnableOthers = false;
}
else {
newColorMode = COLOR_OWN;
bEnableOthers = true;
}
for (auto &it : colorPicker)
Utils::enableDlgControl(m_hwnd, it.res, bEnableOthers);
chkPopupColors.Enable(bEnableOthers);
}
void onChange_UsePopupColors(CCtrlCheck *pCheck)
{
bool bEnableOthers;
if (pCheck->IsChecked()) {
newColorMode = COLOR_POPUP;
bEnableOthers = false;
}
else {
newColorMode = COLOR_OWN;
bEnableOthers = true;
}
for (int i = 0; i < sizeof(colorPicker) / sizeof(colorPicker[0]); i++)
Utils::enableDlgControl(m_hwnd, colorPicker[i].res, bEnableOthers);
chkWinColors.Enable(bEnableOthers);
}
void onClick_Preview(CCtrlButton *)
{
for (int i = 0; i < 2; i++) {
POPUPDATAW ppd;
int notyping;
if (i == PROTOTYPE_CONTACTTYPING_OFF) {
wcsncpy_s(ppd.lpwzContactName, TranslateT("Contact"), _TRUNCATE);
wcsncpy_s(ppd.lpwzText, TranslateT("...has stopped typing."), _TRUNCATE);
notyping = 1;
}
else {
wcsncpy_s(ppd.lpwzContactName, TranslateT("Contact"), _TRUNCATE);
wcsncpy_s(ppd.lpwzText, TranslateT("...is typing a message."), _TRUNCATE);
notyping = 0;
}
switch (newColorMode) {
case COLOR_OWN:
ppd.colorText = SendDlgItemMessage(m_hwnd, colorPicker[2 * notyping + 1].res, CPM_GETCOLOUR, 0, 0);
ppd.colorBack = SendDlgItemMessage(m_hwnd, colorPicker[2 * notyping].res, CPM_GETCOLOUR, 0, 0);
break;
case COLOR_WINDOWS:
ppd.colorBack = GetSysColor(COLOR_BTNFACE);
ppd.colorText = GetSysColor(COLOR_WINDOWTEXT);
break;
case COLOR_POPUP:
default:
ppd.colorBack = ppd.colorText = 0;
break;
}
if (notyping)
switch (newTimeoutMode2) {
case TIMEOUT_CUSTOM:
ppd.iSeconds = newTimeout2;
break;
case TIMEOUT_PERMANENT:
ppd.iSeconds = -1;
break;
case TIMEOUT_POPUP:
default:
ppd.iSeconds = 0;
break;
}
else
switch (newTimeoutMode) {
case TIMEOUT_CUSTOM:
ppd.iSeconds = newTimeout;
break;
case TIMEOUT_PROTO:
ppd.iSeconds = 10;
break;
case TIMEOUT_PERMANENT:
ppd.iSeconds = -1;
break;
case TIMEOUT_POPUP:
default:
ppd.iSeconds = 0;
break;
}
ppd.lchIcon = PluginConfig.g_buttonBarIcons[ICON_DEFAULT_TYPING];
ppd.lchContact = 0;
ppd.PluginWindowProc = nullptr;
ppd.PluginData = nullptr;
PUAddPopupW(&ppd);
}
}
void onChange_Popup2(CCtrlCheck *)
{
newTimeoutMode2 = TIMEOUT_POPUP;
Utils::enableDlgControl(m_hwnd, IDC_TIMEOUT_VALUE2, 0);
}
void onChange_Custom2(CCtrlCheck *)
{
newTimeoutMode2 = TIMEOUT_CUSTOM;
Utils::enableDlgControl(m_hwnd, IDC_TIMEOUT_VALUE2, 1);
}
void onChange_Popup(CCtrlCheck *)
{
newTimeoutMode = TIMEOUT_POPUP;
Utils::enableDlgControl(m_hwnd, IDC_TIMEOUT_VALUE, 0);
}
void onChange_Permanent(CCtrlCheck *)
{
newTimeoutMode = TIMEOUT_PERMANENT;
Utils::enableDlgControl(m_hwnd, IDC_TIMEOUT_VALUE, 0);
}
void onChange_Permanent2(CCtrlCheck *)
{
newTimeoutMode2 = TIMEOUT_PERMANENT;
Utils::enableDlgControl(m_hwnd, IDC_TIMEOUT_VALUE2, 0);
}
void onChange_Custom(CCtrlCheck *)
{
newTimeoutMode = TIMEOUT_CUSTOM;
Utils::enableDlgControl(m_hwnd, IDC_TIMEOUT_VALUE, 1);
}
void onChange_Proto(CCtrlCheck *)
{
newTimeoutMode = TIMEOUT_PROTO;
Utils::enableDlgControl(m_hwnd, IDC_TIMEOUT_VALUE, 0);
}
void onChange_Value(CCtrlEdit *pEdit)
{
int newValue = pEdit->GetInt();
if (newValue > TIMEOUT_MAXVALUE)
newValue = TIMEOUT_MAXVALUE;
else if (newValue < TIMEOUT_MINVALUE)
newValue = TIMEOUT_MINVALUE;
if (pEdit->GetCtrlId() == IDC_TIMEOUT_VALUE)
newTimeout = newValue;
else
newTimeout2 = newValue;
}
};
int TN_OptionsInitialize(WPARAM wParam, LPARAM)
{
OPTIONSDIALOGPAGE odp = {};
odp.flags = ODPF_BOLDGROUPS;
odp.position = 100000000;
odp.szTitle.a = LPGEN("Typing notify");
odp.szGroup.a = LPGEN("Popups");
odp.pDialog = new CTypingOpts();
g_plugin.addOptions(wParam, &odp);
return 0;
}
int TN_ModuleInit()
{
hPopupsList = WindowList_Create();
OnePopup = db_get_b(0, TypingModule, SET_ONEPOPUP, DEF_ONEPOPUP);
int i = db_get_b(0, TypingModule, SET_DISABLED, DEF_DISABLED);
if (i & 1)
g_plugin.bPopups = false;
StartDisabled = i & 2;
StopDisabled = i & 4;
ColorMode = db_get_b(0, TypingModule, SET_COLOR_MODE, DEF_COLOR_MODE);
TimeoutMode = db_get_b(0, TypingModule, SET_TIMEOUT_MODE, DEF_TIMEOUT_MODE);
Timeout = db_get_b(0, TypingModule, SET_TIMEOUT, DEF_TIMEOUT);
TimeoutMode2 = db_get_b(0, TypingModule, SET_TIMEOUT_MODE2, DEF_TIMEOUT_MODE2);
Timeout2 = db_get_b(0, TypingModule, SET_TIMEOUT2, DEF_TIMEOUT2);
if (!(db_get_dw(0, TypingModule, colorPicker[0].desc, 1) && !db_get_dw(0, TypingModule, colorPicker[0].desc, 0)))
for (auto &it : colorPicker)
it.color = db_get_dw(0, TypingModule, it.desc, 0);
g_plugin.addPopupOption(LPGEN("Typing notifications"), g_plugin.bPopups);
g_plugin.addSound("TNStart", LPGENW("Instant messages"), LPGENW("Contact started typing"));
g_plugin.addSound("TNStop", LPGENW("Instant messages"), LPGENW("Contact stopped typing"));
return 0;
}
int TN_ModuleDeInit()
{
WindowList_Destroy(hPopupsList);
db_set_b(0, TypingModule, SET_DISABLED, (uint8_t)(StartDisabled | StopDisabled));
return 0;
}
|