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
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
|
/*
Scriver
Copyright (c) 2000-12 Miranda ICQ/IM project,
all portions of this codebase are copyrighted to the people
listed in contributors.txt.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "stdafx.h"
#define VALID_AVATAR(x) (x==PA_FORMAT_PNG||x==PA_FORMAT_JPEG||x==PA_FORMAT_ICON||x==PA_FORMAT_BMP||x==PA_FORMAT_GIF)
#define ENTERCLICKTIME 1000 //max time in ms during which a double-tap on enter will cause a send
extern HCURSOR hCurSplitNS, hCurSplitWE, hCurHyperlinkHand, hDragCursor;
extern HANDLE hHookWinEvt;
static void UpdateReadChars(HWND hwndDlg, SrmmWindowData * dat);
static wchar_t* GetIEViewSelection(SrmmWindowData *dat)
{
IEVIEWEVENT evt = { sizeof(evt) };
evt.hwnd = dat->hwndLog;
evt.hContact = dat->hContact;
evt.iType = IEE_GET_SELECTION;
return mir_wstrdup((wchar_t*)CallService(MS_IEVIEW_EVENT, 0, (LPARAM)&evt));
}
static wchar_t* GetQuotedTextW(wchar_t *text)
{
size_t i, j, l = mir_wstrlen(text);
int newLine = 1;
int wasCR = 0;
for (i = j = 0; i < l; i++) {
if (text[i] == '\r') {
wasCR = 1;
newLine = 1;
j += text[i + 1] != '\n' ? 2 : 1;
}
else if (text[i] == '\n') {
newLine = 1;
j += wasCR ? 1 : 2;
wasCR = 0;
}
else {
j++;
if (newLine) {
//for (;i<l && text[i]=='>';i++) j--;
j += 2;
}
newLine = 0;
wasCR = 0;
}
}
j += 3;
wchar_t *out = (wchar_t*)mir_alloc(sizeof(wchar_t)* j);
newLine = 1;
wasCR = 0;
for (i = j = 0; i < l; i++) {
if (text[i] == '\r') {
wasCR = 1;
newLine = 1;
out[j++] = '\r';
if (text[i + 1] != '\n')
out[j++] = '\n';
}
else if (text[i] == '\n') {
newLine = 1;
if (!wasCR)
out[j++] = '\r';
out[j++] = '\n';
wasCR = 0;
}
else {
if (newLine) {
out[j++] = '>';
out[j++] = ' ';
//for (;i<l && text[i]=='>';i++) j--;
}
newLine = 0;
wasCR = 0;
out[j++] = text[i];
}
}
out[j++] = '\r';
out[j++] = '\n';
out[j++] = '\0';
return out;
}
void NotifyLocalWinEvent(MCONTACT hContact, HWND hwnd, unsigned int type)
{
if (hContact == NULL || hwnd == NULL)
return;
MessageWindowEventData mwe = { sizeof(mwe) };
mwe.hContact = hContact;
mwe.hwndWindow = hwnd;
mwe.szModule = SRMMMOD;
mwe.uType = type;
mwe.uFlags = MSG_WINDOW_UFLAG_MSG_BOTH;
if (WindowList_Find(pci->hWindowList, hContact)) {
mwe.hwndInput = GetDlgItem(hwnd, IDC_MESSAGE);
mwe.hwndLog = GetDlgItem(hwnd, IDC_LOG);
}
else {
mwe.hwndInput = GetDlgItem(hwnd, IDC_CHAT_MESSAGE);
mwe.hwndLog = GetDlgItem(hwnd, IDC_CHAT_LOG);
}
NotifyEventHooks(hHookWinEvt, 0, (LPARAM)&mwe);
}
int RTL_Detect(WCHAR *pszwText)
{
size_t iLen = mir_wstrlen(pszwText);
WORD *infoTypeC2 = (WORD *)mir_calloc(sizeof(WORD) * (iLen + 2));
if (infoTypeC2) {
GetStringTypeW(CT_CTYPE2, pszwText, (int)iLen, infoTypeC2);
for (size_t i = 0; i < iLen; i++) {
if (infoTypeC2[i] == C2_RIGHTTOLEFT) {
mir_free(infoTypeC2);
return 1;
}
}
mir_free(infoTypeC2);
}
return 0;
}
static void AddToFileList(wchar_t ***pppFiles, int *totalCount, const wchar_t* szFilename)
{
*pppFiles = (wchar_t**)mir_realloc(*pppFiles, (++*totalCount + 1)*sizeof(wchar_t*));
(*pppFiles)[*totalCount] = NULL;
(*pppFiles)[*totalCount - 1] = mir_wstrdup(szFilename);
if (GetFileAttributes(szFilename) & FILE_ATTRIBUTE_DIRECTORY) {
WIN32_FIND_DATA fd;
wchar_t szPath[MAX_PATH];
mir_snwprintf(szPath, L"%s\\*", szFilename);
HANDLE hFind = FindFirstFile(szPath, &fd);
if (hFind != INVALID_HANDLE_VALUE) {
do {
if (!mir_wstrcmp(fd.cFileName, L".") || !mir_wstrcmp(fd.cFileName, L"..")) continue;
mir_snwprintf(szPath, L"%s\\%s", szFilename, fd.cFileName);
AddToFileList(pppFiles, totalCount, szPath);
} while (FindNextFile(hFind, &fd));
FindClose(hFind);
}
}
}
static void SetDialogToType(HWND hwndDlg)
{
BOOL showToolbar = SendMessage(GetParent(hwndDlg), CM_GETTOOLBARSTATUS, 0, 0);
SrmmWindowData *dat = (SrmmWindowData *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
ParentWindowData *pdat = dat->parent;
if (pdat->flags2 & SMF2_SHOWINFOBAR)
ShowWindow(dat->infobarData->hWnd, SW_SHOW);
else
ShowWindow(dat->infobarData->hWnd, SW_HIDE);
CustomButtonData *cbd;
for (int i = 0; cbd = Srmm_GetNthButton(i); i++) {
HWND hwndButton = GetDlgItem(hwndDlg, cbd->m_dwButtonCID);
if (hwndButton == NULL)
continue;
if (dat->hContact) {
if (cbd->m_dwButtonCID == IDC_ADD && !db_get_b(dat->hContact, "CList", "NotOnList", 0))
ShowWindow(hwndButton, SW_HIDE);
else
ShowWindow(hwndButton, showToolbar ? SW_SHOW : SW_HIDE);
}
else ShowWindow(hwndButton, SW_HIDE);
}
ShowWindow(GetDlgItem(hwndDlg, IDC_MESSAGE), SW_SHOW);
if (dat->hwndLog != NULL)
ShowWindow(GetDlgItem(hwndDlg, IDC_LOG), SW_HIDE);
else
ShowWindow(GetDlgItem(hwndDlg, IDC_LOG), SW_SHOW);
ShowWindow(GetDlgItem(hwndDlg, IDC_SPLITTERY), SW_SHOW);
UpdateReadChars(hwndDlg, dat);
EnableWindow(GetDlgItem(hwndDlg, IDOK), GetRichTextLength(GetDlgItem(hwndDlg, IDC_MESSAGE), 1200, FALSE) ? TRUE : FALSE);
SendMessage(hwndDlg, DM_CLISTSETTINGSCHANGED, 0, 0);
SendMessage(hwndDlg, WM_SIZE, 0, 0);
}
void SetStatusIcon(SrmmWindowData *dat)
{
if (dat->szProto == NULL)
return;
MCONTACT hContact = db_mc_getSrmmSub(dat->hContact);
if (hContact == NULL)
hContact = dat->hContact;
char *szProto = GetContactProto(hContact);
dat->statusIcon = Skin_LoadProtoIcon(szProto, dat->wStatus, false);
dat->statusIconBig = Skin_LoadProtoIcon(szProto, dat->wStatus, true);
if (dat->statusIconOverlay != NULL)
DestroyIcon(dat->statusIconOverlay);
int index = ImageList_ReplaceIcon(g_dat.hHelperIconList, 0, dat->statusIcon);
dat->statusIconOverlay = ImageList_GetIcon(g_dat.hHelperIconList, index, ILD_TRANSPARENT | INDEXTOOVERLAYMASK(1));
}
void GetTitlebarIcon(SrmmWindowData *dat, TitleBarData *tbd)
{
if (dat->showTyping && (g_dat.flags2 & SMF2_SHOWTYPINGWIN))
tbd->hIconNot = tbd->hIcon = GetCachedIcon("scriver_TYPING");
else if (dat->showUnread && (GetActiveWindow() != dat->hwndParent || GetForegroundWindow() != dat->hwndParent)) {
tbd->hIcon = (g_dat.flags & SMF_STATUSICON) ? dat->statusIcon : g_dat.hMsgIcon;
tbd->hIconNot = (g_dat.flags & SMF_STATUSICON) ? g_dat.hMsgIcon : GetCachedIcon("scriver_OVERLAY");
}
else {
tbd->hIcon = (g_dat.flags & SMF_STATUSICON) ? dat->statusIcon : g_dat.hMsgIcon;
tbd->hIconNot = NULL;
}
tbd->hIconBig = (g_dat.flags & SMF_STATUSICON) ? dat->statusIconBig : g_dat.hMsgIconBig;
}
HICON GetTabIcon(SrmmWindowData *dat)
{
if (dat->showTyping)
return GetCachedIcon("scriver_TYPING");
if (dat->showUnread != 0)
return dat->statusIconOverlay;
return dat->statusIcon;
}
static LRESULT CALLBACK LogEditSubclassProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
static BOOL inMenu = FALSE;
switch (msg) {
case WM_MEASUREITEM:
MeasureMenuItem(wParam, lParam);
return TRUE;
case WM_DRAWITEM:
return DrawMenuItem(wParam, lParam);
case WM_SETCURSOR:
if (inMenu) {
SetCursor(LoadCursor(NULL, IDC_ARROW));
return TRUE;
}
break;
case WM_CONTEXTMENU:
HMENU hMenu = LoadMenu(g_hInst, MAKEINTRESOURCE(IDR_CONTEXT));
HMENU hSubMenu = GetSubMenu(hMenu, 0);
TranslateMenu(hSubMenu);
CHARRANGE sel, all = { 0, -1 };
SendMessage(hwnd, EM_EXGETSEL, 0, (LPARAM)&sel);
if (sel.cpMin == sel.cpMax)
EnableMenuItem(hSubMenu, IDM_COPY, MF_BYCOMMAND | MF_GRAYED);
POINT pt;
if (lParam == 0xFFFFFFFF) {
SendMessage(hwnd, EM_POSFROMCHAR, (WPARAM)&pt, (LPARAM)sel.cpMax);
ClientToScreen(hwnd, &pt);
}
else {
pt.x = GET_X_LPARAM(lParam);
pt.y = GET_Y_LPARAM(lParam);
}
POINTL ptl = { (LONG)pt.x, (LONG)pt.y };
ScreenToClient(hwnd, (LPPOINT)&ptl);
ptrW pszWord(GetRichTextWord(hwnd, &ptl));
if (pszWord && pszWord[0]) {
wchar_t szMenuText[4096];
mir_snwprintf(szMenuText, TranslateT("Look up '%s':"), pszWord);
ModifyMenu(hSubMenu, 5, MF_STRING | MF_BYPOSITION, 5, szMenuText);
SetSearchEngineIcons(hMenu, g_dat.hSearchEngineIconList);
}
else ModifyMenu(hSubMenu, 5, MF_STRING | MF_GRAYED | MF_BYPOSITION, 5, TranslateT("No word to look up"));
inMenu = TRUE;
int uID = TrackPopupMenu(hSubMenu, TPM_RETURNCMD, pt.x, pt.y, 0, hwnd, NULL);
inMenu = FALSE;
switch (uID) {
case IDM_COPY:
SendMessage(hwnd, WM_COPY, 0, 0);
break;
case IDM_COPYALL:
SendMessage(hwnd, EM_EXSETSEL, 0, (LPARAM)&all);
SendMessage(hwnd, WM_COPY, 0, 0);
SendMessage(hwnd, EM_EXSETSEL, 0, (LPARAM)&sel);
break;
case IDM_SELECTALL:
SendMessage(hwnd, EM_EXSETSEL, 0, (LPARAM)&all);
break;
case IDM_CLEAR:
SendMessage(GetParent(hwnd), DM_CLEARLOG, 0, 0);
break;
case IDM_SEARCH_GOOGLE:
case IDM_SEARCH_BING:
case IDM_SEARCH_YANDEX:
case IDM_SEARCH_YAHOO:
case IDM_SEARCH_WIKIPEDIA:
case IDM_SEARCH_FOODNETWORK:
case IDM_SEARCH_GOOGLE_MAPS:
case IDM_SEARCH_GOOGLE_TRANSLATE:
SearchWord(pszWord, uID - IDM_SEARCH_GOOGLE + SEARCHENGINE_GOOGLE);
PostMessage(GetParent(hwnd), WM_MOUSEACTIVATE, 0, 0);
break;
}
DestroyMenu(hMenu);
return TRUE;
}
return mir_callNextSubclass(hwnd, LogEditSubclassProc, msg, wParam, lParam);
}
/////////////////////////////////////////////////////////////////////////////////////////
struct MsgEditSubclassData
{
DWORD lastEnterTime;
};
static LRESULT CALLBACK MessageEditSubclassProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
MsgEditSubclassData *dat = (MsgEditSubclassData*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
SrmmWindowData *pdat = (SrmmWindowData*)GetWindowLongPtr(GetParent(hwnd), GWLP_USERDATA);
int result = InputAreaShortcuts(hwnd, msg, wParam, lParam, pdat);
if (result != -1)
return result;
BOOL isCtrl = GetKeyState(VK_CONTROL) & 0x8000;
BOOL isAlt = GetKeyState(VK_MENU) & 0x8000;
switch (msg) {
case EM_SUBCLASSED:
dat = (MsgEditSubclassData*)mir_alloc(sizeof(MsgEditSubclassData));
SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)dat);
DragAcceptFiles(hwnd, TRUE);
dat->lastEnterTime = 0;
return 0;
case WM_KEYDOWN:
if (wParam == VK_RETURN) {
if ((isCtrl != 0) ^ (0 != (g_dat.flags & SMF_SENDONENTER))) {
PostMessage(GetParent(hwnd), WM_COMMAND, IDOK, 0);
return 0;
}
if (g_dat.flags & SMF_SENDONDBLENTER) {
if (dat->lastEnterTime + ENTERCLICKTIME < GetTickCount())
dat->lastEnterTime = GetTickCount();
else {
SendMessage(hwnd, WM_KEYDOWN, VK_BACK, 0);
SendMessage(hwnd, WM_KEYUP, VK_BACK, 0);
PostMessage(GetParent(hwnd), WM_COMMAND, IDOK, 0);
return 0;
}
}
}
else dat->lastEnterTime = 0;
break;
case WM_MOUSEWHEEL:
if ((GetWindowLongPtr(hwnd, GWL_STYLE) & WS_VSCROLL) == 0)
SendDlgItemMessage(GetParent(hwnd), IDC_LOG, WM_MOUSEWHEEL, wParam, lParam);
break;
case WM_LBUTTONDOWN:
case WM_RBUTTONDOWN:
case WM_MBUTTONDOWN:
case WM_KILLFOCUS:
dat->lastEnterTime = 0;
break;
case WM_SYSCHAR:
dat->lastEnterTime = 0;
if ((wParam == 's' || wParam == 'S') && isAlt) {
PostMessage(GetParent(hwnd), WM_COMMAND, IDOK, 0);
return 0;
}
break;
case EM_PASTESPECIAL:
case WM_PASTE:
if (IsClipboardFormatAvailable(CF_HDROP)) {
if (OpenClipboard(hwnd)) {
HANDLE hDrop = GetClipboardData(CF_HDROP);
if (hDrop)
SendMessage(GetParent(hwnd), WM_DROPFILES, (WPARAM)hDrop, 0);
CloseClipboard();
}
return 0;
}
break;
case WM_DROPFILES:
SendMessage(GetParent(hwnd), WM_DROPFILES, wParam, lParam);
return 0;
case WM_CONTEXTMENU:
InputAreaContextMenu(hwnd, wParam, lParam, pdat->hContact);
return TRUE;
case WM_DESTROY:
mir_free(dat);
break;
}
return mir_callNextSubclass(hwnd, MessageEditSubclassProc, msg, wParam, lParam);
}
static void SubclassMessageEdit(HWND hwnd)
{
RichUtil_SubClass(hwnd);
mir_subclassWindow(hwnd, MessageEditSubclassProc);
SendMessage(hwnd, EM_SUBCLASSED, 0, 0);
}
static void SubclassLogEdit(HWND hwnd)
{
RichUtil_SubClass(hwnd);
mir_subclassWindow(hwnd, LogEditSubclassProc);
SendMessage(hwnd, EM_SUBCLASSED, 0, 0);
}
static void MessageDialogResize(HWND hwndDlg, SrmmWindowData *dat, int w, int h)
{
ParentWindowData *pdat = dat->parent;
int hSplitterPos = dat->splitterPos, toolbarHeight = dat->toolbarSize.cy;
int hSplitterMinTop = toolbarHeight + dat->minLogBoxHeight, hSplitterMinBottom = dat->minEditBoxHeight;
int infobarInnerHeight = INFO_BAR_INNER_HEIGHT;
int infobarHeight = INFO_BAR_HEIGHT;
int avatarWidth = 0, avatarHeight = 0;
int toolbarWidth = w;
int messageEditWidth = w - 2;
int logY, logH;
if (!dat->infobarData)
return;
if (!(pdat->flags2 & SMF2_SHOWINFOBAR)) {
infobarHeight = 0;
infobarInnerHeight = 0;
}
hSplitterPos = dat->desiredInputAreaHeight + SPLITTER_HEIGHT + 3;
if (hSplitterPos > (h - toolbarHeight - infobarHeight + SPLITTER_HEIGHT + 1) / 2)
hSplitterPos = (h - toolbarHeight - infobarHeight + SPLITTER_HEIGHT + 1) / 2;
if (h - hSplitterPos - infobarHeight < hSplitterMinTop)
hSplitterPos = h - hSplitterMinTop - infobarHeight;
if (hSplitterPos < avatarHeight)
hSplitterPos = avatarHeight;
if (hSplitterPos < hSplitterMinBottom)
hSplitterPos = hSplitterMinBottom;
if (!(pdat->flags2 & SMF2_SHOWINFOBAR)) {
if (dat->avatarPic && (g_dat.flags & SMF_AVATAR)) {
avatarWidth = BOTTOM_RIGHT_AVATAR_HEIGHT;
avatarHeight = toolbarHeight + hSplitterPos - 2;
if (avatarHeight < BOTTOM_RIGHT_AVATAR_HEIGHT) {
avatarHeight = BOTTOM_RIGHT_AVATAR_HEIGHT;
hSplitterPos = avatarHeight - toolbarHeight + 2;
}
else avatarHeight = BOTTOM_RIGHT_AVATAR_HEIGHT;
avatarWidth = avatarHeight;
if (avatarWidth > BOTTOM_RIGHT_AVATAR_HEIGHT && avatarWidth > w / 4)
avatarWidth = w / 4;
if ((toolbarWidth - avatarWidth - 2) < dat->toolbarSize.cx)
avatarWidth = toolbarWidth - dat->toolbarSize.cx - 2;
toolbarWidth -= avatarWidth + 2;
messageEditWidth -= avatarWidth + 1;
}
}
dat->splitterPos = hSplitterPos;
logY = infobarInnerHeight;
logH = h - hSplitterPos - toolbarHeight - infobarInnerHeight;
HDWP hdwp = BeginDeferWindowPos(5);
hdwp = DeferWindowPos(hdwp, dat->infobarData->hWnd, 0, 1, 0, w - 2, infobarInnerHeight - 2, SWP_NOZORDER);
hdwp = DeferWindowPos(hdwp, GetDlgItem(hwndDlg, IDC_LOG), 0, 1, logY, w - 2, logH, SWP_NOZORDER);
hdwp = DeferWindowPos(hdwp, GetDlgItem(hwndDlg, IDC_MESSAGE), 0, 1, h - hSplitterPos + SPLITTER_HEIGHT, messageEditWidth, hSplitterPos - SPLITTER_HEIGHT - 1, SWP_NOZORDER);
hdwp = DeferWindowPos(hdwp, GetDlgItem(hwndDlg, IDC_AVATAR), 0, w - avatarWidth - 1, h - (avatarHeight + avatarWidth) / 2 - 1, avatarWidth, avatarWidth, SWP_NOZORDER);
hdwp = DeferWindowPos(hdwp, GetDlgItem(hwndDlg, IDC_SPLITTERY), 0, 0, h - hSplitterPos - 1, toolbarWidth, SPLITTER_HEIGHT, SWP_NOZORDER);
EndDeferWindowPos(hdwp);
SetButtonsPos(hwndDlg);
if (dat->hwndLog != NULL) {
IEVIEWWINDOW ieWindow = { sizeof(ieWindow) };
ieWindow.iType = IEW_SETPOS;
ieWindow.parent = hwndDlg;
ieWindow.hwnd = dat->hwndLog;
ieWindow.x = 0;
ieWindow.y = logY;
ieWindow.cx = w;
ieWindow.cy = logH;
CallService(MS_IEVIEW_WINDOW, 0, (LPARAM)&ieWindow);
}
else RedrawWindow(GetDlgItem(hwndDlg, IDC_LOG), NULL, NULL, RDW_INVALIDATE);
RedrawWindow(GetDlgItem(hwndDlg, IDC_MESSAGE), NULL, NULL, RDW_INVALIDATE);
RefreshInfobar(dat->infobarData);
RedrawWindow(GetDlgItem(hwndDlg, IDC_AVATAR), NULL, NULL, RDW_INVALIDATE);
}
static void UpdateReadChars(HWND hwndDlg, SrmmWindowData *dat)
{
if (dat->parent->hwndActive == hwndDlg) {
wchar_t szText[256];
int len = GetRichTextLength(GetDlgItem(hwndDlg, IDC_MESSAGE), 1200, FALSE);
StatusBarData sbd;
sbd.iItem = 1;
sbd.iFlags = SBDF_TEXT | SBDF_ICON;
sbd.hIcon = NULL;
sbd.pszText = szText;
mir_snwprintf(szText, L"%d", len);
SendMessage(dat->hwndParent, CM_UPDATESTATUSBAR, (WPARAM)&sbd, (LPARAM)hwndDlg);
}
}
void ShowAvatar(HWND hwndDlg, SrmmWindowData *dat)
{
INT_PTR res = CallService(MS_AV_GETAVATARBITMAP, dat->hContact, 0);
dat->ace = res != CALLSERVICE_NOTFOUND ? (AVATARCACHEENTRY*)res : NULL;
dat->avatarPic = (dat->ace != NULL && (dat->ace->dwFlags & AVS_HIDEONCLIST) == 0) ? dat->ace->hbmPic : NULL;
SendMessage(hwndDlg, WM_SIZE, 0, 0);
RefreshInfobar(dat->infobarData);
RedrawWindow(GetDlgItem(hwndDlg, IDC_AVATAR), NULL, NULL, RDW_INVALIDATE);
}
static BOOL IsTypingNotificationSupported(SrmmWindowData *dat)
{
if (!dat->hContact)
return FALSE;
if (!dat->szProto)
return FALSE;
DWORD typeCaps = CallProtoService(dat->szProto, PS_GETCAPS, PFLAGNUM_4, 0);
if (!(typeCaps & PF4_SUPPORTTYPING))
return FALSE;
return TRUE;
}
static BOOL IsTypingNotificationEnabled(SrmmWindowData *dat)
{
if (!db_get_b(dat->hContact, SRMMMOD, SRMSGSET_TYPING, db_get_b(NULL, SRMMMOD, SRMSGSET_TYPINGNEW, SRMSGDEFSET_TYPINGNEW)))
return FALSE;
DWORD protoStatus = CallProtoService(dat->szProto, PS_GETSTATUS, 0, 0);
if (protoStatus < ID_STATUS_ONLINE)
return FALSE;
DWORD protoCaps = CallProtoService(dat->szProto, PS_GETCAPS, PFLAGNUM_1, 0);
if (protoCaps & PF1_VISLIST && db_get_w(dat->hContact, dat->szProto, "ApparentMode", 0) == ID_STATUS_OFFLINE)
return FALSE;
if (protoCaps & PF1_INVISLIST && protoStatus == ID_STATUS_INVISIBLE && db_get_w(dat->hContact, dat->szProto, "ApparentMode", 0) != ID_STATUS_ONLINE)
return FALSE;
if (db_get_b(dat->hContact, "CList", "NotOnList", 0)
&& !db_get_b(NULL, SRMMMOD, SRMSGSET_TYPINGUNKNOWN, SRMSGDEFSET_TYPINGUNKNOWN))
return FALSE;
return TRUE;
}
// Don't send to protocols who don't support typing
// Don't send to users who are unchecked in the typing notification options
// Don't send to protocols that are offline
// Don't send to users who are not visible and
// Don't send to users who are not on the visible list when you are in invisible mode.
static void NotifyTyping(SrmmWindowData *dat, int mode)
{
if (!IsTypingNotificationSupported(dat))
return;
if (!IsTypingNotificationEnabled(dat))
return;
// End user check
dat->nTypeMode = mode;
CallService(MS_PROTO_SELFISTYPING, dat->hContact, dat->nTypeMode);
}
static INT_PTR CALLBACK ConfirmSendAllDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM)
{
switch (msg) {
case WM_INITDIALOG:
RECT rcParent, rcChild;
TranslateDialogDefault(hwndDlg);
GetWindowRect(GetParent(hwndDlg), &rcParent);
GetWindowRect(hwndDlg, &rcChild);
rcChild.bottom -= rcChild.top;
rcChild.right -= rcChild.left;
rcParent.bottom -= rcParent.top;
rcParent.right -= rcParent.left;
rcChild.left = rcParent.left + (rcParent.right - rcChild.right) / 2;
rcChild.top = rcParent.top + (rcParent.bottom - rcChild.bottom) / 2;
MoveWindow(hwndDlg, rcChild.left, rcChild.top, rcChild.right, rcChild.bottom, FALSE);
return TRUE;
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDYES:
case IDNO:
case IDCANCEL:
int result = LOWORD(wParam);
if (IsDlgButtonChecked(hwndDlg, IDC_REMEMBER))
result |= 0x10000;
EndDialog(hwndDlg, result);
return TRUE;
}
break;
}
return FALSE;
}
INT_PTR CALLBACK DlgProcMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
PARAFORMAT2 pf2;
CHARFORMAT2 cf2;
LPNMHDR pNmhdr;
HCURSOR hCur;
SrmmWindowData *dat = (SrmmWindowData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
if (!dat && msg != WM_INITDIALOG)
return FALSE;
switch (msg) {
case WM_INITDIALOG:
TranslateDialogDefault(hwndDlg);
{
int len = 0;
RECT minEditInit;
NewMessageWindowLParam *newData = (NewMessageWindowLParam*)lParam;
dat = (SrmmWindowData*)mir_calloc(sizeof(SrmmWindowData));
SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)dat);
dat->hContact = newData->hContact;
WindowList_Add(pci->hWindowList, hwndDlg, dat->hContact);
NotifyLocalWinEvent(dat->hContact, hwndDlg, MSG_WINDOW_EVT_OPENING);
dat->hwnd = hwndDlg;
dat->hwndParent = GetParent(hwndDlg);
dat->parent = (ParentWindowData *)GetWindowLongPtr(dat->hwndParent, GWLP_USERDATA);
dat->hwndLog = NULL;
dat->szProto = GetContactProto(dat->hContact);
dat->avatarPic = 0;
if (dat->hContact && dat->szProto != NULL)
dat->wStatus = db_get_w(dat->hContact, dat->szProto, "Status", ID_STATUS_OFFLINE);
else
dat->wStatus = ID_STATUS_OFFLINE;
dat->hDbEventFirst = NULL;
dat->hDbEventLast = NULL;
dat->hDbUnreadEventFirst = NULL;
dat->messagesInProgress = 0;
dat->nTypeSecs = 0;
dat->nLastTyping = 0;
dat->showTyping = 0;
dat->showUnread = 0;
dat->sendAllConfirm = 0;
dat->nTypeMode = PROTOTYPE_SELFTYPING_OFF;
SetTimer(hwndDlg, TIMERID_TYPE, 1000, NULL);
dat->lastMessage = 0;
dat->lastEventType = -1;
dat->lastEventTime = time(NULL);
dat->startTime = time(NULL);
dat->flags = 0;
if (db_get_b(dat->hContact, SRMMMOD, "UseRTL", (BYTE)0))
dat->flags |= SMF_RTL;
dat->flags |= g_dat.ieviewInstalled ? g_dat.flags & SMF_USEIEVIEW : 0;
{
memset(&pf2, 0, sizeof(pf2));
pf2.cbSize = sizeof(pf2);
pf2.dwMask = PFM_RTLPARA;
if (!(dat->flags & SMF_RTL)) {
pf2.wEffects = 0;
SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_MESSAGE), GWL_EXSTYLE, GetWindowLongPtr(GetDlgItem(hwndDlg, IDC_MESSAGE), GWL_EXSTYLE) & ~(WS_EX_RIGHT | WS_EX_RTLREADING | WS_EX_LEFTSCROLLBAR));
}
else {
pf2.wEffects = PFE_RTLPARA;
SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_MESSAGE), GWL_EXSTYLE, GetWindowLongPtr(GetDlgItem(hwndDlg, IDC_MESSAGE), GWL_EXSTYLE) | WS_EX_RIGHT | WS_EX_RTLREADING | WS_EX_LEFTSCROLLBAR);
}
SendDlgItemMessage(hwndDlg, IDC_MESSAGE, EM_SETPARAFORMAT, 0, (LPARAM)&pf2);
/* Workaround to make Richedit display RTL messages correctly */
memset(&pf2, 0, sizeof(pf2));
pf2.cbSize = sizeof(pf2);
pf2.dwMask = PFM_RTLPARA | PFM_OFFSETINDENT | PFM_RIGHTINDENT;
pf2.wEffects = PFE_RTLPARA;
pf2.dxStartIndent = 30;
pf2.dxRightIndent = 30;
SendDlgItemMessage(hwndDlg, IDC_LOG, EM_SETPARAFORMAT, 0, (LPARAM)&pf2);
pf2.dwMask = PFM_RTLPARA;
pf2.wEffects = 0;
SendDlgItemMessage(hwndDlg, IDC_LOG, EM_SETPARAFORMAT, 0, (LPARAM)&pf2);
if (dat->flags & SMF_RTL)
SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_LOG), GWL_EXSTYLE, GetWindowLongPtr(GetDlgItem(hwndDlg, IDC_LOG), GWL_EXSTYLE) | WS_EX_LEFTSCROLLBAR);
else
SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_LOG), GWL_EXSTYLE, GetWindowLongPtr(GetDlgItem(hwndDlg, IDC_LOG), GWL_EXSTYLE) & ~WS_EX_LEFTSCROLLBAR);
}
dat->ace = NULL;
GetWindowRect(GetDlgItem(hwndDlg, IDC_MESSAGE), &minEditInit);
dat->minEditBoxHeight = minEditInit.bottom - minEditInit.top;
dat->minLogBoxHeight = dat->minEditBoxHeight;
dat->toolbarSize.cy = TOOLBAR_HEIGHT;
dat->toolbarSize.cx = 0;
if (dat->splitterPos == -1)
dat->splitterPos = dat->minEditBoxHeight;
if (newData->szInitialText) {
if (newData->isWchar)
SetDlgItemText(hwndDlg, IDC_MESSAGE, (wchar_t*)newData->szInitialText);
else
SetDlgItemTextA(hwndDlg, IDC_MESSAGE, newData->szInitialText);
}
else if (g_dat.flags & SMF_SAVEDRAFTS) {
ptrW ptszSavedMsg(db_get_wsa(dat->hContact, "SRMM", "SavedMsg"));
if (ptszSavedMsg)
len = SetRichText(GetDlgItem(hwndDlg, IDC_MESSAGE), ptszSavedMsg);
PostMessage(GetDlgItem(hwndDlg, IDC_MESSAGE), EM_SETSEL, len, len);
}
CustomButtonData *cbd;
for (int i = 0; cbd = Srmm_GetNthButton(i); i++) {
if (!cbd->m_bIMButton)
continue;
int width = (cbd->m_dwArrowCID) ? 34 : 22;
HWND hwndButton = CreateWindowEx(0, L"MButtonClass", L"", WS_CHILD | WS_VISIBLE | WS_TABSTOP, 0, 0, width, 22, hwndDlg, (HMENU)cbd->m_dwButtonCID, g_hInst, NULL);
SendMessage(hwndButton, BUTTONSETASFLATBTN, TRUE, 0);
if (cbd->m_pwszTooltip)
SendMessage(hwndButton, BUTTONADDTOOLTIP, LPARAM(cbd->m_pwszTooltip), BATF_UNICODE);
if (cbd->m_hIcon)
SendMessage(hwndButton, BM_SETIMAGE, IMAGE_ICON, (LPARAM)IcoLib_GetIconByHandle(cbd->m_hIcon));
}
SendDlgItemMessage(hwndDlg, IDC_LOG, EM_SETOLECALLBACK, 0, (LPARAM)&reOleCallback);
SendDlgItemMessage(hwndDlg, IDC_LOG, EM_SETEVENTMASK, 0, ENM_MOUSEEVENTS | ENM_LINK | ENM_KEYEVENTS);
SendDlgItemMessage(hwndDlg, IDC_LOG, EM_SETEDITSTYLE, SES_EXTENDBACKCOLOR, SES_EXTENDBACKCOLOR);
SendDlgItemMessage(hwndDlg, IDC_LOG, EM_SETLANGOPTIONS, 0, (LPARAM)SendDlgItemMessage(hwndDlg, IDC_LOG, EM_GETLANGOPTIONS, 0, 0) & ~(IMF_AUTOKEYBOARD | IMF_AUTOFONTSIZEADJUST));
SendDlgItemMessage(hwndDlg, IDC_LOG, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(0, 0));
/* duh, how come we didnt use this from the start? */
SendDlgItemMessage(hwndDlg, IDC_LOG, EM_AUTOURLDETECT, TRUE, 0);
SendDlgItemMessage(hwndDlg, IDC_MESSAGE, EM_SETLANGOPTIONS, 0, (LPARAM)SendDlgItemMessage(hwndDlg, IDC_MESSAGE, EM_GETLANGOPTIONS, 0, 0) & ~IMF_AUTOKEYBOARD);
SendDlgItemMessage(hwndDlg, IDC_MESSAGE, EM_SETOLECALLBACK, 0, (LPARAM)&reOleCallback2);
SendDlgItemMessage(hwndDlg, IDC_MESSAGE, EM_SETEVENTMASK, 0, ENM_MOUSEEVENTS | ENM_KEYEVENTS | ENM_CHANGE | ENM_REQUESTRESIZE);
if (dat->hContact && dat->szProto) {
int nMax = CallProtoService(dat->szProto, PS_GETCAPS, PFLAG_MAXLENOFMESSAGE, dat->hContact);
if (nMax)
SendDlgItemMessage(hwndDlg, IDC_MESSAGE, EM_LIMITTEXT, nMax, 0);
}
/* get around a lame bug in the Windows template resource code where richedits are limited to 0x7FFF */
SendDlgItemMessage(hwndDlg, IDC_LOG, EM_LIMITTEXT, sizeof(wchar_t) * 0x7FFFFFFF, 0);
SubclassLogEdit(GetDlgItem(hwndDlg, IDC_LOG));
SubclassMessageEdit(GetDlgItem(hwndDlg, IDC_MESSAGE));
dat->infobarData = CreateInfobar(hwndDlg, dat);
if (dat->flags & SMF_USEIEVIEW) {
IEVIEWWINDOW ieWindow = { sizeof(IEVIEWWINDOW) };
ieWindow.iType = IEW_CREATE;
ieWindow.dwMode = IEWM_SCRIVER;
ieWindow.parent = hwndDlg;
ieWindow.cx = 200;
ieWindow.cy = 300;
CallService(MS_IEVIEW_WINDOW, 0, (LPARAM)&ieWindow);
dat->hwndLog = ieWindow.hwnd;
if (dat->hwndLog == NULL)
dat->flags ^= SMF_USEIEVIEW;
}
bool notifyUnread = false;
if (dat->hContact) {
int historyMode = db_get_b(NULL, SRMMMOD, SRMSGSET_LOADHISTORY, SRMSGDEFSET_LOADHISTORY);
// This finds the first message to display, it works like shit
dat->hDbEventFirst = db_event_firstUnread(dat->hContact);
if (dat->hDbEventFirst != NULL) {
DBEVENTINFO dbei = { sizeof(dbei) };
db_event_get(dat->hDbEventFirst, &dbei);
if (DbEventIsMessageOrCustom(&dbei) && !(dbei.flags & DBEF_READ) && !(dbei.flags & DBEF_SENT))
notifyUnread = true;
}
DBEVENTINFO dbei = { sizeof(dbei) };
MEVENT hPrevEvent;
switch (historyMode) {
case LOADHISTORY_COUNT:
for (int i = db_get_w(NULL, SRMMMOD, SRMSGSET_LOADCOUNT, SRMSGDEFSET_LOADCOUNT); i > 0; i--) {
if (dat->hDbEventFirst == NULL)
hPrevEvent = db_event_last(dat->hContact);
else
hPrevEvent = db_event_prev(dat->hContact, dat->hDbEventFirst);
if (hPrevEvent == NULL)
break;
dbei.cbBlob = 0;
dat->hDbEventFirst = hPrevEvent;
db_event_get(dat->hDbEventFirst, &dbei);
if (!DbEventIsShown(dbei))
i++;
}
break;
case LOADHISTORY_TIME:
if (dat->hDbEventFirst == NULL) {
dbei.timestamp = time(NULL);
hPrevEvent = db_event_last(dat->hContact);
}
else {
db_event_get(dat->hDbEventFirst, &dbei);
hPrevEvent = db_event_prev(dat->hContact, dat->hDbEventFirst);
}
DWORD firstTime = dbei.timestamp - 60 * db_get_w(NULL, SRMMMOD, SRMSGSET_LOADTIME, SRMSGDEFSET_LOADTIME);
for (;;) {
if (hPrevEvent == NULL)
break;
dbei.cbBlob = 0;
db_event_get(hPrevEvent, &dbei);
if (dbei.timestamp < firstTime)
break;
if (DbEventIsShown(dbei))
dat->hDbEventFirst = hPrevEvent;
hPrevEvent = db_event_prev(dat->hContact, hPrevEvent);
}
break;
}
}
SendMessage(dat->hwndParent, CM_ADDCHILD, (WPARAM)hwndDlg, dat->hContact);
{
MEVENT hdbEvent = db_event_last(dat->hContact);
if (hdbEvent) {
DBEVENTINFO dbei = { sizeof(dbei) };
do {
db_event_get(hdbEvent, &dbei);
if (dbei.eventType == EVENTTYPE_MESSAGE && !(dbei.flags & DBEF_SENT)) {
dat->lastMessage = dbei.timestamp;
break;
}
} while ((hdbEvent = db_event_prev(dat->hContact, hdbEvent)));
}
}
SendMessage(hwndDlg, DM_OPTIONSAPPLIED, 0, 0);
SendMessage(GetParent(hwndDlg), CM_POPUPWINDOW, newData->flags & NMWLP_INCOMING, (LPARAM)hwndDlg);
if (notifyUnread) {
if (GetForegroundWindow() != dat->hwndParent || dat->parent->hwndActive != hwndDlg) {
dat->showUnread = 1;
SendMessage(hwndDlg, DM_UPDATEICON, 0, 0);
SetTimer(hwndDlg, TIMERID_UNREAD, TIMEOUT_UNREAD, NULL);
}
SendMessage(dat->hwndParent, CM_STARTFLASHING, 0, 0);
}
dat->messagesInProgress = ReattachSendQueueItems(hwndDlg, dat->hContact);
if (dat->messagesInProgress > 0)
SendMessage(hwndDlg, DM_SHOWMESSAGESENDING, 0, 0);
NotifyLocalWinEvent(dat->hContact, hwndDlg, MSG_WINDOW_EVT_OPEN);
}
return TRUE;
case DM_GETCONTEXTMENU:
{
HMENU hMenu = Menu_BuildContactMenu(dat->hContact);
SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, (LONG_PTR)hMenu);
}
return TRUE;
case WM_CONTEXTMENU:
if (dat->hwndParent == (HWND)wParam) {
POINT pt;
HMENU hMenu = Menu_BuildContactMenu(dat->hContact);
GetCursorPos(&pt);
TrackPopupMenu(hMenu, 0, pt.x, pt.y, 0, hwndDlg, NULL);
DestroyMenu(hMenu);
}
break;
case WM_LBUTTONDBLCLK:
SendMessage(dat->hwndParent, WM_SYSCOMMAND, SC_MINIMIZE, 0);
break;
case WM_DROPFILES:
if (dat->szProto == NULL) break;
if (!(CallProtoService(dat->szProto, PS_GETCAPS, PFLAGNUM_1, 0)&PF1_FILESEND)) break;
if (dat->wStatus == ID_STATUS_OFFLINE) break;
if (dat->hContact != NULL) {
wchar_t szFilename[MAX_PATH];
HDROP hDrop = (HDROP)wParam;
int fileCount = DragQueryFile(hDrop, -1, NULL, 0), totalCount = 0, i;
wchar_t** ppFiles = NULL;
for (i = 0; i < fileCount; i++) {
DragQueryFile(hDrop, i, szFilename, _countof(szFilename));
AddToFileList(&ppFiles, &totalCount, szFilename);
}
CallServiceSync(MS_FILE_SENDSPECIFICFILEST, dat->hContact, (LPARAM)ppFiles);
for (i = 0; ppFiles[i]; i++) mir_free(ppFiles[i]);
mir_free(ppFiles);
}
break;
case DM_AVATARCHANGED:
ShowAvatar(hwndDlg, dat);
break;
case DM_GETAVATAR:
{
PROTO_AVATAR_INFORMATION ai = { 0 };
ai.hContact = dat->hContact;
CallProtoService(dat->szProto, PS_GETAVATARINFO, GAIF_FORCE, (LPARAM)&ai);
ShowAvatar(hwndDlg, dat);
}
break;
case DM_TYPING:
dat->nTypeSecs = (int)lParam > 0 ? (int)lParam : 0;
break;
case DM_CHANGEICONS:
SendMessage(hwndDlg, DM_UPDATESTATUSBAR, 0, 0);
SetStatusIcon(dat);
case DM_UPDATEICON:
{
TitleBarData tbd = { 0 };
tbd.iFlags = TBDF_ICON;
GetTitlebarIcon(dat, &tbd);
SendMessage(dat->hwndParent, CM_UPDATETITLEBAR, (WPARAM)&tbd, (LPARAM)hwndDlg);
TabControlData tcd;
tcd.iFlags = TCDF_ICON;
tcd.hIcon = GetTabIcon(dat);
SendMessage(dat->hwndParent, CM_UPDATETABCONTROL, (WPARAM)&tcd, (LPARAM)hwndDlg);
SendDlgItemMessage(hwndDlg, IDC_USERMENU, BM_SETIMAGE, IMAGE_ICON, (LPARAM)dat->statusIcon);
}
break;
case DM_UPDATETABCONTROL: {
TabControlData tcd;
tcd.iFlags = TCDF_TEXT | TCDF_ICON;
tcd.hIcon = GetTabIcon(dat);
tcd.pszText = pcli->pfnGetContactDisplayName(dat->hContact, 0);
SendMessage(dat->hwndParent, CM_UPDATETABCONTROL, (WPARAM)&tcd, (LPARAM)hwndDlg);
break;
}
case DM_UPDATETITLEBAR:
{
TitleBarData tbd = { 0 };
tbd.iFlags = TBDF_TEXT | TBDF_ICON;
GetTitlebarIcon(dat, &tbd);
tbd.pszText = GetWindowTitle(dat->hContact, dat->szProto);
SendMessage(dat->hwndParent, CM_UPDATETITLEBAR, (WPARAM)&tbd, (LPARAM)hwndDlg);
mir_free(tbd.pszText);
}
break;
case DM_CLISTSETTINGSCHANGED:
if (wParam == dat->hContact) {
if (dat->hContact && dat->szProto) {
DBCONTACTWRITESETTING *cws = (DBCONTACTWRITESETTING *)lParam;
char idbuf[128], buf[128];
GetContactUniqueId(dat, idbuf, sizeof(idbuf));
mir_snprintf(buf, Translate("User menu - %s"), idbuf);
SendDlgItemMessage(hwndDlg, IDC_USERMENU, BUTTONADDTOOLTIP, (WPARAM)buf, 0);
if (cws && !mir_strcmp(cws->szModule, dat->szProto) && !mir_strcmp(cws->szSetting, "Status"))
dat->wStatus = cws->value.wVal;
SetStatusIcon(dat);
SendMessage(hwndDlg, DM_UPDATEICON, 0, 0);
SendMessage(hwndDlg, DM_UPDATETITLEBAR, 0, 0);
SendMessage(hwndDlg, DM_UPDATETABCONTROL, 0, 0);
ShowAvatar(hwndDlg, dat);
}
}
break;
case DM_OPTIONSAPPLIED:
memset(&pf2, 0, sizeof(pf2));
memset(&cf2, 0, sizeof(cf2));
LOGFONT lf;
COLORREF colour;
dat->flags &= ~SMF_USEIEVIEW;
dat->flags |= g_dat.ieviewInstalled ? g_dat.flags & SMF_USEIEVIEW : 0;
if (dat->flags & SMF_USEIEVIEW && dat->hwndLog == NULL) {
IEVIEWWINDOW ieWindow = { sizeof(ieWindow) };
ieWindow.iType = IEW_CREATE;
ieWindow.dwMode = IEWM_SCRIVER;
ieWindow.parent = hwndDlg;
ieWindow.cx = 200;
ieWindow.cy = 300;
CallService(MS_IEVIEW_WINDOW, 0, (LPARAM)&ieWindow);
dat->hwndLog = ieWindow.hwnd;
if (dat->hwndLog == NULL)
dat->flags ^= SMF_USEIEVIEW;
}
else if (!(dat->flags & SMF_USEIEVIEW) && dat->hwndLog != NULL) {
if (dat->hwndLog != NULL) {
IEVIEWWINDOW ieWindow = { sizeof(ieWindow) };
ieWindow.iType = IEW_DESTROY;
ieWindow.hwnd = dat->hwndLog;
CallService(MS_IEVIEW_WINDOW, 0, (LPARAM)&ieWindow);
}
dat->hwndLog = NULL;
}
SendMessage(hwndDlg, DM_GETAVATAR, 0, 0);
SetDialogToType(hwndDlg);
colour = db_get_dw(NULL, SRMMMOD, SRMSGSET_BKGCOLOUR, SRMSGDEFSET_BKGCOLOUR);
SendDlgItemMessage(hwndDlg, IDC_LOG, EM_SETBKGNDCOLOR, 0, colour);
colour = db_get_dw(NULL, SRMMMOD, SRMSGSET_INPUTBKGCOLOUR, SRMSGDEFSET_INPUTBKGCOLOUR);
SendDlgItemMessage(hwndDlg, IDC_MESSAGE, EM_SETBKGNDCOLOR, 0, colour);
InvalidateRect(GetDlgItem(hwndDlg, IDC_MESSAGE), NULL, FALSE);
LoadMsgDlgFont(MSGFONTID_MESSAGEAREA, &lf, &colour);
cf2.cbSize = sizeof(cf2);
cf2.dwMask = CFM_COLOR | CFM_FACE | CFM_CHARSET | CFM_SIZE | CFM_WEIGHT | CFM_BOLD | CFM_ITALIC;
cf2.crTextColor = colour;
cf2.bCharSet = lf.lfCharSet;
wcsncpy(cf2.szFaceName, lf.lfFaceName, LF_FACESIZE);
cf2.dwEffects = ((lf.lfWeight >= FW_BOLD) ? CFE_BOLD : 0) | (lf.lfItalic ? CFE_ITALIC : 0);
cf2.wWeight = (WORD)lf.lfWeight;
cf2.bPitchAndFamily = lf.lfPitchAndFamily;
cf2.yHeight = abs(lf.lfHeight) * 1440 / g_dat.logPixelSY;
SendDlgItemMessage(hwndDlg, IDC_MESSAGE, EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cf2);
SendDlgItemMessage(hwndDlg, IDC_MESSAGE, EM_SETLANGOPTIONS, 0, (LPARAM)SendDlgItemMessage(hwndDlg, IDC_MESSAGE, EM_GETLANGOPTIONS, 0, 0) & ~IMF_AUTOKEYBOARD);
pf2.cbSize = sizeof(pf2);
pf2.dwMask = PFM_OFFSET;
pf2.dxOffset = (g_dat.flags & SMF_INDENTTEXT) ? g_dat.indentSize * 1440 / g_dat.logPixelSX : 0;
SetDlgItemText(hwndDlg, IDC_LOG, L"");
SendDlgItemMessage(hwndDlg, IDC_LOG, EM_SETPARAFORMAT, 0, (LPARAM)&pf2);
SendDlgItemMessage(hwndDlg, IDC_LOG, EM_SETLANGOPTIONS, 0, (LPARAM)SendDlgItemMessage(hwndDlg, IDC_LOG, EM_GETLANGOPTIONS, 0, 0) & ~(IMF_AUTOKEYBOARD | IMF_AUTOFONTSIZEADJUST));
SendMessage(hwndDlg, DM_REMAKELOG, 0, 0);
SendMessage(hwndDlg, DM_UPDATETITLEBAR, 0, 0);
SendMessage(hwndDlg, DM_UPDATETABCONTROL, 0, 0);
SendMessage(hwndDlg, DM_UPDATESTATUSBAR, 0, 0);
SendDlgItemMessage(hwndDlg, IDC_MESSAGE, EM_REQUESTRESIZE, 0, 0);
SetupInfobar(dat->infobarData);
break;
case DM_USERNAMETOCLIP:
if (dat->hContact) {
char buf[128];
GetContactUniqueId(dat, buf, sizeof(buf));
if (!OpenClipboard(hwndDlg) || !mir_strlen(buf))
break;
EmptyClipboard();
HGLOBAL hData = GlobalAlloc(GMEM_MOVEABLE, mir_strlen(buf) + 1);
mir_strcpy((LPSTR)GlobalLock(hData), buf);
GlobalUnlock(hData);
SetClipboardData(CF_TEXT, hData);
CloseClipboard();
}
break;
case DM_SWITCHINFOBAR:
case DM_SWITCHTOOLBAR:
SetDialogToType(hwndDlg);
break;
case DM_SWITCHTYPING:
if (IsTypingNotificationSupported(dat)) {
StatusIconData sid = { sizeof(sid) };
sid.szModule = SRMMMOD;
sid.dwId = 1;
BYTE typingNotify = (db_get_b(dat->hContact, SRMMMOD, SRMSGSET_TYPING,
db_get_b(NULL, SRMMMOD, SRMSGSET_TYPINGNEW, SRMSGDEFSET_TYPINGNEW)));
db_set_b(dat->hContact, SRMMMOD, SRMSGSET_TYPING, (BYTE)!typingNotify);
sid.flags = typingNotify ? MBF_DISABLED : 0;
Srmm_ModifyIcon(dat->hContact, &sid);
}
break;
case DM_SWITCHRTL:
memset(&pf2, 0, sizeof(pf2));
pf2.cbSize = sizeof(pf2);
pf2.dwMask = PFM_RTLPARA;
dat->flags ^= SMF_RTL;
if (dat->flags & SMF_RTL) {
pf2.wEffects = PFE_RTLPARA;
SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_MESSAGE), GWL_EXSTYLE, GetWindowLongPtr(GetDlgItem(hwndDlg, IDC_MESSAGE), GWL_EXSTYLE) | WS_EX_RIGHT | WS_EX_RTLREADING | WS_EX_LEFTSCROLLBAR);
SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_LOG), GWL_EXSTYLE, GetWindowLongPtr(GetDlgItem(hwndDlg, IDC_LOG), GWL_EXSTYLE) | WS_EX_LEFTSCROLLBAR);
}
else {
pf2.wEffects = 0;
SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_MESSAGE), GWL_EXSTYLE, GetWindowLongPtr(GetDlgItem(hwndDlg, IDC_MESSAGE), GWL_EXSTYLE) &~(WS_EX_RIGHT | WS_EX_RTLREADING | WS_EX_LEFTSCROLLBAR));
SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_LOG), GWL_EXSTYLE, GetWindowLongPtr(GetDlgItem(hwndDlg, IDC_LOG), GWL_EXSTYLE) &~(WS_EX_LEFTSCROLLBAR));
}
SendDlgItemMessage(hwndDlg, IDC_MESSAGE, EM_SETPARAFORMAT, 0, (LPARAM)&pf2);
SendMessage(hwndDlg, DM_REMAKELOG, 0, 0);
break;
case DM_GETWINDOWSTATE:
{
UINT state = MSG_WINDOW_STATE_EXISTS;
if (IsWindowVisible(hwndDlg))
state |= MSG_WINDOW_STATE_VISIBLE;
if (GetForegroundWindow() == dat->hwndParent)
state |= MSG_WINDOW_STATE_FOCUS;
if (IsIconic(dat->hwndParent))
state |= MSG_WINDOW_STATE_ICONIC;
SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, state);
}
return TRUE;
case DM_ACTIVATE:
case WM_ACTIVATE:
if (LOWORD(wParam) != WA_ACTIVE)
break;
//fall through
case WM_MOUSEACTIVATE:
if (dat->hDbUnreadEventFirst != NULL) {
MEVENT hDbEvent = dat->hDbUnreadEventFirst;
dat->hDbUnreadEventFirst = NULL;
while (hDbEvent != NULL) {
DBEVENTINFO dbei = { sizeof(dbei) };
db_event_get(hDbEvent, &dbei);
if (!(dbei.flags & DBEF_SENT) && (DbEventIsMessageOrCustom(&dbei) || dbei.eventType == EVENTTYPE_URL))
pcli->pfnRemoveEvent(dat->hContact, hDbEvent);
hDbEvent = db_event_next(dat->hContact, hDbEvent);
}
}
if (dat->showUnread) {
dat->showUnread = 0;
KillTimer(hwndDlg, TIMERID_UNREAD);
SendMessage(hwndDlg, DM_UPDATEICON, 0, 0);
}
break;
case WM_LBUTTONDOWN:
SendMessage(dat->hwndParent, WM_LBUTTONDOWN, wParam, lParam);
return TRUE;
case DM_SETFOCUS:
if (lParam == WM_MOUSEACTIVATE) {
HWND hLog;
POINT pt;
GetCursorPos(&pt);
if (dat->hwndLog != NULL)
hLog = dat->hwndLog;
else
hLog = GetDlgItem(hwndDlg, IDC_LOG);
RECT rc;
GetWindowRect(hLog, &rc);
if (pt.x >= rc.left && pt.x <= rc.right && pt.y >= rc.top && pt.y <= rc.bottom)
return TRUE;
}
if (g_dat.hFocusWnd == hwndDlg)
SetFocus(GetDlgItem(hwndDlg, IDC_MESSAGE));
return TRUE;
case WM_SETFOCUS:
SendMessage(dat->hwndParent, CM_ACTIVATECHILD, 0, (LPARAM)hwndDlg);
g_dat.hFocusWnd = hwndDlg;
PostMessage(hwndDlg, DM_SETFOCUS, 0, 0);
return TRUE;
case DM_SETPARENT:
dat->hwndParent = (HWND)lParam;
dat->parent = (ParentWindowData *)GetWindowLongPtr(dat->hwndParent, GWLP_USERDATA);
SetParent(hwndDlg, dat->hwndParent);
return TRUE;
case WM_GETMINMAXINFO:
{
MINMAXINFO *mmi = (MINMAXINFO *)lParam;
mmi->ptMinTrackSize.x = dat->toolbarSize.cx + BOTTOM_RIGHT_AVATAR_HEIGHT;
mmi->ptMinTrackSize.y = dat->minLogBoxHeight + dat->toolbarSize.cy + dat->minEditBoxHeight + max(INFO_BAR_HEIGHT, BOTTOM_RIGHT_AVATAR_HEIGHT - dat->toolbarSize.cy) + 5;
}
return 0;
case WM_SIZE:
if (wParam == SIZE_RESTORED || wParam == SIZE_MAXIMIZED) {
RECT rc;
GetClientRect(hwndDlg, &rc);
MessageDialogResize(hwndDlg, dat, rc.right - rc.left, rc.bottom - rc.top);
}
return TRUE;
case DM_SPLITTERMOVED:
if ((HWND)lParam == GetDlgItem(hwndDlg, IDC_SPLITTERY)) {
RECT rc, rcLog;
GetWindowRect(GetDlgItem(hwndDlg, IDC_LOG), &rcLog);
GetClientRect(hwndDlg, &rc);
POINT pt = { 0, (int)wParam };
ScreenToClient(hwndDlg, &pt);
dat->splitterPos = rc.bottom - pt.y;
SendMessage(hwndDlg, WM_SIZE, 0, 0);
}
break;
case DM_REMAKELOG:
dat->lastEventType = -1;
if (wParam == 0 || wParam == dat->hContact)
StreamInEvents(hwndDlg, dat->hDbEventFirst, -1, 0);
InvalidateRect(GetDlgItem(hwndDlg, IDC_LOG), NULL, FALSE);
break;
case DM_APPENDTOLOG: //takes wParam=hDbEvent
StreamInEvents(hwndDlg, wParam, 1, 1);
break;
case DM_SCROLLLOGTOBOTTOM:
if (dat->hwndLog == NULL) {
if ((GetWindowLongPtr(GetDlgItem(hwndDlg, IDC_LOG), GWL_STYLE) & WS_VSCROLL) == 0)
break;
SCROLLINFO si = { sizeof(si) };
si.fMask = SIF_PAGE | SIF_RANGE | SIF_POS;
if (GetScrollInfo(GetDlgItem(hwndDlg, IDC_LOG), SB_VERT, &si)) {
if (GetDlgItem(hwndDlg, IDC_LOG) != GetFocus()) {
si.fMask = SIF_POS;
si.nPos = si.nMax - si.nPage + 1;
SetScrollInfo(GetDlgItem(hwndDlg, IDC_LOG), SB_VERT, &si, TRUE);
PostMessage(GetDlgItem(hwndDlg, IDC_LOG), WM_VSCROLL, MAKEWPARAM(SB_BOTTOM, 0), 0);
}
}
RedrawWindow(GetDlgItem(hwndDlg, IDC_LOG), NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
}
else {
IEVIEWWINDOW ieWindow;
ieWindow.cbSize = sizeof(IEVIEWWINDOW);
ieWindow.iType = IEW_SCROLLBOTTOM;
ieWindow.hwnd = dat->hwndLog;
CallService(MS_IEVIEW_WINDOW, 0, (LPARAM)&ieWindow);
}
break;
case HM_DBEVENTADDED:
if (wParam == dat->hContact) {
MEVENT hDbEvent = lParam;
DBEVENTINFO dbei = { sizeof(dbei) };
db_event_get(hDbEvent, &dbei);
if (dat->hDbEventFirst == NULL)
dat->hDbEventFirst = hDbEvent;
if (DbEventIsShown(dbei)) {
if (dbei.eventType == EVENTTYPE_MESSAGE && !(dbei.flags & (DBEF_SENT))) {
/* store the event when the container is hidden so that clist notifications can be removed */
if (!IsWindowVisible(GetParent(hwndDlg)) && dat->hDbUnreadEventFirst == NULL)
dat->hDbUnreadEventFirst = hDbEvent;
dat->lastMessage = dbei.timestamp;
SendMessage(hwndDlg, DM_UPDATESTATUSBAR, 0, 0);
if (GetForegroundWindow() == dat->hwndParent && dat->parent->hwndActive == hwndDlg)
SkinPlaySound("RecvMsgActive");
else SkinPlaySound("RecvMsgInactive");
if ((g_dat.flags2 & SMF2_SWITCHTOACTIVE) && (IsIconic(dat->hwndParent) || GetActiveWindow() != dat->hwndParent) && IsWindowVisible(dat->hwndParent))
SendMessage(dat->hwndParent, CM_ACTIVATECHILD, 0, (LPARAM)hwndDlg);
if (IsAutoPopup(dat->hContact))
SendMessage(GetParent(hwndDlg), CM_POPUPWINDOW, 1, (LPARAM)hwndDlg);
}
if (hDbEvent != dat->hDbEventFirst && db_event_next(dat->hContact, hDbEvent) == NULL)
SendMessage(hwndDlg, DM_APPENDTOLOG, WPARAM(hDbEvent), 0);
else
SendMessage(hwndDlg, DM_REMAKELOG, 0, 0);
if (!(dbei.flags & DBEF_SENT) && !DbEventIsCustomForMsgWindow(&dbei)) {
if (GetActiveWindow() != dat->hwndParent || GetForegroundWindow() != dat->hwndParent || dat->parent->hwndActive != hwndDlg) {
dat->showUnread = 1;
SendMessage(hwndDlg, DM_UPDATEICON, 0, 0);
SetTimer(hwndDlg, TIMERID_UNREAD, TIMEOUT_UNREAD, NULL);
}
SendMessage(dat->hwndParent, CM_STARTFLASHING, 0, 0);
}
}
}
break;
case DM_UPDATESTATUSBAR:
if (dat->parent->hwndActive == hwndDlg) {
wchar_t szText[256];
StatusBarData sbd = { 0 };
sbd.iFlags = SBDF_TEXT | SBDF_ICON;
if (dat->messagesInProgress && (g_dat.flags & SMF_SHOWPROGRESS)) {
sbd.hIcon = GetCachedIcon("scriver_DELIVERING");
sbd.pszText = szText;
mir_snwprintf(szText, TranslateT("Sending in progress: %d message(s) left..."), dat->messagesInProgress);
}
else if (dat->nTypeSecs) {
sbd.hIcon = GetCachedIcon("scriver_TYPING");
sbd.pszText = szText;
mir_snwprintf(szText, TranslateT("%s is typing a message..."), pcli->pfnGetContactDisplayName(dat->hContact, 0));
dat->nTypeSecs--;
}
else if (dat->lastMessage) {
wchar_t date[64], time[64];
TimeZone_PrintTimeStamp(NULL, dat->lastMessage, L"d", date, _countof(date), 0);
TimeZone_PrintTimeStamp(NULL, dat->lastMessage, L"t", time, _countof(time), 0);
mir_snwprintf(szText, TranslateT("Last message received on %s at %s."), date, time);
sbd.pszText = szText;
}
else sbd.pszText = L"";
SendMessage(dat->hwndParent, CM_UPDATESTATUSBAR, (WPARAM)&sbd, (LPARAM)hwndDlg);
UpdateReadChars(hwndDlg, dat);
StatusIconData sid = { sizeof(sid) };
sid.szModule = SRMMMOD;
sid.flags = MBF_DISABLED;
Srmm_ModifyIcon(dat->hContact, &sid);
sid.dwId = 1;
if (IsTypingNotificationSupported(dat) && g_dat.flags2 & SMF2_SHOWTYPINGSWITCH)
sid.flags = (db_get_b(dat->hContact, SRMMMOD, SRMSGSET_TYPING,
db_get_b(NULL, SRMMMOD, SRMSGSET_TYPINGNEW, SRMSGDEFSET_TYPINGNEW))) ? 0 : MBF_DISABLED;
else
sid.flags = MBF_HIDDEN;
Srmm_ModifyIcon(dat->hContact, &sid);
}
break;
case DM_CLEARLOG:
if (dat->hwndLog != NULL) {
IEVIEWEVENT evt = { sizeof(evt) };
evt.iType = IEE_CLEAR_LOG;
evt.dwFlags = ((dat->flags & SMF_RTL) ? IEEF_RTL : 0);
evt.hwnd = dat->hwndLog;
evt.hContact = dat->hContact;
evt.pszProto = dat->szProto;
CallService(MS_IEVIEW_EVENT, 0, (LPARAM)&evt);
}
SetDlgItemText(hwndDlg, IDC_LOG, L"");
dat->hDbEventFirst = NULL;
dat->lastEventType = -1;
break;
case WM_TIMER:
if (wParam == TIMERID_MSGSEND)
ReportSendQueueTimeouts(hwndDlg);
else if (wParam == TIMERID_TYPE) {
if (dat->nTypeMode == PROTOTYPE_SELFTYPING_ON && GetTickCount() - dat->nLastTyping > TIMEOUT_TYPEOFF)
NotifyTyping(dat, PROTOTYPE_SELFTYPING_OFF);
if (dat->showTyping) {
if (dat->nTypeSecs)
dat->nTypeSecs--;
else {
dat->showTyping = 0;
SendMessage(hwndDlg, DM_UPDATESTATUSBAR, 0, 0);
SendMessage(hwndDlg, DM_UPDATEICON, 0, 0);
}
}
else {
if (dat->nTypeSecs) {
dat->showTyping = 1;
SendMessage(hwndDlg, DM_UPDATESTATUSBAR, 0, 0);
SendMessage(hwndDlg, DM_UPDATEICON, 0, 0);
}
}
}
else if (wParam == TIMERID_UNREAD) {
TabControlData tcd;
tcd.iFlags = TCDF_ICON;
if (!dat->showTyping) {
dat->showUnread++;
tcd.hIcon = (dat->showUnread & 1) ? dat->statusIconOverlay : dat->statusIcon;
SendMessage(dat->hwndParent, CM_UPDATETABCONTROL, (WPARAM)&tcd, (LPARAM)hwndDlg);
}
}
break;
case DM_SENDMESSAGE:
if (lParam) {
MessageSendQueueItem *msi = (MessageSendQueueItem *)lParam;
SendMessage(hwndDlg, DM_STARTMESSAGESENDING, 0, 0);
MessageSendQueueItem *item = CreateSendQueueItem(hwndDlg);
item->hContact = dat->hContact;
item->proto = mir_strdup(dat->szProto);
item->flags = msi->flags;
item->sendBufferSize = msi->sendBufferSize;
item->sendBuffer = mir_strndup(msi->sendBuffer, msi->sendBufferSize);
SendSendQueueItem(item);
}
break;
case DM_STARTMESSAGESENDING:
dat->messagesInProgress++;
case DM_SHOWMESSAGESENDING:
SetTimer(hwndDlg, TIMERID_MSGSEND, 1000, NULL);
if (g_dat.flags & SMF_SHOWPROGRESS)
SendMessage(dat->hwnd, DM_UPDATESTATUSBAR, 0, 0);
break;
case DM_STOPMESSAGESENDING:
if (dat->messagesInProgress > 0) {
dat->messagesInProgress--;
if (g_dat.flags & SMF_SHOWPROGRESS)
SendMessage(dat->hwnd, DM_UPDATESTATUSBAR, 0, 0);
}
if (dat->messagesInProgress == 0)
KillTimer(hwndDlg, TIMERID_MSGSEND);
break;
case DM_SHOWERRORMESSAGE:
if (lParam) {
ErrorWindowData *ewd = (ErrorWindowData *)lParam;
SendMessage(hwndDlg, DM_STOPMESSAGESENDING, 0, 0);
ewd->queueItem->hwndErrorDlg = CreateDialogParam(g_hInst, MAKEINTRESOURCE(IDD_MSGSENDERROR), hwndDlg, ErrorDlgProc, (LPARAM)ewd);//hwndDlg
}
break;
case DM_ERRORDECIDED:
{
MessageSendQueueItem *item = (MessageSendQueueItem *)lParam;
item->hwndErrorDlg = NULL;
switch (wParam) {
case MSGERROR_CANCEL:
RemoveSendQueueItem(item);
SetFocus(GetDlgItem(hwndDlg, IDC_MESSAGE));
break;
case MSGERROR_RETRY:
SendMessage(hwndDlg, DM_STARTMESSAGESENDING, 0, 0);
SendSendQueueItem(item);
break;
}
}
break;
case WM_MEASUREITEM:
if (!MeasureMenuItem(wParam, lParam))
return Menu_MeasureItem(lParam);
return TRUE;
case WM_DRAWITEM:
if (!DrawMenuItem(wParam, lParam)) {
LPDRAWITEMSTRUCT dis = (LPDRAWITEMSTRUCT)lParam;
if (dis->hwndItem == GetDlgItem(hwndDlg, IDC_AVATAR)) {
int avatarWidth = 0, avatarHeight = 0;
int itemWidth = dis->rcItem.right - dis->rcItem.left + 1, itemHeight = dis->rcItem.bottom - dis->rcItem.top + 1;
HDC hdcMem = CreateCompatibleDC(dis->hDC);
HBITMAP hbmMem = CreateCompatibleBitmap(dis->hDC, itemWidth, itemHeight);
hbmMem = (HBITMAP)SelectObject(hdcMem, hbmMem);
RECT rect;
rect.top = 0;
rect.left = 0;
rect.right = itemWidth - 1;
rect.bottom = itemHeight - 1;
FillRect(hdcMem, &rect, GetSysColorBrush(COLOR_BTNFACE));
if (dat->avatarPic && (g_dat.flags&SMF_AVATAR)) {
BITMAP bminfo;
GetObject(dat->avatarPic, sizeof(bminfo), &bminfo);
if (bminfo.bmWidth != 0 && bminfo.bmHeight != 0) {
avatarHeight = itemHeight;
avatarWidth = bminfo.bmWidth * avatarHeight / bminfo.bmHeight;
if (avatarWidth > itemWidth) {
avatarWidth = itemWidth;
avatarHeight = bminfo.bmHeight * avatarWidth / bminfo.bmWidth;
}
AVATARDRAWREQUEST adr = { sizeof(adr) };
adr.hContact = dat->hContact;
adr.hTargetDC = hdcMem;
adr.rcDraw.left = (itemWidth - avatarWidth) / 2;
adr.rcDraw.top = (itemHeight - avatarHeight) / 2;
adr.rcDraw.right = avatarWidth - 1;
adr.rcDraw.bottom = avatarHeight - 1;
adr.dwFlags = AVDRQ_DRAWBORDER | AVDRQ_HIDEBORDERONTRANSPARENCY;
CallService(MS_AV_DRAWAVATAR, 0, (LPARAM)&adr);
}
}
BitBlt(dis->hDC, 0, 0, itemWidth, itemHeight, hdcMem, 0, 0, SRCCOPY);
hbmMem = (HBITMAP)SelectObject(hdcMem, hbmMem);
DeleteObject(hbmMem);
DeleteDC(hdcMem);
return TRUE;
}
}
return Menu_MeasureItem(lParam);
case WM_COMMAND:
if (!lParam && Clist_MenuProcessCommand(LOWORD(wParam), MPCF_CONTACTMENU, dat->hContact))
break;
if (HIWORD(wParam) == BN_CLICKED)
if (LOWORD(wParam) >= MIN_CBUTTONID && LOWORD(wParam) <= MAX_CBUTTONID) {
Srmm_ClickToolbarIcon(dat->hContact, LOWORD(wParam), GetDlgItem(hwndDlg, LOWORD(wParam)), 0);
break;
}
switch (LOWORD(wParam)) {
case IDC_SENDALL:
int result;
if (dat->sendAllConfirm == 0) {
result = DialogBoxParam(g_hInst, MAKEINTRESOURCE(IDD_CONFIRM_SENDALL), hwndDlg, ConfirmSendAllDlgProc, (LPARAM)hwndDlg);
if (result & 0x10000)
dat->sendAllConfirm = result;
}
else result = dat->sendAllConfirm;
if (LOWORD(result) != IDYES)
break;
case IDOK:
// this is a 'send' button
if (!IsWindowEnabled(GetDlgItem(hwndDlg, IDOK)))
break;
if (dat->hContact != NULL) {
memset(&pf2, 0, sizeof(pf2));
pf2.cbSize = sizeof(pf2);
pf2.dwMask = PFM_RTLPARA;
SendDlgItemMessage(hwndDlg, IDC_MESSAGE, EM_GETPARAFORMAT, 0, (LPARAM)&pf2);
int bufSize = GetRichTextLength(GetDlgItem(hwndDlg, IDC_MESSAGE), 1200, TRUE) + 2;
ptrW ptszUnicode((wchar_t*)mir_alloc(bufSize * sizeof(wchar_t)));
MessageSendQueueItem msi = { 0 };
if (pf2.wEffects & PFE_RTLPARA)
msi.flags |= PREF_RTL;
GETTEXTEX gt = { 0 };
gt.flags = GT_USECRLF;
gt.cb = bufSize;
gt.codepage = 1200; // Unicode
SendDlgItemMessage(hwndDlg, IDC_MESSAGE, EM_GETTEXTEX, (WPARAM)>, ptszUnicode);
if (RTL_Detect(ptszUnicode))
msi.flags |= PREF_RTL;
msi.sendBuffer = mir_utf8encodeW(ptszUnicode);
msi.sendBufferSize = (int)mir_strlen(msi.sendBuffer);
if (msi.sendBufferSize == 0)
break;
/* Store messaging history */
TCmdList *cmdListNew = tcmdlist_last(dat->cmdList);
while (cmdListNew != NULL && cmdListNew->temporary) {
dat->cmdList = tcmdlist_remove(dat->cmdList, cmdListNew);
cmdListNew = tcmdlist_last(dat->cmdList);
}
if (msi.sendBuffer != NULL)
dat->cmdList = tcmdlist_append(dat->cmdList, rtrim(msi.sendBuffer), 20, FALSE);
dat->cmdListCurrent = NULL;
if (dat->nTypeMode == PROTOTYPE_SELFTYPING_ON)
NotifyTyping(dat, PROTOTYPE_SELFTYPING_OFF);
SetDlgItemText(hwndDlg, IDC_MESSAGE, L"");
EnableWindow(GetDlgItem(hwndDlg, IDOK), FALSE);
if (db_get_b(NULL, SRMMMOD, SRMSGSET_AUTOMIN, SRMSGDEFSET_AUTOMIN))
ShowWindow(dat->hwndParent, SW_MINIMIZE);
if (LOWORD(wParam) == IDC_SENDALL)
SendMessage(dat->hwndParent, DM_SENDMESSAGE, 0, (LPARAM)&msi);
else
SendMessage(hwndDlg, DM_SENDMESSAGE, 0, (LPARAM)&msi);
}
return TRUE;
case IDCANCEL:
DestroyWindow(hwndDlg);
return TRUE;
case IDC_USERMENU:
if (GetKeyState(VK_SHIFT) & 0x8000) // copy user name
SendMessage(hwndDlg, DM_USERNAMETOCLIP, 0, 0);
else {
RECT rc;
HMENU hMenu = Menu_BuildContactMenu(dat->hContact);
GetWindowRect(GetDlgItem(hwndDlg, LOWORD(wParam)), &rc);
TrackPopupMenu(hMenu, 0, rc.left, rc.bottom, 0, hwndDlg, NULL);
DestroyMenu(hMenu);
}
break;
case IDC_HISTORY:
CallService(MS_HISTORY_SHOWCONTACTHISTORY, dat->hContact, 0);
break;
case IDC_DETAILS:
CallService(MS_USERINFO_SHOWDIALOG, dat->hContact, 0);
break;
case IDC_QUOTE:
if (dat->hDbEventLast != NULL) {
SETTEXTEX st;
st.flags = ST_SELECTION;
st.codepage = 1200;
wchar_t *buffer = NULL;
if (dat->hwndLog != NULL)
buffer = GetIEViewSelection(dat);
else
buffer = GetRichEditSelection(GetDlgItem(hwndDlg, IDC_LOG));
if (buffer != NULL) {
wchar_t *quotedBuffer = GetQuotedTextW(buffer);
SendDlgItemMessage(hwndDlg, IDC_MESSAGE, EM_SETTEXTEX, (WPARAM)&st, (LPARAM)quotedBuffer);
mir_free(quotedBuffer);
mir_free(buffer);
}
else {
DBEVENTINFO dbei = { sizeof(dbei) };
dbei.cbBlob = db_event_getBlobSize(dat->hDbEventLast);
if (dbei.cbBlob == 0xFFFFFFFF)
break;
dbei.pBlob = (PBYTE)mir_alloc(dbei.cbBlob);
db_event_get(dat->hDbEventLast, &dbei);
if (DbEventIsMessageOrCustom(&dbei)) {
buffer = DbEvent_GetTextW(&dbei, CP_ACP);
if (buffer != NULL) {
wchar_t *quotedBuffer = GetQuotedTextW(buffer);
SendDlgItemMessage(hwndDlg, IDC_MESSAGE, EM_SETTEXTEX, (WPARAM)&st, (LPARAM)quotedBuffer);
mir_free(quotedBuffer);
mir_free(buffer);
}
}
mir_free(dbei.pBlob);
}
SetFocus(GetDlgItem(hwndDlg, IDC_MESSAGE));
}
break;
case IDC_ADD:
{
ADDCONTACTSTRUCT acs = { 0 };
acs.hContact = dat->hContact;
acs.handleType = HANDLE_CONTACT;
acs.szProto = 0;
CallService(MS_ADDCONTACT_SHOW, (WPARAM)hwndDlg, (LPARAM)&acs);
}
if (!db_get_b(dat->hContact, "CList", "NotOnList", 0))
ShowWindow(GetDlgItem(hwndDlg, IDC_ADD), SW_HIDE);
case IDC_MESSAGE:
if (HIWORD(wParam) == EN_CHANGE) {
int len = GetRichTextLength(GetDlgItem(hwndDlg, IDC_MESSAGE), 1200, FALSE);
dat->cmdListCurrent = NULL;
UpdateReadChars(hwndDlg, dat);
EnableWindow(GetDlgItem(hwndDlg, IDOK), len != 0);
if (!(GetKeyState(VK_CONTROL) & 0x8000) && !(GetKeyState(VK_SHIFT) & 0x8000)) {
dat->nLastTyping = GetTickCount();
if (len != 0) {
if (dat->nTypeMode == PROTOTYPE_SELFTYPING_OFF)
NotifyTyping(dat, PROTOTYPE_SELFTYPING_ON);
}
else if (dat->nTypeMode == PROTOTYPE_SELFTYPING_ON)
NotifyTyping(dat, PROTOTYPE_SELFTYPING_OFF);
}
}
break;
}
break;
case WM_NOTIFY:
pNmhdr = (LPNMHDR)lParam;
switch (pNmhdr->idFrom) {
case IDC_LOG:
switch (pNmhdr->code) {
case EN_MSGFILTER:
{
int result = InputAreaShortcuts(GetDlgItem(hwndDlg, IDC_MESSAGE), ((MSGFILTER *)lParam)->msg, ((MSGFILTER *)lParam)->wParam, ((MSGFILTER *)lParam)->lParam, dat);
if (result != -1) {
SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, TRUE);
return TRUE;
}
}
switch (((MSGFILTER *)lParam)->msg) {
case WM_CHAR:
if (!(GetKeyState(VK_CONTROL) & 0x8000)) {
SetFocus(GetDlgItem(hwndDlg, IDC_MESSAGE));
SendDlgItemMessage(hwndDlg, IDC_MESSAGE, ((MSGFILTER *)lParam)->msg, ((MSGFILTER *)lParam)->wParam, ((MSGFILTER *)lParam)->lParam);
SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, TRUE);
}
return TRUE;
case WM_LBUTTONDOWN:
hCur = GetCursor();
if (hCur == LoadCursor(NULL, IDC_SIZENS) || hCur == LoadCursor(NULL, IDC_SIZEWE) || hCur == LoadCursor(NULL, IDC_SIZENESW) || hCur == LoadCursor(NULL, IDC_SIZENWSE)) {
SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, TRUE);
return TRUE;
}
break;
case WM_MOUSEMOVE:
hCur = GetCursor();
if (hCur == LoadCursor(NULL, IDC_SIZENS) || hCur == LoadCursor(NULL, IDC_SIZEWE) || hCur == LoadCursor(NULL, IDC_SIZENESW) || hCur == LoadCursor(NULL, IDC_SIZENWSE))
SetCursor(LoadCursor(NULL, IDC_ARROW));
break;
case WM_RBUTTONUP:
SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, TRUE);
return TRUE;
}
break;
case EN_LINK:
switch (((ENLINK *)lParam)->msg) {
case WM_SETCURSOR:
SetCursor(hCurHyperlinkHand);
SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, TRUE);
return TRUE;
case WM_RBUTTONDOWN:
case WM_LBUTTONUP:
if (HandleLinkClick(g_hInst, hwndDlg, GetDlgItem(hwndDlg, IDC_MESSAGE), (ENLINK*)lParam)) {
SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, TRUE);
return TRUE;
}
break;
}
}
break;
case IDC_MESSAGE:
switch (((NMHDR *)lParam)->code) {
case EN_MSGFILTER:
switch (((MSGFILTER *)lParam)->msg) {
case WM_RBUTTONUP:
SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, TRUE);
return TRUE;
}
break;
case EN_REQUESTRESIZE:
REQRESIZE *rr = (REQRESIZE *)lParam;
int height = rr->rc.bottom - rr->rc.top + 1;
if (height < g_dat.minInputAreaHeight)
height = g_dat.minInputAreaHeight;
if (dat->desiredInputAreaHeight != height) {
dat->desiredInputAreaHeight = height;
SendMessage(hwndDlg, WM_SIZE, 0, 0);
PostMessage(hwndDlg, DM_SCROLLLOGTOBOTTOM, 0, 0);
}
break;
}
}
break;
case WM_CHAR:
SetFocus(GetDlgItem(hwndDlg, IDC_MESSAGE));
SendDlgItemMessage(hwndDlg, IDC_MESSAGE, msg, wParam, lParam);
break;
case WM_DESTROY:
NotifyLocalWinEvent(dat->hContact, hwndDlg, MSG_WINDOW_EVT_CLOSING);
if (dat->nTypeMode == PROTOTYPE_SELFTYPING_ON)
NotifyTyping(dat, PROTOTYPE_SELFTYPING_OFF);
IcoLib_ReleaseIcon(dat->statusIcon);
IcoLib_ReleaseIcon(dat->statusIconBig);
if (dat->statusIconOverlay != NULL) DestroyIcon(dat->statusIconOverlay);
dat->statusIcon = NULL;
dat->statusIconOverlay = NULL;
ReleaseSendQueueItems(hwndDlg);
if (g_dat.flags & SMF_SAVEDRAFTS) {
ptrA szText(GetRichTextUtf(GetDlgItem(hwndDlg, IDC_MESSAGE)));
if (szText)
db_set_utf(dat->hContact, "SRMM", "SavedMsg", szText);
else
db_unset(dat->hContact, "SRMM", "SavedMsg");
}
tcmdlist_free(dat->cmdList);
WindowList_Remove(pci->hWindowList, hwndDlg);
HFONT hFont = (HFONT)SendDlgItemMessage(hwndDlg, IDC_MESSAGE, WM_GETFONT, 0, 0);
if (hFont != NULL && hFont != (HFONT)SendDlgItemMessage(hwndDlg, IDOK, WM_GETFONT, 0, 0))
DeleteObject(hFont);
db_set_b(dat->hContact, SRMMMOD, "UseRTL", (BYTE)((dat->flags & SMF_RTL) ? 1 : 0));
if (dat->hContact && (g_dat.flags & SMF_DELTEMP))
if (db_get_b(dat->hContact, "CList", "NotOnList", 0))
db_delete_contact(dat->hContact);
SetWindowLongPtr(hwndDlg, GWLP_USERDATA, 0);
SendMessage(dat->hwndParent, CM_REMOVECHILD, 0, (LPARAM)hwndDlg);
if (dat->hwndLog != NULL) {
IEVIEWWINDOW ieWindow = { sizeof(ieWindow) };
ieWindow.iType = IEW_DESTROY;
ieWindow.hwnd = dat->hwndLog;
CallService(MS_IEVIEW_WINDOW, 0, (LPARAM)&ieWindow);
}
NotifyLocalWinEvent(dat->hContact, hwndDlg, MSG_WINDOW_EVT_CLOSE);
mir_free(dat);
break;
}
return FALSE;
}
|