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
|
/* GTK - The GIMP Toolkit
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
* file for a list of people on the GTK+ Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
*/
#include "config.h"
#include "gtkscrolledwindow.h"
#include "gtkadjustment.h"
#include "gtkadjustmentprivate.h"
#include "gtkbindings.h"
#include "gtkdnd.h"
#include "gtkintl.h"
#include "gtkmain.h"
#include "gtkmarshalers.h"
#include "gtkprivate.h"
#include "gtkscrollable.h"
#include "gtkscrollbar.h"
#include "gtkrangeprivate.h"
#include "gtktypebuiltins.h"
#include "gtkviewport.h"
#include "gtkwidgetprivate.h"
#include "gtkwindow.h"
#include "gtkkineticscrolling.h"
#include "a11y/gtkscrolledwindowaccessible.h"
#include <math.h>
/**
* SECTION:gtkscrolledwindow
* @Short_description: Adds scrollbars to its child widget
* @Title: GtkScrolledWindow
* @See_also: #GtkScrollable, #GtkViewport, #GtkAdjustment
*
* GtkScrolledWindow is a #GtkBin subclass: it’s a container
* the accepts a single child widget. GtkScrolledWindow adds scrollbars
* to the child widget and optionally draws a beveled frame around the
* child widget.
*
* The scrolled window can work in two ways. Some widgets have native
* scrolling support; these widgets implement the #GtkScrollable interface.
* Widgets with native scroll support include #GtkTreeView, #GtkTextView,
* and #GtkLayout.
*
* For widgets that lack native scrolling support, the #GtkViewport
* widget acts as an adaptor class, implementing scrollability for child
* widgets that lack their own scrolling capabilities. Use #GtkViewport
* to scroll child widgets such as #GtkGrid, #GtkBox, and so on.
*
* If a widget has native scrolling abilities, it can be added to the
* GtkScrolledWindow with gtk_container_add(). If a widget does not, you
* must first add the widget to a #GtkViewport, then add the #GtkViewport
* to the scrolled window. gtk_container_add() will do this for you for
* widgets that don’t implement #GtkScrollable natively, so you can
* ignore the presence of the viewport.
*
* The position of the scrollbars is controlled by the scroll adjustments.
* See #GtkAdjustment for the fields in an adjustment — for
* #GtkScrollbar, used by GtkScrolledWindow, the “value” field
* represents the position of the scrollbar, which must be between the
* “lower” field and “upper - page_size.” The “page_size” field
* represents the size of the visible scrollable area. The
* “step_increment” and “page_increment” fields are used when the user
* asks to step down (using the small stepper arrows) or page down (using
* for example the PageDown key).
*
* If a GtkScrolledWindow doesn’t behave quite as you would like, or
* doesn’t have exactly the right layout, it’s very possible to set up
* your own scrolling with #GtkScrollbar and for example a #GtkGrid.
*/
/* scrolled window policy and size requisition handling:
*
* gtk size requisition works as follows:
* a widget upon size-request reports the width and height that it finds
* to be best suited to display its contents, including children.
* the width and/or height reported from a widget upon size requisition
* may be overidden by the user by specifying a width and/or height
* other than 0 through gtk_widget_set_size_request().
*
* a scrolled window needs (for implementing all three policy types) to
* request its width and height based on two different rationales.
* 1) the user wants the scrolled window to just fit into the space
* that it gets allocated for a specifc dimension.
* 1.1) this does not apply if the user specified a concrete value
* value for that specific dimension by either specifying usize for the
* scrolled window or for its child.
* 2) the user wants the scrolled window to take as much space up as
* is desired by the child for a specifc dimension (i.e. POLICY_NEVER).
*
* also, kinda obvious:
* 3) a user would certainly not have choosen a scrolled window as a container
* for the child, if the resulting allocation takes up more space than the
* child would have allocated without the scrolled window.
*
* conclusions:
* A) from 1) follows: the scrolled window shouldn’t request more space for a
* specifc dimension than is required at minimum.
* B) from 1.1) follows: the requisition may be overidden by usize of the scrolled
* window (done automatically) or by usize of the child (needs to be checked).
* C) from 2) follows: for POLICY_NEVER, the scrolled window simply reports the
* child’s dimension.
* D) from 3) follows: the scrolled window child’s minimum width and minimum height
* under A) at least correspond to the space taken up by its scrollbars.
*/
#define DEFAULT_SCROLLBAR_SPACING 3
#define TOUCH_BYPASS_CAPTURED_THRESHOLD 30
/* Kinetic scrolling */
#define MAX_OVERSHOOT_DISTANCE 100
#define DECELERATION_FRICTION 4
#define OVERSHOOT_FRICTION 20
/* Animated scrolling */
#define ANIMATION_DURATION 200
struct _GtkScrolledWindowPrivate
{
GtkWidget *hscrollbar;
GtkWidget *vscrollbar;
GtkCornerType window_placement;
guint16 shadow_type;
guint hscrollbar_policy : 2;
guint vscrollbar_policy : 2;
guint hscrollbar_visible : 1;
guint vscrollbar_visible : 1;
guint focus_out : 1; /* Flag used by ::move-focus-out implementation */
gint min_content_width;
gint min_content_height;
guint scroll_events_overshoot_id;
/* Kinetic scrolling */
GtkGesture *long_press_gesture;
GtkGesture *swipe_gesture;
/* These two gestures are mutually exclusive */
GtkGesture *drag_gesture;
GtkGesture *pan_gesture;
gdouble drag_start_x;
gdouble drag_start_y;
GdkDevice *drag_device;
guint kinetic_scrolling : 1;
guint capture_button_press : 1;
guint in_drag : 1;
guint deceleration_id;
gdouble x_velocity;
gdouble y_velocity;
gdouble unclamped_hadj_value;
gdouble unclamped_vadj_value;
};
typedef struct
{
GtkScrolledWindow *scrolled_window;
gint64 last_deceleration_time;
GtkKineticScrolling *hscrolling;
GtkKineticScrolling *vscrolling;
} KineticScrollData;
enum {
PROP_0,
PROP_HADJUSTMENT,
PROP_VADJUSTMENT,
PROP_HSCROLLBAR_POLICY,
PROP_VSCROLLBAR_POLICY,
PROP_WINDOW_PLACEMENT,
PROP_WINDOW_PLACEMENT_SET,
PROP_SHADOW_TYPE,
PROP_MIN_CONTENT_WIDTH,
PROP_MIN_CONTENT_HEIGHT,
PROP_KINETIC_SCROLLING
};
/* Signals */
enum
{
SCROLL_CHILD,
MOVE_FOCUS_OUT,
LAST_SIGNAL
};
static void gtk_scrolled_window_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec);
static void gtk_scrolled_window_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec);
static void gtk_scrolled_window_destroy (GtkWidget *widget);
static gboolean gtk_scrolled_window_draw (GtkWidget *widget,
cairo_t *cr);
static void gtk_scrolled_window_size_allocate (GtkWidget *widget,
GtkAllocation *allocation);
static gboolean gtk_scrolled_window_scroll_event (GtkWidget *widget,
GdkEventScroll *event);
static gboolean gtk_scrolled_window_focus (GtkWidget *widget,
GtkDirectionType direction);
static void gtk_scrolled_window_add (GtkContainer *container,
GtkWidget *widget);
static void gtk_scrolled_window_remove (GtkContainer *container,
GtkWidget *widget);
static void gtk_scrolled_window_forall (GtkContainer *container,
gboolean include_internals,
GtkCallback callback,
gpointer callback_data);
static gboolean gtk_scrolled_window_scroll_child (GtkScrolledWindow *scrolled_window,
GtkScrollType scroll,
gboolean horizontal);
static void gtk_scrolled_window_move_focus_out (GtkScrolledWindow *scrolled_window,
GtkDirectionType direction_type);
static void gtk_scrolled_window_relative_allocation(GtkWidget *widget,
GtkAllocation *allocation);
static void gtk_scrolled_window_adjustment_changed (GtkAdjustment *adjustment,
gpointer data);
static void gtk_scrolled_window_adjustment_value_changed (GtkAdjustment *adjustment,
gpointer data);
static gboolean gtk_scrolled_window_should_animate (GtkScrolledWindow *sw);
static void gtk_scrolled_window_get_preferred_width (GtkWidget *widget,
gint *minimum_size,
gint *natural_size);
static void gtk_scrolled_window_get_preferred_height (GtkWidget *widget,
gint *minimum_size,
gint *natural_size);
static void gtk_scrolled_window_get_preferred_height_for_width (GtkWidget *layout,
gint width,
gint *minimum_height,
gint *natural_height);
static void gtk_scrolled_window_get_preferred_width_for_height (GtkWidget *layout,
gint width,
gint *minimum_height,
gint *natural_height);
static void gtk_scrolled_window_map (GtkWidget *widget);
static void gtk_scrolled_window_unmap (GtkWidget *widget);
static void gtk_scrolled_window_grab_notify (GtkWidget *widget,
gboolean was_grabbed);
static void _gtk_scrolled_window_set_adjustment_value (GtkScrolledWindow *scrolled_window,
GtkAdjustment *adjustment,
gdouble value);
static void gtk_scrolled_window_cancel_deceleration (GtkScrolledWindow *scrolled_window);
static gboolean _gtk_scrolled_window_get_overshoot (GtkScrolledWindow *scrolled_window,
gint *overshoot_x,
gint *overshoot_y);
static void gtk_scrolled_window_start_deceleration (GtkScrolledWindow *scrolled_window);
static gint _gtk_scrolled_window_get_scrollbar_spacing (GtkScrolledWindow *scrolled_window);
static guint signals[LAST_SIGNAL] = {0};
G_DEFINE_TYPE_WITH_PRIVATE (GtkScrolledWindow, gtk_scrolled_window, GTK_TYPE_BIN)
static void
add_scroll_binding (GtkBindingSet *binding_set,
guint keyval,
GdkModifierType mask,
GtkScrollType scroll,
gboolean horizontal)
{
guint keypad_keyval = keyval - GDK_KEY_Left + GDK_KEY_KP_Left;
gtk_binding_entry_add_signal (binding_set, keyval, mask,
"scroll-child", 2,
GTK_TYPE_SCROLL_TYPE, scroll,
G_TYPE_BOOLEAN, horizontal);
gtk_binding_entry_add_signal (binding_set, keypad_keyval, mask,
"scroll-child", 2,
GTK_TYPE_SCROLL_TYPE, scroll,
G_TYPE_BOOLEAN, horizontal);
}
static void
add_tab_bindings (GtkBindingSet *binding_set,
GdkModifierType modifiers,
GtkDirectionType direction)
{
gtk_binding_entry_add_signal (binding_set, GDK_KEY_Tab, modifiers,
"move-focus-out", 1,
GTK_TYPE_DIRECTION_TYPE, direction);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Tab, modifiers,
"move-focus-out", 1,
GTK_TYPE_DIRECTION_TYPE, direction);
}
static void
gtk_scrolled_window_class_init (GtkScrolledWindowClass *class)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (class);
GtkWidgetClass *widget_class;
GtkContainerClass *container_class;
GtkBindingSet *binding_set;
widget_class = (GtkWidgetClass*) class;
container_class = (GtkContainerClass*) class;
gobject_class->set_property = gtk_scrolled_window_set_property;
gobject_class->get_property = gtk_scrolled_window_get_property;
widget_class->destroy = gtk_scrolled_window_destroy;
widget_class->draw = gtk_scrolled_window_draw;
widget_class->size_allocate = gtk_scrolled_window_size_allocate;
widget_class->scroll_event = gtk_scrolled_window_scroll_event;
widget_class->focus = gtk_scrolled_window_focus;
widget_class->get_preferred_width = gtk_scrolled_window_get_preferred_width;
widget_class->get_preferred_height = gtk_scrolled_window_get_preferred_height;
widget_class->get_preferred_height_for_width = gtk_scrolled_window_get_preferred_height_for_width;
widget_class->get_preferred_width_for_height = gtk_scrolled_window_get_preferred_width_for_height;
widget_class->map = gtk_scrolled_window_map;
widget_class->unmap = gtk_scrolled_window_unmap;
widget_class->grab_notify = gtk_scrolled_window_grab_notify;
container_class->add = gtk_scrolled_window_add;
container_class->remove = gtk_scrolled_window_remove;
container_class->forall = gtk_scrolled_window_forall;
gtk_container_class_handle_border_width (container_class);
class->scrollbar_spacing = -1;
class->scroll_child = gtk_scrolled_window_scroll_child;
class->move_focus_out = gtk_scrolled_window_move_focus_out;
g_object_class_install_property (gobject_class,
PROP_HADJUSTMENT,
g_param_spec_object ("hadjustment",
P_("Horizontal Adjustment"),
P_("The GtkAdjustment for the horizontal position"),
GTK_TYPE_ADJUSTMENT,
GTK_PARAM_READWRITE|G_PARAM_CONSTRUCT));
g_object_class_install_property (gobject_class,
PROP_VADJUSTMENT,
g_param_spec_object ("vadjustment",
P_("Vertical Adjustment"),
P_("The GtkAdjustment for the vertical position"),
GTK_TYPE_ADJUSTMENT,
GTK_PARAM_READWRITE|G_PARAM_CONSTRUCT));
g_object_class_install_property (gobject_class,
PROP_HSCROLLBAR_POLICY,
g_param_spec_enum ("hscrollbar-policy",
P_("Horizontal Scrollbar Policy"),
P_("When the horizontal scrollbar is displayed"),
GTK_TYPE_POLICY_TYPE,
GTK_POLICY_AUTOMATIC,
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
g_object_class_install_property (gobject_class,
PROP_VSCROLLBAR_POLICY,
g_param_spec_enum ("vscrollbar-policy",
P_("Vertical Scrollbar Policy"),
P_("When the vertical scrollbar is displayed"),
GTK_TYPE_POLICY_TYPE,
GTK_POLICY_AUTOMATIC,
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
g_object_class_install_property (gobject_class,
PROP_WINDOW_PLACEMENT,
g_param_spec_enum ("window-placement",
P_("Window Placement"),
P_("Where the contents are located with respect to the scrollbars."),
GTK_TYPE_CORNER_TYPE,
GTK_CORNER_TOP_LEFT,
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
/**
* GtkScrolledWindow:window-placement-set:
*
* Whether "window-placement" should be used to determine the location
* of the contents with respect to the scrollbars.
*
* Since: 2.10
*
* Deprecated: 3.10: This value is ignored and
* #GtkScrolledWindow:window-placement value is always honored.
*/
g_object_class_install_property (gobject_class,
PROP_WINDOW_PLACEMENT_SET,
g_param_spec_boolean ("window-placement-set",
P_("Window Placement Set"),
P_("Whether \"window-placement\" should be used to determine the location of the contents with respect to the scrollbars."),
TRUE,
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
g_object_class_install_property (gobject_class,
PROP_SHADOW_TYPE,
g_param_spec_enum ("shadow-type",
P_("Shadow Type"),
P_("Style of bevel around the contents"),
GTK_TYPE_SHADOW_TYPE,
GTK_SHADOW_NONE,
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
/**
* GtkScrolledWindow:scrollbars-within-bevel:
*
* Whether to place scrollbars within the scrolled window's bevel.
*
* Since: 2.12
*/
gtk_widget_class_install_style_property (widget_class,
g_param_spec_boolean ("scrollbars-within-bevel",
P_("Scrollbars within bevel"),
P_("Place scrollbars within the scrolled window's bevel"),
FALSE,
GTK_PARAM_READABLE));
gtk_widget_class_install_style_property (widget_class,
g_param_spec_int ("scrollbar-spacing",
P_("Scrollbar spacing"),
P_("Number of pixels between the scrollbars and the scrolled window"),
0,
G_MAXINT,
DEFAULT_SCROLLBAR_SPACING,
GTK_PARAM_READABLE));
/**
* GtkScrolledWindow:min-content-width:
*
* The minimum content width of @scrolled_window, or -1 if not set.
*
* Since: 3.0
*/
g_object_class_install_property (gobject_class,
PROP_MIN_CONTENT_WIDTH,
g_param_spec_int ("min-content-width",
P_("Minimum Content Width"),
P_("The minimum width that the scrolled window will allocate to its content"),
-1, G_MAXINT, -1,
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
/**
* GtkScrolledWindow:min-content-height:
*
* The minimum content height of @scrolled_window, or -1 if not set.
*
* Since: 3.0
*/
g_object_class_install_property (gobject_class,
PROP_MIN_CONTENT_HEIGHT,
g_param_spec_int ("min-content-height",
P_("Minimum Content Height"),
P_("The minimum height that the scrolled window will allocate to its content"),
-1, G_MAXINT, -1,
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
/**
* GtkScrolledWindow:kinetic-scrolling:
*
* The kinetic scrolling behavior flags. Kinetic scrolling
* only applies to devices with source %GDK_SOURCE_TOUCHSCREEN
*
* Since: 3.4
*/
g_object_class_install_property (gobject_class,
PROP_KINETIC_SCROLLING,
g_param_spec_boolean ("kinetic-scrolling",
P_("Kinetic Scrolling"),
P_("Kinetic scrolling mode."),
TRUE,
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
/**
* GtkScrolledWindow::scroll-child:
* @scrolled_window: a #GtkScrolledWindow
* @scroll: a #GtkScrollType describing how much to scroll
* @horizontal: whether the keybinding scrolls the child
* horizontally or not
*
* The ::scroll-child signal is a
* [keybinding signal][GtkBindingSignal]
* which gets emitted when a keybinding that scrolls is pressed.
* The horizontal or vertical adjustment is updated which triggers a
* signal that the scrolled windows child may listen to and scroll itself.
*/
signals[SCROLL_CHILD] =
g_signal_new (I_("scroll-child"),
G_TYPE_FROM_CLASS (gobject_class),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET (GtkScrolledWindowClass, scroll_child),
NULL, NULL,
_gtk_marshal_BOOLEAN__ENUM_BOOLEAN,
G_TYPE_BOOLEAN, 2,
GTK_TYPE_SCROLL_TYPE,
G_TYPE_BOOLEAN);
/**
* GtkScrolledWindow::move-focus-out:
* @scrolled_window: a #GtkScrolledWindow
* @direction_type: either %GTK_DIR_TAB_FORWARD or
* %GTK_DIR_TAB_BACKWARD
*
* The ::move-focus-out signal is a
* [keybinding signal][GtkBindingSignal] which gets
* emitted when focus is moved away from the scrolled window by a
* keybinding. The #GtkWidget::move-focus signal is emitted with
* @direction_type on this scrolled windows toplevel parent in the
* container hierarchy. The default bindings for this signal are
* `Tab + Ctrl` and `Tab + Ctrl + Shift`.
*/
signals[MOVE_FOCUS_OUT] =
g_signal_new (I_("move-focus-out"),
G_TYPE_FROM_CLASS (gobject_class),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET (GtkScrolledWindowClass, move_focus_out),
NULL, NULL,
_gtk_marshal_VOID__ENUM,
G_TYPE_NONE, 1,
GTK_TYPE_DIRECTION_TYPE);
binding_set = gtk_binding_set_by_class (class);
add_scroll_binding (binding_set, GDK_KEY_Left, GDK_CONTROL_MASK, GTK_SCROLL_STEP_BACKWARD, TRUE);
add_scroll_binding (binding_set, GDK_KEY_Right, GDK_CONTROL_MASK, GTK_SCROLL_STEP_FORWARD, TRUE);
add_scroll_binding (binding_set, GDK_KEY_Up, GDK_CONTROL_MASK, GTK_SCROLL_STEP_BACKWARD, FALSE);
add_scroll_binding (binding_set, GDK_KEY_Down, GDK_CONTROL_MASK, GTK_SCROLL_STEP_FORWARD, FALSE);
add_scroll_binding (binding_set, GDK_KEY_Page_Up, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_BACKWARD, TRUE);
add_scroll_binding (binding_set, GDK_KEY_Page_Down, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_FORWARD, TRUE);
add_scroll_binding (binding_set, GDK_KEY_Page_Up, 0, GTK_SCROLL_PAGE_BACKWARD, FALSE);
add_scroll_binding (binding_set, GDK_KEY_Page_Down, 0, GTK_SCROLL_PAGE_FORWARD, FALSE);
add_scroll_binding (binding_set, GDK_KEY_Home, GDK_CONTROL_MASK, GTK_SCROLL_START, TRUE);
add_scroll_binding (binding_set, GDK_KEY_End, GDK_CONTROL_MASK, GTK_SCROLL_END, TRUE);
add_scroll_binding (binding_set, GDK_KEY_Home, 0, GTK_SCROLL_START, FALSE);
add_scroll_binding (binding_set, GDK_KEY_End, 0, GTK_SCROLL_END, FALSE);
add_tab_bindings (binding_set, GDK_CONTROL_MASK, GTK_DIR_TAB_FORWARD);
add_tab_bindings (binding_set, GDK_CONTROL_MASK | GDK_SHIFT_MASK, GTK_DIR_TAB_BACKWARD);
gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_SCROLLED_WINDOW_ACCESSIBLE);
}
static gboolean
may_hscroll (GtkScrolledWindow *scrolled_window)
{
GtkScrolledWindowPrivate *priv = scrolled_window->priv;
return priv->hscrollbar_visible || priv->hscrollbar_policy == GTK_POLICY_EXTERNAL;
}
static gboolean
may_vscroll (GtkScrolledWindow *scrolled_window)
{
GtkScrolledWindowPrivate *priv = scrolled_window->priv;
return priv->vscrollbar_visible || priv->vscrollbar_policy == GTK_POLICY_EXTERNAL;
}
static inline gboolean
policy_may_be_visible (GtkPolicyType policy)
{
return policy == GTK_POLICY_ALWAYS || policy == GTK_POLICY_AUTOMATIC;
}
static void
scrolled_window_drag_begin_cb (GtkScrolledWindow *scrolled_window,
gdouble start_x,
gdouble start_y,
GtkGesture *gesture)
{
GtkScrolledWindowPrivate *priv = scrolled_window->priv;
GtkEventSequenceState state;
GdkEventSequence *sequence;
GtkWidget *event_widget;
const GdkEvent *event;
priv->in_drag = FALSE;
priv->drag_start_x = priv->unclamped_hadj_value;
priv->drag_start_y = priv->unclamped_vadj_value;
gtk_scrolled_window_cancel_deceleration (scrolled_window);
sequence = gtk_gesture_single_get_current_sequence (GTK_GESTURE_SINGLE (gesture));
event = gtk_gesture_get_last_event (gesture, sequence);
event_widget = gtk_get_event_widget ((GdkEvent *) event);
if (event_widget == priv->vscrollbar || event_widget == priv->hscrollbar ||
(!may_hscroll (scrolled_window) && !may_vscroll (scrolled_window)))
state = GTK_EVENT_SEQUENCE_DENIED;
else if (priv->capture_button_press)
state = GTK_EVENT_SEQUENCE_CLAIMED;
else
return;
gtk_gesture_set_sequence_state (gesture, sequence, state);
}
static void
gtk_scrolled_window_invalidate_overshoot (GtkScrolledWindow *scrolled_window)
{
GtkAllocation child_allocation, allocation;
gint overshoot_x, overshoot_y;
GdkRectangle rect;
if (!_gtk_scrolled_window_get_overshoot (scrolled_window, &overshoot_x, &overshoot_y))
return;
gtk_widget_get_allocation (GTK_WIDGET (scrolled_window), &allocation);
gtk_scrolled_window_relative_allocation (GTK_WIDGET (scrolled_window),
&child_allocation);
child_allocation.x += allocation.x;
child_allocation.y += allocation.y;
if (overshoot_x != 0)
{
if (overshoot_x < 0)
rect.x = child_allocation.x;
else
rect.x = child_allocation.x + child_allocation.width - MAX_OVERSHOOT_DISTANCE;
rect.y = child_allocation.y;
rect.width = MAX_OVERSHOOT_DISTANCE;
rect.height = child_allocation.height;
gdk_window_invalidate_rect (gtk_widget_get_window (GTK_WIDGET (scrolled_window)),
&rect, TRUE);
}
if (overshoot_y != 0)
{
if (overshoot_y < 0)
rect.y = child_allocation.y;
else
rect.y = child_allocation.y + child_allocation.height - MAX_OVERSHOOT_DISTANCE;
rect.x = child_allocation.x;
rect.width = child_allocation.width;
rect.height = MAX_OVERSHOOT_DISTANCE;
gdk_window_invalidate_rect (gtk_widget_get_window (GTK_WIDGET (scrolled_window)),
&rect, TRUE);
}
}
static void
scrolled_window_drag_update_cb (GtkScrolledWindow *scrolled_window,
gdouble offset_x,
gdouble offset_y,
GtkGesture *gesture)
{
GtkScrolledWindowPrivate *priv = scrolled_window->priv;
GtkAdjustment *hadjustment;
GtkAdjustment *vadjustment;
gdouble dx, dy;
gtk_scrolled_window_invalidate_overshoot (scrolled_window);
if (!priv->capture_button_press)
{
GdkEventSequence *sequence;
sequence = gtk_gesture_single_get_current_sequence (GTK_GESTURE_SINGLE (gesture));
gtk_gesture_set_sequence_state (gesture, sequence,
GTK_EVENT_SEQUENCE_CLAIMED);
}
hadjustment = gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar));
if (hadjustment && may_hscroll (scrolled_window))
{
dx = priv->drag_start_x - offset_x;
_gtk_scrolled_window_set_adjustment_value (scrolled_window,
hadjustment, dx);
}
vadjustment = gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar));
if (vadjustment && may_vscroll (scrolled_window))
{
dy = priv->drag_start_y - offset_y;
_gtk_scrolled_window_set_adjustment_value (scrolled_window,
vadjustment, dy);
}
gtk_scrolled_window_invalidate_overshoot (scrolled_window);
}
static void
scrolled_window_drag_end_cb (GtkScrolledWindow *scrolled_window,
GdkEventSequence *sequence,
GtkGesture *gesture)
{
GtkScrolledWindowPrivate *priv = scrolled_window->priv;
if (!priv->in_drag || !gtk_gesture_handles_sequence (gesture, sequence))
gtk_gesture_set_state (gesture, GTK_EVENT_SEQUENCE_DENIED);
}
static void
scrolled_window_swipe_cb (GtkScrolledWindow *scrolled_window,
gdouble x_velocity,
gdouble y_velocity)
{
GtkScrolledWindowPrivate *priv = scrolled_window->priv;
gboolean overshoot;
overshoot = _gtk_scrolled_window_get_overshoot (scrolled_window, NULL, NULL);
priv->x_velocity = -x_velocity;
priv->y_velocity = -y_velocity;
/* Zero out vector components for which we don't scroll */
if (!may_hscroll (scrolled_window))
priv->x_velocity = 0;
if (!may_vscroll (scrolled_window))
priv->y_velocity = 0;
if (priv->x_velocity != 0 || priv->y_velocity != 0 || overshoot)
{
gtk_scrolled_window_start_deceleration (scrolled_window);
priv->x_velocity = priv->y_velocity = 0;
}
}
static void
scrolled_window_long_press_cb (GtkScrolledWindow *scrolled_window,
gdouble x,
gdouble y,
GtkGesture *gesture)
{
GdkEventSequence *sequence;
sequence = gtk_gesture_single_get_current_sequence (GTK_GESTURE_SINGLE (gesture));
gtk_gesture_set_sequence_state (gesture, sequence,
GTK_EVENT_SEQUENCE_DENIED);
}
static void
scrolled_window_long_press_cancelled_cb (GtkScrolledWindow *scrolled_window,
GtkGesture *gesture)
{
GtkScrolledWindowPrivate *priv = scrolled_window->priv;
GdkEventSequence *sequence;
const GdkEvent *event;
sequence = gtk_gesture_get_last_updated_sequence (gesture);
event = gtk_gesture_get_last_event (gesture, sequence);
if (event->type == GDK_TOUCH_BEGIN ||
event->type == GDK_BUTTON_PRESS)
gtk_gesture_set_sequence_state (gesture, sequence,
GTK_EVENT_SEQUENCE_DENIED);
else if (event->type != GDK_TOUCH_END &&
event->type != GDK_BUTTON_RELEASE)
priv->in_drag = TRUE;
}
static void
gtk_scrolled_window_check_attach_pan_gesture (GtkScrolledWindow *sw)
{
GtkPropagationPhase phase = GTK_PHASE_NONE;
GtkScrolledWindowPrivate *priv = sw->priv;
if (priv->kinetic_scrolling &&
((may_hscroll (sw) && !may_vscroll (sw)) ||
(!may_hscroll (sw) && may_vscroll (sw))))
{
GtkOrientation orientation;
if (may_hscroll (sw))
orientation = GTK_ORIENTATION_HORIZONTAL;
else
orientation = GTK_ORIENTATION_VERTICAL;
gtk_gesture_pan_set_orientation (GTK_GESTURE_PAN (priv->pan_gesture),
orientation);
phase = GTK_PHASE_CAPTURE;
}
gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (priv->pan_gesture), phase);
}
static void
gtk_scrolled_window_init (GtkScrolledWindow *scrolled_window)
{
GtkWidget *widget = GTK_WIDGET (scrolled_window);
GtkScrolledWindowPrivate *priv;
scrolled_window->priv = priv =
gtk_scrolled_window_get_instance_private (scrolled_window);
gtk_widget_set_has_window (widget, FALSE);
gtk_widget_set_can_focus (widget, TRUE);
/* Instantiated by gtk_scrolled_window_set_[hv]adjustment
* which are both construct properties
*/
priv->hscrollbar = NULL;
priv->vscrollbar = NULL;
priv->hscrollbar_policy = GTK_POLICY_AUTOMATIC;
priv->vscrollbar_policy = GTK_POLICY_AUTOMATIC;
priv->hscrollbar_visible = FALSE;
priv->vscrollbar_visible = FALSE;
priv->focus_out = FALSE;
priv->window_placement = GTK_CORNER_TOP_LEFT;
priv->min_content_width = -1;
priv->min_content_height = -1;
priv->drag_gesture = gtk_gesture_drag_new (widget);
gtk_gesture_single_set_touch_only (GTK_GESTURE_SINGLE (priv->drag_gesture), TRUE);
g_signal_connect_swapped (priv->drag_gesture, "drag-begin",
G_CALLBACK (scrolled_window_drag_begin_cb),
scrolled_window);
g_signal_connect_swapped (priv->drag_gesture, "drag-update",
G_CALLBACK (scrolled_window_drag_update_cb),
scrolled_window);
g_signal_connect_swapped (priv->drag_gesture, "end",
G_CALLBACK (scrolled_window_drag_end_cb),
scrolled_window);
priv->pan_gesture = gtk_gesture_pan_new (widget, GTK_ORIENTATION_VERTICAL);
gtk_gesture_group (priv->pan_gesture, priv->drag_gesture);
gtk_gesture_single_set_touch_only (GTK_GESTURE_SINGLE (priv->pan_gesture), TRUE);
priv->swipe_gesture = gtk_gesture_swipe_new (widget);
gtk_gesture_group (priv->swipe_gesture, priv->drag_gesture);
gtk_gesture_single_set_touch_only (GTK_GESTURE_SINGLE (priv->swipe_gesture), TRUE);
g_signal_connect_swapped (priv->swipe_gesture, "swipe",
G_CALLBACK (scrolled_window_swipe_cb),
scrolled_window);
priv->long_press_gesture = gtk_gesture_long_press_new (widget);
gtk_gesture_group (priv->long_press_gesture, priv->drag_gesture);
gtk_gesture_single_set_touch_only (GTK_GESTURE_SINGLE (priv->long_press_gesture), TRUE);
g_signal_connect_swapped (priv->long_press_gesture, "pressed",
G_CALLBACK (scrolled_window_long_press_cb),
scrolled_window);
g_signal_connect_swapped (priv->long_press_gesture, "cancelled",
G_CALLBACK (scrolled_window_long_press_cancelled_cb),
scrolled_window);
gtk_scrolled_window_set_kinetic_scrolling (scrolled_window, TRUE);
gtk_scrolled_window_set_capture_button_press (scrolled_window, TRUE);
}
/**
* gtk_scrolled_window_new:
* @hadjustment: (allow-none): horizontal adjustment
* @vadjustment: (allow-none): vertical adjustment
*
* Creates a new scrolled window.
*
* The two arguments are the scrolled window’s adjustments; these will be
* shared with the scrollbars and the child widget to keep the bars in sync
* with the child. Usually you want to pass %NULL for the adjustments, which
* will cause the scrolled window to create them for you.
*
* Returns: a new scrolled window
*/
GtkWidget*
gtk_scrolled_window_new (GtkAdjustment *hadjustment,
GtkAdjustment *vadjustment)
{
GtkWidget *scrolled_window;
if (hadjustment)
g_return_val_if_fail (GTK_IS_ADJUSTMENT (hadjustment), NULL);
if (vadjustment)
g_return_val_if_fail (GTK_IS_ADJUSTMENT (vadjustment), NULL);
scrolled_window = g_object_new (GTK_TYPE_SCROLLED_WINDOW,
"hadjustment", hadjustment,
"vadjustment", vadjustment,
NULL);
return scrolled_window;
}
/**
* gtk_scrolled_window_set_hadjustment:
* @scrolled_window: a #GtkScrolledWindow
* @hadjustment: horizontal scroll adjustment
*
* Sets the #GtkAdjustment for the horizontal scrollbar.
*/
void
gtk_scrolled_window_set_hadjustment (GtkScrolledWindow *scrolled_window,
GtkAdjustment *hadjustment)
{
GtkScrolledWindowPrivate *priv;
GtkBin *bin;
GtkWidget *child;
g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
if (hadjustment)
g_return_if_fail (GTK_IS_ADJUSTMENT (hadjustment));
else
hadjustment = (GtkAdjustment*) g_object_new (GTK_TYPE_ADJUSTMENT, NULL);
bin = GTK_BIN (scrolled_window);
priv = scrolled_window->priv;
if (!priv->hscrollbar)
{
priv->hscrollbar = gtk_scrollbar_new (GTK_ORIENTATION_HORIZONTAL, hadjustment);
gtk_widget_set_parent (priv->hscrollbar, GTK_WIDGET (scrolled_window));
g_object_ref (priv->hscrollbar);
gtk_widget_show (priv->hscrollbar);
}
else
{
GtkAdjustment *old_adjustment;
old_adjustment = gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar));
if (old_adjustment == hadjustment)
return;
g_signal_handlers_disconnect_by_func (old_adjustment,
gtk_scrolled_window_adjustment_changed,
scrolled_window);
gtk_adjustment_enable_animation (old_adjustment, NULL, 0);
gtk_range_set_adjustment (GTK_RANGE (priv->hscrollbar), hadjustment);
}
hadjustment = gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar));
g_signal_connect (hadjustment,
"changed",
G_CALLBACK (gtk_scrolled_window_adjustment_changed),
scrolled_window);
g_signal_connect (hadjustment,
"value-changed",
G_CALLBACK (gtk_scrolled_window_adjustment_value_changed),
scrolled_window);
gtk_scrolled_window_adjustment_changed (hadjustment, scrolled_window);
gtk_scrolled_window_adjustment_value_changed (hadjustment, scrolled_window);
child = gtk_bin_get_child (bin);
if (GTK_IS_SCROLLABLE (child))
gtk_scrollable_set_hadjustment (GTK_SCROLLABLE (child), hadjustment);
if (gtk_scrolled_window_should_animate (scrolled_window))
gtk_adjustment_enable_animation (hadjustment, gtk_widget_get_frame_clock (GTK_WIDGET (scrolled_window)), ANIMATION_DURATION);
g_object_notify (G_OBJECT (scrolled_window), "hadjustment");
}
/**
* gtk_scrolled_window_set_vadjustment:
* @scrolled_window: a #GtkScrolledWindow
* @vadjustment: vertical scroll adjustment
*
* Sets the #GtkAdjustment for the vertical scrollbar.
*/
void
gtk_scrolled_window_set_vadjustment (GtkScrolledWindow *scrolled_window,
GtkAdjustment *vadjustment)
{
GtkScrolledWindowPrivate *priv;
GtkBin *bin;
GtkWidget *child;
g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
if (vadjustment)
g_return_if_fail (GTK_IS_ADJUSTMENT (vadjustment));
else
vadjustment = (GtkAdjustment*) g_object_new (GTK_TYPE_ADJUSTMENT, NULL);
bin = GTK_BIN (scrolled_window);
priv = scrolled_window->priv;
if (!priv->vscrollbar)
{
priv->vscrollbar = gtk_scrollbar_new (GTK_ORIENTATION_VERTICAL, vadjustment);
gtk_widget_set_parent (priv->vscrollbar, GTK_WIDGET (scrolled_window));
g_object_ref (priv->vscrollbar);
gtk_widget_show (priv->vscrollbar);
}
else
{
GtkAdjustment *old_adjustment;
old_adjustment = gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar));
if (old_adjustment == vadjustment)
return;
g_signal_handlers_disconnect_by_func (old_adjustment,
gtk_scrolled_window_adjustment_changed,
scrolled_window);
gtk_adjustment_enable_animation (old_adjustment, NULL, 0);
gtk_range_set_adjustment (GTK_RANGE (priv->vscrollbar), vadjustment);
}
vadjustment = gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar));
g_signal_connect (vadjustment,
"changed",
G_CALLBACK (gtk_scrolled_window_adjustment_changed),
scrolled_window);
g_signal_connect (vadjustment,
"value-changed",
G_CALLBACK (gtk_scrolled_window_adjustment_value_changed),
scrolled_window);
gtk_scrolled_window_adjustment_changed (vadjustment, scrolled_window);
gtk_scrolled_window_adjustment_value_changed (vadjustment, scrolled_window);
child = gtk_bin_get_child (bin);
if (GTK_IS_SCROLLABLE (child))
gtk_scrollable_set_vadjustment (GTK_SCROLLABLE (child), vadjustment);
if (gtk_scrolled_window_should_animate (scrolled_window))
gtk_adjustment_enable_animation (vadjustment, gtk_widget_get_frame_clock (GTK_WIDGET (scrolled_window)), ANIMATION_DURATION);
g_object_notify (G_OBJECT (scrolled_window), "vadjustment");
}
/**
* gtk_scrolled_window_get_hadjustment:
* @scrolled_window: a #GtkScrolledWindow
*
* Returns the horizontal scrollbar’s adjustment, used to connect the
* horizontal scrollbar to the child widget’s horizontal scroll
* functionality.
*
* Returns: (transfer none): the horizontal #GtkAdjustment
*/
GtkAdjustment*
gtk_scrolled_window_get_hadjustment (GtkScrolledWindow *scrolled_window)
{
GtkScrolledWindowPrivate *priv;
g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), NULL);
priv = scrolled_window->priv;
return gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar));
}
/**
* gtk_scrolled_window_get_vadjustment:
* @scrolled_window: a #GtkScrolledWindow
*
* Returns the vertical scrollbar’s adjustment, used to connect the
* vertical scrollbar to the child widget’s vertical scroll functionality.
*
* Returns: (transfer none): the vertical #GtkAdjustment
*/
GtkAdjustment*
gtk_scrolled_window_get_vadjustment (GtkScrolledWindow *scrolled_window)
{
GtkScrolledWindowPrivate *priv;
g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), NULL);
priv = scrolled_window->priv;
return gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar));
}
/**
* gtk_scrolled_window_get_hscrollbar:
* @scrolled_window: a #GtkScrolledWindow
*
* Returns the horizontal scrollbar of @scrolled_window.
*
* Returns: (transfer none): the horizontal scrollbar of the scrolled window.
*
* Since: 2.8
*/
GtkWidget*
gtk_scrolled_window_get_hscrollbar (GtkScrolledWindow *scrolled_window)
{
g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), NULL);
return scrolled_window->priv->hscrollbar;
}
/**
* gtk_scrolled_window_get_vscrollbar:
* @scrolled_window: a #GtkScrolledWindow
*
* Returns the vertical scrollbar of @scrolled_window.
*
* Returns: (transfer none): the vertical scrollbar of the scrolled window.
*
* Since: 2.8
*/
GtkWidget*
gtk_scrolled_window_get_vscrollbar (GtkScrolledWindow *scrolled_window)
{
g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), NULL);
return scrolled_window->priv->vscrollbar;
}
/**
* gtk_scrolled_window_set_policy:
* @scrolled_window: a #GtkScrolledWindow
* @hscrollbar_policy: policy for horizontal bar
* @vscrollbar_policy: policy for vertical bar
*
* Sets the scrollbar policy for the horizontal and vertical scrollbars.
*
* The policy determines when the scrollbar should appear; it is a value
* from the #GtkPolicyType enumeration. If %GTK_POLICY_ALWAYS, the
* scrollbar is always present; if %GTK_POLICY_NEVER, the scrollbar is
* never present; if %GTK_POLICY_AUTOMATIC, the scrollbar is present only
* if needed (that is, if the slider part of the bar would be smaller
* than the trough — the display is larger than the page size).
*/
void
gtk_scrolled_window_set_policy (GtkScrolledWindow *scrolled_window,
GtkPolicyType hscrollbar_policy,
GtkPolicyType vscrollbar_policy)
{
GtkScrolledWindowPrivate *priv;
GObject *object = G_OBJECT (scrolled_window);
g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
priv = scrolled_window->priv;
if ((priv->hscrollbar_policy != hscrollbar_policy) ||
(priv->vscrollbar_policy != vscrollbar_policy))
{
priv->hscrollbar_policy = hscrollbar_policy;
priv->vscrollbar_policy = vscrollbar_policy;
gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
g_object_freeze_notify (object);
g_object_notify (object, "hscrollbar-policy");
g_object_notify (object, "vscrollbar-policy");
g_object_thaw_notify (object);
}
}
/**
* gtk_scrolled_window_get_policy:
* @scrolled_window: a #GtkScrolledWindow
* @hscrollbar_policy: (out) (allow-none): location to store the policy
* for the horizontal scrollbar, or %NULL
* @vscrollbar_policy: (out) (allow-none): location to store the policy
* for the vertical scrollbar, or %NULL
*
* Retrieves the current policy values for the horizontal and vertical
* scrollbars. See gtk_scrolled_window_set_policy().
*/
void
gtk_scrolled_window_get_policy (GtkScrolledWindow *scrolled_window,
GtkPolicyType *hscrollbar_policy,
GtkPolicyType *vscrollbar_policy)
{
GtkScrolledWindowPrivate *priv;
g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
priv = scrolled_window->priv;
if (hscrollbar_policy)
*hscrollbar_policy = priv->hscrollbar_policy;
if (vscrollbar_policy)
*vscrollbar_policy = priv->vscrollbar_policy;
}
static void
gtk_scrolled_window_set_placement_internal (GtkScrolledWindow *scrolled_window,
GtkCornerType window_placement)
{
GtkScrolledWindowPrivate *priv = scrolled_window->priv;
if (priv->window_placement != window_placement)
{
priv->window_placement = window_placement;
gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
g_object_notify (G_OBJECT (scrolled_window), "window-placement");
}
}
/**
* gtk_scrolled_window_set_placement:
* @scrolled_window: a #GtkScrolledWindow
* @window_placement: position of the child window
*
* Sets the placement of the contents with respect to the scrollbars
* for the scrolled window.
*
* The default is %GTK_CORNER_TOP_LEFT, meaning the child is
* in the top left, with the scrollbars underneath and to the right.
* Other values in #GtkCornerType are %GTK_CORNER_TOP_RIGHT,
* %GTK_CORNER_BOTTOM_LEFT, and %GTK_CORNER_BOTTOM_RIGHT.
*
* See also gtk_scrolled_window_get_placement() and
* gtk_scrolled_window_unset_placement().
*/
void
gtk_scrolled_window_set_placement (GtkScrolledWindow *scrolled_window,
GtkCornerType window_placement)
{
g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
gtk_scrolled_window_set_placement_internal (scrolled_window, window_placement);
}
/**
* gtk_scrolled_window_get_placement:
* @scrolled_window: a #GtkScrolledWindow
*
* Gets the placement of the contents with respect to the scrollbars
* for the scrolled window. See gtk_scrolled_window_set_placement().
*
* Returns: the current placement value.
*
* See also gtk_scrolled_window_set_placement() and
* gtk_scrolled_window_unset_placement().
**/
GtkCornerType
gtk_scrolled_window_get_placement (GtkScrolledWindow *scrolled_window)
{
g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), GTK_CORNER_TOP_LEFT);
return scrolled_window->priv->window_placement;
}
/**
* gtk_scrolled_window_unset_placement:
* @scrolled_window: a #GtkScrolledWindow
*
* Unsets the placement of the contents with respect to the scrollbars
* for the scrolled window. If no window placement is set for a scrolled
* window, it defaults to %GTK_CORNER_TOP_LEFT.
*
* See also gtk_scrolled_window_set_placement() and
* gtk_scrolled_window_get_placement().
*
* Since: 2.10
**/
void
gtk_scrolled_window_unset_placement (GtkScrolledWindow *scrolled_window)
{
g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
gtk_scrolled_window_set_placement_internal (scrolled_window, GTK_CORNER_TOP_LEFT);
}
/**
* gtk_scrolled_window_set_shadow_type:
* @scrolled_window: a #GtkScrolledWindow
* @type: kind of shadow to draw around scrolled window contents
*
* Changes the type of shadow drawn around the contents of
* @scrolled_window.
**/
void
gtk_scrolled_window_set_shadow_type (GtkScrolledWindow *scrolled_window,
GtkShadowType type)
{
GtkScrolledWindowPrivate *priv;
GtkStyleContext *context;
g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
g_return_if_fail (type >= GTK_SHADOW_NONE && type <= GTK_SHADOW_ETCHED_OUT);
priv = scrolled_window->priv;
if (priv->shadow_type != type)
{
priv->shadow_type = type;
context = gtk_widget_get_style_context (GTK_WIDGET (scrolled_window));
if (type != GTK_SHADOW_NONE)
gtk_style_context_add_class (context, GTK_STYLE_CLASS_FRAME);
else
gtk_style_context_remove_class (context, GTK_STYLE_CLASS_FRAME);
if (gtk_widget_is_drawable (GTK_WIDGET (scrolled_window)))
gtk_widget_queue_draw (GTK_WIDGET (scrolled_window));
gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
g_object_notify (G_OBJECT (scrolled_window), "shadow-type");
}
}
/**
* gtk_scrolled_window_get_shadow_type:
* @scrolled_window: a #GtkScrolledWindow
*
* Gets the shadow type of the scrolled window. See
* gtk_scrolled_window_set_shadow_type().
*
* Returns: the current shadow type
**/
GtkShadowType
gtk_scrolled_window_get_shadow_type (GtkScrolledWindow *scrolled_window)
{
g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), GTK_SHADOW_NONE);
return scrolled_window->priv->shadow_type;
}
/**
* gtk_scrolled_window_set_kinetic_scrolling:
* @scrolled_window: a #GtkScrolledWindow
* @kinetic_scrolling: %TRUE to enable kinetic scrolling
*
* Turns kinetic scrolling on or off.
* Kinetic scrolling only applies to devices with source
* %GDK_SOURCE_TOUCHSCREEN.
*
* Since: 3.4
**/
void
gtk_scrolled_window_set_kinetic_scrolling (GtkScrolledWindow *scrolled_window,
gboolean kinetic_scrolling)
{
GtkPropagationPhase phase = GTK_PHASE_NONE;
GtkScrolledWindowPrivate *priv;
g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
priv = scrolled_window->priv;
if (priv->kinetic_scrolling == kinetic_scrolling)
return;
priv->kinetic_scrolling = kinetic_scrolling;
gtk_scrolled_window_check_attach_pan_gesture (scrolled_window);
if (priv->kinetic_scrolling)
phase = GTK_PHASE_CAPTURE;
else
gtk_scrolled_window_cancel_deceleration (scrolled_window);
gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (priv->drag_gesture), phase);
gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (priv->swipe_gesture), phase);
gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (priv->long_press_gesture), phase);
gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (priv->pan_gesture), phase);
g_object_notify (G_OBJECT (scrolled_window), "kinetic-scrolling");
}
/**
* gtk_scrolled_window_get_kinetic_scrolling:
* @scrolled_window: a #GtkScrolledWindow
*
* Returns the specified kinetic scrolling behavior.
*
* Returns: the scrolling behavior flags.
*
* Since: 3.4
*/
gboolean
gtk_scrolled_window_get_kinetic_scrolling (GtkScrolledWindow *scrolled_window)
{
g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), FALSE);
return scrolled_window->priv->kinetic_scrolling;
}
/**
* gtk_scrolled_window_set_capture_button_press:
* @scrolled_window: a #GtkScrolledWindow
* @capture_button_press: %TRUE to capture button presses
*
* Changes the behaviour of @scrolled_window wrt. to the initial
* event that possibly starts kinetic scrolling. When @capture_button_press
* is set to %TRUE, the event is captured by the scrolled window, and
* then later replayed if it is meant to go to the child widget.
*
* This should be enabled if any child widgets perform non-reversible
* actions on #GtkWidget::button-press-event. If they don't, and handle
* additionally handle #GtkWidget::grab-broken-event, it might be better
* to set @capture_button_press to %FALSE.
*
* This setting only has an effect if kinetic scrolling is enabled.
*
* Since: 3.4
*/
void
gtk_scrolled_window_set_capture_button_press (GtkScrolledWindow *scrolled_window,
gboolean capture_button_press)
{
g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
scrolled_window->priv->capture_button_press = capture_button_press;
}
/**
* gtk_scrolled_window_get_capture_button_press:
* @scrolled_window: a #GtkScrolledWindow
*
* Return whether button presses are captured during kinetic
* scrolling. See gtk_scrolled_window_set_capture_button_press().
*
* Returns: %TRUE if button presses are captured during kinetic scrolling
*
* Since: 3.4
*/
gboolean
gtk_scrolled_window_get_capture_button_press (GtkScrolledWindow *scrolled_window)
{
g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), FALSE);
return scrolled_window->priv->capture_button_press;
}
static void
gtk_scrolled_window_destroy (GtkWidget *widget)
{
GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (widget);
GtkScrolledWindowPrivate *priv = scrolled_window->priv;
if (priv->hscrollbar)
{
g_signal_handlers_disconnect_by_func (gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar)),
gtk_scrolled_window_adjustment_changed,
scrolled_window);
gtk_widget_unparent (priv->hscrollbar);
gtk_widget_destroy (priv->hscrollbar);
g_object_unref (priv->hscrollbar);
priv->hscrollbar = NULL;
}
if (priv->vscrollbar)
{
g_signal_handlers_disconnect_by_func (gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar)),
gtk_scrolled_window_adjustment_changed,
scrolled_window);
gtk_widget_unparent (priv->vscrollbar);
gtk_widget_destroy (priv->vscrollbar);
g_object_unref (priv->vscrollbar);
priv->vscrollbar = NULL;
}
if (priv->deceleration_id)
{
gtk_widget_remove_tick_callback (widget, priv->deceleration_id);
priv->deceleration_id = 0;
}
if (priv->scroll_events_overshoot_id)
{
g_source_remove (priv->scroll_events_overshoot_id);
priv->scroll_events_overshoot_id = 0;
}
g_clear_object (&priv->drag_gesture);
g_clear_object (&priv->swipe_gesture);
g_clear_object (&priv->long_press_gesture);
GTK_WIDGET_CLASS (gtk_scrolled_window_parent_class)->destroy (widget);
}
static void
gtk_scrolled_window_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (object);
GtkScrolledWindowPrivate *priv = scrolled_window->priv;
switch (prop_id)
{
case PROP_HADJUSTMENT:
gtk_scrolled_window_set_hadjustment (scrolled_window,
g_value_get_object (value));
break;
case PROP_VADJUSTMENT:
gtk_scrolled_window_set_vadjustment (scrolled_window,
g_value_get_object (value));
break;
case PROP_HSCROLLBAR_POLICY:
gtk_scrolled_window_set_policy (scrolled_window,
g_value_get_enum (value),
priv->vscrollbar_policy);
break;
case PROP_VSCROLLBAR_POLICY:
gtk_scrolled_window_set_policy (scrolled_window,
priv->hscrollbar_policy,
g_value_get_enum (value));
break;
case PROP_WINDOW_PLACEMENT:
gtk_scrolled_window_set_placement_internal (scrolled_window,
g_value_get_enum (value));
break;
case PROP_WINDOW_PLACEMENT_SET:
/* noop */
break;
case PROP_SHADOW_TYPE:
gtk_scrolled_window_set_shadow_type (scrolled_window,
g_value_get_enum (value));
break;
case PROP_MIN_CONTENT_WIDTH:
gtk_scrolled_window_set_min_content_width (scrolled_window,
g_value_get_int (value));
break;
case PROP_MIN_CONTENT_HEIGHT:
gtk_scrolled_window_set_min_content_height (scrolled_window,
g_value_get_int (value));
break;
case PROP_KINETIC_SCROLLING:
gtk_scrolled_window_set_kinetic_scrolling (scrolled_window,
g_value_get_boolean (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gtk_scrolled_window_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (object);
GtkScrolledWindowPrivate *priv = scrolled_window->priv;
switch (prop_id)
{
case PROP_HADJUSTMENT:
g_value_set_object (value,
G_OBJECT (gtk_scrolled_window_get_hadjustment (scrolled_window)));
break;
case PROP_VADJUSTMENT:
g_value_set_object (value,
G_OBJECT (gtk_scrolled_window_get_vadjustment (scrolled_window)));
break;
case PROP_WINDOW_PLACEMENT:
g_value_set_enum (value, priv->window_placement);
break;
case PROP_WINDOW_PLACEMENT_SET:
g_value_set_boolean (value, TRUE);
break;
case PROP_SHADOW_TYPE:
g_value_set_enum (value, priv->shadow_type);
break;
case PROP_HSCROLLBAR_POLICY:
g_value_set_enum (value, priv->hscrollbar_policy);
break;
case PROP_VSCROLLBAR_POLICY:
g_value_set_enum (value, priv->vscrollbar_policy);
break;
case PROP_MIN_CONTENT_WIDTH:
g_value_set_int (value, priv->min_content_width);
break;
case PROP_MIN_CONTENT_HEIGHT:
g_value_set_int (value, priv->min_content_height);
break;
case PROP_KINETIC_SCROLLING:
g_value_set_boolean (value, priv->kinetic_scrolling);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gtk_scrolled_window_draw_scrollbars_junction (GtkScrolledWindow *scrolled_window,
cairo_t *cr)
{
GtkScrolledWindowPrivate *priv = scrolled_window->priv;
GtkWidget *widget = GTK_WIDGET (scrolled_window);
GtkAllocation hscr_allocation, vscr_allocation;
GtkStyleContext *context;
GdkRectangle junction_rect;
gboolean is_rtl, scrollbars_within_bevel;
is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
gtk_widget_get_allocation (GTK_WIDGET (priv->hscrollbar), &hscr_allocation);
gtk_widget_get_allocation (GTK_WIDGET (priv->vscrollbar), &vscr_allocation);
gtk_widget_style_get (widget,
"scrollbars-within-bevel", &scrollbars_within_bevel,
NULL);
context = gtk_widget_get_style_context (widget);
if (scrollbars_within_bevel &&
priv->shadow_type != GTK_SHADOW_NONE)
{
GtkStateFlags state;
GtkBorder padding, border;
state = gtk_widget_get_state_flags (widget);
gtk_style_context_get_padding (context, state, &padding);
gtk_style_context_get_border (context, state, &border);
junction_rect.x = padding.left + border.left;
junction_rect.y = padding.top + border.top;
}
else
{
junction_rect.x = 0;
junction_rect.y = 0;
}
junction_rect.width = vscr_allocation.width;
junction_rect.height = hscr_allocation.height;
if ((is_rtl &&
(priv->window_placement == GTK_CORNER_TOP_RIGHT ||
priv->window_placement == GTK_CORNER_BOTTOM_RIGHT)) ||
(!is_rtl &&
(priv->window_placement == GTK_CORNER_TOP_LEFT ||
priv->window_placement == GTK_CORNER_BOTTOM_LEFT)))
junction_rect.x += hscr_allocation.width;
if (priv->window_placement == GTK_CORNER_TOP_LEFT ||
priv->window_placement == GTK_CORNER_TOP_RIGHT)
junction_rect.y += vscr_allocation.height;
gtk_style_context_save (context);
gtk_style_context_add_class (context, GTK_STYLE_CLASS_SCROLLBARS_JUNCTION);
gtk_render_background (context, cr,
junction_rect.x, junction_rect.y,
junction_rect.width, junction_rect.height);
gtk_render_frame (context, cr,
junction_rect.x, junction_rect.y,
junction_rect.width, junction_rect.height);
gtk_style_context_restore (context);
}
static void
gtk_scrolled_window_draw_overshoot (GtkScrolledWindow *scrolled_window,
cairo_t *cr)
{
GtkWidget *widget = GTK_WIDGET (scrolled_window);
gint overshoot_x, overshoot_y;
GtkStyleContext *context;
GdkRectangle rect;
if (!_gtk_scrolled_window_get_overshoot (scrolled_window, &overshoot_x, &overshoot_y))
return;
context = gtk_widget_get_style_context (widget);
gtk_scrolled_window_relative_allocation (widget, &rect);
overshoot_x = CLAMP (overshoot_x, - MAX_OVERSHOOT_DISTANCE, MAX_OVERSHOOT_DISTANCE);
overshoot_y = CLAMP (overshoot_y, - MAX_OVERSHOOT_DISTANCE, MAX_OVERSHOOT_DISTANCE);
gtk_style_context_save (context);
gtk_style_context_remove_class (context, GTK_STYLE_CLASS_FRAME);
gtk_style_context_add_class (context, GTK_STYLE_CLASS_OVERSHOOT);
if (overshoot_x > 0)
{
gtk_style_context_add_class (context, GTK_STYLE_CLASS_RIGHT);
gtk_render_background (context, cr, rect.x + rect.width - overshoot_x, rect.y, overshoot_x, rect.height);
gtk_render_frame (context, cr, rect.x + rect.width - overshoot_x, rect.y, overshoot_x, rect.height);
}
else if (overshoot_x < 0)
{
gtk_style_context_add_class (context, GTK_STYLE_CLASS_LEFT);
gtk_render_background (context, cr, rect.x, rect.y, -overshoot_x, rect.height);
gtk_render_frame (context, cr, rect.x, rect.y, -overshoot_x, rect.height);
}
gtk_style_context_restore (context);
gtk_style_context_save (context);
gtk_style_context_remove_class (context, GTK_STYLE_CLASS_FRAME);
gtk_style_context_add_class (context, GTK_STYLE_CLASS_OVERSHOOT);
if (overshoot_y > 0)
{
gtk_style_context_add_class (context, GTK_STYLE_CLASS_BOTTOM);
gtk_render_background (context, cr, rect.x, rect.y + rect.height - overshoot_y, rect.width, overshoot_y);
gtk_render_frame (context, cr, rect.x, rect.y + rect.height - overshoot_y, rect.width, overshoot_y);
}
else if (overshoot_y < 0)
{
gtk_style_context_add_class (context, GTK_STYLE_CLASS_TOP);
gtk_render_background (context, cr, rect.x, rect.y, rect.width, -overshoot_y);
gtk_render_frame (context, cr, rect.x, rect.y, rect.width, -overshoot_y);
}
gtk_style_context_restore (context);
}
static gboolean
gtk_scrolled_window_draw (GtkWidget *widget,
cairo_t *cr)
{
GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (widget);
GtkScrolledWindowPrivate *priv = scrolled_window->priv;
GtkAllocation relative_allocation;
GtkStyleContext *context;
gboolean scrollbars_within_bevel;
context = gtk_widget_get_style_context (widget);
gtk_scrolled_window_relative_allocation (widget, &relative_allocation);
gtk_render_background (context, cr,
0, 0,
gtk_widget_get_allocated_width (widget),
gtk_widget_get_allocated_height (widget));
if (priv->hscrollbar_visible &&
priv->vscrollbar_visible)
gtk_scrolled_window_draw_scrollbars_junction (scrolled_window, cr);
gtk_widget_style_get (widget, "scrollbars-within-bevel", &scrollbars_within_bevel, NULL);
if (!scrollbars_within_bevel)
{
GtkStateFlags state;
GtkBorder padding, border;
state = gtk_widget_get_state_flags (widget);
gtk_style_context_get_padding (context, state, &padding);
gtk_style_context_get_border (context, state, &border);
relative_allocation.x -= padding.left + border.left;
relative_allocation.y -= padding.top + border.top;
relative_allocation.width += padding.left + padding.right + border.left + border.right;
relative_allocation.height += padding.top + padding.bottom + border.top + border.bottom;
}
else
{
relative_allocation.x = 0;
relative_allocation.y = 0;
relative_allocation.width = gtk_widget_get_allocated_width (widget);
relative_allocation.height = gtk_widget_get_allocated_height (widget);
}
gtk_render_frame (context, cr,
relative_allocation.x,
relative_allocation.y,
relative_allocation.width,
relative_allocation.height);
GTK_WIDGET_CLASS (gtk_scrolled_window_parent_class)->draw (widget, cr);
gtk_scrolled_window_draw_overshoot (scrolled_window, cr);
return FALSE;
}
static void
gtk_scrolled_window_forall (GtkContainer *container,
gboolean include_internals,
GtkCallback callback,
gpointer callback_data)
{
GtkScrolledWindowPrivate *priv;
GtkScrolledWindow *scrolled_window;
GTK_CONTAINER_CLASS (gtk_scrolled_window_parent_class)->forall (container,
include_internals,
callback,
callback_data);
if (include_internals)
{
scrolled_window = GTK_SCROLLED_WINDOW (container);
priv = scrolled_window->priv;
if (priv->vscrollbar)
callback (priv->vscrollbar, callback_data);
if (priv->hscrollbar)
callback (priv->hscrollbar, callback_data);
}
}
static gboolean
gtk_scrolled_window_scroll_child (GtkScrolledWindow *scrolled_window,
GtkScrollType scroll,
gboolean horizontal)
{
GtkScrolledWindowPrivate *priv = scrolled_window->priv;
GtkAdjustment *adjustment = NULL;
switch (scroll)
{
case GTK_SCROLL_STEP_UP:
scroll = GTK_SCROLL_STEP_BACKWARD;
horizontal = FALSE;
break;
case GTK_SCROLL_STEP_DOWN:
scroll = GTK_SCROLL_STEP_FORWARD;
horizontal = FALSE;
break;
case GTK_SCROLL_STEP_LEFT:
scroll = GTK_SCROLL_STEP_BACKWARD;
horizontal = TRUE;
break;
case GTK_SCROLL_STEP_RIGHT:
scroll = GTK_SCROLL_STEP_FORWARD;
horizontal = TRUE;
break;
case GTK_SCROLL_PAGE_UP:
scroll = GTK_SCROLL_PAGE_BACKWARD;
horizontal = FALSE;
break;
case GTK_SCROLL_PAGE_DOWN:
scroll = GTK_SCROLL_PAGE_FORWARD;
horizontal = FALSE;
break;
case GTK_SCROLL_PAGE_LEFT:
scroll = GTK_SCROLL_STEP_BACKWARD;
horizontal = TRUE;
break;
case GTK_SCROLL_PAGE_RIGHT:
scroll = GTK_SCROLL_STEP_FORWARD;
horizontal = TRUE;
break;
case GTK_SCROLL_STEP_BACKWARD:
case GTK_SCROLL_STEP_FORWARD:
case GTK_SCROLL_PAGE_BACKWARD:
case GTK_SCROLL_PAGE_FORWARD:
case GTK_SCROLL_START:
case GTK_SCROLL_END:
break;
default:
g_warning ("Invalid scroll type %u for GtkScrolledWindow::scroll-child", scroll);
return FALSE;
}
if (horizontal)
adjustment = gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar));
else
adjustment = gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar));
if (adjustment)
{
gdouble value = gtk_adjustment_get_value (adjustment);
switch (scroll)
{
case GTK_SCROLL_STEP_FORWARD:
value += gtk_adjustment_get_step_increment (adjustment);
break;
case GTK_SCROLL_STEP_BACKWARD:
value -= gtk_adjustment_get_step_increment (adjustment);
break;
case GTK_SCROLL_PAGE_FORWARD:
value += gtk_adjustment_get_page_increment (adjustment);
break;
case GTK_SCROLL_PAGE_BACKWARD:
value -= gtk_adjustment_get_page_increment (adjustment);
break;
case GTK_SCROLL_START:
value = gtk_adjustment_get_lower (adjustment);
break;
case GTK_SCROLL_END:
value = gtk_adjustment_get_upper (adjustment);
break;
default:
g_assert_not_reached ();
break;
}
gtk_adjustment_animate_to_value (adjustment, value);
return TRUE;
}
return FALSE;
}
static void
gtk_scrolled_window_move_focus_out (GtkScrolledWindow *scrolled_window,
GtkDirectionType direction_type)
{
GtkScrolledWindowPrivate *priv = scrolled_window->priv;
GtkWidget *toplevel;
/* Focus out of the scrolled window entirely. We do this by setting
* a flag, then propagating the focus motion to the notebook.
*/
toplevel = gtk_widget_get_toplevel (GTK_WIDGET (scrolled_window));
if (!gtk_widget_is_toplevel (toplevel))
return;
g_object_ref (scrolled_window);
priv->focus_out = TRUE;
g_signal_emit_by_name (toplevel, "move-focus", direction_type);
priv->focus_out = FALSE;
g_object_unref (scrolled_window);
}
static void
gtk_scrolled_window_relative_allocation (GtkWidget *widget,
GtkAllocation *allocation)
{
GtkAllocation widget_allocation;
GtkScrolledWindow *scrolled_window;
GtkScrolledWindowPrivate *priv;
gint sb_spacing;
gint sb_width;
gint sb_height;
g_return_if_fail (widget != NULL);
g_return_if_fail (allocation != NULL);
scrolled_window = GTK_SCROLLED_WINDOW (widget);
priv = scrolled_window->priv;
/* Get possible scrollbar dimensions */
sb_spacing = _gtk_scrolled_window_get_scrollbar_spacing (scrolled_window);
gtk_widget_get_preferred_height (priv->hscrollbar, &sb_height, NULL);
gtk_widget_get_preferred_width (priv->vscrollbar, &sb_width, NULL);
gtk_widget_get_allocation (widget, &widget_allocation);
allocation->x = 0;
allocation->y = 0;
allocation->width = widget_allocation.width;
allocation->height = widget_allocation.height;
/* Subtract some things from our available allocation size */
if (priv->shadow_type != GTK_SHADOW_NONE)
{
GtkStyleContext *context;
GtkStateFlags state;
GtkBorder padding, border;
context = gtk_widget_get_style_context (widget);
state = gtk_widget_get_state_flags (widget);
gtk_style_context_save (context);
gtk_style_context_add_class (context, GTK_STYLE_CLASS_FRAME);
gtk_style_context_get_border (context, state, &border);
gtk_style_context_get_padding (context, state, &padding);
allocation->x += padding.left + border.left;
allocation->y += padding.top + border.top;
allocation->width = MAX (1, allocation->width - (padding.left + border.left + padding.right + border.right));
allocation->height = MAX (1, allocation->height - (padding.top + border.top + padding.bottom + border.bottom));
gtk_style_context_restore (context);
}
if (priv->vscrollbar_visible)
{
gboolean is_rtl;
is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
if ((!is_rtl &&
(priv->window_placement == GTK_CORNER_TOP_RIGHT ||
priv->window_placement == GTK_CORNER_BOTTOM_RIGHT)) ||
(is_rtl &&
(priv->window_placement == GTK_CORNER_TOP_LEFT ||
priv->window_placement == GTK_CORNER_BOTTOM_LEFT)))
allocation->x += (sb_width + sb_spacing);
allocation->width = MAX (1, allocation->width - (sb_width + sb_spacing));
}
if (priv->hscrollbar_visible)
{
if (priv->window_placement == GTK_CORNER_BOTTOM_LEFT ||
priv->window_placement == GTK_CORNER_BOTTOM_RIGHT)
allocation->y += (sb_height + sb_spacing);
allocation->height = MAX (1, allocation->height - (sb_height + sb_spacing));
}
}
static gboolean
_gtk_scrolled_window_get_overshoot (GtkScrolledWindow *scrolled_window,
gint *overshoot_x,
gint *overshoot_y)
{
GtkScrolledWindowPrivate *priv = scrolled_window->priv;
GtkAdjustment *vadjustment, *hadjustment;
gdouble lower, upper, x, y;
/* Vertical overshoot */
vadjustment = gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar));
lower = gtk_adjustment_get_lower (vadjustment);
upper = gtk_adjustment_get_upper (vadjustment) -
gtk_adjustment_get_page_size (vadjustment);
if (priv->unclamped_vadj_value < lower)
y = priv->unclamped_vadj_value - lower;
else if (priv->unclamped_vadj_value > upper)
y = priv->unclamped_vadj_value - upper;
else
y = 0;
/* Horizontal overshoot */
hadjustment = gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar));
lower = gtk_adjustment_get_lower (hadjustment);
upper = gtk_adjustment_get_upper (hadjustment) -
gtk_adjustment_get_page_size (hadjustment);
if (priv->unclamped_hadj_value < lower)
x = priv->unclamped_hadj_value - lower;
else if (priv->unclamped_hadj_value > upper)
x = priv->unclamped_hadj_value - upper;
else
x = 0;
if (overshoot_x)
*overshoot_x = x;
if (overshoot_y)
*overshoot_y = y;
return (x != 0 || y != 0);
}
static void
gtk_scrolled_window_allocate_child (GtkScrolledWindow *swindow,
GtkAllocation *relative_allocation)
{
GtkWidget *widget = GTK_WIDGET (swindow), *child;
GtkAllocation allocation;
GtkAllocation child_allocation;
child = gtk_bin_get_child (GTK_BIN (widget));
gtk_widget_get_allocation (widget, &allocation);
gtk_scrolled_window_relative_allocation (widget, relative_allocation);
child_allocation.x = relative_allocation->x + allocation.x;
child_allocation.y = relative_allocation->y + allocation.y;
child_allocation.width = relative_allocation->width;
child_allocation.height = relative_allocation->height;
gtk_widget_size_allocate (child, &child_allocation);
}
static void
gtk_scrolled_window_size_allocate (GtkWidget *widget,
GtkAllocation *allocation)
{
GtkScrolledWindow *scrolled_window;
GtkScrolledWindowPrivate *priv;
GtkStyleContext *context;
GtkStateFlags state;
GtkBorder padding, border;
GtkBin *bin;
GtkAllocation relative_allocation;
GtkAllocation child_allocation;
GtkWidget *child;
gboolean scrollbars_within_bevel;
gint sb_spacing;
gint sb_width;
gint sb_height;
scrolled_window = GTK_SCROLLED_WINDOW (widget);
bin = GTK_BIN (scrolled_window);
priv = scrolled_window->priv;
/* Get possible scrollbar dimensions */
sb_spacing = _gtk_scrolled_window_get_scrollbar_spacing (scrolled_window);
gtk_widget_get_preferred_height (priv->hscrollbar, &sb_height, NULL);
gtk_widget_get_preferred_width (priv->vscrollbar, &sb_width, NULL);
context = gtk_widget_get_style_context (widget);
state = gtk_widget_get_state_flags (widget);
gtk_style_context_save (context);
gtk_style_context_add_class (context, GTK_STYLE_CLASS_FRAME);
gtk_style_context_get_padding (context, state, &padding);
gtk_style_context_get_border (context, state, &border);
gtk_widget_style_get (widget, "scrollbars-within-bevel", &scrollbars_within_bevel, NULL);
gtk_widget_set_allocation (widget, allocation);
gtk_style_context_restore (context);
if (priv->hscrollbar_policy == GTK_POLICY_ALWAYS)
priv->hscrollbar_visible = TRUE;
else if (priv->hscrollbar_policy == GTK_POLICY_NEVER ||
priv->hscrollbar_policy == GTK_POLICY_EXTERNAL)
priv->hscrollbar_visible = FALSE;
if (priv->vscrollbar_policy == GTK_POLICY_ALWAYS)
priv->vscrollbar_visible = TRUE;
else if (priv->vscrollbar_policy == GTK_POLICY_NEVER ||
priv->vscrollbar_policy == GTK_POLICY_EXTERNAL)
priv->vscrollbar_visible = FALSE;
child = gtk_bin_get_child (bin);
if (child && gtk_widget_get_visible (child))
{
gint child_scroll_width;
gint child_scroll_height;
GtkScrollablePolicy hscroll_policy;
GtkScrollablePolicy vscroll_policy;
gboolean previous_hvis;
gboolean previous_vvis;
guint count = 0;
hscroll_policy = GTK_IS_SCROLLABLE (child)
? gtk_scrollable_get_hscroll_policy (GTK_SCROLLABLE (child))
: GTK_SCROLL_MINIMUM;
vscroll_policy = GTK_IS_SCROLLABLE (child)
? gtk_scrollable_get_vscroll_policy (GTK_SCROLLABLE (child))
: GTK_SCROLL_MINIMUM;
/* Determine scrollbar visibility first via hfw apis */
if (gtk_widget_get_request_mode (child) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
{
if (hscroll_policy == GTK_SCROLL_MINIMUM)
gtk_widget_get_preferred_width (child, &child_scroll_width, NULL);
else
gtk_widget_get_preferred_width (child, NULL, &child_scroll_width);
if (priv->vscrollbar_policy == GTK_POLICY_AUTOMATIC)
{
/* First try without a vertical scrollbar if the content will fit the height
* given the extra width of the scrollbar */
if (vscroll_policy == GTK_SCROLL_MINIMUM)
gtk_widget_get_preferred_height_for_width (child,
MAX (allocation->width, child_scroll_width),
&child_scroll_height, NULL);
else
gtk_widget_get_preferred_height_for_width (child,
MAX (allocation->width, child_scroll_width),
NULL, &child_scroll_height);
if (priv->hscrollbar_policy == GTK_POLICY_AUTOMATIC)
{
/* Does the content height fit the allocation height ? */
priv->vscrollbar_visible = child_scroll_height > allocation->height;
/* Does the content width fit the allocation with minus a possible scrollbar ? */
priv->hscrollbar_visible =
child_scroll_width > allocation->width -
(priv->vscrollbar_visible ? sb_width + sb_spacing : 0);
/* Now that we've guessed the hscrollbar, does the content height fit
* the possible new allocation height ? */
priv->vscrollbar_visible =
child_scroll_height > allocation->height -
(priv->hscrollbar_visible ? sb_height + sb_spacing : 0);
/* Now that we've guessed the vscrollbar, does the content width fit
* the possible new allocation width ? */
priv->hscrollbar_visible =
child_scroll_width > allocation->width -
(priv->vscrollbar_visible ? sb_width + sb_spacing : 0);
}
else /* priv->hscrollbar_policy != GTK_POLICY_AUTOMATIC */
{
priv->hscrollbar_visible = policy_may_be_visible (priv->hscrollbar_policy);
priv->vscrollbar_visible = child_scroll_height > allocation->height -
(priv->hscrollbar_visible ? sb_height + sb_spacing : 0);
}
}
else /* priv->vscrollbar_policy != GTK_POLICY_AUTOMATIC */
{
priv->vscrollbar_visible = policy_may_be_visible (priv->vscrollbar_policy);
if (priv->hscrollbar_policy == GTK_POLICY_AUTOMATIC)
priv->hscrollbar_visible =
child_scroll_width > allocation->width -
(priv->vscrollbar_visible ? 0 : sb_width + sb_spacing);
else
priv->hscrollbar_visible = policy_may_be_visible (priv->hscrollbar_policy);
}
}
else /* GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT */
{
if (vscroll_policy == GTK_SCROLL_MINIMUM)
gtk_widget_get_preferred_height (child, &child_scroll_height, NULL);
else
gtk_widget_get_preferred_height (child, NULL, &child_scroll_height);
if (priv->hscrollbar_policy == GTK_POLICY_AUTOMATIC)
{
/* First try without a horizontal scrollbar if the content will fit the width
* given the extra height of the scrollbar */
if (hscroll_policy == GTK_SCROLL_MINIMUM)
gtk_widget_get_preferred_width_for_height (child,
MAX (allocation->height, child_scroll_height),
&child_scroll_width, NULL);
else
gtk_widget_get_preferred_width_for_height (child,
MAX (allocation->height, child_scroll_height),
NULL, &child_scroll_width);
if (priv->vscrollbar_policy == GTK_POLICY_AUTOMATIC)
{
/* Does the content width fit the allocation width ? */
priv->hscrollbar_visible = child_scroll_width > allocation->width;
/* Does the content height fit the allocation with minus a possible scrollbar ? */
priv->vscrollbar_visible =
child_scroll_height > allocation->height -
(priv->hscrollbar_visible ? sb_height + sb_spacing : 0);
/* Now that we've guessed the vscrollbar, does the content width fit
* the possible new allocation width ? */
priv->hscrollbar_visible =
child_scroll_width > allocation->width -
(priv->vscrollbar_visible ? sb_width + sb_spacing : 0);
/* Now that we've guessed the hscrollbar, does the content height fit
* the possible new allocation height ? */
priv->vscrollbar_visible =
child_scroll_height > allocation->height -
(priv->hscrollbar_visible ? sb_height + sb_spacing : 0);
}
else /* priv->vscrollbar_policy != GTK_POLICY_AUTOMATIC */
{
priv->vscrollbar_visible = policy_may_be_visible (priv->vscrollbar_policy);
priv->hscrollbar_visible = child_scroll_width > allocation->width -
(priv->vscrollbar_visible ? sb_width + sb_spacing : 0);
}
}
else /* priv->hscrollbar_policy != GTK_POLICY_AUTOMATIC */
{
priv->hscrollbar_visible = policy_may_be_visible (priv->hscrollbar_policy);
if (priv->vscrollbar_policy == GTK_POLICY_AUTOMATIC)
priv->vscrollbar_visible =
child_scroll_height > allocation->height -
(priv->hscrollbar_visible ? 0 : sb_height + sb_spacing);
else
priv->vscrollbar_visible = policy_may_be_visible (priv->vscrollbar_policy);
}
}
/* Now after guessing scrollbar visibility; fall back on the allocation loop which
* observes the adjustments to detect scrollbar visibility and also avoids
* infinite recursion
*/
do
{
previous_hvis = priv->hscrollbar_visible;
previous_vvis = priv->vscrollbar_visible;
gtk_scrolled_window_allocate_child (scrolled_window, &relative_allocation);
/* Explicitly force scrollbar visibility checks.
*
* Since we make a guess above, the child might not decide to update the adjustments
* if they logically did not change since the last configuration
*/
if (priv->hscrollbar)
gtk_scrolled_window_adjustment_changed
(gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar)), scrolled_window);
if (priv->vscrollbar)
gtk_scrolled_window_adjustment_changed
(gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar)), scrolled_window);
/* If, after the first iteration, the hscrollbar and the
* vscrollbar flip visiblity... or if one of the scrollbars flip
* on each itteration indefinitly/infinitely, then we just need both
* at this size.
*/
if ((count &&
previous_hvis != priv->hscrollbar_visible &&
previous_vvis != priv->vscrollbar_visible) || count > 3)
{
priv->hscrollbar_visible = TRUE;
priv->vscrollbar_visible = TRUE;
gtk_scrolled_window_allocate_child (scrolled_window, &relative_allocation);
break;
}
count++;
}
while (previous_hvis != priv->hscrollbar_visible ||
previous_vvis != priv->vscrollbar_visible);
}
else
{
priv->hscrollbar_visible = priv->hscrollbar_policy == GTK_POLICY_ALWAYS;
priv->vscrollbar_visible = priv->vscrollbar_policy == GTK_POLICY_ALWAYS;
gtk_scrolled_window_relative_allocation (widget, &relative_allocation);
}
gtk_widget_set_child_visible (priv->hscrollbar, priv->hscrollbar_visible);
if (priv->hscrollbar_visible)
{
child_allocation.x = relative_allocation.x;
if (priv->window_placement == GTK_CORNER_TOP_LEFT ||
priv->window_placement == GTK_CORNER_TOP_RIGHT)
child_allocation.y = (relative_allocation.y +
relative_allocation.height +
sb_spacing);
else
child_allocation.y = relative_allocation.y - sb_spacing - sb_height;
child_allocation.width = relative_allocation.width;
child_allocation.height = sb_height;
child_allocation.x += allocation->x;
child_allocation.y += allocation->y;
if (priv->shadow_type != GTK_SHADOW_NONE)
{
if (!scrollbars_within_bevel)
{
child_allocation.x -= padding.left + border.left;
child_allocation.width += padding.left + padding.right + border.left + border.right;
if (priv->window_placement == GTK_CORNER_TOP_LEFT ||
priv->window_placement == GTK_CORNER_TOP_RIGHT)
child_allocation.y += padding.bottom + border.bottom;
else
child_allocation.y -= padding.top + border.top;
}
}
gtk_widget_size_allocate (priv->hscrollbar, &child_allocation);
}
gtk_widget_set_child_visible (priv->vscrollbar, priv->vscrollbar_visible);
if (priv->vscrollbar_visible)
{
if ((gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL &&
(priv->window_placement == GTK_CORNER_TOP_RIGHT ||
priv->window_placement == GTK_CORNER_BOTTOM_RIGHT)) ||
(gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR &&
(priv->window_placement == GTK_CORNER_TOP_LEFT ||
priv->window_placement == GTK_CORNER_BOTTOM_LEFT)))
child_allocation.x = (relative_allocation.x +
relative_allocation.width +
sb_spacing);
else
child_allocation.x = relative_allocation.x - sb_spacing - sb_width;
child_allocation.y = relative_allocation.y;
child_allocation.width = sb_width;
child_allocation.height = relative_allocation.height;
child_allocation.x += allocation->x;
child_allocation.y += allocation->y;
if (priv->shadow_type != GTK_SHADOW_NONE)
{
if (!scrollbars_within_bevel)
{
child_allocation.y -= padding.top + border.top;
child_allocation.height += padding.top + padding.bottom + border.top + border.bottom;
if ((gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL &&
(priv->window_placement == GTK_CORNER_TOP_RIGHT ||
priv->window_placement == GTK_CORNER_BOTTOM_RIGHT)) ||
(gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR &&
(priv->window_placement == GTK_CORNER_TOP_LEFT ||
priv->window_placement == GTK_CORNER_BOTTOM_LEFT)))
child_allocation.x += padding.right + border.right;
else
child_allocation.x -= padding.left + border.left;
}
}
gtk_widget_size_allocate (priv->vscrollbar, &child_allocation);
}
gtk_scrolled_window_check_attach_pan_gesture (scrolled_window);
}
static gboolean
start_scroll_deceleration_cb (gpointer user_data)
{
GtkScrolledWindow *scrolled_window = user_data;
GtkScrolledWindowPrivate *priv = scrolled_window->priv;
priv->scroll_events_overshoot_id = 0;
gtk_scrolled_window_start_deceleration (scrolled_window);
return FALSE;
}
static gboolean
gtk_scrolled_window_scroll_event (GtkWidget *widget,
GdkEventScroll *event)
{
GtkScrolledWindowPrivate *priv;
GtkScrolledWindow *scrolled_window;
gboolean handled = FALSE;
gdouble delta_x;
gdouble delta_y;
gdouble delta;
scrolled_window = GTK_SCROLLED_WINDOW (widget);
priv = scrolled_window->priv;
gtk_scrolled_window_invalidate_overshoot (scrolled_window);
if (gdk_event_get_scroll_deltas ((GdkEvent *) event, &delta_x, &delta_y))
{
if (delta_x != 0.0 &&
may_hscroll (scrolled_window))
{
GtkAdjustment *adj;
gdouble new_value;
gdouble page_size;
gdouble scroll_unit;
adj = gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar));
page_size = gtk_adjustment_get_page_size (adj);
#ifdef GDK_WINDOWING_QUARTZ
scroll_unit = 1;
#else
scroll_unit = pow (page_size, 2.0 / 3.0);
#endif
new_value = priv->unclamped_hadj_value + delta_x * scroll_unit;
_gtk_scrolled_window_set_adjustment_value (scrolled_window, adj,
new_value);
handled = TRUE;
}
if (delta_y != 0.0 &&
may_vscroll (scrolled_window))
{
GtkAdjustment *adj;
gdouble new_value;
gdouble page_size;
gdouble scroll_unit;
adj = gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar));
page_size = gtk_adjustment_get_page_size (adj);
#ifdef GDK_WINDOWING_QUARTZ
scroll_unit = 1;
#else
scroll_unit = pow (page_size, 2.0 / 3.0);
#endif
new_value = priv->unclamped_vadj_value + delta_y * scroll_unit;
_gtk_scrolled_window_set_adjustment_value (scrolled_window, adj,
new_value);
handled = TRUE;
}
}
else
{
GtkWidget *range;
gboolean may_scroll;
if (event->direction == GDK_SCROLL_UP || event->direction == GDK_SCROLL_DOWN)
{
range = priv->vscrollbar;
may_scroll = may_vscroll (scrolled_window);
}
else
{
range = priv->hscrollbar;
may_scroll = may_hscroll (scrolled_window);
}
if (range && may_scroll)
{
GtkAdjustment *adj = gtk_range_get_adjustment (GTK_RANGE (range));
gdouble new_value;
delta = _gtk_range_get_wheel_delta (GTK_RANGE (range), event);
new_value = CLAMP (gtk_adjustment_get_value (adj) + delta,
gtk_adjustment_get_lower (adj),
gtk_adjustment_get_upper (adj) -
gtk_adjustment_get_page_size (adj));
gtk_adjustment_set_value (adj, new_value);
handled = TRUE;
}
}
if (handled)
{
gtk_scrolled_window_cancel_deceleration (scrolled_window);
gtk_scrolled_window_invalidate_overshoot (scrolled_window);
if (priv->scroll_events_overshoot_id)
{
g_source_remove (priv->scroll_events_overshoot_id);
priv->scroll_events_overshoot_id = 0;
}
if (_gtk_scrolled_window_get_overshoot (scrolled_window, NULL, NULL))
{
priv->scroll_events_overshoot_id =
gdk_threads_add_timeout (50, start_scroll_deceleration_cb, scrolled_window);
g_source_set_name_by_id (priv->scroll_events_overshoot_id,
"[gtk+] start_scroll_deceleration_cb");
}
}
return handled;
}
static void
_gtk_scrolled_window_set_adjustment_value (GtkScrolledWindow *scrolled_window,
GtkAdjustment *adjustment,
gdouble value)
{
GtkScrolledWindowPrivate *priv = scrolled_window->priv;
gdouble lower, upper, *prev_value;
lower = gtk_adjustment_get_lower (adjustment) - MAX_OVERSHOOT_DISTANCE;
upper = gtk_adjustment_get_upper (adjustment) -
gtk_adjustment_get_page_size (adjustment) + MAX_OVERSHOOT_DISTANCE;
if (adjustment == gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar)))
prev_value = &priv->unclamped_hadj_value;
else if (adjustment == gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar)))
prev_value = &priv->unclamped_vadj_value;
else
return;
*prev_value = CLAMP (value, lower, upper);
gtk_adjustment_set_value (adjustment, value);
}
static gboolean
scrolled_window_deceleration_cb (GtkWidget *widget,
GdkFrameClock *frame_clock,
gpointer user_data)
{
KineticScrollData *data = user_data;
GtkScrolledWindow *scrolled_window = data->scrolled_window;
GtkScrolledWindowPrivate *priv = scrolled_window->priv;
GtkAdjustment *hadjustment, *vadjustment;
gint64 current_time;
gdouble position, elapsed;
current_time = gdk_frame_clock_get_frame_time (frame_clock);
elapsed = (current_time - data->last_deceleration_time) / 1000000.0;
data->last_deceleration_time = current_time;
hadjustment = gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar));
vadjustment = gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar));
gtk_scrolled_window_invalidate_overshoot (scrolled_window);
if (data->hscrolling &&
gtk_kinetic_scrolling_tick (data->hscrolling, elapsed, &position))
{
priv->unclamped_hadj_value = position;
gtk_adjustment_set_value (hadjustment, position);
}
else if (data->hscrolling)
g_clear_pointer (&data->hscrolling, (GDestroyNotify) gtk_kinetic_scrolling_free);
if (data->vscrolling &&
gtk_kinetic_scrolling_tick (data->vscrolling, elapsed, &position))
{
priv->unclamped_vadj_value = position;
gtk_adjustment_set_value (vadjustment, position);
}
else if (data->vscrolling)
g_clear_pointer (&data->vscrolling, (GDestroyNotify) gtk_kinetic_scrolling_free);
if (!data->hscrolling && !data->vscrolling)
{
gtk_scrolled_window_cancel_deceleration (scrolled_window);
return G_SOURCE_REMOVE;
}
gtk_scrolled_window_invalidate_overshoot (scrolled_window);
return G_SOURCE_CONTINUE;
}
static void
gtk_scrolled_window_cancel_deceleration (GtkScrolledWindow *scrolled_window)
{
GtkScrolledWindowPrivate *priv = scrolled_window->priv;
if (priv->deceleration_id)
{
gtk_widget_remove_tick_callback (GTK_WIDGET (scrolled_window),
priv->deceleration_id);
priv->deceleration_id = 0;
}
}
static void
kinetic_scroll_data_free (KineticScrollData *data)
{
if (data->hscrolling)
gtk_kinetic_scrolling_free (data->hscrolling);
if (data->vscrolling)
gtk_kinetic_scrolling_free (data->vscrolling);
g_free (data);
}
static void
gtk_scrolled_window_start_deceleration (GtkScrolledWindow *scrolled_window)
{
GtkScrolledWindowPrivate *priv = scrolled_window->priv;
GdkFrameClock *frame_clock;
KineticScrollData *data;
g_return_if_fail (priv->deceleration_id == 0);
frame_clock = gtk_widget_get_frame_clock (GTK_WIDGET (scrolled_window));
data = g_new0 (KineticScrollData, 1);
data->scrolled_window = scrolled_window;
data->last_deceleration_time = gdk_frame_clock_get_frame_time (frame_clock);
if (may_hscroll (scrolled_window))
{
gdouble lower,upper;
GtkAdjustment *hadjustment;
hadjustment = gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar));
lower = gtk_adjustment_get_lower (hadjustment);
upper = gtk_adjustment_get_upper (hadjustment);
upper -= gtk_adjustment_get_page_size (hadjustment);
data->hscrolling =
gtk_kinetic_scrolling_new (lower,
upper,
MAX_OVERSHOOT_DISTANCE,
DECELERATION_FRICTION,
OVERSHOOT_FRICTION,
priv->unclamped_hadj_value,
priv->x_velocity);
}
if (may_vscroll (scrolled_window))
{
gdouble lower,upper;
GtkAdjustment *vadjustment;
vadjustment = gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar));
lower = gtk_adjustment_get_lower(vadjustment);
upper = gtk_adjustment_get_upper(vadjustment);
upper -= gtk_adjustment_get_page_size(vadjustment);
data->vscrolling =
gtk_kinetic_scrolling_new (lower,
upper,
MAX_OVERSHOOT_DISTANCE,
DECELERATION_FRICTION,
OVERSHOOT_FRICTION,
priv->unclamped_vadj_value,
priv->y_velocity);
}
scrolled_window->priv->deceleration_id =
gtk_widget_add_tick_callback (GTK_WIDGET (scrolled_window),
scrolled_window_deceleration_cb, data,
(GDestroyNotify) kinetic_scroll_data_free);
}
static gboolean
gtk_scrolled_window_focus (GtkWidget *widget,
GtkDirectionType direction)
{
GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (widget);
GtkScrolledWindowPrivate *priv = scrolled_window->priv;
GtkWidget *child;
gboolean had_focus_child;
had_focus_child = gtk_container_get_focus_child (GTK_CONTAINER (widget)) != NULL;
if (priv->focus_out)
{
priv->focus_out = FALSE; /* Clear this to catch the wrap-around case */
return FALSE;
}
if (gtk_widget_is_focus (widget))
return FALSE;
/* We only put the scrolled window itself in the focus chain if it
* isn't possible to focus any children.
*/
child = gtk_bin_get_child (GTK_BIN (widget));
if (child)
{
if (gtk_widget_child_focus (child, direction))
return TRUE;
}
if (!had_focus_child && gtk_widget_get_can_focus (widget))
{
gtk_widget_grab_focus (widget);
return TRUE;
}
else
return FALSE;
}
static void
gtk_scrolled_window_adjustment_changed (GtkAdjustment *adjustment,
gpointer data)
{
GtkScrolledWindowPrivate *priv;
GtkScrolledWindow *scrolled_window;
scrolled_window = GTK_SCROLLED_WINDOW (data);
priv = scrolled_window->priv;
if (adjustment == gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar)))
{
if (priv->hscrollbar_policy == GTK_POLICY_AUTOMATIC)
{
gboolean visible;
visible = priv->hscrollbar_visible;
priv->hscrollbar_visible = (gtk_adjustment_get_upper (adjustment) - gtk_adjustment_get_lower (adjustment) >
gtk_adjustment_get_page_size (adjustment));
if (priv->hscrollbar_visible != visible)
gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
}
}
else if (adjustment == gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar)))
{
if (priv->vscrollbar_policy == GTK_POLICY_AUTOMATIC)
{
gboolean visible;
visible = priv->vscrollbar_visible;
priv->vscrollbar_visible = (gtk_adjustment_get_upper (adjustment) - gtk_adjustment_get_lower (adjustment) >
gtk_adjustment_get_page_size (adjustment));
if (priv->vscrollbar_visible != visible)
gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
}
}
}
static void
gtk_scrolled_window_adjustment_value_changed (GtkAdjustment *adjustment,
gpointer user_data)
{
GtkScrolledWindow *scrolled_window = user_data;
GtkScrolledWindowPrivate *priv = scrolled_window->priv;
/* Allow overshooting for kinetic scrolling operations */
if (priv->drag_device || priv->deceleration_id)
return;
/* Ensure GtkAdjustment and unclamped values are in sync */
if (adjustment == gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar)))
priv->unclamped_hadj_value = gtk_adjustment_get_value (adjustment);
else if (adjustment == gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar)))
priv->unclamped_vadj_value = gtk_adjustment_get_value (adjustment);
}
static void
gtk_scrolled_window_add (GtkContainer *container,
GtkWidget *child)
{
GtkScrolledWindowPrivate *priv;
GtkScrolledWindow *scrolled_window;
GtkBin *bin;
GtkWidget *child_widget, *scrollable_child;
GtkAdjustment *hadj, *vadj;
bin = GTK_BIN (container);
child_widget = gtk_bin_get_child (bin);
g_return_if_fail (child_widget == NULL);
scrolled_window = GTK_SCROLLED_WINDOW (container);
priv = scrolled_window->priv;
/* gtk_scrolled_window_set_[hv]adjustment have the side-effect
* of creating the scrollbars
*/
if (!priv->hscrollbar)
gtk_scrolled_window_set_hadjustment (scrolled_window, NULL);
if (!priv->vscrollbar)
gtk_scrolled_window_set_vadjustment (scrolled_window, NULL);
hadj = gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar));
vadj = gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar));
if (GTK_IS_SCROLLABLE (child))
{
scrollable_child = child;
}
else
{
scrollable_child = gtk_viewport_new (hadj, vadj);
gtk_widget_show (scrollable_child);
gtk_container_set_focus_hadjustment (GTK_CONTAINER (scrollable_child),
gtk_scrolled_window_get_hadjustment (GTK_SCROLLED_WINDOW (scrolled_window)));
gtk_container_set_focus_vadjustment (GTK_CONTAINER (scrollable_child),
gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (scrolled_window)));
gtk_container_add (GTK_CONTAINER (scrollable_child), child);
}
_gtk_bin_set_child (bin, scrollable_child);
gtk_widget_set_parent (scrollable_child, GTK_WIDGET (bin));
g_object_set (scrollable_child, "hadjustment", hadj, "vadjustment", vadj, NULL);
}
static void
gtk_scrolled_window_remove (GtkContainer *container,
GtkWidget *child)
{
g_object_set (child, "hadjustment", NULL, "vadjustment", NULL, NULL);
GTK_CONTAINER_CLASS (gtk_scrolled_window_parent_class)->remove (container, child);
}
/**
* gtk_scrolled_window_add_with_viewport:
* @scrolled_window: a #GtkScrolledWindow
* @child: the widget you want to scroll
*
* Used to add children without native scrolling capabilities. This
* is simply a convenience function; it is equivalent to adding the
* unscrollable child to a viewport, then adding the viewport to the
* scrolled window. If a child has native scrolling, use
* gtk_container_add() instead of this function.
*
* The viewport scrolls the child by moving its #GdkWindow, and takes
* the size of the child to be the size of its toplevel #GdkWindow.
* This will be very wrong for most widgets that support native scrolling;
* for example, if you add a widget such as #GtkTreeView with a viewport,
* the whole widget will scroll, including the column headings. Thus,
* widgets with native scrolling support should not be used with the
* #GtkViewport proxy.
*
* A widget supports scrolling natively if it implements the
* #GtkScrollable interface.
*
* Deprecated: 3.8: gtk_container_add() will automatically add
* a #GtkViewport if the child doesn’t implement #GtkScrollable.
*/
void
gtk_scrolled_window_add_with_viewport (GtkScrolledWindow *scrolled_window,
GtkWidget *child)
{
GtkBin *bin;
GtkWidget *viewport;
GtkWidget *child_widget;
g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
g_return_if_fail (GTK_IS_WIDGET (child));
g_return_if_fail (gtk_widget_get_parent (child) == NULL);
bin = GTK_BIN (scrolled_window);
child_widget = gtk_bin_get_child (bin);
if (child_widget)
{
g_return_if_fail (GTK_IS_VIEWPORT (child_widget));
g_return_if_fail (gtk_bin_get_child (GTK_BIN (child_widget)) == NULL);
viewport = child_widget;
}
else
{
viewport =
gtk_viewport_new (gtk_scrolled_window_get_hadjustment (scrolled_window),
gtk_scrolled_window_get_vadjustment (scrolled_window));
gtk_container_set_focus_hadjustment (GTK_CONTAINER (viewport),
gtk_scrolled_window_get_hadjustment (GTK_SCROLLED_WINDOW (scrolled_window)));
gtk_container_set_focus_vadjustment (GTK_CONTAINER (viewport),
gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (scrolled_window)));
gtk_container_add (GTK_CONTAINER (scrolled_window), viewport);
}
gtk_widget_show (viewport);
gtk_container_add (GTK_CONTAINER (viewport), child);
}
/*
* _gtk_scrolled_window_get_spacing:
* @scrolled_window: a scrolled window
*
* Gets the spacing between the scrolled window’s scrollbars and
* the scrolled widget. Used by GtkCombo
*
* Returns: the spacing, in pixels.
*/
static gint
_gtk_scrolled_window_get_scrollbar_spacing (GtkScrolledWindow *scrolled_window)
{
GtkScrolledWindowClass *class;
g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), 0);
class = GTK_SCROLLED_WINDOW_GET_CLASS (scrolled_window);
if (class->scrollbar_spacing >= 0)
return class->scrollbar_spacing;
else
{
gint scrollbar_spacing;
gtk_widget_style_get (GTK_WIDGET (scrolled_window),
"scrollbar-spacing", &scrollbar_spacing,
NULL);
return scrollbar_spacing;
}
}
static void
gtk_scrolled_window_get_preferred_size (GtkWidget *widget,
GtkOrientation orientation,
gint *minimum_size,
gint *natural_size)
{
GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (widget);
GtkScrolledWindowPrivate *priv = scrolled_window->priv;
GtkBin *bin = GTK_BIN (scrolled_window);
gint extra_width;
gint extra_height;
gint scrollbar_spacing;
GtkRequisition hscrollbar_requisition;
GtkRequisition vscrollbar_requisition;
GtkRequisition minimum_req, natural_req;
GtkWidget *child;
gint min_child_size, nat_child_size;
scrollbar_spacing = _gtk_scrolled_window_get_scrollbar_spacing (scrolled_window);
extra_width = 0;
extra_height = 0;
minimum_req.width = 0;
minimum_req.height = 0;
natural_req.width = 0;
natural_req.height = 0;
gtk_widget_get_preferred_size (priv->hscrollbar,
&hscrollbar_requisition, NULL);
gtk_widget_get_preferred_size (priv->vscrollbar,
&vscrollbar_requisition, NULL);
child = gtk_bin_get_child (bin);
if (child && gtk_widget_get_visible (child))
{
if (orientation == GTK_ORIENTATION_HORIZONTAL)
{
gtk_widget_get_preferred_width (child,
&min_child_size,
&nat_child_size);
if (priv->hscrollbar_policy == GTK_POLICY_NEVER)
{
minimum_req.width += min_child_size;
natural_req.width += nat_child_size;
}
else
{
gint min_content_width = priv->min_content_width;
if (min_content_width >= 0)
{
minimum_req.width = MAX (minimum_req.width, min_content_width);
natural_req.width = MAX (natural_req.width, min_content_width);
extra_width = -1;
}
else if (policy_may_be_visible (priv->vscrollbar_policy))
{
minimum_req.width += vscrollbar_requisition.width;
natural_req.width += vscrollbar_requisition.width;
}
}
}
else /* GTK_ORIENTATION_VERTICAL */
{
gtk_widget_get_preferred_height (child,
&min_child_size,
&nat_child_size);
if (priv->vscrollbar_policy == GTK_POLICY_NEVER)
{
minimum_req.height += min_child_size;
natural_req.height += nat_child_size;
}
else
{
gint min_content_height = priv->min_content_height;
if (min_content_height >= 0)
{
minimum_req.height = MAX (minimum_req.height, min_content_height);
natural_req.height = MAX (natural_req.height, min_content_height);
extra_height = -1;
}
else if (policy_may_be_visible (priv->vscrollbar_policy))
{
minimum_req.height += vscrollbar_requisition.height;
natural_req.height += vscrollbar_requisition.height;
}
}
}
}
if (policy_may_be_visible (priv->hscrollbar_policy))
{
minimum_req.width = MAX (minimum_req.width, hscrollbar_requisition.width);
natural_req.width = MAX (natural_req.width, hscrollbar_requisition.width);
if (!extra_height || priv->hscrollbar_policy == GTK_POLICY_ALWAYS)
extra_height = scrollbar_spacing + hscrollbar_requisition.height;
}
if (policy_may_be_visible (priv->vscrollbar_policy))
{
minimum_req.height = MAX (minimum_req.height, vscrollbar_requisition.height);
natural_req.height = MAX (natural_req.height, vscrollbar_requisition.height);
if (!extra_width || priv->vscrollbar_policy == GTK_POLICY_ALWAYS)
extra_width = scrollbar_spacing + vscrollbar_requisition.width;
}
minimum_req.width += MAX (0, extra_width);
minimum_req.height += MAX (0, extra_height);
natural_req.width += MAX (0, extra_width);
natural_req.height += MAX (0, extra_height);
if (priv->shadow_type != GTK_SHADOW_NONE)
{
GtkStyleContext *context;
GtkStateFlags state;
GtkBorder padding, border;
context = gtk_widget_get_style_context (GTK_WIDGET (widget));
state = gtk_widget_get_state_flags (GTK_WIDGET (widget));
gtk_style_context_save (context);
gtk_style_context_add_class (context, GTK_STYLE_CLASS_FRAME);
gtk_style_context_get_padding (context, state, &padding);
gtk_style_context_get_border (context, state, &border);
minimum_req.width += padding.left + padding.right + border.left + border.right;
minimum_req.height += padding.top + padding.bottom + border.top + border.bottom;
natural_req.width += padding.left + padding.right + border.left + border.right;
natural_req.height += padding.top + padding.bottom + border.top + border.bottom;
gtk_style_context_restore (context);
}
if (orientation == GTK_ORIENTATION_HORIZONTAL)
{
*minimum_size = minimum_req.width;
*natural_size = natural_req.width;
}
else
{
*minimum_size = minimum_req.height;
*natural_size = natural_req.height;
}
}
static void
gtk_scrolled_window_get_preferred_width (GtkWidget *widget,
gint *minimum_size,
gint *natural_size)
{
gtk_scrolled_window_get_preferred_size (widget, GTK_ORIENTATION_HORIZONTAL, minimum_size, natural_size);
}
static void
gtk_scrolled_window_get_preferred_height (GtkWidget *widget,
gint *minimum_size,
gint *natural_size)
{
gtk_scrolled_window_get_preferred_size (widget, GTK_ORIENTATION_VERTICAL, minimum_size, natural_size);
}
static void
gtk_scrolled_window_get_preferred_height_for_width (GtkWidget *widget,
gint width,
gint *minimum_height,
gint *natural_height)
{
GTK_WIDGET_GET_CLASS (widget)->get_preferred_height (widget, minimum_height, natural_height);
}
static void
gtk_scrolled_window_get_preferred_width_for_height (GtkWidget *widget,
gint height,
gint *minimum_width,
gint *natural_width)
{
GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, minimum_width, natural_width);
}
static gboolean
gtk_scrolled_window_should_animate (GtkScrolledWindow *sw)
{
gboolean animate;
if (!gtk_widget_get_mapped (GTK_WIDGET (sw)))
return FALSE;
g_object_get (gtk_widget_get_settings (GTK_WIDGET (sw)),
"gtk-enable-animations", &animate,
NULL);
return animate;
}
static void
gtk_scrolled_window_update_animating (GtkScrolledWindow *sw)
{
GtkAdjustment *adjustment;
GdkFrameClock *clock = NULL;
guint duration = 0;
if (gtk_scrolled_window_should_animate (sw))
{
clock = gtk_widget_get_frame_clock (GTK_WIDGET (sw)),
duration = ANIMATION_DURATION;
}
adjustment = gtk_range_get_adjustment (GTK_RANGE (sw->priv->hscrollbar));
gtk_adjustment_enable_animation (adjustment, clock, duration);
adjustment = gtk_range_get_adjustment (GTK_RANGE (sw->priv->vscrollbar));
gtk_adjustment_enable_animation (adjustment, clock, duration);
}
static void
gtk_scrolled_window_map (GtkWidget *widget)
{
GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (widget);
GTK_WIDGET_CLASS (gtk_scrolled_window_parent_class)->map (widget);
gtk_scrolled_window_update_animating (scrolled_window);
}
static void
gtk_scrolled_window_unmap (GtkWidget *widget)
{
GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (widget);
GTK_WIDGET_CLASS (gtk_scrolled_window_parent_class)->unmap (widget);
gtk_scrolled_window_update_animating (scrolled_window);
}
static void
gtk_scrolled_window_grab_notify (GtkWidget *widget,
gboolean was_grabbed)
{
GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (widget);
GtkScrolledWindowPrivate *priv = scrolled_window->priv;
if (priv->drag_device &&
gtk_widget_device_is_shadowed (widget,
priv->drag_device))
{
gdk_device_ungrab (priv->drag_device,
gtk_get_current_event_time ());
priv->drag_device = NULL;
if (_gtk_scrolled_window_get_overshoot (scrolled_window, NULL, NULL))
gtk_scrolled_window_start_deceleration (scrolled_window);
else
gtk_scrolled_window_cancel_deceleration (scrolled_window);
}
}
/**
* gtk_scrolled_window_get_min_content_width:
* @scrolled_window: a #GtkScrolledWindow
*
* Gets the minimum content width of @scrolled_window, or -1 if not set.
*
* Returns: the minimum content width
*
* Since: 3.0
*/
gint
gtk_scrolled_window_get_min_content_width (GtkScrolledWindow *scrolled_window)
{
g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), 0);
return scrolled_window->priv->min_content_width;
}
/**
* gtk_scrolled_window_set_min_content_width:
* @scrolled_window: a #GtkScrolledWindow
* @width: the minimal content width
*
* Sets the minimum width that @scrolled_window should keep visible.
* Note that this can and (usually will) be smaller than the minimum
* size of the content.
*
* Since: 3.0
*/
void
gtk_scrolled_window_set_min_content_width (GtkScrolledWindow *scrolled_window,
gint width)
{
GtkScrolledWindowPrivate *priv;
g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
priv = scrolled_window->priv;
if (priv->min_content_width != width)
{
priv->min_content_width = width;
gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
g_object_notify (G_OBJECT (scrolled_window), "min-content-width");
}
}
/**
* gtk_scrolled_window_get_min_content_height:
* @scrolled_window: a #GtkScrolledWindow
*
* Gets the minimal content height of @scrolled_window, or -1 if not set.
*
* Returns: the minimal content height
*
* Since: 3.0
*/
gint
gtk_scrolled_window_get_min_content_height (GtkScrolledWindow *scrolled_window)
{
g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), 0);
return scrolled_window->priv->min_content_height;
}
/**
* gtk_scrolled_window_set_min_content_height:
* @scrolled_window: a #GtkScrolledWindow
* @height: the minimal content height
*
* Sets the minimum height that @scrolled_window should keep visible.
* Note that this can and (usually will) be smaller than the minimum
* size of the content.
*
* Since: 3.0
*/
void
gtk_scrolled_window_set_min_content_height (GtkScrolledWindow *scrolled_window,
gint height)
{
GtkScrolledWindowPrivate *priv;
g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
priv = scrolled_window->priv;
if (priv->min_content_height != height)
{
priv->min_content_height = height;
gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
g_object_notify (G_OBJECT (scrolled_window), "min-content-height");
}
}
|