summaryrefslogtreecommitdiff
path: root/svtools/source/contnr/svimpicn.cxx
blob: 2d4c9cf2df0e04344544f6eb079bca8d73d31928 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2000, 2010 Oracle and/or its affiliates.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_svtools.hxx"

#include <limits.h>
#ifndef _METRIC_HXX
#include <vcl/metric.hxx>
#endif
#include <vcl/svapp.hxx>
#ifdef DBG_UTIL
#include <vcl/sound.hxx>
#endif

#include <svtools/svlbox.hxx>
#include <svtools/svicnvw.hxx>
#include <svimpicn.hxx>
#ifndef _SVLBITM_HXX
#include <svtools/svlbitm.hxx>
#endif
#include <svl/svarray.hxx>



#define VIEWMODE_ICON   0x0001  // Text unter Bitmap
#define VIEWMODE_NAME   0x0002  // Text rechts neben Bitmap
#define VIEWMODE_TEXT   0x0004  // Text ohne Bitmap

#define DD_SCROLL_PIXEL 10

// alle Angaben in Pixel

#define ICONVIEW_OFFS_BMP_STRING    3

// fuer das Bounding-Rectangle
#define LROFFS_BOUND                2
#define TBOFFS_BOUND                2

// fuer das Focus-Rectangle um Icons
#define LROFFS_ICON                 2
#define TBOFFS_ICON                 2

#define NAMEVIEW_OFFS_BMP_STRING    3

// Abstaende von Fensterraendern
#define LROFFS_WINBORDER            4
#define TBOFFS_WINBORDER            4

// Breitenoffset Highlight-Rect bei Text
#define LROFFS_TEXT                 2


#define ICNVIEWDATA(xPtr) (SvIcnVwDataEntry*)(pView->GetViewDataEntry(xPtr))
#define ICNVIEWDATA2(xPtr) (SvIcnVwDataEntry*)(pView->pView->GetViewDataEntry(xPtr))

//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
// -------------------------------------------------------------------------
// Hilfsfunktionen von Thomas Hosemann zur mehrzeiligen Ausgabe von
// Strings. Die Funktionen werden spaeter in StarView integriert.
// -------------------------------------------------------------------------
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------

// keine doppelten Defines
#ifdef TEXT_DRAW_CLIP
#undef TEXT_DRAW_CLIP
#endif
#ifdef TEXT_DRAW_MULTILINE
#undef TEXT_DRAW_MULTILINE
#endif
#ifdef TEXT_DRAW_WORDBREAK
#undef TEXT_DRAW_WORDBREAK
#endif

// #define TEXT_DRAW_DISABLE           ((USHORT)0x0001)
// #define TEXT_DRAW_3DLOOK            ((USHORT)0x0002)
// #define TEXT_DRAW_MNEMONIC          ((USHORT)0x0004)
#define TEXT_DRAW_LEFT              ((USHORT)0x0010)
#define TEXT_DRAW_CENTER            ((USHORT)0x0020)
#define TEXT_DRAW_RIGHT             ((USHORT)0x0040)
#define TEXT_DRAW_TOP               ((USHORT)0x0080)
#define TEXT_DRAW_VCENTER           ((USHORT)0x0100)
#define TEXT_DRAW_BOTTOM            ((USHORT)0x0200)
#define TEXT_DRAW_ENDELLIPSIS       ((USHORT)0x0400)
#define TEXT_DRAW_PATHELLIPSIS      ((USHORT)0x0800)
#define TEXT_DRAW_CLIP              ((USHORT)0x1000)
#define TEXT_DRAW_MULTILINE         ((USHORT)0x2000)
#define TEXT_DRAW_WORDBREAK         ((USHORT)0x4000)

XubString GetEllipsisString( OutputDevice* pDev,
                            const XubString& rStr, long nMaxWidth,
                            USHORT nStyle = TEXT_DRAW_ENDELLIPSIS )
{
    XubString aStr = rStr;

    if ( nStyle & TEXT_DRAW_ENDELLIPSIS )
    {
        USHORT nIndex = pDev->GetTextBreak( rStr, nMaxWidth );
        if ( nIndex != STRING_LEN )
        {
            aStr.Erase( nIndex );
            if ( nIndex > 1 )
            {
                aStr.AppendAscii("...");
                while ( aStr.Len() &&
                        (pDev->GetTextWidth( aStr ) > nMaxWidth) )
                {
                    if ( (nIndex > 1) || (nIndex == aStr.Len()) )
                        nIndex--;
                    aStr.Erase( nIndex, 1 );
                }
            }

            if ( !aStr.Len() && (nStyle & TEXT_DRAW_CLIP) )
                aStr += rStr.GetChar( 0 );
        }
    }

    return aStr;
}

class TextLineInfo
{
private:
    long        mnWidth;
    USHORT      mnIndex;
    USHORT      mnLen;

public:
                TextLineInfo( long nWidth, USHORT nIndex, USHORT nLen )
                {
                    mnWidth = nWidth;
                    mnIndex = nIndex;
                    mnLen   = nLen;
                }

    long        GetWidth() const { return mnWidth; }
    USHORT      GetIndex() const { return mnIndex; }
    USHORT      GetLen() const { return mnLen; }
};

#define MULTITEXTLINEINFO_RESIZE    16
typedef TextLineInfo* PTextLineInfo;

class MultiTextLineInfo
{
private:
    PTextLineInfo*      mpLines;
    USHORT              mnLines;
    USHORT              mnSize;

public:
                        MultiTextLineInfo();
                        ~MultiTextLineInfo();

    void                AddLine( TextLineInfo* pLine );
    void                Clear();

    TextLineInfo*       GetLine( USHORT nLine ) const
                            { return mpLines[nLine]; }
    USHORT              Count() const { return mnLines; }

private:
                        MultiTextLineInfo( const MultiTextLineInfo& );
    MultiTextLineInfo&  operator=( const MultiTextLineInfo& );
};

MultiTextLineInfo::MultiTextLineInfo()
{
    mpLines         = new PTextLineInfo[MULTITEXTLINEINFO_RESIZE];
    mnLines         = 0;
    mnSize          = MULTITEXTLINEINFO_RESIZE;
}

MultiTextLineInfo::~MultiTextLineInfo()
{
    for ( USHORT i = 0; i < mnLines; i++ )
        delete mpLines[i];
    delete [] mpLines;
}

void MultiTextLineInfo::AddLine( TextLineInfo* pLine )
{
    if ( mnSize == mnLines )
    {
        mnSize += MULTITEXTLINEINFO_RESIZE;
        PTextLineInfo* pNewLines = new PTextLineInfo[mnSize];
        memcpy( pNewLines, mpLines, mnLines*sizeof(PTextLineInfo) );
        mpLines = pNewLines;
    }

    mpLines[mnLines] = pLine;
    mnLines++;
}

void MultiTextLineInfo::Clear()
{
    for ( USHORT i = 0; i < mnLines; i++ )
        delete mpLines[i];
    mnLines = 0;
}

// -----------------------------------------------------------------------

long GetTextLines( OutputDevice* pDev, MultiTextLineInfo& rLineInfo,
                   long nWidth, const XubString& rStr,
                   USHORT nStyle = TEXT_DRAW_WORDBREAK )
{
    rLineInfo.Clear();
    if ( !rStr.Len() )
        return 0;
    if ( nWidth <= 0 )
        nWidth = 1;

    USHORT          nStartPos       = 0;                // Start-Position der Zeile
    USHORT          nLastLineLen    = 0;                // Zeilenlaenge bis zum vorherigen Wort
    USHORT          nLastWordPos    = 0;                // Position des letzten Wortanfangs
    USHORT          i               = 0;
    USHORT          nPos;                               // StartPositon der Zeile (nur Temp)
    USHORT          nLen;                               // Laenge der Zeile (nur Temp)
    USHORT          nStrLen         = rStr.Len();
    long            nMaxLineWidth   = 0;                // Maximale Zeilenlaenge
    long            nLineWidth;                         // Aktuelle Zeilenlaenge
    long            nLastLineWidth  = 0;                // Zeilenlaenge der letzten Zeile
    xub_Unicode          c;
    xub_Unicode          c2;
    const xub_Unicode*   pStr       = rStr.GetBuffer();
    BOOL            bHardBreak      = FALSE;

    do
    {
        c = pStr[i];

        // Auf Zeilenende ermitteln
        if ( (c == _CR) || (c == _LF) )
            bHardBreak = TRUE;
        else
            bHardBreak = FALSE;

        // Testen, ob ein Wortende erreicht ist
        if ( bHardBreak || (i == nStrLen) ||
             (((c == ' ') || (c == '-')) && (nStyle & TEXT_DRAW_WORDBREAK)) )
        {
            nLen = i-nStartPos;
            if ( c == '-' )
                nLen++;
            nLineWidth = pDev->GetTextWidth( rStr, nStartPos, nLen );

            // Findet ein Zeilenumbruch statt
            if ( bHardBreak || (i == nStrLen) ||
                ((nLineWidth >= nWidth) && (nStyle & TEXT_DRAW_WORDBREAK)) )
            {
                nPos = nStartPos;

                if ( (nLineWidth >= nWidth) && (nStyle & TEXT_DRAW_WORDBREAK) )
                {
                    nLineWidth      = nLastLineWidth;
                    nLen            = nLastLineLen;
                    nStartPos       = nLastWordPos;
                    nLastLineLen    = i-nStartPos;
                    nLastWordPos    = nStartPos+nLastLineLen+1;
                    if ( c == '-' )
                        nLastLineLen++;
                    else if ( bHardBreak && (i > nStartPos) )
                        i--;
                }
                else
                {
                    nStartPos = i;
                    // Zeilenende-Zeichen und '-' beruecksichtigen
                    if ( bHardBreak )
                    {
                        nStartPos++;
                        c2 = pStr[i+1];
                        if ( (c != c2) && ((c2 == _CR) || (c2 == _LF)) )
                        {
                            nStartPos++;
                            i++;
                        }
                    }
                    else if ( c != '-' )
                        nStartPos++;
                    nLastWordPos    = nStartPos;
                    nLastLineLen    = 0;
                }

                if ( nLineWidth > nMaxLineWidth )
                    nMaxLineWidth = nLineWidth;

                if ( nLen || bHardBreak  )
                    rLineInfo.AddLine( new TextLineInfo( nLineWidth, nPos, nLen ) );

                // Testen, ob aktuelles Wort noch auf die Zeile passt,
                // denn ansonsten mueessen wir es auftrennen
                if ( nLastLineLen )
                {
                    nLineWidth = pDev->GetTextWidth( rStr, nStartPos, nLastLineLen );
                    if ( nLineWidth > nWidth )
                    {
                        // Wenn ein Wortumbruch in einem Wort stattfindet,
                        // ist die maximale Zeilenlaenge die Laenge
                        // des laengsten Wortes
                        if ( nLineWidth > nMaxLineWidth )
                            nMaxLineWidth = nLineWidth;

                        // Solange Wort auftrennen, bis es auf eine Zeile passt
                        do
                        {
                            nPos = pDev->GetTextBreak( rStr, nWidth, nStartPos, nLastLineLen );
                            nLen = nPos-nStartPos;
                            if ( !nLen )
                            {
                                nPos++;
                                nLen++;
                            }
                            nLineWidth = pDev->GetTextWidth( rStr, nStartPos, nLen );
                            rLineInfo.AddLine( new TextLineInfo( nLineWidth, nStartPos, nLen ) );
                            nStartPos       = nPos;
                            nLastLineLen = nLastLineLen - nLen;
                            nLineWidth = pDev->GetTextWidth( rStr, nStartPos, nLastLineLen );
                        }
                        while ( nLineWidth > nWidth );
                    }
                    nLastLineWidth = nLineWidth;

                    // Bei Stringende muessen wir die letzte Zeile auch noch
                    // dranhaengen
                    if ( (i == nStrLen) && nLastLineLen )
                        rLineInfo.AddLine( new TextLineInfo( nLastLineWidth, nStartPos, nLastLineLen ) );
                }
                else
                    nLastLineWidth = 0;
            }
            else
            {
                nLastLineWidth  = nLineWidth;
                nLastLineLen    = nLen;
                nLastWordPos    = nStartPos+nLastLineLen;
                if ( c != '-' )
                    nLastWordPos++;
            }
        }

        i++;
    }
    while ( i <= nStrLen );

    return nMaxLineWidth;
}

// -----------------------------------------------------------------------

USHORT GetTextLines( OutputDevice* pDev, const Rectangle& rRect,
                     const XubString& rStr,
                     USHORT nStyle = TEXT_DRAW_WORDBREAK,
                     long* pMaxWidth = NULL )
{
    MultiTextLineInfo aMultiLineInfo;
    long nMaxWidth = GetTextLines( pDev, aMultiLineInfo,
                                   rRect.GetWidth(), rStr, nStyle );
    if ( pMaxWidth )
        *pMaxWidth = nMaxWidth;
    return aMultiLineInfo.Count();
}

// -----------------------------------------------------------------------

Rectangle GetTextRect( OutputDevice* pDev, const Rectangle& rRect,
                       const XubString& rStr,
                       USHORT nStyle = TEXT_DRAW_WORDBREAK )
{
    Rectangle           aRect = rRect;
    USHORT              nLines;
    long                nWidth = rRect.GetWidth();
    long                nMaxWidth;
    long                nTextHeight;

    if ( nStyle & TEXT_DRAW_MULTILINE )
    {
        MultiTextLineInfo   aMultiLineInfo;
        TextLineInfo*       pLineInfo;
        USHORT              nFormatLines;

        nMaxWidth = 0;
        GetTextLines( pDev, aMultiLineInfo, nWidth, rStr, nStyle );
        nFormatLines = aMultiLineInfo.Count();
        nTextHeight = pDev->GetTextHeight();
        nLines = (USHORT)(aRect.GetHeight()/nTextHeight);
        if ( nFormatLines <= nLines )
            nLines = nFormatLines;
        else
        {
            if ( !(nStyle & TEXT_DRAW_ENDELLIPSIS) )
                nLines = nFormatLines;
            else
                nMaxWidth = nWidth;
        }
        for ( USHORT i = 0; i < nLines; i++ )
        {
            pLineInfo = aMultiLineInfo.GetLine( i );
            if ( pLineInfo->GetWidth() > nMaxWidth )
                nMaxWidth = pLineInfo->GetWidth();
        }
    }
    else
    {
        nLines          = 1;
        nMaxWidth       = pDev->GetTextWidth( rStr );
        nTextHeight     = pDev->GetTextHeight();
        if ( (nMaxWidth > nWidth) && (nStyle & TEXT_DRAW_ENDELLIPSIS) )
            nMaxWidth = nWidth;
    }

    if ( nStyle & TEXT_DRAW_RIGHT )
        aRect.Left() = aRect.Right()-nMaxWidth+1;
    else if ( nStyle & TEXT_DRAW_CENTER )
    {
        aRect.Left() += (nWidth-nMaxWidth)/2;
        aRect.Right() = aRect.Left()+nMaxWidth-1;
    }
    else
        aRect.Right() = aRect.Left()+nMaxWidth-1;

    if ( nStyle & TEXT_DRAW_BOTTOM )
        aRect.Top() = aRect.Bottom()-(nTextHeight*nLines)+1;
    else if ( nStyle & TEXT_DRAW_VCENTER )
    {
        aRect.Top()   += (aRect.GetHeight()-(nTextHeight*nLines))/2;
        aRect.Bottom() = aRect.Top()+(nTextHeight*nLines)-1;
    }
    else
        aRect.Bottom() = aRect.Top()+(nTextHeight*nLines)-1;

    return aRect;
}

// -----------------------------------------------------------------------

