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
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use crate::AccelGroup;
use crate::Orientation;
use crate::PageSetup;
use crate::PositionType;
use crate::PrintSettings;
use crate::SelectionData;
use crate::SpinButton;
use crate::StyleContext;
use crate::TextBuffer;
use crate::TextDirection;
use crate::TreeModel;
use crate::TreePath;
use crate::Widget;
use crate::Window;
use glib::object::IsA;
use glib::translate::*;
use std::boxed::Box as Box_;
use std::mem;
use std::ptr;

/// Finds the first accelerator in any [`AccelGroup`][crate::AccelGroup] attached
/// to `object` that matches `accel_key` and `accel_mods`, and
/// activates that accelerator.
/// ## `object`
/// the [`glib::Object`][crate::glib::Object], usually a [`Window`][crate::Window], on which
///  to activate the accelerator
/// ## `accel_key`
/// accelerator keyval from a key event
/// ## `accel_mods`
/// keyboard state mask from a key event
///
/// # Returns
///
/// [`true`] if an accelerator was activated and handled
///  this keypress
#[doc(alias = "gtk_accel_groups_activate")]
pub fn accel_groups_activate<P: IsA<glib::Object>>(
    object: &P,
    accel_key: u32,
    accel_mods: gdk::ModifierType,
) -> bool {
    assert_initialized_main_thread!();
    unsafe {
        from_glib(ffi::gtk_accel_groups_activate(
            object.as_ref().to_glib_none().0,
            accel_key,
            accel_mods.into_glib(),
        ))
    }
}

/// Gets a list of all accel groups which are attached to `object`.
/// ## `object`
/// a [`glib::Object`][crate::glib::Object], usually a [`Window`][crate::Window]
///
/// # Returns
///
/// a list of
///  all accel groups which are attached to `object`
#[doc(alias = "gtk_accel_groups_from_object")]
pub fn accel_groups_from_object<P: IsA<glib::Object>>(object: &P) -> Vec<AccelGroup> {
    assert_initialized_main_thread!();
    unsafe {
        FromGlibPtrContainer::from_glib_none(ffi::gtk_accel_groups_from_object(
            object.as_ref().to_glib_none().0,
        ))
    }
}

/// Gets the modifier mask.
///
/// The modifier mask determines which modifiers are considered significant
/// for keyboard accelerators. See [`accelerator_set_default_mod_mask()`][crate::accelerator_set_default_mod_mask()].
///
/// # Returns
///
/// the default accelerator modifier mask
#[doc(alias = "gtk_accelerator_get_default_mod_mask")]
pub fn accelerator_get_default_mod_mask() -> gdk::ModifierType {
    assert_initialized_main_thread!();
    unsafe { from_glib(ffi::gtk_accelerator_get_default_mod_mask()) }
}

/// Converts an accelerator keyval and modifier mask into a string
/// which can be used to represent the accelerator to the user.
/// ## `accelerator_key`
/// accelerator keyval
/// ## `accelerator_mods`
/// accelerator modifier mask
///
/// # Returns
///
/// a newly-allocated string representing the accelerator.
#[doc(alias = "gtk_accelerator_get_label")]
pub fn accelerator_get_label(
    accelerator_key: u32,
    accelerator_mods: gdk::ModifierType,
) -> Option<glib::GString> {
    assert_initialized_main_thread!();
    unsafe {
        from_glib_full(ffi::gtk_accelerator_get_label(
            accelerator_key,
            accelerator_mods.into_glib(),
        ))
    }
}

/// Converts an accelerator keyval and modifier mask
/// into a (possibly translated) string that can be displayed to
/// a user, similarly to [`accelerator_get_label()`][crate::accelerator_get_label()], but handling
/// keycodes.
///
/// This is only useful for system-level components, applications
/// should use [`accelerator_parse()`][crate::accelerator_parse()] instead.
/// ## `display`
/// a [`gdk::Display`][crate::gdk::Display] or [`None`] to use the default display
/// ## `accelerator_key`
/// accelerator keyval
/// ## `keycode`
/// accelerator keycode
/// ## `accelerator_mods`
/// accelerator modifier mask
///
/// # Returns
///
/// a newly-allocated string representing the accelerator.
#[doc(alias = "gtk_accelerator_get_label_with_keycode")]
pub fn accelerator_get_label_with_keycode(
    display: Option<&gdk::Display>,
    accelerator_key: u32,
    keycode: u32,
    accelerator_mods: gdk::ModifierType,
) -> Option<glib::GString> {
    assert_initialized_main_thread!();
    unsafe {
        from_glib_full(ffi::gtk_accelerator_get_label_with_keycode(
            display.to_glib_none().0,
            accelerator_key,
            keycode,
            accelerator_mods.into_glib(),
        ))
    }
}

/// Converts an accelerator keyval and modifier mask into a string
/// parseable by [`accelerator_parse()`][crate::accelerator_parse()]. For example, if you pass in
/// `GDK_KEY_q` and [`gdk::ModifierType::CONTROL_MASK`][crate::gdk::ModifierType::CONTROL_MASK], this function returns “`<Control>`q”.
///
/// If you need to display accelerators in the user interface,
/// see [`accelerator_get_label()`][crate::accelerator_get_label()].
/// ## `accelerator_key`
/// accelerator keyval
/// ## `accelerator_mods`
/// accelerator modifier mask
///
/// # Returns
///
/// a newly-allocated accelerator name
#[doc(alias = "gtk_accelerator_name")]
pub fn accelerator_name(
    accelerator_key: u32,
    accelerator_mods: gdk::ModifierType,
) -> Option<glib::GString> {
    assert_initialized_main_thread!();
    unsafe {
        from_glib_full(ffi::gtk_accelerator_name(
            accelerator_key,
            accelerator_mods.into_glib(),
        ))
    }
}

/// Converts an accelerator keyval and modifier mask
/// into a string parseable by `gtk_accelerator_parse_with_keycode()`,
/// similarly to [`accelerator_name()`][crate::accelerator_name()] but handling keycodes.
/// This is only useful for system-level components, applications
/// should use [`accelerator_parse()`][crate::accelerator_parse()] instead.
/// ## `display`
/// a [`gdk::Display`][crate::gdk::Display] or [`None`] to use the default display
/// ## `accelerator_key`
/// accelerator keyval
/// ## `keycode`
/// accelerator keycode
/// ## `accelerator_mods`
/// accelerator modifier mask
///
/// # Returns
///
/// a newly allocated accelerator name.
#[doc(alias = "gtk_accelerator_name_with_keycode")]
pub fn accelerator_name_with_keycode(
    display: Option<&gdk::Display>,
    accelerator_key: u32,
    keycode: u32,
    accelerator_mods: gdk::ModifierType,
) -> Option<glib::GString> {
    assert_initialized_main_thread!();
    unsafe {
        from_glib_full(ffi::gtk_accelerator_name_with_keycode(
            display.to_glib_none().0,
            accelerator_key,
            keycode,
            accelerator_mods.into_glib(),
        ))
    }
}

/// Parses a string representing an accelerator. The format looks like
/// “`<Control>`a” or “`<Shift>``<Alt>`F1” or “`<Release>`z” (the last one is
/// for key release).
///
/// The parser is fairly liberal and allows lower or upper case, and also
/// abbreviations such as “`<Ctl>`” and “`<Ctrl>`”. Key names are parsed using
/// `gdk_keyval_from_name()`. For character keys the name is not the symbol,
/// but the lowercase name, e.g. one would use “`<Ctrl>`minus” instead of
/// “`<Ctrl>`-”.
///
/// If the parse fails, `accelerator_key` and `accelerator_mods` will
/// be set to 0 (zero).
/// ## `accelerator`
/// string representing an accelerator
///
/// # Returns
///
///
/// ## `accelerator_key`
/// return location for accelerator
///  keyval, or [`None`]
///
/// ## `accelerator_mods`
/// return location for accelerator
///  modifier mask, [`None`]
#[doc(alias = "gtk_accelerator_parse")]
pub fn accelerator_parse(accelerator: &str) -> (u32, gdk::ModifierType) {
    assert_initialized_main_thread!();
    unsafe {
        let mut accelerator_key = mem::MaybeUninit::uninit();
        let mut accelerator_mods = mem::MaybeUninit::uninit();
        ffi::gtk_accelerator_parse(
            accelerator.to_glib_none().0,
            accelerator_key.as_mut_ptr(),
            accelerator_mods.as_mut_ptr(),
        );
        let accelerator_key = accelerator_key.assume_init();
        let accelerator_mods = accelerator_mods.assume_init();
        (accelerator_key, from_glib(accelerator_mods))
    }
}

//#[doc(alias = "gtk_accelerator_parse_with_keycode")]
//pub fn accelerator_parse_with_keycode(accelerator: &str, accelerator_codes: Vec<u32>) -> (u32, gdk::ModifierType) {
//    unsafe { TODO: call ffi:gtk_accelerator_parse_with_keycode() }
//}

/// Sets the modifiers that will be considered significant for keyboard
/// accelerators. The default mod mask depends on the GDK backend in use,
/// but will typically include [`gdk::ModifierType::CONTROL_MASK`][crate::gdk::ModifierType::CONTROL_MASK] | [`gdk::ModifierType::SHIFT_MASK`][crate::gdk::ModifierType::SHIFT_MASK] |
/// [`gdk::ModifierType::MOD1_MASK`][crate::gdk::ModifierType::MOD1_MASK] | [`gdk::ModifierType::SUPER_MASK`][crate::gdk::ModifierType::SUPER_MASK] | [`gdk::ModifierType::HYPER_MASK`][crate::gdk::ModifierType::HYPER_MASK] | [`gdk::ModifierType::META_MASK`][crate::gdk::ModifierType::META_MASK].
/// In other words, Control, Shift, Alt, Super, Hyper and Meta. Other
/// modifiers will by default be ignored by [`AccelGroup`][crate::AccelGroup].
///
/// You must include at least the three modifiers Control, Shift
/// and Alt in any value you pass to this function.
///
/// The default mod mask should be changed on application startup,
/// before using any accelerator groups.
/// ## `default_mod_mask`
/// accelerator modifier mask
#[doc(alias = "gtk_accelerator_set_default_mod_mask")]
pub fn accelerator_set_default_mod_mask(default_mod_mask: gdk::ModifierType) {
    assert_initialized_main_thread!();
    unsafe {
        ffi::gtk_accelerator_set_default_mod_mask(default_mod_mask.into_glib());
    }
}

