1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
|
/* nautilus-canvas-container.c - Canvas container widget.
*
* Copyright (C) 1999, 2000 Free Software Foundation
* Copyright (C) 2000, 2001 Eazel, Inc.
* Copyright (C) 2002, 2003 Red Hat, Inc.
*
* The Gnome Library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* The Gnome Library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with the Gnome Library; see the file COPYING.LIB. If not,
* see <http://www.gnu.org/licenses/>.
*
* Authors: Ettore Perazzoli <ettore@gnu.org>,
* Darin Adler <darin@bentspoon.com>
*/
#include "nautilus-canvas-container.h"
#include <atk/atkaction.h>
#include <eel/eel-art-extensions.h>
#include <eel/eel-gtk-extensions.h>
#include <eel/eel-vfs-extensions.h>
#include <gdk/gdkkeysyms.h>
#include <gdk/gdk.h>
#include <glib/gi18n.h>
#include <gtk/gtk.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#define DEBUG_FLAG NAUTILUS_DEBUG_CANVAS_CONTAINER
#include "nautilus-debug.h"
#include "nautilus-canvas-private.h"
#include "nautilus-global-preferences.h"
#include "nautilus-icon-info.h"
#include "nautilus-lib-self-check-functions.h"
#include "nautilus-selection-canvas-item.h"
/* Interval for updating the rubberband selection, in milliseconds. */
#define RUBBERBAND_TIMEOUT_INTERVAL 10
#define RUBBERBAND_SCROLL_THRESHOLD 5
/* Initial unpositioned icon value */
#define ICON_UNPOSITIONED_VALUE -1
/* Timeout for making the icon currently selected for keyboard operation visible.
* If this is 0, you can get into trouble with extra scrolling after holding
* down the arrow key for awhile when there are many items.
*/
#define KEYBOARD_ICON_REVEAL_TIMEOUT 10
#define CONTEXT_MENU_TIMEOUT_INTERVAL 500
/* Maximum amount of milliseconds the mouse button is allowed to stay down
* and still be considered a click.
*/
#define MAX_CLICK_TIME 1500
/* Button assignments. */
#define DRAG_BUTTON 1
#define RUBBERBAND_BUTTON 1
#define MIDDLE_BUTTON 2
#define CONTEXTUAL_MENU_BUTTON 3
#define DRAG_MENU_BUTTON 2
/* Maximum size (pixels) allowed for icons at the standard zoom level. */
#define MINIMUM_IMAGE_SIZE 24
#define MAXIMUM_IMAGE_SIZE 96
#define ICON_PAD_LEFT 4
#define ICON_PAD_RIGHT 4
#define ICON_PAD_TOP 4
#define ICON_PAD_BOTTOM 4
#define CONTAINER_PAD_LEFT 4
#define CONTAINER_PAD_RIGHT 4
#define CONTAINER_PAD_TOP 4
#define CONTAINER_PAD_BOTTOM 4
/* Width of a "grid unit". Canvas items will always take up one or more
* grid units, rounding up their size relative to the unit width.
* So with an 80px grid unit, a 100px canvas item would take two grid units,
* where a 76px canvas item would only take one.
* Canvas items are then centered in the extra available space.
* Keep in sync with MAX_TEXT_WIDTH at nautilus-canvas-item.
*/
#define SMALL_ICON_GRID_WIDTH 124
#define STANDARD_ICON_GRID_WIDTH 112
#define LARGE_ICON_GRID_WIDTH 106
#define LARGER_ICON_GRID_WIDTH 128
/* Copied from NautilusCanvasContainer */
#define NAUTILUS_CANVAS_CONTAINER_SEARCH_DIALOG_TIMEOUT 5
/* Copied from NautilusFile */
#define UNDEFINED_TIME ((time_t) (-1))
enum
{
ACTION_ACTIVATE,
ACTION_MENU,
LAST_ACTION
};
typedef struct
{
GList *selection;
char *action_descriptions[LAST_ACTION];
} NautilusCanvasContainerAccessiblePrivate;
static GType nautilus_canvas_container_accessible_get_type (void);
static void preview_selected_items (NautilusCanvasContainer *container);
static void activate_selected_items (NautilusCanvasContainer *container);
static void activate_selected_items_alternate (NautilusCanvasContainer *container,
NautilusCanvasIcon *icon);
static NautilusCanvasIcon *get_first_selected_icon (NautilusCanvasContainer *container);
static NautilusCanvasIcon *get_nth_selected_icon (NautilusCanvasContainer *container,
int index);
static gboolean has_multiple_selection (NautilusCanvasContainer *container);
static gboolean all_selected (NautilusCanvasContainer *container);
static gboolean has_selection (NautilusCanvasContainer *container);
static void icon_destroy (NautilusCanvasContainer *container,
NautilusCanvasIcon *icon);
static gboolean finish_adding_new_icons (NautilusCanvasContainer *container);
static inline void icon_get_bounding_box (NautilusCanvasIcon *icon,
int *x1_return,
int *y1_return,
int *x2_return,
int *y2_return,
NautilusCanvasItemBoundsUsage usage);
static void handle_hadjustment_changed (GtkAdjustment *adjustment,
NautilusCanvasContainer *container);
static void handle_vadjustment_changed (GtkAdjustment *adjustment,
NautilusCanvasContainer *container);
static GList *nautilus_canvas_container_get_selected_icons (NautilusCanvasContainer *container);
static void nautilus_canvas_container_update_visible_icons (NautilusCanvasContainer *container);
static void reveal_icon (NautilusCanvasContainer *container,
NautilusCanvasIcon *icon);
static void nautilus_canvas_container_set_rtl_positions (NautilusCanvasContainer *container);
static double get_mirror_x_position (NautilusCanvasContainer *container,
NautilusCanvasIcon *icon,
double x);
static void text_ellipsis_limit_changed_container_callback (gpointer callback_data);
static int compare_icons_horizontal (NautilusCanvasContainer *container,
NautilusCanvasIcon *icon_a,
NautilusCanvasIcon *icon_b);
static int compare_icons_vertical (NautilusCanvasContainer *container,
NautilusCanvasIcon *icon_a,
NautilusCanvasIcon *icon_b);
static void schedule_redo_layout (NautilusCanvasContainer *container);
static const char *nautilus_canvas_container_accessible_action_names[] =
{
"activate",
"menu",
NULL
};
static const char *nautilus_canvas_container_accessible_action_descriptions[] =
{
"Activate selected items",
"Popup context menu",
NULL
};
G_DEFINE_TYPE (NautilusCanvasContainer, nautilus_canvas_container, EEL_TYPE_CANVAS);
/* The NautilusCanvasContainer signals. */
enum
{
ACTIVATE,
ACTIVATE_ALTERNATE,
ACTIVATE_PREVIEWER,
BAND_SELECT_STARTED,
BAND_SELECT_ENDED,
BUTTON_PRESS,
CONTEXT_CLICK_BACKGROUND,
CONTEXT_CLICK_SELECTION,
MIDDLE_CLICK,
GET_CONTAINER_URI,
GET_ICON_URI,
GET_ICON_ACTIVATION_URI,
GET_ICON_DROP_TARGET_URI,
ICON_RENAME_STARTED,
ICON_RENAME_ENDED,
ICON_STRETCH_STARTED,
ICON_STRETCH_ENDED,
MOVE_COPY_ITEMS,
HANDLE_NETSCAPE_URL,
HANDLE_URI_LIST,
HANDLE_TEXT,
HANDLE_RAW,
HANDLE_HOVER,
SELECTION_CHANGED,
ICON_ADDED,
ICON_REMOVED,
CLEARED,
LAST_SIGNAL
};
typedef struct
{
int **icon_grid;
int *grid_memory;
int num_rows;
int num_columns;
gboolean tight;
} PlacementGrid;
static guint signals[LAST_SIGNAL];
/* Functions dealing with NautilusIcons. */
static void
icon_free (NautilusCanvasIcon *icon)
{
/* Destroy this icon item; the parent will unref it. */
eel_canvas_item_destroy (EEL_CANVAS_ITEM (icon->item));
g_free (icon);
}
static gboolean
icon_is_positioned (const NautilusCanvasIcon *icon)
{
return icon->x != ICON_UNPOSITIONED_VALUE && icon->y != ICON_UNPOSITIONED_VALUE;
}
/* x, y are the top-left coordinates of the icon. */
static void
icon_set_position (NautilusCanvasIcon *icon,
double x,
double y)
{
if (icon->x == x && icon->y == y)
{
return;
}
if (icon->x == ICON_UNPOSITIONED_VALUE)
{
icon->x = 0;
}
if (icon->y == ICON_UNPOSITIONED_VALUE)
{
icon->y = 0;
}
eel_canvas_item_move (EEL_CANVAS_ITEM (icon->item),
x - icon->x,
y - icon->y);
icon->x = x;
icon->y = y;
}
static guint
nautilus_canvas_container_get_grid_size_for_zoom_level (NautilusCanvasZoomLevel zoom_level)
{
switch (zoom_level)
{
case NAUTILUS_CANVAS_ZOOM_LEVEL_SMALL:
{
return SMALL_ICON_GRID_WIDTH;
}
break;
case NAUTILUS_CANVAS_ZOOM_LEVEL_STANDARD:
{
return STANDARD_ICON_GRID_WIDTH;
}
break;
case NAUTILUS_CANVAS_ZOOM_LEVEL_LARGE:
{
return LARGE_ICON_GRID_WIDTH;
}
break;
case NAUTILUS_CANVAS_ZOOM_LEVEL_LARGER:
{
return LARGER_ICON_GRID_WIDTH;
}
break;
default:
{
g_return_val_if_reached (STANDARD_ICON_GRID_WIDTH);
}
break;
}
}
guint
nautilus_canvas_container_get_icon_size_for_zoom_level (NautilusCanvasZoomLevel zoom_level)
{
switch (zoom_level)
{
case NAUTILUS_CANVAS_ZOOM_LEVEL_SMALL:
{
return NAUTILUS_CANVAS_ICON_SIZE_SMALL;
}
break;
case NAUTILUS_CANVAS_ZOOM_LEVEL_STANDARD:
{
return NAUTILUS_CANVAS_ICON_SIZE_STANDARD;
}
break;
case NAUTILUS_CANVAS_ZOOM_LEVEL_LARGE:
{
return NAUTILUS_CANVAS_ICON_SIZE_LARGE;
}
break;
case NAUTILUS_CANVAS_ZOOM_LEVEL_LARGER:
{
return NAUTILUS_CANVAS_ICON_SIZE_LARGER;
}
break;
default:
{
g_return_val_if_reached (NAUTILUS_CANVAS_ICON_SIZE_STANDARD);
}
break;
}
}
static void
icon_get_size (NautilusCanvasContainer *container,
NautilusCanvasIcon *icon,
guint *size)
{
if (size != NULL)
{
*size = MAX (nautilus_canvas_container_get_icon_size_for_zoom_level (container->details->zoom_level),
NAUTILUS_CANVAS_ICON_SIZE_SMALL);
}
}
static void
icon_raise (NautilusCanvasIcon *icon)
{
EelCanvasItem *item, *band;
item = EEL_CANVAS_ITEM (icon->item);
band = NAUTILUS_CANVAS_CONTAINER (item->canvas)->details->rubberband_info.selection_rectangle;
eel_canvas_item_send_behind (item, band);
}
static void
icon_toggle_selected (NautilusCanvasContainer *container,
NautilusCanvasIcon *icon)
{
icon->is_selected = !icon->is_selected;
if (icon->is_selected)
{
container->details->selection = g_list_prepend (container->details->selection, icon->data);
container->details->selection_needs_resort = TRUE;
}
else
{
container->details->selection = g_list_remove (container->details->selection, icon->data);
}
eel_canvas_item_set (EEL_CANVAS_ITEM (icon->item),
"highlighted_for_selection", (gboolean) icon->is_selected,
NULL);
/* Raise each newly-selected icon to the front as it is selected. */
if (icon->is_selected)
{
icon_raise (icon);
}
}
/* Select an icon. Return TRUE if selection has changed. */
static gboolean
icon_set_selected (NautilusCanvasContainer *container,
NautilusCanvasIcon *icon,
gboolean select)
{
if (select == icon->is_selected)
{
return FALSE;
}
icon_toggle_selected (container, icon);
g_assert (select == icon->is_selected);
return TRUE;
}
static inline void
icon_get_bounding_box (NautilusCanvasIcon *icon,
int *x1_return,
int *y1_return,
int *x2_return,
int *y2_return,
NautilusCanvasItemBoundsUsage usage)
{
double x1, y1, x2, y2;
if (usage == BOUNDS_USAGE_FOR_DISPLAY)
{
eel_canvas_item_get_bounds (EEL_CANVAS_ITEM (icon->item),
&x1, &y1, &x2, &y2);
}
else if (usage == BOUNDS_USAGE_FOR_LAYOUT)
{
nautilus_canvas_item_get_bounds_for_layout (icon->item,
&x1, &y1, &x2, &y2);
}
else if (usage == BOUNDS_USAGE_FOR_ENTIRE_ITEM)
{
nautilus_canvas_item_get_bounds_for_entire_item (icon->item,
&x1, &y1, &x2, &y2);
}
else
{
g_assert_not_reached ();
}
if (x1_return != NULL)
{
*x1_return = x1;
}
if (y1_return != NULL)
{
*y1_return = y1;
}
if (x2_return != NULL)
{
*x2_return = x2;
}
if (y2_return != NULL)
{
*y2_return = y2;
}
}
/* Utility functions for NautilusCanvasContainer. */
gboolean
nautilus_canvas_container_scroll (NautilusCanvasContainer *container,
int delta_x,
int delta_y)
{
GtkAdjustment *hadj, *vadj;
int old_h_value, old_v_value;
hadj = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (container));
vadj = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (container));
/* Store the old ajustment values so we can tell if we
* ended up actually scrolling. We may not have in a case
* where the resulting value got pinned to the adjustment
* min or max.
*/
old_h_value = gtk_adjustment_get_value (hadj);
old_v_value = gtk_adjustment_get_value (vadj);
gtk_adjustment_set_value (hadj, gtk_adjustment_get_value (hadj) + delta_x);
gtk_adjustment_set_value (vadj, gtk_adjustment_get_value (vadj) + delta_y);
/* return TRUE if we did scroll */
return gtk_adjustment_get_value (hadj) != old_h_value || gtk_adjustment_get_value (vadj) != old_v_value;
}
static void
pending_icon_to_reveal_destroy_callback (NautilusCanvasItem *item,
NautilusCanvasContainer *container)
{
g_assert (NAUTILUS_IS_CANVAS_CONTAINER (container));
g_assert (container->details->pending_icon_to_reveal != NULL);
g_assert (container->details->pending_icon_to_reveal->item == item);
container->details->pending_icon_to_reveal = NULL;
}
static NautilusCanvasIcon *
get_pending_icon_to_reveal (NautilusCanvasContainer *container)
{
return container->details->pending_icon_to_reveal;
}
static void
set_pending_icon_to_reveal (NautilusCanvasContainer *container,
NautilusCanvasIcon *icon)
{
NautilusCanvasIcon *old_icon;
old_icon = container->details->pending_icon_to_reveal;
if (icon == old_icon)
{
return;
}
if (old_icon != NULL)
{
g_signal_handlers_disconnect_by_func
(old_icon->item,
G_CALLBACK (pending_icon_to_reveal_destroy_callback),
container);
}
if (icon != NULL)
{
g_signal_connect (icon->item, "destroy",
G_CALLBACK (pending_icon_to_reveal_destroy_callback),
container);
}
container->details->pending_icon_to_reveal = icon;
}
static void
item_get_canvas_bounds (EelCanvasItem *item,
EelIRect *bounds)
{
EelDRect world_rect;
eel_canvas_item_get_bounds (item,
&world_rect.x0,
&world_rect.y0,
&world_rect.x1,
&world_rect.y1);
eel_canvas_item_i2w (item->parent,
&world_rect.x0,
&world_rect.y0);
eel_canvas_item_i2w (item->parent,
&world_rect.x1,
&world_rect.y1);
world_rect.x0 -= ICON_PAD_LEFT + ICON_PAD_RIGHT;
world_rect.x1 += ICON_PAD_LEFT + ICON_PAD_RIGHT;
world_rect.y0 -= ICON_PAD_TOP + ICON_PAD_BOTTOM;
world_rect.y1 += ICON_PAD_TOP + ICON_PAD_BOTTOM;
eel_canvas_w2c (item->canvas,
world_rect.x0,
world_rect.y0,
&bounds->x0,
&bounds->y0);
eel_canvas_w2c (item->canvas,
world_rect.x1,
world_rect.y1,
&bounds->x1,
&bounds->y1);
}
static void
icon_get_row_and_column_bounds (NautilusCanvasContainer *container,
NautilusCanvasIcon *icon,
EelIRect *bounds)
{
GList *p;
NautilusCanvasIcon *one_icon;
EelIRect one_bounds;
item_get_canvas_bounds (EEL_CANVAS_ITEM (icon->item), bounds);
for (p = container->details->icons; p != NULL; p = p->next)
{
one_icon = p->data;
if (icon == one_icon)
{
continue;
}
if (compare_icons_horizontal (container, icon, one_icon) == 0)
{
item_get_canvas_bounds (EEL_CANVAS_ITEM (one_icon->item), &one_bounds);
bounds->x0 = MIN (bounds->x0, one_bounds.x0);
bounds->x1 = MAX (bounds->x1, one_bounds.x1);
}
if (compare_icons_vertical (container, icon, one_icon) == 0)
{
item_get_canvas_bounds (EEL_CANVAS_ITEM (one_icon->item), &one_bounds);
bounds->y0 = MIN (bounds->y0, one_bounds.y0);
bounds->y1 = MAX (bounds->y1, one_bounds.y1);
}
}
}
static void
reveal_icon (NautilusCanvasContainer *container,
NautilusCanvasIcon *icon)
{
GtkAllocation allocation;
GtkAdjustment *hadj, *vadj;
EelIRect bounds;
if (!icon_is_positioned (icon))
{
set_pending_icon_to_reveal (container, icon);
return;
}
set_pending_icon_to_reveal (container, NULL);
gtk_widget_get_allocation (GTK_WIDGET (container), &allocation);
hadj = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (container));
vadj = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (container));
/* ensure that we reveal the entire row/column */
icon_get_row_and_column_bounds (container, icon, &bounds);
if (bounds.y0 < gtk_adjustment_get_value (vadj))
{
gtk_adjustment_set_value (vadj, bounds.y0);
}
else if (bounds.y1 > gtk_adjustment_get_value (vadj) + allocation.height)
{
gtk_adjustment_set_value
(vadj, bounds.y1 - allocation.height);
}
if (bounds.x0 < gtk_adjustment_get_value (hadj))
{
gtk_adjustment_set_value (hadj, bounds.x0);
}
else if (bounds.x1 > gtk_adjustment_get_value (hadj) + allocation.width)
{
gtk_adjustment_set_value
(hadj, bounds.x1 - allocation.width);
}
}
static void
process_pending_icon_to_reveal (NautilusCanvasContainer *container)
{
NautilusCanvasIcon *pending_icon_to_reveal;
pending_icon_to_reveal = get_pending_icon_to_reveal (container);
if (pending_icon_to_reveal != NULL)
{
reveal_icon (container, pending_icon_to_reveal);
}
}
static gboolean
keyboard_icon_reveal_timeout_callback (gpointer data)
{
NautilusCanvasContainer *container;
NautilusCanvasIcon *icon;
container = NAUTILUS_CANVAS_CONTAINER (data);
icon = container->details->keyboard_icon_to_reveal;
g_assert (icon != NULL);
/* Only reveal the icon if it's still the keyboard focus or if
* it's still selected. Someone originally thought we should
* cancel this reveal if the user manages to sneak a direct
* scroll in before the timeout fires, but we later realized
* this wouldn't actually be an improvement
* (see bugzilla.gnome.org 40612).
*/
if (icon == container->details->focus
|| icon->is_selected)
{
reveal_icon (container, icon);
}
container->details->keyboard_icon_reveal_timer_id = 0;
return FALSE;
}
static void
unschedule_keyboard_icon_reveal (NautilusCanvasContainer *container)
{
NautilusCanvasContainerDetails *details;
details = container->details;
if (details->keyboard_icon_reveal_timer_id != 0)
{
g_source_remove (details->keyboard_icon_reveal_timer_id);
}
}
static void
schedule_keyboard_icon_reveal (NautilusCanvasContainer *container,
NautilusCanvasIcon *icon)
{
NautilusCanvasContainerDetails *details;
details = container->details;
unschedule_keyboard_icon_reveal (container);
details->keyboard_icon_to_reveal = icon;
details->keyboard_icon_reveal_timer_id
= g_timeout_add (KEYBOARD_ICON_REVEAL_TIMEOUT,
keyboard_icon_reveal_timeout_callback,
container);
}
static void inline
emit_atk_object_notify_focused (NautilusCanvasIcon *icon,
gboolean focused)
{
AtkObject *atk_object = atk_gobject_accessible_for_object (G_OBJECT (icon->item));
atk_object_notify_state_change (atk_object, ATK_STATE_FOCUSED, focused);
}
static void
clear_focus (NautilusCanvasContainer *container)
{
if (container->details->focus != NULL)
{
if (container->details->keyboard_focus)
{
eel_canvas_item_set (EEL_CANVAS_ITEM (container->details->focus->item),
"highlighted_as_keyboard_focus", 0,
NULL);
}
else
{
emit_atk_object_notify_focused (container->details->focus, FALSE);
}
}
container->details->focus = NULL;
}
/* Set @icon as the icon currently focused for accessibility. */
static void
set_focus (NautilusCanvasContainer *container,
NautilusCanvasIcon *icon,
gboolean keyboard_focus)
{
g_assert (icon != NULL);
if (icon == container->details->focus)
{
return;
}
clear_focus (container);
container->details->focus = icon;
container->details->keyboard_focus = keyboard_focus;
if (keyboard_focus)
{
eel_canvas_item_set (EEL_CANVAS_ITEM (container->details->focus->item),
"highlighted_as_keyboard_focus", 1,
NULL);
}
else
{
emit_atk_object_notify_focused (container->details->focus, TRUE);
}
}
static void
set_keyboard_rubberband_start (NautilusCanvasContainer *container,
NautilusCanvasIcon *icon)
{
container->details->keyboard_rubberband_start = icon;
}
static void
clear_keyboard_rubberband_start (NautilusCanvasContainer *container)
{
container->details->keyboard_rubberband_start = NULL;
}
/* carbon-copy of eel_canvas_group_bounds(), but
* for NautilusCanvasContainerItems it returns the
* bounds for the “entire item”.
*/
static void
get_icon_bounds_for_canvas_bounds (EelCanvasGroup *group,
double *x1,
double *y1,
double *x2,
double *y2,
NautilusCanvasItemBoundsUsage usage)
{
EelCanvasItem *child;
GList *list;
double tx1, ty1, tx2, ty2;
double minx, miny, maxx, maxy;
int set;
/* Get the bounds of the first visible item */
child = NULL; /* Unnecessary but eliminates a warning. */
set = FALSE;
for (list = group->item_list; list; list = list->next)
{
child = list->data;
if (!NAUTILUS_IS_CANVAS_ITEM (child))
{
continue;
}
if (child->flags & EEL_CANVAS_ITEM_VISIBLE)
{
set = TRUE;
if (!NAUTILUS_IS_CANVAS_ITEM (child) ||
usage == BOUNDS_USAGE_FOR_DISPLAY)
{
eel_canvas_item_get_bounds (child, &minx, &miny, &maxx, &maxy);
}
else if (usage == BOUNDS_USAGE_FOR_LAYOUT)
{
nautilus_canvas_item_get_bounds_for_layout (NAUTILUS_CANVAS_ITEM (child),
&minx, &miny, &maxx, &maxy);
}
else if (usage == BOUNDS_USAGE_FOR_ENTIRE_ITEM)
{
nautilus_canvas_item_get_bounds_for_entire_item (NAUTILUS_CANVAS_ITEM (child),
&minx, &miny, &maxx, &maxy);
}
else
{
g_assert_not_reached ();
}
break;
}
}
/* If there were no visible items, return an empty bounding box */
if (!set)
{
*x1 = *y1 = *x2 = *y2 = 0.0;
return;
}
/* Now we can grow the bounds using the rest of the items */
list = list->next;
for (; list; list = list->next)
{
child = list->data;
if (!NAUTILUS_IS_CANVAS_ITEM (child))
{
continue;
}
if (!(child->flags & EEL_CANVAS_ITEM_VISIBLE))
{
continue;
}
if (!NAUTILUS_IS_CANVAS_ITEM (child) ||
usage == BOUNDS_USAGE_FOR_DISPLAY)
{
eel_canvas_item_get_bounds (child, &tx1, &ty1, &tx2, &ty2);
}
else if (usage == BOUNDS_USAGE_FOR_LAYOUT)
{
nautilus_canvas_item_get_bounds_for_layout (NAUTILUS_CANVAS_ITEM (child),
&tx1, &ty1, &tx2, &ty2);
}
else if (usage == BOUNDS_USAGE_FOR_ENTIRE_ITEM)
{
nautilus_canvas_item_get_bounds_for_entire_item (NAUTILUS_CANVAS_ITEM (child),
&tx1, &ty1, &tx2, &ty2);
}
else
{
g_assert_not_reached ();
}
if (tx1 < minx)
{
minx = tx1;
}
if (ty1 < miny)
{
miny = ty1;
}
if (tx2 > maxx)
{
maxx = tx2;
}
if (ty2 > maxy)
{
maxy = ty2;
}
}
/* Make the bounds be relative to our parent's coordinate system */
if (EEL_CANVAS_ITEM (group)->parent)
{
minx += group->xpos;
miny += group->ypos;
maxx += group->xpos;
maxy += group->ypos;
}
if (x1 != NULL)
{
*x1 = minx;
}
if (y1 != NULL)
{
*y1 = miny;
}
if (x2 != NULL)
{
*x2 = maxx;
}
if (y2 != NULL)
{
*y2 = maxy;
}
}
static void
get_all_icon_bounds (NautilusCanvasContainer *container,
double *x1,
double *y1,
double *x2,
double *y2,
NautilusCanvasItemBoundsUsage usage)
{
/* FIXME bugzilla.gnome.org 42477: Do we have to do something about the rubberband
* here? Any other non-icon items?
*/
get_icon_bounds_for_canvas_bounds (EEL_CANVAS_GROUP (EEL_CANVAS (container)->root),
x1, y1, x2, y2, usage);
}
void
nautilus_canvas_container_update_scroll_region (NautilusCanvasContainer *container)
{
double x1, y1, x2, y2;
double pixels_per_unit;
GtkAdjustment *hadj, *vadj;
float step_increment;
GtkAllocation allocation;
pixels_per_unit = EEL_CANVAS (container)->pixels_per_unit;
get_all_icon_bounds (container, &x1, &y1, &x2, &y2, BOUNDS_USAGE_FOR_ENTIRE_ITEM);
/* Add border at the "end"of the layout (i.e. after the icons), to
* ensure we get some space when scrolled to the end.
*/
y2 += ICON_PAD_BOTTOM + CONTAINER_PAD_BOTTOM;
/* Auto-layout assumes a 0, 0 scroll origin and at least allocation->width.
* Then we lay out to the right or to the left, so
* x can be < 0 and > allocation */
gtk_widget_get_allocation (GTK_WIDGET (container), &allocation);
x1 = MIN (x1, 0);
x2 = MAX (x2, allocation.width / pixels_per_unit);
y1 = 0;
x2 -= 1;
x2 = MAX (x1, x2);
y2 -= 1;
y2 = MAX (y1, y2);
eel_canvas_set_scroll_region (EEL_CANVAS (container), x1, y1, x2, y2);
hadj = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (container));
vadj = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (container));
/* Scroll by 1/4 icon each time you click. */
step_increment = nautilus_canvas_container_get_icon_size_for_zoom_level
(container->details->zoom_level) / 4;
if (gtk_adjustment_get_step_increment (hadj) != step_increment)
{
gtk_adjustment_set_step_increment (hadj, step_increment);
}
if (gtk_adjustment_get_step_increment (vadj) != step_increment)
{
gtk_adjustment_set_step_increment (vadj, step_increment);
}
}
static void
cache_icon_positions (NautilusCanvasContainer *container)
{
GList *l;
gint idx;
NautilusCanvasIcon *icon;
for (l = container->details->icons, idx = 0; l != NULL; l = l->next)
{
icon = l->data;
icon->position = idx++;
}
}
static int
compare_icons_data (gconstpointer a,
gconstpointer b,
gpointer canvas_container)
{
NautilusCanvasContainerClass *klass;
NautilusCanvasIconData *data_a, *data_b;
data_a = (NautilusCanvasIconData *) a;
data_b = (NautilusCanvasIconData *) b;
klass = NAUTILUS_CANVAS_CONTAINER_GET_CLASS (canvas_container);
return klass->compare_icons (canvas_container, data_a, data_b);
}
static int
compare_icons (gconstpointer a,
gconstpointer b,
gpointer canvas_container)
{
NautilusCanvasContainerClass *klass;
const NautilusCanvasIcon *icon_a, *icon_b;
icon_a = a;
icon_b = b;
klass = NAUTILUS_CANVAS_CONTAINER_GET_CLASS (canvas_container);
return klass->compare_icons (canvas_container, icon_a->data, icon_b->data);
}
static void
sort_selection (NautilusCanvasContainer *container)
{
container->details->selection = g_list_sort_with_data (container->details->selection,
compare_icons_data,
container);
container->details->selection_needs_resort = FALSE;
}
static void
sort_icons (NautilusCanvasContainer *container,
GList **icons)
{
NautilusCanvasContainerClass *klass;
klass = NAUTILUS_CANVAS_CONTAINER_GET_CLASS (container);
g_assert (klass->compare_icons != NULL);
*icons = g_list_sort_with_data (*icons, compare_icons, container);
}
static void
resort (NautilusCanvasContainer *container)
{
sort_icons (container, &container->details->icons);
sort_selection (container);
cache_icon_positions (container);
}
typedef struct
{
double width;
double height;
double x_offset;
double y_offset;
} IconPositions;
static void
lay_down_one_line (NautilusCanvasContainer *container,
GList *line_start,
GList *line_end,
double y,
double max_height,
GArray *positions,
gboolean whole_text)
{
GList *p;
NautilusCanvasIcon *icon;
double x, ltr_icon_x, icon_x, y_offset;
IconPositions *position;
int i;
gboolean is_rtl;
is_rtl = nautilus_canvas_container_is_layout_rtl (container);
/* Lay out the icons along the baseline. */
x = ICON_PAD_LEFT;
i = 0;
for (p = line_start; p != line_end; p = p->next)
{
icon = p->data;
position = &g_array_index (positions, IconPositions, i++);
ltr_icon_x = x + position->x_offset;
icon_x = is_rtl ? get_mirror_x_position (container, icon, ltr_icon_x) : ltr_icon_x;
y_offset = position->y_offset;
icon_set_position (icon, icon_x, y + y_offset);
nautilus_canvas_item_set_entire_text (icon->item, whole_text);
icon->saved_ltr_x = is_rtl ? ltr_icon_x : icon->x;
x += position->width;
}
}
static void
lay_down_icons_horizontal (NautilusCanvasContainer *container,
GList *icons,
double start_y)
{
GList *p, *line_start;
NautilusCanvasIcon *icon;
double canvas_width, y;
double available_width;
GArray *positions;
IconPositions *position;
EelDRect bounds;
EelDRect icon_bounds;
double max_height_above, max_height_below;
double height_above, height_below;
double line_width;
double min_grid_width;
double grid_width;
double num_columns;
double icon_width, icon_size;
int i;
GtkAllocation allocation;
g_assert (NAUTILUS_IS_CANVAS_CONTAINER (container));
/* We can't get the right allocation if the size hasn't been allocated yet */
g_return_if_fail (container->details->has_been_allocated);
if (icons == NULL)
{
return;
}
positions = g_array_new (FALSE, FALSE, sizeof (IconPositions));
gtk_widget_get_allocation (GTK_WIDGET (container), &allocation);
/* Lay out icons a line at a time. */
canvas_width = CANVAS_WIDTH (container, allocation);
min_grid_width = nautilus_canvas_container_get_grid_size_for_zoom_level (container->details->zoom_level);
icon_size = nautilus_canvas_container_get_icon_size_for_zoom_level (container->details->zoom_level);
/* Subtracting 1.0 adds some room for error to prevent the jitter due to
* the code not being able to decide how many columns should be there, as
* "double" is not perfectly precise and increasing the size of the the
* window by one pixel could well make it so that the space taken by the
* icons and the padding is actually greater than the canvas with by like
* 0.01, causing an entire column to be dropped unnecessarily. This fix is
* adapted from Nemo.
*/
available_width = MAX (1.0, canvas_width - ICON_PAD_LEFT - ICON_PAD_RIGHT - 1.0);
num_columns = MAX (1.0, floor (available_width / min_grid_width));
if (g_list_nth (icons, num_columns) != NULL)
{
grid_width = available_width / num_columns;
}
else
{
/* It does not look good when the icons jump around when new columns are
* added or removed to the grid while there is only one line. It does
* not look good either when the icons do not move at all when the
* window is resized.
*
* To do this, we first compute the maximum extra fraction we can add to
* the grid width. Adding this much, however, would simply distribute
* the icons evenly, which looks bad when there's a wide window with
* only a few icons.
*
* To fix this, we need to apply a function to the fraction which never
* makes it larger and instead makes its growth slow down quickly but
* smoothly as the window gets wider and wider. Here's the function used
* by this code:
*
* f(x) = ∜(x + 1) - 1
*
* The +1 and -1 are there to skip the 0 to 1 part of ∜ where it makes
* the number larger.
*/
double num_icons = MAX (1.0, g_list_length (icons));
double used_width = num_icons * min_grid_width;
double unused_width = available_width - used_width;
double max_extra_fraction = (unused_width / num_icons) / min_grid_width;
double extra_fraction = pow(max_extra_fraction + 1.0, 1.0 / 4.0) - 1.0;
grid_width = min_grid_width * (1 + extra_fraction);
}
grid_width = MAX (min_grid_width, grid_width);
line_width = 0;
line_start = icons;
y = start_y + CONTAINER_PAD_TOP;
i = 0;
max_height_above = 0;
max_height_below = 0;
for (p = icons; p != NULL; p = p->next)
{
icon = p->data;
/* Assume it's only one level hierarchy to avoid costly affine calculations */
nautilus_canvas_item_get_bounds_for_layout (icon->item,
&bounds.x0, &bounds.y0,
&bounds.x1, &bounds.y1);
/* Normalize the icon width to the grid unit.
* Use the icon size for this zoom level too in the calculation, since
* the actual bounds might be smaller - e.g. because we have a very
* narrow thumbnail.
*/
icon_width = ceil (MAX ((bounds.x1 - bounds.x0), icon_size) / grid_width) * grid_width;
/* Calculate size above/below baseline */
icon_bounds = nautilus_canvas_item_get_icon_rectangle (icon->item);
height_above = icon_bounds.y1 - bounds.y0;
height_below = bounds.y1 - icon_bounds.y1;
/* If this icon doesn't fit, it's time to lay out the line that's queued up. */
if (line_start != p && line_width + icon_width >= canvas_width)
{
/* Advance to the baseline. */
y += ICON_PAD_TOP + max_height_above;
lay_down_one_line (container, line_start, p, y, max_height_above, positions, FALSE);
/* Advance to next line. */
y += max_height_below + ICON_PAD_BOTTOM;
line_width = 0;
line_start = p;
i = 0;
max_height_above = height_above;
max_height_below = height_below;
}
else
{
if (height_above > max_height_above)
{
max_height_above = height_above;
}
if (height_below > max_height_below)
{
max_height_below = height_below;
}
}
g_array_set_size (positions, i + 1);
position = &g_array_index (positions, IconPositions, i++);
position->width = icon_width;
position->height = icon_bounds.y1 - icon_bounds.y0;
position->x_offset = (icon_width - (icon_bounds.x1 - icon_bounds.x0)) / 2;
position->y_offset = icon_bounds.y0 - icon_bounds.y1;
/* Add this icon. */
line_width += icon_width;
}
/* Lay down that last line of icons. */
if (line_start != NULL)
{
/* Advance to the baseline. */
y += ICON_PAD_TOP + max_height_above;
lay_down_one_line (container, line_start, NULL, y, max_height_above, positions, FALSE);
}
g_array_free (positions, TRUE);
}
static double
get_mirror_x_position (NautilusCanvasContainer *container,
NautilusCanvasIcon *icon,
double x)
{
EelDRect icon_bounds;
GtkAllocation allocation;
gtk_widget_get_allocation (GTK_WIDGET (container), &allocation);
icon_bounds = nautilus_canvas_item_get_icon_rectangle (icon->item);
return CANVAS_WIDTH (container, allocation) - x - (icon_bounds.x1 - icon_bounds.x0);
}
static void
nautilus_canvas_container_set_rtl_positions (NautilusCanvasContainer *container)
{
GList *l;
NautilusCanvasIcon *icon;
double x;
if (!container->details->icons)
{
return;
}
for (l = container->details->icons; l != NULL; l = l->next)
{
icon = l->data;
x = get_mirror_x_position (container, icon, icon->saved_ltr_x);
icon_set_position (icon, x, icon->y);
}
}
static void
lay_down_icons (NautilusCanvasContainer *container,
GList *icons,
double start_y)
{
lay_down_icons_horizontal (container, icons, start_y);
}
static void
redo_layout_internal (NautilusCanvasContainer *container)
{
gboolean layout_possible;
layout_possible = finish_adding_new_icons (container);
if (!layout_possible)
{
schedule_redo_layout (container);
return;
}
if (container->details->needs_resort)
{
resort (container);
container->details->needs_resort = FALSE;
}
lay_down_icons (container, container->details->icons, 0);
if (nautilus_canvas_container_is_layout_rtl (container))
{
nautilus_canvas_container_set_rtl_positions (container);
}
nautilus_canvas_container_update_scroll_region (container);
process_pending_icon_to_reveal (container);
nautilus_canvas_container_update_visible_icons (container);
}
static gboolean
redo_layout_callback (gpointer callback_data)
{
NautilusCanvasContainer *container;
container = NAUTILUS_CANVAS_CONTAINER (callback_data);
redo_layout_internal (container);
container->details->idle_id = 0;
return FALSE;
}
static void
unschedule_redo_layout (NautilusCanvasContainer *container)
{
if (container->details->idle_id != 0)
{
g_source_remove (container->details->idle_id);
container->details->idle_id = 0;
}
}
static void
schedule_redo_layout (NautilusCanvasContainer *container)
{
if (container->details->idle_id == 0
&& container->details->has_been_allocated)
{
container->details->idle_id = g_idle_add
(redo_layout_callback, container);
}
}
static void
redo_layout (NautilusCanvasContainer *container)
{
unschedule_redo_layout (container);
/* We can't lay out if the size hasn't been allocated yet; wait for it to
* be and then we will be called again from size_allocate ()
*/
if (container->details->has_been_allocated)
{
redo_layout_internal (container);
}
}
/* Container-level icon handling functions. */
static gboolean
button_event_modifies_selection (GdkEventButton *event)
{
return (event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK)) != 0;
}
/* invalidate the cached label sizes for all the icons */
static void
invalidate_label_sizes (NautilusCanvasContainer *container)
{
GList *p;
NautilusCanvasIcon *icon;
for (p = container->details->icons; p != NULL; p = p->next)
{
icon = p->data;
nautilus_canvas_item_invalidate_label_size (icon->item);
}
}
static gboolean
select_range (NautilusCanvasContainer *container,
NautilusCanvasIcon *icon1,
NautilusCanvasIcon *icon2,
gboolean unselect_outside_range)
{
gboolean selection_changed;
GList *p;
NautilusCanvasIcon *icon;
NautilusCanvasIcon *unmatched_icon;
gboolean select;
selection_changed = FALSE;
unmatched_icon = NULL;
select = FALSE;
for (p = container->details->icons; p != NULL; p = p->next)
{
icon = p->data;
if (unmatched_icon == NULL)
{
if (icon == icon1)
{
unmatched_icon = icon2;
select = TRUE;
}
else if (icon == icon2)
{
unmatched_icon = icon1;
select = TRUE;
}
}
if (select || unselect_outside_range)
{
selection_changed |= icon_set_selected
(container, icon, select);
}
if (unmatched_icon != NULL && icon == unmatched_icon)
{
select = FALSE;
}
}
return selection_changed;
}
static gboolean
select_one_unselect_others (NautilusCanvasContainer *container,
NautilusCanvasIcon *icon_to_select)
{
gboolean selection_changed;
GList *p;
NautilusCanvasIcon *icon;
selection_changed = FALSE;
for (p = container->details->icons; p != NULL; p = p->next)
{
icon = p->data;
selection_changed |= icon_set_selected
(container, icon, icon == icon_to_select);
}
if (selection_changed && icon_to_select != NULL)
{
reveal_icon (container, icon_to_select);
}
return selection_changed;
}
static gboolean
unselect_all (NautilusCanvasContainer *container)
{
return select_one_unselect_others (container, NULL);
}
/* Implementation of rubberband selection. */
static void
rubberband_select (NautilusCanvasContainer *container,
const EelDRect *current_rect)
{
GList *p;
gboolean selection_changed, is_in, canvas_rect_calculated;
NautilusCanvasIcon *icon;
EelIRect canvas_rect;
EelCanvas *canvas;
selection_changed = FALSE;
canvas_rect_calculated = FALSE;
for (p = container->details->icons; p != NULL; p = p->next)
{
icon = p->data;
if (!canvas_rect_calculated)
{
/* Only do this calculation once, since all the canvas items
* we are interating are in the same coordinate space
*/
canvas = EEL_CANVAS_ITEM (icon->item)->canvas;
eel_canvas_w2c (canvas,
current_rect->x0,
current_rect->y0,
&canvas_rect.x0,
&canvas_rect.y0);
eel_canvas_w2c (canvas,
current_rect->x1,
current_rect->y1,
&canvas_rect.x1,
&canvas_rect.y1);
canvas_rect_calculated = TRUE;
}
is_in = nautilus_canvas_item_hit_test_rectangle (icon->item, canvas_rect);
selection_changed |= icon_set_selected
(container, icon,
is_in ^ icon->was_selected_before_rubberband);
}
if (selection_changed)
{
g_signal_emit (container,
signals[SELECTION_CHANGED], 0);
}
}
static int
rubberband_timeout_callback (gpointer data)
{
NautilusCanvasContainer *container;
GtkWidget *widget;
NautilusCanvasRubberbandInfo *band_info;
int x, y;
double x1, y1, x2, y2;
double world_x, world_y;
int x_scroll, y_scroll;
int adj_x, adj_y;
gboolean adj_changed;
GtkAllocation allocation;
EelDRect selection_rect;
widget = GTK_WIDGET (data);
container = NAUTILUS_CANVAS_CONTAINER (data);
band_info = &container->details->rubberband_info;
g_assert (band_info->timer_id != 0);
adj_changed = FALSE;
gtk_widget_get_allocation (widget, &allocation);
adj_x = gtk_adjustment_get_value (gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (container)));
if (adj_x != band_info->last_adj_x)
{
band_info->last_adj_x = adj_x;
adj_changed = TRUE;
}
adj_y = gtk_adjustment_get_value (gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (container)));
if (adj_y != band_info->last_adj_y)
{
band_info->last_adj_y = adj_y;
adj_changed = TRUE;
}
gdk_window_get_device_position (gtk_widget_get_window (widget),
band_info->device,
&x, &y, NULL);
if (x < RUBBERBAND_SCROLL_THRESHOLD)
{
x_scroll = x - RUBBERBAND_SCROLL_THRESHOLD;
x = 0;
}
else if (x >= allocation.width - RUBBERBAND_SCROLL_THRESHOLD)
{
x_scroll = x - allocation.width + RUBBERBAND_SCROLL_THRESHOLD + 1;
x = allocation.width - 1;
}
else
{
x_scroll = 0;
}
if (y < RUBBERBAND_SCROLL_THRESHOLD)
{
y_scroll = y - RUBBERBAND_SCROLL_THRESHOLD;
y = 0;
}
else if (y >= allocation.height - RUBBERBAND_SCROLL_THRESHOLD)
{
y_scroll = y - allocation.height + RUBBERBAND_SCROLL_THRESHOLD + 1;
y = allocation.height - 1;
}
else
{
y_scroll = 0;
}
if (y_scroll == 0 && x_scroll == 0
&& (int) band_info->prev_x == x && (int) band_info->prev_y == y && !adj_changed)
{
return TRUE;
}
nautilus_canvas_container_scroll (container, x_scroll, y_scroll);
/* Remember to convert from widget to scrolled window coords */
eel_canvas_window_to_world (EEL_CANVAS (container),
x + gtk_adjustment_get_value (gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (container))),
y + gtk_adjustment_get_value (gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (container))),
&world_x, &world_y);
if (world_x < band_info->start_x)
{
x1 = world_x;
x2 = band_info->start_x;
}
else
{
x1 = band_info->start_x;
x2 = world_x;
}
if (world_y < band_info->start_y)
{
y1 = world_y;
y2 = band_info->start_y;
}
else
{
y1 = band_info->start_y;
y2 = world_y;
}
/* Don't let the area of the selection rectangle be empty.
* Aside from the fact that it would be funny when the rectangle disappears,
* this also works around a crash in libart that happens sometimes when a
* zero height rectangle is passed.
*/
x2 = MAX (x1 + 1, x2);
y2 = MAX (y1 + 1, y2);
eel_canvas_item_set
(band_info->selection_rectangle,
"x1", x1, "y1", y1,
"x2", x2, "y2", y2,
NULL);
selection_rect.x0 = x1;
selection_rect.y0 = y1;
selection_rect.x1 = x2;
selection_rect.y1 = y2;
rubberband_select (container,
&selection_rect);
band_info->prev_x = x;
band_info->prev_y = y;
return TRUE;
}
static void
stop_rubberbanding (NautilusCanvasContainer *container,
GdkEventButton *event);
static void
start_rubberbanding (NautilusCanvasContainer *container,
GdkEventButton *event)
{
AtkObject *accessible;
NautilusCanvasContainerDetails *details;
NautilusCanvasRubberbandInfo *band_info;
GList *p;
NautilusCanvasIcon *icon;
details = container->details;
band_info = &details->rubberband_info;
if (band_info->active)
{
g_debug ("Canceling active rubberband by device %s", gdk_device_get_name (band_info->device));
stop_rubberbanding (container, NULL);
}
g_signal_emit (container,
signals[BAND_SELECT_STARTED], 0);
band_info->device = event->device;
for (p = details->icons; p != NULL; p = p->next)
{
icon = p->data;
icon->was_selected_before_rubberband = icon->is_selected;
}
eel_canvas_window_to_world
(EEL_CANVAS (container), event->x, event->y,
&band_info->start_x, &band_info->start_y);
band_info->selection_rectangle = eel_canvas_item_new
(eel_canvas_root
(EEL_CANVAS (container)),
NAUTILUS_TYPE_SELECTION_CANVAS_ITEM,
"x1", band_info->start_x,
"y1", band_info->start_y,
"x2", band_info->start_x,
"y2", band_info->start_y,
NULL);
accessible = atk_gobject_accessible_for_object
(G_OBJECT (band_info->selection_rectangle));
atk_object_set_name (accessible, "selection");
atk_object_set_description (accessible, _("The selection rectangle"));
band_info->prev_x = event->x - gtk_adjustment_get_value (gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (container)));
band_info->prev_y = event->y - gtk_adjustment_get_value (gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (container)));
band_info->active = TRUE;
if (band_info->timer_id == 0)
{
band_info->timer_id = g_timeout_add
(RUBBERBAND_TIMEOUT_INTERVAL,
rubberband_timeout_callback,
container);
}
eel_canvas_item_grab (band_info->selection_rectangle,
(GDK_POINTER_MOTION_MASK
| GDK_BUTTON_RELEASE_MASK
| GDK_SCROLL_MASK),
NULL,
(GdkEvent *) event);
}
static void
stop_rubberbanding (NautilusCanvasContainer *container,
GdkEventButton *event)
{
NautilusCanvasRubberbandInfo *band_info;
GList *icons;
gboolean enable_animation;
band_info = &container->details->rubberband_info;
if (event != NULL && event->device != band_info->device)
{
return;
}
g_assert (band_info->timer_id != 0);
g_source_remove (band_info->timer_id);
band_info->timer_id = 0;
band_info->active = FALSE;
band_info->device = NULL;
g_object_get (gtk_settings_get_default (), "gtk-enable-animations", &enable_animation, NULL);
/* Destroy this canvas item; the parent will unref it. */
eel_canvas_item_ungrab (band_info->selection_rectangle);
eel_canvas_item_lower_to_bottom (band_info->selection_rectangle);
eel_canvas_item_destroy (band_info->selection_rectangle);
band_info->selection_rectangle = NULL;
/* if only one item has been selected, use it as range
* selection base (cf. handle_icon_button_press) */
icons = nautilus_canvas_container_get_selected_icons (container);
if (g_list_length (icons) == 1)
{
container->details->range_selection_base_icon = icons->data;
}
g_list_free (icons);
g_signal_emit (container,
signals[BAND_SELECT_ENDED], 0);
}
/* Keyboard navigation. */
typedef gboolean (*IsBetterCanvasFunction) (NautilusCanvasContainer *container,
NautilusCanvasIcon *start_icon,
NautilusCanvasIcon *best_so_far,
NautilusCanvasIcon *candidate,
void *data);
static NautilusCanvasIcon *
find_best_icon (NautilusCanvasContainer *container,
NautilusCanvasIcon *start_icon,
IsBetterCanvasFunction function,
void *data)
{
GList *p;
NautilusCanvasIcon *best, *candidate;
best = NULL;
for (p = container->details->icons; p != NULL; p = p->next)
{
candidate = p->data;
if (candidate != start_icon)
{
if ((*function)(container, start_icon, best, candidate, data))
{
best = candidate;
}
}
}
return best;
}
static NautilusCanvasIcon *
find_best_selected_icon (NautilusCanvasContainer *container,
NautilusCanvasIcon *start_icon,
IsBetterCanvasFunction function,
void *data)
{
GList *p;
NautilusCanvasIcon *best, *candidate;
best = NULL;
for (p = container->details->icons; p != NULL; p = p->next)
{
candidate = p->data;
if (candidate != start_icon && candidate->is_selected)
{
if ((*function)(container, start_icon, best, candidate, data))
{
best = candidate;
}
}
}
return best;
}
static int
compare_icons_by_uri (NautilusCanvasContainer *container,
NautilusCanvasIcon *icon_a,
NautilusCanvasIcon *icon_b)
{
char *uri_a, *uri_b;
int result;
g_assert (NAUTILUS_IS_CANVAS_CONTAINER (container));
g_assert (icon_a != NULL);
g_assert (icon_b != NULL);
g_assert (icon_a != icon_b);
uri_a = nautilus_canvas_container_get_icon_uri (container, icon_a);
uri_b = nautilus_canvas_container_get_icon_uri (container, icon_b);
result = strcmp (uri_a, uri_b);
g_assert (result != 0);
g_free (uri_a);
g_free (uri_b);
return result;
}
static int
get_cmp_point_x (NautilusCanvasContainer *container,
EelDRect icon_rect)
{
return (icon_rect.x0 + icon_rect.x1) / 2;
}
static int
get_cmp_point_y (NautilusCanvasContainer *container,
EelDRect icon_rect)
{
return icon_rect.y1;
}
static int
compare_icons_horizontal (NautilusCanvasContainer *container,
NautilusCanvasIcon *icon_a,
NautilusCanvasIcon *icon_b)
{
EelDRect world_rect;
int ax, bx;
world_rect = nautilus_canvas_item_get_icon_rectangle (icon_a->item);
eel_canvas_w2c
(EEL_CANVAS (container),
get_cmp_point_x (container, world_rect),
get_cmp_point_y (container, world_rect),
&ax,
NULL);
world_rect = nautilus_canvas_item_get_icon_rectangle (icon_b->item);
eel_canvas_w2c
(EEL_CANVAS (container),
get_cmp_point_x (container, world_rect),
get_cmp_point_y (container, world_rect),
&bx,
NULL);
if (ax < bx)
{
return -1;
}
if (ax > bx)
{
return +1;
}
return 0;
}
static int
compare_icons_vertical (NautilusCanvasContainer *container,
NautilusCanvasIcon *icon_a,
NautilusCanvasIcon *icon_b)
{
EelDRect world_rect;
int ay, by;
world_rect = nautilus_canvas_item_get_icon_rectangle (icon_a->item);
eel_canvas_w2c
(EEL_CANVAS (container),
get_cmp_point_x (container, world_rect),
get_cmp_point_y (container, world_rect),
NULL,
&ay);
world_rect = nautilus_canvas_item_get_icon_rectangle (icon_b->item);
eel_canvas_w2c
(EEL_CANVAS (container),
get_cmp_point_x (container, world_rect),
get_cmp_point_y (container, world_rect),
NULL,
&by);
if (ay < by)
{
return -1;
}
if (ay > by)
{
return +1;
}
return 0;
}
static int
compare_icons_horizontal_first (NautilusCanvasContainer *container,
NautilusCanvasIcon *icon_a,
NautilusCanvasIcon *icon_b)
{
EelDRect world_rect;
int ax, ay, bx, by;
world_rect = nautilus_canvas_item_get_icon_rectangle (icon_a->item);
eel_canvas_w2c
(EEL_CANVAS (container),
get_cmp_point_x (container, world_rect),
get_cmp_point_y (container, world_rect),
&ax,
&ay);
world_rect = nautilus_canvas_item_get_icon_rectangle (icon_b->item);
eel_canvas_w2c
(EEL_CANVAS (container),
get_cmp_point_x (container, world_rect),
get_cmp_point_y (container, world_rect),
&bx,
&by);
if (ax < bx)
{
return -1;
}
if (ax > bx)
{
return +1;
}
if (ay < by)
{
return -1;
}
if (ay > by)
{
return +1;
}
return compare_icons_by_uri (container, icon_a, icon_b);
}
static int
compare_icons_vertical_first (NautilusCanvasContainer *container,
NautilusCanvasIcon *icon_a,
NautilusCanvasIcon *icon_b)
{
EelDRect world_rect;
int ax, ay, bx, by;
world_rect = nautilus_canvas_item_get_icon_rectangle (icon_a->item);
eel_canvas_w2c
(EEL_CANVAS (container),
get_cmp_point_x (container, world_rect),
get_cmp_point_y (container, world_rect),
&ax,
&ay);
world_rect = nautilus_canvas_item_get_icon_rectangle (icon_b->item);
eel_canvas_w2c
(EEL_CANVAS (container),
get_cmp_point_x (container, world_rect),
get_cmp_point_y (container, world_rect),
&bx,
&by);
if (ay < by)
{
return -1;
}
if (ay > by)
{
return +1;
}
if (ax < bx)
{
return -1;
}
if (ax > bx)
{
return +1;
}
return compare_icons_by_uri (container, icon_a, icon_b);
}
static gboolean
leftmost_in_top_row (NautilusCanvasContainer *container,
NautilusCanvasIcon *start_icon,
NautilusCanvasIcon *best_so_far,
NautilusCanvasIcon *candidate,
void *data)
{
if (best_so_far == NULL)
{
return TRUE;
}
return compare_icons_vertical_first (container, best_so_far, candidate) > 0;
}
static gboolean
rightmost_in_top_row (NautilusCanvasContainer *container,
NautilusCanvasIcon *start_icon,
NautilusCanvasIcon *best_so_far,
NautilusCanvasIcon *candidate,
void *data)
{
if (best_so_far == NULL)
{
return TRUE;
}
return compare_icons_vertical (container, best_so_far, candidate) > 0;
return compare_icons_horizontal (container, best_so_far, candidate) < 0;
}
static gboolean
rightmost_in_bottom_row (NautilusCanvasContainer *container,
NautilusCanvasIcon *start_icon,
NautilusCanvasIcon *best_so_far,
NautilusCanvasIcon *candidate,
void *data)
{
if (best_so_far == NULL)
{
return TRUE;
}
return compare_icons_vertical_first (container, best_so_far, candidate) < 0;
}
static int
compare_with_start_row (NautilusCanvasContainer *container,
NautilusCanvasIcon *icon)
{
EelCanvasItem *item;
item = EEL_CANVAS_ITEM (icon->item);
if (container->details->arrow_key_start_y < item->y1)
{
return -1;
}
if (container->details->arrow_key_start_y > item->y2)
{
return +1;
}
return 0;
}
static int
compare_with_start_column (NautilusCanvasContainer *container,
NautilusCanvasIcon *icon)
{
EelCanvasItem *item;
item = EEL_CANVAS_ITEM (icon->item);
if (container->details->arrow_key_start_x < item->x1)
{
return -1;
}
if (container->details->arrow_key_start_x > item->x2)
{
return +1;
}
return 0;
}
static gboolean
same_row_right_side_leftmost (NautilusCanvasContainer *container,
NautilusCanvasIcon *start_icon,
NautilusCanvasIcon *best_so_far,
NautilusCanvasIcon *candidate,
void *data)
{
/* Candidates not on the start row do not qualify. */
if (compare_with_start_row (container, candidate) != 0)
{
return FALSE;
}
/* Candidates that are farther right lose out. */
if (best_so_far != NULL)
{
if (compare_icons_horizontal_first (container,
best_so_far,
candidate) < 0)
{
return FALSE;
}
}
/* Candidate to the left of the start do not qualify. */
if (compare_icons_horizontal_first (container,
candidate,
start_icon) <= 0)
{
return FALSE;
}
return TRUE;
}
static gboolean
same_row_left_side_rightmost (NautilusCanvasContainer *container,
NautilusCanvasIcon *start_icon,
NautilusCanvasIcon *best_so_far,
NautilusCanvasIcon *candidate,
void *data)
{
/* Candidates not on the start row do not qualify. */
if (compare_with_start_row (container, candidate) != 0)
{
return FALSE;
}
/* Candidates that are farther left lose out. */
if (best_so_far != NULL)
{
if (compare_icons_horizontal_first (container,
best_so_far,
candidate) > 0)
{
return FALSE;
}
}
/* Candidate to the right of the start do not qualify. */
if (compare_icons_horizontal_first (container,
candidate,
start_icon) >= 0)
{
return FALSE;
}
return TRUE;
}
static gboolean
next_row_leftmost (NautilusCanvasContainer *container,
NautilusCanvasIcon *start_icon,
NautilusCanvasIcon *best_so_far,
NautilusCanvasIcon *candidate,
void *data)
{
/* sort out icons that are not below the current row */
if (compare_with_start_row (container, candidate) >= 0)
{
return FALSE;
}
if (best_so_far != NULL)
{
if (compare_icons_vertical_first (container,
best_so_far,
candidate) > 0)
{
/* candidate is above best choice, but below the current row */
return TRUE;
}
if (compare_icons_horizontal_first (container,
best_so_far,
candidate) > 0)
{
return TRUE;
}
}
return best_so_far == NULL;
}
static gboolean
next_row_rightmost (NautilusCanvasContainer *container,
NautilusCanvasIcon *start_icon,
NautilusCanvasIcon *best_so_far,
NautilusCanvasIcon *candidate,
void *data)
{
/* sort out icons that are not below the current row */
if (compare_with_start_row (container, candidate) >= 0)
{
return FALSE;
}
if (best_so_far != NULL)
{
if (compare_icons_vertical_first (container,
best_so_far,
candidate) > 0)
{
/* candidate is above best choice, but below the current row */
return TRUE;
}
if (compare_icons_horizontal_first (container,
best_so_far,
candidate) < 0)
{
return TRUE;
}
}
return best_so_far == NULL;
}
static gboolean
previous_row_rightmost (NautilusCanvasContainer *container,
NautilusCanvasIcon *start_icon,
NautilusCanvasIcon *best_so_far,
NautilusCanvasIcon *candidate,
void *data)
{
/* sort out icons that are not above the current row */
if (compare_with_start_row (container, candidate) <= 0)
{
return FALSE;
}
if (best_so_far != NULL)
{
if (compare_icons_vertical_first (container,
best_so_far,
candidate) < 0)
{
/* candidate is below the best choice, but above the current row */
return TRUE;
}
if (compare_icons_horizontal_first (container,
best_so_far,
candidate) < 0)
{
return TRUE;
}
}
return best_so_far == NULL;
}
static gboolean
same_column_above_lowest (NautilusCanvasContainer *container,
NautilusCanvasIcon *start_icon,
NautilusCanvasIcon *best_so_far,
NautilusCanvasIcon *candidate,
void *data)
{
/* Candidates not on the start column do not qualify. */
if (compare_with_start_column (container, candidate) != 0)
{
return FALSE;
}
/* Candidates that are higher lose out. */
if (best_so_far != NULL)
{
if (compare_icons_vertical_first (container,
best_so_far,
candidate) > 0)
{
return FALSE;
}
}
/* Candidates below the start do not qualify. */
if (compare_icons_vertical_first (container,
candidate,
start_icon) >= 0)
{
return FALSE;
}
return TRUE;
}
static gboolean
same_column_below_highest (NautilusCanvasContainer *container,
NautilusCanvasIcon *start_icon,
NautilusCanvasIcon *best_so_far,
NautilusCanvasIcon *candidate,
void *data)
{
/* Candidates not on the start column do not qualify. */
if (compare_with_start_column (container, candidate) != 0)
{
return FALSE;
}
/* Candidates that are lower lose out. */
if (best_so_far != NULL)
{
if (compare_icons_vertical_first (container,
best_so_far,
candidate) < 0)
{
return FALSE;
}
}
/* Candidates above the start do not qualify. */
if (compare_icons_vertical_first (container,
candidate,
start_icon) <= 0)
{
return FALSE;
}
return TRUE;
}
static gboolean
closest_in_90_degrees (NautilusCanvasContainer *container,
NautilusCanvasIcon *start_icon,
NautilusCanvasIcon *best_so_far,
NautilusCanvasIcon *candidate,
void *data)
{
EelDRect world_rect;
int x, y;
int dx, dy;
int dist;
int *best_dist;
world_rect = nautilus_canvas_item_get_icon_rectangle (candidate->item);
eel_canvas_w2c
(EEL_CANVAS (container),
get_cmp_point_x (container, world_rect),
get_cmp_point_y (container, world_rect),
&x,
&y);
dx = x - container->details->arrow_key_start_x;
dy = y - container->details->arrow_key_start_y;
switch (container->details->arrow_key_direction)
{
case GTK_DIR_UP:
{
if (dy > 0 ||
ABS (dx) > ABS (dy))
{
return FALSE;
}
}
break;
case GTK_DIR_DOWN:
{
if (dy < 0 ||
ABS (dx) > ABS (dy))
{
return FALSE;
}
}
break;
case GTK_DIR_LEFT:
{
if (dx > 0 ||
ABS (dy) > ABS (dx))
{
return FALSE;
}
}
break;
case GTK_DIR_RIGHT:
{
if (dx < 0 ||
ABS (dy) > ABS (dx))
{
return FALSE;
}
}
break;
default:
{
g_assert_not_reached ();
}
break;
}
dist = dx * dx + dy * dy;
best_dist = data;
if (best_so_far == NULL)
{
*best_dist = dist;
return TRUE;
}
if (dist < *best_dist)
{
*best_dist = dist;
return TRUE;
}
return FALSE;
}
static EelDRect
get_rubberband (NautilusCanvasIcon *icon1,
NautilusCanvasIcon *icon2)
{
EelDRect rect1;
EelDRect rect2;
EelDRect ret;
eel_canvas_item_get_bounds (EEL_CANVAS_ITEM (icon1->item),
&rect1.x0, &rect1.y0,
&rect1.x1, &rect1.y1);
eel_canvas_item_get_bounds (EEL_CANVAS_ITEM (icon2->item),
&rect2.x0, &rect2.y0,
&rect2.x1, &rect2.y1);
eel_drect_union (&ret, &rect1, &rect2);
return ret;
}
static void
keyboard_move_to (NautilusCanvasContainer *container,
NautilusCanvasIcon *icon,
NautilusCanvasIcon *from,
GdkEventKey *event)
{
if (icon == NULL)
{
return;
}
set_focus (container, icon, TRUE);
if (event != NULL &&
(event->state & GDK_CONTROL_MASK) != 0 &&
(event->state & GDK_SHIFT_MASK) == 0)
{
clear_keyboard_rubberband_start (container);
}
else if (event != NULL &&
(event->state & GDK_CONTROL_MASK) != 0 &&
(event->state & GDK_SHIFT_MASK) != 0)
{
/* Do rubberband selection */
EelDRect rect;
if (from && !container->details->keyboard_rubberband_start)
{
set_keyboard_rubberband_start (container, from);
}
if (icon && container->details->keyboard_rubberband_start)
{
rect = get_rubberband (container->details->keyboard_rubberband_start,
icon);
rubberband_select (container, &rect);
}
}
else if (event != NULL &&
(event->state & GDK_CONTROL_MASK) == 0 &&
(event->state & GDK_SHIFT_MASK) != 0)
{
/* Select range */
NautilusCanvasIcon *start_icon;
start_icon = container->details->range_selection_base_icon;
if (start_icon == NULL || !start_icon->is_selected)
{
start_icon = icon;
container->details->range_selection_base_icon = icon;
}
if (select_range (container, start_icon, icon, TRUE))
{
g_signal_emit (container,
signals[SELECTION_CHANGED], 0);
}
}
else
{
/* Select icon. */
clear_keyboard_rubberband_start (container);
container->details->range_selection_base_icon = icon;
if (select_one_unselect_others (container, icon))
{
g_signal_emit (container,
signals[SELECTION_CHANGED], 0);
}
}
schedule_keyboard_icon_reveal (container, icon);
}
static void
keyboard_home (NautilusCanvasContainer *container,
GdkEventKey *event)
{
NautilusCanvasIcon *from;
NautilusCanvasIcon *to;
/* Home selects the first canvas.
* Control-Home sets the keyboard focus to the first canvas.
*/
from = find_best_selected_icon (container, NULL,
rightmost_in_bottom_row,
NULL);
to = find_best_icon (container, NULL, leftmost_in_top_row, NULL);
keyboard_move_to (container, to, from, event);
}
static void
keyboard_end (NautilusCanvasContainer *container,
GdkEventKey *event)
{
NautilusCanvasIcon *to;
NautilusCanvasIcon *from;
/* End selects the last canvas.
* Control-End sets the keyboard focus to the last canvas.
*/
from = find_best_selected_icon (container, NULL,
leftmost_in_top_row,
NULL);
to = find_best_icon (container, NULL, rightmost_in_bottom_row, NULL);
keyboard_move_to (container, to, from, event);
}
static void
record_arrow_key_start (NautilusCanvasContainer *container,
NautilusCanvasIcon *icon,
GtkDirectionType direction)
{
EelDRect world_rect;
world_rect = nautilus_canvas_item_get_icon_rectangle (icon->item);
eel_canvas_w2c
(EEL_CANVAS (container),
get_cmp_point_x (container, world_rect),
get_cmp_point_y (container, world_rect),
&container->details->arrow_key_start_x,
&container->details->arrow_key_start_y);
container->details->arrow_key_direction = direction;
}
static void
keyboard_arrow_key (NautilusCanvasContainer *container,
GdkEventKey *event,
GtkDirectionType direction,
IsBetterCanvasFunction better_start,
IsBetterCanvasFunction empty_start,
IsBetterCanvasFunction better_destination,
IsBetterCanvasFunction better_destination_fallback,
IsBetterCanvasFunction better_destination_fallback_fallback,
IsBetterCanvasFunction better_destination_manual)
{
NautilusCanvasIcon *from;
NautilusCanvasIcon *to;
int data;
/* Chose the icon to start with.
* If we have a keyboard focus, start with it.
* Otherwise, use the single selected icon.
* If there's multiple selection, use the icon farthest toward the end.
*/
from = container->details->focus;
if (from == NULL)
{
if (has_multiple_selection (container))
{
if (all_selected (container))
{
from = find_best_selected_icon
(container, NULL,
empty_start, NULL);
}
else
{
from = find_best_selected_icon
(container, NULL,
better_start, NULL);
}
}
else
{
from = get_first_selected_icon (container);
}
}
/* If there's no icon, select the icon farthest toward the end.
* If there is an icon, select the next icon based on the arrow direction.
*/
if (from == NULL)
{
to = from = find_best_icon
(container, NULL,
empty_start, NULL);
}
else
{
record_arrow_key_start (container, from, direction);
to = find_best_icon
(container, from,
better_destination,
&data);
/* Wrap around to next/previous row/column */
if (to == NULL &&
better_destination_fallback != NULL)
{
to = find_best_icon
(container, from,
better_destination_fallback,
&data);
}
/* With a layout like
* 1 2 3
* 4
* (horizontal layout)
*
* or
*
* 1 4
* 2
* 3
* (vertical layout)
*
* * pressing down for any of 1,2,3 (horizontal layout)
* * pressing right for any of 1,2,3 (vertical layout)
*
* Should select 4.
*/
if (to == NULL &&
better_destination_fallback_fallback != NULL)
{
to = find_best_icon
(container, from,
better_destination_fallback_fallback,
&data);
}
if (to == NULL)
{
to = from;
}
}
keyboard_move_to (container, to, from, event);
}
static gboolean
is_rectangle_selection_event (GdkEventKey *event)
{
return event != NULL &&
(event->state & GDK_CONTROL_MASK) != 0 &&
(event->state & GDK_SHIFT_MASK) != 0;
}
static void
keyboard_right (NautilusCanvasContainer *container,
GdkEventKey *event)
{
IsBetterCanvasFunction fallback;
fallback = NULL;
if (!is_rectangle_selection_event (event))
{
fallback = next_row_leftmost;
}
/* Right selects the next icon in the same row.
* Control-Right sets the keyboard focus to the next icon in the same row.
*/
keyboard_arrow_key (container,
event,
GTK_DIR_RIGHT,
rightmost_in_bottom_row,
nautilus_canvas_container_is_layout_rtl (container) ?
rightmost_in_top_row : leftmost_in_top_row,
same_row_right_side_leftmost,
fallback,
NULL,
closest_in_90_degrees);
}
static void
keyboard_left (NautilusCanvasContainer *container,
GdkEventKey *event)
{
IsBetterCanvasFunction fallback;
fallback = NULL;
if (!is_rectangle_selection_event (event))
{
fallback = previous_row_rightmost;
}
/* Left selects the next icon in the same row.
* Control-Left sets the keyboard focus to the next icon in the same row.
*/
keyboard_arrow_key (container,
event,
GTK_DIR_LEFT,
rightmost_in_bottom_row,
nautilus_canvas_container_is_layout_rtl (container) ?
rightmost_in_top_row : leftmost_in_top_row,
same_row_left_side_rightmost,
fallback,
NULL,
closest_in_90_degrees);
}
static void
keyboard_down (NautilusCanvasContainer *container,
GdkEventKey *event)
{
IsBetterCanvasFunction next_row_fallback;
next_row_fallback = NULL;
if (gtk_widget_get_direction (GTK_WIDGET (container)) == GTK_TEXT_DIR_RTL)
{
next_row_fallback = next_row_leftmost;
}
else
{
next_row_fallback = next_row_rightmost;
}
/* Down selects the next icon in the same column.
* Control-Down sets the keyboard focus to the next icon in the same column.
*/
keyboard_arrow_key (container,
event,
GTK_DIR_DOWN,
rightmost_in_bottom_row,
nautilus_canvas_container_is_layout_rtl (container) ?
rightmost_in_top_row : leftmost_in_top_row,
same_column_below_highest,
NULL,
next_row_fallback,
closest_in_90_degrees);
}
static void
keyboard_up (NautilusCanvasContainer *container,
GdkEventKey *event)
{
/* Up selects the next icon in the same column.
* Control-Up sets the keyboard focus to the next icon in the same column.
*/
keyboard_arrow_key (container,
event,
GTK_DIR_UP,
rightmost_in_bottom_row,
nautilus_canvas_container_is_layout_rtl (container) ?
rightmost_in_top_row : leftmost_in_top_row,
same_column_above_lowest,
NULL,
NULL,
closest_in_90_degrees);
}
void
nautilus_canvas_container_preview_selection_event (NautilusCanvasContainer *container,
GtkDirectionType direction)
{
if (direction == GTK_DIR_UP)
{
keyboard_up (container, NULL);
}
else if (direction == GTK_DIR_DOWN)
{
keyboard_down (container, NULL);
}
else if (direction == GTK_DIR_LEFT)
{
keyboard_left (container, NULL);
}
else if (direction == GTK_DIR_RIGHT)
{
keyboard_right (container, NULL);
}
}
static void
keyboard_space (NautilusCanvasContainer *container,
GdkEventKey *event)
{
NautilusCanvasIcon *icon;
if (!has_selection (container) &&
container->details->focus != NULL)
{
keyboard_move_to (container,
container->details->focus,
NULL, NULL);
}
else if ((event->state & GDK_CONTROL_MASK) != 0 &&
(event->state & GDK_SHIFT_MASK) == 0)
{
/* Control-space toggles the selection state of the current icon. */
if (container->details->focus != NULL)
{
icon_toggle_selected (container, container->details->focus);
g_signal_emit (container, signals[SELECTION_CHANGED], 0);
if (container->details->focus->is_selected)
{
container->details->range_selection_base_icon = container->details->focus;
}
}
else
{
icon = find_best_selected_icon (container,
NULL,
leftmost_in_top_row,
NULL);
if (icon == NULL)
{
icon = find_best_icon (container,
NULL,
leftmost_in_top_row,
NULL);
}
if (icon != NULL)
{
set_focus (container, icon, TRUE);
}
}
}
else if ((event->state & GDK_SHIFT_MASK) != 0)
{
activate_selected_items_alternate (container, NULL);
}
else
{
preview_selected_items (container);
}
}
static void
destroy (GtkWidget *object)
{
NautilusCanvasContainer *container;
container = NAUTILUS_CANVAS_CONTAINER (object);
nautilus_canvas_container_clear (container);
if (container->details->rubberband_info.timer_id != 0)
{
g_source_remove (container->details->rubberband_info.timer_id);
container->details->rubberband_info.timer_id = 0;
}
if (container->details->idle_id != 0)
{
g_source_remove (container->details->idle_id);
container->details->idle_id = 0;
}
if (container->details->align_idle_id != 0)
{
g_source_remove (container->details->align_idle_id);
container->details->align_idle_id = 0;
}
if (container->details->selection_changed_id != 0)
{
g_source_remove (container->details->selection_changed_id);
container->details->selection_changed_id = 0;
}
if (container->details->size_allocation_count_id != 0)
{
g_source_remove (container->details->size_allocation_count_id);
container->details->size_allocation_count_id = 0;
}
GTK_WIDGET_CLASS (nautilus_canvas_container_parent_class)->destroy (object);
}
static void
finalize (GObject *object)
{
NautilusCanvasContainerDetails *details;
details = NAUTILUS_CANVAS_CONTAINER (object)->details;
g_signal_handlers_disconnect_by_func (nautilus_icon_view_preferences,
text_ellipsis_limit_changed_container_callback,
object);
g_hash_table_destroy (details->icon_set);
details->icon_set = NULL;
g_free (details->font);
if (details->a11y_item_action_queue != NULL)
{
while (!g_queue_is_empty (details->a11y_item_action_queue))
{
g_free (g_queue_pop_head (details->a11y_item_action_queue));
}
g_queue_free (details->a11y_item_action_queue);
}
if (details->a11y_item_action_idle_handler != 0)
{
g_source_remove (details->a11y_item_action_idle_handler);
}
g_free (details);
G_OBJECT_CLASS (nautilus_canvas_container_parent_class)->finalize (object);
}
/* GtkWidget methods. */
static gboolean
clear_size_allocation_count (gpointer data)
{
NautilusCanvasContainer *container;
container = NAUTILUS_CANVAS_CONTAINER (data);
container->details->size_allocation_count_id = 0;
container->details->size_allocation_count = 0;
return FALSE;
}
static void
size_allocate (GtkWidget *widget,
GtkAllocation *allocation)
{
NautilusCanvasContainer *container;
gboolean need_layout_redone;
GtkAllocation wid_allocation;
container = NAUTILUS_CANVAS_CONTAINER (widget);
need_layout_redone = !container->details->has_been_allocated;
gtk_widget_get_allocation (widget, &wid_allocation);
if (allocation->width != wid_allocation.width)
{
need_layout_redone = TRUE;
}
if (allocation->height != wid_allocation.height)
{
need_layout_redone = TRUE;
}
/* Under some conditions we can end up in a loop when size allocating.
* This happens when the icons don't fit without a scrollbar, but fits
* when a scrollbar is added (bug #129963 for details).
* We keep track of this looping by increasing a counter in size_allocate
* and clearing it in a high-prio idle (the only way to detect the loop is
* done).
* When we've done at more than two iterations (with/without scrollbar)
* we terminate this looping by not redoing the layout when the width
* is wider than the current one (i.e when removing the scrollbar).
*/
if (container->details->size_allocation_count_id == 0)
{
container->details->size_allocation_count_id =
g_idle_add_full (G_PRIORITY_HIGH,
clear_size_allocation_count,
container, NULL);
}
container->details->size_allocation_count++;
if (container->details->size_allocation_count > 2 &&
allocation->width >= wid_allocation.width)
{
need_layout_redone = FALSE;
}
GTK_WIDGET_CLASS (nautilus_canvas_container_parent_class)->size_allocate (widget, allocation);
container->details->has_been_allocated = TRUE;
if (need_layout_redone)
{
redo_layout (container);
}
}
static GtkSizeRequestMode
get_request_mode (GtkWidget *widget)
{
/* Don't trade size at all, since we get whatever we get anyway. */
return GTK_SIZE_REQUEST_CONSTANT_SIZE;
}
/* We need to implement these since the GtkScrolledWindow uses them
* to guess whether to show scrollbars or not, and if we don't report
* anything it'll tend to get it wrong causing double calls
* to size_allocate (at different sizes) during its size allocation. */
static void
get_prefered_width (GtkWidget *widget,
gint *minimum_size,
gint *natural_size)
{
EelCanvasGroup *root;
double x1, x2;
int cx1, cx2;
int width;
root = eel_canvas_root (EEL_CANVAS (widget));
eel_canvas_item_get_bounds (EEL_CANVAS_ITEM (root),
&x1, NULL, &x2, NULL);
eel_canvas_w2c (EEL_CANVAS (widget), x1, 0, &cx1, NULL);
eel_canvas_w2c (EEL_CANVAS (widget), x2, 0, &cx2, NULL);
width = cx2 - cx1;
if (natural_size)
{
*natural_size = width;
}
if (minimum_size)
{
*minimum_size = width;
}
}
static void
get_prefered_height (GtkWidget *widget,
gint *minimum_size,
gint *natural_size)
{
EelCanvasGroup *root;
double y1, y2;
int cy1, cy2;
int height;
root = eel_canvas_root (EEL_CANVAS (widget));
eel_canvas_item_get_bounds (EEL_CANVAS_ITEM (root),
NULL, &y1, NULL, &y2);
eel_canvas_w2c (EEL_CANVAS (widget), 0, y1, NULL, &cy1);
eel_canvas_w2c (EEL_CANVAS (widget), 0, y2, NULL, &cy2);
height = cy2 - cy1;
if (natural_size)
{
*natural_size = height;
}
if (minimum_size)
{
*minimum_size = height;
}
}
static void
realize (GtkWidget *widget)
{
GtkAdjustment *vadj, *hadj;
NautilusCanvasContainer *container;
GTK_WIDGET_CLASS (nautilus_canvas_container_parent_class)->realize (widget);
container = NAUTILUS_CANVAS_CONTAINER (widget);
/* Set up DnD. */
nautilus_canvas_dnd_init (container);
hadj = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (widget));
g_signal_connect (hadj, "value-changed",
G_CALLBACK (handle_hadjustment_changed), widget);
vadj = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (widget));
g_signal_connect (vadj, "value-changed",
G_CALLBACK (handle_vadjustment_changed), widget);
}
static void
unrealize (GtkWidget *widget)
{
NautilusCanvasContainer *container;
container = NAUTILUS_CANVAS_CONTAINER (widget);
nautilus_canvas_dnd_fini (container);
GTK_WIDGET_CLASS (nautilus_canvas_container_parent_class)->unrealize (widget);
}
static void
nautilus_canvas_container_request_update_all_internal (NautilusCanvasContainer *container,
gboolean invalidate_labels)
{
GList *node;
NautilusCanvasIcon *icon;
g_return_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container));
for (node = container->details->icons; node != NULL; node = node->next)
{
icon = node->data;
if (invalidate_labels)
{
nautilus_canvas_item_invalidate_label (icon->item);
}
nautilus_canvas_container_update_icon (container, icon);
}
container->details->needs_resort = TRUE;
redo_layout (container);
}
static void
style_updated (GtkWidget *widget)
{
NautilusCanvasContainer *container;
container = NAUTILUS_CANVAS_CONTAINER (widget);
GTK_WIDGET_CLASS (nautilus_canvas_container_parent_class)->style_updated (widget);
if (gtk_widget_get_realized (widget))
{
nautilus_canvas_container_request_update_all_internal (container, TRUE);
}
}
static gboolean
button_press_event (GtkWidget *widget,
GdkEventButton *event)
{
NautilusCanvasContainer *container;
gboolean selection_changed;
gboolean return_value;
gboolean clicked_on_icon;
container = NAUTILUS_CANVAS_CONTAINER (widget);
container->details->button_down_time = event->time;
/* Forget about the old keyboard selection now that we've started mousing. */
clear_keyboard_rubberband_start (container);
if (event->type == GDK_2BUTTON_PRESS || event->type == GDK_3BUTTON_PRESS)
{
/* We use our own double-click detection. */
return TRUE;
}
/* Invoke the canvas event handler and see if an item picks up the event. */
clicked_on_icon = GTK_WIDGET_CLASS (nautilus_canvas_container_parent_class)->button_press_event (widget, event);
if (!gtk_widget_has_focus (widget))
{
gtk_widget_grab_focus (widget);
}
if (clicked_on_icon)
{
return TRUE;
}
clear_focus (container);
if (event->button == DRAG_BUTTON &&
event->type == GDK_BUTTON_PRESS)
{
/* Clear the last click icon for double click */
container->details->double_click_icon[1] = container->details->double_click_icon[0];
container->details->double_click_icon[0] = NULL;
}
/* Button 1 does rubber banding. */
if (event->button == RUBBERBAND_BUTTON)
{
if (!button_event_modifies_selection (event))
{
selection_changed = unselect_all (container);
if (selection_changed)
{
g_signal_emit (container,
signals[SELECTION_CHANGED], 0);
}
}
start_rubberbanding (container, event);
return TRUE;
}
/* Prevent multi-button weirdness such as bug 6181 */
if (container->details->rubberband_info.active)
{
return TRUE;
}
/* Button 2 may be passed to the window manager. */
if (event->button == MIDDLE_BUTTON)
{
selection_changed = unselect_all (container);
if (selection_changed)
{
g_signal_emit (container, signals[SELECTION_CHANGED], 0);
}
g_signal_emit (widget, signals[MIDDLE_CLICK], 0, event);
return TRUE;
}
/* Button 3 does a contextual menu. */
if (event->button == CONTEXTUAL_MENU_BUTTON)
{
selection_changed = unselect_all (container);
if (selection_changed)
{
g_signal_emit (container, signals[SELECTION_CHANGED], 0);
}
g_signal_emit (widget, signals[CONTEXT_CLICK_BACKGROUND], 0, event);
return TRUE;
}
/* Otherwise, we emit a button_press message. */
g_signal_emit (widget,
signals[BUTTON_PRESS], 0, event,
&return_value);
return return_value;
}
static void
nautilus_canvas_container_did_not_drag (NautilusCanvasContainer *container,
GdkEventButton *event)
{
NautilusCanvasContainerDetails *details;
gboolean selection_changed;
static gint64 last_click_time = 0;
static gint click_count = 0;
gint double_click_time;
gint64 current_time;
details = container->details;
if (details->icon_selected_on_button_down &&
((event->state & GDK_CONTROL_MASK) != 0 ||
(event->state & GDK_SHIFT_MASK) == 0))
{
if (button_event_modifies_selection (event))
{
details->range_selection_base_icon = NULL;
icon_toggle_selected (container, details->drag_icon);
g_signal_emit (container,
signals[SELECTION_CHANGED], 0);
}
else
{
details->range_selection_base_icon = details->drag_icon;
selection_changed = select_one_unselect_others
(container, details->drag_icon);
if (selection_changed)
{
g_signal_emit (container,
signals[SELECTION_CHANGED], 0);
}
}
}
if (details->drag_icon != NULL &&
(details->single_click_mode ||
event->button == MIDDLE_BUTTON))
{
/* Determine click count */
g_object_get (G_OBJECT (gtk_widget_get_settings (GTK_WIDGET (container))),
"gtk-double-click-time", &double_click_time,
NULL);
current_time = g_get_monotonic_time ();
if (current_time - last_click_time < double_click_time * 1000)
{
click_count++;
}
else
{
click_count = 0;
}
/* Stash time for next compare */
last_click_time = current_time;
/* If single-click mode, activate the selected icons, unless modifying
* the selection or pressing for a very long time, or double clicking.
*/
if (click_count == 0 &&
event->time - details->button_down_time < MAX_CLICK_TIME &&
!button_event_modifies_selection (event))
{
/* It's a tricky UI issue whether this should activate
* just the clicked item (as if it were a link), or all
* the selected items (as if you were issuing an "activate
* selection" command). For now, we're trying the activate
* entire selection version to see how it feels. Note that
* NautilusList goes the other way because its "links" seem
* much more link-like.
*/
if (event->button == MIDDLE_BUTTON)
{
activate_selected_items_alternate (container, NULL);
}
else
{
activate_selected_items (container);
}
}
}
}
static gboolean
clicked_within_double_click_interval (NautilusCanvasContainer *container)
{
static gint64 last_click_time = 0;
static gint click_count = 0;
gint double_click_time;
gint64 current_time;
/* Determine click count */
g_object_get (G_OBJECT (gtk_widget_get_settings (GTK_WIDGET (container))),
"gtk-double-click-time", &double_click_time,
NULL);
current_time = g_get_monotonic_time ();
if (current_time - last_click_time < double_click_time * 1000)
{
click_count++;
}
else
{
click_count = 0;
}
/* Stash time for next compare */
last_click_time = current_time;
/* Only allow double click */
if (click_count == 1)
{
click_count = 0;
return TRUE;
}
else
{
return FALSE;
}
}
static void
clear_drag_state (NautilusCanvasContainer *container)
{
container->details->drag_icon = NULL;
container->details->drag_state = DRAG_STATE_INITIAL;
}
static gboolean
button_release_event (GtkWidget *widget,
GdkEventButton *event)
{
NautilusCanvasContainer *container;
NautilusCanvasContainerDetails *details;
container = NAUTILUS_CANVAS_CONTAINER (widget);
details = container->details;
if (event->button == RUBBERBAND_BUTTON && details->rubberband_info.active)
{
stop_rubberbanding (container, event);
return TRUE;
}
if (event->button == details->drag_button)
{
details->drag_button = 0;
switch (details->drag_state)
{
case DRAG_STATE_MOVE_OR_COPY:
{
if (!details->drag_started)
{
nautilus_canvas_container_did_not_drag (container, event);
}
else
{
nautilus_canvas_dnd_end_drag (container);
DEBUG ("Ending drag from canvas container");
}
}
break;
default:
{
}
break;
}
clear_drag_state (container);
return TRUE;
}
return GTK_WIDGET_CLASS (nautilus_canvas_container_parent_class)->button_release_event (widget, event);
}
static int
motion_notify_event (GtkWidget *widget,
GdkEventMotion *event)
{
NautilusCanvasContainer *container;
NautilusCanvasContainerDetails *details;
double world_x, world_y;
int canvas_x, canvas_y;
GdkDragAction actions;
container = NAUTILUS_CANVAS_CONTAINER (widget);
details = container->details;
if (details->drag_button != 0)
{
switch (details->drag_state)
{
case DRAG_STATE_MOVE_OR_COPY:
{
if (details->drag_started)
{
break;
}
eel_canvas_window_to_world
(EEL_CANVAS (container), event->x, event->y, &world_x, &world_y);
if (gtk_drag_check_threshold (widget,
details->drag_x,
details->drag_y,
world_x,
world_y))
{
details->drag_started = TRUE;
details->drag_state = DRAG_STATE_MOVE_OR_COPY;
eel_canvas_w2c (EEL_CANVAS (container),
details->drag_x,
details->drag_y,
&canvas_x,
&canvas_y);
actions = GDK_ACTION_COPY
| GDK_ACTION_MOVE
| GDK_ACTION_LINK
| GDK_ACTION_ASK;
nautilus_canvas_dnd_begin_drag (container,
actions,
details->drag_button,
event,
canvas_x,
canvas_y);
DEBUG ("Beginning drag from canvas container");
}
}
break;
default:
{
}
break;
}
}
return GTK_WIDGET_CLASS (nautilus_canvas_container_parent_class)->motion_notify_event (widget, event);
}
static void
nautilus_canvas_container_get_icon_text (NautilusCanvasContainer *container,
NautilusCanvasIconData *data,
char **editable_text,
char **additional_text,
gboolean include_invisible)
{
NautilusCanvasContainerClass *klass;
klass = NAUTILUS_CANVAS_CONTAINER_GET_CLASS (container);
g_assert (klass->get_icon_text != NULL);
klass->get_icon_text (container, data, editable_text, additional_text, include_invisible);
}
static gboolean
handle_popups (NautilusCanvasContainer *container,
GdkEvent *event,
const char *signal)
{
/* ensure we clear the drag state before showing the menu */
clear_drag_state (container);
g_signal_emit_by_name (container, signal, event);
return TRUE;
}
static int
key_press_event (GtkWidget *widget,
GdkEventKey *event)
{
NautilusCanvasContainer *container;
gboolean handled;
container = NAUTILUS_CANVAS_CONTAINER (widget);
handled = FALSE;
switch (event->keyval)
{
case GDK_KEY_Home:
case GDK_KEY_KP_Home:
{
keyboard_home (container, event);
handled = TRUE;
}
break;
case GDK_KEY_End:
case GDK_KEY_KP_End:
{
keyboard_end (container, event);
handled = TRUE;
}
break;
case GDK_KEY_Left:
case GDK_KEY_KP_Left:
{
/* Don't eat Alt-Left, as that is used for history browsing */
if ((event->state & GDK_MOD1_MASK) == 0)
{
keyboard_left (container, event);
handled = TRUE;
}
}
break;
case GDK_KEY_Up:
case GDK_KEY_KP_Up:
{
/* Don't eat Alt-Up, as that is used for alt-shift-Up */
if ((event->state & GDK_MOD1_MASK) == 0)
{
keyboard_up (container, event);
handled = TRUE;
}
}
break;
case GDK_KEY_Right:
case GDK_KEY_KP_Right:
{
/* Don't eat Alt-Right, as that is used for history browsing */
if ((event->state & GDK_MOD1_MASK) == 0)
{
keyboard_right (container, event);
handled = TRUE;
}
}
break;
case GDK_KEY_Down:
case GDK_KEY_KP_Down:
{
/* Don't eat Alt-Down, as that is used for Open */
if ((event->state & GDK_MOD1_MASK) == 0)
{
keyboard_down (container, event);
handled = TRUE;
}
}
break;
case GDK_KEY_space:
{
keyboard_space (container, event);
handled = TRUE;
}
break;
case GDK_KEY_F10:
{
/* handle Ctrl+F10 because we want to display the
* background popup even if something is selected.
* The other cases are handled by the "popup-menu" GtkWidget signal.
*/
if (event->state & GDK_CONTROL_MASK)
{
handled = handle_popups (container, (GdkEvent *) event,
"context_click_background");
}
}
break;
case GDK_KEY_v:
{
/* Eat Control + v to not enable type ahead */
if ((event->state & GDK_CONTROL_MASK) != 0)
{
handled = TRUE;
}
}
break;
default:
{
}
break;
}
if (!handled)
{
handled = GTK_WIDGET_CLASS (nautilus_canvas_container_parent_class)->key_press_event (widget, event);
}
return handled;
}
static void
grab_notify_cb (GtkWidget *widget,
gboolean was_grabbed)
{
NautilusCanvasContainer *container;
container = NAUTILUS_CANVAS_CONTAINER (widget);
if (container->details->rubberband_info.active &&
!was_grabbed)
{
/* we got a (un)grab-notify during rubberband.
* This happens when a new modal dialog shows
* up (e.g. authentication or an error). Stop
* the rubberbanding so that we can handle the
* dialog. */
stop_rubberbanding (container, NULL);
}
}
static void
text_ellipsis_limit_changed_container_callback (gpointer callback_data)
{
NautilusCanvasContainer *container;
container = NAUTILUS_CANVAS_CONTAINER (callback_data);
invalidate_label_sizes (container);
schedule_redo_layout (container);
}
static GObject *
nautilus_canvas_container_constructor (GType type,
guint n_construct_params,
GObjectConstructParam *construct_params)
{
NautilusCanvasContainer *container;
GObject *object;
object = G_OBJECT_CLASS (nautilus_canvas_container_parent_class)->constructor
(type,
n_construct_params,
construct_params);
container = NAUTILUS_CANVAS_CONTAINER (object);
g_signal_connect_swapped (nautilus_icon_view_preferences,
"changed::" NAUTILUS_PREFERENCES_ICON_VIEW_TEXT_ELLIPSIS_LIMIT,
G_CALLBACK (text_ellipsis_limit_changed_container_callback),
container);
return object;
}
/* Initialization. */
static void
nautilus_canvas_container_class_init (NautilusCanvasContainerClass *class)
{
GtkWidgetClass *widget_class;
G_OBJECT_CLASS (class)->constructor = nautilus_canvas_container_constructor;
G_OBJECT_CLASS (class)->finalize = finalize;
/* Signals. */
signals[SELECTION_CHANGED]
= g_signal_new ("selection-changed",
G_TYPE_FROM_CLASS (class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (NautilusCanvasContainerClass,
selection_changed),
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
signals[BUTTON_PRESS]
= g_signal_new ("button-press",
G_TYPE_FROM_CLASS (class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (NautilusCanvasContainerClass,
button_press),
NULL, NULL,
g_cclosure_marshal_generic,
G_TYPE_BOOLEAN, 1,
GDK_TYPE_EVENT);
signals[ACTIVATE]
= g_signal_new ("activate",
G_TYPE_FROM_CLASS (class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (NautilusCanvasContainerClass,
activate),
NULL, NULL,
g_cclosure_marshal_VOID__POINTER,
G_TYPE_NONE, 1,
G_TYPE_POINTER);
signals[ACTIVATE_ALTERNATE]
= g_signal_new ("activate-alternate",
G_TYPE_FROM_CLASS (class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (NautilusCanvasContainerClass,
activate_alternate),
NULL, NULL,
g_cclosure_marshal_VOID__POINTER,
G_TYPE_NONE, 1,
G_TYPE_POINTER);
signals[ACTIVATE_PREVIEWER]
= g_signal_new ("activate-previewer",
G_TYPE_FROM_CLASS (class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (NautilusCanvasContainerClass,
activate_previewer),
NULL, NULL,
g_cclosure_marshal_generic,
G_TYPE_NONE, 2,
G_TYPE_POINTER, G_TYPE_POINTER);
signals[CONTEXT_CLICK_SELECTION]
= g_signal_new ("context-click-selection",
G_TYPE_FROM_CLASS (class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (NautilusCanvasContainerClass,
context_click_selection),
NULL, NULL,
g_cclosure_marshal_VOID__POINTER,
G_TYPE_NONE, 1,
G_TYPE_POINTER);
signals[CONTEXT_CLICK_BACKGROUND]
= g_signal_new ("context-click-background",
G_TYPE_FROM_CLASS (class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (NautilusCanvasContainerClass,
context_click_background),
NULL, NULL,
g_cclosure_marshal_VOID__POINTER,
G_TYPE_NONE, 1,
G_TYPE_POINTER);
signals[MIDDLE_CLICK]
= g_signal_new ("middle-click",
G_TYPE_FROM_CLASS (class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (NautilusCanvasContainerClass,
middle_click),
NULL, NULL,
g_cclosure_marshal_VOID__POINTER,
G_TYPE_NONE, 1,
G_TYPE_POINTER);
signals[GET_ICON_URI]
= g_signal_new ("get-icon-uri",
G_TYPE_FROM_CLASS (class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (NautilusCanvasContainerClass,
get_icon_uri),
NULL, NULL,
g_cclosure_marshal_generic,
G_TYPE_STRING, 1,
G_TYPE_POINTER);
signals[GET_ICON_ACTIVATION_URI]
= g_signal_new ("get-icon-activation-uri",
G_TYPE_FROM_CLASS (class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (NautilusCanvasContainerClass,
get_icon_activation_uri),
NULL, NULL,
g_cclosure_marshal_generic,
G_TYPE_STRING, 1,
G_TYPE_POINTER);
signals[GET_ICON_DROP_TARGET_URI]
= g_signal_new ("get-icon-drop-target-uri",
G_TYPE_FROM_CLASS (class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (NautilusCanvasContainerClass,
get_icon_drop_target_uri),
NULL, NULL,
g_cclosure_marshal_generic,
G_TYPE_STRING, 1,
G_TYPE_POINTER);
signals[MOVE_COPY_ITEMS]
= g_signal_new ("move-copy-items",
G_TYPE_FROM_CLASS (class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (NautilusCanvasContainerClass,
move_copy_items),
NULL, NULL,
g_cclosure_marshal_generic,
G_TYPE_NONE, 3,
G_TYPE_POINTER,
G_TYPE_POINTER,
GDK_TYPE_DRAG_ACTION);
signals[HANDLE_NETSCAPE_URL]
= g_signal_new ("handle-netscape-url",
G_TYPE_FROM_CLASS (class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (NautilusCanvasContainerClass,
handle_netscape_url),
NULL, NULL,
g_cclosure_marshal_generic,
G_TYPE_NONE, 3,
G_TYPE_STRING,
G_TYPE_STRING,
GDK_TYPE_DRAG_ACTION);
signals[HANDLE_URI_LIST]
= g_signal_new ("handle-uri-list",
G_TYPE_FROM_CLASS (class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (NautilusCanvasContainerClass,
handle_uri_list),
NULL, NULL,
g_cclosure_marshal_generic,
G_TYPE_NONE, 3,
G_TYPE_STRING,
G_TYPE_STRING,
GDK_TYPE_DRAG_ACTION);
signals[HANDLE_TEXT]
= g_signal_new ("handle-text",
G_TYPE_FROM_CLASS (class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (NautilusCanvasContainerClass,
handle_text),
NULL, NULL,
g_cclosure_marshal_generic,
G_TYPE_NONE, 3,
G_TYPE_STRING,
G_TYPE_STRING,
GDK_TYPE_DRAG_ACTION);
signals[HANDLE_RAW]
= g_signal_new ("handle-raw",
G_TYPE_FROM_CLASS (class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (NautilusCanvasContainerClass,
handle_raw),
NULL, NULL,
g_cclosure_marshal_generic,
G_TYPE_NONE, 5,
G_TYPE_POINTER,
G_TYPE_INT,
G_TYPE_STRING,
G_TYPE_STRING,
GDK_TYPE_DRAG_ACTION);
signals[HANDLE_HOVER] =
g_signal_new ("handle-hover",
G_TYPE_FROM_CLASS (class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (NautilusCanvasContainerClass,
handle_hover),
NULL, NULL,
g_cclosure_marshal_generic,
G_TYPE_NONE, 1,
G_TYPE_STRING);
signals[GET_CONTAINER_URI]
= g_signal_new ("get-container-uri",
G_TYPE_FROM_CLASS (class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (NautilusCanvasContainerClass,
get_container_uri),
NULL, NULL,
g_cclosure_marshal_generic,
G_TYPE_STRING, 0);
signals[BAND_SELECT_STARTED]
= g_signal_new ("band-select-started",
G_TYPE_FROM_CLASS (class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (NautilusCanvasContainerClass,
band_select_started),
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
signals[BAND_SELECT_ENDED]
= g_signal_new ("band-select-ended",
G_TYPE_FROM_CLASS (class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (NautilusCanvasContainerClass,
band_select_ended),
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
signals[ICON_ADDED]
= g_signal_new ("icon-added",
G_TYPE_FROM_CLASS (class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (NautilusCanvasContainerClass,
icon_added),
NULL, NULL,
g_cclosure_marshal_VOID__POINTER,
G_TYPE_NONE, 1, G_TYPE_POINTER);
signals[ICON_REMOVED]
= g_signal_new ("icon-removed",
G_TYPE_FROM_CLASS (class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (NautilusCanvasContainerClass,
icon_removed),
NULL, NULL,
g_cclosure_marshal_VOID__POINTER,
G_TYPE_NONE, 1, G_TYPE_POINTER);
signals[CLEARED]
= g_signal_new ("cleared",
G_TYPE_FROM_CLASS (class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (NautilusCanvasContainerClass,
cleared),
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
/* GtkWidget class. */
widget_class = GTK_WIDGET_CLASS (class);
widget_class->destroy = destroy;
widget_class->size_allocate = size_allocate;
widget_class->get_request_mode = get_request_mode;
widget_class->get_preferred_width = get_prefered_width;
widget_class->get_preferred_height = get_prefered_height;
widget_class->realize = realize;
widget_class->unrealize = unrealize;
widget_class->button_press_event = button_press_event;
widget_class->button_release_event = button_release_event;
widget_class->motion_notify_event = motion_notify_event;
widget_class->key_press_event = key_press_event;
widget_class->style_updated = style_updated;
widget_class->grab_notify = grab_notify_cb;
gtk_widget_class_set_accessible_type (widget_class, nautilus_canvas_container_accessible_get_type ());
}
static void
update_selected (NautilusCanvasContainer *container)
{
GList *node;
NautilusCanvasIcon *icon;
for (node = container->details->icons; node != NULL; node = node->next)
{
icon = node->data;
if (icon->is_selected)
{
eel_canvas_item_request_update (EEL_CANVAS_ITEM (icon->item));
}
}
}
static void
handle_has_focus_changed (GObject *object,
GParamSpec *pspec,
gpointer user_data)
{
update_selected (NAUTILUS_CANVAS_CONTAINER (object));
}
static void
handle_scale_factor_changed (GObject *object,
GParamSpec *pspec,
gpointer user_data)
{
nautilus_canvas_container_request_update_all_internal (NAUTILUS_CANVAS_CONTAINER (object),
TRUE);
}
static int text_ellipsis_limits[NAUTILUS_CANVAS_ZOOM_LEVEL_N_ENTRIES];
static gboolean
get_text_ellipsis_limit_for_zoom (char **strs,
const char *zoom_level,
int *limit)
{
char **p;
char *str;
gboolean success;
success = FALSE;
/* default */
*limit = 3;
if (zoom_level != NULL)
{
str = g_strdup_printf ("%s:%%d", zoom_level);
}
else
{
str = g_strdup ("%d");
}
if (strs != NULL)
{
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
for (p = strs; *p != NULL; p++)
{
if (sscanf (*p, str, limit))
{
success = TRUE;
}
}
#pragma GCC diagnostic pop
}
g_free (str);
return success;
}
static const char *zoom_level_names[] =
{
"small",
"standard",
"large",
};
static void
text_ellipsis_limit_changed_callback (gpointer callback_data)
{
char **pref;
unsigned int i;
int one_limit;
pref = g_settings_get_strv (nautilus_icon_view_preferences,
NAUTILUS_PREFERENCES_ICON_VIEW_TEXT_ELLIPSIS_LIMIT);
/* set default */
get_text_ellipsis_limit_for_zoom (pref, NULL, &one_limit);
for (i = 0; i < NAUTILUS_CANVAS_ZOOM_LEVEL_N_ENTRIES; i++)
{
text_ellipsis_limits[i] = one_limit;
}
/* override for each zoom level */
for (i = 0; i < G_N_ELEMENTS (zoom_level_names); i++)
{
if (get_text_ellipsis_limit_for_zoom (pref,
zoom_level_names[i],
&one_limit))
{
text_ellipsis_limits[i] = one_limit;
}
}
g_strfreev (pref);
}
static void
nautilus_canvas_container_init (NautilusCanvasContainer *container)
{
NautilusCanvasContainerDetails *details;
static gboolean setup_prefs = FALSE;
details = g_new0 (NautilusCanvasContainerDetails, 1);
details->icon_set = g_hash_table_new (g_direct_hash, g_direct_equal);
details->zoom_level = NAUTILUS_CANVAS_ZOOM_LEVEL_STANDARD;
container->details = details;
g_signal_connect (container, "notify::has-focus",
G_CALLBACK (handle_has_focus_changed), NULL);
g_signal_connect (container, "notify::scale-factor",
G_CALLBACK (handle_scale_factor_changed), NULL);
if (!setup_prefs)
{
g_signal_connect_swapped (nautilus_icon_view_preferences,
"changed::" NAUTILUS_PREFERENCES_ICON_VIEW_TEXT_ELLIPSIS_LIMIT,
G_CALLBACK (text_ellipsis_limit_changed_callback),
NULL);
text_ellipsis_limit_changed_callback (NULL);
setup_prefs = TRUE;
}
}
typedef struct
{
NautilusCanvasContainer *container;
GdkEventButton *event;
} ContextMenuParameters;
static gboolean
handle_canvas_double_click (NautilusCanvasContainer *container,
NautilusCanvasIcon *icon,
GdkEventButton *event)
{
NautilusCanvasContainerDetails *details;
if (event->button != DRAG_BUTTON)
{
return FALSE;
}
details = container->details;
if (!details->single_click_mode &&
clicked_within_double_click_interval (container) &&
details->double_click_icon[0] == details->double_click_icon[1] &&
details->double_click_button[0] == details->double_click_button[1])
{
details->double_clicked = TRUE;
return TRUE;
}
return FALSE;
}
/* NautilusCanvasIcon event handling. */
/* Conceptually, pressing button 1 together with CTRL or SHIFT toggles
* selection of a single icon without affecting the other icons;
* without CTRL or SHIFT, it selects a single icon and un-selects all
* the other icons. But in this latter case, the de-selection should
* only happen when the button is released if the icon is already
* selected, because the user might select multiple icons and drag all
* of them by doing a simple click-drag.
*/
static gboolean
handle_canvas_button_press (NautilusCanvasContainer *container,
NautilusCanvasIcon *icon,
GdkEventButton *event)
{
NautilusCanvasContainerDetails *details;
details = container->details;
if (event->type == GDK_2BUTTON_PRESS || event->type == GDK_3BUTTON_PRESS)
{
return TRUE;
}
if (event->button != DRAG_BUTTON
&& event->button != CONTEXTUAL_MENU_BUTTON
&& event->button != DRAG_MENU_BUTTON)
{
return TRUE;
}
if ((event->button == DRAG_BUTTON) &&
event->type == GDK_BUTTON_PRESS)
{
/* The next double click has to be on this icon */
details->double_click_icon[1] = details->double_click_icon[0];
details->double_click_icon[0] = icon;
details->double_click_button[1] = details->double_click_button[0];
details->double_click_button[0] = event->button;
}
if (handle_canvas_double_click (container, icon, event))
{
/* Double clicking does not trigger a D&D action. */
details->drag_button = 0;
details->drag_icon = NULL;
return TRUE;
}
if (event->button == DRAG_BUTTON
|| event->button == DRAG_MENU_BUTTON)
{
details->drag_button = event->button;
details->drag_icon = icon;
details->drag_x = event->x;
details->drag_y = event->y;
details->drag_state = DRAG_STATE_MOVE_OR_COPY;
details->drag_started = FALSE;
}
/* Modify the selection as appropriate. Selection is modified
* the same way for contextual menu as it would be without.
*/
details->icon_selected_on_button_down = icon->is_selected;
if ((event->button == DRAG_BUTTON || event->button == MIDDLE_BUTTON) &&
(event->state & GDK_SHIFT_MASK) != 0)
{
NautilusCanvasIcon *start_icon;
set_focus (container, icon, FALSE);
start_icon = details->range_selection_base_icon;
if (start_icon == NULL || !start_icon->is_selected)
{
start_icon = icon;
details->range_selection_base_icon = icon;
}
if (select_range (container, start_icon, icon,
(event->state & GDK_CONTROL_MASK) == 0))
{
g_signal_emit (container,
signals[SELECTION_CHANGED], 0);
}
}
else if (!details->icon_selected_on_button_down)
{
set_focus (container, icon, FALSE);
details->range_selection_base_icon = icon;
if (button_event_modifies_selection (event))
{
icon_toggle_selected (container, icon);
g_signal_emit (container,
signals[SELECTION_CHANGED], 0);
}
else
{
select_one_unselect_others (container, icon);
g_signal_emit (container,
signals[SELECTION_CHANGED], 0);
}
}
if (event->button == CONTEXTUAL_MENU_BUTTON)
{
clear_drag_state (container);
g_signal_emit (container,
signals[CONTEXT_CLICK_SELECTION], 0,
event);
}
return TRUE;
}
static int
item_event_callback (EelCanvasItem *item,
GdkEvent *event,
gpointer data)
{
NautilusCanvasContainer *container;
NautilusCanvasIcon *icon;
GdkEventButton *event_button;
container = NAUTILUS_CANVAS_CONTAINER (data);
icon = NAUTILUS_CANVAS_ITEM (item)->user_data;
g_assert (icon != NULL);
event_button = &event->button;
switch (event->type)
{
case GDK_MOTION_NOTIFY:
{
return FALSE;
}
case GDK_BUTTON_PRESS:
{
container->details->double_clicked = FALSE;
if (handle_canvas_button_press (container, icon, event_button))
{
/* Stop the event from being passed along further. Returning
* TRUE ain't enough.
*/
return TRUE;
}
return FALSE;
}
case GDK_BUTTON_RELEASE:
{
if (event_button->button == DRAG_BUTTON
&& container->details->double_clicked)
{
if (!button_event_modifies_selection (event_button))
{
activate_selected_items (container);
}
else if ((event_button->state & GDK_CONTROL_MASK) == 0 &&
(event_button->state & GDK_SHIFT_MASK) != 0)
{
activate_selected_items_alternate (container, icon);
}
}
/* fall through */
}
default:
{
container->details->double_clicked = FALSE;
return FALSE;
}
break;
}
}
GtkWidget *
nautilus_canvas_container_new (void)
{
return gtk_widget_new (NAUTILUS_TYPE_CANVAS_CONTAINER, NULL);
}
/* Clear all of the icons in the container. */
void
nautilus_canvas_container_clear (NautilusCanvasContainer *container)
{
NautilusCanvasContainerDetails *details;
GList *p;
g_return_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container));
details = container->details;
if (details->icons == NULL)
{
return;
}
clear_focus (container);
clear_keyboard_rubberband_start (container);
unschedule_keyboard_icon_reveal (container);
set_pending_icon_to_reveal (container, NULL);
details->drop_target = NULL;
for (p = details->icons; p != NULL; p = p->next)
{
icon_free (p->data);
}
g_list_free (details->icons);
details->icons = NULL;
g_list_free (details->new_icons);
details->new_icons = NULL;
g_list_free (details->selection);
details->selection = NULL;
g_hash_table_destroy (details->icon_set);
details->icon_set = g_hash_table_new (g_direct_hash, g_direct_equal);
nautilus_canvas_container_update_scroll_region (container);
}
gboolean
nautilus_canvas_container_is_empty (NautilusCanvasContainer *container)
{
return container->details->icons == NULL;
}
NautilusCanvasIconData *
nautilus_canvas_container_get_first_visible_icon (NautilusCanvasContainer *container)
{
GList *l;
NautilusCanvasIcon *icon, *best_icon;
double x, y;
double x1, y1, x2, y2;
double *pos, best_pos;
double hadj_v, vadj_v, h_page_size;
gboolean better_icon;
gboolean compare_lt;
hadj_v = gtk_adjustment_get_value (gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (container)));
vadj_v = gtk_adjustment_get_value (gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (container)));
h_page_size = gtk_adjustment_get_page_size (gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (container)));
if (nautilus_canvas_container_is_layout_rtl (container))
{
x = hadj_v + h_page_size - ICON_PAD_LEFT - 1;
y = vadj_v;
}
else
{
x = hadj_v;
y = vadj_v;
}
eel_canvas_c2w (EEL_CANVAS (container),
x, y,
&x, &y);
l = container->details->icons;
best_icon = NULL;
best_pos = 0;
while (l != NULL)
{
icon = l->data;
if (icon_is_positioned (icon))
{
eel_canvas_item_get_bounds (EEL_CANVAS_ITEM (icon->item),
&x1, &y1, &x2, &y2);
compare_lt = FALSE;
pos = &y1;
better_icon = y2 > y + ICON_PAD_TOP;
if (better_icon)
{
if (best_icon == NULL)
{
better_icon = TRUE;
}
else if (compare_lt)
{
better_icon = best_pos < *pos;
}
else
{
better_icon = best_pos > *pos;
}
if (better_icon)
{
best_icon = icon;
best_pos = *pos;
}
}
}
l = l->next;
}
return best_icon ? best_icon->data : NULL;
}
NautilusCanvasIconData *
nautilus_canvas_container_get_focused_icon (NautilusCanvasContainer *container)
{
NautilusCanvasIcon *icon;
icon = container->details->focus;
if (icon != NULL)
{
return icon->data;
}
return NULL;
}
/* puts the icon at the top of the screen */
void
nautilus_canvas_container_scroll_to_canvas (NautilusCanvasContainer *container,
NautilusCanvasIconData *data)
{
GList *l;
NautilusCanvasIcon *icon;
GtkAdjustment *vadj;
EelIRect bounds;
GtkAllocation allocation;
vadj = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (container));
gtk_widget_get_allocation (GTK_WIDGET (container), &allocation);
/* We need to force a relayout now if there are updates queued
* since we need the final positions */
nautilus_canvas_container_layout_now (container);
l = container->details->icons;
while (l != NULL)
{
icon = l->data;
if (icon->data == data &&
icon_is_positioned (icon))
{
/* ensure that we reveal the entire row/column */
icon_get_row_and_column_bounds (container, icon, &bounds);
gtk_adjustment_set_value (vadj, bounds.y0);
}
l = l->next;
}
}
/* Call a function for all the icons. */
typedef struct
{
NautilusCanvasCallback callback;
gpointer callback_data;
} CallbackAndData;
static void
call_canvas_callback (gpointer data,
gpointer callback_data)
{
NautilusCanvasIcon *icon;
CallbackAndData *callback_and_data;
icon = data;
callback_and_data = callback_data;
(*callback_and_data->callback)(icon->data, callback_and_data->callback_data);
}
void
nautilus_canvas_container_for_each (NautilusCanvasContainer *container,
NautilusCanvasCallback callback,
gpointer callback_data)
{
CallbackAndData callback_and_data;
g_return_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container));
callback_and_data.callback = callback;
callback_and_data.callback_data = callback_data;
g_list_foreach (container->details->icons,
call_canvas_callback, &callback_and_data);
}
static int
selection_changed_at_idle_callback (gpointer data)
{
NautilusCanvasContainer *container;
container = NAUTILUS_CANVAS_CONTAINER (data);
g_signal_emit (container,
signals[SELECTION_CHANGED], 0);
container->details->selection_changed_id = 0;
return FALSE;
}
/* utility routine to remove a single icon from the container */
static void
icon_destroy (NautilusCanvasContainer *container,
NautilusCanvasIcon *icon)
{
NautilusCanvasContainerDetails *details;
gboolean was_selected;
NautilusCanvasIcon *icon_to_focus;
GList *item;
details = container->details;
item = g_list_find (details->icons, icon);
item = item->next ? item->next : item->prev;
icon_to_focus = (item != NULL) ? item->data : NULL;
details->icons = g_list_remove (details->icons, icon);
details->new_icons = g_list_remove (details->new_icons, icon);
details->selection = g_list_remove (details->selection, icon->data);
g_hash_table_remove (details->icon_set, icon->data);
was_selected = icon->is_selected;
if (details->focus == icon ||
details->focus == NULL)
{
if (icon_to_focus != NULL)
{
set_focus (container, icon_to_focus, TRUE);
}
else
{
clear_focus (container);
}
}
if (details->keyboard_rubberband_start == icon)
{
clear_keyboard_rubberband_start (container);
}
if (details->keyboard_icon_to_reveal == icon)
{
unschedule_keyboard_icon_reveal (container);
}
if (details->drag_icon == icon)
{
clear_drag_state (container);
}
if (details->drop_target == icon)
{
details->drop_target = NULL;
}
if (details->range_selection_base_icon == icon)
{
details->range_selection_base_icon = NULL;
}
if (details->pending_icon_to_reveal == icon)
{
set_pending_icon_to_reveal (container, NULL);
}
icon_free (icon);
if (was_selected)
{
/* Coalesce multiple removals causing multiple selection_changed events */
details->selection_changed_id = g_idle_add (selection_changed_at_idle_callback, container);
}
}
/* activate any selected items in the container */
static void
activate_selected_items (NautilusCanvasContainer *container)
{
GList *selection;
g_return_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container));
selection = nautilus_canvas_container_get_selection (container);
if (selection != NULL)
{
g_signal_emit (container,
signals[ACTIVATE], 0,
selection);
}
g_list_free (selection);
}
static void
preview_selected_items (NautilusCanvasContainer *container)
{
GList *selection;
GArray *locations;
gint idx;
g_return_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container));
selection = nautilus_canvas_container_get_selection (container);
locations = nautilus_canvas_container_get_selected_icon_locations (container);
for (idx = 0; idx < locations->len; idx++)
{
GdkPoint *point = &(g_array_index (locations, GdkPoint, idx));
gint scroll_x, scroll_y;
eel_canvas_get_scroll_offsets (EEL_CANVAS (container),
&scroll_x, &scroll_y);
point->x -= scroll_x;
point->y -= scroll_y;
}
if (selection != NULL)
{
g_signal_emit (container,
signals[ACTIVATE_PREVIEWER], 0,
selection, locations);
}
g_list_free (selection);
g_array_unref (locations);
}
static void
activate_selected_items_alternate (NautilusCanvasContainer *container,
NautilusCanvasIcon *icon)
{
GList *selection;
g_assert (NAUTILUS_IS_CANVAS_CONTAINER (container));
if (icon != NULL)
{
selection = g_list_prepend (NULL, icon->data);
}
else
{
selection = nautilus_canvas_container_get_selection (container);
}
if (selection != NULL)
{
g_signal_emit (container,
signals[ACTIVATE_ALTERNATE], 0,
selection);
}
g_list_free (selection);
}
static NautilusIconInfo *
nautilus_canvas_container_get_icon_images (NautilusCanvasContainer *container,
NautilusCanvasIconData *data,
int size,
gboolean for_drag_accept)
{
NautilusCanvasContainerClass *klass;
klass = NAUTILUS_CANVAS_CONTAINER_GET_CLASS (container);
g_assert (klass->get_icon_images != NULL);
return klass->get_icon_images (container, data, size, for_drag_accept);
}
static void
nautilus_canvas_container_prioritize_thumbnailing (NautilusCanvasContainer *container,
NautilusCanvasIcon *icon)
{
NautilusCanvasContainerClass *klass;
klass = NAUTILUS_CANVAS_CONTAINER_GET_CLASS (container);
g_assert (klass->prioritize_thumbnailing != NULL);
klass->prioritize_thumbnailing (container, icon->data);
}
static void
nautilus_canvas_container_update_visible_icons (NautilusCanvasContainer *container)
{
GtkAdjustment *vadj, *hadj;
double min_y, max_y;
double min_x, max_x;
double x0, y0, x1, y1;
GList *node;
NautilusCanvasIcon *icon;
gboolean visible;
GtkAllocation allocation;
hadj = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (container));
vadj = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (container));
gtk_widget_get_allocation (GTK_WIDGET (container), &allocation);
min_x = gtk_adjustment_get_value (hadj);
max_x = min_x + allocation.width;
min_y = gtk_adjustment_get_value (vadj);
max_y = min_y + allocation.height;
eel_canvas_c2w (EEL_CANVAS (container),
min_x, min_y, &min_x, &min_y);
eel_canvas_c2w (EEL_CANVAS (container),
max_x, max_y, &max_x, &max_y);
/* Do the iteration in reverse to get the render-order from top to
* bottom for the prioritized thumbnails.
*/
for (node = g_list_last (container->details->icons); node != NULL; node = node->prev)
{
icon = node->data;
if (icon_is_positioned (icon))
{
eel_canvas_item_get_bounds (EEL_CANVAS_ITEM (icon->item),
&x0,
&y0,
&x1,
&y1);
eel_canvas_item_i2w (EEL_CANVAS_ITEM (icon->item)->parent,
&x0,
&y0);
eel_canvas_item_i2w (EEL_CANVAS_ITEM (icon->item)->parent,
&x1,
&y1);
visible = y1 >= min_y && y0 <= max_y;
if (visible)
{
nautilus_canvas_item_set_is_visible (icon->item, TRUE);
nautilus_canvas_container_prioritize_thumbnailing (container,
icon);
}
else
{
nautilus_canvas_item_set_is_visible (icon->item, FALSE);
}
}
}
}
static void
handle_vadjustment_changed (GtkAdjustment *adjustment,
NautilusCanvasContainer *container)
{
nautilus_canvas_container_update_visible_icons (container);
}
static void
handle_hadjustment_changed (GtkAdjustment *adjustment,
NautilusCanvasContainer *container)
{
nautilus_canvas_container_update_visible_icons (container);
}
void
nautilus_canvas_container_update_icon (NautilusCanvasContainer *container,
NautilusCanvasIcon *icon)
{
NautilusCanvasContainerDetails *details;
guint icon_size;
guint min_image_size, max_image_size;
NautilusIconInfo *icon_info;
GdkPixbuf *pixbuf;
char *editable_text, *additional_text;
if (icon == NULL)
{
return;
}
details = container->details;
/* compute the maximum size based on the scale factor */
min_image_size = MINIMUM_IMAGE_SIZE * EEL_CANVAS (container)->pixels_per_unit;
max_image_size = MAX (MAXIMUM_IMAGE_SIZE * EEL_CANVAS (container)->pixels_per_unit, NAUTILUS_ICON_MAXIMUM_SIZE);
/* Get the appropriate images for the file. */
icon_get_size (container, icon, &icon_size);
icon_size = MAX (icon_size, min_image_size);
icon_size = MIN (icon_size, max_image_size);
DEBUG ("Icon size, getting for size %d", icon_size);
/* Get the icons. */
icon_info = nautilus_canvas_container_get_icon_images (container, icon->data, icon_size,
icon == details->drop_target);
pixbuf = nautilus_icon_info_get_pixbuf (icon_info);
g_object_unref (icon_info);
nautilus_canvas_container_get_icon_text (container,
icon->data,
&editable_text,
&additional_text,
FALSE);
eel_canvas_item_set (EEL_CANVAS_ITEM (icon->item),
"editable_text", editable_text,
"additional_text", additional_text,
"highlighted_for_drop", icon == details->drop_target,
NULL);
nautilus_canvas_item_set_image (icon->item, pixbuf);
/* Let the pixbufs go. */
g_object_unref (pixbuf);
g_free (editable_text);
g_free (additional_text);
}
static void
finish_adding_icon (NautilusCanvasContainer *container,
NautilusCanvasIcon *icon)
{
nautilus_canvas_container_update_icon (container, icon);
eel_canvas_item_show (EEL_CANVAS_ITEM (icon->item));
g_signal_connect_object (icon->item, "event",
G_CALLBACK (item_event_callback), container, 0);
g_signal_emit (container, signals[ICON_ADDED], 0, icon->data);
}
static gboolean
finish_adding_new_icons (NautilusCanvasContainer *container)
{
GList *p, *new_icons;
new_icons = container->details->new_icons;
container->details->new_icons = NULL;
container->details->is_populating_container = g_list_length (new_icons) ==
g_hash_table_size (container->details->icon_set);
/* Position most icons (not unpositioned manual-layout icons). */
new_icons = g_list_reverse (new_icons);
for (p = new_icons; p != NULL; p = p->next)
{
finish_adding_icon (container, p->data);
}
g_list_free (new_icons);
return TRUE;
}
/**
* nautilus_canvas_container_add:
* @container: A NautilusCanvasContainer
* @data: Icon data.
*
* Add icon to represent @data to container.
* Returns FALSE if there was already such an icon.
**/
gboolean
nautilus_canvas_container_add (NautilusCanvasContainer *container,
NautilusCanvasIconData *data)
{
NautilusCanvasContainerDetails *details;
NautilusCanvasIcon *icon;
EelCanvasItem *band, *item;
g_return_val_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container), FALSE);
g_return_val_if_fail (data != NULL, FALSE);
details = container->details;
if (g_hash_table_lookup (details->icon_set, data) != NULL)
{
return FALSE;
}
/* Create the new icon, including the canvas item. */
icon = g_new0 (NautilusCanvasIcon, 1);
icon->data = data;
icon->x = ICON_UNPOSITIONED_VALUE;
icon->y = ICON_UNPOSITIONED_VALUE;
/* Whether the saved icon position should only be used
* if the previous icon position is free. If the position
* is occupied, another position near the last one will
*/
icon->item = NAUTILUS_CANVAS_ITEM
(eel_canvas_item_new (EEL_CANVAS_GROUP (EEL_CANVAS (container)->root),
nautilus_canvas_item_get_type (),
"visible", FALSE,
NULL));
icon->item->user_data = icon;
/* Make sure the icon is under the selection_rectangle */
item = EEL_CANVAS_ITEM (icon->item);
band = NAUTILUS_CANVAS_CONTAINER (item->canvas)->details->rubberband_info.selection_rectangle;
if (band)
{
eel_canvas_item_send_behind (item, band);
}
/* Put it on both lists. */
details->icons = g_list_prepend (details->icons, icon);
details->new_icons = g_list_prepend (details->new_icons, icon);
g_hash_table_insert (details->icon_set, data, icon);
details->needs_resort = TRUE;
/* Run an idle function to add the icons. */
schedule_redo_layout (container);
return TRUE;
}
void
nautilus_canvas_container_layout_now (NautilusCanvasContainer *container)
{
container->details->in_layout_now = TRUE;
if (container->details->idle_id != 0)
{
unschedule_redo_layout (container);
redo_layout_internal (container);
}
/* Also need to make sure we're properly resized, for instance
* newly added files may trigger a change in the size allocation and
* thus toggle scrollbars on */
gtk_container_check_resize (GTK_CONTAINER (gtk_widget_get_parent (GTK_WIDGET (container))));
container->details->in_layout_now = FALSE;
}
/**
* nautilus_canvas_container_remove:
* @container: A NautilusCanvasContainer.
* @data: Icon data.
*
* Remove the icon with this data.
**/
gboolean
nautilus_canvas_container_remove (NautilusCanvasContainer *container,
NautilusCanvasIconData *data)
{
NautilusCanvasIcon *icon;
g_return_val_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container), FALSE);
g_return_val_if_fail (data != NULL, FALSE);
icon = g_hash_table_lookup (container->details->icon_set, data);
if (icon == NULL)
{
return FALSE;
}
icon_destroy (container, icon);
schedule_redo_layout (container);
g_signal_emit (container, signals[ICON_REMOVED], 0, icon);
return TRUE;
}
/**
* nautilus_canvas_container_request_update:
* @container: A NautilusCanvasContainer.
* @data: Icon data.
*
* Update the icon with this data.
**/
void
nautilus_canvas_container_request_update (NautilusCanvasContainer *container,
NautilusCanvasIconData *data)
{
NautilusCanvasIcon *icon;
g_return_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container));
g_return_if_fail (data != NULL);
icon = g_hash_table_lookup (container->details->icon_set, data);
if (icon != NULL)
{
nautilus_canvas_container_update_icon (container, icon);
container->details->needs_resort = TRUE;
schedule_redo_layout (container);
}
}
/* zooming */
NautilusCanvasZoomLevel
nautilus_canvas_container_get_zoom_level (NautilusCanvasContainer *container)
{
return container->details->zoom_level;
}
void
nautilus_canvas_container_set_zoom_level (NautilusCanvasContainer *container,
int new_level)
{
NautilusCanvasContainerDetails *details;
int pinned_level;
double pixels_per_unit;
details = container->details;
pinned_level = new_level;
if (pinned_level < NAUTILUS_CANVAS_ZOOM_LEVEL_SMALL)
{
pinned_level = NAUTILUS_CANVAS_ZOOM_LEVEL_SMALL;
}
else if (pinned_level > NAUTILUS_CANVAS_ZOOM_LEVEL_LARGER)
{
pinned_level = NAUTILUS_CANVAS_ZOOM_LEVEL_LARGER;
}
if (pinned_level == details->zoom_level)
{
return;
}
details->zoom_level = pinned_level;
pixels_per_unit = (double) nautilus_canvas_container_get_icon_size_for_zoom_level (pinned_level)
/ NAUTILUS_CANVAS_ICON_SIZE_STANDARD;
eel_canvas_set_pixels_per_unit (EEL_CANVAS (container), pixels_per_unit);
nautilus_canvas_container_request_update_all_internal (container, TRUE);
}
/**
* nautilus_canvas_container_request_update_all:
* For each icon, synchronizes the displayed information (image, text) with the
* information from the model.
*
* @container: An canvas container.
**/
void
nautilus_canvas_container_request_update_all (NautilusCanvasContainer *container)
{
nautilus_canvas_container_request_update_all_internal (container, FALSE);
}
/**
* nautilus_canvas_container_reveal:
* Change scroll position as necessary to reveal the specified item.
*/
void
nautilus_canvas_container_reveal (NautilusCanvasContainer *container,
NautilusCanvasIconData *data)
{
NautilusCanvasIcon *icon;
g_return_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container));
g_return_if_fail (data != NULL);
icon = g_hash_table_lookup (container->details->icon_set, data);
if (icon != NULL)
{
reveal_icon (container, icon);
}
}
/**
* nautilus_canvas_container_get_selection:
* @container: An canvas container.
*
* Get a list of the icons currently selected in @container.
*
* Return value: A GList of the programmer-specified data associated to each
* selected icon, or NULL if no canvas is selected. The caller is expected to
* free the list when it is not needed anymore.
**/
GList *
nautilus_canvas_container_get_selection (NautilusCanvasContainer *container)
{
g_return_val_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container), NULL);
if (container->details->selection_needs_resort)
{
sort_selection (container);
}
return g_list_copy (container->details->selection);
}
static GList *
nautilus_canvas_container_get_selected_icons (NautilusCanvasContainer *container)
{
GList *list, *p;
g_return_val_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container), NULL);
list = NULL;
for (p = container->details->icons; p != NULL; p = p->next)
{
NautilusCanvasIcon *icon;
icon = p->data;
if (icon->is_selected)
{
list = g_list_prepend (list, icon);
}
}
return g_list_reverse (list);
}
/**
* nautilus_canvas_container_invert_selection:
* @container: An canvas container.
*
* Inverts the selection in @container.
*
**/
void
nautilus_canvas_container_invert_selection (NautilusCanvasContainer *container)
{
GList *p;
g_return_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container));
for (p = container->details->icons; p != NULL; p = p->next)
{
NautilusCanvasIcon *icon;
icon = p->data;
icon_toggle_selected (container, icon);
}
g_signal_emit (container, signals[SELECTION_CHANGED], 0);
}
/* Returns an array of GdkPoints of locations of the icons. */
static GArray *
nautilus_canvas_container_get_icon_locations (NautilusCanvasContainer *container,
GList *icons)
{
GArray *result;
GList *node;
int index;
result = g_array_new (FALSE, TRUE, sizeof (GdkPoint));
result = g_array_set_size (result, g_list_length (icons));
for (index = 0, node = icons; node != NULL; index++, node = node->next)
{
g_array_index (result, GdkPoint, index).x =
((NautilusCanvasIcon *) node->data)->x;
g_array_index (result, GdkPoint, index).y =
((NautilusCanvasIcon *) node->data)->y;
}
return result;
}
/* Returns a GdkRectangle of the icon. The bounding box is adjusted with the
* pixels_per_unit already, so they are the final positions on the canvas */
GdkRectangle *
nautilus_canvas_container_get_icon_bounding_box (NautilusCanvasContainer *container,
NautilusCanvasIconData *data)
{
NautilusCanvasIcon *icon;
int x1, x2, y1, y2;
GdkRectangle *bounding_box;
g_return_val_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container), NULL);
g_return_val_if_fail (data != NULL, NULL);
icon = g_hash_table_lookup (container->details->icon_set, data);
icon_get_bounding_box (icon,
&x1, &y1, &x2, &y2,
BOUNDS_USAGE_FOR_DISPLAY);
bounding_box = g_malloc0 (sizeof (GdkRectangle));
bounding_box->x = x1 * EEL_CANVAS (container)->pixels_per_unit;
bounding_box->width = (x2 - x1) * EEL_CANVAS (container)->pixels_per_unit;
bounding_box->y = y1 * EEL_CANVAS (container)->pixels_per_unit;
bounding_box->height = (y2 - y1) * EEL_CANVAS (container)->pixels_per_unit;
return bounding_box;
}
/**
* nautilus_canvas_container_get_selected_icon_locations:
* @container: An canvas container widget.
*
* Returns an array of GdkPoints of locations of the selected icons.
**/
GArray *
nautilus_canvas_container_get_selected_icon_locations (NautilusCanvasContainer *container)
{
GArray *result;
GList *icons;
g_return_val_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container), NULL);
icons = nautilus_canvas_container_get_selected_icons (container);
result = nautilus_canvas_container_get_icon_locations (container, icons);
g_list_free (icons);
return result;
}
/**
* nautilus_canvas_container_select_all:
* @container: An canvas container widget.
*
* Select all the icons in @container at once.
**/
void
nautilus_canvas_container_select_all (NautilusCanvasContainer *container)
{
gboolean selection_changed;
GList *p;
NautilusCanvasIcon *icon;
g_return_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container));
selection_changed = FALSE;
for (p = container->details->icons; p != NULL; p = p->next)
{
icon = p->data;
selection_changed |= icon_set_selected (container, icon, TRUE);
}
if (selection_changed)
{
g_signal_emit (container,
signals[SELECTION_CHANGED], 0);
}
}
/**
* nautilus_canvas_container_select_first:
* @container: An canvas container widget.
*
* Select the first icon in @container.
**/
void
nautilus_canvas_container_select_first (NautilusCanvasContainer *container)
{
gboolean selection_changed;
NautilusCanvasIcon *icon;
g_return_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container));
selection_changed = FALSE;
if (container->details->needs_resort)
{
resort (container);
container->details->needs_resort = FALSE;
}
icon = g_list_nth_data (container->details->icons, 0);
if (icon)
{
selection_changed |= icon_set_selected (container, icon, TRUE);
}
if (selection_changed)
{
g_signal_emit (container,
signals[SELECTION_CHANGED], 0);
}
}
/**
* nautilus_canvas_container_set_selection:
* @container: An canvas container widget.
* @selection: A list of NautilusCanvasIconData *.
*
* Set the selection to exactly the icons in @container which have
* programmer data matching one of the items in @selection.
**/
void
nautilus_canvas_container_set_selection (NautilusCanvasContainer *container,
GList *selection)
{
gboolean selection_changed;
GHashTable *hash;
GList *p;
gboolean res;
NautilusCanvasIcon *icon, *selected_icon;
g_return_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container));
selection_changed = FALSE;
selected_icon = NULL;
hash = g_hash_table_new (NULL, NULL);
for (p = selection; p != NULL; p = p->next)
{
g_hash_table_insert (hash, p->data, p->data);
}
for (p = container->details->icons; p != NULL; p = p->next)
{
icon = p->data;
res = icon_set_selected
(container, icon,
g_hash_table_lookup (hash, icon->data) != NULL);
selection_changed |= res;
if (res)
{
selected_icon = icon;
}
}
g_hash_table_destroy (hash);
if (selection_changed)
{
/* if only one item has been selected, use it as range
* selection base (cf. handle_canvas_button_press) */
if (g_list_length (selection) == 1)
{
container->details->range_selection_base_icon = selected_icon;
}
g_signal_emit (container,
signals[SELECTION_CHANGED], 0);
}
}
/**
* nautilus_canvas_container_select_list_unselect_others.
* @container: An canvas container widget.
* @selection: A list of NautilusCanvasIcon *.
*
* Set the selection to exactly the icons in @selection.
**/
void
nautilus_canvas_container_select_list_unselect_others (NautilusCanvasContainer *container,
GList *selection)
{
gboolean selection_changed;
GHashTable *hash;
GList *p;
NautilusCanvasIcon *icon;
g_return_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container));
selection_changed = FALSE;
hash = g_hash_table_new (NULL, NULL);
for (p = selection; p != NULL; p = p->next)
{
g_hash_table_insert (hash, p->data, p->data);
}
for (p = container->details->icons; p != NULL; p = p->next)
{
icon = p->data;
selection_changed |= icon_set_selected
(container, icon,
g_hash_table_lookup (hash, icon) != NULL);
}
g_hash_table_destroy (hash);
if (selection_changed)
{
g_signal_emit (container,
signals[SELECTION_CHANGED], 0);
}
}
/**
* nautilus_canvas_container_unselect_all:
* @container: An canvas container widget.
*
* Deselect all the icons in @container.
**/
void
nautilus_canvas_container_unselect_all (NautilusCanvasContainer *container)
{
if (unselect_all (container))
{
g_signal_emit (container,
signals[SELECTION_CHANGED], 0);
}
}
/**
* nautilus_canvas_container_get_icon_by_uri:
* @container: An canvas container widget.
* @uri: The uri of an canvas to find.
*
* Locate an icon, given the URI. The URI must match exactly.
* Later we may have to have some way of figuring out if the
* URI specifies the same object that does not require an exact match.
**/
NautilusCanvasIcon *
nautilus_canvas_container_get_icon_by_uri (NautilusCanvasContainer *container,
const char *uri)
{
NautilusCanvasContainerDetails *details;
GList *p;
/* Eventually, we must avoid searching the entire canvas list,
* but it's OK for now.
* A hash table mapping uri to canvas is one possibility.
*/
details = container->details;
for (p = details->icons; p != NULL; p = p->next)
{
NautilusCanvasIcon *icon;
char *icon_uri;
gboolean is_match;
icon = p->data;
icon_uri = nautilus_canvas_container_get_icon_uri
(container, icon);
is_match = strcmp (uri, icon_uri) == 0;
g_free (icon_uri);
if (is_match)
{
return icon;
}
}
return NULL;
}
static NautilusCanvasIcon *
get_nth_selected_icon (NautilusCanvasContainer *container,
int index)
{
GList *p;
NautilusCanvasIcon *icon;
int selection_count;
g_assert (index > 0);
/* Find the nth selected icon. */
selection_count = 0;
for (p = container->details->icons; p != NULL; p = p->next)
{
icon = p->data;
if (icon->is_selected)
{
if (++selection_count == index)
{
return icon;
}
}
}
return NULL;
}
static NautilusCanvasIcon *
get_first_selected_icon (NautilusCanvasContainer *container)
{
return get_nth_selected_icon (container, 1);
}
static gboolean
has_multiple_selection (NautilusCanvasContainer *container)
{
return get_nth_selected_icon (container, 2) != NULL;
}
static gboolean
all_selected (NautilusCanvasContainer *container)
{
GList *p;
NautilusCanvasIcon *icon;
for (p = container->details->icons; p != NULL; p = p->next)
{
icon = p->data;
if (!icon->is_selected)
{
return FALSE;
}
}
return TRUE;
}
static gboolean
has_selection (NautilusCanvasContainer *container)
{
return get_nth_selected_icon (container, 1) != NULL;
}
char *
nautilus_canvas_container_get_icon_uri (NautilusCanvasContainer *container,
NautilusCanvasIcon *icon)
{
char *uri;
uri = NULL;
g_signal_emit (container,
signals[GET_ICON_URI], 0,
icon->data,
&uri);
return uri;
}
char *
nautilus_canvas_container_get_icon_activation_uri (NautilusCanvasContainer *container,
NautilusCanvasIcon *icon)
{
char *uri;
uri = NULL;
g_signal_emit (container,
signals[GET_ICON_ACTIVATION_URI], 0,
icon->data,
&uri);
return uri;
}
char *
nautilus_canvas_container_get_icon_drop_target_uri (NautilusCanvasContainer *container,
NautilusCanvasIcon *icon)
{
char *uri;
uri = NULL;
g_signal_emit (container,
signals[GET_ICON_DROP_TARGET_URI], 0,
icon->data,
&uri);
return uri;
}
/* Re-sort, switching to automatic layout if it was in manual layout. */
void
nautilus_canvas_container_sort (NautilusCanvasContainer *container)
{
container->details->needs_resort = TRUE;
redo_layout (container);
}
void
nautilus_canvas_container_set_single_click_mode (NautilusCanvasContainer *container,
gboolean single_click_mode)
{
g_return_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container));
container->details->single_click_mode = single_click_mode;
}
/* handle theme changes */
void
nautilus_canvas_container_set_font (NautilusCanvasContainer *container,
const char *font)
{
g_return_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container));
if (g_strcmp0 (container->details->font, font) == 0)
{
return;
}
g_free (container->details->font);
container->details->font = g_strdup (font);
nautilus_canvas_container_request_update_all_internal (container, TRUE);
gtk_widget_queue_draw (GTK_WIDGET (container));
}
/**
* nautilus_canvas_container_get_icon_description
* @container: An canvas container widget.
* @data: Icon data
*
* Gets the description for the icon. This function may return NULL.
**/
char *
nautilus_canvas_container_get_icon_description (NautilusCanvasContainer *container,
NautilusCanvasIconData *data)
{
NautilusCanvasContainerClass *klass;
klass = NAUTILUS_CANVAS_CONTAINER_GET_CLASS (container);
if (klass->get_icon_description)
{
return klass->get_icon_description (container, data);
}
else
{
return NULL;
}
}
/**
* nautilus_canvas_container_set_highlighted_for_clipboard
* @container: An canvas container widget.
* @data: Canvas Data associated with all icons that should be highlighted.
* Others will be unhighlighted.
**/
void
nautilus_canvas_container_set_highlighted_for_clipboard (NautilusCanvasContainer *container,
GList *clipboard_canvas_data)
{
GList *l;
NautilusCanvasIcon *icon;
gboolean highlighted_for_clipboard;
g_return_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container));
for (l = container->details->icons; l != NULL; l = l->next)
{
icon = l->data;
highlighted_for_clipboard = (g_list_find (clipboard_canvas_data, icon->data) != NULL);
eel_canvas_item_set (EEL_CANVAS_ITEM (icon->item),
"highlighted-for-clipboard", highlighted_for_clipboard,
NULL);
}
}
/* NautilusCanvasContainerAccessible */
typedef struct
{
EelCanvasAccessible parent;
NautilusCanvasContainerAccessiblePrivate *priv;
} NautilusCanvasContainerAccessible;
typedef EelCanvasAccessibleClass NautilusCanvasContainerAccessibleClass;
#define GET_ACCESSIBLE_PRIV(o) ((NautilusCanvasContainerAccessible *) o)->priv
/* AtkAction interface */
static gboolean
nautilus_canvas_container_accessible_do_action (AtkAction *accessible,
int i)
{
GtkWidget *widget;
NautilusCanvasContainer *container;
GList *selection;
g_return_val_if_fail (i < LAST_ACTION, FALSE);
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
if (!widget)
{
return FALSE;
}
container = NAUTILUS_CANVAS_CONTAINER (widget);
switch (i)
{
case ACTION_ACTIVATE:
{
selection = nautilus_canvas_container_get_selection (container);
if (selection)
{
g_signal_emit_by_name (container, "activate", selection);
g_list_free (selection);
}
}
break;
case ACTION_MENU:
{
handle_popups (container, NULL, "context_click_background");
}
break;
default:
{
g_warning ("Invalid action passed to NautilusCanvasContainerAccessible::do_action");
return FALSE;
}
break;
}
return TRUE;
}
static int
nautilus_canvas_container_accessible_get_n_actions (AtkAction *accessible)
{
return LAST_ACTION;
}
static const char *
nautilus_canvas_container_accessible_action_get_description (AtkAction *accessible,
int i)
{
NautilusCanvasContainerAccessiblePrivate *priv;
g_assert (i < LAST_ACTION);
priv = GET_ACCESSIBLE_PRIV (accessible);
if (priv->action_descriptions[i])
{
return priv->action_descriptions[i];
}
else
{
return nautilus_canvas_container_accessible_action_descriptions[i];
}
}
static const char *
nautilus_canvas_container_accessible_action_get_name (AtkAction *accessible,
int i)
{
g_assert (i < LAST_ACTION);
return nautilus_canvas_container_accessible_action_names[i];
}
static const char *
nautilus_canvas_container_accessible_action_get_keybinding (AtkAction *accessible,
int i)
{
g_assert (i < LAST_ACTION);
return NULL;
}
static gboolean
nautilus_canvas_container_accessible_action_set_description (AtkAction *accessible,
int i,
const char *description)
{
NautilusCanvasContainerAccessiblePrivate *priv;
g_assert (i < LAST_ACTION);
priv = GET_ACCESSIBLE_PRIV (accessible);
if (priv->action_descriptions[i])
{
g_free (priv->action_descriptions[i]);
}
priv->action_descriptions[i] = g_strdup (description);
return FALSE;
}
static void
nautilus_canvas_container_accessible_action_interface_init (AtkActionIface *iface)
{
iface->do_action = nautilus_canvas_container_accessible_do_action;
iface->get_n_actions = nautilus_canvas_container_accessible_get_n_actions;
iface->get_description = nautilus_canvas_container_accessible_action_get_description;
iface->get_name = nautilus_canvas_container_accessible_action_get_name;
iface->get_keybinding = nautilus_canvas_container_accessible_action_get_keybinding;
iface->set_description = nautilus_canvas_container_accessible_action_set_description;
}
/* AtkSelection interface */
static void
nautilus_canvas_container_accessible_update_selection (AtkObject *accessible)
{
NautilusCanvasContainer *container;
NautilusCanvasContainerAccessiblePrivate *priv;
container = NAUTILUS_CANVAS_CONTAINER (gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible)));
priv = GET_ACCESSIBLE_PRIV (accessible);
if (priv->selection)
{
g_list_free (priv->selection);
priv->selection = NULL;
}
priv->selection = nautilus_canvas_container_get_selected_icons (container);
}
static void
nautilus_canvas_container_accessible_selection_changed_cb (NautilusCanvasContainer *container,
gpointer data)
{
g_signal_emit_by_name (data, "selection-changed");
}
static void
nautilus_canvas_container_accessible_icon_added_cb (NautilusCanvasContainer *container,
NautilusCanvasIconData *icon_data,
gpointer data)
{
NautilusCanvasIcon *icon;
AtkObject *atk_parent;
AtkObject *atk_child;
/* We don't want to emit children_changed signals during any type of load. */
if (!container->details->in_layout_now || container->details->is_populating_container)
return;
icon = g_hash_table_lookup (container->details->icon_set, icon_data);
if (icon)
{
atk_parent = ATK_OBJECT (data);
atk_child = atk_gobject_accessible_for_object
(G_OBJECT (icon->item));
g_signal_emit_by_name (atk_parent, "children-changed::add",
icon->position, atk_child, NULL);
}
}
static void
nautilus_canvas_container_accessible_icon_removed_cb (NautilusCanvasContainer *container,
NautilusCanvasIconData *icon_data,
gpointer data)
{
NautilusCanvasIcon *icon;
AtkObject *atk_parent;
AtkObject *atk_child;
icon = g_hash_table_lookup (container->details->icon_set, icon_data);
if (icon)
{
atk_parent = ATK_OBJECT (data);
atk_child = atk_gobject_accessible_for_object
(G_OBJECT (icon->item));
g_signal_emit_by_name (atk_parent, "children-changed::remove",
icon->position, atk_child, NULL);
}
}
static void
nautilus_canvas_container_accessible_cleared_cb (NautilusCanvasContainer *container,
gpointer data)
{
g_signal_emit_by_name (data, "children-changed", 0, NULL, NULL);
}
static gboolean
nautilus_canvas_container_accessible_add_selection (AtkSelection *accessible,
int i)
{
GtkWidget *widget;
NautilusCanvasContainer *container;
GList *l;
GList *selection;
NautilusCanvasIcon *icon;
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
if (!widget)
{
return FALSE;
}
container = NAUTILUS_CANVAS_CONTAINER (widget);
l = g_list_nth (container->details->icons, i);
if (l)
{
icon = l->data;
selection = nautilus_canvas_container_get_selection (container);
selection = g_list_prepend (selection,
icon->data);
nautilus_canvas_container_set_selection (container, selection);
g_list_free (selection);
return TRUE;
}
return FALSE;
}
static gboolean
nautilus_canvas_container_accessible_clear_selection (AtkSelection *accessible)
{
GtkWidget *widget;
NautilusCanvasContainer *container;
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
if (!widget)
{
return FALSE;
}
container = NAUTILUS_CANVAS_CONTAINER (widget);
nautilus_canvas_container_unselect_all (container);
return TRUE;
}
static AtkObject *
nautilus_canvas_container_accessible_ref_selection (AtkSelection *accessible,
int i)
{
NautilusCanvasContainerAccessiblePrivate *priv;
AtkObject *atk_object;
GList *item;
NautilusCanvasIcon *icon;
nautilus_canvas_container_accessible_update_selection (ATK_OBJECT (accessible));
priv = GET_ACCESSIBLE_PRIV (accessible);
item = (g_list_nth (priv->selection, i));
if (item)
{
icon = item->data;
atk_object = atk_gobject_accessible_for_object (G_OBJECT (icon->item));
if (atk_object)
{
g_object_ref (atk_object);
}
return atk_object;
}
else
{
return NULL;
}
}
static int
nautilus_canvas_container_accessible_get_selection_count (AtkSelection *accessible)
{
NautilusCanvasContainerAccessiblePrivate *priv;
int count;
priv = GET_ACCESSIBLE_PRIV (accessible);
nautilus_canvas_container_accessible_update_selection (ATK_OBJECT (accessible));
count = g_list_length (priv->selection);
return count;
}
static gboolean
nautilus_canvas_container_accessible_is_child_selected (AtkSelection *accessible,
int i)
{
NautilusCanvasContainer *container;
GList *l;
NautilusCanvasIcon *icon;
GtkWidget *widget;
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
if (!widget)
{
return FALSE;
}
container = NAUTILUS_CANVAS_CONTAINER (widget);
l = g_list_nth (container->details->icons, i);
if (l)
{
icon = l->data;
return icon->is_selected;
}
return FALSE;
}
static gboolean
nautilus_canvas_container_accessible_remove_selection (AtkSelection *accessible,
int i)
{
NautilusCanvasContainerAccessiblePrivate *priv;
NautilusCanvasContainer *container;
GList *l;
GList *selection;
NautilusCanvasIcon *icon;
GtkWidget *widget;
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
if (!widget)
{
return FALSE;
}
container = NAUTILUS_CANVAS_CONTAINER (widget);
nautilus_canvas_container_accessible_update_selection (ATK_OBJECT (accessible));
priv = GET_ACCESSIBLE_PRIV (accessible);
l = g_list_nth (priv->selection, i);
if (l)
{
icon = l->data;
selection = nautilus_canvas_container_get_selection (container);
selection = g_list_remove (selection, icon->data);
nautilus_canvas_container_set_selection (container, selection);
g_list_free (selection);
return TRUE;
}
return FALSE;
}
static gboolean
nautilus_canvas_container_accessible_select_all_selection (AtkSelection *accessible)
{
NautilusCanvasContainer *container;
GtkWidget *widget;
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
if (!widget)
{
return FALSE;
}
container = NAUTILUS_CANVAS_CONTAINER (widget);
nautilus_canvas_container_select_all (container);
return TRUE;
}
void
nautilus_canvas_container_widget_to_file_operation_position (NautilusCanvasContainer *container,
GdkPoint *position)
{
double x, y;
g_return_if_fail (position != NULL);
x = position->x;
y = position->y;
eel_canvas_window_to_world (EEL_CANVAS (container), x, y, &x, &y);
position->x = (int) x;
position->y = (int) y;
/* ensure that we end up in the middle of the icon */
position->x -= nautilus_canvas_container_get_icon_size_for_zoom_level (container->details->zoom_level) / 2;
position->y -= nautilus_canvas_container_get_icon_size_for_zoom_level (container->details->zoom_level) / 2;
}
static void
nautilus_canvas_container_accessible_selection_interface_init (AtkSelectionIface *iface)
{
iface->add_selection = nautilus_canvas_container_accessible_add_selection;
iface->clear_selection = nautilus_canvas_container_accessible_clear_selection;
iface->ref_selection = nautilus_canvas_container_accessible_ref_selection;
iface->get_selection_count = nautilus_canvas_container_accessible_get_selection_count;
iface->is_child_selected = nautilus_canvas_container_accessible_is_child_selected;
iface->remove_selection = nautilus_canvas_container_accessible_remove_selection;
iface->select_all_selection = nautilus_canvas_container_accessible_select_all_selection;
}
static gint
nautilus_canvas_container_accessible_get_n_children (AtkObject *accessible)
{
NautilusCanvasContainer *container;
GtkWidget *widget;
gint i;
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
if (!widget)
{
return FALSE;
}
container = NAUTILUS_CANVAS_CONTAINER (widget);
i = g_hash_table_size (container->details->icon_set);
return i;
}
static AtkObject *
nautilus_canvas_container_accessible_ref_child (AtkObject *accessible,
int i)
{
AtkObject *atk_object;
NautilusCanvasContainer *container;
GList *item;
NautilusCanvasIcon *icon;
GtkWidget *widget;
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
if (!widget)
{
return NULL;
}
container = NAUTILUS_CANVAS_CONTAINER (widget);
item = (g_list_nth (container->details->icons, i));
if (item)
{
icon = item->data;
atk_object = atk_gobject_accessible_for_object (G_OBJECT (icon->item));
g_object_ref (atk_object);
return atk_object;
}
return NULL;
}
G_DEFINE_TYPE_WITH_CODE (NautilusCanvasContainerAccessible, nautilus_canvas_container_accessible,
eel_canvas_accessible_get_type (),
G_IMPLEMENT_INTERFACE (ATK_TYPE_ACTION, nautilus_canvas_container_accessible_action_interface_init)
G_IMPLEMENT_INTERFACE (ATK_TYPE_SELECTION, nautilus_canvas_container_accessible_selection_interface_init))
static void
nautilus_canvas_container_accessible_initialize (AtkObject *accessible,
gpointer data)
{
NautilusCanvasContainer *container;
if (ATK_OBJECT_CLASS (nautilus_canvas_container_accessible_parent_class)->initialize)
{
ATK_OBJECT_CLASS (nautilus_canvas_container_accessible_parent_class)->initialize (accessible, data);
}
if (GTK_IS_ACCESSIBLE (accessible))
{
nautilus_canvas_container_accessible_update_selection
(ATK_OBJECT (accessible));
container = NAUTILUS_CANVAS_CONTAINER (gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible)));
g_signal_connect (container, "selection-changed",
G_CALLBACK (nautilus_canvas_container_accessible_selection_changed_cb),
accessible);
g_signal_connect (container, "icon-added",
G_CALLBACK (nautilus_canvas_container_accessible_icon_added_cb),
accessible);
g_signal_connect (container, "icon-removed",
G_CALLBACK (nautilus_canvas_container_accessible_icon_removed_cb),
accessible);
g_signal_connect (container, "cleared",
G_CALLBACK (nautilus_canvas_container_accessible_cleared_cb),
accessible);
}
}
static void
nautilus_canvas_container_accessible_finalize (GObject *object)
{
NautilusCanvasContainerAccessiblePrivate *priv;
int i;
priv = GET_ACCESSIBLE_PRIV (object);
if (priv->selection)
{
g_list_free (priv->selection);
}
for (i = 0; i < LAST_ACTION; i++)
{
if (priv->action_descriptions[i])
{
g_free (priv->action_descriptions[i]);
}
}
G_OBJECT_CLASS (nautilus_canvas_container_accessible_parent_class)->finalize (object);
}
static void
nautilus_canvas_container_accessible_init (NautilusCanvasContainerAccessible *self)
{
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, nautilus_canvas_container_accessible_get_type (),
NautilusCanvasContainerAccessiblePrivate);
}
static void
nautilus_canvas_container_accessible_class_init (NautilusCanvasContainerAccessibleClass *klass)
{
AtkObjectClass *atk_class = ATK_OBJECT_CLASS (klass);
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
gobject_class->finalize = nautilus_canvas_container_accessible_finalize;
atk_class->get_n_children = nautilus_canvas_container_accessible_get_n_children;
atk_class->ref_child = nautilus_canvas_container_accessible_ref_child;
atk_class->initialize = nautilus_canvas_container_accessible_initialize;
g_type_class_add_private (klass, sizeof (NautilusCanvasContainerAccessiblePrivate));
}
gboolean
nautilus_canvas_container_is_layout_rtl (NautilusCanvasContainer *container)
{
g_return_val_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container), 0);
return (gtk_widget_get_direction (GTK_WIDGET (container)) == GTK_TEXT_DIR_RTL);
}
int
nautilus_canvas_container_get_max_layout_lines_for_pango (NautilusCanvasContainer *container)
{
int limit;
limit = text_ellipsis_limits[container->details->zoom_level];
if (limit <= 0)
{
return G_MININT;
}
return -limit;
}
int
nautilus_canvas_container_get_max_layout_lines (NautilusCanvasContainer *container)
{
int limit;
limit = text_ellipsis_limits[container->details->zoom_level];
if (limit <= 0)
{
return G_MAXINT;
}
return limit;
}
|