void DrawText( OutputDevice* pDev, const Rectangle& rRect,
               const XubString& rStr, USHORT nStyle = 0 )
{
    if ( !rStr.Len() || rRect.IsEmpty() )
        return;

    Point       aPos    = rRect.TopLeft();
    long        nWidth  = rRect.GetWidth();
    long        nHeight = rRect.GetHeight();
    FontAlign   eAlign  = pDev->GetFont().GetAlign();

    if ( ((nWidth <= 0) || (nHeight <= 0)) && (nStyle & TEXT_DRAW_CLIP) )
        return;

    // Mehrzeiligen Text behandeln wir anders
    if ( nStyle & TEXT_DRAW_MULTILINE )
    {
        String              aLastLine;
        Region              aOldRegion;
        MultiTextLineInfo   aMultiLineInfo;
        TextLineInfo*       pLineInfo;
        long                nTextHeight     = pDev->GetTextHeight();
        long                nMaxTextWidth;
        USHORT              i;
        USHORT              nLines          = (USHORT)(nHeight/nTextHeight);
        USHORT              nFormatLines;
        BOOL                bIsClipRegion = FALSE;
        nMaxTextWidth = GetTextLines( pDev, aMultiLineInfo, nWidth, rStr, nStyle );

        nFormatLines = aMultiLineInfo.Count();
        if ( nFormatLines > nLines )
        {
            if ( nStyle & TEXT_DRAW_ENDELLIPSIS )
            {
                // Letzte Zeile zusammenbauen und kuerzen
                nFormatLines = nLines-1;
                pLineInfo = aMultiLineInfo.GetLine( nFormatLines );
                aLastLine = rStr.Copy( pLineInfo->GetIndex() );
                aLastLine.ConvertLineEnd( LINEEND_LF );
                aLastLine.SearchAndReplace( _LF, ' ' );
                aLastLine = GetEllipsisString( pDev, aLastLine, nWidth, nStyle );
                nStyle &= ~(TEXT_DRAW_VCENTER | TEXT_DRAW_BOTTOM);
                nStyle |= TEXT_DRAW_TOP;
            }
        }
        else
        {
            if ( nMaxTextWidth <= nWidth )
                nStyle &= ~TEXT_DRAW_CLIP;
        }

        // Clipping setzen
        if ( nStyle & TEXT_DRAW_CLIP )
        {
            bIsClipRegion = pDev->IsClipRegion();
            if ( bIsClipRegion )
            {
                aOldRegion = pDev->GetClipRegion();
                pDev->IntersectClipRegion( rRect );
            }
            else
            {
                Region aRegion( rRect );
                pDev->SetClipRegion( aRegion );
            }
        }

        // Vertikales Alignment
        if ( nStyle & TEXT_DRAW_BOTTOM )
            aPos.Y() += nHeight-(nFormatLines*nTextHeight);
        else if ( nStyle & TEXT_DRAW_VCENTER )
            aPos.Y() += (nHeight-(nFormatLines*nTextHeight))/2;

        // Font Alignment
        if ( eAlign == ALIGN_BOTTOM )
            aPos.Y() += nTextHeight;
        else if ( eAlign == ALIGN_BASELINE )
            aPos.Y() += pDev->GetFontMetric().GetAscent();

        // Alle Zeilen ausgeben, bis auf die letzte
        for ( i = 0; i < nFormatLines; i++ )
        {
            pLineInfo = aMultiLineInfo.GetLine( i );
            if ( nStyle & TEXT_DRAW_RIGHT )
                aPos.X() += nWidth-pLineInfo->GetWidth();
            else if ( nStyle & TEXT_DRAW_CENTER )
                aPos.X() += (nWidth-pLineInfo->GetWidth())/2;
            pDev->DrawText( aPos, rStr, pLineInfo->GetIndex(), pLineInfo->GetLen() );
            aPos.Y() += nTextHeight;
            aPos.X() = rRect.Left();
        }

        // Gibt es noch eine letzte Zeile, dann diese linksbuendig ausgeben,
        // da die Zeile gekuerzt wurde
        if ( aLastLine.Len() )
            pDev->DrawText( aPos, aLastLine );

        // Clipping zuruecksetzen
        if ( nStyle & TEXT_DRAW_CLIP )
        {
            if ( bIsClipRegion )
                pDev->SetClipRegion( aOldRegion );
            else
                pDev->SetClipRegion();
        }
    }
    else
    {
        XubString    aStr = rStr;
        Size        aTextSize(pDev->GetTextWidth( aStr ), pDev->GetTextHeight());

        // Evt. Text kuerzen
        if ( aTextSize.Width() > nWidth )
        {
            if ( nStyle & TEXT_DRAW_ENDELLIPSIS )
            {
                aStr = GetEllipsisString( pDev, rStr, nWidth, nStyle );
                nStyle &= ~(TEXT_DRAW_CENTER | TEXT_DRAW_RIGHT);
                nStyle |= TEXT_DRAW_LEFT;
                aTextSize.Width() = pDev->GetTextWidth(aStr);
            }
        }
        else
        {
            if ( aTextSize.Height() <= nHeight )
                nStyle &= ~TEXT_DRAW_CLIP;
        }

        // Vertikales Alignment
        if ( nStyle & TEXT_DRAW_RIGHT )
            aPos.X() += nWidth-aTextSize.Width();
        else if ( nStyle & TEXT_DRAW_CENTER )
            aPos.X() += (nWidth-aTextSize.Width())/2;

        // Font Alignment
        if ( eAlign == ALIGN_BOTTOM )
            aPos.Y() += aTextSize.Height();
        else if ( eAlign == ALIGN_BASELINE )
            aPos.Y() += pDev->GetFontMetric().GetAscent();

        if ( nStyle & TEXT_DRAW_BOTTOM )
            aPos.Y() += nHeight-aTextSize.Height();
        else if ( nStyle & TEXT_DRAW_VCENTER )
            aPos.Y() += (nHeight-aTextSize.Height())/2;

        if ( nStyle & TEXT_DRAW_CLIP )
        {
            BOOL bIsClipRegion = pDev->IsClipRegion();
            if ( bIsClipRegion )
            {
                Region aOldRegion = pDev->GetClipRegion();
                pDev->IntersectClipRegion( rRect );
                pDev->DrawText( aPos, aStr );
                pDev->SetClipRegion( aOldRegion );
            }
            else
            {
                Region aRegion( rRect );
                pDev->SetClipRegion( aRegion );
                pDev->DrawText( aPos, aStr );
                pDev->SetClipRegion();
            }
        }
        else
            pDev->DrawText( aPos, aStr );
    }
}

// -----------------------------------------------------------------------


//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------


#define DRAWTEXT_FLAGS (TEXT_DRAW_CENTER|TEXT_DRAW_TOP|TEXT_DRAW_ENDELLIPSIS|\
                        TEXT_DRAW_CLIP|TEXT_DRAW_MULTILINE|TEXT_DRAW_WORDBREAK)


class ImpIcnCursor
{
    SvImpIconView*  pView;
    SvPtrarr*       pColumns;
    SvPtrarr*       pRows;
    BOOL*           pGridMap;
    long            nGridDX, nGridDY;
    long            nGridCols, nGridRows;
    long            nCols;
    long            nRows;
    short           nDeltaWidth;
    short           nDeltaHeight;
    SvLBoxEntry*    pCurEntry;
    void            SetDeltas();
    void            ImplCreate();
    void            Create() {  if( !pColumns ) ImplCreate(); }

    USHORT          GetSortListPos( SvPtrarr* pList, long nValue, int bVertical);
    SvLBoxEntry*    SearchCol(USHORT nCol,USHORT nTop,USHORT nBottom,USHORT nPref,
                        BOOL bDown, BOOL bSimple );
    SvLBoxEntry*    SearchRow(USHORT nRow,USHORT nRight,USHORT nLeft,USHORT nPref,
                        BOOL bRight, BOOL bSimple );

    void            ExpandGrid();
    void            CreateGridMap();
    // Rueckgabe FALSE: Eintrag liegt nicht in der GridMap. rGridx,y werden
    // dann an nGridCols, nGridRows geclippt
    BOOL            GetGrid( const Point& rDocPos, USHORT& rGridX, USHORT& rGridY ) const;
    void            SetGridUsed( USHORT nDX, USHORT nDY, BOOL bUsed )
                    {
                        pGridMap[ (nDY * nGridCols) + nDX ] = bUsed;
                    }
    BOOL            IsGridUsed( USHORT nDX, USHORT nDY )
                    {
                        return pGridMap[ (nDY * nGridCols) + nDX ];
                    }
public:
                    ImpIcnCursor( SvImpIconView* pOwner );
                    ~ImpIcnCursor();
    void            Clear( BOOL bGridToo = TRUE );

    // fuer Cursortravelling usw.
    SvLBoxEntry*    GoLeftRight( SvLBoxEntry*, BOOL bRight );
    SvLBoxEntry*    GoUpDown( SvLBoxEntry*, BOOL bDown );

    // Rueckgaebe: FALSE == Das leere Rect steht hinter dem letzten
    // Eintrag; d.h. beim naechsten Einfuegen ergibt sich das naechste
    // leere Rechteck durch Addition. Hinweis: Das Rechteck kann dann
    // ausserhalb des View-Space liegen
    BOOL            FindEmptyGridRect( Rectangle& rRect );

    // Erzeugt fuer jede Zeile (Hoehe=nGridDY) eine nach BoundRect.Left()
    // sortierte Liste der Eintraege, die in ihr stehen. Eine Liste kann
    // leer sein. Die Listen gehen in das Eigentum des Rufenden ueber und
    // muessen mit DestroyGridAdjustData geloescht werden
    void            CreateGridAjustData( SvPtrarr& pLists, SvLBoxEntry* pRow=0);
    static void     DestroyGridAdjustData( SvPtrarr& rLists );
    void            SetGridUsed( const Rectangle&, BOOL bUsed = TRUE );
};




SvImpIconView::SvImpIconView( SvIconView* pCurView, SvLBoxTreeList* pTree,
    WinBits nWinStyle ) :
    aVerSBar( pCurView, WB_DRAG | WB_VSCROLL ),
    aHorSBar( pCurView, WB_DRAG | WB_HSCROLL )
{
    pView = pCurView;
    pModel = pTree;
    pCurParent = 0;
    pZOrderList = new SvPtrarr;
    SetWindowBits( nWinStyle );
    nHorDist = 0;
    nVerDist = 0;
    nFlags = 0;
    nCurUserEvent = 0;
    nMaxVirtWidth = 200;
    pDDRefEntry = 0;
    pDDDev = 0;
    pDDBufDev = 0;
    pDDTempDev = 0;
    eTextMode = ShowTextShort;
    pImpCursor = new ImpIcnCursor( this );

    aVerSBar.SetScrollHdl( LINK( this, SvImpIconView, ScrollUpDownHdl ) );
    aHorSBar.SetScrollHdl( LINK( this, SvImpIconView, ScrollLeftRightHdl ) );
    nHorSBarHeight = aHorSBar.GetSizePixel().Height();
    nVerSBarWidth = aVerSBar.GetSizePixel().Width();

    aMouseMoveTimer.SetTimeout( 20 );
    aMouseMoveTimer.SetTimeoutHdl(LINK(this,SvImpIconView,MouseMoveTimeoutHdl));

    aEditTimer.SetTimeout( 800 );
    aEditTimer.SetTimeoutHdl(LINK(this,SvImpIconView,EditTimeoutHdl));

    Clear( TRUE );
}

SvImpIconView::~SvImpIconView()
{
    StopEditTimer();
    CancelUserEvent();
    delete pZOrderList;
    delete pImpCursor;
    delete pDDDev;
    delete pDDBufDev;
    delete pDDTempDev;
    ClearSelectedRectList();
}

void SvImpIconView::Clear( BOOL bInCtor )
{
    StopEditTimer();
    CancelUserEvent();
    nMaxBmpWidth = 0;
    nMaxBmpHeight = 0;
    nMaxTextWidth = 0;
    bMustRecalcBoundingRects = FALSE;
    nMaxBoundHeight = 0;

    //XXX
    nFlags |= F_GRID_INSERT;
    nFlags &= ~F_PAINTED;
    SetNextEntryPos( Point( LROFFS_WINBORDER, TBOFFS_WINBORDER ) );
    pCursor = 0;
    if( !bInCtor )
    {
        pImpCursor->Clear();
        aVirtOutputSize.Width() = 0;
        aVirtOutputSize.Height() = 0;
        pZOrderList->Remove(0,pZOrderList->Count());
        MapMode aMapMode( pView->GetMapMode());
        aMapMode.SetOrigin( Point() );
        pView->SetMapMode( aMapMode );
        if( pView->IsUpdateMode() )
            pView->Invalidate();
    }
    AdjustScrollBars();
}

void SvImpIconView::SetWindowBits( WinBits nWinStyle )
{
    nWinBits = nWinStyle;
    nViewMode = VIEWMODE_TEXT;
    if( nWinStyle & WB_NAME )
        nViewMode = VIEWMODE_NAME;
    if( nWinStyle & WB_ICON )
        nViewMode = VIEWMODE_ICON;
}


IMPL_LINK( SvImpIconView, ScrollUpDownHdl, ScrollBar *, pScrollBar )
{
    pView->EndEditing( TRUE );
    // Pfeil hoch: delta=-1; Pfeil runter: delta=+1
    Scroll( 0, pScrollBar->GetDelta(), TRUE );
    return 0;
}

IMPL_LINK( SvImpIconView, ScrollLeftRightHdl, ScrollBar *, pScrollBar )
{
    pView->EndEditing( TRUE );
    // Pfeil links: delta=-1; Pfeil rechts: delta=+1
    Scroll( pScrollBar->GetDelta(), 0, TRUE );
    return 0;
}

void SvImpIconView::ChangedFont()
{
    StopEditTimer();
    ImpArrange();
}


void SvImpIconView::CheckAllSizes()
{
    nMaxTextWidth = 0;
    nMaxBmpWidth = 0;
    nMaxBmpHeight = 0;
    SvLBoxEntry* pEntry = pModel->First();
    while( pEntry )
    {
        CheckSizes( pEntry );
        pEntry = pModel->Next( pEntry );
    }
}

void SvImpIconView::CheckSizes( SvLBoxEntry* pEntry,
    const SvIcnVwDataEntry* pViewData )
{
    Size aSize;

    if( !pViewData )
        pViewData = ICNVIEWDATA(pEntry);

    SvLBoxString* pStringItem = (SvLBoxString*)(pEntry->GetFirstItem(SV_ITEM_ID_LBOXSTRING));
    if( pStringItem )
    {
        aSize = GetItemSize( pView, pEntry, pStringItem, pViewData );
        if( aSize.Width() > nMaxTextWidth )
        {
            nMaxTextWidth = aSize.Width();
            if( !(nFlags & F_GRIDMODE ) )
                bMustRecalcBoundingRects = TRUE;
        }
    }
    SvLBoxContextBmp* pBmpItem = (SvLBoxContextBmp*)(pEntry->GetFirstItem(SV_ITEM_ID_LBOXCONTEXTBMP));
    if( pBmpItem )
    {
        aSize = GetItemSize( pView, pEntry, pBmpItem, pViewData );
        if( aSize.Width() > nMaxBmpWidth )
        {
            nMaxBmpWidth = aSize.Width();
            nMaxBmpWidth += (2*LROFFS_ICON);
            if( !(nFlags & F_GRIDMODE ) )
                bMustRecalcBoundingRects = TRUE;
        }
        if( aSize.Height() > nMaxBmpHeight )
        {
            nMaxBmpHeight = aSize.Height();
            nMaxBmpHeight += (2*TBOFFS_ICON);;
            if( !(nFlags & F_GRIDMODE ) )
                bMustRecalcBoundingRects = TRUE;
        }
    }
}

void SvImpIconView::EntryInserted( SvLBoxEntry* pEntry )
{
    if( pModel->GetParent(pEntry) == pCurParent )
    {
        StopEditTimer();
        DBG_ASSERT(pZOrderList->GetPos(pEntry)==0xffff,"EntryInserted:ZOrder?");
        pZOrderList->Insert( pEntry, pZOrderList->Count() );
        if( nFlags & F_GRIDMODE )
            pImpCursor->Clear( FALSE );
        else
            pImpCursor->Clear( TRUE );
        SvIcnVwDataEntry* pViewData = ICNVIEWDATA(pEntry);
        CheckSizes( pEntry, pViewData );
        if( pView->IsUpdateMode() )
        {
            FindBoundingRect( pEntry, pViewData );
            PaintEntry( pEntry, pViewData );
        }
        else
            InvalidateBoundingRect( pViewData->aRect );
    }
}

void SvImpIconView::RemovingEntry( SvLBoxEntry* pEntry )
{
    if( pModel->GetParent(pEntry) == pCurParent)
    {
        StopEditTimer();
        DBG_ASSERT(pZOrderList->GetPos(pEntry)!=0xffff,"RemovingEntry:ZOrder?");
        SvIcnVwDataEntry* pViewData = ICNVIEWDATA(pEntry);
        if( IsBoundingRectValid( pViewData->aRect ) )
        {
            // bei gueltigem Bounding-Rect muss in EntryRemoved eine
            // Sonderbehandlung erfolgen
            nFlags |= F_ENTRY_REMOVED;
            pView->Invalidate( pViewData->aRect );
        }
        if( pEntry == pCursor )
        {
            SvLBoxEntry* pNewCursor = GetNewCursor();
            ShowCursor( FALSE );
            pCursor = 0; // damit er nicht deselektiert wird
            SetCursor( pNewCursor );
        }
        USHORT nPos = pZOrderList->GetPos( (void*)pEntry );
        pZOrderList->Remove( nPos, 1 );
        pImpCursor->Clear();
    }
}

void SvImpIconView::EntryRemoved()
{
    if( (nFlags & (F_ENTRY_REMOVED | F_PAINTED)) == (F_ENTRY_REMOVED | F_PAINTED))
    {
        // Ein Eintrag mit gueltigem BoundRect wurde geloescht und wir
        // haben schon mal gepaintet. In diesem Fall muessen wir die
        // Position des naechsten Eintrags, der eingefuegt wird oder noch
        // kein gueltiges BoundRect hat, "suchen" d.h. ein "Loch" in
        // der View auffuellen.
        nFlags &= ~( F_ENTRY_REMOVED | F_GRID_INSERT );
    }
}


void SvImpIconView::MovingEntry( SvLBoxEntry* pEntry )
{
    DBG_ASSERT(pEntry,"MovingEntry: 0!");
    pNextCursor = 0;
    StopEditTimer();
    if( pModel->GetParent(pEntry) == pCurParent )
    {
        DBG_ASSERT(pZOrderList->GetPos(pEntry)!=0xffff,"MovingEntry:ZOrder?");
        nFlags |= F_MOVING_SIBLING;
        SvIcnVwDataEntry* pViewData = ICNVIEWDATA(pEntry);
        if( IsBoundingRectValid( pViewData->aRect ) )
            pView->Invalidate( pViewData->aRect );
        // falls Eintrag seinen Parent wechselt vorsichtshalber
        // die neue Cursorposition berechnen
        if( pEntry == pCursor )
            pNextCursor = GetNewCursor();
        pImpCursor->Clear();
    }
}


void SvImpIconView::EntryMoved( SvLBoxEntry* pEntry )
{
    ShowCursor( FALSE );
    SvIcnVwDataEntry* pViewData = ICNVIEWDATA(pEntry);
    if( pModel->GetParent(pEntry)==pCurParent )
    {
        if( nFlags & F_MOVING_SIBLING )
        {
            // die Neu-Positionierung eines Eintrags bei D&D innerhalb
            // einer IconView findet bereits in NotifyMoving statt
            // (MovingEntry/EntryMoved wird dann nicht mehr gerufen)
            ToTop( pEntry );
        }
        else
        {
            pImpCursor->Clear();
            pZOrderList->Insert( pEntry, pZOrderList->Count() );
            DBG_ASSERT(pZOrderList->Count()==pModel->GetChildCount(pCurParent),"EntryMoved:Bad zorder count");
            FindBoundingRect( pEntry, pViewData );
        }
        PaintEntry( pEntry, pViewData );
    }
    else
    {
        if( pEntry == pCursor )
        {
            DBG_ASSERT(pNextCursor,"EntryMoved: Next cursor bad");
            SetCursor( pNextCursor );
        }
        pImpCursor->Clear();
        USHORT nPos = pZOrderList->GetPos( (void*)pEntry );
        pZOrderList->Remove( nPos, 1 );
        pView->Select( pEntry, FALSE );
        // wenn er nochmal in dieser View auftaucht, muss sein
        // Bounding-Rect neu berechnet werden
        InvalidateBoundingRect( pViewData->aRect );
    }
    nFlags &= (~F_MOVING_SIBLING);
}