/// Determines whether a given keyval and modifier mask constitute
/// a valid keyboard accelerator. For example, the `GDK_KEY_a` keyval
/// plus [`gdk::ModifierType::CONTROL_MASK`][crate::gdk::ModifierType::CONTROL_MASK] is valid - this is a “Ctrl+a” accelerator.
/// But, you can't, for instance, use the `GDK_KEY_Control_L` keyval
/// as an accelerator.
/// ## `keyval`
/// a GDK keyval
/// ## `modifiers`
/// modifier mask
///
/// # Returns
///
/// [`true`] if the accelerator is valid
#[doc(alias = "gtk_accelerator_valid")]
pub fn accelerator_valid(keyval: u32, modifiers: gdk::ModifierType) -> bool {
    assert_initialized_main_thread!();
    unsafe { from_glib(ffi::gtk_accelerator_valid(keyval, modifiers.into_glib())) }
}

/// Find a key binding matching `keyval` and `modifiers` and activate the
/// binding on `object`.
/// ## `object`
/// object to activate when binding found
/// ## `keyval`
/// key value of the binding
/// ## `modifiers`
/// key modifier of the binding
///
/// # Returns
///
/// [`true`] if a binding was found and activated
#[doc(alias = "gtk_bindings_activate")]
pub fn bindings_activate<P: IsA<glib::Object>>(
    object: &P,
    keyval: u32,
    modifiers: gdk::ModifierType,
) -> bool {
    assert_initialized_main_thread!();
    unsafe {
        from_glib(ffi::gtk_bindings_activate(
            object.as_ref().to_glib_none().0,
            keyval,
            modifiers.into_glib(),
        ))
    }
}

/// Looks up key bindings for `object` to find one matching
/// `event`, and if one was found, activate it.
/// ## `object`
/// a [`glib::Object`][crate::glib::Object] (generally must be a widget)
/// ## `event`
/// a [`gdk::EventKey`][crate::gdk::EventKey]
///
/// # Returns
///
/// [`true`] if a matching key binding was found
#[doc(alias = "gtk_bindings_activate_event")]
pub fn bindings_activate_event<P: IsA<glib::Object>>(
    object: &P,
    event: &mut gdk::EventKey,
) -> bool {
    assert_initialized_main_thread!();
    unsafe {
        from_glib(ffi::gtk_bindings_activate_event(
            object.as_ref().to_glib_none().0,
            event.to_glib_none_mut().0,
        ))
    }
}

/// This function is supposed to be called in `signal::Widget::draw`
/// implementations for widgets that support multiple windows.
/// `cr` must be untransformed from invoking of the draw function.
/// This function will return [`true`] if the contents of the given
/// `window` are supposed to be drawn and [`false`] otherwise. Note
/// that when the drawing was not initiated by the windowing
/// system this function will return [`true`] for all windows, so
/// you need to draw the bottommost window first. Also, do not
/// use “else if” statements to check which window should be drawn.
/// ## `cr`
/// a cairo context
/// ## `window`
/// the window to check. `window` may not be an input-only
///  window.
///
/// # Returns
///
/// [`true`] if `window` should be drawn
#[doc(alias = "gtk_cairo_should_draw_window")]
pub fn cairo_should_draw_window(cr: &cairo::Context, window: &gdk::Window) -> bool {
    assert_initialized_main_thread!();
    unsafe {
        from_glib(ffi::gtk_cairo_should_draw_window(
            mut_override(cr.to_glib_none().0),
            window.to_glib_none().0,
        ))
    }
}

/// Transforms the given cairo context `cr` that from `widget`-relative
/// coordinates to `window`-relative coordinates.
/// If the `widget`’s window is not an ancestor of `window`, no
/// modification will be applied.
///
/// This is the inverse to the transformation GTK applies when
/// preparing an expose event to be emitted with the `signal::Widget::draw`
/// signal. It is intended to help porting multiwindow widgets from
/// GTK+ 2 to the rendering architecture of GTK+ 3.
/// ## `cr`
/// the cairo context to transform
/// ## `widget`
/// the widget the context is currently centered for
/// ## `window`
/// the window to transform the context to
#[doc(alias = "gtk_cairo_transform_to_window")]
pub fn cairo_transform_to_window<P: IsA<Widget>>(
    cr: &cairo::Context,
    widget: &P,
    window: &gdk::Window,
) {
    skip_assert_initialized!();
    unsafe {
        ffi::gtk_cairo_transform_to_window(
            mut_override(cr.to_glib_none().0),
            widget.as_ref().to_glib_none().0,
            window.to_glib_none().0,
        );
    }
}

/// Checks that the GTK+ library in use is compatible with the
/// given version. Generally you would pass in the constants
/// `GTK_MAJOR_VERSION`, `GTK_MINOR_VERSION`, `GTK_MICRO_VERSION`
/// as the three arguments to this function; that produces
/// a check that the library in use is compatible with
/// the version of GTK+ the application or module was compiled
/// against.
///
/// Compatibility is defined by two things: first the version
/// of the running library is newer than the version
/// `required_major`.`required_micro`. Second
/// the running library must be binary compatible with the
/// version `required_major`.`required_micro`
/// (same major version.)
///
/// This function is primarily for GTK+ modules; the module
/// can call this function to check that it wasn’t loaded
/// into an incompatible version of GTK+. However, such a
/// check isn’t completely reliable, since the module may be
/// linked against an old version of GTK+ and calling the
/// old version of [`check_version()`][crate::check_version()], but still get loaded
/// into an application using a newer version of GTK+.
/// ## `required_major`
/// the required major version
/// ## `required_minor`
/// the required minor version
/// ## `required_micro`
/// the required micro version
///
/// # Returns
///
/// [`None`] if the GTK+ library is compatible with the
///  given version, or a string describing the version mismatch.
///  The returned string is owned by GTK+ and should not be modified
///  or freed.
#[doc(alias = "gtk_check_version")]
pub fn check_version(
    required_major: u32,
    required_minor: u32,
    required_micro: u32,
) -> Option<glib::GString> {
    skip_assert_initialized!();
    unsafe {
        from_glib_none(ffi::gtk_check_version(
            required_major,
            required_minor,
            required_micro,
        ))
    }
}

/// Adds a GTK+ grab on `device`, so all the events on `device` and its
/// associated pointer or keyboard (if any) are delivered to `widget`.
/// If the `block_others` parameter is [`true`], any other devices will be
/// unable to interact with `widget` during the grab.
/// ## `widget`
/// a [`Widget`][crate::Widget]
/// ## `device`
/// a [`gdk::Device`][crate::gdk::Device] to grab on.
/// ## `block_others`
/// [`true`] to prevent other devices to interact with `widget`.
#[doc(alias = "gtk_device_grab_add")]
pub fn device_grab_add<P: IsA<Widget>>(widget: &P, device: &gdk::Device, block_others: bool) {
    skip_assert_initialized!();
    unsafe {
        ffi::gtk_device_grab_add(
            widget.as_ref().to_glib_none().0,
            device.to_glib_none().0,
            block_others.into_glib(),
        );
    }
}

/// Removes a device grab from the given widget.
///
/// You have to pair calls to [`device_grab_add()`][crate::device_grab_add()] and
/// [`device_grab_remove()`][crate::device_grab_remove()].
/// ## `widget`
/// a [`Widget`][crate::Widget]
/// ## `device`
/// a [`gdk::Device`][crate::gdk::Device]
#[doc(alias = "gtk_device_grab_remove")]
pub fn device_grab_remove<P: IsA<Widget>>(widget: &P, device: &gdk::Device) {
    skip_assert_initialized!();
    unsafe {
        ffi::gtk_device_grab_remove(widget.as_ref().to_glib_none().0, device.to_glib_none().0);
    }
}

/// Prevents `gtk_init()`, `gtk_init_check()`, `gtk_init_with_args()` and
/// `gtk_parse_args()` from automatically
/// calling `setlocale (LC_ALL, "")`. You would
/// want to use this function if you wanted to set the locale for
/// your program to something other than the user’s locale, or if
/// you wanted to set different values for different locale categories.
///
/// Most programs should not need to call this function.
#[doc(alias = "gtk_disable_setlocale")]
pub fn disable_setlocale() {
    assert_not_initialized!();
    unsafe {
        ffi::gtk_disable_setlocale();
    }
}

//#[doc(alias = "gtk_distribute_natural_allocation")]
//pub fn distribute_natural_allocation(extra_space: i32, n_requested_sizes: u32, sizes: /*Ignored*/&mut RequestedSize) -> i32 {
//    unsafe { TODO: call ffi:gtk_distribute_natural_allocation() }
//}

/// Checks if any events are pending.
///
/// This can be used to update the UI and invoke timeouts etc.
/// while doing some time intensive computation.
///
/// ## Updating the UI during a long computation
///
///
///
/// **⚠️ The following code is in C ⚠️**
///
/// ```C
///  // computation going on...
///
///  while (gtk_events_pending ())
///    gtk_main_iteration ();
///
///  // ...computation continued
/// ```
///
/// # Returns
///
/// [`true`] if any events are pending, [`false`] otherwise
#[doc(alias = "gtk_events_pending")]
pub fn events_pending() -> bool {
    assert_initialized_main_thread!();
    unsafe { from_glib(ffi::gtk_events_pending()) }
}

#[doc(alias = "gtk_false")]
#[doc(alias = "false")]
pub fn false_() -> bool {
    assert_initialized_main_thread!();
    unsafe { from_glib(ffi::gtk_false()) }
}

/// Returns the binary age as passed to `libtool`
/// when building the GTK+ library the process is running against.
/// If `libtool` means nothing to you, don't
/// worry about it.
///
/// # Returns
///
/// the binary age of the GTK+ library
#[doc(alias = "gtk_get_binary_age")]
#[doc(alias = "get_binary_age")]
pub fn binary_age() -> u32 {
    skip_assert_initialized!();
    unsafe { ffi::gtk_get_binary_age() }
}

/// Obtains a copy of the event currently being processed by GTK+.
///
/// For example, if you are handling a `signal::Button::clicked` signal,
/// the current event will be the [`gdk::EventButton`][crate::gdk::EventButton] that triggered
/// the ::clicked signal.
///
/// # Returns
///
/// a copy of the current event, or
///  [`None`] if there is no current event. The returned event must be
///  freed with `gdk_event_free()`.
#[doc(alias = "gtk_get_current_event")]
#[doc(alias = "get_current_event")]
pub fn current_event() -> Option<gdk::Event> {
    assert_initialized_main_thread!();
    unsafe { from_glib_full(ffi::gtk_get_current_event()) }
}

/// If there is a current event and it has a device, return that
/// device, otherwise return [`None`].
///
/// # Returns
///
/// a [`gdk::Device`][crate::gdk::Device], or [`None`]
#[doc(alias = "gtk_get_current_event_device")]
#[doc(alias = "get_current_event_device")]
pub fn current_event_device() -> Option<gdk::Device> {
    assert_initialized_main_thread!();
    unsafe { from_glib_none(ffi::gtk_get_current_event_device()) }
}

