Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

[r5079]: trunk / pwsafe / pwsafe / src / ui / Windows / MainView.cpp Maximize Restore History

Download this file

MainView.cpp    4565 lines (3973 with data), 141.8 kB

   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
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
/*
* Copyright (c) 2003-2012 Rony Shapiro <ronys@users.sourceforge.net>.
* All rights reserved. Use of the code is allowed under the
* Artistic License 2.0 terms, as specified in the LICENSE file
* distributed with this code, or available from
* http://www.opensource.org/licenses/artistic-license-2.0.php
*/
/// file MainView.cpp
//
// View-related methods of DboxMain
//-----------------------------------------------------------------------------
#include "PasswordSafe.h"
#include "ThisMfcApp.h"
#include "AddEdit_PropertySheet.h"
#include "DboxMain.h"
#include "TryAgainDlg.h"
#include "ColumnChooserDlg.h"
#include "GeneralMsgBox.h"
#include "FontsDialog.h"
#include "Fonts.h"
#include "InfoDisplay.h"
#include "ViewReport.h"
#include "ExpPWListDlg.h"
#include "VirtualKeyboard/VKeyBoardDlg.h"
#include "core/pwsprefs.h"
#include "core/core.h"
#include "core/PWHistory.h"
#include "core/StringXStream.h"
#include "os/Debug.h"
#include "os/dir.h"
#include "os/run.h"
#include "os/logit.h"
#if defined(POCKET_PC)
#include "pocketpc/resource.h"
#else
#include "resource.h"
#include "resource2.h" // Menu, Toolbar & Accelerator resources
#include "resource3.h" // String resources
#endif
#include "commctrl.h"
#include <shlwapi.h>
#include <vector>
#include <algorithm>
#include <sys/stat.h>
using namespace std;
using pws_os::CUUID;
extern const wchar_t *GROUP_SEP2;
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
void DboxMain::DatabaseModified(bool bChanged)
{
PWS_LOGIT_ARGS("bChanged=%s", bChanged ? _T("true") : _T("false"));
// Callback from PWScore if the database has been changed
// entries or preferences stored in the database
// Callback from PWScore if the password list has been changed,
// invalidating the indices vector in Find
InvalidateSearch();
OnHideFindToolBar();
// This is to prevent Windows (Vista & later) from shutting down
// if the database has been modified (including preferences stored in the DB)
static bool bCurrentState(false);
// Don't do anything if status unchanged or not at least Vista
if (m_WindowsMajorVersion < 6 ||
m_core.IsReadOnly() || bChanged == bCurrentState)
return;
bCurrentState = bChanged;
// Only supported on Vista and later
if (bCurrentState) {
if (m_pfcnShutdownBlockReasonCreate != NULL) {
CString cs_stopreason;
cs_stopreason.Format(IDS_STOPREASON, m_core.GetCurFile().c_str());
m_pfcnShutdownBlockReasonCreate(m_hWnd, cs_stopreason);
m_bBlockShutdown = true;
}
} else {
if (m_pfcnShutdownBlockReasonDestroy != NULL) {
m_pfcnShutdownBlockReasonDestroy(m_hWnd);
m_bBlockShutdown = false;
}
}
}
void DboxMain::UpdateGUI(UpdateGUICommand::GUI_Action ga,
const CUUID &entry_uuid, CItemData::FieldType ft,
bool bUpdateGUI)
{
// Callback from PWScore if GUI needs updating
// Note: For some values of 'ga', 'ci' & ft are invalid and not used.
// "bUpdateGUI" is only used by GUI_DELETE_ENTRY when called as part
// of the Edit Entry Command where the entry is deleted and then added and
// the GUI should not be updated until after the Add.
CItemData *pci(NULL);
ItemListIter pos = Find(entry_uuid);
if (pos != End()) {
pci = &pos->second;
}
PWSprefs *prefs = PWSprefs::GetInstance();
switch (ga) {
case UpdateGUICommand::GUI_UPDATE_STATUSBAR:
if (app.GetBaseThreadID() == AfxGetThread()->m_nThreadID) {
// Can't do UI from a worker thread - so check if it is the main thread!
UpdateToolBarDoUndo();
UpdateStatusBar();
}
break;
case UpdateGUICommand::GUI_ADD_ENTRY:
AddToGUI(*pci);
break;
case UpdateGUICommand::GUI_DELETE_ENTRY:
RemoveFromGUI(*pci, bUpdateGUI);
break;
case UpdateGUICommand::GUI_REFRESH_ENTRYFIELD:
RefreshEntryFieldInGUI(*pci, ft);
break;
case UpdateGUICommand::GUI_REFRESH_ENTRYPASSWORD:
RefreshEntryPasswordInGUI(*pci);
break;
case UpdateGUICommand::GUI_REDO_IMPORT:
case UpdateGUICommand::GUI_UNDO_IMPORT:
case UpdateGUICommand::GUI_REDO_MERGESYNC:
case UpdateGUICommand::GUI_UNDO_MERGESYNC:
// During these processes, many entries may be added/removed
// To stop the UI going nuts, updates to the UI are suspended until
// the action is complete - when these calls are then sent
RebuildGUI();
break;
case UpdateGUICommand::GUI_PWH_CHANGED_IN_DB:
// During this process, many entries may have been edited (marked modified)
if (prefs->GetPref(PWSprefs::HighlightChanges))
RebuildGUI();
break;
case UpdateGUICommand::GUI_REFRESH_TREE:
// Rebuid the entire tree view
RebuildGUI(iTreeOnly);
break;
case UpdateGUICommand::GUI_DB_PREFERENCES_CHANGED:
// Change any impact on the application due to a database preference change
// Currently - only Idle Timeout values and potentially whether the
// user/password is shown in the Tree view
KillTimer(TIMER_LOCKDBONIDLETIMEOUT);
ResetIdleLockCounter();
if (prefs->GetPref(PWSprefs::LockDBOnIdleTimeout)) {
SetTimer(TIMER_LOCKDBONIDLETIMEOUT, IDLE_CHECK_INTERVAL, NULL);
}
RebuildGUI(iTreeOnly);
break;
default:
break;
}
}
void DboxMain::UpdateGUIDisplay()
{
ChangeOkUpdate();
RefreshViews();
// May need to update menu/toolbar if original database was empty
UpdateMenuAndToolBar(m_bOpen);
}
// Called from PWScore to get GUI to update its reserved field
void DboxMain::GUISetupDisplayInfo(CItemData &ci)
{
ci.SetDisplayInfo(new DisplayInfo);
}
void DboxMain::GUIRefreshEntry(const CItemData &ci)
{
UpdateEntryImages(ci);
}
void DboxMain::UpdateWizard(const stringT &s)
{
if (m_pWZWnd != NULL)
m_pWZWnd->SetWindowText(s.c_str());
}
//-----------------------------------------------------------------------------
/*
* Compare function used by m_ctlItemList.SortItems()
* "The comparison function must return a negative value if the first item should precede
* the second, a positive value if the first item should follow the second, or zero if
* the two items are equivalent."
*
* If sorting is by group (title/user), title (username), username (title)
* fields in brackets are the secondary fields if the primary fields are identical.
*/
int CALLBACK DboxMain::CompareFunc(LPARAM lParam1, LPARAM lParam2,
LPARAM closure)
{
// closure is "this" of the calling DboxMain, from which we use:
// m_iTypeSortColumn to determine which column is getting sorted
// which is by column data TYPE and NOT by column index!
// m_bSortAscending to determine the direction of the sort (duh)
DboxMain *self = (DboxMain *)closure;
ASSERT(self != NULL);
const int nTypeSortColumn = self->m_iTypeSortColumn;
CItemData* pLHS_PCI = (CItemData *)lParam1;
CItemData* pRHS_PCI = (CItemData *)lParam2;
StringX group1, group2;
time_t t1, t2;
int xint1, xint2;
int iResult(0);
switch (nTypeSortColumn) {
case CItemData::UUID: // Image
if (pLHS_PCI->GetEntryType() != pRHS_PCI->GetEntryType())
iResult = (pLHS_PCI->GetEntryType() < pRHS_PCI->GetEntryType()) ? -1 : 1;
break;
case CItemData::GROUP:
group1 = pLHS_PCI->GetGroup();
group2 = pRHS_PCI->GetGroup();
if (group1.empty()) // root?
group1 = L"\xff";
if (group2.empty()) // root?
group2 = L"\xff";
iResult = CompareNoCase(group1, group2);
if (iResult == 0) {
iResult = CompareNoCase(pLHS_PCI->GetTitle(), pRHS_PCI->GetTitle());
if (iResult == 0) {
iResult = CompareNoCase(pLHS_PCI->GetUser(), pRHS_PCI->GetUser());
}
}
break;
case CItemData::TITLE:
iResult = CompareNoCase(pLHS_PCI->GetTitle(), pRHS_PCI->GetTitle());
if (iResult == 0) {
iResult = CompareNoCase(pLHS_PCI->GetUser(), pRHS_PCI->GetUser());
}
break;
case CItemData::USER:
iResult = CompareNoCase(pLHS_PCI->GetUser(), pRHS_PCI->GetUser());
if (iResult == 0) {
iResult = CompareNoCase(pLHS_PCI->GetTitle(), pRHS_PCI->GetTitle());
}
break;
case CItemData::NOTES:
iResult = CompareNoCase(pLHS_PCI->GetNotes(), pRHS_PCI->GetNotes());
break;
case CItemData::PASSWORD:
iResult = CompareNoCase(pLHS_PCI->GetPassword(), pRHS_PCI->GetPassword());
break;
case CItemData::URL:
iResult = CompareNoCase(pLHS_PCI->GetURL(), pRHS_PCI->GetURL());
break;
case CItemData::EMAIL:
iResult = CompareNoCase(pLHS_PCI->GetEmail(), pRHS_PCI->GetEmail());
break;
case CItemData::SYMBOLS:
iResult = CompareNoCase(pLHS_PCI->GetSymbols(), pRHS_PCI->GetSymbols());
break;
case CItemData::RUNCMD:
iResult = CompareNoCase(pLHS_PCI->GetRunCommand(), pRHS_PCI->GetRunCommand());
break;
case CItemData::AUTOTYPE:
iResult = CompareNoCase(pLHS_PCI->GetAutoType(), pRHS_PCI->GetAutoType());
break;
case CItemData::CTIME:
pLHS_PCI->GetCTime(t1);
pRHS_PCI->GetCTime(t2);
if (t1 != t2)
iResult = ((long)t1 < (long)t2) ? -1 : 1;
break;
case CItemData::PMTIME:
pLHS_PCI->GetPMTime(t1);
if (t1 == 0)
pLHS_PCI->GetCTime(t1);
pRHS_PCI->GetPMTime(t2);
if (t2 == 0)
pRHS_PCI->GetCTime(t2);
if (t1 != t2)
iResult = ((long)t1 < (long)t2) ? -1 : 1;
break;
case CItemData::ATIME:
pLHS_PCI->GetATime(t1);
pRHS_PCI->GetATime(t2);
if (t1 != t2)
iResult = ((long)t1 < (long)t2) ? -1 : 1;
break;
case CItemData::XTIME:
pLHS_PCI->GetXTime(t1);
pRHS_PCI->GetXTime(t2);
if (t1 != t2)
iResult = ((long)t1 < (long)t2) ? -1 : 1;
break;
case CItemData::XTIME_INT:
pLHS_PCI->GetXTimeInt(xint1);
pRHS_PCI->GetXTimeInt(xint2);
if (xint1 != xint2)
iResult = (xint1 < xint2) ? -1 : 1;
break;
case CItemData::RMTIME:
pLHS_PCI->GetRMTime(t1);
if (t1 == 0)
pLHS_PCI->GetCTime(t1);
pRHS_PCI->GetRMTime(t2);
if (t2 == 0)
pRHS_PCI->GetCTime(t2);
if (t1 != t2)
iResult = ((long)t1 < (long)t2) ? -1 : 1;
break;
case CItemData::POLICY:
iResult = CompareNoCase(pLHS_PCI->GetPWPolicy(), pRHS_PCI->GetPWPolicy());
break;
case CItemData::POLICYNAME:
iResult = CompareCase(pLHS_PCI->GetPolicyName(), pRHS_PCI->GetPolicyName());
break;
case CItemData::PROTECTED:
if (pLHS_PCI->IsProtected() != pRHS_PCI->IsProtected())
iResult = pLHS_PCI->IsProtected() ? 1 : -1;
break;
default:
ASSERT(FALSE);
}
if (!self->m_bSortAscending && iResult != 0) {
iResult *= -1;
}
return iResult;
}
void DboxMain::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(DboxMain)
DDX_Control(pDX, IDC_ITEMLIST, m_ctlItemList);
DDX_Control(pDX, IDC_ITEMTREE, m_ctlItemTree);
DDX_Control(pDX, IDC_STATIC_DRAGGROUP, m_DDGroup);
DDX_Control(pDX, IDC_STATIC_DRAGTITLE, m_DDTitle);
DDX_Control(pDX, IDC_STATIC_DRAGUSER, m_DDUser);
DDX_Control(pDX, IDC_STATIC_DRAGPASSWORD, m_DDPassword);
DDX_Control(pDX, IDC_STATIC_DRAGNOTES, m_DDNotes);
DDX_Control(pDX, IDC_STATIC_DRAGURL, m_DDURL);
DDX_Control(pDX, IDC_STATIC_DRAGEMAIL, m_DDemail);
DDX_Control(pDX, IDC_STATIC_DRAGAUTO, m_DDAutotype);
//}}AFX_DATA_MAP
}
void DboxMain::UpdateToolBarROStatus(const bool bIsRO)
{
if (m_toolbarsSetup == TRUE) {
BOOL State = bIsRO ? FALSE : TRUE;
BOOL SaveState = (!bIsRO && (m_core.IsChanged() || m_core.HaveDBPrefsChanged())) ? TRUE : FALSE;
CToolBarCtrl& mainTBCtrl = m_MainToolBar.GetToolBarCtrl();
mainTBCtrl.EnableButton(ID_MENUITEM_ADD, State);
mainTBCtrl.EnableButton(ID_MENUITEM_DELETEENTRY, State);
mainTBCtrl.EnableButton(ID_MENUITEM_SAVE, SaveState);
}
}
void DboxMain::UpdateToolBarForSelectedItem(const CItemData *pci)
{
// Following test required since this can be called on exit, with a pci
// from ItemData that's already been deleted. Ugh.
const CItemData *pci_entry(pci);
if (m_core.GetNumEntries() != 0) {
BOOL State = (pci_entry == NULL) ? FALSE : TRUE;
int IDs[] = {ID_MENUITEM_COPYPASSWORD, ID_MENUITEM_COPYUSERNAME,
ID_MENUITEM_COPYNOTESFLD, ID_MENUITEM_AUTOTYPE,
ID_MENUITEM_RUNCOMMAND, ID_MENUITEM_EDIT,
ID_MENUITEM_PASSWORDSUBSET};
CToolBarCtrl& mainTBCtrl = m_MainToolBar.GetToolBarCtrl();
for (int i = 0; i < _countof(IDs); i++) {
mainTBCtrl.EnableButton(IDs[i], State);
}
mainTBCtrl.EnableButton(ID_MENUITEM_UNDO, m_core.AnyToUndo() ? TRUE : FALSE);
mainTBCtrl.EnableButton(ID_MENUITEM_REDO, m_core.AnyToRedo() ? TRUE : FALSE);
if (pci_entry != NULL && pci_entry->IsShortcut()) {
pci_entry = GetBaseEntry(pci_entry);
}
if (pci_entry == NULL || pci_entry->IsUserEmpty()) {
mainTBCtrl.EnableButton(ID_MENUITEM_COPYUSERNAME, FALSE);
} else {
mainTBCtrl.EnableButton(ID_MENUITEM_COPYUSERNAME, TRUE);
}
if (pci_entry == NULL || pci_entry->IsNotesEmpty()) {
mainTBCtrl.EnableButton(ID_MENUITEM_COPYNOTESFLD, FALSE);
} else {
mainTBCtrl.EnableButton(ID_MENUITEM_COPYNOTESFLD, TRUE);
}
if (pci_entry == NULL || pci_entry->IsRunCommandEmpty()) {
mainTBCtrl.EnableButton(ID_MENUITEM_RUNCOMMAND, FALSE);
} else {
mainTBCtrl.EnableButton(ID_MENUITEM_RUNCOMMAND, TRUE);
}
if (pci_entry == NULL ||
(pci_entry->IsEmailEmpty() && !pci_entry->IsURLEmail())) {
mainTBCtrl.EnableButton(ID_MENUITEM_SENDEMAIL, FALSE);
} else {
mainTBCtrl.EnableButton(ID_MENUITEM_SENDEMAIL, TRUE);
}
if (pci_entry == NULL || pci_entry->IsURLEmpty() || pci_entry->IsURLEmail()) {
mainTBCtrl.EnableButton(ID_MENUITEM_BROWSEURL, FALSE);
mainTBCtrl.EnableButton(ID_MENUITEM_BROWSEURLPLUS, FALSE);
} else {
mainTBCtrl.EnableButton(ID_MENUITEM_BROWSEURL, TRUE);
mainTBCtrl.EnableButton(ID_MENUITEM_BROWSEURLPLUS, TRUE);
}
bool bDragBarState = PWSprefs::GetInstance()->GetPref(PWSprefs::ShowDragbar);
if (bDragBarState) {
// Note: Title & Password are mandatory
if (pci_entry == NULL) {
m_DDGroup.SetStaticState(m_core.GetNumEntries() != 0);
m_DDTitle.SetStaticState(false);
m_DDPassword.SetStaticState(false);
m_DDUser.SetStaticState(false);
m_DDNotes.SetStaticState(false);
m_DDURL.SetStaticState(false);
m_DDemail.SetStaticState(false);
m_DDAutotype.SetStaticState(false);
} else {
m_DDGroup.SetStaticState(!pci_entry->IsGroupEmpty());
m_DDTitle.SetStaticState(true);
m_DDPassword.SetStaticState(true);
m_DDUser.SetStaticState(!pci_entry->IsUserEmpty());
m_DDNotes.SetStaticState(!pci_entry->IsNotesEmpty());
m_DDURL.SetStaticState(!pci_entry->IsURLEmpty());
m_DDemail.SetStaticState(!pci_entry->IsEmailEmpty());
m_DDAutotype.SetStaticState(true);
}
}
}
}
void DboxMain::setupBars()
{
#if !defined(POCKET_PC)
// This code is copied from the DLGCBR32 example that comes with MFC
// Add the status bar
if (m_statusBar.Create(this)) {
// Set up DoubleClickAction text - remove Shift+DCA
const int dca = int(PWSprefs::GetInstance()->GetPref(PWSprefs::DoubleClickAction));
switch (dca) {
case PWSprefs::DoubleClickAutoType:
statustext[CPWStatusBar::SB_DBLCLICK] = IDS_STATAUTOTYPE;
break;
case PWSprefs::DoubleClickBrowse:
statustext[CPWStatusBar::SB_DBLCLICK] = IDS_STATBROWSE;
break;
case PWSprefs::DoubleClickCopyNotes:
statustext[CPWStatusBar::SB_DBLCLICK] = IDS_STATCOPYNOTES;
break;
case PWSprefs::DoubleClickCopyPassword:
statustext[CPWStatusBar::SB_DBLCLICK] = IDS_STATCOPYPASSWORD;
break;
case PWSprefs::DoubleClickCopyUsername:
statustext[CPWStatusBar::SB_DBLCLICK] = IDS_STATCOPYUSERNAME;
break;
case PWSprefs::DoubleClickViewEdit:
statustext[CPWStatusBar::SB_DBLCLICK] = IDS_STATVIEWEDIT;
break;
case PWSprefs::DoubleClickCopyPasswordMinimize:
statustext[CPWStatusBar::SB_DBLCLICK] = IDS_STATCOPYPASSWORDMIN;
break;
case PWSprefs::DoubleClickBrowsePlus:
statustext[CPWStatusBar::SB_DBLCLICK] = IDS_STATBROWSEPLUS;
break;
case PWSprefs::DoubleClickRun:
statustext[CPWStatusBar::SB_DBLCLICK] = IDS_STATRUN;
break;
case PWSprefs::DoubleClickSendEmail:
statustext[CPWStatusBar::SB_DBLCLICK] = IDS_STATSENDEMAIL;
break;
default:
statustext[CPWStatusBar::SB_DBLCLICK] = IDS_STATCOMPANY;
}
statustext[CPWStatusBar::SB_CLIPBOARDACTION] = IDS_BLANK;
// Set up Configuration source indicator (debug only)
#if defined(_DEBUG) || defined(DEBUG)
statustext[CPWStatusBar::SB_CONFIG] = PWSprefs::GetInstance()->GetConfigIndicator();
#endif /* DEBUG */
// Set up the rest - all but one empty as pane now re-sized according to contents
statustext[CPWStatusBar::SB_MODIFIED] = IDS_BLANK;
statustext[CPWStatusBar::SB_NUM_ENT] = IDS_BLANK;
statustext[CPWStatusBar::SB_FILTER] = IDS_BLANK;
statustext[CPWStatusBar::SB_READONLY] = IDS_READ_ONLY;
// And show
m_statusBar.SetIndicators(statustext, CPWStatusBar::SB_TOTAL);
UINT uiID, uiStyle;
int cxWidth;
m_statusBar.GetPaneInfo(CPWStatusBar::SB_FILTER, uiID,
uiStyle, cxWidth);
int iBMWidth = m_statusBar.GetBitmapWidth();
m_statusBar.SetPaneInfo(CPWStatusBar::SB_FILTER, uiID,
uiStyle | SBT_OWNERDRAW, iBMWidth);
// Make a sunken or recessed border around the first pane
m_statusBar.SetPaneInfo(CPWStatusBar::SB_DBLCLICK,
m_statusBar.GetItemID(CPWStatusBar::SB_DBLCLICK),
SBPS_STRETCH, NULL);
}
CDC* pDC = this->GetDC();
int NumBits = (pDC ? pDC->GetDeviceCaps(12 /*BITSPIXEL*/) : 32);
m_MainToolBar.Init(NumBits);
m_FindToolBar.Init(NumBits, this, PWS_MSG_TOOLBAR_FIND,
&m_SaveAdvValues[CAdvancedDlg::FIND]);
ReleaseDC(pDC);
// Add the Main ToolBar.
if (!m_MainToolBar.CreateEx(this, TBSTYLE_FLAT | TBSTYLE_TRANSPARENT,
WS_CHILD | WS_VISIBLE | CCS_ADJUSTABLE |
CBRS_TOP | CBRS_SIZE_DYNAMIC,
CRect(0, 0, 0, 0), AFX_IDW_RESIZE_BAR + 1)) {
pws_os::Trace(L"Failed to create Main toolbar\n");
return; // fail to create
}
DWORD dwStyle = m_MainToolBar.GetBarStyle();
dwStyle = dwStyle | CBRS_BORDER_BOTTOM | CBRS_BORDER_TOP |
CBRS_BORDER_LEFT | CBRS_BORDER_RIGHT |
CBRS_TOOLTIPS | CBRS_FLYBY;
m_MainToolBar.SetBarStyle(dwStyle);
m_MainToolBar.SetWindowText(L"Standard");
// Add the Find ToolBar.
if (!m_FindToolBar.CreateEx(this, TBSTYLE_FLAT | TBSTYLE_TRANSPARENT,
WS_CHILD | WS_VISIBLE |
CBRS_BOTTOM | CBRS_SIZE_DYNAMIC,
CRect(0, 0, 0, 0), AFX_IDW_RESIZE_BAR + 2)) {
pws_os::Trace(L"Failed to create Find toolbar\n");
return; // fail to create
}
dwStyle = m_FindToolBar.GetBarStyle();
dwStyle = dwStyle | CBRS_BORDER_BOTTOM | CBRS_BORDER_TOP |
CBRS_BORDER_LEFT | CBRS_BORDER_RIGHT |
CBRS_TOOLTIPS | CBRS_FLYBY;
m_FindToolBar.SetBarStyle(dwStyle);
m_FindToolBar.SetWindowText(L"Find");
// Set dragbar & toolbar according to graphic capabilities, overridable by user choice.
if (NumBits < 16 || !PWSprefs::GetInstance()->GetPref(PWSprefs::UseNewToolbar)) {
SetToolbar(ID_MENUITEM_OLD_TOOLBAR, true);
} else {
SetToolbar(ID_MENUITEM_NEW_TOOLBAR, true);
}
m_FindToolBar.ShowFindToolBar(false);
// Set flag - we're done
m_toolbarsSetup = TRUE;
m_MainToolBar.ShowWindow(PWSprefs::GetInstance()->GetPref(PWSprefs::ShowToolbar) ?
SW_SHOW : SW_HIDE);
UpdateToolBarROStatus(m_core.IsReadOnly());
m_menuManager.SetImageList(&m_MainToolBar);
m_menuManager.SetMapping(&m_MainToolBar);
m_DDGroup.EnableWindow(TRUE);
m_DDGroup.ShowWindow(SW_SHOW);
m_DDTitle.EnableWindow(TRUE);
m_DDTitle.ShowWindow(SW_SHOW);
m_DDUser.EnableWindow(TRUE);
m_DDUser.ShowWindow(SW_SHOW);
m_DDPassword.EnableWindow(TRUE);
m_DDPassword.ShowWindow(SW_SHOW);
m_DDNotes.EnableWindow(TRUE);
m_DDNotes.ShowWindow(SW_SHOW);
m_DDURL.EnableWindow(TRUE);
m_DDURL.ShowWindow(SW_SHOW);
m_DDemail.EnableWindow(TRUE);
m_DDemail.ShowWindow(SW_SHOW);
m_DDAutotype.EnableWindow(TRUE);
m_DDAutotype.ShowWindow(SW_SHOW);
#endif
}
void DboxMain::UpdateListItem(const int lindex, const int type, const StringX &newText)
{
int iSubItem = m_nColumnIndexByType[type];
// Ignore if this column is not being displayed
if (iSubItem < 0)
return;
BOOL brc = m_ctlItemList.SetItemText(lindex, iSubItem, newText.c_str());
ASSERT(brc == TRUE);
if (m_iTypeSortColumn == type) { // resort if necessary
m_bSortAscending = PWSprefs::GetInstance()->GetPref(PWSprefs::SortAscending);
m_ctlItemList.SortItems(CompareFunc, (LPARAM)this);
FixListIndexes();
}
}
void DboxMain::UpdateTreeItem(const HTREEITEM hItem, const StringX &newText)
{
CRect rect;
m_ctlItemTree.SetItemText(hItem, newText.c_str());
m_ctlItemTree.GetItemRect(hItem, &rect, FALSE);
m_ctlItemTree.InvalidateRect(&rect);
}
// Find in m_pwlist entry with same title and user name as the i'th entry in m_ctlItemList
ItemListIter DboxMain::Find(int i)
{
CItemData *pci = (CItemData *)m_ctlItemList.GetItemData(i);
ASSERT(pci != NULL);
const StringX curGroup = pci->GetGroup();
const StringX curTitle = pci->GetTitle();
const StringX curUser = pci->GetUser();
return Find(curGroup, curTitle, curUser);
}
/*
* Finds all entries in m_pwlist that contain str in any text
* field, returns their sorted indices in m_listctrl via indices, which is
* assumed to be allocated by caller to DboxMain::GetNumEntries() ints.
* FindAll returns the number of entries that matched.
*/
size_t DboxMain::FindAll(const CString &str, BOOL CaseSensitive,
vector<int> &indices)
{
CItemData::FieldBits bsFields;
bsFields.set(); // Default search is all text fields!
return FindAll(str, CaseSensitive, indices, bsFields, false,
L"", 0, 0);
}
size_t DboxMain::FindAll(const CString &str, BOOL CaseSensitive,
vector<int> &indices,
const CItemData::FieldBits &bsFields, const bool &subgroup_bset,
const std::wstring &subgroup_name, const int subgroup_object,
const int subgroup_function)
{
ASSERT(!str.IsEmpty());
ASSERT(indices.empty());
StringX curGroup, curTitle, curUser, curNotes, curPassword, curURL, curAT, curXInt;
StringX curEmail, curSymbols, curPolicyName, curRunCommand, listTitle, saveTitle;
bool bFoundit;
CString searchstr(str); // Since str is const, and we might need to MakeLower
size_t retval = 0;
if (!CaseSensitive)
searchstr.MakeLower();
int ititle(-1); // Must be there as it is mandatory!
for (int ic = 0; ic < m_nColumns; ic++) {
if (m_nColumnTypeByIndex[ic] == CItemData::TITLE) {
ititle = ic;
break;
}
}
ItemListConstIter listPos, listEnd;
OrderedItemList orderedItemList;
OrderedItemList::const_iterator olistPos, olistEnd;
if (m_IsListView) {
listPos = m_core.GetEntryIter();
listEnd = m_core.GetEntryEndIter();
} else {
MakeOrderedItemList(orderedItemList);
olistPos = orderedItemList.begin();
olistEnd = orderedItemList.end();
}
while (m_IsListView ? (listPos != listEnd) : (olistPos != olistEnd)) {
const CItemData &curitem = m_IsListView ? listPos->second : *olistPos;
if (subgroup_bset &&
!curitem.Matches(std::wstring(subgroup_name),
subgroup_object, subgroup_function))
goto nextentry;
bFoundit = false;
saveTitle = curTitle = curitem.GetTitle(); // saveTitle keeps orig case
curGroup = curitem.GetGroup();
curUser = curitem.GetUser();
curPassword = curitem.GetPassword();
curNotes = curitem.GetNotes();
curURL = curitem.GetURL();
curEmail = curitem.GetEmail();
curSymbols = curitem.GetSymbols();
curPolicyName = curitem.GetPolicyName();
curRunCommand = curitem.GetRunCommand();
curAT = curitem.GetAutoType();
curXInt = curitem.GetXTimeInt();
if (!CaseSensitive) {
ToLower(curGroup);
ToLower(curTitle);
ToLower(curUser);
ToLower(curPassword);
ToLower(curNotes);
ToLower(curURL);
ToLower(curEmail);
// ToLower(curSymbols); - not needed as contains only symbols
ToLower(curPolicyName);
ToLower(curRunCommand);
ToLower(curAT);
}
// do loop to easily break out as soon as a match is found
// saves more checking if entry already selected
do {
if (bsFields.test(CItemData::GROUP) && ::wcsstr(curGroup.c_str(), searchstr)) {
bFoundit = true;
break;
}
if (bsFields.test(CItemData::TITLE) && ::wcsstr(curTitle.c_str(), searchstr)) {
bFoundit = true;
break;
}
if (bsFields.test(CItemData::USER) && ::wcsstr(curUser.c_str(), searchstr)) {
bFoundit = true;
break;
}
if (bsFields.test(CItemData::PASSWORD) && ::wcsstr(curPassword.c_str(), searchstr)) {
bFoundit = true;
break;
}
if (bsFields.test(CItemData::NOTES) && ::wcsstr(curNotes.c_str(), searchstr)) {
bFoundit = true;
break;
}
if (bsFields.test(CItemData::URL) && ::wcsstr(curURL.c_str(), searchstr)) {
bFoundit = true;
break;
}
if (bsFields.test(CItemData::EMAIL) && ::wcsstr(curEmail.c_str(), searchstr)) {
bFoundit = true;
break;
}
if (bsFields.test(CItemData::SYMBOLS) && ::wcsstr(curSymbols.c_str(), searchstr)) {
bFoundit = true;
break;
}
if (bsFields.test(CItemData::RUNCMD) && ::wcsstr(curRunCommand.c_str(), searchstr)) {
bFoundit = true;
break;
}
if (bsFields.test(CItemData::POLICYNAME) && ::wcsstr(curPolicyName.c_str(), searchstr)) {
bFoundit = true;
break;
}
if (bsFields.test(CItemData::AUTOTYPE) && ::wcsstr(curAT.c_str(), searchstr)) {
bFoundit = true;
break;
}
if (bsFields.test(CItemData::PWHIST)) {
size_t pwh_max, err_num;
PWHistList pwhistlist;
CreatePWHistoryList(curitem.GetPWHistory(), pwh_max, err_num,
pwhistlist, PWSUtil::TMC_XML);
PWHistList::iterator iter;
for (iter = pwhistlist.begin(); iter != pwhistlist.end();
iter++) {
PWHistEntry pwshe = *iter;
if (!CaseSensitive)
ToLower(pwshe.password);
if (::wcsstr(pwshe.password.c_str(), searchstr)) {
bFoundit = true;
break; // break out of for loop
}
}
pwhistlist.clear();
if (bFoundit)
break; // break out of do loop
}
if (bsFields.test(CItemData::XTIME_INT) && ::wcsstr(curXInt.c_str(), searchstr)) {
bFoundit = true;
break;
}
} while(FALSE); // only do it once!
if (bFoundit) {
// Find index in displayed list
DisplayInfo *pdi = (DisplayInfo *)curitem.GetDisplayInfo();
ASSERT(pdi != NULL);
int li = pdi->list_index;
ASSERT(m_ctlItemList.GetItemText(li, ititle) == saveTitle.c_str());
// add to indices, bump retval
indices.push_back(li);
} // match found in m_pwlist
nextentry:
if (m_IsListView)
listPos++;
else
olistPos++;
} // while
retval = indices.size();
// Sort indices if in List View
if (m_IsListView && retval > 1)
sort(indices.begin(), indices.end());
if (!m_IsListView)
orderedItemList.clear();
return retval;
}
//Checks and sees if everything works and something is selected
BOOL DboxMain::SelItemOk()
{
CItemData *pci = getSelectedItem();
return (pci == NULL) ? FALSE : TRUE;
}
BOOL DboxMain::SelectEntry(const int i, BOOL MakeVisible)
{
BOOL retval;
ASSERT(i >= 0);
if (m_ctlItemList.GetItemCount() == 0)
return false;
if (m_ctlItemList.IsWindowVisible()) {
retval = m_ctlItemList.SetItemState(i,
LVIS_FOCUSED | LVIS_SELECTED,
LVIS_FOCUSED | LVIS_SELECTED);
if (MakeVisible) {
m_ctlItemList.EnsureVisible(i, FALSE);
}
m_ctlItemList.Invalidate();
} else { //Tree view active
CItemData *pci = (CItemData *)m_ctlItemList.GetItemData(i);
ASSERT(pci != NULL);
DisplayInfo *pdi = (DisplayInfo *)pci->GetDisplayInfo();
ASSERT(pdi != NULL);
ASSERT(pdi->list_index == i);
// Was there anything selected before?
HTREEITEM hti = m_ctlItemTree.GetSelectedItem();
// NULL means nothing was selected.
if (hti != NULL) {
// Time to remove the old "fake selection" (a.k.a. drop-hilite)
// Make sure to undo "MakeVisible" on the previous selection.
m_ctlItemTree.SetItemState(hti, 0, TVIS_DROPHILITED);
}
retval = m_ctlItemTree.SelectItem(pdi->tree_item);
if (MakeVisible) {
// Following needed to show selection when Find dbox has focus. Ugh.
m_ctlItemTree.SetItemState(pdi->tree_item,
TVIS_DROPHILITED | TVIS_SELECTED,
TVIS_DROPHILITED | TVIS_SELECTED);
}
m_ctlItemTree.Invalidate();
}
return retval;
}
void DboxMain::SelectFirstEntry()
{
if (m_core.GetNumEntries() > 0) {
// Ensure an entry is selected after open
CItemData *pci(NULL);
if (m_ctlItemList.IsWindowVisible()) {
m_ctlItemList.SetItemState(0,
LVIS_FOCUSED | LVIS_SELECTED,
LVIS_FOCUSED | LVIS_SELECTED);
m_ctlItemList.EnsureVisible(0, FALSE);
pci = (CItemData *)m_ctlItemList.GetItemData(0);
} else {
HTREEITEM hitem = m_ctlItemTree.GetFirstVisibleItem();
if (hitem != NULL) {
m_ctlItemTree.SelectItem(hitem);
pci = (CItemData *)m_ctlItemTree.GetItemData(hitem);
}
}
UpdateToolBarForSelectedItem(pci);
SetDCAText(pci);
}
}
BOOL DboxMain::SelectFindEntry(const int i, BOOL MakeVisible)
{
BOOL retval;
if (m_ctlItemList.GetItemCount() == 0)
return FALSE;
CItemData *pci = (CItemData *)m_ctlItemList.GetItemData(i);
ASSERT(pci != NULL);
if (m_ctlItemList.IsWindowVisible()) {
// Unselect all others first
POSITION pos = m_ctlItemList.GetFirstSelectedItemPosition();
while (pos) {
int iIndex = m_ctlItemList.GetNextSelectedItem(pos);
m_ctlItemList.SetItemState(iIndex, 0, LVIS_FOCUSED | LVIS_SELECTED);
}
// Now select found item
retval = m_ctlItemList.SetItemState(i,
LVIS_FOCUSED | LVIS_SELECTED,
LVIS_FOCUSED | LVIS_SELECTED);
m_LastFoundListItem = i;
if (MakeVisible) {
m_ctlItemList.EnsureVisible(i, FALSE);
}
m_ctlItemList.Invalidate();
} else { //Tree view active
DisplayInfo *pdi = (DisplayInfo *)pci->GetDisplayInfo();
ASSERT(pdi != NULL);
ASSERT(pdi->list_index == i);
UnFindItem();
retval = m_ctlItemTree.SelectItem(pdi->tree_item);
if (MakeVisible) {
m_ctlItemTree.SetItemState(pdi->tree_item, TVIS_BOLD, TVIS_BOLD);
m_LastFoundTreeItem = pdi->tree_item;
m_bBoldItem = true;
}
m_ctlItemTree.Invalidate();
}
UpdateToolBarForSelectedItem(pci);
return retval;
}
// Updates m_ctlItemList and m_ctlItemTree from m_pwlist
// updates of windows suspended until all data is in.
void DboxMain::RefreshViews(const int iView)
{
PWS_LOGIT_ARGS("iView=%d", iView);
if (!m_bInitDone)
return;
#if defined(POCKET_PC)
HCURSOR waitCursor = app.LoadStandardCursor(IDC_WAIT);
#endif
if (m_core.GetNumEntries() == 0) {
if (iView & iListOnly) {
if (m_ctlItemList.GetItemCount() > 0) {
m_ctlItemList.SetRedraw(FALSE);
m_ctlItemList.DeleteAllItems();
}
m_ctlItemList.SetRedraw(TRUE);
m_ctlItemList.Invalidate();
}
if (iView & iTreeOnly) {
if (m_ctlItemTree.GetCount () > 0) {
m_ctlItemTree.SetRedraw(FALSE);
m_ctlItemTree.DeleteAllItems();
}
m_ctlItemTree.SetRedraw(TRUE);
m_ctlItemTree.Invalidate();
}
return;
}
m_bNumPassedFiltering = 0;
m_bInRefresh = true;
// can't use LockWindowUpdate 'cause only one window at a time can be locked
if (iView & iListOnly) {
m_ctlItemList.SetRedraw(FALSE);
m_ctlItemList.DeleteAllItems();
}
if (iView & iTreeOnly) {
m_ctlItemTree.SetRedraw(FALSE);
m_mapGroupToTreeItem.clear();
m_ctlItemTree.DeleteAllItems();
}
m_bBoldItem = false;
if (m_core.GetNumEntries() != 0) {
ItemListIter listPos;
#if defined(POCKET_PC)
SetCursor(waitCursor);
#endif
for (listPos = m_core.GetEntryIter(); listPos != m_core.GetEntryEndIter();
listPos++) {
CItemData &ci = m_core.GetEntry(listPos);
DisplayInfo *pdi = (DisplayInfo *)ci.GetDisplayInfo();
if (pdi != NULL)
pdi->list_index = -1; // easier, but less efficient, to delete pdi
InsertItemIntoGUITreeList(ci, -1, false, iView);
}
// Need to add any empty groups into the view
std::vector<StringX> vEmptyGroups = m_core.GetEmptyGroups();
for (size_t n = 0; n < vEmptyGroups.size(); n++) {
bool bAlreadyExists;
m_ctlItemTree.AddGroup(vEmptyGroups[n].c_str(), bAlreadyExists);
}
m_ctlItemTree.SortTree(TVI_ROOT);
SortListView();
#if defined(POCKET_PC)
SetCursor(NULL);
#endif
} // we have entries
if (m_bImageInLV) {
m_ctlItemList.SetColumnWidth(0, LVSCW_AUTOSIZE);
}
// re-enable and force redraw!
if (iView & iListOnly) {
m_ctlItemList.SetRedraw(TRUE);
m_ctlItemList.Invalidate();
}
if (iView & iTreeOnly) {
m_ctlItemTree.SetRedraw(TRUE);
m_ctlItemTree.Invalidate();
}
RestoreGUIStatusEx();
if (m_bFilterActive)
UpdateStatusBar();
m_bInRefresh = false;
}
static void Shower(CWnd *pWnd)
{
pWnd->ShowWindow(SW_SHOW);
}
void DboxMain::RestoreWindows()
{
PWS_LOGIT;
ShowWindow(SW_RESTORE);
// Restore saved DB preferences that may not have been saved in the database
// over the minimize/restore event.
// Can't use the fact that the string is empty, as that is a valid state!
// Use arbitrary value "#Empty#" to indicate nothing here.
if (m_savedDBprefs != EMPTYSAVEDDBPREFS) {
if (m_core.HaveHeaderPreferencesChanged(m_savedDBprefs)) {
PWSprefs::GetInstance()->Load(m_savedDBprefs);
m_core.SetDBPrefsChanged(true);
}
m_savedDBprefs = EMPTYSAVEDDBPREFS;
}
RefreshViews();
BringWindowToTop();
CPWDialog::GetDialogTracker()->Apply(Shower);
//RestoreDisplayAfterMinimize();
}
// this tells OnSize that the user is currently
// changing the size of the dialog, and not restoring it
void DboxMain::OnSizing(UINT fwSide, LPRECT pRect)
{
PWS_LOGIT;
#if !defined(POCKET_PC)
CDialog::OnSizing(fwSide, pRect);
m_bSizing = true;
#endif
}
void DboxMain::OnMove(int x, int y)
{
CDialog::OnMove(x, y);
// turns out that minimizing calls this
// with x = y = -32000. Oh joy.
if (m_bInitDone && IsWindowVisible() == TRUE &&
x >= 0 && y >= 0) {
WINDOWPLACEMENT wp = {sizeof(WINDOWPLACEMENT)};
GetWindowPlacement(&wp);
PWSprefs::GetInstance()->SetPrefRect(wp.rcNormalPosition.top,
wp.rcNormalPosition.bottom,
wp.rcNormalPosition.left,
wp.rcNormalPosition.right);
}
}
void DboxMain::OnSize(UINT nType, int cx, int cy)
{
PWS_LOGIT_ARGS("nType=%d", nType);
// Note that onsize runs before InitDialog (Gee, I love MFC)
// Also, OnSize is called AFTER the function has been peformed.
// To verify IF the function should be done at all, it must be checked in OnSysCommand.
CDialog::OnSize(nType, cx, cy);
// If m_bInitDone not true, then dialog has not yet been completely initialised
if (!m_bInitDone)
return;
if (nType != SIZE_MINIMIZED) {
// Position the control bars - don't bother if just been minimized
CRect rect, dragrect;
RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);
RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0, reposQuery, &rect);
bool bDragBarState = PWSprefs::GetInstance()->GetPref(PWSprefs::ShowDragbar);
if (bDragBarState) {
const int i = GetSystemMetrics(SM_CYBORDER);
const int j = rect.top + i;
m_DDGroup.GetWindowRect(&dragrect);
ScreenToClient(&dragrect);
m_DDGroup.SetWindowPos(NULL, dragrect.left, j, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
m_DDTitle.GetWindowRect(&dragrect);
ScreenToClient(&dragrect);
m_DDTitle.SetWindowPos(NULL, dragrect.left, j, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
m_DDUser.GetWindowRect(&dragrect);
ScreenToClient(&dragrect);
m_DDUser.SetWindowPos(NULL, dragrect.left, j, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
m_DDPassword.GetWindowRect(&dragrect);
ScreenToClient(&dragrect);
m_DDPassword.SetWindowPos(NULL, dragrect.left, j, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
m_DDNotes.GetWindowRect(&dragrect);
ScreenToClient(&dragrect);
m_DDNotes.SetWindowPos(NULL, dragrect.left, j, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
m_DDURL.GetWindowRect(&dragrect);
ScreenToClient(&dragrect);
m_DDURL.SetWindowPos(NULL, dragrect.left, j, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
m_DDemail.GetWindowRect(&dragrect);
ScreenToClient(&dragrect);
m_DDemail.SetWindowPos(NULL, dragrect.left, j, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
m_DDAutotype.GetWindowRect(&dragrect);
ScreenToClient(&dragrect);
m_DDAutotype.SetWindowPos(NULL, dragrect.left, j, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
rect.top += dragrect.Height() + 2 * i;
}
m_ctlItemList.MoveWindow(&rect, TRUE);
m_ctlItemTree.MoveWindow(&rect, TRUE);
}
PWSprefs *prefs = PWSprefs::GetInstance();
// {kjp} Only SIZE_RESTORED is supported on Pocket PC.
#if !defined(POCKET_PC)
switch (nType) {
case SIZE_MINIMIZED:
//pws_os::Trace(L"OnSize:SIZE_MINIMIZED\n");
// Called when minimize button select on main dialog control box
// or the system menu or by right clicking in the Taskbar
// AFTER THE WINDOW HAS BEEN MINIMIZED!!!
// Save DB preferences that may not have been saved in the database
// over the minimize/restore event.
m_savedDBprefs = prefs->Store();
// Suspend notification of changes
m_core.SuspendOnDBNotification();
// PWSprefs::DatabaseClear == Locked
if (prefs->GetPref(PWSprefs::DatabaseClear)) {
if (!LockDataBase()) {
// Failed to save - abort minimize and clearing of data
ShowWindow(SW_SHOW);
return;
}
}
m_ctlItemList.DeleteAllItems();
m_mapGroupToTreeItem.clear();
m_ctlItemTree.DeleteAllItems();
m_bBoldItem = false;
m_LastFoundTreeItem = NULL;
m_LastFoundListItem = -1;
if (prefs->GetPref(PWSprefs::ClearClipboardOnMinimize))
OnClearClipboard();
if (prefs->GetPref(PWSprefs::UseSystemTray)) {
ShowWindow(SW_HIDE);
// User can have 'stealth' mode where, as long as a hot-key is defined,
// they can hide the System Tray icon when PasswordSafe is minimized
if (prefs->GetPref(PWSprefs::HideSystemTray) &&
prefs->GetPref(PWSprefs::HotKeyEnabled) &&
prefs->GetPref(PWSprefs::HotKey) > 0)
app.HideIcon();
else if (app.IsIconVisible() == FALSE)
app.ShowIcon();
}
break;
case SIZE_MAXIMIZED:
case SIZE_RESTORED:
if (!m_bSizing) { // here if actually restored
#endif
/*
if (nType == SIZE_MAXIMIZED)
pws_os::Trace(L"OnSize:SIZE_MAXIMIZED\n");
else
pws_os::Trace(L"OnSize:SIZE_RESTORED\n");
*/
if (!RestoreWindowsData(false))
return;
m_bIsRestoring = true; // Stop 'sort of list view' hiding FindToolBar
m_ctlItemTree.SetRestoreMode(true);
RefreshViews();
m_ctlItemTree.SetRestoreMode(false);
m_bIsRestoring = false;
// Restore saved DB preferences that may not have been saved in the database
// over the minimize/restore event.
// Can't use the fact that the string is empty, as that is a valid state!
// Use arbitrary value "#Empty#" to indicate nothing here.
if (m_savedDBprefs != EMPTYSAVEDDBPREFS) {
if (m_core.HaveHeaderPreferencesChanged(m_savedDBprefs)) {
prefs->Load(m_savedDBprefs);
m_core.SetDBPrefsChanged(true);
}
m_savedDBprefs = EMPTYSAVEDDBPREFS;
}
CPWDialog::GetDialogTracker()->Apply(Shower);
RestoreGUIStatusEx();
if (prefs->GetPref(PWSprefs::UseSystemTray) && app.IsIconVisible() == FALSE) {
app.ShowIcon();
}
// Resume notification of changes
m_core.ResumeOnDBNotification();
if (m_FindToolBar.IsVisible())
SetFindToolBar(true);
#if !defined(POCKET_PC)
} else { // m_bSizing == true: here if size changed
WINDOWPLACEMENT wp = {sizeof(WINDOWPLACEMENT)};
GetWindowPlacement(&wp);
PWSprefs::GetInstance()->SetPrefRect(wp.rcNormalPosition.top,
wp.rcNormalPosition.bottom,
wp.rcNormalPosition.left,
wp.rcNormalPosition.right);
// Make sure Find toolbar is above Status bar
if (m_FindToolBar.IsVisible())
SetToolBarPositions();
}
// Set timer for user-defined idle lockout, if selected (DB preference)
KillTimer(TIMER_LOCKDBONIDLETIMEOUT);
if (PWSprefs::GetInstance()->GetPref(PWSprefs::LockDBOnIdleTimeout)) {
ResetIdleLockCounter();
SetTimer(TIMER_LOCKDBONIDLETIMEOUT, IDLE_CHECK_INTERVAL, NULL);
}
break;
case SIZE_MAXHIDE:
//pws_os::Trace(L"OnSize:SIZE_MAXHIDE\n");
break;
case SIZE_MAXSHOW:
//pws_os::Trace(L"OnSize:SIZE_MAXSHOW\n");
break;
} // nType switch statement
#endif
m_bSizing = false;
}
void DboxMain::OnMinimize()
{
PWS_LOGIT;
// Called when the System Tray Minimize menu option is used
if (m_bStartHiddenAndMinimized)
m_bStartHiddenAndMinimized = false;
// Let OnSize handle this
ShowWindow(SW_MINIMIZE);
}
void DboxMain::OnRestore()
{
PWS_LOGIT;
m_ctlItemTree.SetRestoreMode(true);
// Called when the System Tray Restore menu option is used
RestoreWindowsData(true);
// No need for next statement as it is done via RestoreWindowsData(true)
// calling RestoreWindows which issues ShowWindow(SW_RESTORE) which does it
// in OnSize - convoluted logic - needs a re-write but oh so carefully!
//RestoreDisplayAfterMinimize();
m_ctlItemTree.SetRestoreMode(false);
TellUserAboutExpiredPasswords();
}
void DboxMain::OnItemSelected(NMHDR *pNotifyStruct, LRESULT *pLResult, const bool bTreeView)
{
// Needed as need public function called by CPWTreeCtrl and CPWListCtrl
if (bTreeView)
OnTreeItemSelected(pNotifyStruct, pLResult);
else
OnListItemSelected(pNotifyStruct, pLResult);
}
void DboxMain::OnListItemSelected(NMHDR *pNotifyStruct, LRESULT *pLResult)
{
// ListView
*pLResult = 0L;
CItemData *pci(NULL);
// More than 2 selected is meaningless in List view
//if (m_IsListView && m_ctlItemList.GetSelectedCount() == 2) {
// *pLResult = 1L;
// return;
//}
int iItem(-1);
switch (pNotifyStruct->code) {
case NM_CLICK:
{
LPNMITEMACTIVATE pLVItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNotifyStruct);
iItem = pLVItemActivate->iItem;
break;
}
case LVN_KEYDOWN:
{
LPNMLVKEYDOWN pLVKeyDown = reinterpret_cast<LPNMLVKEYDOWN>(pNotifyStruct);
iItem = m_ctlItemList.GetNextItem(-1, LVNI_SELECTED);
int nCount = m_ctlItemList.GetItemCount();
if (pLVKeyDown->wVKey == VK_DOWN)
iItem = (iItem + 1) % nCount;
if (pLVKeyDown->wVKey == VK_UP)
iItem = (iItem - 1 + nCount) % nCount;
break;
}
default:
// No idea how we got here!
return;
}
if (iItem != -1) {
// -1 if nothing selected, e.g., empty list
pci = (CItemData *)m_ctlItemList.GetItemData(iItem);
}
UpdateToolBarForSelectedItem(pci);
SetDCAText(pci);
m_LastFoundTreeItem = NULL;
m_LastFoundListItem = -1;
}
void DboxMain::OnTreeItemSelected(NMHDR *pNotifyStruct, LRESULT *pLResult)
{
// TreeView
*pLResult = 0L;
CItemData *pci(NULL);
// Seems that under Vista with Windows Common Controls V6, it is ignoring
// the single click on the button (+/-) of a node and only processing the
// double click, which generates a copy of whatever the user selected
// for a double click (except that it invalid for a node!) and then does
// the expand/collapse as appropriate.
// This codes attempts to fix this.
HTREEITEM hItem(NULL);
UnFindItem();
switch (pNotifyStruct->code) {
case NM_CLICK:
{
// Mouseclick - Need to find the item clicked via HitTest
TVHITTESTINFO htinfo = {0};
CPoint local = ::GetMessagePos();
m_ctlItemTree.ScreenToClient(&local);
htinfo.pt = local;
m_ctlItemTree.HitTest(&htinfo);
hItem = htinfo.hItem;
// Ignore any clicks not on an item (group or entry)
if (hItem == NULL ||
htinfo.flags & (TVHT_NOWHERE | TVHT_ONITEMRIGHT |
TVHT_ABOVE | TVHT_BELOW |
TVHT_TORIGHT | TVHT_TOLEFT))
return;
// If a group
if (!m_ctlItemTree.IsLeaf(hItem)) {
// If on indent or button
if (htinfo.flags & (TVHT_ONITEMINDENT | TVHT_ONITEMBUTTON)) {
m_ctlItemTree.Expand(htinfo.hItem, TVE_TOGGLE);
*pLResult = 1L; // We have toggled the group
return;
}
}
break;
}
case TVN_SELCHANGED:
// Keyboard - We are given the new selected entry
hItem = ((NMTREEVIEW *)pNotifyStruct)->itemNew.hItem;
break;
default:
// No idea how we got here!
return;
}
// Check it was on an item
if (hItem != NULL && m_ctlItemTree.IsLeaf(hItem)) {
pci = (CItemData *)m_ctlItemTree.GetItemData(hItem);
}
HTREEITEM hti = m_ctlItemTree.GetDropHilightItem();
if (hti != NULL)
m_ctlItemTree.SetItemState(hti, 0, TVIS_DROPHILITED);
UpdateToolBarForSelectedItem(pci);
SetDCAText(pci);
m_LastFoundTreeItem = NULL;
m_LastFoundListItem = -1;
}
void DboxMain::OnKeydownItemlist(NMHDR *pNotifyStruct, LRESULT *pLResult)
{
LPNMLVKEYDOWN pLVKeyDown = reinterpret_cast<LPNMLVKEYDOWN>(pNotifyStruct);
// TRUE = we have processed the key stroke - don't call anyone else
*pLResult = TRUE;
switch (pLVKeyDown->wVKey) {
case VK_DELETE:
OnDelete();
return;
case VK_INSERT:
OnAdd();
return;
case VK_ADD:
if ((GetKeyState(VK_CONTROL) & 0x8000) == 0x8000) {
SetHeaderInfo();
return;
}
break;
default:
break;
}
// FALSE = call next in line to process event
*pLResult = FALSE;
}
////////////////////////////////////////////////////////////////////////////////
// NOTE!
// itemData must be the actual item in the item list. if the item is removed
// from the list, it must be removed from the display as well and vice versa.
// A pointer is associated with the item in the display that is used for
// sorting.
// The exception is deleted items (database not saved). They exist in memory
// but are not displayed unless the user specifically wants them via a filter.
// {kjp} We could use itemData.GetNotes(CString&) to reduce the number of
// {kjp} temporary objects created and copied.
//
int DboxMain::InsertItemIntoGUITreeList(CItemData &ci, int iIndex,
const bool bSort, const int iView)
{
DisplayInfo *pdi = (DisplayInfo *)ci.GetDisplayInfo();
if (pdi != NULL && pdi->list_index != -1) {
// true iff item already displayed
return iIndex;
}
int iResult = iIndex;
if (iResult < 0) {
iResult = m_ctlItemList.GetItemCount();
}
if (pdi == NULL) {
pdi = new DisplayInfo;
ci.SetDisplayInfo(pdi);
}
if (iView & iListOnly)
pdi->list_index = -1;
if (iView & iTreeOnly)
pdi->tree_item = NULL;
if (m_bFilterActive) {
if (!PassesFiltering(ci, m_currentfilter))
return -1;
m_bNumPassedFiltering++;
}
int nImage = GetEntryImage(ci);
StringX group = ci.GetGroup();
StringX title = ci.GetTitle();
StringX username = ci.GetUser();
// get only the first line for display
StringX strNotes = ci.GetNotes();
StringX::size_type iEOL = strNotes.find(L'\r');
if (iEOL != StringX::npos) {
StringX strTemp = strNotes.substr(0, iEOL);
strNotes = strTemp;
}
StringX sx_fielddata;
if (iView & iListOnly) {
// Insert the first column data
if (m_bImageInLV)
sx_fielddata = L"";
else {
time_t t;
const CItemData::FieldType ft = (CItemData::FieldType)m_nColumnTypeByIndex[0];
switch (ft) {
case CItemData::PMTIME:
ci.GetPMTime(t);
if ((long)t == 0)
sx_fielddata = ci.GetCTimeL();
break;
case CItemData::RMTIME:
ci.GetPMTime(t);
if ((long)t == 0)
sx_fielddata = ci.GetCTimeL();
break;
case CItemData::POLICY:
{
PWPolicy pwp;
ci.GetPWPolicy(pwp);
sx_fielddata = pwp.GetDisplayString();
break;
}
default:
sx_fielddata = ci.GetFieldValue(ft);
}
}
iResult = m_ctlItemList.InsertItem(iResult, sx_fielddata.c_str());
if (iResult < 0) {
// TODO: issue error here...
return iResult;
}
pdi->list_index = iResult;
if (m_bImageInLV)
SetEntryImage(iResult, nImage);
}
if (iView & iTreeOnly) {
HTREEITEM ti;
StringX treeDispString = (LPCWSTR)m_ctlItemTree.MakeTreeDisplayString(ci);
// get path, create if necessary, add title as last node
bool bAlreadyExists;
ti = m_ctlItemTree.AddGroup(ci.GetGroup().c_str(), bAlreadyExists);
if (!PWSprefs::GetInstance()->GetPref(PWSprefs::ExplorerTypeTree)) {
ti = m_ctlItemTree.InsertItem(treeDispString.c_str(), ti, TVI_SORT);
m_ctlItemTree.SetItemData(ti, (DWORD_PTR)&ci);
} else {
ti = m_ctlItemTree.InsertItem(treeDispString.c_str(), ti, TVI_LAST);
m_ctlItemTree.SetItemData(ti, (DWORD_PTR)&ci);
if (bSort)
m_ctlItemTree.SortTree(m_ctlItemTree.GetParentItem(ti));
}
SetEntryImage(ti, nImage);
ASSERT(ti != NULL);
pdi->tree_item = ti;
}
if (iView & iListOnly) {
// Set the data in the rest of the columns
// First get the 1st line of the Notes field
StringX sxnotes, line1(L"");
sxnotes = ci.GetNotes();
if (!sxnotes.empty()) {
StringX::size_type end;
const StringX delim = L"\r\n";
end = sxnotes.find(delim, 0);
line1 = sxnotes.substr(0,
(end == StringX::npos) ? StringX::npos : end);
// If more than one line, add '[>>>]' to end of this line
// Note CHeaderStrl adds the normal ellipsis '...' (without square
// brackets) if the text doesn't fit in the cell. Use this to show
// more lines rather than more text in the first line.
if (end != StringX::npos)
line1 += L"[>>>]";
}
time_t t;
const StringX sxUnknown = PWSUtil::UNKNOWN_ASC_TIME_STR;
StringX sxNA; LoadAString(sxNA, IDS_NA);
for (int i = 1; i < m_nColumns; i++) {
const CItemData::FieldType ft = (CItemData::FieldType)m_nColumnTypeByIndex[i];
switch (ft) {
case CItemData::NOTES:
sx_fielddata = line1;
break;
case CItemData::CTIME:
ci.GetCTime(t);
sx_fielddata = ((long)t == 0) ? sxUnknown : ci.GetCTimeL();
break;
case CItemData::PMTIME:
ci.GetPMTime(t);
sx_fielddata = ((long)t == 0) ? sxNA : ci.GetPMTimeL();
break;
case CItemData::RMTIME:
ci.GetRMTime(t);
sx_fielddata = ((long)t == 0) ? sxNA : ci.GetRMTimeL();
break;
case CItemData::POLICY:
{
PWPolicy pwp;
ci.GetPWPolicy(pwp);
sx_fielddata = pwp.GetDisplayString();
break;
}
default:
sx_fielddata = ci.GetFieldValue(ft);
}
m_ctlItemList.SetItemText(iResult, i, sx_fielddata.c_str());
}
m_ctlItemList.SetItemData(iResult, (DWORD_PTR)&ci);
}
return iResult;
}
CItemData *DboxMain::getSelectedItem()
{
CItemData *pci = NULL;
if (m_core.GetNumEntries() == 0)
return pci;
if (m_ctlItemList.IsWindowVisible()) { // list view
POSITION pos = m_ctlItemList.GetFirstSelectedItemPosition();
if (pos) {
int i = m_ctlItemList.GetNextSelectedItem(pos);
pci = (CItemData *)m_ctlItemList.GetItemData(i);
ASSERT(pci != NULL);
DisplayInfo *pdi = (DisplayInfo *)pci->GetDisplayInfo();
ASSERT(pdi != NULL && pdi->list_index == i);
}
} else { // tree view; go from HTREEITEM to index
HTREEITEM ti = m_ctlItemTree.GetSelectedItem();
if (ti != NULL) {
pci = (CItemData *)m_ctlItemTree.GetItemData(ti);
if (pci != NULL) {
// leaf: do some sanity tests
DisplayInfo *pdi = (DisplayInfo *)pci->GetDisplayInfo();
ASSERT(pdi != NULL);
if (pdi->tree_item != ti) {
pws_os::Trace(L"DboxMain::getSelectedItem: fixing pdi->tree_item!\n");
pdi->tree_item = ti;
}
}
} // ti != NULL
} // tree view
return pci;
}
void DboxMain::ClearData(const bool clearMRE)
{
PWS_LOGIT;
m_core.ClearData(); // Clears DB & DB Preferences changed flags
if (clearMRE)
m_RUEList.ClearEntries();
UpdateSystemTray(m_bOpen ? LOCKED : CLOSED);
//Because GetText returns a copy, we cannot do anything about the names
if (m_bInitDone) {
// For long lists, this is painful, so we disable updates
m_ctlItemList.LockWindowUpdate();
m_ctlItemList.DeleteAllItems();
m_ctlItemList.UnlockWindowUpdate();
m_ctlItemTree.LockWindowUpdate();
m_mapGroupToTreeItem.clear();
m_ctlItemTree.DeleteAllItems();
m_ctlItemTree.UnlockWindowUpdate();
m_bBoldItem = false;
}
m_bDBNeedsReading = true;
}
void DboxMain::OnColumnClick(NMHDR *pNotifyStruct, LRESULT *pLResult)
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNotifyStruct;
// Get column index to CItemData value
int iIndex = pNMListView->iSubItem;
int iTypeSortColumn = m_nColumnTypeByIndex[iIndex];
if (m_iTypeSortColumn == iTypeSortColumn) {
m_bSortAscending = !m_bSortAscending;
PWSprefs *prefs = PWSprefs::GetInstance();
prefs->SetPref(PWSprefs::SortAscending, m_bSortAscending);
if (!m_core.GetCurFile().empty() &&
m_core.GetReadFileVersion() == PWSfile::VCURRENT) {
if (!m_core.IsReadOnly()) {
const StringX prefString(prefs->Store());
SetChanged(m_core.HaveHeaderPreferencesChanged(prefString) ? DBPrefs : ClearDBPrefs);
}
ChangeOkUpdate();
}
} else {
// Turn off all previous sort arrrows
// Note: not sure where, as user may have played with the columns!
HDITEM hdi;
hdi.mask = HDI_FORMAT;
for (int i = 0; i < m_LVHdrCtrl.GetItemCount(); i++) {
m_LVHdrCtrl.GetItem(i, &hdi);
if ((hdi.fmt & (HDF_SORTUP | HDF_SORTDOWN)) != 0) {
hdi.fmt &= ~(HDF_SORTUP | HDF_SORTDOWN);
m_LVHdrCtrl.SetItem(i, &hdi);
}
}
m_iTypeSortColumn = iTypeSortColumn;
m_bSortAscending = true;
}
SortListView();
OnHideFindToolBar();
*pLResult = TRUE;
}
void DboxMain::SortListView()
{
HDITEM hdi;
hdi.mask = HDI_FORMAT;
m_bSortAscending = PWSprefs::GetInstance()->GetPref(PWSprefs::SortAscending);
m_ctlItemList.SortItems(CompareFunc, (LPARAM)this);
FixListIndexes();
const int iIndex = m_nColumnIndexByType[m_iTypeSortColumn];
m_LVHdrCtrl.GetItem(iIndex, &hdi);
// Turn off all arrows
hdi.fmt &= ~(HDF_SORTUP | HDF_SORTDOWN);
// Turn on the correct arrow
hdi.fmt |= ((m_bSortAscending == TRUE) ? HDF_SORTUP : HDF_SORTDOWN);
m_LVHdrCtrl.SetItem(iIndex, &hdi);
if (!m_bIsRestoring && m_FindToolBar.IsVisible())
OnHideFindToolBar();
}
void DboxMain::OnHeaderRClick(NMHDR *, LRESULT *pLResult)
{
#if defined(POCKET_PC)
const DWORD dwTrackPopupFlags = TPM_LEFTALIGN;
#else
const DWORD dwTrackPopupFlags = TPM_LEFTALIGN | TPM_RIGHTBUTTON;
#endif
CMenu menu;
CPoint ptMousePos;
GetCursorPos(&ptMousePos);
if (menu.LoadMenu(IDR_POPCOLUMNS)) {
MENUINFO minfo;
SecureZeroMemory(&minfo, sizeof(minfo));
minfo.cbSize = sizeof(minfo);
minfo.fMask = MIM_MENUDATA;
minfo.dwMenuData = IDR_POPCOLUMNS;
menu.SetMenuInfo(&minfo);
CMenu* pPopup = menu.GetSubMenu(0);
ASSERT(pPopup != NULL);
if (m_pCC != NULL)
pPopup->CheckMenuItem(ID_MENUITEM_COLUMNPICKER,
m_pCC->IsWindowVisible() ? MF_CHECKED : MF_UNCHECKED);
else
pPopup->CheckMenuItem(ID_MENUITEM_COLUMNPICKER, MF_UNCHECKED);
pPopup->TrackPopupMenu(dwTrackPopupFlags, ptMousePos.x, ptMousePos.y, this);
}
*pLResult = TRUE;
}
void DboxMain::OnHeaderBeginDrag(NMHDR *pNotifyStruct, LRESULT *pLResult)
{
// Called for HDN_BEGINDRAG which changes the column order when CC not visible
// Stop drag of first column (image)
NMHEADER *phdn = (NMHEADER *)pNotifyStruct;
*pLResult = (m_bImageInLV && phdn->iItem == 0) ? TRUE : FALSE;
}
void DboxMain::OnHeaderEndDrag(NMHDR *pNotifyStruct, LRESULT *pLResult)
{
// Called for HDN_ENDDRAG which changes the column order when CC not visible
// Unfortunately the changes are only really done when this call returns,
// hence the PostMessage to get the information later
// Get control after operation is really complete
NMHEADER *phdn = (NMHEADER *)pNotifyStruct;
// Stop drag of first column (image)
if (m_bImageInLV &&
(phdn->iItem == 0 ||
(((phdn->pitem->mask & HDI_ORDER) == HDI_ORDER) &&
phdn->pitem->iOrder == 0))) {
*pLResult = TRUE;
return;
}
// Otherwise allow
PostMessage(PWS_MSG_HDR_DRAG_COMPLETE);
*pLResult = FALSE;
}
void DboxMain::OnHeaderNotify(NMHDR *pNotifyStruct, LRESULT *pLResult)
{
NMHEADER *phdn = (NMHEADER *)pNotifyStruct;
*pLResult = FALSE;
if (m_nColumnWidthByIndex == NULL || phdn->pitem == NULL)
return;
UINT mask = phdn->pitem->mask;
if ((mask & HDI_WIDTH) != HDI_WIDTH)
return;
// column width changed
switch (phdn->hdr.code) {
case HDN_ENDTRACK:
case HDN_ITEMCHANGED:
m_nColumnWidthByIndex[phdn->iItem] = phdn->pitem->cxy;
break;
default:
break;
}
}
void DboxMain::OnToggleView()
{
if (m_IsListView)
OnTreeView();
else
OnListView();
}
void DboxMain::OnListView()
{
SetListView();
if (m_FindToolBar.IsVisible())
OnHideFindToolBar();
}
void DboxMain::OnTreeView()
{
SetTreeView();
if (m_FindToolBar.IsVisible())
OnHideFindToolBar();
}
void DboxMain::SetListView()
{
UnFindItem();
m_ctlItemTree.ShowWindow(SW_HIDE);
m_ctlItemList.ShowWindow(SW_SHOW);
PWSprefs::GetInstance()->SetPref(PWSprefs::LastView, L"list");
m_ctlItemList.SetFocus();
m_IsListView = true;
// Some items may change on change of view
UpdateMenuAndToolBar(m_bOpen);
}
void DboxMain::SetTreeView()
{
UnFindItem();
m_ctlItemList.ShowWindow(SW_HIDE);
m_ctlItemTree.ShowWindow(SW_SHOW);
PWSprefs::GetInstance()->SetPref(PWSprefs::LastView, L"tree");
m_ctlItemTree.SetFocus();
m_IsListView = false;
// Some items may change on change of view
UpdateMenuAndToolBar(m_bOpen);
}
void DboxMain::OnShowHideToolbar()
{
bool bState = PWSprefs::GetInstance()->GetPref(PWSprefs::ShowToolbar);
PWSprefs::GetInstance()->SetPref(PWSprefs::ShowToolbar, !bState);
m_MainToolBar.ShowWindow(bState ? SW_HIDE : SW_SHOW);
SetToolBarPositions();
UpdateToolBarROStatus(m_core.IsReadOnly());
}
void DboxMain::OnShowHideDragbar()
{
bool bDragBarState = PWSprefs::GetInstance()->GetPref(PWSprefs::ShowDragbar);
PWSprefs::GetInstance()->SetPref(PWSprefs::ShowDragbar, !bDragBarState);
SetToolBarPositions();
}
void DboxMain::OnOldToolbar()
{
PWSprefs::GetInstance()->SetPref(PWSprefs::UseNewToolbar, false);
SetToolbar(ID_MENUITEM_OLD_TOOLBAR);
UpdateToolBarROStatus(m_core.IsReadOnly());
}
void DboxMain::OnNewToolbar()
{
PWSprefs::GetInstance()->SetPref(PWSprefs::UseNewToolbar, true);
SetToolbar(ID_MENUITEM_NEW_TOOLBAR);
UpdateToolBarROStatus(m_core.IsReadOnly());
}
void DboxMain::SetToolbar(const int menuItem, bool bInit)
{
// Toolbar
m_toolbarMode = menuItem;
if (bInit) {
// Dragbar
if (menuItem == ID_MENUITEM_NEW_TOOLBAR) {
m_DDGroup.Init(IDB_DRAGGROUP_NEW, IDB_DRAGGROUPX_NEW);
m_DDTitle.Init(IDB_DRAGTITLE_NEW, IDB_DRAGTITLEX_NEW);
m_DDUser.Init(IDB_DRAGUSER_NEW, IDB_DRAGUSERX_NEW);
m_DDPassword.Init(IDB_DRAGPASSWORD_NEW, IDB_DRAGPASSWORDX_NEW);
m_DDNotes.Init(IDB_DRAGNOTES_NEW, IDB_DRAGNOTESX_NEW);
m_DDURL.Init(IDB_DRAGURL_NEW, IDB_DRAGURLX_NEW);
m_DDemail.Init(IDB_DRAGEMAIL_NEW, IDB_DRAGEMAILX_NEW);
m_DDAutotype.Init(IDB_AUTOTYPE_NEW, IDB_DRAGAUTOX_NEW);
} else if (menuItem == ID_MENUITEM_OLD_TOOLBAR) {
m_DDGroup.Init(IDB_DRAGGROUP_CLASSIC, IDB_DRAGGROUPX_CLASSIC);
m_DDTitle.Init(IDB_DRAGTITLE_CLASSIC, IDB_DRAGTITLEX_CLASSIC);
m_DDUser.Init(IDB_DRAGUSER_CLASSIC, IDB_DRAGUSERX_CLASSIC);
m_DDPassword.Init(IDB_DRAGPASSWORD_CLASSIC, IDB_DRAGPASSWORDX_CLASSIC);
m_DDNotes.Init(IDB_DRAGNOTES_CLASSIC, IDB_DRAGNOTESX_CLASSIC);
m_DDURL.Init(IDB_DRAGURL_CLASSIC, IDB_DRAGURLX_CLASSIC);
m_DDemail.Init(IDB_DRAGEMAIL_CLASSIC, IDB_DRAGEMAILX_CLASSIC);
m_DDAutotype.Init(IDB_AUTOTYPE_CLASSIC, IDB_DRAGAUTOX_CLASSIC);
} else {
ASSERT(0);
}
m_MainToolBar.LoadDefaultToolBar(m_toolbarMode);
m_FindToolBar.LoadDefaultToolBar(m_toolbarMode);
CString csButtonNames = PWSprefs::GetInstance()->
GetPref(PWSprefs::MainToolBarButtons).c_str();
m_MainToolBar.CustomizeButtons(csButtonNames);
} else { // !bInit - changing bitmaps
m_MainToolBar.ChangeImages(m_toolbarMode);
m_FindToolBar.ChangeImages(m_toolbarMode);
if (menuItem == ID_MENUITEM_NEW_TOOLBAR) {
m_DDGroup.ReInit(IDB_DRAGGROUP_NEW, IDB_DRAGGROUPX_NEW);
m_DDTitle.ReInit(IDB_DRAGTITLE_NEW, IDB_DRAGTITLEX_NEW);
m_DDUser.ReInit(IDB_DRAGUSER_NEW, IDB_DRAGUSERX_NEW);
m_DDPassword.ReInit(IDB_DRAGPASSWORD_NEW, IDB_DRAGPASSWORDX_NEW);
m_DDNotes.ReInit(IDB_DRAGNOTES_NEW, IDB_DRAGNOTESX_NEW);
m_DDURL.ReInit(IDB_DRAGURL_NEW, IDB_DRAGURLX_NEW);
m_DDemail.ReInit(IDB_DRAGEMAIL_NEW, IDB_DRAGEMAILX_NEW);
m_DDAutotype.ReInit(IDB_AUTOTYPE_NEW, IDB_DRAGAUTOX_NEW);
} else if (menuItem == ID_MENUITEM_OLD_TOOLBAR) {
m_DDGroup.ReInit(IDB_DRAGGROUP_CLASSIC, IDB_DRAGGROUPX_CLASSIC);
m_DDTitle.ReInit(IDB_DRAGTITLE_CLASSIC, IDB_DRAGTITLEX_CLASSIC);
m_DDUser.ReInit(IDB_DRAGUSER_CLASSIC, IDB_DRAGUSERX_CLASSIC);
m_DDPassword.ReInit(IDB_DRAGPASSWORD_CLASSIC, IDB_DRAGPASSWORDX_CLASSIC);
m_DDNotes.ReInit(IDB_DRAGNOTES_CLASSIC, IDB_DRAGNOTESX_CLASSIC);
m_DDURL.ReInit(IDB_DRAGURL_CLASSIC, IDB_DRAGURLX_CLASSIC);
m_DDemail.ReInit(IDB_DRAGEMAIL_CLASSIC, IDB_DRAGEMAILX_CLASSIC);
m_DDAutotype.ReInit(IDB_AUTOTYPE_CLASSIC, IDB_DRAGAUTOX_CLASSIC);
} else {
ASSERT(0);
}
m_DDGroup.Invalidate(); m_DDTitle.Invalidate(); m_DDUser.Invalidate();
m_DDPassword.Invalidate(); m_DDNotes.Invalidate(); m_DDURL.Invalidate();
m_DDemail.Invalidate(); m_DDAutotype.Invalidate();
}
m_menuManager.SetImageList(&m_MainToolBar);
m_MainToolBar.Invalidate();
m_FindToolBar.Invalidate();
SetToolBarPositions();
}
void DboxMain::OnExpandAll()
{
m_ctlItemTree.OnExpandAll();
}
void DboxMain::OnCollapseAll()
{
m_ctlItemTree.OnCollapseAll();
}
static void Hider(CWnd *pWnd)
{
pWnd->ShowWindow(SW_HIDE);
}
void DboxMain::OnTimer(UINT_PTR nIDEvent)
{
if ((nIDEvent == TIMER_LOCKONWTSLOCK && IsWorkstationLocked()) ||
(nIDEvent == TIMER_LOCKDBONIDLETIMEOUT &&
DecrementAndTestIdleLockCounter())) {
// OK, so we need to lock. If we're not using a system tray,
// just minimize. If we are, then we need to hide (which
// also requires children be hidden explicitly)
pws_os::Trace(L"Locking due to Timer lock countdown or ws lock\n");
m_vGroupDisplayState = GetGroupDisplayState();
if (!LockDataBase())
return;
// Save any database preference changes
PWSprefs *prefs = PWSprefs::GetInstance();
m_savedDBprefs = prefs->Store();
bool usingsystray = prefs->GetPref(PWSprefs::UseSystemTray);
if (!usingsystray) {
ShowWindow(SW_MINIMIZE);
} else {
CPWDialog::GetDialogTracker()->Apply(Hider);
ShowWindow(SW_HIDE);
}
if (nIDEvent == TIMER_LOCKONWTSLOCK)
KillTimer(TIMER_LOCKONWTSLOCK);
} else if (nIDEvent == TIMER_EXPENT) {
// once a day, we want to check the expired entries list
CheckExpireList();
} else {
pws_os::Trace(L"Timer lock kicked in (countdown=%u), not locking. Timer ID=%d\n",
m_IdleLockCountDown, nIDEvent);
}
}
LRESULT DboxMain::OnSessionChange(WPARAM wParam, LPARAM )
{
PWS_LOGIT_ARGS("wParam=%d", wParam);
// Windows XP and later only
// Handle Lock/Unlock, Fast User Switching and Remote access.
// Won't be called if the registration failed (i.e. < Windows XP
// or the "Windows Terminal Server" service wasn't active at startup).
pws_os::Trace(L"OnSessionChange. wParam = %d\n", wParam);
PWSprefs *prefs = PWSprefs::GetInstance();
switch (wParam) {
case WTS_CONSOLE_DISCONNECT:
case WTS_REMOTE_DISCONNECT:
case WTS_SESSION_LOCK:
if (m_bOpen && app.GetSystemTrayState() == UNLOCKED) {
m_bWSLocked = true;
if (prefs->GetPref(PWSprefs::LockOnWindowLock) &&
LockDataBase()) {
bool usingsystray = prefs->GetPref(PWSprefs::UseSystemTray);
if (!usingsystray) {
ShowWindow(SW_MINIMIZE);
} else {
CPWDialog::GetDialogTracker()->Apply(Hider);
ShowWindow(SW_HIDE);
}
}
}
break;
case WTS_CONSOLE_CONNECT:
case WTS_REMOTE_CONNECT:
case WTS_SESSION_UNLOCK:
case WTS_SESSION_LOGON:
m_bWSLocked = false;
break;
case WTS_SESSION_LOGOFF:
// This does NOT get called as OnQueryEndSession/OnEndSession
// handle this event - but just in case!
SavePreferencesOnExit();
SaveDatabaseOnExit(ST_WTSLOGOFFEXIT);
CleanUpAndExit(false);
break;
case WTS_SESSION_REMOTE_CONTROL:
default:
break;
}
return 0L;
}
bool DboxMain::LockDataBase()
{
PWS_LOGIT;
/*
* Since we clear the data, any unchanged changes will be lost,
* so we force a save if database is modified, and fail
* to lock if the save fails (unless db is r-o).
*
* returns false iff save was required AND failed.
*/
// Now try and save changes
if (m_core.IsChanged() || m_bTSUpdated || m_core.HaveDBPrefsChanged()) {
if (Save() != PWScore::SUCCESS) {
// If we don't warn the user, data may be lost!
CGeneralMsgBox gmb;
CString cs_text(MAKEINTRESOURCE(IDS_COULDNOTSAVE)),
cs_title(MAKEINTRESOURCE(IDS_SAVEERROR));
gmb.MessageBox(cs_text, cs_title, MB_ICONSTOP);
return false;
}
}
// If there's a pending dialog box prompting for a
// password, we need to kill it, since we will prompt
// for the existing dbase's password upon restore.
// Avoid lots of edge cases this way.
CancelPendingPasswordDialog();
ClearData(false);
// Because LockDatabase actually doen't minimize the Window, the OnSize
// routine is not called to clear the clipboard - so do it here
if (PWSprefs::GetInstance()->GetPref(PWSprefs::ClearClipboardOnMinimize)) {
ClearClipboardData();
}
return true;
}
// This function determines if the workstation is locked.
bool DboxMain::IsWorkstationLocked() const
{
bool bResult = false;
if (m_bWTSRegistered)
bResult = m_bWSLocked;
else {
// Rather not use this as may have impact with multiple desktops
// but if registering for session change messages failed ...
HDESK hDesktop = OpenDesktop(L"default", 0, false, DESKTOP_SWITCHDESKTOP);
if (hDesktop != 0) {
// SwitchDesktop fails if hDesktop invisible, screensaver or winlogin.
bResult = !SwitchDesktop(hDesktop);
CloseDesktop(hDesktop);
}
}
if (bResult)
pws_os::Trace(L"IsWorkstationLocked() returning true");
return bResult;
}
void DboxMain::OnChangeTreeFont()
{
PWSprefs *prefs = PWSprefs::GetInstance();
CFont *pOldFontTree;
pOldFontTree = m_ctlItemTree.GetFont();
// Make sure we know what is inside the font.
LOGFONT lf;
pOldFontTree->GetLogFont(&lf);
// Present Tree/List view font and possibly change it
// Allow user to apply changes to font
StringX cs_TreeListSampleText = prefs->GetPref(PWSprefs::TreeListSampleText);
CFontsDialog fontdlg(&lf, CF_SCREENFONTS | CF_INITTOLOGFONTSTRUCT, NULL, NULL, TLFONT);
fontdlg.m_sampletext = cs_TreeListSampleText.c_str();
if (fontdlg.DoModal() == IDOK) {
Fonts::GetInstance()->SetCurrentFont(&lf);
// Transfer the fonts to the tree and list windows
m_ctlItemTree.SetUpFont();
m_ctlItemList.SetUpFont();
m_LVHdrCtrl.SetFont(Fonts::GetInstance()->GetCurrentFont());
// Recalculate header widths
CalcHeaderWidths();
// Reset column widths
AutoResizeColumns();
// Check if default
CString csfn(lf.lfFaceName), csdfltfn(dfltTreeListFont.lfFaceName);
if (lf.lfHeight == dfltTreeListFont.lfHeight &&
lf.lfWeight == dfltTreeListFont.lfWeight &&
lf.lfItalic == dfltTreeListFont.lfItalic &&
csfn == csdfltfn) {
// Delete config Tree/List font
prefs->ResetPref(PWSprefs::TreeFont);
} else { // Save user's choice of Tree/List font
CString treefont_str;
treefont_str.Format(L"%i,%i,%i,%i,%i,%i,%i,%i,%i,%i,%i,%i,%i,%s",
lf.lfHeight, lf.lfWidth, lf.lfEscapement, lf.lfOrientation,
lf.lfWeight, lf.lfItalic, lf.lfUnderline, lf.lfStrikeOut,
lf.lfCharSet, lf.lfOutPrecision, lf.lfClipPrecision,
lf.lfQuality, lf.lfPitchAndFamily, lf.lfFaceName);
prefs->SetPref(PWSprefs::TreeFont, LPCWSTR(treefont_str));
}
// Save user's sample text
prefs->SetPref(PWSprefs::TreeListSampleText,
LPCWSTR(fontdlg.m_sampletext));
} // DoModal
}
void DboxMain::OnChangePswdFont()
{
PWSprefs *prefs = PWSprefs::GetInstance();
LOGFONT lf;
// Get Password font in case the user wants to change this.
Fonts *pFonts = Fonts::GetInstance();
pFonts->GetPasswordFont(&lf);
// Present Password font and possibly change it
// Allow user to apply changes to font
StringX cs_PswdSampleText = prefs->GetPref(PWSprefs::PswdSampleText);
CFontsDialog fontdlg(&lf, CF_SCREENFONTS | CF_INITTOLOGFONTSTRUCT, NULL, NULL, PWFONT);
fontdlg.m_sampletext = cs_PswdSampleText.c_str();
if (fontdlg.DoModal() == IDOK) {
// Transfer the new font to the passwords
pFonts->SetPasswordFont(&lf);
// Recalculating row height
m_ctlItemList.UpdateRowHeight(true);
LOGFONT dfltfont;
pFonts->GetDefaultPasswordFont(dfltfont);
// Check if default
CString csfn(lf.lfFaceName), csdfltfn(dfltfont.lfFaceName);
if (lf.lfHeight == dfltfont.lfHeight &&
lf.lfWeight == dfltfont.lfWeight &&
lf.lfItalic == dfltfont.lfItalic &&
csfn == csdfltfn) {
// Delete config password font
prefs->ResetPref(PWSprefs::PasswordFont);
} else { // Save user's choice of password font
CString pswdfont_str;
pswdfont_str.Format(L"%i,%i,%i,%i,%i,%i,%i,%i,%i,%i,%i,%i,%i,%s",
lf.lfHeight, lf.lfWidth, lf.lfEscapement, lf.lfOrientation,
lf.lfWeight, lf.lfItalic, lf.lfUnderline, lf.lfStrikeOut,
lf.lfCharSet, lf.lfOutPrecision, lf.lfClipPrecision,
lf.lfQuality, lf.lfPitchAndFamily, lf.lfFaceName);
prefs->SetPref(PWSprefs::PasswordFont, LPCWSTR(pswdfont_str));
}
// Save user's sample text
prefs->SetPref(PWSprefs::PswdSampleText, LPCWSTR(fontdlg.m_sampletext));
} // DoModal
}
void DboxMain::OnChangeVKFont()
{
PWSprefs *prefs = PWSprefs::GetInstance();
LOGFONT lf = {-16, 0, 0, 0, FW_NORMAL, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0,
L""};
// Get VKeyboard font in case the user wants to change this.
StringX cs_VKeyboardFont = prefs->GetPref(PWSprefs::VKeyboardFontName);
if (cs_VKeyboardFont.length() != 0 &&
cs_VKeyboardFont.length() <= LF_FACESIZE) {
memcpy_s(lf.lfFaceName, LF_FACESIZE * sizeof(wchar_t),
cs_VKeyboardFont.c_str(), cs_VKeyboardFont.length() * sizeof(wchar_t));
}
// Present VKeyboard font and possibly change it
// Allow user to apply changes to font
StringX cs_VKSampleText = prefs->GetPref(PWSprefs::VKSampleText);
CFontsDialog fontdlg(&lf, CF_SCREENFONTS | CF_INITTOLOGFONTSTRUCT |
CF_LIMITSIZE | CF_NOSCRIPTSEL,
NULL, NULL, VKFONT);
fontdlg.m_cf.nSizeMin = 10;
fontdlg.m_cf.nSizeMax = 14;
fontdlg.m_sampletext = cs_VKSampleText.c_str();
INT_PTR rc = fontdlg.DoModal();
if (rc == IDOK) {
// Check if default
CString csfn(lf.lfFaceName);
if (csfn.IsEmpty()) {
// Delete config VKeyboard font face name
prefs->ResetPref(PWSprefs::VKeyboardFontName);
} else {
// Save user's choice of VKeyboard font face name
// Remove leading @ (OpenType) if present
if (csfn.Left(1) == L"@")
csfn = csfn.Mid(1);
if (csfn == CString(CVKeyBoardDlg::ARIALUMS))
prefs->ResetPref(PWSprefs::VKeyboardFontName);
else
prefs->SetPref(PWSprefs::VKeyboardFontName, LPCWSTR(csfn));
}
// Save user's sample text
prefs->SetPref(PWSprefs::VKSampleText, LPCWSTR(fontdlg.m_sampletext));
} else
if (fontdlg.m_bReset) {
// Check if user reset it to none.
prefs->ResetPref(PWSprefs::VKeyboardFontName);
}
}
void DboxMain::UpdateSystemTray(const STATE s)
{
switch (s) {
case LOCKED:
app.SetSystemTrayState(ThisMfcApp::LOCKED);
if (!m_core.GetCurFile().empty()) {
CString ttt(L"[");
ttt += m_core.GetCurFile().c_str();
ttt += L"]";
app.SetTooltipText(ttt);
}
break;
case UNLOCKED:
app.SetSystemTrayState(ThisMfcApp::UNLOCKED);
if (!m_core.GetCurFile().empty())
app.SetTooltipText(m_core.GetCurFile().c_str());
break;
case CLOSED:
app.SetSystemTrayState(ThisMfcApp::CLOSED);
break;
default:
ASSERT(0);
}
}
BOOL DboxMain::LaunchBrowser(const CString &csURL, const StringX &sxAutotype,
const std::vector<size_t> &vactionverboffsets,
const bool &bDoAutotype)
{
CString theURL(csURL);
// csURL should be a well-formed URL as defined in RFC3986 with
// the exceptions listed below.
//
// The default behaviour of this function is to pass the URL to the Windows shell.
// This will invoke a the default browser for http: and https: schema, the default
// mailer for mailto: schema, etc.
//
// The exceptions to the csURL syntax are as follows:
// 0. csURL is "sanitized" - newlines, tabs & carriage returns are removed.
// 1. If csURL doesn't contain "://" OR "mailto:" or [ssh], then we prepend
// "http://" to it. This is to allow users to enter "amazon.com" and get the
// behaviour the expect.
// 2. If csURL contains [alt], then the rest of the text is passed to the "alternate"
// browser defined in the preferences, along with the command-line parameters.
// For example, if AltBrowser is "CoolBrowser.exe" and AltBrowserCmdLineParms
// is "-x", then the csURL "[alt] supersite.com" will cause the following to
// be invoked:
// CoolBrowser.exe -x http://supersite.com
// 3. If csURL contains {alt} or [ssh], then the behaviour is the same as in (2),
// except that "http://" is NOT prepended to the rest of the text. This allows
// one to specify an ssh client (such as Putty) as the alternate browser,
// and user@machine as the URL. However, this really should be actioned via
// the new Run Command!
theURL.Remove(L'\r');
theURL.Remove(L'\n');
theURL.Remove(L'\t');
bool isMailto = (theURL.Find(L"mailto:") != -1);
UINT errID = isMailto ? IDS_CANTEMAIL : IDS_CANTBROWSE;
int altReplacements = theURL.Replace(L"[alt]", L"");
int alt2Replacements = (theURL.Replace(L"[ssh]", L"") +
theURL.Replace(L"{alt}", L""));
int autotypeReplacements = theURL.Replace(L"[autotype]", L"");
int no_autotype = theURL.Replace(L"[xa]", L"");
if (alt2Replacements <= 0 && !isMailto && theURL.Find(L"://") == -1)
theURL = L"http://" + theURL;
StringX sxAltBrowser(PWSprefs::GetInstance()->
GetPref(PWSprefs::AltBrowser));
bool useAltBrowser = ((altReplacements > 0 || alt2Replacements > 0) &&
!sxAltBrowser.empty());
StringX sxFile, sxParameters(L"");
if (!useAltBrowser) {
sxFile = theURL;
} else { // alternate browser specified, invoke w/optional args
sxFile = sxAltBrowser;
StringX sxCmdLineParms(PWSprefs::GetInstance()->
GetPref(PWSprefs::AltBrowserCmdLineParms));
if (!sxCmdLineParms.empty())
sxParameters = sxCmdLineParms + StringX(L" ") + StringX(theURL);
else
sxParameters = StringX(theURL);
}
TrimLeft(sxFile);
// Obey user's No Autotype flag [xa]
if (no_autotype > 0) {
m_bDoAutoType = false;
m_sxAutoType = L"";
m_vactionverboffsets.clear();
} else {
// Either do it because they pressed the right menu/shortcut
// or they had specified Do Auotype flag [autotype]
m_bDoAutoType = bDoAutotype || autotypeReplacements > 0;
m_sxAutoType = m_bDoAutoType ? sxAutotype : L"";
if (m_bDoAutoType)
m_vactionverboffsets = vactionverboffsets;
}
bool rc = m_runner.issuecmd(sxFile, sxParameters, !m_sxAutoType.empty());
if (!rc) {
CGeneralMsgBox gmb;
gmb.AfxMessageBox(errID, MB_ICONSTOP);
}
return rc ? TRUE : FALSE;
}
BOOL DboxMain::SendEmail(const CString &cs_Email)
{
/*
* Format is the standard 'mailto:' rules as per RFC 2368.
* 'mailto:' is prefixed the the string passed to this routine.
*
* sAddress[sHeaders]
*
* sAddress
* One or more valid email addresses separated by a semicolon.
* You must use Internet-safe characters. Use %20 for the space character.
*
* sHeaders
* Optional. One or more name-value pairs. The first pair should be
* prefixed by a "?" and any additional pairs should be prefixed by a "&".
*
* The name can be one of the following strings:
* subject
* Text to appear in the subject line of the message.
* body
* Text to appear in the body of the message.
* CC
* Addresses to be included in the "cc" (carbon copy) section of the
* message.
* BCC
* Addresses to be included in the "bcc" (blind carbon copy) section
* of the message.
*
* Example:
* user@example.com?subject=Message Title&body=Message Content"
*/
StringX sx_Email(L"mailto:"), sxParameters(L"");
sx_Email += cs_Email;
Trim(sx_Email);
bool rc = m_runner.issuecmd(sx_Email, sxParameters, false);
if (!rc) {
CGeneralMsgBox gmb;
gmb.AfxMessageBox(IDS_CANTEMAIL, MB_ICONSTOP);
}
return rc ? TRUE : FALSE;
}
void DboxMain::SetColumns()
{
// User hasn't yet saved the columns he/she wants and so gets our order!
// Or - user has reset the columns (popup menu from right click on Header)
CString cs_header;
HDITEM hdi;
hdi.mask = HDI_LPARAM;
PWSprefs *prefs = PWSprefs::GetInstance();
int ipwd = prefs->GetPref(PWSprefs::ShowPasswordInTree) ? 1 : 0;
CRect rect;
m_ctlItemList.GetClientRect(&rect);
int i1stWidth = prefs->GetPref(PWSprefs::Column1Width,
(rect.Width() / 3 + rect.Width() % 3), false);
int i2ndWidth = prefs->GetPref(PWSprefs::Column2Width,
rect.Width() / 3, false);
int i3rdWidth = prefs->GetPref(PWSprefs::Column3Width,
rect.Width() / 3, false);
cs_header = GetHeaderText(CItemData::TITLE);
m_ctlItemList.InsertColumn(0, cs_header);
hdi.lParam = CItemData::TITLE;
m_LVHdrCtrl.SetItem(0, &hdi);
m_ctlItemList.SetColumnWidth(0, i1stWidth);
cs_header = GetHeaderText(CItemData::USER);
m_ctlItemList.InsertColumn(1, cs_header);
hdi.lParam = CItemData::USER;
m_LVHdrCtrl.SetItem(1, &hdi);
m_ctlItemList.SetColumnWidth(1, i2ndWidth);
cs_header = GetHeaderText(CItemData::NOTES);
m_ctlItemList.InsertColumn(2, cs_header);
hdi.lParam = CItemData::NOTES;
m_LVHdrCtrl.SetItem(2, &hdi);
m_ctlItemList.SetColumnWidth(2, i3rdWidth);
if (PWSprefs::GetInstance()->GetPref(PWSprefs::ShowPasswordInTree)) {
cs_header = GetHeaderText(CItemData::PASSWORD);
m_ctlItemList.InsertColumn(3, cs_header);
hdi.lParam = CItemData::PASSWORD;
m_LVHdrCtrl.SetItem(3, &hdi);
m_ctlItemList.SetColumnWidth(3,
PWSprefs::GetInstance()->GetPref(PWSprefs::Column4Width,
rect.Width() / 4, false));
}
int ioff = 3;
CItemData::FieldType defCols[] = {CItemData::URL, CItemData::EMAIL,
CItemData::RUNCMD, CItemData::CTIME,
CItemData::PMTIME, CItemData::ATIME,
CItemData::XTIME, CItemData::RMTIME,
CItemData::POLICY,
};
for (int i = 0; i < sizeof(defCols)/sizeof(defCols[0]); i++) {
cs_header = GetHeaderText(defCols[i]);
m_ctlItemList.InsertColumn(ipwd + ioff, cs_header);
hdi.lParam = defCols[i];
m_LVHdrCtrl.SetItem(ipwd + ioff, &hdi);
ioff++;
}
m_ctlItemList.SetRedraw(FALSE);
for (int i = ipwd + 3; i < (ipwd + ioff); i++) {
m_ctlItemList.SetColumnWidth(i, m_iDateTimeFieldWidth);
}
SetHeaderInfo();
}
void DboxMain::SetColumns(const CString cs_ListColumns)
{
// User has saved the columns he/she wants and now we are putting them back
CString cs_header;
HDITEM hdi;
hdi.mask = HDI_LPARAM;
vector<int> vi_columns;
vector<int>::const_iterator vi_IterColumns;
const wchar_t pSep[] = L",";
wchar_t *pTemp;
// Duplicate as strtok modifies the string
pTemp = _wcsdup((LPCWSTR)cs_ListColumns);
#if (_MSC_VER >= 1400)
// Capture columns shown:
wchar_t *next_token;
wchar_t *token = wcstok_s(pTemp, pSep, &next_token);
while(token) {
vi_columns.push_back(_wtoi(token));
token = wcstok_s(NULL, pSep, &next_token);
}
#else
// Capture columns shown:
wchar_t *token = _wcstok(pTemp, pSep);
while(token) {
vi_columns.push_back(_wtoi(token));
token = _wcstok(NULL, pSep);
}
#endif
free(pTemp);
// If present, the images are always first
int iType= *vi_columns.begin();
if (iType == CItemData::UUID) {
m_bImageInLV = true;
m_ctlItemList.SetImageList(m_pImageList, LVSIL_NORMAL);
m_ctlItemList.SetImageList(m_pImageList, LVSIL_SMALL);
}
int icol(0);
for (vi_IterColumns = vi_columns.begin();
vi_IterColumns != vi_columns.end();
vi_IterColumns++) {
iType = *vi_IterColumns;
cs_header = GetHeaderText(iType);
// Images (if present) must be the first column!
if (iType == CItemData::UUID && icol != 0)
continue;
if (!cs_header.IsEmpty()) {
m_ctlItemList.InsertColumn(icol, cs_header);
hdi.lParam = iType;
m_LVHdrCtrl.SetItem(icol, &hdi);
icol++;
}
}
SetHeaderInfo();
}
void DboxMain::SetColumnWidths(const CString cs_ListColumnsWidths)
{
// User has saved the columns he/she wants and now we are putting them back
std::vector<int> vi_widths;
std::vector<int>::const_iterator vi_IterWidths;
const wchar_t pSep[] = L",";
wchar_t *pWidths;
// Duplicate as strtok modifies the string
pWidths = _wcsdup((LPCWSTR)cs_ListColumnsWidths);
#if (_MSC_VER >= 1400)
// Capture column widths shown:
wchar_t *next_token;
wchar_t *token = wcstok_s(pWidths, pSep, &next_token);
while(token) {
vi_widths.push_back(_wtoi(token));
token = wcstok_s(NULL, pSep, &next_token);
}
#else
// Capture columnwidths shown:
wchar_t *token = _wcstok(pWidths, pSep);
while(token) {
vi_widths.push_back(_wtoi(token));
token = _wcstok(NULL, pSep);
}
#endif
free(pWidths);
int icol = 0, index;
for (vi_IterWidths = vi_widths.begin();
vi_IterWidths != vi_widths.end();
vi_IterWidths++) {
if (icol == (m_nColumns - 1))
break;
int iWidth = *vi_IterWidths;
m_ctlItemList.SetColumnWidth(icol, iWidth);
index = m_LVHdrCtrl.OrderToIndex(icol);
m_nColumnWidthByIndex[index] = iWidth;
icol++;
}
// First column special if the Image
if (m_bImageInLV) {
m_ctlItemList.SetColumnWidth(0, LVSCW_AUTOSIZE);
}
// Last column special
index = m_LVHdrCtrl.OrderToIndex(m_nColumns - 1);
m_ctlItemList.SetColumnWidth(index, LVSCW_AUTOSIZE_USEHEADER);
}
void DboxMain::AddColumn(const int iType, const int iIndex)
{
// Add new column of type iType after current column index iIndex
CString cs_header;
HDITEM hdi;
int iNewIndex(iIndex);
// If iIndex = -1, means drop on the end
if (iIndex < 0)
iNewIndex = m_nColumns;
hdi.mask = HDI_LPARAM | HDI_WIDTH;
cs_header = GetHeaderText(iType);
ASSERT(!cs_header.IsEmpty());
iNewIndex = m_ctlItemList.InsertColumn(iNewIndex, cs_header);
ASSERT(iNewIndex != -1);
hdi.lParam = iType;
hdi.cxy = GetHeaderWidth(iType);
m_LVHdrCtrl.SetItem(iNewIndex, &hdi);
}
void DboxMain::DeleteColumn(const int iType)
{
// Delete column
m_ctlItemList.DeleteColumn(m_nColumnIndexByType[iType]);
}
void DboxMain::SetHeaderInfo()
{
HDITEM hdi_get;
// CHeaderCtrl get values
hdi_get.mask = HDI_LPARAM | HDI_ORDER;
m_nColumns = m_LVHdrCtrl.GetItemCount();
ASSERT(m_nColumns > 1); // Title & User are mandatory!
// re-initialise array
for (int i = 0; i < CItemData::LAST; i++)
m_nColumnIndexByType[i] =
m_nColumnIndexByOrder[i] =
m_nColumnTypeByIndex[i] =
m_nColumnWidthByIndex[i] = -1;
m_LVHdrCtrl.GetOrderArray(m_nColumnIndexByOrder, m_nColumns);
for (int iOrder = 0; iOrder < m_nColumns; iOrder++) {
const int iIndex = m_nColumnIndexByOrder[iOrder];
m_ctlItemList.SetColumnWidth(iIndex, LVSCW_AUTOSIZE);
m_LVHdrCtrl.GetItem(iIndex, &hdi_get);
ASSERT(iOrder == hdi_get.iOrder);
m_nColumnIndexByType[hdi_get.lParam] = iIndex;
m_nColumnTypeByIndex[iIndex] = (int)hdi_get.lParam;
}
// Check sort column still there; if not TITLE always is!
if (m_nColumnIndexByType[m_iTypeSortColumn] == -1)
m_iTypeSortColumn = CItemData::TITLE;
SortListView();
AutoResizeColumns();
}
void DboxMain::OnResetColumns()
{
// Delete all existing columns
for (int i = 0; i < m_nColumns; i++) {
m_ctlItemList.DeleteColumn(0);
}
if (m_bImageInLV) {
m_bImageInLV = false;
m_ctlItemList.SetImageList(NULL, LVSIL_NORMAL);
m_ctlItemList.SetImageList(NULL, LVSIL_SMALL);
}
// re-initialise array
for (int itype = 0; itype < CItemData::LAST; itype++)
m_nColumnIndexByType[itype] = -1;
// Set default columns
SetColumns();
// Reset the column widths
AutoResizeColumns();
// Refresh the ListView
RefreshViews(iListOnly);
// Reset Column Chooser dialog but only if already created
if (m_pCC != NULL)
SetupColumnChooser(false);
}
void DboxMain::AutoResizeColumns()
{
int iIndex, iType;
// CHeaderCtrl get values
for (int iOrder = 0; iOrder < m_nColumns; iOrder++) {
iIndex = m_nColumnIndexByOrder[iOrder];
iType = m_nColumnTypeByIndex[iIndex];
m_ctlItemList.SetColumnWidth(iIndex, LVSCW_AUTOSIZE);
m_nColumnWidthByIndex[iIndex] = m_ctlItemList.GetColumnWidth(iIndex);
if (m_nColumnWidthByIndex[iIndex] < m_nColumnHeaderWidthByType[iType]) {
m_ctlItemList.SetColumnWidth(iIndex, m_nColumnHeaderWidthByType[iType]);
m_nColumnWidthByIndex[iIndex] = m_nColumnHeaderWidthByType[iType];
}
}
m_ctlItemList.UpdateWindow();
// First column is special if an image
if (m_bImageInLV) {
m_ctlItemList.SetColumnWidth(0, LVSCW_AUTOSIZE);
}
// Last column is special
iIndex = m_nColumnIndexByOrder[m_nColumns - 1];
m_ctlItemList.SetColumnWidth(iIndex, LVSCW_AUTOSIZE);
m_ctlItemList.SetColumnWidth(iIndex, LVSCW_AUTOSIZE_USEHEADER);
m_nColumnWidthByIndex[iIndex] = m_ctlItemList.GetColumnWidth(iIndex);
}
void DboxMain::OnColumnPicker()
{
SetupColumnChooser(true);
}
void DboxMain::SetupColumnChooser(const bool bShowHide)
{
if (m_pCC == NULL) {
m_pCC = new CColumnChooserDlg;
BOOL ret = m_pCC->Create(IDD_COLUMNCHOOSER, this);
if (!ret) { //Create failed.
m_pCC = NULL;
return;
}
m_pCC->SetLVHdrCtrlPtr(&m_LVHdrCtrl);
// Set extended style
DWORD dw_style = m_pCC->m_ccListCtrl.GetExtendedStyle() | LVS_EX_ONECLICKACTIVATE;
m_pCC->m_ccListCtrl.SetExtendedStyle(dw_style);
// Make sure it doesn't appear obscure the header
CRect HDRrect, CCrect;
m_LVHdrCtrl.GetWindowRect(&HDRrect);
m_pCC->GetWindowRect(&CCrect);
// Note (0,0) is the top left of screen
if (CCrect.top < HDRrect.bottom) {
int x = CCrect.left;
int y = HDRrect.bottom + 20;
m_pCC->SetWindowPos(0, x, y, 0, 0, SWP_NOZORDER | SWP_NOSIZE);
}
// Insert column with "dummy" header
m_pCC->m_ccListCtrl.InsertColumn(0, L"");
m_pCC->m_ccListCtrl.SetColumnWidth(0, m_iheadermaxwidth);
// Make it just wide enough to take the text
CRect rect1, rect2;
m_pCC->GetWindowRect(&rect1);
m_pCC->m_ccListCtrl.GetWindowRect(&rect2);
m_pCC->SetWindowPos(NULL, 0, 0, m_iheadermaxwidth + 18,
rect1.Height(), SWP_NOMOVE | SWP_NOZORDER);
m_pCC->m_ccListCtrl.SetWindowPos(NULL, 0, 0, m_iheadermaxwidth + 6,
rect2.Height(), SWP_NOMOVE | SWP_NOZORDER);
}
int i;
CString cs_header;
// Clear all current entries
m_pCC->m_ccListCtrl.DeleteAllItems();
// and repopulate
int iItem;
for (i = CItemData::LAST - 1; i >= 0; i--) {
// Can't play with Title or User columns
if (i == CItemData::TITLE || i == CItemData::USER)
continue;
if (m_nColumnIndexByType[i] == -1) {
cs_header = GetHeaderText(i);
if (!cs_header.IsEmpty()) {
iItem = m_pCC->m_ccListCtrl.InsertItem(0, cs_header);
m_pCC->m_ccListCtrl.SetItemData(iItem, (DWORD)i);
}
}
}
// If called by user right clicking on header, hide it or show it
if (bShowHide)
m_pCC->ShowWindow(m_pCC->IsWindowVisible() ? SW_HIDE : SW_SHOW);
}
CString DboxMain::GetHeaderText(int iType) const
{
CString cs_header;
switch (iType) {
case CItemData::UUID:
cs_header.LoadString(IDS_ICON);
break;
case CItemData::GROUP:
cs_header.LoadString(IDS_GROUP);
break;
case CItemData::TITLE:
cs_header.LoadString(IDS_TITLE);
break;
case CItemData::USER:
cs_header.LoadString(IDS_USERNAME);
break;
case CItemData::PASSWORD:
cs_header.LoadString(IDS_PASSWORD);
break;
case CItemData::URL:
cs_header.LoadString(IDS_URL);
break;
case CItemData::AUTOTYPE:
cs_header.LoadString(IDS_AUTOTYPE);
break;
case CItemData::EMAIL:
cs_header.LoadString(IDS_EMAIL);
break;
case CItemData::SYMBOLS:
cs_header.LoadString(IDS_SYMBOLS);
break;
case CItemData::RUNCMD:
cs_header.LoadString(IDS_RUNCOMMAND);
break;
case CItemData::NOTES:
cs_header.LoadString(IDS_NOTES);
break;
case CItemData::CTIME:
cs_header.LoadString(IDS_CREATED);
break;
case CItemData::PMTIME:
cs_header.LoadString(IDS_PASSWORDMODIFIED);
break;
case CItemData::ATIME:
cs_header.LoadString(IDS_LASTACCESSED);
break;
case CItemData::XTIME:
cs_header.LoadString(IDS_PASSWORDEXPIRYDATE);
break;
case CItemData::XTIME_INT:
cs_header.LoadString(IDS_PASSWORDEXPIRYDATEINT);
break;
case CItemData::RMTIME:
cs_header.LoadString(IDS_LASTMODIFIED);
break;
case CItemData::POLICY:
cs_header.LoadString(IDS_PWPOLICY);
break;
case CItemData::POLICYNAME:
cs_header.LoadString(IDS_POLICYNAME);
break;
case CItemData::PROTECTED:
cs_header.LoadString(IDS_PROTECTED);
break;
default:
cs_header.Empty();
}
return cs_header;
}
int DboxMain::GetHeaderWidth(int iType) const
{
int nWidth(0);
switch (iType) {
case CItemData::UUID:
case CItemData::GROUP:
case CItemData::TITLE:
case CItemData::USER:
case CItemData::PASSWORD:
case CItemData::NOTES:
case CItemData::URL:
case CItemData::EMAIL:
case CItemData::SYMBOLS:
case CItemData::RUNCMD:
case CItemData::POLICY:
case CItemData::POLICYNAME:
case CItemData::XTIME_INT:
nWidth = m_nColumnHeaderWidthByType[iType];
break;
case CItemData::CTIME:
case CItemData::PMTIME:
case CItemData::ATIME:
case CItemData::XTIME:
case CItemData::RMTIME:
nWidth = m_iDateTimeFieldWidth;
break;
default:
break;
}
return nWidth;
}
void DboxMain::CalcHeaderWidths()
{
// Get default column width for datetime fields
wchar_t time_str[80], datetime_str[80];
// Use "fictitious" longest English date
SYSTEMTIME systime;
systime.wYear = (WORD)2000;
systime.wMonth = (WORD)9;
systime.wDay = (WORD)30;
systime.wDayOfWeek = (WORD)3;
systime.wHour = (WORD)23;
systime.wMinute = (WORD)44;
systime.wSecond = (WORD)55;
systime.wMilliseconds = (WORD)0;
wchar_t szBuf[80];
VERIFY(::GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SSHORTDATE, szBuf, 80));
GetDateFormat(LOCALE_USER_DEFAULT, 0, &systime, szBuf, datetime_str, 80);
szBuf[0] = L' '; // Put a blank between date and time
VERIFY(::GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_STIMEFORMAT, &szBuf[1], 79));
GetTimeFormat(LOCALE_USER_DEFAULT, 0, &systime, szBuf, time_str, 80);
#if (_MSC_VER >= 1400)
wcscat_s(datetime_str, 80, time_str);
#else
wcscat(datetime_str, 80, time_str);
#endif
m_iDateTimeFieldWidth = m_ctlItemList.GetStringWidth(datetime_str) + 6;
m_iheadermaxwidth = -1;
CString cs_header;
for (int iType = 0; iType < CItemData::LAST; iType++) {
cs_header = GetHeaderText(iType);
if (!cs_header.IsEmpty())
m_nColumnHeaderWidthByType[iType] = m_ctlItemList.GetStringWidth(cs_header) + 20;
else
m_nColumnHeaderWidthByType[iType] = -4;
m_iheadermaxwidth = max(m_iheadermaxwidth, m_nColumnHeaderWidthByType[iType]);
} // for
}
void DboxMain::UnFindItem()
{
// Entries found are made bold - remove it here.
if (m_bBoldItem) {
m_ctlItemTree.SetItemState(m_LastFoundTreeItem, 0, TVIS_BOLD);
m_bBoldItem = false;
}
}
static bool GetDriveAndDirectory(const StringX &cs_infile, CString &cs_drive,
CString &cs_directory)
{
std::wstring applicationpath = pws_os::getexecdir();
std::wstring inpath = cs_infile.c_str();
std::wstring appdrive, appdir;
std::wstring drive, dir, file, ext;
pws_os::splitpath(applicationpath, appdrive, appdir, file, ext);
if (!pws_os::splitpath(inpath, drive, dir, file, ext)) {
pws_os::IssueError(L"View Report: Error finding path to database");
return false;
}
if (drive.empty())
drive = appdrive;
if (dir.empty())
dir = appdir;
cs_drive = drive.c_str();
cs_directory = dir.c_str();
return true;
}
void DboxMain::OnViewReports()
{
CString cs_filename, cs_path, csAction;
CString cs_directory, cs_drive;
if (!GetDriveAndDirectory(m_core.GetCurFile(), cs_drive, cs_directory))
return;
CGeneralMsgBox gmb;
CString cs_msg(MAKEINTRESOURCE(IDS_SELECTREPORT));
gmb.SetMsg(cs_msg);
struct _stat statbuf;
bool bReportExists(false);
int Reports[] = {
IDS_RPTCOMPARE, IDS_RPTFIND, IDS_RPTIMPORTTEXT, IDS_RPTIMPORTXML,
IDS_RPTIMPORTKPV1CSV, IDS_RPTIMPORTKPV1TXT,
IDS_RPTEXPORTTEXT, IDS_RPTEXPORTXML,
IDS_RPTMERGE, IDS_RPTSYNCH, IDS_RPTVALIDATE,
};
for (int i = 0; i < sizeof(Reports) / sizeof(Reports[0]); i++) {
csAction.LoadString(Reports[i]);
cs_filename.Format(IDSC_REPORTFILENAME, cs_drive, cs_directory, csAction);
if (::_tstat(cs_filename, &statbuf) == 0) {
gmb.AddButton(Reports[i], csAction);
bReportExists = true;
}
}
if (!bReportExists) {
CGeneralMsgBox gmb;
gmb.AfxMessageBox(IDS_NOREPORTSEXIST);
return;
}
gmb.AddButton(IDCANCEL, IDS_CANCEL, TRUE, TRUE);
gmb.SetStandardIcon(MB_ICONQUESTION);
INT_PTR rc = gmb.DoModal();
UINT uistring(0);
switch (rc) {
case IDS_RPTCOMPARE:
case IDS_RPTFIND:
case IDS_RPTIMPORTTEXT:
case IDS_RPTIMPORTXML:
case IDS_RPTIMPORTKPV1CSV:
case IDS_RPTIMPORTKPV1TXT:
case IDS_RPTEXPORTTEXT:
case IDS_RPTEXPORTXML:
case IDS_RPTMERGE:
case IDS_RPTSYNCH:
case IDS_RPTVALIDATE:
uistring = (UINT)rc;
break;
default:
return;
}
csAction.LoadString(uistring);
cs_filename.Format(IDSC_REPORTFILENAME, cs_drive, cs_directory, csAction);
ViewReport(cs_filename);
return;
}
static UINT SetupViewReports(const int nID)
{
switch (nID) {
case ID_MENUITEM_REPORT_COMPARE:
return IDS_RPTCOMPARE;
case ID_MENUITEM_REPORT_FIND:
return IDS_RPTFIND;
case ID_MENUITEM_REPORT_IMPORTTEXT:
return IDS_RPTIMPORTTEXT;
case ID_MENUITEM_REPORT_IMPORTXML:
return IDS_RPTIMPORTXML;
case ID_MENUITEM_REPORT_IMPORTKP1CSV:
return IDS_RPTIMPORTKPV1CSV;
case ID_MENUITEM_REPORT_IMPORTKP1TXT:
return IDS_RPTIMPORTKPV1TXT;
case ID_MENUITEM_REPORT_MERGE:
return IDS_RPTMERGE;
case ID_MENUITEM_REPORT_SYNCHRONIZE:
return IDS_RPTSYNCH;
case ID_MENUITEM_REPORT_EXPORTTEXT:
return IDS_RPTEXPORTTEXT;
case ID_MENUITEM_REPORT_EXPORTXML:
return IDS_RPTEXPORTXML;
case ID_MENUITEM_REPORT_VALIDATE:
return IDS_RPTVALIDATE;
default:
pws_os::Trace(L"ID=%d\n", nID);
ASSERT(0);
return 0;
}
}
void DboxMain::OnViewReportsByID(UINT nID)
{
CString cs_filename, cs_path, csAction;
CString cs_drive, cs_directory;
if (!GetDriveAndDirectory(m_core.GetCurFile(), cs_drive, cs_directory))
return;
csAction.LoadString(SetupViewReports(nID));
cs_filename.Format(IDSC_REPORTFILENAME, cs_drive, cs_directory, csAction);
ViewReport(cs_filename);
}
void DboxMain::ViewReport(CReport &rpt) const
{
CViewReport vr_dlg(const_cast<DboxMain*>(this), &rpt);
vr_dlg.DoModal();
}
void DboxMain::ViewReport(const CString &cs_ReportFileName) const
{
CString cs_drive, cs_directory;
if (!GetDriveAndDirectory(LPCWSTR(cs_ReportFileName), cs_drive, cs_directory))
return;
CString cs_path = cs_drive + cs_directory;
wchar_t szExecName[MAX_PATH + 1];
// Find out the users default editor for "txt" files
DWORD dwSize(MAX_PATH);
HRESULT stat = ::AssocQueryString(0, ASSOCSTR_EXECUTABLE, L".txt", L"Open",
szExecName, &dwSize);
if (int(stat) != S_OK) {
#ifdef _DEBUG
CGeneralMsgBox gmb;
gmb.AfxMessageBox(L"oops");
#endif
return;
}
// Create an Edit process
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
ZeroMemory(&pi, sizeof(pi));
DWORD dwCreationFlags(0);
dwCreationFlags = CREATE_UNICODE_ENVIRONMENT;
CString cs_CommandLine;
// Make the command line = "<program>" "file"
cs_CommandLine.Format(L"\"%s\" \"%s\"", szExecName, cs_ReportFileName);
int ilen = cs_CommandLine.GetLength();
LPWSTR pszCommandLine = cs_CommandLine.GetBuffer(ilen);
if (!CreateProcess(NULL, pszCommandLine, NULL, NULL, FALSE, dwCreationFlags,
NULL, cs_path, &si, &pi)) {
pws_os::Trace(L"CreateProcess failed (%d).\n", GetLastError());
}
// Close process and thread handles.
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
cs_CommandLine.ReleaseBuffer();
}
int DboxMain::OnUpdateViewReports(const int nID)
{
StringX cs_Database(m_core.GetCurFile());
if (cs_Database.empty()) {
return FALSE;
}
CString cs_filename, csAction;
CString cs_drive, cs_directory;
if (!GetDriveAndDirectory(cs_Database, cs_drive, cs_directory))
return FALSE;
csAction.LoadString(SetupViewReports(nID));
cs_filename.Format(IDSC_REPORTFILENAME, cs_drive, cs_directory, csAction);
struct _stat statbuf;
// Only allow selection if file exists!
int status = ::_tstat(cs_filename, &statbuf);
return (status != 0) ? FALSE : TRUE;
}
void DboxMain::OnRefreshWindow()
{
PWS_LOGIT;
// Useful for users if they are using a filter and have edited an entry
// so it no longer passes
RefreshViews();
}
void DboxMain::OnCustomizeToolbar()
{
CToolBarCtrl& mainTBCtrl = m_MainToolBar.GetToolBarCtrl();
mainTBCtrl.Customize();
StringX cs_temp = LPCWSTR(m_MainToolBar.GetButtonString());
PWSprefs::GetInstance()->SetPref(PWSprefs::MainToolBarButtons, cs_temp);
CItemData *pci = getSelectedItem();
UpdateToolBarForSelectedItem(pci);
}
void DboxMain::OnHideFindToolBar()
{
SetFindToolBar(false);
// Select the last found item on closing the FindToolbar (either by pressing
// close or via Esc key if not used to minimize application).
if (m_ctlItemList.IsWindowVisible() && m_LastFoundListItem != -1) {
m_ctlItemList.SetFocus();
m_ctlItemList.SetItemState(m_LastFoundListItem,
LVIS_FOCUSED | LVIS_SELECTED,
LVIS_FOCUSED | LVIS_SELECTED);
} else
if (m_ctlItemTree.IsWindowVisible() && m_LastFoundTreeItem != NULL) {
m_ctlItemTree.SetFocus();
m_ctlItemTree.Select(m_LastFoundTreeItem, TVGN_CARET);
}
}
void DboxMain::SetFindToolBar(bool bShow)
{
if (m_FindToolBar.GetSafeHwnd() == NULL)
return;
if (bShow)
m_core.ResumeOnDBNotification();
m_FindToolBar.ShowFindToolBar(bShow);
SetToolBarPositions();
}
void DboxMain::SetToolBarPositions()
{
if (m_FindToolBar.GetSafeHwnd() == NULL)
return;
CRect rect, dragrect;
RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);
RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0, reposQuery, &rect);
bool bDragBarState = PWSprefs::GetInstance()->GetPref(PWSprefs::ShowDragbar);
CDDStatic *DDs[] = { &m_DDGroup, &m_DDTitle, &m_DDUser,
&m_DDPassword, &m_DDNotes, &m_DDURL, &m_DDemail,
&m_DDAutotype};
if (bDragBarState) {
// Get the image states just incase another entry selected
// since last shown
CItemData *entry = GetLastSelected();
if (entry == NULL) {
m_DDGroup.SetStaticState(m_core.GetNumEntries() != 0);
m_DDTitle.SetStaticState(false);
m_DDPassword.SetStaticState(false);
m_DDUser.SetStaticState(false);
m_DDNotes.SetStaticState(false);
m_DDURL.SetStaticState(false);
m_DDemail.SetStaticState(false);
m_DDAutotype.SetStaticState(false);
} else {
m_DDGroup.SetStaticState(!entry->IsGroupEmpty());
m_DDTitle.SetStaticState(true);
m_DDPassword.SetStaticState(true);
m_DDUser.SetStaticState(!entry->IsUserEmpty());
m_DDNotes.SetStaticState(!entry->IsNotesEmpty());
m_DDURL.SetStaticState(!entry->IsURLEmpty());
m_DDemail.SetStaticState(!entry->IsEmailEmpty());
m_DDAutotype.SetStaticState(true);
}
const int i = GetSystemMetrics(SM_CYBORDER);
for (int j = 0; j < sizeof(DDs)/sizeof(DDs[0]); j++) {
DDs[j]->ShowWindow(SW_SHOW);
DDs[j]->EnableWindow(TRUE);
DDs[j]->GetWindowRect(&dragrect);
ScreenToClient(&dragrect);
DDs[j]->SetWindowPos(NULL, dragrect.left, rect.top + i, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
}
rect.top += dragrect.Height() + 2 * i;
} else { // !bDragBarState
for (int j = 0; j < sizeof(DDs)/sizeof(DDs[0]); j++) {
DDs[j]->ShowWindow(SW_HIDE);
DDs[j]->EnableWindow(FALSE);
}
}
m_ctlItemList.MoveWindow(&rect, TRUE);
m_ctlItemTree.MoveWindow(&rect, TRUE);
if (m_FindToolBar.IsVisible()) {
// Is visible. Try to get FindToolBar "above" the StatusBar!
ASSERT(m_FindToolBar.GetParent() == m_statusBar.GetParent());
CRect ftb_rect, stb_rect;
m_FindToolBar.GetWindowRect(&ftb_rect);
m_statusBar.GetWindowRect(&stb_rect);
if (ftb_rect.top > stb_rect.top) {
// FindToolBar is "below" the StatusBar
ScreenToClient(&ftb_rect);
ScreenToClient(&stb_rect);
// Move FindToolBar up by the height of the Statusbar
m_FindToolBar.MoveWindow(ftb_rect.left, ftb_rect.top - stb_rect.Height(),
ftb_rect.Width(), ftb_rect.Height());
// Move Statusbar down by the height of the FindToolBar
m_statusBar.MoveWindow(stb_rect.left, stb_rect.top + ftb_rect.Height(),
stb_rect.Width(), stb_rect.Height());
m_FindToolBar.Invalidate();
m_statusBar.Invalidate();
}
}
}
void DboxMain::OnToolBarClearFind()
{
m_FindToolBar.ClearFind();
}
void DboxMain::OnToolBarFindCase()
{
m_FindToolBar.ToggleToolBarFindCase();
}
void DboxMain::OnToolBarFindAdvanced()
{
m_FindToolBar.ShowFindAdvanced();
}
void DboxMain::OnToolBarFindReport()
{
std::vector<int> *pindices;
CString csFindString;
pindices = m_FindToolBar.GetSearchResults();
m_FindToolBar.GetSearchText(csFindString);
if (pindices == NULL || csFindString.IsEmpty())
return;
CString buffer, cs_temp;
CReport rpt;
cs_temp.LoadString(IDS_RPTFIND);
rpt.StartReport(cs_temp, m_core.GetCurFile().c_str());
CItemData::FieldBits bsFFields;
bool bFAdvanced;
std::wstring Fsubgroup_name;
int Fsubgroup_object, Fsubgroup_function;
bool Fsubgroup_set;
m_FindToolBar.GetSearchInfo(bFAdvanced, bsFFields, Fsubgroup_name,
Fsubgroup_set, Fsubgroup_object, Fsubgroup_function);
// tell the user we're done & provide short Compare report
if (!bFAdvanced) {
cs_temp.LoadString(IDS_NONE);
buffer.Format(IDS_ADVANCEDOPTIONS, cs_temp);
rpt.WriteLine((LPCWSTR)buffer);
rpt.WriteLine();
} else {
if (!Fsubgroup_set) {
cs_temp.LoadString(IDS_NONE);
} else {
CString cs_Object, cs_case, cs_text;
UINT uistring(0);
switch(Fsubgroup_object) {
case CItemData::GROUP:
uistring = IDS_GROUP;
break;
case CItemData::TITLE:
uistring = IDS_TITLE;
break;
case CItemData::USER:
uistring = IDS_USERNAME;
break;
case CItemData::GROUPTITLE:
uistring = IDS_GROUPTITLE;
break;
case CItemData::URL:
uistring = IDS_URL;
break;
case CItemData::EMAIL:
uistring = IDS_EMAIL;
break;
case CItemData::SYMBOLS:
uistring = IDS_SYMBOLS;
break;
case CItemData::RUNCMD:
uistring = IDS_RUNCOMMAND;
break;
case CItemData::NOTES:
uistring = IDS_NOTES;
break;
default:
ASSERT(0);
}
cs_Object.LoadString(uistring);
cs_case.LoadString(Fsubgroup_function > 0 ?
IDS_ADVCASE_INSENSITIVE : IDS_ADVCASE_SENSITIVE);
uistring = PWSMatch::GetRule(PWSMatch::MatchRule(abs(Fsubgroup_function)));
cs_text.LoadString(uistring);
cs_temp.Format(IDS_ADVANCEDSUBSET, cs_Object, cs_text, Fsubgroup_name,
cs_case);
}
buffer.Format(IDS_ADVANCEDOPTIONS, cs_temp);
rpt.WriteLine((LPCWSTR)buffer);
rpt.WriteLine();
cs_temp.LoadString(IDS_RPTFIND);
buffer.Format(IDS_ADVANCEDFIELDS, cs_temp);
rpt.WriteLine((LPCWSTR)buffer);
buffer = L"\t";
// Non-time fields
if (bsFFields.test(CItemData::GROUP))
buffer += L"\t" + CString(MAKEINTRESOURCE(IDS_FINDGROUP));
if (bsFFields.test(CItemData::TITLE))
buffer += L"\t" + CString(MAKEINTRESOURCE(IDS_FINDTITLE));
if (bsFFields.test(CItemData::USER))
buffer += L"\t" + CString(MAKEINTRESOURCE(IDS_FINDUSER));
if (bsFFields.test(CItemData::PASSWORD))
buffer += L"\t" + CString(MAKEINTRESOURCE(IDS_COMPPASSWORD));
if (bsFFields.test(CItemData::NOTES))
buffer += L"\t" + CString(MAKEINTRESOURCE(IDS_COMPNOTES));
if (bsFFields.test(CItemData::URL))
buffer += L"\t" + CString(MAKEINTRESOURCE(IDS_COMPURL));
if (bsFFields.test(CItemData::EMAIL))
buffer += L"\t" + CString(MAKEINTRESOURCE(IDS_COMPEMAIL));
if (bsFFields.test(CItemData::PROTECTED))
buffer += L"\t" + CString(MAKEINTRESOURCE(IDS_COMPPROTECTED));
if (bsFFields.test(CItemData::SYMBOLS))
buffer += L"\t" + CString(MAKEINTRESOURCE(IDS_COMPSYMBOLS));
if (bsFFields.test(CItemData::RUNCMD))
buffer += L"\t" + CString(MAKEINTRESOURCE(IDS_COMPRUNCOMMAND));
if (bsFFields.test(CItemData::AUTOTYPE))
buffer += L"\t" + CString(MAKEINTRESOURCE(IDS_COMPAUTOTYPE));
if (bsFFields.test(CItemData::PWHIST))
buffer += L"\t" + CString(MAKEINTRESOURCE(IDS_COMPPWHISTORY));
if (bsFFields.test(CItemData::POLICYNAME))
buffer += L"\t" + CString(MAKEINTRESOURCE(IDS_COMPPOLICYNAME));
rpt.WriteLine((LPCWSTR)buffer);
rpt.WriteLine();
}
if (pindices->empty()) {
buffer.Format(IDS_SEARCHRESULTS1, csFindString);
rpt.WriteLine((LPCWSTR)buffer);
} else {
buffer.Format(IDS_SEARCHRESULTS2, csFindString);
rpt.WriteLine((LPCWSTR)buffer);
int i, index;
for (i = 0; i < (int)pindices->size(); i++) {
index = pindices->at(i);
CItemData *pci = (CItemData *)m_ctlItemList.GetItemData(index);
buffer.Format(IDS_COMPARESTATS, pci->GetGroup().c_str(),
pci->GetTitle().c_str(), pci->GetUser().c_str());
rpt.WriteLine((LPCWSTR)buffer, false);
}
}
rpt.WriteLine();
rpt.EndReport();
CGeneralMsgBox gmb;
gmb.SetTitle(IDS_RPTFIND);
gmb.SetMsg(IDS_REPORTCREATED);
gmb.SetStandardIcon(MB_ICONINFORMATION);
gmb.AddButton(IDS_OK, IDS_OK, TRUE, TRUE);
gmb.AddButton(IDS_VIEWREPORT, IDS_VIEWREPORT);
INT_PTR msg_rc = gmb.DoModal();
if (msg_rc == IDS_VIEWREPORT)
ViewReport(rpt);
m_FindToolBar.SetStatus(cs_temp);
}
int DboxMain::GetEntryImage(const CItemData &ci) const
{
int entrytype = ci.GetEntryType();
if (entrytype == CItemData::ET_ALIAS) {
return CPWTreeCtrl::ALIAS;
}
if (entrytype == CItemData::ET_SHORTCUT) {
return CPWTreeCtrl::SHORTCUT;
}
int nImage;
switch (entrytype) {
case CItemData::ET_NORMAL:
nImage = CPWTreeCtrl::NORMAL;
break;
case CItemData::ET_ALIASBASE:
nImage = CPWTreeCtrl::ALIASBASE;
break;
case CItemData::ET_SHORTCUTBASE:
nImage = CPWTreeCtrl::SHORTCUTBASE;
break;
default:
nImage = CPWTreeCtrl::NORMAL;
}
time_t tttXTime;
ci.GetXTime(tttXTime);
if (tttXTime > time_t(0) && tttXTime <= time_t(3650)) {
time_t tttCPMTime;
ci.GetPMTime(tttCPMTime);
if ((long)tttCPMTime == 0L)
ci.GetCTime(tttCPMTime);
tttXTime = (time_t)((long)tttCPMTime + (long)tttXTime * 86400);
}
if (tttXTime != 0) {
time_t now, warnexptime((time_t)0);
time(&now);
if (PWSprefs::GetInstance()->GetPref(PWSprefs::PreExpiryWarn)) {
int idays = PWSprefs::GetInstance()->GetPref(PWSprefs::PreExpiryWarnDays);
struct tm st;
#if (_MSC_VER >= 1400)
errno_t err;
err = localtime_s(&st, &now); // secure version
ASSERT(err == 0);
#else
st = *localtime(&now);
ASSERT(st != NULL); // null means invalid time
#endif
st.tm_mday += idays;
warnexptime = mktime(&st);
if (warnexptime == (time_t)-1)
warnexptime = (time_t)0;
}
if (tttXTime <= now) {
nImage += 2; // Expired
} else if (tttXTime < warnexptime) {
nImage += 1; // Warn nearly expired
}
}
return nImage;
}
void DboxMain::SetEntryImage(const int &index, const int nImage, const bool bOneEntry)
{
if (!m_bImageInLV)
return;
m_ctlItemList.SetItem(index, 0, LVIF_IMAGE, NULL, nImage, 0, 0, 0);
if (bOneEntry) {
CRect rect;
m_ctlItemList.GetItemRect(index, &rect, LVIR_ICON);
m_ctlItemList.InvalidateRect(&rect);
}
}
void DboxMain::SetEntryImage(HTREEITEM &ti, const int nImage, const bool bOneEntry)
{
m_ctlItemTree.SetItemImage(ti, nImage, nImage);
if (bOneEntry) {
CRect rect;
m_ctlItemTree.GetItemRect(ti, &rect, FALSE);
m_ctlItemTree.InvalidateRect(&rect);
}
}
void DboxMain::UpdateEntryImages(const CItemData &ci)
{
DisplayInfo *pdi = (DisplayInfo *)ci.GetDisplayInfo();
if (ci.GetStatus() != CItemData::ES_DELETED) {
int nImage = GetEntryImage(ci);
SetEntryImage(pdi->list_index, nImage, true);
SetEntryImage(pdi->tree_item, nImage, true);
} else { // deleted item, remove from display
m_ctlItemList.DeleteItem(pdi->list_index);
m_ctlItemTree.DeleteItem(pdi->tree_item);
}
}
void DboxMain::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpdis)
{
if (lpdis == NULL || lpdis->CtlType != ODT_MENU) {
// not for an ownerdrawn menu
CDialog::OnDrawItem(nIDCtl, lpdis);
return;
}
if (lpdis->rcItem.left != 2) {
lpdis->rcItem.left -= (lpdis->rcItem.left - 2);
lpdis->rcItem.right -= 60;
if (lpdis->itemState & ODS_SELECTED) {
lpdis->rcItem.left++;
lpdis->rcItem.right++;
}
}
CRUEItemData *pmd;
pmd = (CRUEItemData *)lpdis->itemData;
if (!pmd || !pmd->IsRUEID() || pmd->nImage < 0)
return;
HICON hIcon = GetEntryIcon(pmd->nImage);
if (hIcon) {
ICONINFO iconinfo;
::GetIconInfo(hIcon, &iconinfo);
BITMAP bitmap;
::GetObject(iconinfo.hbmColor, sizeof(bitmap), &bitmap);
::DeleteObject(iconinfo.hbmColor);
::DeleteObject(iconinfo.hbmMask);
::DrawIconEx(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top, hIcon,
bitmap.bmWidth, bitmap.bmHeight,
0, NULL, DI_IMAGE /*NORMAL*/);
::DeleteObject(hIcon);
}
}
void DboxMain::OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpmis)
{
if (lpmis == NULL || lpmis->CtlType != ODT_MENU) {
// not for an ownerdrawn menu
CDialog::OnMeasureItem(nIDCtl, lpmis);
return;
}
lpmis->itemWidth = 16;
lpmis->itemHeight = 16;
CRUEItemData *pmd;
pmd = (CRUEItemData *)lpmis->itemData;
if (!pmd || !pmd->IsRUEID() || pmd->nImage < 0)
return;
HICON hIcon = GetEntryIcon(pmd->nImage);
if (hIcon) {
ICONINFO iconinfo;
::GetIconInfo(hIcon, &iconinfo);
BITMAP bitmap;
::GetObject(iconinfo.hbmColor, sizeof(bitmap), &bitmap);
::DeleteObject(iconinfo.hbmColor);
::DeleteObject(iconinfo.hbmMask);
lpmis->itemWidth = bitmap.bmWidth;
lpmis->itemHeight = bitmap.bmHeight;
}
}
HICON DboxMain::GetEntryIcon(const int nImage) const
{
int nID;
switch (nImage) {
case CPWTreeCtrl::NORMAL:
nID = IDI_NORMAL;
break;
case CPWTreeCtrl::WARNEXPIRED_NORMAL:
nID = IDI_NORMAL_WARNEXPIRED;
break;
case CPWTreeCtrl::EXPIRED_NORMAL:
nID = IDI_NORMAL_EXPIRED;
break;
case CPWTreeCtrl::ALIASBASE:
nID = IDI_ABASE;
break;
case CPWTreeCtrl::WARNEXPIRED_ALIASBASE:
nID = IDI_ABASE_WARNEXPIRED;
break;
case CPWTreeCtrl::EXPIRED_ALIASBASE:
nID = IDI_ABASE_EXPIRED;
break;
case CPWTreeCtrl::ALIAS:
nID = IDI_ALIAS;
break;
case CPWTreeCtrl::SHORTCUTBASE:
nID = IDI_SBASE;
break;
case CPWTreeCtrl::WARNEXPIRED_SHORTCUTBASE:
nID = IDI_SBASE_WARNEXPIRED;
break;
case CPWTreeCtrl::EXPIRED_SHORTCUTBASE:
nID = IDI_SBASE_EXPIRED;
break;
case CPWTreeCtrl::SHORTCUT:
nID = IDI_SHORTCUT;
break;
default:
nID = IDI_NORMAL;
}
HICON hIcon = (HICON)::LoadImage(::AfxGetResourceHandle(), MAKEINTRESOURCE(nID),
IMAGE_ICON, 0, 0,
LR_LOADMAP3DCOLORS | LR_SHARED);
return hIcon;
}
bool DboxMain::SetNotesWindow(const CPoint ptClient, const bool bVisible)
{
const CItemData *pci(NULL);
CPoint ptScreen(ptClient);
StringX sx_notes(L"");
UINT nFlags;
HTREEITEM hItem(NULL);
int nItem(-1);
if (m_pNotesDisplay == NULL)
return false;
if (!bVisible) {
m_pNotesDisplay->SetWindowText(sx_notes.c_str());
m_pNotesDisplay->ShowWindow(SW_HIDE);
return false;
}
if (m_ctlItemTree.IsWindowVisible()) {
m_ctlItemTree.ClientToScreen(&ptScreen);
hItem = m_ctlItemTree.HitTest(ptClient, &nFlags);
if (hItem != NULL &&
(nFlags & (TVHT_ONITEM | TVHT_ONITEMBUTTON | TVHT_ONITEMINDENT))) {
pci = (CItemData *)m_ctlItemTree.GetItemData(hItem);
}
} else {
m_ctlItemList.ClientToScreen(&ptScreen);
nItem = m_ctlItemList.HitTest(ptClient, &nFlags);
if (nItem >= 0) {
pci = (CItemData *)m_ctlItemList.GetItemData(nItem);
}
}
ptScreen.y += ::GetSystemMetrics(SM_CYCURSOR) / 2; // half-height of cursor
if (pci != NULL) {
if (pci->IsShortcut())
pci = GetBaseEntry(pci);
sx_notes = pci->GetNotes();
}
if (!sx_notes.empty()) {
Replace(sx_notes, StringX(L"\r\n"), StringX(L"\n"));
Remove(sx_notes, L'\r');
if (sx_notes.length() > 256)
sx_notes = sx_notes.substr(0, 250) + L"[...]";
}
// move window
CString cs_oldnotes;
m_pNotesDisplay->GetWindowText(cs_oldnotes);
if (LPCWSTR(cs_oldnotes) != sx_notes)
m_pNotesDisplay->SetWindowText(sx_notes.c_str());
m_pNotesDisplay->SetWindowPos(NULL, ptScreen.x, ptScreen.y, 0, 0,
SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
m_pNotesDisplay->ShowWindow(!sx_notes.empty() ? SW_SHOWNA : SW_HIDE);
return !sx_notes.empty();
}
CItemData *DboxMain::GetLastSelected() const
{
CItemData *pci(NULL);
if (m_core.GetNumEntries() == 0)
return pci;
if (m_ctlItemTree.IsWindowVisible()) {
HTREEITEM hSelected = m_ctlItemTree.GetSelectedItem();
if (hSelected != NULL)
pci = (CItemData *)m_ctlItemTree.GetItemData(hSelected);
} else {
POSITION pos = m_ctlItemList.GetFirstSelectedItemPosition();
if (pos != NULL) {
int i = m_ctlItemList.GetNextSelectedItem(pos);
pci = (CItemData *)m_ctlItemList.GetItemData(i);
}
}
return pci;
}
StringX DboxMain::GetGroupName() const
{
HTREEITEM hi = m_ctlItemTree.GetSelectedItem();
StringX s(L"");
if (hi != NULL)
s = m_ctlItemTree.GetItemText(hi);
if ((GetKeyState(VK_CONTROL) & 0x8000) == 0) {
while ((hi = m_ctlItemTree.GetParentItem(hi)) != NULL) {
s = StringX(m_ctlItemTree.GetItemText(hi)) + StringX(L".") + s;
}
}
return s;
}
void DboxMain::UpdateGroupNamesInMap(const StringX sxOldPath, const StringX sxNewPath)
{
// When a group node is renamed, need to update the group to HTREEITEM map
// We need to build a new map, as we can't erase & add while iterating.
std::map<StringX, HTREEITEM> new_map;
size_t len = sxOldPath.length();
std::map<StringX, HTREEITEM>::iterator iter;
for (iter = m_mapGroupToTreeItem.begin();
iter != m_mapGroupToTreeItem.end(); iter++) {
// Only change if path to root is the same
if (iter->first.length() == len) {
if (wcsncmp(sxOldPath.c_str(), iter->first.c_str(), len) == 0) {
HTREEITEM ti = iter->second;
new_map.insert(make_pair(sxNewPath, ti));
continue;
}
} else if (iter->first.length() > len) {
// Need to add group seperator to ensure not affecting another group
StringX path = sxOldPath + StringX(GROUP_SEP2);
if (wcsncmp(path.c_str(), iter->first.c_str(), len + 1) == 0) {
HTREEITEM ti = iter->second;
StringX sxNewGroup = sxNewPath + iter->first.substr(len);
new_map.insert(make_pair(sxNewGroup, ti));
continue;
}
}
new_map.insert(*iter);
} // for
ASSERT(new_map.size() == m_mapGroupToTreeItem.size());
m_mapGroupToTreeItem = new_map;
}
void DboxMain::OnShowUnsavedEntries()
{
m_bUnsavedDisplayed = !m_bUnsavedDisplayed;
// Check if it needs setting up the first time
if (m_showunsavedfilter.num_Mactive < 3) {
CString cs_temp(MAKEINTRESOURCE(IDS_NONSAVEDCHANGES));
m_showunsavedfilter.fname = cs_temp;
st_FilterRow fr;
fr.bFilterComplete = true;
fr.ftype = FT_ENTRYSTATUS;
fr.mtype = PWSMatch::MT_ENTRYSTATUS;
fr.rule = PWSMatch::MR_IS;
fr.ltype = LC_OR;
fr.estatus = CItemData::ES_ADDED;
m_showunsavedfilter.vMfldata.push_back(fr);
fr.estatus = CItemData::ES_MODIFIED;
m_showunsavedfilter.vMfldata.push_back(fr);
m_showunsavedfilter.num_Mactive = (int)m_showunsavedfilter.vMfldata.size();
}
if (!m_bExpireDisplayed)
m_bFilterActive = !m_bFilterActive;
if (m_bFilterActive) {
if (m_bExpireDisplayed)
m_bExpireDisplayed = !m_bExpireDisplayed;
m_currentfilter = m_showunsavedfilter;
} else
m_currentfilter.Empty();
ApplyFilters();
m_MainToolBar.GetToolBarCtrl().EnableButton(ID_MENUITEM_APPLYFILTER,
(m_bUnsavedDisplayed || !m_bFilterActive) ? FALSE : TRUE);
m_MainToolBar.GetToolBarCtrl().EnableButton(ID_MENUITEM_EDITFILTER,
m_bUnsavedDisplayed ? FALSE : TRUE);
m_MainToolBar.GetToolBarCtrl().EnableButton(ID_MENUITEM_MANAGEFILTERS,
m_bUnsavedDisplayed ? FALSE : TRUE);
}
void DboxMain::OnShowExpireList()
{
m_bExpireDisplayed = !m_bExpireDisplayed;
if (m_bExpireDisplayed) {
CString cs_temp(MAKEINTRESOURCE(IDS_EXPIREPASSWORDS));
m_showexpirefilter.Empty();
m_showexpirefilter.fname = cs_temp;
st_FilterRow fr;
fr.bFilterComplete = true;
fr.ftype = FT_XTIME;
fr.mtype = PWSMatch::MT_DATE;
fr.rule = PWSMatch::MR_NOTEQUAL;
fr.ltype = LC_OR;
fr.fdate1 = 0;
m_showexpirefilter.vMfldata.push_back(fr);
m_showexpirefilter.num_Mactive = (int)m_showexpirefilter.vMfldata.size();
}
if (!m_bUnsavedDisplayed)
m_bFilterActive = !m_bFilterActive;
if (m_bFilterActive) {
if (m_bUnsavedDisplayed)
m_bUnsavedDisplayed = !m_bUnsavedDisplayed;
m_currentfilter = m_showexpirefilter;
} else
m_currentfilter.Empty();
ApplyFilters();
m_MainToolBar.GetToolBarCtrl().EnableButton(ID_MENUITEM_APPLYFILTER,
(m_bExpireDisplayed || !m_bFilterActive) ? FALSE : TRUE);
m_MainToolBar.GetToolBarCtrl().EnableButton(ID_MENUITEM_EDITFILTER,
m_bExpireDisplayed ? FALSE : TRUE);
m_MainToolBar.GetToolBarCtrl().EnableButton(ID_MENUITEM_MANAGEFILTERS,
m_bExpireDisplayed ? FALSE : TRUE);
}
void DboxMain::UpdateToolBarDoUndo()
{
m_MainToolBar.GetToolBarCtrl().EnableButton(ID_MENUITEM_UNDO,
(m_core.AnyToUndo()) ? TRUE : FALSE);
m_MainToolBar.GetToolBarCtrl().EnableButton(ID_MENUITEM_REDO,
(m_core.AnyToRedo()) ? TRUE : FALSE);
}
void DboxMain::AddToGUI(CItemData &ci)
{
int newpos = InsertItemIntoGUITreeList(m_core.GetEntry(m_core.Find(ci.GetUUID())));
if (newpos >= 0) {
SelectEntry(newpos);
FixListIndexes();
}
RefreshViews();
}
void DboxMain::RemoveFromGUI(CItemData &ci, bool bUpdateGUI)
{
// RemoveFromGUI should always occur BEFORE the entry is deleted!
// Note: Also called if a filter is active and an entry is changed and no longer
// satisfies the filter criteria.
ItemListIter iter = m_core.Find(ci.GetUUID());
if (iter == End()) {
ASSERT(0);
return;
}
CItemData *pci2 = &iter->second;
DisplayInfo *pdi2 = (DisplayInfo *)pci2->GetDisplayInfo();
DisplayInfo *pdi = (DisplayInfo *)ci.GetDisplayInfo();
if (pdi != NULL) {
ASSERT(pdi2->list_index == pdi->list_index &&
pdi2->tree_item == pdi->tree_item);
if (bUpdateGUI) {
HTREEITEM hItem = m_ctlItemTree.GetNextItem(pdi->tree_item,
TVGN_PREVIOUSVISIBLE);
m_ctlItemTree.SelectItem(hItem);
}
m_ctlItemList.DeleteItem(pdi->list_index);
m_ctlItemTree.DeleteWithParents(pdi->tree_item);
pdi->list_index = -1;
pdi->tree_item = NULL;
FixListIndexes(); // sucks, as make M deletions an NxM operation
if (bUpdateGUI) { // Make controls redraw
m_ctlItemList.Invalidate();
m_ctlItemTree.Invalidate();
}
}
}
void DboxMain::RefreshEntryPasswordInGUI(CItemData &ci)
{
// For when Entry's password + PW history has been updated
DisplayInfo *pdi = (DisplayInfo *)ci.GetDisplayInfo();
UpdateListItem(pdi->list_index, CItemData::PWHIST, ci.GetPWHistory());
RefreshEntryFieldInGUI(ci, CItemData::PASSWORD);
}
void DboxMain::RefreshEntryFieldInGUI(CItemData &ci, CItemData::FieldType ft)
{
// For when any field is updated
DisplayInfo *pdi = (DisplayInfo *)ci.GetDisplayInfo();
StringX sx_fielddata;
const StringX &sxUnknown = PWSUtil::UNKNOWN_ASC_TIME_STR;
StringX sxNA; LoadAString(sxNA, IDS_NA);
time_t t;
switch (ft) {
case CItemData::NOTES:
{
StringX sxnotes, line1(L"");
sxnotes = ci.GetNotes();
if (!sxnotes.empty()) {
StringX::size_type end;
const StringX delim = L"\r\n";
end = sxnotes.find(delim, 0);
line1 = sxnotes.substr(0,
(end == StringX::npos) ? StringX::npos : end);
// If more than one line, add '[>>>]' to end of this line
// Note CHeaderStrl adds the normal ellipsis '...' (without square
// brackets) if the text doesn't fit in the cell. Use this to show
// more lines rather than more text in the first line.
if (end != StringX::npos)
line1 += L"[>>>]";
}
sx_fielddata = line1;
break;
}
case CItemData::CTIME:
ci.GetCTime(t);
sx_fielddata = ((long)t == 0) ? sxUnknown : ci.GetCTimeL();
break;
case CItemData::PMTIME:
ci.GetPMTime(t);
sx_fielddata = ((long)t == 0) ? sxNA : ci.GetPMTimeL();
break;
case CItemData::RMTIME:
ci.GetRMTime(t);
sx_fielddata = ((long)t == 0) ? sxNA : ci.GetRMTimeL();
break;
case CItemData::POLICY:
{
PWPolicy pwp;
ci.GetPWPolicy(pwp);
sx_fielddata = pwp.GetDisplayString();
break;
}
default:
sx_fielddata = ci.GetFieldValue(ft);
}
UpdateListItem(pdi->list_index, ft, sx_fielddata);
if (ft == CItemData::GROUP || m_bFilterActive) {
RefreshViews();
} else {
PWSprefs *prefs = PWSprefs::GetInstance();
bool bShowUsernameInTree = prefs->GetPref(PWSprefs::ShowUsernameInTree);
bool bShowPasswordInTree = prefs->GetPref(PWSprefs::ShowPasswordInTree);
if (ft == CItemData::START || ft == CItemData::TITLE ||
(ft == CItemData::USER && bShowUsernameInTree) ||
(ft == CItemData::PASSWORD && bShowPasswordInTree) ||
ft == CItemData::PROTECTED) {
StringX treeDispString = ci.GetTitle();
if (bShowUsernameInTree)
treeDispString += L" [" + ci.GetUser() + L"]";
if (bShowPasswordInTree)
treeDispString += L" {" + ci.GetPassword() + L"}";
if (ci.IsProtected())
treeDispString += L" #";
UpdateTreeItem(pdi->tree_item, treeDispString);
if (ft == CItemData::PASSWORD && bShowPasswordInTree) {
UpdateEntryImages(ci);
}
}
}
}
void DboxMain::RebuildGUI(const int iView)
{
RefreshViews(iView);
}
void DboxMain::SaveGUIStatusEx(const int iView)
{
PWS_LOGIT_ARGS("iView=%d", iView);
if (m_bInRefresh || m_bInRestoreWindows)
return;
if (!m_bOpen || app.GetSystemTrayState() != UNLOCKED || IsIconic())
return;
if (m_core.GetNumEntries() == 0)
return;
if (m_ctlItemList.GetItemCount() == 0 || m_ctlItemTree.GetCount() == 0)
return;
//pws_os::Trace(L"SaveGUIStatusEx\n");
CItemData *pci(NULL);
POSITION pos;
HTREEITEM ti;
int i;
// Note: User can have different entries selected/visible in Tree & List Views
if ((iView & iListOnly) == iListOnly) {
m_LUUIDSelectedAtMinimize = CUUID::NullUUID();
m_LUUIDVisibleAtMinimize = CUUID::NullUUID();
// List view
// Get selected entry in CListCtrl
pos = m_ctlItemList.GetFirstSelectedItemPosition();
if (pos) {
int i = m_ctlItemList.GetNextSelectedItem(pos);
pci = (CItemData *)m_ctlItemList.GetItemData(i);
ASSERT(pci != NULL); // No groups in List View
DisplayInfo *pdi = (DisplayInfo *)pci->GetDisplayInfo();
ASSERT(pdi != NULL && pdi->list_index == i);
m_LUUIDSelectedAtMinimize = pci->GetUUID();
} // p != 0
// Get first entry visible in CListCtrl
i = m_ctlItemList.GetTopIndex();
if (i >= 0) {
pci = (CItemData *)m_ctlItemList.GetItemData(i);
ASSERT(pci != NULL); // No groups in List View
DisplayInfo *pdi = (DisplayInfo *)pci->GetDisplayInfo();
ASSERT(pdi != NULL && pdi->list_index == i);
m_LUUIDVisibleAtMinimize = pci->GetUUID();
} // i >= 0
}
if ((iView & iTreeOnly) == iTreeOnly) {
// Save expand/collapse status of groups
m_vGroupDisplayState = GetGroupDisplayState();
m_LUUIDSelectedAtMinimize = CUUID::NullUUID();
m_LUUIDVisibleAtMinimize = CUUID::NullUUID();
m_sxSelectedGroup = L"";
m_sxVisibleGroup = L"";
// Tree view
// Get selected entry in CTreeCtrl
ti = m_ctlItemTree.GetSelectedItem();
if (ti != NULL) {
pci = (CItemData *)m_ctlItemTree.GetItemData(ti);
if (pci != NULL) {
// Entry: do some sanity tests
DisplayInfo *pdi = (DisplayInfo *)pci->GetDisplayInfo();
ASSERT(pdi != NULL);
if (pdi->tree_item != ti) {
pws_os::Trace(L"DboxMain::SaveGUIStatusEx: fixing pdi->tree_item!\n");
pdi->tree_item = ti;
}
m_TUUIDSelectedAtMinimize = pci->GetUUID();
} else {
// Group: save entry text
m_sxSelectedGroup = m_ctlItemTree.GetGroup(ti);
}
} // ti != NULL
// Get first entry visible in CTreeCtrl
ti = m_ctlItemTree.GetFirstVisibleItem();
if (ti != NULL) {
pci = (CItemData *)m_ctlItemTree.GetItemData(ti);
if (pci != NULL) {
// Entry: do some sanity tests
DisplayInfo *pdi = (DisplayInfo *)pci->GetDisplayInfo();
ASSERT(pdi != NULL);
if (pdi->tree_item != ti) {
pws_os::Trace(L"DboxMain::SaveGUIStatusEx: fixing pdi->tree_item!\n");
pdi->tree_item = ti;
}
m_TUUIDVisibleAtMinimize = pci->GetUUID();
} else {
// Group: save entry text
m_sxVisibleGroup = m_ctlItemTree.GetGroup(ti);
}
} // ti != NULL
}
}
void DboxMain::RestoreGUIStatusEx()
{
PWS_LOGIT;
if (m_core.GetNumEntries() == 0)
return;
if (m_ctlItemList.GetItemCount() == 0 || m_ctlItemTree.GetCount() == 0)
return;
m_bInRestoreWindows = true;
// Restore expand/collapse status of groups
m_bIsRestoring = true;
m_ctlItemTree.SetRestoreMode(true);
if (!m_vGroupDisplayState.empty()) {
SetGroupDisplayState(m_vGroupDisplayState);
m_vGroupDisplayState.clear();
}
m_ctlItemTree.SetRestoreMode(false);
m_bIsRestoring = false;
HTREEITEM htvis(NULL), htsel(NULL);
CItemData *pci(NULL);
// Process Tree - Selected
if (m_TUUIDSelectedAtMinimize != CUUID::NullUUID()) {
// Entry selected
ItemListIter iter = Find(m_TUUIDSelectedAtMinimize);
if (iter != End()) {
DisplayInfo *pdi = ((DisplayInfo *)(iter->second.GetDisplayInfo()));
ASSERT(pdi != NULL);
if (pdi != NULL) {
htsel = pdi->tree_item;
pci = &iter->second;
}
}
} else {
// Group selected
if (!m_sxSelectedGroup.empty()) {
// Find corresponding tree item
std::map<StringX, HTREEITEM>::iterator iter;
iter = m_mapGroupToTreeItem.find(m_sxSelectedGroup);
if (iter != m_mapGroupToTreeItem.end()) {
htsel = iter->second;
}
}
}
if (htsel != NULL) {
m_ctlItemTree.Select(htsel, TVGN_CARET);
RECT rect;
m_ctlItemTree.GetItemRect(htsel, &rect, FALSE);
m_ctlItemTree.InvalidateRect(&rect, TRUE);
if (m_ctlItemTree.IsWindowVisible())
UpdateToolBarForSelectedItem(pci);
}
// Process Tree - Visible
if (m_TUUIDVisibleAtMinimize != CUUID::NullUUID()) {
// Entry topmost visible
ItemListIter iter = Find(m_TUUIDVisibleAtMinimize);
if (iter != End()) {
DisplayInfo *pdi = ((DisplayInfo *)(iter->second.GetDisplayInfo()));
ASSERT(pdi != NULL);
if (pdi != NULL) {
htvis = pdi->tree_item;
}
}
} else {
// Group topmost visible
if (!m_sxVisibleGroup.empty()) {
// Find corresponding tree item
std::map<StringX, HTREEITEM>::iterator iter;
iter = m_mapGroupToTreeItem.find(m_sxVisibleGroup);
if (iter != m_mapGroupToTreeItem.end()) {
htvis = iter->second;
}
}
}
// Just in case MFC actually selected the first visible entry
if (htvis != NULL) {
m_ctlItemTree.Select(htvis, TVGN_FIRSTVISIBLE);
RECT rect;
m_ctlItemTree.GetItemRect(htvis, &rect, FALSE);
m_ctlItemTree.InvalidateRect(&rect, TRUE);
}
// Process List - selected
if (m_LUUIDSelectedAtMinimize != CUUID::NullUUID()) {
ItemListIter iter = Find(m_LUUIDSelectedAtMinimize);
if (iter != End()) {
DisplayInfo *pdi = ((DisplayInfo *)(iter->second.GetDisplayInfo()));
ASSERT(pdi != NULL);
if (pdi != NULL) {
// Select the Entry
m_ctlItemList.SetItemState(pdi->list_index,
LVIS_FOCUSED | LVIS_SELECTED,
LVIS_FOCUSED | LVIS_SELECTED);
m_ctlItemList.Update(pdi->list_index);
if (m_ctlItemList.IsWindowVisible())
UpdateToolBarForSelectedItem(&iter->second);
}
}
}
// Process List - visible
if (m_LUUIDVisibleAtMinimize != CUUID::NullUUID()) {
ItemListIter iter = Find(m_LUUIDVisibleAtMinimize);
if (iter != End()) {
DisplayInfo *pdi = ((DisplayInfo *)(iter->second.GetDisplayInfo()));
ASSERT(pdi != NULL);
if (pdi != NULL) {
// There is CListCtrl::GetTopIndex but No CListCtrl::SetTopIndex - Grrrrr!
CRect indexRect, topRect;
m_ctlItemList.EnsureVisible(pdi->list_index, FALSE);
int icurtop = m_ctlItemList.GetTopIndex();
m_ctlItemList.GetItemRect(pdi->list_index, indexRect, LVIR_BOUNDS);
m_ctlItemList.GetItemRect(icurtop, topRect, LVIR_BOUNDS);
m_ctlItemList.Scroll(CSize(0, (topRect.top - indexRect.top) * indexRect.Height()));
// Just in case MFC actually selected the first visible entry
m_ctlItemList.SetItemState(pdi->list_index, 0, LVIS_FOCUSED | LVIS_SELECTED);
m_ctlItemList.Update(pdi->list_index);
}
}
}
m_bInRestoreWindows = false;
}
void DboxMain::SaveGroupDisplayState()
{
PWS_LOGIT;
vector <bool> v = GetGroupDisplayState(); // update it
m_core.SetDisplayStatus(v); // store it
}
void DboxMain::RestoreGroupDisplayState()
{
PWS_LOGIT;
const vector<bool> &displaystatus = m_core.GetDisplayStatus();
if (!displaystatus.empty())
SetGroupDisplayState(displaystatus);
}
vector<bool> DboxMain::GetGroupDisplayState()
{
PWS_LOGIT;
HTREEITEM hItem = NULL;
vector<bool> v;
if (m_ctlItemTree.GetSafeHwnd() == NULL)
return v;
while (NULL != (hItem = m_ctlItemTree.GetNextTreeItem(hItem))) {
if (m_ctlItemTree.ItemHasChildren(hItem)) {
bool bState = (m_ctlItemTree.GetItemState(hItem, TVIS_EXPANDED) &
TVIS_EXPANDED) != 0;
v.push_back(bState);
}
}
return v;
}
void DboxMain::SetGroupDisplayState(const vector<bool> &displaystatus)
{
PWS_LOGIT;
// We need to copy displaystatus since Expand may cause
// SaveGroupDisplayState to be called, updating it
// Could be called from OnSize before anything set up!
// Check Tree is valid first
if (m_ctlItemTree.GetSafeHwnd() == NULL || displaystatus.empty())
return;
const vector<bool> dstatus(displaystatus);
const size_t num = dstatus.size();
if (num == 0)
return;
HTREEITEM hItem = NULL;
size_t i(0);
while (NULL != (hItem = m_ctlItemTree.GetNextTreeItem(hItem))) {
if (m_ctlItemTree.ItemHasChildren(hItem)) {
m_ctlItemTree.Expand(hItem, dstatus[i] ? TVE_EXPAND : TVE_COLLAPSE);
i++;
if (i == num)
break;
}
}
}
void DboxMain::SaveGUIStatus()
{
PWS_LOGIT;
st_SaveGUIInfo SaveGUIInfo;
CItemData *pci_list(NULL), *pci_tree(NULL);
// Note: we try and keep the same entry selected when the users
// switches between List & Tree views.
// But we can't if the user has selected a Group in the Tree view
// Note: Must do this using the entry's UUID as the POSITION &
// HTREEITEM values may be different when we come to use it.
POSITION pos = m_ctlItemList.GetFirstSelectedItemPosition();
if (pos != NULL) {
pci_list = (CItemData *)m_ctlItemList.GetItemData((int)pos - 1);
if (pci_list != NULL) {
SaveGUIInfo.lSelected = pci_list->GetUUID();
SaveGUIInfo.blSelectedValid = true;
}
}
HTREEITEM hi = m_ctlItemTree.GetSelectedItem();
if (hi != NULL) {
pci_tree = (CItemData *)m_ctlItemTree.GetItemData(hi);
if (pci_tree != pci_list) {
if (pci_tree != NULL) {
SaveGUIInfo.tSelected = pci_tree->GetUUID();
SaveGUIInfo.btSelectedValid = true;
} else {
StringX s(L"");
if (hi != NULL)
s = m_ctlItemTree.GetItemText(hi);
while ((hi = m_ctlItemTree.GetParentItem(hi)) != NULL) {
s = StringX(m_ctlItemTree.GetItemText(hi)) + StringX(L".") + s;
}
SaveGUIInfo.sxGroupName = s;
}
}
}
SaveGUIInfo.vGroupDisplayState = GetGroupDisplayState();
m_stkSaveGUIInfo.push(SaveGUIInfo);
}
void DboxMain::RestoreGUIStatus()
{
PWS_LOGIT;
if (m_stkSaveGUIInfo.empty())
return; // better safe than sorry...
st_SaveGUIInfo &SaveGUIInfo = m_stkSaveGUIInfo.top();
ItemListIter iter;
DisplayInfo *pdi;
if (SaveGUIInfo.blSelectedValid) {
iter = Find(SaveGUIInfo.lSelected);
pdi = (DisplayInfo *)iter->second.GetDisplayInfo();
m_ctlItemList.SetItemState(pdi->list_index, LVIS_SELECTED, LVIS_SELECTED);
m_ctlItemTree.SelectItem(pdi->tree_item);
}
if (SaveGUIInfo.btSelectedValid) {
iter = Find(SaveGUIInfo.tSelected);
pdi = (DisplayInfo *)iter->second.GetDisplayInfo();
m_ctlItemTree.SelectItem(pdi->tree_item);
}
if (SaveGUIInfo.btGroupValid) {
std::map<StringX, HTREEITEM>::iterator iter;
iter = m_mapGroupToTreeItem.find(SaveGUIInfo.sxGroupName);
if (iter != m_mapGroupToTreeItem.end()) {
m_ctlItemTree.SelectItem(iter->second);
}
}
SetGroupDisplayState(SaveGUIInfo.vGroupDisplayState);
m_stkSaveGUIInfo.pop();
}
void DboxMain::GetAllGroups(std::vector<std::wstring> &vGroups) const
{
std::map<StringX, HTREEITEM>::const_iterator iter;
for (iter = m_mapGroupToTreeItem.begin();
iter != m_mapGroupToTreeItem.end(); iter++) {
vGroups.push_back(iter->first.c_str());
}
}
bool DboxMain::LongPPs(CWnd *pWnd)
{
// Based on current screen height, decide if we want to display.
// The normal "tall/long" page, or the "wide/short" version (for netbooks)
MONITORINFO mi;
mi.cbSize = sizeof(mi);
GetMonitorInfo(MonitorFromWindow(GetSafeHwnd(), MONITOR_DEFAULTTONEAREST), &mi);
const int YM = abs(mi.rcWork.bottom - mi.rcWork.top);
// This is the main dialog - not the one we need to ask about!
CRect rect;
pWnd->GetWindowRect(&rect);
const int YD = abs(rect.bottom - rect.top);
return (YM > YD);
}
bool DboxMain::GetShortCut(const unsigned int &uiMenuItem,
unsigned short int &siVirtKey, unsigned char &cModifier)
{
siVirtKey = 0;
cModifier = '0';
MapMenuShortcutsIter iter;
iter = m_MapMenuShortcuts.find(uiMenuItem);
if (iter == m_MapMenuShortcuts.end())
return false;
if (iter->second.siVirtKey != iter->second.siDefVirtKey ||
iter->second.cModifier != iter->second.cDefModifier) {
siVirtKey = iter->second.siVirtKey;
cModifier = iter->second.cModifier;
} else {
siVirtKey = iter->second.siDefVirtKey;
cModifier = iter->second.cDefModifier;
}
return true;
}