void SvImpIconView::TreeInserted( SvLBoxEntry* pEntry )
{
    EntryMoved( pEntry ); // vorlaeufig
}

void SvImpIconView::EntryExpanded( SvLBoxEntry* )
{
}

void SvImpIconView::EntryCollapsed( SvLBoxEntry*)
{
}

void SvImpIconView::CollapsingEntry( SvLBoxEntry* )
{
}

void SvImpIconView::EntrySelected( SvLBoxEntry* pEntry, BOOL bSelect )
{
    if( pModel->GetParent(pEntry) != pCurParent  )
        return;

    // bei SingleSelection dafuer sorgen, dass der Cursor immer
    // auf dem (einzigen) selektierten Eintrag steht
    if( bSelect && pCursor &&
        pView->GetSelectionMode() == SINGLE_SELECTION &&
        pEntry != pCursor )
    {
        SetCursor( pEntry );
        DBG_ASSERT(pView->GetSelectionCount()==1,"selection count?");
    }
    // bei Gummibandselektion ist uns das zu teuer
    if( !(nFlags & F_RUBBERING ))
        ToTop( pEntry );
    if( pView->IsUpdateMode() )
    {
        if( pEntry == pCursor )
            ShowCursor( FALSE );
        if( nFlags & F_RUBBERING )
            PaintEntry( pEntry );
        else
            pView->Invalidate( GetBoundingRect( pEntry ) );
        if( pEntry == pCursor )
            ShowCursor( TRUE );
    }
}

void SvImpIconView::SetNextEntryPos(const Point& rPos)
{
    aPrevBoundRect.SetPos( rPos );
    aPrevBoundRect.Right() = LONG_MAX;  // dont know
}

Point SvImpIconView::FindNextEntryPos( const Size& rBoundSize )
{
    if( nFlags & F_GRIDMODE )
    {
        if( nFlags & F_GRID_INSERT )
        {
            if( aPrevBoundRect.Right() != LONG_MAX )
            {
                // passt der naechste Entry noch in die Zeile ?
                long nNextWidth = aPrevBoundRect.Right() + nGridDX + LROFFS_WINBORDER;
                if( nNextWidth > aVirtOutputSize.Width() )
                {
                    // darf aVirtOutputSize verbreitert werden ?
                    if( nNextWidth < nMaxVirtWidth )
                    {
                        // verbreitern & in Zeile aufnehmen
                        aPrevBoundRect.Left() += nGridDX;
                    }
                    else
                    {
                        // erhoehen & neue Zeile beginnen
                        aPrevBoundRect.Top() += nGridDY;
                        aPrevBoundRect.Left() = LROFFS_WINBORDER;
                    }
                }
                else
                {
                    // in die Zeile aufnehmen
                    aPrevBoundRect.Left() += nGridDX;
                }
            }
            aPrevBoundRect.SetSize( Size( nGridDX, nGridDY ) );
        }
        else
        {
            if( !pImpCursor->FindEmptyGridRect( aPrevBoundRect ) )
            {
                // mitten in den Entries gibts keine Loecher mehr,
                // wir koennen also wieder ins "Fast Insert" springen
                nFlags |= F_GRID_INSERT;
            }
        }
    }
    else
    {
        if( aPrevBoundRect.Right() != LONG_MAX )
        {
            // passt der naechste Entry noch in die Zeile ?
            long nNextWidth=aPrevBoundRect.Right()+rBoundSize.Width()+LROFFS_BOUND+nHorDist;
            if( nNextWidth > aVirtOutputSize.Width() )
            {
                // darf aVirtOutputSize verbreitert werden ?
                if( nNextWidth < nMaxVirtWidth )
                {
                    // verbreitern & in Zeile aufnehmen
                    aPrevBoundRect.SetPos( aPrevBoundRect.TopRight() );
                    aPrevBoundRect.Left() += nHorDist;
                }
                else
                {
                    // erhoehen & neue Zeile beginnen
                    aPrevBoundRect.Top() += nMaxBoundHeight + nVerDist + TBOFFS_BOUND;
                    aPrevBoundRect.Left() = LROFFS_WINBORDER;
                }
            }
            else
            {
                // in die Zeile aufnehmen
                aPrevBoundRect.SetPos( aPrevBoundRect.TopRight() );
                aPrevBoundRect.Left() += nHorDist;
            }
        }
        aPrevBoundRect.SetSize( rBoundSize );
    }
    return aPrevBoundRect.TopLeft();
}

void SvImpIconView::ResetVirtSize()
{
    StopEditTimer();
    aVirtOutputSize.Width() = 0;
    aVirtOutputSize.Height() = 0;
    BOOL bLockedEntryFound = FALSE;
    nFlags &= (~F_GRID_INSERT);
    SvLBoxEntry* pCur = pModel->FirstChild( pCurParent );
    while( pCur )
    {
        SvIcnVwDataEntry* pViewData = ICNVIEWDATA(pCur);
        if( pViewData->IsEntryPosLocked() )
        {
            // VirtSize u.a. anpassen
            if( !IsBoundingRectValid( pViewData->aRect ) )
                FindBoundingRect( pCur, pViewData );
            else
                AdjustVirtSize( pViewData->aRect );
            bLockedEntryFound = TRUE;
        }
        else
            InvalidateBoundingRect( pViewData->aRect );

        pCur = pModel->NextSibling( pCur );
    }
    if( !bLockedEntryFound )
    {
        //XXX
        nFlags |= F_GRID_INSERT;
    }

    SetNextEntryPos( Point( LROFFS_WINBORDER, TBOFFS_WINBORDER ) );
    pImpCursor->Clear();
}


void SvImpIconView::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();
        AdjustScrollBars();
    }
}

void SvImpIconView::Arrange()
{
    nMaxVirtWidth = aOutputSize.Width();
    ImpArrange();
}

void SvImpIconView::ImpArrange()
{
    StopEditTimer();
    ShowCursor( FALSE );
    ResetVirtSize();
    bMustRecalcBoundingRects = FALSE;
    MapMode aMapMode( pView->GetMapMode());
    aMapMode.SetOrigin( Point() );
    pView->SetMapMode( aMapMode );
    CheckAllSizes();
    RecalcAllBoundingRectsSmart();
    pView->Invalidate();
    ShowCursor( TRUE );
}

void SvImpIconView::Paint( const Rectangle& rRect )
{
    if( !pView->IsUpdateMode() )
        return;

#if defined(DBG_UTIL) && defined(OV_DRAWGRID)
    if( nFlags & F_GRIDMODE )
    {
        Color aOldColor = pView->GetLineColor();
        Color aNewColor( COL_BLACK );
        pView->SetLineColor( aNewColor );
        Point aOffs( pView->GetMapMode().GetOrigin());
        Size aXSize( pView->GetOutputSizePixel() );
        for( long nDX = nGridDX; nDX <= aXSize.Width(); nDX += nGridDX )
        {
            Point aStart( nDX+LROFFS_BOUND, 0 );
            Point aEnd( nDX+LROFFS_BOUND, aXSize.Height());
            aStart -= aOffs;
            aEnd -= aOffs;
            pView->DrawLine( aStart, aEnd );
        }
        for( long nDY = nGridDY; nDY <= aXSize.Height(); nDY += nGridDY )
        {
            Point aStart( 0, nDY+TBOFFS_BOUND );
            Point aEnd( aXSize.Width(), nDY+TBOFFS_BOUND );
            aStart -= aOffs;
            aEnd -= aOffs;
            pView->DrawLine( aStart, aEnd );
        }
        pView->SetLineColor( aOldColor );
    }
#endif
    nFlags |= F_PAINTED;

    if( !(pModel->HasChilds( pCurParent ) ))
        return;
    if( !pCursor )
        pCursor = pModel->FirstChild( pCurParent );

    USHORT nCount = pZOrderList->Count();
    if( !nCount )
        return;

    SvPtrarr* pNewZOrderList = new SvPtrarr;
    SvPtrarr* pPaintedEntries = new SvPtrarr;

    USHORT nPos = 0;
    while( nCount )
    {
        SvLBoxEntry* pEntry = (SvLBoxEntry*)(pZOrderList->GetObject(nPos ));
        SvIcnVwDataEntry* pViewData = ICNVIEWDATA(pEntry);
        const Rectangle& rBoundRect = GetBoundingRect( pEntry, pViewData );
        if( rRect.IsOver( rBoundRect ) )
        {
            PaintEntry( pEntry, rBoundRect.TopLeft(), pViewData );
            // Eintraege, die neu gezeichnet werden, auf Top setzen
            pPaintedEntries->Insert( pEntry, pPaintedEntries->Count() );
        }
        else
            pNewZOrderList->Insert( pEntry, pNewZOrderList->Count() );

        nCount--;
        nPos++;
    }
    delete pZOrderList;
    pZOrderList = pNewZOrderList;
    nCount = pPaintedEntries->Count();
    if( nCount )
    {
        for( USHORT nCur = 0; nCur < nCount; nCur++ )
            pZOrderList->Insert( pPaintedEntries->GetObject( nCur ),pZOrderList->Count());
    }
    delete pPaintedEntries;

    Rectangle aRect;
    if( GetResizeRect( aRect ))
        PaintResizeRect( aRect );
}

BOOL SvImpIconView::GetResizeRect( Rectangle& rRect )
{
    if( aHorSBar.IsVisible() && aVerSBar.IsVisible() )
    {
        const MapMode& rMapMode = pView->GetMapMode();
        Point aOrigin( rMapMode.GetOrigin());
        aOrigin *= -1;
        aOrigin.X() += aOutputSize.Width();
        aOrigin.Y() += aOutputSize.Height();
        rRect.SetPos( aOrigin );
        rRect.SetSize( Size( nVerSBarWidth, nHorSBarHeight));
        return TRUE;
    }
    return FALSE;
}

void SvImpIconView::PaintResizeRect( const Rectangle& rRect )
{
    const StyleSettings& rStyleSettings = pView->GetSettings().GetStyleSettings();
    Color aNewColor = rStyleSettings.GetFaceColor();
    Color aOldColor = pView->GetFillColor();
    pView->SetFillColor( aNewColor );
    pView->DrawRect( rRect );
    pView->SetFillColor( aOldColor );
}

void SvImpIconView::RepaintSelectionItems()
{
    DBG_ERROR("RepaintSelectionItems");
    pView->Invalidate(); // vorlaeufig
}

SvLBoxItem* SvImpIconView::GetItem( SvLBoxEntry* pEntry,
                    const Point& rAbsPos )
{
    Rectangle aRect;
    SvLBoxString* pStringItem = (SvLBoxString*)(pEntry->GetFirstItem(SV_ITEM_ID_LBOXSTRING));
    if( pStringItem )
    {
        aRect = CalcTextRect( pEntry, pStringItem );
        if( aRect.IsInside( rAbsPos ) )
            return pStringItem;
    }
    SvLBoxContextBmp* pBmpItem = (SvLBoxContextBmp*)(pEntry->GetFirstItem(SV_ITEM_ID_LBOXCONTEXTBMP));
    if( pBmpItem )
    {
        aRect = CalcBmpRect( pEntry );
        if( aRect.IsInside( rAbsPos ) )
            return pBmpItem;
    }
    return 0;
}

void SvImpIconView::CalcDocPos( Point& aMaeuschenPos )
{
    aMaeuschenPos -= pView->GetMapMode().GetOrigin();
}