/// If there is a current event and it has a state field, place
/// that state field in `state` and return [`true`], otherwise return
/// [`false`].
///
/// # Returns
///
/// [`true`] if there was a current event and it
///  had a state field
///
/// ## `state`
/// a location to store the state of the current event
#[doc(alias = "gtk_get_current_event_state")]
#[doc(alias = "get_current_event_state")]
pub fn current_event_state() -> Option<gdk::ModifierType> {
    assert_initialized_main_thread!();
    unsafe {
        let mut state = mem::MaybeUninit::uninit();
        let ret = from_glib(ffi::gtk_get_current_event_state(state.as_mut_ptr()));
        let state = state.assume_init();
        if ret {
            Some(from_glib(state))
        } else {
            None
        }
    }
}

/// If there is a current event and it has a timestamp,
/// return that timestamp, otherwise return `GDK_CURRENT_TIME`.
///
/// # Returns
///
/// the timestamp from the current event,
///  or `GDK_CURRENT_TIME`.
#[doc(alias = "gtk_get_current_event_time")]
#[doc(alias = "get_current_event_time")]
pub fn current_event_time() -> u32 {
    assert_initialized_main_thread!();
    unsafe { ffi::gtk_get_current_event_time() }
}

/// Returns the GTK+ debug flags.
///
/// This function is intended for GTK+ modules that want
/// to adjust their debug output based on GTK+ debug flags.
///
/// # Returns
///
/// the GTK+ debug flags.
#[doc(alias = "gtk_get_debug_flags")]
#[doc(alias = "get_debug_flags")]
pub fn debug_flags() -> u32 {
    assert_initialized_main_thread!();
    unsafe { ffi::gtk_get_debug_flags() }
}

/// Returns the [`pango::Language`][crate::pango::Language] for the default language currently in
/// effect. (Note that this can change over the life of an
/// application.) The default language is derived from the current
/// locale. It determines, for example, whether GTK+ uses the
/// right-to-left or left-to-right text direction.
///
/// This function is equivalent to [`pango::Language::default()`][crate::pango::Language::default()].
/// See that function for details.
///
/// # Returns
///
/// the default language as a [`pango::Language`][crate::pango::Language],
///  must not be freed
#[doc(alias = "gtk_get_default_language")]
#[doc(alias = "get_default_language")]
pub fn default_language() -> Option<pango::Language> {
    assert_initialized_main_thread!();
    unsafe { from_glib_none(ffi::gtk_get_default_language()) }
}

/// If `event` is [`None`] or the event was not associated with any widget,
/// returns [`None`], otherwise returns the widget that received the event
/// originally.
/// ## `event`
/// a `GdkEvent`
///
/// # Returns
///
/// the widget that originally
///  received `event`, or [`None`]
#[doc(alias = "gtk_get_event_widget")]
#[doc(alias = "get_event_widget")]
pub fn event_widget(event: &mut gdk::Event) -> Option<Widget> {
    assert_initialized_main_thread!();
    unsafe { from_glib_none(ffi::gtk_get_event_widget(event.to_glib_none_mut().0)) }
}

/// Returns the interface age as passed to `libtool`
/// when building the GTK+ library the process is running against.
/// If `libtool` means nothing to you, don't
/// worry about it.
///
/// # Returns
///
/// the interface age of the GTK+ library
#[doc(alias = "gtk_get_interface_age")]
#[doc(alias = "get_interface_age")]
pub fn interface_age() -> u32 {
    skip_assert_initialized!();
    unsafe { ffi::gtk_get_interface_age() }
}

/// Get the direction of the current locale. This is the expected
/// reading direction for text and UI.
///
/// This function depends on the current locale being set with
/// `setlocale()` and will default to setting the [`TextDirection::Ltr`][crate::TextDirection::Ltr]
/// direction otherwise. [`TextDirection::None`][crate::TextDirection::None] will never be returned.
///
/// GTK+ sets the default text direction according to the locale
/// during `gtk_init()`, and you should normally use
/// [`WidgetExt::direction()`][crate::prelude::WidgetExt::direction()] or [`Widget::default_direction()`][crate::Widget::default_direction()]
/// to obtain the current direcion.
///
/// This function is only needed rare cases when the locale is
/// changed after GTK+ has already been initialized. In this case,
/// you can use it to update the default text direction as follows:
///
///
///
/// **⚠️ The following code is in C ⚠️**
///
/// ```C
/// setlocale (LC_ALL, new_locale);
/// direction = gtk_get_locale_direction ();
/// gtk_widget_set_default_direction (direction);
/// ```
///
/// # Returns
///
/// the [`TextDirection`][crate::TextDirection] of the current locale
#[doc(alias = "gtk_get_locale_direction")]
#[doc(alias = "get_locale_direction")]
pub fn locale_direction() -> TextDirection {
    assert_initialized_main_thread!();
    unsafe { from_glib(ffi::gtk_get_locale_direction()) }
}

/// Returns the major version number of the GTK+ library.
/// (e.g. in GTK+ version 3.1.5 this is 3.)
///
/// This function is in the library, so it represents the GTK+ library
/// your code is running against. Contrast with the `GTK_MAJOR_VERSION`
/// macro, which represents the major version of the GTK+ headers you
/// have included when compiling your code.
///
/// # Returns
///
/// the major version number of the GTK+ library
#[doc(alias = "gtk_get_major_version")]
#[doc(alias = "get_major_version")]
pub fn major_version() -> u32 {
    skip_assert_initialized!();
    unsafe { ffi::gtk_get_major_version() }
}

/// Returns the micro version number of the GTK+ library.
/// (e.g. in GTK+ version 3.1.5 this is 5.)
///
/// This function is in the library, so it represents the GTK+ library
/// your code is are running against. Contrast with the
/// `GTK_MICRO_VERSION` macro, which represents the micro version of the
/// GTK+ headers you have included when compiling your code.
///
/// # Returns
///
/// the micro version number of the GTK+ library
#[doc(alias = "gtk_get_micro_version")]
#[doc(alias = "get_micro_version")]
pub fn micro_version() -> u32 {
    skip_assert_initialized!();
    unsafe { ffi::gtk_get_micro_version() }
}

/// Returns the minor version number of the GTK+ library.
/// (e.g. in GTK+ version 3.1.5 this is 1.)
///
/// This function is in the library, so it represents the GTK+ library
/// your code is are running against. Contrast with the
/// `GTK_MINOR_VERSION` macro, which represents the minor version of the
/// GTK+ headers you have included when compiling your code.
///
/// # Returns
///
/// the minor version number of the GTK+ library
#[doc(alias = "gtk_get_minor_version")]
#[doc(alias = "get_minor_version")]
pub fn minor_version() -> u32 {
    skip_assert_initialized!();
    unsafe { ffi::gtk_get_minor_version() }
}

//#[doc(alias = "gtk_get_option_group")]
//#[doc(alias = "get_option_group")]
//pub fn option_group(open_default_display: bool) -> /*Ignored*/Option<glib::OptionGroup> {
//    unsafe { TODO: call ffi:gtk_get_option_group() }
//}

/// Queries the current grab of the default window group.
///
/// # Returns
///
/// The widget which currently
///  has the grab or [`None`] if no grab is active
#[doc(alias = "gtk_grab_get_current")]
pub fn grab_get_current() -> Option<Widget> {
    assert_initialized_main_thread!();
    unsafe { from_glib_none(ffi::gtk_grab_get_current()) }
}

//#[doc(alias = "gtk_init_check")]
//pub fn init_check(argv: /*Unimplemented*/Vec<glib::GString>) -> bool {
//    unsafe { TODO: call ffi:gtk_init_check() }
//}

//#[doc(alias = "gtk_init_with_args")]
//pub fn init_with_args(argv: /*Unimplemented*/Vec<glib::GString>, parameter_string: Option<&str>, entries: /*Ignored*/&[&glib::OptionEntry], translation_domain: Option<&str>) -> Result<(), glib::Error> {
//    unsafe { TODO: call ffi:gtk_init_with_args() }
//}

/// Runs the main loop until `gtk_main_quit()` is called.
///
/// You can nest calls to [`main()`][crate::main()]. In that case `gtk_main_quit()`
/// will make the innermost invocation of the main loop return.
#[doc(alias = "gtk_main")]
pub fn main() {
    assert_initialized_main_thread!();
    unsafe {
        ffi::gtk_main();
    }
}

/// Processes a single GDK event.
///
/// This is public only to allow filtering of events between GDK and GTK+.
/// You will not usually need to call this function directly.
///
/// While you should not call this function directly, you might want to
/// know how exactly events are handled. So here is what this function
/// does with the event:
///
/// 1. Compress enter/leave notify events. If the event passed build an
///  enter/leave pair together with the next event (peeked from GDK), both
///  events are thrown away. This is to avoid a backlog of (de-)highlighting
///  widgets crossed by the pointer.
///
/// 2. Find the widget which got the event. If the widget can’t be determined
///  the event is thrown away unless it belongs to a INCR transaction.
///
/// 3. Then the event is pushed onto a stack so you can query the currently
///  handled event with [`current_event()`][crate::current_event()].
///
/// 4. The event is sent to a widget. If a grab is active all events for widgets
///  that are not in the contained in the grab widget are sent to the latter
///  with a few exceptions:
///  - Deletion and destruction events are still sent to the event widget for
///  obvious reasons.
///  - Events which directly relate to the visual representation of the event
///  widget.
///  - Leave events are delivered to the event widget if there was an enter
///  event delivered to it before without the paired leave event.
///  - Drag events are not redirected because it is unclear what the semantics
///  of that would be.
///  Another point of interest might be that all key events are first passed
///  through the key snooper functions if there are any. Read the description
///  of `gtk_key_snooper_install()` if you need this feature.
///
/// 5. After finishing the delivery the event is popped from the event stack.
/// ## `event`
/// An event to process (normally passed by GDK)
#[doc(alias = "gtk_main_do_event")]
pub fn main_do_event(event: &mut gdk::Event) {
    assert_initialized_main_thread!();
    unsafe {
        ffi::gtk_main_do_event(event.to_glib_none_mut().0);
    }
}

/// Runs a single iteration of the mainloop.
///
/// If no events are waiting to be processed GTK+ will block
/// until the next event is noticed. If you don’t want to block
/// look at [`main_iteration_do()`][crate::main_iteration_do()] or check if any events are
/// pending with [`events_pending()`][crate::events_pending()] first.
///
/// # Returns
///
/// [`true`] if `gtk_main_quit()` has been called for the
///  innermost mainloop
#[doc(alias = "gtk_main_iteration")]
pub fn main_iteration() -> bool {
    assert_initialized_main_thread!();
    unsafe { from_glib(ffi::gtk_main_iteration()) }
}

/// Runs a single iteration of the mainloop.
/// If no events are available either return or block depending on
/// the value of `blocking`.
/// ## `blocking`
/// [`true`] if you want GTK+ to block if no events are pending
///
/// # Returns
///
/// [`true`] if `gtk_main_quit()` has been called for the
///  innermost mainloop
#[doc(alias = "gtk_main_iteration_do")]
pub fn main_iteration_do(blocking: bool) -> bool {
    assert_initialized_main_thread!();
    unsafe { from_glib(ffi::gtk_main_iteration_do(blocking.into_glib())) }
}

