1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <limits.h>
#include <tools/debug.hxx>
#include <vcl/wall.hxx>
#include <vcl/help.hxx>
#include <vcl/decoview.hxx>
#include <vcl/svapp.hxx>
#include <tools/poly.hxx>
#include <vcl/lineinfo.hxx>
#include <vcl/i18nhelp.hxx>
#include <vcl/mnemonic.hxx>
#include <vcl/controllayout.hxx>
#include <vcl/settings.hxx>
#include <svtools/ivctrl.hxx>
#include "imivctl.hxx"
#include <svtools/svmedit.hxx>
#include <algorithm>
#include <boost/scoped_ptr.hpp>
#include <vcl/idle.hxx>
#define IMPICNVIEW_ACC_RETURN 1
#define IMPICNVIEW_ACC_ESCAPE 2
#define DRAWTEXT_FLAGS_ICON \
( TEXT_DRAW_CENTER | TEXT_DRAW_TOP | TEXT_DRAW_ENDELLIPSIS | \
TEXT_DRAW_CLIP | TEXT_DRAW_MULTILINE | TEXT_DRAW_WORDBREAK | TEXT_DRAW_MNEMONIC )
#define DRAWTEXT_FLAGS_SMALLICON (TEXT_DRAW_LEFT|TEXT_DRAW_ENDELLIPSIS|TEXT_DRAW_CLIP)
#define EVENTID_SHOW_CURSOR (reinterpret_cast<void*>(1))
#define EVENTID_ADJUST_SCROLLBARS (reinterpret_cast<void*>(2))
static bool bEndScrollInvalidate = true;
class IcnViewEdit_Impl : public MultiLineEdit
{
Link aCallBackHdl;
Accelerator aAccReturn;
Accelerator aAccEscape;
Idle aIdle;
bool bCanceled;
bool bAlreadyInCallback;
bool bGrabFocus;
void CallCallBackHdl_Impl();
DECL_LINK(Timeout_Impl, void *);
DECL_LINK( ReturnHdl_Impl, Accelerator * );
DECL_LINK( EscapeHdl_Impl, Accelerator * );
public:
IcnViewEdit_Impl(
SvtIconChoiceCtrl* pParent,
const Point& rPos,
const Size& rSize,
const OUString& rData,
const Link& rNotifyEditEnd );
virtual ~IcnViewEdit_Impl();
virtual void KeyInput( const KeyEvent& rKEvt ) SAL_OVERRIDE;
virtual bool PreNotify( NotifyEvent& rNEvt ) SAL_OVERRIDE;
bool EditingCanceled() const { return bCanceled; }
void StopEditing( bool bCancel = false );
bool IsGrabFocus() const { return bGrabFocus; }
};
SvxIconChoiceCtrl_Impl::SvxIconChoiceCtrl_Impl(
SvtIconChoiceCtrl* pCurView,
WinBits nWinStyle
) :
aEntries( this ),
aVerSBar( pCurView, WB_DRAG | WB_VSCROLL ),
aHorSBar( pCurView, WB_DRAG | WB_HSCROLL ),
aScrBarBox( pCurView ),
aImageSize( 32, 32 ),
pColumns( 0 )
{
bChooseWithCursor = false;
pEntryPaintDev = 0;
pCurEditedEntry = 0;
pCurHighlightFrame = 0;
pEdit = 0;
pAnchor = 0;
pPrevDropTarget = 0;
pHdlEntry = 0;
pHead = NULL;
pCursor = NULL;
bUpdateMode = true;
bEntryEditingEnabled = false;
bHighlightFramePressed = false;
eSelectionMode = MULTIPLE_SELECTION;
pView = pCurView;
pZOrderList = new SvxIconChoiceCtrlEntryList_impl();
ePositionMode = IcnViewPositionModeFree;
SetStyle( nWinStyle );
nFlags = 0;
nUserEventAdjustScrBars = 0;
nUserEventShowCursor = 0;
nMaxVirtWidth = DEFAULT_MAX_VIRT_WIDTH;
nMaxVirtHeight = DEFAULT_MAX_VIRT_HEIGHT;
pDDRefEntry = 0;
pDDDev = 0;
pDDBufDev = 0;
pDDTempDev = 0;
eTextMode = IcnShowTextShort;
pImpCursor = new IcnCursor_Impl( this );
pGridMap = new IcnGridMap_Impl( this );
aVerSBar.SetScrollHdl( LINK( this, SvxIconChoiceCtrl_Impl, ScrollUpDownHdl ) );
aHorSBar.SetScrollHdl( LINK( this, SvxIconChoiceCtrl_Impl, ScrollLeftRightHdl ) );
Link aEndScrollHdl( LINK( this, SvxIconChoiceCtrl_Impl, EndScrollHdl ) );
aVerSBar.SetEndScrollHdl( aEndScrollHdl );
aHorSBar.SetEndScrollHdl( aEndScrollHdl );
nHorSBarHeight = aHorSBar.GetSizePixel().Height();
nVerSBarWidth = aVerSBar.GetSizePixel().Width();
aEditIdle.SetPriority( IdlePriority::VCL_IDLE_PRIORITY_LOWEST );
aEditIdle.SetIdleHdl(LINK(this,SvxIconChoiceCtrl_Impl,EditTimeoutHdl));
aAutoArrangeIdle.SetPriority( IdlePriority::VCL_IDLE_PRIORITY_LOW );
aAutoArrangeIdle.SetIdleHdl(LINK(this,SvxIconChoiceCtrl_Impl,AutoArrangeHdl));
aCallSelectHdlIdle.SetPriority( IdlePriority::VCL_IDLE_PRIORITY_LOWEST );
aCallSelectHdlIdle.SetIdleHdl( LINK(this,SvxIconChoiceCtrl_Impl,CallSelectHdlHdl));
aDocRectChangedIdle.SetPriority( IdlePriority::VCL_IDLE_PRIORITY_MEDIUM );
aDocRectChangedIdle.SetIdleHdl(LINK(this,SvxIconChoiceCtrl_Impl,DocRectChangedHdl));
aVisRectChangedIdle.SetPriority( IdlePriority::VCL_IDLE_PRIORITY_MEDIUM );
aVisRectChangedIdle.SetIdleHdl(LINK(this,SvxIconChoiceCtrl_Impl,VisRectChangedHdl));
Clear( true );
SetGrid( Size(100, 70) );
}
SvxIconChoiceCtrl_Impl::~SvxIconChoiceCtrl_Impl()
{
pCurEditedEntry = 0;
DELETEZ(pEdit);
Clear();
StopEditTimer();
CancelUserEvents();
delete pZOrderList;
delete pImpCursor;
delete pGridMap;
delete pDDDev;
delete pDDBufDev;
delete pDDTempDev;
delete pEntryPaintDev;
ClearSelectedRectList();
ClearColumnList();
}
void SvxIconChoiceCtrl_Impl::Clear( bool bInCtor )
{
StopEntryEditing( true );
nSelectionCount = 0;
pCurHighlightFrame = 0;
StopEditTimer();
CancelUserEvents();
ShowCursor( false );
bBoundRectsDirty = false;
nMaxBoundHeight = 0;
nFlags &= ~(F_PAINTED | F_MOVED_ENTRIES);
pCursor = 0;
if( !bInCtor )
{
pImpCursor->Clear();
pGridMap->Clear();
aVirtOutputSize.Width() = 0;
aVirtOutputSize.Height() = 0;
Size aSize( pView->GetOutputSizePixel() );
nMaxVirtWidth = aSize.Width() - nVerSBarWidth;
if( nMaxVirtWidth <= 0 )
nMaxVirtWidth = DEFAULT_MAX_VIRT_WIDTH;
nMaxVirtHeight = aSize.Height() - nHorSBarHeight;
if( nMaxVirtHeight <= 0 )
nMaxVirtHeight = DEFAULT_MAX_VIRT_HEIGHT;
pZOrderList->clear();
SetOrigin( Point() );
if( bUpdateMode )
pView->Invalidate(INVALIDATE_NOCHILDREN);
}
AdjustScrollBars();
size_t nCount = aEntries.size();
for( size_t nCur = 0; nCur < nCount; nCur++ )
{
SvxIconChoiceCtrlEntry* pCur = aEntries[ nCur ];
delete pCur;
}
aEntries.clear();
DocRectChanged();
VisRectChanged();
}
void SvxIconChoiceCtrl_Impl::SetStyle( WinBits nWinStyle )
{
nWinBits = nWinStyle;
nCurTextDrawFlags = DRAWTEXT_FLAGS_ICON;
if( nWinBits & (WB_SMALLICON | WB_DETAILS) )
nCurTextDrawFlags = DRAWTEXT_FLAGS_SMALLICON;
if( nWinBits & WB_NOSELECTION )
eSelectionMode = NO_SELECTION;
if( !(nWinStyle & (WB_ALIGN_TOP | WB_ALIGN_LEFT)))
nWinBits |= WB_ALIGN_LEFT;
if( (nWinStyle & WB_DETAILS))
{
if( !pColumns )
SetColumn( 0, SvxIconChoiceCtrlColumnInfo( 0, 100, IcnViewAlignLeft ));
}
}
IMPL_LINK( SvxIconChoiceCtrl_Impl, ScrollUpDownHdl, ScrollBar*, pScrollBar )
{
StopEntryEditing( true );
// arrow up: delta=-1; arrow down: delta=+1
Scroll( 0, pScrollBar->GetDelta(), true );
bEndScrollInvalidate = true;
return 0;
}
IMPL_LINK( SvxIconChoiceCtrl_Impl, ScrollLeftRightHdl, ScrollBar*, pScrollBar )
{
StopEntryEditing( true );
// arrow left: delta=-1; arrow right: delta=+1
Scroll( pScrollBar->GetDelta(), 0, true );
bEndScrollInvalidate = true;
return 0;
}
IMPL_LINK_NOARG(SvxIconChoiceCtrl_Impl, EndScrollHdl)
{
if( pView->HasBackground() && !pView->GetBackground().IsScrollable() &&
bEndScrollInvalidate )
{
pView->Invalidate(INVALIDATE_NOCHILDREN);
}
return 0;
}
void SvxIconChoiceCtrl_Impl::FontModified()
{
StopEditTimer();
DELETEZ(pDDDev);
DELETEZ(pDDBufDev);
DELETEZ(pDDTempDev);
DELETEZ(pEntryPaintDev);
SetDefaultTextSize();
ShowCursor( false );
ShowCursor( true );
}
void SvxIconChoiceCtrl_Impl::InsertEntry( SvxIconChoiceCtrlEntry* pEntry, size_t nPos,
const Point* pPos )
{
StopEditTimer();
aEntries.insert( nPos, pEntry );
if( (nFlags & F_ENTRYLISTPOS_VALID) && nPos >= aEntries.size() - 1 )
pEntry->nPos = aEntries.size() - 1;
else
nFlags &= ~F_ENTRYLISTPOS_VALID;
pZOrderList->push_back( pEntry );
pImpCursor->Clear();
if( pPos )
{
Size aSize( CalcBoundingSize( pEntry ) );
SetBoundingRect_Impl( pEntry, *pPos, aSize );
SetEntryPos( pEntry, *pPos, false, true, true /*keep grid map*/ );
pEntry->nFlags |= ICNVIEW_FLAG_POS_MOVED;
SetEntriesMoved( true );
}
else
{
// If the UpdateMode is true, don't set all bounding rectangles to
// 'to be checked', but only the bounding rectangle of the new entry.
// Thus, don't call InvalidateBoundingRect!
pEntry->aRect.Right() = LONG_MAX;
if( bUpdateMode )
{
FindBoundingRect( pEntry );
Rectangle aOutputArea( GetOutputRect() );
pGridMap->OccupyGrids( pEntry );
if( !aOutputArea.IsOver( pEntry->aRect ) )
return; // is invisible
pView->Invalidate( pEntry->aRect );
}
else
InvalidateBoundingRect( pEntry->aRect );
}
}
void SvxIconChoiceCtrl_Impl::CreateAutoMnemonics( MnemonicGenerator* _pGenerator )
{
boost::scoped_ptr< MnemonicGenerator > pAutoDeleteOwnGenerator;
if ( !_pGenerator )
{
_pGenerator = new MnemonicGenerator;
pAutoDeleteOwnGenerator.reset( _pGenerator );
}
sal_uLong nEntryCount = GetEntryCount();
sal_uLong i;
// insert texts in generator
for( i = 0; i < nEntryCount; ++i )
{
DBG_ASSERT( GetEntry( i ), "-SvxIconChoiceCtrl_Impl::CreateAutoMnemonics(): more expected than provided!" );
_pGenerator->RegisterMnemonic( GetEntry( i )->GetText() );
}
// exchange texts with generated mnemonics
for( i = 0; i < nEntryCount; ++i )
{
SvxIconChoiceCtrlEntry* pEntry = GetEntry( i );
OUString aTxt = pEntry->GetText();
OUString aNewText = _pGenerator->CreateMnemonic( aTxt );
if( aNewText != aTxt )
pEntry->SetText( aNewText );
}
}
Rectangle SvxIconChoiceCtrl_Impl::GetOutputRect() const
{
Point aOrigin( pView->GetMapMode().GetOrigin() );
aOrigin *= -1;
return Rectangle( aOrigin, aOutputSize );
}
void SvxIconChoiceCtrl_Impl::SetListPositions()
{
if( nFlags & F_ENTRYLISTPOS_VALID )
return;
size_t nCount = aEntries.size();
for( size_t nCur = 0; nCur < nCount; nCur++ )
{
SvxIconChoiceCtrlEntry* pEntry = aEntries[ nCur ];
pEntry->nPos = nCur;
}
nFlags |= F_ENTRYLISTPOS_VALID;
}
void SvxIconChoiceCtrl_Impl::SelectEntry( SvxIconChoiceCtrlEntry* pEntry, bool bSelect,
bool bCallHdl, bool bAdd, bool bSyncPaint )
{
if( eSelectionMode == NO_SELECTION )
return;
if( !bAdd )
{
if ( 0 == ( nFlags & F_CLEARING_SELECTION ) )
{
nFlags |= F_CLEARING_SELECTION;
DeselectAllBut( pEntry, true );
nFlags &= ~F_CLEARING_SELECTION;
}
}
if( pEntry->IsSelected() != bSelect )
{
pHdlEntry = pEntry;
sal_uInt16 nEntryFlags = pEntry->GetFlags();
if( bSelect )
{
nEntryFlags |= ICNVIEW_FLAG_SELECTED;
pEntry->AssignFlags( nEntryFlags );
nSelectionCount++;
if( bCallHdl )
CallSelectHandler( pEntry );
}
else
{
nEntryFlags &= ~( ICNVIEW_FLAG_SELECTED);
pEntry->AssignFlags( nEntryFlags );
nSelectionCount--;
if( bCallHdl )
CallSelectHandler( 0 );
}
EntrySelected( pEntry, bSelect, bSyncPaint );
}
}
void SvxIconChoiceCtrl_Impl::EntrySelected( SvxIconChoiceCtrlEntry* pEntry, bool bSelect,
bool bSyncPaint )
{
// When using SingleSelection, make sure that the cursor is always placed
// over the (only) selected entry. (But only if a cursor exists.)
if( bSelect && pCursor &&
eSelectionMode == SINGLE_SELECTION &&
pEntry != pCursor )
{
SetCursor( pEntry );
//DBG_ASSERT(pView->GetSelectionCount()==1,"selection count?")
}
// Not when dragging though, else the loop in SelectRect doesn't work
// correctly!
if( !(nFlags & F_SELECTING_RECT) )
ToTop( pEntry );
if( bUpdateMode )
{
if( pEntry == pCursor )
ShowCursor( false );
if( pView->IsTracking() && (bSelect || !pView->HasBackground()) ) // always synchronous when tracking
PaintEntry( pEntry );
else if( bSyncPaint ) // synchronous & with a virtual OutDev!
PaintEntryVirtOutDev( pEntry );
else
{
pView->Invalidate( CalcFocusRect( pEntry ) );
}
if( pEntry == pCursor )
ShowCursor( true );
}
// #i101012# emit vcl event LISTBOX_SELECT only in case that the given entry is selected.
if ( bSelect )
{
CallEventListeners( VCLEVENT_LISTBOX_SELECT, pEntry );
}
}
void SvxIconChoiceCtrl_Impl::ResetVirtSize()
{
StopEditTimer();
aVirtOutputSize.Width() = 0;
aVirtOutputSize.Height() = 0;
const size_t nCount = aEntries.size();
for( size_t nCur = 0; nCur < nCount; nCur++ )
{
SvxIconChoiceCtrlEntry* pCur = aEntries[ nCur ];
pCur->ClearFlags( ICNVIEW_FLAG_POS_MOVED );
if( pCur->IsPosLocked() )
{
// adapt (among others) VirtSize
if( !IsBoundingRectValid( pCur->aRect ) )
FindBoundingRect( pCur );
else
AdjustVirtSize( pCur->aRect );
}
else
InvalidateBoundingRect( pCur->aRect );
}
if( !(nWinBits & (WB_NOVSCROLL | WB_NOHSCROLL)) )
{
Size aRealOutputSize( pView->GetOutputSizePixel() );
if( aVirtOutputSize.Width() < aRealOutputSize.Width() ||
aVirtOutputSize.Height() < aRealOutputSize.Height() )
{
sal_uLong nGridCount = IcnGridMap_Impl::GetGridCount(
aRealOutputSize, (sal_uInt16)nGridDX, (sal_uInt16)nGridDY );
if( nGridCount < nCount )
{
if( nWinBits & WB_ALIGN_TOP )
nMaxVirtWidth = aRealOutputSize.Width() - nVerSBarWidth;
else // WB_ALIGN_LEFT
nMaxVirtHeight = aRealOutputSize.Height() - nHorSBarHeight;
}
}
}
pImpCursor->Clear();
pGridMap->Clear();
VisRectChanged();
}
void SvxIconChoiceCtrl_Impl::AdjustVirtSize( const Rectangle& rRect )
{
long nHeightOffs = 0;
long nWidthOffs = 0;
if( aVirtOutputSize.Width() < (rRect.Right()+LROFFS_WINBORDER) )
nWidthOffs = (rRect.Right()+LROFFS_WINBORDER) - aVirtOutputSize.Width();
if( aVirtOutputSize.Height() < (rRect.Bottom()+TBOFFS_WINBORDER) )
nHeightOffs = (rRect.Bottom()+TBOFFS_WINBORDER) - aVirtOutputSize.Height();
if( nWidthOffs || nHeightOffs )
{
Range aRange;
aVirtOutputSize.Width() += nWidthOffs;
aRange.Max() = aVirtOutputSize.Width();
aHorSBar.SetRange( aRange );
aVirtOutputSize.Height() += nHeightOffs;
aRange.Max() = aVirtOutputSize.Height();
aVerSBar.SetRange( aRange );
pImpCursor->Clear();
pGridMap->OutputSizeChanged();
AdjustScrollBars();
DocRectChanged();
}
}
void SvxIconChoiceCtrl_Impl::InitPredecessors()
{
DBG_ASSERT(!pHead,"SvxIconChoiceCtrl_Impl::InitPredecessors() >> Already initialized");
size_t nCount = aEntries.size();
if( nCount )
{
SvxIconChoiceCtrlEntry* pPrev = aEntries[ 0 ];
for( size_t nCur = 1; nCur <= nCount; nCur++ )
{
pPrev->ClearFlags( ICNVIEW_FLAG_POS_LOCKED | ICNVIEW_FLAG_POS_MOVED |
ICNVIEW_FLAG_PRED_SET);
SvxIconChoiceCtrlEntry* pNext;
if( nCur == nCount )
pNext = aEntries[ 0 ];
else
pNext = aEntries[ nCur ];
pPrev->pflink = pNext;
pNext->pblink = pPrev;
pPrev = pNext;
}
pHead = aEntries[ 0 ];
}
else
pHead = 0;
nFlags &= ~F_MOVED_ENTRIES;
}
void SvxIconChoiceCtrl_Impl::ClearPredecessors()
{
if( pHead )
{
size_t nCount = aEntries.size();
for( size_t nCur = 0; nCur < nCount; nCur++ )
{
SvxIconChoiceCtrlEntry* pCur = aEntries[ nCur ];
pCur->pflink = 0;
pCur->pblink = 0;
pCur->ClearFlags( ICNVIEW_FLAG_PRED_SET );
}
pHead = 0;
}
}
void SvxIconChoiceCtrl_Impl::Arrange( bool bKeepPredecessors, long nSetMaxVirtWidth, long nSetMaxVirtHeight )
{
if ( nSetMaxVirtWidth != 0 )
nMaxVirtWidth = nSetMaxVirtWidth;
else
nMaxVirtWidth = aOutputSize.Width();
if ( nSetMaxVirtHeight != 0 )
nMaxVirtHeight = nSetMaxVirtHeight;
else
nMaxVirtHeight = aOutputSize.Height();
ImpArrange( bKeepPredecessors );
}
void SvxIconChoiceCtrl_Impl::ImpArrange( bool bKeepPredecessors )
{
static Point aEmptyPoint;
bool bOldUpdate = bUpdateMode;
Rectangle aCurOutputArea( GetOutputRect() );
if( (nWinBits & WB_SMART_ARRANGE) && aCurOutputArea.TopLeft() != aEmptyPoint )
bUpdateMode = false;
aAutoArrangeIdle.Stop();
nFlags &= ~F_MOVED_ENTRIES;
nFlags |= F_ARRANGING;
StopEditTimer();
ShowCursor( false );
ResetVirtSize();
if( !bKeepPredecessors )
ClearPredecessors();
bBoundRectsDirty = false;
SetOrigin( Point() );
VisRectChanged();
RecalcAllBoundingRectsSmart();
// TODO: the invalidation in the detail view should be more intelligent
//if( !(nWinBits & WB_DETAILS ))
pView->Invalidate( INVALIDATE_NOCHILDREN );
nFlags &= ~F_ARRANGING;
if( (nWinBits & WB_SMART_ARRANGE) && aCurOutputArea.TopLeft() != aEmptyPoint )
{
MakeVisible( aCurOutputArea );
SetUpdateMode( bOldUpdate );
}
ShowCursor( true );
}
void SvxIconChoiceCtrl_Impl::Paint( const Rectangle& rRect )
{
bEndScrollInvalidate = false;
#if defined(OV_DRAWGRID)
Color aOldColor ( pView->GetLineColor() );
Color aColor( COL_BLACK );
pView->SetLineColor( aColor );
Point aOffs( pView->GetMapMode().GetOrigin());
Size aXSize( pView->GetOutputSizePixel() );
{
Point aStart( LROFFS_WINBORDER, 0 );
Point aEnd( LROFFS_WINBORDER, aXSize.Height());
aStart -= aOffs;
aEnd -= aOffs;
pView->DrawLine( aStart, aEnd );
}
{
Point aStart( 0, TBOFFS_WINBORDER );
Point aEnd( aXSize.Width(), TBOFFS_WINBORDER );
aStart -= aOffs;
aEnd -= aOffs;
pView->DrawLine( aStart, aEnd );
}
for( long nDX = nGridDX; nDX <= aXSize.Width(); nDX += nGridDX )
{
Point aStart( nDX+LROFFS_WINBORDER, 0 );
Point aEnd( nDX+LROFFS_WINBORDER, aXSize.Height());
aStart -= aOffs;
aEnd -= aOffs;
pView->DrawLine( aStart, aEnd );
}
for( long nDY = nGridDY; nDY <= aXSize.Height(); nDY += nGridDY )
{
Point aStart( 0, nDY+TBOFFS_WINBORDER );
Point aEnd( aXSize.Width(), nDY+TBOFFS_WINBORDER );
aStart -= aOffs;
aEnd -= aOffs;
pView->DrawLine( aStart, aEnd );
}
pView->SetLineColor( aOldColor );
#endif
nFlags |= F_PAINTED;
if( !aEntries.size() )
return;
if( !pCursor )
{
// set cursor to item with focus-flag
bool bfound = false;
for ( sal_uLong i = 0; i < pView->GetEntryCount() && !bfound; i++)
{
SvxIconChoiceCtrlEntry* pEntry = pView->GetEntry ( i );
if( pEntry->IsFocused() )
{
pCursor = pEntry;
bfound = true;
}
}
if( !bfound )
pCursor = aEntries[ 0 ];
}
// Show Focus at Init-Time
if ( pView->HasFocus() )
GetFocus();
size_t nCount = pZOrderList->size();
if( !nCount )
return;
bool bResetClipRegion = false;
if( !pView->IsClipRegion() )
{
vcl::Region const aOutputArea( GetOutputRect() );
bResetClipRegion = true;
pView->SetClipRegion( aOutputArea );
}
SvxIconChoiceCtrlEntryList_impl* pNewZOrderList = new SvxIconChoiceCtrlEntryList_impl();
boost::scoped_ptr<SvxIconChoiceCtrlEntryList_impl> pPaintedEntries(new SvxIconChoiceCtrlEntryList_impl());
size_t nPos = 0;
while( nCount )
{
SvxIconChoiceCtrlEntry* pEntry = (*pZOrderList)[ nPos ];
const Rectangle& rBoundRect = GetEntryBoundRect( pEntry );
if( rRect.IsOver( rBoundRect ) )
{
PaintEntry( pEntry, rBoundRect.TopLeft(), pView, true );
// set entries to Top if they are being repainted
pPaintedEntries->push_back( pEntry );
}
else
pNewZOrderList->push_back( pEntry );
nCount--;
nPos++;
}
delete pZOrderList;
pZOrderList = pNewZOrderList;
nCount = pPaintedEntries->size();
if( nCount )
{
for( size_t nCur = 0; nCur < nCount; nCur++ )
pZOrderList->push_back( (*pPaintedEntries)[ nCur ] );
}
pPaintedEntries.reset();
if( bResetClipRegion )
pView->SetClipRegion();
}
void SvxIconChoiceCtrl_Impl::RepaintEntries( sal_uInt16 nEntryFlagsMask )
{
const size_t nCount = pZOrderList->size();
if( !nCount )
return;
bool bResetClipRegion = false;
Rectangle aOutRect( GetOutputRect() );
if( !pView->IsClipRegion() )
{
bResetClipRegion = true;
pView->SetClipRegion(vcl::Region(aOutRect));
}
for( size_t nCur = 0; nCur < nCount; nCur++ )
{
SvxIconChoiceCtrlEntry* pEntry = (*pZOrderList)[ nCur ];
if( pEntry->GetFlags() & nEntryFlagsMask )
{
const Rectangle& rBoundRect = GetEntryBoundRect( pEntry );
if( aOutRect.IsOver( rBoundRect ) )
PaintEntry( pEntry, rBoundRect.TopLeft() );
}
}
if( bResetClipRegion )
pView->SetClipRegion();
}
void SvxIconChoiceCtrl_Impl::InitScrollBarBox()
{
aScrBarBox.SetSizePixel( Size(nVerSBarWidth-1, nHorSBarHeight-1) );
Size aSize( pView->GetOutputSizePixel() );
aScrBarBox.SetPosPixel( Point(aSize.Width()-nVerSBarWidth+1, aSize.Height()-nHorSBarHeight+1));
}
bool SvxIconChoiceCtrl_Impl::MouseButtonDown( const MouseEvent& rMEvt)
{
bool bHandled = true;
bHighlightFramePressed = false;
StopEditTimer();
bool bGotFocus = (!pView->HasFocus() && !(nWinBits & WB_NOPOINTERFOCUS));
if( !(nWinBits & WB_NOPOINTERFOCUS) )
pView->GrabFocus();
Point aDocPos( rMEvt.GetPosPixel() );
if(aDocPos.X()>=aOutputSize.Width() || aDocPos.Y()>=aOutputSize.Height())
return false;
ToDocPos( aDocPos );
SvxIconChoiceCtrlEntry* pEntry = GetEntry( aDocPos, true );
if( pEntry )
MakeEntryVisible( pEntry, false );
if( rMEvt.IsShift() && eSelectionMode != SINGLE_SELECTION )
{
if( pEntry )
SetCursor_Impl( pCursor, pEntry, rMEvt.IsMod1(), rMEvt.IsShift(), true);
return true;
}
if( pAnchor && (rMEvt.IsShift() || rMEvt.IsMod1())) // keyboard selection?
{
DBG_ASSERT(eSelectionMode != SINGLE_SELECTION,"Invalid selection mode");
if( rMEvt.IsMod1() )
nFlags |= F_ADD_MODE;
if( rMEvt.IsShift() )
{
Rectangle aRect( GetEntryBoundRect( pAnchor ));
if( pEntry )
aRect.Union( GetEntryBoundRect( pEntry ) );
else
{
Rectangle aTempRect( aDocPos, Size(1,1));
aRect.Union( aTempRect );
}
aCurSelectionRect = aRect;
SelectRect( aRect, (nFlags & F_ADD_MODE)!=0, &aSelectedRectList );
}
else if( rMEvt.IsMod1() )
{
AddSelectedRect( aCurSelectionRect );
pAnchor = 0;
aCurSelectionRect.SetPos( aDocPos );
}
if( !pEntry && !(nWinBits & WB_NODRAGSELECTION))
pView->StartTracking( STARTTRACK_SCROLLREPEAT );
return true;
}
else
{
if( !pEntry )
{
if( eSelectionMode == MULTIPLE_SELECTION )
{
if( !rMEvt.IsMod1() ) // Ctrl
{
if( !bGotFocus )
{
SetNoSelection();
ClearSelectedRectList();
}
}
else
nFlags |= F_ADD_MODE;
aCurSelectionRect.SetPos( aDocPos );
pView->StartTracking( STARTTRACK_SCROLLREPEAT );
}
else
bHandled = false;
return bHandled;
}
}
bool bSelected = pEntry->IsSelected();
bool bEditingEnabled = IsEntryEditingEnabled();
if( rMEvt.GetClicks() == 2 )
{
DeselectAllBut( pEntry );
SelectEntry( pEntry, true, true, false, true );
pHdlEntry = pEntry;
pView->ClickIcon();
}
else
{
// Inplace-Editing ?
if( rMEvt.IsMod2() ) // Alt?
{
if( bEntryEditingEnabled && pEntry &&
pEntry->IsSelected())
{
if( pView->EditingEntry( pEntry ))
EditEntry( pEntry );
}
}
else if( eSelectionMode == SINGLE_SELECTION )
{
DeselectAllBut( pEntry );
SetCursor( pEntry );
if( bEditingEnabled && bSelected && !rMEvt.GetModifier() &&
rMEvt.IsLeft() && IsTextHit( pEntry, aDocPos ) )
{
nFlags |= F_START_EDITTIMER_IN_MOUSEUP;
}
}
else if( eSelectionMode == NO_SELECTION )
{
if( rMEvt.IsLeft() && (nWinBits & WB_HIGHLIGHTFRAME) )
{
pCurHighlightFrame = 0; // force repaint of frame
bHighlightFramePressed = true;
SetEntryHighlightFrame( pEntry, true );
}
}
else
{
if( !rMEvt.GetModifier() && rMEvt.IsLeft() )
{
if( !bSelected )
{
DeselectAllBut( pEntry, true /* paint synchronously */ );
SetCursor( pEntry );
SelectEntry( pEntry, true, true, false, true );
}
else
{
// deselect only in the Up, if the Move happened via D&D!
nFlags |= F_DOWN_DESELECT;
if( bEditingEnabled && IsTextHit( pEntry, aDocPos ) &&
rMEvt.IsLeft())
{
nFlags |= F_START_EDITTIMER_IN_MOUSEUP;
}
}
}
else if( rMEvt.IsMod1() )
nFlags |= F_DOWN_CTRL;
}
}
return bHandled;
}
bool SvxIconChoiceCtrl_Impl::MouseButtonUp( const MouseEvent& rMEvt )
{
bool bHandled = false;
if( rMEvt.IsRight() && (nFlags & (F_DOWN_CTRL | F_DOWN_DESELECT) ))
{
nFlags &= ~(F_DOWN_CTRL | F_DOWN_DESELECT);
bHandled = true;
}
Point aDocPos( rMEvt.GetPosPixel() );
ToDocPos( aDocPos );
SvxIconChoiceCtrlEntry* pDocEntry = GetEntry( aDocPos );
if( pDocEntry )
{
if( nFlags & F_DOWN_CTRL )
{
// Ctrl & MultiSelection
ToggleSelection( pDocEntry );
SetCursor( pDocEntry );
bHandled = true;
}
else if( nFlags & F_DOWN_DESELECT )
{
DeselectAllBut( pDocEntry );
SetCursor( pDocEntry );
SelectEntry( pDocEntry, true, true, false, true );
bHandled = true;
}
}
nFlags &= ~(F_DOWN_CTRL | F_DOWN_DESELECT);
if( nFlags & F_START_EDITTIMER_IN_MOUSEUP )
{
bHandled = true;
StartEditTimer();
nFlags &= ~F_START_EDITTIMER_IN_MOUSEUP;
}
if((nWinBits & WB_HIGHLIGHTFRAME) && bHighlightFramePressed && pCurHighlightFrame)
{
bHandled = true;
SvxIconChoiceCtrlEntry* pEntry = pCurHighlightFrame;
pCurHighlightFrame = 0; // force repaint of frame
bHighlightFramePressed = false;
SetEntryHighlightFrame( pEntry, true );
pHdlEntry = pCurHighlightFrame;
pView->ClickIcon();
// set focus on Icon
SvxIconChoiceCtrlEntry* pOldCursor = pCursor;
SetCursor_Impl( pOldCursor, pHdlEntry, false, false, true );
pHdlEntry = 0;
}
return bHandled;
}
bool SvxIconChoiceCtrl_Impl::MouseMove( const MouseEvent& rMEvt )
{
const Point aDocPos( pView->PixelToLogic(rMEvt.GetPosPixel()) );
if( pView->IsTracking() )
return false;
else if( nWinBits & WB_HIGHLIGHTFRAME )
{
SvxIconChoiceCtrlEntry* pEntry = GetEntry( aDocPos, true );
SetEntryHighlightFrame( pEntry );
}
else
return false;
return true;
}
void SvxIconChoiceCtrl_Impl::SetCursor_Impl( SvxIconChoiceCtrlEntry* pOldCursor,
SvxIconChoiceCtrlEntry* pNewCursor, bool bMod1, bool bShift, bool bPaintSync )
{
if( pNewCursor )
{
SvxIconChoiceCtrlEntry* pFilterEntry = 0;
bool bDeselectAll = false;
if( eSelectionMode != SINGLE_SELECTION )
{
if( !bMod1 && !bShift )
bDeselectAll = true;
else if( bShift && !bMod1 && !pAnchor )
{
bDeselectAll = true;
pFilterEntry = pOldCursor;
}
}
if( bDeselectAll )
DeselectAllBut( pFilterEntry, bPaintSync );
ShowCursor( false );
MakeEntryVisible( pNewCursor );
SetCursor( pNewCursor );
if( bMod1 && !bShift )
{
if( pAnchor )
{
AddSelectedRect( pAnchor, pOldCursor );
pAnchor = 0;
}
}
else if( bShift )
{
if( !pAnchor )
pAnchor = pOldCursor;
if ( nWinBits & WB_ALIGN_LEFT )
SelectRange( pAnchor, pNewCursor, (nFlags & F_ADD_MODE)!=0 );
else
SelectRect(pAnchor,pNewCursor,(nFlags & F_ADD_MODE)!=0,&aSelectedRectList);
}
else
{
SelectEntry( pCursor, true, true, false, bPaintSync );
aCurSelectionRect = GetEntryBoundRect( pCursor );
CallEventListeners( VCLEVENT_LISTBOX_SELECT, pCursor );
}
}
}
bool SvxIconChoiceCtrl_Impl::KeyInput( const KeyEvent& rKEvt )
{
StopEditTimer();
bool bMod2 = rKEvt.GetKeyCode().IsMod2();
sal_Unicode cChar = rKEvt.GetCharCode();
sal_uLong nPos = (sal_uLong)-1;
if ( bMod2 && cChar && IsMnemonicChar( cChar, nPos ) )
{
// shortcut is clicked
SvxIconChoiceCtrlEntry* pNewCursor = GetEntry( nPos );
SvxIconChoiceCtrlEntry* pOldCursor = pCursor;
if ( pNewCursor != pOldCursor )
SetCursor_Impl( pOldCursor, pNewCursor, false, false, false );
return true;
}
if ( bMod2 )
// no actions with <ALT>
return false;
bool bKeyUsed = true;
bool bMod1 = rKEvt.GetKeyCode().IsMod1();
bool bShift = rKEvt.GetKeyCode().IsShift();
if( eSelectionMode == SINGLE_SELECTION || eSelectionMode == NO_SELECTION)
{
bShift = false;
bMod1 = false;
}
if( bMod1 )
nFlags |= F_ADD_MODE;
SvxIconChoiceCtrlEntry* pNewCursor;
SvxIconChoiceCtrlEntry* pOldCursor = pCursor;
sal_uInt16 nCode = rKEvt.GetKeyCode().GetCode();
switch( nCode )
{
case KEY_UP:
case KEY_PAGEUP:
if( pCursor )
{
MakeEntryVisible( pCursor );
if( nCode == KEY_UP )
pNewCursor = pImpCursor->GoUpDown(pCursor,false);
else
pNewCursor = pImpCursor->GoPageUpDown(pCursor,false);
SetCursor_Impl( pOldCursor, pNewCursor, bMod1, bShift, true );
if( !pNewCursor )
{
Rectangle aRect( GetEntryBoundRect( pCursor ) );
if( aRect.Top())
{
aRect.Bottom() -= aRect.Top();
aRect.Top() = 0;
MakeVisible( aRect );
}
}
if ( bChooseWithCursor && pNewCursor != NULL )
{
pHdlEntry = pNewCursor;//GetCurEntry();
pCurHighlightFrame = pHdlEntry;
pView->ClickIcon();
pCurHighlightFrame = NULL;
}
}
break;
case KEY_DOWN:
case KEY_PAGEDOWN:
if( pCursor )
{
if( nCode == KEY_DOWN )
pNewCursor=pImpCursor->GoUpDown( pCursor,true );
else
pNewCursor=pImpCursor->GoPageUpDown( pCursor,true );
SetCursor_Impl( pOldCursor, pNewCursor, bMod1, bShift, true );
if ( bChooseWithCursor && pNewCursor != NULL)
{
pHdlEntry = pNewCursor;//GetCurEntry();
pCurHighlightFrame = pHdlEntry;
pView->ClickIcon();
pCurHighlightFrame = NULL;
}
}
break;
case KEY_RIGHT:
if( pCursor )
{
pNewCursor=pImpCursor->GoLeftRight(pCursor,true );
SetCursor_Impl( pOldCursor, pNewCursor, bMod1, bShift, true );
}
break;
case KEY_LEFT:
if( pCursor )
{
MakeEntryVisible( pCursor );
pNewCursor = pImpCursor->GoLeftRight(pCursor,false );
SetCursor_Impl( pOldCursor, pNewCursor, bMod1, bShift, true );
if( !pNewCursor )
{
Rectangle aRect( GetEntryBoundRect(pCursor));
if( aRect.Left() )
{
aRect.Right() -= aRect.Left();
aRect.Left() = 0;
MakeVisible( aRect );
}
}
}
break;
case KEY_F2:
if( !bMod1 && !bShift )
EditTimeoutHdl( 0 );
else
bKeyUsed = false;
break;
case KEY_F8:
if( rKEvt.GetKeyCode().IsShift() )
{
if( nFlags & F_ADD_MODE )
nFlags &= (~F_ADD_MODE);
else
nFlags |= F_ADD_MODE;
}
else
bKeyUsed = false;
break;
case KEY_SPACE:
if( pCursor && eSelectionMode != SINGLE_SELECTION )
{
if( !bMod1 )
{
//SelectAll( false );
SetNoSelection();
ClearSelectedRectList();
// click Icon with spacebar
SetEntryHighlightFrame( GetCurEntry(), true );
pView->ClickIcon();
pHdlEntry = pCurHighlightFrame;
pCurHighlightFrame=0;
}
else
ToggleSelection( pCursor );
}
break;
#ifdef DBG_UTIL
case KEY_F10:
if( rKEvt.GetKeyCode().IsShift() )
{
if( pCursor )
pView->SetEntryTextMode( IcnShowTextFull, pCursor );
}
if( rKEvt.GetKeyCode().IsMod1() )
{
if( pCursor )
pView->SetEntryTextMode( IcnShowTextShort, pCursor );
}
break;
#endif
case KEY_ADD:
case KEY_DIVIDE :
case KEY_A:
if( bMod1 && (eSelectionMode != SINGLE_SELECTION))
SelectAll( true );
else
bKeyUsed = false;
break;
case KEY_SUBTRACT:
case KEY_COMMA :
if( bMod1 )
SetNoSelection();
else
bKeyUsed = false;
break;
case KEY_RETURN:
if( bMod1 )
{
if( pCursor && bEntryEditingEnabled )
/*pView->*/EditEntry( pCursor );
}
else
bKeyUsed = false;
break;
case KEY_END:
if( pCursor )
{
pNewCursor = aEntries[ aEntries.size() - 1 ];
SetCursor_Impl( pOldCursor, pNewCursor, bMod1, bShift, true );
}
break;
case KEY_HOME:
if( pCursor )
{
pNewCursor = aEntries[ 0 ];
SetCursor_Impl( pOldCursor, pNewCursor, bMod1, bShift, true );
}
break;
default:
bKeyUsed = false;
}
return bKeyUsed;
}
// recalculate TopLeft of scrollbars (but not their sizes!)
void SvxIconChoiceCtrl_Impl::PositionScrollBars( long nRealWidth, long nRealHeight )
{
// horizontal scrollbar
Point aPos( 0, nRealHeight );
aPos.Y() -= nHorSBarHeight;
if( aHorSBar.GetPosPixel() != aPos )
aHorSBar.SetPosPixel( aPos );
// vertical scrollbar
aPos.X() = nRealWidth; aPos.Y() = 0;
aPos.X() -= nVerSBarWidth;
aPos.X()++;
aPos.Y()--;
if( aVerSBar.GetPosPixel() != aPos )
aVerSBar.SetPosPixel( aPos );
}
void SvxIconChoiceCtrl_Impl::AdjustScrollBars( bool )
{
Rectangle aOldOutRect( GetOutputRect() );
long nVirtHeight = aVirtOutputSize.Height();
long nVirtWidth = aVirtOutputSize.Width();
Size aOSize( pView->Control::GetOutputSizePixel() );
long nRealHeight = aOSize.Height();
long nRealWidth = aOSize.Width();
PositionScrollBars( nRealWidth, nRealHeight );
const MapMode& rMapMode = pView->GetMapMode();
Point aOrigin( rMapMode.GetOrigin() );
long nVisibleWidth;
if( nRealWidth > nVirtWidth )
nVisibleWidth = nVirtWidth + aOrigin.X();
else
nVisibleWidth = nRealWidth;
long nVisibleHeight;
if( nRealHeight > nVirtHeight )
nVisibleHeight = nVirtHeight + aOrigin.Y();
else
nVisibleHeight = nRealHeight;
bool bVerSBar = ( nWinBits & WB_VSCROLL ) != 0;
bool bHorSBar = ( nWinBits & WB_HSCROLL ) != 0;
bool bNoVerSBar = ( nWinBits & WB_NOVSCROLL ) != 0;
bool bNoHorSBar = ( nWinBits & WB_NOHSCROLL ) != 0;
sal_uInt16 nResult = 0;
if( nVirtHeight )
{
// activate vertical scrollbar?
if( !bNoVerSBar && (bVerSBar || ( nVirtHeight > nVisibleHeight)) )
{
nResult = 0x0001;
nRealWidth -= nVerSBarWidth;
if( nRealWidth > nVirtWidth )
nVisibleWidth = nVirtWidth + aOrigin.X();
else
nVisibleWidth = nRealWidth;
nFlags |= F_HOR_SBARSIZE_WITH_VBAR;
}
// activate horizontal scrollbar?
if( !bNoHorSBar && (bHorSBar || (nVirtWidth > nVisibleWidth)) )
{
nResult |= 0x0002;
nRealHeight -= nHorSBarHeight;
if( nRealHeight > nVirtHeight )
nVisibleHeight = nVirtHeight + aOrigin.Y();
else
nVisibleHeight = nRealHeight;
// do we need a vertical scrollbar after all?
if( !(nResult & 0x0001) && // only if not already there
( !bNoVerSBar && ((nVirtHeight > nVisibleHeight) || bVerSBar)) )
{
nResult = 3; // both turned on
nRealWidth -= nVerSBarWidth;
if( nRealWidth > nVirtWidth )
nVisibleWidth = nVirtWidth + aOrigin.X();
else
nVisibleWidth = nRealWidth;
nFlags |= F_VER_SBARSIZE_WITH_HBAR;
}
}
}
// size vertical scrollbar
long nThumb = aVerSBar.GetThumbPos();
Size aSize( nVerSBarWidth, nRealHeight );
aSize.Height() += 2;
if( aSize != aVerSBar.GetSizePixel() )
aVerSBar.SetSizePixel( aSize );
aVerSBar.SetVisibleSize( nVisibleHeight );
aVerSBar.SetPageSize( GetScrollBarPageSize( nVisibleHeight ));
if( nResult & 0x0001 )
{
aVerSBar.SetThumbPos( nThumb );
aVerSBar.Show();
}
else
{
aVerSBar.SetThumbPos( 0 );
aVerSBar.Hide();
}
// size horizontal scrollbar
nThumb = aHorSBar.GetThumbPos();
aSize.Width() = nRealWidth;
aSize.Height() = nHorSBarHeight;
aSize.Width()++;
if( nResult & 0x0001 ) // vertical scrollbar?
{
aSize.Width()++;
nRealWidth++;
}
if( aSize != aHorSBar.GetSizePixel() )
aHorSBar.SetSizePixel( aSize );
aHorSBar.SetVisibleSize( nVisibleWidth );
aHorSBar.SetPageSize( GetScrollBarPageSize(nVisibleWidth ));
if( nResult & 0x0002 )
{
aHorSBar.SetThumbPos( nThumb );
aHorSBar.Show();
}
else
{
aHorSBar.SetThumbPos( 0 );
aHorSBar.Hide();
}
aOutputSize.Width() = nRealWidth;
if( nResult & 0x0002 ) // horizontal scrollbar ?
nRealHeight++; // because lower border is clipped
aOutputSize.Height() = nRealHeight;
Rectangle aNewOutRect( GetOutputRect() );
if( aNewOutRect != aOldOutRect && pView->HasBackground() )
{
Wallpaper aPaper( pView->GetBackground() );
aPaper.SetRect( aNewOutRect );
pView->SetBackground( aPaper );
}
if( (nResult & (0x0001|0x0002)) == (0x0001|0x0002) )
aScrBarBox.Show();
else
aScrBarBox.Hide();
}
void SvxIconChoiceCtrl_Impl::Resize()
{
StopEditTimer();
InitScrollBarBox();
aOutputSize = pView->GetOutputSizePixel();
pImpCursor->Clear();
pGridMap->OutputSizeChanged();
const Size& rSize = pView->Control::GetOutputSizePixel();
PositionScrollBars( rSize.Width(), rSize.Height() );
// The scrollbars are shown/hidden asynchronously, so derived classes can
// do an Arrange during Resize, without the scrollbars suddenly turning
// on and off again.
// If an event is already underway, we don't need to send a new one, at least
// as long as there is only one event type.
if ( ! nUserEventAdjustScrBars )
nUserEventAdjustScrBars =
Application::PostUserEvent( LINK( this, SvxIconChoiceCtrl_Impl, UserEventHdl),
EVENTID_ADJUST_SCROLLBARS);
if( pView->HasBackground() && !pView->GetBackground().IsScrollable() )
{
Rectangle aRect( GetOutputRect());
Wallpaper aPaper( pView->GetBackground() );
aPaper.SetRect( aRect );
pView->SetBackground( aPaper );
}
VisRectChanged();
}
bool SvxIconChoiceCtrl_Impl::CheckHorScrollBar()
{
if( !pZOrderList || !aHorSBar.IsVisible() )
return false;
const MapMode& rMapMode = pView->GetMapMode();
Point aOrigin( rMapMode.GetOrigin() );
if(!( nWinBits & WB_HSCROLL) && !aOrigin.X() )
{
long nWidth = aOutputSize.Width();
const size_t nCount = pZOrderList->size();
long nMostRight = 0;
for( size_t nCur = 0; nCur < nCount; nCur++ )
{
SvxIconChoiceCtrlEntry* pEntry = (*pZOrderList)[ nCur ];
long nRight = GetEntryBoundRect(pEntry).Right();
if( nRight > nWidth )
return false;
if( nRight > nMostRight )
nMostRight = nRight;
}
aHorSBar.Hide();
aOutputSize.Height() += nHorSBarHeight;
aVirtOutputSize.Width() = nMostRight;
aHorSBar.SetThumbPos( 0 );
Range aRange;
aRange.Max() = nMostRight - 1;
aHorSBar.SetRange( aRange );
if( aVerSBar.IsVisible() )
{
Size aSize( aVerSBar.GetSizePixel());
aSize.Height() += nHorSBarHeight;
aVerSBar.SetSizePixel( aSize );
}
return true;
}
return false;
}
bool SvxIconChoiceCtrl_Impl::CheckVerScrollBar()
{
if( !pZOrderList || !aVerSBar.IsVisible() )
return false;
const MapMode& rMapMode = pView->GetMapMode();
Point aOrigin( rMapMode.GetOrigin() );
if(!( nWinBits & WB_VSCROLL) && !aOrigin.Y() )
{
long nDeepest = 0;
long nHeight = aOutputSize.Height();
const size_t nCount = pZOrderList->size();
for( size_t nCur = 0; nCur < nCount; nCur++ )
{
SvxIconChoiceCtrlEntry* pEntry = (*pZOrderList)[ nCur ];
long nBottom = GetEntryBoundRect(pEntry).Bottom();
if( nBottom > nHeight )
return false;
if( nBottom > nDeepest )
nDeepest = nBottom;
}
aVerSBar.Hide();
aOutputSize.Width() += nVerSBarWidth;
aVirtOutputSize.Height() = nDeepest;
aVerSBar.SetThumbPos( 0 );
Range aRange;
aRange.Max() = nDeepest - 1;
aVerSBar.SetRange( aRange );
if( aHorSBar.IsVisible() )
{
Size aSize( aHorSBar.GetSizePixel());
aSize.Width() += nVerSBarWidth;
aHorSBar.SetSizePixel( aSize );
}
return true;
}
return false;
}
// hides scrollbars if they're unnecessary
void SvxIconChoiceCtrl_Impl::CheckScrollBars()
{
CheckVerScrollBar();
if( CheckHorScrollBar() )
CheckVerScrollBar();
if( aVerSBar.IsVisible() && aHorSBar.IsVisible() )
aScrBarBox.Show();
else
aScrBarBox.Hide();
}
void SvxIconChoiceCtrl_Impl::GetFocus()
{
RepaintEntries( ICNVIEW_FLAG_SELECTED );
if( pCursor )
{
pCursor->SetFlags( ICNVIEW_FLAG_FOCUSED );
ShowCursor( true );
}
}
void SvxIconChoiceCtrl_Impl::LoseFocus()
{
StopEditTimer();
if( pCursor )
pCursor->ClearFlags( ICNVIEW_FLAG_FOCUSED );
ShowCursor( false );
// HideFocus ();
// pView->Invalidate ( aFocus.aRect );
RepaintEntries( ICNVIEW_FLAG_SELECTED );
}
void SvxIconChoiceCtrl_Impl::SetUpdateMode( bool bUpdate )
{
if( bUpdate != bUpdateMode )
{
bUpdateMode = bUpdate;
if( bUpdate )
{
AdjustScrollBars();
pImpCursor->Clear();
pGridMap->Clear();
pView->Invalidate(INVALIDATE_NOCHILDREN);
}
}
}
void SvxIconChoiceCtrl_Impl::PaintEntry( SvxIconChoiceCtrlEntry* pEntry, bool bIsBackgroundPainted )
{
Point aPos( GetEntryPos( pEntry ) );
PaintEntry( pEntry, aPos, 0, bIsBackgroundPainted );
}
// priorities of the emphasis: bDropTarget => bCursored => bSelected
void SvxIconChoiceCtrl_Impl::PaintEmphasis(
const Rectangle& rTextRect, const Rectangle& rImageRect,
bool bSelected, bool bDropTarget, bool bCursored, OutputDevice* pOut,
bool bIsBackgroundPainted )
{
static Color aTransparent( COL_TRANSPARENT );
if( !pOut )
pOut = pView;
const StyleSettings& rSettings = pOut->GetSettings().GetStyleSettings();
Color aOldFillColor( pOut->GetFillColor() );
bool bSolidTextRect = false;
bool bSolidImageRect = false;
if( bDropTarget && ( eSelectionMode != NO_SELECTION ) )
{
pOut->SetFillColor( rSettings.GetHighlightColor() );
bSolidTextRect = true;
bSolidImageRect = true;
}
else
{
if ( !bSelected || bCursored )
{
if( !pView->HasFontFillColor() )
pOut->SetFillColor( pOut->GetBackground().GetColor() );
else
{
const Color& rFillColor = pView->GetFont().GetFillColor();
pOut->SetFillColor( rFillColor );
if( rFillColor != aTransparent )
bSolidTextRect = true;
}
}
}
// draw text rectangle
if( !bSolidTextRect )
{
if( !bIsBackgroundPainted )
pOut->Erase( rTextRect );
}
else
{
Color aOldLineColor;
if( bCursored )
{
aOldLineColor = pOut->GetLineColor();
pOut->SetLineColor( Color( COL_GRAY ) );
}
pOut->DrawRect( rTextRect );
if( bCursored )
pOut->SetLineColor( aOldLineColor );
}
// draw image rectangle
if( !bSolidImageRect )
{
if( !bIsBackgroundPainted )
pOut->Erase( rImageRect );
}
// the emphasis of the images has to be drawn by the derived class (in the
// virtual function DrawEntryImage)
// else
// pOut->DrawRect( rImageRect );
pOut->SetFillColor( aOldFillColor );
}
void SvxIconChoiceCtrl_Impl::PaintItem( const Rectangle& rRect,
IcnViewFieldType eItem, SvxIconChoiceCtrlEntry* pEntry, sal_uInt16 nPaintFlags,
OutputDevice* pOut, const OUString* pStr, ::vcl::ControlLayoutData* _pLayoutData )
{
if( eItem == IcnViewFieldTypeText )
{
OUString aText;
if( !pStr )
aText = pView->GetEntryText( pEntry, false );
else
aText = *pStr;
if ( _pLayoutData )
{
pOut->DrawText( rRect, aText, nCurTextDrawFlags,
&_pLayoutData->m_aUnicodeBoundRects, &_pLayoutData->m_aDisplayText );
}
else
{
Color aOldFontColor = pOut->GetTextColor();
if ( pView->AutoFontColor() )
{
Color aBkgColor( pOut->GetBackground().GetColor() );
Color aFontColor;
sal_uInt16 nColor = ( aBkgColor.GetRed() + aBkgColor.GetGreen() + aBkgColor.GetBlue() ) / 3;
if ( nColor > 127 )
aFontColor.SetColor ( COL_BLACK );
else
aFontColor.SetColor( COL_WHITE );
pOut->SetTextColor( aFontColor );
}
pOut->DrawText( rRect, aText, nCurTextDrawFlags );
if ( pView->AutoFontColor() )
pOut->SetTextColor( aOldFontColor );
if( pEntry->IsFocused() )
{
Rectangle aRect ( CalcFocusRect( (SvxIconChoiceCtrlEntry*)pEntry ) );
/*pView->*/ShowFocus( aRect );
DrawFocusRect( pOut );
}
}
}
else
{
Point aPos( rRect.TopLeft() );
if( nPaintFlags & PAINTFLAG_HOR_CENTERED )
aPos.X() += (rRect.GetWidth() - aImageSize.Width() ) / 2;
if( nPaintFlags & PAINTFLAG_VER_CENTERED )
aPos.Y() += (rRect.GetHeight() - aImageSize.Height() ) / 2;
pView->DrawEntryImage( pEntry, aPos, *pOut );
}
}
void SvxIconChoiceCtrl_Impl::PaintEntryVirtOutDev( SvxIconChoiceCtrlEntry* pEntry )
{
if( !pEntryPaintDev )
{
pEntryPaintDev = new VirtualDevice( *pView );
pEntryPaintDev->SetFont( pView->GetFont() );
pEntryPaintDev->SetLineColor();
//pEntryPaintDev->SetBackground( pView->GetBackground() );
}
const Rectangle& rRect = GetEntryBoundRect( pEntry );
Rectangle aOutRect( GetOutputRect() );
if( !rRect.IsOver( aOutRect ) )
return;
Wallpaper aPaper( pView->GetBackground() );
Rectangle aRect( aPaper.GetRect() );
// move rectangle, so the bounding rectangle of the entry lies in
// VirtOut-Dev at 0,0
aRect.Move( -rRect.Left(), -rRect.Top() );
aPaper.SetRect( aRect );
pEntryPaintDev->SetBackground( aPaper );
pEntryPaintDev->SetFont( pView->GetFont() );
Size aSize( rRect.GetSize() );
pEntryPaintDev->SetOutputSizePixel( aSize );
pEntryPaintDev->DrawOutDev(
Point(), aSize, rRect.TopLeft(), aSize, *pView );
PaintEntry( pEntry, Point(), pEntryPaintDev );
pView->DrawOutDev(
rRect.TopLeft(),
aSize,
Point(),
aSize,
*pEntryPaintDev );
}
void SvxIconChoiceCtrl_Impl::PaintEntry( SvxIconChoiceCtrlEntry* pEntry, const Point& rPos,
OutputDevice* pOut, bool bIsBackgroundPainted )
{
if( !pOut )
pOut = pView;
bool bSelected = false;
if( eSelectionMode != NO_SELECTION )
bSelected = pEntry->IsSelected();
bool bCursored = pEntry->IsCursored();
bool bDropTarget = pEntry->IsDropTarget();
bool bNoEmphasis = pEntry->IsBlockingEmphasis();
vcl::Font aTempFont( pOut->GetFont() );
// AutoFontColor
/*
if ( pView->AutoFontColor() )
{
aTempFont.SetColor ( aFontColor );
}
*/
OUString aEntryText( pView->GetEntryText( pEntry, false ) );
Rectangle aTextRect( CalcTextRect(pEntry,&rPos,false,&aEntryText));
Rectangle aBmpRect( CalcBmpRect(pEntry, &rPos ) );
bool bShowSelection =
( ( ( bSelected && !bCursored )
|| bDropTarget
)
&& !bNoEmphasis
&& ( eSelectionMode != NO_SELECTION )
);
bool bActiveSelection = ( 0 != ( nWinBits & WB_NOHIDESELECTION ) ) || pView->HasFocus();
if ( bShowSelection )
{
const StyleSettings& rSettings = pOut->GetSettings().GetStyleSettings();
vcl::Font aNewFont( aTempFont );
// font fill colors that are attributed "hard" need corresponding "hard"
// attributed highlight colors
if( pView->HasFontFillColor() )
{
if( (nWinBits & WB_NOHIDESELECTION) || pView->HasFocus() )
aNewFont.SetFillColor( rSettings.GetHighlightColor() );
else
aNewFont.SetFillColor( rSettings.GetDeactiveColor() );
}
Color aWinCol = rSettings.GetWindowTextColor();
if ( !bActiveSelection && rSettings.GetFaceColor().IsBright() == aWinCol.IsBright() )
aNewFont.SetColor( rSettings.GetWindowTextColor() );
else
aNewFont.SetColor( rSettings.GetHighlightTextColor() );
pOut->SetFont( aNewFont );
pOut->SetFillColor( pOut->GetBackground().GetColor() );
pOut->DrawRect( CalcFocusRect( pEntry ) );
pOut->SetFillColor( );
}
bool bResetClipRegion = false;
if( !pView->IsClipRegion() && (aVerSBar.IsVisible() || aHorSBar.IsVisible()) )
{
Rectangle aOutputArea( GetOutputRect() );
if( aOutputArea.IsOver(aTextRect) || aOutputArea.IsOver(aBmpRect) )
{
pView->SetClipRegion(vcl::Region(aOutputArea));
bResetClipRegion = true;
}
}
bool bLargeIconMode = WB_ICON == ( nWinBits & (VIEWMODE_MASK) );
sal_uInt16 nBmpPaintFlags = PAINTFLAG_VER_CENTERED;
if ( bLargeIconMode )
nBmpPaintFlags |= PAINTFLAG_HOR_CENTERED;
sal_uInt16 nTextPaintFlags = bLargeIconMode ? PAINTFLAG_HOR_CENTERED : PAINTFLAG_VER_CENTERED;
if( !bNoEmphasis )
PaintEmphasis(aTextRect,aBmpRect,bSelected,bDropTarget,bCursored,pOut,bIsBackgroundPainted);
if ( bShowSelection )
pView->DrawSelectionBackground( CalcFocusRect( pEntry ),
bActiveSelection ? 1 : 2 /* highlight */, false /* check */, true /* border */, false /* ext border only */ );
PaintItem( aBmpRect, IcnViewFieldTypeImage, pEntry, nBmpPaintFlags, pOut );
PaintItem( aTextRect, IcnViewFieldTypeText, pEntry,
nTextPaintFlags, pOut );
// draw highlight frame
if( pEntry == pCurHighlightFrame && !bNoEmphasis )
DrawHighlightFrame( pOut, CalcFocusRect( pEntry ), false );
pOut->SetFont( aTempFont );
if( bResetClipRegion )
pView->SetClipRegion();
}
void SvxIconChoiceCtrl_Impl::SetEntryPos( SvxIconChoiceCtrlEntry* pEntry, const Point& rPos,
bool bAdjustAtGrid, bool bCheckScrollBars, bool bKeepGridMap )
{
ShowCursor( false );
Rectangle aBoundRect( GetEntryBoundRect( pEntry ));
pView->Invalidate( aBoundRect );
ToTop( pEntry );
if( !IsAutoArrange() )
{
bool bAdjustVirtSize = false;
if( rPos != aBoundRect.TopLeft() )
{
Point aGridOffs(
pEntry->aGridRect.TopLeft() - pEntry->aRect.TopLeft() );
pImpCursor->Clear();
if( !bKeepGridMap )
pGridMap->Clear();
aBoundRect.SetPos( rPos );
pEntry->aRect = aBoundRect;
pEntry->aGridRect.SetPos( rPos + aGridOffs );
bAdjustVirtSize = true;
}
if( bAdjustAtGrid )
{
if( bAdjustVirtSize )
{
// By aligning the (in some cases newly positioned) entry, it
// can become completely visible again, so that maybe we don't
// need a scrollbar after all. To avoid suddenly turning the
// scrollbar(s) on and then off again, we use the aligned
// bounding rectangle of the entry to enlarge the virtual
// output size. The virtual size has to be adapted, because
// AdjustEntryAtGrid depends on it.
const Rectangle& rBoundRect = GetEntryBoundRect( pEntry );
Rectangle aCenterRect( CalcBmpRect( pEntry, 0 ));
Point aNewPos( AdjustAtGrid( aCenterRect, rBoundRect ) );
Rectangle aNewBoundRect( aNewPos, pEntry->aRect.GetSize());
AdjustVirtSize( aNewBoundRect );
bAdjustVirtSize = false;
}
AdjustEntryAtGrid( pEntry );
ToTop( pEntry );
}
if( bAdjustVirtSize )
AdjustVirtSize( pEntry->aRect );
if( bCheckScrollBars && bUpdateMode )
CheckScrollBars();
pView->Invalidate( pEntry->aRect );
pGridMap->OccupyGrids( pEntry );
}
else
{
SvxIconChoiceCtrlEntry* pPrev = FindEntryPredecessor( pEntry, rPos );
SetEntryPredecessor( pEntry, pPrev );
aAutoArrangeIdle.Start();
}
ShowCursor( true );
}
void SvxIconChoiceCtrl_Impl::SetNoSelection()
{
// block recursive calls via SelectEntry
if( !(nFlags & F_CLEARING_SELECTION ))
{
nFlags |= F_CLEARING_SELECTION;
DeselectAllBut( 0, true );
nFlags &= ~F_CLEARING_SELECTION;
}
}
SvxIconChoiceCtrlEntry* SvxIconChoiceCtrl_Impl::GetEntry( const Point& rDocPos, bool bHit )
{
CheckBoundingRects();
// search through z-order list from the end
size_t nCount = pZOrderList->size();
while( nCount )
{
nCount--;
SvxIconChoiceCtrlEntry* pEntry = (*pZOrderList)[ nCount ];
if( pEntry->aRect.IsInside( rDocPos ) )
{
if( bHit )
{
Rectangle aRect = CalcBmpRect( pEntry );
aRect.Top() -= 3;
aRect.Bottom() += 3;
aRect.Left() -= 3;
aRect.Right() += 3;
if( aRect.IsInside( rDocPos ) )
return pEntry;
aRect = CalcTextRect( pEntry );
if( aRect.IsInside( rDocPos ) )
return pEntry;
}
else
return pEntry;
}
}
return 0;
}
Point SvxIconChoiceCtrl_Impl::GetEntryPos( SvxIconChoiceCtrlEntry* pEntry )
{
return pEntry->aRect.TopLeft();
}
void SvxIconChoiceCtrl_Impl::MakeEntryVisible( SvxIconChoiceCtrlEntry* pEntry, bool bBound )
{
if ( bBound )
{
const Rectangle& rRect = GetEntryBoundRect( pEntry );
MakeVisible( rRect );
}
else
{
Rectangle aRect = CalcBmpRect( pEntry );
aRect.Union( CalcTextRect( pEntry ) );
aRect.Top() += TBOFFS_BOUND;
aRect.Bottom() += TBOFFS_BOUND;
aRect.Left() += LROFFS_BOUND;
aRect.Right() += LROFFS_BOUND;
MakeVisible( aRect );
}
}
const Rectangle& SvxIconChoiceCtrl_Impl::GetEntryBoundRect( SvxIconChoiceCtrlEntry* pEntry )
{
if( !IsBoundingRectValid( pEntry->aRect ))
FindBoundingRect( pEntry );
return pEntry->aRect;
}
Rectangle SvxIconChoiceCtrl_Impl::CalcBmpRect( SvxIconChoiceCtrlEntry* pEntry, const Point* pPos )
{
Rectangle aBound = GetEntryBoundRect( pEntry );
if( pPos )
aBound.SetPos( *pPos );
Point aPos( aBound.TopLeft() );
switch( nWinBits & (VIEWMODE_MASK) )
{
case WB_ICON:
{
aPos.X() += ( aBound.GetWidth() - aImageSize.Width() ) / 2;
return Rectangle( aPos, aImageSize );
}
case WB_SMALLICON:
case WB_DETAILS:
aPos.Y() += ( aBound.GetHeight() - aImageSize.Height() ) / 2;
//TODO: determine horizontal distance to bounding rectangle
return Rectangle( aPos, aImageSize );
default:
OSL_FAIL("IconView: Viewmode not set");
return aBound;
}
}
Rectangle SvxIconChoiceCtrl_Impl::CalcTextRect( SvxIconChoiceCtrlEntry* pEntry,
const Point* pEntryPos, bool bEdit, const OUString* pStr )
{
OUString aEntryText;
if( !pStr )
aEntryText = pView->GetEntryText( pEntry, bEdit );
else
aEntryText = *pStr;
const Rectangle aMaxTextRect( CalcMaxTextRect( pEntry ) );
Rectangle aBound( GetEntryBoundRect( pEntry ) );
if( pEntryPos )
aBound.SetPos( *pEntryPos );
Rectangle aTextRect( aMaxTextRect );
if( !bEdit )
aTextRect = pView->GetTextRect( aTextRect, aEntryText, nCurTextDrawFlags );
Size aTextSize( aTextRect.GetSize() );
Point aPos( aBound.TopLeft() );
long nBoundWidth = aBound.GetWidth();
long nBoundHeight = aBound.GetHeight();
switch( nWinBits & (VIEWMODE_MASK) )
{
case WB_ICON:
aPos.Y() += aImageSize.Height();
aPos.Y() += VER_DIST_BMP_STRING;
// at little more space when editing
if( bEdit )
{
// +20%
long nMinWidth = (( (aImageSize.Width()*10) / 100 ) * 2 ) +
aImageSize.Width();
if( nMinWidth > nBoundWidth )
nMinWidth = nBoundWidth;
if( aTextSize.Width() < nMinWidth )
aTextSize.Width() = nMinWidth;
// when editing, overlap with the area below is allowed
Size aOptSize = aMaxTextRect.GetSize();
if( aOptSize.Height() > aTextSize.Height() )
aTextSize.Height() = aOptSize.Height();
}
aPos.X() += (nBoundWidth - aTextSize.Width()) / 2;
break;
case WB_SMALLICON:
case WB_DETAILS:
aPos.X() += aImageSize.Width();
aPos.X() += HOR_DIST_BMP_STRING;
aPos.Y() += (nBoundHeight - aTextSize.Height()) / 2;
break;
}
return Rectangle( aPos, aTextSize );
}
long SvxIconChoiceCtrl_Impl::CalcBoundingWidth( SvxIconChoiceCtrlEntry* pEntry ) const
{
long nStringWidth = GetItemSize( pEntry, IcnViewFieldTypeText ).Width();
// nStringWidth += 2*LROFFS_TEXT;
long nWidth = 0;
switch( nWinBits & (VIEWMODE_MASK) )
{
case WB_ICON:
nWidth = std::max( nStringWidth, aImageSize.Width() );
break;
case WB_SMALLICON:
case WB_DETAILS:
nWidth = aImageSize.Width();
nWidth += HOR_DIST_BMP_STRING;
nWidth += nStringWidth;
break;
}
return nWidth;
}
long SvxIconChoiceCtrl_Impl::CalcBoundingHeight( SvxIconChoiceCtrlEntry* pEntry ) const
{
long nStringHeight = GetItemSize( pEntry, IcnViewFieldTypeText).Height();
long nHeight = 0;
switch( nWinBits & (VIEWMODE_MASK) )
{
case WB_ICON:
nHeight = aImageSize.Height();
nHeight += VER_DIST_BMP_STRING;
nHeight += nStringHeight;
break;
case WB_SMALLICON:
case WB_DETAILS:
nHeight = std::max( aImageSize.Height(), nStringHeight );
break;
}
if( nHeight > nMaxBoundHeight )
{
((SvxIconChoiceCtrl_Impl*)this)->nMaxBoundHeight = nHeight;
((SvxIconChoiceCtrl_Impl*)this)->aHorSBar.SetLineSize( GetScrollBarLineSize() );
((SvxIconChoiceCtrl_Impl*)this)->aVerSBar.SetLineSize( GetScrollBarLineSize() );
}
return nHeight;
}
Size SvxIconChoiceCtrl_Impl::CalcBoundingSize( SvxIconChoiceCtrlEntry* pEntry ) const
{
return Size( CalcBoundingWidth( pEntry ),
CalcBoundingHeight( pEntry ) );
}
void SvxIconChoiceCtrl_Impl::RecalcAllBoundingRectsSmart()
{
nMaxBoundHeight = 0;
pZOrderList->clear();
size_t nCur;
SvxIconChoiceCtrlEntry* pEntry;
const size_t nCount = aEntries.size();
if( !IsAutoArrange() || !pHead )
{
for( nCur = 0; nCur < nCount; nCur++ )
{
pEntry = aEntries[ nCur ];
if( IsBoundingRectValid( pEntry->aRect ))
{
Size aBoundSize( pEntry->aRect.GetSize() );
if( aBoundSize.Height() > nMaxBoundHeight )
nMaxBoundHeight = aBoundSize.Height();
}
else
FindBoundingRect( pEntry );
pZOrderList->push_back( pEntry );
}
}
else
{
nCur = 0;
pEntry = pHead;
while( nCur != nCount )
{
DBG_ASSERT(pEntry->pflink&&pEntry->pblink,"SvxIconChoiceCtrl_Impl::RecalcAllBoundingRect > Bad link(s)");
if( IsBoundingRectValid( pEntry->aRect ))
{
Size aBoundSize( pEntry->aRect.GetSize() );
if( aBoundSize.Height() > nMaxBoundHeight )
nMaxBoundHeight = aBoundSize.Height();
}
else
FindBoundingRect( pEntry );
pZOrderList->push_back( pEntry );
pEntry = pEntry->pflink;
nCur++;
}
}
AdjustScrollBars();
}
void SvxIconChoiceCtrl_Impl::FindBoundingRect( SvxIconChoiceCtrlEntry* pEntry )
{
DBG_ASSERT(!pEntry->IsPosLocked(),"Locked entry pos in FindBoundingRect");
if( pEntry->IsPosLocked() && IsBoundingRectValid( pEntry->aRect) )
{
AdjustVirtSize( pEntry->aRect );
return;
}
Size aSize( CalcBoundingSize( pEntry ) );
Point aPos(pGridMap->GetGridRect(pGridMap->GetUnoccupiedGrid(true)).TopLeft());
SetBoundingRect_Impl( pEntry, aPos, aSize );
}
void SvxIconChoiceCtrl_Impl::SetBoundingRect_Impl( SvxIconChoiceCtrlEntry* pEntry, const Point& rPos,
const Size& /*rBoundingSize*/ )
{
Rectangle aGridRect( rPos, Size(nGridDX, nGridDY) );
pEntry->aGridRect = aGridRect;
Center( pEntry );
AdjustVirtSize( pEntry->aRect );
pGridMap->OccupyGrids( pEntry );
}
void SvxIconChoiceCtrl_Impl::SetCursor( SvxIconChoiceCtrlEntry* pEntry, bool bSyncSingleSelection,
bool bShowFocusAsync )
{
if( pEntry == pCursor )
{
if( pCursor && eSelectionMode == SINGLE_SELECTION && bSyncSingleSelection &&
!pCursor->IsSelected() )
SelectEntry( pCursor, true, true );
return;
}
ShowCursor( false );
SvxIconChoiceCtrlEntry* pOldCursor = pCursor;
pCursor = pEntry;
if( pOldCursor )
{
pOldCursor->ClearFlags( ICNVIEW_FLAG_FOCUSED );
if( eSelectionMode == SINGLE_SELECTION && bSyncSingleSelection )
SelectEntry( pOldCursor, false, true ); // deselect old cursor
}
if( pCursor )
{
ToTop( pCursor );
pCursor->SetFlags( ICNVIEW_FLAG_FOCUSED );
if( eSelectionMode == SINGLE_SELECTION && bSyncSingleSelection )
SelectEntry( pCursor, true, true );
if( !bShowFocusAsync )
ShowCursor( true );
else
{
if( !nUserEventShowCursor )
nUserEventShowCursor =
Application::PostUserEvent( LINK( this, SvxIconChoiceCtrl_Impl, UserEventHdl),
EVENTID_SHOW_CURSOR );
}
}
}
void SvxIconChoiceCtrl_Impl::ShowCursor( bool bShow )
{
if( !pCursor || !bShow || !pView->HasFocus() )
{
pView->HideFocus();
return;
}
Rectangle aRect ( CalcFocusRect( pCursor ) );
/*pView->*/ShowFocus( aRect );
}
void SvxIconChoiceCtrl_Impl::HideDDIcon()
{
pView->Update();
ImpHideDDIcon();
pDDBufDev = pDDDev;
pDDDev = 0;
}
void SvxIconChoiceCtrl_Impl::ImpHideDDIcon()
{
if( pDDDev )
{
Size aSize( pDDDev->GetOutputSizePixel() );
// restore pView
pView->DrawOutDev( aDDLastRectPos, aSize, Point(), aSize, *pDDDev );
}
}
bool SvxIconChoiceCtrl_Impl::HandleScrollCommand( const CommandEvent& rCmd )
{
Rectangle aDocRect( GetDocumentRect() );
Rectangle aVisRect( GetVisibleRect() );
if( aVisRect.IsInside( aDocRect ))
return false;
Size aDocSize( aDocRect.GetSize() );
Size aVisSize( aVisRect.GetSize() );
bool bHor = aDocSize.Width() > aVisSize.Width();
bool bVer = aDocSize.Height() > aVisSize.Height();
long nScrollDX = 0, nScrollDY = 0;
switch( rCmd.GetCommand() )
{
case COMMAND_STARTAUTOSCROLL:
{
pView->EndTracking();
sal_uInt16 nScrollFlags = 0;
if( bHor )
nScrollFlags |= AUTOSCROLL_HORZ;
if( bVer )
nScrollFlags |= AUTOSCROLL_VERT;
if( nScrollFlags )
{
pView->StartAutoScroll( nScrollFlags );
return true;
}
}
break;
case COMMAND_WHEEL:
{
const CommandWheelData* pData = rCmd.GetWheelData();
if( pData && (CommandWheelMode::SCROLL == pData->GetMode()) && !pData->IsHorz() )
{
sal_uLong nScrollLines = pData->GetScrollLines();
if( nScrollLines == COMMAND_WHEEL_PAGESCROLL )
{
nScrollDY = GetScrollBarPageSize( aVisSize.Width() );
if( pData->GetDelta() < 0 )
nScrollDY *= -1;
}
else
{
nScrollDY = pData->GetNotchDelta() * (long)nScrollLines;
nScrollDY *= GetScrollBarLineSize();
}
}
}
break;
case COMMAND_AUTOSCROLL:
{
const CommandScrollData* pData = rCmd.GetAutoScrollData();
if( pData )
{
nScrollDX = pData->GetDeltaX() * GetScrollBarLineSize();
nScrollDY = pData->GetDeltaY() * GetScrollBarLineSize();
}
}
break;
}
if( nScrollDX || nScrollDY )
{
aVisRect.Top() -= nScrollDY;
aVisRect.Bottom() -= nScrollDY;
aVisRect.Left() -= nScrollDX;
aVisRect.Right() -= nScrollDX;
MakeVisible( aVisRect );
return true;
}
return false;
}
void SvxIconChoiceCtrl_Impl::Command( const CommandEvent& rCEvt )
{
// scroll mouse event?
if( (rCEvt.GetCommand() == COMMAND_WHEEL) ||
(rCEvt.GetCommand() == COMMAND_STARTAUTOSCROLL) ||
(rCEvt.GetCommand() == COMMAND_AUTOSCROLL) )
{
if( HandleScrollCommand( rCEvt ) )
return;
}
}
void SvxIconChoiceCtrl_Impl::ToTop( SvxIconChoiceCtrlEntry* pEntry )
{
if( !pZOrderList->empty()
&& pEntry != pZOrderList->back()
) {
for(
SvxIconChoiceCtrlEntryList_impl::iterator it = pZOrderList->begin();
it != pZOrderList->end();
++it
) {
if ( *it == pEntry )
{
pZOrderList->erase( it );
pZOrderList->push_back( pEntry );
break;
}
}
}
}
void SvxIconChoiceCtrl_Impl::ClipAtVirtOutRect( Rectangle& rRect ) const
{
if( rRect.Bottom() >= aVirtOutputSize.Height() )
rRect.Bottom() = aVirtOutputSize.Height() - 1;
if( rRect.Right() >= aVirtOutputSize.Width() )
rRect.Right() = aVirtOutputSize.Width() - 1;
if( rRect.Top() < 0 )
rRect.Top() = 0;
if( rRect.Left() < 0 )
rRect.Left() = 0;
}
// rRect: area of the document (in document coordinates) that we want to make
// visible
// bScrBar == true: rectangle was calculated because of a scrollbar event
void SvxIconChoiceCtrl_Impl::MakeVisible( const Rectangle& rRect, bool bScrBar,
bool bCallRectChangedHdl )
{
Rectangle aVirtRect( rRect );
ClipAtVirtOutRect( aVirtRect );
Point aOrigin( pView->GetMapMode().GetOrigin() );
// convert to document coordinate
aOrigin *= -1;
Rectangle aOutputArea( GetOutputRect() );
if( aOutputArea.IsInside( aVirtRect ) )
return; // is already visible
long nDy;
if( aVirtRect.Top() < aOutputArea.Top() )
{
// scroll up (nDy < 0)
nDy = aVirtRect.Top() - aOutputArea.Top();
}
else if( aVirtRect.Bottom() > aOutputArea.Bottom() )
{
// scroll down (nDy > 0)
nDy = aVirtRect.Bottom() - aOutputArea.Bottom();
}
else
nDy = 0;
long nDx;
if( aVirtRect.Left() < aOutputArea.Left() )
{
// scroll to the left (nDx < 0)
nDx = aVirtRect.Left() - aOutputArea.Left();
}
else if( aVirtRect.Right() > aOutputArea.Right() )
{
// scroll to the right (nDx > 0)
nDx = aVirtRect.Right() - aOutputArea.Right();
}
else
nDx = 0;
aOrigin.X() += nDx;
aOrigin.Y() += nDy;
aOutputArea.SetPos( aOrigin );
if( GetUpdateMode() )
{
HideDDIcon();
pView->Update();
ShowCursor( false );
}
// invert origin for SV (so we can scroll/paint using document coordinates)
aOrigin *= -1;
SetOrigin( aOrigin );
bool bScrollable = pView->GetBackground().IsScrollable();
if( pView->HasBackground() && !bScrollable )
{
Rectangle aRect( GetOutputRect());
Wallpaper aPaper( pView->GetBackground() );
aPaper.SetRect( aRect );
pView->SetBackground( aPaper );
}
if( bScrollable && GetUpdateMode() )
{
// scroll in reverse direction!
pView->Control::Scroll( -nDx, -nDy, aOutputArea,
SCROLL_NOCHILDREN | SCROLL_USECLIPREGION | SCROLL_CLIP );
}
else
pView->Invalidate(INVALIDATE_NOCHILDREN);
if( aHorSBar.IsVisible() || aVerSBar.IsVisible() )
{
if( !bScrBar )
{
aOrigin *= -1;
// correct thumbs
if(aHorSBar.IsVisible() && aHorSBar.GetThumbPos() != aOrigin.X())
aHorSBar.SetThumbPos( aOrigin.X() );
if(aVerSBar.IsVisible() && aVerSBar.GetThumbPos() != aOrigin.Y())
aVerSBar.SetThumbPos( aOrigin.Y() );
}
}
if( GetUpdateMode() )
ShowCursor( true );
// check if we still need scrollbars
CheckScrollBars();
if( bScrollable && GetUpdateMode() )
pView->Update();
// If the requested area can not be made completely visible, the
// Vis-Rect-Changed handler is called in any case. This case may occur e.g.
// if only few pixels of the lower border are invisible, but a scrollbar has
// a larger line size.
if( bCallRectChangedHdl || GetOutputRect() != rRect )
VisRectChanged();
}
sal_uLong SvxIconChoiceCtrl_Impl::GetSelectionCount() const
{
if( (nWinBits & WB_HIGHLIGHTFRAME) && pCurHighlightFrame )
return 1;
return nSelectionCount;
}
void SvxIconChoiceCtrl_Impl::ToggleSelection( SvxIconChoiceCtrlEntry* pEntry )
{
bool bSel;
if( pEntry->IsSelected() )
bSel = false;
else
bSel = true;
SelectEntry( pEntry, bSel, true, true );
}
void SvxIconChoiceCtrl_Impl::DeselectAllBut( SvxIconChoiceCtrlEntry* pThisEntryNot,
bool bPaintSync )
{
ClearSelectedRectList();
// TODO: work through z-order list, if necessary!
size_t nCount = aEntries.size();
for( size_t nCur = 0; nCur < nCount; nCur++ )
{
SvxIconChoiceCtrlEntry* pEntry = aEntries[ nCur ];
if( pEntry != pThisEntryNot && pEntry->IsSelected() )
SelectEntry( pEntry, false, true, true, bPaintSync );
}
pAnchor = 0;
nFlags &= (~F_ADD_MODE);
}
Size SvxIconChoiceCtrl_Impl::GetMinGrid() const
{
Size aMinSize( aImageSize );
aMinSize.Width() += 2 * LROFFS_BOUND;
aMinSize.Height() += TBOFFS_BOUND; // single offset is enough (FileDlg)
OUString aStrDummy( "XXX" );
Size aTextSize( pView->GetTextWidth( aStrDummy ), pView->GetTextHeight() );
if( nWinBits & WB_ICON )
{
aMinSize.Height() += VER_DIST_BMP_STRING;
aMinSize.Height() += aTextSize.Height();
}
else
{
aMinSize.Width() += HOR_DIST_BMP_STRING;
aMinSize.Width() += aTextSize.Width();
}
return aMinSize;
}
void SvxIconChoiceCtrl_Impl::SetGrid( const Size& rSize )
{
Size aSize( rSize );
Size aMinSize( GetMinGrid() );
if( aSize.Width() < aMinSize.Width() )
aSize.Width() = aMinSize.Width();
if( aSize.Height() < aMinSize.Height() )
aSize.Height() = aMinSize.Height();
nGridDX = aSize.Width();
// HACK: Detail mode is not yet fully implemented, this workaround makes it
// fly with a single column
if( nWinBits & WB_DETAILS )
{
const SvxIconChoiceCtrlColumnInfo* pCol = GetColumn( 0 );
if( pCol )
((SvxIconChoiceCtrlColumnInfo*)pCol)->SetWidth( nGridDX );
}
nGridDY = aSize.Height();
SetDefaultTextSize();
}
// Calculates the maximum size that the text rectangle may use within its
// bounding rectangle. In WB_ICON mode with IcnShowTextFull, Bottom is set to
// LONG_MAX.
Rectangle SvxIconChoiceCtrl_Impl::CalcMaxTextRect( const SvxIconChoiceCtrlEntry* pEntry ) const
{
Rectangle aBoundRect;
// avoid infinite recursion: don't calculate the bounding rectangle here
if( IsBoundingRectValid( pEntry->aRect ) )
aBoundRect = pEntry->aRect;
else
aBoundRect = pEntry->aGridRect;
Rectangle aBmpRect( ((SvxIconChoiceCtrl_Impl*)this)->CalcBmpRect(
(SvxIconChoiceCtrlEntry*)pEntry ) );
if( nWinBits & WB_ICON )
{
aBoundRect.Top() = aBmpRect.Bottom();
aBoundRect.Top() += VER_DIST_BMP_STRING;
if( aBoundRect.Top() > aBoundRect.Bottom())
aBoundRect.Top() = aBoundRect.Bottom();
aBoundRect.Left() += LROFFS_BOUND;
aBoundRect.Left()++;
aBoundRect.Right() -= LROFFS_BOUND;
aBoundRect.Right()--;
if( aBoundRect.Left() > aBoundRect.Right())
aBoundRect.Left() = aBoundRect.Right();
if( GetEntryTextModeSmart( pEntry ) == IcnShowTextFull )
aBoundRect.Bottom() = LONG_MAX;
}
else
{
aBoundRect.Left() = aBmpRect.Right();
aBoundRect.Left() += HOR_DIST_BMP_STRING;
aBoundRect.Right() -= LROFFS_BOUND;
if( aBoundRect.Left() > aBoundRect.Right() )
aBoundRect.Left() = aBoundRect.Right();
long nHeight = aBoundRect.GetSize().Height();
nHeight = nHeight - aDefaultTextSize.Height();
nHeight /= 2;
aBoundRect.Top() += nHeight;
aBoundRect.Bottom() -= nHeight;
}
return aBoundRect;
}
void SvxIconChoiceCtrl_Impl::SetDefaultTextSize()
{
long nDY = nGridDY;
nDY -= aImageSize.Height();
nDY -= VER_DIST_BMP_STRING;
nDY -= 2*TBOFFS_BOUND;
if( nDY <= 0 )
nDY = 2;
long nDX = nGridDX;
nDX -= 2*LROFFS_BOUND;
nDX -= 2;
if( nDX <= 0 )
nDX = 2;
long nHeight = pView->GetTextHeight();
if( nDY < nHeight )
nDY = nHeight;
aDefaultTextSize = Size( nDX, nDY );
}
void SvxIconChoiceCtrl_Impl::Center( SvxIconChoiceCtrlEntry* pEntry ) const
{
pEntry->aRect = pEntry->aGridRect;
Size aSize( CalcBoundingSize( pEntry ) );
if( nWinBits & WB_ICON )
{
// center horizontally
long nBorder = pEntry->aGridRect.GetWidth() - aSize.Width();
pEntry->aRect.Left() += nBorder / 2;
pEntry->aRect.Right() -= nBorder / 2;
}
// center vertically
pEntry->aRect.Bottom() = pEntry->aRect.Top() + aSize.Height();
}
// The deltas are the offsets by which the view is moved on the document.
// left, up: offsets < 0
// right, down: offsets > 0
void SvxIconChoiceCtrl_Impl::Scroll( long nDeltaX, long nDeltaY, bool bScrollBar )
{
const MapMode& rMapMode = pView->GetMapMode();
Point aOrigin( rMapMode.GetOrigin() );
// convert to document coordinate
aOrigin *= -1;
aOrigin.Y() += nDeltaY;
aOrigin.X() += nDeltaX;
Rectangle aRect( aOrigin, aOutputSize );
MakeVisible( aRect, bScrollBar );
}
const Size& SvxIconChoiceCtrl_Impl::GetItemSize( SvxIconChoiceCtrlEntry*,
IcnViewFieldType eItem ) const
{
if( eItem == IcnViewFieldTypeText )
return aDefaultTextSize;
return aImageSize;
}
Rectangle SvxIconChoiceCtrl_Impl::CalcFocusRect( SvxIconChoiceCtrlEntry* pEntry )
{
Rectangle aTextRect( CalcTextRect( pEntry ) );
Rectangle aBoundRect( GetEntryBoundRect( pEntry ) );
return Rectangle(
aBoundRect.Left(), aBoundRect.Top() - 1, aBoundRect.Right() - 1,
aTextRect.Bottom() + 1);
}
// the hot spot is the inner 50% of the rectangle
static Rectangle GetHotSpot( const Rectangle& rRect )
{
Rectangle aResult( rRect );
aResult.Justify();
Size aSize( rRect.GetSize() );
long nDelta = aSize.Width() / 4;
aResult.Left() += nDelta;
aResult.Right() -= nDelta;
nDelta = aSize.Height() / 4;
aResult.Top() += nDelta;
aResult.Bottom() -= nDelta;
return aResult;
}
void SvxIconChoiceCtrl_Impl::SelectRect( SvxIconChoiceCtrlEntry* pEntry1, SvxIconChoiceCtrlEntry* pEntry2,
bool bAdd, std::vector<Rectangle*>* pOtherRects )
{
DBG_ASSERT(pEntry1 && pEntry2,"SelectEntry: Invalid Entry-Ptr");
Rectangle aRect( GetEntryBoundRect( pEntry1 ) );
aRect.Union( GetEntryBoundRect( pEntry2 ) );
SelectRect( aRect, bAdd, pOtherRects );
}
void SvxIconChoiceCtrl_Impl::SelectRect( const Rectangle& rRect, bool bAdd,
std::vector<Rectangle*>* pOtherRects )
{
aCurSelectionRect = rRect;
if( !pZOrderList || !pZOrderList->size() )
return;
// set flag, so ToTop won't be called in Select
bool bAlreadySelectingRect = nFlags & F_SELECTING_RECT ? true : false;
nFlags |= F_SELECTING_RECT;
CheckBoundingRects();
pView->Update();
const size_t nCount = pZOrderList->size();
Rectangle aRect( rRect );
aRect.Justify();
bool bCalcOverlap = (bAdd && pOtherRects && !pOtherRects->empty());
bool bResetClipRegion = false;
if( !pView->IsClipRegion() )
{
bResetClipRegion = true;
pView->SetClipRegion(vcl::Region(GetOutputRect()));
}
for( size_t nPos = 0; nPos < nCount; nPos++ )
{
SvxIconChoiceCtrlEntry* pEntry = (*pZOrderList)[ nPos ];
if( !IsBoundingRectValid( pEntry->aRect ))
FindBoundingRect( pEntry );
Rectangle aBoundRect( GetHotSpot( pEntry->aRect ) );
bool bSelected = pEntry->IsSelected();
bool bOverlaps;
if( bCalcOverlap )
bOverlaps = IsOver( pOtherRects, aBoundRect );
else
bOverlaps = false;
bool bOver = aRect.IsOver( aBoundRect );
if( bOver && !bOverlaps )
{
// is inside the new selection rectangle and outside of any old one
// => select
if( !bSelected )
SelectEntry( pEntry, true, true, true );
}
else if( !bAdd )
{
// is outside of the selection rectangle
// => deselect
if( bSelected )
SelectEntry( pEntry, false, true, true );
}
else if( bAdd && bOverlaps )
{
// The entry is inside an old (=>span multiple rectangles with Ctrl)
// selection rectangle.
// There is still a bug here! The selection status of an entry in a
// previous rectangle has to be restored, if it was touched by the
// current selection rectangle but is not inside it any more.
// For simplicity's sake, let's assume that all entries in the old
// rectangles were correctly selected. It is wrong to just deselect
// the intersection.
// Possible solution: remember a snapshot of the selection before
// spanning the rectangle.
if( aBoundRect.IsOver( rRect))
{
// deselect intersection between old rectangles and current rectangle
if( bSelected )
SelectEntry( pEntry, false, true, true );
}
else
{
// select entry of an old rectangle
if( !bSelected )
SelectEntry( pEntry, true, true, true );
}
}
else if( !bOver && bSelected )
{
// this entry is completely outside the rectangle => deselect it
SelectEntry( pEntry, false, true, true );
}
}
if( !bAlreadySelectingRect )
nFlags &= ~F_SELECTING_RECT;
pView->Update();
if( bResetClipRegion )
pView->SetClipRegion();
}
void SvxIconChoiceCtrl_Impl::SelectRange(
SvxIconChoiceCtrlEntry* pStart,
SvxIconChoiceCtrlEntry* pEnd,
bool bAdd )
{
sal_uLong nFront = GetEntryListPos( pStart );
sal_uLong nBack = GetEntryListPos( pEnd );
sal_uLong nFirst = std::min( nFront, nBack );
sal_uLong nLast = std::max( nFront, nBack );
sal_uLong i;
SvxIconChoiceCtrlEntry* pEntry;
if ( ! bAdd )
{
// deselect everything before the first entry if not in
// adding mode
for ( i=0; i<nFirst; i++ )
{
pEntry = GetEntry( i );
if( pEntry->IsSelected() )
SelectEntry( pEntry, false, true, true, true );
}
}
// select everything between nFirst and nLast
for ( i=nFirst; i<=nLast; i++ )
{
pEntry = GetEntry( i );
if( ! pEntry->IsSelected() )
SelectEntry( pEntry, true, true, true, true );
}
if ( ! bAdd )
{
// deselect everything behind the last entry if not in
// adding mode
sal_uLong nEnd = GetEntryCount();
for ( ; i<nEnd; i++ )
{
pEntry = GetEntry( i );
if( pEntry->IsSelected() )
SelectEntry( pEntry, false, true, true, true );
}
}
}
bool SvxIconChoiceCtrl_Impl::IsOver( std::vector<Rectangle*>* pRectList, const Rectangle& rBoundRect ) const
{
const sal_uInt16 nCount = pRectList->size();
for( sal_uInt16 nCur = 0; nCur < nCount; nCur++ )
{
Rectangle* pRect = (*pRectList)[ nCur ];
if( rBoundRect.IsOver( *pRect ))
return true;
}
return false;
}
void SvxIconChoiceCtrl_Impl::AddSelectedRect( SvxIconChoiceCtrlEntry* pEntry1,
SvxIconChoiceCtrlEntry* pEntry2 )
{
DBG_ASSERT(pEntry1 && pEntry2,"SelectEntry: Invalid Entry-Ptr");
Rectangle aRect( GetEntryBoundRect( pEntry1 ) );
aRect.Union( GetEntryBoundRect( pEntry2 ) );
AddSelectedRect( aRect );
}
void SvxIconChoiceCtrl_Impl::AddSelectedRect( const Rectangle& rRect )
{
Rectangle* pRect = new Rectangle( rRect );
pRect->Justify();
aSelectedRectList.push_back( pRect );
}
void SvxIconChoiceCtrl_Impl::ClearSelectedRectList()
{
const sal_uInt16 nCount = aSelectedRectList.size();
for( sal_uInt16 nCur = 0; nCur < nCount; nCur++ )
{
Rectangle* pRect = aSelectedRectList[ nCur ];
delete pRect;
}
aSelectedRectList.clear();
}
IMPL_LINK_NOARG(SvxIconChoiceCtrl_Impl, AutoArrangeHdl)
{
aAutoArrangeIdle.Stop();
Arrange( IsAutoArrange() );
return 0;
}
IMPL_LINK_NOARG(SvxIconChoiceCtrl_Impl, VisRectChangedHdl)
{
aVisRectChangedIdle.Stop();
pView->VisibleRectChanged();
return 0;
}
IMPL_LINK_NOARG(SvxIconChoiceCtrl_Impl, DocRectChangedHdl)
{
aDocRectChangedIdle.Stop();
pView->DocumentRectChanged();
return 0;
}
bool SvxIconChoiceCtrl_Impl::IsTextHit( SvxIconChoiceCtrlEntry* pEntry, const Point& rDocPos )
{
Rectangle aRect( CalcTextRect( pEntry ));
if( aRect.IsInside( rDocPos ) )
return true;
return false;
}
IMPL_LINK_NOARG(SvxIconChoiceCtrl_Impl, EditTimeoutHdl)
{
SvxIconChoiceCtrlEntry* pEntry = GetCurEntry();
if( bEntryEditingEnabled && pEntry &&
pEntry->IsSelected())
{
if( pView->EditingEntry( pEntry ))
EditEntry( pEntry );
}
return 0;
}
// Function to align entries to the grid
// pStart == 0: align all entries
// else: align all entries of the row from pStart on (including pStart)
void SvxIconChoiceCtrl_Impl::AdjustEntryAtGrid( SvxIconChoiceCtrlEntry* pStart )
{
IconChoiceMap aLists;
pImpCursor->CreateGridAjustData( aLists, pStart );
for (IconChoiceMap::const_iterator iter = aLists.begin();
iter != aLists.end(); ++iter)
{
AdjustAtGrid(iter->second, pStart);
}
IcnCursor_Impl::DestroyGridAdjustData( aLists );
CheckScrollBars();
}
// align a row, might expand width, doesn't break the line
void SvxIconChoiceCtrl_Impl::AdjustAtGrid( const SvxIconChoiceCtrlEntryPtrVec& rRow, SvxIconChoiceCtrlEntry* pStart )
{
if( rRow.empty() )
return;
bool bGo;
if( !pStart )
bGo = true;
else
bGo = false;
long nCurRight = 0;
for( sal_uInt16 nCur = 0; nCur < rRow.size(); nCur++ )
{
SvxIconChoiceCtrlEntry* pCur = rRow[ nCur ];
if( !bGo && pCur == pStart )
bGo = true;
// SvIcnVwDataEntry* pViewData = ICNVIEWDATA(pCur);
// Decisive (for our eye) is the bitmap, else, the entry might jump too
// much within long texts.
const Rectangle& rBoundRect = GetEntryBoundRect( pCur );
Rectangle aCenterRect( CalcBmpRect( pCur, 0 ));
if( bGo && !pCur->IsPosLocked() )
{
long nWidth = aCenterRect.GetSize().Width();
Point aNewPos( AdjustAtGrid( aCenterRect, rBoundRect ) );
while( aNewPos.X() < nCurRight )
aNewPos.X() += nGridDX;
if( aNewPos != rBoundRect.TopLeft() )
{
SetEntryPos( pCur, aNewPos );
pCur->SetFlags( ICNVIEW_FLAG_POS_MOVED );
nFlags |= F_MOVED_ENTRIES;
}
nCurRight = aNewPos.X() + nWidth;
}
else
{
nCurRight = rBoundRect.Right();
}
}
}
// Aligns a rectangle to the grid, but doesn't guarantee that the new position
// is vacant. The position can be used for SetEntryPos. The CenterRect describes
// a part of the bounding rectangle that is used for calculating the target
// rectangle.
Point SvxIconChoiceCtrl_Impl::AdjustAtGrid( const Rectangle& rCenterRect,
const Rectangle& rBoundRect ) const
{
Point aPos( rCenterRect.TopLeft() );
Size aSize( rCenterRect.GetSize() );
aPos.X() -= LROFFS_WINBORDER;
aPos.Y() -= TBOFFS_WINBORDER;
// align (the center of the rectangle is the reference)
short nGridX = (short)((aPos.X()+(aSize.Width()/2)) / nGridDX);
short nGridY = (short)((aPos.Y()+(aSize.Height()/2)) / nGridDY);
aPos.X() = nGridX * nGridDX;
aPos.Y() = nGridY * nGridDY;
// horizontal center
aPos.X() += (nGridDX - rBoundRect.GetSize().Width() ) / 2;
aPos.X() += LROFFS_WINBORDER;
aPos.Y() += TBOFFS_WINBORDER;
return aPos;
}
#ifdef DBG_UTIL
void SvxIconChoiceCtrl_Impl::SetEntryTextMode( SvxIconChoiceCtrlTextMode eMode, SvxIconChoiceCtrlEntry* pEntry )
{
if( !pEntry )
{
if( eTextMode != eMode )
{
if( eTextMode == IcnShowTextDontKnow )
eTextMode = IcnShowTextShort;
eTextMode = eMode;
Arrange( true );
}
}
else
{
if( pEntry->eTextMode != eMode )
{
pEntry->eTextMode = eMode;
InvalidateEntry( pEntry );
pView->Invalidate( GetEntryBoundRect( pEntry ) );
AdjustVirtSize( pEntry->aRect );
}
}
}
#endif
SvxIconChoiceCtrlTextMode SvxIconChoiceCtrl_Impl::GetEntryTextModeSmart( const SvxIconChoiceCtrlEntry* pEntry ) const
{
DBG_ASSERT(pEntry,"GetEntryTextModeSmart: Entry not set");
SvxIconChoiceCtrlTextMode eMode = pEntry->GetTextMode();
if( eMode == IcnShowTextDontKnow )
return eTextMode;
return eMode;
}
// Draw my own focusrect, because the focusrect of the outputdevice has got the inverted color
// of the background. But what will we see, if the backgroundcolor is gray ? - We will see
// a gray focusrect on a gray background !!!
void SvxIconChoiceCtrl_Impl::ShowFocus ( Rectangle& rRect )
{
Color aBkgColor ( pView->GetBackground().GetColor() );
Color aPenColor;
sal_uInt16 nColor = ( aBkgColor.GetRed() + aBkgColor.GetGreen() + aBkgColor.GetBlue() ) / 3;
if ( nColor > 128 )
aPenColor.SetColor ( COL_BLACK );
else
aPenColor.SetColor( COL_WHITE );
aFocus.bOn = true;
aFocus.aPenColor = aPenColor;
aFocus.aRect = rRect;
}
void SvxIconChoiceCtrl_Impl::DrawFocusRect ( OutputDevice* pOut )
{
pOut->SetLineColor( aFocus.aPenColor );
pOut->SetFillColor();
Polygon aPolygon ( aFocus.aRect );
LineInfo aLineInfo ( LINE_DASH );
aLineInfo.SetDashLen ( 1 );
aLineInfo.SetDotLen ( 1L );
aLineInfo.SetDistance ( 1L );
aLineInfo.SetDotCount ( 1 );
pOut->DrawPolyLine ( aPolygon, aLineInfo );
}
bool SvxIconChoiceCtrl_Impl::IsMnemonicChar( sal_Unicode cChar, sal_uLong& rPos ) const
{
bool bRet = false;
const vcl::I18nHelper& rI18nHelper = Application::GetSettings().GetUILocaleI18nHelper();
size_t nEntryCount = GetEntryCount();
for ( size_t i = 0; i < nEntryCount; ++i )
{
if ( rI18nHelper.MatchMnemonic( GetEntry( i )->GetText(), cChar ) )
{
bRet = true;
rPos = i;
break;
}
}
return bRet;
}
IMPL_LINK(SvxIconChoiceCtrl_Impl, UserEventHdl, void*, nId )
{
if( nId == EVENTID_ADJUST_SCROLLBARS )
{
nUserEventAdjustScrBars = 0;
AdjustScrollBars();
}
else if( nId == EVENTID_SHOW_CURSOR )
{
nUserEventShowCursor = 0;
ShowCursor( true );
}
return 0;
}
void SvxIconChoiceCtrl_Impl::CancelUserEvents()
{
if( nUserEventAdjustScrBars )
{
Application::RemoveUserEvent( nUserEventAdjustScrBars );
nUserEventAdjustScrBars = 0;
}
if( nUserEventShowCursor )
{
Application::RemoveUserEvent( nUserEventShowCursor );
nUserEventShowCursor = 0;
}
}
void SvxIconChoiceCtrl_Impl::InvalidateEntry( SvxIconChoiceCtrlEntry* pEntry )
{
if( pEntry == pCursor )
ShowCursor( false );
pView->Invalidate( pEntry->aRect );
Center( pEntry );
pView->Invalidate( pEntry->aRect );
if( pEntry == pCursor )
ShowCursor( true );
}
void SvxIconChoiceCtrl_Impl::EditEntry( SvxIconChoiceCtrlEntry* pEntry )
{
DBG_ASSERT(pEntry,"EditEntry: Entry not set");
if( !pEntry )
return;
StopEntryEditing( true );
DELETEZ(pEdit);
SetNoSelection();
pCurEditedEntry = pEntry;
OUString aEntryText( pView->GetEntryText( pEntry, true ) );
Rectangle aRect( CalcTextRect( pEntry, 0, true, &aEntryText ) );
MakeVisible( aRect );
Point aPos( aRect.TopLeft() );
aPos = pView->GetPixelPos( aPos );
aRect.SetPos( aPos );
pView->HideFocus();
pEdit = new IcnViewEdit_Impl(
pView,
aRect.TopLeft(),
aRect.GetSize(),
aEntryText,
LINK( this, SvxIconChoiceCtrl_Impl, TextEditEndedHdl ) );
}
IMPL_LINK_NOARG(SvxIconChoiceCtrl_Impl, TextEditEndedHdl)
{
DBG_ASSERT(pEdit,"TextEditEnded: pEdit not set");
if( !pEdit )
{
pCurEditedEntry = 0;
return 0;
}
DBG_ASSERT(pCurEditedEntry,"TextEditEnded: pCurEditedEntry not set");
if( !pCurEditedEntry )
{
pEdit->Hide();
if( pEdit->IsGrabFocus() )
pView->GrabFocus();
return 0;
}
OUString aText;
if ( !pEdit->EditingCanceled() )
aText = pEdit->GetText();
else
aText = pEdit->GetSavedValue();
if( pView->EditedEntry( pCurEditedEntry, aText, pEdit->EditingCanceled() ) )
InvalidateEntry( pCurEditedEntry );
if( !GetSelectionCount() )
SelectEntry( pCurEditedEntry, true );
pEdit->Hide();
if( pEdit->IsGrabFocus() )
pView->GrabFocus();
// The edit can not be deleted here, because it is not within a handler. It
// will be deleted in the dtor or in the next EditEntry.
pCurEditedEntry = 0;
return 0;
}
void SvxIconChoiceCtrl_Impl::StopEntryEditing( bool bCancel )
{
if( pEdit )
pEdit->StopEditing( bCancel );
}
SvxIconChoiceCtrlEntry* SvxIconChoiceCtrl_Impl::GetFirstSelectedEntry( sal_uLong& rPos ) const
{
if( !GetSelectionCount() )
return 0;
if( (nWinBits & WB_HIGHLIGHTFRAME) && (eSelectionMode == NO_SELECTION) )
{
rPos = pView->GetEntryListPos( pCurHighlightFrame );
return pCurHighlightFrame;
}
size_t nCount = aEntries.size();
if( !pHead )
{
for( size_t nCur = 0; nCur < nCount; nCur++ )
{
SvxIconChoiceCtrlEntry* pEntry = aEntries[ nCur ];
if( pEntry->IsSelected() )
{
rPos = nCur;
return pEntry;
}
}
}
else
{
SvxIconChoiceCtrlEntry* pEntry = pHead;
while( nCount-- )
{
if( pEntry->IsSelected() )
{
rPos = GetEntryListPos( pEntry );
return pEntry;
}
pEntry = pEntry->pflink;
if( nCount && pEntry == pHead )
{
OSL_FAIL("SvxIconChoiceCtrl_Impl::GetFirstSelectedEntry > infinite loop!");
return 0;
}
}
}
return 0;
}
void SvxIconChoiceCtrl_Impl::SelectAll( bool bSelect, bool bPaint )
{
bPaint = true;
size_t nCount = aEntries.size();
for( size_t nCur = 0; nCur < nCount && (bSelect || GetSelectionCount() ); nCur++ )
{
SvxIconChoiceCtrlEntry* pEntry = aEntries[ nCur ];
SelectEntry( pEntry, bSelect, true, true, bPaint );
}
nFlags &= (~F_ADD_MODE);
pAnchor = 0;
}
IcnViewEdit_Impl::IcnViewEdit_Impl( SvtIconChoiceCtrl* pParent, const Point& rPos,
const Size& rSize, const OUString& rData, const Link& rNotifyEditEnd ) :
MultiLineEdit( pParent, (pParent->GetStyle() & WB_ICON) ? WB_CENTER : WB_LEFT),
aCallBackHdl( rNotifyEditEnd ),
bCanceled( false ),
bAlreadyInCallback( false ),
bGrabFocus( false )
{
vcl::Font aFont( pParent->GetPointFont() );
aFont.SetTransparent( false );
SetControlFont( aFont );
if( !pParent->HasFontFillColor() )
{
Color aColor( pParent->GetBackground().GetColor() );
SetControlBackground( aColor );
}
else
SetControlBackground( aFont.GetFillColor() );
SetControlForeground( aFont.GetColor() );
SetPosPixel( rPos );
SetSizePixel( CalcAdjustedSize(rSize) );
SetText( rData );
SaveValue();
aAccReturn.InsertItem( IMPICNVIEW_ACC_RETURN, vcl::KeyCode(KEY_RETURN) );
aAccEscape.InsertItem( IMPICNVIEW_ACC_ESCAPE, vcl::KeyCode(KEY_ESCAPE) );
aAccReturn.SetActivateHdl( LINK( this, IcnViewEdit_Impl, ReturnHdl_Impl) );
aAccEscape.SetActivateHdl( LINK( this, IcnViewEdit_Impl, EscapeHdl_Impl) );
Application::InsertAccel( &aAccReturn);//, ACCEL_ALWAYS );
Application::InsertAccel( &aAccEscape);//, ACCEL_ALWAYS );
Show();
GrabFocus();
}
IcnViewEdit_Impl::~IcnViewEdit_Impl()
{
if( !bAlreadyInCallback )
{
Application::RemoveAccel( &aAccReturn );
Application::RemoveAccel( &aAccEscape );
}
}
void IcnViewEdit_Impl::CallCallBackHdl_Impl()
{
aIdle.Stop();
if ( !bAlreadyInCallback )
{
bAlreadyInCallback = true;
Application::RemoveAccel( &aAccReturn );
Application::RemoveAccel( &aAccEscape );
Hide();
aCallBackHdl.Call( this );
}
}
IMPL_LINK_NOARG(IcnViewEdit_Impl, Timeout_Impl)
{
CallCallBackHdl_Impl();
return 0;
}
IMPL_LINK( IcnViewEdit_Impl, ReturnHdl_Impl, Accelerator*, EMPTYARG )
{
bCanceled = false;
bGrabFocus = true;
CallCallBackHdl_Impl();
return 1;
}
IMPL_LINK( IcnViewEdit_Impl, EscapeHdl_Impl, Accelerator*, EMPTYARG )
{
bCanceled = true;
bGrabFocus = true;
CallCallBackHdl_Impl();
return 1;
}
void IcnViewEdit_Impl::KeyInput( const KeyEvent& rKEvt )
{
vcl::KeyCode aCode = rKEvt.GetKeyCode();
sal_uInt16 nCode = aCode.GetCode();
switch ( nCode )
{
case KEY_ESCAPE:
bCanceled = true;
bGrabFocus = true;
CallCallBackHdl_Impl();
break;
case KEY_RETURN:
bCanceled = false;
bGrabFocus = true;
CallCallBackHdl_Impl();
break;
default:
MultiLineEdit::KeyInput( rKEvt );
}
}
bool IcnViewEdit_Impl::PreNotify( NotifyEvent& rNEvt )
{
if( rNEvt.GetType() == MouseNotifyEvent::LOSEFOCUS )
{
if ( !bAlreadyInCallback &&
((!Application::GetFocusWindow()) || !IsChild(Application::GetFocusWindow())))
{
bCanceled = false;
aIdle.SetPriority(IdlePriority::VCL_IDLE_PRIORITY_REPAINT);
aIdle.SetIdleHdl(LINK(this,IcnViewEdit_Impl,Timeout_Impl));
aIdle.Start();
}
}
return false;
}
void IcnViewEdit_Impl::StopEditing( bool bCancel )
{
if ( !bAlreadyInCallback )
{
bCanceled = bCancel;
CallCallBackHdl_Impl();
}
}
sal_uLong SvxIconChoiceCtrl_Impl::GetEntryListPos( SvxIconChoiceCtrlEntry* pEntry ) const
{
if( !(nFlags & F_ENTRYLISTPOS_VALID ))
((SvxIconChoiceCtrl_Impl*)this)->SetListPositions();
return pEntry->nPos;
}
void SvxIconChoiceCtrl_Impl::InitSettings()
{
const StyleSettings& rStyleSettings = pView->GetSettings().GetStyleSettings();
if( !pView->HasFont() )
{
// unit (from settings) is Point
vcl::Font aFont( rStyleSettings.GetFieldFont() );
aFont.SetColor( rStyleSettings.GetWindowTextColor() );
pView->SetPointFont( aFont );
SetDefaultTextSize();
}
pView->SetTextColor( rStyleSettings.GetFieldTextColor() );
pView->SetTextFillColor();
pView->SetBackground( rStyleSettings.GetFieldColor());
long nScrBarSize = rStyleSettings.GetScrollBarSize();
if( nScrBarSize != nHorSBarHeight || nScrBarSize != nVerSBarWidth )
{
nHorSBarHeight = nScrBarSize;
Size aSize( aHorSBar.GetSizePixel() );
aSize.Height() = nScrBarSize;
aHorSBar.Hide();
aHorSBar.SetSizePixel( aSize );
nVerSBarWidth = nScrBarSize;
aSize = aVerSBar.GetSizePixel();
aSize.Width() = nScrBarSize;
aVerSBar.Hide();
aVerSBar.SetSizePixel( aSize );
Size aOSize( pView->Control::GetOutputSizePixel() );
PositionScrollBars( aOSize.Width(), aOSize.Height() );
AdjustScrollBars();
}
}
EntryList_Impl::EntryList_Impl( SvxIconChoiceCtrl_Impl* pOwner ) :
_pOwner( pOwner )
{
_pOwner->pHead = 0;
}
EntryList_Impl::~EntryList_Impl()
{
_pOwner->pHead = 0;
}
void EntryList_Impl::clear()
{
_pOwner->pHead = 0;
maIconChoiceCtrlEntryList.clear();
}
void EntryList_Impl::insert( size_t nPos, SvxIconChoiceCtrlEntry* pEntry )
{
if ( nPos < maIconChoiceCtrlEntryList.size() ) {
maIconChoiceCtrlEntryList.insert( maIconChoiceCtrlEntryList.begin() + nPos, pEntry );
} else {
maIconChoiceCtrlEntryList.push_back( pEntry );
}
if( _pOwner->pHead )
pEntry->SetBacklink( _pOwner->pHead->pblink );
}
void SvxIconChoiceCtrl_Impl::SetPositionMode( SvxIconChoiceCtrlPositionMode eMode )
{
if( eMode == ePositionMode )
return;
SvxIconChoiceCtrlPositionMode eOldMode = ePositionMode;
ePositionMode = eMode;
size_t nCount = aEntries.size();
if( eOldMode == IcnViewPositionModeAutoArrange )
{
// when positioning moved entries "hard", there are problems with
// unwanted overlaps, as these entries aren't taken into account in
// Arrange.
if( aEntries.size() )
aAutoArrangeIdle.Start();
return;
}
if( ePositionMode == IcnViewPositionModeAutoArrange )
{
for( size_t nCur = 0; nCur < nCount; nCur++ )
{
SvxIconChoiceCtrlEntry* pEntry = aEntries[ nCur ];
if( pEntry->GetFlags() & (ICNVIEW_FLAG_POS_LOCKED | ICNVIEW_FLAG_POS_MOVED))
SetEntryPos(pEntry, GetEntryBoundRect( pEntry ).TopLeft());
}
if( aEntries.size() )
aAutoArrangeIdle.Start();
}
else if( ePositionMode == IcnViewPositionModeAutoAdjust )
{
AdjustEntryAtGrid( 0 );
}
}
void SvxIconChoiceCtrl_Impl::SetEntryPredecessor( SvxIconChoiceCtrlEntry* pEntry,
SvxIconChoiceCtrlEntry* pPredecessor )
{
if( !IsAutoArrange() )
return;
if( pEntry == pPredecessor )
return;
sal_uLong nPos1 = GetEntryListPos( pEntry );
if( !pHead )
{
if( pPredecessor )
{
sal_uLong nPos2 = GetEntryListPos( pPredecessor );
if( nPos1 == (nPos2 + 1) )
return; // is already the predecessor
}
else if( !nPos1 )
return;
}
if( !pHead )
InitPredecessors();
if( !pPredecessor && pHead == pEntry )
return; // is already the first one
bool bSetHead = false;
if( !pPredecessor )
{
bSetHead = true;
pPredecessor = pHead->pblink;
}
if( pEntry == pHead )
{
pHead = pHead->pflink;
bSetHead = false;
}
if( pEntry != pPredecessor )
{
pEntry->Unlink();
pEntry->SetBacklink( pPredecessor );
}
if( bSetHead )
pHead = pEntry;
pEntry->SetFlags( ICNVIEW_FLAG_PRED_SET );
aAutoArrangeIdle.Start();
}
SvxIconChoiceCtrlEntry* SvxIconChoiceCtrl_Impl::FindEntryPredecessor( SvxIconChoiceCtrlEntry* pEntry,
const Point& rPosTopLeft )
{
Point aPos( rPosTopLeft ); //TopLeft
Rectangle aCenterRect( CalcBmpRect( pEntry, &aPos ));
Point aNewPos( aCenterRect.Center() );
sal_uLong nGrid = GetPredecessorGrid( aNewPos );
size_t nCount = aEntries.size();
if( nGrid == ULONG_MAX )
return 0;
if( nGrid >= nCount )
nGrid = nCount - 1;
if( !pHead )
return aEntries[ nGrid ];
SvxIconChoiceCtrlEntry* pCur = pHead; // Grid 0
// TODO: go through list from the end if nGrid > nCount/2
for( sal_uLong nCur = 0; nCur < nGrid; nCur++ )
pCur = pCur->pflink;
return pCur;
}
sal_uLong SvxIconChoiceCtrl_Impl::GetPredecessorGrid( const Point& rPos) const
{
Point aPos( rPos );
aPos.X() -= LROFFS_WINBORDER;
aPos.Y() -= TBOFFS_WINBORDER;
long nMaxCol = aVirtOutputSize.Width() / nGridDX;
if( nMaxCol )
nMaxCol--;
long nGridX = aPos.X() / nGridDX;
if( nGridX > nMaxCol )
nGridX = nMaxCol;
long nGridY = aPos.Y() / nGridDY;
long nGridsX = aOutputSize.Width() / nGridDX;
sal_uLong nGrid = (nGridY * nGridsX) + nGridX;
long nMiddle = (nGridX * nGridDX) + (nGridDX / 2);
if( rPos.X() < nMiddle )
{
if( !nGrid )
nGrid = ULONG_MAX;
else
nGrid--;
}
return nGrid;
}
bool SvxIconChoiceCtrl_Impl::RequestHelp( const HelpEvent& rHEvt )
{
if ( !(rHEvt.GetMode() & HelpEventMode::QUICK ) )
return false;
Point aPos( pView->ScreenToOutputPixel(rHEvt.GetMousePosPixel() ) );
aPos -= pView->GetMapMode().GetOrigin();
SvxIconChoiceCtrlEntry* pEntry = GetEntry( aPos, true );
if ( !pEntry )
return false;
OUString sQuickHelpText = pEntry->GetQuickHelpText();
OUString aEntryText( pView->GetEntryText( pEntry, false ) );
Rectangle aTextRect( CalcTextRect( pEntry, 0, false, &aEntryText ) );
if ( ( !aTextRect.IsInside( aPos ) || aEntryText.isEmpty() ) && sQuickHelpText.isEmpty() )
return false;
Rectangle aOptTextRect( aTextRect );
aOptTextRect.Bottom() = LONG_MAX;
sal_uInt16 nNewFlags = nCurTextDrawFlags;
nNewFlags &= ~( TEXT_DRAW_CLIP | TEXT_DRAW_ENDELLIPSIS );
aOptTextRect = pView->GetTextRect( aOptTextRect, aEntryText, nNewFlags );
if ( aOptTextRect != aTextRect || !sQuickHelpText.isEmpty() )
{
//aTextRect.Right() = aTextRect.Left() + aRealSize.Width() + 4;
Point aPt( aOptTextRect.TopLeft() );
aPt += pView->GetMapMode().GetOrigin();
aPt = pView->OutputToScreenPixel( aPt );
// subtract border of tooltip help
aPt.Y() -= 1;
aPt.X() -= 3;
aOptTextRect.SetPos( aPt );
OUString sHelpText;
if ( !sQuickHelpText.isEmpty() )
sHelpText = sQuickHelpText;
else
sHelpText = aEntryText;
Help::ShowQuickHelp( (vcl::Window*)pView, aOptTextRect, sHelpText, QUICKHELP_LEFT | QUICKHELP_VCENTER );
}
return true;
}
void SvxIconChoiceCtrl_Impl::ClearColumnList()
{
if( !pColumns )
return;
pColumns->clear();
DELETEZ(pColumns);
}
void SvxIconChoiceCtrl_Impl::SetColumn( sal_uInt16 nIndex, const SvxIconChoiceCtrlColumnInfo& rInfo)
{
if( !pColumns )
pColumns = new SvxIconChoiceCtrlColumnInfoMap;
SvxIconChoiceCtrlColumnInfo* pInfo = new SvxIconChoiceCtrlColumnInfo( rInfo );
pColumns->insert( nIndex, pInfo );
// HACK: Detail mode is not yet fully implemented, this workaround makes it
// fly with a single column
if( !nIndex && (nWinBits & WB_DETAILS) )
nGridDX = pInfo->GetWidth();
if( GetUpdateMode() )
Arrange( IsAutoArrange() );
}
const SvxIconChoiceCtrlColumnInfo* SvxIconChoiceCtrl_Impl::GetColumn( sal_uInt16 nIndex ) const
{
if (!pColumns)
return 0;
SvxIconChoiceCtrlColumnInfoMap::const_iterator it = pColumns->find( nIndex );
if( it == pColumns->end() )
return 0;
return it->second;
}
void SvxIconChoiceCtrl_Impl::DrawHighlightFrame(
OutputDevice* pOut, const Rectangle& rBmpRect, bool bHide )
{
Rectangle aBmpRect( rBmpRect );
long nBorder = 2;
if( aImageSize.Width() < 32 )
nBorder = 1;
aBmpRect.Right() += nBorder;
aBmpRect.Left() -= nBorder;
aBmpRect.Bottom() += nBorder;
aBmpRect.Top() -= nBorder;
if ( bHide )
pView->Invalidate( aBmpRect );
else
{
DecorationView aDecoView( pOut );
sal_uInt16 nDecoFlags;
if ( bHighlightFramePressed )
nDecoFlags = FRAME_HIGHLIGHT_TESTBACKGROUND | FRAME_HIGHLIGHT_IN;
else
nDecoFlags = FRAME_HIGHLIGHT_TESTBACKGROUND | FRAME_HIGHLIGHT_OUT;
aDecoView.DrawHighlightFrame( aBmpRect, nDecoFlags );
}
}
void SvxIconChoiceCtrl_Impl::SetEntryHighlightFrame( SvxIconChoiceCtrlEntry* pEntry,
bool bKeepHighlightFlags )
{
if( pEntry == pCurHighlightFrame )
return;
if( !bKeepHighlightFlags )
bHighlightFramePressed = false;
HideEntryHighlightFrame();
pCurHighlightFrame = pEntry;
if( pEntry )
{
Rectangle aBmpRect( CalcFocusRect(pEntry) );
DrawHighlightFrame( pView, aBmpRect, false );
}
}
void SvxIconChoiceCtrl_Impl::HideEntryHighlightFrame()
{
if( !pCurHighlightFrame )
return;
SvxIconChoiceCtrlEntry* pEntry = pCurHighlightFrame;
pCurHighlightFrame = 0;
Rectangle aBmpRect( CalcFocusRect(pEntry) );
DrawHighlightFrame( pView, aBmpRect, true );
}
void SvxIconChoiceCtrl_Impl::CallSelectHandler( SvxIconChoiceCtrlEntry* )
{
// When single-click mode is active, the selection handler should be called
// synchronously, as the selection is automatically taken away once the
// mouse cursor doesn't touch the object any more. Else, we might run into
// missing calls to Select if the object is selected from a mouse movement,
// because when starting the timer, the mouse cursor might have already left
// the object.
// In special cases (=>SfxFileDialog!), synchronous calls can be forced via
// WB_NOASYNCSELECTHDL.
if( nWinBits & (WB_NOASYNCSELECTHDL | WB_HIGHLIGHTFRAME) )
{
pHdlEntry = 0;
pView->ClickIcon();
//pView->Select();
}
else
aCallSelectHdlIdle.Start();
}
IMPL_LINK_NOARG(SvxIconChoiceCtrl_Impl, CallSelectHdlHdl)
{
pHdlEntry = 0;
pView->ClickIcon();
//pView->Select();
return 0;
}
void SvxIconChoiceCtrl_Impl::SetOrigin( const Point& rPos, bool bDoNotUpdateWallpaper )
{
MapMode aMapMode( pView->GetMapMode() );
aMapMode.SetOrigin( rPos );
pView->SetMapMode( aMapMode );
if( !bDoNotUpdateWallpaper )
{
bool bScrollable = pView->GetBackground().IsScrollable();
if( pView->HasBackground() && !bScrollable )
{
Rectangle aRect( GetOutputRect());
Wallpaper aPaper( pView->GetBackground() );
aPaper.SetRect( aRect );
pView->SetBackground( aPaper );
}
}
}
void SvxIconChoiceCtrl_Impl::CallEventListeners( sal_uLong nEvent, void* pData )
{
pView->CallImplEventListeners( nEvent, pData );
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|