void SvImpIconView::MouseButtonDown( const MouseEvent& rMEvt)
{
    StopEditTimer();
    pView->GrabFocus();
    Point aDocPos( rMEvt.GetPosPixel() );
    if(aDocPos.X()>=aOutputSize.Width() || aDocPos.Y()>=aOutputSize.Height())
        return;
    CalcDocPos( aDocPos );
    SvLBoxEntry* pEntry = GetEntry( aDocPos );
    if( !pEntry )
    {
        if( pView->GetSelectionMode() != SINGLE_SELECTION )
        {
            if( !rMEvt.IsMod1() )  // Ctrl
            {
                pView->SelectAll( FALSE );
                ClearSelectedRectList();
            }
            else
                nFlags |= F_ADD_MODE;
            nFlags |= F_RUBBERING;
            aCurSelectionRect.SetPos( aDocPos );
            pView->CaptureMouse();
        }
        return;
    }

    BOOL bSelected = pView->IsSelected( pEntry );
    BOOL bEditingEnabled = pView->IsInplaceEditingEnabled();

    if( rMEvt.GetClicks() == 2 )
    {
        DeselectAllBut( pEntry );
        pView->pHdlEntry = pEntry;
        pView->DoubleClickHdl();
    }
    else
    {
        // Inplace-Editing ?
        if( rMEvt.IsMod2() )  // Alt?
        {
            if( bEditingEnabled )
            {
                SvLBoxItem* pItem = GetItem(pEntry,aDocPos);
                if( pItem )
                    pView->EditingRequest( pEntry, pItem, aDocPos);
            }
        }
        else if( pView->GetSelectionMode() == SINGLE_SELECTION )
        {
            DeselectAllBut( pEntry );
            SetCursor( pEntry );
            pView->Select( pEntry, TRUE );
            if( bEditingEnabled && bSelected && !rMEvt.GetModifier() &&
                rMEvt.IsLeft() && IsTextHit( pEntry, aDocPos ) )
            {
                nFlags |= F_START_EDITTIMER_IN_MOUSEUP;
            }
        }
        else
        {
            if( !rMEvt.GetModifier() )
            {
                if( !bSelected )
                {
                    DeselectAllBut( pEntry );
                    SetCursor( pEntry );
                    pView->Select( pEntry, TRUE );
                }
                else
                {
                    // erst im Up deselektieren, falls Move per 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;
        }
    }
}

void SvImpIconView::MouseButtonUp( const MouseEvent& rMEvt )
{
    aMouseMoveTimer.Stop();
    pView->ReleaseMouse();
    // HACK, da Einar noch nicht PrepareCommandEvent aufruft
    if( rMEvt.IsRight() && (nFlags & (F_DOWN_CTRL | F_DOWN_DESELECT) ))
        nFlags &= ~(F_DOWN_CTRL | F_DOWN_DESELECT);

    if( nFlags & F_RUBBERING )
    {
        aMouseMoveTimer.Stop();
        AddSelectedRect( aCurSelectionRect );
        HideSelectionRect();
        nFlags &= ~(F_RUBBERING | F_ADD_MODE);
    }

    SvLBoxEntry* pEntry = pView->GetEntry( rMEvt.GetPosPixel(), TRUE );
    if( pEntry )
    {
        if( nFlags & F_DOWN_CTRL )
        {
            // Ctrl & MultiSelection
            ToggleSelection( pEntry );
            SetCursor( pEntry );
        }
        else if( nFlags & F_DOWN_DESELECT )
        {
            DeselectAllBut( pEntry );
            SetCursor( pEntry );
            pView->Select( pEntry, TRUE );
        }
    }

    nFlags &= ~(F_DOWN_CTRL | F_DOWN_DESELECT);
    if( nFlags & F_START_EDITTIMER_IN_MOUSEUP )
    {
        StartEditTimer();
        nFlags &= ~F_START_EDITTIMER_IN_MOUSEUP;
    }
}

void SvImpIconView::MouseMove( const MouseEvent& rMEvt )
{
    if( nFlags & F_RUBBERING )
    {
        const Point& rPosPixel = rMEvt.GetPosPixel();
        if( !aMouseMoveTimer.IsActive() )
        {
            aMouseMoveEvent = rMEvt;
            aMouseMoveTimer.Start();
            // ausserhalb des Fensters liegende Move-Events muessen
            // vom Timer kommen, damit die Scrollgeschwindigkeit
            // unabhaengig von Mausbewegungen ist.
            if( rPosPixel.X() < 0 || rPosPixel.Y() < 0 )
                return;
            const Size& rSize = pView->GetOutputSizePixel();
            if( rPosPixel.X() > rSize.Width() || rPosPixel.Y() > rSize.Height())
                return;
        }

        if( &rMEvt != &aMouseMoveEvent )
            aMouseMoveEvent = rMEvt;

        long nScrollDX, nScrollDY;

        CalcScrollOffsets(rMEvt.GetPosPixel(),nScrollDX,nScrollDY,FALSE );
        BOOL bSelRectHidden = FALSE;
        if( nScrollDX || nScrollDY )
        {
            HideSelectionRect();
            bSelRectHidden = TRUE;
            pView->Scroll( nScrollDX, nScrollDY );
        }
        Point aDocPos( rMEvt.GetPosPixel() );
        aDocPos = pView->PixelToLogic( aDocPos );
        Rectangle aRect( aCurSelectionRect.TopLeft(), aDocPos );
        if( aRect != aCurSelectionRect )
        {
            HideSelectionRect();
            bSelRectHidden = TRUE;
            BOOL bAdd = (nFlags & F_ADD_MODE) ? TRUE : FALSE;
            SelectRect( aRect, bAdd, &aSelectedRectList );
        }
        if( bSelRectHidden )
            DrawSelectionRect( aRect );
    }
}

BOOL SvImpIconView::KeyInput( const KeyEvent& rKEvt )
{
    StopEditTimer();
    BOOL bKeyUsed = TRUE;
    BOOL bMod1 = rKEvt.GetKeyCode().IsMod1();
    BOOL bInAddMode = (BOOL)((nFlags & F_ADD_MODE) != 0);
    int bDeselAll = (pView->GetSelectionMode() != SINGLE_SELECTION) &&
                    !bInAddMode;
    SvLBoxEntry* pNewCursor;
    USHORT nCode = rKEvt.GetKeyCode().GetCode();
    switch( nCode )
    {
        case KEY_UP:
            if( pCursor )
            {
                MakeVisible( pCursor );
                pNewCursor = pImpCursor->GoUpDown(pCursor,FALSE);
                if( pNewCursor )
                {
                    if( bDeselAll )
                        pView->SelectAll( FALSE );
                    ShowCursor( FALSE );
                    MakeVisible( pNewCursor );
                    SetCursor( pNewCursor );
                    if( !bInAddMode )
                        pView->Select( pCursor, TRUE );
                }
                else
                {
                    Rectangle aRect( GetBoundingRect( pCursor ) );
                    if( aRect.Top())
                    {
                        aRect.Bottom() -= aRect.Top();
                        aRect.Top() = 0;
                        MakeVisible( aRect );
                    }
                }
            }
            break;

        case KEY_DOWN:
            if( pCursor )
            {
                pNewCursor=pImpCursor->GoUpDown( pCursor,TRUE );
                if( pNewCursor )
                {
                    MakeVisible( pCursor );
                    if( bDeselAll )
                        pView->SelectAll( FALSE );
                    ShowCursor( FALSE );
                    MakeVisible( pNewCursor );
                    SetCursor( pNewCursor );
                    if( !bInAddMode )
                        pView->Select( pCursor, TRUE );
                }
            }
            break;

        case KEY_RIGHT:
            if( pCursor )
            {
                pNewCursor=pImpCursor->GoLeftRight(pCursor,TRUE );
                if( pNewCursor )
                {
                    MakeVisible( pCursor );
                    if( bDeselAll )
                        pView->SelectAll( FALSE );
                    ShowCursor( FALSE );
                    MakeVisible( pNewCursor );
                    SetCursor( pNewCursor );
                    if( !bInAddMode )
                        pView->Select( pCursor, TRUE );
                }
            }
            break;

        case KEY_LEFT:
            if( pCursor )
            {
                MakeVisible( pCursor );
                pNewCursor = pImpCursor->GoLeftRight(pCursor,FALSE );
                if( pNewCursor )
                {
                    if( bDeselAll )
                        pView->SelectAll( FALSE );
                    ShowCursor( FALSE );
                    MakeVisible( pNewCursor );
                    SetCursor( pNewCursor );
                    if( !bInAddMode )
                        pView->Select( pCursor, TRUE );
                }
                else
                {
                    Rectangle aRect( GetBoundingRect(pCursor));
                    if( aRect.Left() )
                    {
                        aRect.Right() -= aRect.Left();
                        aRect.Left() = 0;
                        MakeVisible( aRect );
                    }
                }
            }
            break;

        case KEY_ESCAPE:
            if( nFlags & F_RUBBERING )
            {
                HideSelectionRect();
                pView->SelectAll( FALSE );
                nFlags &= ~F_RUBBERING;
            }
            break;

        case KEY_F8:
            if( rKEvt.GetKeyCode().IsShift() )
            {
                if( nFlags & F_ADD_MODE )
                    nFlags &= (~F_ADD_MODE);
                else
                    nFlags |= F_ADD_MODE;
            }
            break;

#ifdef OS2
        case KEY_F9:
            if( rKEvt.GetKeyCode().IsShift() )
            {
                if( pCursor && pView->IsInplaceEditingEnabled() )
                    pView->EditEntry( pCursor );
            }
            break;
#endif

        case KEY_SPACE:
            if( pCursor )
            {
                ToggleSelection( pCursor );
            }
            break;


        case KEY_PAGEDOWN:
            break;
        case KEY_PAGEUP:
            break;

        case KEY_ADD:
        case KEY_DIVIDE :
            if( bMod1 )
                pView->SelectAll( TRUE );
            break;

        case KEY_SUBTRACT:
        case KEY_COMMA :
            if( bMod1 )
                pView->SelectAll( FALSE );
            break;

        case KEY_RETURN:
            if( bMod1 )
            {
                if( pCursor && pView->IsInplaceEditingEnabled() )
                    pView->EditEntry( pCursor );
            }
            break;

        default:
            bKeyUsed = FALSE;

    }
    return bKeyUsed;
}


void SvImpIconView::PositionScrollBars( long nRealWidth, long nRealHeight )
{
    // hor scrollbar
    Point aPos( 0, nRealHeight );
    aPos.Y() -= nHorSBarHeight;

#ifdef WIN
    // vom linken und unteren Rand ein Pixel abschneiden
    aPos.Y()++;
    aPos.X()--;
#endif
#ifdef OS2
    aPos.Y()++;
#endif
    if( aHorSBar.GetPosPixel() != aPos )
        aHorSBar.SetPosPixel( aPos );

    // ver scrollbar
    aPos.X() = nRealWidth; aPos.Y() = 0;
    aPos.X() -= nVerSBarWidth;

#if defined(WIN) || defined(WNT)
    aPos.X()++;
    aPos.Y()--;
#endif

#ifdef OS2
    aPos.Y()--;
    aPos.X()++;
#endif

    if( aVerSBar.GetPosPixel() != aPos )
        aVerSBar.SetPosPixel( aPos );
}



void SvImpIconView::AdjustScrollBars()
{
    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 = (pView->nWindowStyle & WB_VSCROLL) ? true : false;
    bool bHorSBar = (pView->nWindowStyle & WB_HSCROLL) ? true : false;

    USHORT nResult = 0;
    if( nVirtHeight )
    {
        // activate ver scrollbar ?
        if( bVerSBar || ( nVirtHeight > nVisibleHeight) )
        {
            nResult = 0x0001;
            nRealWidth -= nVerSBarWidth;

            if( nRealWidth > nVirtWidth )
                nVisibleWidth = nVirtWidth + aOrigin.X();
            else
                nVisibleWidth = nRealWidth;

            nFlags |= F_HOR_SBARSIZE_WITH_VBAR;
        }
        // activate hor scrollbar ?
        if( bHorSBar || (nVirtWidth > nVisibleWidth) )
        {
            nResult |= 0x0002;
            nRealHeight -= nHorSBarHeight;

            if( nRealHeight > nVirtHeight )
                nVisibleHeight = nVirtHeight + aOrigin.Y();
            else
                nVisibleHeight = nRealHeight;

            // brauchen wir jetzt doch eine senkrechte Scrollbar ?
            if( !(nResult & 0x0001) &&  // nur wenn nicht schon da
                ( (nVirtHeight > nVisibleHeight) || bVerSBar) )
            {
                nResult = 3; // both are active
                nRealWidth -= nVerSBarWidth;

                if( nRealWidth > nVirtWidth )
                    nVisibleWidth = nVirtWidth + aOrigin.X();
                else
                    nVisibleWidth = nRealWidth;

                nFlags |= F_VER_SBARSIZE_WITH_HBAR;
            }
        }
    }

    // size ver scrollbar
    long nThumb = aVerSBar.GetThumbPos();
    Size aSize( nVerSBarWidth, nRealHeight );
#if defined(WIN) || defined(WNT)
    aSize.Height() += 2;
#endif
#ifdef OS2
    aSize.Height() += 3;
#endif
    if( aSize != aVerSBar.GetSizePixel() )
        aVerSBar.SetSizePixel( aSize );
    aVerSBar.SetVisibleSize( nVisibleHeight );
    aVerSBar.SetPageSize( (nVisibleHeight*75)/100 );
    if( nResult & 0x0001 )
    {
        aVerSBar.SetThumbPos( nThumb );
        aVerSBar.Show();
    }
    else
    {
        aVerSBar.SetThumbPos( 0 );
        aVerSBar.Hide();
    }

    // size hor scrollbar
    nThumb = aHorSBar.GetThumbPos();
    aSize.Width() = nRealWidth;
    aSize.Height() = nHorSBarHeight;
#if defined(WIN) || defined(WNT)
    aSize.Width()++;
#endif
#ifdef OS2
    aSize.Width() += 3;
    if( nResult & 0x0001 ) // vertikale Scrollbar ?
        aSize.Width()--;
#endif
#if defined(WIN) || defined(WNT)
    if( nResult & 0x0001 ) // vertikale Scrollbar ?
    {
        aSize.Width()++;
        nRealWidth++;
    }
#endif
    if( aSize != aHorSBar.GetSizePixel() )
        aHorSBar.SetSizePixel( aSize );
    aHorSBar.SetVisibleSize( nVisibleWidth ); //nRealWidth );
    aHorSBar.SetPageSize( (nVisibleWidth*75)/100 );
    if( nResult & 0x0002 )
    {
        aHorSBar.SetThumbPos( nThumb );
        aHorSBar.Show();
    }
    else
    {
        aHorSBar.SetThumbPos( 0 );
        aHorSBar.Hide();
    }

#ifdef OS2
    nRealWidth++;
#endif
    aOutputSize.Width() = nRealWidth;
#if defined(WIN) || defined(WNT)
    if( nResult & 0x0002 ) // hor scrollbar ?
        nRealHeight++; // weil unterer Rand geclippt wird
#endif
#ifdef OS2
    if( nResult & 0x0002 ) // hor scrollbar ?
        nRealHeight++;
#endif
    aOutputSize.Height() = nRealHeight;
}

void __EXPORT SvImpIconView::Resize()
{
    StopEditTimer();
    Rectangle aRect;
    if( GetResizeRect(aRect) )
        pView->Invalidate( aRect );
    aOutputSize = pView->GetOutputSizePixel();
    pImpCursor->Clear();

#if 1
    const Size& rSize = pView->Control::GetOutputSizePixel();
    PositionScrollBars( rSize.Width(), rSize.Height() );
    // Die ScrollBars werden asynchron ein/ausgeblendet, damit abgeleitete
    // Klassen im Resize ein Arrange durchfuehren koennen, ohne dass
    // die ScrollBars aufblitzen (SfxExplorerIconView!)
    nCurUserEvent = Application::PostUserEvent(LINK(this,SvImpIconView,UserEventHdl),0);
#else
    AdjustScrollBars();
    if( GetResizeRect(aRect) )
        PaintResizeRect( aRect );
#endif
}

BOOL SvImpIconView::CheckHorScrollBar()
{
    if( !pZOrderList || !aHorSBar.IsVisible() )
        return FALSE;
    const MapMode& rMapMode = pView->GetMapMode();
    Point aOrigin( rMapMode.GetOrigin() );
    if(!(pView->nWindowStyle & WB_HSCROLL) && !aOrigin.X() )
    {
        long nWidth = aOutputSize.Width();
        USHORT nCount = pZOrderList->Count();
        long nMostRight = 0;
        for( USHORT nCur = 0; nCur < nCount; nCur++ )
        {
            SvLBoxEntry* pEntry = (SvLBoxEntry*)pZOrderList->operator[](nCur);
            long nRight = GetBoundingRect(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 SvImpIconView::CheckVerScrollBar()
{
    if( !pZOrderList || !aVerSBar.IsVisible() )
        return FALSE;
    const MapMode& rMapMode = pView->GetMapMode();
    Point aOrigin( rMapMode.GetOrigin() );
    if(!(pView->nWindowStyle & WB_VSCROLL) && !aOrigin.Y() )
    {
        long nDeepest = 0;
        long nHeight = aOutputSize.Height();
        USHORT nCount = pZOrderList->Count();
        for( USHORT nCur = 0; nCur < nCount; nCur++ )
        {
            SvLBoxEntry* pEntry = (SvLBoxEntry*)pZOrderList->operator[](nCur);
            long nBottom = GetBoundingRect(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;
}


// blendet Scrollbars aus, wenn sie nicht mehr benoetigt werden
void SvImpIconView::CheckScrollBars()
{
    CheckVerScrollBar();
    if( CheckHorScrollBar() )
        CheckVerScrollBar();
}


void __EXPORT SvImpIconView::GetFocus()
{
    if( pCursor )
    {
        pView->SetEntryFocus( pCursor, TRUE );
        ShowCursor( TRUE );
    }
}

void __EXPORT SvImpIconView::LoseFocus()
{
    StopEditTimer();
    if( pCursor )
        pView->SetEntryFocus( pCursor,FALSE );
    ShowCursor( FALSE );
}

void SvImpIconView::UpdateAll()
{
    AdjustScrollBars();
    pImpCursor->Clear();
    pView->Invalidate();
}

void SvImpIconView::PaintEntry( SvLBoxEntry* pEntry, SvIcnVwDataEntry* pViewData )
{
    Point aPos( GetEntryPosition( pEntry ) );
    PaintEntry( pEntry, aPos, pViewData );
}

void SvImpIconView::PaintEmphasis( const Rectangle& rRect, BOOL bSelected,
                                   BOOL bCursored, OutputDevice* pOut )
{
    // HACK fuer D&D
    if( nFlags & F_NO_EMPHASIS )
        return;

    if( !pOut )
        pOut = pView;

    // Selektion painten
    Color aOldFillColor =  pOut->GetFillColor();
    Color aOldLineColor =  pOut->GetLineColor();
    Color aNewColor;
    const StyleSettings& rStyleSettings = pOut->GetSettings().GetStyleSettings();
    if( bSelected )
    {
        aNewColor = rStyleSettings.GetHighlightColor();
    }
    else
    {
#ifndef OS2
        aNewColor =rStyleSettings.GetFieldColor();
#else
        aNewColor = pOut->GetBackground().GetColor();
#endif
    }

    if( bCursored )
    {
        pOut->SetLineColor( Color( COL_BLACK ) );
    }
    pOut->SetFillColor( aNewColor );
    pOut->DrawRect( rRect );
    pOut->SetFillColor( aOldFillColor );
    pOut->SetLineColor( aOldLineColor );
}

void SvImpIconView::PaintItem( const Rectangle& rRect,
    SvLBoxItem* pItem, SvLBoxEntry* pEntry, USHORT nPaintFlags,
    OutputDevice* pOut )
{
    if( nViewMode == VIEWMODE_ICON && pItem->IsA() == SV_ITEM_ID_LBOXSTRING )
    {
        const String& rStr = ((SvLBoxString*)pItem)->GetText();
        DrawText( pOut, rRect, rStr, DRAWTEXT_FLAGS );
    }
    else
    {
        Point aPos( rRect.TopLeft() );
        const Size& rSize = GetItemSize( pView, pEntry, pItem );
        if( nPaintFlags & PAINTFLAG_HOR_CENTERED )
            aPos.X() += (rRect.GetWidth() - rSize.Width() ) / 2;
        if( nPaintFlags & PAINTFLAG_VER_CENTERED )
            aPos.Y() += (rRect.GetHeight() - rSize.Height() ) / 2;
        pItem->Paint( aPos, *(SvLBox*)pOut, 0, pEntry );
    }
}

void SvImpIconView::PaintEntry( SvLBoxEntry* pEntry, const Point& rPos,
    SvIcnVwDataEntry* pViewData, OutputDevice* pOut )
{
    if( !pView->IsUpdateMode() )
        return;

    if( !pOut )
        pOut = pView;

    SvLBoxContextBmp* pBmpItem;

    pView->PreparePaint( pEntry );

    if( !pViewData )
        pViewData = ICNVIEWDATA(pEntry);

    SvLBoxString* pStringItem = (SvLBoxString*)(pEntry->GetFirstItem(SV_ITEM_ID_LBOXSTRING));

    BOOL bSelected  = pViewData->IsSelected();
    BOOL bCursored  = pViewData->IsCursored();

    Font aTempFont( pOut->GetFont() );
    // waehrend D&D nicht die Fontfarbe wechseln, da sonst auch die
    // Emphasis gezeichnet werden muss! (weisser Adler auf weissem Grund)
    if( bSelected && !(nFlags & F_NO_EMPHASIS) )
    {
        const StyleSettings& rStyleSettings = pOut->GetSettings().GetStyleSettings();
        Font aNewFont( aTempFont );
        aNewFont.SetColor( rStyleSettings.GetHighlightTextColor() );
        pOut->SetFont( aNewFont );
    }
    Rectangle aTextRect( CalcTextRect(pEntry,pStringItem,&rPos,FALSE,pViewData));
    Rectangle aBmpRect( CalcBmpRect(pEntry, &rPos, pViewData ) );

    switch( nViewMode )
    {
        case VIEWMODE_ICON:
            pBmpItem = (SvLBoxContextBmp*)(pEntry->GetFirstItem(SV_ITEM_ID_LBOXCONTEXTBMP));
            PaintEmphasis( aBmpRect, bSelected, bCursored, pOut );
            PaintItem( aBmpRect, pBmpItem, pEntry,
                PAINTFLAG_HOR_CENTERED | PAINTFLAG_VER_CENTERED, pOut );
            PaintEmphasis( aTextRect, bSelected, FALSE, pOut );
            PaintItem( aTextRect, pStringItem, pEntry, PAINTFLAG_HOR_CENTERED, pOut );
            break;

        case VIEWMODE_NAME:
            pBmpItem = (SvLBoxContextBmp*)(pEntry->GetFirstItem(SV_ITEM_ID_LBOXCONTEXTBMP));
            PaintEmphasis( aBmpRect, bSelected, bCursored, pOut );
            PaintItem( aBmpRect, pBmpItem, pEntry, PAINTFLAG_VER_CENTERED, pOut );
            PaintEmphasis( aTextRect, bSelected, FALSE, pOut );
            PaintItem( aTextRect, pStringItem, pEntry,PAINTFLAG_VER_CENTERED, pOut );
            break;

        case VIEWMODE_TEXT:
            PaintEmphasis( aTextRect, bSelected, bCursored, pOut );
            PaintItem( aTextRect, pStringItem, pEntry, PAINTFLAG_VER_CENTERED, pOut );
            break;
    }
    pOut->SetFont( aTempFont );
}

void SvImpIconView::SetEntryPosition( SvLBoxEntry* pEntry, const Point& rPos,
    BOOL bAdjustAtGrid, BOOL bCheckScrollBars )
{
    if( pModel->GetParent(pEntry) == pCurParent )
    {
        ShowCursor( FALSE );
        SvIcnVwDataEntry* pViewData = ICNVIEWDATA(pEntry);
        Rectangle aBoundRect( GetBoundingRect( pEntry, pViewData ));
        pView->Invalidate( aBoundRect );
        ToTop( pEntry );
        if( rPos != aBoundRect.TopLeft() )
        {
            Point aGridOffs = pViewData->aGridRect.TopLeft() -
                              pViewData->aRect.TopLeft();
            pImpCursor->Clear();
            nFlags &= ~F_GRID_INSERT;
            aBoundRect.SetPos( rPos );
            pViewData->aRect = aBoundRect;
            pViewData->aGridRect.SetPos( rPos + aGridOffs );
            AdjustVirtSize( aBoundRect );
        }
        //HACK(Billigloesung, die noch verbessert werden muss)
        if( bAdjustAtGrid )
        {
            AdjustAtGrid( pEntry );
            ToTop( pEntry );
        }
        if( bCheckScrollBars && pView->IsUpdateMode() )
            CheckScrollBars();

        PaintEntry( pEntry, pViewData );
        ShowCursor( TRUE );
    }
}

void SvImpIconView::ViewDataInitialized( SvLBoxEntry*)
{
}

void SvImpIconView::ModelHasEntryInvalidated( SvListEntry* pEntry )
{
    if( pEntry == pCursor )
        ShowCursor( FALSE );
    SvIcnVwDataEntry* pViewData = ICNVIEWDATA(pEntry);
    pView->Invalidate( pViewData->aRect );

    if( nFlags & F_GRIDMODE )
        Center( (SvLBoxEntry*)pEntry, pViewData );
    else
        pViewData->aRect.SetSize( CalcBoundingSize(
            (SvLBoxEntry*)pEntry, pViewData ) );

    ViewDataInitialized( (SvLBoxEntry*)pEntry );
    pView->Invalidate( pViewData->aRect );
    if( pEntry == pCursor )
        ShowCursor( TRUE );
}


void SvImpIconView::InvalidateEntry( SvLBoxEntry* pEntry )
{
    const Rectangle& rRect = GetBoundingRect( pEntry );
    pView->Invalidate( rRect );
}

void SvImpIconView::SetNoSelection()
{
}

void SvImpIconView::SetDragDropMode( DragDropMode )
{
}

void SvImpIconView::SetSelectionMode( SelectionMode )
{
}

BOOL SvImpIconView::IsEntryInView( SvLBoxEntry* )
{
    return FALSE;
}

SvLBoxEntry* SvImpIconView::GetDropTarget( const Point& rPos )
{
    Point aDocPos( rPos );
    CalcDocPos( aDocPos );
    SvLBoxEntry* pTarget = GetEntry( aDocPos );
    if( !pTarget || !pTarget->HasChilds() )
        pTarget = pCurParent;
    return pTarget;
}

SvLBoxEntry* SvImpIconView::GetEntry( const Point& rDocPos )
{
    CheckBoundingRects();
    SvLBoxEntry* pTarget = 0;
    // Z-Order-Liste vom Ende her absuchen
    USHORT nCount = pZOrderList->Count();
    while( nCount )
    {
        nCount--;
        SvLBoxEntry* pEntry = (SvLBoxEntry*)(pZOrderList->GetObject(nCount));
        SvIcnVwDataEntry* pViewData = ICNVIEWDATA(pEntry);
        if( pViewData->aRect.IsInside( rDocPos ) )
        {
            pTarget = pEntry;
            break;
        }
    }
    return pTarget;
}

SvLBoxEntry* SvImpIconView::GetNextEntry( const Point& rDocPos, SvLBoxEntry* pCurEntry )
{
    CheckBoundingRects();
    SvLBoxEntry* pTarget = 0;
    USHORT nStartPos = pZOrderList->GetPos( (void*)pCurEntry );
    if( nStartPos != USHRT_MAX )
    {
        USHORT nCount = pZOrderList->Count();
        for( USHORT nCur = nStartPos+1; nCur < nCount; nCur++ )
        {
            SvLBoxEntry* pEntry = (SvLBoxEntry*)(pZOrderList->GetObject(nCur));
            SvIcnVwDataEntry* pViewData = ICNVIEWDATA(pEntry);
            if( pViewData->aRect.IsInside( rDocPos ) )
            {
                pTarget = pEntry;
                break;
            }
        }
    }
    return pTarget;
}

SvLBoxEntry* SvImpIconView::GetPrevEntry( const Point& rDocPos, SvLBoxEntry* pCurEntry )
{
    CheckBoundingRects();
    SvLBoxEntry* pTarget = 0;
    USHORT nStartPos = pZOrderList->GetPos( (void*)pCurEntry );
    if( nStartPos != USHRT_MAX && nStartPos != 0 )
    {
        nStartPos--;
        do
        {
            SvLBoxEntry* pEntry = (SvLBoxEntry*)(pZOrderList->GetObject(nStartPos));
            SvIcnVwDataEntry* pViewData = ICNVIEWDATA(pEntry);
            if( pViewData->aRect.IsInside( rDocPos ) )
            {
                pTarget = pEntry;
                break;
            }
        } while( nStartPos > 0 );
    }
    return pTarget;
}


Point SvImpIconView::GetEntryPosition( SvLBoxEntry* pEntry )
{
    SvIcnVwDataEntry* pViewData = ICNVIEWDATA(pEntry);
    DBG_ASSERT(pViewData,"Entry not in model");
    return pViewData->aRect.TopLeft();
}

const Rectangle& SvImpIconView::GetBoundingRect( SvLBoxEntry* pEntry, SvIcnVwDataEntry* pViewData )
{
    if( !pViewData )
        pViewData = ICNVIEWDATA(pEntry);
    DBG_ASSERT(pViewData,"Entry not in model");
    if( !IsBoundingRectValid( pViewData->aRect ))
        FindBoundingRect( pEntry, pViewData );
    return pViewData->aRect;
}

void SvImpIconView::SetSpaceBetweenEntries( long nHor, long nVer )
{
    nHorDist = nHor;
    nVerDist = nVer;
}

Rectangle SvImpIconView::CalcBmpRect( SvLBoxEntry* pEntry, const Point* pPos,
    SvIcnVwDataEntry* pViewData  )
{
    if( !pViewData )
        pViewData = ICNVIEWDATA(pEntry);

    Rectangle aBound = GetBoundingRect( pEntry, pViewData );
    if( pPos )
        aBound.SetPos( *pPos );
    Point aPos( aBound.TopLeft() );

    switch( nViewMode )
    {
        case VIEWMODE_ICON:
        {
            aPos.X() += ( aBound.GetWidth() - nMaxBmpWidth ) / 2;
            Size aSize( nMaxBmpWidth, nMaxBmpHeight );
            // das Bitmap-Rechteck soll nicht das TextRect beruehren
            aSize.Height() -= 3;
            return Rectangle( aPos, aSize );
        }

        case VIEWMODE_NAME:
            return Rectangle( aPos,
                Size( nMaxBmpWidth, aBound.GetHeight() ));

        case VIEWMODE_TEXT:
            return Rectangle( aPos, aBound.GetSize() );

        default:
        {
            Rectangle aRect;
            return aRect;
        }
    }
}

Rectangle SvImpIconView::CalcTextRect( SvLBoxEntry* pEntry,
    SvLBoxString* pItem, const Point* pPos, BOOL bForInplaceEdit,
    SvIcnVwDataEntry* pViewData )
{
    long nBmpHeight, nBmpWidth;

    if( !pItem )
        pItem = (SvLBoxString*)(pEntry->GetFirstItem(SV_ITEM_ID_LBOXSTRING));

    if( !pViewData )
        pViewData = ICNVIEWDATA(pEntry);

    Size aTextSize( GetItemSize( pView, pEntry, pItem, pViewData ));
    aTextSize.Width() += 2*LROFFS_TEXT;

    Size aContextBmpSize(pEntry->GetFirstItem(SV_ITEM_ID_LBOXCONTEXTBMP)->GetSize(pView,pEntry));
    Rectangle aBound = GetBoundingRect( pEntry, pViewData );
    if( pPos )
        aBound.SetPos( *pPos );
    Point aPos( aBound.TopLeft() );

    switch( nViewMode )
    {
        case VIEWMODE_ICON:
            nBmpHeight = aContextBmpSize.Height();
            if( nBmpHeight < nMaxBmpHeight )
                nBmpHeight = nMaxBmpHeight;
            aPos.Y() += nBmpHeight;

            // beim Inplace-Editieren, spendieren wir ein bisschen mehr Platz
            if( bForInplaceEdit )
            {
                // 20% rauf
                long nMinWidth = (( (aContextBmpSize.Width()*10) / 100 ) * 2 ) +
                                 aContextBmpSize.Width();
                if( nMinWidth > aBound.GetWidth() )
                    nMinWidth = aBound.GetWidth();

                if( aTextSize.Width() < nMinWidth )
                    aTextSize.Width() = nMinWidth;

                // beim Inplace-Ed. darfs auch untere Eintraege ueberlappen
                Rectangle aMaxGridTextRect = CalcMaxTextRect(pEntry, pViewData);
                Size aOptSize = aMaxGridTextRect.GetSize();
                if( aOptSize.Height() > aTextSize.Height() )
                    aTextSize.Height() = aOptSize.Height();
            }


            aPos.X() += ( aBound.GetWidth() - aTextSize.Width() ) / 2;
            break;

        case VIEWMODE_NAME:
            nBmpWidth = aContextBmpSize.Width();
            if( nBmpWidth < nMaxBmpWidth )
                nBmpWidth = nMaxBmpWidth;
            aPos.X() += nBmpWidth;
            // vertikal ausrichten
            aPos.Y() += ( nBmpWidth - aTextSize.Height() ) / 2;
            break;
    }

    Rectangle aRect( aPos, aTextSize );
// KNALLT BEIM D&D, WENN GECLIPPT WIRD (In DrawText von Thomas)
//  ClipAtVirtOutRect( aRect );
    return aRect;
}


long SvImpIconView::CalcBoundingWidth( SvLBoxEntry* pEntry,
    const SvIcnVwDataEntry* pViewData ) const
{
    DBG_ASSERT(pEntry->GetFirstItem(SV_ITEM_ID_LBOXCONTEXTBMP),"No Bitmaps");
    DBG_ASSERT(pEntry->GetFirstItem(SV_ITEM_ID_LBOXSTRING),"No Text");
    long nStringWidth = GetItemSize( pView, pEntry, pEntry->GetFirstItem(SV_ITEM_ID_LBOXSTRING),pViewData).Width();
    nStringWidth += 2*LROFFS_TEXT;
    long nBmpWidth = pEntry->GetFirstItem(SV_ITEM_ID_LBOXCONTEXTBMP)->GetSize(pView,pEntry).Width();
    long nWidth = 0;

    switch( nViewMode )
    {
        case VIEWMODE_ICON:
            nWidth = Max( nStringWidth, nBmpWidth );
            nWidth = Max( nWidth, nMaxBmpWidth );
            break;

        case VIEWMODE_NAME:
            nWidth = Max( nBmpWidth, nMaxBmpWidth );
            nWidth += NAMEVIEW_OFFS_BMP_STRING;  // Abstand Bitmap String
            nWidth += nStringWidth;
            break;

        case VIEWMODE_TEXT:
            nWidth = nStringWidth;
            break;
    }
    return nWidth;
}

long SvImpIconView::CalcBoundingHeight( SvLBoxEntry* pEntry,
    const SvIcnVwDataEntry* pViewData ) const
{
    DBG_ASSERT(pEntry->GetFirstItem(SV_ITEM_ID_LBOXCONTEXTBMP),"No Bitmaps");
    DBG_ASSERT(pEntry->GetFirstItem(SV_ITEM_ID_LBOXSTRING),"No Text");
    long nStringHeight = GetItemSize(pView,pEntry,pEntry->GetFirstItem(SV_ITEM_ID_LBOXSTRING),pViewData).Height();
    long nBmpHeight = pEntry->GetFirstItem(SV_ITEM_ID_LBOXCONTEXTBMP)->GetSize(pView,pEntry).Height();
    long nHeight = 0;

    switch( nViewMode )
    {
        case VIEWMODE_ICON:
            nHeight = Max( nBmpHeight, nMaxBmpHeight );
            nHeight += ICONVIEW_OFFS_BMP_STRING; // Abstand Bitmap String
            nHeight += nStringHeight;
            break;

        case VIEWMODE_NAME:
            nHeight = Max( nBmpHeight, nMaxBmpHeight );
            nHeight = Max( nHeight, nStringHeight );
            break;

        case VIEWMODE_TEXT:
            nHeight = nStringHeight;
            break;
    }
    if( nHeight > nMaxBoundHeight )
    {
        ((SvImpIconView*)this)->nMaxBoundHeight = nHeight;
        ((SvImpIconView*)this)->aHorSBar.SetLineSize( nHeight / 2 );
        ((SvImpIconView*)this)->aVerSBar.SetLineSize( nHeight / 2 );
    }
    return nHeight;
}

Size SvImpIconView::CalcBoundingSize( SvLBoxEntry* pEntry,
    SvIcnVwDataEntry* pViewData ) const
{
    if( !pViewData )
        pViewData = ICNVIEWDATA(pEntry);
    return Size( CalcBoundingWidth(pEntry,pViewData),
                 CalcBoundingHeight(pEntry,pViewData) );
}

void SvImpIconView::RecalcAllBoundingRects()
{
    nMaxBoundHeight = 0;
    pZOrderList->Remove(0, pZOrderList->Count() );
    SvLBoxEntry* pEntry = pModel->FirstChild( pCurParent );
    while( pEntry )
    {
        FindBoundingRect( pEntry );
        pZOrderList->Insert( pEntry, pZOrderList->Count() );
        pEntry = pModel->NextSibling( pEntry );
    }
    bMustRecalcBoundingRects = FALSE;
    AdjustScrollBars();
}

void SvImpIconView::RecalcAllBoundingRectsSmart()
{
    nMaxBoundHeight = 0;
    pZOrderList->Remove(0, pZOrderList->Count() );
    SvLBoxEntry* pEntry = pModel->FirstChild( pCurParent );
    while( pEntry )
    {
        SvIcnVwDataEntry* pViewData = ICNVIEWDATA(pEntry);
        if( IsBoundingRectValid( pViewData->aRect ))
        {
            Size aBoundSize( pViewData->aRect.GetSize() );
            if( aBoundSize.Height() > nMaxBoundHeight )
                nMaxBoundHeight = aBoundSize.Height();
            pZOrderList->Insert( pEntry, pZOrderList->Count() );
        }
        else
        {
            FindBoundingRect( pEntry, pViewData );
        }
        pZOrderList->Insert( pEntry, pZOrderList->Count() );
        pEntry = pModel->NextSibling( pEntry );
    }
    AdjustScrollBars();
}

void SvImpIconView::UpdateBoundingRects()
{
    SvLBoxEntry* pEntry = pModel->FirstChild( pCurParent );
    while( pEntry )
    {
        GetBoundingRect( pEntry );
        pEntry = pModel->NextSibling( pEntry );
    }
}

void SvImpIconView::FindBoundingRect( SvLBoxEntry* pEntry,
    SvIcnVwDataEntry* pViewData )
{
    if( !pViewData )
        pViewData = ICNVIEWDATA(pEntry);

    Size aSize( CalcBoundingSize( pEntry, pViewData ) );
    Point aPos;

    DBG_ASSERT(!pViewData->IsEntryPosLocked(),"Locked entry pos in FindBoundingRect");
    // damits in der IconView nicht drunter & drueber geht
    if( pViewData->IsEntryPosLocked() && IsBoundingRectValid(pViewData->aRect) )
    {
        AdjustVirtSize( pViewData->aRect );
        return;
    }

    aPos = FindNextEntryPos( aSize );

    if( nFlags & F_GRIDMODE )
    {
        Rectangle aGridRect( aPos, Size(nGridDX, nGridDY) );
        pViewData->aGridRect = aGridRect;
        Center( pEntry, pViewData );
        AdjustVirtSize( pViewData->aRect );
        pImpCursor->SetGridUsed( pViewData->aRect );
    }
    else
    {
        pViewData->aRect = Rectangle( aPos, aSize );
        AdjustVirtSize( pViewData->aRect );
    }
}


void SvImpIconView::SetCursor( SvLBoxEntry* pEntry )
{
    if( pEntry == pCursor )
        return;

    ShowCursor( FALSE );
    if( pCursor )
    {
        pView->SetEntryFocus( pCursor, FALSE );
        if( pView->GetSelectionMode() == SINGLE_SELECTION )
            pView->Select( pCursor, FALSE );
    }
    pCursor = pEntry;
    ToTop( pCursor );
    if( pCursor )
    {
        pView->SetEntryFocus(pCursor, TRUE );
        if( pView->GetSelectionMode() == SINGLE_SELECTION )
            pView->Select( pCursor, TRUE );
        ShowCursor( TRUE );
    }
}


void SvImpIconView::ShowCursor( BOOL bShow )
{
    if( !pCursor || !bShow || !pView->HasFocus() )
    {
        pView->HideFocus();
        return;
    }
    Rectangle aRect ( CalcFocusRect( pCursor ) );
    pView->ShowFocus( aRect );
}


void SvImpIconView::HideDDIcon()
{
    pView->Update();
    ImpHideDDIcon();
    pDDBufDev = pDDDev;
    pDDDev = 0;
}

void SvImpIconView::ImpHideDDIcon()
{
    if( pDDDev )
    {
        Size aSize( pDDDev->GetOutputSizePixel() );
        // pView restaurieren
        pView->DrawOutDev( aDDLastRectPos, aSize, Point(), aSize, *pDDDev );
    }
}


void SvImpIconView::ShowDDIcon( SvLBoxEntry* pRefEntry, const Point& rPosPix )
{
    pView->Update();
    if( pRefEntry != pDDRefEntry )
    {
        DELETEZ(pDDDev);
        DELETEZ(pDDBufDev);
    }
    BOOL bSelected = pView->SvListView::Select( pRefEntry, FALSE );
    if( !pDDDev )
    {
        if( pDDBufDev )
        {
            // nicht bei jedem Move ein Device anlegen, da dies besonders
            // auf Remote-Clients zu langsam ist
            pDDDev = pDDBufDev;
            pDDBufDev = 0;
        }
        else
        {
            pDDDev = new VirtualDevice( *pView );
            pDDDev->SetFont( pView->GetFont() );
        }
    }
    else
    {
        ImpHideDDIcon();
    }
    const Rectangle& rRect = GetBoundingRect( pRefEntry );
    pDDDev->SetOutputSizePixel( rRect.GetSize() );

    Point aPos( rPosPix );
    CalcDocPos( aPos );

    Size aSize( pDDDev->GetOutputSizePixel() );
    pDDRefEntry = pRefEntry;
    aDDLastEntryPos = aPos;
    aDDLastRectPos = aPos;

    // Hintergrund sichern
    pDDDev->DrawOutDev( Point(), aSize, aPos, aSize, *pView );
    // Icon in pView malen
    nFlags |= F_NO_EMPHASIS;
    PaintEntry( pRefEntry, aPos );
    nFlags &= ~F_NO_EMPHASIS;
    if( bSelected )
        pView->SvListView::Select( pRefEntry, TRUE );
}

void SvImpIconView::HideShowDDIcon( SvLBoxEntry* pRefEntry, const Point& rPosPix )
{
/*  In Notfaellen folgenden flackernden Code aktivieren:

        HideDDIcon();
        ShowDDIcon( pRefEntry, rPosPix );
        return;
*/
    if( !pDDDev )
    {
        ShowDDIcon( pRefEntry, rPosPix );
        return;
    }

    if( pRefEntry != pDDRefEntry )
    {
        HideDDIcon();
        ShowDDIcon( pRefEntry, rPosPix );
        return;
    }

    Point aEmptyPoint;

    Point aCurEntryPos( rPosPix );
    CalcDocPos( aCurEntryPos );

    const Rectangle& rRect = GetBoundingRect( pRefEntry );
    Size aEntrySize( rRect.GetSize() );
    Rectangle aPrevEntryRect( aDDLastEntryPos, aEntrySize );
    Rectangle aCurEntryRect( aCurEntryPos, aEntrySize );

    if( !aPrevEntryRect.IsOver( aCurEntryRect ) )
    {
        HideDDIcon();
        ShowDDIcon( pRefEntry, rPosPix );
        return;
    }

    // Ueberlappung des neuen und alten D&D-Pointers!

    Rectangle aFullRect( aPrevEntryRect.Union( aCurEntryRect ) );
    if( !pDDTempDev )
    {
        pDDTempDev = new VirtualDevice( *pView );
        pDDTempDev->SetFont( pView->GetFont() );
    }

    Size aFullSize( aFullRect.GetSize() );
    Point aFullPos( aFullRect.TopLeft() );

    pDDTempDev->SetOutputSizePixel( aFullSize );

    // Hintergrund (mit dem alten D&D-Pointer!) sichern
    pDDTempDev->DrawOutDev( aEmptyPoint, aFullSize, aFullPos, aFullSize, *pView );
    // den alten Buffer in den neuen Buffer pasten
    aDDLastRectPos = aDDLastRectPos - aFullPos;

    pDDTempDev->DrawOutDev(
        aDDLastRectPos,
        pDDDev->GetOutputSizePixel(),
        aEmptyPoint,
        pDDDev->GetOutputSizePixel(),
        *pDDDev );

    // Swap
    VirtualDevice* pTemp = pDDDev;
    pDDDev = pDDTempDev;
    pDDTempDev = pTemp;

    // in den restaurierten Hintergrund den neuen D&D-Pointer zeichnen
    pDDTempDev->SetOutputSizePixel( pDDDev->GetOutputSizePixel() );
    pDDTempDev->DrawOutDev(
        aEmptyPoint, aFullSize, aEmptyPoint, aFullSize, *pDDDev );
    Point aRelPos = aCurEntryPos - aFullPos;
    nFlags |= F_NO_EMPHASIS;
    PaintEntry( pRefEntry, aRelPos, 0, pDDTempDev );
    nFlags &= ~F_NO_EMPHASIS;

    aDDLastRectPos = aFullPos;
    aDDLastEntryPos = aCurEntryPos;

    pView->DrawOutDev(
        aDDLastRectPos,
        pDDDev->GetOutputSizePixel(),
        aEmptyPoint,
        pDDDev->GetOutputSizePixel(),
        *pDDTempDev );

    BOOL bSelected = pView->SvListView::Select( pRefEntry, FALSE );
    if( bSelected )
        pView->SvListView::Select( pRefEntry, TRUE );
}

void SvImpIconView::ShowTargetEmphasis( SvLBoxEntry* pEntry, BOOL )
{
    CheckBoundingRects();
    Rectangle aRect;
    if( pEntry != pCurParent &&
        (pEntry->HasChilds() || pEntry->HasChildsOnDemand()) )
        aRect = CalcBmpRect( pEntry );
    else
    {
        aRect.SetSize( aOutputSize );
        const MapMode& rMapMode = pView->GetMapMode();
        Point aOrigin( rMapMode.GetOrigin());
        aOrigin *= -1; // in Doc-Koord wandeln
        aRect.SetPos( aOrigin );
        aRect.Left()++; aRect.Top()++;
        aRect.Right()--; aRect.Bottom()--;
    }
    ImpDrawXORRect( aRect );
}

BOOL SvImpIconView::NotifyMoving( SvLBoxEntry* pTarget, SvLBoxEntry* pEntry,
    SvLBoxEntry*& rpNewPar, ULONG& rNewChildPos )
{
    if( pTarget == pCurParent && pModel->GetParent(pEntry) == pCurParent )
    {
        // D&D innerhalb einer Childlist
        StopEditTimer();
        SvIcnVwDataEntry* pViewData = ICNVIEWDATA(pEntry);
        Size aSize( pViewData->aRect.GetSize() );
        Point aNewPos = FindNextEntryPos( aSize );
        AdjustVirtSize( Rectangle( aNewPos, aSize ) );
        SetEntryPosition( pEntry, aNewPos, FALSE, TRUE );
        return FALSE;
    }
    return pView->SvLBox::NotifyMoving(pTarget,pEntry,rpNewPar,rNewChildPos);
}

BOOL SvImpIconView::NotifyCopying( SvLBoxEntry* pTarget, SvLBoxEntry* pEntry,
    SvLBoxEntry*& rpNewParent, ULONG& rNewChildPos )
{
    return pView->SvLBox::NotifyCopying(pTarget,pEntry,rpNewParent,rNewChildPos);
}

void SvImpIconView::WriteDragServerInfo( const Point& rPos, SvLBoxDDInfo* pInfo)
{
    SvLBoxEntry* pCurEntry = GetCurEntry();
    Point aEntryPos;
    if( pCurEntry )
    {
        aEntryPos = rPos;
        aEntryPos -= GetEntryPosition( pCurEntry );
    }
    pInfo->nMouseRelX = aEntryPos.X();
    pInfo->nMouseRelY = aEntryPos.Y();
}

void SvImpIconView::ReadDragServerInfo( const Point& rPos, SvLBoxDDInfo* pInfo )
{
    Point aDropPos( rPos );
    aDropPos.X() -= pInfo->nMouseRelX;
    aDropPos.Y() -= pInfo->nMouseRelY;
    SetNextEntryPos( aDropPos );
}

void SvImpIconView::InvalidateBoundingRect( SvLBoxEntry* pEntry )
{
    SvIcnVwDataEntry* pViewData = ICNVIEWDATA(pEntry);
    InvalidateBoundingRect( pViewData->aRect );
}

void SvImpIconView::PrepareCommandEvent( const Point& rPt )
{
    aMouseMoveTimer.Stop();
    StopEditTimer();
    nFlags |= F_CMD_ARRIVED;
    SvLBoxEntry* pEntry = pView->GetEntry( rPt, TRUE );
    if( (nFlags & F_DOWN_CTRL) && pEntry && !pView->IsSelected(pEntry) )
        pView->Select( pEntry, TRUE );
    nFlags &= ~(F_DOWN_CTRL | F_DOWN_DESELECT);
}

void SvImpIconView::SttDrag( const Point& rPos )
{
    PrepareCommandEvent( rPos );

    nFlags |= F_DRAG_SOURCE;
    ShowCursor( FALSE );
}

void SvImpIconView::EndDrag()
{
    ShowCursor( TRUE );
    nFlags &= (~F_DRAG_SOURCE);
}

void SvImpIconView::ToTop( SvLBoxEntry* pEntry )
{
    DBG_ASSERT(pZOrderList->GetPos(pEntry)!=0xffff,"ToTop:ZOrder?");
    if( pZOrderList->GetObject( pZOrderList->Count() -1 ) != pEntry )
    {
        USHORT nPos = pZOrderList->GetPos( (void*)pEntry );
        pZOrderList->Remove( nPos, 1 );
        pZOrderList->Insert( pEntry, pZOrderList->Count() );
    }
}

void SvImpIconView::SetCurParent( SvLBoxEntry* pNewParent )
{
    Clear();
    pCurParent = pNewParent;
    ImpArrange();
}

void SvImpIconView::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: Bereich des Dokumentes (in Dokumentkoordinaten), der
// sichtbar gemacht werden soll.
// bScrBar == TRUE: Das Rect wurde aufgrund eines ScrollBar-Events berechnet

void SvImpIconView::MakeVisible( const Rectangle& rRect, BOOL bScrBar )
{
    Rectangle aRect( rRect );
    ClipAtVirtOutRect( aRect );
    MapMode aMapMode( pView->GetMapMode() );
    Point aOrigin( aMapMode.GetOrigin() );
    // in Dokumentkoordinate umwandeln
    aOrigin *= -1;

    Rectangle aOutputArea( aOrigin, aOutputSize );
    if( aOutputArea.IsInside( aRect ) )
        return; // ist schon sichtbar

    long nDy;
    if( aRect.Top() < aOutputArea.Top() )
    {
        // nach oben scrollen (nDy < 0)
        nDy = aRect.Top() - aOutputArea.Top();
    }
    else if( aRect.Bottom() > aOutputArea.Bottom() )
    {
        // nach unten scrollen (nDy > 0)
        nDy = aRect.Bottom() - aOutputArea.Bottom();
    }
    else
        nDy = 0;

    long nDx;
    if( aRect.Left() < aOutputArea.Left() )
    {
        // nach links scrollen (nDx < 0)
        nDx = aRect.Left() - aOutputArea.Left();
    }
    else if( aRect.Right() > aOutputArea.Right() )
    {
        // nach rechts scrollen (nDx > 0)
        nDx = aRect.Right() - aOutputArea.Right();
    }
    else
        nDx = 0;

    aOrigin.X() += nDx;
    aOrigin.Y() += nDy;
    aOutputArea.SetPos( aOrigin );

    pView->Update();

    // Origin fuer SV invertieren (damit wir in
    // Dokumentkoordinaten scrollen/painten koennen)
    aOrigin *= -1;
    aMapMode.SetOrigin( aOrigin );
    pView->SetMapMode( aMapMode );

    // in umgekehrte Richtung scrollen!
    pView->Control::Scroll( -nDx, -nDy, aOutputArea, TRUE );
    if( aHorSBar.IsVisible() || aVerSBar.IsVisible() )
    {
        if( !bScrBar )
        {
            aOrigin *= -1;
            // Thumbs korrigieren
            if(aHorSBar.IsVisible() && aHorSBar.GetThumbPos() != aOrigin.X())
                aHorSBar.SetThumbPos( aOrigin.X() );
            if(aVerSBar.IsVisible() && aVerSBar.GetThumbPos() != aOrigin.Y())
                aVerSBar.SetThumbPos( aOrigin.Y() );
        }
    }
    // pruefen, ob ScrollBars noch benoetigt werden
    CheckScrollBars();
    pView->Update();
}


SvLBoxEntry* SvImpIconView::GetNewCursor()
{
    SvLBoxEntry* pNewCursor;
    if( pCursor )
    {
        pNewCursor = pImpCursor->GoLeftRight( pCursor, FALSE );
        if( !pNewCursor )
        {
            pNewCursor = pImpCursor->GoLeftRight( pCursor, TRUE );
            if( !pNewCursor )
            {
                pNewCursor = pImpCursor->GoUpDown( pCursor, FALSE );
                if( !pNewCursor )
                    pNewCursor = pImpCursor->GoUpDown( pCursor, TRUE );
            }
        }
    }
    else
        pNewCursor = pModel->FirstChild( pCurParent );
    DBG_ASSERT(!pNewCursor|| (pCursor&&pCursor!=pNewCursor),"GetNewCursor failed");
    return pNewCursor;
}


USHORT SvImpIconView:: GetSelectionCount() const
{
    USHORT nSelected = 0;
    SvLBoxEntry* pEntry = pModel->FirstChild( pCurParent);
    while( pEntry )
    {
        if( pView->IsSelected( pEntry ) )
            nSelected++;
        pEntry = pModel->NextSibling( pEntry );
    }
    return nSelected;
}


void SvImpIconView::ToggleSelection( SvLBoxEntry* pEntry )
{
    BOOL bSel;
    if( pView->IsSelected( pEntry ) )
        bSel = FALSE;
    else
        bSel = TRUE;
    pView->Select( pEntry, bSel );
}

void SvImpIconView::DeselectAllBut( SvLBoxEntry* pThisEntryNot )
{
    ClearSelectedRectList();
    SvLBoxEntry* pEntry = pModel->FirstChild( pCurParent );
    while( pEntry )
    {
        if( pEntry != pThisEntryNot && pView->IsSelected( pEntry ))
            pView->Select( pEntry, FALSE );
        pEntry = pModel->NextSibling( pEntry );
    }
}

#define ICN_ROWS    50
#define ICN_COLS    30

ImpIcnCursor::ImpIcnCursor( SvImpIconView* pOwner )
{
    pView       = pOwner;
    pColumns    = 0;
    pRows       = 0;
    pCurEntry   = 0;
    nDeltaWidth = 0;
    nDeltaHeight= 0;
    nCols       = 0;
    nRows       = 0;
    nGridCols   = 0;
    nGridRows   = 0;
    pGridMap    = 0;
}

ImpIcnCursor::~ImpIcnCursor()
{
    delete[] pColumns;
    delete[] pRows;
    delete pGridMap;
}

USHORT ImpIcnCursor::GetSortListPos( SvPtrarr* pList, long nValue,
    int bVertical )
{
    USHORT nCount = (USHORT)pList->Count();
    if( !nCount )
        return 0;

    USHORT nCurPos = 0;
    long nPrevValue = LONG_MIN;
    while( nCount )
    {
        const Rectangle& rRect=
            pView->GetBoundingRect((SvLBoxEntry*)(pList->GetObject(nCurPos)));
        long nCurValue;
        if( bVertical )
            nCurValue = rRect.Top();
        else
            nCurValue = rRect.Left();
        if( nValue >= nPrevValue && nValue <= nCurValue )
            return (USHORT)nCurPos;
        nPrevValue = nCurValue;
        nCount--;
        nCurPos++;
    }
    return pList->Count();
}

void ImpIcnCursor::ImplCreate()
{
    pView->CheckBoundingRects();
    DBG_ASSERT(pColumns==0&&pRows==0,"ImplCreate: Not cleared");

    SetDeltas();

    pColumns = new SvPtrarr[ nCols ];
    pRows = new SvPtrarr[ nRows ];

    DELETEZ(pGridMap);

    SvLBoxTreeList* pModel = pView->pModel;
    SvLBoxEntry* pEntry = pModel->FirstChild( pView->pCurParent );
    while( pEntry )
    {
        SvIcnVwDataEntry* pViewData = ICNVIEWDATA2(pEntry);
        // const Rectangle& rRect = pView->GetBoundingRect( pEntry );
        Rectangle rRect( pView->CalcBmpRect( pEntry,0,pViewData ) );
        short nY = (short)( ((rRect.Top()+rRect.Bottom())/2) / nDeltaHeight );
        short nX = (short)( ((rRect.Left()+rRect.Right())/2) / nDeltaWidth );

        // Rundungsfehler abfangen
        if( nY >= nRows )
            nY = sal::static_int_cast< short >(nRows - 1);
        if( nX >= nCols )
            nX = sal::static_int_cast< short >(nCols - 1);

        USHORT nIns = GetSortListPos( &pColumns[nX], rRect.Top(), TRUE );
        pColumns[ nX ].Insert( pEntry, nIns );

        nIns = GetSortListPos( &pRows[nY], rRect.Left(), FALSE );
        pRows[ nY ].Insert( pEntry, nIns );

        pViewData->nX = nX;
        pViewData->nY = nY;

        pEntry = pModel->NextSibling( pEntry );
    }
}

void ImpIcnCursor::CreateGridMap()
{
    if( pGridMap )
        return;

    const Size& rSize = pView->aVirtOutputSize;
    long nWidth = rSize.Width();
    if( nWidth < pView->nMaxVirtWidth )
        nWidth = pView->nMaxVirtWidth;
    nWidth -= 2*LROFFS_WINBORDER;
    if( nWidth <= 0 )
        nWidth = 1;

    nGridDX = pView->nGridDX;
    nGridDY = pView->nGridDY;

    // Hinweis: Wegen der Abrundung bei Berechnung von nGridCols
    // ist es moeglich, dass Eintrage nicht im Grid liegen. Diese
    // wurden typischerweise manuell verschoben und gelockt
    nGridCols = nWidth / nGridDX;
    if( !nGridCols ) nGridCols = 1;

    nGridRows = rSize.Height() / nGridDY;
    // nRows nicht abrunden, da zur Vermeidung von Ueberlappungen
    // das gesamte BoundingRect des Eintrags zur Markierung im Grid
    // herangezogen wird.
    if( (nGridRows * nGridDY) < rSize.Height() )
        nGridRows++;
    else if( !nGridRows )
        nGridRows = 1;

    //XXX
    //nGridRows += 50; // in fuenfziger-Schritten

    pGridMap = new BOOL[ nGridRows*nGridCols];
    memset( (void*)pGridMap, 0, nGridRows*nGridCols );

    SvLBoxTreeList* pModel = pView->pModel;
    SvLBoxEntry* pEntry = pModel->FirstChild( pView->pCurParent );
    while( pEntry )
    {
        SvIcnVwDataEntry* pViewData = ICNVIEWDATA2(pEntry);
        const Rectangle& rRect = pViewData->aRect;
        // nur, wenn der Entry schon plaziert ist
        if( pView->IsBoundingRectValid( rRect ))
        {
            // Alle vom Eintrag beruehrten Grids kennzeichnen
            SetGridUsed( pView->GetBoundingRect( pEntry, pViewData ) );
        }
        pEntry = pModel->NextSibling( pEntry );
    }
}

BOOL ImpIcnCursor::GetGrid( const Point& rDocPos, USHORT& rGridX, USHORT& rGridY ) const
{
    Point aPos( rDocPos );
    aPos.X() -= LROFFS_WINBORDER;
    aPos.Y() -= TBOFFS_WINBORDER;
    rGridX = (USHORT)(aPos.X() / nGridDX);
    rGridY = (USHORT)(aPos.Y() / nGridDY);
    BOOL bInGrid = TRUE;
    if( rGridX >= nGridCols )
    {
        rGridX = sal::static_int_cast< USHORT >(nGridCols - 1);
        bInGrid = FALSE;
    }
    if( rGridY >= nGridRows )
    {
        rGridY = sal::static_int_cast< USHORT >(nGridRows - 1);
        if( !bInGrid )
            return FALSE; // beide Koordinaten nicht im Grid
    }
    return TRUE;
}

void ImpIcnCursor::SetGridUsed( const Rectangle& rRect, BOOL bUsed  )
{
    CreateGridMap();
    USHORT nTLX, nTLY, nBRX, nBRY;

    BOOL bTLInGrid = GetGrid( rRect.TopLeft(), nTLX, nTLY );
    BOOL bBRInGrid = GetGrid( rRect.BottomRight(), nBRX, nBRY );

    if( !bTLInGrid && !bBRInGrid )
        return;

    for( USHORT nCurY = nTLY; nCurY <= nBRY; nCurY++ )
    {
        for( USHORT nCurX = nTLX; nCurX <= nBRX; nCurX++ )
        {
            SetGridUsed( nCurX, nCurY, bUsed );
        }
    }
}

void ImpIcnCursor::Clear( BOOL bGridToo )
{
    if( pColumns )
    {
        delete[] pColumns;
        delete[] pRows;
        pColumns = 0;
        pRows = 0;
        pCurEntry = 0;
        nDeltaWidth = 0;
        nDeltaHeight = 0;
    }
    if( bGridToo && pGridMap )
    {
        DELETEZ(pGridMap);
        nGridRows = 0;
        nGridCols = 0;
    }
}

SvLBoxEntry* ImpIcnCursor::SearchCol(USHORT nCol,USHORT nTop,USHORT nBottom,
    USHORT, BOOL bDown, BOOL bSimple  )
{
    DBG_ASSERT(pCurEntry,"SearchCol: No reference entry");
    SvPtrarr* pList = &(pColumns[ nCol ]);
    USHORT nCount = pList->Count();
    if( !nCount )
        return 0;

    const Rectangle& rRefRect = pView->GetBoundingRect(pCurEntry);

    if( bSimple )
    {
        USHORT nListPos = pList->GetPos( pCurEntry );
        DBG_ASSERT(nListPos!=0xffff,"Entry not in Col-List");
        if( bDown )
        {
            while( nListPos < nCount-1 )
            {
                nListPos++;
                SvLBoxEntry* pEntry = (SvLBoxEntry*)pList->GetObject( nListPos );
                const Rectangle& rRect = pView->GetBoundingRect( pEntry );
                if( rRect.Top() > rRefRect.Top() )
                    return pEntry;
            }
            return 0;
        }
        else
        {
            while( nListPos )
            {
                nListPos--;
                if( nListPos < nCount )
                {
                    SvLBoxEntry* pEntry = (SvLBoxEntry*)pList->GetObject( nListPos );
                    const Rectangle& rRect = pView->GetBoundingRect( pEntry );
                    if( rRect.Top() < rRefRect.Top() )
                        return pEntry;
                }
            }
            return 0;
        }
    }

    if( nTop > nBottom )
    {
        USHORT nTemp = nTop;
        nTop = nBottom;
        nBottom = nTemp;
    }
    long nMinDistance = LONG_MAX;
    SvLBoxEntry* pResult = 0;
    for( USHORT nCur = 0; nCur < nCount; nCur++ )
    {
        SvLBoxEntry* pEntry = (SvLBoxEntry*)(pList->GetObject( nCur ));
        if( pEntry != pCurEntry )
        {
            SvIcnVwDataEntry* pViewData = ICNVIEWDATA2(pEntry);
            USHORT nY = pViewData->nY;
            if( nY >= nTop && nY <= nBottom )
            {
                const Rectangle& rRect = pView->GetBoundingRect( pEntry );
                long nDistance = rRect.Top() - rRefRect.Top();
                if( nDistance < 0 )
                    nDistance *= -1;
                if( nDistance && nDistance < nMinDistance )
                {
                    nMinDistance = nDistance;
                    pResult = pEntry;
                }
            }
        }
    }
    return pResult;
}

SvLBoxEntry* ImpIcnCursor::SearchRow(USHORT nRow,USHORT nLeft,USHORT nRight,
    USHORT, BOOL bRight, BOOL bSimple )
{
    DBG_ASSERT(pCurEntry,"SearchRow: No reference entry");
    SvPtrarr* pList = &(pRows[ nRow ]);
    USHORT nCount = pList->Count();
    if( !nCount )
        return 0;

    const Rectangle& rRefRect = pView->GetBoundingRect(pCurEntry);

    if( bSimple )
    {
        USHORT nListPos = pList->GetPos( pCurEntry );
        DBG_ASSERT(nListPos!=0xffff,"Entry not in Row-List");
        if( bRight )
        {
            while( nListPos < nCount-1 )
            {
                nListPos++;
                SvLBoxEntry* pEntry = (SvLBoxEntry*)pList->GetObject( nListPos );
                const Rectangle& rRect = pView->GetBoundingRect( pEntry );
                if( rRect.Left() > rRefRect.Left() )
                    return pEntry;
            }
            return 0;
        }
        else
        {
            while( nListPos )
            {
                nListPos--;
                if( nListPos < nCount )
                {
                    SvLBoxEntry* pEntry = (SvLBoxEntry*)pList->GetObject( nListPos );
                    const Rectangle& rRect = pView->GetBoundingRect( pEntry );
                    if( rRect.Left() < rRefRect.Left() )
                        return pEntry;
                }
            }
            return 0;
        }

    }
    if( nRight < nLeft )
    {
        USHORT nTemp = nRight;
        nRight = nLeft;
        nLeft = nTemp;
    }
    long nMinDistance = LONG_MAX;
    SvLBoxEntry* pResult = 0;
    for( USHORT nCur = 0; nCur < nCount; nCur++ )
    {
        SvLBoxEntry* pEntry = (SvLBoxEntry*)(pList->GetObject( nCur ));
        if( pEntry != pCurEntry )
        {
            SvIcnVwDataEntry* pViewData = ICNVIEWDATA2(pEntry);
            USHORT nX = pViewData->nX;
            if( nX >= nLeft && nX <= nRight )
            {
                const Rectangle& rRect = pView->GetBoundingRect( pEntry );
                long nDistance = rRect.Left() - rRefRect.Left();
                if( nDistance < 0 )
                    nDistance *= -1;
                if( nDistance && nDistance < nMinDistance )
                {
                    nMinDistance = nDistance;
                    pResult = pEntry;
                }
            }
        }
    }
    return pResult;
}



/*
    Sucht ab dem uebergebenen Eintrag den naechsten rechts- bzw.
    linksstehenden. Suchverfahren am Beispiel bRight = TRUE:

                  c
                b c
              a b c
            S 1 1 1      ====> Suchrichtung
              a b c
                b c
                  c

    S : Startposition
    1 : erstes Suchrechteck
    a,b,c : 2., 3., 4. Suchrechteck
*/

SvLBoxEntry* ImpIcnCursor::GoLeftRight( SvLBoxEntry* pIcnEntry, BOOL bRight )
{
    SvLBoxEntry* pResult;
    pCurEntry = pIcnEntry;
    Create();
    SvIcnVwDataEntry* pViewData = ICNVIEWDATA2(pIcnEntry);
    USHORT nY = pViewData->nY;
    USHORT nX = pViewData->nX;
    DBG_ASSERT(nY< nRows,"GoLeftRight:Bad column");
    DBG_ASSERT(nX< nCols,"GoLeftRight:Bad row");
    // Nachbar auf gleicher Zeile ?
    if( bRight )
        pResult = SearchRow(
            nY, nX, sal::static_int_cast< USHORT >(nCols-1), nX, TRUE, TRUE );
    else
        pResult = SearchRow( nY, nX ,0, nX, FALSE, TRUE );
    if( pResult )
        return pResult;

    long nCurCol = nX;

    long nColOffs, nLastCol;
    if( bRight )
    {
        nColOffs = 1;
        nLastCol = nCols;
    }
    else
    {
        nColOffs = -1;
        nLastCol = -1;   // 0-1
    }

    USHORT nRowMin = nY;
    USHORT nRowMax = nY;
    do
    {
        SvLBoxEntry* pEntry = SearchCol((USHORT)nCurCol,nRowMin,nRowMax,nY,TRUE, FALSE);
        if( pEntry )
            return pEntry;
        if( nRowMin )
            nRowMin--;
        if( nRowMax < (nRows-1))
            nRowMax++;
        nCurCol += nColOffs;
    } while( nCurCol != nLastCol );
    return 0;
}

SvLBoxEntry* ImpIcnCursor::GoUpDown( SvLBoxEntry* pIcnEntry, BOOL bDown)
{
    SvLBoxEntry* pResult;
    pCurEntry = pIcnEntry;
    Create();
    SvIcnVwDataEntry* pViewData = ICNVIEWDATA2(pIcnEntry);
    USHORT nY = pViewData->nY;
    USHORT nX = pViewData->nX;
    DBG_ASSERT(nY<nRows,"GoUpDown:Bad column");
    DBG_ASSERT(nX<nCols,"GoUpDown:Bad row");

    // Nachbar in gleicher Spalte ?
    if( bDown )
        pResult = SearchCol(
            nX, nY, sal::static_int_cast< USHORT >(nRows-1), nY, TRUE, TRUE );
    else
        pResult = SearchCol( nX, nY ,0, nY, FALSE, TRUE );
    if( pResult )
        return pResult;

    long nCurRow = nY;

    long nRowOffs, nLastRow;
    if( bDown )
    {
        nRowOffs = 1;
        nLastRow = nRows;
    }
    else
    {
        nRowOffs = -1;
        nLastRow = -1;   // 0-1
    }

    USHORT nColMin = nX;
    USHORT nColMax = nX;
    do
    {
        SvLBoxEntry* pEntry = SearchRow((USHORT)nCurRow,nColMin,nColMax,nX,TRUE, FALSE);
        if( pEntry )
            return pEntry;
        if( nColMin )
            nColMin--;
        if( nColMax < (nCols-1))
            nColMax++;
        nCurRow += nRowOffs;
    } while( nCurRow != nLastRow );
    return 0;
}

void ImpIcnCursor::SetDeltas()
{
    const Size& rSize = pView->aVirtOutputSize;
    if( pView->nFlags & F_GRIDMODE )
    {
        nGridDX = pView->nGridDX;
        nGridDY = pView->nGridDY;
    }
    else
    {
        nGridDX = 20;
        nGridDY = 20;
    }
    nCols = rSize.Width() / nGridDX;
    if( !nCols )
        nCols = 1;
    nRows = rSize.Height() / nGridDY;
    if( (nRows * nGridDY) < rSize.Height() )
        nRows++;
    if( !nRows )
        nRows = 1;

    nDeltaWidth = (short)(rSize.Width() / nCols);
    nDeltaHeight = (short)(rSize.Height() / nRows);
    if( !nDeltaHeight )
    {
        nDeltaHeight = 1;
        DBG_WARNING("SetDeltas:Bad height");
    }
    if( !nDeltaWidth )
    {
        nDeltaWidth = 1;
        DBG_WARNING("SetDeltas:Bad width");
    }
}


void ImpIcnCursor::ExpandGrid()
{
    if( pGridMap )
    {
        long nNewGridRows = nGridRows + 20;
        unsigned char* pTempMap = new unsigned char[ nNewGridRows * nGridCols ];
        memcpy( pTempMap, pGridMap, nGridRows * nGridCols );
        delete pGridMap;
        pGridMap = pTempMap;
        nGridRows = nNewGridRows;
    }
}

BOOL ImpIcnCursor::FindEmptyGridRect( Rectangle& rRect )
{
    CreateGridMap();
    USHORT nCount = (USHORT)(nGridCols * nGridRows);
    if( !nCount )
        return FALSE;
    for( USHORT nCur = 0; nCur < nCount; nCur++ )
    {
        if( !pGridMap[ nCur ] )
        {
            USHORT nCol = (USHORT)(nCur % nGridCols);
            USHORT nRow = (USHORT)(nCur / nGridCols);
            rRect.Top() = nRow * nGridDY + TBOFFS_WINBORDER;
            rRect.Bottom() = rRect.Top() + nGridDY;
            rRect.Left() = nCol * nGridDX+ LROFFS_WINBORDER;
            rRect.Right() = rRect.Left() + nGridDX;
            SetGridUsed( nCol, nRow, TRUE );

            //XXX
            //if( nRow + 5 > nGridRows )
            //  ExpandGrid();
            DBG_ASSERT(pGridMap[nCur],"SetGridUsed failed");
            return TRUE;
        }
    }
    // Gridmap ist voll: Um eine Zeile erweitern
    rRect.Top() = nGridRows * nGridDY + TBOFFS_WINBORDER;
    rRect.Bottom() = rRect.Top() + nGridDY;
    rRect.Left() = LROFFS_WINBORDER;
    rRect.Right() = rRect.Left() + nGridDX;
    return FALSE;
    //XXX
    //ExpandGrid();
    //return TRUE;
}

void ImpIcnCursor::CreateGridAjustData( SvPtrarr& rLists, SvLBoxEntry* pRefEntry)
{
    if( !pRefEntry )
    {
        USHORT nAdjustRows = (USHORT)(pView->aVirtOutputSize.Height() / pView->nGridDY);
        nAdjustRows++; // wg. Abrundung!

        if( !nAdjustRows )
            return;
        for( USHORT nCurList = 0; nCurList < nAdjustRows; nCurList++ )
        {
            SvPtrarr* pRow = new SvPtrarr;
            rLists.Insert( (void*)pRow, nCurList );
        }
        SvLBoxEntry* pEntry = pView->pModel->FirstChild( pView->pCurParent );
        while( pEntry )
        {
            const Rectangle& rRect = pView->GetBoundingRect( pEntry );
            short nY = (short)( ((rRect.Top()+rRect.Bottom())/2) / pView->nGridDY );
            USHORT nIns = GetSortListPos((SvPtrarr*)rLists[nY],rRect.Left(),FALSE);
            ((SvPtrarr*)rLists[ nY ])->Insert( pEntry, nIns );
            pEntry = pView->pModel->NextSibling( pEntry );
        }
    }
    else
    {
        // Aufbau eines hor. "Schlauchs" auf der RefEntry-Zeile

        // UEBERLEGEN: BoundingRect nehmen wg. Ueberlappungen???

        Rectangle rRefRect( pView->CalcBmpRect( pRefEntry ) );
        //const Rectangle& rRefRect = pView->GetBoundingRect( pRefEntry );
        short nRefRow = (short)( ((rRefRect.Top()+rRefRect.Bottom())/2) / pView->nGridDY );
        SvPtrarr* pRow = new SvPtrarr;
        rLists.Insert( (void*)pRow, 0 );
        SvLBoxEntry* pEntry = pView->pModel->FirstChild( pView->pCurParent );
        while( pEntry )
        {
            Rectangle rRect( pView->CalcBmpRect(pEntry) );
            //const Rectangle& rRect = pView->GetBoundingRect( pEntry );
            short nY = (short)( ((rRect.Top()+rRect.Bottom())/2) / pView->nGridDY );
            if( nY == nRefRow )
            {
                USHORT nIns = GetSortListPos( pRow, rRect.Left(), FALSE );
                pRow->Insert( pEntry, nIns );
            }
            pEntry = pView->pModel->NextSibling( pEntry );
        }
    }
}

//static
void ImpIcnCursor::DestroyGridAdjustData( SvPtrarr& rLists )
{
    USHORT nCount = rLists.Count();
    for( USHORT nCur = 0; nCur < nCount; nCur++ )
    {
        SvPtrarr* pArr = (SvPtrarr*)rLists[ nCur ];
        delete pArr;
    }
    rLists.Remove( 0, rLists.Count() );
}

void SvImpIconView::SetGrid( long nDX, long nDY )
{
    nGridDX = nDX;
    nGridDY = nDY;
    nFlags |= F_GRIDMODE;
}

Rectangle SvImpIconView::CalcMaxTextRect( const SvLBoxEntry* pEntry,
    const SvIcnVwDataEntry* pViewData ) const
{
    Rectangle aRect = pViewData->aGridRect;
    long nBmpHeight = ((SvLBoxEntry*)pEntry)->GetFirstItem(SV_ITEM_ID_LBOXCONTEXTBMP)->GetSize(pView,(SvLBoxEntry*)pEntry).Height();
    aRect.Top() += nBmpHeight;
    aRect.Top() += ICONVIEW_OFFS_BMP_STRING;
    if( aRect.Top() > aRect.Bottom())
        aRect.Top() = aRect.Bottom();
    aRect.Left() += LROFFS_BOUND;
    aRect.Left()++;
    aRect.Right() -= LROFFS_BOUND;
    aRect.Right()--;
    if( aRect.Left() > aRect.Right())
        aRect.Left() = aRect.Right();
    if( GetTextMode( pEntry, pViewData ) == ShowTextFull )
        aRect.Bottom() = LONG_MAX;
    return aRect;
}

void SvImpIconView::Center( SvLBoxEntry* pEntry,
    SvIcnVwDataEntry* pViewData ) const
{
    SvLBoxString* pStringItem = (SvLBoxString*)(pEntry->GetFirstItem(SV_ITEM_ID_LBOXSTRING));
    const String& rEntryText = pStringItem->GetText();

    Rectangle aTextRect = CalcMaxTextRect(pEntry,pViewData);
    aTextRect = GetTextRect( pView, aTextRect, rEntryText, DRAWTEXT_FLAGS );
    pViewData->aTextSize = aTextRect.GetSize();

    pViewData->aRect = pViewData->aGridRect;
    Size aSize( CalcBoundingSize( pEntry, pViewData ) );
    long nBorder = pViewData->aGridRect.GetWidth() - aSize.Width();
    pViewData->aRect.Left() += nBorder / 2;
    pViewData->aRect.Right() -= nBorder / 2;
    pViewData->aRect.Bottom() = pViewData->aRect.Top() + aSize.Height();
}


// Die Deltas entsprechen Offsets, um die die View auf dem Doc verschoben wird
// links, hoch: Offsets < 0
// rechts, runter: Offsets > 0
void SvImpIconView::Scroll( long nDeltaX, long nDeltaY, BOOL bScrollBar )
{
    const MapMode& rMapMode = pView->GetMapMode();
    Point aOrigin( rMapMode.GetOrigin() );
    // in Dokumentkoordinate umwandeln
    aOrigin *= -1;
    aOrigin.Y() += nDeltaY;
    aOrigin.X() += nDeltaX;
    Rectangle aRect( aOrigin, aOutputSize );
    MakeVisible( aRect, bScrollBar );
}


const Size& SvImpIconView::GetItemSize( SvIconView* pIconView,
    SvLBoxEntry* pEntry, SvLBoxItem* pItem, const SvIcnVwDataEntry* pViewData) const
{
    if( (nFlags & F_GRIDMODE) && pItem->IsA() == SV_ITEM_ID_LBOXSTRING )
    {
        if( !pViewData )
            pViewData = ICNVIEWDATA(pEntry);
        return pViewData->aTextSize;
    }
    else
        return pItem->GetSize( pIconView, pEntry );
}

Rectangle SvImpIconView::CalcFocusRect( SvLBoxEntry* pEntry )
{
#if !defined(OS2)
    SvLBoxString* pStringItem = (SvLBoxString*)(pEntry->GetFirstItem(SV_ITEM_ID_LBOXSTRING));
    DBG_ASSERT(pStringItem,"Text not set");
    return CalcTextRect( pEntry, pStringItem );
#else
    return CalcBmpRect( pEntry );
#endif
}


void SvImpIconView::SelectRect( const Rectangle& rRect, BOOL bAdd,
    SvPtrarr* pOtherRects, short nBorderOffs )
{
    if( !pZOrderList || !pZOrderList->Count() )
        return;

    CheckBoundingRects();
    pView->Update();
    USHORT nCount = pZOrderList->Count();

    Rectangle aRect( rRect );
    aRect.Justify();
    if( nBorderOffs )
    {
        aRect.Left() -= nBorderOffs;
        aRect.Right() += nBorderOffs;
        aRect.Top() -= nBorderOffs;
        aRect.Bottom() += nBorderOffs;
    }
    BOOL bCalcOverlap = (bAdd && pOtherRects && pOtherRects->Count()) ? TRUE : FALSE;

    for( USHORT nPos = 0; nPos < nCount; nPos++ )
    {
        SvLBoxEntry* pEntry = (SvLBoxEntry*)(pZOrderList->GetObject(nPos ));

        SvIcnVwDataEntry* pViewData = ICNVIEWDATA(pEntry);
        DBG_ASSERT(pViewData,"Entry not in model");
        if( !IsBoundingRectValid( pViewData->aRect ))
            FindBoundingRect( pEntry, pViewData );
        const Rectangle& rBoundRect = pViewData->aRect;
        BOOL bSelected = pViewData->IsSelected();

        BOOL bOverlaps;
        if( bCalcOverlap )
            bOverlaps = IsOver( pOtherRects, rBoundRect );
        else
            bOverlaps = FALSE;
        BOOL bOver = aRect.IsOver( rBoundRect );

        if( bOver && !bOverlaps )
        {
            // Ist im neuen Selektionsrechteck und in keinem alten
            // => selektieren
            if( !bSelected )
                pView->Select( pEntry, TRUE );
        }
        else if( !bAdd )
        {
            // ist ausserhalb des Selektionsrechtecks
            // => Selektion entfernen
            if( bSelected )
                pView->Select( pEntry, FALSE );
        }
        else if( bAdd && bOverlaps )
        {
            // Der Eintrag befindet sich in einem alten (=>Aufspannen
            // mehrerer Rechtecke mit Ctrl!) Selektionsrechteck

            // Hier ist noch ein Bug! Der Selektionsstatus eines Eintrags
            // in einem vorherigen Rechteck, muss restauriert werden, wenn
            // er vom aktuellen Selektionsrechteck beruehrt wurde, jetzt aber
            // nicht mehr in ihm liegt. Ich gehe hier der Einfachheit halber
            // pauschal davon aus, dass die Eintraege in den alten Rechtecken
            // alle selektiert sind. Ebenso ist es falsch, die Schnittmenge
            // nur zu deselektieren.
            // Loesungsmoeglichkeit: Snapshot der Selektion vor dem Auf-
            // spannen des Rechtecks merken
            if( rBoundRect.IsOver( rRect))
            {
                // Schnittmenge zwischen alten Rects & aktuellem Rect desel.
                if( bSelected )
                    pView->Select( pEntry, FALSE );
            }
            else
            {
                // Eintrag eines alten Rects selektieren
                if( !bSelected )
                    pView->Select( pEntry, TRUE );
            }
        }
        else if( !bOver && bSelected )
        {
            // Der Eintrag liegt voellig ausserhalb und wird deshalb desel.
            pView->Select( pEntry, FALSE );
        }
    }
    pView->Update();
}

BOOL SvImpIconView::IsOver( SvPtrarr* pRectList, const Rectangle& rBoundRect ) const
{
    USHORT nCount = pRectList->Count();
    for( USHORT nCur = 0; nCur < nCount; nCur++ )
    {
        Rectangle* pRect = (Rectangle*)pRectList->GetObject( nCur );
        if( rBoundRect.IsOver( *pRect ))
            return TRUE;
    }
    return FALSE;
}

void SvImpIconView::AddSelectedRect( const Rectangle& rRect, short nBorderOffs )
{
    Rectangle* pRect = new Rectangle( rRect );
    pRect->Justify();
    if( nBorderOffs )
    {
        pRect->Left() -= nBorderOffs;
        pRect->Right() += nBorderOffs;
        pRect->Top() -= nBorderOffs;
        pRect->Bottom() += nBorderOffs;
    }
    aSelectedRectList.Insert( (void*)pRect, aSelectedRectList.Count() );
}

void SvImpIconView::ClearSelectedRectList()
{
    USHORT nCount = aSelectedRectList.Count();
    for( USHORT nCur = 0; nCur < nCount; nCur++ )
    {
        Rectangle* pRect = (Rectangle*)aSelectedRectList.GetObject( nCur );
        delete pRect;
    }
    aSelectedRectList.Remove( 0, aSelectedRectList.Count() );
}


void SvImpIconView::DrawSelectionRect( const Rectangle& rRect )
{
    pView->HideTracking();
    nFlags |= F_SELRECT_VISIBLE;
    pView->ShowTracking( rRect, SHOWTRACK_SMALL | SHOWTRACK_WINDOW );
    aCurSelectionRect = rRect;
}

void SvImpIconView::HideSelectionRect()
{
    if( nFlags & F_SELRECT_VISIBLE )
    {
        pView->HideTracking();
        nFlags &= ~F_SELRECT_VISIBLE;
    }
}

void SvImpIconView::ImpDrawXORRect( const Rectangle& rRect )
{
    RasterOp eOldOp = pView->GetRasterOp();
    pView->SetRasterOp( ROP_XOR );
    Color aOldColor = pView->GetFillColor();
    pView->SetFillColor();
    pView->DrawRect( rRect );
    pView->SetFillColor( aOldColor );
    pView->SetRasterOp( eOldOp );
}

void SvImpIconView::CalcScrollOffsets( const Point& rPosPixel,
    long& rX, long& rY, BOOL bInDragDrop, USHORT nBorderWidth)
{
    // Scrolling der View, falls sich der Mauszeiger im Grenzbereich des
    // Fensters befindet
    long nPixelToScrollX = 0;
    long nPixelToScrollY = 0;
    Size aWndSize = aOutputSize;

    nBorderWidth = (USHORT)(Min( (long)(aWndSize.Height()-1), (long)nBorderWidth ));
    nBorderWidth = (USHORT)(Min( (long)(aWndSize.Width()-1), (long)nBorderWidth ));

    if ( rPosPixel.X() < nBorderWidth )
    {
        if( bInDragDrop )
            nPixelToScrollX = -DD_SCROLL_PIXEL;
        else
            nPixelToScrollX = rPosPixel.X()- nBorderWidth;
    }
    else if ( rPosPixel.X() > aWndSize.Width() - nBorderWidth )
    {
        if( bInDragDrop )
            nPixelToScrollX = DD_SCROLL_PIXEL;
        else
            nPixelToScrollX = rPosPixel.X() - (aWndSize.Width() - nBorderWidth);
    }
    if ( rPosPixel.Y() < nBorderWidth )
    {
        if( bInDragDrop )
            nPixelToScrollY = -DD_SCROLL_PIXEL;
        else
            nPixelToScrollY = rPosPixel.Y() - nBorderWidth;
    }
    else if ( rPosPixel.Y() > aWndSize.Height() - nBorderWidth )
    {
        if( bInDragDrop )
            nPixelToScrollY = DD_SCROLL_PIXEL;
        else
            nPixelToScrollY = rPosPixel.Y() - (aWndSize.Height() - nBorderWidth);
    }

    rX = nPixelToScrollX;
    rY = nPixelToScrollY;
}

IMPL_LINK(SvImpIconView, MouseMoveTimeoutHdl, Timer*, pTimer )
{
    pTimer->Start();
    MouseMove( aMouseMoveEvent );
    return 0;
}

void SvImpIconView::EndTracking()
{
    pView->ReleaseMouse();
    if( nFlags & F_RUBBERING )
    {
        aMouseMoveTimer.Stop();
        nFlags &= ~(F_RUBBERING | F_ADD_MODE);
    }
}

BOOL SvImpIconView::IsTextHit( SvLBoxEntry* pEntry, const Point& rDocPos )
{
    SvLBoxString* pItem = (SvLBoxString*)(pEntry->GetFirstItem(SV_ITEM_ID_LBOXSTRING));
    if( pItem )
    {
        Rectangle aRect( CalcTextRect( pEntry, pItem ));
        if( aRect.IsInside( rDocPos ) )
            return TRUE;
    }
    return FALSE;
}

IMPL_LINK(SvImpIconView, EditTimeoutHdl, Timer*, EMPTYARG )
{
    SvLBoxEntry* pEntry = GetCurEntry();
    if( pView->IsInplaceEditingEnabled() && pEntry &&
        pView->IsSelected( pEntry ))
    {
        pView->EditEntry( pEntry );
    }
    return 0;
}


//
// Funktionen zum Ausrichten der Eintraege am Grid
//

// pStart == 0: Alle Eintraege werden ausgerichtet
// sonst: Alle Eintraege der Zeile ab einschliesslich pStart werden ausgerichtet
void SvImpIconView::AdjustAtGrid( SvLBoxEntry* pStart )
{
    SvPtrarr aLists;
    pImpCursor->CreateGridAjustData( aLists, pStart );
    USHORT nCount = aLists.Count();
    for( USHORT nCur = 0; nCur < nCount; nCur++ )
    {
        AdjustAtGrid( *(SvPtrarr*)aLists[ nCur ], pStart );
    }
    ImpIcnCursor::DestroyGridAdjustData( aLists );
    CheckScrollBars();
}

// Richtet eine Zeile aus, erweitert ggf. die Breite; Bricht die Zeile nicht um
void SvImpIconView::AdjustAtGrid( const SvPtrarr& rRow, SvLBoxEntry* pStart )
{
    if( !rRow.Count() )
        return;

    BOOL bGo;
    if( !pStart )
        bGo = TRUE;
    else
        bGo = FALSE;

    long nCurRight = 0;
    for( USHORT nCur = 0; nCur < rRow.Count(); nCur++ )
    {
        SvLBoxEntry* pCur = (SvLBoxEntry*)rRow[ nCur ];
        if( !bGo && pCur == pStart )
            bGo = TRUE;

        SvIcnVwDataEntry* pViewData = ICNVIEWDATA(pCur);
        // Massgebend (fuer das menschliche Auge) ist die Bitmap, da sonst
        // durch lange Texte der Eintrag stark springen kann
        const Rectangle& rBoundRect = GetBoundingRect( pCur, pViewData );
        Rectangle aCenterRect( CalcBmpRect( pCur, 0, pViewData ));
        if( bGo && !pViewData->IsEntryPosLocked() )
        {
            long nWidth = aCenterRect.GetSize().Width();
            Point aNewPos( AdjustAtGrid( aCenterRect, rBoundRect ) );
            while( aNewPos.X() < nCurRight )
                aNewPos.X() += nGridDX;
            if( aNewPos != rBoundRect.TopLeft() )
                SetEntryPosition( pCur, aNewPos );
            nCurRight = aNewPos.X() + nWidth;
        }
        else
        {
            nCurRight = rBoundRect.Right();
        }
    }
}

// Richtet Rect am Grid aus, garantiert jedoch nicht, dass die
// neue Pos. frei ist. Die Pos. kann fuer SetEntryPos verwendet werden.
// Das CenterRect beschreibt den Teil des BoundRects, der fuer
// die Berechnung des Ziel-Rechtecks verwendet wird.
Point SvImpIconView::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 (ref ist mitte des rects)
    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;
    // hor. center
    aPos.X() += (nGridDX - rBoundRect.GetSize().Width() ) / 2;

    aPos.X() += LROFFS_WINBORDER;
    aPos.Y() += TBOFFS_WINBORDER;

    return aPos;
}


void SvImpIconView::SetTextMode( SvIconViewTextMode eMode, SvLBoxEntry* pEntry )
{
    if( !pEntry )
    {
        if( eTextMode != eMode )
        {
            if( eTextMode == ShowTextDontKnow )
                eTextMode = ShowTextShort;
            eTextMode = eMode;
            pView->Arrange();
        }
    }
    else
    {
        SvIcnVwDataEntry* pViewData = ICNVIEWDATA(pEntry);
        if( pViewData->eTextMode != eMode )
        {
            pViewData->eTextMode = eMode;
            pModel->InvalidateEntry( pEntry );
            AdjustVirtSize( pViewData->aRect );
        }
    }
}

SvIconViewTextMode SvImpIconView::GetTextMode( const SvLBoxEntry* pEntry,
    const SvIcnVwDataEntry* pViewData ) const
{
    if( !pEntry )
        return eTextMode;
    else
    {
        if( !pViewData )
            pViewData = ICNVIEWDATA(((SvLBoxEntry*)pEntry));
        return pViewData->GetTextMode();
    }
}

SvIconViewTextMode SvImpIconView::GetEntryTextModeSmart( const SvLBoxEntry* pEntry,
    const SvIcnVwDataEntry* pViewData ) const
{
    DBG_ASSERT(pEntry,"GetEntryTextModeSmart: Entry not set");
    if( !pViewData )
        pViewData = ICNVIEWDATA(((SvLBoxEntry*)pEntry));
    SvIconViewTextMode eMode = pViewData->GetTextMode();
    if( eMode == ShowTextDontKnow )
        return eTextMode;
    return eMode;
}

void SvImpIconView::ShowFocusRect( const SvLBoxEntry* pEntry )
{
    if( !pEntry )
        pView->HideFocus();
    else
    {
        Rectangle aRect ( CalcFocusRect( (SvLBoxEntry*)pEntry ) );
        pView->ShowFocus( aRect );
    }
}

IMPL_LINK(SvImpIconView, UserEventHdl, void*, EMPTYARG )
{
    nCurUserEvent = 0;
    AdjustScrollBars();
    Rectangle aRect;
    if( GetResizeRect(aRect) )
        PaintResizeRect( aRect );
    return 0;
}

void SvImpIconView::CancelUserEvent()
{
    if( nCurUserEvent )
    {
        Application::RemoveUserEvent( nCurUserEvent );
        nCurUserEvent = 0;
    }
}