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
|
/*
UserinfoEx plugin for Miranda IM
Copyright:
© 2006-2010 DeathAxe, Yasnovidyashii, Merlin, K. Romanov, Kreol
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.
===============================================================================
File name : $HeadURL: https://userinfoex.googlecode.com/svn/trunk/dlg_propsheet.cpp $
Revision : $Revision: 210 $
Last change on : $Date: 2010-10-02 22:27:36 +0400 (Сб, 02 окт 2010) $
Last change by : $Author: ing.u.horn $
===============================================================================
*/
/**
* System & local includes:
**/
#include "commonheaders.h"
#include "dlg_propsheet.h"
#include "psp_base.h"
#include "svc_ExImport.h"
#include "svc_reminder.h"
#define OPTIONPAGE_OLD_SIZE (offsetof(OPTIONSDIALOGPAGE, hLangpack))
#define UPDATEANIMFRAMES 20
// internal dialog message handler
#define M_CHECKONLINE (WM_USER+10)
#define HM_PROTOACK (WM_USER+11)
#define HM_SETTING_CHANGED (WM_USER+12)
#define HM_RELOADICONS (WM_USER+13)
#define HM_SETWINDOWTITLE (WM_USER+14)
#define TIMERID_UPDATING 1
#ifndef TIMERID_RENAME
#define TIMERID_RENAME 2
#endif
// flags for the PS structure
#define PSF_CHANGED 0x00000100
#define PSF_LOCKED 0x00000200
#define PSF_INITIALIZED 0x00000400
#define INIT_ICONS_NONE 0
#define INIT_ICONS_OWNER 1
#define INIT_ICONS_CONTACT 2
#define INIT_ICONS_ALL (INIT_ICONS_OWNER|INIT_ICONS_CONTACT)
/***********************************************************************************************************
* internal variables
***********************************************************************************************************/
static BOOLEAN bInitIcons = INIT_ICONS_NONE;
static HANDLE ghWindowList = NULL;
static HANDLE ghDetailsInitEvent = NULL;
static INT_PTR CALLBACK DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
CPsHdr::CPsHdr() :
_ignore(10, (LIST<TCHAR>::FTSortFunc)_tcscmp)
{
_dwSize = sizeof(*this);
_hContact = NULL;
_pszProto = NULL;
_pszPrefix = NULL;
_pPages = NULL;
_numPages = 0;
_dwFlags = 0;
_hImages = NULL;
}
CPsHdr::~CPsHdr()
{
INT i;
// delete data
for (i = 0 ; i < _ignore.getCount(); i++)
{
if (_ignore[i]) mir_free(_ignore[i]);
}
// delete the list
_ignore.destroy();
}
VOID CPsHdr::Free_pPages()
{
for ( int i = 0 ; i < _numPages; i++)
if (_pPages[i]) delete _pPages[i];
_numPages = 0;
MIR_FREE(_pPages);
}
/***********************************************************************************************************
* class CPsUpload
***********************************************************************************************************/
class CPsUpload {
public:
enum EPsUpReturn {
UPLOAD_CONTINUE = 0,
UPLOAD_FINISH = 1,
UPLOAD_FINISH_CLOSE = 2
};
private:
PROTOCOLDESCRIPTOR **_pPd;
INT _numProto;
BOOLEAN _bExitAfterUploading;
HANDLE _hUploading;
LPPS _pPs;
/**
* @class Upload
* @class CPsUpload
* @desc start upload process for the current protocol
* @param none
* @return 0 on success
* @return 1 otherwise
**/
INT Upload()
{
CPsTreeItem *pti;
// check if icq is online
if (!IsProtoOnline((*_pPd)->szName)) {
TCHAR szMsg[MAX_PATH];
LPTSTR ptszProto;
ptszProto = mir_a2t((*_pPd)->szName);
mir_sntprintf(szMsg, SIZEOF(szMsg), TranslateT("Protocol '%s' is offline"), ptszProto);
mir_free(ptszProto);
MsgBox(_pPs->hDlg, MB_ICON_WARNING, TranslateT("Upload Details"), szMsg,
TranslateT("You are not currently connected to the ICQ network.\nYou must be online in order to update your information on the server.\n\nYour changes will be saved to database only."));
}
// start uploading process
else {
_hUploading = (HANDLE)CallProtoService((*_pPd)->szName, PS_CHANGEINFOEX, CIXT_FULL, NULL);
if (_hUploading && _hUploading != (HANDLE)CALLSERVICE_NOTFOUND) {
EnableWindow(_pPs->pTree->Window(), FALSE);
if (pti = _pPs->pTree->CurrentItem()) {
EnableWindow(pti->Wnd(), FALSE);
}
EnableWindow(GetDlgItem(_pPs->hDlg, IDOK), FALSE);
EnableWindow(GetDlgItem(_pPs->hDlg, IDAPPLY), FALSE);
mir_snprintf(_pPs->szUpdating, SIZEOF(_pPs->szUpdating), "%s (%s)", Translate("Uploading"), (*_pPd)->szName);
ShowWindow(GetDlgItem(_pPs->hDlg, TXT_UPDATING), SW_SHOW);
SetTimer(_pPs->hDlg, TIMERID_UPDATING, 100, NULL);
return 0;
}
}
return 1;
}
public:
/**
* @name CPsUpload
* @class CPsUpload
* @desc retrieves the list of installed protocols and initializes the class
* @param pPs - the owning propertysheet
* @param bExitAfter - whether the dialog is to close after upload or not
* @return nothing
**/
CPsUpload(LPPS pPs, BOOLEAN bExitAfter)
{
_pPs = pPs;
_pPd = NULL;
_numProto = 0;
_hUploading = NULL;
_bExitAfterUploading = bExitAfter;
}
INT UploadFirst() {
// create a list of all protocols which support uploading contact information
if (CallService(MS_PROTO_ENUMPROTOCOLS, (WPARAM)&_numProto, (LPARAM)&_pPd)) {
return _bExitAfterUploading ? UPLOAD_FINISH_CLOSE : UPLOAD_FINISH;
}
return UploadNext();
}
/**
* @name ~CPsUpload
* @class CPsUpload
* @desc clear pointer to the upload object
* @param none
* @return nothing
**/
~CPsUpload()
{ _pPs->pUpload = NULL; }
/**
* @name Handle
* @class CPsUpload
* @desc returns the handle of the current upload process
* @param none
* @return handle of the current upload process
**/
__inline HANDLE Handle() const
{ return _hUploading; };
/**
* @name UploadNext
* @class CPsUpload
* @desc Search the next protocol which supports uploading contact information
* and start uploading. Delete the object if ready
* @param none
* @return nothing
**/
INT UploadNext()
{
CHAR str[MAXMODULELABELLENGTH];
while (_pPd && *_pPd && _numProto-- > 0) {
if ((*_pPd)->type == PROTOTYPE_PROTOCOL) {
mir_strncpy(str, (*_pPd)->szName, MAXMODULELABELLENGTH);
mir_strncat(str, PS_CHANGEINFOEX, MAXMODULELABELLENGTH);
if (ServiceExists(str) && !Upload()) {
_pPd++;
return UPLOAD_CONTINUE;
}
}
_pPd++;
}
return _bExitAfterUploading ? UPLOAD_FINISH_CLOSE : UPLOAD_FINISH;
}
};
/***********************************************************************************************************
* propertysheet
***********************************************************************************************************/
/**
* @name SortProc()
* @desc used for sorting the tab pages
*
* @return -1 or 0 or 1
**/
static INT SortProc(CPsTreeItem** item1, CPsTreeItem** item2)
{
if (*item1 && *item2) {
if ((*item2)->Pos() > (*item1)->Pos()) return -1;
if ((*item2)->Pos() < (*item1)->Pos()) return 1;
}
return 0;
}
/**
* This service routine creates the DetailsDialog
* @param wParam - handle to contact
* @param lParam - not used
*
* @retval 0 on success
* @retval 1 on failure
**/
static INT_PTR ShowDialog(WPARAM wParam, LPARAM lParam)
{
HWND hWnd;
// update some cached settings
myGlobals.ShowPropsheetColours = DB::Setting::GetByte(SET_PROPSHEET_SHOWCOLOURS, TRUE);
myGlobals.WantAeroAdaption = DB::Setting::GetByte(SET_PROPSHEET_AEROADAPTION, TRUE);
// allow only one dialog per user
if (hWnd = WindowList_Find(ghWindowList, (HANDLE)wParam)) {
SetForegroundWindow(hWnd);
SetFocus(hWnd);
}
else {
CPsHdr psh;
POINT metrics;
BOOLEAN bScanMetaSubContacts = FALSE;
HICON hDefIcon;
// init the treeview options
if (DB::Setting::GetByte(SET_PROPSHEET_SORTITEMS, FALSE))
psh._dwFlags |= PSTVF_SORTTREE;
if (DB::Setting::GetByte(SET_PROPSHEET_GROUPS, TRUE))
psh._dwFlags |= PSTVF_GROUPS;
// create imagelist
metrics.x = GetSystemMetrics(SM_CXSMICON);
metrics.y = GetSystemMetrics(SM_CYSMICON);
if ((psh._hImages = ImageList_Create(metrics.x, metrics.y, (IsWinVerXPPlus() ? ILC_COLOR32 : ILC_COLOR16) | ILC_MASK, 0, 1)) == NULL) {
MsgErr(NULL, LPGENT("Creating the imagelist failed!"));
return 1;
}
hDefIcon = IcoLib_GetIcon(ICO_TREE_DEFAULT);
if (!hDefIcon)
{
hDefIcon = (HICON) LoadImage(ghInst, MAKEINTRESOURCE(IDI_DEFAULT), IMAGE_ICON, metrics.x, metrics.y, 0);
}
// add the default icon to imagelist
ImageList_AddIcon(psh._hImages, hDefIcon);
// init contact
psh._hContact = (HANDLE)wParam;
if (psh._hContact == NULL) {
// mark owner icons as initiated
bInitIcons |= INIT_ICONS_OWNER;
psh._pszProto = NULL;
psh._pszPrefix = NULL;
}
else {
// get contact's protocol
psh._pszPrefix = psh._pszProto = DB::Contact::Proto((HANDLE)wParam);
if (psh._pszProto == NULL) {
MsgErr(NULL, LPGENT("Could not find contact's protocol. Maybe it is not active!"));
return 1;
}
// prepare scanning for metacontact's subcontact's pages
if (bScanMetaSubContacts = DB::Module::IsMetaAndScan(psh._pszProto))
psh._dwFlags |= PSF_PROTOPAGESONLY_INIT;
}
// add the pages
NotifyEventHooks(ghDetailsInitEvent, (WPARAM)&psh, wParam);
if (!psh._pPages || !psh._numPages) {
MsgErr(NULL, LPGENT("No pages have been added. Canceling dialog creation!"));
return 1;
}
// metacontacts sub pages
if (bScanMetaSubContacts)
{
INT numSubs = DB::MetaContact::SubCount((HANDLE)wParam);
psh._dwFlags &= ~PSF_PROTOPAGESONLY_INIT;
psh._dwFlags |= PSF_PROTOPAGESONLY;
for (INT i = 0; i < numSubs; i++)
{
psh._hContact = DB::MetaContact::Sub((HANDLE)wParam, i);
psh._nSubContact = i;
if (psh._hContact)
{
psh._pszProto = DB::Contact::Proto(psh._hContact);
if ((INT_PTR)psh._pszProto != CALLSERVICE_NOTFOUND)
NotifyEventHooks(ghDetailsInitEvent, (WPARAM)&psh, (LPARAM)psh._hContact);
}
}
psh._hContact = (HANDLE)wParam;
}
// sort the pages by the position read from database
if (!(psh._dwFlags & PSTVF_SORTTREE)) {
qsort(psh._pPages, psh._numPages, sizeof(CPsTreeItem*),
(INT (*)(const VOID*, const VOID*))SortProc);
}
// create the dialog itself
hWnd = CreateDialogParam(ghInst, MAKEINTRESOURCE(IDD_DETAILS), NULL, DlgProc, (LPARAM)&psh);
if (!hWnd) {
MsgErr(NULL, LPGENT("Details dialog failed to be created. Returning error is %d."), GetLastError());
}
else
MagneticWindows_AddWindow(hWnd);
}
return 0;
}
/**
* @name AddPage()
* @desc this adds a new pages
* @param wParam - The List of pages we want to add the new one to
* @param lParam - it's the page to add
*
* @return 0
**/
static INT_PTR AddPage(WPARAM wParam, LPARAM lParam)
{
CPsHdr *pPsh = (CPsHdr*)wParam;
OPTIONSDIALOGPAGE *odp = (OPTIONSDIALOGPAGE*)lParam;
// check size of the handled structures
if (pPsh == NULL || odp == NULL || pPsh->_dwSize != sizeof(CPsHdr))
return 1;
if (odp->cbSize != sizeof(OPTIONSDIALOGPAGE) && odp->cbSize != OPTIONPAGE_OLD_SIZE) {
MsgErr(NULL, LPGENT("The Page to add has invalid size %d bytes!"), odp->cbSize);
return 1;
}
// try to check whether the flag member is initialized or not
odp->flags = odp->flags > (ODPF_UNICODE|ODPF_BOLDGROUPS|ODPF_ICON|PSPF_PROTOPREPENDED) ? 0 : odp->flags;
if (pPsh->_dwFlags & (PSF_PROTOPAGESONLY|PSF_PROTOPAGESONLY_INIT)) {
BOOLEAN bIsUnicode = (odp->flags & ODPF_UNICODE) == ODPF_UNICODE;
TCHAR* ptszTitle = bIsUnicode ? mir_tstrdup(odp->ptszTitle) : mir_a2t(odp->pszTitle);
// avoid adding pages for a meta subcontact, which have been added for a metacontact.
if (pPsh->_dwFlags & PSF_PROTOPAGESONLY) {
if (pPsh->_ignore.getIndex(ptszTitle) != -1) {
mir_free(ptszTitle);
return 0;
}
}
// init ignore list with pages added by metacontact
else if (pPsh->_dwFlags & PSF_PROTOPAGESONLY_INIT)
pPsh->_ignore.insert(mir_tstrdup(ptszTitle));
mir_free(ptszTitle);
}
// create the new tree item
CPsTreeItem *pNew = new CPsTreeItem();
if (pNew) {
if (pNew->Create(pPsh, odp)) {
MIR_DELETE(pNew);
return 1;
}
// resize the array
pPsh->_pPages = (CPsTreeItem**)mir_realloc(pPsh->_pPages, (pPsh->_numPages + 1) * sizeof(CPsTreeItem*));
if (pPsh->_pPages != NULL) {
pPsh->_pPages[pPsh->_numPages++] = pNew;
return 0;
}
pPsh->_numPages = 0;
}
return 1;
}
/**
* @name OnDeleteContact()
* @desc a user was deleted, so need to close its details dialog, if one open
*
* @return 0
**/
static INT OnDeleteContact(WPARAM wParam, LPARAM lParam)
{
HWND hWnd = WindowList_Find(ghWindowList, (HANDLE)wParam);
if (hWnd != NULL)
DestroyWindow(hWnd);
return 0;
}
/**
* @name OnShutdown()
* @desc we need to emptify the windowlist
*
* @return 0
**/
static INT OnShutdown(WPARAM wParam, LPARAM lParam)
{
WindowList_BroadcastAsync(ghWindowList, WM_DESTROY, 0, 0);
return 0;
}
/**
* @name AddProtocolPages()
* @desc is called by Miranda if user selects to display the userinfo dialog
* @param odp - optiondialogpage structure to use
* @param wParam - the propertysheet init structure to pass
* @param pszProto - the protocol name to prepend as item name (can be NULL)
*
* @return 0
**/
static INT AddProtocolPages(OPTIONSDIALOGPAGE& odp, WPARAM wParam, LPSTR pszProto = NULL)
{
TCHAR szTitle[MAX_PATH];
const BYTE ofs = (pszProto) ? mir_sntprintf(szTitle, SIZEOF(szTitle), _T(TCHAR_STR_PARAM) _T("\\"), pszProto) : 0;
odp.ptszTitle = szTitle;
odp.pszTemplate = MAKEINTRESOURCEA(IDD_CONTACT_GENERAL);
odp.position = 0x8000000;
odp.pfnDlgProc = PSPProcGeneral;
odp.hIcon = (HICON)ICONINDEX(IDI_TREE_GENERAL);
mir_tcsncpy(szTitle + ofs, LPGENT("General"), SIZEOF(szTitle) - ofs);
AddPage(wParam, (LPARAM)&odp);
odp.pszTemplate = MAKEINTRESOURCEA(IDD_CONTACT_ADDRESS);
odp.position = 0x8000001;
odp.pfnDlgProc = PSPProcContactHome;
odp.hIcon = (HICON)ICONINDEX(IDI_TREE_ADDRESS);
mir_tcsncpy(szTitle + ofs, LPGENT("General") _T("\\") LPGENT("Contact (private)"), SIZEOF(szTitle) - ofs);
AddPage(wParam, (LPARAM)&odp);
odp.pszTemplate = MAKEINTRESOURCEA(IDD_CONTACT_ORIGIN);
odp.position = 0x8000002;
odp.pfnDlgProc = PSPProcOrigin;
odp.hIcon = (HICON)ICONINDEX(IDI_TREE_ADVANCED);
mir_tcsncpy(szTitle + ofs, LPGENT("General") _T("\\") LPGENT("Origin"), SIZEOF(szTitle) - ofs);
AddPage(wParam, (LPARAM)&odp);
odp.pszTemplate = MAKEINTRESOURCEA(IDD_CONTACT_ANNIVERSARY);
odp.position = 0x8000003;
odp.pfnDlgProc = PSPProcAnniversary;
odp.hIcon = (HICON)ICONINDEX(IDI_BIRTHDAY);
mir_tcsncpy(szTitle + ofs, LPGENT("General") _T("\\") LPGENT("Anniversaries"), SIZEOF(szTitle) - ofs);
AddPage(wParam, (LPARAM)&odp);
odp.pszTemplate = MAKEINTRESOURCEA(IDD_CONTACT_COMPANY);
odp.position = 0x8000004;
odp.pfnDlgProc = PSPProcCompany;
odp.hIcon = (HICON)ICONINDEX(IDI_TREE_COMPANY);
mir_tcsncpy(szTitle + ofs, LPGENT("Work"), SIZEOF(szTitle) - ofs);
AddPage(wParam, (LPARAM)&odp);
odp.pszTemplate = MAKEINTRESOURCEA(IDD_CONTACT_ADDRESS);
odp.position = 0x8000005;
odp.pfnDlgProc = PSPProcContactWork;
odp.hIcon = (HICON)ICONINDEX(IDI_TREE_ADDRESS);
mir_tcsncpy(szTitle + ofs, LPGENT("Work") _T("\\") LPGENT("Contact (Work)"), SIZEOF(szTitle) - ofs);
AddPage(wParam, (LPARAM)&odp);
odp.pszTemplate = MAKEINTRESOURCEA(IDD_CONTACT_ABOUT);
odp.position = 0x8000006;
odp.pfnDlgProc = PSPProcAbout;
odp.hIcon = (HICON)ICONINDEX(IDI_TREE_ABOUT);
mir_tcsncpy(szTitle + ofs, LPGENT("About"), SIZEOF(szTitle) - ofs);
AddPage(wParam, (LPARAM)&odp);
odp.pszTemplate = MAKEINTRESOURCEA(IDD_CONTACT_PROFILE);
odp.position = 0x8000007;
odp.pfnDlgProc = PSPProcContactProfile;
odp.hIcon = (HICON)ICONINDEX(IDI_TREE_PROFILE);
mir_tcsncpy(szTitle + ofs, LPGENT("About") _T("\\") LPGENT("Profile"), SIZEOF(szTitle) - ofs);
AddPage(wParam, (LPARAM)&odp);
return 0;
}
/**
* @name InitDetails
* @desc is called by Miranda if user selects to display the userinfo dialog
* @param wParam - the propertysheet init structure to pass
* @param lParam - handle to contact whose information are read
*
* @return 0
**/
static INT InitDetails(WPARAM wParam, LPARAM lParam)
{
CPsHdr* pPsh = (CPsHdr*)wParam;
if (!(pPsh->_dwFlags & PSF_PROTOPAGESONLY)) {
OPTIONSDIALOGPAGE odp;
BOOLEAN bChangeDetailsEnabled = myGlobals.CanChangeDetails && DB::Setting::GetByte(SET_PROPSHEET_CHANGEMYDETAILS, FALSE);
// important to avoid craches!!
ZeroMemory(&odp, sizeof(odp));
if (lParam || bChangeDetailsEnabled) {
odp.cbSize = sizeof(odp);
odp.hInstance = ghInst;
odp.flags = ODPF_ICON | ODPF_TCHAR;
odp.ptszGroup = IcoLib_GetDefaultIconFileName();
if (lParam) {
// ignore common pages for weather contacts
if (!pPsh->_pszProto || stricmp(pPsh->_pszProto, "weather"))
{
AddProtocolPages(odp, wParam);
odp.ptszTitle = LPGENT("About") _T("\\") LPGENT("Notes");
}
else {
odp.ptszTitle = LPGENT("Notes");
}
odp.pszTemplate = MAKEINTRESOURCEA(IDD_CONTACT_ABOUT);
odp.position = 0x8000008;
odp.pfnDlgProc = PSPProcMyNotes;
odp.hIcon = (HICON)ICONINDEX(IDI_TREE_NOTES);
AddPage(wParam, (LPARAM)&odp);
}
/* Editing owner details no longer supported due to leak of common interface for all protocols.
else
if (!(pPsh->_dwFlags & PSTVF_INITICONS))
{
PROTOCOLDESCRIPTOR **pd;
INT ProtoCount, i;
CHAR str[MAXMODULELABELLENGTH];
odp.flags |= PSPF_PROTOPREPENDED;
// create a list of all protocols which support uploading contact information
if (!CallService(MS_PROTO_ENUMPROTOCOLS, (WPARAM)&ProtoCount, (LPARAM)&pd)) {
for (i = 0; i < ProtoCount; i++) {
if (pd[i]->type == PROTOTYPE_PROTOCOL) {
pPsh->_pszProto = pd[i]->szName;
mir_snprintf(str, MAXMODULELABELLENGTH, "%s"PS_CHANGEINFOEX, pd[i]->szName);
if (ServiceExists(str)) AddProtocolPages(odp, wParam, pd[i]->szName);
}
}
}
}
*/
}
}
return 0;
}
/**
* @name InitTreeIcons()
* @desc initalize all treeview icons
* @param none
*
* @return nothing
**/
VOID DlgContactInfoInitTreeIcons()
{
// make sure this is run only once
if (!(bInitIcons & INIT_ICONS_ALL)) {
CPsHdr psh;
POINT metrics = {0};
INT i = 0;
psh._dwFlags = PSTVF_INITICONS;
metrics.x = GetSystemMetrics(SM_CXSMICON);
metrics.y = GetSystemMetrics(SM_CYSMICON);
if (psh._hImages = ImageList_Create(metrics.x, metrics.y, (IsWinVerXPPlus() ? ILC_COLOR32 : ILC_COLOR16) | ILC_MASK, 0, 1)) {
HICON hDefIcon = IcoLib_GetIcon(ICO_TREE_DEFAULT);
if (!hDefIcon)
{
hDefIcon = (HICON) LoadImage(ghInst, MAKEINTRESOURCE(IDI_DEFAULT), IMAGE_ICON, metrics.x, metrics.y, 0);
}
// add the default icon to imagelist
ImageList_AddIcon(psh._hImages, hDefIcon);
}
// avoid pages from loading doubled
if (!(bInitIcons & INIT_ICONS_CONTACT)) {
LPCSTR pszContactProto = NULL;
PROTOCOLDESCRIPTOR **pd;
INT ProtoCount = 0;
psh._dwFlags |= PSF_PROTOPAGESONLY_INIT;
// enumerate all protocols
if (!CallService(MS_PROTO_ENUMPROTOCOLS, (WPARAM)&ProtoCount, (LPARAM)&pd)) {
for (i = 0; i < ProtoCount; i++) {
if (pd[i]->type == PROTOTYPE_PROTOCOL) {
// enumerate all contacts
for (psh._hContact = DB::Contact::FindFirst();
psh._hContact != NULL;
psh._hContact = DB::Contact::FindNext(psh._hContact))
{
// compare contact's protocol to the current one, to add
pszContactProto = DB::Contact::Proto(psh._hContact);
if ((INT_PTR)pszContactProto != CALLSERVICE_NOTFOUND && !mir_strcmp(pd[i]->szName, pszContactProto)) {
// call a notification for the contact to retrieve all protocol specific tree items
NotifyEventHooks(ghDetailsInitEvent, (WPARAM)&psh, (LPARAM)psh._hContact);
if (psh._pPages) {
psh.Free_pPages();
psh._dwFlags = PSTVF_INITICONS|PSF_PROTOPAGESONLY;
}
break;
}
}
}
}
}
bInitIcons |= INIT_ICONS_CONTACT;
}
// load all treeitems for owner contact
if (!(bInitIcons & INIT_ICONS_OWNER)) {
psh._hContact = NULL;
psh._pszProto = NULL;
NotifyEventHooks(ghDetailsInitEvent, (WPARAM)&psh, (LPARAM)psh._hContact);
if (psh._pPages) {
psh.Free_pPages();
}
bInitIcons |= INIT_ICONS_OWNER;
}
ImageList_Destroy(psh._hImages);
}
}
/**
* @name UnLoadModule()
* @desc unload the UserInfo Module
*
* @return nothing
**/
VOID DlgContactInfoUnLoadModule()
{
DestroyHookableEvent(ghDetailsInitEvent);
}
/**
* @name LoadModule()
* @desc load the UserInfo Module
*
* @return nothing
**/
VOID DlgContactInfoLoadModule()
{
ghDetailsInitEvent = CreateHookableEvent(ME_USERINFO_INITIALISE);
CreateServiceFunction(MS_USERINFO_SHOWDIALOG, ShowDialog);
CreateServiceFunction("UserInfo/AddPage", AddPage);
HookEvent(ME_DB_CONTACT_DELETED, OnDeleteContact);
HookEvent(ME_SYSTEM_PRESHUTDOWN, OnShutdown);
HookEvent(ME_USERINFO_INITIALISE, InitDetails);
ghWindowList = (HANDLE)CallService(MS_UTILS_ALLOCWINDOWLIST, 0, 0);
// check whether changing my details via UserInfoEx is basically possible
{
PROTOACCOUNT **pAcc;
INT i, nAccCount;
myGlobals.CanChangeDetails = FALSE;
if (MIRSUCCEEDED(ProtoEnumAccounts(&nAccCount, &pAcc)))
{
for (i = 0; (i < nAccCount) && !myGlobals.CanChangeDetails; i++)
{
if (IsProtoAccountEnabled(pAcc[i]))
{
// update my contact information on icq server
myGlobals.CanChangeDetails = MIREXISTS(CallProtoService(pAcc[i]->szModuleName, PS_CHANGEINFOEX, NULL, NULL));
}
}
}
}
}
static void ResetUpdateInfo(LPPS pPs)
{
INT i;
// free the array of accomblished acks
for (i = 0; i < (INT)pPs->nSubContacts; i++)
MIR_FREE(pPs->infosUpdated[i].acks);
MIR_FREE(pPs->infosUpdated);
pPs->nSubContacts = 0;
}
/*
============================================================================================
PropertySheet's Dialog Procedures
============================================================================================
*/
/**
* @name DlgProc()
* @desc dialog procedure for the main propertysheet dialog box
*
* @return 0 or 1
**/
static INT_PTR CALLBACK DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
LPPS pPs = (LPPS)GetUserData(hDlg);
// do not process any message if pPs is no longer existent
if (!PtrIsValid(pPs) && uMsg != WM_INITDIALOG)
return FALSE;
switch (uMsg)
{
/**
* @class WM_INITDIALOG
* @desc initiates all dialog controls
* @param wParam - not used
* lParam - pointer to a PSHDR structure, which contains all information to create the dialog
*
* @return TRUE if everything is ok, FALSE if dialog creation should fail
**/
case WM_INITDIALOG:
{
CPsHdr* pPsh = (CPsHdr*)lParam;
WORD needWidth = 0;
RECT rc;
if (!pPsh || pPsh->_dwSize != sizeof(CPsHdr))
return FALSE;
TranslateDialogDefault(hDlg);
//
// create data structures
//
if (!(pPs = (LPPS)mir_alloc(sizeof(PS))))
return FALSE;
ZeroMemory(pPs, sizeof(PS));
if (!(pPs->pTree = new CPsTree(pPs)))
return FALSE;
if (!(pPs->pTree->Create(GetDlgItem(hDlg, STATIC_TREE), pPsh))) {
return FALSE;
}
SetUserData(hDlg, pPs);
pPs->hDlg = hDlg;
pPs->dwFlags |= PSF_LOCKED;
pPs->hContact = pPsh->_hContact;
pPs->hProtoAckEvent = HookEventMessage(ME_PROTO_ACK, hDlg, HM_PROTOACK);
pPs->hSettingChanged = HookEventMessage(ME_DB_CONTACT_SETTINGCHANGED, hDlg, HM_SETTING_CHANGED);
pPs->hIconsChanged = HookEventMessage(ME_SKIN2_ICONSCHANGED, hDlg, HM_RELOADICONS);
ShowWindow(GetDlgItem(hDlg, IDC_PAGETITLEBG),IsAeroMode());
ShowWindow(GetDlgItem(hDlg, IDC_PAGETITLEBG2),!IsAeroMode());
//
// set icons
//
SendMessage(hDlg, WM_SETICON, ICON_BIG, (LPARAM)LoadIcon(ghInst, MAKEINTRESOURCE(IDI_MAIN)));
DlgProc(hDlg, HM_RELOADICONS, NULL, NULL);
//
// load basic protocol for current contact (for faster load later on and better handling for owner protocol)
//
if (pPs->hContact) mir_strncpy(pPs->pszProto, pPsh->_pszPrefix, MAXMODULELABELLENGTH);
// set the windowtitle
DlgProc(hDlg, HM_SETWINDOWTITLE, NULL, NULL);
// translate Userinfo buttons
{
SendDlgItemMessage(hDlg, BTN_UPDATE, BUTTONTRANSLATE, NULL, NULL);
SendDlgItemMessage(hDlg, IDOK, BUTTONTRANSLATE, NULL, NULL);
SendDlgItemMessage(hDlg, IDCANCEL, BUTTONTRANSLATE, NULL, NULL);
SendDlgItemMessage(hDlg, IDAPPLY, BUTTONTRANSLATE, NULL, NULL);
SendDlgItemMessage(hDlg, BTN_EXPORT, BUTTONADDTOOLTIP, (WPARAM)TranslateT("Export to file"), MBF_TCHAR);
SendDlgItemMessage(hDlg, BTN_IMPORT, BUTTONADDTOOLTIP, (WPARAM)TranslateT("Import from file"), MBF_TCHAR);
}
//
// set bold font for name in description area
//
{
LOGFONT lf;
HFONT hNormalFont = (HFONT)SendMessage(hDlg, WM_GETFONT, 0, 0);
GetObject(hNormalFont, sizeof(lf), &lf);
lf.lfHeight = 22;
mir_tcscpy(lf.lfFaceName, _T("Segoe UI"));
pPs->hCaptionFont = CreateFontIndirect(&lf);
SendDlgItemMessage(hDlg, IDC_PAGETITLE, WM_SETFONT, (WPARAM)pPs->hCaptionFont, 0);
GetObject(hNormalFont, sizeof(lf), &lf);
lf.lfWeight = FW_BOLD;
pPs->hBoldFont = CreateFontIndirect(&lf);
}
//
// initialize the optionpages and tree control
//
if (!pPs->pTree->InitTreeItems((LPWORD)&needWidth))
return FALSE;
//
// move and resize dialog and its controls
//
{
HWND hCtrl;
RECT rcTree;
POINT pt = { 0, 0 };
INT addWidth = 0;
// at least add width of scrollbar
needWidth += 8 + GetSystemMetrics(SM_CXVSCROLL);
// get tree rectangle
GetWindowRect(hDlg, &pPs->rcDisplay);
GetWindowRect(pPs->pTree->Window(), &rcTree);
ClientToScreen(hDlg, &pt);
OffsetRect(&rcTree, -pt.x, -pt.y);
// calculate the amout of pixels to resize the dialog by?
if (needWidth > rcTree.right - rcTree.left) {
RECT rcMax = { 0, 0, 0, 0 };
rcMax.right = 280;
MapDialogRect(hDlg, &rcMax);
addWidth = min(needWidth, rcMax.right) - rcTree.right + rcTree.left;
rcTree.right += addWidth;
// resize tree
MoveWindow(pPs->pTree->Window(), rcTree.left, rcTree.top, rcTree.right - rcTree.left, rcTree.bottom - rcTree.top, FALSE);
pPs->rcDisplay.right += addWidth;
MoveWindow(hDlg, pPs->rcDisplay.left, pPs->rcDisplay.top,
pPs->rcDisplay.right - pPs->rcDisplay.left,
pPs->rcDisplay.bottom - pPs->rcDisplay.top, FALSE);
}
GetClientRect(GetDlgItem(hDlg, IDC_PAGETITLEBG), &rc);
// calculate dislpay area for pages
OffsetRect(&pPs->rcDisplay, -pt.x, -pt.y);
pPs->rcDisplay.bottom = rcTree.bottom;
pPs->rcDisplay.left = rcTree.right + 2;
pPs->rcDisplay.top = rcTree.top+rc.bottom;
pPs->rcDisplay.right -= 2;
// move and resize the rest of the controls
if (addWidth > 0) {
const WORD idResize[] = { IDC_HEADERBAR, STATIC_LINE2 };
const WORD idMove[] = { IDC_PAGETITLE, IDC_PAGETITLEBG, IDC_PAGETITLEBG2, IDOK, IDCANCEL, IDAPPLY };
WORD i;
for (i = 0; i < SIZEOF(idResize); i++) {
if (hCtrl = GetDlgItem(hDlg, idResize[i])) {
GetWindowRect(hCtrl, &rc);
OffsetRect(&rc, -pt.x, -pt.y);
MoveWindow(hCtrl, rc.left, rc.top, rc.right - rc.left + addWidth, rc.bottom - rc.top, FALSE);
}
}
for (i = 0; i < SIZEOF(idMove); i++) {
if (hCtrl = GetDlgItem(hDlg, idMove[i])) {
GetWindowRect(hCtrl, &rc);
OffsetRect(&rc, -pt.x, -pt.y);
MoveWindow(hCtrl, rc.left + addWidth, rc.top, rc.right - rc.left, rc.bottom - rc.top, FALSE);
}
}
}
// restore window position and add required size
Utils_RestoreWindowPositionNoSize(hDlg, NULL, MODNAME, "DetailsDlg");
}
//
// show the first propsheetpage
//
// finally add the dialog to the window list
WindowList_Add(ghWindowList, hDlg, pPs->hContact);
// show the dialog
pPs->dwFlags &= ~PSF_LOCKED;
pPs->dwFlags |= PSF_INITIALIZED;
//
// initialize the "updating" button and statustext and check for online status
//
pPs->updateAnimFrame = 0;
if (pPs->hContact && *pPs->pszProto)
{
GetDlgItemTextA(hDlg, TXT_UPDATING, pPs->szUpdating, SIZEOF(pPs->szUpdating));
ShowWindow(GetDlgItem(hDlg, TXT_UPDATING), SW_HIDE);
if (DlgProc(hDlg, M_CHECKONLINE, NULL, NULL))
{
DlgProc(hDlg, WM_COMMAND, MAKEWPARAM(BTN_UPDATE, BN_CLICKED), (LPARAM)GetDlgItem(hDlg, BTN_UPDATE));
}
}
{
INT nPage = pPs->pTree->CurrentItemIndex();
if (!pPs->pTree->IsIndexValid(nPage))
nPage = 0;
TreeView_Select(pPs->pTree->Window(), NULL, TVGN_CARET);
TreeView_Select(pPs->pTree->Window(), pPs->pTree->TreeItemHandle(nPage), TVGN_CARET);
ShowWindow(hDlg, SW_SHOW);
}
}
return TRUE;
/**
* @class WM_TIMER
* @desc is called to display the "updating" text in the status area
* @param wParam - not used
* lParam - not used
*
* @return always FALSE
**/
case WM_TIMER:
switch (wParam)
{
case TIMERID_UPDATING:
{
CHAR str[84];
mir_snprintf(str, SIZEOF(str), "%.*s%s%.*s", pPs->updateAnimFrame%10, ".........", pPs->szUpdating, pPs->updateAnimFrame%10, ".........");
SetDlgItemTextA(hDlg, TXT_UPDATING, str);
if (++pPs->updateAnimFrame == UPDATEANIMFRAMES)
pPs->updateAnimFrame = 0;
return FALSE;
}
}
break;
case 0x031E: /*WM_DWMCOMPOSITIONCHANGED:*/
{
ShowWindow(GetDlgItem(hDlg, IDC_PAGETITLEBG),IsAeroMode());
InvalidateRect(hDlg, NULL, TRUE);
}
break;
/**
* @class WM_CTLCOLORSTATIC
* @desc sets the colour of some of the dialog's static controls
* @param wParam - HWND of the contrls
* lParam - HDC for drawing
*
* @return StockObject
**/
case WM_CTLCOLORSTATIC:
switch (GetWindowLongPtr((HWND)lParam, GWLP_ID))
{
case TXT_UPDATING:
{
COLORREF textCol, bgCol, newCol;
INT ratio;
textCol = GetSysColor(COLOR_BTNTEXT);
bgCol = GetSysColor(COLOR_3DFACE);
ratio = abs(UPDATEANIMFRAMES/2 - pPs->updateAnimFrame) * 510 / UPDATEANIMFRAMES;
newCol = RGB(GetRValue(bgCol) + (GetRValue(textCol) - GetRValue(bgCol)) * ratio / 256,
GetGValue(bgCol) + (GetGValue(textCol) - GetGValue(bgCol)) * ratio / 256,
GetBValue(bgCol) + (GetBValue(textCol) - GetBValue(bgCol)) * ratio / 256);
SetTextColor((HDC)wParam, newCol);
SetBkColor((HDC)wParam, GetSysColor(COLOR_3DFACE));
}
return (INT_PTR)GetSysColorBrush(COLOR_3DFACE);
case IDC_PAGETITLE:
case IDC_PAGETITLEBG:
{
if (IsAeroMode())
{
SetTextColor((HDC)wParam, RGB(0,90,180));
SetBkColor((HDC)wParam, RGB(255, 255, 255));
return (INT_PTR)GetStockObject(WHITE_BRUSH);
}
else
{
SetBkColor((HDC)wParam, GetSysColor(COLOR_3DFACE));
return (INT_PTR)GetSysColorBrush(COLOR_3DFACE);
}
}
}
SetBkMode((HDC)wParam, TRANSPARENT);
return (INT_PTR)GetStockObject(NULL_BRUSH);
/**
* @class PSM_CHANGED
* @desc indicates the propertysheet and the current selected page as changed
* @param wParam - not used
* lParam - not used
*
* @return TRUE if successful FALSE if the dialog is locked at the moment
**/
case PSM_CHANGED:
if (!(pPs->dwFlags & PSF_LOCKED))
{
pPs->dwFlags |= PSF_CHANGED;
pPs->pTree->CurrentItem()->AddFlags(PSPF_CHANGED);
EnableWindow(GetDlgItem(hDlg, IDAPPLY), TRUE);
return TRUE;
}
break;
/**
* @class PSM_GETBOLDFONT
* @desc returns the bold font
* @param wParam - not used
* lParam - pointer to a HFONT, which takes the boldfont
*
* @return TRUE if successful, FALSE otherwise
**/
case PSM_GETBOLDFONT:
if (pPs->hBoldFont && lParam)
{
*(HFONT*)lParam = pPs->hBoldFont;
SetWindowLongPtr(hDlg, DWLP_MSGRESULT, (LONG_PTR)pPs->hBoldFont);
return TRUE;
}
*(HFONT*)lParam = NULL;
SetWindowLongPtr(hDlg, DWLP_MSGRESULT, 0l);
break;
/**
* @class PSM_GETCONTACT
* @desc returns the handle to the contact, associated with this propertysheet
* @param wParam - index or -1 for current item
* lParam - pointer to a HANDLE, which takes the contact handle
*
* @return TRUE if successful, FALSE otherwise
**/
case PSM_GETCONTACT:
if (lParam)
{
CPsTreeItem *pti = ((INT)wParam != -1)
? pPs->pTree->TreeItem((INT)wParam)
: pPs->pTree->CurrentItem();
// prefer to return the contact accociated with the current page
if (pti && pti->hContact() != INVALID_HANDLE_VALUE) {
*(HANDLE*)lParam = pti->hContact();
SetWindowLongPtr(hDlg, DWLP_MSGRESULT, (LONG_PTR)pti->hContact());
return TRUE;
}
// return contact who owns the details dialog
if (pPs->hContact != INVALID_HANDLE_VALUE) {
*(HANDLE*)lParam = pPs->hContact;
SetWindowLongPtr(hDlg, DWLP_MSGRESULT, (LONG_PTR)pPs->hContact);
return TRUE;
}
*(HANDLE*)lParam = NULL;
SetWindowLongPtr(hDlg, DWLP_MSGRESULT, NULL);
}
break;
/**
* @class PSM_GETBASEPROTO
* @desc returns the basic protocol module for the associated contact
* @param wParam - index or -1 for current item
* lParam - pointer to a LPCSTR which takes the protocol string pointer
*
* @return TRUE if successful, FALSE otherwise
**/
case PSM_GETBASEPROTO:
if (lParam) {
CPsTreeItem *pti = ((INT)wParam != -1)
? pPs->pTree->TreeItem((INT)wParam)
: pPs->pTree->CurrentItem();
if (pti && pti->Proto()) {
// return custom protocol for the current page
*(LPCSTR*)lParam = pti->Proto();
SetWindowLongPtr(hDlg, DWLP_MSGRESULT, (LONG_PTR)pti->Proto());
return TRUE;
}
if (*pPs->pszProto) {
// return global protocol
*(LPSTR*)lParam = pPs->pszProto;
SetWindowLongPtr(hDlg, DWLP_MSGRESULT, (LONG_PTR)pPs->pszProto);
return TRUE;
}
}
*(LPCSTR*)lParam = NULL;
SetWindowLongPtr(hDlg, DWLP_MSGRESULT, 0l);
break;
/**
* @class PSM_ISLOCKED
* @desc returns the lock state of the propertysheetpage
* @param wParam - not used
* lParam - not used
*
* @return TRUE if propertysheet is locked, FALSE if not
**/
case PSM_ISLOCKED:
{
BOOLEAN bLocked = (pPs->dwFlags & PSF_LOCKED) == PSF_LOCKED;
SetWindowLongPtr(hDlg, DWLP_MSGRESULT, bLocked);
return bLocked;
}
/**
* @class PSM_FORCECHANGED
* @desc force all propertysheetpages to update their controls with new values from the database
* @param wParam - whether to replace changed settings too or not
* lParam - not used
*
* @return always FALSE
**/
case PSM_FORCECHANGED:
if (!(pPs->dwFlags & PSF_LOCKED)) {
BOOLEAN bChanged;
pPs->dwFlags |= PSF_LOCKED;
if (bChanged = pPs->pTree->OnInfoChanged())
pPs->dwFlags |= PSF_CHANGED;
else
pPs->dwFlags &= ~PSF_CHANGED;
pPs->dwFlags &= ~PSF_LOCKED;
EnableWindow(GetDlgItem(hDlg, IDAPPLY), bChanged);
}
break;
/**
* @class PSM_DLGMESSAGE
* @desc Sends a message to a specified propertysheetpage
* @param wParam - not used
* lParam - LPDLGCOMMAND structure, which contains information about the message to forward
*
* @return E_FAIL if the page was not found
**/
case PSM_DLGMESSAGE:
{
LPDLGCOMMAND pCmd = (LPDLGCOMMAND)lParam;
CPsTreeItem *pti;
if (pCmd && (pti = pPs->pTree->FindItemByResource(pCmd->hInst, pCmd->idDlg)) && pti->Wnd()) {
if (!pCmd->idDlgItem)
return SendMessage(pti->Wnd(), pCmd->uMsg, pCmd->wParam, pCmd->lParam);
else
return SendDlgItemMessage(pti->Wnd(), pCmd->idDlgItem, pCmd->uMsg, pCmd->wParam, pCmd->lParam);
}
return E_FAIL;
}
/**
* @class PSM_GETPAGEHWND
* @desc get the window handle for a specified propertysheetpage
* @param wParam - recource id of the dialog recource
* lParam - hinstance of the plugin, which created the dialog box
*
* @return TRUE if handle was found and dialog was created before, false otherwise
**/
case PSM_GETPAGEHWND:
{
CPsTreeItem *pti;
if (pti = pPs->pTree->FindItemByResource((HINSTANCE)lParam, wParam)) {
SetWindowLongPtr(hDlg, DWLP_MSGRESULT, (LONG_PTR)pti->Wnd());
return (pti->Wnd() != NULL);
}
}
return FALSE;
case PSM_ISAEROMODE:
{
BOOLEAN bIsAeroMode = IsAeroMode();
if (lParam)
{
*(BOOLEAN*)lParam = bIsAeroMode;
}
return (INT_PTR)bIsAeroMode;
}
/**
* @class HM_SETWINDOWTITLE
* @desc set the window title and text of the infobar
* @param wParam - not used
* lParam - DBCONTACTWRITESETTING structure if called by HM_SETTING_CHANGED message handler
*
* @return FALSE
**/
case HM_SETWINDOWTITLE:
{
LPCTSTR pszName = NULL;
TCHAR newTitle[MAX_PATH];
RECT rc;
POINT pt = { 0, 0 };
HWND hName = GetDlgItem(hDlg, TXT_NAME);
DBCONTACTWRITESETTING* pdbcws = (DBCONTACTWRITESETTING*)lParam;
if (!pPs->hContact)
pszName = TranslateT("Owner");
else
if (pdbcws && pdbcws->value.type == DBVT_TCHAR)
pszName = pdbcws->value.ptszVal;
else
pszName = DB::Contact::DisplayName(pPs->hContact);
SetWindowText(hName, pszName);
mir_sntprintf(newTitle, MAX_PATH, _T("%s - %s"), pszName, TranslateT("Edit Contact Information"));
SetWindowText(hDlg, newTitle);
mir_sntprintf(newTitle, MAX_PATH, _T("%s\n%s"), TranslateT("Edit Contact Information"), pszName);
SetDlgItemText(hDlg, IDC_HEADERBAR, newTitle);
// redraw the name control
ScreenToClient(hDlg, &pt);
GetWindowRect(hName, &rc);
OffsetRect(&rc, pt.x, pt.y);
InvalidateRect(hDlg, &rc, TRUE);
break;
}
/**
* @class HM_RELOADICONS
* @desc handles the changed icon event from the icolib plugin and reloads all icons
* @param wParam - not used
* lParam - not used
*
* @return FALSE
**/
case HM_RELOADICONS:
{
HWND hCtrl;
HICON hIcon;
const ICONCTRL idIcon[] = {
{ ICO_DLG_DETAILS, STM_SETIMAGE, ICO_DLGLOGO },
{ ICO_BTN_UPDATE, BM_SETIMAGE, BTN_UPDATE },
{ ICO_BTN_OK, BM_SETIMAGE, IDOK },
{ ICO_BTN_CANCEL, BM_SETIMAGE, IDCANCEL },
{ ICO_BTN_APPLY, BM_SETIMAGE, IDAPPLY }
};
const INT numIconsToSet = DB::Setting::GetByte(SET_ICONS_BUTTONS, 1) ? SIZEOF(idIcon) : 1;
IcoLib_SetCtrlIcons(hDlg, idIcon, numIconsToSet);
if (hCtrl = GetDlgItem(hDlg, BTN_IMPORT)) {
hIcon = IcoLib_GetIcon(ICO_BTN_IMPORT);
SendMessage(hCtrl, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcon);
SetWindowText(hCtrl, hIcon ? _T("") : _T("I"));
}
if (hCtrl = GetDlgItem(hDlg, BTN_EXPORT)) {
hIcon = IcoLib_GetIcon(ICO_BTN_EXPORT);
SendMessage(hCtrl, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcon);
SetWindowText(hCtrl, hIcon ? _T("") : _T("E"));
}
// update page icons
if (PtrIsValid(pPs) && (pPs->dwFlags & PSF_INITIALIZED))
pPs->pTree->OnIconsChanged();
break;
}
/**
* @class M_CHECKONLINE
* @desc determines whether miranda is online or not
* @param wParam - not used
* lParam - not used
*
* @return TRUE if online, FALSE if offline
**/
case M_CHECKONLINE:
{
if (IsProtoOnline(pPs->pszProto))
{
EnableWindow(GetDlgItem(hDlg, BTN_UPDATE), !IsWindowVisible(GetDlgItem(hDlg, TXT_UPDATING)));
return TRUE;
}
EnableWindow(GetDlgItem(hDlg, BTN_UPDATE), FALSE);
EnableWindow(GetDlgItem(hDlg, TXT_UPDATING), FALSE);
break;
}
/**
* @class HM_PROTOACK
* @desc handles all acks from the protocol plugin
* @param wParam - not used
* lParam - pointer to a ACKDATA structure
*
* @return FALSE
**/
case HM_PROTOACK:
{
ACKDATA *ack = (ACKDATA*)lParam;
INT i, iSubContact;
CPsTreeItem *pti;
if (!ack->hContact && ack->type == ACKTYPE_STATUS)
return DlgProc(hDlg, M_CHECKONLINE, NULL, NULL);
switch (ack->type) {
case ACKTYPE_SETINFO:
{
if (ack->hContact != pPs->hContact || !pPs->pUpload || pPs->pUpload->Handle() != ack->hProcess)
break;
if (ack->result == ACKRESULT_SUCCESS) {
ShowWindow(GetDlgItem(hDlg, TXT_UPDATING), SW_HIDE);
KillTimer(hDlg, TIMERID_UPDATING);
// upload next protocols contact information
switch (pPs->pUpload->UploadNext()) {
case CPsUpload::UPLOAD_FINISH_CLOSE:
MIR_DELETE(pPs->pUpload);
DestroyWindow(hDlg);
case CPsUpload::UPLOAD_CONTINUE:
return FALSE;
case CPsUpload::UPLOAD_FINISH:
MIR_DELETE(pPs->pUpload);
break;
}
DlgProc(hDlg, M_CHECKONLINE, NULL, NULL);
EnableWindow(pPs->pTree->Window(), TRUE);
if (pti = pPs->pTree->CurrentItem()) {
EnableWindow(pti->Wnd(), TRUE);
}
EnableWindow(GetDlgItem(hDlg, IDOK), TRUE);
pPs->dwFlags &= ~PSF_LOCKED;
}
else
if (ack->result == ACKRESULT_FAILED) {
MsgBox(hDlg, MB_ICON_WARNING,
LPGENT("Upload ICQ Details"),
LPGENT("Upload failed"),
LPGENT("Your details were not uploaded successfully.\nThey were written to database only."));
KillTimer(hDlg, TIMERID_UPDATING);
ShowWindow(GetDlgItem(hDlg, TXT_UPDATING), SW_HIDE);
DlgProc(hDlg, M_CHECKONLINE, NULL, NULL);
// upload next protocols contact information
switch (pPs->pUpload->UploadNext()) {
case CPsUpload::UPLOAD_FINISH_CLOSE:
MIR_DELETE(pPs->pUpload);
DestroyWindow(hDlg);
case CPsUpload::UPLOAD_CONTINUE:
return 0;
case CPsUpload::UPLOAD_FINISH:
MIR_DELETE(pPs->pUpload);
break;
}
if (pti = pPs->pTree->CurrentItem()) {
EnableWindow(pti->Wnd(), TRUE);
}
// activate all controls again
EnableWindow(pPs->pTree->Window(), TRUE);
EnableWindow(GetDlgItem(hDlg, IDOK), TRUE);
pPs->dwFlags &= ~PSF_LOCKED;
}
break;
}
case ACKTYPE_GETINFO:
// is contact the owner of the dialog or any metasubcontact of the owner? skip handling otherwise!
if (ack->hContact != pPs->hContact) {
if (!myGlobals.szMetaProto)
break;
if (!DB::Setting::GetByte(SET_META_SCAN, TRUE))
break;
for (i = 0; i < pPs->nSubContacts; i++) {
if (pPs->infosUpdated[i].hContact == ack->hContact) {
iSubContact = i;
break;
}
}
if (i == pPs->nSubContacts)
break;
}
else {
iSubContact = 0;
}
// if they're not gonna send any more ACK's don't let that mean we should crash
if (!pPs->infosUpdated || (!ack->hProcess && !ack->lParam)) {
ResetUpdateInfo(pPs);
ShowWindow(GetDlgItem(hDlg, TXT_UPDATING), SW_HIDE);
KillTimer(hDlg, TIMERID_UPDATING);
DlgProc(hDlg, M_CHECKONLINE, NULL, NULL);
break;
}
if (iSubContact < pPs->nSubContacts) {
// init the acks structure for a sub contact
if (pPs->infosUpdated[iSubContact].acks == NULL) {
pPs->infosUpdated[iSubContact].acks = (LPINT)mir_calloc(sizeof(INT) * (INT)(INT_PTR)ack->hProcess);
pPs->infosUpdated[iSubContact].count = (INT)(INT_PTR)ack->hProcess;
}
if (ack->result == ACKRESULT_SUCCESS || ack->result == ACKRESULT_FAILED)
pPs->infosUpdated[iSubContact].acks[ack->lParam] = 1;
// check for pending tasks
for (iSubContact = 0; iSubContact < pPs->nSubContacts; iSubContact++) {
for (i = 0; i < pPs->infosUpdated[iSubContact].count; i++) {
if (pPs->infosUpdated[iSubContact].acks[i] == 0)
break;
}
if (i < pPs->infosUpdated[iSubContact].count)
break;
}
}
// all acks are done, finish updating
if (iSubContact >= pPs->nSubContacts) {
ResetUpdateInfo(pPs);
ShowWindow(GetDlgItem(hDlg, TXT_UPDATING), SW_HIDE);
KillTimer(hDlg, TIMERID_UPDATING);
DlgProc(hDlg, M_CHECKONLINE, NULL, NULL);
}
}
break;
}
/**
* @class HM_SETTING_CHANGED
* @desc This message is called by the ME_DB_CONTACT_SETTINGCHANGED event and forces all
* unedited settings in the propertysheetpages to be updated
* @param wParam - handle to the contact whose settings are to be changed
* lParam - DBCONTACTWRITESETTING structure that identifies the changed setting
* @return FALSE
**/
case HM_SETTING_CHANGED:
if (!(pPs->dwFlags & PSF_LOCKED)) {
HANDLE hContact = (HANDLE)wParam;
DBCONTACTWRITESETTING* pdbcws = (DBCONTACTWRITESETTING*)lParam;
if (hContact != pPs->hContact) {
if (!myGlobals.szMetaProto)
break;
if (pPs->hContact != (HANDLE)CallService(MS_MC_GETMETACONTACT, (WPARAM)hContact, NULL))
break;
if (!DB::Setting::GetByte(SET_META_SCAN, TRUE))
break;
}
if (
!mir_stricmp(pdbcws->szSetting, SET_CONTACT_MYHANDLE) ||
!mir_stricmp(pdbcws->szSetting, SET_CONTACT_NICK)
)
{
// force the update of all propertysheetpages
DlgProc(hDlg, PSM_FORCECHANGED, NULL, NULL);
// update the windowtitle
DlgProc(hDlg, HM_SETWINDOWTITLE, NULL, lParam);
}
else if (
!mir_stricmp(pdbcws->szModule, USERINFO) ||
!mir_stricmp(pdbcws->szModule, pPs->pszProto) ||
!mir_stricmp(pdbcws->szModule, MOD_MBIRTHDAY)
)
{
// force the update of all propertysheetpages
DlgProc(hDlg, PSM_FORCECHANGED, NULL, NULL);
}
}
break;
case WM_NOTIFY:
switch (wParam) {
//
// Notification Messages sent by the TreeView
//
case STATIC_TREE:
switch (((LPNMHDR)lParam)->code) {
case TVN_SELCHANGING:
{
pPs->dwFlags |= PSF_LOCKED;
pPs->pTree->OnSelChanging();
pPs->dwFlags &= ~PSF_LOCKED;
break;
}
case TVN_SELCHANGED:
if (pPs->dwFlags & PSF_INITIALIZED) {
pPs->dwFlags |= PSF_LOCKED;
pPs->pTree->OnSelChanged((LPNMTREEVIEW)lParam);
if (pPs->pTree->CurrentItem())
{
RECT rc;
POINT pt = { 0, 0 };
GetWindowRect(GetDlgItem(hDlg, IDC_PAGETITLE), &rc);
ScreenToClient(hDlg, &pt);
OffsetRect(&rc, pt.x, pt.y);
SetDlgItemText(hDlg, IDC_PAGETITLE, pPs->pTree->CurrentItem()->Label());
InvalidateRect(GetDlgItem(hDlg, IDC_PAGETITLEBG), &rc, TRUE);
InvalidateRect(hDlg, &rc, TRUE);
}
pPs->dwFlags &= ~PSF_LOCKED;
}
break;
case TVN_BEGINDRAG:
{
LPNMTREEVIEW nmtv = (LPNMTREEVIEW)lParam;
if (nmtv->itemNew.hItem == TreeView_GetSelection(nmtv->hdr.hwndFrom)) {
SetCapture(hDlg);
pPs->pTree->BeginDrag(nmtv->itemNew.hItem);
}
TreeView_SelectItem(nmtv->hdr.hwndFrom, nmtv->itemNew.hItem);
break;
}
case TVN_ITEMEXPANDED:
pPs->pTree->AddFlags(PSTVF_STATE_CHANGED);
break;
case NM_KILLFOCUS:
KillTimer(hDlg, TIMERID_RENAME);
break;
case NM_CLICK:
{
TVHITTESTINFO hti;
GetCursorPos(&hti.pt);
ScreenToClient(pPs->pTree->Window(), &hti.pt);
TreeView_HitTest(pPs->pTree->Window(), &hti);
if ((hti.flags & (TVHT_ONITEM|TVHT_ONITEMRIGHT)) && hti.hItem == TreeView_GetSelection(pPs->pTree->Window()))
SetTimer(hDlg, TIMERID_RENAME, 500, NULL);
break;
}
case NM_RCLICK:
pPs->pTree->PopupMenu();
return 0;
}
break;
}
break;
case WM_MOUSEMOVE:
if (pPs->pTree->IsDragging()) {
TVHITTESTINFO hti;
hti.pt.x = (SHORT)LOWORD(lParam);
hti.pt.y = (SHORT)HIWORD(lParam);
MapWindowPoints(hDlg, pPs->pTree->Window(), &hti.pt, 1);
TreeView_HitTest(pPs->pTree->Window(), &hti);
if (hti.flags & (TVHT_ONITEM|TVHT_ONITEMRIGHT)) {
RECT rc;
BYTE height;
// check where over the item, the pointer is
if (TreeView_GetItemRect(pPs->pTree->Window(), hti.hItem, &rc, FALSE)) {
height = (BYTE)(rc.bottom - rc.top);
if (hti.pt.y - (height / 3) < rc.top) {
SetCursor(LoadCursor(NULL, IDC_ARROW));
TreeView_SetInsertMark(pPs->pTree->Window(), hti.hItem, 0);
}
else
if (hti.pt.y + (height / 3) > rc.bottom) {
SetCursor(LoadCursor(NULL, IDC_ARROW));
TreeView_SetInsertMark(pPs->pTree->Window(), hti.hItem, 1);
}
else {
TreeView_SetInsertMark(pPs->pTree->Window(), NULL, 0);
SetCursor(LoadCursor(ghInst, MAKEINTRESOURCE(CURSOR_ADDGROUP)));
}
}
}
else {
if (hti.flags & TVHT_ABOVE) SendMessage(pPs->pTree->Window(), WM_VSCROLL, MAKEWPARAM(SB_LINEUP, 0), 0);
if (hti.flags & TVHT_BELOW) SendMessage(pPs->pTree->Window(), WM_VSCROLL, MAKEWPARAM(SB_LINEDOWN, 0), 0);
TreeView_SetInsertMark(pPs->pTree->Window(), NULL, 0);
}
}
break;
case WM_LBUTTONUP:
// drop item
if (pPs->pTree->IsDragging()) {
TVHITTESTINFO hti;
RECT rc;
BYTE height;
BOOLEAN bAsChild = FALSE;
TreeView_SetInsertMark(pPs->pTree->Window(), NULL, 0);
ReleaseCapture();
SetCursor(LoadCursor(NULL, IDC_ARROW));
hti.pt.x = (SHORT)LOWORD(lParam);
hti.pt.y = (SHORT)HIWORD(lParam);
MapWindowPoints(hDlg, pPs->pTree->Window(), &hti.pt, 1);
TreeView_HitTest(pPs->pTree->Window(), &hti);
if (hti.hItem == pPs->pTree->DragItem()) {
pPs->pTree->EndDrag();
break;
}
if (hti.flags & TVHT_ABOVE) {
hti.hItem = TVI_FIRST;
}
else
if (hti.flags & (TVHT_NOWHERE|TVHT_BELOW)) {
hti.hItem = TVI_LAST;
}
else
if (hti.flags & (TVHT_ONITEM|TVHT_ONITEMRIGHT)) {
// check where over the item, the pointer is
if (!TreeView_GetItemRect(pPs->pTree->Window(), hti.hItem, &rc, FALSE)) {
pPs->pTree->EndDrag();
break;
}
height = (BYTE)(rc.bottom - rc.top);
if (hti.pt.y - (height / 3) < rc.top) {
HTREEITEM hItem = hti.hItem;
if (!(hti.hItem = TreeView_GetPrevSibling(pPs->pTree->Window(), hItem))) {
if (!(hti.hItem = TreeView_GetParent(pPs->pTree->Window(), hItem)))
hti.hItem = TVI_FIRST;
else
bAsChild = TRUE;
}
}
else
if (hti.pt.y + (height / 3) <= rc.bottom) {
bAsChild = TRUE;
}
}
pPs->pTree->MoveItem(pPs->pTree->DragItem(), hti.hItem, bAsChild);
pPs->pTree->EndDrag();
}
break;
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDCANCEL:
{
pPs->pTree->OnCancel();
DestroyWindow(hDlg);
break;
}
/**
* name: IDOK / IDAPPLY
* desc: user clicked on apply or ok button in order to save changes
**/
case IDOK:
case IDAPPLY:
if (pPs->dwFlags & PSF_CHANGED) {
// kill focus from children to make sure all data can be saved (ComboboxEx)
SetFocus(hDlg);
pPs->dwFlags |= PSF_LOCKED;
if (pPs->pTree->OnApply()) {
pPs->dwFlags &= ~(PSF_LOCKED|PSF_CHANGED);
break;
}
pPs->dwFlags &= ~PSF_CHANGED;
EnableWindow(GetDlgItem(hDlg, IDAPPLY), FALSE);
CallService(MS_CLIST_INVALIDATEDISPLAYNAME, (WPARAM)pPs->hContact, NULL);
// need to upload owners settings
if (!pPs->hContact && myGlobals.CanChangeDetails && DB::Setting::GetByte(SET_PROPSHEET_CHANGEMYDETAILS, FALSE)) {
if (pPs->pUpload = new CPsUpload(pPs, LOWORD(wParam) == IDOK)) {
if (pPs->pUpload->UploadFirst() == CPsUpload::UPLOAD_CONTINUE)
break;
MIR_DELETE(pPs->pUpload);
}
}
pPs->dwFlags &= ~PSF_LOCKED;
}
if (LOWORD(wParam) == IDOK)
DestroyWindow(hDlg);
break;
case BTN_UPDATE:
{
if (pPs->hContact != NULL)
{
ResetUpdateInfo(pPs);
mir_snprintf(pPs->szUpdating, SIZEOF(pPs->szUpdating),
"%s (%s)", Translate("Updating"), pPs->pszProto);
// need meta contact's subcontact information
if (DB::Module::IsMetaAndScan(pPs->pszProto))
{
HANDLE hSubContact;
CHAR szService[MAXSETTING];
INT i, numSubs;
numSubs = DB::MetaContact::SubCount(pPs->hContact);
// count valid subcontacts whose protocol supports the PSS_GETINFO service to update the information
for (i = 0; i < numSubs; i++)
{
hSubContact = DB::MetaContact::Sub(pPs->hContact, i);
if (hSubContact != NULL)
{
mir_snprintf(szService, SIZEOF(szService), "%s%s",
DB::Contact::Proto(hSubContact), PSS_GETINFO);
if (ServiceExists(szService))
{
pPs->infosUpdated = (TAckInfo*)mir_realloc(pPs->infosUpdated, sizeof(TAckInfo) * (pPs->nSubContacts + 1));
pPs->infosUpdated[pPs->nSubContacts].hContact = hSubContact;
pPs->infosUpdated[pPs->nSubContacts].acks = NULL;
pPs->infosUpdated[pPs->nSubContacts].count = 0;
pPs->nSubContacts++;
}
}
}
if (pPs->nSubContacts != 0)
{
BOOLEAN bDo = FALSE;
// call the services
for (i = 0; i < pPs->nSubContacts; i++)
{
if (!CallContactService(pPs->infosUpdated[pPs->nSubContacts].hContact, PSS_GETINFO, NULL, NULL))
{
bDo = TRUE;
}
}
if (bDo)
{
EnableWindow(GetDlgItem(hDlg, BTN_UPDATE), FALSE);
ShowWindow(GetDlgItem(hDlg, TXT_UPDATING), SW_SHOW);
SetTimer(hDlg, TIMERID_UPDATING, 100, NULL);
}
}
}
else if (!CallContactService(pPs->hContact, PSS_GETINFO, NULL, NULL))
{
pPs->infosUpdated = (TAckInfo*)mir_calloc(sizeof(TAckInfo));
pPs->infosUpdated[0].hContact = pPs->hContact;
pPs->nSubContacts = 1;
EnableWindow(GetDlgItem(hDlg, BTN_UPDATE), FALSE);
ShowWindow(GetDlgItem(hDlg, TXT_UPDATING), SW_SHOW);
SetTimer(hDlg, TIMERID_UPDATING, 100, NULL);
}
}
}
break;
case BTN_IMPORT:
svcExIm_ContactImport_Service((WPARAM) pPs->hContact, 0);
break;
case BTN_EXPORT:
// save changes before exporting data
DlgProc(hDlg, WM_COMMAND, MAKEWPARAM(IDAPPLY, BN_CLICKED), (LPARAM)GetDlgItem(hDlg, IDAPPLY));
// do the exporting stuff
svcExIm_ContactExport_Service((WPARAM) pPs->hContact, 0);
break;
}
break;
case WM_CLOSE:
DlgProc(hDlg, WM_COMMAND, MAKEWPARAM(IDCANCEL, BN_CLICKED), (LPARAM)GetDlgItem(hDlg, IDCANCEL));
break;
case WM_DESTROY:
{
INT i = 0;
// hide before destroy
ShowWindow(hDlg, SW_HIDE);
ResetUpdateInfo(pPs);
// avoid any further message processing for this dialog page
WindowList_Remove(ghWindowList, hDlg);
SetUserData(hDlg, NULL);
// unhook events and stop timers
KillTimer(hDlg, TIMERID_RENAME);
UnhookEvent(pPs->hProtoAckEvent);
UnhookEvent(pPs->hSettingChanged);
UnhookEvent(pPs->hIconsChanged);
// save my window position
Utils_SaveWindowPosition(hDlg, NULL, MODNAME, "DetailsDlg");
// save current tree and destroy it
if (pPs->pTree != NULL) {
// save tree's current look
pPs->pTree->SaveState();
delete pPs->pTree;
pPs->pTree = NULL;
}
DeleteObject(pPs->hCaptionFont);
DeleteObject(pPs->hBoldFont);
mir_free(pPs); pPs = NULL;
MagneticWindows_RemoveWindow(hDlg);
}
}
return FALSE;
}
|