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
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
|
/*
Copyright 2000-2012 Miranda 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 "commonheaders.h"
#include "statusicon.h"
#define TIMERID_FLASHWND 1
#define TIMERID_TYPE 2
#define TIMEOUT_FLASHWND 900
#define TIMEOUT_TYPEOFF 10000 //send type off after 10 seconds of inactivity
#define SB_CHAR_WIDTH 45
#define SB_TIME_WIDTH 60
#define SB_GRIP_WIDTH 20 // pixels - buffer used to prevent sizegrip from overwriting statusbar icons
#define VALID_AVATAR(x) (x == PA_FORMAT_PNG || x == PA_FORMAT_JPEG || x == PA_FORMAT_ICON || x == PA_FORMAT_BMP || x == PA_FORMAT_GIF)
extern HCURSOR hCurSplitNS, hCurSplitWE, hCurHyperlinkHand;
extern HANDLE hHookWinEvt, hHookWinPopup;
extern CREOleCallback reOleCallback;
static void UpdateReadChars(HWND hwndDlg, HWND hwndStatus);
static const UINT infoLineControls[] = { IDC_PROTOCOL, IDC_NAME };
static const UINT buttonLineControls[] = { IDC_ADD, IDC_USERMENU, IDC_DETAILS, IDC_HISTORY };
static const UINT sendControls[] = { IDC_MESSAGE };
static void NotifyLocalWinEvent(HANDLE hContact, HWND hwnd, unsigned int type)
{
if (hContact == NULL || hwnd == NULL)
return;
MessageWindowEventData mwe = { 0 };
mwe.cbSize = sizeof(mwe);
mwe.hContact = hContact;
mwe.hwndWindow = hwnd;
mwe.szModule = SRMMMOD;
mwe.uType = type;
mwe.uFlags = MSG_WINDOW_UFLAG_MSG_BOTH;
mwe.hwndInput = GetDlgItem(hwnd, IDC_MESSAGE);
mwe.hwndLog = GetDlgItem(hwnd, IDC_LOG);
NotifyEventHooks(hHookWinEvt, 0, (LPARAM)&mwe);
}
static char *MsgServiceName(HANDLE hContact)
{
char szServiceName[100];
char *szProto = (char *) CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM) hContact, 0);
if (szProto == NULL)
return PSS_MESSAGE;
mir_snprintf(szServiceName, SIZEOF(szServiceName), "%s%sW", szProto, PSS_MESSAGE);
if (ServiceExists(szServiceName))
return PSS_MESSAGE "W";
return PSS_MESSAGE;
}
static BOOL IsUtfSendAvailable(HANDLE hContact)
{
char* szProto = (char *) CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM) hContact, 0);
if ( szProto == NULL )
return FALSE;
return ( CallProtoService(szProto, PS_GETCAPS, PFLAGNUM_4, 0) & PF4_IMSENDUTF ) ? TRUE : FALSE;
}
static int RTL_Detect(const TCHAR *ptszText)
{
WORD *infoTypeC2;
int i;
int iLen = (int)_tcslen(ptszText);
infoTypeC2 = (WORD*)alloca(sizeof(WORD) * (iLen + 2));
GetStringTypeEx(LOCALE_USER_DEFAULT, CT_CTYPE2, ptszText, iLen, infoTypeC2);
for(i = 0; i < iLen; i++) {
if(infoTypeC2[i] == C2_RIGHTTOLEFT)
return 1;
}
return 0;
}
HANDLE SendMessageDirect(const TCHAR *szMsg, HANDLE hContact, char *szProto)
{
int flags = 0;
int bufSize = 0;
char *sendBuffer = NULL;
if (RTL_Detect(szMsg)) flags |= PREF_RTL;
if (IsUtfSendAvailable(hContact)) {
flags |= PREF_UTF;
sendBuffer = mir_utf8encodeT(szMsg);
if (!sendBuffer || !sendBuffer[0]) {
mir_free(sendBuffer);
return NULL;
}
bufSize = (int)strlen(sendBuffer) + 1;
}
else {
flags |= PREF_TCHAR;
sendBuffer = mir_t2a(szMsg);
if (!sendBuffer || !sendBuffer[0])
{
mir_free(sendBuffer);
return NULL;
}
bufSize = (int)strlen(sendBuffer) + 1;
size_t bufSizeT = (_tcslen(szMsg) + 1) * sizeof(TCHAR) ;
sendBuffer = (char*)mir_realloc(sendBuffer, bufSizeT + bufSize);
memcpy((TCHAR*)&sendBuffer[bufSize], szMsg, bufSizeT);
bufSize += (int)bufSizeT;
}
if (hContact == NULL) {
mir_free(sendBuffer);
return NULL;
}
if (sendBuffer) {
HANDLE hNewEvent, hSendId;
DBEVENTINFO dbei = { 0 };
dbei.cbSize = sizeof(dbei);
dbei.eventType = EVENTTYPE_MESSAGE;
dbei.flags = DBEF_SENT | (flags & PREF_UTF ? DBEF_UTF : 0) | (flags & PREF_RTL ? DBEF_RTL : 0);
dbei.szModule = szProto;
dbei.timestamp = (DWORD)time(NULL);
dbei.cbBlob = (DWORD)bufSize;
dbei.pBlob = (PBYTE)sendBuffer;
hNewEvent = (HANDLE) CallService(MS_DB_EVENT_ADD, (WPARAM)hContact, (LPARAM)&dbei);
hSendId = (HANDLE) CallContactService(hContact, MsgServiceName(hContact), flags, (LPARAM) sendBuffer);
msgQueue_add(hContact, hSendId, szMsg, hNewEvent);
mir_free(sendBuffer);
return hNewEvent;
}
return NULL;
}
static void AddToFileList(TCHAR ***pppFiles,int *totalCount,const TCHAR* szFilename)
{
*pppFiles=(TCHAR**)mir_realloc(*pppFiles,(++*totalCount+1)*sizeof(TCHAR*));
(*pppFiles)[*totalCount] = NULL;
(*pppFiles)[*totalCount-1] = mir_tstrdup( szFilename );
if ( GetFileAttributes(szFilename) & FILE_ATTRIBUTE_DIRECTORY ) {
WIN32_FIND_DATA fd;
HANDLE hFind;
TCHAR szPath[MAX_PATH];
mir_sntprintf(szPath, SIZEOF(szPath), _T("%s\\*"), szFilename);
if (( hFind = FindFirstFile( szPath, &fd )) != INVALID_HANDLE_VALUE ) {
do {
if ( !_tcscmp(fd.cFileName,_T(".")) || !_tcscmp(fd.cFileName,_T(".."))) continue;
mir_sntprintf(szPath, SIZEOF(szPath), _T("%s\\%s"), szFilename, fd.cFileName);
AddToFileList(pppFiles,totalCount,szPath);
}
while( FindNextFile( hFind,&fd ));
FindClose( hFind );
} } }
static void ShowMultipleControls(HWND hwndDlg, const UINT * controls, int cControls, int state)
{
int i;
for (i = 0; i < cControls; i++)
ShowWindow(GetDlgItem(hwndDlg, controls[i]), state);
}
static void UpdateReadChars(HWND hwndDlg, HWND hwndStatus)
{
if (hwndStatus && (g_dat->flags & SMF_SHOWREADCHAR))
{
TCHAR buf[32];
int len = GetWindowTextLength(GetDlgItem(hwndDlg, IDC_MESSAGE));
mir_sntprintf(buf, SIZEOF(buf), _T("%d"), len);
SendMessage(hwndStatus, SB_SETTEXT, 1, (LPARAM) buf);
}
}
static void ShowTime(struct SrmmWindowData *dat)
{
if (dat->hwndStatus && dat->hTimeZone)
{
SYSTEMTIME st;
GetSystemTime(&st);
if (dat->wMinute != st.wMinute)
{
TCHAR buf[32];
unsigned i = (g_dat->flags & SMF_SHOWREADCHAR) ? 2 : 1;
tmi.printDateTime(dat->hTimeZone, _T("t"), buf, SIZEOF(buf), 0);
SendMessage(dat->hwndStatus, SB_SETTEXT, i, (LPARAM) buf);
dat->wMinute = st.wMinute;
}
}
}
static void SetupStatusBar(HWND hwndDlg, struct SrmmWindowData *dat)
{
int icons_width, cx, i = 0, statwidths[4];
RECT rc;
icons_width = GetStatusIconsCount(dat->hContact) * (GetSystemMetrics(SM_CXSMICON) + 2) + SB_GRIP_WIDTH;
GetWindowRect(dat->hwndStatus, &rc);
cx = rc.right - rc.left;
if (dat->hTimeZone)
{
if (g_dat->flags & SMF_SHOWREADCHAR)
statwidths[i++] = cx - SB_TIME_WIDTH - SB_CHAR_WIDTH - icons_width;
statwidths[i++] = cx - SB_TIME_WIDTH - icons_width;
}
else if (g_dat->flags & SMF_SHOWREADCHAR)
statwidths[i++] = cx - SB_CHAR_WIDTH - icons_width;
statwidths[i++] = cx - icons_width;
statwidths[i++] = -1;
SendMessage(dat->hwndStatus, SB_SETPARTS, i, (LPARAM) statwidths);
UpdateReadChars(hwndDlg, dat->hwndStatus);
ShowTime(dat);
SendMessage(hwndDlg, DM_STATUSICONCHANGE, 0, 0);
}
static void SetDialogToType(HWND hwndDlg)
{
struct SrmmWindowData *dat;
dat = (struct SrmmWindowData *) GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
if (dat->hContact)
ShowMultipleControls(hwndDlg, infoLineControls, SIZEOF(infoLineControls), (g_dat->flags&SMF_SHOWINFO) ? SW_SHOW : SW_HIDE);
else
ShowMultipleControls(hwndDlg, infoLineControls, SIZEOF(infoLineControls), SW_HIDE);
if (dat->hContact) {
ShowMultipleControls(hwndDlg, buttonLineControls, SIZEOF(buttonLineControls), (g_dat->flags&SMF_SHOWBTNS) ? SW_SHOW : SW_HIDE);
if (!DBGetContactSettingByte(dat->hContact, "CList", "NotOnList", 0))
ShowWindow(GetDlgItem(hwndDlg, IDC_ADD), SW_HIDE);
}
else ShowMultipleControls(hwndDlg, buttonLineControls, SIZEOF(buttonLineControls), SW_HIDE);
ShowMultipleControls(hwndDlg, sendControls, SIZEOF(sendControls), SW_SHOW);
if (!dat->hwndStatus) {
int grip = (GetWindowLongPtr(hwndDlg, GWL_STYLE) & WS_THICKFRAME) ? SBARS_SIZEGRIP : 0;
dat->hwndStatus = CreateWindowEx(0, STATUSCLASSNAME, NULL, WS_CHILD | WS_VISIBLE | grip, 0, 0, 0, 0, hwndDlg, NULL, g_hInst, NULL);
SendMessage(dat->hwndStatus, SB_SETMINHEIGHT, GetSystemMetrics(SM_CYSMICON), 0);
}
ShowWindow(GetDlgItem(hwndDlg, IDCANCEL), SW_HIDE);
ShowWindow(GetDlgItem(hwndDlg, IDC_SPLITTER), SW_SHOW);
ShowWindow(GetDlgItem(hwndDlg, IDOK), (g_dat->flags & SMF_SENDBTN) ? SW_SHOW : SW_HIDE);
EnableWindow(GetDlgItem(hwndDlg, IDOK), GetWindowTextLength(GetDlgItem(hwndDlg, IDC_MESSAGE)) != 0);
if (dat->avatarPic == NULL || !(g_dat->flags & SMF_AVATAR))
ShowWindow(GetDlgItem(hwndDlg, IDC_AVATAR), SW_HIDE);
SendMessage(hwndDlg, DM_UPDATETITLE, 0, 0);
SendMessage(hwndDlg, WM_SIZE, 0, 0);
}
struct MsgEditSubclassData
{
DWORD lastEnterTime;
};
static void SetEditorText(HWND hwnd, const TCHAR* txt)
{
SetWindowText(hwnd, txt);
SendMessage(hwnd, EM_SETSEL, -1, -1);
}
#define EM_SUBCLASSED (WM_USER+0x101)
#define EM_UNSUBCLASSED (WM_USER+0x102)
#define ENTERCLICKTIME 1000 //max time in ms during which a double-tap on enter will cause a send
static LRESULT CALLBACK MessageEditSubclassProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
struct SrmmWindowData *pdat = (struct SrmmWindowData *)GetWindowLongPtr(GetParent(hwnd),GWLP_USERDATA);
struct MsgEditSubclassData *dat = (struct MsgEditSubclassData *) GetWindowLongPtr(hwnd, GWLP_USERDATA);
switch (msg) {
case WM_DROPFILES:
SendMessage(GetParent(hwnd), WM_DROPFILES, (WPARAM)wParam, (LPARAM)lParam);
break;
case EM_SUBCLASSED:
dat = (struct MsgEditSubclassData *) mir_alloc(sizeof(struct MsgEditSubclassData));
SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR) dat);
dat->lastEnterTime = 0;
return 0;
case WM_CHAR:
if (GetWindowLongPtr(hwnd, GWL_STYLE) & ES_READONLY)
break;
if (wParam == 1 && GetKeyState(VK_CONTROL) & 0x8000) { //ctrl-a
SendMessage(hwnd, EM_SETSEL, 0, -1);
return 0;
}
if (wParam == 23 && GetKeyState(VK_CONTROL) & 0x8000) { // ctrl-w
SendMessage(GetParent(hwnd), WM_CLOSE, 0, 0);
return 0;
}
break;
case WM_KEYDOWN:
if (wParam == VK_RETURN)
{
if (!(GetKeyState(VK_SHIFT) & 0x8000) &&
((GetKeyState(VK_CONTROL) & 0x8000) != 0) != ((g_dat->flags & SMF_SENDONENTER) != 0))
{
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;
if (((wParam == VK_INSERT && (GetKeyState(VK_SHIFT) & 0x8000)) || (wParam == 'V' && (GetKeyState(VK_CONTROL) & 0x8000))) &&
!(GetKeyState(VK_MENU) & 0x8000)) // ctrl-v (paste clean text)
{
SendMessage(hwnd, WM_PASTE, 0, 0);
return 0;
}
if (wParam == VK_UP && (GetKeyState(VK_CONTROL) & 0x8000) &&
((g_dat->flags & (SMF_AUTOCLOSE | SMF_CTRLSUPPORT)) == SMF_CTRLSUPPORT))
{
if (pdat->cmdList->realCount)
{
if (pdat->cmdListInd < 0)
{
pdat->cmdListInd = pdat->cmdList->realCount - 1;
SetEditorText(hwnd, tcmdlist_getitem(pdat->cmdList, pdat->cmdListInd));
}
else if (pdat->cmdListInd > 0)
{
SetEditorText(hwnd, tcmdlist_getitem(pdat->cmdList, --pdat->cmdListInd));
}
}
EnableWindow(GetDlgItem(GetParent(hwnd), IDOK), GetWindowTextLength(hwnd) != 0);
UpdateReadChars(GetParent(hwnd), pdat->hwndStatus);
return 0;
}
else if (wParam == VK_DOWN && (GetKeyState(VK_CONTROL) & 0x8000) &&
((g_dat->flags & (SMF_AUTOCLOSE | SMF_CTRLSUPPORT)) == SMF_CTRLSUPPORT))
{
if (pdat->cmdList->realCount && pdat->cmdListInd >= 0)
{
if (pdat->cmdListInd < (pdat->cmdList->realCount - 1))
{
SetEditorText(hwnd, tcmdlist_getitem(pdat->cmdList, ++pdat->cmdListInd));
}
else
{
pdat->cmdListInd = -1;
SetEditorText(hwnd, tcmdlist_getitem(pdat->cmdList, pdat->cmdList->realCount - 1));
}
}
EnableWindow(GetDlgItem(GetParent(hwnd), IDOK), GetWindowTextLength(hwnd) != 0);
UpdateReadChars(GetParent(hwnd), pdat->hwndStatus);
}
break;
case WM_LBUTTONDOWN:
case WM_RBUTTONDOWN:
case WM_MBUTTONDOWN:
case WM_MOUSEWHEEL:
case WM_KILLFOCUS:
dat->lastEnterTime = 0;
break;
case WM_SYSCHAR:
dat->lastEnterTime = 0;
if ((wParam == 's' || wParam == 'S') && GetKeyState(VK_MENU) & 0x8000)
{
PostMessage(GetParent(hwnd), WM_COMMAND, IDOK, 0);
return 0;
}
break;
case WM_CONTEXTMENU:
{
HMENU hMenu;
CHARRANGE sel;
static const CHARRANGE all = {0, -1};
MessageWindowPopupData mwpd = {0};
mwpd.cbSize = sizeof(mwpd);
mwpd.uType = MSG_WINDOWPOPUP_SHOWING;
mwpd.uFlags = MSG_WINDOWPOPUP_INPUT;
mwpd.hContact = pdat->hContact;
mwpd.hwnd = hwnd;
hMenu = LoadMenu(g_hInst, MAKEINTRESOURCE(IDR_CONTEXT));
mwpd.hMenu = GetSubMenu(hMenu, 2);
TranslateMenu(mwpd.hMenu);
SendMessage(hwnd, EM_EXGETSEL, 0, (LPARAM)&sel);
if (sel.cpMin == sel.cpMax)
{
EnableMenuItem(mwpd.hMenu, IDM_CUT, MF_BYCOMMAND | MF_GRAYED);
EnableMenuItem(mwpd.hMenu, IDM_COPY, MF_BYCOMMAND | MF_GRAYED);
EnableMenuItem(mwpd.hMenu, IDM_DELETE, MF_BYCOMMAND | MF_GRAYED);
}
if (!SendMessage(hwnd, EM_CANUNDO, 0, 0))
{
EnableMenuItem(mwpd.hMenu, IDM_UNDO, MF_BYCOMMAND | MF_GRAYED);
}
if (!SendMessage(hwnd, EM_CANREDO, 0, 0))
{
EnableMenuItem(mwpd.hMenu, IDM_REDO, MF_BYCOMMAND | MF_GRAYED);
}
if (!SendMessage(hwnd, EM_CANPASTE, 0, 0))
{
if (!IsClipboardFormatAvailable(CF_HDROP))
EnableMenuItem(mwpd.hMenu, IDM_PASTE, MF_BYCOMMAND | MF_GRAYED);
EnableMenuItem(mwpd.hMenu, IDM_PASTESEND, MF_BYCOMMAND | MF_GRAYED);
}
if (lParam == 0xFFFFFFFF)
{
SendMessage(hwnd, EM_POSFROMCHAR, (WPARAM)&mwpd.pt, (LPARAM)sel.cpMax);
ClientToScreen(hwnd, &mwpd.pt);
}
else
{
mwpd.pt.x = GET_X_LPARAM(lParam);
mwpd.pt.y = GET_Y_LPARAM(lParam);
}
// First notification
NotifyEventHooks(hHookWinPopup, 0, (LPARAM)&mwpd);
// Someone added items?
if (GetMenuItemCount(mwpd.hMenu) > 0)
{
SetCursor(LoadCursor(NULL, IDC_ARROW));
mwpd.selection = TrackPopupMenu(mwpd.hMenu, TPM_RETURNCMD, mwpd.pt.x, mwpd.pt.y, 0, hwnd, NULL);
}
// Second notification
mwpd.uType = MSG_WINDOWPOPUP_SELECTED;
NotifyEventHooks(hHookWinPopup, 0, (LPARAM)&mwpd);
switch (mwpd.selection)
{
case IDM_UNDO:
SendMessage(hwnd, WM_UNDO, 0, 0);
break;
case IDM_REDO:
SendMessage(hwnd, EM_REDO, 0, 0);
break;
case IDM_CUT:
SendMessage(hwnd, WM_CUT, 0, 0);
break;
case IDM_COPY:
SendMessage(hwnd, WM_COPY, 0, 0);
break;
case IDM_PASTE:
SendMessage(hwnd, WM_PASTE, 0, 0);
break;
case IDM_PASTESEND:
SendMessage(hwnd, EM_PASTESPECIAL, CF_TEXT, 0);
PostMessage(GetParent(hwnd), WM_COMMAND, IDOK, 0);
break;
case IDM_DELETE:
SendMessage(hwnd, EM_REPLACESEL, TRUE, 0);
break;
case IDM_SELECTALL:
SendMessage(hwnd, EM_EXSETSEL, 0, (LPARAM)&all);
break;
case IDM_CLEAR:
SetWindowText(hwnd, _T( "" ));
break;
}
DestroyMenu(hMenu);
return 0;
}
case WM_PASTE:
if (IsClipboardFormatAvailable(CF_HDROP))
{
if (OpenClipboard(hwnd))
{
HANDLE hDrop = GetClipboardData(CF_HDROP);
if (hDrop)
SendMessage(hwnd, WM_DROPFILES, (WPARAM)hDrop, 0);
CloseClipboard();
}
}
else
SendMessage(hwnd, EM_PASTESPECIAL, CF_TEXT, 0);
return 0;
case EM_UNSUBCLASSED:
mir_free(dat);
return 0;
}
return CallWindowProc(pdat->OldMessageEditProc, hwnd, msg, wParam, lParam);
}
static LRESULT CALLBACK SplitterSubclassProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
struct SrmmWindowData *pdat = (struct SrmmWindowData *)GetWindowLongPtr(GetParent(hwnd),GWLP_USERDATA);
switch (msg) {
case WM_NCHITTEST:
return HTCLIENT;
case WM_SETCURSOR:
{
RECT rc;
GetClientRect(hwnd, &rc);
SetCursor(rc.right > rc.bottom ? hCurSplitNS : hCurSplitWE);
return TRUE;
}
case WM_LBUTTONDOWN:
SetCapture(hwnd);
return 0;
case WM_MOUSEMOVE:
if (GetCapture() == hwnd) {
RECT rc;
GetClientRect(hwnd, &rc);
SendMessage(GetParent(hwnd), DM_SPLITTERMOVED, rc.right > rc.bottom ? (short) HIWORD(GetMessagePos()) + rc.bottom / 2 : (short) LOWORD(GetMessagePos()) + rc.right / 2, (LPARAM) hwnd);
}
return 0;
case WM_LBUTTONUP:
ReleaseCapture();
return 0;
}
return CallWindowProc(pdat->OldSplitterProc, hwnd, msg, wParam, lParam);
}
static int MessageDialogResize(HWND hwndDlg, LPARAM lParam, UTILRESIZECONTROL * urc)
{
struct SrmmWindowData *dat = (struct SrmmWindowData *) lParam;
if (!(g_dat->flags&SMF_SHOWINFO) && !(g_dat->flags&SMF_SHOWBTNS)) {
int i;
for (i = 0; i < SIZEOF(buttonLineControls); i++)
if (buttonLineControls[i] == urc->wId)
OffsetRect(&urc->rcItem, 0, -dat->lineHeight);
}
switch (urc->wId) {
case IDC_NAME:
{
int len;
HWND h;
h = GetDlgItem(hwndDlg, IDC_NAME);
len = GetWindowTextLength(h);
if (len > 0) {
TCHAR buf[256];
GetWindowText(h, buf, SIZEOF(buf));
HDC hdc = GetDC(h);
HFONT hFont = (HFONT)SelectObject(hdc, (HFONT) SendMessage(GetDlgItem(hwndDlg, IDOK), WM_GETFONT, 0, 0));
SIZE textSize;
GetTextExtentPoint32(hdc, buf, lstrlen(buf), &textSize);
urc->rcItem.right = urc->rcItem.left + textSize.cx + 10;
if ((g_dat->flags&SMF_SHOWBTNS) && urc->rcItem.right > urc->dlgNewSize.cx - dat->nLabelRight)
urc->rcItem.right = urc->dlgNewSize.cx - dat->nLabelRight;
SelectObject(hdc, hFont);
ReleaseDC(h, hdc);
}
}
case IDC_PROTOCOL:
return RD_ANCHORX_LEFT | RD_ANCHORY_TOP;
case IDC_ADD:
case IDC_USERMENU:
case IDC_DETAILS:
case IDC_HISTORY:
return RD_ANCHORX_RIGHT | RD_ANCHORY_TOP;
case IDC_LOG:
if (!(g_dat->flags&SMF_SHOWINFO) && !(g_dat->flags&SMF_SHOWBTNS))
urc->rcItem.top -= dat->lineHeight;
urc->rcItem.bottom -= dat->splitterPos - dat->originalSplitterPos;
return RD_ANCHORX_WIDTH | RD_ANCHORY_HEIGHT;
case IDC_SPLITTER:
urc->rcItem.top -= dat->splitterPos - dat->originalSplitterPos;
urc->rcItem.bottom -= dat->splitterPos - dat->originalSplitterPos;
return RD_ANCHORX_WIDTH | RD_ANCHORY_BOTTOM;
case IDC_MESSAGE:
{
if (!(g_dat->flags & SMF_SENDBTN))
urc->rcItem.right = urc->dlgNewSize.cx - urc->rcItem.left;
if ((g_dat->flags & SMF_AVATAR) && dat->avatarPic) {
urc->rcItem.left = dat->avatarWidth+4;
}
urc->rcItem.top -= dat->splitterPos - dat->originalSplitterPos;
if (!(g_dat->flags & SMF_SENDBTN))
return RD_ANCHORX_CUSTOM | RD_ANCHORY_BOTTOM;
return RD_ANCHORX_WIDTH | RD_ANCHORY_BOTTOM;
}
case IDCANCEL:
case IDOK:
urc->rcItem.top -= dat->splitterPos - dat->originalSplitterPos;
return RD_ANCHORX_RIGHT | RD_ANCHORY_BOTTOM;
case IDC_AVATAR:
urc->rcItem.top=urc->rcItem.bottom-(dat->avatarHeight + 2);
urc->rcItem.right=urc->rcItem.left+(dat->avatarWidth + 2);
return RD_ANCHORX_LEFT|RD_ANCHORY_BOTTOM;
}
return RD_ANCHORX_LEFT | RD_ANCHORY_TOP;
}
void ShowAvatar(HWND hwndDlg, struct SrmmWindowData *dat)
{
if (g_dat->flags & SMF_AVATAR)
{
AVATARCACHEENTRY *ace = (AVATARCACHEENTRY *)CallService(MS_AV_GETAVATARBITMAP, (WPARAM)dat->hContact, 0);
if (ace && (INT_PTR)ace != CALLSERVICE_NOTFOUND && (ace->dwFlags & AVS_BITMAP_VALID) && !(ace->dwFlags & AVS_HIDEONCLIST))
dat->avatarPic = ace->hbmPic;
else
dat->avatarPic = NULL;
}
else
dat->avatarPic = NULL;
SendMessage(hwndDlg, DM_UPDATESIZEBAR, 0, 0);
SendMessage(hwndDlg, DM_AVATARSIZECHANGE, 0, 0);
}
static void NotifyTyping(struct SrmmWindowData *dat, int mode)
{
DWORD protoStatus;
DWORD protoCaps;
DWORD typeCaps;
if (!dat->hContact)
return;
// 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.
if (!DBGetContactSettingByte(dat->hContact, SRMMMOD, SRMSGSET_TYPING, DBGetContactSettingByte(NULL, SRMMMOD, SRMSGSET_TYPINGNEW, SRMSGDEFSET_TYPINGNEW)))
return;
if (!dat->szProto)
return;
protoStatus = CallProtoService(dat->szProto, PS_GETSTATUS, 0, 0);
protoCaps = CallProtoService(dat->szProto, PS_GETCAPS, PFLAGNUM_1, 0);
typeCaps = CallProtoService(dat->szProto, PS_GETCAPS, PFLAGNUM_4, 0);
if (!(typeCaps & PF4_SUPPORTTYPING))
return;
if (protoStatus < ID_STATUS_ONLINE)
return;
if (protoCaps & PF1_VISLIST && DBGetContactSettingWord(dat->hContact, dat->szProto, "ApparentMode", 0) == ID_STATUS_OFFLINE)
return;
if (protoCaps & PF1_INVISLIST && protoStatus == ID_STATUS_INVISIBLE && DBGetContactSettingWord(dat->hContact, dat->szProto, "ApparentMode", 0) != ID_STATUS_ONLINE)
return;
if (!(g_dat->flags & SMF_TYPINGUNKNOWN) && DBGetContactSettingByte(dat->hContact, "CList", "NotOnList", 0))
return;
// End user check
dat->nTypeMode = mode;
CallService(MS_PROTO_SELFISTYPING, (WPARAM) dat->hContact, dat->nTypeMode);
}
void Button_SetIcon_IcoLib(HWND hwndDlg, int itemId, int iconId, const char* tooltip)
{
HWND hWnd = GetDlgItem( hwndDlg, itemId );
SendMessage( hWnd, BM_SETIMAGE, IMAGE_ICON, ( LPARAM )LoadSkinnedIcon( iconId ));
SendMessage( hWnd, BUTTONSETASFLATBTN, TRUE, 0 );
SendMessage( hWnd, BUTTONADDTOOLTIP, (WPARAM)tooltip, 0);
}
void Button_FreeIcon_IcoLib(HWND hwndDlg, int itemId)
{
HICON hIcon = ( HICON )SendDlgItemMessage(hwndDlg, itemId, BM_SETIMAGE, IMAGE_ICON, 0 );
CallService(MS_SKIN2_RELEASEICON, (WPARAM)hIcon, 0);
}
void Window_FreeIcon_IcoLib(HWND hwndDlg)
{
HICON hIcon = (HICON)SendMessage(hwndDlg, WM_SETICON, ICON_BIG, 0);
CallService(MS_SKIN2_RELEASEICON, (WPARAM)hIcon, 0);
hIcon = (HICON)SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, 0);
CallService(MS_SKIN2_RELEASEICON, (WPARAM)hIcon, 0);
}
INT_PTR CALLBACK DlgProcMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
struct SrmmWindowData *dat;
dat = (struct SrmmWindowData *) GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
switch (msg)
{
case WM_INITDIALOG:
{
struct NewMessageWindowLParam *newData = (struct NewMessageWindowLParam *) lParam;
TranslateDialogDefault(hwndDlg);
dat = (struct SrmmWindowData *) mir_calloc(sizeof(struct SrmmWindowData));
SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR) dat);
dat->hContact = newData->hContact;
dat->hTimeZone = tmi.createByContact(dat->hContact, TZF_KNOWNONLY);
dat->wMinute = 61;
NotifyLocalWinEvent(dat->hContact, hwndDlg, MSG_WINDOW_EVT_OPENING);
if (newData->szInitialText)
{
int len;
if(newData->isWchar)
SetDlgItemText(hwndDlg, IDC_MESSAGE, (TCHAR *)newData->szInitialText);
else
SetDlgItemTextA(hwndDlg, IDC_MESSAGE, newData->szInitialText);
len = GetWindowTextLength(GetDlgItem(hwndDlg, IDC_MESSAGE));
PostMessage(GetDlgItem(hwndDlg, IDC_MESSAGE), EM_SETSEL, len, len);
}
dat->szProto = (char *) CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM) dat->hContact, 0);
RichUtil_SubClass(GetDlgItem(hwndDlg, IDC_LOG));
RichUtil_SubClass(GetDlgItem(hwndDlg, IDC_MESSAGE));
// avatar stuff
dat->limitAvatarH = DBGetContactSettingByte(NULL, SRMMMOD, SRMSGSET_LIMITAVHEIGHT, SRMSGDEFSET_LIMITAVHEIGHT)?DBGetContactSettingDword(NULL, SRMMMOD, SRMSGSET_AVHEIGHT, SRMSGDEFSET_AVHEIGHT):0;
if (dat->hContact && dat->szProto != NULL)
dat->wStatus = DBGetContactSettingWord(dat->hContact, dat->szProto, "Status", ID_STATUS_OFFLINE);
else
dat->wStatus = ID_STATUS_OFFLINE;
dat->wOldStatus = dat->wStatus;
dat->splitterPos = (int) DBGetContactSettingDword(DBGetContactSettingByte(NULL, SRMMMOD, SRMSGSET_SAVEPERCONTACT, SRMSGDEFSET_SAVEPERCONTACT)?dat->hContact:NULL, SRMMMOD, "splitterPos", (DWORD) - 1);
dat->cmdList = List_Create(0, 20);
dat->cmdListInd = -1;
dat->nTypeMode = PROTOTYPE_SELFTYPING_OFF;
SetTimer(hwndDlg, TIMERID_TYPE, 1000, NULL);
{
RECT rc, rc2;
GetWindowRect(GetDlgItem(hwndDlg, IDC_USERMENU), &rc);
GetWindowRect(hwndDlg, &rc2);
dat->nLabelRight = rc2.right - rc.left;
}
{
RECT rc;
POINT pt;
GetWindowRect(GetDlgItem(hwndDlg, IDC_SPLITTER), &rc);
pt.y = (rc.top + rc.bottom) / 2;
pt.x = 0;
ScreenToClient(hwndDlg, &pt);
dat->originalSplitterPos = pt.y;
if (dat->splitterPos == -1)
dat->splitterPos = dat->originalSplitterPos;// + 60;
GetWindowRect(GetDlgItem(hwndDlg, IDC_ADD), &rc);
dat->lineHeight = rc.bottom - rc.top + 3;
}
WindowList_Add(g_dat->hMessageWindowList, hwndDlg, dat->hContact);
GetWindowRect(GetDlgItem(hwndDlg, IDC_MESSAGE), &dat->minEditInit);
SendMessage(hwndDlg, DM_UPDATESIZEBAR, 0, 0);
dat->hwndStatus = NULL;
Button_SetIcon_IcoLib(hwndDlg, IDC_ADD, SKINICON_OTHER_ADDCONTACT, "Add Contact Permanently to List" );
Button_SetIcon_IcoLib(hwndDlg, IDC_DETAILS, SKINICON_OTHER_USERDETAILS, "View User's Details" );
Button_SetIcon_IcoLib(hwndDlg, IDC_HISTORY, SKINICON_OTHER_HISTORY, "View User's History" );
Button_SetIcon_IcoLib(hwndDlg, IDC_USERMENU, SKINICON_OTHER_DOWNARROW, "User Menu" );
SendDlgItemMessage(hwndDlg, IDC_NAME, BUTTONSETASFLATBTN, TRUE, 0 );
EnableWindow(GetDlgItem(hwndDlg, IDC_PROTOCOL), FALSE);
EnableWindow(GetDlgItem(hwndDlg, IDC_AVATAR), FALSE);
SendDlgItemMessage(hwndDlg, IDC_LOG, EM_SETOLECALLBACK, 0, (LPARAM) & reOleCallback);
SendDlgItemMessage(hwndDlg, IDC_LOG, EM_SETEVENTMASK, 0, ENM_MOUSEEVENTS | ENM_LINK | ENM_SCROLL);
/* duh, how come we didnt use this from the start? */
SendDlgItemMessage(hwndDlg, IDC_LOG, EM_AUTOURLDETECT, (WPARAM) TRUE, 0);
if (dat->hContact && dat->szProto) {
int nMax;
nMax = CallProtoService(dat->szProto, PS_GETCAPS, PFLAG_MAXLENOFMESSAGE, (LPARAM) dat->hContact);
if (nMax)
SendDlgItemMessage(hwndDlg, IDC_MESSAGE, EM_LIMITTEXT, (WPARAM) 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, (WPARAM) sizeof(TCHAR) * 0x7FFFFFFF, 0);
}
dat->OldMessageEditProc = (WNDPROC) SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_MESSAGE), GWLP_WNDPROC, (LONG_PTR) MessageEditSubclassProc);
SendDlgItemMessage(hwndDlg, IDC_MESSAGE, EM_SUBCLASSED, 0, 0);
dat->OldSplitterProc = (WNDPROC) SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_SPLITTER), GWLP_WNDPROC, (LONG_PTR) SplitterSubclassProc);
if (dat->hContact)
{
int historyMode = DBGetContactSettingByte(NULL, SRMMMOD, SRMSGSET_LOADHISTORY, SRMSGDEFSET_LOADHISTORY);
// This finds the first message to display, it works like shit
dat->hDbEventFirst = (HANDLE) CallService(MS_DB_EVENT_FINDFIRSTUNREAD, (WPARAM) dat->hContact, 0);
switch (historyMode)
{
case LOADHISTORY_COUNT:
{
int i;
HANDLE hPrevEvent;
DBEVENTINFO dbei = { 0 };
dbei.cbSize = sizeof(dbei);
for (i = DBGetContactSettingWord(NULL, SRMMMOD, SRMSGSET_LOADCOUNT, SRMSGDEFSET_LOADCOUNT); i--; )
{
if (dat->hDbEventFirst == NULL)
hPrevEvent = (HANDLE) CallService(MS_DB_EVENT_FINDLAST, (WPARAM) dat->hContact, 0);
else
hPrevEvent = (HANDLE) CallService(MS_DB_EVENT_FINDPREV, (WPARAM) dat->hDbEventFirst, 0);
if (hPrevEvent == NULL)
break;
dbei.cbBlob = 0;
dat->hDbEventFirst = hPrevEvent;
CallService(MS_DB_EVENT_GET, (WPARAM) hPrevEvent, (LPARAM) &dbei);
if (!DbEventIsShown(&dbei, dat))
i++;
}
break;
}
case LOADHISTORY_TIME:
{
HANDLE hPrevEvent;
DBEVENTINFO dbei = { 0 };
DWORD firstTime;
dbei.cbSize = sizeof(dbei);
if (dat->hDbEventFirst == NULL)
dbei.timestamp = (DWORD)time(NULL);
else
CallService(MS_DB_EVENT_GET, (WPARAM) dat->hDbEventFirst, (LPARAM) & dbei);
firstTime = dbei.timestamp - 60 * DBGetContactSettingWord(NULL, SRMMMOD, SRMSGSET_LOADTIME, SRMSGDEFSET_LOADTIME);
for (;;)
{
if (dat->hDbEventFirst == NULL)
hPrevEvent = (HANDLE) CallService(MS_DB_EVENT_FINDLAST, (WPARAM) dat->hContact, 0);
else
hPrevEvent = (HANDLE) CallService(MS_DB_EVENT_FINDPREV, (WPARAM) dat->hDbEventFirst, 0);
if (hPrevEvent == NULL)
break;
dbei.cbBlob = 0;
CallService(MS_DB_EVENT_GET, (WPARAM) hPrevEvent, (LPARAM) & dbei);
if (dbei.timestamp < firstTime)
break;
dat->hDbEventFirst = hPrevEvent;
}
break;
}
}
}
{
DBEVENTINFO dbei = { 0 };
HANDLE hdbEvent;
dbei.cbSize = sizeof(dbei);
hdbEvent = (HANDLE) CallService(MS_DB_EVENT_FINDLAST, (WPARAM) dat->hContact, 0);
if (hdbEvent)
{
do {
ZeroMemory(&dbei, sizeof(dbei));
dbei.cbSize = sizeof(dbei);
CallService(MS_DB_EVENT_GET, (WPARAM) hdbEvent, (LPARAM) & dbei);
if (( dbei.eventType == EVENTTYPE_MESSAGE || DbEventIsForMsgWindow(&dbei)) && !(dbei.flags & DBEF_SENT)) {
dat->lastMessage = dbei.timestamp;
PostMessage(hwndDlg, DM_UPDATELASTMESSAGE, 0, 0);
break;
}
}
while (hdbEvent = (HANDLE) CallService(MS_DB_EVENT_FINDPREV, (WPARAM) hdbEvent, 0));
}
}
SendMessage(hwndDlg, DM_OPTIONSAPPLIED, 1, 0);
//restore saved msg if any...
if (dat->hContact)
{
DBVARIANT dbv;
if (!DBGetContactSettingTString(dat->hContact, SRMSGMOD, DBSAVEDMSG, &dbv))
{
if (dbv.ptszVal[0])
{
SetDlgItemText(hwndDlg, IDC_MESSAGE, dbv.ptszVal);
EnableWindow(GetDlgItem(hwndDlg, IDOK), TRUE);
UpdateReadChars(hwndDlg, dat->hwndStatus);
PostMessage(GetDlgItem(hwndDlg, IDC_MESSAGE), EM_SETSEL, -1, -1);
}
DBFreeVariant(&dbv);
}
}
SendDlgItemMessage(hwndDlg, IDC_MESSAGE, EM_SETEVENTMASK, 0, ENM_CHANGE);
{
int flag = newData->noActivate ? RWPF_HIDDEN : 0;
int savePerContact = DBGetContactSettingByte(NULL, SRMMMOD, SRMSGSET_SAVEPERCONTACT, SRMSGDEFSET_SAVEPERCONTACT);
if (Utils_RestoreWindowPositionEx(hwndDlg, flag, savePerContact ? dat->hContact : NULL, SRMMMOD, "")) {
if (savePerContact) {
if (Utils_RestoreWindowPositionEx(hwndDlg, flag | RWPF_NOMOVE, NULL, SRMMMOD, ""))
SetWindowPos(hwndDlg, 0, 0, 0, 450, 300, SWP_NOZORDER | SWP_NOMOVE | SWP_SHOWWINDOW);
}
else
SetWindowPos(hwndDlg, 0, 0, 0, 450, 300, SWP_NOZORDER | SWP_NOMOVE | SWP_SHOWWINDOW);
}
if (!savePerContact && DBGetContactSettingByte(NULL, SRMMMOD, SRMSGSET_CASCADE, SRMSGDEFSET_CASCADE))
WindowList_Broadcast(g_dat->hMessageWindowList, DM_CASCADENEWWINDOW, (WPARAM) hwndDlg, (LPARAM) & dat->windowWasCascaded);
}
if (newData->noActivate)
{
SetWindowPos(hwndDlg, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_SHOWWINDOW);
SetTimer(hwndDlg, TIMERID_FLASHWND, TIMEOUT_FLASHWND, NULL);
}
else
{
SetWindowPos(hwndDlg, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
SetForegroundWindow(hwndDlg);
SetFocus(GetDlgItem(hwndDlg, IDC_MESSAGE));
}
SendMessage(hwndDlg, DM_GETAVATAR, 0, 0);
NotifyLocalWinEvent(dat->hContact, hwndDlg, MSG_WINDOW_EVT_OPEN);
return FALSE;
}
case WM_CONTEXTMENU:
if (dat->hwndStatus && dat->hwndStatus == (HWND) wParam) {
POINT pt, pt2;
HMENU hMenu;
RECT rc;
GetCursorPos(&pt);
pt2.x = pt.x; pt2.y = pt.y;
ScreenToClient(dat->hwndStatus, &pt);
// no popup menu for status icons - this is handled via NM_RCLICK notification and the plugins that added the icons
SendMessage(dat->hwndStatus, SB_GETRECT, SendMessage(dat->hwndStatus, SB_GETPARTS, 0, 0) - 1, (LPARAM)&rc);
if (pt.x >= rc.left) break;
hMenu = (HMENU) CallService(MS_CLIST_MENUBUILDCONTACT, (WPARAM) dat->hContact, 0);
TrackPopupMenu(hMenu, 0, pt2.x, pt2.y, 0, hwndDlg, NULL);
DestroyMenu(hMenu);
}
break;
// Mod from tabsrmm
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) {
TCHAR szFilename[MAX_PATH];
HDROP hDrop = (HDROP)wParam;
int fileCount = DragQueryFile(hDrop,-1,NULL,0), totalCount = 0, i;
TCHAR** ppFiles = NULL;
for ( i=0; i < fileCount; i++ ) {
DragQueryFile(hDrop, i, szFilename, SIZEOF(szFilename));
AddToFileList(&ppFiles, &totalCount, szFilename);
}
CallServiceSync(MS_FILE_SENDSPECIFICFILEST, (WPARAM)dat->hContact, (LPARAM)ppFiles);
for(i=0;ppFiles[i];i++) mir_free(ppFiles[i]);
mir_free(ppFiles);
}
break;
case HM_AVATARACK:
ShowAvatar(hwndDlg, dat);
break;
case DM_AVATARCALCSIZE:
{
BITMAP bminfo;
if (dat->avatarPic == NULL || !(g_dat->flags&SMF_AVATAR))
{
dat->avatarWidth=50;
dat->avatarHeight=50;
ShowWindow(GetDlgItem(hwndDlg, IDC_AVATAR), SW_HIDE);
return 0;
}
GetObject(dat->avatarPic, sizeof(bminfo), &bminfo);
dat->avatarWidth=bminfo.bmWidth+2;
dat->avatarHeight=bminfo.bmHeight+2;
if (dat->limitAvatarH&&dat->avatarHeight>dat->limitAvatarH) {
dat->avatarWidth = bminfo.bmWidth * dat->limitAvatarH / bminfo.bmHeight + 2;
dat->avatarHeight = dat->limitAvatarH + 2;
}
ShowWindow(GetDlgItem(hwndDlg, IDC_AVATAR), SW_SHOW);
}
break;
case DM_UPDATESIZEBAR:
dat->minEditBoxSize.cx = dat->minEditInit.right - dat->minEditInit.left;
dat->minEditBoxSize.cy = dat->minEditInit.bottom - dat->minEditInit.top;
if(g_dat->flags&SMF_AVATAR) {
SendMessage(hwndDlg, DM_AVATARCALCSIZE, 0, 0);
if(dat->avatarPic && dat->minEditBoxSize.cy <= dat->avatarHeight)
dat->minEditBoxSize.cy = dat->avatarHeight;
}
break;
case DM_AVATARSIZECHANGE:
{
RECT rc;
GetWindowRect(GetDlgItem(hwndDlg, IDC_MESSAGE), &rc);
if (rc.bottom-rc.top<dat->minEditBoxSize.cy) {
SendMessage(hwndDlg, DM_SPLITTERMOVED, rc.top-(rc.bottom-rc.top-dat->minEditBoxSize.cy-4), (LPARAM) GetDlgItem(hwndDlg, IDC_SPLITTER));
}
SendMessage(hwndDlg, WM_SIZE, 0, 0);
}
break;
case DM_GETAVATAR:
{
PROTO_AVATAR_INFORMATIONT ai = { sizeof(ai), dat->hContact };
CallProtoService(dat->szProto, PS_GETAVATARINFOT, GAIF_FORCE, (LPARAM)&ai);
ShowAvatar(hwndDlg, dat);
SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, 1);
}
break;
case DM_TYPING:
dat->nTypeSecs = (INT_PTR)lParam > 0 ? (int)lParam : 0;
break;
case DM_UPDATEWINICON:
if (DBGetContactSettingByte(NULL, SRMMMOD, SRMSGSET_STATUSICON, SRMSGDEFSET_STATUSICON)) {
WORD wStatus;
Window_FreeIcon_IcoLib(hwndDlg);
if (dat->szProto) {
wStatus = DBGetContactSettingWord(dat->hContact, dat->szProto, "Status", ID_STATUS_OFFLINE);
SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM) LoadSkinnedProtoIconBig(dat->szProto, wStatus));
SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM) LoadSkinnedProtoIcon(dat->szProto, wStatus));
break;
}
}
SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM) LoadSkinnedIconBig(SKINICON_EVENT_MESSAGE));
SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM) LoadSkinnedIcon(SKINICON_EVENT_MESSAGE));
break;
case DM_USERNAMETOCLIP:
if (dat->hContact)
{
TCHAR buf[128] = _T("");
CONTACTINFO ci = {0};
ci.cbSize = sizeof(ci);
ci.hContact = dat->hContact;
ci.szProto = dat->szProto;
ci.dwFlag = CNF_UNIQUEID | CNF_TCHAR;
if (!CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM) & ci))
{
switch (ci.type)
{
case CNFT_ASCIIZ:
mir_sntprintf(buf, SIZEOF(buf), _T("%s"), ci.pszVal);
mir_free(ci.pszVal);
break;
case CNFT_DWORD:
mir_sntprintf(buf, SIZEOF(buf), _T("%u"), ci.dVal);
break;
}
}
if (buf[0] && OpenClipboard(hwndDlg))
{
HGLOBAL hData;
EmptyClipboard();
hData = GlobalAlloc(GMEM_MOVEABLE, _tcslen(buf) * sizeof(TCHAR) + 1);
_tcscpy((TCHAR*)GlobalLock(hData), buf);
GlobalUnlock(hData);
SetClipboardData(CF_UNICODETEXT, hData);
CloseClipboard();
}
}
break;
case DM_UPDATELASTMESSAGE:
if (!dat->hwndStatus || dat->nTypeSecs)
break;
if (dat->lastMessage)
{
TCHAR date[64], time[64], fmt[128];
tmi.printTimeStamp(NULL, dat->lastMessage, _T("d"), date, SIZEOF(date), 0);
tmi.printTimeStamp(NULL, dat->lastMessage, _T("t"), time, SIZEOF(time), 0);
mir_sntprintf(fmt, SIZEOF(fmt), TranslateT("Last message received on %s at %s."), date, time);
SendMessage(dat->hwndStatus, SB_SETTEXT, 0, (LPARAM) fmt);
}
else {
SendMessage(dat->hwndStatus, SB_SETTEXT, 0, (LPARAM) _T(""));
}
SendMessage(dat->hwndStatus, SB_SETICON, 0, (LPARAM) NULL);
break;
case DM_OPTIONSAPPLIED:
SetDialogToType(hwndDlg);
if (dat->hBkgBrush)
DeleteObject(dat->hBkgBrush);
{
COLORREF colour = DBGetContactSettingDword(NULL, SRMMMOD, SRMSGSET_BKGCOLOUR, SRMSGDEFSET_BKGCOLOUR);
dat->hBkgBrush = CreateSolidBrush(colour);
SendDlgItemMessage(hwndDlg, IDC_LOG, EM_SETBKGNDCOLOR, 0, colour);
SendDlgItemMessage(hwndDlg, IDC_MESSAGE, EM_SETBKGNDCOLOR, 0, colour);
}
{ // avatar stuff
dat->avatarPic = NULL;
dat->limitAvatarH = 0;
if (CallProtoService(dat->szProto, PS_GETCAPS, PFLAGNUM_4, 0) & PF4_AVATARS)
{
dat->limitAvatarH = DBGetContactSettingByte(NULL, SRMMMOD, SRMSGSET_LIMITAVHEIGHT, SRMSGDEFSET_LIMITAVHEIGHT) ?
DBGetContactSettingDword(NULL, SRMMMOD, SRMSGSET_AVHEIGHT, SRMSGDEFSET_AVHEIGHT) : 0;
}
if (!wParam) SendMessage(hwndDlg, DM_GETAVATAR, 0, 0);
}
InvalidateRect(GetDlgItem(hwndDlg, IDC_MESSAGE), NULL, FALSE);
{
HFONT hFont;
LOGFONT lf;
CHARFORMAT cf = {0};
hFont = (HFONT) SendDlgItemMessage(hwndDlg, IDC_MESSAGE, WM_GETFONT, 0, 0);
if (hFont != NULL && hFont != (HFONT) SendDlgItemMessage(hwndDlg, IDOK, WM_GETFONT, 0, 0))
DeleteObject(hFont);
LoadMsgDlgFont(MSGFONTID_MESSAGEAREA, &lf, &cf.crTextColor);
hFont = CreateFontIndirect(&lf);
SendDlgItemMessage(hwndDlg, IDC_MESSAGE, WM_SETFONT, (WPARAM) hFont, MAKELPARAM(TRUE, 0));
cf.cbSize = sizeof(CHARFORMAT);
cf.dwMask = CFM_COLOR;
SendDlgItemMessage(hwndDlg, IDC_MESSAGE, EM_SETCHARFORMAT, SCF_ALL, (WPARAM) &cf);
}
/*
* configure message history for proper RTL formatting
*/
{
PARAFORMAT2 pf2;
ZeroMemory((void *)&pf2, sizeof(pf2));
pf2.cbSize = sizeof(pf2);
pf2.wEffects = PFE_RTLPARA;
pf2.dwMask = PFM_RTLPARA;
SetDlgItemText(hwndDlg, IDC_LOG, _T(""));
SendDlgItemMessage(hwndDlg, IDC_LOG, EM_SETPARAFORMAT, 0, (LPARAM)&pf2);
pf2.wEffects = 0;
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);
}
SendMessage(hwndDlg, DM_REMAKELOG, 0, 0);
SendMessage(hwndDlg, DM_UPDATEWINICON, 0, 0);
break;
case DM_UPDATETITLE:
{
TCHAR newtitle[256], oldtitle[256], *szStatus;
TCHAR *contactName, *pszNewTitleEnd;
DBCONTACTWRITESETTING *cws = (DBCONTACTWRITESETTING *) wParam;
pszNewTitleEnd = _T("Message Session");
if (dat->hContact)
{
if (dat->szProto)
{
TCHAR buf[128] = _T("");
int statusIcon = DBGetContactSettingByte(NULL, SRMMMOD, SRMSGSET_STATUSICON, SRMSGDEFSET_STATUSICON);
dat->wStatus = DBGetContactSettingWord(dat->hContact, dat->szProto, "Status", ID_STATUS_OFFLINE);
contactName = ( TCHAR* )CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM) dat->hContact, GCDNF_TCHAR);
if (strcmp(dat->szProto, "MetaContacts"))
{
CONTACTINFO ci = {0};
ci.cbSize = sizeof(ci);
ci.hContact = dat->hContact;
ci.szProto = dat->szProto;
ci.dwFlag = CNF_DISPLAYUID | CNF_TCHAR;
if (!CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM) & ci)) {
switch (ci.type) {
case CNFT_ASCIIZ:
mir_sntprintf(buf, SIZEOF(buf), _T("%s"), (TCHAR*)ci.pszVal);
mir_free(ci.pszVal);
break;
case CNFT_DWORD:
mir_sntprintf(buf, SIZEOF(buf), _T("%u"), ci.dVal);
break;
}
}
}
if (buf[0])
SetDlgItemText(hwndDlg, IDC_NAME, buf);
else
SetDlgItemText(hwndDlg, IDC_NAME, contactName);
szStatus = (TCHAR*)CallService(MS_CLIST_GETSTATUSMODEDESCRIPTION, dat->szProto == NULL ? ID_STATUS_OFFLINE : DBGetContactSettingWord(dat->hContact, dat->szProto, "Status", ID_STATUS_OFFLINE), GSMDF_TCHAR);
if (statusIcon)
mir_sntprintf(newtitle, SIZEOF(newtitle), _T("%s - %s"), contactName, TranslateTS(pszNewTitleEnd));
else
mir_sntprintf(newtitle, SIZEOF(newtitle), _T("%s (%s): %s"), contactName, szStatus, TranslateTS(pszNewTitleEnd));
if (!cws || (!strcmp(cws->szModule, dat->szProto) && !strcmp(cws->szSetting, "Status")))
{
InvalidateRect(GetDlgItem(hwndDlg, IDC_PROTOCOL), NULL, TRUE);
if (statusIcon)
SendMessage(hwndDlg, DM_UPDATEWINICON, 0, 0);
}
// log
if ((dat->wStatus != dat->wOldStatus || lParam != 0) &&
DBGetContactSettingByte(NULL, SRMMMOD, SRMSGSET_SHOWSTATUSCH, SRMSGDEFSET_SHOWSTATUSCH))
{
DBEVENTINFO dbei;
TCHAR buffer[200];
HANDLE hNewEvent;
int iLen;
TCHAR *szOldStatus = (TCHAR*)CallService(MS_CLIST_GETSTATUSMODEDESCRIPTION, (WPARAM) dat->wOldStatus, GSMDF_TCHAR);
TCHAR *szNewStatus = (TCHAR*)CallService(MS_CLIST_GETSTATUSMODEDESCRIPTION, (WPARAM) dat->wStatus, GSMDF_TCHAR);
if (dat->wStatus == ID_STATUS_OFFLINE)
{
iLen = mir_sntprintf(buffer, SIZEOF(buffer), TranslateT("signed off (was %s)"), szOldStatus);
SendMessage(hwndDlg, DM_TYPING, 0, 0);
}
else if (dat->wOldStatus == ID_STATUS_OFFLINE)
iLen = mir_sntprintf(buffer, SIZEOF(buffer), TranslateT("signed on (%s)"), szNewStatus);
else
iLen = mir_sntprintf(buffer, SIZEOF(buffer), TranslateT("is now %s (was %s)"), szNewStatus, szOldStatus);
{
char* blob = ( char* )alloca(1000);
int ansiLen = WideCharToMultiByte(CP_ACP, 0, buffer, -1, blob, 1000, 0, 0);
memcpy( blob+ansiLen, buffer, sizeof(TCHAR)*(iLen+1));
dbei.cbBlob = ansiLen + sizeof(TCHAR)*(iLen+1);
dbei.cbSize = sizeof(dbei);
dbei.pBlob = (PBYTE) blob;
dbei.eventType = EVENTTYPE_STATUSCHANGE;
dbei.flags = 0;
dbei.timestamp = (DWORD)time(NULL);
dbei.szModule = dat->szProto;
hNewEvent = (HANDLE) CallService(MS_DB_EVENT_ADD, (WPARAM) dat->hContact, (LPARAM) & dbei);
if (dat->hDbEventFirst == NULL)
{
dat->hDbEventFirst = hNewEvent;
SendMessage(hwndDlg, DM_REMAKELOG, 0, 0);
}
}
}
dat->wOldStatus = dat->wStatus;
}
}
else lstrcpyn(newtitle, pszNewTitleEnd, SIZEOF(newtitle));
GetWindowText(hwndDlg, oldtitle, SIZEOF(oldtitle));
if ( _tcscmp(newtitle, oldtitle )) { //swt() flickers even if the title hasn't actually changed
SetWindowText(hwndDlg, newtitle);
SendMessage(hwndDlg, WM_SIZE, 0, 0);
}
break;
}
case DM_NEWTIMEZONE:
dat->hTimeZone = tmi.createByContact(dat->hContact, TZF_KNOWNONLY);
dat->wMinute = 61;
SendMessage(hwndDlg, WM_SIZE, 0, 0);
break;
case DM_GETWINDOWSTATE:
{
UINT state = 0;
state |= MSG_WINDOW_STATE_EXISTS;
if (IsWindowVisible(hwndDlg))
state |= MSG_WINDOW_STATE_VISIBLE;
if (GetForegroundWindow() == hwndDlg)
state |= MSG_WINDOW_STATE_FOCUS;
if (IsIconic(hwndDlg))
state |= MSG_WINDOW_STATE_ICONIC;
SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, state);
return TRUE;
}
case DM_CASCADENEWWINDOW:
if ((HWND) wParam == hwndDlg)
break;
{
RECT rcThis, rcNew;
GetWindowRect(hwndDlg, &rcThis);
GetWindowRect((HWND) wParam, &rcNew);
if (abs(rcThis.left - rcNew.left) < 3 && abs(rcThis.top - rcNew.top) < 3) {
int offset = GetSystemMetrics(SM_CYCAPTION) + GetSystemMetrics(SM_CYFRAME);
SetWindowPos((HWND) wParam, 0, rcNew.left + offset, rcNew.top + offset, 0, 0, SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOSIZE);
*(int *) lParam = 1;
}
}
break;
case WM_ACTIVATE:
if (LOWORD(wParam) != WA_ACTIVE)
break;
SetFocus(GetDlgItem(hwndDlg, IDC_MESSAGE));
//fall through
case WM_MOUSEACTIVATE:
if (KillTimer(hwndDlg, TIMERID_FLASHWND))
FlashWindow(hwndDlg, FALSE);
break;
case WM_GETMINMAXINFO:
{
MINMAXINFO* mmi = (MINMAXINFO *) lParam;
RECT rcWindow, rcLog;
GetWindowRect(hwndDlg, &rcWindow);
GetWindowRect(GetDlgItem(hwndDlg, IDC_LOG), &rcLog);
mmi->ptMinTrackSize.x = rcWindow.right - rcWindow.left - ((rcLog.right - rcLog.left) - dat->minEditBoxSize.cx);
mmi->ptMinTrackSize.y = rcWindow.bottom - rcWindow.top - ((rcLog.bottom - rcLog.top) - dat->minEditBoxSize.cy);
return 0;
}
case WM_SIZE:
{
UTILRESIZEDIALOG urd = {0};
BOOL bottomScroll = TRUE;
if (IsIconic(hwndDlg))
break;
if (dat->hwndStatus)
{
SendMessage(dat->hwndStatus, WM_SIZE, 0, 0);
SetupStatusBar(hwndDlg, dat);
}
if (GetWindowLongPtr(GetDlgItem(hwndDlg, IDC_LOG), GWL_STYLE) & WS_VSCROLL)
{
SCROLLINFO si = {0};
si.cbSize = sizeof(si);
si.fMask = SIF_PAGE | SIF_RANGE | SIF_POS;
GetScrollInfo(GetDlgItem(hwndDlg, IDC_LOG), SB_VERT, &si);
bottomScroll = (si.nPos + (int)si.nPage + 5) >= si.nMax;
}
urd.cbSize = sizeof(urd);
urd.hInstance = g_hInst;
urd.hwndDlg = hwndDlg;
urd.lParam = (LPARAM) dat;
urd.lpTemplate = MAKEINTRESOURCEA(IDD_MSG);
urd.pfnResizer = MessageDialogResize;
CallService(MS_UTILS_RESIZEDIALOG, 0, (LPARAM) & urd);
// The statusbar sometimes draws over these 2 controls so
// redraw them
if (dat->hwndStatus)
{
RedrawWindow(GetDlgItem(hwndDlg, IDOK), NULL, NULL, RDW_INVALIDATE);
RedrawWindow(GetDlgItem(hwndDlg, IDC_MESSAGE), NULL, NULL, RDW_INVALIDATE);
}
if ((g_dat->flags & SMF_AVATAR) && dat->avatarPic)
RedrawWindow(GetDlgItem(hwndDlg, IDC_AVATAR), NULL, NULL, RDW_INVALIDATE);
if (bottomScroll)
PostMessage(hwndDlg, DM_SCROLLLOGTOBOTTOM, 0, 0);
break;
}
case DM_SPLITTERMOVED:
{
if ((HWND) lParam == GetDlgItem(hwndDlg, IDC_SPLITTER))
{
POINT pt;
RECT rc;
RECT rcLog;
int oldSplitterY;
HWND hwndLog = GetDlgItem(hwndDlg, IDC_LOG);
GetClientRect(hwndDlg, &rc);
GetWindowRect(hwndLog, &rcLog);
pt.x = 0;
pt.y = wParam;
ScreenToClient(hwndDlg, &pt);
oldSplitterY = dat->splitterPos;
dat->splitterPos = rc.bottom - pt.y + 23;
GetWindowRect(GetDlgItem(hwndDlg, IDC_MESSAGE), &rc);
if (rc.bottom - rc.top + (dat->splitterPos - oldSplitterY) < dat->minEditBoxSize.cy)
dat->splitterPos = oldSplitterY + dat->minEditBoxSize.cy - (rc.bottom - rc.top);
if (rcLog.bottom - rcLog.top - (dat->splitterPos - oldSplitterY) < dat->minEditBoxSize.cy)
dat->splitterPos = oldSplitterY - dat->minEditBoxSize.cy + (rcLog.bottom - rcLog.top);
SendMessage(hwndDlg, WM_SIZE, 0, 0);
}
}
break;
case DM_REMAKELOG:
StreamInEvents(hwndDlg, dat->hDbEventFirst, -1, 0);
break;
case DM_APPENDTOLOG: //takes wParam=hDbEvent
StreamInEvents(hwndDlg, (HANDLE) wParam, 1, 1);
break;
case DM_SCROLLLOGTOBOTTOM:
{
HWND hwndLog = GetDlgItem(hwndDlg, IDC_LOG);
if (GetWindowLongPtr(hwndLog, GWL_STYLE) & WS_VSCROLL)
{
SCROLLINFO si = {0};
si.cbSize = sizeof(si);
si.fMask = SIF_PAGE | SIF_RANGE;
GetScrollInfo(hwndLog, SB_VERT, &si);
si.fMask = SIF_POS;
si.nPos = si.nMax - si.nPage;
SetScrollInfo(hwndLog, SB_VERT, &si, TRUE);
SendMessage(hwndLog, WM_VSCROLL, MAKEWPARAM(SB_BOTTOM, 0), 0);
}
}
break;
case HM_DBEVENTADDED:
if ((HANDLE) wParam != dat->hContact)
break;
{
DBEVENTINFO dbei = { 0 };
dbei.cbSize = sizeof(dbei);
CallService(MS_DB_EVENT_GET, lParam, (LPARAM) & dbei);
if (dat->hDbEventFirst == NULL)
dat->hDbEventFirst = (HANDLE) lParam;
if (DbEventIsShown(&dbei, dat) && !(dbei.flags & DBEF_READ))
{
if ((dbei.eventType == EVENTTYPE_MESSAGE || DbEventIsForMsgWindow(&dbei)) && !(dbei.flags & DBEF_SENT))
{
if (GetForegroundWindow() == hwndDlg)
SkinPlaySound("RecvMsgActive");
else
SkinPlaySound("RecvMsgInactive");
}
if (( dbei.eventType == EVENTTYPE_MESSAGE || DbEventIsForMsgWindow(&dbei)) && dat->hwndStatus && !(dbei.flags & DBEF_SENT))
{
dat->lastMessage = dbei.timestamp;
SendMessage(hwndDlg, DM_UPDATELASTMESSAGE, 0, 0);
}
if ((HANDLE) lParam != dat->hDbEventFirst && (HANDLE) CallService(MS_DB_EVENT_FINDNEXT, lParam, 0) == NULL)
SendMessage(hwndDlg, DM_APPENDTOLOG, lParam, 0);
else
SendMessage(hwndDlg, DM_REMAKELOG, 0, 0);
if (!(dbei.flags & DBEF_SENT) && dbei.eventType != EVENTTYPE_STATUSCHANGE)
{
if (GetActiveWindow() == hwndDlg && GetForegroundWindow() == hwndDlg)
{
HWND hwndLog = GetDlgItem(hwndDlg, IDC_LOG);
if (GetWindowLongPtr(hwndLog, GWL_STYLE) & WS_VSCROLL)
{
SCROLLINFO si = {0};
si.cbSize = sizeof(si);
si.fMask = SIF_PAGE | SIF_RANGE | SIF_POS;
GetScrollInfo(hwndLog, SB_VERT, &si);
if ((si.nPos + (int)si.nPage + 5) < si.nMax)
SetTimer(hwndDlg, TIMERID_FLASHWND, TIMEOUT_FLASHWND, NULL);
}
}
else
SetTimer(hwndDlg, TIMERID_FLASHWND, TIMEOUT_FLASHWND, NULL);
}
}
}
break;
case WM_TIMECHANGE:
PostMessage(hwndDlg, DM_NEWTIMEZONE, 0, 0);
PostMessage(hwndDlg, DM_REMAKELOG, 0, 0);
break;
case WM_TIMER:
if (wParam == TIMERID_FLASHWND)
{
FlashWindow(hwndDlg, TRUE);
if (dat->nFlash > 2 * g_dat->nFlashMax)
{
KillTimer(hwndDlg, TIMERID_FLASHWND);
FlashWindow(hwndDlg, FALSE);
dat->nFlash = 0;
}
dat->nFlash++;
}
else if (wParam == TIMERID_TYPE)
{
ShowTime(dat);
if (dat->nTypeMode == PROTOTYPE_SELFTYPING_ON && GetTickCount() - dat->nLastTyping > TIMEOUT_TYPEOFF)
NotifyTyping(dat, PROTOTYPE_SELFTYPING_OFF);
if (dat->showTyping)
{
if (dat->nTypeSecs)
{
dat->nTypeSecs--;
if (GetForegroundWindow() == hwndDlg)
SendMessage(hwndDlg, DM_UPDATEWINICON, 0, 0);
}
else
{
SendMessage(hwndDlg, DM_UPDATELASTMESSAGE, 0, 0);
if (g_dat->flags & SMF_SHOWTYPINGWIN)
SendMessage(hwndDlg, DM_UPDATEWINICON, 0, 0);
dat->showTyping = 0;
}
}
else
{
if (dat->nTypeSecs)
{
TCHAR szBuf[256];
TCHAR* szContactName = (TCHAR*) CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM) dat->hContact, GCDNF_TCHAR);
HICON hTyping = LoadSkinnedIcon(SKINICON_OTHER_TYPING);
mir_sntprintf(szBuf, SIZEOF(szBuf), TranslateT("%s is typing a message..."), szContactName);
dat->nTypeSecs--;
SendMessage(dat->hwndStatus, SB_SETTEXT, 0, (LPARAM) szBuf);
SendMessage(dat->hwndStatus, SB_SETICON, 0, (LPARAM) hTyping);
if ((g_dat->flags & SMF_SHOWTYPINGWIN) && GetForegroundWindow() != hwndDlg)
{
HICON hIcon = (HICON)SendMessage(hwndDlg, WM_GETICON, ICON_SMALL, 0);
SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM)hTyping );
CallService(MS_SKIN2_RELEASEICON, (WPARAM)hIcon, 0);
}
dat->showTyping = 1;
}
}
}
break;
case WM_MEASUREITEM:
{
LPMEASUREITEMSTRUCT mis = (LPMEASUREITEMSTRUCT) lParam;
if (mis->CtlType == ODT_MENU)
return CallService(MS_CLIST_MENUMEASUREITEM, wParam, lParam);
}
break;
case WM_DRAWITEM:
{
LPDRAWITEMSTRUCT dis = (LPDRAWITEMSTRUCT) lParam;
if (dis->CtlType == ODT_MENU)
return CallService(MS_CLIST_MENUDRAWITEM, wParam, lParam);
else if (dis->hwndItem == dat->hwndStatus)
{
DrawStatusIcons(dat->hContact, dis->hDC, dis->rcItem, 2);
return TRUE;
}
else if (dis->CtlID == IDC_PROTOCOL)
{
if (dat->szProto)
{
HICON hIcon;
int dwStatus;
dwStatus = DBGetContactSettingWord(dat->hContact, dat->szProto, "Status", ID_STATUS_OFFLINE);
hIcon = LoadSkinnedProtoIcon(dat->szProto, dwStatus);
if (hIcon)
{
if (DBGetContactSettingDword(dat->hContact, dat->szProto, "IdleTS", 0))
{
HIMAGELIST hImageList;
hImageList = ImageList_Create(GetSystemMetrics(SM_CXSMICON),GetSystemMetrics(SM_CYSMICON), IsWinVerXPPlus()? ILC_COLOR32 | ILC_MASK : ILC_COLOR16 | ILC_MASK, 1, 0);
ImageList_AddIcon(hImageList, hIcon);
ImageList_DrawEx(hImageList, 0, dis->hDC, dis->rcItem.left, dis->rcItem.top, 0, 0, CLR_NONE, CLR_NONE, ILD_SELECTED);
ImageList_Destroy(hImageList);
}
else
DrawIconEx(dis->hDC, dis->rcItem.left, dis->rcItem.top, hIcon, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), 0, NULL, DI_NORMAL);
CallService(MS_SKIN2_RELEASEICON,(WPARAM)hIcon, 0);
return TRUE;
}
}
}
else if (dis->CtlID == IDC_AVATAR && dat->avatarPic && (g_dat->flags & SMF_AVATAR))
{
HPEN hPen = CreatePen(PS_SOLID, 1, RGB(0,0,0));
HPEN hOldPen = (HPEN)SelectObject(dis->hDC, hPen);
Rectangle(dis->hDC, 0, 0, dat->avatarWidth, dat->avatarHeight);
SelectObject(dis->hDC,hOldPen);
DeleteObject(hPen);
BITMAP bminfo;
GetObject(dat->avatarPic, sizeof(bminfo), &bminfo);
{
HDC hdcMem = CreateCompatibleDC(dis->hDC);
HBITMAP hbmMem = (HBITMAP)SelectObject(hdcMem, dat->avatarPic);
{
SetStretchBltMode(dis->hDC, HALFTONE);
StretchBlt(dis->hDC, 1, 1, dat->avatarWidth-2, dat->avatarHeight-2, hdcMem, 0, 0,
bminfo.bmWidth, bminfo.bmHeight, SRCCOPY);
}
SelectObject(hdcMem,hbmMem);
DeleteDC(hdcMem);
}
return TRUE;
}
}
break;
case WM_COMMAND:
if (!lParam && CallService(MS_CLIST_MENUPROCESSCOMMAND, MAKEWPARAM(LOWORD(wParam), MPCF_CONTACTMENU), (LPARAM) dat->hContact))
break;
switch (LOWORD(wParam))
{
case IDOK:
if (!IsWindowEnabled(GetDlgItem(hwndDlg, IDOK)))
break;
{
HANDLE hNewEvent;
int bufSize = GetWindowTextLength(GetDlgItem(hwndDlg, IDC_MESSAGE)) + 1;
TCHAR* temp = (TCHAR*)alloca(bufSize * sizeof(TCHAR));
GetDlgItemText(hwndDlg, IDC_MESSAGE, temp, bufSize);
if (!temp[0]) break;
hNewEvent = SendMessageDirect(temp, dat->hContact, dat->szProto);
if (hNewEvent)
{
tcmdlist_append(dat->cmdList, temp);
dat->cmdListInd = -1;
if (dat->nTypeMode == PROTOTYPE_SELFTYPING_ON)
NotifyTyping(dat, PROTOTYPE_SELFTYPING_OFF);
EnableWindow(GetDlgItem(hwndDlg, IDOK), FALSE);
SetFocus(GetDlgItem(hwndDlg, IDC_MESSAGE));
if (dat->hDbEventFirst == NULL)
{
dat->hDbEventFirst = hNewEvent;
SendMessage(hwndDlg, DM_REMAKELOG, 0, 0);
}
SetDlgItemText(hwndDlg, IDC_MESSAGE, _T(""));
if (g_dat->flags & SMF_AUTOCLOSE)
DestroyWindow(hwndDlg);
else if (g_dat->flags & SMF_AUTOMIN)
ShowWindow(hwndDlg, SW_MINIMIZE);
}
}
return TRUE;
case IDCANCEL:
DestroyWindow(hwndDlg);
return TRUE;
case IDC_USERMENU:
case IDC_NAME:
if (GetKeyState(VK_SHIFT) & 0x8000) // copy user name
SendMessage(hwndDlg, DM_USERNAMETOCLIP, 0, 0);
else {
RECT rc;
HMENU hMenu = (HMENU) CallService(MS_CLIST_MENUBUILDCONTACT, (WPARAM) dat->hContact, 0);
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, (WPARAM) dat->hContact, 0);
break;
case IDC_DETAILS:
CallService(MS_USERINFO_SHOWDIALOG, (WPARAM) dat->hContact, 0);
break;
case IDC_ADD:
{
ADDCONTACTSTRUCT acs = { 0 };
acs.handle = dat->hContact;
acs.handleType = HANDLE_CONTACT;
acs.szProto = 0;
CallService(MS_ADDCONTACT_SHOW, (WPARAM) hwndDlg, (LPARAM) & acs);
}
if (!DBGetContactSettingByte(dat->hContact, "CList", "NotOnList", 0))
ShowWindow(GetDlgItem(hwndDlg, IDC_ADD), FALSE);
break;
case IDC_MESSAGE:
if (HIWORD(wParam) == EN_CHANGE)
{
int len = GetWindowTextLength(GetDlgItem(hwndDlg, IDC_MESSAGE));
UpdateReadChars(hwndDlg, dat->hwndStatus);
EnableWindow(GetDlgItem(hwndDlg, IDOK), len != 0);
if (!(GetKeyState(VK_CONTROL) & 0x8000) && !(GetKeyState(VK_SHIFT) & 0x8000))
{
dat->nLastTyping = GetTickCount();
if (len)
{
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:
if (dat && ((LPNMHDR) lParam)->hwndFrom == dat->hwndStatus)
{
if (((LPNMHDR) lParam)->code == NM_CLICK || ((LPNMHDR) lParam)->code == NM_RCLICK)
{
NMMOUSE *nm = (NMMOUSE *) lParam;
RECT rc;
SendMessage(dat->hwndStatus, SB_GETRECT, SendMessage(dat->hwndStatus, SB_GETPARTS, 0, 0) - 1, (LPARAM)&rc);
if (nm->pt.x >= rc.left)
CheckIconClick(dat->hContact, dat->hwndStatus, nm->pt, rc, 2, ((LPNMHDR) lParam)->code == NM_RCLICK ? MBCF_RIGHTBUTTON : 0);
return TRUE;
}
}
switch (((LPNMHDR) lParam)->idFrom)
{
case IDC_LOG:
switch (((LPNMHDR) lParam)->code)
{
case EN_MSGFILTER:
switch (((MSGFILTER *) lParam)->msg)
{
case WM_LBUTTONDOWN:
{
HCURSOR 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:
{
HCURSOR 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:
{
HMENU hMenu, hSubMenu;
POINT pt;
CHARRANGE sel, all = { 0, -1 };
hMenu = LoadMenu(g_hInst, MAKEINTRESOURCE(IDR_CONTEXT));
hSubMenu = GetSubMenu(hMenu, 0);
TranslateMenu(hSubMenu);
SendMessage(((NMHDR *) lParam)->hwndFrom, EM_EXGETSEL, 0, (LPARAM) & sel);
if (sel.cpMin == sel.cpMax)
EnableMenuItem(hSubMenu, IDM_COPY, MF_BYCOMMAND | MF_GRAYED);
pt.x = (short) LOWORD(((ENLINK *) lParam)->lParam);
pt.y = (short) HIWORD(((ENLINK *) lParam)->lParam);
ClientToScreen(((NMHDR *) lParam)->hwndFrom, &pt);
switch (TrackPopupMenu(hSubMenu, TPM_RETURNCMD, pt.x, pt.y, 0, hwndDlg, NULL))
{
case IDM_COPY:
SendMessage(((NMHDR *) lParam)->hwndFrom, WM_COPY, 0, 0);
break;
case IDM_COPYALL:
SendMessage(((NMHDR *) lParam)->hwndFrom, EM_EXSETSEL, 0, (LPARAM) & all);
SendMessage(((NMHDR *) lParam)->hwndFrom, WM_COPY, 0, 0);
SendMessage(((NMHDR *) lParam)->hwndFrom, EM_EXSETSEL, 0, (LPARAM) & sel);
break;
case IDM_SELECTALL:
SendMessage(((NMHDR *) lParam)->hwndFrom, EM_EXSETSEL, 0, (LPARAM) & all);
break;
case IDM_CLEAR:
SetDlgItemText(hwndDlg, IDC_LOG, _T(""));
dat->hDbEventFirst = NULL;
break;
}
DestroyMenu(hSubMenu);
DestroyMenu(hMenu);
SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, TRUE);
return TRUE;
}
}
break;
case EN_VSCROLL:
if (LOWORD(wParam) == IDC_LOG && GetWindowLongPtr((HWND)lParam, GWL_STYLE) & WS_VSCROLL)
{
SCROLLINFO si = {0};
si.cbSize = sizeof(si);
si.fMask = SIF_PAGE | SIF_RANGE | SIF_POS;
GetScrollInfo((HWND)lParam, SB_VERT, &si);
if ((si.nPos + (int)si.nPage + 5) >= si.nMax)
if (KillTimer(hwndDlg, TIMERID_FLASHWND))
FlashWindow(hwndDlg, FALSE);
}
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:
{
TEXTRANGE tr;
CHARRANGE sel;
SendDlgItemMessage(hwndDlg, IDC_LOG, EM_EXGETSEL, 0, (LPARAM) & sel);
if (sel.cpMin != sel.cpMax)
break;
tr.chrg = ((ENLINK *) lParam)->chrg;
tr.lpstrText = (TCHAR*)_alloca((tr.chrg.cpMax - tr.chrg.cpMin + 8) * sizeof(TCHAR));
SendDlgItemMessage(hwndDlg, IDC_LOG, EM_GETTEXTRANGE, 0, (LPARAM) & tr);
if (_tcschr(tr.lpstrText, '@') != NULL && _tcschr(tr.lpstrText, ':') == NULL && _tcschr(tr.lpstrText, '/') == NULL)
{
memmove(tr.lpstrText + 7, tr.lpstrText, (tr.chrg.cpMax - tr.chrg.cpMin + 1) * sizeof(TCHAR));
memcpy(tr.lpstrText, _T("mailto:"), 7 * sizeof(TCHAR));
}
if (((ENLINK *) lParam)->msg == WM_RBUTTONDOWN)
{
HMENU hMenu, hSubMenu;
POINT pt;
hMenu = LoadMenu(g_hInst, MAKEINTRESOURCE(IDR_CONTEXT));
hSubMenu = GetSubMenu(hMenu, 1);
TranslateMenu(hSubMenu);
pt.x = (short) LOWORD(((ENLINK *) lParam)->lParam);
pt.y = (short) HIWORD(((ENLINK *) lParam)->lParam);
ClientToScreen(((NMHDR *) lParam)->hwndFrom, &pt);
switch (TrackPopupMenu(hSubMenu, TPM_RETURNCMD, pt.x, pt.y, 0, hwndDlg, NULL))
{
case IDM_OPENLINK:
ShellExecute(NULL, _T("open"), tr.lpstrText, NULL, NULL, SW_SHOW);
break;
case IDM_COPYLINK:
if (OpenClipboard(hwndDlg))
{
HGLOBAL hData;
EmptyClipboard();
hData = GlobalAlloc(GMEM_MOVEABLE, (_tcslen(tr.lpstrText) + 1) * sizeof(TCHAR));
_tcscpy((TCHAR*)GlobalLock(hData), tr.lpstrText);
GlobalUnlock(hData);
SetClipboardData(CF_UNICODETEXT, hData);
CloseClipboard();
}
break;
}
DestroyMenu(hMenu);
SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, TRUE);
return TRUE;
}
else
{
ShellExecute(NULL, _T("open"), tr.lpstrText, NULL, NULL, SW_SHOW);
SetFocus(GetDlgItem(hwndDlg, IDC_MESSAGE));
}
break;
}
}
}
}
break;
case DM_STATUSICONCHANGE:
SendMessage(dat->hwndStatus, SB_SETTEXT, (WPARAM)(SBT_OWNERDRAW | (SendMessage(dat->hwndStatus, SB_GETPARTS, 0, 0) - 1)), (LPARAM)0);
break;
case WM_CLOSE:
DestroyWindow(hwndDlg);
break;
case WM_DESTROY:
if (!dat) return 0;
NotifyLocalWinEvent(dat->hContact, hwndDlg, MSG_WINDOW_EVT_CLOSING);
//save string from the editor
if(dat->hContact)
{
TCHAR* msg;
int len = GetWindowTextLength(GetDlgItem(hwndDlg, IDC_MESSAGE)) + 1;
msg = (TCHAR*)alloca(sizeof(TCHAR) * len);
GetDlgItemText(hwndDlg, IDC_MESSAGE, msg, len);
if (msg[0])
DBWriteContactSettingTString(dat->hContact, SRMSGMOD, DBSAVEDMSG, msg);
else
DBDeleteContactSetting(dat->hContact, SRMSGMOD, DBSAVEDMSG);
}
KillTimer(hwndDlg, TIMERID_TYPE);
if (dat->nTypeMode == PROTOTYPE_SELFTYPING_ON)
NotifyTyping(dat, PROTOTYPE_SELFTYPING_OFF);
if (dat->hBkgBrush)
DeleteObject(dat->hBkgBrush);
if (dat->hwndStatus)
DestroyWindow(dat->hwndStatus);
tcmdlist_free(dat->cmdList);
WindowList_Remove(g_dat->hMessageWindowList, hwndDlg);
DBWriteContactSettingDword(DBGetContactSettingByte(NULL, SRMMMOD, SRMSGSET_SAVEPERCONTACT, SRMSGDEFSET_SAVEPERCONTACT)?dat->hContact:NULL, SRMMMOD, "splitterPos", dat->splitterPos);
SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_SPLITTER), GWLP_WNDPROC, (LONG_PTR) dat->OldSplitterProc);
SendDlgItemMessage(hwndDlg, IDC_MESSAGE, EM_UNSUBCLASSED, 0, 0);
SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_MESSAGE), GWLP_WNDPROC, (LONG_PTR) dat->OldMessageEditProc);
{
HFONT 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);
}
{
WINDOWPLACEMENT wp = { 0 };
HANDLE hContact;
if (DBGetContactSettingByte(NULL, SRMMMOD, SRMSGSET_SAVEPERCONTACT, SRMSGDEFSET_SAVEPERCONTACT))
hContact = dat->hContact;
else
hContact = NULL;
wp.length = sizeof(wp);
GetWindowPlacement(hwndDlg, &wp);
if (!dat->windowWasCascaded)
{
DBWriteContactSettingDword(hContact, SRMMMOD, "x", wp.rcNormalPosition.left);
DBWriteContactSettingDword(hContact, SRMMMOD, "y", wp.rcNormalPosition.top);
}
DBWriteContactSettingDword(hContact, SRMMMOD, "width", wp.rcNormalPosition.right - wp.rcNormalPosition.left);
DBWriteContactSettingDword(hContact, SRMMMOD, "height", wp.rcNormalPosition.bottom - wp.rcNormalPosition.top);
}
NotifyLocalWinEvent(dat->hContact, hwndDlg, MSG_WINDOW_EVT_CLOSE);
if (dat->hContact&&DBGetContactSettingByte(NULL, SRMMMOD, SRMSGSET_DELTEMP, SRMSGDEFSET_DELTEMP))
if (DBGetContactSettingByte(dat->hContact, "CList", "NotOnList", 0))
CallService(MS_DB_CONTACT_DELETE, (WPARAM)dat->hContact, 0);
Button_FreeIcon_IcoLib(hwndDlg, IDC_ADD);
Button_FreeIcon_IcoLib(hwndDlg, IDC_DETAILS);
Button_FreeIcon_IcoLib(hwndDlg, IDC_HISTORY);
Button_FreeIcon_IcoLib(hwndDlg, IDC_USERMENU);
Window_FreeIcon_IcoLib(hwndDlg);
mir_free(dat);
SetWindowLongPtr(hwndDlg, GWLP_USERDATA, 0);
break;
}
return FALSE;
}
|