/// Asks for the current nesting level of the main loop.
///
/// # Returns
///
/// the nesting level of the current invocation
///  of the main loop
#[doc(alias = "gtk_main_level")]
pub fn main_level() -> u32 {
    assert_initialized_main_thread!();
    unsafe { ffi::gtk_main_level() }
}

//#[doc(alias = "gtk_parse_args")]
//pub fn parse_args(argv: /*Unimplemented*/Vec<glib::GString>) -> bool {
//    unsafe { TODO: call ffi:gtk_parse_args() }
//}

/// Runs a page setup dialog, letting the user modify the values from
/// `page_setup`. If the user cancels the dialog, the returned [`PageSetup`][crate::PageSetup]
/// is identical to the passed in `page_setup`, otherwise it contains the
/// modifications done in the dialog.
///
/// Note that this function may use a recursive mainloop to show the page
/// setup dialog. See [`print_run_page_setup_dialog_async()`][crate::print_run_page_setup_dialog_async()] if this is
/// a problem.
/// ## `parent`
/// transient parent
/// ## `page_setup`
/// an existing [`PageSetup`][crate::PageSetup]
/// ## `settings`
/// a [`PrintSettings`][crate::PrintSettings]
///
/// # Returns
///
/// a new [`PageSetup`][crate::PageSetup]
#[doc(alias = "gtk_print_run_page_setup_dialog")]
pub fn print_run_page_setup_dialog<P: IsA<Window>>(
    parent: Option<&P>,
    page_setup: Option<&PageSetup>,
    settings: &PrintSettings,
) -> Option<PageSetup> {
    skip_assert_initialized!();
    unsafe {
        from_glib_full(ffi::gtk_print_run_page_setup_dialog(
            parent.map(|p| p.as_ref()).to_glib_none().0,
            page_setup.to_glib_none().0,
            settings.to_glib_none().0,
        ))
    }
}

/// Runs a page setup dialog, letting the user modify the values from `page_setup`.
///
/// In contrast to [`print_run_page_setup_dialog()`][crate::print_run_page_setup_dialog()], this function returns after
/// showing the page setup dialog on platforms that support this, and calls `done_cb`
/// from a signal handler for the ::response signal of the dialog.
/// ## `parent`
/// transient parent, or [`None`]
/// ## `page_setup`
/// an existing [`PageSetup`][crate::PageSetup], or [`None`]
/// ## `settings`
/// a [`PrintSettings`][crate::PrintSettings]
/// ## `done_cb`
/// a function to call when the user saves
///  the modified page setup
#[doc(alias = "gtk_print_run_page_setup_dialog_async")]
pub fn print_run_page_setup_dialog_async<
    P: IsA<Window>,
    Q: FnOnce(&PageSetup) + Send + Sync + 'static,
>(
    parent: Option<&P>,
    page_setup: Option<&PageSetup>,
    settings: &PrintSettings,
    done_cb: Q,
) {
    skip_assert_initialized!();
    let done_cb_data: Box_<Q> = Box_::new(done_cb);
    unsafe extern "C" fn done_cb_func<
        P: IsA<Window>,
        Q: FnOnce(&PageSetup) + Send + Sync + 'static,
    >(
        page_setup: *mut ffi::GtkPageSetup,
        data: glib::ffi::gpointer,
    ) {
        let page_setup = from_glib_borrow(page_setup);
        let callback: Box_<Q> = Box_::from_raw(data as *mut _);
        (*callback)(&page_setup);
    }
    let done_cb = Some(done_cb_func::<P, Q> as _);
    let super_callback0: Box_<Q> = done_cb_data;
    unsafe {
        ffi::gtk_print_run_page_setup_dialog_async(
            parent.map(|p| p.as_ref()).to_glib_none().0,
            page_setup.to_glib_none().0,
            settings.to_glib_none().0,
            done_cb,
            Box_::into_raw(super_callback0) as *mut _,
        );
    }
}

/// Sends an event to a widget, propagating the event to parent widgets
/// if the event remains unhandled.
///
/// Events received by GTK+ from GDK normally begin in [`main_do_event()`][crate::main_do_event()].
/// Depending on the type of event, existence of modal dialogs, grabs, etc.,
/// the event may be propagated; if so, this function is used.
///
/// [`propagate_event()`][crate::propagate_event()] calls [`WidgetExt::event()`][crate::prelude::WidgetExt::event()] on each widget it
/// decides to send the event to. So [`WidgetExt::event()`][crate::prelude::WidgetExt::event()] is the lowest-level
/// function; it simply emits the `signal::Widget::event` and possibly an
/// event-specific signal on a widget. [`propagate_event()`][crate::propagate_event()] is a bit
/// higher-level, and [`main_do_event()`][crate::main_do_event()] is the highest level.
///
/// All that said, you most likely don’t want to use any of these
/// functions; synthesizing events is rarely needed. There are almost
/// certainly better ways to achieve your goals. For example, use
/// [`Window::invalidate_rect()`][crate::gdk::Window::invalidate_rect()] or [`WidgetExt::queue_draw()`][crate::prelude::WidgetExt::queue_draw()] instead
/// of making up expose events.
/// ## `widget`
/// a [`Widget`][crate::Widget]
/// ## `event`
/// an event
#[doc(alias = "gtk_propagate_event")]
pub fn propagate_event<P: IsA<Widget>>(widget: &P, event: &mut gdk::Event) {
    skip_assert_initialized!();
    unsafe {
        ffi::gtk_propagate_event(widget.as_ref().to_glib_none().0, event.to_glib_none_mut().0);
    }
}

/// Renders an activity indicator (such as in [`Spinner`][crate::Spinner]).
/// The state [`StateFlags::CHECKED`][crate::StateFlags::CHECKED] determines whether there is
/// activity going on.
/// ## `context`
/// a [`StyleContext`][crate::StyleContext]
/// ## `cr`
/// a [`cairo::Context`][crate::cairo::Context]
/// ## `x`
/// X origin of the rectangle
/// ## `y`
/// Y origin of the rectangle
/// ## `width`
/// rectangle width
/// ## `height`
/// rectangle height
#[doc(alias = "gtk_render_activity")]
pub fn render_activity<P: IsA<StyleContext>>(
    context: &P,
    cr: &cairo::Context,
    x: f64,
    y: f64,
    width: f64,
    height: f64,
) {
    skip_assert_initialized!();
    unsafe {
        ffi::gtk_render_activity(
            context.as_ref().to_glib_none().0,
            mut_override(cr.to_glib_none().0),
            x,
            y,
            width,
            height,
        );
    }
}

/// Renders an arrow pointing to `angle`.
///
/// Typical arrow rendering at 0, 1⁄2 π;, π; and 3⁄2 π:
///
/// ![](arrows.png)
/// ## `context`
/// a [`StyleContext`][crate::StyleContext]
/// ## `cr`
/// a [`cairo::Context`][crate::cairo::Context]
/// ## `angle`
/// arrow angle from 0 to 2 * `G_PI`, being 0 the arrow pointing to the north
/// ## `x`
/// X origin of the render area
/// ## `y`
/// Y origin of the render area
/// ## `size`
/// square side for render area
#[doc(alias = "gtk_render_arrow")]
pub fn render_arrow<P: IsA<StyleContext>>(
    context: &P,
    cr: &cairo::Context,
    angle: f64,
    x: f64,
    y: f64,
    size: f64,
) {
    skip_assert_initialized!();
    unsafe {
        ffi::gtk_render_arrow(
            context.as_ref().to_glib_none().0,
            mut_override(cr.to_glib_none().0),
            angle,
            x,
            y,
            size,
        );
    }
}

/// Renders the background of an element.
///
/// Typical background rendering, showing the effect of
/// `background-image`, `border-width` and `border-radius`:
///
/// ![](background.png)
/// ## `context`
/// a [`StyleContext`][crate::StyleContext]
/// ## `cr`
/// a [`cairo::Context`][crate::cairo::Context]
/// ## `x`
/// X origin of the rectangle
/// ## `y`
/// Y origin of the rectangle
/// ## `width`
/// rectangle width
/// ## `height`
/// rectangle height
#[doc(alias = "gtk_render_background")]
pub fn render_background<P: IsA<StyleContext>>(
    context: &P,
    cr: &cairo::Context,
    x: f64,
    y: f64,
    width: f64,
    height: f64,
) {
    skip_assert_initialized!();
    unsafe {
        ffi::gtk_render_background(
            context.as_ref().to_glib_none().0,
            mut_override(cr.to_glib_none().0),
            x,
            y,
            width,
            height,
        );
    }
}

/// Returns the area that will be affected (i.e. drawn to) when
/// calling [`render_background()`][crate::render_background()] for the given `context` and
/// rectangle.
/// ## `context`
/// a [`StyleContext`][crate::StyleContext]
/// ## `x`
/// X origin of the rectangle
/// ## `y`
/// Y origin of the rectangle
/// ## `width`
/// rectangle width
/// ## `height`
/// rectangle height
///
/// # Returns
///
///
/// ## `out_clip`
/// return location for the clip
#[cfg(any(feature = "v3_20", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v3_20")))]
#[doc(alias = "gtk_render_background_get_clip")]
pub fn render_background_get_clip<P: IsA<StyleContext>>(
    context: &P,
    x: f64,
    y: f64,
    width: f64,
    height: f64,
) -> gdk::Rectangle {
    skip_assert_initialized!();
    unsafe {
        let mut out_clip = gdk::Rectangle::uninitialized();
        ffi::gtk_render_background_get_clip(
            context.as_ref().to_glib_none().0,
            x,
            y,
            width,
            height,
            out_clip.to_glib_none_mut().0,
        );
        out_clip
    }
}

/// Renders a checkmark (as in a [`CheckButton`][crate::CheckButton]).
///
/// The [`StateFlags::CHECKED`][crate::StateFlags::CHECKED] state determines whether the check is
/// on or off, and [`StateFlags::INCONSISTENT`][crate::StateFlags::INCONSISTENT] determines whether it
/// should be marked as undefined.
///
/// Typical checkmark rendering:
///
/// ![](checks.png)
/// ## `context`
/// a [`StyleContext`][crate::StyleContext]
/// ## `cr`
/// a [`cairo::Context`][crate::cairo::Context]
/// ## `x`
/// X origin of the rectangle
/// ## `y`
/// Y origin of the rectangle
/// ## `width`
/// rectangle width
/// ## `height`
/// rectangle height
#[doc(alias = "gtk_render_check")]
pub fn render_check<P: IsA<StyleContext>>(
    context: &P,
    cr: &cairo::Context,
    x: f64,
    y: f64,
    width: f64,
    height: f64,
) {
    skip_assert_initialized!();
    unsafe {
        ffi::gtk_render_check(
            context.as_ref().to_glib_none().0,
            mut_override(cr.to_glib_none().0),
            x,
            y,
            width,
            height,
        );
    }
}

