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
|
/*******************************************************************************
* Copyright (c) 2000, 2003 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.swt.widgets;
import org.eclipse.swt.internal.win32.*;
import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.events.*;
/**
* Instances of this class implement a selectable user interface
* object that displays a list of images and strings and issue
* notificiation when selected.
* <p>
* The item children that may be added to instances of this class
* must be of type <code>TableItem</code>.
* </p><p>
* Note that although this class is a subclass of <code>Composite</code>,
* it does not make sense to add <code>Control</code> children to it,
* or set a layout on it.
* </p><p>
* <dl>
* <dt><b>Styles:</b></dt>
* <dd>SINGLE, MULTI, CHECK, FULL_SELECTION, HIDE_SELECTION</dd>
* <dt><b>Events:</b></dt>
* <dd>Selection, DefaultSelection</dd>
* </dl>
* <p>
* Note: Only one of the styles SINGLE, and MULTI may be specified.
* </p><p>
* IMPORTANT: This class is <em>not</em> intended to be subclassed.
* </p>
*/
public class Table extends Composite {
TableItem [] items;
TableColumn [] columns;
ImageList imageList;
int lastIndexOf, lastWidth;
boolean fixScrollWidth;
boolean ignoreSelect, dragStarted, ignoreResize, ignoreRedraw, mouseDown, customDraw;
static final int TableProc;
static final TCHAR TableClass = new TCHAR (0, OS.WC_LISTVIEW, true);
static {
WNDCLASS lpWndClass = new WNDCLASS ();
OS.GetClassInfo (0, TableClass, lpWndClass);
TableProc = lpWndClass.lpfnWndProc;
}
/**
* Constructs a new instance of this class given its parent
* and a style value describing its behavior and appearance.
* <p>
* The style value is either one of the style constants defined in
* class <code>SWT</code> which is applicable to instances of this
* class, or must be built by <em>bitwise OR</em>'ing together
* (that is, using the <code>int</code> "|" operator) two or more
* of those <code>SWT</code> style constants. The class description
* lists the style constants that are applicable to the class.
* Style bits are also inherited from superclasses.
* </p>
*
* @param parent a composite control which will be the parent of the new instance (cannot be null)
* @param style the style of control to construct
*
* @exception IllegalArgumentException <ul>
* <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
* </ul>
* @exception SWTException <ul>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
* <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
* </ul>
*
* @see SWT#SINGLE
* @see SWT#MULTI
* @see SWT#CHECK
* @see SWT#FULL_SELECTION
* @see SWT#HIDE_SELECTION
* @see Widget#checkSubclass
* @see Widget#getStyle
*/
public Table (Composite parent, int style) {
super (parent, checkStyle (style));
}
TableItem _getItem (int index) {
if (items [index] != null) return items [index];
return items [index] = new TableItem (this, SWT.NONE, -1, false);
}
/**
* Adds the listener to the collection of listeners who will
* be notified when the receiver's selection changes, by sending
* it one of the messages defined in the <code>SelectionListener</code>
* interface.
* <p>
* When <code>widgetSelected</code> is called, the item field of the event object is valid.
* If the reciever has <code>SWT.CHECK</code> style set and the check selection changes,
* the event object detail field contains the value <code>SWT.CHECK</code>.
* <code>widgetDefaultSelected</code> is typically called when an item is double-clicked.
* The item field of the event object is valid for default selection, but the detail field is not used.
* </p>
*
* @param listener the listener which should be notified
*
* @exception IllegalArgumentException <ul>
* <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
* </ul>
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*
* @see SelectionListener
* @see #removeSelectionListener
* @see SelectionEvent
*/
public void addSelectionListener (SelectionListener listener) {
checkWidget ();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
TypedListener typedListener = new TypedListener (listener);
addListener (SWT.Selection,typedListener);
addListener (SWT.DefaultSelection,typedListener);
}
int callWindowProc (int msg, int wParam, int lParam) {
if (handle == 0) return 0;
return OS.CallWindowProc (TableProc, handle, msg, wParam, lParam);
}
static int checkStyle (int style) {
/*
* Feature in Windows. It is not possible to create
* a table that does not have scroll bars. Therefore,
* no matter what style bits are specified, set the
* H_SCROLL and V_SCROLL bits so that the SWT style
* will match the widget that Windows creates.
*/
style |= SWT.H_SCROLL | SWT.V_SCROLL;
return checkBits (style, SWT.SINGLE, SWT.MULTI, 0, 0, 0, 0);
}
protected void checkSubclass () {
if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
}
/**
* Clears the item at the given zero-relative index in the receiver.
* The text, icon and other attribues of the item are set to the default
* value. If the table was created with the SWT.VIRTUAL style, these
* attributes are requested again as needed.
*
* @param index the index of the item to clear
*
* @exception IllegalArgumentException <ul>
* <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
* </ul>
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*
* @see SWT#VIRTUAL
* @see SWT#SetData
*
* @since 3.0
*/
public void clear (int index) {
checkWidget ();
int count = OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
if (!(0 <= index && index < count)) error (SWT.ERROR_INVALID_RANGE);
TableItem item = items [index];
if (item != null) {
item.clear ();
/*
* Bug in Windows. Despite the fact that every item in the
* table always has LPSTR_TEXTCALLBACK, Windows caches the
* bounds for the selected items. This means that
* when you change the string to be something else, Windows
* correctly asks you for the new string but when the item
* is selected, the selection draws using the bounds of the
* previous item. The fix is to reset LPSTR_TEXTCALLBACK
* even though it has not changed, causing Windows to flush
* cached bounds.
*/
if ((style & SWT.VIRTUAL) == 0 && item.cached) {
int hwnd = parent.handle;
LVITEM lvItem = new LVITEM ();
lvItem.mask = OS.LVIF_TEXT | OS.LVIF_INDENT;
lvItem.pszText = OS.LPSTR_TEXTCALLBACK;
lvItem.iItem = index;
OS.SendMessage (handle, OS.LVM_SETITEM, 0, lvItem);
item.cached = false;
}
if (!ignoreRedraw && drawCount == 0 && OS.IsWindowVisible (handle)) {
OS.SendMessage (handle, OS.LVM_REDRAWITEMS, index, index);
}
setScrollWidth (item, false);
}
}
/**
* Removes the items from the receiver which are between the given
* zero-relative start and end indices (inclusive). The text, icon
* and other attribues of the items are set to their default values.
* If the table was created with the SWT.VIRTUAL style, these attributes
* are requested again as needed.
*
* @param start the start index of the item to clear
* @param end the end index of the item to clear
*
* @exception IllegalArgumentException <ul>
* <li>ERROR_INVALID_RANGE - if either the start or end are not between 0 and the number of elements in the list minus 1 (inclusive)</li>
* </ul>
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*
* @see SWT#VIRTUAL
* @see SWT.SetData
*
* @since 3.0
*/
public void clear (int start, int end) {
checkWidget ();
if (start > end) return;
int count = OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
if (!(0 <= start && start <= end && end < count)) {
error (SWT.ERROR_INVALID_RANGE);
}
if (start == 0 && end == count - 1) {
clearAll ();
} else {
LVITEM lvItem = null;
boolean cleared = false;
for (int i=start; i<=end; i++) {
TableItem item = items [i];
if (item != null) {
cleared = true;
item.clear ();
/*
* Bug in Windows. Despite the fact that every item in the
* table always has LPSTR_TEXTCALLBACK, Windows caches the
* bounds for the selected items. This means that
* when you change the string to be something else, Windows
* correctly asks you for the new string but when the item
* is selected, the selection draws using the bounds of the
* previous item. The fix is to reset LPSTR_TEXTCALLBACK
* even though it has not changed, causing Windows to flush
* cached bounds.
*/
if ((style & SWT.VIRTUAL) == 0 && item.cached) {
if (lvItem == null) {
lvItem = new LVITEM ();
lvItem.mask = OS.LVIF_TEXT | OS.LVIF_INDENT;
lvItem.pszText = OS.LPSTR_TEXTCALLBACK;
}
lvItem.iItem = i;
OS.SendMessage (handle, OS.LVM_SETITEM, 0, lvItem);
item.cached = false;
}
}
}
if (cleared) {
if (!ignoreRedraw && drawCount == 0 && OS.IsWindowVisible (handle)) {
OS.SendMessage (handle, OS.LVM_REDRAWITEMS, start, end);
}
TableItem item = start == end ? items [start] : null;
setScrollWidth (item, false);
}
}
}
/**
* Clears the items at the given zero-relative indices in the receiver.
* The text, icon and other attribues of the items are set to their default
* values. If the table was created with the SWT.VIRTUAL style, these
* attributes are requested again as needed.
*
* @param indices the array of indices of the items
*
* @exception IllegalArgumentException <ul>
* <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
* <li>ERROR_NULL_ARGUMENT - if the indices array is null</li>
* </ul>
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*
* @see SWT#VIRTUAL
* @see SWT.SetData
*
* @since 3.0
*/
public void clear (int [] indices) {
checkWidget ();
if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
if (indices.length == 0) return;
int count = OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
for (int i=0; i<indices.length; i++) {
if (!(0 <= indices [i] && indices [i] < count)) {
error (SWT.ERROR_INVALID_RANGE);
}
}
LVITEM lvItem = null;
boolean cleared = false;
for (int i=0; i<indices.length; i++) {
int index = indices [i];
TableItem item = items [index];
if (item != null) {
cleared = true;
item.clear ();
/*
* Bug in Windows. Despite the fact that every item in the
* table always has LPSTR_TEXTCALLBACK, Windows caches the
* bounds for the selected items. This means that
* when you change the string to be something else, Windows
* correctly asks you for the new string but when the item
* is selected, the selection draws using the bounds of the
* previous item. The fix is to reset LPSTR_TEXTCALLBACK
* even though it has not changed, causing Windows to flush
* cached bounds.
*/
if ((style & SWT.VIRTUAL) == 0 && item.cached) {
if (lvItem == null) {
lvItem = new LVITEM ();
lvItem.mask = OS.LVIF_TEXT | OS.LVIF_INDENT;
lvItem.pszText = OS.LPSTR_TEXTCALLBACK;
}
lvItem.iItem = i;
OS.SendMessage (handle, OS.LVM_SETITEM, 0, lvItem);
item.cached = false;
}
if (!ignoreRedraw && drawCount == 0 && OS.IsWindowVisible (handle)) {
OS.SendMessage (handle, OS.LVM_REDRAWITEMS, index, index);
}
}
}
if (cleared) setScrollWidth (null, false);
}
/**
* Clears all the items in the receiver. The text, icon and other
* attribues of the items are set to their default values. If the
* table was created with the SWT.VIRTUAL style, these attributes
* are requested again as needed.
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*
* @see SWT#VIRTUAL
* @see SWT.SetData
*
* @since 3.0
*/
public void clearAll () {
checkWidget ();
int count = OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
LVITEM lvItem = null;
boolean cleared = false;
for (int i=0; i<count; i++) {
TableItem item = items [i];
if (item != null) {
item.clear ();
/*
* Bug in Windows. Despite the fact that every item in the
* table always has LPSTR_TEXTCALLBACK, Windows caches the
* bounds for the selected items. This means that
* when you change the string to be something else, Windows
* correctly asks you for the new string but when the item
* is selected, the selection draws using the bounds of the
* previous item. The fix is to reset LPSTR_TEXTCALLBACK
* even though it has not changed, causing Windows to flush
* cached bounds.
*/
if ((style & SWT.VIRTUAL) == 0 && item.cached) {
if (lvItem == null) {
lvItem = new LVITEM ();
lvItem.mask = OS.LVIF_TEXT | OS.LVIF_INDENT;
lvItem.pszText = OS.LPSTR_TEXTCALLBACK;
}
lvItem.iItem = i;
OS.SendMessage (handle, OS.LVM_SETITEM, 0, lvItem);
item.cached = false;
}
}
}
if (cleared) {
if (!ignoreRedraw && drawCount == 0 && OS.IsWindowVisible (handle)) {
OS.SendMessage (handle, OS.LVM_REDRAWITEMS, 0, count - 1);
}
setScrollWidth (null, false);
}
}
public Point computeSize (int wHint, int hHint, boolean changed) {
checkWidget ();
if (fixScrollWidth) setScrollWidth (null, true);
int bits = 0;
if (wHint != SWT.DEFAULT) {
bits |= wHint & 0xFFFF;
} else {
int width = 0;
int hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
int count = OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0);
for (int i=0; i<count; i++) {
width += OS.SendMessage (handle, OS.LVM_GETCOLUMNWIDTH, i, 0);
}
bits |= width & 0xFFFF;
}
if (hHint != SWT.DEFAULT) bits |= hHint << 16;
int result = OS.SendMessage (handle, OS.LVM_APPROXIMATEVIEWRECT, -1, bits);
int width = result & 0xFFFF, height = result >> 16;
/*
* Feature in Windows. The height returned by LVM_APPROXIMATEVIEWRECT
* includes the trim plus the height of the items plus one extra row.
* The fix is to subtract the height of one row from the result height.
*/
int empty = OS.SendMessage (handle, OS.LVM_APPROXIMATEVIEWRECT, 0, 0);
int oneItem = OS.SendMessage (handle, OS.LVM_APPROXIMATEVIEWRECT, 1, 0);
height -= (oneItem >> 16) - (empty >> 16);
if (width == 0) width = DEFAULT_WIDTH;
if (height == 0) height = DEFAULT_HEIGHT;
if (wHint != SWT.DEFAULT) width = wHint;
if (hHint != SWT.DEFAULT) height = hHint;
int border = getBorderWidth ();
width += border * 2; height += border * 2;
if ((style & SWT.V_SCROLL) != 0) {
width += OS.GetSystemMetrics (OS.SM_CXVSCROLL);
}
if ((style & SWT.H_SCROLL) != 0) {
height += OS.GetSystemMetrics (OS.SM_CYHSCROLL);
}
return new Point (width, height);
}
void createHandle () {
super.createHandle ();
state &= ~CANVAS;
/*
* This code is intentionally commented. According to
* the documentation, setting the default item size is
* supposed to improve performance. By experimentation,
* this does not seem to have much of an effect.
*/
// OS.SendMessage (handle, OS.LVM_SETITEMCOUNT, 1024 * 2, 0);
/* Set the checkbox image list */
if ((style & SWT.CHECK) != 0) {
int empty = OS.SendMessage (handle, OS.LVM_APPROXIMATEVIEWRECT, 0, 0);
int oneItem = OS.SendMessage (handle, OS.LVM_APPROXIMATEVIEWRECT, 1, 0);
int width = (oneItem >> 16) - (empty >> 16), height = width;
setCheckboxImageList (width, height);
OS.SendMessage (handle, OS. LVM_SETCALLBACKMASK, OS.LVIS_STATEIMAGEMASK, 0);
}
/*
* Feature in Windows. When the control is created,
* it does not use the default system font. A new HFONT
* is created and destroyed when the control is destroyed.
* This means that a program that queries the font from
* this control, uses the font in another control and then
* destroys this control will have the font unexpectedly
* destroyed in the other control. The fix is to assign
* the font ourselves each time the control is created.
* The control will not destroy a font that it did not
* create.
*/
int hFont = OS.GetStockObject (OS.SYSTEM_FONT);
OS.SendMessage (handle, OS.WM_SETFONT, hFont, 0);
/*
* Bug in Windows. When the first column is inserted
* without setting the header text, Windows will never
* allow the header text for the first column to be set.
* The fix is to set the text to an empty string when
* the column is inserted.
*/
LVCOLUMN lvColumn = new LVCOLUMN ();
lvColumn.mask = OS.LVCF_TEXT;
int hHeap = OS.GetProcessHeap ();
int pszText = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, TCHAR.sizeof);
lvColumn.pszText = pszText;
OS.SendMessage (handle, OS.LVM_INSERTCOLUMN, 0, lvColumn);
OS.HeapFree (hHeap, 0, pszText);
/* Set the extended style bits */
int bits = OS.LVS_EX_SUBITEMIMAGES | OS.LVS_EX_LABELTIP;
if ((style & SWT.FULL_SELECTION) != 0) bits |= OS.LVS_EX_FULLROWSELECT;
OS.SendMessage (handle, OS.LVM_SETEXTENDEDLISTVIEWSTYLE, bits, bits);
/*
* Feature in Windows. Windows does not explicitly set the orientation of
* the header. Instead, the orientation is inherited when WS_EX_LAYOUTRTL
* is specified for the table. This means that when both WS_EX_LAYOUTRTL
* and WS_EX_NOINHERITLAYOUT are specified for the table, the header will
* not be oriented correctly. The fix is to explicitly set the orientation
* for the header.
*
* NOTE: WS_EX_LAYOUTRTL is not supported on Windows NT.
*/
if ((OS.WIN32_MAJOR << 16 | OS.WIN32_MINOR) < (4 << 16 | 10)) return;
if ((style & SWT.RIGHT_TO_LEFT) != 0) {
int hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
int exStyle = OS.GetWindowLong (hwndHeader, OS.GWL_EXSTYLE);
OS.SetWindowLong (hwndHeader, OS.GWL_EXSTYLE, exStyle | OS.WS_EX_LAYOUTRTL);
}
}
void createItem (TableColumn column, int index) {
int hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
int count = OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0);
int columnCount = count + 1;
if (count == 1 && columns [0] == null) count = 0;
if (!(0 <= index && index <= count)) error (SWT.ERROR_INVALID_RANGE);
if (count == columns.length) {
TableColumn [] newColumns = new TableColumn [columns.length + 4];
System.arraycopy (columns, 0, newColumns, 0, columns.length);
columns = newColumns;
}
if (count != 0) {
int itemCount = OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
for (int i=0; i<itemCount; i++) {
TableItem item = items [i];
if (item != null) {
String [] strings = item.strings;
if (strings != null) {
String [] temp = new String [columnCount];
System.arraycopy (strings, 0, temp, 0, index);
System.arraycopy (strings, index, temp, index+1, columnCount-index-1);
temp [index] = "";
item.strings = temp;
}
if (index == 0) item.text = "";
Image [] images = item.images;
if (images != null) {
Image [] temp = new Image [columnCount];
System.arraycopy (images, 0, temp, 0, index);
System.arraycopy (images, index, temp, index+1, columnCount-index-1);
item.images = temp;
}
if (index == 0) item.image = null;
if (item.cellBackground != null) {
int [] cellBackground = item.cellBackground;
int [] temp = new int [columnCount];
System.arraycopy (cellBackground, 0, temp, 0, index);
System.arraycopy (cellBackground, index, temp, index+1, columnCount-index-1);
temp [index] = -1;
item.cellBackground = temp;
}
if (item.cellForeground != null) {
int [] cellForeground = item.cellForeground;
int [] temp = new int [columnCount];
System.arraycopy (cellForeground, 0, temp, 0, index);
System.arraycopy (cellForeground, index, temp, index+1, columnCount-index-1);
temp [index] = -1;
item.cellForeground = temp;
}
if (item.cellFont != null) {
int [] cellFont = item.cellFont;
int [] temp = new int [columnCount];
System.arraycopy (cellFont, 0, temp, 0, index);
System.arraycopy (cellFont, index, temp, index+1, columnCount-index-1);
temp [index] = -1;
item.cellFont = temp;
}
}
}
}
/*
* Insert the column into the columns array before inserting
* it into the widget so that the column will be present when
* any callbacks are issued as a result of LVM_INSERTCOLUMN
* or LVM_SETCOLUMN.
*/
System.arraycopy (columns, index, columns, index + 1, count - index);
columns [index] = column;
if (index == 0) {
if (count > 0) {
LVCOLUMN lvColumn = new LVCOLUMN ();
lvColumn.mask = OS.LVCF_WIDTH;
OS.SendMessage (handle, OS.LVM_INSERTCOLUMN, 1, lvColumn);
OS.SendMessage (handle, OS.LVM_GETCOLUMN, 1, lvColumn);
int width = lvColumn.cx;
int cchTextMax = 1024;
int hHeap = OS.GetProcessHeap ();
int byteCount = cchTextMax * TCHAR.sizeof;
int pszText = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount);
lvColumn.mask = OS.LVCF_TEXT | OS.LVCF_IMAGE | OS.LVCF_WIDTH | OS.LVCF_FMT;
lvColumn.pszText = pszText;
lvColumn.cchTextMax = cchTextMax;
OS.SendMessage (handle, OS.LVM_GETCOLUMN, 0, lvColumn);
OS.SendMessage (handle, OS.LVM_SETCOLUMN, 1, lvColumn);
lvColumn.fmt = OS.LVCFMT_IMAGE;
lvColumn.cx = width;
lvColumn.iImage = OS.I_IMAGENONE;
lvColumn.pszText = lvColumn.cchTextMax = 0;
OS.SendMessage (handle, OS.LVM_SETCOLUMN, 0, lvColumn);
lvColumn.mask = OS.LVCF_FMT;
lvColumn.fmt = OS.LVCFMT_LEFT;
OS.SendMessage (handle, OS.LVM_SETCOLUMN, 0, lvColumn);
if (pszText != 0) OS.HeapFree (hHeap, 0, pszText);
} else {
OS.SendMessage (handle, OS.LVM_SETCOLUMNWIDTH, 0, 0);
}
if ((parent.style & SWT.VIRTUAL) == 0) {
LVITEM lvItem = new LVITEM ();
lvItem.mask = OS.LVIF_TEXT | OS.LVIF_IMAGE;
lvItem.pszText = OS.LPSTR_TEXTCALLBACK;
lvItem.iImage = OS.I_IMAGECALLBACK;
int itemCount = OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
for (int i=0; i<itemCount; i++) {
lvItem.iItem = i;
OS.SendMessage (handle, OS.LVM_SETITEM, 0, lvItem);
}
}
} else {
int fmt = OS.LVCFMT_LEFT;
if ((column.style & SWT.CENTER) == SWT.CENTER) fmt = OS.LVCFMT_CENTER;
if ((column.style & SWT.RIGHT) == SWT.RIGHT) fmt = OS.LVCFMT_RIGHT;
LVCOLUMN lvColumn = new LVCOLUMN ();
lvColumn.mask = OS.LVCF_WIDTH | OS.LVCF_FMT;
lvColumn.fmt = fmt;
OS.SendMessage (handle, OS.LVM_INSERTCOLUMN, index, lvColumn);
}
}
void createItem (TableItem item, int index) {
int count = OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
if (!(0 <= index && index <= count)) error (SWT.ERROR_INVALID_RANGE);
if (count == items.length) {
/*
* Grow the array faster when redraw is off or the
* table is not visible. When the table is painted,
* the items array is resized to be smaller to reduce
* memory usage.
*/
boolean small = drawCount == 0 && OS.IsWindowVisible (handle);
int length = small ? items.length + 4 : items.length * 3 / 2;
TableItem [] newItems = new TableItem [length];
System.arraycopy (items, 0, newItems, 0, items.length);
items = newItems;
}
LVITEM lvItem = new LVITEM ();
lvItem.iItem = index;
lvItem.pszText = OS.LPSTR_TEXTCALLBACK;
lvItem.mask |= OS.LVIF_TEXT;
/*
* Bug in Windows. Despite the fact that the image list
* index has never been set for the item, Windows always
* assumes that the image index for the item is valid.
* When an item is inserted, the image index is zero.
* Therefore, when the first image is inserted and is
* assigned image index zero, every item draws with this
* image. The fix is to set the image index when the
* the item is created.
*/
lvItem.iImage = OS.I_IMAGECALLBACK;
lvItem.mask |= OS.LVIF_IMAGE;
/* Insert the item */
ignoreSelect = true;
int result = OS.SendMessage (handle, OS.LVM_INSERTITEM, 0, lvItem);
ignoreSelect = false;
if (result == -1) error (SWT.ERROR_ITEM_NOT_ADDED);
System.arraycopy (items, index, items, index + 1, count - index);
items [index] = item;
}
void createWidget () {
super.createWidget ();
items = new TableItem [4];
columns = new TableColumn [4];
}
int defaultBackground () {
return OS.GetSysColor (OS.COLOR_WINDOW);
}
/**
* Deselects the items at the given zero-relative indices in the receiver.
* If the item at the given zero-relative index in the receiver
* is selected, it is deselected. If the item at the index
* was not selected, it remains deselected. Indices that are out
* of range and duplicate indices are ignored.
*
* @param indices the array of indices for the items to deselect
*
* @exception IllegalArgumentException <ul>
* <li>ERROR_NULL_ARGUMENT - if the set of indices is null</li>
* </ul>
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public void deselect (int [] indices) {
checkWidget ();
if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
if (indices.length == 0) return;
LVITEM lvItem = new LVITEM ();
lvItem.stateMask = OS.LVIS_SELECTED;
for (int i=0; i<indices.length; i++) {
/*
* An index of -1 will apply the change to all
* items. Ensure that indices are greater than -1.
*/
if (indices [i] >= 0) {
ignoreSelect = true;
OS.SendMessage (handle, OS.LVM_SETITEMSTATE, indices [i], lvItem);
ignoreSelect = false;
}
}
}
/**
* Deselects the item at the given zero-relative index in the receiver.
* If the item at the index was already deselected, it remains
* deselected. Indices that are out of range are ignored.
*
* @param index the index of the item to deselect
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public void deselect (int index) {
checkWidget ();
/*
* An index of -1 will apply the change to all
* items. Ensure that index is greater than -1.
*/
if (index < 0) return;
LVITEM lvItem = new LVITEM ();
lvItem.stateMask = OS.LVIS_SELECTED;
ignoreSelect = true;
OS.SendMessage (handle, OS.LVM_SETITEMSTATE, index, lvItem);
ignoreSelect = false;
}
/**
* Deselects the items at the given zero-relative indices in the receiver.
* If the item at the given zero-relative index in the receiver
* is selected, it is deselected. If the item at the index
* was not selected, it remains deselected. The range of the
* indices is inclusive. Indices that are out of range are ignored.
*
* @param start the start index of the items to deselect
* @param end the end index of the items to deselect
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public void deselect (int start, int end) {
checkWidget ();
int count = OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
if (start == 0 && end == count - 1) {
deselectAll ();
} else {
LVITEM lvItem = new LVITEM ();
lvItem.stateMask = OS.LVIS_SELECTED;
/*
* An index of -1 will apply the change to all
* items. Ensure that indices are greater than -1.
*/
start = Math.max (0, start);
for (int i=start; i<=end; i++) {
ignoreSelect = true;
OS.SendMessage (handle, OS.LVM_SETITEMSTATE, i, lvItem);
ignoreSelect = false;
}
}
}
/**
* Deselects all selected items in the receiver.
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public void deselectAll () {
checkWidget ();
LVITEM lvItem = new LVITEM ();
lvItem.mask = OS.LVIF_STATE;
lvItem.stateMask = OS.LVIS_SELECTED;
OS.SendMessage (handle, OS.LVM_SETITEMSTATE, -1, lvItem);
}
void destroyItem (TableColumn column) {
int hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
int columnCount = OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0);
int index = 0;
while (index < columnCount) {
if (columns [index] == column) break;
index++;
}
boolean first = false;
if (index == 0) {
first = true;
if (columnCount > 1) {
index = 1;
int cchTextMax = 1024;
int hHeap = OS.GetProcessHeap ();
int byteCount = cchTextMax * TCHAR.sizeof;
int pszText = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount);
LVCOLUMN lvColumn = new LVCOLUMN ();
lvColumn.mask = OS.LVCF_TEXT | OS.LVCF_WIDTH;
lvColumn.pszText = pszText;
lvColumn.cchTextMax = cchTextMax;
OS.SendMessage (handle, OS.LVM_GETCOLUMN, 1, lvColumn);
lvColumn.mask |= OS.LVCF_FMT;
lvColumn.fmt = OS.LVCFMT_LEFT;
OS.SendMessage (handle, OS.LVM_SETCOLUMN, 0, lvColumn);
if (pszText != 0) OS.HeapFree (hHeap, 0, pszText);
} else {
int hHeap = OS.GetProcessHeap ();
int pszText = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, TCHAR.sizeof);
LVCOLUMN lvColumn = new LVCOLUMN ();
lvColumn.mask = OS.LVCF_TEXT;
lvColumn.pszText = pszText;
OS.SendMessage (handle, OS.LVM_SETCOLUMN, 0, lvColumn);
if (pszText != 0) OS.HeapFree (hHeap, 0, pszText);
}
if ((parent.style & SWT.VIRTUAL) == 0) {
LVITEM lvItem = new LVITEM ();
lvItem.mask = OS.LVIF_TEXT | OS.LVIF_IMAGE;
lvItem.pszText = OS.LPSTR_TEXTCALLBACK;
lvItem.iImage = OS.I_IMAGECALLBACK;
int itemCount = OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
for (int i=0; i<itemCount; i++) {
lvItem.iItem = i;
OS.SendMessage (handle, OS.LVM_SETITEM, 0, lvItem);
}
}
}
if (columnCount > 1) {
if (OS.SendMessage (handle, OS.LVM_DELETECOLUMN, index, 0) == 0) {
error (SWT.ERROR_ITEM_NOT_REMOVED);
}
}
if (first) index = 0;
System.arraycopy (columns, index + 1, columns, index, --columnCount - index);
columns [columnCount] = null;
int itemCount = OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
for (int i=0; i<itemCount; i++) {
TableItem item = items [i];
if (item != null) {
String [] strings = item.strings;
if (strings != null) {
if (columnCount == 0) {
item.strings = null;
} else {
if (index == 0) item.text = strings [1];
String [] temp = new String [columnCount];
System.arraycopy (strings, 0, temp, 0, index);
System.arraycopy (strings, index + 1, temp, index, columnCount - index);
item.strings = temp;
}
}
Image [] images = item.images;
if (images != null) {
if (columnCount == 0) {
item.images = null;
} else {
if (index == 0) item.image = images [1];
Image [] temp = new Image [columnCount];
System.arraycopy (images, 0, temp, 0, index);
System.arraycopy (images, index + 1, temp, index, columnCount - index);
item.images = temp;
}
}
if (item.cellBackground != null) {
if (columnCount == 0) {
item.cellBackground = null;
} else {
int [] cellBackground = item.cellBackground;
int [] temp = new int [columnCount];
System.arraycopy (cellBackground, 0, temp, 0, index);
System.arraycopy (cellBackground, index + 1, temp, index, columnCount - index);
item.cellBackground = temp;
}
}
if (item.cellForeground != null) {
if (columnCount == 0) {
item.cellForeground = null;
} else {
int [] cellForeground = item.cellForeground;
int [] temp = new int [columnCount];
System.arraycopy (cellForeground, 0, temp, 0, index);
System.arraycopy (cellForeground, index + 1, temp, index, columnCount - index);
item.cellForeground = temp;
}
}
if (item.cellFont != null) {
if (columnCount == 0) {
item.cellFont = null;
} else {
int [] cellFont = item.cellFont;
int [] temp = new int [columnCount];
System.arraycopy (cellFont, 0, temp, 0, index);
System.arraycopy (cellFont, index + 1, temp, index, columnCount - index);
item.cellFont = temp;
}
}
}
}
if (columnCount == 0) setScrollWidth (null, true);
}
void destroyItem (TableItem item) {
int count = OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
int index = 0;
while (index < count) {
if (items [index] == item) break;
index++;
}
if (index == count) return;
ignoreSelect = true;
int code = OS.SendMessage (handle, OS.LVM_DELETEITEM, index, 0);
ignoreSelect = false;
if (code == 0) error (SWT.ERROR_ITEM_NOT_REMOVED);
System.arraycopy (items, index + 1, items, index, --count - index);
items [count] = null;
if (count == 0) {
if (imageList != null) {
int hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
int columnCount = OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0);
if (columnCount == 1 && columns [0] == null) columnCount = 0;
int i = 0;
while (i < columnCount) {
TableColumn column = columns [i];
if (column.getImage () != null) break;
i++;
}
if (i == columnCount) {
OS.SendMessage (handle, OS.LVM_SETIMAGELIST, OS.LVSIL_SMALL, 0);
display.releaseImageList (imageList);
imageList = null;
}
}
customDraw = false;
items = new TableItem [4];
}
}
void fixCheckboxImageList () {
/*
* Bug in Windows. When the state image list is larger than the
* image list, Windows incorrectly positions the state images. When
* the table is scrolled, Windows draws garbage. The fix is to force
* the state image list to be the same size as the image list.
*/
if ((style & SWT.CHECK) == 0) return;
int hImageList = OS.SendMessage (handle, OS.LVM_GETIMAGELIST, OS.LVSIL_SMALL, 0);
if (hImageList == 0) return;
int [] cx = new int [1], cy = new int [1];
OS.ImageList_GetIconSize (hImageList, cx, cy);
int hOldStateList = OS.SendMessage (handle, OS.LVM_GETIMAGELIST, OS.LVSIL_STATE, 0);
if (hOldStateList == 0) return;
int [] stateCx = new int [1], stateCy = new int [1];
OS.ImageList_GetIconSize (hOldStateList, stateCx, stateCy);
if (cx [0] == stateCx [0] && cy [0] == stateCy [0]) return;
setCheckboxImageList (cx [0], cy [0]);
}
int getBackgroundPixel () {
return OS.SendMessage (handle, OS.LVM_GETBKCOLOR, 0, 0);
}
/**
* Returns the column at the given, zero-relative index in the
* receiver. Throws an exception if the index is out of range.
* If no <code>TableColumn</code>s were created by the programmer,
* this method will throw <code>ERROR_INVALID_RANGE</code> despite
* the fact that a single column of data may be visible in the table.
* This occurs when the programmer uses the table like a list, adding
* items but never creating a column.
*
* @param index the index of the column to return
* @return the column at the given index
*
* @exception IllegalArgumentException <ul>
* <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
* </ul>
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public TableColumn getColumn (int index) {
checkWidget ();
int hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
int count = OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0);
if (count == 1 && columns [0] == null) count = 0;
if (!(0 <= index && index < count)) error (SWT.ERROR_INVALID_RANGE);
return columns [index];
}
/**
* Returns the number of columns contained in the receiver.
* If no <code>TableColumn</code>s were created by the programmer,
* this value is zero, despite the fact that visually, one column
* of items is may be visible. This occurs when the programmer uses
* the table like a list, adding items but never creating a column.
*
* @return the number of columns
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
* @exception SWTError <ul>
* <li>ERROR_CANNOT_GET_COUNT - if the operation fails because of an operating system failure</li>
* </ul>
*/
public int getColumnCount () {
checkWidget ();
int hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
int count = OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0);
if (count == 1 && columns [0] == null) count = 0;
return count;
}
/**
* Returns an array of <code>TableColumn</code>s which are the
* columns in the receiver. If no <code>TableColumn</code>s were
* created by the programmer, the array is empty, despite the fact
* that visually, one column of items may be visible. This occurs
* when the programmer uses the table like a list, adding items but
* never creating a column.
* <p>
* Note: This is not the actual structure used by the receiver
* to maintain its list of items, so modifying the array will
* not affect the receiver.
* </p>
*
* @return the items in the receiver
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public TableColumn [] getColumns () {
checkWidget ();
int hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
int count = OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0);
if (count == 1 && columns [0] == null) count = 0;
TableColumn [] result = new TableColumn [count];
System.arraycopy (columns, 0, result, 0, count);
return result;
}
/*
* Not currently used.
*/
int getFocusIndex () {
// checkWidget ();
return OS.SendMessage (handle, OS.LVM_GETNEXTITEM, -1, OS.LVNI_FOCUSED);
}
int getForegroundPixel () {
return OS.SendMessage (handle, OS.LVM_GETTEXTCOLOR, 0, 0);
}
/**
* Returns the width in pixels of a grid line.
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public int getGridLineWidth () {
checkWidget ();
return 1;
}
/**
* Returns the height of the receiver's header
*
* @return the height of the header or zero if the header is not visible
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*
* @since 2.0
*/
public int getHeaderHeight () {
checkWidget ();
int hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
if (hwndHeader == 0) return 0;
RECT rect = new RECT ();
OS.GetWindowRect (hwndHeader, rect);
return rect.bottom - rect.top;
}
/**
* Returns <code>true</code> if the receiver's header is visible,
* and <code>false</code> otherwise.
* <p>
* If one of the receiver's ancestors is not visible or some
* other condition makes the receiver not visible, this method
* may still indicate that it is considered visible even though
* it may not actually be showing.
* </p>
*
* @return the receiver's header's visibility state
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public boolean getHeaderVisible () {
checkWidget ();
int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
return (bits & OS.LVS_NOCOLUMNHEADER) == 0;
}
/**
* Returns the item at the given, zero-relative index in the
* receiver. Throws an exception if the index is out of range.
*
* @param index the index of the item to return
* @return the item at the given index
*
* @exception IllegalArgumentException <ul>
* <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
* </ul>
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public TableItem getItem (int index) {
checkWidget ();
int count = OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
if (!(0 <= index && index < count)) error (SWT.ERROR_INVALID_RANGE);
return _getItem (index);
}
/**
* Returns the item at the given point in the receiver
* or null if no such item exists. The point is in the
* coordinate system of the receiver.
*
* @param point the point used to locate the item
* @return the item at the given point
*
* @exception IllegalArgumentException <ul>
* <li>ERROR_NULL_ARGUMENT - if the point is null</li>
* </ul>
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public TableItem getItem (Point point) {
checkWidget ();
if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
LVHITTESTINFO pinfo = new LVHITTESTINFO ();
pinfo.x = point.x; pinfo.y = point.y;
OS.SendMessage (handle, OS.LVM_HITTEST, 0, pinfo);
if (pinfo.iItem != -1) return _getItem (pinfo.iItem);
return null;
}
/**
* Returns the number of items contained in the receiver.
*
* @return the number of items
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public int getItemCount () {
checkWidget ();
return OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
}
/**
* Returns the height of the area which would be used to
* display <em>one</em> of the items in the receiver's.
*
* @return the height of one item
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public int getItemHeight () {
checkWidget ();
int empty = OS.SendMessage (handle, OS.LVM_APPROXIMATEVIEWRECT, 0, 0);
int oneItem = OS.SendMessage (handle, OS.LVM_APPROXIMATEVIEWRECT, 1, 0);
return (oneItem >> 16) - (empty >> 16);
}
/**
* Returns an array of <code>TableItem</code>s which are the items
* in the receiver.
* <p>
* Note: This is not the actual structure used by the receiver
* to maintain its list of items, so modifying the array will
* not affect the receiver.
* </p>
*
* @return the items in the receiver
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public TableItem [] getItems () {
checkWidget ();
int count = OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
TableItem [] result = new TableItem [count];
if ((style & SWT.VIRTUAL) != 0) {
for (int i=0; i<count; i++) {
result [i] = _getItem (i);
}
} else {
System.arraycopy (items, 0, result, 0, count);
}
return result;
}
/**
* Returns <code>true</code> if the receiver's lines are visible,
* and <code>false</code> otherwise.
* <p>
* If one of the receiver's ancestors is not visible or some
* other condition makes the receiver not visible, this method
* may still indicate that it is considered visible even though
* it may not actually be showing.
* </p>
*
* @return the visibility state of the lines
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public boolean getLinesVisible () {
checkWidget ();
int bits = OS.SendMessage (handle, OS.LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
return (bits & OS.LVS_EX_GRIDLINES) != 0;
}
/**
* Returns an array of <code>TableItem</code>s that are currently
* selected in the receiver. An empty array indicates that no
* items are selected.
* <p>
* Note: This is not the actual structure used by the receiver
* to maintain its selection, so modifying the array will
* not affect the receiver.
* </p>
* @return an array representing the selection
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public TableItem [] getSelection () {
checkWidget ();
int i = -1, j = 0, count = OS.SendMessage (handle, OS.LVM_GETSELECTEDCOUNT, 0, 0);
TableItem [] result = new TableItem [count];
while ((i = OS.SendMessage (handle, OS.LVM_GETNEXTITEM, i, OS.LVNI_SELECTED)) != -1) {
result [j++] = _getItem (i);
}
return result;
}
/**
* Returns the number of selected items contained in the receiver.
*
* @return the number of selected items
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public int getSelectionCount () {
checkWidget ();
return OS.SendMessage (handle, OS.LVM_GETSELECTEDCOUNT, 0, 0);
}
/**
* Returns the zero-relative index of the item which is currently
* selected in the receiver, or -1 if no item is selected.
*
* @return the index of the selected item
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public int getSelectionIndex () {
checkWidget ();
int focusIndex = OS.SendMessage (handle, OS.LVM_GETNEXTITEM, -1, OS.LVNI_FOCUSED);
int selectedIndex = OS.SendMessage (handle, OS.LVM_GETNEXTITEM, -1, OS.LVNI_SELECTED);
if (focusIndex == selectedIndex) return selectedIndex;
int i = -1;
while ((i = OS.SendMessage (handle, OS.LVM_GETNEXTITEM, i, OS.LVNI_SELECTED)) != -1) {
if (i == focusIndex) return i;
}
return selectedIndex;
}
/**
* Returns the zero-relative indices of the items which are currently
* selected in the receiver. The array is empty if no items are selected.
* <p>
* Note: This is not the actual structure used by the receiver
* to maintain its selection, so modifying the array will
* not affect the receiver.
* </p>
* @return the array of indices of the selected items
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public int [] getSelectionIndices () {
checkWidget ();
int i = -1, j = 0, count = OS.SendMessage (handle, OS.LVM_GETSELECTEDCOUNT, 0, 0);
int [] result = new int [count];
while ((i = OS.SendMessage (handle, OS.LVM_GETNEXTITEM, i, OS.LVNI_SELECTED)) != -1) {
result [j++] = i;
}
return result;
}
/**
* Returns the zero-relative index of the item which is currently
* at the top of the receiver. This index can change when items are
* scrolled or new items are added or removed.
*
* @return the index of the top item
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public int getTopIndex () {
checkWidget ();
/*
* Bug in Windows. Under rare circumstances, LVM_GETTOPINDEX
* can return a negative number. When this happens, the table
* is displaying blank lines at the top of the controls. The
* fix is to check for a negative number and return zero instead.
*/
return Math.max (0, OS.SendMessage (handle, OS.LVM_GETTOPINDEX, 0, 0));
}
int imageIndex (Image image) {
if (image == null) return OS.I_IMAGENONE;
if (imageList == null) {
Rectangle bounds = image.getBounds ();
imageList = display.getImageList (new Point (bounds.width, bounds.height));
int index = imageList.indexOf (image);
if (index == -1) index = imageList.add (image);
int hImageList = imageList.getHandle ();
OS.SendMessage (handle, OS.LVM_SETIMAGELIST, OS.LVSIL_SMALL, hImageList);
fixCheckboxImageList ();
return index;
}
int index = imageList.indexOf (image);
if (index != -1) return index;
return imageList.add (image);
}
/**
* Searches the receiver's list starting at the first column
* (index 0) until a column is found that is equal to the
* argument, and returns the index of that column. If no column
* is found, returns -1.
*
* @param column the search column
* @return the index of the column
*
* @exception IllegalArgumentException <ul>
* <li>ERROR_NULL_ARGUMENT - if the string is null</li>
* </ul>
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public int indexOf (TableColumn column) {
checkWidget ();
if (column == null) error (SWT.ERROR_NULL_ARGUMENT);
int hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
int count = OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0);
for (int i=0; i<count; i++) {
if (columns [i] == column) return i;
}
return -1;
}
/**
* Searches the receiver's list starting at the first item
* (index 0) until an item is found that is equal to the
* argument, and returns the index of that item. If no item
* is found, returns -1.
*
* @param item the search item
* @return the index of the item
*
* @exception IllegalArgumentException <ul>
* <li>ERROR_NULL_ARGUMENT - if the string is null</li>
* </ul>
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public int indexOf (TableItem item) {
checkWidget ();
if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
int count = OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
if (1 <= lastIndexOf && lastIndexOf < count - 1) {
if (items [lastIndexOf] == item) return lastIndexOf;
if (items [lastIndexOf + 1] == item) return ++lastIndexOf;
if (items [lastIndexOf - 1] == item) return --lastIndexOf;
}
if (lastIndexOf < count / 2) {
for (int i=0; i<count; i++) {
if (items [i] == item) return lastIndexOf = i;
}
} else {
for (int i=count - 1; i>=0; --i) {
if (items [i] == item) return lastIndexOf = i;
}
}
return -1;
}
/**
* Returns <code>true</code> if the item is selected,
* and <code>false</code> otherwise. Indices out of
* range are ignored.
*
* @param index the index of the item
* @return the visibility state of the item at the index
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public boolean isSelected (int index) {
checkWidget ();
LVITEM lvItem = new LVITEM ();
lvItem.mask = OS.LVIF_STATE;
lvItem.stateMask = OS.LVIS_SELECTED;
lvItem.iItem = index;
int result = OS.SendMessage (handle, OS.LVM_GETITEM, 0, lvItem);
return (result != 0) && ((lvItem.state & OS.LVIS_SELECTED) != 0);
}
void releaseWidget () {
int hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
int columnCount = OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0);
if (columnCount == 1 && columns [0] == null) columnCount = 0;
for (int i=0; i<columnCount; i++) {
TableColumn column = columns [i];
if (!column.isDisposed ()) column.releaseResources ();
}
columns = null;
int itemCount = OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
/*
* Feature in Windows 98. When there are a large number
* of columns and items in a table (>1000) where each
* of the subitems in the table has a string, it is much
* faster to delete each item with LVM_DELETEITEM rather
* than using LVM_DELETEALLITEMS. The fix is to detect
* this case and delete the items, one by one. The fact
* that the fix is only necessary on Windows 98 was
* confirmed using version 5.81 of COMCTL32.DLL on both
* Windows 98 and NT.
*
* NOTE: LVM_DELETEALLITEMS is also sent by the table
* when the table is destroyed.
*/
if (OS.IsWin95 && columnCount > 1) {
/* Turn off redraw and leave it off */
OS.SendMessage (handle, OS.WM_SETREDRAW, 0, 0);
for (int i=itemCount-1; i>=0; --i) {
ignoreSelect = true;
OS.SendMessage (handle, OS.LVM_DELETEITEM, i, 0);
ignoreSelect = false;
TableItem item = items [i];
if (item != null && !item.isDisposed ()) item.releaseResources ();
}
} else {
for (int i=0; i<itemCount; i++) {
TableItem item = items [i];
if (item != null && !item.isDisposed ()) item.releaseResources ();
}
}
customDraw = false;
items = null;
if (imageList != null) {
OS.SendMessage (handle, OS.LVM_SETIMAGELIST, OS.LVSIL_SMALL, 0);
display.releaseImageList (imageList);
}
imageList = null;
int hOldList = OS.SendMessage (handle, OS.LVM_GETIMAGELIST, OS.LVSIL_STATE, 0);
OS.SendMessage (handle, OS.LVM_SETIMAGELIST, OS.LVSIL_STATE, 0);
if (hOldList != 0) OS.ImageList_Destroy (hOldList);
super.releaseWidget ();
}
/**
* Removes the items from the receiver's list at the given
* zero-relative indices.
*
* @param indices the array of indices of the items
*
* @exception IllegalArgumentException <ul>
* <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
* <li>ERROR_NULL_ARGUMENT - if the indices array is null</li>
* </ul>
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
* @exception SWTError <ul>
* <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</li>
* </ul>
*/
public void remove (int [] indices) {
checkWidget ();
if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
if (indices.length == 0) return;
int [] newIndices = new int [indices.length];
System.arraycopy (indices, 0, newIndices, 0, indices.length);
sort (newIndices);
int start = newIndices [newIndices.length - 1], end = newIndices [0];
int count = OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
if (!(0 <= start && start <= end && end < count)) {
error (SWT.ERROR_INVALID_RANGE);
}
int last = -1;
for (int i=0; i<newIndices.length; i++) {
int index = newIndices [i];
if (index != last) {
ignoreSelect = true;
int code = OS.SendMessage (handle, OS.LVM_DELETEITEM, index, 0);
ignoreSelect = false;
if (code == 0) error (SWT.ERROR_ITEM_NOT_REMOVED);
if (items [index] != null) items [index].releaseResources ();
System.arraycopy (items, index + 1, items, index, --count - index);
items [count] = null;
last = index;
}
}
}
/**
* Removes the item from the receiver at the given
* zero-relative index.
*
* @param index the index for the item
*
* @exception IllegalArgumentException <ul>
* <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
* </ul>
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
* @exception SWTError <ul>
* <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</li>
* </ul>
*/
public void remove (int index) {
checkWidget ();
int count = OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
ignoreSelect = true;
int code = OS.SendMessage (handle, OS.LVM_DELETEITEM, index, 0);
ignoreSelect = false;
if (code == 0) {
if (0 <= index && index < count) {
error (SWT.ERROR_ITEM_NOT_REMOVED);
} else {
error (SWT.ERROR_INVALID_RANGE);
}
}
TableItem item = items [index];
System.arraycopy (items, index + 1, items, index, --count - index);
items [count] = null;
if (item != null) item.releaseResources ();
}
/**
* Removes the items from the receiver which are
* between the given zero-relative start and end
* indices (inclusive).
*
* @param start the start of the range
* @param end the end of the range
*
* @exception IllegalArgumentException <ul>
* <li>ERROR_INVALID_RANGE - if either the start or end are not between 0 and the number of elements in the list minus 1 (inclusive)</li>
* </ul>
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
* @exception SWTError <ul>
* <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</li>
* </ul>
*/
public void remove (int start, int end) {
checkWidget ();
if (start > end) return;
int count = OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
if (!(0 <= start && start <= end && end < count)) {
error (SWT.ERROR_INVALID_RANGE);
}
if (start == 0 && end == count - 1) {
removeAll ();
} else {
int index = start;
while (index <= end) {
ignoreSelect = true;
int code = OS.SendMessage (handle, OS.LVM_DELETEITEM, start, 0);
ignoreSelect = false;
if (code == 0) break;
if (items [index] != null) items [index].releaseResources ();
index++;
}
System.arraycopy (items, index, items, start, count - index);
for (int i=count-(index-start); i<count; i++) items [i] = null;
if (index <= end) error (SWT.ERROR_ITEM_NOT_REMOVED);
}
}
/**
* Removes all of the items from the receiver.
* <p>
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public void removeAll () {
checkWidget ();
int hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
int columnCount = OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0);
if (columnCount == 1 && columns [0] == null) columnCount = 0;
int itemCount = OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
/*
* Feature in Windows 98. When there are a large number
* of columns and items in a table (>1000) where each
* of the subitems in the table has a string, it is much
* faster to delete each item with LVM_DELETEITEM rather
* than using LVM_DELETEALLITEMS. The fix is to detect
* this case and delete the items, one by one. The fact
* that the fix is only necessary on Windows 98 was
* confirmed using version 5.81 of COMCTL32.DLL on both
* Windows 98 and NT.
*
* NOTE: LVM_DELETEALLITEMS is also sent by the table
* when the table is destroyed.
*/
if (OS.IsWin95 && columnCount > 1) {
boolean redraw = drawCount == 0 && OS.IsWindowVisible (handle);
if (redraw) OS.SendMessage (handle, OS.WM_SETREDRAW, 0, 0);
int index = itemCount - 1;
while (index >= 0) {
ignoreSelect = true;
int code = OS.SendMessage (handle, OS.LVM_DELETEITEM, index, 0);
ignoreSelect = false;
if (code == 0) break;
// BUG - disposed callback could remove an item
if (items [index] != null) items [index].releaseResources ();
--index;
}
if (redraw) {
OS.SendMessage (handle, OS.WM_SETREDRAW, 1, 0);
/*
* This code is intentionally commented. The window proc
* for the table implements WM_SETREDRAW to invalidate
* and erase the table so it is not necessary to do this
* again.
*/
// int flags = OS.RDW_ERASE | OS.RDW_FRAME | OS.RDW_INVALIDATE;
// OS.RedrawWindow (handle, null, 0, flags);
}
if (index != -1) error (SWT.ERROR_ITEM_NOT_REMOVED);
} else {
ignoreSelect = true;
int code = OS.SendMessage (handle, OS.LVM_DELETEALLITEMS, 0, 0);
ignoreSelect = false;
if (code == 0) error (SWT.ERROR_ITEM_NOT_REMOVED);
for (int i=0; i<itemCount; i++) {
TableItem item = items [i];
if (item != null && !item.isDisposed ()) item.releaseResources ();
}
}
if (imageList != null) {
int i = 0;
while (i < columnCount) {
TableColumn column = columns [i];
if (column.getImage () != null) break;
i++;
}
if (i == columnCount) {
OS.SendMessage (handle, OS.LVM_SETIMAGELIST, OS.LVSIL_SMALL, 0);
display.releaseImageList (imageList);
imageList = null;
}
}
customDraw = false;
items = new TableItem [4];
}
/**
* Removes the listener from the collection of listeners who will
* be notified when the receiver's selection changes.
*
* @param listener the listener which should no longer be notified
*
* @exception IllegalArgumentException <ul>
* <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
* </ul>
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*
* @see SelectionListener
* @see #addSelectionListener(SelectionListener)
*/
public void removeSelectionListener(SelectionListener listener) {
checkWidget ();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
if (eventTable == null) return;
eventTable.unhook (SWT.Selection, listener);
eventTable.unhook (SWT.DefaultSelection,listener);
}
/**
* Selects the items at the given zero-relative indices in the receiver.
* The current selection is not cleared before the new items are selected.
* <p>
* If the item at a given index is not selected, it is selected.
* If the item at a given index was already selected, it remains selected.
* Indices that are out of range and duplicate indices are ignored.
* If the receiver is single-select and multiple indices are specified,
* then all indices are ignored.
*
* @param indices the array of indices for the items to select
*
* @exception IllegalArgumentException <ul>
* <li>ERROR_NULL_ARGUMENT - if the array of indices is null</li>
* </ul>
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*
* @see Table#setSelection(int[])
*/
public void select (int [] indices) {
checkWidget ();
if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
int length = indices.length;
if (length == 0 || ((style & SWT.SINGLE) != 0 && length > 1)) return;
LVITEM lvItem = new LVITEM ();
lvItem.state = OS.LVIS_SELECTED;
lvItem.stateMask = OS.LVIS_SELECTED;
for (int i=length-1; i>=0; --i) {
/*
* An index of -1 will apply the change to all
* items. Ensure that indices are greater than -1.
*/
if (indices [i] >= 0) {
ignoreSelect = true;
OS.SendMessage (handle, OS.LVM_SETITEMSTATE, indices [i], lvItem);
ignoreSelect = false;
}
}
}
/**
* Selects the item at the given zero-relative index in the receiver.
* If the item at the index was already selected, it remains
* selected. Indices that are out of range are ignored.
*
* @param index the index of the item to select
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public void select (int index) {
checkWidget ();
/*
* An index of -1 will apply the change to all
* items. Ensure that index is greater than -1.
*/
if (index < 0) return;
LVITEM lvItem = new LVITEM ();
lvItem.state = OS.LVIS_SELECTED;
lvItem.stateMask = OS.LVIS_SELECTED;
ignoreSelect = true;
OS.SendMessage (handle, OS.LVM_SETITEMSTATE, index, lvItem);
ignoreSelect = false;
}
/**
* Selects the items in the range specified by the given zero-relative
* indices in the receiver. The range of indices is inclusive.
* The current selection is not cleared before the new items are selected.
* <p>
* If an item in the given range is not selected, it is selected.
* If an item in the given range was already selected, it remains selected.
* Indices that are out of range are ignored and no items will be selected
* if start is greater than end.
* If the receiver is single-select and there is more than one item in the
* given range, then all indices are ignored.
*
* @param start the start of the range
* @param end the end of the range
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*
* @see Table#setSelection(int,int)
*/
public void select (int start, int end) {
checkWidget ();
if (end < 0 || start > end || ((style & SWT.SINGLE) != 0 && start != end)) return;
int count = OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
if (count == 0 || start >= count) return;
start = Math.max (0, start);
end = Math.min (end, count - 1);
if (start == 0 && end == count - 1) {
selectAll ();
} else {
/*
* An index of -1 will apply the change to all
* items. Indices must be greater than -1.
*/
LVITEM lvItem = new LVITEM ();
lvItem.state = OS.LVIS_SELECTED;
lvItem.stateMask = OS.LVIS_SELECTED;
for (int i=start; i<=end; i++) {
ignoreSelect = true;
OS.SendMessage (handle, OS.LVM_SETITEMSTATE, i, lvItem);
ignoreSelect = false;
}
}
}
/**
* Selects all of the items in the receiver.
* <p>
* If the receiver is single-select, do nothing.
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public void selectAll () {
checkWidget ();
if ((style & SWT.SINGLE) != 0) return;
LVITEM lvItem = new LVITEM ();
lvItem.mask = OS.LVIF_STATE;
lvItem.state = OS.LVIS_SELECTED;
lvItem.stateMask = OS.LVIS_SELECTED;
ignoreSelect = true;
OS.SendMessage (handle, OS.LVM_SETITEMSTATE, -1, lvItem);
ignoreSelect = false;
}
LRESULT sendMouseDownEvent (int type, int button, int msg, int wParam, int lParam) {
/*
* Feature in Windows. Inside WM_LBUTTONDOWN and WM_RBUTTONDOWN,
* the widget starts a modal loop to determine if the user wants
* to begin a drag/drop operation or marque select. Unfortunately,
* this modal loop eats the corresponding mouse up. The fix is to
* detect the cases when the modal loop has eaten the mouse up and
* issue a fake mouse up.
*
* By observation, when the mouse is clicked anywhere but the check
* box, the widget eats the mouse up. When the mouse is dragged,
* the widget does not eat the mouse up.
*/
LVHITTESTINFO pinfo = new LVHITTESTINFO ();
pinfo.x = (short) (lParam & 0xFFFF);
pinfo.y = (short) (lParam >> 16);
OS.SendMessage (handle, OS.LVM_HITTEST, 0, pinfo);
sendMouseEvent (type, button, msg, wParam, lParam);
/*
* Force the table to have focus so that when the user
* reselects the focus item, the LVIS_FOCUSED state bits
* for the item will be set. These bits are used when
* the table is multi-select to issue the selection
* event. If the user did not click on an item, then
* set focus to the table so that it will come to the
* front and take focus in the work around below.
*/
OS.SetFocus (handle);
/*
* Feature in Windows. When the user selects outside of
* a table item, Windows deselects all the items, even
* when the table is multi-select. While not strictly
* wrong, this is unexpected. The fix is to detect the
* case and avoid calling the window proc.
*/
if (pinfo.iItem == -1) {
if (OS.GetCapture () != handle) OS.SetCapture (handle);
return LRESULT.ZERO;
}
/*
* Feature in Windows. When a table item is reselected
* in a single-select table, Windows does not issue a
* WM_NOTIFY because the item state has not changed.
* This is strictly correct but is inconsistent with the
* list widget and other widgets in Windows. The fix is
* to detect the case when an item is reselected and issue
* the notification.
*
* NOTE: This code runs for multi-select as well, ignoring
* the selection that is issed from WM_NOTIFY.
*/
boolean wasSelected = false;
int count = OS.SendMessage (handle, OS.LVM_GETSELECTEDCOUNT, 0, 0);
if (count == 1 && pinfo.iItem != -1) {
LVITEM lvItem = new LVITEM ();
lvItem.mask = OS.LVIF_STATE;
lvItem.stateMask = OS.LVIS_SELECTED;
lvItem.iItem = pinfo.iItem;
OS.SendMessage (handle, OS.LVM_GETITEM, 0, lvItem);
wasSelected = (lvItem.state & OS.LVIS_SELECTED) != 0;
if (wasSelected) ignoreSelect = true;
}
dragStarted = false;
int code = callWindowProc (msg, wParam, lParam);
if (wasSelected) {
ignoreSelect = false;
Event event = new Event ();
event.item = _getItem (pinfo.iItem);
postEvent (SWT.Selection, event);
}
if (dragStarted) {
if (OS.GetCapture () != handle) OS.SetCapture (handle);
} else {
int flags = OS.LVHT_ONITEMLABEL | OS.LVHT_ONITEMICON;
boolean fakeMouseUp = (pinfo.flags & flags) != 0;
if (!fakeMouseUp && (style & SWT.MULTI) != 0) {
fakeMouseUp = (pinfo.flags & OS.LVHT_ONITEMSTATEICON) == 0;
}
if (fakeMouseUp) {
mouseDown = false;
sendMouseEvent (SWT.MouseUp, button, msg, wParam, lParam);
}
}
dragStarted = false;
return new LRESULT (code);
}
void setBackgroundPixel (int pixel) {
if (background == pixel) return;
background = pixel;
/*
* Feature in Windows. Setting the color to be
* the current default is not correct because the
* widget will not change colors when the colors
* are changed from the control panel. There is
* no fix at this time.
*/
if (pixel == -1) pixel = defaultBackground ();
OS.SendMessage (handle, OS.LVM_SETBKCOLOR, 0, pixel);
OS.SendMessage (handle, OS.LVM_SETTEXTBKCOLOR, 0, pixel);
if ((style & SWT.CHECK) != 0) setCheckboxImageListColor ();
/*
* Feature in Windows. When the background color is
* changed, the table does not redraw until the next
* WM_PAINT. The fix is to force a redraw.
*/
OS.InvalidateRect (handle, null, true);
}
void setCheckboxImageListColor () {
if ((style & SWT.CHECK) == 0) return;
int hOldStateList = OS.SendMessage (handle, OS.LVM_GETIMAGELIST, OS.LVSIL_STATE, 0);
if (hOldStateList == 0) return;
int [] cx = new int [1], cy = new int [1];
OS.ImageList_GetIconSize (hOldStateList, cx, cy);
setCheckboxImageList (cx [0], cy [0]);
}
void setCheckboxImageList (int width, int height) {
if ((style & SWT.CHECK) == 0) return;
int count = 4;
int hStateList = OS.ImageList_Create (width, height, OS.ILC_COLOR, count, count);
int hDC = OS.GetDC (handle);
if (!OS.IsWinCE && (OS.WIN32_MAJOR << 16 | OS.WIN32_MINOR) >= (4 << 16 | 10)) {
OS.SetLayout (hDC, 0);
}
int memDC = OS.CreateCompatibleDC (hDC);
int hBitmap = OS.CreateCompatibleBitmap (hDC, width * count, height);
int hOldBitmap = OS.SelectObject (memDC, hBitmap);
RECT rect = new RECT ();
OS.SetRect (rect, 0, 0, width * count, height);
int hBrush = OS.CreateSolidBrush (getBackgroundPixel ());
OS.FillRect (memDC, rect, hBrush);
OS.DeleteObject (hBrush);
int oldFont = OS.SelectObject (hDC, defaultFont ());
TEXTMETRIC tm = OS.IsUnicode ? (TEXTMETRIC) new TEXTMETRICW () : new TEXTMETRICA ();
OS.GetTextMetrics (hDC, tm);
OS.SelectObject (hDC, oldFont);
int itemWidth = Math.min (tm.tmHeight, width);
int itemHeight = Math.min (tm.tmHeight, height);
int left = (width - itemWidth) / 2, top = (height - itemHeight) / 2 + 1;
OS.SetRect (rect, left, top, left + itemWidth, top + itemHeight);
OS.DrawFrameControl (memDC, rect, OS.DFC_BUTTON, OS.DFCS_BUTTONCHECK | OS.DFCS_FLAT);
rect.left += width; rect.right += width;
OS.DrawFrameControl (memDC, rect, OS.DFC_BUTTON, OS.DFCS_BUTTONCHECK | OS.DFCS_CHECKED | OS.DFCS_FLAT);
rect.left += width; rect.right += width;
OS.DrawFrameControl (memDC, rect, OS.DFC_BUTTON, OS.DFCS_BUTTONCHECK | OS.DFCS_INACTIVE | OS.DFCS_FLAT);
rect.left += width; rect.right += width;
OS.DrawFrameControl (memDC, rect, OS.DFC_BUTTON, OS.DFCS_BUTTONCHECK | OS.DFCS_CHECKED | OS.DFCS_INACTIVE | OS.DFCS_FLAT);
OS.SelectObject (memDC, hOldBitmap);
OS.DeleteDC (memDC);
OS.ReleaseDC (handle, hDC);
OS.ImageList_AddMasked (hStateList, hBitmap, 0);
OS.DeleteObject (hBitmap);
int hOldStateList = OS.SendMessage (handle, OS.LVM_GETIMAGELIST, OS.LVSIL_STATE, 0);
OS.SendMessage (handle, OS.LVM_SETIMAGELIST, OS.LVSIL_STATE, hStateList);
if (hOldStateList != 0) OS.ImageList_Destroy (hOldStateList);
}
void setFocusIndex (int index) {
// checkWidget ();
/*
* An index of -1 will apply the change to all
* items. Ensure that index is greater than -1.
*/
if (index < 0) return;
LVITEM lvItem = new LVITEM ();
lvItem.state = OS.LVIS_FOCUSED;
lvItem.stateMask = OS.LVIS_FOCUSED;
ignoreSelect = true;
OS.SendMessage (handle, OS.LVM_SETITEMSTATE, index, lvItem);
ignoreSelect = false;
}
public void setFont (Font font) {
checkWidget ();
super.setFont (font);
setScrollWidth (null, true);
/*
* Bug in Windows. Setting the font will cause the
* table area to be redrawn but not the column headers.
* Fix is to force a redraw on the column headers.
*/
int hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
OS.InvalidateRect (hwndHeader, null, true);
int bits = OS.SendMessage (handle, OS.LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
if ((bits & OS.LVS_EX_GRIDLINES) == 0) return;
bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
if ((bits & OS.LVS_NOCOLUMNHEADER) != 0) return;
setRowHeight ();
}
void setForegroundPixel (int pixel) {
if (foreground == pixel) return;
foreground = pixel;
/*
* Feature in Windows. Setting the color to be
* the current default is not correct because the
* table will not change colors when the colors
* are changed from the control panel. There is
* no fix at this time.
*/
if (pixel == -1) pixel = defaultForeground ();
OS.SendMessage (handle, OS.LVM_SETTEXTCOLOR, 0, pixel);
/*
* Feature in Windows. When the foreground color is
* changed, the table does not redraw until the next
* WM_PAINT. The fix is to force a redraw.
*/
OS.InvalidateRect (handle, null, true);
}
/**
* Marks the receiver's header as visible if the argument is <code>true</code>,
* and marks it invisible otherwise.
* <p>
* If one of the receiver's ancestors is not visible or some
* other condition makes the receiver not visible, marking
* it visible may not actually cause it to be displayed.
* </p>
*
* @param show the new visibility state
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public void setHeaderVisible (boolean show) {
checkWidget ();
int newBits = OS.GetWindowLong (handle, OS.GWL_STYLE);
newBits &= ~OS.LVS_NOCOLUMNHEADER;
if (!show) newBits |= OS.LVS_NOCOLUMNHEADER;
/*
* Feature in Windows. Setting or clearing LVS_NOCOLUMNHEADER
* causes the table to scroll to the beginning. The fix is to
* save and restore the top index.
*/
int topIndex = getTopIndex ();
OS.SetWindowLong (handle, OS.GWL_STYLE, newBits);
if (topIndex != 0) setTopIndex (topIndex);
if (show) {
int bits = OS.SendMessage (handle, OS.LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
if ((bits & OS.LVS_EX_GRIDLINES) != 0) setRowHeight ();
}
}
/**
* Sets the number of items contained in the receiver.
*
* @param show the new visibility state
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*
* @since 3.0
*/
public void setItemCount (int count) {
checkWidget ();
count = Math.max (0, count);
boolean isVirtual = (style & SWT.VIRTUAL) != 0;
setRedraw (false);
removeAll ();
if (isVirtual) {
OS.SendMessage (handle, OS.LVM_SETITEMCOUNT, count, 0);
count = OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
/*
* Bug in Windows. When LVM_SETITEMCOUNT is sent to a table
* that is too small to show a single item, when the table is
* resized to be larger, it is scrolled to the second item.
* The fix is to use LVM_ENSUREVISIBLE to scroll the table to
* the first item.
*/
OS.SendMessage (handle, OS.LVM_ENSUREVISIBLE, 0, 1);
}
items = new TableItem [(count + 3) / 4 * 4];
if (!isVirtual) {
for (int i=0; i<count; i++) {
items [i] = new TableItem (this, SWT.NONE, i, true);
}
}
setRedraw (true);
}
/**
* Marks the receiver's lines as visible if the argument is <code>true</code>,
* and marks it invisible otherwise.
* <p>
* If one of the receiver's ancestors is not visible or some
* other condition makes the receiver not visible, marking
* it visible may not actually cause it to be displayed.
* </p>
*
* @param show the new visibility state
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public void setLinesVisible (boolean show) {
checkWidget ();
int newBits = 0;
if (show) {
newBits = OS.LVS_EX_GRIDLINES;
int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
if ((bits & OS.LVS_NOCOLUMNHEADER) == 0) setRowHeight ();
}
OS.SendMessage (handle, OS.LVM_SETEXTENDEDLISTVIEWSTYLE, OS.LVS_EX_GRIDLINES, newBits);
}
public void setRedraw (boolean redraw) {
checkWidget ();
/*
* Feature in Windows. When WM_SETREDRAW is used to turn
* off drawing in a widget, it clears the WS_VISIBLE bits
* and then sets them when redraw is turned back on. This
* means that WM_SETREDRAW will make a widget unexpectedly
* visible. The fix is to track the visibility state while
* drawing is turned off and restore it when drawing is turned
* back on.
*/
if (drawCount == 0) {
int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
if ((bits & OS.WS_VISIBLE) == 0) state |= HIDDEN;
}
if (redraw) {
if (--drawCount == 0) {
/*
* When many items are added to a table, it is faster to
* temporarily unsubclass the window proc so that messages
* are dispatched directly to the table.
*
* NOTE: This is optimization somewhat dangerous because any
* operation can occur when redraw is turned off, even operations
* where the table must be subclassed in order to have the correct
* behavior or work around a Windows bug.
*
* This code is intentionally commented.
*/
// subclass ();
/* Set the width of the horizontal scroll bar */
setScrollWidth (null, true);
/*
* Bug in Windows. For some reason, when WM_SETREDRAW is used
* to turn redraw back on this may result in a WM_SIZE. If the
* table column widths are adjusted in WM_SIZE, blank lines may
* be inserted at the top of the widget. A call to LVM_GETTOPINDEX
* will return a negative number (this is an impossible result).
* The fix is to ignore any resize generated by WM_SETREDRAW and
* defer the work until the WM_SETREDRAW has returned.
*/
ignoreResize = true;
OS.SendMessage (handle, OS.WM_SETREDRAW, 1, 0);
if ((state & HIDDEN) != 0) {
state &= ~HIDDEN;
OS.ShowWindow (handle, OS.SW_HIDE);
}
if (!ignoreResize) {
setResizeChildren (false);
sendEvent (SWT.Resize);
// widget may be disposed at this point
if (isDisposed ()) return;
if (layout != null) layout.layout (this, false);
setResizeChildren (true);
}
ignoreResize = false;
/*
* This code is intentionally commented. The window proc
* for the table implements WM_SETREDRAW to invalidate
* and erase the table and the header. This is undocumented
* behavior. The commented code below shows what is actually
* happening and reminds us that we are relying on this
* undocumented behavior.
*/
// int hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
// if (hwndHeader != 0) OS.SendMessage (hwndHeader, OS.WM_SETREDRAW, 1, 0);
// int flags = OS.RDW_ERASE | OS.RDW_FRAME | OS.RDW_INVALIDATE | OS.RDW_ALLCHILDREN;
// OS.RedrawWindow (handle, null, 0, flags);
// if (hwndHeader != 0) OS.RedrawWindow (hwndHeader, null, 0, flags);
/*
* NOTE: The window proc for the table does not redraw the
* non-client area (ie. the border and scroll bars). This
* must be explicitly redrawn. This code can be removed
* if we stop relying on the undocuemented behavior described
* above.
*/
if (OS.IsWinCE) {
OS.InvalidateRect (handle, null, false);
} else {
OS.RedrawWindow (handle, null, 0, OS.RDW_FRAME | OS.RDW_INVALIDATE);
}
}
} else {
if (drawCount++ == 0) {
OS.SendMessage (handle, OS.WM_SETREDRAW, 0, 0);
int hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
if (hwndHeader != 0) OS.SendMessage (hwndHeader, OS.WM_SETREDRAW, 0, 0);
/*
* When many items are added to a table, it is faster to
* temporarily unsubclass the window proc so that messages
* are dispatched directly to the table.
*
* NOTE: This is optimization somewhat dangerous because any
* operation can occur when redraw is turned off, even operations
* where the table must be subclassed in order to have the correct
* behavior or work around a Windows bug.
*
* This code is intentionally commented.
*/
// unsubclass ();
}
}
}
void setRowHeight () {
/*
* Bug in Windows. When both a header and grid lines are
* displayed, the grid lines do not take into account the
* height of the header and draw in the wrong place. The
* fix is to set the height of the table items to be the
* height of the header so that the lines draw in the right
* place. The height of a table item is the maximum of the
* height of the font or the height of image list.
*
* NOTE: In version 5.80 of COMCTL32.DLL, the bug is fixed.
*/
if ((OS.COMCTL32_MAJOR << 16 | OS.COMCTL32_MINOR) >= (5 << 16 | 80)) return;
int hOldList = OS.SendMessage (handle, OS.LVM_GETIMAGELIST, OS.LVSIL_SMALL, 0);
if (hOldList != 0) return;
int hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
RECT rect = new RECT ();
OS.GetWindowRect (hwndHeader, rect);
int height = rect.bottom - rect.top - 1;
int hImageList = OS.ImageList_Create (1, height, 0, 0, 0);
OS.SendMessage (handle, OS.LVM_SETIMAGELIST, OS.LVSIL_SMALL, hImageList);
fixCheckboxImageList ();
OS.SendMessage (handle, OS.LVM_SETIMAGELIST, OS.LVSIL_SMALL, 0);
OS.ImageList_Destroy (hImageList);
}
boolean setScrollWidth (TableItem item, boolean force) {
if (ignoreRedraw) return false;
if (!force && (drawCount != 0 || !OS.IsWindowVisible (handle))) {
fixScrollWidth = true;
return false;
}
fixScrollWidth = false;
int hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
int count = OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0);
if (count == 1 && columns [0] == null) {
if ((style & SWT.VIRTUAL) != 0) {
int newWidth = 0;
count = OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
int index = 0;
while (index < count) {
String string = null;
if (item != null) {
string = item.text;
} else {
if (items [index] != null) string = items [index].text;
}
if (string != null && string.length () != 0) {
TCHAR buffer = new TCHAR (getCodePage (), string, true);
newWidth = Math.max (newWidth, OS.SendMessage (handle, OS.LVM_GETSTRINGWIDTH, 0, buffer));
}
if (item != null) break;
index++;
}
int hStateList = OS.SendMessage (handle, OS.LVM_GETIMAGELIST, OS.LVSIL_STATE, 0);
if (hStateList != 0) {
int [] cx = new int [1], cy = new int [1];
OS.ImageList_GetIconSize (hStateList, cx, cy);
newWidth += cx [0] + 4;
}
int hImageList = OS.SendMessage (handle, OS.LVM_GETIMAGELIST, OS.LVSIL_SMALL, 0);
if (hImageList != 0) {
int [] cx = new int [1], cy = new int [1];
OS.ImageList_GetIconSize (hImageList, cx, cy);
newWidth += cx [0];
}
newWidth += 8;
int oldWidth = OS.SendMessage (handle, OS.LVM_GETCOLUMNWIDTH, 0, 0);
if (newWidth > oldWidth) {
OS.SendMessage (handle, OS.LVM_SETCOLUMNWIDTH, 0, newWidth);
return true;
}
} else {
/*
* Bug in Windows. When the table has no icons, the width that is
* computed by LVM_SETCOLUMNWIDTH with LVSCW_AUTOSIZE is too small,
* causing the long items to be truncated with '...'. The fix is
* to increase the size by a small amount.
*/
OS.SendMessage (handle, OS.LVM_SETCOLUMNWIDTH, 0, OS.LVSCW_AUTOSIZE);
if (imageList == null) {
int width = OS.SendMessage (handle, OS.LVM_GETCOLUMNWIDTH, 0, 0);
OS.SendMessage (handle, OS.LVM_SETCOLUMNWIDTH, 0, width + 2);
}
return true;
}
}
return false;
}
/**
* Selects the items at the given zero-relative indices in the receiver.
* The current selection is cleared before the new items are selected.
* <p>
* Indices that are out of range and duplicate indices are ignored.
* If the receiver is single-select and multiple indices are specified,
* then all indices are ignored.
*
* @param indices the indices of the items to select
*
* @exception IllegalArgumentException <ul>
* <li>ERROR_NULL_ARGUMENT - if the array of indices is null</li>
* </ul>
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*
* @see Table#deselectAll()
* @see Table#select(int[])
*/
public void setSelection (int [] indices) {
checkWidget ();
if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
deselectAll ();
int length = indices.length;
if (length == 0 || ((style & SWT.SINGLE) != 0 && length > 1)) return;
select (indices);
int focusIndex = indices [0];
if (focusIndex != -1) setFocusIndex (focusIndex);
showSelection ();
}
/**
* Sets the receiver's selection to be the given array of items.
* The current selection is cleared before the new items are selected.
* <p>
* Items that are not in the receiver are ignored.
* If the receiver is single-select and multiple items are specified,
* then all items are ignored.
*
* @param items the array of items
*
* @exception IllegalArgumentException <ul>
* <li>ERROR_NULL_ARGUMENT - if the array of items is null</li>
* <li>ERROR_INVALID_ARGUMENT - if one of the items has been disposed</li>
* </ul>
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*
* @see Table#deselectAll()
* @see Table#select(int[])
* @see Table#setSelection(int[])
*/
public void setSelection (TableItem [] items) {
checkWidget ();
if (items == null) error (SWT.ERROR_NULL_ARGUMENT);
deselectAll ();
int length = items.length;
if (length == 0 || ((style & SWT.SINGLE) != 0 && length > 1)) return;
int focusIndex = -1;
for (int i=length-1; i>=0; --i) {
int index = indexOf (items [i]);
if (index != -1) {
select (focusIndex = index);
}
}
if (focusIndex != -1) setFocusIndex (focusIndex);
showSelection ();
}
/**
* Selects the item at the given zero-relative index in the receiver.
* The current selected is first cleared, then the new item is selected.
*
* @param index the index of the item to select
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*
* @see Table#deselectAll()
* @see Table#select(int)
*/
public void setSelection (int index) {
checkWidget ();
deselectAll ();
select (index);
if (index != -1) setFocusIndex (index);
showSelection ();
}
/**
* Selects the items in the range specified by the given zero-relative
* indices in the receiver. The range of indices is inclusive.
* The current selection is cleared before the new items are selected.
* <p>
* Indices that are out of range are ignored and no items will be selected
* if start is greater than end.
* If the receiver is single-select and there is more than one item in the
* given range, then all indices are ignored.
*
* @param start the start index of the items to select
* @param end the end index of the items to select
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*
* @see Table#deselectAll()
* @see Table#select(int,int)
*/
public void setSelection (int start, int end) {
checkWidget ();
deselectAll ();
if (end < 0 || start > end || ((style & SWT.SINGLE) != 0 && start != end)) return;
int count = OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
if (count == 0 || start >= count) return;
start = Math.max (0, start);
end = Math.min (end, count - 1);
select (start, end);
setFocusIndex (start);
showSelection ();
}
/**
* Sets the zero-relative index of the item which is currently
* at the top of the receiver. This index can change when items
* are scrolled or new items are added and removed.
*
* @param index the index of the top item
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public void setTopIndex (int index) {
checkWidget ();
int topIndex = OS.SendMessage (handle, OS.LVM_GETTOPINDEX, 0, 0);
if (index == topIndex) return;
/*
* Bug in Windows. For some reason, LVM_SCROLL refuses to
* scroll a table vertically when the width and height of
* the table is smaller than a certain size. The values
* that the author is seeing are width=68 and height=6
* but there is no guarantee that these values are absolute.
* They may depend on the font and any number of other
* factors. In fact, the author has observed that setting
* the font to anything but the default seems to sometimes
* fix the problem. The fix is to use LVM_GETCOUNTPERPAGE
* to detect the case when the number of visible items is
* zero and use LVM_ENSUREVISIBLE to scroll the table to
* make the index visible.
*/
/*
* Bug in Windows. When the table header is visible and
* there is not enough space to show a single table item,
* LVM_GETCOUNTPERPAGE can return a negative number instead
* of zero. The fix is to test for negative or zero.
*/
if (OS.SendMessage (handle, OS.LVM_GETCOUNTPERPAGE, 0, 0) <= 0) {
/*
* Bug in Windows. For some reason, LVM_ENSUREVISIBLE can
* scroll one item more or one item less when there is not
* enough space to show a single table item. The fix is
* to detect the case and call LVM_ENSUREVISIBLE again with
* the same arguments. It seems that once LVM_ENSUREVISIBLE
* has scrolled into the general area, it is able to scroll
* to the exact item.
*/
OS.SendMessage (handle, OS.LVM_ENSUREVISIBLE, index, 1);
if (index != OS.SendMessage (handle, OS.LVM_GETTOPINDEX, 0, 0)) {
OS.SendMessage (handle, OS.LVM_ENSUREVISIBLE, index, 1);
}
return;
}
/* Use LVM_SCROLL to scroll the table */
RECT rect = new RECT ();
rect.left = OS.LVIR_BOUNDS;
OS.SendMessage (handle, OS.LVM_GETITEMRECT, 0, rect);
int dy = (index - topIndex) * (rect.bottom - rect.top);
OS.SendMessage (handle, OS.LVM_SCROLL, 0, dy);
}
/**
* Shows the column. If the column is already showing in the receiver,
* this method simply returns. Otherwise, the columns are scrolled until
* the column is visible.
*
* @param column the column to be shown
*
* @exception IllegalArgumentException <ul>
* <li>ERROR_NULL_ARGUMENT - if the item is null</li>
* <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li>
* </ul>
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*
* @since 3.0
*/
public void showColumn (TableColumn column) {
checkWidget ();
if (column == null) error (SWT.ERROR_NULL_ARGUMENT);
if (column.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
if (column.parent != this) return;
int index = indexOf (column);
int hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
int count = OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0);
if (count <= 1 || !(0 <= index && index < count)) return;
/*
* Feature in Windows. Calling LVM_GETSUBITEMRECT with -1 for the
* row number gives the bounds of the item that would be above the
* first row in the table. This is undocumented and does not work
* for the first column. In this case, to get the bounds of the
* first column, get the bounds of the second column and subtract
* the width of the first. The left edge of the second column is
* also used as the right edge of the first.
*/
RECT rect = new RECT ();
rect.left = OS.LVIR_BOUNDS;
if (index == 0) {
rect.top = 1;
OS.SendMessage (handle, OS.LVM_GETSUBITEMRECT, -1, rect);
rect.right = rect.left;
int width = OS.SendMessage (handle, OS.LVM_GETCOLUMNWIDTH, 0, 0);
rect.left = rect.right - width;
} else {
rect.top = index;
OS.SendMessage (handle, OS.LVM_GETSUBITEMRECT, -1, rect);
}
RECT area = new RECT ();
OS.GetClientRect (handle, area);
if (rect.left < area.left) {
int dx = rect.left - area.left;
OS.SendMessage (handle, OS.LVM_SCROLL, dx, 0);
} else {
int width = Math.min (area.right - area.left, rect.right - rect.left);
if (rect.left + width > area.right) {
int dx = rect.left + width - area.right;
OS.SendMessage (handle, OS.LVM_SCROLL, dx, 0);
}
}
}
void showItem (int index) {
/*
* Bug in Windows. For some reason, when there is insufficient space
* to show an item, LVM_ENSUREVISIBLE causes blank lines to be
* inserted at the top of the widget. A call to LVM_GETTOPINDEX will
* return a negative number (this is an impossible result). The fix
* is to use LVM_GETCOUNTPERPAGE to detect the case when the number
* of visible items is zero and use LVM_ENSUREVISIBLE with the fPartialOK
* flag to scroll the table.
*/
if (OS.SendMessage (handle, OS.LVM_GETCOUNTPERPAGE, 0, 0) <= 0) {
/*
* Bug in Windows. For some reason, LVM_ENSUREVISIBLE can
* scroll one item more or one item less when there is not
* enough space to show a single table item. The fix is
* to detect the case and call LVM_ENSUREVISIBLE again with
* the same arguments. It seems that once LVM_ENSUREVISIBLE
* has scrolled into the general area, it is able to scroll
* to the exact item.
*/
OS.SendMessage (handle, OS.LVM_ENSUREVISIBLE, index, 1);
if (index != OS.SendMessage (handle, OS.LVM_GETTOPINDEX, 0, 0)) {
OS.SendMessage (handle, OS.LVM_ENSUREVISIBLE, index, 1);
}
} else {
OS.SendMessage (handle, OS.LVM_ENSUREVISIBLE, index, 0);
}
}
/**
* Shows the item. If the item is already showing in the receiver,
* this method simply returns. Otherwise, the items are scrolled until
* the item is visible.
*
* @param item the item to be shown
*
* @exception IllegalArgumentException <ul>
* <li>ERROR_NULL_ARGUMENT - if the item is null</li>
* <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li>
* </ul>
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*
* @see Table#showSelection()
*/
public void showItem (TableItem item) {
checkWidget ();
if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
if (item.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
int index = indexOf (item);
if (index != -1) showItem (index);
}
/**
* Shows the selection. If the selection is already showing in the receiver,
* this method simply returns. Otherwise, the items are scrolled until
* the selection is visible.
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*
* @see Table#showItem(TableItem)
*/
public void showSelection () {
checkWidget ();
int index = OS.SendMessage (handle, OS.LVM_GETNEXTITEM, -1, OS.LVNI_SELECTED);
if (index != -1) showItem (index);
}
String toolTipText (NMTTDISPINFO hdr) {
int hwndToolTip = OS.SendMessage (handle, OS.LVM_GETTOOLTIPS, 0, 0);
if (hwndToolTip == hdr.hwndFrom && toolTipText != null) return ""; //$NON-NLS-1$
return super.toolTipText (hdr);
}
int widgetStyle () {
int bits = super.widgetStyle () | OS.LVS_SHAREIMAGELISTS | OS.WS_CLIPCHILDREN;
if ((style & SWT.HIDE_SELECTION) == 0) bits |= OS.LVS_SHOWSELALWAYS;
if ((style & SWT.SINGLE) != 0) bits |= OS.LVS_SINGLESEL;
/*
* This code is intentionally commented. In the future,
* the FLAT bit may be used to make the header flat and
* unresponsive to mouse clicks.
*/
// if ((style & SWT.FLAT) != 0) bits |= OS.LVS_NOSORTHEADER;
bits |= OS.LVS_REPORT | OS.LVS_NOCOLUMNHEADER;
if ((style & SWT.VIRTUAL) != 0) bits |= OS.LVS_OWNERDATA;
return bits;
}
TCHAR windowClass () {
return TableClass;
}
int windowProc () {
return TableProc;
}
LRESULT WM_ERASEBKGND (int wParam, int lParam) {
LRESULT result = super.WM_ERASEBKGND (wParam, lParam);
if (result != null) return result;
/*
* Feature in Windows. When WM_ERASEBKGND is called,
* it clears the damaged area by filling it with the
* background color. During WM_PAINT, when the table
* items are drawn, the background for each item is
* also drawn, causing flashing. The fix is to adjust
* the damage by subtracting the bounds of each visible
* table item.
*/
int itemCount = getItemCount ();
if (itemCount == 0) return result;
GCData data = new GCData();
data.device = display;
GC gc = GC.win32_new (wParam, data);
Region region = new Region (display);
gc.getClipping (region);
int columnCount = Math.max (1, getColumnCount ());
Rectangle clientArea = getClientArea ();
int i = getTopIndex ();
while (i < itemCount) {
int j = 0;
while (j < columnCount) {
if (j != 0 || (!isSelected (i) && i != getFocusIndex ())) {
RECT rect = new RECT ();
rect.top = j;
rect.left = OS.LVIR_LABEL;
OS.SendMessage (handle, OS. LVM_GETSUBITEMRECT, i, rect);
int width = Math.max (0, rect.right - rect.left);
int height = Math.max (0, rect.bottom - rect.top);
Rectangle rect2 = new Rectangle (rect.left, rect.top, width, height);
if (!rect2.intersects (clientArea)) break;
region.subtract (rect2);
}
j++;
}
if (j < columnCount) break;
i++;
}
gc.setClipping (region);
drawBackground (wParam);
gc.setClipping ((Region) null);
region.dispose ();
gc.dispose ();
return LRESULT.ONE;
}
LRESULT WM_GETOBJECT (int wParam, int lParam) {
/*
* Ensure that there is an accessible object created for this
* control because support for checked item accessibility is
* temporarily implemented in the accessibility package.
*/
if ((style & SWT.CHECK) != 0) {
if (accessible == null) accessible = new_Accessible (this);
}
return super.WM_GETOBJECT (wParam, lParam);
}
LRESULT WM_KEYDOWN (int wParam, int lParam) {
LRESULT result = super.WM_KEYDOWN (wParam, lParam);
if (result != null) return result;
if ((style & SWT.CHECK) != 0 && wParam == OS.VK_SPACE) {
int index = OS.SendMessage (handle, OS.LVM_GETNEXTITEM, -1, OS.LVNI_FOCUSED);
if (index != -1) {
TableItem item = _getItem (index);
item.setChecked (!item.getChecked (), true);
}
}
return result;
}
LRESULT WM_LBUTTONDBLCLK (int wParam, int lParam) {
/*
* Feature in Windows. When the user selects outside of
* a table item, Windows deselects all the items, even
* when the table is multi-select. While not strictly
* wrong, this is unexpected. The fix is to detect the
* case and avoid calling the window proc.
*/
LVHITTESTINFO pinfo = new LVHITTESTINFO ();
pinfo.x = (short) (lParam & 0xFFFF);
pinfo.y = (short) (lParam >> 16);
OS.SendMessage (handle, OS.LVM_HITTEST, 0, pinfo);
sendMouseEvent (SWT.MouseDown, 1, OS.WM_LBUTTONDOWN, wParam, lParam);
sendMouseEvent (SWT.MouseDoubleClick, 1, OS.WM_LBUTTONDBLCLK, wParam, lParam);
if (pinfo.iItem != -1) callWindowProc (OS.WM_LBUTTONDBLCLK, wParam, lParam);
if (OS.GetCapture () != handle) OS.SetCapture (handle);
return LRESULT.ZERO;
}
LRESULT WM_LBUTTONDOWN (int wParam, int lParam) {
mouseDown = true;
/*
* Feature in Windows. For some reason, capturing
* the mouse after processing the mouse event for the
* widget interferes with the normal mouse processing
* for the widget. The fix is to avoid the automatic
* mouse capture.
*/
LRESULT result = sendMouseDownEvent (SWT.MouseDown, 1, OS.WM_LBUTTONDOWN, wParam, lParam);
/* Look for check/uncheck */
if ((style & SWT.CHECK) != 0) {
LVHITTESTINFO pinfo = new LVHITTESTINFO ();
pinfo.x = (short) (lParam & 0xFFFF);
pinfo.y = (short) (lParam >> 16);
/*
* Note that when the table has LVS_EX_FULLROWSELECT and the
* user clicks anywhere on a row except on the check box, all
* of the bits are set. The hit test flags are LVHT_ONITEM.
* This means that a bit test for LVHT_ONITEMSTATEICON is not
* the correct way to determine that the user has selected
* the check box.
*/
int index = OS.SendMessage (handle, OS.LVM_HITTEST, 0, pinfo);
if (index != -1 && pinfo.flags == OS.LVHT_ONITEMSTATEICON) {
TableItem item = _getItem (index);
item.setChecked (!item.getChecked (), true);
}
}
return result;
}
LRESULT WM_LBUTTONUP (int wParam, int lParam) {
mouseDown = false;
return super.WM_LBUTTONUP (wParam, lParam);
}
LRESULT WM_MOUSEHOVER (int wParam, int lParam) {
/*
* Feature in Windows. Despite the fact that hot
* tracking is not enabled, the hot tracking code
* in WM_MOUSEHOVER is executed causing the item
* under the cursor to be selected. The fix is to
* avoid calling the window proc.
*/
LRESULT result = super.WM_MOUSEHOVER (wParam, lParam);
int bits = OS.SendMessage (handle, OS.LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
int mask = OS.LVS_EX_ONECLICKACTIVATE | OS.LVS_EX_TRACKSELECT | OS.LVS_EX_TWOCLICKACTIVATE;
if ((bits & mask) != 0) return result;
return LRESULT.ZERO;
}
LRESULT WM_PAINT (int wParam, int lParam) {
/* Resize the item array to match the item count */
int count = OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
if (items.length > 4 && items.length - count > 3) {
TableItem [] newItems = new TableItem [(count + 3) / 4 * 4];
System.arraycopy (items, 0, newItems, 0, count);
items = newItems;
}
if (fixScrollWidth) setScrollWidth (null, true);
return super.WM_PAINT (wParam, lParam);
}
LRESULT WM_NOTIFY (int wParam, int lParam) {
NMHDR hdr = new NMHDR ();
OS.MoveMemory (hdr, lParam, NMHDR.sizeof);
int hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
if (hdr.hwndFrom == hwndHeader) {
/*
* Feature in Windows. On NT, the automatically created
* header control is created as a UNICODE window, not an
* ANSI window despite the fact that the parent is created
* as an ANSI window. This means that it sends UNICODE
* notification messages to the parent window on NT for
* no good reason. The data and size in the NMHEADER and
* HDITEM structs is identical between the platforms so no
* different message is actually necessary. Despite this,
* Windows sends different messages. The fix is to look
* for both messages, despite the platform. This works
* because only one will be sent on either platform, never
* both.
*/
switch (hdr.code) {
case OS.HDN_BEGINTRACKW:
case OS.HDN_BEGINTRACKA:
case OS.HDN_DIVIDERDBLCLICKW:
case OS.HDN_DIVIDERDBLCLICKA:{
NMHEADER phdn = new NMHEADER ();
OS.MoveMemory (phdn, lParam, NMHEADER.sizeof);
TableColumn column = columns [phdn.iItem];
if (column != null && !column.getResizable ()) {
return LRESULT.ONE;
}
break;
}
case OS.HDN_ITEMCHANGEDW:
case OS.HDN_ITEMCHANGEDA: {
/*
* Bug in Windows. When a table has the LVS_EX_GRIDLINES extended
* style and the user drags any column over the first column in the
* table, making the size become zero, when the user drags a column
* such that the size of the first column becomes non-zero, the grid
* lines are not redrawn. The fix is to detect the case and force
* a redraw of the first column.
*/
int width = OS.SendMessage (handle, OS.LVM_GETCOLUMNWIDTH, 0, 0);
if (lastWidth == 0 && width > 0) {
int bits = OS.SendMessage (handle, OS.LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
if ((bits & OS.LVS_EX_GRIDLINES) != 0) {
RECT rect = new RECT ();
OS.GetClientRect (handle, rect);
rect.right = rect.left + width;
OS.InvalidateRect (handle, rect, true);
}
}
lastWidth = width;
NMHEADER phdn = new NMHEADER ();
OS.MoveMemory (phdn, lParam, NMHEADER.sizeof);
if (phdn.pitem != 0) {
HDITEM pitem = new HDITEM ();
OS.MoveMemory (pitem, phdn.pitem, HDITEM.sizeof);
if ((pitem.mask & OS.HDI_WIDTH) != 0) {
TableColumn column = columns [phdn.iItem];
if (column != null) {
column.sendEvent (SWT.Resize);
/*
* It is possible (but unlikely), that application
* code could have disposed the widget in the resize
* event. If this happens, end the processing of the
* Windows message by returning zero as the result of
* the window proc.
*/
if (isDisposed ()) return LRESULT.ZERO;
int count = OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0);
if (count == 1 && columns [0] == null) count = 0;
/*
* It is possible (but unlikely), that application
* code could have disposed the column in the move
* event. If this happens, process the move event
* for those columns that have not been destroyed.
*/
TableColumn [] newColumns = new TableColumn [count];
System.arraycopy (columns, 0, newColumns, 0, count);
for (int i=phdn.iItem+1; i<count; i++) {
if (!newColumns [i].isDisposed ()) {
newColumns [i].sendEvent (SWT.Move);
}
}
}
}
}
break;
}
case OS.HDN_ITEMDBLCLICKW:
case OS.HDN_ITEMDBLCLICKA: {
NMHEADER phdn = new NMHEADER ();
OS.MoveMemory (phdn, lParam, NMHEADER.sizeof);
TableColumn column = columns [phdn.iItem];
if (column != null) {
column.postEvent (SWT.DefaultSelection);
}
break;
}
}
}
return super.WM_NOTIFY (wParam, lParam);
}
LRESULT WM_RBUTTONDBLCLK (int wParam, int lParam) {
/*
* Feature in Windows. When the user selects outside of
* a table item, Windows deselects all the items, even
* when the table is multi-select. While not strictly
* wrong, this is unexpected. The fix is to detect the
* case and avoid calling the window proc.
*/
LVHITTESTINFO pinfo = new LVHITTESTINFO ();
pinfo.x = (short) (lParam & 0xFFFF);
pinfo.y = (short) (lParam >> 16);
OS.SendMessage (handle, OS.LVM_HITTEST, 0, pinfo);
sendMouseEvent (SWT.MouseDown, 1, OS.WM_RBUTTONDOWN, wParam, lParam);
sendMouseEvent (SWT.MouseDoubleClick, 1, OS.WM_RBUTTONDBLCLK, wParam, lParam);
if (pinfo.iItem != -1) callWindowProc (OS.WM_RBUTTONDBLCLK, wParam, lParam);
if (OS.GetCapture () != handle) OS.SetCapture (handle);
return LRESULT.ZERO;
}
LRESULT WM_RBUTTONDOWN (int wParam, int lParam) {
/*
* Feature in Windows. For some reason, capturing
* the mouse after processing the mouse event for the
* widget interferes with the normal mouse processing
* for the widget. The fix is to avoid the automatic
* mouse capture.
*/
return sendMouseDownEvent (SWT.MouseDown, 3, OS.WM_RBUTTONDOWN, wParam, lParam);
}
LRESULT WM_SETFOCUS (int wParam, int lParam) {
LRESULT result = super.WM_SETFOCUS (wParam, lParam);
/*
* Bug in Windows. For some reason, the table does
* not set the default focus rectangle to be the first
* item in the table when it gets focus and there is
* no selected item. The fix to make the first item
* be the focus item.
*/
int count = OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
if (count == 0) return result;
int index = OS.SendMessage (handle, OS.LVM_GETNEXTITEM, -1, OS.LVNI_FOCUSED);
if (index == -1) {
LVITEM lvItem = new LVITEM ();
lvItem.state = OS.LVIS_FOCUSED;
lvItem.stateMask = OS.LVIS_FOCUSED;
ignoreSelect = true;
OS.SendMessage (handle, OS.LVM_SETITEMSTATE, 0, lvItem);
ignoreSelect = false;
}
return result;
}
LRESULT WM_SIZE (int wParam, int lParam) {
if (ignoreResize) {
ignoreResize = false;
int code = callWindowProc (OS.WM_SIZE, wParam, lParam);
return new LRESULT (code);
}
return super.WM_SIZE (wParam, lParam);
}
LRESULT WM_SYSCOLORCHANGE (int wParam, int lParam) {
LRESULT result = super.WM_SYSCOLORCHANGE (wParam, lParam);
if (result != null) return result;
if ((style & SWT.CHECK) != 0) setCheckboxImageListColor ();
return result;
}
LRESULT wmNotifyChild (int wParam, int lParam) {
NMHDR hdr = new NMHDR ();
OS.MoveMemory (hdr, lParam, NMHDR.sizeof);
switch (hdr.code) {
case OS.LVN_ODFINDITEMA:
case OS.LVN_ODFINDITEMW: {
if ((style & SWT.VIRTUAL) != 0) {
NMLVFINDITEM pnmfi = new NMLVFINDITEM ();
OS.MoveMemory (pnmfi, lParam, NMLVFINDITEM.sizeof);
int index = Math.max (0, pnmfi.iStart - 1);
return new LRESULT (index);
}
break;
}
case OS.LVN_GETDISPINFOA:
case OS.LVN_GETDISPINFOW: {
NMLVDISPINFO plvfi = new NMLVDISPINFO ();
OS.MoveMemory (plvfi, lParam, NMLVDISPINFO.sizeof);
lastIndexOf = plvfi.iItem;
TableItem item = _getItem (plvfi.iItem);
if (!item.cached) {
if ((style & SWT.VIRTUAL) != 0) {
Event event = new Event ();
event.item = item;
ignoreRedraw = true;
sendEvent (SWT.SetData, event);
//widget could be disposed at this point
if (isDisposed ()) break;
ignoreRedraw = false;
TableItem newItem = fixScrollWidth ? null : item;
if (setScrollWidth (newItem, true)) redraw ();
}
item.cached = true;
}
if ((plvfi.mask & OS.LVIF_TEXT) != 0) {
String string = null;
if (plvfi.iSubItem == 0) {
string = item.text;
} else {
String [] strings = item.strings;
if (strings != null) string = strings [plvfi.iSubItem];
}
if (string != null) {
TCHAR buffer = new TCHAR (getCodePage (), string, false);
int byteCount = Math.min (buffer.length (), plvfi.cchTextMax - 1) * TCHAR.sizeof;
OS.MoveMemory (plvfi.pszText, buffer, byteCount);
OS.MoveMemory (plvfi.pszText + byteCount, new byte [TCHAR.sizeof], TCHAR.sizeof);
plvfi.cchTextMax = Math.min (plvfi.cchTextMax, string.length () + 1);
}
}
if ((plvfi.mask & OS.LVIF_IMAGE) != 0) {
Image image = null;
if (plvfi.iSubItem == 0) {
image = item.image;
} else {
Image [] images = item.images;
if (images != null) image = images [plvfi.iSubItem];
}
if (image != null) plvfi.iImage = imageIndex (image);
}
if ((plvfi.mask & OS.LVIF_STATE) != 0) {
if (plvfi.iSubItem == 0) {
int state = 1;
if (item.checked) state++;
if (item.grayed) state +=2;
plvfi.state = state << 12;
plvfi.stateMask = OS.LVIS_STATEIMAGEMASK;
}
}
if ((plvfi.mask & OS.LVIF_INDENT) != 0) {
if (plvfi.iSubItem == 0) plvfi.iIndent = item.imageIndent;
}
OS.MoveMemory (lParam, plvfi, NMLVDISPINFO.sizeof);
break;
}
case OS.NM_CUSTOMDRAW: {
if (!customDraw) break;
NMLVCUSTOMDRAW nmcd = new NMLVCUSTOMDRAW ();
OS.MoveMemory (nmcd, lParam, NMLVCUSTOMDRAW.sizeof);
switch (nmcd.dwDrawStage) {
case OS.CDDS_PREPAINT: return new LRESULT (OS.CDRF_NOTIFYITEMDRAW);
case OS.CDDS_ITEMPREPAINT: return new LRESULT (OS.CDRF_NOTIFYSUBITEMDRAW);
case OS.CDDS_ITEMPREPAINT | OS.CDDS_SUBITEM: {
TableItem item = _getItem (nmcd.dwItemSpec);
int hFont = item.cellFont != null ? item.cellFont [nmcd.iSubItem] : -1;
if (hFont == -1) hFont = item.font;
int clrText = item.cellForeground != null ? item.cellForeground [nmcd.iSubItem] : -1;
if (clrText == -1) clrText = item.foreground;
int clrTextBk = item.cellBackground != null ? item.cellBackground [nmcd.iSubItem] : -1;
if (clrTextBk == -1) clrTextBk = item.background;
if (hFont == -1 && clrText == -1 && clrTextBk == -1) {
if (item.cellForeground == null && item.cellBackground == null && item.cellFont == null) {
break;
}
}
if (hFont != -1) OS.SelectObject(nmcd.hdc, hFont);
nmcd.clrText = clrText == -1 ? getForegroundPixel () : clrText;
nmcd.clrTextBk = clrTextBk == -1 ? getBackgroundPixel () : clrTextBk;
OS.MoveMemory (lParam, nmcd, NMLVCUSTOMDRAW.sizeof);
return new LRESULT (OS.CDRF_NEWFONT);
}
}
break;
}
case OS.LVN_MARQUEEBEGIN: return LRESULT.ONE;
case OS.LVN_BEGINDRAG:
case OS.LVN_BEGINRDRAG: {
dragStarted = true;
if (hdr.code == OS.LVN_BEGINDRAG) {
int pos = OS.GetMessagePos ();
POINT pt = new POINT ();
pt.x = (short) (pos & 0xFFFF);
pt.y = (short) (pos >> 16);
OS.ScreenToClient (handle, pt);
Event event = new Event ();
event.x = pt.x;
event.y = pt.y;
postEvent (SWT.DragDetect, event);
}
break;
}
case OS.LVN_COLUMNCLICK: {
NMLISTVIEW pnmlv = new NMLISTVIEW ();
OS.MoveMemory(pnmlv, lParam, NMLISTVIEW.sizeof);
TableColumn column = columns [pnmlv.iSubItem];
if (column != null) {
column.postEvent (SWT.Selection);
}
break;
}
case OS.LVN_ITEMACTIVATE: {
NMLISTVIEW pnmlv = new NMLISTVIEW ();
OS.MoveMemory(pnmlv, lParam, NMLISTVIEW.sizeof);
if (pnmlv.iItem != -1) {
Event event = new Event ();
event.item = _getItem (pnmlv.iItem);
postEvent (SWT.DefaultSelection, event);
}
break;
}
case OS.LVN_ITEMCHANGED: {
if (!ignoreSelect) {
NMLISTVIEW pnmlv = new NMLISTVIEW ();
OS.MoveMemory (pnmlv, lParam, NMLISTVIEW.sizeof);
if (pnmlv.iItem != -1 && (pnmlv.uChanged & OS.LVIF_STATE) != 0) {
boolean isFocus = (pnmlv.uNewState & OS.LVIS_FOCUSED) != 0;
int index = OS.SendMessage (handle, OS.LVM_GETNEXTITEM, -1, OS.LVNI_FOCUSED);
if ((style & SWT.MULTI) != 0) {
if (OS.GetKeyState (OS.VK_CONTROL) < 0) {
if (!isFocus) {
if (index == pnmlv.iItem) {
boolean isSelected = (pnmlv.uNewState & OS.LVIS_SELECTED) != 0;
boolean wasSelected = (pnmlv.uOldState & OS.LVIS_SELECTED) != 0;
isFocus = isSelected != wasSelected;
}
} else {
isFocus = mouseDown;
}
}
}
if (OS.GetKeyState (OS.VK_SPACE) < 0) isFocus = true;
if (isFocus) {
Event event = new Event();
if (index != -1) {
/*
* This code is intentionally commented.
*/
// OS.SendMessage (handle, OS.LVM_ENSUREVISIBLE, index, 0);
event.item = _getItem (index);
}
postEvent (SWT.Selection, event);
}
}
}
break;
}
case OS.NM_RECOGNIZEGESTURE:
/*
* Feature on Pocket PC. The tree and table controls detect the tap
* and hold gesture by default. They send a GN_CONTEXTMENU message to show
* the popup menu. This default behaviour is unwanted on Pocket PC 2002
* when no menu has been set, as it still draws a red circle. The fix
* is to disable this default behaviour when no menu is set by returning
* TRUE when receiving the Pocket PC 2002 specific NM_RECOGNIZEGESTURE
* message.
*/
if (OS.IsPPC) {
boolean hasMenu = menu != null && !menu.isDisposed ();
if (!hasMenu && !hooks (SWT.MenuDetect)) return LRESULT.ONE;
}
break;
case OS.GN_CONTEXTMENU:
if (OS.IsPPC) {
boolean hasMenu = menu != null && !menu.isDisposed ();
if (hasMenu || hooks (SWT.MenuDetect)) {
NMRGINFO nmrg = new NMRGINFO ();
OS.MoveMemory (nmrg, lParam, NMRGINFO.sizeof);
showMenu (nmrg.x, nmrg.y);
return LRESULT.ONE;
}
}
break;
}
return super.wmNotifyChild (wParam, lParam);
}
}
|