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
|
#ifdef HAVE_CONFIG_H
# include "elementary_config.h"
#endif
#include <Elementary.h>
#include "elm_priv.h"
#ifdef HAVE_MMAN_H
# include <sys/mman.h>
#endif
//#define DEBUGON 1
#ifdef DEBUGON
# define cnp_debug(fmt, args...) fprintf(stderr, __FILE__":%s : " fmt , __FUNCTION__, ##args)
#else
# define cnp_debug(x...) do { } while (0)
#endif
// common stuff
enum
{
CNP_ATOM_TARGETS = 0,
CNP_ATOM_ATOM,
CNP_ATOM_LISTING_ATOMS = CNP_ATOM_ATOM,
CNP_ATOM_text_uri,
CNP_ATOM_text_urilist,
CNP_ATOM_text_x_vcard,
CNP_ATOM_image_png,
CNP_ATOM_image_jpeg,
CNP_ATOM_image_bmp,
CNP_ATOM_image_gif,
CNP_ATOM_image_tiff,
CNP_ATOM_image_svg,
CNP_ATOM_image_xpm,
CNP_ATOM_image_tga,
CNP_ATOM_image_ppm,
CNP_ATOM_XELM,
// CNP_ATOM_text_html_utf8,
// CNP_ATOM_text_html,
CNP_ATOM_UTF8STRING,
CNP_ATOM_STRING,
CNP_ATOM_COMPOUND_TEXT,
CNP_ATOM_TEXT,
CNP_ATOM_text_plain_utf8,
CNP_ATOM_text_plain,
CNP_N_ATOMS,
};
typedef struct _Tmp_Info Tmp_Info;
typedef struct _Saved_Type Saved_Type;
typedef struct _Cnp_Escape Cnp_Escape;
typedef struct _Dropable Dropable;
typedef struct _Dropable_Cbs Dropable_Cbs;
static Eina_Bool doaccept = EINA_FALSE;
struct _Tmp_Info
{
char *filename;
void *map;
int fd;
int len;
};
struct _Saved_Type
{
const char **types;
char *imgfile;
int ntypes;
int x, y;
Eina_Bool textreq: 1;
};
struct _Cnp_Escape
{
const char *escape;
const char *value;
};
struct _Dropable_Cbs
{
EINA_INLIST;
Elm_Sel_Format types;
Elm_Drag_State entercb;
Elm_Drag_State leavecb;
Elm_Drag_Pos poscb;
Elm_Drop_Cb dropcb;
void *enterdata;
void *leavedata;
void *posdata;
void *dropdata;
};
struct _Dropable
{
Evas_Object *obj;
/* FIXME: Cache window */
Eina_Inlist *cbs_list; /* List of Dropable_Cbs * */
struct {
Evas_Coord x, y;
Eina_Bool in : 1;
} last;
};
struct _Item_Container_Drop_Info
{ /* Info kept for containers to support drop */
Evas_Object *obj;
Elm_Xy_Item_Get_Cb itemgetcb;
Elm_Drop_Item_Container_Cb dropcb;
Elm_Drag_Item_Container_Pos poscb;
};
typedef struct _Item_Container_Drop_Info Item_Container_Drop_Info;
struct _Anim_Icon
{
int start_x;
int start_y;
int start_w;
int start_h;
Evas_Object *o;
};
typedef struct _Anim_Icon Anim_Icon;
struct _Item_Container_Drag_Info
{ /* Info kept for containers to support drag */
Evas_Object *obj;
Ecore_Timer *tm; /* When this expires, start drag */
double anim_tm; /* Time period to set tm */
double tm_to_drag; /* Time period to set tm */
Elm_Xy_Item_Get_Cb itemgetcb;
Elm_Item_Container_Data_Get_Cb data_get;
Evas_Coord x_down; /* Mouse down x cord when drag starts */
Evas_Coord y_down; /* Mouse down y cord when drag starts */
/* Some extra information needed to impl default anim */
Evas *e;
Eina_List *icons; /* List of icons to animate (Anim_Icon) */
int final_icon_w; /* We need the w and h of the final icon for the animation */
int final_icon_h;
Ecore_Animator *ea;
Elm_Drag_User_Info user_info;
};
typedef struct _Item_Container_Drag_Info Item_Container_Drag_Info;
static int _elm_cnp_init_count = 0;
/* Stringshared, so I can just compare pointers later */
static const char *text_uri;
/* Data for DND in progress */
static Saved_Type savedtypes = { NULL, NULL, 0, 0, 0, EINA_FALSE };
/* Drag & Drop functions */
/* FIXME: Way too many globals */
static Eina_List *drops = NULL;
static Evas_Object *dragwin = NULL;
static int dragwin_x_start, dragwin_y_start;
static int dragwin_x_end, dragwin_y_end;
static int _dragx = 0, _dragy = 0;
static Ecore_Event_Handler *handler_pos = NULL;
static Ecore_Event_Handler *handler_drop = NULL;
static Ecore_Event_Handler *handler_enter = NULL;
static Ecore_Event_Handler *handler_status = NULL;
static Ecore_Event_Handler *handler_leave = NULL;
static Ecore_Event_Handler *handler_up = NULL;
/* TODO BUG: should NEVER have these as globals! They should be per context (window). */
static Elm_Drag_Pos dragposcb = NULL;
static Elm_Drag_Accept dragacceptcb = NULL;
static Elm_Drag_State dragdonecb = NULL;
static void *dragposdata = NULL;
static void *dragacceptdata = NULL;
static void *dragdonedata = NULL;
static Evas_Object *dragwidget = NULL;
static Elm_Xdnd_Action dragaction = ELM_XDND_ACTION_UNKNOWN;
static Eina_List *cont_drop_tg = NULL; /* List of Item_Container_Drop_Info */
static Eina_List *cont_drag_tg = NULL; /* List of Item_Container_Drag_Info */
static void _cont_obj_mouse_up( void *data, Evas *e, Evas_Object *obj, void *event_info);
static void _cont_obj_mouse_move( void *data, Evas *e, Evas_Object *obj, void *event_info);
static void _all_drop_targets_cbs_del(void *data, Evas *e, Evas_Object *obj, void *info);
static Eina_Bool
_drag_cancel_animate(void *data __UNUSED__, double pos)
{ /* Animation to "move back" drag-window */
if (pos >= 0.99)
{
evas_object_del(data);
return ECORE_CALLBACK_CANCEL;
}
else
{
int x, y;
x = dragwin_x_end - (pos * (dragwin_x_end - dragwin_x_start));
y = dragwin_y_end - (pos * (dragwin_y_end - dragwin_y_start));
evas_object_move(data, x, y);
}
return ECORE_CALLBACK_RENEW;
}
static void
_all_drop_targets_cbs_del(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *info __UNUSED__)
{
Dropable *dropable = NULL;
eo_do(obj, eo_base_data_get("__elm_dropable", (void **)&dropable));
if (dropable)
{
Eina_Inlist *itr;
Dropable_Cbs *cbs;
EINA_INLIST_FOREACH_SAFE(dropable->cbs_list, itr, cbs)
{
elm_drop_target_del(obj, cbs->types,
cbs->entercb, cbs->enterdata, cbs->leavecb, cbs->leavedata,
cbs->poscb, cbs->posdata, cbs->dropcb, cbs->dropdata);
}
}
}
#ifdef HAVE_ELEMENTARY_X
static Tmp_Info *_tempfile_new (int size);
static int _tmpinfo_free (Tmp_Info *tmp);
static Eina_Bool _pasteimage_append (char *file, Evas_Object *entry);
#endif
// x11 specific stuff
////////////////////////////////////////////////////////////////////////////
#ifdef HAVE_ELEMENTARY_X
#define ARRAYINIT(foo) [foo] =
typedef struct _X11_Cnp_Selection X11_Cnp_Selection;
typedef struct _X11_Cnp_Atom X11_Cnp_Atom;
typedef Eina_Bool (*X11_Converter_Fn_Cb) (char *target, void *data, int size, void **data_ret, int *size_ret, Ecore_X_Atom *ttype, int *typesize);
typedef int (*X11_Response_Handler_Cb) (X11_Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *);
typedef int (*X11_Notify_Handler_Cb) (X11_Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *);
struct _X11_Cnp_Selection
{
const char *debug;
Evas_Object *widget;
char *selbuf;
Evas_Object *requestwidget;
void *udata;
Elm_Sel_Format requestformat;
Elm_Drop_Cb datacb;
Eina_Bool (*set) (Ecore_X_Window, const void *data, int size);
Eina_Bool (*clear) (void);
void (*request) (Ecore_X_Window, const char *target);
Elm_Selection_Loss_Cb loss_cb;
void *loss_data;
Elm_Sel_Format format;
Ecore_X_Selection ecore_sel;
Ecore_X_Window xwin;
Elm_Xdnd_Action action;
Eina_Bool active : 1;
};
struct _X11_Cnp_Atom
{
const char *name;
Elm_Sel_Format formats;
/* Called by ecore to do conversion */
X11_Converter_Fn_Cb converter;
X11_Response_Handler_Cb response;
X11_Notify_Handler_Cb notify;
/* Atom */
Ecore_X_Atom atom;
};
static void _x11_sel_obj_del (void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__);
static void _x11_sel_obj_del2 (void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__);
static Eina_Bool _x11_selection_clear (void *udata __UNUSED__, int type, void *event);
static Eina_Bool _x11_selection_notify (void *udata __UNUSED__, int type, void *event);
static Eina_Bool _x11_targets_converter (char *target, void *data, int size, void **data_ret, int *size_ret, Ecore_X_Atom *ttype, int *typesize);
static Eina_Bool _x11_text_converter (char *target, void *data, int size, void **data_ret, int *size_ret, Ecore_X_Atom *ttype, int *typesize);
static Eina_Bool _x11_general_converter (char *target, void *data, int size, void **data_ret, int *size_ret, Ecore_X_Atom *ttype, int *typesize);
static Eina_Bool _x11_image_converter (char *target, void *data, int size, void **data_ret, int *size_ret, Ecore_X_Atom *ttype, int *typesize);
static Eina_Bool _x11_vcard_send (char *target, void *data, int size, void **data_ret, int *size_ret, Ecore_X_Atom *ttype, int *typesize);
static Eina_Bool _x11_is_uri_type_data (X11_Cnp_Selection *sel __UNUSED__, Ecore_X_Event_Selection_Notify *notify);
static int _x11_response_handler_targets (X11_Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *);
static int _x11_notify_handler_targets (X11_Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify);
static int _x11_notify_handler_text (X11_Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify);
static int _x11_notify_handler_image (X11_Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify);
static int _x11_notify_handler_uri (X11_Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify);
//static int _x11_notify_handler_html (X11_Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify);
static int _x11_vcard_receive (X11_Cnp_Selection *sed, Ecore_X_Event_Selection_Notify *notify);
static Eina_Bool _x11_dnd_enter (void *data __UNUSED__, int etype __UNUSED__, void *ev);
static Eina_Bool _x11_dnd_drop (void *data __UNUSED__, int etype __UNUSED__, void *ev);
static Eina_Bool _x11_dnd_position (void *data __UNUSED__, int etype __UNUSED__, void *ev);
static Eina_Bool _x11_dnd_status (void *data __UNUSED__, int etype __UNUSED__, void *ev);
static Eina_Bool _x11_dnd_leave (void *data __UNUSED__, int etype __UNUSED__, void *ev);
static Eina_Bool _x11_drag_mouse_up (void *data, int etype __UNUSED__, void *event);
static void _x11_drag_move (void *data __UNUSED__, Ecore_X_Xdnd_Position *pos);
static Ecore_X_Window _x11_elm_widget_xwin_get (const Evas_Object *obj);
static Eina_Bool _x11_elm_cnp_init (void);
static Eina_Bool _x11_elm_cnp_selection_set (Evas_Object *obj, Elm_Sel_Type selection, Elm_Sel_Format format, const void *selbuf, size_t buflen);
static void _x11_elm_cnp_selection_loss_callback_set(Evas_Object *obj __UNUSED__, Elm_Sel_Type selection, Elm_Selection_Loss_Cb func, const void *data);
static Eina_Bool _x11_elm_object_cnp_selection_clear (Evas_Object *obj, Elm_Sel_Type selection);
static Eina_Bool _x11_elm_cnp_selection_get (Evas_Object *obj, Elm_Sel_Type selection, Elm_Sel_Format format, Elm_Drop_Cb datacb, void *udata);
static Eina_Bool _x11_elm_drop_target_add (Evas_Object *obj, Elm_Sel_Format format,
Elm_Drag_State entercb, void *enterdata,
Elm_Drag_State leavecb, void *leavedata,
Elm_Drag_Pos poscb, void *posdata,
Elm_Drop_Cb dropcb, void *dropdata);
static Eina_Bool _x11_elm_drop_target_del (Evas_Object *obj, Elm_Sel_Format format,
Elm_Drag_State entercb, void *enterdata,
Elm_Drag_State leavecb, void *leavedata,
Elm_Drag_Pos poscb, void *posdata,
Elm_Drop_Cb dropcb, void *dropdata);
static Eina_Bool _x11_elm_selection_selection_has_owner (Evas_Object *obj __UNUSED__);
static X11_Cnp_Atom _x11_atoms[CNP_N_ATOMS] = {
[CNP_ATOM_TARGETS] = {
"TARGETS",
ELM_SEL_FORMAT_TARGETS,
_x11_targets_converter,
_x11_response_handler_targets,
_x11_notify_handler_targets,
0
},
[CNP_ATOM_ATOM] = {
"ATOM", // for opera browser
ELM_SEL_FORMAT_TARGETS,
_x11_targets_converter,
_x11_response_handler_targets,
_x11_notify_handler_targets,
0
},
[CNP_ATOM_XELM] = {
"application/x-elementary-markup",
ELM_SEL_FORMAT_MARKUP,
_x11_general_converter,
NULL,
NULL,
0
},
[CNP_ATOM_text_uri] = {
"text/uri",
ELM_SEL_FORMAT_MARKUP | ELM_SEL_FORMAT_IMAGE, /* Either images or entries */
_x11_general_converter,
NULL,
_x11_notify_handler_uri,
0
},
[CNP_ATOM_text_urilist] = {
"text/uri-list",
ELM_SEL_FORMAT_IMAGE,
_x11_general_converter,
NULL,
_x11_notify_handler_uri,
0
},
[CNP_ATOM_text_x_vcard] = {
"text/x-vcard",
ELM_SEL_FORMAT_VCARD,
_x11_vcard_send, NULL,
_x11_vcard_receive, 0
},
[CNP_ATOM_image_png] = {
"image/png",
ELM_SEL_FORMAT_IMAGE,
_x11_image_converter,
NULL,
_x11_notify_handler_image,
0
},
[CNP_ATOM_image_jpeg] = {
"image/jpeg",
ELM_SEL_FORMAT_IMAGE,
_x11_image_converter,
NULL,
_x11_notify_handler_image,/* Raw image data is the same */
0
},
[CNP_ATOM_image_bmp] = {
"image/x-ms-bmp",
ELM_SEL_FORMAT_IMAGE,
_x11_image_converter,
NULL,
_x11_notify_handler_image,/* Raw image data is the same */
0
},
[CNP_ATOM_image_gif] = {
"image/gif",
ELM_SEL_FORMAT_IMAGE,
_x11_image_converter,
NULL,
_x11_notify_handler_image,/* Raw image data is the same */
0
},
[CNP_ATOM_image_tiff] = {
"image/tiff",
ELM_SEL_FORMAT_IMAGE,
_x11_image_converter,
NULL,
_x11_notify_handler_image,/* Raw image data is the same */
0
},
[CNP_ATOM_image_svg] = {
"image/svg+xml",
ELM_SEL_FORMAT_IMAGE,
_x11_image_converter,
NULL,
_x11_notify_handler_image,/* Raw image data is the same */
0
},
[CNP_ATOM_image_xpm] = {
"image/x-xpixmap",
ELM_SEL_FORMAT_IMAGE,
_x11_image_converter,
NULL,
_x11_notify_handler_image,/* Raw image data is the same */
0
},
[CNP_ATOM_image_tga] = {
"image/x-tga",
ELM_SEL_FORMAT_IMAGE,
_x11_image_converter,
NULL,
_x11_notify_handler_image,/* Raw image data is the same */
0
},
[CNP_ATOM_image_ppm] = {
"image/x-portable-pixmap",
ELM_SEL_FORMAT_IMAGE,
_x11_image_converter,
NULL,
_x11_notify_handler_image,/* Raw image data is the same */
0
},
/*
[CNP_ATOM_text_html_utf8] = {
"text/html;charset=utf-8",
ELM_SEL_FORMAT_HTML,
_x11_general_converter,
NULL,
_x11_notify_handler_html,
0
},
[CNP_ATOM_text_html] = {
"text/html",
ELM_SEL_FORMAT_HTML,
_x11_general_converter,
NULL,
_x11_notify_handler_html, // No encoding: Webkit only
0
},
*/
[CNP_ATOM_UTF8STRING] = {
"UTF8_STRING",
ELM_SEL_FORMAT_TEXT | ELM_SEL_FORMAT_MARKUP | ELM_SEL_FORMAT_HTML,
_x11_text_converter,
NULL,
_x11_notify_handler_text,
0
},
[CNP_ATOM_STRING] = {
"STRING",
ELM_SEL_FORMAT_TEXT | ELM_SEL_FORMAT_MARKUP | ELM_SEL_FORMAT_HTML,
_x11_text_converter,
NULL,
_x11_notify_handler_text,
0
},
[CNP_ATOM_COMPOUND_TEXT] = {
"COMPOUND_TEXT",
ELM_SEL_FORMAT_TEXT | ELM_SEL_FORMAT_MARKUP | ELM_SEL_FORMAT_HTML,
_x11_text_converter,
NULL,
_x11_notify_handler_text,
0
},
[CNP_ATOM_TEXT] = {
"TEXT",
ELM_SEL_FORMAT_TEXT | ELM_SEL_FORMAT_MARKUP | ELM_SEL_FORMAT_HTML,
_x11_text_converter,
NULL,
_x11_notify_handler_text,
0
},
[CNP_ATOM_text_plain_utf8] = {
"text/plain;charset=utf-8",
ELM_SEL_FORMAT_TEXT | ELM_SEL_FORMAT_MARKUP | ELM_SEL_FORMAT_HTML,
_x11_text_converter,
NULL,
_x11_notify_handler_text,
0
},
[CNP_ATOM_text_plain] = {
"text/plain",
ELM_SEL_FORMAT_TEXT | ELM_SEL_FORMAT_MARKUP | ELM_SEL_FORMAT_HTML,
_x11_text_converter,
NULL,
_x11_notify_handler_text,
0
},
};
static X11_Cnp_Selection _x11_selections[ELM_SEL_TYPE_CLIPBOARD + 1] = {
ARRAYINIT(ELM_SEL_TYPE_PRIMARY) {
.debug = "Primary",
.ecore_sel = ECORE_X_SELECTION_PRIMARY,
.set = ecore_x_selection_primary_set,
.clear = ecore_x_selection_primary_clear,
.request = ecore_x_selection_primary_request,
},
ARRAYINIT(ELM_SEL_TYPE_SECONDARY) {
.debug = "Secondary",
.ecore_sel = ECORE_X_SELECTION_SECONDARY,
.set = ecore_x_selection_secondary_set,
.clear = ecore_x_selection_secondary_clear,
.request = ecore_x_selection_secondary_request,
},
ARRAYINIT(ELM_SEL_TYPE_XDND) {
.debug = "XDnD",
.ecore_sel = ECORE_X_SELECTION_XDND,
.request = ecore_x_selection_xdnd_request,
},
ARRAYINIT(ELM_SEL_TYPE_CLIPBOARD) {
.debug = "Clipboard",
.ecore_sel = ECORE_X_SELECTION_CLIPBOARD,
.set = ecore_x_selection_clipboard_set,
.clear = ecore_x_selection_clipboard_clear,
.request = ecore_x_selection_clipboard_request,
},
};
static void
_x11_sel_obj_del(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
{
X11_Cnp_Selection *sel = data;
if (sel->widget == obj) sel->widget = NULL;
if (dragwidget == obj) dragwidget = NULL;
}
static void
_x11_sel_obj_del2(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
{
X11_Cnp_Selection *sel = data;
if (sel->requestwidget == obj) sel->requestwidget = NULL;
}
static Eina_Bool
_x11_selection_clear(void *udata __UNUSED__, int type __UNUSED__, void *event)
{
Ecore_X_Event_Selection_Clear *ev = event;
X11_Cnp_Selection *sel;
unsigned int i;
_x11_elm_cnp_init();
for (i = ELM_SEL_TYPE_PRIMARY; i <= ELM_SEL_TYPE_CLIPBOARD; i++)
{
if (_x11_selections[i].ecore_sel == ev->selection) break;
}
cnp_debug("selection %d clear\n", i);
/* Not me... Don't care */
if (i > ELM_SEL_TYPE_CLIPBOARD) return ECORE_CALLBACK_PASS_ON;
sel = _x11_selections + i;
if (sel->loss_cb) sel->loss_cb(sel->loss_data, i);
if (sel->widget)
evas_object_event_callback_del_full(sel->widget, EVAS_CALLBACK_DEL,
_x11_sel_obj_del, sel);
if (sel->requestwidget)
evas_object_event_callback_del_full(sel->requestwidget, EVAS_CALLBACK_DEL,
_x11_sel_obj_del2, sel);
sel->widget = NULL;
sel->requestwidget = NULL;
sel->active = EINA_FALSE;
sel->widget = NULL;
ELM_SAFE_FREE(sel->selbuf, free);
return ECORE_CALLBACK_PASS_ON;
}
/*
* Response to a selection notify:
* - So we have asked for the selection list.
* - If it's the targets list, parse it, and fire of what we want,
* else it's the data we want.
*/
static Eina_Bool
_x11_selection_notify(void *udata __UNUSED__, int type __UNUSED__, void *event)
{
Ecore_X_Event_Selection_Notify *ev = event;
X11_Cnp_Selection *sel;
int i;
cnp_debug("selection notify callback: %d\n",ev->selection);
switch (ev->selection)
{
case ECORE_X_SELECTION_PRIMARY:
sel = _x11_selections + ELM_SEL_TYPE_PRIMARY;
break;
case ECORE_X_SELECTION_SECONDARY:
sel = _x11_selections + ELM_SEL_TYPE_SECONDARY;
break;
case ECORE_X_SELECTION_XDND:
sel = _x11_selections + ELM_SEL_TYPE_XDND;
break;
case ECORE_X_SELECTION_CLIPBOARD:
sel = _x11_selections + ELM_SEL_TYPE_CLIPBOARD;
break;
default:
return ECORE_CALLBACK_PASS_ON;
}
cnp_debug("Target is %s\n", ev->target);
for (i = 0; i < CNP_N_ATOMS; i++)
{
if (!strcmp(ev->target, _x11_atoms[i].name))
{
if (_x11_atoms[i].notify)
{
cnp_debug("Found something: %s\n", _x11_atoms[i].name);
_x11_atoms[i].notify(sel, ev);
}
else cnp_debug("Ignored: No handler!\n");
}
}
return ECORE_CALLBACK_PASS_ON;
}
static Elm_Sel_Format
_get_selection_type(void *data, int size)
{
if (size == sizeof(Elm_Sel_Type))
{
unsigned int seltype = *((unsigned int *)data);
if (seltype > ELM_SEL_TYPE_CLIPBOARD)
return ELM_SEL_FORMAT_NONE;
X11_Cnp_Selection *sel = _x11_selections + seltype;
if (sel->active &&
(sel->format >= ELM_SEL_FORMAT_TARGETS) &&
(sel->format <= ELM_SEL_FORMAT_HTML))
return sel->format;
}
return ELM_SEL_FORMAT_NONE;
}
static Eina_Bool
_x11_targets_converter(char *target __UNUSED__, void *data, int size, void **data_ret, int *size_ret, Ecore_X_Atom *ttype, int *typesize)
{
int i, count;
Ecore_X_Atom *aret;
X11_Cnp_Selection *sel;
Elm_Sel_Format seltype;
if (!data_ret) return EINA_FALSE;
if (_get_selection_type(data, size) == ELM_SEL_FORMAT_NONE)
{
/* TODO : fallback into precise type */
seltype = ELM_SEL_FORMAT_TEXT;
}
else
{
sel = _x11_selections + *((int *)data);
seltype = sel->format;
}
for (i = 0, count = 0; i < CNP_N_ATOMS ; i++)
{
if (seltype & _x11_atoms[i].formats) count++;
}
aret = malloc(sizeof(Ecore_X_Atom) * count);
if (!aret) return EINA_FALSE;
for (i = 0, count = 0; i < CNP_N_ATOMS; i++)
{
if (seltype & _x11_atoms[i].formats)
aret[count ++] = _x11_atoms[i].atom;
}
*data_ret = aret;
if (typesize) *typesize = 32 /* urk */;
if (ttype) *ttype = ECORE_X_ATOM_ATOM;
if (size_ret) *size_ret = count;
return EINA_TRUE;
}
static Eina_Bool
_x11_image_converter(char *target __UNUSED__, void *data __UNUSED__, int size __UNUSED__, void **data_ret __UNUSED__, int *size_ret __UNUSED__, Ecore_X_Atom *ttype __UNUSED__, int *typesize __UNUSED__)
{
cnp_debug("Image converter called\n");
return EINA_TRUE;
}
static Eina_Bool
_x11_vcard_send(char *target __UNUSED__, void *data __UNUSED__, int size __UNUSED__, void **data_ret, int *size_ret, Ecore_X_Atom *ttype __UNUSED__, int *typesize __UNUSED__)
{
X11_Cnp_Selection *sel;
cnp_debug("Vcard send called\n");
sel = _x11_selections + *((int *)data);
if (data_ret) *data_ret = strdup(sel->selbuf);
if (size_ret) *size_ret = strlen(sel->selbuf);
return EINA_TRUE;
}
static Eina_Bool
_x11_is_uri_type_data(X11_Cnp_Selection *sel __UNUSED__, Ecore_X_Event_Selection_Notify *notify)
{
Ecore_X_Selection_Data *data;
char *p;
data = notify->data;
cnp_debug("data->format is %d %p %p\n", data->format, notify, data);
if (data->content == ECORE_X_SELECTION_CONTENT_FILES) return EINA_TRUE;
p = (char *)data->data;
if (!p) return EINA_TRUE;
cnp_debug("Got %s\n", p);
if (strncmp(p, "file://", 7))
{
if (*p != '/') return EINA_FALSE;
}
return EINA_TRUE;
}
/*
* Callback to handle a targets response on a selection request:
* So pick the format we'd like; and then request it.
*/
static int
_x11_notify_handler_targets(X11_Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify)
{
Ecore_X_Selection_Data_Targets *targets;
Ecore_X_Atom *atomlist;
int i, j;
targets = notify->data;
atomlist = (Ecore_X_Atom *)(targets->data.data);
for (j = (CNP_ATOM_LISTING_ATOMS + 1); j < CNP_N_ATOMS; j++)
{
cnp_debug("\t%s %d\n", _x11_atoms[j].name, _x11_atoms[j].atom);
if (!(_x11_atoms[j].formats & sel->requestformat)) continue;
for (i = 0; i < targets->data.length; i++)
{
if ((_x11_atoms[j].atom == atomlist[i]) && (_x11_atoms[j].notify))
{
if ((j == CNP_ATOM_text_uri) ||
(j == CNP_ATOM_text_urilist))
{
if (!_x11_is_uri_type_data(sel, notify)) continue;
}
cnp_debug("Atom %s matches\n", _x11_atoms[j].name);
goto done;
}
}
}
cnp_debug("Couldn't find anything that matches\n");
return ECORE_CALLBACK_PASS_ON;
done:
cnp_debug("Sending request for %s, xwin=%#llx\n",
_x11_atoms[j].name, (unsigned long long)sel->xwin);
sel->request(sel->xwin, _x11_atoms[j].name);
return ECORE_CALLBACK_PASS_ON;
}
static int
_x11_response_handler_targets(X11_Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify)
{
Ecore_X_Selection_Data_Targets *targets;
Ecore_X_Atom *atomlist;
int i, j;
targets = notify->data;
atomlist = (Ecore_X_Atom *)(targets->data.data);
for (j = (CNP_ATOM_LISTING_ATOMS + 1); j < CNP_N_ATOMS; j++)
{
if (!(_x11_atoms[j].formats & sel->requestformat)) continue;
for (i = 0; i < targets->data.length; i++)
{
if ((_x11_atoms[j].atom == atomlist[i]) &&
(_x11_atoms[j].response))
goto found;
}
}
cnp_debug("No matching type found\n");
return 0;
found:
sel->request(sel->xwin, _x11_atoms[j].name);
return 0;
}
static int
_x11_notify_handler_text(X11_Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify)
{
Ecore_X_Selection_Data *data;
Eina_List *l;
Dropable *dropable;
data = notify->data;
if (sel == (_x11_selections + ELM_SEL_TYPE_XDND))
{
Elm_Selection_Data ddata;
cnp_debug("drag & drop\n");
/* FIXME: this needs to be generic: Used for all receives */
EINA_LIST_FOREACH(drops, l, dropable)
{
if (dropable->obj == sel->requestwidget) break;
dropable = NULL;
}
if (dropable)
{
Dropable_Cbs *cbs;
Eina_Inlist *itr;
ddata.x = savedtypes.x;
ddata.y = savedtypes.y;
ddata.format = ELM_SEL_FORMAT_TEXT;
ddata.data = data->data;
ddata.len = data->length;
ddata.action = sel->action;
EINA_INLIST_FOREACH_SAFE(dropable->cbs_list, itr, cbs)
if (cbs->dropcb)
cbs->dropcb(cbs->dropdata, dropable->obj, &ddata);
goto end;
}
}
if (sel->datacb)
{
Elm_Selection_Data ddata;
ddata.x = ddata.y = 0;
ddata.format = ELM_SEL_FORMAT_TEXT;
ddata.data = data->data;
ddata.len = data->length;
ddata.action = sel->action;
sel->datacb(sel->udata, sel->widget, &ddata);
}
else
{
char *stripstr, *mkupstr;
stripstr = malloc(data->length + 1);
if (!stripstr) goto end;
strncpy(stripstr, (char *)data->data, data->length);
stripstr[data->length] = '\0';
cnp_debug("Notify handler text %d %d %p\n", data->format,
data->length, data->data);
mkupstr = _elm_util_text_to_mkup((const char *)stripstr);
cnp_debug("String is %s (from %s)\n", stripstr, data->data);
/* TODO BUG: should never NEVER assume it's an elm_entry! */
_elm_entry_entry_paste(sel->requestwidget, mkupstr);
free(stripstr);
free(mkupstr);
}
end:
if (sel == (_x11_selections + ELM_SEL_TYPE_XDND))
ecore_x_dnd_send_finished();
return 0;
}
/**
* So someone is pasting an image into my entry or widget...
*/
static int
_x11_notify_handler_uri(X11_Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify)
{
Ecore_X_Selection_Data *data;
Ecore_X_Selection_Data_Files *files;
char *p, *s, *stripstr = NULL;
data = notify->data;
cnp_debug("data->format is %d %p %p\n", data->format, notify, data);
if (data->content == ECORE_X_SELECTION_CONTENT_FILES)
{
int i, len = 0;
cnp_debug("got a files list\n");
files = notify->data;
/*
if (files->num_files > 1)
{
// Don't handle many items <- this makes mr bigglesworth sad :(
cnp_debug("more then one file: Bailing\n");
return 0;
}
stripstr = p = strdup(files->files[0]);
*/
for (i = 0; i < files->num_files ; i++)
{
p = files->files[i];
if ((strncmp(p, "file://", 7)) && (p[0] != '/')) continue;
len += strlen(files->files[i]) + 1;
}
p = NULL;
if (len > 0)
{
s = stripstr = malloc(len + 1);
for (i = 0; i < files->num_files ; i++)
{
p = files->files[i];
if (!strncmp(p, "file://", 7)) p += 7;
else if (p[0] != '/') continue;
len = strlen(p);
strcpy(s, p);
if (i < (files->num_files - 1))
{
s[len] = '\n';
s[len + 1] = 0;
s += len + 1;
}
else
{
s[len] = 0;
s += len;
}
}
}
}
else
{
p = (char *)data->data;
if ((!strncmp(p, "file://", 7)) || (p[0] == '/'))
{
int len = data->length;
if (!strncmp(p, "file://", 7))
{
p += 7;
len -= 7;
}
stripstr = malloc(len + 1);
if (!stripstr) return 0;
memcpy(stripstr, p, len);
stripstr[len] = 0;
}
}
if (!stripstr)
{
cnp_debug("Couldn't find a file\n");
return 0;
}
if (savedtypes.imgfile) free(savedtypes.imgfile);
if (savedtypes.textreq)
{
savedtypes.textreq = 0;
savedtypes.imgfile = stripstr;
}
else
{
savedtypes.imgfile = NULL;
_pasteimage_append(p, sel->requestwidget);
free(stripstr);
}
return 0;
}
/**
* Just received an vcard, either through cut and paste, or dnd.
*/
static int
_x11_vcard_receive(X11_Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify)
{
Dropable *dropable;
Eina_List *l;
Ecore_X_Selection_Data *data;
data = notify->data;
cnp_debug("vcard receive\n");
if (sel == (_x11_selections + ELM_SEL_TYPE_XDND))
{
Dropable_Cbs *cbs;
Eina_Inlist *itr;
Elm_Selection_Data ddata;
cnp_debug("drag & drop\n");
/* FIXME: this needs to be generic: Used for all receives */
EINA_LIST_FOREACH(drops, l, dropable)
{
if (dropable->obj == sel->requestwidget) break;
}
if (!dropable)
{
cnp_debug("Unable to find drop object");
ecore_x_dnd_send_finished();
return 0;
}
dropable = eina_list_data_get(l);
ddata.x = savedtypes.x;
ddata.y = savedtypes.y;
ddata.format = ELM_SEL_FORMAT_VCARD;
ddata.data = data->data;
ddata.len = data->length;
ddata.action = sel->action;
EINA_INLIST_FOREACH_SAFE(dropable->cbs_list, itr, cbs)
if (cbs->dropcb)
cbs->dropcb(cbs->dropdata, dropable->obj, &ddata);
ecore_x_dnd_send_finished();
}
else if (sel->datacb)
{
Elm_Selection_Data ddata;
ddata.x = ddata.y = 0;
ddata.format = ELM_SEL_FORMAT_VCARD;
ddata.data = data->data;
ddata.len = data->length;
ddata.action = sel->action;
sel->datacb(sel->udata, sel->widget, &ddata);
}
else cnp_debug("Paste request\n");
return 0;
}
static int
_x11_notify_handler_image(X11_Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify)
{
Ecore_X_Selection_Data *data;
Tmp_Info *tmp;
cnp_debug("got a image file!\n");
data = notify->data;
cnp_debug("Size if %d\n", data->length);
if (sel->datacb)
{
Elm_Selection_Data ddata;
ddata.x = ddata.y = 0;
ddata.format = ELM_SEL_FORMAT_IMAGE;
ddata.data = data->data;
ddata.len = data->length;
ddata.action = sel->action;
sel->datacb(sel->udata, sel->widget, &ddata);
return 0;
}
/* generate tmp name */
tmp = _tempfile_new(data->length);
if (!tmp) return 0;
memcpy(tmp->map, data->data, data->length);
munmap(tmp->map, data->length);
/* FIXME: Add to paste image data to clean up */
_pasteimage_append(tmp->filename, sel->requestwidget);
_tmpinfo_free(tmp);
return 0;
}
/**
* Warning: Generic text/html can';t handle it sanely.
* Firefox sends ucs2 (i think).
* chrome sends utf8... blerg
*/
/*
static int
_x11_notify_handler_html(X11_Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify)
{
Ecore_X_Selection_Data *data;
cnp_debug("Got some HTML: Checking encoding is useful\n");
data = notify->data;
char *stripstr = malloc(data->length + 1);
if (!stripstr) return 0;
strncpy(stripstr, (char *)data->data, data->length);
stripstr[data->length] = '\0';
if (sel->datacb)
{
Elm_Selection_Data ddata;
ddata.x = ddata.y = 0;
ddata.format = ELM_SEL_FORMAT_HTML;
ddata.data = stripstr;
ddata.len = data->length;
ddata.action = ELM_XDND_ACTION_UNKNOWN;
sel->datacb(sel->udata, sel->widget, &ddata);
free(stripstr);
return 0;
}
cnp_debug("String is %s (%d bytes)\n", stripstr, data->length);
// TODO BUG: should never NEVER assume it's an elm_entry!
_elm_entry_entry_paste(sel->requestwidget, stripstr);
free(stripstr);
return 0;
}
*/
static Eina_Bool
_x11_text_converter(char *target, void *data, int size, void **data_ret, int *size_ret, Ecore_X_Atom *ttype, int *typesize)
{
X11_Cnp_Selection *sel;
cnp_debug("text converter\n");
if (_get_selection_type(data, size) == ELM_SEL_FORMAT_NONE)
{
if (data_ret)
{
*data_ret = malloc(size * sizeof(char) + 1);
if (!*data_ret) return EINA_FALSE;
memcpy(*data_ret, data, size);
((char**)(data_ret))[0][size] = 0;
}
if (size_ret) *size_ret = size;
return EINA_TRUE;
}
sel = _x11_selections + *((int *)data);
if (!sel->active) return EINA_TRUE;
if ((sel->format & ELM_SEL_FORMAT_MARKUP) ||
(sel->format & ELM_SEL_FORMAT_HTML))
{
*data_ret = _elm_util_mkup_to_text(sel->selbuf);
if (size_ret && *data_ret) *size_ret = strlen(*data_ret);
}
else if (sel->format & ELM_SEL_FORMAT_TEXT)
{
ecore_x_selection_converter_text(target, sel->selbuf,
strlen(sel->selbuf),
data_ret, size_ret,
ttype, typesize);
}
else if (sel->format & ELM_SEL_FORMAT_IMAGE)
{
cnp_debug("Image %s\n", evas_object_type_get(sel->widget));
cnp_debug("Elm type: %s\n", elm_object_widget_type_get(sel->widget));
evas_object_image_file_get(elm_photocam_internal_image_get(sel->widget),
(const char **)data_ret, NULL);
if (!*data_ret) *data_ret = strdup("No file");
else *data_ret = strdup(*data_ret);
*size_ret = strlen(*data_ret);
}
return EINA_TRUE;
}
static Eina_Bool
_x11_general_converter(char *target __UNUSED__, void *data, int size, void **data_ret, int *size_ret, Ecore_X_Atom *ttype __UNUSED__, int *typesize __UNUSED__)
{
if (_get_selection_type(data, size) == ELM_SEL_FORMAT_NONE)
{
if (data_ret)
{
*data_ret = malloc(size * sizeof(char) + 1);
if (!*data_ret) return EINA_FALSE;
memcpy(*data_ret, data, size);
((char**)(data_ret))[0][size] = 0;
}
if (size_ret) *size_ret = size;
}
else
{
X11_Cnp_Selection *sel = _x11_selections + *((int *)data);
if (sel->selbuf)
{
if (data_ret) *data_ret = strdup(sel->selbuf);
if (size_ret) *size_ret = strlen(sel->selbuf);
}
else
{
if (data_ret) *data_ret = NULL;
if (size_ret) *size_ret = 0;
}
}
return EINA_TRUE;
}
static Dropable *
_x11_dropable_find(Ecore_X_Window win)
{
Eina_List *l;
Dropable *dropable;
if (!drops) return NULL;
EINA_LIST_FOREACH(drops, l, dropable)
{
if (_x11_elm_widget_xwin_get(dropable->obj) == win) return dropable;
}
return NULL;
}
static Dropable *
_x11_dropable_geom_find(Ecore_X_Window win, Evas_Coord px, Evas_Coord py)
{
Eina_List *itr, *top_objects_list = NULL;
Evas *evas = NULL;
Evas_Object *top_obj;
Dropable *dropable = NULL;
if (!drops) return NULL;
/* Find the Evas connected to the window */
EINA_LIST_FOREACH(drops, itr, dropable)
{
if (_x11_elm_widget_xwin_get(dropable->obj) == win)
{
evas = evas_object_evas_get(dropable->obj);
break;
}
}
if (!evas) return NULL;
/* We retrieve the (non-smart) objects pointed by (px, py) */
top_objects_list = evas_tree_objects_at_xy_get(evas, NULL, px, py);
/* We walk on this list from the last because if the list contains more than one
* element, all but the last will repeat events. The last one can repeat events
* or not. Anyway, this last one is the first that has to be taken into account
* for the determination of the drop target.
*/
EINA_LIST_REVERSE_FOREACH(top_objects_list, itr, top_obj)
{
Evas_Object *object = top_obj;
/* We search for the dropable data into the object. If not found, we search into its parent.
* For example, if a button is a drop target, the first object will be an (internal) image.
* The drop target is attached to the button, i.e to image's parent. That's why we need to
* walk on the parents until NULL.
* If we find this dropable data, we found our drop target.
*/
while (object)
{
eo_do(object, eo_base_data_get("__elm_dropable", (void **)&dropable));
if (dropable)
goto end;
else
object = evas_object_smart_parent_get(object);
}
}
end:
eina_list_free(top_objects_list);
if (dropable) cnp_debug("Drop target %p of type %s found\n", dropable->obj, eo_class_name_get(eo_class_get(dropable->obj)));
return dropable;
}
static void
_x11_dropable_coords_adjust(Dropable *dropable, Evas_Coord *x, Evas_Coord *y)
{
Ecore_Evas *ee;
int ex = 0, ey = 0;
ee = ecore_evas_ecore_evas_get(evas_object_evas_get(dropable->obj));
ecore_evas_geometry_get(ee, &ex, &ey, NULL, NULL);
*x = *x - ex;
*y = *y - ey;
}
static void
_x11_dropable_all_set(Ecore_X_Window win, Evas_Coord x, Evas_Coord y, Eina_Bool set)
{
Eina_List *l;
Dropable *dropable;
EINA_LIST_FOREACH(drops, l, dropable)
{
if (_x11_elm_widget_xwin_get(dropable->obj) == win)
{
dropable->last.x = x;
dropable->last.y = y;
dropable->last.in = set;
}
}
}
static Eina_Bool
_x11_dnd_enter(void *data __UNUSED__, int etype __UNUSED__, void *ev)
{
Ecore_X_Event_Xdnd_Enter *enter = ev;
int i;
Dropable *dropable;
if (!enter) return EINA_TRUE;
dropable = _x11_dropable_find(enter->win);
if (dropable)
{
cnp_debug("Enter %x\n", enter->win);
_x11_dropable_all_set(enter->win, 0, 0, EINA_FALSE);
}
/* Skip it */
cnp_debug("enter types=%p (%d)\n", enter->types, enter->num_types);
if ((!enter->num_types) || (!enter->types)) return EINA_TRUE;
cnp_debug("Types\n");
savedtypes.ntypes = enter->num_types;
if (savedtypes.types) free(savedtypes.types);
savedtypes.types = malloc(sizeof(char *) * enter->num_types);
if (!savedtypes.types) return EINA_FALSE;
for (i = 0; i < enter->num_types; i++)
{
savedtypes.types[i] = eina_stringshare_add(enter->types[i]);
cnp_debug("Type is %s %p %p\n", enter->types[i],
savedtypes.types[i], text_uri);
if (savedtypes.types[i] == text_uri)
{
/* Request it, so we know what it is */
cnp_debug("Sending uri request\n");
savedtypes.textreq = 1;
if (savedtypes.imgfile) free(savedtypes.imgfile);
savedtypes.imgfile = NULL;
ecore_x_selection_xdnd_request(enter->win, text_uri);
}
}
/* FIXME: Find an object and make it current */
return EINA_TRUE;
}
static void
_x11_dnd_dropable_handle(Dropable *dropable, Evas_Coord x, Evas_Coord y, Eina_Bool have_obj, Elm_Xdnd_Action action)
{
Dropable *dropable_last = NULL;
Dropable_Cbs *cbs;
Eina_Inlist *itr;
if (dropable->last.in)
dropable_last = _x11_dropable_geom_find
(_x11_elm_widget_xwin_get(dropable->obj),
dropable->last.x, dropable->last.y);
if ((have_obj) && (dropable_last == dropable)) // same
{
cnp_debug("same obj dropable %p\n", dropable);
EINA_INLIST_FOREACH_SAFE(dropable->cbs_list, itr, cbs)
if (cbs->poscb)
cbs->poscb(cbs->posdata, dropable->obj, x, y, action);
}
else if ((have_obj) && (!dropable_last)) // enter new obj
{
cnp_debug("enter %p\n", dropable->obj);
EINA_INLIST_FOREACH_SAFE(dropable->cbs_list, itr, cbs)
if (cbs->entercb)
cbs->entercb(cbs->enterdata, dropable->obj);
EINA_INLIST_FOREACH_SAFE(dropable->cbs_list, itr, cbs)
if (cbs->poscb)
cbs->poscb(cbs->posdata, dropable->obj, x, y, action);
}
else if ((!have_obj) && (dropable_last)) // leave last obj
{
cnp_debug("leave %p\n", dropable_last->obj);
EINA_INLIST_FOREACH_SAFE(dropable->cbs_list, itr, cbs)
if (cbs->leavecb)
cbs->leavecb(cbs->leavedata, dropable->obj);
}
else if (have_obj) // leave last obj and enter new one
{
cnp_debug("enter %p\n", dropable->obj);
EINA_INLIST_FOREACH_SAFE(dropable->cbs_list, itr, cbs)
if (cbs->entercb)
cbs->entercb(cbs->enterdata, dropable->obj);
if (dropable_last)
{
dropable = dropable_last;
EINA_INLIST_FOREACH_SAFE(dropable->cbs_list, itr, cbs)
if (cbs->leavecb)
cbs->leavecb(cbs->leavedata, dropable->obj);
cnp_debug("leave %p\n", dropable->obj);
}
}
}
static Elm_Xdnd_Action
_x11_dnd_action_map(Ecore_X_Atom action)
{
Elm_Xdnd_Action act = ELM_XDND_ACTION_UNKNOWN;
if (action == ECORE_X_ATOM_XDND_ACTION_COPY)
act = ELM_XDND_ACTION_COPY;
else if (action == ECORE_X_ATOM_XDND_ACTION_MOVE)
act = ELM_XDND_ACTION_MOVE;
else if (action == ECORE_X_ATOM_XDND_ACTION_PRIVATE)
act = ELM_XDND_ACTION_PRIVATE;
else if (action == ECORE_X_ATOM_XDND_ACTION_ASK)
act = ELM_XDND_ACTION_ASK;
else if (action == ECORE_X_ATOM_XDND_ACTION_LIST)
act = ELM_XDND_ACTION_LIST;
else if (action == ECORE_X_ATOM_XDND_ACTION_LINK)
act = ELM_XDND_ACTION_LINK;
else if (action == ECORE_X_ATOM_XDND_ACTION_DESCRIPTION)
act = ELM_XDND_ACTION_DESCRIPTION;
return act;
}
static Ecore_X_Atom
_x11_dnd_action_rev_map(Elm_Xdnd_Action action)
{
Ecore_X_Atom act = ECORE_X_ATOM_XDND_ACTION_MOVE;
if (action == ELM_XDND_ACTION_COPY)
act = ECORE_X_ATOM_XDND_ACTION_COPY;
else if (action == ELM_XDND_ACTION_MOVE)
act = ECORE_X_ATOM_XDND_ACTION_MOVE;
else if (action == ELM_XDND_ACTION_PRIVATE)
act = ECORE_X_ATOM_XDND_ACTION_PRIVATE;
else if (action == ELM_XDND_ACTION_ASK)
act = ECORE_X_ATOM_XDND_ACTION_ASK;
else if (action == ELM_XDND_ACTION_LIST)
act = ECORE_X_ATOM_XDND_ACTION_LIST;
else if (action == ELM_XDND_ACTION_LINK)
act = ECORE_X_ATOM_XDND_ACTION_LINK;
else if (action == ELM_XDND_ACTION_DESCRIPTION)
act = ECORE_X_ATOM_XDND_ACTION_DESCRIPTION;
return act;
}
static Eina_Bool
_x11_dnd_position(void *data __UNUSED__, int etype __UNUSED__, void *ev)
{
Ecore_X_Event_Xdnd_Position *pos = ev;
Ecore_X_Rectangle rect = { 0, 0, 0, 0 };
Dropable *dropable, *dropable_old;
Elm_Xdnd_Action act;
/* Need to send a status back */
/* FIXME: Should check I can drop here */
/* FIXME: Should highlight widget */
dropable_old = dropable = _x11_dropable_find(pos->win);
if (dropable)
{
Evas_Coord x, y, ox = 0, oy = 0, ow = 0, oh = 0;
x = pos->position.x;
y = pos->position.y;
_x11_dropable_coords_adjust(dropable, &x, &y);
dropable = _x11_dropable_geom_find(pos->win, x, y);
act = _x11_dnd_action_map(pos->action);
if (dropable)
{
evas_object_geometry_get(dropable->obj, &ox, &oy, &ow, &oh);
rect.x = pos->position.x - x + ox;
rect.y = pos->position.y - y + oy;
rect.width = ow;
rect.height = oh;
ecore_x_dnd_send_status(EINA_TRUE, EINA_FALSE, rect, pos->action);
cnp_debug("dnd position %i %i %p\n", x - ox, y - oy, dropable);
_x11_dnd_dropable_handle(dropable, x - ox, y - oy, EINA_TRUE,
act);
// CCCCCCC: call dnd exit on last obj if obj != last
// CCCCCCC: call drop position on obj
_x11_dropable_all_set(pos->win, x, y, EINA_TRUE);
}
else
{
ecore_x_dnd_send_status(EINA_FALSE, EINA_FALSE, rect, pos->action);
cnp_debug("dnd position (%d, %d) not in obj\n", x, y);
_x11_dnd_dropable_handle(dropable_old, 0, 0, EINA_FALSE,
act);
// CCCCCCC: call dnd exit on last obj
_x11_dropable_all_set(pos->win, x, y, EINA_TRUE);
}
}
else
{
ecore_x_dnd_send_status(EINA_FALSE, EINA_FALSE, rect, pos->action);
}
return EINA_TRUE;
}
static Eina_Bool
_x11_dnd_leave(void *data __UNUSED__, int etype __UNUSED__, void *ev)
{
Ecore_X_Event_Xdnd_Leave *leave = ev;
Dropable *dropable;
dropable = _x11_dropable_find(leave->win);
if (dropable)
{
cnp_debug("Leave %x\n", leave->win);
_x11_dnd_dropable_handle(dropable, 0, 0, EINA_FALSE, ELM_XDND_ACTION_UNKNOWN);
_x11_dropable_all_set(leave->win, 0, 0, EINA_FALSE);
// CCCCCCC: call dnd exit on last obj if there was one
}
// leave->win leave->source
return EINA_TRUE;
}
static Eina_Bool
_x11_dnd_drop(void *data __UNUSED__, int etype __UNUSED__, void *ev)
{
Ecore_X_Event_Xdnd_Drop *drop;
Dropable *dropable;
Elm_Selection_Data ddata;
Evas_Coord x = 0, y = 0;
Elm_Xdnd_Action act = ELM_XDND_ACTION_UNKNOWN;
int i, j;
drop = ev;
cnp_debug("drops %p (%d)\n", drops, eina_list_count(drops));
if (!(dropable = _x11_dropable_find(drop->win))) return EINA_TRUE;
/* Calculate real (widget relative) position */
// - window position
// - widget position
savedtypes.x = drop->position.x;
savedtypes.y = drop->position.y;
_x11_dropable_coords_adjust(dropable, &savedtypes.x, &savedtypes.y);
cnp_debug("Drop position is %d,%d\n", savedtypes.x, savedtypes.y);
dropable = _x11_dropable_geom_find(drop->win, savedtypes.x, savedtypes.y);
if (!dropable) return EINA_TRUE; /* didn't find one */
evas_object_geometry_get(dropable->obj, &x, &y, NULL, NULL);
savedtypes.x -= x;
savedtypes.y -= y;
/* Find our type from the previous list */
for (i = 0; i < CNP_N_ATOMS; i++)
{
for (j = 0; j < savedtypes.ntypes; j++)
{
if (!strcmp(savedtypes.types[j], _x11_atoms[i].name)) goto found;
}
}
cnp_debug("Didn't find a target\n");
return EINA_TRUE;
found:
cnp_debug("Found a target we'd like: %s\n", _x11_atoms[i].name);
cnp_debug("0x%x\n", drop->win);
act = _x11_dnd_action_map(drop->action);
if (i == CNP_ATOM_text_urilist)
{
cnp_debug("We found a URI... (%scached) %s\n",
savedtypes.imgfile ? "" : "not ",
savedtypes.imgfile);
if (savedtypes.imgfile)
{
char *entrytag;
static const char *tagstring =
"<item absize=240x180 href=file://%s></item>";
ddata.x = savedtypes.x;
ddata.y = savedtypes.y;
ddata.action = act;
Dropable_Cbs *cbs;
Eina_Inlist *itr;
EINA_INLIST_FOREACH_SAFE(dropable->cbs_list, itr, cbs)
{
/* If it's markup that also supports images */
if ((cbs->types & ELM_SEL_FORMAT_MARKUP) &&
(cbs->types & ELM_SEL_FORMAT_IMAGE))
{
int len;
ddata.format = ELM_SEL_FORMAT_MARKUP;
len = strlen(tagstring) + strlen(savedtypes.imgfile);
entrytag = alloca(len + 1);
snprintf(entrytag, len + 1, tagstring, savedtypes.imgfile);
ddata.data = entrytag;
cnp_debug("Insert %s\n", (char *)ddata.data);
if (cbs->dropcb)
cbs->dropcb(cbs->dropdata, dropable->obj, &ddata);
}
else if (cbs->types & ELM_SEL_FORMAT_IMAGE)
{
cnp_debug("Doing image insert (%s)\n", savedtypes.imgfile);
ddata.format = ELM_SEL_FORMAT_IMAGE;
ddata.data = (char *)savedtypes.imgfile;
if (cbs->dropcb)
cbs->dropcb(cbs->dropdata, dropable->obj, &ddata);
}
else
{
cnp_debug("Item doesn't support images... passing\n");
}
}
ecore_x_dnd_send_finished();
ELM_SAFE_FREE(savedtypes.imgfile, free);
return EINA_TRUE;
}
else if (savedtypes.textreq)
{
/* Already asked: Pretend we asked now, and paste immediately when
* it comes in */
savedtypes.textreq = 0;
ecore_x_dnd_send_finished();
return EINA_TRUE;
}
}
cnp_debug("doing a request then\n");
_x11_selections[ELM_SEL_TYPE_XDND].xwin = drop->win;
_x11_selections[ELM_SEL_TYPE_XDND].requestwidget = dropable->obj;
_x11_selections[ELM_SEL_TYPE_XDND].requestformat = ELM_SEL_FORMAT_MARKUP;
_x11_selections[ELM_SEL_TYPE_XDND].active = EINA_TRUE;
_x11_selections[ELM_SEL_TYPE_XDND].action = act;
ecore_x_selection_xdnd_request(drop->win, _x11_atoms[i].name);
return EINA_TRUE;
}
static Eina_Bool
_x11_dnd_status(void *data __UNUSED__, int etype __UNUSED__, void *ev)
{
Ecore_X_Event_Xdnd_Status *status = ev;
doaccept = EINA_FALSE;
/* Only thing we care about: will accept */
if ((status) && (status->will_accept))
{
cnp_debug("Will accept\n");
doaccept = EINA_TRUE;
}
/* Won't accept */
else
{
cnp_debug("Won't accept accept\n");
}
if (dragacceptcb)
dragacceptcb(dragacceptdata, _x11_selections[ELM_SEL_TYPE_XDND].widget,
doaccept);
return EINA_TRUE;
}
static Eina_Bool
_x11_drag_mouse_up(void *data, int etype __UNUSED__, void *event)
{
Ecore_X_Window xwin = (Ecore_X_Window)(long)data;
Ecore_Event_Mouse_Button *ev = event;
if ((ev->buttons == 1) &&
(ev->event_window == xwin))
{
Eina_Bool have_drops = EINA_FALSE;
Eina_List *l;
Dropable *dropable;
ecore_x_pointer_ungrab();
ELM_SAFE_FREE(handler_up, ecore_event_handler_del);
ELM_SAFE_FREE(handler_status, ecore_event_handler_del);
ecore_x_dnd_self_drop();
cnp_debug("mouse up, xwin=%#llx\n", (unsigned long long)xwin);
EINA_LIST_FOREACH(drops, l, dropable)
{
if (xwin == _x11_elm_widget_xwin_get(dropable->obj))
{
have_drops = EINA_TRUE;
break;
}
}
if (!have_drops) ecore_x_dnd_aware_set(xwin, EINA_FALSE);
if (dragdonecb) dragdonecb(dragdonedata, dragwidget);
if (dragwin)
{
if (!doaccept)
{ /* Commit animation when drag cancelled */
/* Record final position of dragwin, then do animation */
ecore_animator_timeline_add(0.3,
_drag_cancel_animate, dragwin);
}
else
{ /* No animation drop was committed */
evas_object_del(dragwin);
}
dragwin = NULL; /* if not freed here, free in end of anim */
}
dragdonecb = NULL;
dragacceptcb = NULL;
dragposcb = NULL;
dragwidget = NULL;
doaccept = EINA_FALSE;
/* moved to _drag_cancel_animate
if (dragwin)
{
evas_object_del(dragwin);
dragwin = NULL;
}
*/
}
return EINA_TRUE;
}
static void
_x11_drag_move(void *data __UNUSED__, Ecore_X_Xdnd_Position *pos)
{
evas_object_move(dragwin,
pos->position.x - _dragx, pos->position.y - _dragy);
dragwin_x_end = pos->position.x - _dragx;
dragwin_y_end = pos->position.y - _dragy;
cnp_debug("dragevas: %p -> %p\n",
dragwidget,
evas_object_evas_get(dragwidget));
if (dragposcb)
dragposcb(dragposdata, dragwidget, pos->position.x, pos->position.y,
dragaction);
}
static Ecore_X_Window
_x11_elm_widget_xwin_get(const Evas_Object *obj)
{
Evas_Object *top;
Ecore_X_Window xwin = 0;
top = elm_widget_top_get(obj);
if (!top) top = elm_widget_top_get(elm_widget_parent_widget_get(obj));
if (top) xwin = elm_win_xwindow_get(top);
if (!xwin)
{
Ecore_Evas *ee;
Evas *evas = evas_object_evas_get(obj);
if (!evas) return 0;
ee = ecore_evas_ecore_evas_get(evas);
if (!ee) return 0;
xwin = _elm_ee_xwin_get(ee);
}
return xwin;
}
static Eina_Bool
_x11_elm_cnp_init(void)
{
int i;
static int _init_count = 0;
if (_init_count > 0) return EINA_TRUE;
_init_count++;
for (i = 0; i < CNP_N_ATOMS; i++)
{
_x11_atoms[i].atom = ecore_x_atom_get(_x11_atoms[i].name);
ecore_x_selection_converter_atom_add
(_x11_atoms[i].atom, _x11_atoms[i].converter);
}
//XXX delete handlers?
ecore_event_handler_add(ECORE_X_EVENT_SELECTION_CLEAR, _x11_selection_clear, NULL);
ecore_event_handler_add(ECORE_X_EVENT_SELECTION_NOTIFY, _x11_selection_notify, NULL);
return EINA_TRUE;
}
static Eina_Bool
_x11_elm_cnp_selection_set(Evas_Object *obj, Elm_Sel_Type selection, Elm_Sel_Format format, const void *selbuf, size_t buflen)
{
Ecore_X_Window xwin = _x11_elm_widget_xwin_get(obj);
X11_Cnp_Selection *sel;
_x11_elm_cnp_init();
if ((!selbuf) && (format != ELM_SEL_FORMAT_IMAGE))
return elm_object_cnp_selection_clear(obj, selection);
sel = _x11_selections + selection;
if (sel->loss_cb) sel->loss_cb(sel->loss_data, selection);
if (sel->widget)
evas_object_event_callback_del_full(sel->widget, EVAS_CALLBACK_DEL,
_x11_sel_obj_del, sel);
sel->widget = NULL;
sel->active = EINA_TRUE;
sel->widget = obj;
sel->xwin = xwin;
if (sel->set) sel->set(xwin, &selection, sizeof(Elm_Sel_Type));
sel->format = format;
sel->loss_cb = NULL;
sel->loss_data = NULL;
evas_object_event_callback_add
(sel->widget, EVAS_CALLBACK_DEL, _x11_sel_obj_del, sel);
if (selbuf)
{
if (format == ELM_SEL_FORMAT_IMAGE)
{
// selbuf is actual image data, not text/string
ELM_SAFE_FREE(sel->selbuf, free);
sel->selbuf = malloc(buflen + 1);
if (!sel->selbuf)
{
elm_object_cnp_selection_clear(obj, selection);
return EINA_FALSE;
}
memcpy(sel->selbuf, selbuf, buflen);
sel->selbuf[buflen] = 0;
}
else
sel->selbuf = strdup((char*)selbuf);
}
else
sel->selbuf = NULL;
return EINA_TRUE;
}
static void
_x11_elm_cnp_selection_loss_callback_set(Evas_Object *obj __UNUSED__, Elm_Sel_Type selection, Elm_Selection_Loss_Cb func, const void *data)
{
X11_Cnp_Selection *sel;
_x11_elm_cnp_init();
sel = _x11_selections + selection;
sel->loss_cb = func;
sel->loss_data = (void *)data;
}
static Eina_Bool
_x11_elm_object_cnp_selection_clear(Evas_Object *obj, Elm_Sel_Type selection)
{
X11_Cnp_Selection *sel;
_x11_elm_cnp_init();
sel = _x11_selections + selection;
/* No longer this selection: Consider it gone! */
if ((!sel->active) || (sel->widget != obj)) return EINA_TRUE;
if (sel->widget)
evas_object_event_callback_del_full(sel->widget, EVAS_CALLBACK_DEL,
_x11_sel_obj_del, sel);
if (sel->requestwidget)
evas_object_event_callback_del_full(sel->requestwidget, EVAS_CALLBACK_DEL,
_x11_sel_obj_del2, sel);
sel->widget = NULL;
sel->requestwidget = NULL;
sel->loss_cb = NULL;
sel->loss_data = NULL;
sel->active = EINA_FALSE;
ELM_SAFE_FREE(sel->selbuf, free);
sel->clear();
return EINA_TRUE;
}
static Eina_Bool
_x11_elm_cnp_selection_get(Evas_Object *obj, Elm_Sel_Type selection,
Elm_Sel_Format format, Elm_Drop_Cb datacb,
void *udata)
{
Ecore_X_Window xwin = _x11_elm_widget_xwin_get(obj);
X11_Cnp_Selection *sel;
_x11_elm_cnp_init();
sel = _x11_selections + selection;
if (sel->requestwidget)
evas_object_event_callback_del_full(sel->requestwidget, EVAS_CALLBACK_DEL,
_x11_sel_obj_del2, sel);
sel->requestwidget = NULL;
sel->requestformat = format;
sel->requestwidget = obj;
sel->xwin = xwin;
sel->request(xwin, ECORE_X_SELECTION_TARGET_TARGETS);
sel->datacb = datacb;
sel->udata = udata;
evas_object_event_callback_add
(sel->requestwidget, EVAS_CALLBACK_DEL, _x11_sel_obj_del2, sel);
return EINA_TRUE;
}
static Eina_Bool
_x11_elm_drop_target_add(Evas_Object *obj, Elm_Sel_Format format,
Elm_Drag_State entercb, void *enterdata,
Elm_Drag_State leavecb, void *leavedata,
Elm_Drag_Pos poscb, void *posdata,
Elm_Drop_Cb dropcb, void *dropdata)
{
Dropable *dropable = NULL;
Dropable_Cbs *cbs = NULL;
Ecore_X_Window xwin = _x11_elm_widget_xwin_get(obj);
Eina_List *l;
Eina_Bool first = !drops;
Eina_Bool have_drops = EINA_FALSE;
_x11_elm_cnp_init();
/* Is this the first? */
EINA_LIST_FOREACH(drops, l, dropable)
{
if (xwin == _x11_elm_widget_xwin_get(dropable->obj))
{
have_drops = EINA_TRUE;
break;
}
}
dropable = NULL; // In case of error, we don't want to free it
cbs = calloc(1, sizeof(*cbs));
if (!cbs) return EINA_FALSE;
cbs->entercb = entercb;
cbs->enterdata = enterdata;
cbs->leavecb = leavecb;
cbs->leavedata = leavedata;
cbs->poscb = poscb;
cbs->posdata = posdata;
cbs->dropcb = dropcb;
cbs->dropdata = dropdata;
cbs->types = format;
eo_do(obj, eo_base_data_get("__elm_dropable", (void **)&dropable));
if (!dropable)
{
/* Create new drop */
dropable = calloc(1, sizeof(Dropable));
if (!dropable) goto error;
drops = eina_list_append(drops, dropable);
if (!drops) goto error;
dropable->obj = obj;
eo_do(obj, eo_base_data_set("__elm_dropable", dropable, NULL));
}
dropable->cbs_list = eina_inlist_append(dropable->cbs_list, EINA_INLIST_GET(cbs));
evas_object_event_callback_add(obj, EVAS_CALLBACK_DEL,
_all_drop_targets_cbs_del, obj);
if (!have_drops) ecore_x_dnd_aware_set(xwin, EINA_TRUE);
/* TODO BUG: should handle dnd-aware per window, not just the first
* window that requested it! */
/* If not the first: We're done */
if (!first) return EINA_TRUE;
cnp_debug("Adding drop target calls xwin=%#llx\n", (unsigned long long)xwin);
handler_enter = ecore_event_handler_add(ECORE_X_EVENT_XDND_ENTER,
_x11_dnd_enter, NULL);
handler_leave = ecore_event_handler_add(ECORE_X_EVENT_XDND_LEAVE,
_x11_dnd_leave, NULL);
handler_pos = ecore_event_handler_add(ECORE_X_EVENT_XDND_POSITION,
_x11_dnd_position, NULL);
handler_drop = ecore_event_handler_add(ECORE_X_EVENT_XDND_DROP,
_x11_dnd_drop, NULL);
return EINA_TRUE;
error:
free(cbs);
free(dropable);
return EINA_FALSE;
}
static Eina_Bool
_x11_elm_drop_target_del(Evas_Object *obj, Elm_Sel_Format format,
Elm_Drag_State entercb, void *enterdata,
Elm_Drag_State leavecb, void *leavedata,
Elm_Drag_Pos poscb, void *posdata,
Elm_Drop_Cb dropcb, void *dropdata)
{
Dropable *dropable;
Eina_List *l;
Ecore_X_Window xwin;
Eina_Bool have_drops = EINA_FALSE;
_x11_elm_cnp_init();
eo_do(obj, eo_base_data_get("__elm_dropable", (void **)&dropable));
if (dropable)
{
Eina_Inlist *itr;
Dropable_Cbs *cbs_info;
/* Look for the callback in the list */
EINA_INLIST_FOREACH_SAFE(dropable->cbs_list, itr, cbs_info)
if (cbs_info->entercb == entercb && cbs_info->enterdata == enterdata &&
cbs_info->leavecb == leavecb && cbs_info->leavedata == leavedata &&
cbs_info->poscb == poscb && cbs_info->posdata == posdata &&
cbs_info->dropcb == dropcb && cbs_info->dropdata == dropdata &&
cbs_info->types == format)
{
dropable->cbs_list = eina_inlist_remove(dropable->cbs_list,
EINA_INLIST_GET(cbs_info));
free(cbs_info);
}
/* In case no more callbacks are listed for the object */
if (!dropable->cbs_list)
{
drops = eina_list_remove(drops, dropable);
eo_do(obj, eo_base_data_del("__elm_dropable"));
free(dropable);
dropable = NULL;
evas_object_event_callback_del(obj, EVAS_CALLBACK_DEL,
_all_drop_targets_cbs_del);
}
}
else return EINA_FALSE;
/* TODO BUG: we should handle dnd-aware per window, not just the last that released it */
/* If still drops there: All fine.. continue */
if (drops) return EINA_TRUE;
cnp_debug("Disabling DND\n");
xwin = _x11_elm_widget_xwin_get(obj);
EINA_LIST_FOREACH(drops, l, dropable)
{
if (xwin == _x11_elm_widget_xwin_get(dropable->obj))
{
have_drops = EINA_TRUE;
break;
}
}
if (!have_drops) ecore_x_dnd_aware_set(xwin, EINA_FALSE);
if (!drops)
{
ELM_SAFE_FREE(handler_pos, ecore_event_handler_del);
ELM_SAFE_FREE(handler_drop, ecore_event_handler_del);
ELM_SAFE_FREE(handler_enter, ecore_event_handler_del);
ELM_SAFE_FREE(handler_leave, ecore_event_handler_del);
}
ELM_SAFE_FREE(savedtypes.imgfile, free);
return EINA_TRUE;
}
static void
_x11_drag_target_del(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *info __UNUSED__)
{
X11_Cnp_Selection *sel = _x11_selections + ELM_SEL_TYPE_XDND;
if (dragwidget == obj)
{
sel->widget = NULL;
dragwidget = NULL;
}
}
static Eina_Bool
_x11_elm_drag_start(Evas_Object *obj, Elm_Sel_Format format, const char *data,
Elm_Xdnd_Action action,
Elm_Drag_Icon_Create_Cb createicon, void *createdata,
Elm_Drag_Pos dragpos, void *dragdata,
Elm_Drag_Accept acceptcb, void *acceptdata,
Elm_Drag_State dragdone, void *donecbdata)
{
Ecore_X_Window xwin = _x11_elm_widget_xwin_get(obj);
X11_Cnp_Selection *sel;
Elm_Sel_Type xdnd = ELM_SEL_TYPE_XDND;
Ecore_Evas *ee;
int x, y, x2 = 0, y2 = 0, x3, y3;
Evas_Object *icon = NULL;
int w = 0, h = 0;
Ecore_X_Atom actx;
_x11_elm_cnp_init();
cnp_debug("starting drag... %p\n", obj);
if (dragwin)
{
cnp_debug("another obj is dragging...\n");
return EINA_FALSE;
}
ecore_x_dnd_type_set(xwin, "text/uri-list", EINA_TRUE);
sel = _x11_selections + ELM_SEL_TYPE_XDND;
sel->active = EINA_TRUE;
sel->widget = obj;
sel->format = format;
sel->selbuf = data ? strdup(data) : NULL;
sel->action = action;
dragwidget = obj;
dragaction = action;
evas_object_event_callback_add(obj, EVAS_CALLBACK_DEL,
_x11_drag_target_del, obj);
/* TODO BUG: should NEVER have these as globals! They should be per context (window). */
dragposcb = dragpos;
dragposdata = dragdata;
dragacceptcb = acceptcb;
dragacceptdata = acceptdata;
dragdonecb = dragdone;
dragdonedata = donecbdata;
/* TODO BUG: should increase dnd-awareness, in case it's drop target as well. See _x11_drag_mouse_up() */
ecore_x_dnd_aware_set(xwin, EINA_TRUE);
ecore_x_dnd_callback_pos_update_set(_x11_drag_move, NULL);
ecore_x_dnd_self_begin(xwin, (unsigned char *)&xdnd, sizeof(Elm_Sel_Type));
actx = _x11_dnd_action_rev_map(dragaction);
ecore_x_dnd_source_action_set(actx);
ecore_x_pointer_grab(xwin);
handler_up = ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_UP,
_x11_drag_mouse_up,
(void *)(long)xwin);
handler_status = ecore_event_handler_add(ECORE_X_EVENT_XDND_STATUS,
_x11_dnd_status, NULL);
dragwin = elm_win_add(NULL, "Elm-Drag", ELM_WIN_UTILITY);
elm_win_alpha_set(dragwin, EINA_TRUE);
elm_win_override_set(dragwin, EINA_TRUE);
/* dragwin has to be rotated as the main window is */
Evas_Object *win = elm_widget_top_get(obj);
if (win && eo_isa(win, ELM_OBJ_WIN_CLASS))
elm_win_rotation_set(dragwin, elm_win_rotation_get(win));
if (createicon)
{
Evas_Coord xoff = 0, yoff = 0;
icon = createicon(createdata, dragwin, &xoff, &yoff);
if (icon)
{
x2 = xoff;
y2 = yoff;
evas_object_geometry_get(icon, NULL, NULL, &w, &h);
}
}
else
{
icon = elm_icon_add(dragwin);
evas_object_size_hint_weight_set(icon, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(icon, EVAS_HINT_FILL, EVAS_HINT_FILL);
// need to resize
}
elm_win_resize_object_add(dragwin, icon);
/* Position subwindow appropriately */
ee = ecore_evas_ecore_evas_get(evas_object_evas_get(obj));
ecore_evas_geometry_get(ee, &x, &y, NULL, NULL);
x += x2;
y += y2;
dragwin_x_start = dragwin_x_end = x;
dragwin_y_start = dragwin_y_end = y;
evas_object_resize(dragwin, w, h);
evas_object_show(icon);
evas_object_show(dragwin);
evas_object_move(dragwin, x, y);
evas_pointer_canvas_xy_get(evas_object_evas_get(obj), &x3, &y3);
_dragx = x3 - x2;
_dragy = y3 - y2;
return EINA_TRUE;
}
static Eina_Bool
_x11_elm_drag_action_set(Evas_Object *obj, Elm_Xdnd_Action action)
{
Ecore_X_Atom actx;
_x11_elm_cnp_init();
if (!dragwin) return EINA_FALSE;
if (dragwidget != obj) return EINA_FALSE;
if (dragaction == action) return EINA_TRUE;
dragaction = action;
actx = _x11_dnd_action_rev_map(dragaction);
ecore_x_dnd_source_action_set(actx);
return EINA_TRUE;
}
static Eina_Bool
_x11_elm_selection_selection_has_owner(Evas_Object *obj __UNUSED__)
{
_x11_elm_cnp_init();
return !!ecore_x_selection_owner_get(ECORE_X_ATOM_SELECTION_CLIPBOARD);
}
#endif
#ifdef HAVE_ELEMENTARY_WAYLAND
typedef struct _Wl_Cnp_Selection Wl_Cnp_Selection;
struct _Wl_Cnp_Selection
{
char *selbuf;
int buflen;
Evas_Object *widget;
Evas_Object *requestwidget;
void *udata;
Elm_Sel_Type seltype;
Elm_Sel_Format requestformat;
Elm_Drop_Cb datacb;
Elm_Selection_Loss_Cb loss_cb;
void *loss_data;
Elm_Sel_Format format;
Ecore_Wl_Window *win;
Elm_Xdnd_Action action;
Eina_Bool active : 1;
};
static Eina_Bool _wl_elm_cnp_init(void);
static Wl_Cnp_Selection wl_cnp_selection =
{
0, 0, NULL, NULL,
NULL, 0, 0, NULL, NULL, NULL,
0, NULL, 0, EINA_FALSE
};
static void _wl_sel_obj_del2(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__);
static Eina_Bool _wl_elm_cnp_selection_set(Evas_Object *obj __UNUSED__, Elm_Sel_Type selection, Elm_Sel_Format format __UNUSED__, const void *selbuf, size_t buflen);
static Eina_Bool _wl_elm_cnp_selection_get(Evas_Object *obj, Elm_Sel_Type selection, Elm_Sel_Format format __UNUSED__, Elm_Drop_Cb datacb __UNUSED__, void *udata __UNUSED__);
static Eina_Bool _wl_elm_cnp_selection_clear(Evas_Object *obj, Elm_Sel_Type selection);
static Eina_Bool _wl_selection_send(void *udata, int type __UNUSED__, void *event);
static Eina_Bool _wl_selection_receive(void *udata, int type __UNUSED__, void *event);
static Eina_Bool _wl_elm_dnd_init(void);
static Eina_Bool _wl_elm_drop_target_add(Evas_Object *obj, Elm_Sel_Format format, Elm_Drag_State entercb, void *enterdata, Elm_Drag_State leavecb, void *leavedata, Elm_Drag_Pos poscb, void *posdata, Elm_Drop_Cb dropcb, void *dropdata);
static Eina_Bool _wl_elm_drop_target_del(Evas_Object *obj, Elm_Sel_Format format, Elm_Drag_State entercb, void *enterdata, Elm_Drag_State leavecb, void *leavedata, Elm_Drag_Pos poscb, void *posdata, Elm_Drop_Cb dropcb, void *dropdata);
static Eina_Bool _wl_elm_drag_action_set(Evas_Object *obj, Elm_Xdnd_Action action);
static Eina_Bool _wl_elm_drag_start(Evas_Object *obj, Elm_Sel_Format format, const char *data, Elm_Xdnd_Action action, Elm_Drag_Icon_Create_Cb createicon, void *createdata, Elm_Drag_Pos dragpos, void *dragdata, Elm_Drag_Accept acceptcb, void *acceptdata, Elm_Drag_State dragdone, void *donecbdata);
static void _wl_drag_source_del(void *data EINA_UNUSED, Evas *evas EINA_UNUSED, Evas_Object *obj, void *event EINA_UNUSED);
static Eina_Bool _wl_dnd_enter(void *data EINA_UNUSED, int type EINA_UNUSED, void *event);
static Eina_Bool _wl_dnd_leave(void *data EINA_UNUSED, int type EINA_UNUSED, void *event);
static Eina_Bool _wl_dnd_position(void *data EINA_UNUSED, int type EINA_UNUSED, void *event);
static Eina_Bool _wl_dnd_drop(void *data EINA_UNUSED, int type EINA_UNUSED, void *event);
/* static Eina_Bool _wl_dnd_offer(void *data EINA_UNUSED, int type EINA_UNUSED, void *event); */
static Eina_Bool _wl_dnd_send(void *data, int type EINA_UNUSED, void *event);
static Eina_Bool _wl_dnd_receive(void *data, int type EINA_UNUSED, void *event);
static Eina_Bool _wl_dnd_end(void *data EINA_UNUSED, int type EINA_UNUSED, void *event EINA_UNUSED);
static void _wl_dropable_data_handle(Wl_Cnp_Selection *sel, char *data);
static Dropable *_wl_dropable_find(unsigned int win);
static Dropable *_wl_dropable_find_geom(unsigned int win, Evas_Coord x, Evas_Coord y);
static void _wl_dropable_handle(Dropable *drop, Evas_Coord x, Evas_Coord y, Eina_Bool have_obj);
static void _wl_dropable_all_set(unsigned int win, Evas_Coord x, Evas_Coord y, Eina_Bool set);
static Eina_Bool _wl_drops_accept(const char *type);
static unsigned int _wl_elm_widget_window_get(Evas_Object *obj);
static void
_wl_sel_obj_del(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
{
Wl_Cnp_Selection *sel = data;
if (sel->widget == obj) sel->widget = NULL;
if (dragwidget == obj) dragwidget = NULL;
}
static void
_wl_sel_obj_del2(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
{
Wl_Cnp_Selection *sel = data;
if (sel->requestwidget == obj) sel->requestwidget = NULL;
}
static Eina_Bool
_wl_elm_cnp_selection_set(Evas_Object *obj, Elm_Sel_Type selection, Elm_Sel_Format format, const void *selbuf, size_t buflen)
{
Ecore_Wl_Window *win;
Wl_Cnp_Selection *sel = &wl_cnp_selection;
if ((!selbuf) && (format != ELM_SEL_FORMAT_IMAGE))
return elm_object_cnp_selection_clear(obj, selection);
_wl_elm_cnp_init();
win = elm_win_wl_window_get(obj);
if (sel->loss_cb) sel->loss_cb(sel->loss_data, selection);
if (sel->widget)
evas_object_event_callback_del_full(sel->widget,
EVAS_CALLBACK_DEL,
_wl_sel_obj_del, &wl_cnp_selection);
sel->widget = NULL;
sel->active = EINA_TRUE;
sel->seltype = selection;
sel->widget = obj;
sel->win = win;
/* sel->set(win, &selection, sizeof(Elm_Sel_Type)); */
sel->format = format;
sel->loss_cb = NULL;
sel->loss_data = NULL;
evas_object_event_callback_add
(sel->widget, EVAS_CALLBACK_DEL, _wl_sel_obj_del,
&wl_cnp_selection);
if (selbuf)
{
if (format & ELM_SEL_FORMAT_IMAGE)
{
/* FIXME */
// selbuf is actual image data, not text/string
sel->selbuf = malloc(buflen + 1);
if (!sel->selbuf)
{
elm_object_cnp_selection_clear(obj, selection);
return EINA_FALSE;
}
memcpy(sel->selbuf, selbuf, buflen);
sel->selbuf[buflen] = 0;
}
else
{
const char *types[10] = {0, };
int i = -1;
if ((format & ELM_SEL_FORMAT_MARKUP) ||
(format & ELM_SEL_FORMAT_TEXT))
{
types[++i] = "application/x-elementary-markup";
types[++i] = "text/plain";
types[++i] = "text/plain;charset=utf-8";
}
if (format & ELM_SEL_FORMAT_HTML)
{
types[++i] = "text/html";
types[++i] = "text/html;charset=utf-8";
}
if (i < 0) return EINA_FALSE;
ecore_wl_dnd_selection_set(ecore_wl_input_get(), types);
if (sel->selbuf) free(sel->selbuf);
sel->buflen = buflen;
sel->selbuf = strdup((char*)selbuf);
return EINA_TRUE;
}
}
else
sel->selbuf = NULL;
return EINA_FALSE;
}
static Eina_Bool
_wl_elm_cnp_selection_get(Evas_Object *obj, Elm_Sel_Type selection, Elm_Sel_Format format, Elm_Drop_Cb datacb, void *udata)
{
Ecore_Wl_Window *win;
Wl_Cnp_Selection *sel = &wl_cnp_selection;
_wl_elm_cnp_init();
win = elm_win_wl_window_get(obj);
if (sel->requestwidget)
evas_object_event_callback_del_full(sel->requestwidget,
EVAS_CALLBACK_DEL,
_wl_sel_obj_del2, &wl_cnp_selection);
sel->requestwidget = NULL;
sel->requestformat = format;
sel->requestwidget = obj;
sel->win = win;
/* sel->request(win, ECORE_X_SELECTION_TARGET_TARGETS); */
sel->datacb = datacb;
sel->udata = udata;
evas_object_event_callback_add(sel->requestwidget,
EVAS_CALLBACK_DEL, _wl_sel_obj_del2,
&wl_cnp_selection);
if ((selection == ELM_SEL_TYPE_CLIPBOARD) ||
(selection == ELM_SEL_TYPE_PRIMARY) ||
(selection == ELM_SEL_TYPE_SECONDARY))
{
const char *types[10] = {0, };
int i = -1;
if ((format & ELM_SEL_FORMAT_MARKUP) ||
(format & ELM_SEL_FORMAT_TEXT))
{
types[++i] = "application/x-elementary-markup";
types[++i] = "text/plain";
types[++i] = "text/plain;charset=utf-8";
}
if (format & ELM_SEL_FORMAT_HTML)
{
types[++i] = "text/html";
types[++i] = "text/html;charset=utf-8";
}
if (i < 0) return EINA_FALSE;
ecore_wl_dnd_selection_get(ecore_wl_input_get(), *types);
}
return EINA_TRUE;
}
static void
_wl_elm_cnp_selection_loss_callback_set(Evas_Object *obj __UNUSED__, Elm_Sel_Type selection __UNUSED__, Elm_Selection_Loss_Cb func, const void *data)
{
Wl_Cnp_Selection *sel = &wl_cnp_selection;
_wl_elm_cnp_init();
sel->loss_cb = func;
sel->loss_data = (void *)data;
}
static Eina_Bool
_wl_elm_cnp_selection_clear(Evas_Object *obj, Elm_Sel_Type selection __UNUSED__)
{
Wl_Cnp_Selection *sel = &wl_cnp_selection;
_wl_elm_cnp_init();
if ((!sel->active) || (sel->widget != obj))
return EINA_TRUE;
if (sel->widget)
evas_object_event_callback_del_full(sel->widget,
EVAS_CALLBACK_DEL,
_wl_sel_obj_del, &wl_cnp_selection);
if (sel->requestwidget)
evas_object_event_callback_del_full(sel->requestwidget,
EVAS_CALLBACK_DEL,
_wl_sel_obj_del2, &wl_cnp_selection);
sel->widget = NULL;
sel->requestwidget = NULL;
sel->loss_cb = NULL;
sel->loss_data = NULL;
sel->active = EINA_FALSE;
ELM_SAFE_FREE(sel->selbuf, free);
sel->buflen = 0;
/* sel->clear(); */
ecore_wl_dnd_selection_clear(ecore_wl_input_get());
return EINA_TRUE;
}
static Eina_Bool
_wl_selection_send(void *udata, int type __UNUSED__, void *event)
{
char *buf;
int ret, len_remained;
int len_written = 0;
Wl_Cnp_Selection *sel = udata;
Ecore_Wl_Event_Data_Source_Send *ev = event;
_wl_elm_cnp_init();
len_remained = sel->buflen;
buf = sel->selbuf;
while (len_written < sel->buflen)
{
ret = write(ev->fd, buf, len_remained);
if (ret == -1) break;
buf += ret;
len_written += ret;
len_remained -= ret;
}
close(ev->fd);
return ECORE_CALLBACK_PASS_ON;
}
static Eina_Bool
_wl_selection_receive(void *udata, int type __UNUSED__, void *event)
{
Wl_Cnp_Selection *sel = udata;
Ecore_Wl_Event_Selection_Data_Ready *ev = event;
_wl_elm_cnp_init();
if (sel->requestwidget)
{
if (!ev->done)
{
if (sel->seltype == ELM_SEL_TYPE_XDND)
{
Elm_Selection_Data sdata;
Eina_List *l;
Dropable *dropable;
EINA_LIST_FOREACH(drops, l, dropable)
{
if (dropable->obj == sel->requestwidget) break;
dropable = NULL;
}
if (dropable)
{
Dropable_Cbs *cbs;
sdata.x = savedtypes.x;
sdata.y = savedtypes.y;
sdata.format = ELM_SEL_FORMAT_TEXT;
sdata.data = ev->data;
sdata.len = ev->len;
sdata.action = sel->action;
EINA_INLIST_FOREACH(dropable->cbs_list, cbs)
if (cbs->dropcb)
cbs->dropcb(cbs->dropdata, dropable->obj, &sdata);
goto end;
}
}
if (sel->datacb)
{
Elm_Selection_Data sdata;
sdata.x = sdata.y = 0;
sdata.format = ELM_SEL_FORMAT_TEXT;
sdata.data = ev->data;
sdata.len = ev->len;
sdata.action = sel->action;
sel->datacb(sel->udata, sel->widget, &sdata);
}
else
{
char *stripstr, *mkupstr;
stripstr = malloc(ev->len + 1);
if (!stripstr) goto end;
strncpy(stripstr, (char *)ev->data, ev->len);
stripstr[ev->len] = '\0';
mkupstr = _elm_util_text_to_mkup((const char *)stripstr);
/* TODO BUG: should never NEVER assume it's an elm_entry! */
_elm_entry_entry_paste(sel->requestwidget, mkupstr);
free(stripstr);
free(mkupstr);
}
}
else
{
evas_object_event_callback_del_full(sel->requestwidget,
EVAS_CALLBACK_DEL,
_wl_sel_obj_del2, sel);
sel->requestwidget = NULL;
}
}
end:
if (sel->seltype == ELM_SEL_TYPE_XDND)
{
/* FIXME: Send Finished ?? */
}
return ECORE_CALLBACK_PASS_ON;
}
static Eina_Bool
_wl_elm_cnp_init(void)
{
static int _init_count = 0;
if (_init_count > 0) return EINA_TRUE;
_init_count++;
ecore_event_handler_add(ECORE_WL_EVENT_DATA_SOURCE_SEND,
_wl_selection_send, &wl_cnp_selection);
ecore_event_handler_add(ECORE_WL_EVENT_SELECTION_DATA_READY,
_wl_selection_receive, &wl_cnp_selection);
return EINA_TRUE;
}
static Eina_Bool
_wl_elm_dnd_init(void)
{
static int _init_count = 0;
if (_init_count > 0) return EINA_TRUE;
_init_count++;
text_uri = eina_stringshare_add("text/uri-list");
ecore_event_handler_add(ECORE_WL_EVENT_DATA_SOURCE_SEND,
_wl_dnd_send, &wl_cnp_selection);
ecore_event_handler_add(ECORE_WL_EVENT_SELECTION_DATA_READY,
_wl_dnd_receive, &wl_cnp_selection);
ecore_event_handler_add(ECORE_WL_EVENT_DND_END,
_wl_dnd_end, &wl_cnp_selection);
return EINA_TRUE;
}
static Eina_Bool
_wl_elm_drop_target_add(Evas_Object *obj, Elm_Sel_Format format, Elm_Drag_State entercb, void *enterdata, Elm_Drag_State leavecb, void *leavedata, Elm_Drag_Pos poscb, void *posdata, Elm_Drop_Cb dropcb, void *dropdata)
{
Dropable *dropable = NULL;
Dropable_Cbs *cbs = NULL;
Eina_Bool first = !drops;
cbs = calloc(1, sizeof(*cbs));
if (!cbs) return EINA_FALSE;
cbs->entercb = entercb;
cbs->enterdata = enterdata;
cbs->leavecb = leavecb;
cbs->leavedata = leavedata;
cbs->poscb = poscb;
cbs->posdata = posdata;
cbs->dropcb = dropcb;
cbs->dropdata = dropdata;
cbs->types = format;
eo_do(obj, eo_base_data_get("__elm_dropable", (void **)&dropable));
if (!dropable)
{
/* Create new drop */
dropable = calloc(1, sizeof(Dropable));
if (!dropable) goto error;
drops = eina_list_append(drops, dropable);
if (!drops) goto error;
dropable->obj = obj;
eo_do(obj, eo_base_data_set("__elm_dropable", dropable, NULL));
}
dropable->cbs_list = eina_inlist_append(dropable->cbs_list, EINA_INLIST_GET(cbs));
evas_object_event_callback_add(obj, EVAS_CALLBACK_DEL,
_all_drop_targets_cbs_del, obj);
if (first)
{
handler_enter =
ecore_event_handler_add(ECORE_WL_EVENT_DND_ENTER,
_wl_dnd_enter, NULL);
handler_leave =
ecore_event_handler_add(ECORE_WL_EVENT_DND_LEAVE,
_wl_dnd_leave, NULL);
handler_pos =
ecore_event_handler_add(ECORE_WL_EVENT_DND_POSITION,
_wl_dnd_position, NULL);
handler_drop =
ecore_event_handler_add(ECORE_WL_EVENT_DND_DROP,
_wl_dnd_drop, NULL);
}
return EINA_TRUE;
error:
free(cbs);
free(dropable);
return EINA_FALSE;
}
static Eina_Bool
_wl_elm_drop_target_del(Evas_Object *obj, Elm_Sel_Format format,
Elm_Drag_State entercb, void *enterdata,
Elm_Drag_State leavecb, void *leavedata,
Elm_Drag_Pos poscb, void *posdata,
Elm_Drop_Cb dropcb, void *dropdata)
{
Dropable *dropable;
eo_do(obj, eo_base_data_get("__elm_dropable", (void **)&dropable));
if (dropable)
{
Eina_Inlist *itr;
Dropable_Cbs *cbs_info;
/* Look for the callback in the list */
EINA_INLIST_FOREACH_SAFE(dropable->cbs_list, itr, cbs_info)
if (cbs_info->entercb == entercb && cbs_info->enterdata == enterdata &&
cbs_info->leavecb == leavecb && cbs_info->leavedata == leavedata &&
cbs_info->poscb == poscb && cbs_info->posdata == posdata &&
cbs_info->dropcb == dropcb && cbs_info->dropdata == dropdata &&
cbs_info->types == format)
{
dropable->cbs_list = eina_inlist_remove(dropable->cbs_list,
EINA_INLIST_GET(cbs_info));
free(cbs_info);
}
/* In case no more callbacks are listed for the object */
if (!dropable->cbs_list)
{
drops = eina_list_remove(drops, dropable);
eo_do(obj, eo_base_data_del("__elm_dropable"));
free(dropable);
dropable = NULL;
evas_object_event_callback_del(obj, EVAS_CALLBACK_DEL,
_all_drop_targets_cbs_del);
}
}
else return EINA_FALSE;
if (!drops)
{
ELM_SAFE_FREE(handler_pos, ecore_event_handler_del);
ELM_SAFE_FREE(handler_drop, ecore_event_handler_del);
ELM_SAFE_FREE(handler_enter, ecore_event_handler_del);
ELM_SAFE_FREE(handler_leave, ecore_event_handler_del);
}
return EINA_TRUE;
}
static Eina_Bool
_wl_elm_drag_action_set(Evas_Object *obj, Elm_Xdnd_Action action)
{
if (!dragwin) return EINA_FALSE;
if (dragwidget != obj) return EINA_FALSE;
if (dragaction == action) return EINA_TRUE;
dragaction = action;
return EINA_TRUE;
}
static Eina_Bool
_wl_elm_drag_start(Evas_Object *obj, Elm_Sel_Format format EINA_UNUSED, const char *data,
Elm_Xdnd_Action action,
Elm_Drag_Icon_Create_Cb createicon, void *createdata,
Elm_Drag_Pos dragpos, void *dragdata,
Elm_Drag_Accept acceptcb, void *acceptdata,
Elm_Drag_State dragdone, void *donecbdata)
{
Ecore_Evas *ee;
Evas_Object *icon = NULL;
int x, y, x2 = 0, y2 = 0, x3, y3, w = 0, h = 0;
const char *types[2] = { "text/uri-list", NULL };
_wl_elm_dnd_init();
/* if we already have a drag, get out */
if (dragwin) return EINA_FALSE;
ecore_wl_dnd_drag_types_set(ecore_wl_input_get(), types);
/* set the drag data used when a drop occurs */
if (wl_cnp_selection.selbuf) free(wl_cnp_selection.selbuf);
wl_cnp_selection.selbuf = strdup((char*)data);
wl_cnp_selection.buflen = strlen(wl_cnp_selection.selbuf);
/* setup callback to notify if this object gets deleted */
evas_object_event_callback_add(obj, EVAS_CALLBACK_DEL,
_wl_drag_source_del, obj);
dragwidget = obj;
dragaction = action;
dragposcb = dragpos;
dragposdata = dragdata;
dragacceptcb = acceptcb;
dragacceptdata = acceptdata;
dragdonecb = dragdone;
dragdonedata = donecbdata;
dragwin = elm_win_add(NULL, "Elm-Drag", ELM_WIN_DND);
elm_win_alpha_set(dragwin, EINA_TRUE);
elm_win_borderless_set(dragwin, EINA_TRUE);
elm_win_override_set(dragwin, EINA_TRUE);
ecore_wl_window_type_set(elm_win_wl_window_get(dragwin),
ECORE_WL_WINDOW_TYPE_DND);
if (createicon)
{
Evas_Coord xoff = 0, yoff = 0;
icon = createicon(createdata, dragwin, &xoff, &yoff);
if (icon)
{
x2 = xoff;
y2 = yoff;
evas_object_geometry_get(icon, NULL, NULL, &w, &h);
}
}
else
{
icon = elm_icon_add(dragwin);
evas_object_size_hint_weight_set(icon, EVAS_HINT_EXPAND,
EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(icon, EVAS_HINT_FILL, EVAS_HINT_FILL);
}
elm_win_resize_object_add(dragwin, icon);
evas_object_show(icon);
/* Position subwindow appropriately */
ee = ecore_evas_ecore_evas_get(evas_object_evas_get(obj));
ecore_evas_geometry_get(ee, &x, &y, NULL, NULL);
x += x2;
y += y2;
dragwin_x_start = dragwin_x_end = x;
dragwin_y_start = dragwin_y_end = y;
evas_object_move(dragwin, x, y);
evas_object_resize(dragwin, w, h);
evas_object_show(dragwin);
evas_pointer_canvas_xy_get(evas_object_evas_get(obj), &x3, &y3);
_dragx = x3 - x2;
_dragy = y3 - y2;
ecore_wl_dnd_drag_start(ecore_wl_input_get(),
elm_win_wl_window_get(obj),
elm_win_wl_window_get(dragwin),
x3, y3, w, h);
return EINA_TRUE;
}
static void
_wl_drag_source_del(void *data EINA_UNUSED, Evas *evas EINA_UNUSED, Evas_Object *obj, void *event EINA_UNUSED)
{
if (dragwidget == obj)
dragwidget = NULL;
}
static Eina_Bool
_wl_dnd_enter(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
{
Ecore_Wl_Event_Dnd_Enter *ev;
int i = 0;
ev = event;
if (_wl_dropable_find(ev->win))
_wl_dropable_all_set(ev->win, 0, 0, EINA_FALSE);
if ((!ev->num_types) || (!ev->types)) return ECORE_CALLBACK_PASS_ON;
savedtypes.ntypes = ev->num_types;
if (savedtypes.types) free(savedtypes.types);
savedtypes.types = malloc(sizeof(char *) * ev->num_types);
if (!savedtypes.types) return EINA_FALSE;
for (i = 0; i < ev->num_types; i++)
{
savedtypes.types[i] = eina_stringshare_add(ev->types[i]);
if (savedtypes.types[i] == text_uri)
{
savedtypes.textreq = 1;
if (savedtypes.imgfile) free(savedtypes.imgfile);
savedtypes.imgfile = NULL;
}
}
doaccept = EINA_FALSE;
for (i = 0; i < ev->num_types; i++)
{
doaccept = _wl_drops_accept(ev->types[i]);
if (doaccept)
wl_data_offer_accept(ev->offer, ev->serial, ev->types[i]);
else
wl_data_offer_accept(ev->offer, ev->serial, NULL);
}
return ECORE_CALLBACK_PASS_ON;
}
static Eina_Bool
_wl_dnd_leave(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
{
Ecore_Wl_Event_Dnd_Leave *ev;
Dropable *drop;
ev = event;
if ((drop = _wl_dropable_find(ev->win)))
{
_wl_dropable_handle(drop, 0, 0, EINA_FALSE);
_wl_dropable_all_set(ev->win, 0, 0, EINA_FALSE);
}
return ECORE_CALLBACK_PASS_ON;
}
static Eina_Bool
_wl_dnd_position(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
{
Ecore_Wl_Event_Dnd_Position *ev;
Dropable *drop, *dropable_old;
Eina_Bool will_accept = EINA_FALSE;
ev = event;
dragwin_x_end = ev->position.x - _dragx;
dragwin_y_end = ev->position.y - _dragy;
dropable_old = drop = _wl_dropable_find(ev->win);
if (drop)
{
Ecore_Evas *ee;
Evas_Coord ex = 0, ey = 0;
Evas_Coord x = 0, y = 0;
x = ev->position.x;
y = ev->position.y;
ee = ecore_evas_ecore_evas_get(evas_object_evas_get(drop->obj));
ecore_evas_geometry_get(ee, &ex, &ey, NULL, NULL);
x -= ex;
y -= ey;
if ((drop = _wl_dropable_find_geom(ev->win, x, y)))
{
Evas_Coord ox = 0, oy = 0;
int i = 0;
evas_object_geometry_get(drop->obj, &ox, &oy, NULL, NULL);
_wl_dropable_handle(drop, x - ox, y - oy, EINA_TRUE);
for (i = 0; i < savedtypes.ntypes; i++)
{
Dropable_Cbs *cbs;
EINA_INLIST_FOREACH(drop->cbs_list, cbs)
{
switch (cbs->types)
{
case ELM_SEL_FORMAT_TARGETS:
case ELM_SEL_FORMAT_IMAGE:
if ((!strncmp(savedtypes.types[i], "text/uri", 8)) ||
(!strncmp(savedtypes.types[i], "image/", 6)))
{
wl_cnp_selection.requestwidget = drop->obj;
will_accept = EINA_TRUE;
}
break;
default:
break;
}
}
if (will_accept) break;
}
}
else
_wl_dropable_handle(dropable_old, 0, 0, EINA_FALSE);
_wl_dropable_all_set(ev->win, x, y, EINA_TRUE);
}
doaccept = will_accept;
if (dragacceptcb)
dragacceptcb(dragacceptdata, wl_cnp_selection.requestwidget, will_accept);
return ECORE_CALLBACK_PASS_ON;
}
static Eina_Bool
_wl_dnd_drop(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
{
Ecore_Wl_Event_Dnd_Drop *ev;
Dropable *drop;
Ecore_Evas *ee;
Evas_Coord ex = 0, ey = 0;
int i = 0;
ev = event;
if (!(drop = _wl_dropable_find(ev->win)))
return ECORE_CALLBACK_PASS_ON;
savedtypes.x = ev->position.x;
savedtypes.y = ev->position.y;
ee = ecore_evas_ecore_evas_get(evas_object_evas_get(drop->obj));
ecore_evas_geometry_get(ee, &ex, &ey, NULL, NULL);
savedtypes.x -= ex;
savedtypes.y -= ey;
if (!(drop = _wl_dropable_find_geom(ev->win, savedtypes.x, savedtypes.y)))
return ECORE_CALLBACK_PASS_ON;
for (i = 0; i < savedtypes.ntypes; i++)
{
Dropable_Cbs *cbs;
EINA_INLIST_FOREACH(drop->cbs_list, cbs)
{
if ((savedtypes.types[i] == text_uri) &&
(cbs->types & ELM_SEL_FORMAT_MARKUP) &&
(cbs->types & ELM_SEL_FORMAT_IMAGE))
{
wl_cnp_selection.requestwidget = drop->obj;
evas_object_event_callback_add(wl_cnp_selection.requestwidget,
EVAS_CALLBACK_DEL,
_wl_sel_obj_del2,
&wl_cnp_selection);
ecore_wl_dnd_drag_get(ecore_wl_input_get(), text_uri);
return ECORE_CALLBACK_PASS_ON;
}
}
}
return ECORE_CALLBACK_PASS_ON;
}
static Eina_Bool
_wl_dnd_send(void *data, int type EINA_UNUSED, void *event)
{
char *buf;
int ret, len_remained;
int len_written = 0;
Wl_Cnp_Selection *sel;
Ecore_Wl_Event_Data_Source_Send *ev;
ev = event;
sel = data;
len_remained = sel->buflen;
buf = sel->selbuf;
while (len_written < sel->buflen)
{
ret = write(ev->fd, buf, len_remained);
if (ret == -1) break;
buf += ret;
len_written += ret;
len_remained -= ret;
}
close(ev->fd);
return ECORE_CALLBACK_PASS_ON;
}
static Eina_Bool
_wl_dnd_receive(void *data, int type EINA_UNUSED, void *event)
{
Wl_Cnp_Selection *sel;
Ecore_Wl_Event_Selection_Data_Ready *ev;
ev = event;
sel = data;
if (sel->requestwidget)
{
if (!ev->done)
_wl_dropable_data_handle(sel, ev->data);
else
{
evas_object_event_callback_del_full(sel->requestwidget,
EVAS_CALLBACK_DEL,
_wl_sel_obj_del2, sel);
sel->requestwidget = NULL;
}
}
return ECORE_CALLBACK_PASS_ON;
}
static Eina_Bool
_wl_dnd_end(void *data EINA_UNUSED, int type EINA_UNUSED, void *event EINA_UNUSED)
{
/* Ecore_Wl_Event_Dnd_End *ev; */
/* ev = event; */
if (dragdonecb) dragdonecb(dragdonedata, dragwidget);
if (dragwin)
{
if (!doaccept)
{
/* Commit animation when drag cancelled */
/* Record final position of dragwin, then do animation */
ecore_animator_timeline_add(0.3, _drag_cancel_animate, dragwin);
}
else
{
/* No animation drop was committed */
evas_object_del(dragwin);
}
dragwin = NULL; /* if not freed here, free in end of anim */
}
dragdonecb = NULL;
dragacceptcb = NULL;
dragposcb = NULL;
dragwidget = NULL;
doaccept = EINA_FALSE;
ecore_wl_input_ungrab(ecore_wl_input_get());
return ECORE_CALLBACK_PASS_ON;
}
static void
_wl_dropable_data_handle(Wl_Cnp_Selection *sel, char *data)
{
Dropable *drop;
unsigned int win = 0;
char *p, *s = NULL, *entrytag;
Elm_Selection_Data sdata;
static const char *tagstring =
"<item absize=240x180 href=file://%s></item>";
win = _wl_elm_widget_window_get(sel->requestwidget);
drop = _wl_dropable_find_geom(win, savedtypes.x, savedtypes.y);
p = data;
if ((!strncmp(p, "file://", 7)) || (p[0] == '/'))
{
int len = 0;
len = sel->buflen;
if (!strncmp(p, "file://", 7))
{
p += 7;
len -= 7;
}
if (!(s = malloc(len + 1))) return;
memcpy(s, p, len);
s[len] = 0;
}
if (savedtypes.textreq)
{
savedtypes.textreq = 0;
savedtypes.imgfile = s;
}
sdata.x = savedtypes.x;
sdata.y = savedtypes.y;
if (!savedtypes.imgfile) return;
Dropable_Cbs *cbs;
Eina_Inlist *itr;
EINA_INLIST_FOREACH_SAFE(drop->cbs_list, itr, cbs)
{
/* If it's markup that also supports images */
if ((cbs->types & ELM_SEL_FORMAT_MARKUP) &&
(cbs->types & ELM_SEL_FORMAT_IMAGE))
{
int l = 0;
sdata.format = ELM_SEL_FORMAT_MARKUP;
l = strlen(tagstring) + strlen(savedtypes.imgfile);
entrytag = alloca(l + 1);
snprintf(entrytag, l + 1, tagstring, savedtypes.imgfile);
sdata.data = entrytag;
if (cbs->dropcb) cbs->dropcb(cbs->dropdata, drop->obj, &sdata);
ecore_wl_dnd_drag_end(ecore_wl_input_get());
}
else if (cbs->types & ELM_SEL_FORMAT_IMAGE)
{
sdata.format = ELM_SEL_FORMAT_IMAGE;
sdata.data = (char *)savedtypes.imgfile;
if (cbs->dropcb) cbs->dropcb(cbs->dropdata, drop->obj, &sdata);
ecore_wl_dnd_drag_end(ecore_wl_input_get());
}
}
ELM_SAFE_FREE(savedtypes.imgfile, free);
}
static Dropable *
_wl_dropable_find(unsigned int win)
{
Eina_List *l;
Dropable *dropable;
if (!drops) return NULL;
EINA_LIST_FOREACH(drops, l, dropable)
if (_wl_elm_widget_window_get(dropable->obj) == win)
return dropable;
return NULL;
}
static Dropable *
_wl_dropable_find_geom(unsigned int win, Evas_Coord x, Evas_Coord y)
{
Eina_List *l;
Dropable *drop;
EINA_LIST_FOREACH(drops, l, drop)
{
if (_wl_elm_widget_window_get(drop->obj) == win)
{
Evas_Coord ox, oy, ow, oh;
evas_object_geometry_get(drop->obj, &ox, &oy, &ow, &oh);
if ((x >= ox) && (y >= oy) && (x < (ox + ow)) && (y < (oy + oh)))
return drop;
}
}
return NULL;
}
static void
_wl_dropable_handle(Dropable *drop, Evas_Coord x, Evas_Coord y, Eina_Bool have_obj)
{
Dropable *last = NULL;
Dropable_Cbs *cbs;
Eina_Inlist *itr;
if (drop->last.in)
last = _wl_dropable_find_geom(_wl_elm_widget_window_get(drop->obj),
drop->last.x, drop->last.y);
if ((have_obj) && (last == drop))
{
EINA_INLIST_FOREACH_SAFE(drop->cbs_list, itr, cbs)
if (cbs->poscb)
cbs->poscb(cbs->posdata, drop->obj, x, y, dragaction);
}
else if ((have_obj) && (!last))
{
EINA_INLIST_FOREACH_SAFE(drop->cbs_list, itr, cbs)
if (cbs->entercb)
cbs->entercb(cbs->enterdata, drop->obj);
EINA_INLIST_FOREACH_SAFE(drop->cbs_list, itr, cbs)
if (cbs->poscb)
cbs->poscb(cbs->posdata, drop->obj, x, y, dragaction);
}
else if ((!have_obj) && (last))
{
EINA_INLIST_FOREACH_SAFE(drop->cbs_list, itr, cbs)
if (cbs->leavecb)
cbs->leavecb(cbs->leavedata, drop->obj);
}
else if (have_obj)
{
EINA_INLIST_FOREACH_SAFE(drop->cbs_list, itr, cbs)
if (cbs->entercb)
cbs->entercb(cbs->enterdata, drop->obj);
if (last)
{
drop = last;
EINA_INLIST_FOREACH_SAFE(drop->cbs_list, itr, cbs)
if (cbs->leavecb)
cbs->leavecb(cbs->leavedata, drop->obj);
}
}
}
static void
_wl_dropable_all_set(unsigned int win, Evas_Coord x, Evas_Coord y, Eina_Bool set)
{
Eina_List *l;
Dropable *dropable;
EINA_LIST_FOREACH(drops, l, dropable)
{
if (_wl_elm_widget_window_get(dropable->obj) == win)
{
dropable->last.x = x;
dropable->last.y = y;
dropable->last.in = set;
}
}
}
static Eina_Bool
_wl_drops_accept(const char *type)
{
Eina_List *l;
Dropable *drop;
Eina_Bool will_accept = EINA_FALSE;
EINA_LIST_FOREACH(drops, l, drop)
{
Dropable_Cbs *cbs;
EINA_INLIST_FOREACH(drop->cbs_list, cbs)
{
switch (cbs->types)
{
case ELM_SEL_FORMAT_TARGETS:
case ELM_SEL_FORMAT_IMAGE:
if ((!strncmp(type, "text/uri", 8)) ||
(!strncmp(type, "image/", 6)))
{
wl_cnp_selection.requestwidget = drop->obj;
return EINA_TRUE;
}
break;
case ELM_SEL_FORMAT_NONE:
break;
case ELM_SEL_FORMAT_TEXT:
break;
case ELM_SEL_FORMAT_MARKUP:
break;
case ELM_SEL_FORMAT_VCARD:
break;
case ELM_SEL_FORMAT_HTML:
break;
}
}
}
return will_accept;
}
static unsigned int
_wl_elm_widget_window_get(Evas_Object *obj)
{
Evas_Object *top;
Ecore_Wl_Window *win = NULL;
top = elm_widget_top_get(obj);
if (!top) top = elm_widget_top_get(elm_widget_parent_widget_get(obj));
if (top) win = elm_win_wl_window_get(top);
if (!win)
{
Ecore_Evas *ee;
Evas *evas;
if (!(evas = evas_object_evas_get(obj)))
return 0;
if (!(ee = ecore_evas_ecore_evas_get(evas)))
return 0;
win = ecore_evas_wayland_window_get(ee);
}
return ecore_wl_window_id_get(win);
}
#endif
////////////////////////////////////////////////////////////////////////////
// for local (Within 1 app/process) cnp (used by fb as fallback
////////////////////////////////////////////////////////////////////////////
#if 1
typedef struct _Local_Selinfo Local_Selinfo;
struct _Local_Selinfo
{
Elm_Sel_Format format;
struct {
char *buf;
size_t size;
} sel;
struct {
Evas_Object *obj;
Elm_Drop_Cb func;
void *data;
Ecore_Job *job;
} get;
};
// for ELM_SEL_TYPE_PRIMARY, ELM_SEL_TYPE_SECONDARY, ELM_SEL_TYPE_XDND,
// ELM_SEL_TYPE_CLIPBOARD
static Local_Selinfo _local_selinfo[4];
static void _local_get_job(void *data);
static Eina_Bool _local_elm_cnp_init(void);
static Eina_Bool _local_elm_cnp_selection_set(Evas_Object *obj __UNUSED__, Elm_Sel_Type selection, Elm_Sel_Format format, const void *selbuf, size_t buflen);
static void _local_elm_cnp_selection_loss_callback_set(Evas_Object *obj __UNUSED__, Elm_Sel_Type selection __UNUSED__, Elm_Selection_Loss_Cb func __UNUSED__, const void *data __UNUSED__);
static Eina_Bool _local_elm_object_cnp_selection_clear(Evas_Object *obj __UNUSED__, Elm_Sel_Type selection);
static Eina_Bool _local_elm_cnp_selection_get(Evas_Object *obj, Elm_Sel_Type selection, Elm_Sel_Format format __UNUSED__, Elm_Drop_Cb datacb, void *udata);
static Eina_Bool _local_elm_drop_target_add(Evas_Object *obj __UNUSED__, Elm_Sel_Format format __UNUSED__,
Elm_Drag_State entercb __UNUSED__, void *enterdata __UNUSED__,
Elm_Drag_State leavecb __UNUSED__, void *leavedata __UNUSED__,
Elm_Drag_Pos poscb __UNUSED__, void *posdata __UNUSED__,
Elm_Drop_Cb dropcb __UNUSED__, void *dropdata __UNUSED__);
static Eina_Bool _local_elm_drop_target_del(Evas_Object *obj __UNUSED__);
static Eina_Bool _local_elm_drag_start(Evas_Object *obj __UNUSED__,
Elm_Sel_Format format __UNUSED__,
const char *data __UNUSED__,
Elm_Xdnd_Action action __UNUSED__,
Elm_Drag_Icon_Create_Cb createicon __UNUSED__,
void *createdata __UNUSED__,
Elm_Drag_Pos dragpos __UNUSED__,
void *dragdata __UNUSED__,
Elm_Drag_Accept acceptcb __UNUSED__,
void *acceptdata __UNUSED__,
Elm_Drag_State dragdone __UNUSED__,
void *donecbdata __UNUSED__);
static Eina_Bool _local_elm_selection_selection_has_owner(Evas_Object *obj __UNUSED__);
static void
_local_get_job(void *data)
{
Local_Selinfo *info = data;
Elm_Selection_Data ev;
info->get.job = NULL;
ev.x = 0;
ev.y = 0;
ev.format = info->format;
ev.data = info->sel.buf;
ev.len = info->sel.size;
ev.action = ELM_XDND_ACTION_UNKNOWN;
if (info->get.func)
info->get.func(info->get.data, info->get.obj, &ev);
}
static Eina_Bool
_local_elm_cnp_init(void)
{
static int _init_count = 0;
if (_init_count > 0) return EINA_TRUE;
_init_count++;
memset(&(_local_selinfo), 0, sizeof(_local_selinfo));
return EINA_TRUE;
}
static Eina_Bool
_local_elm_cnp_selection_set(Evas_Object *obj __UNUSED__,
Elm_Sel_Type selection, Elm_Sel_Format format,
const void *selbuf, size_t buflen)
{
_local_elm_cnp_init();
if (_local_selinfo[selection].sel.buf)
free(_local_selinfo[selection].sel.buf);
_local_selinfo[selection].format = format;
_local_selinfo[selection].sel.buf = malloc(buflen + 1);
if (_local_selinfo[selection].sel.buf)
{
memcpy(_local_selinfo[selection].sel.buf, selbuf, buflen);
_local_selinfo[selection].sel.buf[buflen] = 0;
_local_selinfo[selection].sel.size = buflen;
}
else
_local_selinfo[selection].sel.size = 0;
return EINA_TRUE;
}
static void
_local_elm_cnp_selection_loss_callback_set(Evas_Object *obj __UNUSED__,
Elm_Sel_Type selection __UNUSED__,
Elm_Selection_Loss_Cb func __UNUSED__,
const void *data __UNUSED__)
{
_local_elm_cnp_init();
// this doesnt need to do anything as we never lose selection to anyone
// as thisis local
}
static Eina_Bool
_local_elm_object_cnp_selection_clear(Evas_Object *obj __UNUSED__,
Elm_Sel_Type selection)
{
_local_elm_cnp_init();
if (_local_selinfo[selection].sel.buf)
free(_local_selinfo[selection].sel.buf);
_local_selinfo[selection].sel.buf = NULL;
_local_selinfo[selection].sel.size = 0;
return EINA_TRUE;
}
static Eina_Bool
_local_elm_cnp_selection_get(Evas_Object *obj,
Elm_Sel_Type selection,
Elm_Sel_Format format __UNUSED__,
Elm_Drop_Cb datacb, void *udata)
{
_local_elm_cnp_init();
if (_local_selinfo[selection].get.job)
ecore_job_del(_local_selinfo[selection].get.job);
_local_selinfo[selection].get.obj = obj;
_local_selinfo[selection].get.func = datacb;
_local_selinfo[selection].get.data = udata;
_local_selinfo[selection].get.job =
ecore_job_add(_local_get_job, &(_local_selinfo[selection]));
return EINA_TRUE;
}
static Eina_Bool
_local_elm_drop_target_add(Evas_Object *obj __UNUSED__,
Elm_Sel_Format format __UNUSED__,
Elm_Drag_State entercb __UNUSED__,
void *enterdata __UNUSED__,
Elm_Drag_State leavecb __UNUSED__,
void *leavedata __UNUSED__,
Elm_Drag_Pos poscb __UNUSED__,
void *posdata __UNUSED__,
Elm_Drop_Cb dropcb __UNUSED__,
void *dropdata __UNUSED__)
{
// XXX: implement me
_local_elm_cnp_init();
return EINA_FALSE;
}
static Eina_Bool
_local_elm_drop_target_del(Evas_Object *obj __UNUSED__)
{
// XXX: implement me
_local_elm_cnp_init();
return EINA_FALSE;
}
static Eina_Bool
_local_elm_drag_start(Evas_Object *obj __UNUSED__,
Elm_Sel_Format format __UNUSED__,
const char *data __UNUSED__,
Elm_Xdnd_Action action __UNUSED__,
Elm_Drag_Icon_Create_Cb createicon __UNUSED__,
void *createdata __UNUSED__,
Elm_Drag_Pos dragpos __UNUSED__,
void *dragdata __UNUSED__,
Elm_Drag_Accept acceptcb __UNUSED__,
void *acceptdata __UNUSED__,
Elm_Drag_State dragdone __UNUSED__,
void *donecbdata __UNUSED__)
{
// XXX: implement me
_local_elm_cnp_init();
return EINA_FALSE;
}
static Eina_Bool
_local_elm_drag_action_set(Evas_Object *obj __UNUSED__,
Elm_Xdnd_Action action __UNUSED__)
{
// XXX: implement me
_local_elm_cnp_init();
return EINA_FALSE;
}
static Eina_Bool
_local_elm_selection_selection_has_owner(Evas_Object *obj __UNUSED__)
{
_local_elm_cnp_init();
if (_local_selinfo[ELM_SEL_TYPE_CLIPBOARD].sel.buf) return EINA_TRUE;
return EINA_FALSE;
}
#endif
// common internal funcs
////////////////////////////////////////////////////////////////////////////
static Eina_Bool
_elm_cnp_init(void)
{
if (_elm_cnp_init_count > 0) return EINA_TRUE;
_elm_cnp_init_count++;
text_uri = eina_stringshare_add("text/uri-list");
return EINA_TRUE;
}
/* TODO: this should not be an actual tempfile, but rather encode the object
* as http://dataurl.net/ if it's an image or similar. Evas should support
* decoding it as memfile. */
static Tmp_Info *
_tempfile_new(int size)
{
#ifdef HAVE_MMAN_H
Tmp_Info *info;
const char *tmppath;
mode_t cur_umask;
int len;
info = calloc(1, sizeof(Tmp_Info));
if (!info) return NULL;
tmppath = getenv("TMP");
if (!tmppath) tmppath = P_tmpdir;
len = snprintf(NULL, 0, "%s/%sXXXXXX", tmppath, "elmcnpitem-");
if (len < 0) goto on_error;
len++;
info->filename = malloc(len);
if (!info->filename) goto on_error;
snprintf(info->filename,len,"%s/%sXXXXXX", tmppath, "elmcnpitem-");
cur_umask = umask(S_IRWXO | S_IRWXG);
info->fd = mkstemp(info->filename);
umask(cur_umask);
if (info->fd < 0) goto on_error;
# ifdef __linux__
{
char *tmp;
/* And before someone says anything see POSIX 1003.1-2008 page 400 */
long pid;
pid = (long)getpid();
/* Use pid instead of /proc/self: That way if can be passed around */
len = snprintf(NULL,0,"/proc/%li/fd/%i", pid, info->fd);
len++;
tmp = malloc(len);
if (tmp)
{
snprintf(tmp,len, "/proc/%li/fd/%i", pid, info->fd);
unlink(info->filename);
free(info->filename);
info->filename = tmp;
}
}
# endif
cnp_debug("filename is %s\n", info->filename);
if (size < 1) goto on_error;
/* Map it in */
if (ftruncate(info->fd, size))
{
perror("ftruncate");
goto on_error;
}
eina_mmap_safety_enabled_set(EINA_TRUE);
info->map = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_SHARED, info->fd, 0);
if (info->map == MAP_FAILED)
{
perror("mmap");
goto on_error;
}
return info;
on_error:
if (info->fd >= 0) close(info->fd);
info->fd = -1;
/* Set map to NULL and return */
info->map = NULL;
info->len = 0;
free(info->filename);
free(info);
return NULL;
#else
(void) size;
return NULL;
#endif
}
static int
_tmpinfo_free(Tmp_Info *info)
{
if (!info) return 0;
free(info->filename);
free(info);
return 0;
}
static Eina_Bool
_pasteimage_append(char *file, Evas_Object *entry)
{
char *entrytag;
int len;
/* TODO BUG: shouldn't define absize=240x180. Prefer data:// instead of href:// -- may need support for evas. See http://dataurl.net/ */
static const char *tagstring = "<item absize=240x180 href=file://%s></item>";
if ((!file) || (!entry)) return EINA_FALSE;
len = strlen(tagstring)+strlen(file);
entrytag = alloca(len + 1);
snprintf(entrytag, len + 1, tagstring, file);
/* TODO BUG: should never NEVER assume it's an elm_entry! */
_elm_entry_entry_paste(entry, entrytag);
return EINA_TRUE;
}
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
// common exposed funcs
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
EAPI Eina_Bool
elm_cnp_selection_set(Evas_Object *obj, Elm_Sel_Type selection,
Elm_Sel_Format format, const void *selbuf, size_t buflen)
{
if (selection > ELM_SEL_TYPE_CLIPBOARD) return EINA_FALSE;
if (!_elm_cnp_init_count) _elm_cnp_init();
#ifdef HAVE_ELEMENTARY_X
if (_x11_elm_widget_xwin_get(obj))
return _x11_elm_cnp_selection_set(obj, selection, format, selbuf, buflen);
#endif
#ifdef HAVE_ELEMENTARY_WAYLAND
if (elm_win_wl_window_get(obj))
return _wl_elm_cnp_selection_set(obj, selection, format, selbuf, buflen);
#endif
return _local_elm_cnp_selection_set(obj, selection, format, selbuf, buflen);
}
EAPI void
elm_cnp_selection_loss_callback_set(Evas_Object *obj, Elm_Sel_Type selection,
Elm_Selection_Loss_Cb func,
const void *data)
{
if (selection > ELM_SEL_TYPE_CLIPBOARD) return;
if (!_elm_cnp_init_count) _elm_cnp_init();
#ifdef HAVE_ELEMENTARY_X
if (_x11_elm_widget_xwin_get(obj))
_x11_elm_cnp_selection_loss_callback_set(obj, selection, func, data);
#endif
#ifdef HAVE_ELEMENTARY_WAYLAND
if (elm_win_wl_window_get(obj))
_wl_elm_cnp_selection_loss_callback_set(obj, selection, func, data);
#endif
_local_elm_cnp_selection_loss_callback_set(obj, selection, func, data);
}
EAPI Eina_Bool
elm_object_cnp_selection_clear(Evas_Object *obj, Elm_Sel_Type selection)
{
if (selection > ELM_SEL_TYPE_CLIPBOARD) return EINA_FALSE;
if (!_elm_cnp_init_count) _elm_cnp_init();
#ifdef HAVE_ELEMENTARY_X
if (_x11_elm_widget_xwin_get(obj))
return _x11_elm_object_cnp_selection_clear(obj, selection);
#endif
#ifdef HAVE_ELEMENTARY_WAYLAND
if (elm_win_wl_window_get(obj))
return _wl_elm_cnp_selection_clear(obj, selection);
#endif
return _local_elm_object_cnp_selection_clear(obj, selection);
}
EAPI Eina_Bool
elm_cnp_selection_get(Evas_Object *obj, Elm_Sel_Type selection,
Elm_Sel_Format format, Elm_Drop_Cb datacb, void *udata)
{
if (selection > ELM_SEL_TYPE_CLIPBOARD) return EINA_FALSE;
if (!_elm_cnp_init_count) _elm_cnp_init();
#ifdef HAVE_ELEMENTARY_X
if (_x11_elm_widget_xwin_get(obj))
return _x11_elm_cnp_selection_get(obj, selection, format, datacb, udata);
#endif
#ifdef HAVE_ELEMENTARY_WAYLAND
if (elm_win_wl_window_get(obj))
return _wl_elm_cnp_selection_get(obj, selection, format, datacb, udata);
#endif
return _local_elm_cnp_selection_get(obj, selection, format, datacb, udata);
}
////////////////////////////////////////////////////////////////////////////
/**
* Add a widget as drop target.
*/
EAPI Eina_Bool
elm_drop_target_add(Evas_Object *obj, Elm_Sel_Format format,
Elm_Drag_State entercb, void *enterdata,
Elm_Drag_State leavecb, void *leavedata,
Elm_Drag_Pos poscb, void *posdata,
Elm_Drop_Cb dropcb, void *dropdata)
{
if (!_elm_cnp_init_count) _elm_cnp_init();
#ifdef HAVE_ELEMENTARY_X
if (_x11_elm_widget_xwin_get(obj))
return _x11_elm_drop_target_add(obj, format, entercb, enterdata,
leavecb, leavedata, poscb, posdata,
dropcb, dropdata);
#endif
#ifdef HAVE_ELEMENTARY_WAYLAND
return _wl_elm_drop_target_add(obj, format, entercb, enterdata,
leavecb, leavedata, poscb, posdata,
dropcb, dropdata);
#endif
return _local_elm_drop_target_add(obj, format, entercb, enterdata,
leavecb, leavedata, poscb, posdata,
dropcb, dropdata);
}
EAPI Eina_Bool
elm_drop_target_del(Evas_Object *obj, Elm_Sel_Format format,
Elm_Drag_State entercb, void *enterdata,
Elm_Drag_State leavecb, void *leavedata,
Elm_Drag_Pos poscb, void *posdata,
Elm_Drop_Cb dropcb, void *dropdata)
{
if (!_elm_cnp_init_count) _elm_cnp_init();
#ifdef HAVE_ELEMENTARY_X
if (_x11_elm_widget_xwin_get(obj))
return _x11_elm_drop_target_del(obj, format, entercb, enterdata,
leavecb, leavedata, poscb, posdata, dropcb, dropdata);
#endif
#ifdef HAVE_ELEMENTARY_WAYLAND
return _wl_elm_drop_target_del(obj, format, entercb, enterdata,
leavecb, leavedata, poscb, posdata, dropcb, dropdata);
#endif
return _local_elm_drop_target_del(obj);
}
EAPI Eina_Bool
elm_drag_start(Evas_Object *obj, Elm_Sel_Format format, const char *data,
Elm_Xdnd_Action action,
Elm_Drag_Icon_Create_Cb createicon, void *createdata,
Elm_Drag_Pos dragpos, void *dragdata,
Elm_Drag_Accept acceptcb, void *acceptdata,
Elm_Drag_State dragdone, void *donecbdata)
{
if (!_elm_cnp_init_count) _elm_cnp_init();
#ifdef HAVE_ELEMENTARY_X
if (_x11_elm_widget_xwin_get(obj))
return _x11_elm_drag_start(obj, format, data, action,
createicon, createdata,
dragpos, dragdata,
acceptcb, acceptdata,
dragdone, donecbdata);
#endif
#ifdef HAVE_ELEMENTARY_WAYLAND
return _wl_elm_drag_start(obj, format, data, action,
createicon, createdata,
dragpos, dragdata,
acceptcb, acceptdata,
dragdone, donecbdata);
#endif
return _local_elm_drag_start(obj, format, data, action,
createicon, createdata,
dragpos, dragdata,
acceptcb, acceptdata,
dragdone, donecbdata);
}
EAPI Eina_Bool
elm_drag_action_set(Evas_Object *obj, Elm_Xdnd_Action action)
{
if (!_elm_cnp_init_count) _elm_cnp_init();
#ifdef HAVE_ELEMENTARY_X
if (_x11_elm_widget_xwin_get(obj))
return _x11_elm_drag_action_set(obj, action);
#endif
#ifdef HAVE_ELEMENTARY_WAYLAND
return _wl_elm_drag_action_set(obj, action);
#endif
return _local_elm_drag_action_set(obj, action);
}
EAPI Eina_Bool
elm_selection_selection_has_owner(Evas_Object *obj)
{
if (!_elm_cnp_init_count) _elm_cnp_init();
#ifdef HAVE_ELEMENTARY_X
if (_x11_elm_widget_xwin_get(obj))
return _x11_elm_selection_selection_has_owner(obj);
#endif
#ifdef HAVE_ELEMENTARY_WAYLAND
if (elm_win_wl_window_get(obj))
return ecore_wl_dnd_selection_owner_has(ecore_wl_input_get());
#endif
return _local_elm_selection_selection_has_owner(obj);
}
/* START - Support elm containers for Drag and Drop */
/* START - Support elm containers for Drop */
static int
_drop_item_container_cmp(const void *d1,
const void *d2)
{
const Item_Container_Drop_Info *st = d1;
return (((uintptr_t) (st->obj)) - ((uintptr_t) d2));
}
static void
_elm_item_container_pos_cb(void *data, Evas_Object *obj, Evas_Coord x, Evas_Coord y, Elm_Xdnd_Action action)
{ /* obj is the container pointer */
Elm_Object_Item *it = NULL;
int xposret = 0;
int yposret = 0;
Item_Container_Drop_Info *st =
eina_list_search_unsorted(cont_drop_tg, _drop_item_container_cmp, obj);
if (st && st->poscb)
{ /* Call container drop func with specific item pointer */
int xo = 0;
int yo = 0;
eo_do(obj, evas_obj_position_get(&xo, &yo));
if (st->itemgetcb)
it = st->itemgetcb(obj, x+xo, y+yo, &xposret, &yposret);
st->poscb(data, obj, it, x, y, xposret, yposret, action);
}
}
static Eina_Bool
_elm_item_container_drop_cb(void *data, Evas_Object *obj , Elm_Selection_Data *ev)
{ /* obj is the container pointer */
Elm_Object_Item *it = NULL;
int xposret = 0;
int yposret = 0;
Item_Container_Drop_Info *st =
eina_list_search_unsorted(cont_drop_tg, _drop_item_container_cmp, obj);
if (st && st->dropcb)
{ /* Call container drop func with specific item pointer */
int xo = 0;
int yo = 0;
eo_do(obj, evas_obj_position_get(&xo, &yo));
if (st->itemgetcb)
it = st->itemgetcb(obj, ev->x+xo, ev->y+yo, &xposret, &yposret);
return st->dropcb(data, obj, it, ev, xposret, yposret);
}
return EINA_FALSE;
}
static Eina_Bool
elm_drop_item_container_del_internal(Evas_Object *obj, Eina_Bool full)
{
Item_Container_Drop_Info *st =
eina_list_search_unsorted(cont_drop_tg, _drop_item_container_cmp, obj);
if (st)
{
// temp until st is stored inside data of obj.
_all_drop_targets_cbs_del(NULL, NULL, obj, NULL);
st->itemgetcb= NULL;
st->poscb = NULL;
st->dropcb = NULL;
if (full)
{
cont_drop_tg = eina_list_remove(cont_drop_tg, st);
free(st);
}
return EINA_TRUE;
}
return EINA_FALSE;
}
EAPI Eina_Bool
elm_drop_item_container_del(Evas_Object *obj)
{
return elm_drop_item_container_del_internal(obj, EINA_TRUE);
}
EAPI Eina_Bool
elm_drop_item_container_add(Evas_Object *obj,
Elm_Sel_Format format,
Elm_Xy_Item_Get_Cb itemgetcb,
Elm_Drag_State entercb, void *enterdata,
Elm_Drag_State leavecb, void *leavedata,
Elm_Drag_Item_Container_Pos poscb, void *posdata,
Elm_Drop_Item_Container_Cb dropcb, void *dropdata)
{
Item_Container_Drop_Info *st;
if (elm_drop_item_container_del_internal(obj, EINA_FALSE))
{ /* Updating info of existing obj */
st = eina_list_search_unsorted(cont_drop_tg, _drop_item_container_cmp, obj);
if (!st) return EINA_FALSE;
}
else
{
st = calloc(1, sizeof(*st));
if (!st) return EINA_FALSE;
st->obj = obj;
cont_drop_tg = eina_list_append(cont_drop_tg, st);
}
st->itemgetcb = itemgetcb;
st->poscb = poscb;
st->dropcb = dropcb;
elm_drop_target_add(obj, format,
entercb, enterdata,
leavecb, leavedata,
_elm_item_container_pos_cb, posdata,
_elm_item_container_drop_cb, dropdata);
return EINA_TRUE;
}
/* END - Support elm containers for Drop */
/* START - Support elm containers for Drag */
static int
_drag_item_container_cmp(const void *d1,
const void *d2)
{
const Item_Container_Drag_Info *st = d1;
return (((uintptr_t) (st->obj)) - ((uintptr_t) d2));
}
static void
_cont_drag_done_cb(void *data, Evas_Object *obj __UNUSED__)
{
Item_Container_Drag_Info *st = data;
elm_widget_scroll_freeze_pop(st->obj);
if (st->user_info.dragdone)
st->user_info.dragdone(st->user_info.donecbdata, dragwidget, doaccept);
}
static Eina_Bool
_cont_obj_drag_start(void *data)
{ /* Start a drag-action when timer expires */
cnp_debug("In\n");
Item_Container_Drag_Info *st = data;
st->tm = NULL;
Elm_Drag_User_Info *info = &st->user_info;
if (info->dragstart) info->dragstart(info->startcbdata, st->obj);
elm_widget_scroll_freeze_push(st->obj);
evas_object_event_callback_del_full
(st->obj, EVAS_CALLBACK_MOUSE_MOVE, _cont_obj_mouse_move, st);
elm_drag_start( /* Commit the start only if data_get successful */
st->obj, info->format,
info->data, info->action,
info->createicon, info->createdata,
info->dragpos, info->dragdata,
info->acceptcb, info->acceptdata,
_cont_drag_done_cb, st);
ELM_SAFE_FREE(info->data, free);
return ECORE_CALLBACK_CANCEL;
}
void
_anim_st_free(Item_Container_Drag_Info *st)
{ /* Stops and free mem of ongoing animation */
if (st)
{
ELM_SAFE_FREE(st->ea, ecore_animator_del);
Anim_Icon *sti;
EINA_LIST_FREE(st->icons, sti)
{
evas_object_del(sti->o);
free(sti);
}
st->icons = NULL;
}
}
static inline Eina_List *
_anim_icons_make(Eina_List *icons)
{ /* Make local copies of all icons, add them to list */
Eina_List *list = NULL, *itr;
Evas_Object *o;
EINA_LIST_FOREACH(icons, itr, o)
{ /* Now add icons to animation window */
Anim_Icon *st = calloc(1, sizeof(*st));
evas_object_geometry_get(o, &st->start_x, &st->start_y, &st->start_w, &st->start_h);
evas_object_show(o);
st->o = o;
list = eina_list_append(list, st);
}
return list;
}
static Eina_Bool
_drag_anim_play(void *data, double pos)
{ /* Impl of the animation of icons, called on frame time */
cnp_debug("In\n");
Item_Container_Drag_Info *st = data;
Eina_List *l;
Anim_Icon *sti;
if (st->ea)
{
if (pos > 0.99)
{
st->ea = NULL; /* Avoid deleting on mouse up */
EINA_LIST_FOREACH(st->icons, l, sti)
evas_object_hide(sti->o);
_cont_obj_drag_start(st); /* Start dragging */
return ECORE_CALLBACK_CANCEL;
}
Evas_Coord xm, ym;
evas_pointer_canvas_xy_get(st->e, &xm, &ym);
EINA_LIST_FOREACH(st->icons, l, sti)
{
int x, y, h, w;
w = sti->start_w + ((st->final_icon_w - sti->start_w) * pos);
h = sti->start_h + ((st->final_icon_h - sti->start_h) * pos);
x = sti->start_x - (pos * ((sti->start_x + (w/2) - xm)));
y = sti->start_y - (pos * ((sti->start_y + (h/2) - ym)));
evas_object_move(sti->o, x, y);
evas_object_resize(sti->o, w, h);
}
return ECORE_CALLBACK_RENEW;
}
return ECORE_CALLBACK_CANCEL;
}
static inline Eina_Bool
_drag_anim_start(void *data)
{ /* Start default animation */
cnp_debug("In\n");
Item_Container_Drag_Info *st = data;
st->tm = NULL;
/* Now we need to build an (Anim_Icon *) list */
st->icons = _anim_icons_make(st->user_info.icons);
if (st->user_info.createicon)
{
Evas_Object *temp_win = elm_win_add(NULL, "Temp", ELM_WIN_UTILITY);
Evas_Object *final_icon = st->user_info.createicon(st->user_info.createdata, temp_win, NULL, NULL);
evas_object_geometry_get(final_icon, NULL, NULL, &st->final_icon_w, &st->final_icon_h);
evas_object_del(final_icon);
evas_object_del(temp_win);
}
st->ea = ecore_animator_timeline_add(st->anim_tm, _drag_anim_play, st);
return EINA_FALSE;
}
static Eina_Bool
_cont_obj_anim_start(void *data)
{ /* Start a drag-action when timer expires */
cnp_debug("In\n");
Item_Container_Drag_Info *st = data;
int xposret, yposret; /* Unused */
Elm_Object_Item *it = (st->itemgetcb) ?
(st->itemgetcb(st->obj, st->x_down, st->y_down, &xposret, &yposret))
: NULL;
st->tm = NULL;
st->user_info.format = ELM_SEL_FORMAT_TARGETS; /* Default */
st->icons = NULL;
st->user_info.data = NULL;
st->user_info.action = ELM_XDND_ACTION_COPY; /* Default */
if (!it) /* Failed to get mouse-down item, abort drag */
return ECORE_CALLBACK_CANCEL;
if (st->data_get)
{ /* collect info then start animation or start dragging */
if(st->data_get( /* Collect drag info */
st->obj, /* The container object */
it, /* Drag started on this item */
&st->user_info))
{
if (st->user_info.icons)
_drag_anim_start(st);
else
{
if (st->anim_tm)
{
// even if we don't manage the icons animation, we have
// to wait until it is finished before beginning drag.
st->tm = ecore_timer_add(st->anim_tm, _cont_obj_drag_start, st);
}
else
_cont_obj_drag_start(st); /* Start dragging, no anim */
}
}
}
return ECORE_CALLBACK_CANCEL;
}
static void
_cont_obj_mouse_down(void *data, Evas *e, Evas_Object *obj __UNUSED__, void *event_info)
{ /* Launch a timer to start dragging */
Evas_Event_Mouse_Down *ev = event_info;
cnp_debug("In - event %X\n", ev->event_flags);
if (ev->button != 1)
return; /* We only process left-click at the moment */
Item_Container_Drag_Info *st = data;
evas_object_event_callback_add(st->obj, EVAS_CALLBACK_MOUSE_MOVE,
_cont_obj_mouse_move, st);
evas_object_event_callback_add(st->obj, EVAS_CALLBACK_MOUSE_UP,
_cont_obj_mouse_up, st);
if (st->tm)
ecore_timer_del(st->tm);
st->e = e;
st->x_down = ev->canvas.x;
st->y_down = ev->canvas.y;
st->tm = ecore_timer_add(st->tm_to_drag, _cont_obj_anim_start, st);
}
static Eina_Bool elm_drag_item_container_del_internal(Evas_Object *obj, Eina_Bool full);
static void
_cont_obj_mouse_move(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
{ /* Cancel any drag waiting to start on timeout */
cnp_debug("In\n");
if (((Evas_Event_Mouse_Move *)event_info)->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
{
cnp_debug("event on hold - have to cancel DnD\n");
Item_Container_Drag_Info *st = data;
evas_object_event_callback_del_full
(st->obj, EVAS_CALLBACK_MOUSE_MOVE, _cont_obj_mouse_move, st);
evas_object_event_callback_del_full
(st->obj, EVAS_CALLBACK_MOUSE_UP, _cont_obj_mouse_up, st);
elm_drag_item_container_del_internal(obj, EINA_FALSE);
ELM_SAFE_FREE(st->tm, ecore_timer_del);
_anim_st_free(st);
}
cnp_debug("Out\n");
}
static void
_cont_obj_mouse_up(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
{ /* Cancel any drag waiting to start on timeout */
Item_Container_Drag_Info *st = data;
cnp_debug("In\n");
if (((Evas_Event_Mouse_Up *)event_info)->button != 1)
return; /* We only process left-click at the moment */
evas_object_event_callback_del_full
(st->obj, EVAS_CALLBACK_MOUSE_MOVE, _cont_obj_mouse_move, st);
evas_object_event_callback_del_full
(st->obj, EVAS_CALLBACK_MOUSE_UP, _cont_obj_mouse_up, st);
ELM_SAFE_FREE(st->tm, ecore_timer_del);
_anim_st_free(st);
}
static Eina_Bool
elm_drag_item_container_del_internal(Evas_Object *obj, Eina_Bool full)
{
Item_Container_Drag_Info *st =
eina_list_search_unsorted(cont_drag_tg, _drag_item_container_cmp, obj);
if (st)
{
ELM_SAFE_FREE(st->tm, ecore_timer_del); /* Cancel drag-start timer */
if (st->ea) /* Cancel ongoing default animation */
_anim_st_free(st);
if (full)
{
st->itemgetcb = NULL;
st->data_get = NULL;
evas_object_event_callback_del_full
(obj, EVAS_CALLBACK_MOUSE_DOWN, _cont_obj_mouse_down, st);
cont_drag_tg = eina_list_remove(cont_drag_tg, st);
ELM_SAFE_FREE(st->user_info.data, free);
free(st);
}
return EINA_TRUE;
}
return EINA_FALSE;
}
EAPI Eina_Bool
elm_drag_item_container_del(Evas_Object *obj)
{
return elm_drag_item_container_del_internal(obj, EINA_TRUE);
}
EAPI Eina_Bool
elm_drag_item_container_add(Evas_Object *obj, double anim_tm, double tm_to_drag, Elm_Xy_Item_Get_Cb itemgetcb, Elm_Item_Container_Data_Get_Cb data_get)
{
Item_Container_Drag_Info *st;
if (elm_drag_item_container_del_internal(obj, EINA_FALSE))
{ /* Updating info of existing obj */
st = eina_list_search_unsorted(cont_drag_tg, _drag_item_container_cmp, obj);
if (!st) return EINA_FALSE;
}
else
{
st = calloc(1, sizeof(*st));
if (!st) return EINA_FALSE;
st->obj = obj;
cont_drag_tg = eina_list_append(cont_drag_tg, st);
/* Register for mouse callback for container to start/abort drag */
evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_DOWN,
_cont_obj_mouse_down, st);
}
st->tm = NULL;
st->anim_tm = anim_tm;
st->tm_to_drag = tm_to_drag;
st->itemgetcb = itemgetcb;
st->data_get = data_get;
return EINA_TRUE;
}
/* END - Support elm containers for Drag */
/* END - Support elm containers for Drag and Drop */
EAPI Eina_Bool
elm_drag_cancel(Evas_Object *obj)
{
#ifdef HAVE_ELEMENTARY_X
Ecore_X_Window xwin = _x11_elm_widget_xwin_get(obj);
if (xwin)
{
ecore_x_pointer_ungrab();
ELM_SAFE_FREE(handler_up, ecore_event_handler_del);
ELM_SAFE_FREE(handler_status, ecore_event_handler_del);
ecore_x_dnd_abort(xwin);
}
#endif
#ifdef HAVE_ELEMENTARY_WAYLAND
/* Have to complete here.
* if (elm_win_wl_window_get(obj)) ... */
#endif
ELM_SAFE_FREE(dragwin, evas_object_del);
dragdonecb = NULL;
dragacceptcb = NULL;
dragposcb = NULL;
dragwidget = NULL;
doaccept = EINA_FALSE;
return EINA_TRUE;
}
|