/// Renders an expander (as used in [`TreeView`][crate::TreeView] and [`Expander`][crate::Expander]) in the area
/// defined by `x`, `y`, `width`, `height`. The state [`StateFlags::CHECKED`][crate::StateFlags::CHECKED]
/// determines whether the expander is collapsed or expanded.
///
/// Typical expander rendering:
///
/// ![](expanders.png)
/// ## `context`
/// a [`StyleContext`][crate::StyleContext]
/// ## `cr`
/// a [`cairo::Context`][crate::cairo::Context]
/// ## `x`
/// X origin of the rectangle
/// ## `y`
/// Y origin of the rectangle
/// ## `width`
/// rectangle width
/// ## `height`
/// rectangle height
#[doc(alias = "gtk_render_expander")]
pub fn render_expander<P: IsA<StyleContext>>(
    context: &P,
    cr: &cairo::Context,
    x: f64,
    y: f64,
    width: f64,
    height: f64,
) {
    skip_assert_initialized!();
    unsafe {
        ffi::gtk_render_expander(
            context.as_ref().to_glib_none().0,
            mut_override(cr.to_glib_none().0),
            x,
            y,
            width,
            height,
        );
    }
}

/// Renders a extension (as in a [`Notebook`][crate::Notebook] tab) in the rectangle
/// defined by `x`, `y`, `width`, `height`. The side where the extension
/// connects to is defined by `gap_side`.
///
/// Typical extension rendering:
///
/// ![](extensions.png)
/// ## `context`
/// a [`StyleContext`][crate::StyleContext]
/// ## `cr`
/// a [`cairo::Context`][crate::cairo::Context]
/// ## `x`
/// X origin of the rectangle
/// ## `y`
/// Y origin of the rectangle
/// ## `width`
/// rectangle width
/// ## `height`
/// rectangle height
/// ## `gap_side`
/// side where the gap is
#[doc(alias = "gtk_render_extension")]
pub fn render_extension<P: IsA<StyleContext>>(
    context: &P,
    cr: &cairo::Context,
    x: f64,
    y: f64,
    width: f64,
    height: f64,
    gap_side: PositionType,
) {
    skip_assert_initialized!();
    unsafe {
        ffi::gtk_render_extension(
            context.as_ref().to_glib_none().0,
            mut_override(cr.to_glib_none().0),
            x,
            y,
            width,
            height,
            gap_side.into_glib(),
        );
    }
}

/// Renders a focus indicator on the rectangle determined by `x`, `y`, `width`, `height`.
///
/// Typical focus rendering:
///
/// ![](focus.png)
/// ## `context`
/// a [`StyleContext`][crate::StyleContext]
/// ## `cr`
/// a [`cairo::Context`][crate::cairo::Context]
/// ## `x`
/// X origin of the rectangle
/// ## `y`
/// Y origin of the rectangle
/// ## `width`
/// rectangle width
/// ## `height`
/// rectangle height
#[doc(alias = "gtk_render_focus")]
pub fn render_focus<P: IsA<StyleContext>>(
    context: &P,
    cr: &cairo::Context,
    x: f64,
    y: f64,
    width: f64,
    height: f64,
) {
    skip_assert_initialized!();
    unsafe {
        ffi::gtk_render_focus(
            context.as_ref().to_glib_none().0,
            mut_override(cr.to_glib_none().0),
            x,
            y,
            width,
            height,
        );
    }
}

/// Renders a frame around the rectangle defined by `x`, `y`, `width`, `height`.
///
/// Examples of frame rendering, showing the effect of `border-image`,
/// `border-color`, `border-width`, `border-radius` and junctions:
///
/// ![](frames.png)
/// ## `context`
/// a [`StyleContext`][crate::StyleContext]
/// ## `cr`
/// a [`cairo::Context`][crate::cairo::Context]
/// ## `x`
/// X origin of the rectangle
/// ## `y`
/// Y origin of the rectangle
/// ## `width`
/// rectangle width
/// ## `height`
/// rectangle height
#[doc(alias = "gtk_render_frame")]
pub fn render_frame<P: IsA<StyleContext>>(
    context: &P,
    cr: &cairo::Context,
    x: f64,
    y: f64,
    width: f64,
    height: f64,
) {
    skip_assert_initialized!();
    unsafe {
        ffi::gtk_render_frame(
            context.as_ref().to_glib_none().0,
            mut_override(cr.to_glib_none().0),
            x,
            y,
            width,
            height,
        );
    }
}

/// Renders a frame around the rectangle defined by (`x`, `y`, `width`, `height`),
/// leaving a gap on one side. `xy0_gap` and `xy1_gap` will mean X coordinates
/// for [`PositionType::Top`][crate::PositionType::Top] and [`PositionType::Bottom`][crate::PositionType::Bottom] gap sides, and Y coordinates for
/// [`PositionType::Left`][crate::PositionType::Left] and [`PositionType::Right`][crate::PositionType::Right].
///
/// Typical rendering of a frame with a gap:
///
/// ![](frame-gap.png)
///
/// # Deprecated since 3.24
///
/// Use [`render_frame()`][crate::render_frame()] instead. Themes can create gaps
///  by omitting borders via CSS.
/// ## `context`
/// a [`StyleContext`][crate::StyleContext]
/// ## `cr`
/// a [`cairo::Context`][crate::cairo::Context]
/// ## `x`
/// X origin of the rectangle
/// ## `y`
/// Y origin of the rectangle
/// ## `width`
/// rectangle width
/// ## `height`
/// rectangle height
/// ## `gap_side`
/// side where the gap is
/// ## `xy0_gap`
/// initial coordinate (X or Y depending on `gap_side`) for the gap
/// ## `xy1_gap`
/// end coordinate (X or Y depending on `gap_side`) for the gap
#[cfg_attr(feature = "v3_24", deprecated = "Since 3.24")]
#[doc(alias = "gtk_render_frame_gap")]
pub fn render_frame_gap<P: IsA<StyleContext>>(
    context: &P,
    cr: &cairo::Context,
    x: f64,
    y: f64,
    width: f64,
    height: f64,
    gap_side: PositionType,
    xy0_gap: f64,
    xy1_gap: f64,
) {
    skip_assert_initialized!();
    unsafe {
        ffi::gtk_render_frame_gap(
            context.as_ref().to_glib_none().0,
            mut_override(cr.to_glib_none().0),
            x,
            y,
            width,
            height,
            gap_side.into_glib(),
            xy0_gap,
            xy1_gap,
        );
    }
}

/// Renders a handle (as in `GtkHandleBox`, [`Paned`][crate::Paned] and
/// [`Window`][crate::Window]’s resize grip), in the rectangle
/// determined by `x`, `y`, `width`, `height`.
///
/// Handles rendered for the paned and grip classes:
///
/// ![](handles.png)
/// ## `context`
/// a [`StyleContext`][crate::StyleContext]
/// ## `cr`
/// a [`cairo::Context`][crate::cairo::Context]
/// ## `x`
/// X origin of the rectangle
/// ## `y`
/// Y origin of the rectangle
/// ## `width`
/// rectangle width
/// ## `height`
/// rectangle height
#[doc(alias = "gtk_render_handle")]
pub fn render_handle<P: IsA<StyleContext>>(
    context: &P,
    cr: &cairo::Context,
    x: f64,
    y: f64,
    width: f64,
    height: f64,
) {
    skip_assert_initialized!();
    unsafe {
        ffi::gtk_render_handle(
            context.as_ref().to_glib_none().0,
            mut_override(cr.to_glib_none().0),
            x,
            y,
            width,
            height,
        );
    }
}

/// Renders the icon in `pixbuf` at the specified `x` and `y` coordinates.
///
/// This function will render the icon in `pixbuf` at exactly its size,
/// regardless of scaling factors, which may not be appropriate when
/// drawing on displays with high pixel densities.
///
/// You probably want to use [`render_icon_surface()`][crate::render_icon_surface()] instead, if you
/// already have a Cairo surface.
/// ## `context`
/// a [`StyleContext`][crate::StyleContext]
/// ## `cr`
/// a [`cairo::Context`][crate::cairo::Context]
/// ## `pixbuf`
/// a [`gdk_pixbuf::Pixbuf`][crate::gdk_pixbuf::Pixbuf] containing the icon to draw
/// ## `x`
/// X position for the `pixbuf`
/// ## `y`
/// Y position for the `pixbuf`
#[doc(alias = "gtk_render_icon")]
pub fn render_icon<P: IsA<StyleContext>>(
    context: &P,
    cr: &cairo::Context,
    pixbuf: &gdk_pixbuf::Pixbuf,
    x: f64,
    y: f64,
) {
    skip_assert_initialized!();
    unsafe {
        ffi::gtk_render_icon(
            context.as_ref().to_glib_none().0,
            mut_override(cr.to_glib_none().0),
            pixbuf.to_glib_none().0,
            x,
            y,
        );
    }
}

/// Renders the icon in `surface` at the specified `x` and `y` coordinates.
/// ## `context`
/// a [`StyleContext`][crate::StyleContext]
/// ## `cr`
/// a [`cairo::Context`][crate::cairo::Context]
/// ## `surface`
/// a [`cairo::Surface`][crate::cairo::Surface] containing the icon to draw
/// ## `x`
/// X position for the `icon`
/// ## `y`
/// Y position for the `incon`
#[doc(alias = "gtk_render_icon_surface")]
pub fn render_icon_surface<P: IsA<StyleContext>>(
    context: &P,
    cr: &cairo::Context,
    surface: &cairo::Surface,
    x: f64,
    y: f64,
) {
    skip_assert_initialized!();
    unsafe {
        ffi::gtk_render_icon_surface(
            context.as_ref().to_glib_none().0,
            mut_override(cr.to_glib_none().0),
            mut_override(surface.to_glib_none().0),
            x,
            y,
        );
    }
}

/// Draws a text caret on `cr` at the specified index of `layout`.
/// ## `context`
/// a [`StyleContext`][crate::StyleContext]
/// ## `cr`
/// a [`cairo::Context`][crate::cairo::Context]
/// ## `x`
/// X origin
/// ## `y`
/// Y origin
/// ## `layout`
/// the [`pango::Layout`][crate::pango::Layout] of the text
/// ## `index`
/// the index in the [`pango::Layout`][crate::pango::Layout]
/// ## `direction`
/// the [`pango::Direction`][crate::pango::Direction] of the text
#[doc(alias = "gtk_render_insertion_cursor")]
pub fn render_insertion_cursor<P: IsA<StyleContext>>(
    context: &P,
    cr: &cairo::Context,
    x: f64,
    y: f64,
    layout: &pango::Layout,
    index: i32,
    direction: pango::Direction,
) {
    skip_assert_initialized!();
    unsafe {
        ffi::gtk_render_insertion_cursor(
            context.as_ref().to_glib_none().0,
            mut_override(cr.to_glib_none().0),
            x,
            y,
            layout.to_glib_none().0,
            index,
            direction.into_glib(),
        );
    }
}

