File: Window.chs

package info (click to toggle)
haskell-gtk 0.11.0-5
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 2,920 kB
  • ctags: 82
  • sloc: haskell: 1,929; ansic: 714; sh: 5; makefile: 3
file content (2271 lines) | stat: -rw-r--r-- 82,918 bytes parent folder | download
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
{-# LANGUAGE CPP #-}
-- -*-haskell-*-
--  GIMP Toolkit (GTK) Window
--
--  Author : Manuel M. T. Chakravarty, Axel Simon, Andy Stewart
--
--  Created: 27 April 2001
--
--  Copyright (C) 2001-2005 Manuel M. T. Chakravarty, Axel Simon
--  Copyright (C) 2009 Andy Stewart
--
--  This library is free software; you can redistribute it and/or
--  modify it under the terms of the GNU Lesser General Public
--  License as published by the Free Software Foundation; either
--  version 2.1 of the License, or (at your option) any later version.
--
--  This library is distributed in the hope that it will be useful,
--  but WITHOUT ANY WARRANTY; without even the implied warranty of
--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
--  Lesser General Public License for more details.
--
-- |
-- Maintainer  : gtk2hs-users@lists.sourceforge.net
-- Stability   : provisional
-- Portability : portable (depends on GHC)
--
-- Toplevel which can contain other widgets
--
module Graphics.UI.Gtk.Windows.Window (

-- * Class Hierarchy
-- |
-- @
-- |  'GObject'
-- |   +----'Object'
-- |         +----'Widget'
-- |               +----'Container'
-- |                     +----'Bin'
-- |                           +----Window
-- |                                 +----'Dialog'
-- |                                 +----'Plug'
-- @

-- * Types
  Window,
  WindowClass,
  castToWindow, gTypeWindow,
  toWindow,
  WindowType(..),
  WindowEdge(..),
  WindowTypeHint(..),
  Gravity(..),

-- * Constructors
  windowNew,
  windowNewPopup,

-- * Methods
  windowActivateFocus,
  windowActivateDefault,
  windowSetDefaultSize,
  windowGetDefaultSize,
  windowSetPosition,
  WindowPosition(..),
#if GTK_CHECK_VERSION(2,4,0)
  windowIsActive,
  windowHasToplevelFocus,
#endif
  windowListToplevels,
  windowSetDefault,
#if GTK_CHECK_VERSION(2,14,0)
  windowGetDefaultWidget,
#endif
  windowAddMnemonic,
  windowRemoveMnemonic,
  windowMnemonicActivate,
  windowActivateKey,
  windowPropagateKeyEvent,
  windowPresent,
  windowDeiconify,
  windowIconify,
  windowMaximize,
  windowUnmaximize,
#if GTK_CHECK_VERSION(2,2,0)
  windowFullscreen,
  windowUnfullscreen,
#endif
#if GTK_CHECK_VERSION(2,4,0)
  windowSetKeepAbove,
  windowSetKeepBelow,
#endif
#if GTK_CHECK_VERSION(2,12,0)
  windowSetStartupId,
#endif
  windowGetFrame,
  windowSetFrameDimensions,
  windowGetFrameDimensions,
  windowStick,
  windowUnstick,
  windowAddAccelGroup,
  windowRemoveAccelGroup,
  windowSetDefaultIconList,
  windowGetDefaultIconList,
#if GTK_CHECK_VERSION(2,4,0)
  windowSetDefaultIcon,
#endif
#if GTK_CHECK_VERSION(2,2,0)
  windowSetDefaultIconFromFile,
  windowSetDefaultIconName,
#if GTK_CHECK_VERSION(2,16,0)
  windowGetDefaultIconName,
#endif
#endif
  windowSetGravity,
  windowGetGravity,
#if GTK_CHECK_VERSION(2,2,0)
  windowSetScreen,
  windowGetScreen,
#endif
  windowBeginResizeDrag,
  windowBeginMoveDrag,
  windowSetTypeHint,
  windowGetTypeHint,
  windowGetIcon,
  windowGetPosition,
  windowGetSize,
  windowMove,
  windowParseGeometry,
  windowReshowWithInitialSize,
  windowResize,
#if GTK_CHECK_VERSION(2,2,0)
  windowSetIconFromFile,
  windowSetAutoStartupNotification,
#endif
#if GTK_CHECK_VERSION(2,8,0)
  windowPresentWithTime,
#endif
  windowSetGeometryHints,
#if GTK_CHECK_VERSION(2,10,0)
  windowGetGroup,
#endif

-- * Attributes
  windowTitle,
  windowType,
  windowAllowShrink,
  windowAllowGrow,
  windowResizable,
  windowModal,
#if GTK_CHECK_VERSION(2,12,0)
  windowOpacity,
#endif
  windowRole,
#if GTK_CHECK_VERSION(2,12,0)
  windowStartupId,
#endif
  windowWindowPosition,
  windowDefaultWidth,
  windowDefaultHeight,
  windowDeletable,
  windowDestroyWithParent,
  windowIcon,
  windowIconName,
#if GTK_CHECK_VERSION(2,2,0)
  windowScreen,
#endif
  windowTypeHint,
#if GTK_CHECK_VERSION(2,2,0)
  windowSkipTaskbarHint,
  windowSkipPagerHint,
#endif
#if GTK_CHECK_VERSION(2,8,0)
  windowUrgencyHint,
#endif
#if GTK_CHECK_VERSION(2,4,0)
  windowAcceptFocus,
#endif
#if GTK_CHECK_VERSION(2,6,0)
  windowFocusOnMap,
#endif
#if GTK_CHECK_VERSION(2,4,0)
  windowDecorated,
  windowGravity,
#endif
  windowToplevelFocus,
  windowTransientFor,
  windowFocus,
  windowHasFrame,
  windowIconList,
  windowMnemonicModifier,

-- * Signals
  frameEvent,
  keysChanged,
  setFocus,

-- * Deprecated
#ifndef DISABLE_DEPRECATED
  windowSetTitle,
  windowGetTitle,
  windowSetResizable,
  windowGetResizable,
  windowSetModal,
  windowGetModal,
  windowSetPolicy,
  windowSetTransientFor,
  windowGetTransientFor,
  windowSetDestroyWithParent,
  windowGetDestroyWithParent,
  windowGetFocus,
  windowSetFocus,
  windowSetMnemonicModifier,
  windowGetMnemonicModifier,
#if GTK_CHECK_VERSION(2,2,0)
  windowSetSkipTaskbarHint,
  windowGetSkipTaskbarHint,
  windowSetSkipPagerHint,
  windowGetSkipPagerHint,
#if GTK_CHECK_VERSION(2,4,0)
  windowSetAcceptFocus,
  windowGetAcceptFocus,
#if GTK_CHECK_VERSION(2,6,0)
  windowSetFocusOnMap,
  windowGetFocusOnMap,
#endif
#endif
#endif
  windowSetDecorated,
  windowGetDecorated,
#if GTK_CHECK_VERSION(2,10,0)
  windowSetDeletable,
  windowGetDeletable,
#endif
  windowSetHasFrame,
  windowGetHasFrame,
  windowSetRole,
  windowGetRole,
  windowSetIcon,
  windowSetIconList,
  windowGetIconList,
#if GTK_CHECK_VERSION(2,6,0)
  windowSetIconName,
  windowGetIconName,
#endif
#if GTK_CHECK_VERSION(2,8,0)
  windowSetUrgencyHint,
  windowGetUrgencyHint,
#if GTK_CHECK_VERSION(2,12,0)
  windowSetOpacity,
  windowGetOpacity,
#endif
#endif
  onSetFocus,
  afterSetFocus
#endif
  ) where

import Control.Monad	(liftM)

import System.Glib.FFI
import System.Glib.UTFString
import System.Glib.Flags
import System.Glib.GError
import System.Glib.Attributes
import System.Glib.Properties
import System.Glib.GList                (fromGList, withGList)
import System.Glib.GObject		(makeNewGObject)
import Graphics.UI.Gtk.Abstract.Object	(makeNewObject)
import Graphics.UI.Gtk.General.Enums	(WindowType(..), WindowPosition(..))
import Graphics.UI.Gtk.General.Structs  (windowGetFrame)
{#import Graphics.UI.Gtk.Types#}
{#import Graphics.UI.Gtk.Signals#}
{#import Graphics.UI.Gtk.Gdk.Enums#}    (Modifier(..))
{#import Graphics.UI.Gtk.Gdk.Keys#}     (KeyVal)
import Graphics.UI.Gtk.Gdk.EventM	(EventM, EAny, EKey, MouseButton, TimeStamp)
import Control.Monad.Reader             ( runReaderT, ask )
import Control.Monad.Trans              ( liftIO )
import Graphics.UI.Gtk.Gdk.Enums	(WindowEdge(..), WindowTypeHint(..),
					Gravity(..))

{# context lib="gtk" prefix="gtk" #}

--------------------
-- Constructors

-- | Create a new top level window.
--
windowNew :: IO Window
windowNew =
  makeNewObject mkWindow $
  liftM (castPtr :: Ptr Widget -> Ptr Window) $
  {# call window_new #}
    ((fromIntegral . fromEnum) WindowToplevel)

-- | Create a popup window.
--
windowNewPopup :: IO Window
windowNewPopup =
  makeNewObject mkWindow $
  liftM (castPtr :: Ptr Widget -> Ptr Window) $
  {# call window_new #}
    ((fromIntegral . fromEnum) WindowPopup)

--------------------
-- Methods

-- | Sets the title of the 'Window'. The title of a window will be displayed
-- in its title bar; on the X Window System, the title bar is rendered by the
-- window manager, so exactly how the title appears to users may vary according
-- to a user's exact configuration. The title should help a user distinguish
-- this window from other windows they may have open. A good title might
-- include the application name and current document filename, for example.
--
windowSetTitle :: WindowClass self => self -> String -> IO ()
windowSetTitle self title =
  withUTFString title $ \titlePtr ->
  {# call gtk_window_set_title #}
    (toWindow self)
    titlePtr

-- | Retrieves the title of the window. See 'windowSetTitle'.
--
windowGetTitle :: WindowClass self => self -> IO String
windowGetTitle self =
  {# call gtk_window_get_title #}
    (toWindow self)
  >>= \strPtr -> if strPtr == nullPtr
                   then return ""
                   else peekUTFString strPtr

-- | Sets whether the user can resize a window. Windows are user resizable by
-- default.
--
windowSetResizable :: WindowClass self => self -> Bool -> IO ()
windowSetResizable self resizable =
  {# call window_set_resizable #}
    (toWindow self)
    (fromBool resizable)

-- | Gets the value set by 'windowSetResizable'.
--
windowGetResizable :: WindowClass self => self
 -> IO Bool -- ^ returns @True@ if the user can resize the window
windowGetResizable self =
  liftM toBool $
  {# call unsafe window_get_resizable #}
    (toWindow self)

-- | Activates the current focused widget within the window.
--
windowActivateFocus :: WindowClass self => self
 -> IO Bool -- ^ returns @True@ if a widget got activated.
windowActivateFocus self =
  liftM toBool $
  {# call window_activate_focus #}
    (toWindow self)

-- | Activates the default widget for the window, unless the current focused
-- widget has been configured to receive the default action (see
-- 'ReceivesDefault' in 'WidgetFlags'), in which case the focused widget is
-- activated.
--
windowActivateDefault :: WindowClass self => self
 -> IO Bool -- ^ returns @True@ if a widget got activated.
windowActivateDefault self =
  liftM toBool $
  {# call window_activate_default #}
    (toWindow self)

#ifndef DISABLE_DEPRECATED
{-# DEPRECATED windowSetPolicy "Use windowSetResizable instead." #-}
-- | Sets the window resizing policy.
--
-- * Warning: this function is deprecated and should not be used in
-- newly-written code. Use 'windowSetResizable' instead.
--
windowSetPolicy :: WindowClass self => self -> Bool -> Bool -> Bool -> IO ()
windowSetPolicy self allowShrink allowGrow autoShrink =
  {# call window_set_policy #}
    (toWindow self)
    (fromBool allowShrink)
    (fromBool allowGrow)
    (fromBool autoShrink)
#endif

-- | Sets a window modal or non-modal. Modal windows prevent interaction with
-- other windows in the same application. To keep modal dialogs on top of main
-- application windows, use 'windowSetTransientFor' to make the dialog
-- transient for the parent; most window managers will then disallow lowering
-- the dialog below the parent.
--
windowSetModal :: WindowClass self => self
 -> Bool  -- ^ @modal@ - whether the window is modal
 -> IO ()
windowSetModal self modal =
  {# call window_set_modal #}
    (toWindow self)
    (fromBool modal)

-- | Returns whether the window is modal. See 'windowSetModal'.
--
windowGetModal :: WindowClass self => self
 -> IO Bool -- ^ returns @True@ if the window is set to be modal and
            -- establishes a grab when shown
windowGetModal self =
  liftM toBool $
  {# call gtk_window_get_modal #}
    (toWindow self)

-- | Sets the default size of a window. If the window's \"natural\" size (its
-- size request) is larger than the default, the default will be ignored. More
-- generally, if the default size does not obey the geometry hints for the
-- window ('windowSetGeometryHints' can be used to set these explicitly), the
-- default size will be clamped to the nearest permitted size.
--
-- Unlike 'widgetSetSizeRequest', which sets a size request for a widget and
-- thus would keep users from shrinking the window, this function only sets the
-- initial size, just as if the user had resized the window themselves. Users
-- can still shrink the window again as they normally would. Setting a default
-- size of -1 means to use the \"natural\" default size (the size request of
-- the window).
--
-- For more control over a window's initial size and how resizing works,
-- investigate 'windowSetGeometryHints'.
--
-- For some uses, 'windowResize' is a more appropriate function.
-- 'windowResize' changes the current size of the window, rather than the size
-- to be used on initial display. 'windowResize' always affects the window
-- itself, not the geometry widget.
--
-- The default size of a window only affects the first time a window is
-- shown; if a window is hidden and re-shown, it will remember the size it had
-- prior to hiding, rather than using the default size.
--
-- Windows can't actually be 0x0 in size, they must be at least 1x1, but
-- passing 0 for @width@ and @height@ is OK, resulting in a 1x1 default size.
--
windowSetDefaultSize :: WindowClass self => self
 -> Int   -- ^ @height@ - height in pixels, or -1 to unset the default height
 -> Int   -- ^ @width@ - width in pixels, or -1 to unset the default width
 -> IO ()
windowSetDefaultSize self height width =
  {# call window_set_default_size #}
    (toWindow self)
    (fromIntegral height)
    (fromIntegral width)

-- | Adds a mnemonic to this window.
--
windowAddMnemonic :: (WindowClass self, WidgetClass widget) => self
 -> KeyVal  -- ^ @keyval@ - the mnemonic
 -> widget  -- ^ @target@ - the widget that gets activated by the mnemonic 
 -> IO ()
windowAddMnemonic self keyval target =
  {# call window_add_mnemonic #}
    (toWindow self)
    (fromIntegral keyval)
    (toWidget target)

-- | Removes a mnemonic from this window.
--
windowRemoveMnemonic :: (WindowClass self, WidgetClass widget) => self
 -> KeyVal -- ^ @keyval@ - the mnemonic                                   
 -> widget  -- ^ @target@ - the widget that gets activated by the mnemonic 
 -> IO ()
windowRemoveMnemonic self keyval target =
  {# call window_remove_mnemonic #} 
    (toWindow self)
    (fromIntegral keyval)
    (toWidget target)

-- | Activates the targets associated with the mnemonic.
windowMnemonicActivate :: WindowClass self => self
 -> KeyVal  -- ^ @keyval@ - the mnemonic                    
 -> [Modifier]  -- ^ @modifier@ - the modifiers                   
 -> IO Bool  -- ^ return @True@ if the activation is done. 
windowMnemonicActivate self keyval modifier = liftM toBool $  
  {# call window_mnemonic_activate #}
    (toWindow self)
    (fromIntegral keyval)
    (fromIntegral (fromFlags modifier))

-- | Sets the mnemonic modifier for this window.
windowSetMnemonicModifier :: WindowClass self => self
 -> [Modifier]  -- ^ @modifier@ - the modifier mask used to activate mnemonics on this window. 
 -> IO ()
windowSetMnemonicModifier self modifier =
  {# call window_set_mnemonic_modifier #}
    (toWindow self)
    (fromIntegral (fromFlags modifier))

-- | Returns the mnemonic modifier for this window. See 'windowSetMnemonicModifier'.
windowGetMnemonicModifier :: WindowClass self => self
 -> IO [Modifier]  -- ^ return the modifier mask used to activate mnemonics on this window. 
windowGetMnemonicModifier self = liftM (toFlags . fromIntegral) $
  {# call window_get_mnemonic_modifier #} 
    (toWindow self)

-- | Activates mnemonics and accelerators for this 'Window'. 
-- This is normally called by the default 'keyPressEvent' handler for toplevel windows, 
-- however in some cases it may be useful to call this directly when overriding the standard key handling for a toplevel window.
-- 
windowActivateKey :: WindowClass self => self -> EventM EKey Bool
  -- ^ return @True@ if a mnemonic or accelerator was found and activated. 
windowActivateKey self = do
  ptr <- ask
  liftIO $ liftM toBool $
    {# call window_activate_key #}
      (toWindow self)
      (castPtr ptr)

-- | Propagate a key press or release event to the focus widget and up the focus container chain until a widget handles event. 
-- This is normally called by the default 'keyPressEvent' and 'keyReleaseEvent' handlers for toplevel windows, 
-- however in some cases it may be useful to call this directly when overriding the standard key handling for a toplevel window.
--
windowPropagateKeyEvent :: WindowClass self => self
  -> EventM EKey Bool
  -- ^ return @True@ if a widget in the focus chain handled the event. 
windowPropagateKeyEvent self = do
  ptr <- ask
  liftIO $ liftM toBool $
    {# call window_propagate_key_event #}
      (toWindow self)
      (castPtr ptr)

-- | Gets the default size of the window. A value of -1 for the width or
-- height indicates that a default size has not been explicitly set for that
-- dimension, so the \"natural\" size of the window will be used.
--
windowGetDefaultSize :: WindowClass self => self
 -> IO (Int, Int) -- ^ @(width, height)@ - the default width and height
windowGetDefaultSize self =
  alloca $ \widthPtr ->
  alloca $ \heightPtr -> do
  {# call gtk_window_get_default_size #}
    (toWindow self)
    widthPtr
    heightPtr
  width <- peek widthPtr
  height <- peek heightPtr
  return (fromIntegral width, fromIntegral height)

-- | Sets a position constraint for this window. If the old or new constraint
-- is 'WinPosCenterAlways', this will also cause the window to be repositioned
-- to satisfy the new constraint.
--
windowSetPosition :: WindowClass self => self -> WindowPosition -> IO ()
windowSetPosition self position =
  {# call window_set_position #}
    (toWindow self)
    ((fromIntegral . fromEnum) position)

-- | Dialog windows should be set transient for the main application window
-- they were spawned from. This allows window managers to e.g. keep the dialog
-- on top of the main window, or center the dialog over the main window.
-- 'dialogNewWithButtons' and other convenience functions in Gtk+ will
-- sometimes call 'windowSetTransientFor' on your behalf.
--
-- On Windows, this function will and put the child window on top of the
-- parent, much as the window manager would have done on X.
--
-- Note that if you want to show a window @self@ on top of a full-screen window @parent@, you need to
-- turn the @self@ window into a dialog (using 'windowSetTypeHint' with 'WindowTypeHintDialog'). 
-- Otherwise the @parent@ window will always cover the @self@ window.
--
windowSetTransientFor :: (WindowClass self, WindowClass parent) => self
 -> parent -- ^ @parent@ - parent window
 -> IO ()
windowSetTransientFor self parent =
  {# call window_set_transient_for #}
    (toWindow self)
    (toWindow parent)

-- | Fetches the transient parent for this window. See
-- 'windowSetTransientFor'.
--
windowGetTransientFor :: WindowClass self => self
 -> IO (Maybe Window) -- ^ returns the transient parent for this window, or
                      -- @Nothing@ if no transient parent has been set.
windowGetTransientFor self =
  maybeNull (makeNewObject mkWindow) $
  {# call gtk_window_get_transient_for #}
    (toWindow self)

-- | If this setting is @True@, then destroying the transient parent of the
-- window will also destroy the window itself. This is useful for dialogs that
-- shouldn't persist beyond the lifetime of the main window they\'re associated
-- with, for example.
--
windowSetDestroyWithParent :: WindowClass self => self -> Bool -> IO ()
windowSetDestroyWithParent self setting =
  {# call window_set_destroy_with_parent #}
    (toWindow self)
    (fromBool setting)

-- | Returns whether the window will be destroyed with its transient parent.
-- See 'windowSetDestroyWithParent'.
--
windowGetDestroyWithParent :: WindowClass self => self
 -> IO Bool -- ^ returns @True@ if the window will be destroyed with its
            -- transient parent.
windowGetDestroyWithParent self =
  liftM toBool $
  {# call gtk_window_get_destroy_with_parent #}
    (toWindow self)

#if GTK_CHECK_VERSION(2,4,0)
-- | Returns whether the window is part of the current active toplevel. (That
-- is, the toplevel window receiving keystrokes.) The return value is @True@ if
-- the window is active toplevel itself, but also if it is, say, a 'Plug'
-- embedded in the active toplevel. You might use this function if you wanted
-- to draw a widget differently in an active window from a widget in an
-- inactive window. See 'windowHasToplevelFocus'
--
-- * Available since Gtk+ version 2.4
--
windowIsActive :: WindowClass self => self
 -> IO Bool -- ^ returns @True@ if the window part of the current active
            -- window.
windowIsActive self =
  liftM toBool $
  {# call gtk_window_is_active #}
    (toWindow self)

-- | Returns whether the input focus is within this 'Window'. For real
-- toplevel windows, this is identical to 'windowIsActive', but for embedded
-- windows, like 'Plug', the results will differ.
--
-- * Available since Gtk+ version 2.4
--
windowHasToplevelFocus :: WindowClass self => self
 -> IO Bool -- ^ returns @True@ if the the input focus is within this 'Window'
windowHasToplevelFocus self =
  liftM toBool $
  {# call gtk_window_has_toplevel_focus #}
    (toWindow self)
#endif

-- | Returns a list of all existing toplevel windows.
--
windowListToplevels :: IO [Window]
windowListToplevels = do
  glistPtr <- {#call unsafe gtk_window_list_toplevels#}
  winPtrs <- fromGList glistPtr
  mapM (\ptr -> makeNewGObject mkWindow (return ptr)) winPtrs

-- | Retrieves the current focused widget within the window.
-- | Note that this is the widget that would have the focus if the toplevel
-- | window focused; if the toplevel window is not focused then
-- | 'widgetHasFocus' will not be True for the widget.
--
windowGetFocus :: WindowClass self => self -> IO (Maybe Widget)
windowGetFocus self =
  maybeNull (makeNewObject mkWidget) $
  {# call unsafe gtk_window_get_focus #}
    (toWindow self)

-- | If focus is not the current focus widget, and is focusable, sets it as
-- | the focus widget for the window. If focus is Nothing, unsets the focus
-- | widget for this window. To set the focus to a particular widget in the
-- | toplevel, it is usually more convenient to use 'widgetGrabFocus' instead
-- | of this function.
--
windowSetFocus :: (WindowClass self, WidgetClass widget) => self
  -> Maybe widget
  -> IO ()
windowSetFocus self focus =
  {# call unsafe gtk_window_set_focus #}
    (toWindow self)
    (maybe (Widget nullForeignPtr) toWidget focus)

#if GTK_CHECK_VERSION(2,14,0)
-- | Returns the default widget for window. See 'windowSetDefault' for more details.
-- 
-- * Available since Gtk+ version 2.14
--
windowGetDefaultWidget :: WindowClass self => self
 -> IO (Maybe Widget)
windowGetDefaultWidget self = 
  maybeNull (makeNewObject mkWidget) $
  {# call window_get_default_widget #}
    (toWindow self)
#endif

-- | The default widget is the widget that's activated when the user presses
--   Enter in a dialog (for example). This function sets or unsets the default
--   widget for a Window about. When setting (rather than unsetting) the
--   default widget it's generally easier to call widgetGrabDefault on the
--   widget. Before making a widget the default widget, you must set the
--   'widgetCanDefault' flag on the widget.
--
windowSetDefault :: (WindowClass self, WidgetClass widget) => self
  -> Maybe widget
  -> IO ()
windowSetDefault self defaultWidget =
  {# call unsafe gtk_window_set_focus #}
    (toWindow self)
    (maybe (Widget nullForeignPtr) toWidget defaultWidget)

-- | Presents a window to the user. This may mean raising the window in the
-- stacking order, deiconifying it, moving it to the current desktop, and\/or
-- giving it the keyboard focus, possibly dependent on the user's platform,
-- window manager, and preferences.
--
-- If @window@ is hidden, this function calls 'widgetShow' as well.
--
-- This function should be used when the user tries to open a window that's
-- already open. Say for example the preferences dialog is currently open, and
-- the user chooses Preferences from the menu a second time; use
-- 'windowPresent' to move the already-open dialog where the user can see it.
--
-- If you are calling this function in response to a user interaction, it is
-- preferable to use 'windowPresentWithTime'.
--
windowPresent :: WindowClass self => self -> IO ()
windowPresent self =
  {# call gtk_window_present #}
    (toWindow self)

-- | Asks to deiconify (i.e. unminimize) the specified @window@. Note that you
-- shouldn't assume the window is definitely deiconified afterward, because
-- other entities (e.g. the user or window manager) could iconify it again
-- before your code which assumes deiconification gets to run.
--
-- You can track iconification via the 'windowStateEvent' signal on
-- 'Widget'.
--
windowDeiconify :: WindowClass self => self -> IO ()
windowDeiconify self =
  {# call window_deiconify #}
    (toWindow self)

-- | Asks to iconify (i.e. minimize) the specified @window@. Note that you
-- shouldn't assume the window is definitely iconified afterward, because other
-- entities (e.g. the user or window manager) could deiconify it again, or
-- there may not be a window manager in which case iconification isn't
-- possible, etc. But normally the window will end up iconified. Just don't
-- write code that crashes if not.
--
-- It's permitted to call this function before showing a window, in which
-- case the window will be iconified before it ever appears onscreen.
--
-- You can track iconification via the 'windowStateEvent' signal on
-- 'Widget'.
--
windowIconify :: WindowClass self => self -> IO ()
windowIconify self =
  {# call window_iconify #}
    (toWindow self)

-- | Asks to maximize the window, so that it becomes full-screen. Note that you
-- shouldn't assume the window is definitely maximized afterward, because other
-- entities (e.g. the user or window manager) could unmaximize it again, and
-- not all window managers support maximization. But normally the window will
-- end up maximized. Just don't write code that crashes if not.
--
-- It's permitted to call this function before showing a window, in which
-- case the window will be maximized when it appears onscreen initially.
--
-- You can track maximization via the 'windowStateEvent' signal on
-- 'Widget'.
--
windowMaximize :: WindowClass self => self -> IO ()
windowMaximize self =
  {# call window_maximize #}
    (toWindow self)

-- | Asks to unmaximize the window. Note that you shouldn't assume the window is
-- definitely unmaximized afterward, because other entities (e.g. the user or
-- window manager) could maximize it again, and not all window managers honor
-- requests to unmaximize. But normally the window will end up unmaximized.
-- Just don't write code that crashes if not.
--
-- You can track maximization via the 'windowStateEvent' signal on
-- 'Widget'.
--
windowUnmaximize :: WindowClass self => self -> IO ()
windowUnmaximize self =
  {# call window_unmaximize #}
    (toWindow self)

#if GTK_CHECK_VERSION(2,2,0)
-- | Asks to place @window@ in the fullscreen state. Note that you shouldn't
-- assume the window is definitely full screen afterward, because other
-- entities (e.g. the user or window manager) could unfullscreen it again, and
-- not all window managers honor requests to fullscreen windows. But normally
-- the window will end up fullscreen. Just don't write code that crashes if
-- not.
--
-- You can track the fullscreen state via the 'windowStateEvent' signal
-- on 'Widget'.
--
-- * Available since Gtk+ version 2.2
--
windowFullscreen :: WindowClass self => self -> IO ()
windowFullscreen self =
  {# call gtk_window_fullscreen #}
    (toWindow self)

-- | Asks to toggle off the fullscreen state for @window@. Note that you
-- shouldn't assume the window is definitely not full screen afterward, because
-- other entities (e.g. the user or window manager) could fullscreen it again,
-- and not all window managers honor requests to unfullscreen windows. But
-- normally the window will end up restored to its normal state. Just don't
-- write code that crashes if not.
--
-- You can track the fullscreen state via the 'windowStateEvent' signal
-- on 'Widget'.
--
-- * Available since Gtk+ version 2.2
--
windowUnfullscreen :: WindowClass self => self -> IO ()
windowUnfullscreen self =
  {# call gtk_window_unfullscreen #}
    (toWindow self)

#if GTK_CHECK_VERSION(2,4,0)
-- | Asks to keep @window@ above, so that it stays on top. Note that you
-- shouldn't assume the window is definitely above afterward, because other
-- entities (e.g. the user or window manager) could not keep it above, and not
-- all window managers support keeping windows above. But normally the window
-- will end kept above. Just don't write code that crashes if not.
--
-- It's permitted to call this function before showing a window, in which
-- case the window will be kept above when it appears onscreen initially.
--
-- You can track the above state via the 'windowStateEvent' signal on
-- 'Widget'.
--
-- Note that, according to the Extended Window Manager Hints specification,
-- the above state is mainly meant for user preferences and should not be used
-- by applications e.g. for drawing attention to their dialogs.
--
-- * Available since Gtk+ version 2.4
--
windowSetKeepAbove :: WindowClass self => self
 -> Bool  -- ^ @setting@ - whether to keep @window@ above other windows
 -> IO ()
windowSetKeepAbove self setting =
  {# call gtk_window_set_keep_above #}
    (toWindow self)
    (fromBool setting)

-- | Asks to keep @window@ below, so that it stays in bottom. Note that you
-- shouldn't assume the window is definitely below afterward, because other
-- entities (e.g. the user or window manager) could not keep it below, and not
-- all window managers support putting windows below. But normally the window
-- will be kept below. Just don't write code that crashes if not.
--
-- It's permitted to call this function before showing a window, in which
-- case the window will be kept below when it appears onscreen initially.
--
-- You can track the below state via the 'windowStateEvent' signal on
-- 'Widget'.
--
-- Note that, according to the Extended Window Manager Hints specification,
-- the above state is mainly meant for user preferences and should not be used
-- by applications e.g. for drawing attention to their dialogs.
--
-- * Available since Gtk+ version 2.4
--
windowSetKeepBelow :: WindowClass self => self
 -> Bool  -- ^ @setting@ - whether to keep @window@ below other windows
 -> IO ()
windowSetKeepBelow self setting =
  {# call gtk_window_set_keep_below #}
    (toWindow self)
    (fromBool setting)
#endif

-- | Windows may set a hint asking the desktop environment not to display the
-- window in the task bar. This function sets this hint.
--
-- * Available since Gtk+ version 2.2
--
windowSetSkipTaskbarHint :: WindowClass self => self
 -> Bool  -- ^ @setting@ - @True@ to keep this window from appearing in the
          -- task bar
 -> IO ()
windowSetSkipTaskbarHint self setting =
  {# call gtk_window_set_skip_taskbar_hint #}
    (toWindow self)
    (fromBool setting)

-- | Gets the value set by 'windowSetSkipTaskbarHint'
--
-- * Available since Gtk+ version 2.2
--
windowGetSkipTaskbarHint :: WindowClass self => self
 -> IO Bool -- ^ returns @True@ if window shouldn't be in taskbar
windowGetSkipTaskbarHint self =
  liftM toBool $
  {# call gtk_window_get_skip_taskbar_hint #}
    (toWindow self)

-- | Windows may set a hint asking the desktop environment not to display the
-- window in the pager. This function sets this hint. (A \"pager\" is any
-- desktop navigation tool such as a workspace switcher that displays a
-- thumbnail representation of the windows on the screen.)
--
-- * Available since Gtk+ version 2.2
--
windowSetSkipPagerHint :: WindowClass self => self
 -> Bool  -- ^ @setting@ - @True@ to keep this window from appearing in the
          -- pager
 -> IO ()
windowSetSkipPagerHint self setting =
  {# call gtk_window_set_skip_pager_hint #}
    (toWindow self)
    (fromBool setting)

-- | Gets the value set by 'windowSetSkipPagerHint'.
--
-- * Available since Gtk+ version 2.2
--
windowGetSkipPagerHint :: WindowClass self => self
 -> IO Bool -- ^ returns @True@ if window shouldn't be in pager
windowGetSkipPagerHint self =
  liftM toBool $
  {# call gtk_window_get_skip_pager_hint #}
    (toWindow self)
#endif

#if GTK_CHECK_VERSION(2,4,0)
-- | Windows may set a hint asking the desktop environment not to receive the
-- input focus. This function sets this hint.
--
-- * Available since Gtk+ version 2.4
--
windowSetAcceptFocus :: WindowClass self => self
 -> Bool  -- ^ @setting@ - @True@ to let this window receive input focus
 -> IO ()
windowSetAcceptFocus self setting =
  {# call gtk_window_set_accept_focus #}
    (toWindow self)
    (fromBool setting)

-- | Gets the value set by 'windowSetAcceptFocus'.
--
-- * Available since Gtk+ version 2.4
--
windowGetAcceptFocus :: WindowClass self => self
 -> IO Bool -- ^ returns @True@ if window should receive the input focus
windowGetAcceptFocus self =
  liftM toBool $
  {# call gtk_window_get_accept_focus #}
    (toWindow self)
#endif

#if GTK_CHECK_VERSION(2,6,0)
-- | Windows may set a hint asking the desktop environment not to receive the
-- input focus when the window is mapped. This function sets this hint.
--
-- * Available since Gtk+ version 2.6
--
windowSetFocusOnMap :: WindowClass self => self
 -> Bool  -- ^ @setting@ - @True@ to let this window receive input focus on
          -- map
 -> IO ()
windowSetFocusOnMap self setting =
  {# call gtk_window_set_focus_on_map #}
    (toWindow self)
    (fromBool setting)

-- | Gets the value set by 'windowSetFocusOnMap'.
--
-- * Available since Gtk+ version 2.6
--
windowGetFocusOnMap :: WindowClass self => self
 -> IO Bool -- ^ returns @True@ if window should receive the input focus when
            -- mapped.
windowGetFocusOnMap self =
  liftM toBool $
  {# call gtk_window_get_focus_on_map #}
    (toWindow self)
#endif

#if GTK_CHECK_VERSION(2,12,0)
-- | Startup notification identifiers are used by desktop environment to track application startup, 
-- to provide user feedback and other features. This function changes the corresponding property on the underlying GdkWindow. 
-- Normally, startup identifier is managed automatically and you should only use this function in special cases like transferring focus from other processes. You should use this function before calling 'windowPresent' or any equivalent function generating a window map event.
--
-- This function is only useful on X11, not with other GTK+ targets.
--
-- * Available since Gtk+ version 2.12
--
windowSetStartupId :: WindowClass self => self
 -> String
 -> IO ()
windowSetStartupId self startupId =
  withUTFString startupId $ \idPtr ->
  {# call window_set_startup_id #}
    (toWindow self)
    idPtr
#endif

-- | By default, windows are decorated with a title bar, resize controls, etc.
-- Some window managers allow Gtk+ to disable these decorations, creating a
-- borderless window. If you set the decorated property to @False@ using this
-- function, Gtk+ will do its best to convince the window manager not to
-- decorate the window. Depending on the system, this function may not have any
-- effect when called on a window that is already visible, so you should call
-- it before calling 'windowShow'.
--
-- On Windows, this function always works, since there's no window manager
-- policy involved.
--
windowSetDecorated :: WindowClass self => self -> Bool -> IO ()
windowSetDecorated self setting =
  {# call window_set_decorated #}
    (toWindow self)
    (fromBool setting)

-- | Returns whether the window has been set to have decorations such as a
-- title bar via 'windowSetDecorated'.
--
windowGetDecorated :: WindowClass self => self
 -> IO Bool -- ^ returns @True@ if the window has been set to have decorations
windowGetDecorated self =
  liftM toBool $
  {# call gtk_window_get_decorated #}
    (toWindow self)

#if GTK_CHECK_VERSION(2,10,0)
-- | By default, windows have a close button in the window frame. 
-- Some window managers allow GTK+ to disable this button. 
-- If you set the deletable property to  @False@ using this function, GTK+ will do its best to convince the window manager not to show a close button. 
-- Depending on the system, this function may not have any effect when called on a window that is already visible, 
-- so you should call it before calling 'windowShow'.
--
-- On Windows, this function always works, since there's no window manager policy involved.
--
-- * Available since Gtk+ version 2.10
--
windowSetDeletable :: WindowClass self => self
 -> Bool  -- ^ @setting@ - @True@ to decorate the window as deletable 
 -> IO ()
windowSetDeletable self setting =
  {# call window_set_deletable #}
    (toWindow self)
    (fromBool setting)

-- | Returns whether the window has been set to have a close button via 'windowSetDeletable'.
--
-- * Available since Gtk+ version 2.10
--
windowGetDeletable :: WindowClass self => self
 -> IO Bool  -- ^ return @True@ if the window has been set to have a close button 
windowGetDeletable self = liftM toBool $  
  {# call window_get_deletable #}
    (toWindow self)
#endif
-- | (Note: this is a special-purpose function intended for the framebuffer
-- port; see 'windowSetHasFrame'. It will have no effect on the window border
-- drawn by the window manager, which is the normal case when using the X
-- Window system.)
--
-- For windows with frames (see 'windowSetHasFrame') this function can be
-- used to change the size of the frame border.
--
windowSetFrameDimensions :: WindowClass self => self
 -> Int   -- ^ @left@ - The width of the left border
 -> Int   -- ^ @top@ - The height of the top border
 -> Int   -- ^ @right@ - The width of the right border
 -> Int   -- ^ @bottom@ - The height of the bottom border
 -> IO ()
windowSetFrameDimensions self left top right bottom =
  {# call window_set_frame_dimensions #}
    (toWindow self)
    (fromIntegral left)
    (fromIntegral top)
    (fromIntegral right)
    (fromIntegral bottom)

-- |  Retrieves the dimensions of the frame window for this toplevel. See 
--    'windowSetHasFrame', 'windowSetFrameDimensions'.
--
-- (Note: this is a special-purpose function intended for the framebuffer port;
-- see 'windowSetHasFrame'. 
-- It will not return the size of the window border drawn by the window manager, 
-- which is the normal case when using a windowing system. 
-- See 'drawWindowGetFrameExtents' to get the standard window border extents.)
--
--
--
windowGetFrameDimensions :: WindowClass self => self
 -> IO (Int, Int, Int, Int)
 -- ^ returns @(left, top, right, bottom)@. @left@ is the
 -- width of the frame at the left, @top@ is the height of the frame at the top, @right@
 -- is the width of the frame at the right, @bottom@ is the height of the frame at the bottom.
windowGetFrameDimensions self = 
  alloca $ \lPtr -> alloca $ \tPtr -> alloca $ \rPtr -> alloca $ \bPtr -> do
    {# call window_get_frame_dimensions #} (toWindow self) lPtr tPtr rPtr bPtr
    lv <- peek lPtr
    tv <- peek tPtr
    rv <- peek rPtr
    bv <- peek bPtr
    return (fromIntegral lv, fromIntegral tv, fromIntegral rv, fromIntegral bv)

-- | If this function is called on a window with setting of @True@, before it is realized
-- or showed, it will have a "frame" window around its 'DrawWindow',
-- accessible using 'windowGetFrame'. Using the signal 'windowFrameEvent' you can
-- receive all events targeted at the frame.
--
-- (Note: this is a special-purpose function for the framebuffer port, that causes GTK+ to draw its own window border. 
-- For most applications, you want  'windowSetDecorated' instead, which tells the window manager whether to draw the window border.)
--
-- This function is used by the linux-fb port to implement managed windows, 
-- but it could conceivably be used by X-programs that want to do their own window
-- decorations.
--
windowSetHasFrame :: WindowClass self => self 
 -> Bool  -- ^ @setting@ - a boolean   
 -> IO ()
windowSetHasFrame self setting =
  {# call window_set_has_frame #}
    (toWindow self)
    (fromBool setting)

-- | Accessor for whether the window has a frame window exterior to window->window. Gets the value set by 'windowSetHasFrame'.
--
windowGetHasFrame :: WindowClass self => self
 -> IO Bool  -- ^ return @True@ if a frame has been added to the window via 'windowSetHasFrame'.
windowGetHasFrame self = liftM toBool $
  {# call window_get_has_frame #}
    (toWindow self)

-- | This function is only useful on X11, not with other Gtk+ targets.
--
-- In combination with the window title, the window role allows a window
-- manager to identify \"the same\" window when an application is restarted. So
-- for example you might set the \"toolbox\" role on your app's toolbox window,
-- so that when the user restarts their session, the window manager can put the
-- toolbox back in the same place.
--
-- If a window already has a unique title, you don't need to set the role,
-- since the WM can use the title to identify the window when restoring the
-- session.
--
windowSetRole :: WindowClass self => self
 -> String -- ^ @role@ - unique identifier for the window to be used when
           -- restoring a session
 -> IO ()
windowSetRole self role =
  withUTFString role $ \rolePtr ->
  {# call window_set_role #}
    (toWindow self)
    rolePtr

-- | Returns the role of the window. See 'windowSetRole' for further
-- explanation.
--
windowGetRole :: WindowClass self => self
 -> IO (Maybe String) -- ^ returns the role of the window if set, or
                      -- @Nothing@.
windowGetRole self =
  {# call gtk_window_get_role #}
    (toWindow self)
  >>= maybePeek peekUTFString

-- | Asks to stick @window@, which means that it will appear on all user
-- desktops. Note that you shouldn't assume the window is definitely stuck
-- afterward, because other entities (e.g. the user or window manager) could
-- unstick it again, and some window managers do not support sticking windows.
-- But normally the window will end up stuck. Just don't write code that
-- crashes if not.
--
-- It's permitted to call this function before showing a window.
--
-- You can track stickiness via the 'windowStateEvent' signal on
-- 'Widget'.
--
windowStick :: WindowClass self => self -> IO ()
windowStick self =
  {# call window_stick #}
    (toWindow self)

-- | Asks to unstick @window@, which means that it will appear on only one of
-- the user's desktops. Note that you shouldn't assume the window is definitely
-- unstuck afterward, because other entities (e.g. the user or window manager)
-- could stick it again. But normally the window will end up stuck. Just don't
-- write code that crashes if not.
--
-- You can track stickiness via the 'windowStateEvent' signal on
-- 'Widget'.
--
windowUnstick :: WindowClass self => self -> IO ()
windowUnstick self =
  {# call window_unstick #}
    (toWindow self)

-- | Associate @accelGroup@ with @window@, such that calling
-- 'accelGroupsActivate' on @window@ will activate accelerators in
-- @accelGroup@.
--
windowAddAccelGroup :: WindowClass self => self
 -> AccelGroup -- ^ @accelGroup@ - a 'AccelGroup'
 -> IO ()
windowAddAccelGroup self accelGroup =
  {# call gtk_window_add_accel_group #}
    (toWindow self)
    accelGroup

-- | Reverses the effects of 'windowAddAccelGroup'.
--
windowRemoveAccelGroup :: WindowClass self => self
 -> AccelGroup -- ^ @accelGroup@ - a 'AccelGroup'
 -> IO ()
windowRemoveAccelGroup self accelGroup =
  {# call gtk_window_remove_accel_group #}
    (toWindow self)
    accelGroup

-- | Sets up the icon representing a 'Window'. This icon is used when the
-- window is minimized (also known as iconified). Some window managers or
-- desktop environments may also place it in the window frame, or display it in
-- other contexts.
--
-- The icon should be provided in whatever size it was naturally drawn; that
-- is, don't scale the image before passing it to Gtk+. Scaling is postponed
-- until the last minute, when the desired final size is known, to allow best
-- quality.
--
-- If you have your icon hand-drawn in multiple sizes, use
-- 'windowSetIconList'. Then the best size will be used.
--
-- This function is equivalent to calling 'windowSetIconList' with a
-- 1-element list.
--
-- See also 'windowSetDefaultIconList' to set the icon for all windows in
-- your application in one go.
--
windowSetIcon :: WindowClass self => self
 -> Maybe Pixbuf -- ^ @icon@ - icon image
 -> IO ()
windowSetIcon self Nothing =
  {# call gtk_window_set_icon #}
    (toWindow self)
    (Pixbuf nullForeignPtr)
windowSetIcon self (Just icon) =
  {# call gtk_window_set_icon #}
    (toWindow self)
    icon

-- | Gets the value set by 'windowSetIcon' (or if you\'ve called
-- 'windowSetIconList', gets the first icon in the icon list).
--
windowGetIcon :: WindowClass self => self
 -> IO (Maybe Pixbuf) -- ^ returns icon for window, or @Nothing@ if none was set
windowGetIcon self =
  maybeNull (makeNewGObject mkPixbuf) $
  {# call gtk_window_get_icon #}
    (toWindow self)

-- | Sets up the icon representing a 'Window'. The icon is used when the window is minimized (also known as iconified). 
-- Some window managers or desktop environments may also place it in the window frame, or display it in other contexts.
--
-- 'windowSetIconList' allows you to pass in the same icon in several hand-drawn sizes. 
-- The list should contain the natural sizes your icon is available in; that is, don't scale the image before passing it to GTK+. 
-- Scaling is postponed until the last minute, when the desired final size is known, to allow best quality.
--
-- By passing several sizes, you may improve the final image quality of the icon, by reducing or eliminating automatic image scaling.
--
-- Recommended sizes to provide: 16x16, 32x32, 48x48 at minimum, and larger images (64x64, 128x128) if you have them.
--
-- See also 'windowSetDefaultIconList' to set the icon for all windows in your application in one go.
--
-- Note that transient windows (those who have been set transient for another window using 'windowSetTransientFor' will inherit their icon from their
-- transient parent. 
-- So there's no need to explicitly set the icon on transient windows.
--
windowSetIconList :: WindowClass self => self
 -> [Pixbuf]
 -> IO ()
windowSetIconList self list =
  withForeignPtrs (map unPixbuf list) $ \ptrList ->
  withGList ptrList $ \glist ->
  {# call window_set_icon_list #}
     (toWindow self)
     glist
    
-- | Retrieves the list of icons set by 'windowSetIconList'. 
--
windowGetIconList :: WindowClass self => self  
 -> IO [Pixbuf]
windowGetIconList self = do
  glist <- {# call window_get_icon_list #} (toWindow self)
  ptrList <- fromGList glist
  mapM (makeNewGObject mkPixbuf . return) ptrList

-- | Sets an icon list to be used as fallback for windows that haven't had 'windowSetIconList' called on them to set up a window-specific icon list. 
-- This function allows you to set up the icon for all windows in your app at once.
--
-- See 'windowSetIconList' for more details.
--
windowSetDefaultIconList :: [Pixbuf] -> IO ()
windowSetDefaultIconList list = 
  withForeignPtrs (map unPixbuf list) $ \ptrList ->
  withGList ptrList $ \glist ->
  {# call window_set_default_icon_list #} glist

-- | Gets the value set by 'windowSetDefaultIconList'. 
--
windowGetDefaultIconList :: IO [Pixbuf]
windowGetDefaultIconList = do
  glist <- {# call window_get_default_icon_list #}
  ptrList <- fromGList glist
  mapM (makeNewGObject mkPixbuf . return) ptrList

#if GTK_CHECK_VERSION(2,6,0)
-- | Sets the icon for the window from a named themed icon. See the docs for
-- 'IconTheme' for more details.
--
-- Note that this has nothing to do with the WM_ICON_NAME property which is
-- mentioned in the ICCCM.
--
-- * Available since Gtk+ version 2.6
--
windowSetIconName :: WindowClass self => self
 -> String -- ^ @name@ - the name of the themed icon
 -> IO ()
windowSetIconName self name =
  withUTFString name $ \namePtr ->
  {# call gtk_window_set_icon_name #}
    (toWindow self)
    namePtr

-- | Returns the name of the themed icon for the window, see
-- 'windowSetIconName'.
--
-- * Available since Gtk+ version 2.6
--
windowGetIconName :: WindowClass self => self
 -> IO String -- ^ returns the icon name or @\"\"@ if the window has no themed
              -- icon.
windowGetIconName self =
  {# call gtk_window_get_icon_name #}
    (toWindow self)
  >>= \strPtr -> if strPtr == nullPtr
                then return ""
                else peekUTFString strPtr

-- | Sets an icon to be used as fallback for windows that haven't had
-- 'windowSetIconList' called on them from a named themed icon, see
-- 'windowSetIconName'.
--
-- * Available since Gtk+ version 2.6
--
windowSetDefaultIconName :: 
    String -- ^ @name@ - the name of the themed icon
 -> IO ()
windowSetDefaultIconName name =
  withUTFString name $ \namePtr ->
  {# call gtk_window_set_default_icon_name #}
    namePtr
#endif

#if GTK_CHECK_VERSION(2,4,0)
-- | Sets an icon to be used as fallback for windows that haven't had 'windowSetIcon' called on them from a pixbuf.
--
-- * Available since Gtk+ version 2.4
--
windowSetDefaultIcon :: Maybe Pixbuf -> IO ()
windowSetDefaultIcon (Just icon) =
  {# call window_set_default_icon #} icon
windowSetDefaultIcon Nothing =
  {# call window_set_default_icon #} (Pixbuf nullForeignPtr)
#endif

#if GTK_CHECK_VERSION(2,2,0)
-- | Sets an icon to be used as fallback for windows that haven't had
-- 'windowSetIconList' called on them from a file on disk. May throw a 'GError' if
--  the file cannot be loaded.
--
-- * Available since Gtk+ version 2.2
--
windowSetDefaultIconFromFile ::
    String  -- ^ @filename@ - location of icon file
 -> IO Bool -- ^ returns @True@ if setting the icon succeeded.
windowSetDefaultIconFromFile filename =
  liftM toBool $
  propagateGError $ \errPtr ->
  withUTFString filename $ \filenamePtr ->
  {# call gtk_window_set_default_icon_from_file #}
    filenamePtr
    errPtr
#endif

#if GTK_CHECK_VERSION(2,16,0)
-- | Returns the fallback icon name for windows that has been set with
-- 'windowSetDefaultIconName'.
--
-- * Available since Gtk+ version 2.16
--
windowGetDefaultIconName ::
    IO String -- ^ returns the fallback icon name for windows
windowGetDefaultIconName =
  {# call window_get_default_icon_name #}
  >>= peekUTFString
#endif

#if GTK_CHECK_VERSION(2,2,0)
-- | Sets the 'Screen' where the @window@ is displayed; if the window is
-- already mapped, it will be unmapped, and then remapped on the new screen.
--
-- * Available since Gtk+ version 2.2
--
windowSetScreen :: WindowClass self => self
 -> Screen -- ^ @screen@ - a 'Screen'.
 -> IO ()
windowSetScreen self screen =
  {# call gtk_window_set_screen #}
    (toWindow self)
    screen

-- | Returns the 'Screen' associated with the window.
--
-- * Available since Gtk+ version 2.2
--
windowGetScreen :: WindowClass self => self
 -> IO Screen -- ^ returns a 'Screen'.
windowGetScreen self =
  makeNewGObject mkScreen $
  {# call gtk_window_get_screen #}
    (toWindow self)

-- | Sets the icon for @window@.
--
-- This function is equivalent to calling 'windowSetIcon' with a pixbuf
-- created by loading the image from @filename@.
--
-- This may throw an exception if the file cannot be loaded.
--
-- * Available since Gtk+ version 2.2
--
windowSetIconFromFile :: WindowClass self => self
 -> FilePath  -- ^ @filename@ - location of icon file
 -> IO ()
windowSetIconFromFile self filename =
  propagateGError $ \errPtr ->
  withUTFString filename $ \filenamePtr -> do
#if defined (WIN32) && GTK_CHECK_VERSION(2,6,0)
  {# call gtk_window_set_icon_from_file_utf8 #}
#else
  {# call gtk_window_set_icon_from_file #}
#endif
    (toWindow self)
    filenamePtr
    errPtr
  return ()

-- | By default, after showing the first 'Window' for each 'Screen', Gtk+
-- calls 'screenNotifyStartupComplete'. Call this function to disable the
-- automatic startup notification. You might do this if your first window is a
-- splash screen, and you want to delay notification until after your real main
-- window has been shown, for example.
--
-- In that example, you would disable startup notification temporarily, show
-- your splash screen, then re-enable it so that showing the main window would
-- automatically result in notification.
--
-- * Available since Gtk+ version 2.2
--
windowSetAutoStartupNotification :: 
    Bool  -- ^ @setting@ - @True@ to automatically do startup notification
 -> IO ()
windowSetAutoStartupNotification setting =
  {# call gtk_window_set_auto_startup_notification #}
    (fromBool setting)
#endif

-- | Window gravity defines the meaning of coordinates passed to 'windowMove'.
-- See 'windowMove' and 'Gravity' for more details.
--
-- The default window gravity is 'GravityNorthWest' which will typically
-- \"do what you mean.\"
--
windowSetGravity :: WindowClass self => self
 -> Gravity -- ^ @gravity@ - window gravity
 -> IO ()
windowSetGravity self gravity =
  {# call gtk_window_set_gravity #}
    (toWindow self)
    ((fromIntegral . fromEnum) gravity)

-- | Gets the value set by 'windowSetGravity'.
--
windowGetGravity :: WindowClass self => self
 -> IO Gravity -- ^ returns window gravity
windowGetGravity self =
  liftM (toEnum . fromIntegral) $
  {# call gtk_window_get_gravity #}
    (toWindow self)

-- | Asks the window manager to move @window@ to the given position. Window
-- managers are free to ignore this; most window managers ignore requests for
-- initial window positions (instead using a user-defined placement algorithm)
-- and honor requests after the window has already been shown.
--
-- Note: the position is the position of the gravity-determined reference
-- point for the window. The gravity determines two things: first, the location
-- of the reference point in root window coordinates; and second, which point
-- on the window is positioned at the reference point.
--
-- By default the gravity is 'GravityNorthWest', so the reference point is
-- simply the @x@, @y@ supplied to 'windowMove'. The top-left corner of the
-- window decorations (aka window frame or border) will be placed at @x@, @y@.
-- Therefore, to position a window at the top left of the screen, you want to
-- use the default gravity (which is 'GravityNorthWest') and move the window to
-- 0,0.
--
-- To position a window at the bottom right corner of the screen, you would
-- set 'GravitySouthEast', which means that the reference point is at @x@ + the
-- window width and @y@ + the window height, and the bottom-right corner of the
-- window border will be placed at that reference point. So, to place a window
-- in the bottom right corner you would first set gravity to south east, then
-- write: @gtk_window_move (window, gdk_screen_width() - window_width,
-- gdk_screen_height() - window_height)@.
--
-- The Extended Window Manager Hints specification at
-- http:\/\/www.freedesktop.org\/Standards\/wm-spec has a nice table of
-- gravities in the \"implementation notes\" section.
--
-- The 'windowGetPosition' documentation may also be relevant.
--
windowMove :: WindowClass self => self
 -> Int   -- ^ @x@ - X coordinate to move window to
 -> Int   -- ^ @y@ - Y coordinate to move window to
 -> IO ()
windowMove self x y =
  {# call gtk_window_move #}
    (toWindow self)
    (fromIntegral x)
    (fromIntegral y)

-- | Parses a standard X Window System geometry string - see the manual page for X (type 'man X') for details on this. 
-- 'windowParseGeometry' does work on all GTK+ ports including Win32 but is primarily intended for an X environment.
--
-- If either a size or a position can be extracted from the geometry string, 
-- 'windowParseGeometry' returns @True@ and calls gtk_window_set_default_size() and/or gtk_window_move() to resize/move the window.
--
-- If 'windowParseGeometry' returns @True@, 
-- it will also set the 'HintUserPos' and/or 'HintUserSize' hints indicating to the window manager that the size/position of the window was user-specified
-- This causes most window managers to honor the geometry.
--
-- Note that for 'windowParseGeometry' to work as expected, it has to be called when the window has its "final" size, i.e. 
-- after calling 'widgetShowAll' on the contents and 'windowSetGeometryHints' on the window.
--
windowParseGeometry :: WindowClass self => self
 -> String
 -> IO Bool
windowParseGeometry self geometry = liftM toBool $
  withUTFString geometry $ \geometryPtr -> 
  {# call window_parse_geometry #}
     (toWindow self)
     geometryPtr

-- | Hides window, then reshows it, resetting the default size and position of the window. Used by GUI builders only.
--
windowReshowWithInitialSize :: WindowClass self => self -> IO ()
windowReshowWithInitialSize self =
  {# call window_reshow_with_initial_size #} (toWindow self)

-- | Resizes the window as if the user had done so, obeying geometry
-- constraints. The default geometry constraint is that windows may not be
-- smaller than their size request; to override this constraint, call
-- 'widgetSetSizeRequest' to set the window's request to a smaller value.
--
-- If 'windowResize' is called before showing a window for the first time,
-- it overrides any default size set with 'windowSetDefaultSize'.
--
-- Windows may not be resized smaller than 1 by 1 pixels.
--
windowResize :: WindowClass self => self
 -> Int   -- ^ @width@ - width in pixels to resize the window to
 -> Int   -- ^ @height@ - height in pixels to resize the window to
 -> IO ()
windowResize self width height =
  {# call gtk_window_resize #}
    (toWindow self)
    (fromIntegral width)
    (fromIntegral height)

-- | Starts resizing a window. This function is used if an application has
-- window resizing controls. When GDK can support it, the resize will be done
-- using the standard mechanism for the window manager or windowing system.
-- Otherwise, GDK will try to emulate window resizing, potentially not all that
-- well, depending on the windowing system.
--
windowBeginResizeDrag :: WindowClass self => self
 -> WindowEdge -- ^ @edge@ - position of the resize control
 -> MouseButton -- ^ @button@ - mouse button that initiated the drag
 -> Int        -- ^ @rootX@ - X position where the user clicked to initiate
               -- the drag, in root window coordinates
 -> Int        -- ^ @rootY@ - Y position where the user clicked to initiate
               -- the drag
 -> TimeStamp  -- ^ @timestamp@ - timestamp from the click event that
               -- initiated the drag
 -> IO ()
windowBeginResizeDrag self edge button rootX rootY timestamp =
  {# call gtk_window_begin_resize_drag #}
    (toWindow self)
    ((fromIntegral . fromEnum) edge)
    ((fromIntegral . fromEnum) button)
    (fromIntegral rootX)
    (fromIntegral rootY)
    (fromIntegral timestamp)

-- | Starts moving a window. This function is used if an application has
-- window movement grips. When GDK can support it, the window movement will be
-- done using the standard mechanism for the window manager or windowing
-- system. Otherwise, GDK will try to emulate window movement, potentially not
-- all that well, depending on the windowing system.
--
windowBeginMoveDrag :: WindowClass self => self
 -> MouseButton -- ^ @button@ - mouse button that initiated the drag
 -> Int    -- ^ @rootX@ - X position where the user clicked to initiate the
           -- drag, in root window coordinates
 -> Int    -- ^ @rootY@ - Y position where the user clicked to initiate the
           -- drag
 -> TimeStamp -- ^ @timestamp@ - timestamp from the click event that initiated
           -- the drag
 -> IO ()
windowBeginMoveDrag self button rootX rootY timestamp =
  {# call gtk_window_begin_move_drag #}
    (toWindow self)
    ((fromIntegral . fromEnum) button)
    (fromIntegral rootX)
    (fromIntegral rootY)
    (fromIntegral timestamp)

-- | This function returns the position you need to pass to 'windowMove' to
-- keep @window@ in its current position. This means that the meaning of the
-- returned value varies with window gravity. See 'windowMove' for more
-- details.
--
-- If you haven't changed the window gravity, its gravity will be
-- 'GravityNorthWest'. This means that 'windowGetPosition' gets the position of
-- the top-left corner of the window manager frame for the window. 'windowMove'
-- sets the position of this same top-left corner.
--
-- Moreover, nearly all window managers are historically broken with respect
-- to their handling of window gravity. So moving a window to its current
-- position as returned by 'windowGetPosition' tends to result in moving the
-- window slightly. Window managers are slowly getting better over time.
--
-- If a window has gravity 'GravityStatic' the window manager frame is not
-- relevant, and thus 'windowGetPosition' will always produce accurate results.
-- However you can't use static gravity to do things like place a window in a
-- corner of the screen, because static gravity ignores the window manager
-- decorations.
--
-- If you are saving and restoring your application's window positions, you
-- should know that it's impossible for applications to do this without getting
-- it somewhat wrong because applications do not have sufficient knowledge of
-- window manager state. The Correct Mechanism is to support the session
-- management protocol (see the \"GnomeClient\" object in the GNOME libraries
-- for example) and allow the window manager to save your window sizes and
-- positions.
--
windowGetPosition :: WindowClass self => self
 -> IO (Int, Int) -- ^ @(rootX, rootY)@ - X and Y coordinate of
                  -- gravity-determined reference point
windowGetPosition self =
  alloca $ \rootXPtr ->
  alloca $ \rootYPtr -> do
  {# call gtk_window_get_position #}
    (toWindow self)
    rootXPtr
    rootYPtr
  rootX <- peek rootXPtr
  rootY <- peek rootYPtr
  return (fromIntegral rootX, fromIntegral rootY)

-- | Obtains the current size of the window. If the window is not onscreen, it
-- returns the size Gtk+ will suggest to the window manager for the initial
-- window size (but this is not reliably the same as the size the window
-- manager will actually select). The size obtained by 'windowGetSize' is the
-- last size received in a 'EventConfigure', that is,
-- Gtk+ uses its locally-stored size, rather than querying the X server for the
-- size. As a result, if you call 'windowResize' then immediately call
-- 'windowGetSize', the size won't have taken effect yet. After the window
-- manager processes the resize request, Gtk+ receives notification that the
-- size has changed via a configure event, and the size of the window gets
-- updated.
--
-- Note 1: Nearly any use of this function creates a race condition, because
-- the size of the window may change between the time that you get the size and
-- the time that you perform some action assuming that size is the current
-- size. To avoid race conditions, connect to \"configure_event\" on the window
-- and adjust your size-dependent state to match the size delivered in the
-- 'EventConfigure'.
--
-- Note 2: The returned size does /not/ include the size of the window
-- manager decorations (aka the window frame or border). Those are not drawn by
-- Gtk+ and Gtk+ has no reliable method of determining their size.
--
-- Note 3: If you are getting a window size in order to position the window
-- onscreen, there may be a better way. The preferred way is to simply set the
-- window's semantic type with 'windowSetTypeHint', which allows the window
-- manager to e.g. center dialogs. Also, if you set the transient parent of
-- dialogs with 'windowSetTransientFor' window managers will often center the
-- dialog over its parent window. It's much preferred to let the window manager
-- handle these things rather than doing it yourself, because all apps will
-- behave consistently and according to user prefs if the window manager
-- handles it. Also, the window manager can take the size of the window
-- decorations\/border into account, while your application cannot.
--
-- In any case, if you insist on application-specified window positioning,
-- there's /still/ a better way than doing it yourself - 'windowSetPosition'
-- will frequently handle the details for you.
--
windowGetSize :: WindowClass self => self
 -> IO (Int, Int) -- ^ @(width, height)@
windowGetSize self =
  alloca $ \widthPtr ->
  alloca $ \heightPtr -> do
  {# call gtk_window_get_size #}
    (toWindow self)
    widthPtr
    heightPtr
  width <- peek widthPtr
  height <- peek heightPtr
  return (fromIntegral width, fromIntegral height)

-- | By setting the type hint for the window, you allow the window manager to
-- decorate and handle the window in a way which is suitable to the function of
-- the window in your application.
--
-- This function should be called before the window becomes visible.
--
windowSetTypeHint :: WindowClass self => self
 -> WindowTypeHint -- ^ @hint@ - the window type
 -> IO ()
windowSetTypeHint self hint =
  {# call gtk_window_set_type_hint #}
    (toWindow self)
    ((fromIntegral . fromEnum) hint)

-- | Gets the type hint for this window. See 'windowSetTypeHint'.
--
windowGetTypeHint :: WindowClass self => self
 -> IO WindowTypeHint -- ^ returns the type hint for @window@.
windowGetTypeHint self =
  liftM (toEnum . fromIntegral) $
  {# call gtk_window_get_type_hint #}
    (toWindow self)

#if GTK_CHECK_VERSION(2,8,0)
-- | Presents a window to the user in response to a user interaction. If you
-- need to present a window without a timestamp, use 'windowPresent'. See
-- 'windowPresent' for details.
--
-- * Available since Gtk+ version 2.8
--
windowPresentWithTime :: WindowClass self => self
 -> TimeStamp -- ^ @timestamp@ - the timestamp of the user interaction
              -- (typically a button or key press event) which triggered this
              -- call
 -> IO ()
windowPresentWithTime self timestamp =
  {# call gtk_window_present_with_time #}
    (toWindow self)
    (fromIntegral timestamp)

-- | Windows may set a hint asking the desktop environment to draw the users
-- attention to the window. This function sets this hint.
--
-- * Available since Gtk+ version 2.8
--
windowSetUrgencyHint :: WindowClass self => self
 -> Bool  -- ^ @setting@ - @True@ to mark this window as urgent
 -> IO ()
windowSetUrgencyHint self setting =
  {# call gtk_window_set_urgency_hint #}
    (toWindow self)
    (fromBool setting)

-- | Gets the value set by 'windowSetUrgencyHint'
--
-- * Available since Gtk+ version 2.8
--
windowGetUrgencyHint :: WindowClass self => self
 -> IO Bool -- ^ returns @True@ if window is urgent
windowGetUrgencyHint self =
  liftM toBool $
  {# call gtk_window_get_urgency_hint #}
    (toWindow self)
#endif

-- | This function sets up hints about how a window can be resized by the
-- user. You can set a minimum and maximum size, the allowed resize increments
-- (e.g. for xterm, you can only resize by the size of a character) and aspect
-- ratios.
--
-- If you set a geometry widget, the hints will apply to the geometry widget
-- instead of directly to the toplevel window. Of course since the geometry
-- widget is a child widget of the top level window, constraining the sizing
-- behaviour of the widget will have a knock-on effect on the sizing of the
-- toplevel window.
--
-- The @minWidth@\/@minHeight@\/@maxWidth@\/@maxHeight@ fields may be set to
-- @-1@, to use the size request of the window or geometry widget. If the
-- minimum size hint is not provided, Gtk+ will use the size requisition of the
-- window (or the geometry widget if it set) as the minimum size. The base size
-- is treated similarly.
--
-- The canonical use-case for 'windowSetGeometryHints' is to get a terminal
-- widget to resize properly. Here, the terminal text area should be the
-- geometry widget. Gtk+ will then automatically set the base size of the
-- terminal window to the size of other widgets in the terminal window, such as
-- the menubar and scrollbar. Then, the @widthInc@ and @heightInc@ values
-- should be set to the size of one character in the terminal. Finally, the
-- base size should be set to the size of one character. The net effect is that
-- the minimum size of the terminal will have a 1x1 character terminal area,
-- and only terminal sizes on the \"character grid\" will be allowed.
--
-- The other useful settings are @minAspect@ and @maxAspect@. These specify a
-- width\/height ratio as a floating point number. If a geometry widget is set,
-- the aspect applies to the geometry widget rather than the entire window. The
-- most common use of these hints is probably to set @minAspect@ and
-- @maxAspect@ to the same value, thus forcing the window to keep a constant
-- aspect ratio.
--
windowSetGeometryHints :: (WindowClass self, WidgetClass widget) =>
    self             -- ^ @window@ - the top level window
 -> Maybe widget     -- ^ @geometryWidget@ - optionall a widget the geometry
                     -- hints will be applied to rather than directly to the
                     -- top level window
 -> Maybe (Int, Int) -- ^ @(minWidth, minHeight)@ - minimum width and height
                     -- of window (or -1 to use requisition)
 -> Maybe (Int, Int) -- ^ @(maxWidth, maxHeight)@ - maximum width and height
                     -- of window (or -1 to use requisition)
 -> Maybe (Int, Int) -- ^ @(baseWidth, baseHeight)@ - the allowed window widths
                     -- are @base_width + width_inc * N@ for any int @N@.
                     -- Similarly, the allowed window widths are @base_height +
                     -- height_inc * N@ for any int @N@. For either the base
                     -- width or height -1 is allowed as described above.
 -> Maybe (Int, Int) -- ^ @(widthInc, heightInc)@ - width and height resize
                     -- increment
 -> Maybe (Double, Double) -- ^ @(minAspect, maxAspect)@ - minimum and maximum
                           -- width\/height ratio
 -> IO ()
windowSetGeometryHints self geometryWidget
  minSize maxSize baseSize incSize aspect =
  allocaBytes {# sizeof GdkGeometry #} $ \geometryPtr -> do
  minSizeFlag <- case minSize of
    Nothing -> return 0
    Just (width, height) -> do
      {# set GdkGeometry->min_width  #} geometryPtr (fromIntegral width)
      {# set GdkGeometry->min_height #} geometryPtr (fromIntegral height)
      return (fromEnum GdkHintMinSize)
  maxSizeFlag <- case maxSize of
    Nothing -> return 0
    Just (width, height) -> do
      {# set GdkGeometry->max_width  #} geometryPtr (fromIntegral width)
      {# set GdkGeometry->max_height #} geometryPtr (fromIntegral height)
      return (fromEnum GdkHintMaxSize)
  baseSizeFlag <- case baseSize of
    Nothing -> return 0
    Just (width, height) -> do
      {# set GdkGeometry->base_width  #} geometryPtr (fromIntegral width)
      {# set GdkGeometry->base_height #} geometryPtr (fromIntegral height)
      return (fromEnum GdkHintBaseSize)
  incSizeFlag <- case incSize of
    Nothing -> return 0
    Just (width, height) -> do
      {# set GdkGeometry->width_inc  #} geometryPtr (fromIntegral width)
      {# set GdkGeometry->height_inc #} geometryPtr (fromIntegral height)
      return (fromEnum GdkHintResizeInc)
  aspectFlag <- case aspect of
    Nothing -> return 0
    Just (min, max) -> do
      {# set GdkGeometry->min_aspect #} geometryPtr (realToFrac min)
      {# set GdkGeometry->max_aspect #} geometryPtr (realToFrac max)
      return (fromEnum GdkHintAspect)

  {# call gtk_window_set_geometry_hints #}
    (toWindow self)
    (maybe (Widget nullForeignPtr) toWidget geometryWidget)
    geometryPtr
    (fromIntegral $ minSizeFlag .|. maxSizeFlag .|. baseSizeFlag
                 .|. incSizeFlag .|. aspectFlag)

{# enum GdkWindowHints {underscoreToCase} #}

#if GTK_CHECK_VERSION(2,12,0)
-- | Request the windowing system to make window partially transparent, with opacity 0 being fully transparent and 1 fully opaque. 
-- (Values of the opacity parameter are clamped to the [0,1] range.) 
-- On X11 this has any effect only on X screens with a compositing manager running.
-- See 'widgetIsComposited'. On Windows it should work always.
--
-- Note that setting a window's opacity after the window has been shown causes it to
-- flicker once on Windows.
-- 
-- * Available since Gtk+ version 2.12
--
windowSetOpacity :: WindowClass self => self
 -> Double  -- ^ @opacity@ - desired opacity, between 0 and 1 
 -> IO ()
windowSetOpacity self opacity =
  {#call window_set_opacity #} (toWindow self) (realToFrac opacity)

-- | Fetches the requested opacity for this window. See 'windowSetOpacity'.
--
-- * Available since Gtk+ version 2.12
--
windowGetOpacity :: WindowClass self => self 
 -> IO Double  -- ^ return the requested opacity for this window. 
windowGetOpacity self = liftM realToFrac $
 {#call window_get_opacity#} (toWindow self)
#endif

#if GTK_CHECK_VERSION(2,10,0)
-- | Returns the group for window or the default group, if window is @Nothing@ or if window does not have an explicit window group.
-- 
-- * Available since Gtk+ version 2.10
--
windowGetGroup :: WindowClass self => Maybe self
 -> IO WindowGroup  -- ^ return the 'WindowGroup' for a window or the default group 
windowGetGroup self = 
  makeNewGObject mkWindowGroup $
  {# call window_get_group #} (maybe (Window nullForeignPtr) toWindow self)
#endif  

--------------------
-- Attributes

-- | The title of the window.
--
windowTitle :: WindowClass self => Attr self String
windowTitle = newAttr
  windowGetTitle
  windowSetTitle

-- | The type of the window.
--
-- Default value: 'WindowToplevel'
--
windowType :: WindowClass self => ReadAttr self WindowType
windowType = readAttrFromEnumProperty "type"
  {# call pure unsafe gtk_window_type_get_type #}

-- | If @True@, the window has no mimimum size. Setting this to @True@ is 99%
-- of the time a bad idea.
--
-- Default value: @False@
--
windowAllowShrink :: WindowClass self => Attr self Bool
windowAllowShrink = newAttrFromBoolProperty "allow-shrink"

-- | If @True@, users can expand the window beyond its minimum size.
--
-- Default value: @True@
--
windowAllowGrow :: WindowClass self => Attr self Bool
windowAllowGrow = newAttrFromBoolProperty "allow-grow"

-- | If @True@, users can resize the window.
--
-- Default value: @True@
--
windowResizable :: WindowClass self => Attr self Bool
windowResizable = newAttr
  windowGetResizable
  windowSetResizable

-- | If @True@, the window is modal (other windows are not usable while this
-- one is up).
--
-- Default value: @False@
--
windowModal :: WindowClass self => Attr self Bool
windowModal = newAttr
  windowGetModal
  windowSetModal

#if GTK_CHECK_VERSION(2,12,0)
-- | The requested opacity of the window. See 'windowSetOpacity' for more details about window opacity.
--
-- Allowed values: [0,1]
--
-- Default values: 1
--
-- * Available since Gtk+ version 2.12
--
windowOpacity :: WindowClass self => Attr self Double
windowOpacity = newAttrFromDoubleProperty "opacity"
#endif

-- | If @focus@ is not the current focus widget, and is focusable, sets it as
-- the focus widget for the window. If @focus@ is @Nothing@, unsets the focus widget for
-- this window. To set the focus to a particular widget in the toplevel, it is
-- usually more convenient to use 'widgetGrabFocus' instead of this function.
--
windowFocus :: WindowClass self => Attr self (Maybe Widget)
windowFocus = newAttr
  windowGetFocus
  windowSetFocus

-- | (Note: this is a special-purpose function for the framebuffer port, that
-- causes Gtk+ to draw its own window border. For most applications, you want
-- 'windowSetDecorated' instead, which tells the window manager whether to draw
-- the window border.)
--
-- If this function is called on a window with setting of @True@, before it
-- is realized or showed, it will have a \"frame\" window around
-- its 'DrawWindow', accessible using 'windowGetFrame'. Using the signal
-- 'windowFrameEvent' you can receive all events targeted at the frame.
--
-- This function is used by the linux-fb port to implement managed windows,
-- but it could conceivably be used by X-programs that want to do their own
-- window decorations.
--
windowHasFrame :: WindowClass self => Attr self Bool
windowHasFrame = newAttr
  windowGetHasFrame
  windowSetHasFrame

-- | Sets up the icon representing a 'Window'. The icon is used when the
-- window is minimized (also known as iconified). Some window managers or
-- desktop environments may also place it in the window frame, or display it in
-- other contexts.
--
-- By passing several sizes, you may improve the final image quality of the
-- icon, by reducing or eliminating automatic image scaling.
--
-- Recommended sizes to provide: 16x16, 32x32, 48x48 at minimum, and larger
-- images (64x64, 128x128) if you have them.
--
-- See also 'windowSetDefaultIconList' to set the icon for all windows in
-- your application in one go.
--
-- Note that transient windows (those who have been set transient for
-- another window using 'windowSetTransientFor') will inherit their icon from
-- their transient parent. So there's no need to explicitly set the icon on
-- transient windows.
--
windowIconList :: WindowClass self => Attr self [Pixbuf]
windowIconList = newAttr
  windowGetIconList
  windowSetIconList

-- | The mnemonic modifier for this window.
--
windowMnemonicModifier :: WindowClass self => Attr self [Modifier]
windowMnemonicModifier = newAttr
  windowGetMnemonicModifier
  windowSetMnemonicModifier

-- | Unique identifier for the window to be used when restoring a session.
--
-- Default value: "\\"
--
windowRole :: WindowClass self => Attr self String
windowRole = newAttrFromStringProperty "role"

#if GTK_CHECK_VERSION(2,12,0)
-- | The 'windowStartupId' is a write-only property for setting window's startup notification identifier.
--
-- Default value: "\\"
--
-- * Available since Gtk+ version 2.12
--
windowStartupId :: WindowClass self => Attr self String
windowStartupId = newAttrFromStringProperty "startup-id"
#endif

-- | The initial position of the window.
--
-- Default value: 'WinPosNone'
--
windowWindowPosition :: WindowClass self => Attr self WindowPosition
windowWindowPosition = newAttrFromEnumProperty "window-position"
  {# call pure unsafe gtk_window_position_get_type #}

-- | The default width of the window, used when initially showing the window.
--
-- Allowed values: >= -1
--
-- Default value: -1
--
windowDefaultWidth :: WindowClass self => Attr self Int
windowDefaultWidth = newAttrFromIntProperty "default-width"

-- | The default height of the window, used when initially showing the window.
--
-- Allowed values: >= -1
--
-- Default value: -1
--
windowDefaultHeight :: WindowClass self => Attr self Int
windowDefaultHeight = newAttrFromIntProperty "default-height"

-- | Whether the window frame should have a close button.
--
-- Default values: @True@
--
-- * Available since Gtk+ version 2.10
--
windowDeletable :: WindowClass self => Attr self Bool
windowDeletable = newAttrFromBoolProperty "deletable"

-- | If this window should be destroyed when the parent is destroyed.
--
-- Default value: @False@
--
windowDestroyWithParent :: WindowClass self => Attr self Bool
windowDestroyWithParent = newAttr
  windowGetDestroyWithParent
  windowSetDestroyWithParent

-- | Icon for this window.
--
windowIcon :: WindowClass self => Attr self (Maybe Pixbuf)
windowIcon = newAttr
  windowGetIcon
  windowSetIcon

-- | The 'windowIconName' property specifies the name of the themed icon to use as the window icon. See 'IconTheme' for more details.
--
-- Default values: "\\"
--
-- * Available since Gtk+ version 2.6
--
--
windowIconName :: WindowClass self => Attr self String
windowIconName = newAttrFromStringProperty "icon-name"

#if GTK_CHECK_VERSION(2,2,0)
-- | The screen where this window will be displayed.
--
windowScreen :: WindowClass self => Attr self Screen
windowScreen = newAttr
  windowGetScreen
  windowSetScreen
#endif

-- | Hint to help the desktop environment understand what kind of window this
-- is and how to treat it.
--
-- Default value: 'WindowTypeHintNormal'
--
windowTypeHint :: WindowClass self => Attr self WindowTypeHint
windowTypeHint = newAttr
  windowGetTypeHint
  windowSetTypeHint

#if GTK_CHECK_VERSION(2,2,0)
-- | @True@ if the window should not be in the task bar.
--
-- Default value: @False@
--
windowSkipTaskbarHint :: WindowClass self => Attr self Bool
windowSkipTaskbarHint = newAttr
  windowGetSkipTaskbarHint
  windowSetSkipTaskbarHint

-- | @True@ if the window should not be in the pager.
--
-- Default value: @False@
--
windowSkipPagerHint :: WindowClass self => Attr self Bool
windowSkipPagerHint = newAttr
  windowGetSkipPagerHint
  windowSetSkipPagerHint
#endif

#if GTK_CHECK_VERSION(2,8,0)
-- | @True@ if the window should be brought to the user's attention.
--
-- Default value: @False@
--
windowUrgencyHint :: WindowClass self => Attr self Bool
windowUrgencyHint = newAttr
  windowGetUrgencyHint
  windowSetUrgencyHint
#endif

#if GTK_CHECK_VERSION(2,4,0)
-- | @True@ if the window should receive the input focus.
--
-- Default value: @True@
--
windowAcceptFocus :: WindowClass self => Attr self Bool
windowAcceptFocus = newAttr
  windowGetAcceptFocus
  windowSetAcceptFocus
#endif

#if GTK_CHECK_VERSION(2,6,0)
-- | @True@ if the window should receive the input focus when mapped.
--
-- Default value: @True@
--
windowFocusOnMap :: WindowClass self => Attr self Bool
windowFocusOnMap = newAttr
  windowGetFocusOnMap
  windowSetFocusOnMap
#endif

#if GTK_CHECK_VERSION(2,4,0)
-- | Whether the window should be decorated by the window manager.
--
-- Default value: @True@
--
windowDecorated :: WindowClass self => Attr self Bool
windowDecorated = newAttr
  windowGetDecorated
  windowSetDecorated

-- | The window gravity of the window. See 'windowMove' and 'Gravity' for more
-- details about window gravity.
--
-- Default value: 'GravityNorthWest'
--
windowGravity :: WindowClass self => Attr self Gravity
windowGravity = newAttr
  windowGetGravity
  windowSetGravity
#endif

-- | Whether the input focus is within this GtkWindow.
--
-- Note: If add `window` before `HasToplevelFocus` (has-toplevel-focus attribute)
-- will conflicts with fucntion `windowHasToplevelFocus`, so we named this attribute 
-- to `windowToplevelFocus`.
--
-- Default values: @False@
--
windowToplevelFocus :: WindowClass self => Attr self Bool
windowToplevelFocus = newAttrFromBoolProperty "has-toplevel-focus"

-- | \'transientFor\' property. See 'windowGetTransientFor' and
-- 'windowSetTransientFor'
--
windowTransientFor :: (WindowClass self, WindowClass parent) => ReadWriteAttr self (Maybe Window) parent
windowTransientFor = newAttr
  windowGetTransientFor
  windowSetTransientFor

--------------------
-- Signals

-- | Observe events that are emitted on the frame of this window.
-- 
frameEvent :: WindowClass self => Signal self (EventM EAny Bool)
frameEvent = Signal (\after obj fun ->
                     connect_PTR__BOOL "frame-event" after obj (runReaderT fun))

-- | The 'keysChanged' signal gets emitted when the set of accelerators or mnemonics that are associated with window changes.
--
keysChanged :: WindowClass self => Signal self (IO ())
keysChanged = Signal (connect_NONE__NONE "keys-changed")

-- | Observe a change in input focus.
--
setFocus :: WindowClass self => Signal self (Widget -> IO ())
setFocus = Signal (connect_OBJECT__NONE "set-focus")

-- * Deprecated
#ifndef DISABLE_DEPRECATED
-- | Observe a change in input focus.
--
onSetFocus, afterSetFocus :: (WindowClass self, WidgetClass foc) => self
 -> (foc -> IO ())
 -> IO (ConnectId self)
onSetFocus = connect_OBJECT__NONE "set-focus" False
afterSetFocus = connect_OBJECT__NONE "set-focus" True

#endif