/// Renders `layout` on the coordinates `x`, `y`
/// ## `context`
/// a [`StyleContext`][crate::StyleContext]
/// ## `cr`
/// a [`cairo::Context`][crate::cairo::Context]
/// ## `x`
/// X origin
/// ## `y`
/// Y origin
/// ## `layout`
/// the [`pango::Layout`][crate::pango::Layout] to render
#[doc(alias = "gtk_render_layout")]
pub fn render_layout<P: IsA<StyleContext>>(
    context: &P,
    cr: &cairo::Context,
    x: f64,
    y: f64,
    layout: &pango::Layout,
) {
    skip_assert_initialized!();
    unsafe {
        ffi::gtk_render_layout(
            context.as_ref().to_glib_none().0,
            mut_override(cr.to_glib_none().0),
            x,
            y,
            layout.to_glib_none().0,
        );
    }
}

/// Renders a line from (x0, y0) to (x1, y1).
/// ## `context`
/// a [`StyleContext`][crate::StyleContext]
/// ## `cr`
/// a [`cairo::Context`][crate::cairo::Context]
/// ## `x0`
/// X coordinate for the origin of the line
/// ## `y0`
/// Y coordinate for the origin of the line
/// ## `x1`
/// X coordinate for the end of the line
/// ## `y1`
/// Y coordinate for the end of the line
#[doc(alias = "gtk_render_line")]
pub fn render_line<P: IsA<StyleContext>>(
    context: &P,
    cr: &cairo::Context,
    x0: f64,
    y0: f64,
    x1: f64,
    y1: f64,
) {
    skip_assert_initialized!();
    unsafe {
        ffi::gtk_render_line(
            context.as_ref().to_glib_none().0,
            mut_override(cr.to_glib_none().0),
            x0,
            y0,
            x1,
            y1,
        );
    }
}

/// Renders an option mark (as in a [`RadioButton`][crate::RadioButton]), the [`StateFlags::CHECKED`][crate::StateFlags::CHECKED]
/// state will determine whether the option is on or off, and
/// [`StateFlags::INCONSISTENT`][crate::StateFlags::INCONSISTENT] whether it should be marked as undefined.
///
/// Typical option mark rendering:
///
/// ![](options.png)
/// ## `context`
/// a [`StyleContext`][crate::StyleContext]
/// ## `cr`
/// a [`cairo::Context`][crate::cairo::Context]
/// ## `x`
/// X origin of the rectangle
/// ## `y`
/// Y origin of the rectangle
/// ## `width`
/// rectangle width
/// ## `height`
/// rectangle height
#[doc(alias = "gtk_render_option")]
pub fn render_option<P: IsA<StyleContext>>(
    context: &P,
    cr: &cairo::Context,
    x: f64,
    y: f64,
    width: f64,
    height: f64,
) {
    skip_assert_initialized!();
    unsafe {
        ffi::gtk_render_option(
            context.as_ref().to_glib_none().0,
            mut_override(cr.to_glib_none().0),
            x,
            y,
            width,
            height,
        );
    }
}

/// Renders a slider (as in [`Scale`][crate::Scale]) in the rectangle defined by `x`, `y`,
/// `width`, `height`. `orientation` defines whether the slider is vertical
/// or horizontal.
///
/// Typical slider rendering:
///
/// ![](sliders.png)
/// ## `context`
/// a [`StyleContext`][crate::StyleContext]
/// ## `cr`
/// a [`cairo::Context`][crate::cairo::Context]
/// ## `x`
/// X origin of the rectangle
/// ## `y`
/// Y origin of the rectangle
/// ## `width`
/// rectangle width
/// ## `height`
/// rectangle height
/// ## `orientation`
/// orientation of the slider
#[doc(alias = "gtk_render_slider")]
pub fn render_slider<P: IsA<StyleContext>>(
    context: &P,
    cr: &cairo::Context,
    x: f64,
    y: f64,
    width: f64,
    height: f64,
    orientation: Orientation,
) {
    skip_assert_initialized!();
    unsafe {
        ffi::gtk_render_slider(
            context.as_ref().to_glib_none().0,
            mut_override(cr.to_glib_none().0),
            x,
            y,
            width,
            height,
            orientation.into_glib(),
        );
    }
}

/// Converts a color from RGB space to HSV.
///
/// Input values must be in the [0.0, 1.0] range;
/// output values will be in the same range.
/// ## `r`
/// Red
/// ## `g`
/// Green
/// ## `b`
/// Blue
///
/// # Returns
///
///
/// ## `h`
/// Return value for the hue component
///
/// ## `s`
/// Return value for the saturation component
///
/// ## `v`
/// Return value for the value component
#[doc(alias = "gtk_rgb_to_hsv")]
pub fn rgb_to_hsv(r: f64, g: f64, b: f64) -> (f64, f64, f64) {
    assert_initialized_main_thread!();
    unsafe {
        let mut h = mem::MaybeUninit::uninit();
        let mut s = mem::MaybeUninit::uninit();
        let mut v = mem::MaybeUninit::uninit();
        ffi::gtk_rgb_to_hsv(r, g, b, h.as_mut_ptr(), s.as_mut_ptr(), v.as_mut_ptr());
        let h = h.assume_init();
        let s = s.assume_init();
        let v = v.assume_init();
        (h, s, v)
    }
}

/// Appends a specified target to the list of supported targets for a
/// given widget and selection.
/// ## `widget`
/// a [`Widget`][crate::Widget]
/// ## `selection`
/// the selection
/// ## `target`
/// target to add.
/// ## `info`
/// A unsigned integer which will be passed back to the application.
#[doc(alias = "gtk_selection_add_target")]
pub fn selection_add_target<P: IsA<Widget>>(
    widget: &P,
    selection: &gdk::Atom,
    target: &gdk::Atom,
    info: u32,
) {
    skip_assert_initialized!();
    unsafe {
        ffi::gtk_selection_add_target(
            widget.as_ref().to_glib_none().0,
            selection.to_glib_none().0,
            target.to_glib_none().0,
            info,
        );
    }
}

/// Remove all targets registered for the given selection for the
/// widget.
/// ## `widget`
/// a [`Widget`][crate::Widget]
/// ## `selection`
/// an atom representing a selection
#[doc(alias = "gtk_selection_clear_targets")]
pub fn selection_clear_targets<P: IsA<Widget>>(widget: &P, selection: &gdk::Atom) {
    skip_assert_initialized!();
    unsafe {
        ffi::gtk_selection_clear_targets(
            widget.as_ref().to_glib_none().0,
            selection.to_glib_none().0,
        );
    }
}

/// Requests the contents of a selection. When received,
/// a “selection-received” signal will be generated.
/// ## `widget`
/// The widget which acts as requestor
/// ## `selection`
/// Which selection to get
/// ## `target`
/// Form of information desired (e.g., STRING)
/// ## `time_`
/// Time of request (usually of triggering event)
///  In emergency, you could use `GDK_CURRENT_TIME`
///
/// # Returns
///
/// [`true`] if requested succeeded. [`false`] if we could not process
///  request. (e.g., there was already a request in process for
///  this widget).
#[doc(alias = "gtk_selection_convert")]
pub fn selection_convert<P: IsA<Widget>>(
    widget: &P,
    selection: &gdk::Atom,
    target: &gdk::Atom,
    time_: u32,
) -> bool {
    skip_assert_initialized!();
    unsafe {
        from_glib(ffi::gtk_selection_convert(
            widget.as_ref().to_glib_none().0,
            selection.to_glib_none().0,
            target.to_glib_none().0,
            time_,
        ))
    }
}

/// Claims ownership of a given selection for a particular widget,
/// or, if `widget` is [`None`], release ownership of the selection.
/// ## `widget`
/// a [`Widget`][crate::Widget], or [`None`].
/// ## `selection`
/// an interned atom representing the selection to claim
/// ## `time_`
/// timestamp with which to claim the selection
///
/// # Returns
///
/// [`true`] if the operation succeeded
#[doc(alias = "gtk_selection_owner_set")]
pub fn selection_owner_set<P: IsA<Widget>>(
    widget: Option<&P>,
    selection: &gdk::Atom,
    time_: u32,
) -> bool {
    assert_initialized_main_thread!();
    unsafe {
        from_glib(ffi::gtk_selection_owner_set(
            widget.map(|p| p.as_ref()).to_glib_none().0,
            selection.to_glib_none().0,
            time_,
        ))
    }
}

/// Claim ownership of a given selection for a particular widget, or,
/// if `widget` is [`None`], release ownership of the selection.
/// ## `display`
/// the [`gdk::Display`][crate::gdk::Display] where the selection is set
/// ## `widget`
/// new selection owner (a [`Widget`][crate::Widget]), or [`None`].
/// ## `selection`
/// an interned atom representing the selection to claim.
/// ## `time_`
/// timestamp with which to claim the selection
///
/// # Returns
///
/// TRUE if the operation succeeded
#[doc(alias = "gtk_selection_owner_set_for_display")]
pub fn selection_owner_set_for_display<P: IsA<Widget>>(
    display: &gdk::Display,
    widget: Option<&P>,
    selection: &gdk::Atom,
    time_: u32,
) -> bool {
    assert_initialized_main_thread!();
    unsafe {
        from_glib(ffi::gtk_selection_owner_set_for_display(
            display.to_glib_none().0,
            widget.map(|p| p.as_ref()).to_glib_none().0,
            selection.to_glib_none().0,
            time_,
        ))
    }
}

/// Removes all handlers and unsets ownership of all
/// selections for a widget. Called when widget is being
/// destroyed. This function will not generally be
/// called by applications.
/// ## `widget`
/// a [`Widget`][crate::Widget]
#[doc(alias = "gtk_selection_remove_all")]
pub fn selection_remove_all<P: IsA<Widget>>(widget: &P) {
    skip_assert_initialized!();
    unsafe {
        ffi::gtk_selection_remove_all(widget.as_ref().to_glib_none().0);
    }
}

/// Sets the GTK+ debug flags.
#[doc(alias = "gtk_set_debug_flags")]
pub fn set_debug_flags(flags: u32) {
    assert_initialized_main_thread!();
    unsafe {
        ffi::gtk_set_debug_flags(flags);
    }
}

//#[doc(alias = "gtk_show_about_dialog")]
//pub fn show_about_dialog<P: IsA<Window>>(parent: Option<&P>, first_property_name: &str, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) {
//    unsafe { TODO: call ffi:gtk_show_about_dialog() }
//}

/// A convenience function for launching the default application
/// to show the uri. Like [`show_uri_on_window()`][crate::show_uri_on_window()], but takes a screen
/// as transient parent instead of a window.
///
/// Note that this function is deprecated as it does not pass the necessary
/// information for helpers to parent their dialog properly, when run from
/// sandboxed applications for example.
/// ## `screen`
/// screen to show the uri on
///  or [`None`] for the default screen
/// ## `uri`
/// the uri to show
/// ## `timestamp`
/// a timestamp to prevent focus stealing
///
/// # Returns
///
/// [`true`] on success, [`false`] on error
#[doc(alias = "gtk_show_uri")]
pub fn show_uri(
    screen: Option<&gdk::Screen>,
    uri: &str,
    timestamp: u32,
) -> Result<(), glib::Error> {
    assert_initialized_main_thread!();
    unsafe {
        let mut error = ptr::null_mut();
        let _ = ffi::gtk_show_uri(
            screen.to_glib_none().0,
            uri.to_glib_none().0,
            timestamp,
            &mut error,
        );
        if error.is_null() {
            Ok(())
        } else {
            Err(from_glib_full(error))
        }
    }
}

/// This is a convenience function for launching the default application
/// to show the uri. The uri must be of a form understood by GIO (i.e. you
/// need to install gvfs to get support for uri schemes such as http://
/// or ftp://, as only local files are handled by GIO itself).
/// Typical examples are
/// - `file:///home/gnome/pict.jpg`
/// - `http://www.gnome.org`
/// - `mailto:me`gnome``
///
/// Ideally the timestamp is taken from the event triggering
/// the [`show_uri()`][crate::show_uri()] call. If timestamp is not known you can take
/// `GDK_CURRENT_TIME`.
///
/// This is the recommended call to be used as it passes information
/// necessary for sandbox helpers to parent their dialogs properly.
/// ## `parent`
/// parent window
/// ## `uri`
/// the uri to show
/// ## `timestamp`
/// a timestamp to prevent focus stealing
///
/// # Returns
///
/// [`true`] on success, [`false`] on error
#[cfg(any(feature = "v3_22", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v3_22")))]
#[doc(alias = "gtk_show_uri_on_window")]
pub fn show_uri_on_window<P: IsA<Window>>(
    parent: Option<&P>,
    uri: &str,
    timestamp: u32,
) -> Result<(), glib::Error> {
    assert_initialized_main_thread!();
    unsafe {
        let mut error = ptr::null_mut();
        let _ = ffi::gtk_show_uri_on_window(
            parent.map(|p| p.as_ref()).to_glib_none().0,
            uri.to_glib_none().0,
            timestamp,
            &mut error,
        );
        if error.is_null() {
            Ok(())
        } else {
            Err(from_glib_full(error))
        }
    }
}

/// Determines if any of the targets in `targets` can be used to
/// provide a [`gdk_pixbuf::Pixbuf`][crate::gdk_pixbuf::Pixbuf].
/// ## `targets`
/// an array of `GdkAtoms`
/// ## `writable`
/// whether to accept only targets for which GTK+ knows
///  how to convert a pixbuf into the format
///
/// # Returns
///
/// [`true`] if `targets` include a suitable target for images,
///  otherwise [`false`].
#[doc(alias = "gtk_targets_include_image")]
pub fn targets_include_image(targets: &[&gdk::Atom], writable: bool) -> bool {
    assert_initialized_main_thread!();
    let n_targets = targets.len() as i32;
    unsafe {
        from_glib(ffi::gtk_targets_include_image(
            targets.to_glib_none().0,
            n_targets,
            writable.into_glib(),
        ))
    }
}

/// Determines if any of the targets in `targets` can be used to
/// provide rich text.
/// ## `targets`
/// an array of `GdkAtoms`
/// ## `buffer`
/// a [`TextBuffer`][crate::TextBuffer]
///
/// # Returns
///
/// [`true`] if `targets` include a suitable target for rich text,
///  otherwise [`false`].
#[doc(alias = "gtk_targets_include_rich_text")]
pub fn targets_include_rich_text<P: IsA<TextBuffer>>(targets: &[&gdk::Atom], buffer: &P) -> bool {
    skip_assert_initialized!();
    let n_targets = targets.len() as i32;
    unsafe {
        from_glib(ffi::gtk_targets_include_rich_text(
            targets.to_glib_none().0,
            n_targets,
            buffer.as_ref().to_glib_none().0,
        ))
    }
}

/// Determines if any of the targets in `targets` can be used to
/// provide text.
/// ## `targets`
/// an array of `GdkAtoms`
///
/// # Returns
///
/// [`true`] if `targets` include a suitable target for text,
///  otherwise [`false`].
#[doc(alias = "gtk_targets_include_text")]
pub fn targets_include_text(targets: &[&gdk::Atom]) -> bool {
    assert_initialized_main_thread!();
    let n_targets = targets.len() as i32;
    unsafe {
        from_glib(ffi::gtk_targets_include_text(
            targets.to_glib_none().0,
            n_targets,
        ))
    }
}

/// Determines if any of the targets in `targets` can be used to
/// provide an uri list.
/// ## `targets`
/// an array of `GdkAtoms`
///
/// # Returns
///
/// [`true`] if `targets` include a suitable target for uri lists,
///  otherwise [`false`].
#[doc(alias = "gtk_targets_include_uri")]
pub fn targets_include_uri(targets: &[&gdk::Atom]) -> bool {
    assert_initialized_main_thread!();
    let n_targets = targets.len() as i32;
    unsafe {
        from_glib(ffi::gtk_targets_include_uri(
            targets.to_glib_none().0,
            n_targets,
        ))
    }
}

/// Create a simple window with window title `window_title` and
/// text contents `dialog_text`.
/// The window will quit any running [`main()`][crate::main()]-loop when destroyed, and it
/// will automatically be destroyed upon test function teardown.
///
/// # Deprecated since 3.20
///
/// This testing infrastructure is phased out in favor of reftests.
/// ## `window_title`
/// Title of the window to be displayed.
/// ## `dialog_text`
/// Text inside the window to be displayed.
///
/// # Returns
///
/// a widget pointer to the newly created GtkWindow.
#[cfg_attr(feature = "v3_20", deprecated = "Since 3.20")]
#[doc(alias = "gtk_test_create_simple_window")]
pub fn test_create_simple_window(window_title: &str, dialog_text: &str) -> Option<Widget> {
    assert_initialized_main_thread!();
    unsafe {
        from_glib_none(ffi::gtk_test_create_simple_window(
            window_title.to_glib_none().0,
            dialog_text.to_glib_none().0,
        ))
    }
}

//#[cfg_attr(feature = "v3_20", deprecated = "Since 3.20")]
//#[doc(alias = "gtk_test_create_widget")]
//pub fn test_create_widget(widget_type: glib::types::Type, first_property_name: Option<&str>, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) -> Option<Widget> {
//    unsafe { TODO: call ffi:gtk_test_create_widget() }
//}

//#[cfg_attr(feature = "v3_20", deprecated = "Since 3.20")]
//#[doc(alias = "gtk_test_display_button_window")]
//pub fn test_display_button_window(window_title: &str, dialog_text: &str, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) -> Option<Widget> {
//    unsafe { TODO: call ffi:gtk_test_display_button_window() }
//}

/// This function will search `widget` and all its descendants for a GtkLabel
/// widget with a text string matching `label_pattern`.
/// The `label_pattern` may contain asterisks “*” and question marks “?” as
/// placeholders, `g_pattern_match()` is used for the matching.
/// Note that locales other than "C“ tend to alter (translate” label strings,
/// so this function is genrally only useful in test programs with
/// predetermined locales, see `gtk_test_init()` for more details.
/// ## `widget`
/// Valid label or container widget.
/// ## `label_pattern`
/// Shell-glob pattern to match a label string.
///
/// # Returns
///
/// a GtkLabel widget if any is found.
#[doc(alias = "gtk_test_find_label")]
pub fn test_find_label<P: IsA<Widget>>(widget: &P, label_pattern: &str) -> Option<Widget> {
    skip_assert_initialized!();
    unsafe {
        from_glib_none(ffi::gtk_test_find_label(
            widget.as_ref().to_glib_none().0,
            label_pattern.to_glib_none().0,
        ))
    }
}

/// This function will search siblings of `base_widget` and siblings of its
/// ancestors for all widgets matching `widget_type`.
/// Of the matching widgets, the one that is geometrically closest to
/// `base_widget` will be returned.
/// The general purpose of this function is to find the most likely “action”
/// widget, relative to another labeling widget. Such as finding a
/// button or text entry widget, given its corresponding label widget.
/// ## `base_widget`
/// Valid widget, part of a widget hierarchy
/// ## `widget_type`
/// Type of a aearched for sibling widget
///
/// # Returns
///
/// a widget of type `widget_type` if any is found.
#[doc(alias = "gtk_test_find_sibling")]
pub fn test_find_sibling<P: IsA<Widget>>(
    base_widget: &P,
    widget_type: glib::types::Type,
) -> Option<Widget> {
    skip_assert_initialized!();
    unsafe {
        from_glib_none(ffi::gtk_test_find_sibling(
            base_widget.as_ref().to_glib_none().0,
            widget_type.into_glib(),
        ))
    }
}

/// This function will search the descendants of `widget` for a widget
/// of type `widget_type` that has a label matching `label_pattern` next
/// to it. This is most useful for automated GUI testing, e.g. to find
/// the “OK” button in a dialog and synthesize clicks on it.
/// However see [`test_find_label()`][crate::test_find_label()], [`test_find_sibling()`][crate::test_find_sibling()] and
/// [`test_widget_click()`][crate::test_widget_click()] for possible caveats involving the search of
/// such widgets and synthesizing widget events.
/// ## `widget`
/// Container widget, usually a GtkWindow.
/// ## `label_pattern`
/// Shell-glob pattern to match a label string.
/// ## `widget_type`
/// Type of a aearched for label sibling widget.
///
/// # Returns
///
/// a valid widget if any is found or [`None`].
#[doc(alias = "gtk_test_find_widget")]
pub fn test_find_widget<P: IsA<Widget>>(
    widget: &P,
    label_pattern: &str,
    widget_type: glib::types::Type,
) -> Option<Widget> {
    skip_assert_initialized!();
    unsafe {
        from_glib_none(ffi::gtk_test_find_widget(
            widget.as_ref().to_glib_none().0,
            label_pattern.to_glib_none().0,
            widget_type.into_glib(),
        ))
    }
}

//#[doc(alias = "gtk_test_init")]
//pub fn test_init(argvp: /*Unimplemented*/Vec<glib::GString>, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) {
//    unsafe { TODO: call ffi:gtk_test_init() }
//}

//#[doc(alias = "gtk_test_list_all_types")]
//pub fn test_list_all_types() -> /*Unimplemented*/CArray TypeId { ns_id: 0, id: 30 } {
//    unsafe { TODO: call ffi:gtk_test_list_all_types() }
//}

/// Force registration of all core Gtk+ and Gdk object types.
/// This allowes to refer to any of those object types via
/// `g_type_from_name()` after calling this function.
#[doc(alias = "gtk_test_register_all_types")]
pub fn test_register_all_types() {
    assert_initialized_main_thread!();
    unsafe {
        ffi::gtk_test_register_all_types();
    }
}

/// Retrive the literal adjustment value for GtkRange based
/// widgets and spin buttons. Note that the value returned by
/// this function is anything between the lower and upper bounds
/// of the adjustment belonging to `widget`, and is not a percentage
/// as passed in to [`test_slider_set_perc()`][crate::test_slider_set_perc()].
///
/// # Deprecated since 3.20
///
/// This testing infrastructure is phased out in favor of reftests.
/// ## `widget`
/// valid widget pointer.
///
/// # Returns
///
/// gtk_adjustment_get_value (adjustment) for an adjustment belonging to `widget`.
#[cfg_attr(feature = "v3_20", deprecated = "Since 3.20")]
#[doc(alias = "gtk_test_slider_get_value")]
pub fn test_slider_get_value<P: IsA<Widget>>(widget: &P) -> f64 {
    skip_assert_initialized!();
    unsafe { ffi::gtk_test_slider_get_value(widget.as_ref().to_glib_none().0) }
}

/// This function will adjust the slider position of all GtkRange
/// based widgets, such as scrollbars or scales, it’ll also adjust
/// spin buttons. The adjustment value of these widgets is set to
/// a value between the lower and upper limits, according to the
/// `percentage` argument.
///
/// # Deprecated since 3.20
///
/// This testing infrastructure is phased out in favor of reftests.
/// ## `widget`
/// valid widget pointer.
/// ## `percentage`
/// value between 0 and 100.
#[cfg_attr(feature = "v3_20", deprecated = "Since 3.20")]
#[doc(alias = "gtk_test_slider_set_perc")]
pub fn test_slider_set_perc<P: IsA<Widget>>(widget: &P, percentage: f64) {
    skip_assert_initialized!();
    unsafe {
        ffi::gtk_test_slider_set_perc(widget.as_ref().to_glib_none().0, percentage);
    }
}

/// This function will generate a `button` click in the upwards or downwards
/// spin button arrow areas, usually leading to an increase or decrease of
/// spin button’s value.
///
/// # Deprecated since 3.20
///
/// This testing infrastructure is phased out in favor of reftests.
/// ## `spinner`
/// valid GtkSpinButton widget.
/// ## `button`
/// Number of the pointer button for the event, usually 1, 2 or 3.
/// ## `upwards`
/// [`true`] for upwards arrow click, [`false`] for downwards arrow click.
///
/// # Returns
///
/// whether all actions neccessary for the button click simulation were carried out successfully.
#[cfg_attr(feature = "v3_20", deprecated = "Since 3.20")]
#[doc(alias = "gtk_test_spin_button_click")]
pub fn test_spin_button_click<P: IsA<SpinButton>>(spinner: &P, button: u32, upwards: bool) -> bool {
    skip_assert_initialized!();
    unsafe {
        from_glib(ffi::gtk_test_spin_button_click(
            spinner.as_ref().to_glib_none().0,
            button,
            upwards.into_glib(),
        ))
    }
}

/// Retrive the text string of `widget` if it is a GtkLabel,
/// GtkEditable (entry and text widgets) or GtkTextView.
///
/// # Deprecated since 3.20
///
/// This testing infrastructure is phased out in favor of reftests.
/// ## `widget`
/// valid widget pointer.
///
/// # Returns
///
/// new 0-terminated C string, needs to be released with `g_free()`.
#[cfg_attr(feature = "v3_20", deprecated = "Since 3.20")]
#[doc(alias = "gtk_test_text_get")]
pub fn test_text_get<P: IsA<Widget>>(widget: &P) -> Option<glib::GString> {
    skip_assert_initialized!();
    unsafe { from_glib_full(ffi::gtk_test_text_get(widget.as_ref().to_glib_none().0)) }
}

/// Set the text string of `widget` to `string` if it is a GtkLabel,
/// GtkEditable (entry and text widgets) or GtkTextView.
///
/// # Deprecated since 3.20
///
/// This testing infrastructure is phased out in favor of reftests.
/// ## `widget`
/// valid widget pointer.
/// ## `string`
/// a 0-terminated C string
#[cfg_attr(feature = "v3_20", deprecated = "Since 3.20")]
#[doc(alias = "gtk_test_text_set")]
pub fn test_text_set<P: IsA<Widget>>(widget: &P, string: &str) {
    skip_assert_initialized!();
    unsafe {
        ffi::gtk_test_text_set(widget.as_ref().to_glib_none().0, string.to_glib_none().0);
    }
}

/// This function will generate a `button` click (button press and button
/// release event) in the middle of the first GdkWindow found that belongs
/// to `widget`.
/// For windowless widgets like [`Button`][crate::Button] (which returns [`false`] from
/// [`WidgetExt::has_window()`][crate::prelude::WidgetExt::has_window()]), this will often be an
/// input-only event window. For other widgets, this is usually widget->window.
/// Certain caveats should be considered when using this function, in
/// particular because the mouse pointer is warped to the button click
/// location, see `gdk_test_simulate_button()` for details.
///
/// # Deprecated since 3.20
///
/// This testing infrastructure is phased out in favor of reftests.
/// ## `widget`
/// Widget to generate a button click on.
/// ## `button`
/// Number of the pointer button for the event, usually 1, 2 or 3.
/// ## `modifiers`
/// Keyboard modifiers the event is setup with.
///
/// # Returns
///
/// whether all actions neccessary for the button click simulation were carried out successfully.
#[cfg_attr(feature = "v3_20", deprecated = "Since 3.20")]
#[doc(alias = "gtk_test_widget_click")]
pub fn test_widget_click<P: IsA<Widget>>(
    widget: &P,
    button: u32,
    modifiers: gdk::ModifierType,
) -> bool {
    skip_assert_initialized!();
    unsafe {
        from_glib(ffi::gtk_test_widget_click(
            widget.as_ref().to_glib_none().0,
            button,
            modifiers.into_glib(),
        ))
    }
}

/// This function will generate keyboard press and release events in
/// the middle of the first GdkWindow found that belongs to `widget`.
/// For windowless widgets like [`Button`][crate::Button] (which returns [`false`] from
/// [`WidgetExt::has_window()`][crate::prelude::WidgetExt::has_window()]), this will often be an
/// input-only event window. For other widgets, this is usually widget->window.
/// Certain caveats should be considered when using this function, in
/// particular because the mouse pointer is warped to the key press
/// location, see `gdk_test_simulate_key()` for details.
/// ## `widget`
/// Widget to generate a key press and release on.
/// ## `keyval`
/// A Gdk keyboard value.
/// ## `modifiers`
/// Keyboard modifiers the event is setup with.
///
/// # Returns
///
/// whether all actions neccessary for the key event simulation were carried out successfully.
#[doc(alias = "gtk_test_widget_send_key")]
pub fn test_widget_send_key<P: IsA<Widget>>(
    widget: &P,
    keyval: u32,
    modifiers: gdk::ModifierType,
) -> bool {
    skip_assert_initialized!();
    unsafe {
        from_glib(ffi::gtk_test_widget_send_key(
            widget.as_ref().to_glib_none().0,
            keyval,
            modifiers.into_glib(),
        ))
    }
}

/// Enters the main loop and waits for `widget` to be “drawn”. In this
/// context that means it waits for the frame clock of `widget` to have
/// run a full styling, layout and drawing cycle.
///
/// This function is intended to be used for syncing with actions that
/// depend on `widget` relayouting or on interaction with the display
/// server.
/// ## `widget`
/// the widget to wait for
#[doc(alias = "gtk_test_widget_wait_for_draw")]
pub fn test_widget_wait_for_draw<P: IsA<Widget>>(widget: &P) {
    skip_assert_initialized!();
    unsafe {
        ffi::gtk_test_widget_wait_for_draw(widget.as_ref().to_glib_none().0);
    }
}

/// Obtains a `tree_model` and `path` from selection data of target type
/// `GTK_TREE_MODEL_ROW`. Normally called from a drag_data_received handler.
/// This function can only be used if `selection_data` originates from the same
/// process that’s calling this function, because a pointer to the tree model
/// is being passed around. If you aren’t in the same process, then you'll
/// get memory corruption. In the [`TreeDragDest`][crate::TreeDragDest] drag_data_received handler,
/// you can assume that selection data of type `GTK_TREE_MODEL_ROW` is
/// in from the current process. The returned path must be freed with
/// `gtk_tree_path_free()`.
/// ## `selection_data`
/// a [`SelectionData`][crate::SelectionData]
///
/// # Returns
///
/// [`true`] if `selection_data` had target type `GTK_TREE_MODEL_ROW` and
///  is otherwise valid
///
/// ## `tree_model`
/// a [`TreeModel`][crate::TreeModel]
///
/// ## `path`
/// row in `tree_model`
#[doc(alias = "gtk_tree_get_row_drag_data")]
pub fn tree_get_row_drag_data(
    selection_data: &SelectionData,
) -> Option<(Option<TreeModel>, Option<TreePath>)> {
    assert_initialized_main_thread!();
    unsafe {
        let mut tree_model = ptr::null_mut();
        let mut path = ptr::null_mut();
        let ret = from_glib(ffi::gtk_tree_get_row_drag_data(
            mut_override(selection_data.to_glib_none().0),
            &mut tree_model,
            &mut path,
        ));
        if ret {
            Some((from_glib_none(tree_model), from_glib_full(path)))
        } else {
            None
        }
    }
}

/// Sets selection data of target type `GTK_TREE_MODEL_ROW`. Normally used
/// in a drag_data_get handler.
/// ## `selection_data`
/// some [`SelectionData`][crate::SelectionData]
/// ## `tree_model`
/// a [`TreeModel`][crate::TreeModel]
/// ## `path`
/// a row in `tree_model`
///
/// # Returns
///
/// [`true`] if the [`SelectionData`][crate::SelectionData] had the proper target type to allow us to set a tree row
#[doc(alias = "gtk_tree_set_row_drag_data")]
pub fn tree_set_row_drag_data<P: IsA<TreeModel>>(
    selection_data: &SelectionData,
    tree_model: &P,
    path: &mut TreePath,
) -> bool {
    skip_assert_initialized!();
    unsafe {
        from_glib(ffi::gtk_tree_set_row_drag_data(
            mut_override(selection_data.to_glib_none().0),
            tree_model.as_ref().to_glib_none().0,
            path.to_glib_none_mut().0,
        ))
    }
}

#[doc(alias = "gtk_true")]
#[doc(alias = "true")]
pub fn true_() -> bool {
    assert_initialized_main_thread!();
    unsafe { from_glib(ffi::gtk_true()) }
}