File: cs.mo

package info (click to toggle)
gtkmm-documentation 4.12.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 25,772 kB
  • sloc: cpp: 15,541; javascript: 1,208; makefile: 1,080; python: 401; xml: 106; perl: 67; sh: 8
file content (2379 lines) | stat: -rw-r--r-- 700,287 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
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
6	\mБRёe$kdq[͓M~Lu][w%ӘU2Oz:>A7`yIڟ$.tѥF٦p279UȬSO3ׯ{}
[pU.Cpacҵg6Kz3Q0FE|2½-S#CwZaUxqο:@{A\$HB;O'=P.B(q(I\
j3}Pd4j6Aoa7GrP52 !B_#EH#<
G|]B4:M.Qw*TajL/)"Y-6PF"a,3`ED	YQ	z&r6S=FLQO:0kI/O !w#%%t&/'Z'7H(9*+\g,,-n.&00C12q3-56 A7b8K99j:7<==?(@@TAz`B^CZ:D=DRD=&EdEsJ2{JLrUNeO.PPQ*RS~iUUkW$fX4YxY9ZWZ V\2w]]m^`a+aha$9b^b$ccQdhe[Qf+f3f.
gT<iYiijq4knkllo^mlm;nnSOoGq_q-KrfyrOr0sv}v/wvBww4x+x z@z={rQ|}YUށ]4jz;sC[Iqjaz"IwmtoHh~0F<
Ǣ5'Px(5AUgBQ}zGv7`28̱7	@9J=º]D0J8Ms	6MVG%;
l#)	=@
O5UQsf	&/J;j+$2!MTxtaNy

2^|	BLXg`XRXu
+1H<?|;I-,Z %;ax.


{
"9F(^@'	?I\i{
'D}Vrq
HOU=RD
=  !!!@! ""v#t#ss$$j%
v&&
&&&&&&'''A'V'e'|''''!'`'*Q(&|(({5*A+H-</(0700?0#p0$0:0>03191J1c1v1111x22
2223303334
*484S4\4h4z4944567"8^488RE<?\aBiBE(CInCCDMDJE
F"FGIHJbHJHwHEpIJIGJCIJFJIJFKBeKBKCKC/LsL-dMM
GNeUNNVOYPOQ$R*RSTUU#UVWXXX+XY[Z[2["A[d\R{\l\\;]N]T]<^k^i_Xa^a|dbXb:cmca5eeYaff
~g g\g
hBj7l<lLCl)mm;_nnop pr
s3t tttBpu<vovT`wSww	ymy6y&z>zWz./{	^{h|||
|/||7}(}~~_=#;zÁ^*)/4YCB҅e${n$!Fb'4M$o!9?D$Sx)QQ{͗o^Ιe=ri9@Smj$Y~2Cc{^߳>jN-A6oHmQV%ǽ^.Bq
ES	
q,S&H="%:\:=1:*	9CLbTd#,Pint%'bHg3		,53b	n
-39

"8
N\"&IX*(9(!xgdiov]-We2I=|MpWg=GR7	
wQmc7'v:
%6O
.o<]
!~@&	QR 	"#$k%L%%%x&t){)"))3))*
***b+h++}+,+++++,.v./b0h0z00
00000a0\1u1}11112322}33)3o3
04>4
J4zX45
7
777	7+7
99;;	;;;;<!<
2<@<?R<>	>v>L"?o?b?{?d@]@VAAB
UCcDtDDD[DFF#F;FFFF"FG
1GQ<GHBIKqLLL2SMNOPiQ'R/R}S{Uy'WW(YIZ___`'`@``Vb
vbmbnb^dYeufCghhhhh>iNEjj^$kkk'mp
p"r7r	sssuLvSwwxPzzP|=bXY`z5_τ`/N߇?!ˉ]`ren&;{yUen9Xazh
]hq
	խ߭
Zt}38Lj9z684op	0:J<9v&O-	4W>A4vWmmigsRjx(uz* ngf{BJ=4	0NsviN"cq`D@G-T	uJeCwn*J0
|e#			3s

&/jV]{/jD[a
?o9A576"9Ym !"c+#(#i'"))+,-1./0	1N	2X2k3s46H+7t8Ty:
:C; =>9???@AsCC@EDD[XEF4H:HcJJRK}eKKnL3L*MMDNwO7P2PXP8LQQLSdiSUT7$U;\VV,WWXdYYYEZ~[[;o\a\
^9&_A`__`[bbacpGgYhjjk<kkrFlnl(n 1nhRn3owpgqLrrs$ttuMv;xBz^{^|"~ÁR9w-?|?Aiߌ3I}YRJܒؓʕrV=7P_l͜՜̞p	ğݟ*i?N0@i	9ѣ
?YHbMMN]|/
öѶ%9
GLֹpsl-I*,FfYvyiUm<}1y{@ZcU2q9I$MSr !!~1a/eiUrUUO<0\v3Hr["~	.

t
,=>A6Ky(]@ ~".^#%s'(r)j*,,-Q/$00UL11y2534f56M78H:<R<R=-j==$==S=/>U@>>>>:?XQ??Z?
@,@4@1M@4@@@)@A/&AVA)rA7A!A3A/*B7ZB3BB
B
BBB
C4CLC'cCC)CC:CD3DLD D:D)E2E8EEEEE!FHIII IIJPKMNNNN_OqOOO
O+O.OPPP$P-PJP	P>P#Q,Q
3Q>QFQUQZQ_QfQ
QQQQQQQQSSSS^S\T`TVVVV
WW+W4>W;sW%W9WaX4qXeXY2 YSYi[[[)[\\F%\l\o\
w\\
\D\>\]p]^7_xH_	____'`(`
0`	>`H`a`0aabbdd )eJe0]efDff
hiQfjbkllcmmnho0xooR4qeqkqdYrqr0ss~wtturvuw]|wVw%1x[Wx/z{|}>[~A~`~I=.ہ
t*;p2ȋUW5Sڎ3.b}[poĒT*Cpchr̕K?z"3Qљ#E2c-SĝCZ\aUqo:A$?HdB;',=TP.((;Id\3Rd>	6HbAFa6?32r#PO5ֱ&ݳB_EYH
IGڽ]4"ٿF4(Z^3Yi
1-P_NhbN`7|Nf|$+V
vQ];hX8@CY)	
~{SZ
_
V[_n!Z^GaORA1-_ !t!a#>$*%&'?(()u+[
,=i,W,?,?-p1g24m~6y7f8999:]<x>>
>^?5@p'AAV^B/C3DE
F?GI8II(JJKLgIMNTPO7O1OEPTURfRSSpdTmTCUUpVmWuWXXM#[aq[/[d\Nh\\_}>`1`v`ea<~b"b(cdefgVjlLmd^m~mBn_o3o+p@qrstQxxzQ|}~~_/*OG<xLŌ]bMJY6+ϒ3g! ԓܕb~
*Ԛd$4K٠-%S^%#,kDs$K=&ήy>%d ŹK2B2uoj=5	S].3+_I/y!D/{=>J	_ieDZ2I0Qu	$]Y7v9Zn	
mDm[K!\E5NkT	
@f+6b !-Bp 0!&&9`q+%1W!i#69I)eF.U"r&			
!


/
% C d!vU\b6COMag\w k &!$2!W!$g!!!!!""">"P"d"|"&")""&"c#+#'##w%S*'Z~)*++7++4,)`,D,G,---B-#a--$-/--.$..//0	=0;G0
000
0#00071!O18q11{2346{5x5+6F9'=h@g@A@0*AA[BLBBCCEGEHFHgFF>OGCG@G<H?PHBH?H;I;OI<I<IJ7J*KKWLXLQM^NFOFP5SPQWS$iSSSbUAVW8WXW-wWWT|YYY=Z@[_U[[l7\Z\c\c]k$^^X+`
`|aXbhb|barddYee
f f\fGgB1jtkkGk6lm;mmnwo#@pdrur3)t ]tt~tTt<HvovTvEJwwxmy6vy+yyy-zz"|3|?|4S||;b}+}}p~}D,A	!.…:@,7mh /*Ԉ5ՎSx$̐o5a	"ēiܓFa=Z'v)Bglԧ˩flSӬ'61O4n"o!#:6̽<@naB-5]vHPU-@a^	^6^VI/HCN]34${Y
ksI./27 =^!n0eMgr
#	.8P6iN/D!+&7>P`y(<#eu5`ED7#zc9P=D,Bq tF	n;

pIhXbJ\|di0Kx|DAx*N y!|3#$$c%4&'3'(**,.0"t23$74Y\444[r57$_8)883889999l:r:):*:	:::;"(;K=T=>?%?#?!?@1@Q@g@@e@A%A!-AOATA@sAB3BB CC,Cs
D%D$DDDF,`H,HHHH-H
!J,KLL
MM%*MPMWM gMMM[M"P1Pu=PYP
Q[!Q}QQORRzSUT(T"V5VQVcV{yVWXX1XX(XY+%YQYpYY+[[_'___U`
bcdee0e
hiKk'kGnbosttuu%uu!awwmw
xyz{|Q~*a~~&~~?~Rh
&oT,=,j/H͐~	.k8nwe9zd`z'CFD"LopL>=˫mnha׭9?_tyYZ%pKAW	,9?W_wo0*\,A:<$,a%9B8,e=H(0rY
|WEDX4s<ii4;{nk=J7\U	5				 	0		J	R		bl	_	/
	\	i	Il		L	Q	)	[	
	&	/		<y		A	v			I_		^!	o!	c"	zt#	$	&	"'	}<(	)	*	.+	I+	1+	(,	:-	n"0	a0	L1	y@3	3	WA7	7	KA8	9	HG;	C;	;	O=	9(>	b?	[/@	:A	KB	<C	]OC	nD	E	 F	f,G	dG	sK	lM	IN	fP	cQ	"WR	LzS	T	gU	
W	s)W	W	qX	Z	.[	G\	;/^	bk`	`	La	c	&d	<"e	_e	?f	z/h	ui	 j	Mj	:k	sl	m	@o	o	pq	r	Xr	s	s	mmt	/t	u	$u	Xv	!w	Cx	+,y	tXy	3y	z	E{	{	e}	;~	;S		0		܁	c		k	V	߄	7		I	9	E	d		b		^	`	8	Ŕ	i	p	_			'	.7	f	V	K	ܜ	͝	z		۟			m	@	e:			ƪ		4			h	i	|	+	1	۵		F	Dڸ		eɺ	E/	u	pj	۾		6	0?	.p		_	s	]Z	&	&	)	.0	_		,						(	'				"	!?	a	.x		z	9	_			X		R	\	i{				(			F	a	d		i	s	n	Fk	c						%		7	4	"E	6h	R					s	}{		n	H&	o	`&	5		h	@		.	4	1	N	-	


O
=

B
}9
_

5
M

u
<)
f
>
5
R
d
l
'

,2
5_
!"
"
$
#&
&
#'
4'
yJ'
'
1(
*
*
+
n,
y,
-
-
z.
O0
i-2
2
93
'4
[4
25
m7
8
S9
9
:
>;
<
=
>
(?
@
jB
kC
D
D
E
F
G
3~H
J
QK
MK
4M
O
Q
Q
R
DT
U
V
Z
\
^
\8_
a
c
5e
Of
f
h
)ei
j
il
Um
m
Mn
n

o
p
q
as

t
ku
w
qy
w{
R{
{
-{
!|
$0|
U|
Sd|
|
U|
}
2}
C}
}
X}
3~
ZL~

~
~
~
1~
4
=
S
)k

/

)
7%
!]
3
/
7
3
O

[

f
q


4
'

)#
M
:Z

3
Ղ
 V
Zw
ރ

s
x


K
`
f
 n

d
Ph

L
T
a
n

%
<
I

_
+j
.




>






,
1
6
=

]
k
t





͒


p
t
.




"
0
<
4L
;
%
9
a
4
e

0.
_
ig
)

$
M1






D
>
/
p
"
7%
x]
	֞



'
	=

G
	U
_
x
G

ݡ
0
d
.
!
-Ф

Y
n


,
[
bU




(
:
4J
w4Q1-X*6~po=..6&"U}-'3gr,:d[	5T[rH#Yi7-huvf]ER9
[kTC;j}oK>%I(`oz&PTm0` +xdhf7w`ox]bg~lCUL~J!AqBZB}S_X~[r'"%'Z~#Pxln5Qou7v37hFm>3ghOK%4;NL?aWW^!>a)%8/]=,Hf}"vEd$c]+,IM_9x!iHF8"sb%LP)65s0Mi"X6&fVDPN'EdFzr?i19:w91{$sVzp=I}#~\Z0zaBY?i^BC-#8[ \$_S
VnsGvx)qUAG2}iY^.)5ZM:E<t@08LQ|&wze DU*A|D	|l`sl,(;/<+0zOytkQ?sW=pt"*">G`*9T{Dch!\
MJO2{FjqKF;ntAMq$`
Ox>bBg$m~2nf0T.pEtZ/$cc
[&Ou= NO2tI_YPDezifcSfp7+o8SUuOT-kJKj+J>=l,oR!tMQW[+eSC\K6c+IKe\FV`>R
BnAW(m/xuY*^bXJSj:BMhH=w 21_4n
1q(d1q
V&\*Hp'n^ 
;LNLdrA,7Zva{5u]b9	w1(
N.a0!:v	Ql @4jRHCj/H@m4.	\<(GjP%R$7<D;](}_|9gWEy%V8b*CIR|mVyyNkp:r#;{h@XR
|JUeT!bJ{)qk5d?)c&P_u?3eakGmes4S,]2Q'6
3<v)@LUFD	<w'/8E@KrY5NyX#2GCI?{-#^-6kGl/^yWgA
@<4yX
3Zga3.|Y	:
        GtkSizeRequestMode gtk_widget_get_request_mode(GtkWidget* widget);
      
        GtkToolItem* gtk_tool_button_new(GtkWidget* icon_widget, const gchar*
        label);
      
        _INITIALIZATION(`Gdk::Rectangle&amp;',`GdkRectangle', `$3 =
        Glib::wrap(&amp;($4))')
      
        _INITIALIZATION(`SizeRequestMode&amp;',`GtkSizeRequestMode',`$3 =
        ($1)($4)')
      
        _INITIALIZATION(`SizeRequestMode&amp;',`GtkSizeRequestMode',`$3 =
        (SizeRequestMode)($4)')
      
        _WRAP_CTOR(ToolButton(Widget&amp; icon_widget, const Glib::ustring&amp;
        label{?}), gtk_tool_button_new)
      
        _WRAP_METHOD(bool get_cell_rect(const TreeModel::Path&amp; path, const
        CellRenderer&amp; cell, Gdk::Rectangle&amp; rect{&gt;&gt;}) const,
        gtk_icon_view_get_cell_rect)
      
        _WRAP_METHOD(void get_request_mode(SizeRequestMode&amp; mode{OUT})
        const, gtk_widget_get_request_mode)
      
        _WRAP_METHOD(void set_device_events(Gdk::EventMask events{.}, const
        Glib::RefPtr&lt;const Gdk::Device&gt;&amp; device{.}),
        gtk_widget_set_device_events)
      
        _WRAP_METHOD(void set_device_events(Gdk::EventMask events{events},
        const Glib::RefPtr&lt;const Gdk::Device&gt;&amp; device{device}),
        gtk_widget_set_device_events)
      
        gboolean gtk_icon_view_get_cell_rect(GtkIconView* icon_view,
        GtkTreePath* path, GtkCellRenderer* cell, GdkRectangle* rect);
      
        void gtk_widget_set_device_events(GtkWidget* widget, GdkDevice* device,
        GdkEventMask events);
      
    ...
    button.signal_clicked().connect(sigc::ptr_fun(&amp;on_button_clicked));
    ...

  $ git clone git://git.gnome.org/mm-common
  $ cp -a mm-common/skeletonmm libsomethingmm

# ./configure
# make
# make install

#include &lt;gtkmm/bin.h&gt;
#include &lt;gtkmm/activatable.h&gt;
_DEFS(gtkmm,gtk)
_PINCLUDE(gtkmm/private/bin_p.h)

namespace Gtk
{

class Button
  : public Bin,
    public Activatable
{
  _CLASS_GTKOBJECT(Button,GtkButton,GTK_BUTTON,Gtk::Bin,GtkBin)
  _IMPLEMENTS_INTERFACE(Activatable)
public:

  _CTOR_DEFAULT
  explicit Button(const Glib::ustring&amp; label, bool mnemonic = false);

  _WRAP_METHOD(void set_label(const Glib::ustring&amp; label), gtk_button_set_label)

  ...

  _WRAP_SIGNAL(void clicked(), "clicked")

  ...

  _WRAP_PROPERTY("label", Glib::ustring)
};

} // namespace Gtk

#include &lt;gtkmm/button.h&gt;

class OverriddenButton : public Gtk::Button
{
protected:
    virtual void on_clicked();
}

void OverriddenButton::on_clicked()
{
    std::cout &lt;&lt; "Hello World" &lt;&lt; std::endl;

    // call the base class's version of the method:
    Gtk::Button::on_clicked();
}

#include &lt;gtkmm/button.h&gt;

void on_button_clicked()
{
    std::cout &lt;&lt; "Hello World" &lt;&lt; std::endl;
}

main()
{
    Gtk::Button button("Hello World");
    button.signal_clicked().connect(sigc::ptr_fun(&amp;on_button_clicked));
}

#include &lt;gtkmm/button.h&gt;
#include &lt;gtkmm/window.h&gt;
class Foo : public Gtk::Window
{
private:
  Gtk::Button theButton;
  // will be destroyed when the Foo object is destroyed
};

#include &lt;libsomething.h&gt;

int main(int, char**)
{
  something_init();

  std::cout &lt;&lt; get_defs(SOME_TYPE_WIDGET)
            &lt;&lt; get_defs(SOME_TYPE_STUFF);
  return 0;
}

$ ./enum.pl /usr/include/gtk-3.0/gtk/*.h &gt; gtk_enums.defs

$ ./h2def.py /usr/include/gtk-3.0/gtk/*.h &gt; gtk_methods.defs

$ cd gtk/src
$ /usr/lib/glibmm-2.4/proc/gmmproc -I ../../tools/m4 --defs . button . ./../gtkmm

$ cd tools/extra_defs_gen
$ ./generate_extra_defs &gt; gtk_signals.defs

$ for f in $(find libsomethingmm -depth -name '*skeleton*'); do \
    d="${f%/*}"; b="${f##*/}"; mv "$f" "$d/${b//skeleton/libsomething}"; \
  done

&gt; gdb with_signal
(gdb) catch throw
Catchpoint 1 (throw)
(gdb) run
Catchpoint 1 (exception thrown), 0x00714ff0 in __cxa_throw ()
(gdb) backtrace
#0  0x00714ff0 in __cxa_throw () from /usr/lib/i386-linux-gnu/libstdc++.so.6
#1  0x08048bd4 in throwSomething () at with_signal.cc:6
(gdb) continue
Continuing.
(with_signal:2375): glibmm-ERROR **
unhandled exception (type unknown) in signal handler

Program received signal SIGTRAP, Trace/breakpoint trap.

&gt; gdb with_signal
(gdb) run
(with_signal:2703): glibmm-ERROR **:
unhandled exception (type unknown) in signal handler

Program received signal SIGTRAP, Trace/breakpoint trap.
(gdb) backtrace
#2  0x0063c6ab in glibmm_unexpected_exception () at exceptionhandler.cc:77
#3  Glib::exception_handlers_invoke () at exceptionhandler.cc:150
#4  0x0063d370 in glibmm_source_callback (data=0x804d620) at main.cc:212
#13 0x002e1b31 in Gtk::Application::run (this=0x804f300) at application.cc:178
#14 0x08048ccc in main (argc=1, argv=0xbfffecd4) at with_signal.cc:16

&gt; gdb without_signal
(gdb) run
terminate called after throwing an instance of 'char const*'

Program received signal SIGABRT, Aborted.
(gdb) backtrace
#7  0x08048864 in throwSomething () at without_signal.cc:6
#8  0x0804887d in main (argc=1, argv=0xbfffecd4) at without_signal.cc:12

(gdb) catch throw
(gdb) commands
(gdb)   backtrace
(gdb)   continue
(gdb)   end
(gdb) set pagination off
(gdb) run

// _MEMBER_GET_PTR(engine_lang, lang_engine, EngineLang*, PangoEngineLang*)
// It's just a comment. It's difficult to find a real-world example.

// in a class that inherits from Gtk::Window...
Glib::RefPtr&lt;PrintOperation&gt; op = PrintOperation::create();
// ...set up op...
op-&gt;run(Gtk::PRINT_OPERATION_ACTION_PREVIEW, *this);

// in class ExampleWindow's method...
Glib::RefPtr&lt;PrintOperation&gt; op = PrintOperation::create();
// ...set up op...
op-&gt;signal_done().connect(sigc::bind(sigc::mem_fun(*this, &amp;ExampleWindow::on_printoperation_done), op));
// run the op

// with_signal.cc
#include &lt;gtkmm.h&gt;

bool throwSomething()
{
  throw "Something";
  return true;
}

int main(int argc, char** argv)
{
  Glib::signal_timeout().connect(sigc::ptr_fun(throwSomething), 500);
  Glib::RefPtr&lt;Gtk::Application&gt; app =
    Gtk::Application::create(argc, argv, "org.gtkmm.with_signal");
  app-&gt;hold();
  return app-&gt;run();
}

// without_signal.cc
#include &lt;gtkmm.h&gt;

bool throwSomething()
{
  throw "Something";
  return true;
}

int main(int argc, char** argv)
{
  throwSomething();
  Glib::RefPtr&lt;Gtk::Application&gt; app =
    Gtk::Application::create(argc, argv, "org.gtkmm.without_signal");
  return app-&gt;run();
}

//Within a class that inherits from Gtk::Window and keeps m_refPageSetup and m_refSettings as members...
Glib::RefPtr&lt;Gtk::PageSetup&gt; new_page_setup = Gtk::run_page_setup_dialog(*this, m_refPageSetup, m_refSettings);
m_refPageSetup = new_page_setup;

Button::Button(const Glib::ustring&amp; label, bool mnemonic)
:
  _CONSTRUCT("label", label.c_str(), "use_underline", gboolean(mnemonic))
{}

DerivedDialog* pDialog = 0;
builder-&gt;get_widget_derived("DialogBasic", pDialog);

DerivedDialog::DerivedDialog(BaseObjectType* cobject, const Glib::RefPtr&lt;Gtk::Builder&gt;&amp; builder)
: Gtk::Dialog(cobject)
{
}

DerivedDialog::DerivedDialog(BaseObjectType* cobject, const Glib::RefPtr&lt;Gtk::Builder&gt;&amp; builder)
: Gtk::Dialog(cobject),
  m_builder(builder),
  m_pButton(0)
{
  //Get the Glade-instantiated Button, and connect a signal handler:
  m_builder-&gt;get_widget("quit_button", m_pButton);
  if(m_pButton)
  {
    m_pButton-&gt;signal_clicked().connect( sigc::mem_fun(*this, &amp;DerivedDialog::on_button_quit) );
  }
}

Glib::RefPtr&lt;Gdk::Pixbuf&gt; pixbuf = Gdk::Pixbuf::create_from_file(filename);

Glib::RefPtr&lt;Gdk::Pixbuf&gt; pixbuf2 = pixbuf;

Glib::RefPtr&lt;Gdk::Pixbuf&gt; refPixbuf = Gdk::Pixbuf::create_from_file(filename);
Gdk::Pixbuf&amp; underlying = *refPixbuf; //Syntax error - will not compile.

Glib::RefPtr&lt;Gdk::Pixbuf&gt; refPixbuf = Gdk::Pixbuf::create_from_file(filename);
Glib::RefPtr&lt;Gdk::Pixbuf&gt; refPixbuf2 = refPixbuf;

Glib::RefPtr&lt;Gdk::Pixbuf&gt; refPixbuf = Gdk::Pixbuf::create_from_file(filename);
int width = refPixbuf-&gt;get_width();

Glib::RefPtr&lt;Gtk::Builder&gt; builder = Gtk::Builder::create_from_file("basic.glade");

Glib::RefPtr&lt;Gtk::Builder&gt; builder = Gtk::Builder::create_from_file("basic.glade", "treeview_products");

Glib::RefPtr&lt;Gtk::PrintOperation&gt; op = Gtk::PrintOperation::create();
// ...set up op...
op-&gt;set_export_filename("test.pdf");
Gtk::PrintOperationResult res = op-&gt;run(Gtk::PRINT_OPERATION_ACTION_EXPORT);

Glib::RefPtr&lt;Gtk::TreeModel&gt; refModel = m_TreeView.get_model();
if(refModel)
{
  int cols_count = refModel-&gt;get_n_columns();
  ...
}

Glib::RefPtr&lt;Gtk::TreeStore&gt; refStore =
Glib::RefPtr&lt;Gtk::TreeStore&gt;::cast_dynamic(refModel);
Glib::RefPtr&lt;Gtk::TreeStore&gt; refStore2 =
Glib::RefPtr&lt;Gtk::TreeStore&gt;::cast_static(refModel);

Glib::RefPtr&lt;Gtk::TreeStore&gt; refStore = Gtk::TreeStore::create(columns);
Glib::RefPtr&lt;Gtk::TreeModel&gt; refModel = refStore;

Glib::SignalProxy1&lt;bool, Gtk::DirectionType&gt; signal_focus()

Glib::SignalProxy3&lt;void, const TextBuffer::iterator&amp;, const Glib::ustrin&amp;, int&gt; signal_insert();

Gtk::Button* button = new Gtk::Button("example");
gtk_button_do_something_new(button-&gt;gobj());

Gtk::Button* pButton = new Gtk::Button("Test");

// do something useful with pButton

delete pButton;

Gtk::Dialog* pDialog = 0;
builder-&gt;get_widget("DialogBasic", pDialog);

Gtk::ToolButton* button = Gtk::manage(new Gtk::ToolButton(icon, "Big"));
button-&gt;set_tooltip_text("Big Brush);
group_brushes-&gt;insert(*button);

Gtk::ToolItemGroup* group_brushes =
  Gtk::manage(new Gtk::ToolItemGroup("Brushes"));
m_ToolPalette.add(*group_brushes);

Gtk::Widget* CustomPrintOperation::on_create_custom_widget()
{
  set_custom_tab_label("My custom tab");

  Gtk::Box* hbox = new Gtk::Box(Gtk::ORIENTATION_HORIZONTAL, 8);
  hbox-&gt;set_border_width(6);

  Gtk::Label* label = Gtk::manage(new Gtk::Label("Enter some text: "));
  hbox-&gt;pack_start(*label, false, false);
  label-&gt;show();

  hbox-&gt;pack_start(m_Entry, false, false);
  m_Entry.show();

  return hbox;
}

void CustomPrintOperation::on_custom_widget_apply(Gtk::Widget* /* widget */)
{
  Glib::ustring user_input = m_Entry.get_text();
  //...
}

GtkButton* cbutton = get_a_button();
Gtk::Button* button = Glib::wrap(cbutton);

GtkWidget* example_widget_new(int something, const char* thing)
{
        ExampleWidget* widget;
        widget = g_object_new (EXAMPLE_TYPE_WIDGET, NULL);
        example_widget_construct(widget, "something", something, "thing", thing);
}

void example_widget_construct(ExampleWidget* widget, int something, const char* thing)
{
        //Do stuff that uses private API:
        widget-&gt;priv-&gt;thing = thing;
        do_something(something);
}

GtkWidget* example_widget_new(int something, const char* thing)
{
        return g_object_new (EXAMPLE_TYPE_WIDGET, "something", something, "thing", thing, NULL);
}

MyContainer::MyContainer()
{
  Gtk::Button* pButton = Gtk::manage(new Gtk::Button("Test"));
  add(*pButton); //add *pButton to MyContainer
}

_CLASS_BOXEDTYPE(RGBA, GdkRGBA, NONE, gdk_rgba_copy, gdk_rgba_free)

_CLASS_BOXEDTYPE_STATIC(Rectangle, GdkRectangle)

_CLASS_GENERIC(AttrIter, PangoAttrIterator)

_CLASS_GOBJECT(AccelGroup, GtkAccelGroup, GTK_ACCEL_GROUP, Glib::Object, GObject)

_CLASS_GTKOBJECT(Button, GtkButton, GTK_BUTTON, Gtk::Bin, GtkBin)

_CLASS_INTERFACE(CellEditable, GtkCellEditable, GTK_CELL_EDITABLE, GtkCellEditableIface)

_CLASS_INTERFACE(LoadableIcon, GLoadableIcon, G_LOADABLE_ICON, GLoadableIconIface, Icon, GIcon)

_CLASS_OPAQUE_COPYABLE(Checksum, GChecksum, NONE, g_checksum_copy, g_checksum_free)

_CLASS_OPAQUE_REFCOUNTED(Coverage, PangoCoverage, pango_coverage_new, pango_coverage_ref, pango_coverage_unref)

_CONVERSION(`GtkTreeView*',`TreeView*',`Glib::wrap($3)')

_CONVERSION(`PrintSettings&amp;',`GtkPrintSettings*',__FR2P)
_CONVERSION(`const PrintSettings&amp;',`GtkPrintSettings*',__FCR2P)
_CONVERSION(`const Glib::RefPtr&lt;Printer&gt;&amp;',`GtkPrinter*',__CONVERT_REFPTR_TO_P($3))

_IGNORE(gtk_button_box_set_spacing, gtk_button_box_get_spacing)

_IMPLEMENTS_INTERFACE(Activatable)

_INITIALIZATION(`Gtk::Widget&amp;',`GtkWidget*',`$3 = Glib::wrap($4)')

_MEMBER_GET_GOBJECT(layout, layout, Pango::Layout, PangoLayout*)

_WRAP_ENUM(IconLookupFlags, GtkIconLookupFlags, NO_GTYPE)

_WRAP_ENUM(WindowType, GtkWindowType)

_WRAP_GERROR(PixbufError, GdkPixbufError, GDK_PIXBUF_ERROR)

_WRAP_METHOD(void set_text(const Glib::ustring&amp; text), gtk_entry_set_text)

_WRAP_METHOD_DOCS_ONLY(gtk_container_remove)

_WRAP_PROPERTY("label", Glib::ustring)

_WRAP_SIGNAL(void clicked(),"clicked")

_WRAP_VFUNC(SizeRequestMode get_request_mode() const, get_request_mode)

bool MyCallback() { std::cout &lt;&lt; "Hello World!\n" &lt;&lt; std::endl; return true; }

bool idleFunc();

bool input_callback(Glib::IOCondition condition);

bool on_button_press(GdkEventButton* event);
Gtk::Button button("label");
button.signal_button_press_event().connect( sigc::ptr_fun(&amp;on_button_press) );

bool on_key_press_or_release_event(GdkEventKey* event)
{
  if (event-&gt;type == GDK_KEY_PRESS &amp;&amp;
    event-&gt;keyval == GDK_KEY_1 &amp;&amp;
    (event-&gt;state &amp; (GDK_SHIFT_MASK | GDK_CONTROL_MASK | GDK_MOD1_MASK)) == GDK_MOD1_MASK)
  {
    handle_alt_1_press(); // GDK_MOD1_MASK is normally the Alt key
    return true;
  }
  return false;
}

Gtk::Entry m_entry; // in a class definition

// in the class constructor
m_entry.signal_key_press_event().connect( sigc::ptr_fun(&amp;on_key_press_or_release_event) );
m_entry.signal_key_release_event().connect( sigc::ptr_fun(&amp;on_key_press_or_release_event) );
m_entry.add_events(Gdk::KEY_PRESS_MASK | Gdk::KEY_RELEASE_MASK);

button.signal_button_press_event().connect( sigc::ptr_fun(&amp;on_mywindow_button_press), false );

class Server
{
public:
  //signal accessor:
  typedef sigc::signal&lt;void, bool, int&gt; type_signal_something;
  type_signal_something signal_something();

protected:
  type_signal_something m_signal_something;
};

Server::type_signal_something Server::signal_something()
{
  return m_signal_something;
}

class TextMark : public Glib::Object
{
  _CLASS_GOBJECT(TextMark, GtkTextMark, GTK_TEXT_MARK, Glib::Object, GObject)

protected:
  _WRAP_CTOR(TextMark(const Glib::ustring&amp; name, bool left_gravity = true), gtk_text_mark_new)

public:
  _WRAP_CREATE(const Glib::ustring&amp; name, bool left_gravity = true)

example-widget.h:56: error: using typedef-name 'ExampleWidget' after 'struct'
../../libexample/libexamplemm/example-widget.h:34: error: 'ExampleWidget' has a previous declaration here
make[4]: *** [example-widget.lo] Error 1

example-widget.h:60: error: '_ExampleWidget ExampleWidget' redeclared as different kind of symbol
../../libexample/libexamplemm/example-widget.h:34: error: previous declaration of 'typedef struct _ExampleWidget ExampleWidget'

int width = 0;
if(pixbuf)
{
  width = pixbuf-&gt;get_width();
}

m_button1.signal_clicked().connect( sigc::bind&lt;Glib::ustring&gt;( sigc::mem_fun(*this, &amp;HelloWorld::on_button_clicked), "button 1") );

my_connection.disconnect();

server.signal_something().connect(
  sigc::mem_fun(client, &amp;Client::on_server_something) );

sigc::connection  Glib::SignalIdle::connect(const sigc::slot&lt;bool&gt;&amp; slot,
                                    int priority = Glib::PRIORITY_DEFAULT_IDLE);

sigc::connection Glib::SignalIO::connect(const sigc::slot&lt;bool,Glib::IOCondition&gt;&amp; slot,
                                 int fd, Glib::IOCondition condition,
                                 int priority = Glib::PRIORITY_DEFAULT);

sigc::connection Glib::SignalTimeout::connect(const sigc::slot&lt;bool&gt;&amp; slot,
                                      unsigned int interval, int priority = Glib::PRIORITY_DEFAULT);

sigc::signal&lt;void, bool, int&gt; signal_something;

sigc::signal&lt;void,int&gt;::iterator signal&lt;void,int&gt;::connect( const sigc::slot&lt;void,int&gt;&amp; );

std::list&lt; Glib::RefPtr&lt;Gdk::Pixbuf&gt; &gt; listPixbufs;
Glib::RefPtr&lt;Gdk::Pixbuf&gt; refPixbuf = Gdk::Pixbuf::create_from_file(filename);
listPixbufs.push_back(refPixbuf);

typedef struct _ExampleWidget ExampleWidget;

struct _ExampleWidget
{
  ...
};

virtual void on_button_clicked(Glib::ustring data);

void ExampleWindow::on_printoperation_done(Gtk::PrintOperationResult result, const Glib::RefPtr&lt;PrintOperation&gt;&amp; op)
{
  if (result == Gtk::PRINT_OPERATION_RESULT_ERROR)
    //notify user
  else if (result == Gtk::PRINT_OPERATION_RESULT_APPLY)
    //Update PrintSettings with the ones used in this PrintOperation

  if (! op-&gt;is_finished())
    op-&gt;signal_status_changed().connect(sigc::bind(sigc::mem_fun(*this, &amp;ExampleWindow::on_printoperation_status_changed), op));
}

void ExampleWindow::on_printoperation_status_changed(const Glib::RefPtr&lt;PrintFormOperation&gt;&amp; op)
{
  if (op-&gt;is_finished())
    //the print job is finished
  else
    //get the status with get_status() or get_status_string()

  //update UI
}

void init()
{
  Gtk::Main::init_gtkmm_internals(); //Sets up the g type system and the Glib::wrap() table.
  wrap_init(); //Tells the Glib::wrap() table about the libsomethingmm classes.
}

void on_button_clicked();

class some_class
{
    void on_button_clicked();
};

some_class some_object;

main()
{
    Gtk::Button button;
    button.signal_clicked().connect( sigc::ptr_fun(&amp;on_button_clicked) );
    button.signal_clicked().connect( sigc::mem_fun(some_object, &amp;some_class::on_button_clicked) );
}

void on_insert(const TextBuffer::iterator&amp; pos, const Glib::ustring&amp; text, int bytes)

{
  Gtk::Button aButton;
  aButton.show();
  ...
  app-&gt;run();
}
"Hidden" Columns# keep this file sorted alphabetically, one language code per line
de
ja#include &lt;gtkmm.h&gt;#m4 _CONVERSION(`GSList*',`std::vector&lt;Widget*&gt;',`Glib::SListHandler&lt;Widget*&gt;::slist_to_vector($3, Glib::OWNERSHIP_SHALLOW)')$ ./plug &amp;$ ./socket(An aside: <application>GTK+</application> calls this scheme "signalling"; the sharp-eyed reader with GUI toolkit experience will note that this same design is often seen under the name of "broadcaster-listener" (e.g., in Metrowerks' PowerPlant framework for the Macintosh). It works in much the same way: one sets up <literal>broadcasters</literal>, and then connects <literal>listeners</literal> to them; the broadcaster keeps a list of the objects listening to it, and when someone gives the broadcaster a message, it calls all of its objects in its list with the message. In <application>gtkmm</application>, signal objects play the role of broadcasters, and slots play the role of listeners - sort of. More on this later.)(In addition, you'd have the files <literal>ja.po</literal> and <literal>de.po</literal> in your <literal>po</literal> directory which contain the German and Japanese translations, respectively.)./docextract_to_xml.py -s ~/checkout/gnome/gtk+/gtk/ &gt; gtk_docs.xml
// creates its own adjustments
Gtk::TextView textview;
// uses the newly-created adjustment for the scrollbar as well
Gtk::Scrollbar vscrollbar (textview.get_vadjustment(), Gtk::ORIENTATION_VERTICAL);// note to translators: don't translate the "[noun]" part - it is
// just here to distinguish the string from another "jumps" string
text = strip(gettext("jumps[noun]"), "[noun]");//compiler error - no conversion from ustring to int.
int number = row[m_Columns.m_col_text];2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010<application>Gtk::Builder</application> checks for a null pointer, and checks that the widget is of the expected type, and will show warnings on the command line about these.<application>glibmm</application> provides the normal set of thread launching functions, mutexes, condition variables and scoped locking classes required for writing multi-threaded programs using C++.<application>gtkmm</application> 3 added some new classes:<application>gtkmm</application> 3 also made several small changes to the API, which you will probably encounter when porting code that used <application>gtkmm</application>-2.4. Here is a short list:<application>gtkmm</application> 3's library is called <literal>libgtkmm-3.0</literal> rather than <literal>libgtkmm-2.4</literal> and installs its headers in a similarly-versioned directory, so your pkg-config check should ask for <literal>gtkmm-3.0</literal> rather than <literal>gtkmm-2.4</literal>.<application>gtkmm</application> allows the programmer to control the lifetime (that is, the construction and destruction) of any widget in the same manner as any other C++ object. This flexibility allows you to use <literal>new</literal> and <literal>delete</literal> to create and destroy objects dynamically or to use regular class members (that are destroyed automatically when the class is destroyed) or to use local instances (that are destroyed when the instance goes out of scope). This flexibility is not present in some C++ GUI toolkits, which restrict the programmer to only a subset of C++'s memory management features.<application>gtkmm</application> allows you to write code using normal C++ techniques such as encapsulation, derivation, and polymorphism. As a C++ programmer you probably already realise that this leads to clearer and better organized code.<application>gtkmm</application> and Win32<application>gtkmm</application> applications can easily support multiple languages, including non-European languages such as Chinese and right-to-left languages such as Arabic. An appropriately-written and translated <application>gtkmm</application> application will use the appropriate language at runtime based on the user's environment.<application>gtkmm</application> applications consist of windows containing widgets, such as buttons and text boxes. In some other systems, widgets are called "controls". For each widget in your application's windows, there is a C++ object in your application's code. So you just need to call a method of the widget's class to affect the visible widget.<application>gtkmm</application> arranges widgets hierarchically, using <emphasis>containers</emphasis>. A Container widget contains other widgets. Most <application>gtkmm</application> widgets are containers. Windows, Notebook tabs, and Buttons are all container widgets. There are two flavours of containers: single-child containers, which are all descendants of <classname>Gtk::Bin</classname>, and multiple-child containers, which are descendants of <classname>Gtk::Container</classname>. Most widgets in <application>gtkmm</application> are descendants of <classname>Gtk::Bin</classname>, including <classname>Gtk::Window</classname>.<application>gtkmm</application> classes are designed with overriding in mind; they contain virtual member methods specifically intended to be overridden.<application>gtkmm</application> compared to Qt<application>gtkmm</application> currently works with the <ulink url="http://mingw.org/">MingW/GCC3.4 compiler</ulink> and Microsoft Visual C++ 2005 or later (including the freely available express editions) on the Windows platform. There is an <ulink url="ftp://ftp.gnome.org/pub/GNOME/binaries/win32/gtkmm"> installer</ulink> available for gtkmm on Microsoft Windows. Refer to <ulink url="https://wiki.gnome.org/Projects/gtkmm/MSWindows/"> https://wiki.gnome.org/Projects/gtkmm/MSWindows</ulink> for instructions how to use it.<application>gtkmm</application> developers tend to prefer <application>gtkmm</application> to Qt because <application>gtkmm</application> does things in a more C++ way. Qt originates from a time when C++ and the standard library were not standardised or well supported by compilers. It therefore duplicates a lot of stuff that is now in the standard library, such as containers and type information. Most significantly, Trolltech modified the C++ language to provide signals, so that Qt classes cannot be used easily with non-Qt classes. <application>gtkmm</application> was able to use standard C++ to provide signals without changing the C++ language. See the <ulink url="https://wiki.gnome.org/Projects/gtkmm/FAQ">FAQ</ulink> for more detailed differences.<application>gtkmm</application> has various widgets that can be visually adjusted using the mouse or the keyboard, such as the <classname>Range</classname> widgets (described in the <link linkend="chapter-range-widgets">Range Widgets</link> section). There are also a few widgets that display some adjustable part of a larger area, such as the <classname>Viewport</classname> widget. These widgets have <classname>Gtk::Adjustment</classname> objects that express this common part of their API.<application>gtkmm</application> involves less code compared to GTK+, which uses prefixed function names and lots of cast macros.<application>gtkmm</application> is a C++ wrapper for <ulink url="http://www.gtk.org/">GTK+</ulink>, a library used to create graphical user interfaces. It is licensed using the LGPL license, so you can develop open software, free software, or even commercial non-free software using <application>gtkmm</application> without purchasing licenses.<application>gtkmm</application> is a wrapper<application>gtkmm</application> is more type-safe, so the compiler can detect errors that would only be detected at run time when using C. This use of specific types also makes the API clearer because you can see what types should be used just by looking at a method's declaration.<application>gtkmm</application> is not a native C++ toolkit, but a C++ wrapper of a C toolkit. This separation of interface and implementation has advantages. The <application>gtkmm</application> developers spend most of their time talking about how <application>gtkmm</application> can present the clearest API, without awkward compromises due to obscure technical details. We contribute a little to the underlying GTK+ code base, but so do the C coders, and the Perl coders and the Python coders, etc. Therefore GTK+ benefits from a broader user base than language-specific toolkits - there are more implementers, more developers, more testers, and more users.<application>gtkmm</application> makes it very easy to derive new widgets by inheriting from an existing widget class, either by deriving from a container and adding child widgets, or by deriving from a single-item widget, and changing its behaviour. But you might occasionally find that no suitable starting point already exists. In this case, you can implement a widget from scratch.<application>gtkmm</application> provides an easy way to manage recently used documents. The classes involved in implementing this functionality are <classname>RecentManager</classname>, <classname>RecentChooserDialog</classname>, <classname>RecentChooserMenu</classname>, <classname>RecentChooserWidget</classname>, <classname>RecentAction</classname>, and <classname>RecentFilter</classname>.<application>gtkmm</application> provides four basic types of buttons:<application>gtkmm</application> provides the <function>manage()</function> function and <methodname>add()</methodname> methods to create and destroy widgets. Every widget except a top-level window must be added or packed into a container in order to be displayed. The <function>manage()</function> function marks a widget so that when the widget is added to a container, the container becomes responsible for deleting the widget.<application>gtkmm</application> signal handlers are strongly-typed, whereas <application>GTK+</application> C code allows you to connect a callback with the wrong number and type of arguments, leading to a segfault at runtime. And, unlike <application>Qt</application>, <application>gtkmm</application> achieves this without modifying the C++ language.<application>gtkmm</application> uses the <command>gmmproc</command> tool to generate most of its source code, using .defs files that define the APIs of <classname>GObject</classname>-based libraries. So it's quite easy to create additional gtkmm-style wrappers of other glib/GObject-based libraries.<application>gtkmm</application> uses the libsigc++ library to implement signals. Here is an example line of code that connects a Gtk::Button's "clicked" signal with a signal handler called "on_button_clicked": <placeholder-1/><application>gtkmm</application> uses the packing system to solve these problems. Rather than specifying the position and size of each widget in the window, you can arrange your widgets in rows, columns, and/or grids. <application>gtkmm</application> can size your window automatically, based on the sizes of the widgets it contains. And the sizes of the widgets are, in turn, determined by the amount of text they contain, or the minimum and maximum sizes that you specify, and/or how you have requested that the available space should be shared between sets of widgets. You can perfect your layout by specifying padding distance and centering values for each of your widgets. <application>gtkmm</application> then uses all this information to resize and reposition everything sensibly and smoothly when the user manipulates the window.<application>gtkmm</application> was originally named gtk-- because GTK+ already has a + in the name. However, as -- is not easily indexed by search engines the package generally went by the name <application>gtkmm</application>, and that's what we stuck with.<application>gtkmm</application> widget classes have signal accessor methods, such as <methodname>Gtk::Button::signal_clicked()</methodname>, which allow you to connect your signal handler. Thanks to the flexibility of <application>libsigc++</application>, the callback library used by <application>gtkmm</application>, the signal handler can be almost any kind of function, but you will probably want to use a class method. Among <application>GTK+</application> C coders, these signal handlers are often named callbacks.<application>gtkmm</application>, like most GUI toolkits, is <emphasis>event-driven</emphasis>. When an event occurs, such as the press of a mouse button, the appropriate signal will be <emphasis>emitted</emphasis> by the Widget that was pressed. Each Widget has a different set of signals that it can emit. To make a button click result in an action, we set up a <emphasis>signal handler</emphasis> to catch the button's "clicked" signal.<application>gtkmm</application>-3.0 is a new version of the <application>gtkmm</application> API that installs in parallel with the older <application>gtkmm</application>-2.4 API. The last version of the <application>gtkmm</application>-2.4 API was <application>gtkmm</application> 2.24. <application>gtkmm</application> 3 has no major fundamental differences to <application>gtkmm</application> 2 but does make several small changes that were not possible while maintaining binary compatibility. If you never used the <application>gtkmm</application>-2.4 API then you can safely ignore this chapter.<application>intltool</application> / <application>xgettext</application> script extracts the strings and puts them in a <filename>mypackage.pot</filename> file. The translators of your application create their translations by first copying this <filename>.pot</filename> file to a <filename>localename.po</filename> file. A locale identifies a language and an encoding for that language, including date and numerical formats. Later, when the text in your source code has changed, the <literal>msmerge</literal> script is used to update the <filename>localename.po</filename> files from the regenerated <filename>.pot</filename> file.<classname>ButtonBox</classname>es help to make applications appear consistent because they use standard settings, such as inter-button spacing and packing.<classname>Gdk::Drawable</classname> was removed, with its methods moving into <classname>Gdk::Window</classname>.<classname>Gdk::Pixmap</classname> and <classname>Gdk::Bitmap</classname> were removed in favour of <classname>Gdk::Pixbuf</classname>.<classname>Gdk::RGBA</classname> replaces <classname>Color</classname>, adding an alpha component for opacity. <classname>Colormap</classname> was removed, along with its awkward use to allocate colors.<classname>Glib::ListHandle&lt;Gtk::Widget*&gt;</classname>: Use <classname>std::vector&lt;Gtk::Widget*&gt;</classname>, <classname>std::list&lt;Gtk::Widget*&gt;</classname>, etc.<classname>Glib::RefPtr</classname> is a smartpointer. Specifically, it is a reference-counting smartpointer. You might be familiar with <classname>std::auto_ptr&lt;&gt;</classname>, <classname>std::unique_ptr&lt;&gt;</classname> and <classname>std::shared_ptr&lt;&gt;</classname>, which are also smartpointers. <classname>Glib::RefPtr&lt;&gt;</classname> is similar to <classname>std::shared_ptr&lt;&gt;</classname>, which is also reference-counting. <classname>Glib::RefPtr&lt;&gt;</classname> was introduced long before there was a reference-counting smartpointer in the C++ Standard Library.<classname>Glib::SListHandle&lt;Gtk::Widget*&gt;</classname>: Use <classname>std::vector&lt;Gtk::Widget*&gt;</classname>, <classname>std::list&lt;Gtk::Widget*&gt;</classname>, etc.<classname>Glib::StringArrayHandle</classname> or <classname>Glib::ArrayHandle&lt;Glib::ustring&gt;</classname>: Use <classname>std::vector&lt;Glib::ustring&gt;</classname>, <classname>std::list&lt;Glib::ustring&gt;</classname>, <type>const char*[]</type>, etc.<classname>Gtk::Adjustment</classname> and <classname>IconSet</classname> and <classname>Gdk::Cursor</classname> are now used via <classname>Glib::RefPtr</classname>.<classname>Gtk::AppChooser</classname>, <classname>Gtk::AppChooserButton</classname>, <classname>Gtk::AppChooserDialog</classname> allow the user to select an installed application to open a particular type of content.<classname>Gtk::Box</classname> arranges its child widgets vertically or horizontally. Use <methodname>pack_start()</methodname> and <methodname>pack_end()</methodname> to insert child widgets.<classname>Gtk::Box</classname>, <classname>Gtk::ButtonBox</classname>, <classname>Gtk::IconView</classname>, <classname>Gtk::Paned</classname>, <classname>Gtk::ProgressBar</classname>, <classname>Gtk::ScaleButton</classname>, <classname>Gtk::Scrollbar</classname> and <classname>Gtk::Separator</classname> now derive from <classname>Gtk::Orientable</classname>, allowing their orientation (vertical or horizontal) to be specified without requiring the use of a derived class such as <classname>Gtk::HBox</classname>.<classname>Gtk::Builder</classname> must be used via a <classname>Glib::RefPtr</classname>. Like all such classes, you need to use a <methodname>create()</methodname> method to instantiate it. For instance, <placeholder-1/> This will instantiate the windows defined in the .glade file, though they will not be shown immediately unless you have specified that via the <guilabel>Properties</guilabel> window in <application>Glade</application>.<classname>Gtk::Button</classname> is also a container so you could put any other widget, such as a <classname>Gtk::Image</classname> into it.<classname>Gtk::CellLayout</classname>, used by <classname>Gtk::IconView</classname>, <classname>Gtk::TreeView::Column</classname> and <classname>Gtk::ComboBox</classname>, now has a <classname>Gtk::CellArea</classname> which can be used to specify more details of how the <classname>CellRenderer</classname>s are arranged and aligned.<classname>Gtk::CheckButton</classname> inherits from <classname>Gtk::ToggleButton</classname>. The only real difference between the two is <classname>Gtk::CheckButton</classname>'s appearance. You can check, set, and toggle a checkbox using the same member methods as for <classname>Gtk::ToggleButton</classname>.<classname>Gtk::Grid</classname> arranges its child widgets in rows and columns. Use <methodname>attach()</methodname>, <methodname>attach_next_to()</methodname> and <methodname>add()</methodname> to insert child widgets.<classname>Gtk::Grid</classname> is a new container widget that will eventually replace <classname>Gtk::Box</classname> and <classname>Gtk::Table</classname>. It arranges its children according to properties of those children rather than its own layout details.<classname>Gtk::IconView</classname>, <classname>Gtk::TextView</classname>, <classname>Gtk::TreeView</classname> and other widgets derive from Scrollable instead of having their own methods such as <methodname>get_vadjustment()</methodname> and instead of having their own set_scroll_adjustments signal.<classname>Gtk::Scale</classname> and <classname>Gtk::Scrollbar</classname> both inherit from <classname>Gtk::Range</classname> and share much functionality. They contain a "trough" and a "slider" (sometimes called a "thumbwheel" in other GUI environments). Dragging the slider with the pointer moves it within the trough, while clicking in the trough advances the slider towards the location of the click, either completely, or by a designated amount, depending on which mouse button is used. This should be familiar scrollbar behaviour.<classname>Gtk::Scale</classname> widgets (or "sliders") allow the user to visually select and manipulate a value within a specific range. You might use one, for instance, to adjust the magnification level on a zoomed preview of a picture, or to control the brightness of a colour, or to specify the number of minutes of inactivity before a screensaver takes over the screen.<classname>Gtk::Style</classname> and <classname>Gtk::Rc</classname> were removed, replaced by <classname>Gtk::StyleContext</classname>, and <classname>Gtk::StyleProvider</classname>s, such as <classname>Gtk::CssProvider</classname>.<classname>Gtk::Switch</classname> displays On/Off states more explictly than <classname>Gtk::CheckBox</classname>. It may be useful, for instance, when allowing users to activate hardware.<classname>Gtk::Table</classname> allows us to place widgets in a grid, similar to <classname>Gtk::Grid</classname>.<classname>Gtk::Table</classname> is deprecated from <application>gtkmm</application> version 3.4 and should not be used in newly-written code. Use <classname>Gtk::Grid</classname> instead.<classname>Gtk::TargetEntry</classname> objects contain this information: <placeholder-1/><classname>Gtk::TextBuffer</classname> is a model containing the data for the <classname>Gtk::TextView</classname>, like the <classname>Gtk::TreeModel</classname> used by <classname>Gtk::TreeView</classname>. This allows two or more <classname>Gtk::TextView</classname>s to share the same <classname>TextBuffer</classname>, and allows those TextBuffers to be displayed slightly differently. Or you could maintain several <classname>Gtk::TextBuffer</classname>s and choose to display each one at different times in the same <classname>Gtk::TextView</classname> widget.<classname>Gtk::TextView</classname> has various <methodname>scroll_to_*()</methodname> methods. These allow you to ensure that a particular part of the text buffer is visible. For instance, your application's Find feature might use <methodname>Gtk::TextView::scroll_to_iter()</methodname> to show the found text.<classname>Gtk::ToggleButton</classname> is most useful as a base class for the <classname>Gtk::CheckButton</classname> and <classname>Gtk::RadioButton</classname> classes.<classname>Gtk::ToolItem</classname>s can then be added to the group. For instance, like so:<classname>Gtk::TreeModel</classname> provides a C++ Standard Library-style container of its children, via the <methodname>children()</methodname> method. You can use the familiar <methodname>begin()</methodname> and <methodname>end()</methodname> methods iterator incrementing, like so:<classname>Gtk::TreeStore</classname> models can have child items. Add them with the <methodname>append()</methodname>, <methodname>prepend()</methodname>, or <methodname>insert()</methodname> methods, like so:<classname>Gtk::TreeView</classname> already implements simple drag-and-drop when used with the <classname>Gtk::ListStore</classname> or <classname>Gtk::TreeStore</classname> models. If necessary, it also allows you to implement more complex behaviour when items are dragged and dropped, using the normal <link linkend="chapter-draganddrop">Drag and Drop</link> API.<classname>Gtk::Widget</classname> has several methods and signals which are prefixed with "drag_". These are used for Drag and Drop.<classname>Menus</classname> are normally just added to a window, but they can also be displayed temporarily as the result of a mouse button click. For instance, a context menu might be displayed when the user clicks their right mouse button.<classname>MessageDialog</classname> is a convenience class, used to create simple, standard message dialogs, with a message, an icon, and buttons for user response. You can specify the type of message and the text in the constructor, as well as specifying standard buttons via the <literal>Gtk::ButtonsType</literal> enum.<classname>RadioButtons</classname> are "off" when created; this means that when you first make a group of them, they will all be off. Don't forget to turn one of them on using <methodname>set_active()</methodname>:<classname>Range</classname> widgets typically connect a handler to this signal, which changes their appearance to reflect the change - for example, the size of the slider in a scrollbar will grow or shrink in inverse proportion to the difference between the <parameter>lower</parameter> and <parameter>upper</parameter> values of its <classname>Adjustment</classname>.<classname>RecentChooser</classname> is an interface that can be implemented by widgets displaying the list of recently used files. <application>gtkmm</application> provides four built-in implementations for choosing recent files: <classname>RecentChooserWidget</classname>, <classname>RecentChooserDialog</classname>, <classname>RecentChooserMenu</classname>, and <classname>RecentAction</classname>.<classname>RecentChooserMenu</classname> and <classname>RecentAction</classname> allow you to list recently used files as a menu.<classname>RecentChooserWidget</classname> is a simple widget for displaying a list of recently used files. <classname>RecentChooserWidget</classname> is the basic building block for <classname>RecentChooserDialog</classname>, but you can embed it into your user interface if you want to.<classname>RecentManager</classname> acts as a database of recently used files. You use this class to register new files, remove files from the list, or look up recently used files. There is one list of recently used files per user.<classname>RecentManager</classname> is the model of a model-view pattern, where the view is a class that implements the <classname>RecentChooser</classname> interface.<classname>Scale</classname> widgets can display their current value as a number next to the trough. By default they show the value, but you can change this with the <methodname>set_draw_value()</methodname> method.<classname>ScrolledWindow</classname> widgets create a scrollable area. You can insert any type of widget into a <classname>ScrolledWindow</classname> window, and it will be accessible regardless of its size by using the scrollbars. Note that <classname>ScrolledWindow</classname> is not a <classname>Gtk::Window</classname> despite the slightly misleading name.<classname>SpinButton</classname>s use an <link linkend="chapter-adjustment">Adjustment</link> object to hold information about the range of values. These Adjustment attributes are used by the Spin Button like so: <placeholder-1/><classname>TextBuffer</classname> iterators are generally invalidated when the text changes, but you can use a <classname>Gtk::TextBuffer::Mark</classname> to remember a position in these situations. For instance,<classname>TextView</classname> has various methods which allow you to change the presentation of the buffer for this particular view. Some of these may be overridden by the <classname>Gtk::TextTag</classname>s in the buffer, if they specify the same things. For instance, <methodname>set_left_margin()</methodname>, <methodname>set_right_margin()</methodname>, <methodname>set_indent()</methodname>, etc.<classname>ToggleButton</classname>s are like normal <classname>Button</classname>s, but when clicked they remain activated, or pressed, until clicked again.<classname>ToolItemGroup</classname>s should be added to the tool palette via the base class's <function>Gtk::Container::add()</function> method, for instance like so:<classname>Widget</classname>s can be identified as sources or destinations using these <classname>Gtk::Widget</classname> methods:<command>gmmproc</command> allows processing the parameters in a method signature for the macros that process method signatures (like <function>_WRAP_METHOD()</function>, <function>_WRAP_CTOR()</function> and <function>_WRAP_CREATE()</function>) in a variety of ways:<command>gmmproc</command> will warn you on stdout about functions and signals that you have forgotten to wrap, helping to ensure that you are wrapping the complete API. But if you don't want to wrap some functions or signals, or if you chose to hand-code some methods then you can use the _IGNORE() or _IGNORE_SIGNAL() macro to make <command>gmmproc</command> stop complaining.<filename>libsomething</filename>: Contains the main include file and the pkg-config .pc file.<filename>libsomethingmm</filename>: Contains generated and hand-written .h and .cc files.<filename>libsomethingmm</filename>: The top-level directory.<filename>private</filename>: Contains generated <filename>*_p.h</filename> files.<filename>src</filename>: Contains .hg and .ccg source files.<function>_WRAP_METHOD()</function> also supports setting C++ output parameters from C output parameters if the C function being wrapped has any. Suppose, for example, that we want to wrap the following C function that returns a value in its C output parameter <parameter>rect</parameter>: <placeholder-1/> To have <command>gmmproc</command> place the value returned in the C++ <parameter>rect</parameter> output parameter, something like the following <function>_WRAP_METHOD()</function> directive could be used: <placeholder-2/> The <literal>{&gt;&gt;}</literal> following the <parameter>rect</parameter> parameter name indicates that the C++ output parameter should be set from the value returned in the C parameter from the C function. <command>gmmproc</command> will generate a declaration of a temporary variable in which to store the value of the C output parameter and a statement that sets the C++ output parameter from the temporary variable. In this case it may be necessary to have an <function>_INITIALIZATION()</function> describing how to set a <classname>Gdk::Rectangle&amp;</classname> from a <classname>GdkRectangle*</classname> such as the following: <placeholder-3/><function>_WRAP_METHOD()</function>, <function>_WRAP_SIGNAL()</function>, and <function>_WRAP_PROPERTY()</function><function>sigc::bind()</function> is not commonly used, but you might find it helpful sometimes. If you are familiar with <application>GTK+</application> programming then you have probably noticed that this is similar to the extra <literal>gpointer data</literal> arguments which all GTK+ callbacks have. This is generally overused in <application>GTK+</application> to pass information that should be stored as member data in a derived widget, but widget derivation is very difficult in C. We have far less need of this hack in <application>gtkmm</application>.<function>sigc::ptr_fun()</function> generates a <classname>sigc::slot</classname>. A slot is an object which looks and feels like a function, but is actually an object. These are also known as function objects, or functors. <function>sigc::ptr_fun()</function> generates a slot for a standalone function or static method. <function>sigc::mem_fun()</function> generates a slot for a member method of a particular instance.<literal>$3</literal> will be replaced by the output parameter name of the C++ method and <literal>$4</literal> will be replaced by the return of the C function when this initialization is used by gmmproc. For convenience, <literal>$1</literal> will also be replaced by the C++ type without the ampersand (&amp;) and <literal>$2</literal> will be replaced by the C type.<literal>$3</literal> will be replaced by the parameter name when this conversion is used by gmmproc.<literal>Gtk::PACK_EXPAND_PADDING</literal>: Extra space is filled with padding. The widgets will be spaced out evenly, but their sizes won't change - there will be empty space between the widgets instead.<literal>Gtk::PACK_EXPAND_WIDGET</literal>: Extra space is taken up by increasing the child widget size, without changing the amount of space between widgets.<literal>Gtk::PACK_SHRINK</literal>: Space is contracted to the child widget size. The widget will take up just-enough space and never expand.<literal>LINGUAS</literal> contains an alphabetically sorted list of codes identifying the languages for which your program is translated (comment lines starting with a <literal>#</literal> are ignored). Each language code listed in the <literal>LINGUAS</literal> file must have a corresponding <literal>.po</literal> file. So, if your program has German and Japanese translations, your <literal>LINGUAS</literal> file would look like this:<literal>POTFILES.in</literal> is a list of paths to all files which contain strings marked up for translation, starting from the project root directory. So for example, if your project sources were located in a subdirectory named <literal>src</literal>, and you had two files that contained strings that should be translated, your <literal>POTFILES.in</literal> file might look like this:<literal>actions</literal> indicates the Drag and Drop actions which this destination can receive - see the description above.<literal>actions</literal> is an ORed combination of values, which specified which Drag and Drop operations will be possible from this source - for instance, copy, move, or link. The user can choose between the actions by using modifier keys, such as <keycap>Shift</keycap> to change from <literal>copy</literal> to <literal>move</literal>, and this will be shown by a different cursor.<literal>begin_print</literal>: You must handle this signal, because this is where you create and set up a <classname>Pango::Layout</classname> using the provided <classname>Gtk::PrintContext</classname>, and break up your printing output into pages.<literal>done</literal>: This signal is emitted when printing is finished, meaning when the print data is spooled. Note that the provided <literal>Gtk::PrintOperationResult</literal> may indicate that an error occurred. In any case you probably want to notify the user about the final status.<literal>drag_begin</literal>: Provides DragContext.<literal>drag_data_delete</literal>: Gives the source the opportunity to delete the original data if that's appropriate.<literal>drag_data_get</literal>: Provides <literal>info</literal> about the dragged data format, and a <literal>Gtk::SelectionData</literal> structure, in which you should put the requested data.<literal>drag_data_received</literal>: Provides <literal>info</literal> about the dragged data format, and a <literal>Gtk::SelectionData</literal> structure which contains the dropped data. You should call the <methodname>drag_finish()</methodname> method of the <literal>DragContext</literal> to indicate whether the operation was successful.<literal>drag_drop</literal>: Provides DragContext and coordinates. You can call <methodname>drag_get_data()</methodname>, which triggers the <literal>drag_data_get</literal> signal in the source widget, and then the <literal>drag_data_received</literal> signal in the destination widget.<literal>drag_end</literal>: Provides DragContext.<literal>drag_motion</literal>: Provides DragContext and coordinates. You can call the <methodname>drag_status()</methodname> method of the DragContext to indicate which action will be accepted.<literal>draw_page</literal>: You must handle this signal, which provides a <classname>PrintContext</classname> and a page number. The <classname>PrintContext</classname> should be used to create a <classname>Cairo::Context</classname> into which the provided page should be drawn. To render text, iterate over the <classname>Pango::Layout</classname> you created in the <literal>begin_print</literal> handler.<literal>end_print</literal>: A handler for it is a safe place to free any resources related to a <classname>PrintOperation</classname>. If you have your custom class that inherits from <classname>PrintOperation</classname>, it is naturally simpler to do it in the destructor.<literal>flags</literal> is an ORed combination of values which indicates how the widget will respond visually to Drag and Drop items.<literal>lower</literal>: lower range value<literal>page_increment</literal>: value to increment/decrement when pressing mouse button 2 on a button<literal>page_size</literal>: unused<literal>paginate</literal>: Pagination is potentially slow so if you need to monitor it you can call the <methodname>PrintOperation::set_show_progress()</methodname> method and handle this signal.<literal>request_page_setup</literal>: Provides a <classname>PrintContext</classname>, page number and <classname>Gtk::PageSetup</classname>. Handle this signal if you need to modify page setup on a per-page basis.<literal>start_button_mask</literal> is an ORed combination of values, which specify which modifier key or mouse button must be pressed to start the drag.<literal>status_changed</literal>: Emitted whenever a print job's status changes, until it is finished. Call the <methodname>PrintOperation::set_track_print_status()</methodname> method to monitor the job status after spooling. To see the status, use <methodname>get_status()</methodname> or <methodname>get_status_string()</methodname>.<literal>step_increment</literal>: value to increment/decrement when pressing mouse button 1 on a button<literal>targets</literal> is a vector of <classname>Gtk::TargetEntry</classname> elements.<literal>upper</literal>: upper range value<literal>value</literal>: value for the Spin Button<methodname>Gtk::Widget::show()</methodname> lets <application>gtkmm</application> know that we have finished setting the attributes of the widget, and that it is ready to be displayed. You can use <methodname>Gtk::Widget::hide()</methodname> to make it disappear again. The order in which you show the widgets is not important, but we do suggest that you show the top-level window last; this way, the whole window will appear with its contents already drawn. Otherwise, the user will first see a blank window, into which the widgets will be gradually drawn.<methodname>child_type_vfunc()</methodname>: Return what type of child can be added.<methodname>forall_vfunc()</methodname>: Call the same callback for each of the children.<methodname>get_preferred_height_for_width_vfunc()</methodname>: Calculate the minimum and natural height of the container, if it would be given the specified width.<methodname>get_preferred_height_for_width_vfunc()</methodname>: Calculate the minimum and natural height of the widget, if it would be given the specified width.<methodname>get_preferred_height_vfunc()</methodname>: Calculate the minimum and natural height of the container.<methodname>get_preferred_height_vfunc()</methodname>: Calculate the minimum and natural height of the widget.<methodname>get_preferred_width_for_height_vfunc()</methodname>: Calculate the minimum and natural width of the container, if it would be given the specified height.<methodname>get_preferred_width_for_height_vfunc()</methodname>: Calculate the minimum and natural width of the widget, if it would be given the specified height.<methodname>get_preferred_width_vfunc()</methodname>: Calculate the minimum and natural width of the container.<methodname>get_preferred_width_vfunc()</methodname>: Calculate the minimum and natural width of the widget.<methodname>get_request_mode_vfunc()</methodname>: (optional) Return what <literal>Gtk::SizeRequestMode</literal> is preferred by the widget.<methodname>get_request_mode_vfunc()</methodname>: Return what <literal>Gtk::SizeRequestMode</literal> is preferred by the container.<methodname>get_widget()</methodname> returns child widgets that are <function>manage()</function>ed (see the <link linkend="chapter-memory">Memory Management</link> chapter), so they will be deleted when their parent container is deleted. So, if you get only a child widget from <application>Gtk::Builder</application>, instead of a whole window, then you must either put it in a <classname>Container</classname> or delete it. <classname>Windows</classname> (such as <classname>Dialogs</classname>) cannot be managed because they have no parent container, so you must delete them at some point.<methodname>on_add()</methodname>: Add a child widget to the container.<methodname>on_draw()</methodname>: Draw on the supplied <classname>Cairo::Context</classname>.<methodname>on_map()</methodname>: (optional)<methodname>on_realize()</methodname>: Associate a <classname>Gdk::Window</classname> with the widget.<methodname>on_remove()</methodname>: Remove a child widget from the container.<methodname>on_size_allocate()</methodname> receives the actual height and width that the parent container has decided to give to your widget. This might be more than the minimum, or even more than the natural size, for instance if the top-level window has been expanded. You might choose to ignore the extra space and leave a blank area, or you might choose to expand your child widgets to fill the space, or you might choose to expand the padding between your widgets. It's your container, so you decide. Don't forget to call <methodname>set_allocation()</methodname> inside your <methodname>on_size_allocate()</methodname> implementation to actually use the allocated space that has been offered by the parent container.<methodname>on_size_allocate()</methodname>: Position the child widgets, given the height and width that the container has actually been given.<methodname>on_size_allocate()</methodname>: Position the widget, given the height and width that it has actually been given.<methodname>on_unmap()</methodname>: (optional)<methodname>on_unrealize()</methodname>: (optional) Break the association with the <classname>Gdk::Window</classname>.<methodname>run()</methodname> may return <literal>PRINT_OPERATION_RESULT_IN_PROGRESS</literal>. To track status and handle the result or error you need to implement signal handlers for the <literal>done</literal> and <literal>status_changed</literal> signals:<placeholder-1/> (or <placeholder-2/> for filenames)<placeholder-1/> Now, when objects of type <classname>MyContainer</classname> are destroyed, the button will also be deleted. It is no longer necessary to delete <varname>pButton</varname> to free the button's memory; its deletion has been delegated to the <classname>MyContainer</classname> object.<placeholder-1/> example package<type>GdkEventButton</type> is a structure containing the event's parameters, such as the coordinates of the mouse pointer at the time the button was pressed. There are several different types of <type>GdkEvent</type> structures for the various events.<ulink url="http://developer.gnome.org/gtkmm/unstable/classGtk_1_1Button.html"><classname>Gtk::Button</classname></ulink>. Standard buttons, usually marked with a label or picture. Pushing one triggers an action. See the <link linkend="sec-pushbuttons">Button</link> section.<ulink url="http://developer.gnome.org/gtkmm/unstable/classGtk_1_1CheckButton.html"><classname>Gtk::CheckButton</classname></ulink>. These act like ToggleButtons, but show their state in small squares, with their label at the side. They should be used in most situations which require an on/off setting. See the <link linkend="sec-checkboxes">CheckButton</link> section.<ulink url="http://developer.gnome.org/gtkmm/unstable/classGtk_1_1RadioButton.html"><classname>Gtk::RadioButton</classname></ulink>. Named after the station selectors on old car radios, these buttons are used in groups for options which are mutually exclusive. Pressing one causes all the others in its group to turn off. They are similar to CheckBoxes (a small widget with a label at the side), but usually look different. See the <link linkend="sec-radio-buttons">RadioButton</link> section.<ulink url="http://developer.gnome.org/gtkmm/unstable/classGtk_1_1ToggleButton.html"><classname>Gtk::ToggleButton</classname></ulink>. Unlike a normal Button, which springs back up, a ToggleButton stays down until you press it again. It might be useful as an on/off switch. See the <link linkend="sec-toggle-buttons">ToggleButton</link> section.<varname>app_exec</varname>: The command line to be used to launch this resource. This string may contain the "f" and "u" escape characters which will be expanded to the resource file path and URI respectively<varname>app_name</varname>: The name of the application that registered the resource<varname>description</varname>: A short description of the resource as a UTF-8 encoded string<varname>display_name</varname>: The name of the resource to be used for display as a UTF-8 encoded string<varname>groups</varname>: A list of groups associated with this item. Groups are essentially arbitrary strings associated with a particular resource. They can be thought of as 'categories' (such as "email", "graphics", etc) or tags for the resource.<varname>is_private</varname>: Whether this resource should be visible only to applications that have registered it or not<varname>mime_type</varname>: The MIME type of the resourceA .hg file will typically include some headers and then declare a class, using some macros to add API or behaviour to this class. For instance, <application>gtkmm</application>'s <filename>button.hg</filename> looks roughly like this: <placeholder-1/>A <classname>ComboBox</classname> may contain an <classname>Entry</classname> widget for entering of arbitrary text, by specifying <literal>true</literal> for the constructor's <literal>has_entry</literal> parameter.A <classname>Entry</classname> widget can offer a drop-down list of pre-existing choices based on the first few characters typed by the user. For instance, a search dialog could suggest text from previous searches.A <classname>Glib::Dispatcher</classname> is used for sending notifications from the worker thread to the GUI thread. The <classname>ExampleWorker</classname> class contains data which is accessed by both threads. This data is protected by a <classname>Glib::Threads::Mutex</classname>. Only the GUI thread updates the GUI.A <classname>Glib::Dispatcher</classname> object can be emitted on by the receiver thread as well as by a worker thread, although this should be done within reasonable bounds. On unix-like systems <classname>Glib::Dispatcher</classname> objects share a single common pipe, which could in theory at least fill up on a very heavily loaded system running a program with a very large number of <classname>Dispatcher</classname> objects in use. Were the pipe to fill up before the receiver thread's main loop has had an opportunity to read from it to empty it, and the receiver thread attempt to emit and so write to it when it is in that condition, the receiver thread would block on the write, so deadlocking. Where the receiver thread is to emit, a normal <classname>sigc::signal&lt;void&gt;</classname> object could of course be used instead.A <classname>Grid</classname> dynamically lays out child widgets in rows and columns. The dimensions of the grid do not need to be specified in the constructor.A <classname>Notebook</classname> has a set of stacked <literal>pages</literal>, each of which contains widgets. Labelled <literal>tabs</literal> allow the user to select the pages. <classname>Notebook</classname>s allow several sets of widgets to be placed in a small space, by only showing one page at a time. For instance, they are often used in preferences dialogs.A <classname>Plug</classname> is a special kind of Window that can be plugged into a <classname>Socket</classname>. Besides the normal properties and methods of <classname>Gtk::Window</classname>, a <classname>Plug</classname> provides a constructor that takes the ID of a <classname>Socket</classname>, which will automatically embed the <classname>Plug</classname> into the <classname>Socket</classname> that matches that ID.A <classname>ProgressBar</classname> is horizontal and left-to-right by default, but you can change it to a vertical progress bar by using the <methodname>set_orientation()</methodname> method.A <classname>RecentInfo</classname> object is essentially an object containing all of the metadata about a single recently-used file. You can use this object to look up any of the properties listed <link linkend="list-file-metadata">above</link>.A <classname>Socket</classname> is a special kind of container widget that provides the ability to embed widgets from one process into another process in a way that is transparent to the user.A <classname>SpinButton</classname> allows the user to select a value from a range of numeric values. It has an <classname>Entry</classname> widget with increment and decrement buttons at the side. Clicking the buttons causes the value to 'spin' up and down across the range of possible values. The <classname>Entry</classname> widget may also be used to enter a value directly.A <classname>ToolPalette</classname> is similar to a <classname>Toolbar</classname> but can contain a grid of items, categorized into groups. The user may hide or expand each group. As in a toolbar, the items may be displayed as only icons, as only text, or as icons with text.A <classname>sigc::signal</classname> object should be regarded as owned by the thread which created it. Only that thread should connect a <classname>sigc::slot</classname> object to the signal object, and only that thread should <methodname>emit()</methodname> or call <methodname>operator()()</methodname> on the signal, or null any connected <classname>sigc::slot</classname> object. It follows (amongst other things) that any signal object provided by a <application>gtkmm</application> widget should only be operated on in the main GUI thread and any object deriving from <classname>sigc::trackable</classname> having its non-static methods referenced by slots connected to the signal object should only be destroyed in that thread.A <classname>sigc::slot</classname> object created by a call to <function>sigc::mem_fun()</function> which references a method of a class deriving from <classname>sigc::trackable</classname> should never be copied to another thread, nor destroyed by a different thread than the one which created it. (One consequence of this is that <methodname>Glib::Threads::Thread::create()</methodname> should not be called with a slot argument created by a call to <function>sigc::mem_fun()</function> which represents a method of such a class. It is however safe to pass <methodname>Glib::Threads::Thread::create()</methodname> a function object representing such a method by using, say, <function>boost::bind()</function> or, in C++11, <function>std::bind()</function> or a C++11 lambda expression.)A child widget can be added to the <classname>EventBox</classname> using:A little example follows. To use the example just execute it from a terminal; it doesn't create a window. It will create a pipe named <literal>testfifo</literal> in the current directory. Then start another shell and execute <literal>echo "Hello" &gt; testfifo</literal>. The example will print each line you enter until you execute <literal>echo "Q" &gt; testfifo</literal>.A nifty feature of Glib (one of the libraries underlying <application>gtkmm</application>) is the ability to have it check for data on a file descriptor for you. This is especially useful for networking applications. The following method is used to do this:A properly internationalized application will not make assumptions about the number of bytes in a character. That means that you shouldn't use pointer arithmetic to step through the characters in a string, and it means you shouldn't use <classname>std::string</classname> or standard C functions such as <function>strlen()</function> because they make the same assumption.A rule to which there may be exceptions: If the virtual C function returns a pointer to an object derived from <classname>GObject</classname>, i.e. a reference-counted object, then the virtual C++ function shall return a <classname>Glib::RefPtr&lt;&gt;</classname> object. One of the extra arguments <parameter>refreturn</parameter> or <parameter>refreturn_ctype</parameter> is required.A smartpointer acts much like a normal pointer. Here are a few examples.A target can be in a variety of binary formats. This chapter, and the examples, assume that the data is 8-bit text. This would allow us to use an XML format for the clipboard data. However this would probably not be appropriate for binary data such as images. <classname>Gtk::Clipboard</classname> provides overloads that allow you to specify the format in more detail if necessary.AM_CPPFLAGSAM_CPPFLAGS = ... -DPROGRAMNAME_LOCALEDIR=\"${PROGRAMNAME_LOCALEDIR}\"AM_CXXFLAGSATKAboutDialogAccessing widgetsActionsActivity ModeAdd <literal>INTLTOOL_FILES</literal> to the <literal>EXTRA_DIST</literal> list of files. This ensures that when you do a <command>make dist</command>, these commands will be included in the source tarball.Add <literal>po</literal> to the <literal>SUBDIRS</literal> variable. Without this, your translations won't get built and installed when you build the programAdd a default constructor.Add methods to wrap parts of the C API.Add rows to the model with the <methodname>append()</methodname>, <methodname>prepend()</methodname>, or <methodname>insert()</methodname> methods.Adding Items to the List of Recent FilesAdding RowsAdding View ColumnsAdding child rowsAdding properties, and ensuring that they interact properly with each other, is relatively difficult to correct in the C library, but it is possible, so do file a bug and try to send a patch to the relevant maintainer.Adding widgetsAdditional command-line flags passed to the <filename>generate_wrap_init.pl</filename> script, such as the C++ namespace and the parent directory prefix of include files.Additionally, mouse button 3 can be used to jump directly to the <literal>upper</literal> or <literal>lower</literal> values.Adjustment InternalsAdjustmentsAfter a <classname>Socket</classname> or <classname>Plug</classname> object is realized, you can obtain its ID with its <methodname>get_id()</methodname> function. This ID can then be shared with other processes so that other processes know how to connect to each other.After appending rows to this model, you should provide the model to the <classname>ComboBox</classname> with the <methodname>set_model()</methodname> method. Then use the <methodname>pack_start()</methodname> or <methodname>pack_end()</methodname> methods to specify what columns will be displayed in the ComboBox. As with the TreeView you may either use the default cell renderer by passing the <classname>TreeModelColumn</classname> to the pack methods, or you may instantiate a specific <classname>CellRenderer</classname> and specify a particular mapping with either <methodname>add_attribute()</methodname> or <methodname>set_cell_data_func()</methodname>. Note that these methods are in the <classname>CellLayout</classname> base class.After building and running this program, try resizing the window to see the behaviour. Also, try playing with the options to <methodname>pack_start()</methodname> while reading the <link linkend="sec-boxes">Boxes</link> section.After drawing the outline, we go around the clock and draw ticks for every hour, with a larger tick at 12, 3, 6, and 9. Now we're finally ready to implement the time-keeping functionality of the clock, which simply involves getting the current values for hours, minutes and seconds, and drawing the hands at the correct angles.After putting the source code in <literal>simple.cc</literal> you can compile the above program with <application>gcc</application> using: <placeholder-1/> Note that you must surround the <literal>pkg-config</literal> invocation with backquotes. Backquotes cause the shell to execute the command inside them, and to use the command's output as part of the command line. Note also that <literal>simple.cc</literal> must come before the <literal>pkg-config</literal> invocation on the command line.After selecting the <guimenuitem>Recent Files Dialog</guimenuitem> menu item, you should see something similar to the following window.After setting the correct moduleset, you need to tell <application>jhbuild</application> which module or modules to build. To build <application>gtkmm</application> and all of its dependencies, set <varname>modules</varname> like so: <placeholder-1/>After starting <filename>socket</filename>, you should see the following output in the terminal:After which you should see something like the following:After you've created and set up the filter to match only the items you want, you can apply a filter to a chooser widget with the <methodname>RecentChooser::add_filter()</methodname> function.After you've finished creating your path, you still haven't drawn anything visible yet. To make the path visible, you must use the function <methodname>stroke()</methodname> which will stroke the current path with the line width and style specified in your <classname>Cairo::Context</classname> object. After stroking, the current path will be cleared so that you can start on your next path.After you've installed all of the dependencies, download the <application>gtkmm</application> source code, unpack it, and change to the newly created directory. <application>gtkmm</application> can be built and installed with the following sequence of commands:After you've installed the git version of <application>gtkmm</application>, you're ready to start using and experimenting with it. In order to use the new version of <application>gtkmm</application> you've just installed, you need to set some environment variables so that your <filename>configure</filename> script knows where to find the new libraries. Fortunately, <application>jhbuild</application> offers an easy solution to this problem. Executing the command <command>jhbuild shell</command> will start a new shell with all of the correct environment variables set. Now if you re-configure and build your project just as you usually do, it should link against the newly installed libraries. To return to your previous environment, simply exit the <application>jhbuild</application> shell.AhlstedtAlignmentAll <application>gtkmm</application> programs must include certain <application>gtkmm</application> headers; <literal>gtkmm.h</literal> includes the entire <application>gtkmm</application> kit. This is usually not a good idea, because it includes a megabyte or so of headers, but for simple programs, it suffices.All container widgets derive from <classname>Gtk::Container</classname>, not always directly. Some container widgets, such as <classname>Gtk::Grid</classname> can hold many child widgets, so these typically have more complex interfaces. Others, such as <classname>Gtk::Frame</classname> contain only one child widget.All deprecated API was removed in <application>gtkmm</application> 3.0, though there will be new deprecations in future versions.All mentions of <varname>skeleton</varname> should be replaced by the correct name of the C library you are wrapping, such as "something" or "libsomething". In the same manner, all instances of <varname>SKELETON</varname> should be replaced by "SOMETHING" or "LIBSOMETHING", and all occurrences of <varname>Skeleton</varname> changed to "Something".Also, the value can be drawn in different positions relative to the trough, specified by the <methodname>set_value_pos()</methodname> method.Alternatively, if a complete list of possible entries would be too large or too inconvenient to generate, a callback slot may instead be specified with <methodname>set_match_func()</methodname>. This is also useful if you wish to match on a part of the string other than the start.Alternatively, you can let a widget's container control when the widget is destroyed. In most cases, you want a widget to last only as long as the container it is in. To delegate the management of a widget's lifetime to its container, first create it with <function>Gtk::manage()</function> and pack it into its container with <methodname>Gtk::Container::add()</methodname>, <methodname>Gtk::Box::pack_start()</methodname>, or a similar method. Now the widget will be destroyed whenever its container is destroyed.Although <application>glib</application> is itself thread-safe, any <application>glibmm</application> wrappers which use <application>libsigc++</application> will not be. So for example, only the thread in which a main loop runs should call <methodname>Glib::SignalIdle::connect()</methodname>, <methodname>Glib::SignalIO::connect()</methodname>, <methodname>Glib::SignalTimeout::connect()</methodname>, <methodname>Glib::SignalTimeout::connect_seconds</methodname> for that main loop, or manipulate any <classname>sigc::connection</classname> object returned by them.Although <application>gtkmm</application> widget instances have lifetimes and scopes just like those of other C++ classes, <application>gtkmm</application> has an optional time-saving feature that you will see in some of the examples. <function>Gtk::manage()</function> allows you to say that a child widget is owned by the container into which you place it. This allows you to <function>new</function> the widget, add it to the container and forget about deleting it. You can learn more about <application>gtkmm</application> memory management techniques in the <link linkend="chapter-memory">Memory Management chapter</link>.Although Cairo can render text, it's not meant to be a replacement for Pango. Pango is a better choice if you need to perform more advanced text rendering such as wrapping or ellipsizing text. Drawing text with Cairo should only be done if the text is part of a graphic.Although the <literal>custom_widget_apply</literal> signal provides the widget you previously created, to simplify things you can keep the widgets you expect to contain some user input as class members. For example, let's say you have a <classname>Gtk::Entry</classname> called <literal>m_Entry</literal> as a member of your <classname>CustomPrintOperation</classname> class: <placeholder-1/>Although the name <classname>EventBox</classname> emphasises the event-handling method, the widget can also be used for clipping (and more; see the example below).Although we have shown the compilation command for the simple example, you really should use the automake and autoconf tools, as described in "Autoconf, Automake, Libtool", by G. V. Vaughan et al. The examples used in this book are included in the <application>gtkmm-documentation</application> package, with appropriate build files, so we won't show the build commands in future. You'll just need to find the appropriate directory and type <literal>make</literal>.Although you can specify the layout and appearance of windows and widgets with C++ code, you will probably find it more convenient to design your user interfaces with <literal>Glade</literal> and load them at runtime with <literal>Gtk::Builder</literal>. See the <link linkend="chapter-builder">Glade and Gtk::Builder</link> chapter.Although you can theoretically implement your own Model, you will normally use either the <classname>ListStore</classname> or <classname>TreeStore</classname> model classes.Although you can use C++ code to instantiate and arrange widgets, this can soon become tedious and repetitive. And it requires a recompilation to show changes. The <application>Glade</application> application allows you to layout widgets on screen and then save an XML description of the arrangement. Your application can then use the <application>Gtk::Builder</application> API to load that XML file at runtime and obtain a pointer to specifically named widget instances.Although your container might have its own method to set the child widgets, you should still provide an implementation for the virtual <methodname>on_add()</methodname> and <methodname>on_remove()</methodname> methods from the base class, so that the add() and remove() methods will do something appropriate if they are called.Although, in most cases, the programmer will prefer to allow containers to automatically destroy their children using <function>Gtk::manage()</function> (see below), the programmer is not required to use <function>Gtk::manage()</function>. The traditional <literal>new</literal> and <literal>delete</literal> operators may also be used. <placeholder-1/> Here, the programmer deletes <varname>pButton</varname> to prevent a memory leak.An <classname>Assistant</classname> splits a complex operation into steps. Each step is a page, containing a header, a child widget and an action area. The Assistant's action area has navigation buttons which update automatically depending on the type of the page, set with <methodname>set_page_type()</methodname>.An <classname>Entry</classname> widget can show a progress bar inside the text area, under the entered text. The progress bar will be shown if the <methodname>set_progress_fraction()</methodname> or <methodname>set_progress_pulse_step()</methodname> methods are called.An <classname>Entry</classname> widget can show an icon at the start or end of the text area. The icon can be specifed by methods such as <methodname>set_icon_from_pixbuf()</methodname> or <methodname>set_icon_from_icon_name()</methodname>. An application can respond to the user pressing the icon by handling the <methodname>signal_icon_press</methodname> signal.An <classname>InfoBar</classname> may show small items of information or ask brief questions. Unlike a <classname>Dialog</classname>, it appears at the top of the current window instead of opening a new window. Its API is very similar to the <link linkend="chapter-dialogs">Gtk::Dialog</link> API.An improved Hello WorldAnastasovAnd here's an excerpt from a <application>gdb</application> session. <placeholder-1/> The exception is caught in <application>glibmm</application>, and the program ends with a call to <function>g_error()</function>. Other exceptions may result in different behaviour, but in any case the exception from a signal handler is caught in <application>glibmm</application> or <application>gtkmm</application>, and <application>gdb</application> can't see where it was thrown.Another thing to note about this example is that we made the call to <methodname>connect()</methodname> twice for the same signal object. This is perfectly fine - when the button is clicked, both signal handlers will be called.Another way of destroying the connection is your signal handler. It has to be of the type <classname>sigc::slot&lt;bool&gt;</classname>. As you see from the definition your signal handler has to return a value of the type <literal>bool</literal>. A definition of a sample method might look like this: <placeholder-1/>Another workaround is to add a <function>*_construct()</function> function that the C++ constructor can call after instantiating its own type. For instance, <placeholder-1/>Any <classname>sigc::connection</classname> object should be regarded as owned by the thread in which the method returning the <classname>sigc::connection</classname> object was called. Only that thread should call <classname>sigc::connection</classname> methods on the object.Any additional non-generated <filename>.h</filename> and <filename>.cc</filename> source files may be placed in <filename>skeleton/skeletonmm/</filename> and listed in <filename>skeleton/skeletonmm/filelist.am</filename>, typically in the <varname>files_extra_h</varname> and <varname>files_extra_cc</varname> variables.Application LifetimeApplying TagsAs a first step to porting your source code to <application>gtkmm</application>-3.0 you should probably ensure that your application builds with the deprecated <application>gtkmm</application>-2.4 API disabled, by defining macro such as GTKMM_DISABLE_DEPRECATED. There are some autotools macros that can help with this by defining them optionally at build time. See the <ulink url="https://wiki.gnome.org/Projects/gtkmm/PortingToGtkmm3">gtkmm 3 porting wiki page</ulink> for more details.As before, almost all of the interesting stuff is done in the draw signal handler <methodname>on_draw()</methodname>. Before we dig into the draw signal handler, notice that the constructor for the <classname>Clock</classname> widget connects a handler function <methodname>on_timeout()</methodname> to a timer with a timeout period of 1000 milliseconds (1 second). This means that <methodname>on_timeout()</methodname> will get called once per second. The sole responsibility of this function is to invalidate the window so that <application>gtkmm</application> will be forced to redraw it.As mentioned above, each <classname>TextView</classname> has a <classname>TextBuffer</classname>, and one or more <classname>TextView</classname>s can share the same <classname>TextBuffer</classname>.As mentioned earlier, <classname>Gtk::Adjustment</classname> can emit signals. This is, of course, how updates happen automatically when you share an <classname>Adjustment</classname> object between a <classname>Scrollbar</classname> and another adjustable widget; all adjustable widgets connect signal handlers to their adjustment's <literal>value_changed</literal> signal, as can your program.As well as renaming the directories, we should rename some of the source files. For instance: <placeholder-1/> A number of the skeleton files must still be filled in with project-specific content later.As will be explained in the <link linkend="chapter-adjustment">Adjustment</link> section, all Range widgets are associated with a <classname>Adjustment</classname> object. To change the lower, upper, and current values used by the widget you need to use the methods of its <classname>Adjustment</classname>, which you can get with the <methodname>get_adjustment()</methodname> method. The <classname>Range</classname> widgets' default constructors create an <classname>Adjustment</classname> automatically, or you can specify an existing <classname>Adjustment</classname>, maybe to share it with another widget. See the <link linkend="chapter-adjustment">Adjustments</link> section for further details.As with <classname>Scrollbar</classname>s, the orientation can be either horizontal or vertical. The default constructor creates an <classname>Adjustment</classname> with all of its values set to <literal>0.0</literal>. This isn't useful so you will need to set some <classname>Adjustment</classname> details to get meaningful behaviour.Aside from the fact that connected slots always execute in the receiver thread, <classname>Glib::Dispatcher</classname> objects are similar to <classname>sigc::signal&lt;void&gt;</classname> objects. They therefore cannot pass unbound arguments nor return a value. The best way to pass unbound arguments is with a thread-safe (asynchronous) queue. At the time of writing <application>glibmm</application> does not have one, although most people writing multi-threaded code will have one available to them (they are relatively easy to write although there are subtleties in combining thread safety with strong exception safety).AspectFrameAssistantAssuming the displayed size of stringsAsynchronous operationsAt install time, the <filename>.po</filename> files are converted to a binary format (with the extension <filename>.mo</filename>) and placed in a system-wide directory for locale files, for example <filename>/usr/share/locale/</filename>.At the application development level, <application>gtkmm</application>'s printing API provides dialogs that are consistent across applications and allows use of Cairo's common drawing API, with Pango-driven text rendering. In the implementation of this common API, platform-specific backends and printer-specific drivers are used.At the least, the <function>_new()</function> function should not use any private API (functions that are only in a .c file). Even when there are no functions, we can sometimes reimplement 2 or 3 lines of code in a <function>_new()</function> function as long as those lines of code use API that is available to us.At the moment, we have separate tools for generating different parts of these <filename>.defs</filename>, so we split them up into separate files. For instance, in the <filename>gtk/src</filename> directory of the <application>gtkmm</application> sources, you will find these files: <placeholder-1/>Automatically-stored editable cells.Basic Type equivalentsBasic TypesBasicsBecause the user may enter arbitrary text, an active model row isn't enough to tell us what text the user has entered. Therefore, you should retrieve the <classname>Entry</classname> widget with the <methodname>ComboBox::get_entry()</methodname> method and call <methodname>get_text()</methodname> on that.Because this automatic transformation is not always appropriate, you might want to provide hand-written text for a particular method. You can do this by copying the XML node for the function from your <filename>something_docs.xml</filename> file to the <filename>something_docs_override.xml</filename> file and changing the contents.Before attempting to install <application>gtkmm</application> 3.0, you might first need to install these other packages.Below is a short example to illustrate these functions. This example makes use of the Frame widget to better demonstrate the label styles. (The Frame widget is explained in the <link linkend="sec-frame">Frame</link> section.) It is possible that the first character in <literal>m_Label_Normal</literal> is shown underlined only when you press the <keycap>Alt</keycap> key.BernhardBesides indicating the amount of progress that has occured, the progress bar can also be used to indicate that there is some activity; this is done by placing the progress bar in <emphasis>activity mode</emphasis>. In this mode, the progress bar displays a small rectangle which moves back and forth. Activity mode is useful in situations where the progress of an operation cannot be calculated as a value range (e.g., receiving a file of unknown length).Binding extra argumentsBjarne Stroustrup, "The C++ Programming Language" Forth Edition - section 34.3Box Packing 1Box Packing 2BoxesBuilding <application>gtkmm</application> on Win32But unlike most smartpointers, you can't use the * operator to access the underlying instance.But unlike normal pointers, <classname>RefPtr</classname>s are automatically initialized to null so you don't need to remember to do that yourself.ButtonButton boxes are a convenient way to quickly arrange a group of buttons. Their orientation can be either horizontal or vertical.Button boxes support several layout styles. The style can be retrieved and changed using <methodname>get_layout()</methodname> and <methodname>set_layout()</methodname>.ButtonBoxButtonBoxesButtonsButtons are added to a <classname>ButtonBox</classname> with the <methodname>add()</methodname> method.By convention, glib/GTK+-style objects have <function>*_new()</function> functions, such as <function>example_widget_new()</function> that do nothing more than call <function>g_object_new()</function> and return the result. The input parameters are supplied to <function>g_object_new()</function> along with the names of the properties for which they are values. For instance, <placeholder-1/>By convention, structs are declared in glib/GTK+-style headers like so: <placeholder-1/>By default, <application>gtkmm</application> will be installed under the <filename>/usr/local</filename> directory. On some systems you may need to install to a different location. For instance, on Red Hat Linux systems you might use the <literal>--prefix</literal> option with configure, like so: <screen>
# ./configure --prefix=/usr
</screen>By default, <application>jhbuild</application>'s configuration is configured to install all software built with <application>jhbuild</application> under the <filename>/opt/gnome</filename> prefix. You can choose a different prefix, but it is recommended that you keep this prefix different from other software that you've installed (don't set it to <filename>/usr</filename>!) If you've followed the jhbuild instructions then this prefix belongs to your user, so you don't need to run jhbuild as <literal>root</literal>.By default, <methodname>PrintOperation::run()</methodname> returns when a print operation is completed. If you need to run a non-blocking print operation, call <methodname>PrintOperation::set_allow_async()</methodname>. Note that <methodname>set_allow_async()</methodname> is not supported on all platforms, however the <literal>done</literal> signal will still be emitted.By default, only single rows can be selected, but you can allow multiple selection by setting the mode, like so: <placeholder-1/>By default, your signal handlers are called after any previously-connected signal handlers. However, this can be a problem with the X Event signals. For instance, the existing signal handlers, or the default signal handler, might return <literal>true</literal> to stop other signal handlers from being called. To specify that your signal handler should be called before the other signal handlers, so that it will always be called, you can specify <literal>false</literal> for the optional <literal>after</literal> parameter. For instance, <placeholder-1/>By deriving directly from <classname>Gtk::Widget</classname> you can do all the drawing for your widget directly, instead of just arranging child widgets. For instance, a <classname>Gtk::Label</classname> draws the text of the label, but does not do this by using other widgets.By overriding <methodname>forall_vfunc()</methodname> you can allow applications to operate on all of the container's child widgets. For instance, <methodname>show_all_children()</methodname> uses this to find all the child widgets and show them.C programmers use <function>sprintf()</function> to compose and concatenate strings. C++ favours streams, but unfortunately, this approach makes translation difficult, because each fragment of text is translated separately, without allowing the translators to rearrange them according to the grammar of the language.C typeC++ typeCairo and PangoCall <methodname>add_drag_dest()</methodname> to allow items or groups to be dragged from the tool palette to a particular destination widget. You can then use <methodname>get_drag_item()</methodname> to discover which ToolItem or ToolItemGroup is being dragged. You can use <literal>dynamic_cast</literal> to discover whether it is an item or a group. For instance, you might use this in your <literal>drag_data_received</literal> signal handler, to add a dropped item, or to show a suitable icon while dragging.Call <methodname>show()</methodname> to display the widget.CastingCells in a <classname>TreeView</classname> can be edited in-place by the user. To allow this, use the <classname>Gtk::TreeView</classname><methodname>insert_column_editable()</methodname> and <methodname>append_column_editable()</methodname> methods instead of <methodname>insert_column()</methodname> and <methodname>append_column()</methodname>. When these cells are edited the new values will be stored immediately in the Model. Note that these methods are templates which can only be instantiated for simple column types such as <classname>Glib::ustring</classname>, int, and long.Changes in <application>gtkmm</application> 3Changing the layout of a window "on the fly", to make some extra widgets appear, for instance, is complex. It requires tedious recalculation of every widget's position.Changing the selectionChapter on "Drawing with Cairo".Chapter on "Multi-threaded programs".Chapter on "Printing".Chapter on "Recent Files".Chapter on "Timeouts".Chapter on "Working with gtkmm's Source Code".Chapter on Keyboard Events.CheckButtonCheckboxesChecking for nullChild widgets can span multiple rows or columns, using <methodname>attach()</methodname>, or added next to an existing widget inside the grid with <methodname>attach_next_to()</methodname>. Individual rows and columns of the grid can be set to have uniform height or width with <methodname>set_row_homogeneous()</methodname> and <methodname>set_column_homogeneous()</methodname>.ChrisClass Scope widgetsClass macrosClipboard - IdealClipboard - SimpleColorChooserDialogCombo BoxesComboBoxComboBox with EntryComboBox with an EntryComboBoxTextComboBoxText with EntryComparison with other signalling systemsComposition of stringsConnect any signals you wish to use to the appropriate handlers.Connecting Plugs and SocketsConnecting signal handlersConst Objects used via <classname>RefPtr</classname>: If the object should not be changed by the function, then make sure that the object is const, even if the <classname>RefPtr</classname> is already const. For instance, <code>const Glib::RefPtr&lt;const Gtk::FileFilter&gt;&amp; filter</code>.ConstnessConstructor macrosConstructorsContainer WidgetsContrary to other events, keyboard events are first sent to the toplevel window (<classname>Gtk::Window</classname>), where it will be checked for any keyboard shortcuts that may be set (accelerator keys and mnemonics, used for selecting menu items from the keyboard). After this (and assuming the event wasn't handled), it is sent to the widget which has focus, and the propagation begins from there.ContributingCopyCopyingCopying the skeleton projectCreate a <classname>Plug</classname> independantly from any particular <classname>Socket</classname> and pass the ID of the <classname>Plug</classname> to other processes that need to use it. The ID of the <classname>Plug</classname> can be associated with a particular <classname>Socket</classname> object using the <methodname>Socket::add_id()</methodname> function. This is the approach used in the example below.Create a <classname>Socket</classname> object in one process and pass the ID of that <classname>Socket</classname> to another process so that it can create a <classname>Plug</classname> object by specifying the given <classname>Socket</classname> ID in its constructor. There is no way to assign a <classname>Plug</classname> to a particular <classname>Socket</classname> after creation, so you must pass the <classname>Socket</classname> ID to the <classname>Plug</classname>'s constructor.Create a sub-directory named <literal>po</literal> in your project's root directory. This directory will eventually contain all of your translations. Within it, create a file named <literal>LINGUAS</literal> and a file named <literal>POTFILES.in</literal>. It is common practice to also create a <literal>ChangeLog</literal> file in the <literal>po</literal> directory so that translators can keep track of translation changes.Create your own signals instead of passing pointers around. Objects can communicate with each other via signals and signal handlers. This is much simpler than objects holding pointers to each other and calling each other's methods. <application>gtkmm</application>'s classes uses special versions of <classname>sigc::signal</classname>, but you should use normal <classname>sigc::signal</classname>s, as described in the <application>libsigc++</application> documentation.Creating .hg and .ccg filesCreating an AdjustmentCreating your own signalsCummingCurrently, <application>gettext</application> does not support non-ASCII characters (i.e. any characters with a code above 127) in source code. For instance, you cannot use the copyright sign (©).Custom ContainerCustom ContainersCustom WidgetCustom WidgetsDISTCLEANFILES = ... intltool-extract \
                 intltool-merge \
                 intltool-update \
                 po/.intltool-merge-cacheDanielDavidDeclare a variable of the type of <classname>Widget</classname> you wish to use, generally as member variable of a derived container class. You could also declare a pointer to the widget type, and then create it with <literal>new</literal> in your code. Even when using the widget via a pointer, it's still probably best to make that pointer a member variable of a container class so that you can access it later.Default formattingDefine <literal>INTLTOOL_FILES</literal> as: <placeholder-1/>Defines a custom clipboard target, though the format of that target is still text.DependenciesDereferencingDesigners without programming skills can create and edit UIs.DialogsDialogs are used as secondary windows, to provide specific information or to ask questions. <classname>Gtk::Dialog</classname> windows contain a few pre-packed widgets to ensure consistency, and a <methodname>run()</methodname> method which blocks until the user dismisses the dialog.Different applications contain different types of data, and they might make that data available in a variety of formats. <application>gtkmm</application> calls these data types <literal>target</literal>s.Different join types in CairoDisconnecting signal handlersDiscovering the available targetsDo an extra <function>reference()</function> on the return value of an overridden <function>something_vfunc()</function> function in the C callback function, in case the calling C function expects it to provide a reference.Do an extra <function>reference()</function> on the return value of the <function>on_something()</function> virtual method, in case the C function does not provide a reference.Do an extra <function>reference()</function> on the return value of the <function>something_vfunc()</function> function, in case the virtual C function does not provide a reference.Do an extra <function>reference()</function> on the return value, in case the C function does not provide a reference.Do not generate a C callback function for the signal. Use this when you must generate the callback function by hand.Do not generate a C callback function for the vfunc. Use this when you must generate the callback function by hand.Do not generate a definition of the vfunc in the <filename>.cc</filename> file. Use this when you must generate the vfunc by hand.Do not generate an <function>on_something()</function> virtual method to allow easy overriding of the default signal handler. Use this when adding a signal with a default signal handler would break the ABI by increasing the size of the class's virtual function table.DocumentationDocumentation build structureDrag and DropDragContextDrawing Arcs and CirclesDrawing Area - ArcsDrawing Area - ImageDrawing Area - LinesDrawing Area - TextDrawing Area - Thin LinesDrawing Curved LinesDrawing ImagesDrawing Straight LinesDrawing TextDrawing Text with PangoDrawing counter-clockwiseDrawing thin linesDrawing with relative coordinatesDuring a <literal>move</literal>, the source widget will also emit this signal: <placeholder-1/>Dynamic allocation with manage() and add()Dynamic allocation with new and deleteEach <classname>Cairo::Context</classname> is associated with a particular <classname>Gdk::Window</classname>, so the first line of the above example creates a <classname>Gtk::DrawingArea</classname> widget and the second line uses its associated <classname>Gdk::Window</classname> to create a <classname>Cairo::Context</classname> object. The final two lines change the graphics state of the context.Each <classname>Gtk::TextBuffer</classname> uses a <classname>Gtk::TextBuffer::TagTable</classname>, which contains the <classname>Tag</classname>s for that buffer. 2 or more <classname>TextBuffer</classname>s may share the same <classname>TagTable</classname>. When you create <classname>Tag</classname>s you should add them to the <classname>TagTable</classname>. For instance:Each <classname>Gtk::TreeView</classname> has an associated <classname>Gtk::TreeModel</classname>, which contains the data displayed by the <classname>TreeView</classname>. Each <classname>Gtk::TreeModel</classname> can be used by more than one <classname>Gtk::TreeView</classname>. For instance, this allows the same underlying data to be displayed and edited in 2 different ways at the same time. Or the 2 Views might display different columns from the same Model data, in the same way that 2 SQL queries (or "views") might show different fields from the same database table.Each item in the list of recently used files is identified by its URI, and can have associated metadata. The metadata can be used to specify how the file should be displayed, a description of the file, its mime type, which application registered it, whether it's private to the registering application, and several other things.Each line contains one horizontal <classname>Box</classname> with several buttons. Each of the buttons on a line is packed into the <classname>Box</classname> with the same arguments to the <methodname>pack_start()</methodname> method.Editable CellsElstnerEmitted when the button is pressed and released.Emitted when the button is pressed.Emitted when the button is released.Emitted when the mouse pointer leaves the button's window.Emitted when the mouse pointer moves over the button's window.EntryEntry CompletionEntry Completion ExampleEntry Icon ExampleEntry IconsEntry ProgressEntry Progress ExampleEntry widgets allow the user to enter text. You can change the contents with the <methodname>set_text()</methodname> method, and read the current contents with the <methodname>get_text()</methodname> method.Entry with IconEntry with Progress BarEnumerations.Event PropagationEvent propagation means that, when an event is emitted on a particular widget, it can be passed to its parent widget (and that widget can pass it to its parent, and so on) and, if the parent has an event handler, that handler will be called.EventBoxExampleExample Application: Creating a Clock with CairoExamplesExceptions in signal handlersExpecting UTF8Export to PDFExtending the print dialogFerreiraFileChooserFileChooserDialogFiltering Recent FilesFinally, check the status. For instance, <placeholder-1/>Finally, to let your program use the translation for the current locale, add this code to the beginning of your <filename>main.cc</filename> file, to initialize gettext. <placeholder-1/>First create the <classname>Action</classname>s and add them to an <classname>ActionGroup</classname>, with <methodname>ActionGroup::add()</methodname>.First we instantiate an object stored in a <classname>RefPtr</classname> smartpointer called <literal>app</literal>. This is of type <classname>Gtk::Application</classname>. Every <application>gtkmm</application> program must have one of these. We pass our command-line arguments to its create() method. It takes the arguments it wants, and leaves you the rest, as we described earlier.First, let's look at a simple example where an exception is thrown from a normal function (no signal handler). <placeholder-1/>FontChooserDialogFor a CellRendererToggle, you would set the <emphasis>activatable</emphasis> property instead.For all macros processing method signatures except <function>_WRAP_SIGNAL()</function> and <function>_WRAP_VFUNC()</function> it is also possible to make the parameters optional so that extra C++ methods are generated without the specified optional parameter. For example, say that the following <function>*_new()</function> function were being wrapped as a constructor in the <classname>Gtk::ToolButton</classname> class: <placeholder-1/> Also, say that the C API allowed NULL for the function's <parameter>label</parameter> parameter so that that parameter is optional. It would be possible to have <command>gmmproc</command> generate the original constructor (with all the parameters) along with an additional constructor without that optional parameter by appending a <literal>{?}</literal> to the parameter name like so: <placeholder-2/> In this case, two constructors would be generated: One with the optional parameter and one without it.For all the macros that process method signatures, it is possible to specify a different order for the C++ parameters than the existing order in the C function, virtual function or signal. For example, say that the following C function were being wrapped as a C++ method for the <classname>Gtk::Widget</classname> class: <placeholder-1/> However, changing the order of the C++ method's two parameters is necessary. Something like the following would wrap the function as a C++ method with a different order for the two parameters: <placeholder-2/> The <literal>{c_param_name}</literal> following the method parameter names tells <command>gmmproc</command> to map the C++ parameter to the specified C parameter within the <literal>{}</literal>. Since the C++ parameter names correspond to the C ones, the above could be re-written as: <placeholder-3/>For any of the <classname>RecentChooser</classname> classes, if you don't wish to display all of the items in the list of recent files, you can filter the list to show only those that you want. You can filter the list with the help of the <classname>RecentFilter</classname> class. This class allows you to filter recent files by their name (<methodname>add_pattern()</methodname>), their mime type (<methodname>add_mime_type()</methodname>), the application that registered them (<methodname>add_application()</methodname>), or by a custom filter function (<methodname>add_custom()</methodname>). It also provides the ability to filter based on how long ago the file was modified and which groups it belongs to.For each page that needs to be rendered, the following signals are emitted: <placeholder-1/>For example, for <classname>Pango::Analysis</classname> in <filename>item.hg</filename>: <placeholder-1/>For example, from <filename>icontheme.hg</filename>: <placeholder-1/>For example, if there was a C function that returned a <type>GtkWidget*</type> and for some reason, instead of having the C++ method also return the widget, it was desirable to have the C++ method place the widget in a specified output parameter, an initialization macro such as the following would be necessary: <placeholder-1/>For example, in <filename>rectangle.hg</filename>: <placeholder-1/>For example, in Pangomm, <filename>layoutline.hg</filename>: <placeholder-1/>For information about implementing your own signals rather than just connecting to the existing <application>gtkmm</application> signals, see the <link linkend="chapter-custom-signals">appendix</link>.For instance,For instance, <application>gedit</application> can supply and receive the <literal>"UTF8_STRING"</literal> target, so you can paste data into <application>gedit</application> from any application that supplies that target. Or two different image editing applications might supply and receive a variety of image formats as targets. As long as one application can receive one of the targets that the other supplies then you will be able to copy data from one to the other.For instance, <placeholder-1/>For instance, for <classname>Gdk::Rectangle</classname>: <placeholder-1/>For instance, for <classname>Pango::AttrIter</classname>: <placeholder-1/>For instance, for <classname>Pango::Coverage</classname>: <placeholder-1/>For instance, for a CellRendererText, you would set the cell's <emphasis>editable</emphasis> property to true, like so:For instance, from <classname>Gdk::RGBA</classname>: <placeholder-1/>For instance, from <classname>Glib::Checksum</classname>: <placeholder-1/>For instance, from <filename>accelgroup.hg</filename>: <placeholder-1/>For instance, from <filename>button.hg</filename>: <placeholder-1/>For instance, from <filename>buttonbox.hg</filename>: <placeholder-1/>For instance, from <filename>celleditable.hg</filename>: <placeholder-1/>For instance, from <filename>container.hg</filename>: <placeholder-1/>For instance, from <filename>entry.hg</filename>: <placeholder-1/>For instance, from <filename>enums.hg</filename>: <placeholder-1/>For instance, from <filename>pixbuf.hg</filename>: <placeholder-1/>For instance, from <filename>widget.hg</filename>: <placeholder-1/>For instance, let's pretend that we are wrapping a C library called libsomething. It provides a <classname>GObject</classname>-based API with types named, for instance, <classname>SomeWidget</classname> and <classname>SomeStuff</classname>.For instance, this code would be problematic:For instance, to create a signal that sends 2 parameters, a <type>bool</type> and an <type>int</type>, just declare a <classname>sigc::signal</classname>, like so: <placeholder-1/>For instance:For more detailed information about signals, see the <link linkend="chapter-signals">appendix</link>.For multiple-selection, you need to define a callback, and give it to <methodname>selected_foreach()</methodname>, <methodname>selected_foreach_path()</methodname>, or <methodname>selected_foreach_iter()</methodname>, like so:For reference, it is possible to generate a file which contains all strings which appear in your code, even if they are not marked for translation, together with file name and line number references. To generate such a file named <literal>my-strings</literal>, execute the following command, within the source code directory: <placeholder-1/>For single-selection, you can just call <methodname>get_selected()</methodname>, like so:For the input of passwords, passphrases and other information you don't want echoed on the screen, calling <methodname>set_visibility()</methodname> with <literal>false</literal> will cause the text to be hidden.FrameFrames can enclose one or a group of widgets within a box, optionally with a title. For instance, you might place a group of <classname>RadioButton</classname>s or <classname>CheckButton</classname>s in a <classname>Frame</classname>.From time to time, it may be useful to be able to embed a widget from another application within your application. <application>gtkmm</application> allows you to do this with the <classname>Gtk::Socket</classname> and <classname>Gtk::Plug</classname> classes. It is not anticipated that very many applications will need this functionality, but in the rare case that you need to display a widget that is running in a completely different process, these classes can be very helpful.Full ExampleFunction scope widgetsGTK+ 3.0GTK+ and <application>gtkmm</application> were designed to work well with Microsoft Windows, and the developers encourage its use on the win32 platform. However, Windows has no standard installation system for development libraries. Please see the <ulink url="https://wiki.gnome.org/Projects/gtkmm/MSWindows">Windows Installation</ulink> page for Windows-specific installation instructions and notes.GTK+ uses the <ulink url="http://cairographics.org">Cairo</ulink> drawing API. With <application>gtkmm</application>, you may use the <ulink url="http://www.cairographics.org/cairomm/">cairomm</ulink> C++ API for cairo.Generate a declaration of the <function>on_something()</function> virtual method in the <filename>.h</filename> file, but do not generate a definition in the <filename>.cc</filename> file. Use this when you must generate the definition by hand.Generating the .defs files.Generating the enums .defsGenerating the methods .defsGenerating the signals and properties .defsGeneration of the source code for a gtkmm-style wrapper API requires use of tools such as <command>gmmproc</command> and <filename>generate_wrap_init.pl</filename>. In theory you could write your own build files to use these appropriately, but a much better option is to make use of the build infrastructure provided by the mm-common module. To get started, it helps a lot to pick an existing binding module as an example to look at.Get the data from the widgets in the <literal>custom_widget_apply</literal> signal handler.Getting help with translationsGetting valuesGive all command-line options to <methodname>Gtk::Application::create()</methodname> and add the flag <literal>Gio::APPLICATION_HANDLES_COMMAND_LINE</literal>. Connect a signal handler to the <literal>command_line</literal> signal, and handle the command-line options in the signal handler.Glade and Gtk::BuilderGlib::IO_ERR - Call your method when an error has occurred on the file descriptor.Glib::IO_HUP - Call your method when hung up (the connection has been broken usually for pipes and sockets).Glib::IO_IN - Call your method when there is data ready for reading on your file descriptor.Glib::IO_OUT - Call your method when the file descriptor is ready for writing.Glib::IO_PRI - Call your method when the file descriptor has urgent data to be read.Glib::RefPtr&lt;Gtk::Adjustment&gt; Gtk::Adjustment::create(
  double value,
  double lower,
  double upper,
  double step_increment = 1,
  double page_increment = 10,
  double page_size = 0);Glib::RefPtr&lt;Gtk::Application&gt; app = Gtk::Application::create(argc, argv, "org.gtkmm.examples.base");Glib::RefPtr&lt;Gtk::Clipboard&gt; refClipboard = Gtk::Clipboard::get();

//Targets:
std::vector&lt;Gtk::TargetEntry&gt; targets;
targets.push_back( Gtk::TargetEntry("example_custom_target") );
targets.push_back( Gtk::TargetEntry("UTF8_STRING") );

refClipboard-&gt;set( targets,
    sigc::mem_fun(*this, &amp;ExampleWindow::on_clipboard_get),
    sigc::mem_fun(*this, &amp;ExampleWindow::on_clipboard_clear) );Glib::RefPtr&lt;Gtk::ListStore&gt; refListStore =
    Gtk::ListStore::create(m_Columns);Glib::RefPtr&lt;Gtk::RecentInfo&gt; info;
try
{
  info = recent_manager-&gt;lookup_item(uri);
}
catch(const Gtk::RecentManagerError&amp; ex)
{
  std::cerr &lt;&lt; "RecentManagerError: " &lt;&lt; ex.what() &lt;&lt; std::endl;
}
if (info)
{
  // item was found
}Glib::RefPtr&lt;Gtk::RecentManager&gt; recent_manager = Gtk::RecentManager::get_default();
recent_manager-&gt;add_item(uri);Glib::RefPtr&lt;Gtk::TextBuffer::Mark&gt; refMark =
    refBuffer-&gt;create_mark(iter);Glib::RefPtr&lt;Gtk::TextBuffer::Tag&gt; refTagMatch =
    Gtk::TextBuffer::Tag::create();
refTagMatch-&gt;property_background() = "orange";Glib::RefPtr&lt;Gtk::TextBuffer::TagTable&gt; refTagTable =
    Gtk::TextBuffer::TagTable::create();
refTagTable-&gt;add(refTagMatch);
//Hopefully a future version of <application>gtkmm</application> will have a set_tag_table() method,
//for use after creation of the buffer.
Glib::RefPtr&lt;Gtk::TextBuffer&gt; refBuffer =
    Gtk::TextBuffer::create(refTagTable);Glib::RefPtr&lt;Gtk::TextChildAnchor&gt; refAnchor =
    refBuffer-&gt;create_child_anchor(iter);Glib::RefPtr&lt;Gtk::TreeModelSort&gt; sorted_model =
    Gtk::TreeModelSort::create(model);
sorted_model-&gt;set_sort_column(columns.m_col_name, Gtk::SORT_ASCENDING);
treeview.set_model(sorted_model);Glib::RefPtr&lt;Gtk::TreeSelection&gt; refTreeSelection =
    m_TreeView.get_selection();Glib::RefPtr&lt;Gtk::UIManager&gt; m_refUIManager =
    Gtk::UIManager::create();
m_refUIManager-&gt;insert_action_group(m_refActionGroup);
add_accel_group(m_refUIManager-&gt;get_accel_group());Glib::ustringGlib::ustring and std::iostreamsGlib::ustring strText = row[m_Columns.m_col_text];
int number = row[m_Columns.m_col_number];Glib::ustring ui_info =
    "&lt;ui&gt;"
    "  &lt;menubar name='MenuBar'&gt;"
    "    &lt;menu action='MenuFile'&gt;"
    "      &lt;menuitem action='New'/&gt;"
    "      &lt;menuitem action='Open'/&gt;"
    "      &lt;separator/&gt;"
    "      &lt;menuitem action='Quit'/&gt;"
    "    &lt;/menu&gt;"
    "    &lt;menu action='MenuEdit'&gt;"
    "      &lt;menuitem action='Cut'/&gt;"
    "      &lt;menuitem action='Copy'/&gt;"
    "      &lt;menuitem action='Paste'/&gt;"
    "    &lt;/menu&gt;"
    "  &lt;/menubar&gt;"
    "  &lt;toolbar  name='ToolBar'&gt;"
    "    &lt;toolitem action='Open'/&gt;"
    "    &lt;toolitem action='Quit'/&gt;"
    "  &lt;/toolbar&gt;"
    "&lt;/ui&gt;";

m_refUIManager-&gt;add_ui_from_string(ui_info);Glib::ustring ui_info =
    "&lt;ui&gt;"
    "  &lt;popup name='PopupMenu'&gt;"
    "    &lt;menuitem action='ContextEdit'/&gt;"
    "    &lt;menuitem action='ContextProcess'/&gt;"
    "    &lt;menuitem action='ContextRemove'/&gt;"
    "  &lt;/popup&gt;"
    "&lt;/ui&gt;";

m_refUIManager-&gt;add_ui_from_string(ui_info);GridGroupsGtk::Alignment
Gtk::Arrow
Gtk::AspectFrame
Gtk::Bin
Gtk::Box
Gtk::Button
Gtk::CheckButton
Gtk::Fixed
Gtk::Frame
Gtk::Grid
Gtk::Image
Gtk::Label
Gtk::MenuItem
Gtk::Notebook
Gtk::Paned
Gtk::RadioButton
Gtk::Range
Gtk::ScrolledWindow
Gtk::Separator
Gtk::Table (deprecated from <application>gtkmm</application> version 3.4)
Gtk::ToolbarGtk::Application and command-line optionsGtk::Box(Gtk::Orientation orientation = Gtk::ORIENTATION_HORIZONTAL, int spacing = 0);
void set_spacing(int spacing);
void set_homogeneous(bool homogeneous = true);Gtk::Button* pButton = new Gtk::Button("_Something", true);Gtk::CellRendererToggle* pRenderer =
    Gtk::manage( new Gtk::CellRendererToggle() );
pRenderer-&gt;signal_toggled().connect(
    sigc::bind( sigc::mem_fun(*this,
        &amp;Example_TreeView_TreeStore::on_cell_toggled), m_columns.dave)
);Gtk::ComboBox now derives from CellLayout, allowing easier layout and alignment of its <classname>Gtk::CellRenderer</classname>s.Gtk::DrawingArea myArea;
Cairo::RefPtr&lt;Cairo::Context&gt; myContext = myArea.get_window()-&gt;create_cairo_context();
myContext-&gt;set_source_rgb(1.0, 0.0, 0.0);
myContext-&gt;set_line_width(2.0);Gtk::Entry* entry = m_Combo.get_entry();
if (entry)
{
  // The Entry shall receive focus-out events.
  entry-&gt;add_events(Gdk::FOCUS_CHANGE_MASK);

  // Alternatively you can connect to m_Combo.signal_changed().
  entry-&gt;signal_changed().connect(sigc::mem_fun(*this,
    &amp;ExampleWindow::on_entry_changed) );

  entry-&gt;signal_activate().connect(sigc::mem_fun(*this,
    &amp;ExampleWindow::on_entry_activate) );

  entry-&gt;signal_focus_out_event().connect(sigc::mem_fun(*this,
    &amp;ExampleWindow::on_entry_focus_out_event) );
}Gtk::EventBox();Gtk::Label support some simple formatting, for instance allowing you to make some text bold, colored, or larger. You can do this by providing a string to <methodname>set_markup()</methodname>, using the <ulink url="http://developer.gnome.org/pango/unstable/PangoMarkupFormat.html">Pango Markup syntax</ulink>. For instance, <code> &lt;b&gt;bold text&lt;/b&gt; and &lt;s&gt;strikethrough text&lt;/s&gt; </code> .Gtk::TreeModel::Children children = row.children();Gtk::TreeModel::Row row = *iter;Gtk::TreeModel::Row row = m_refModel-&gt;children()[5]; //The fifth row.
if(row)
  refTreeSelection-&gt;select(row);Gtk::TreeModel::iterator iter = m_Combo.get_active();
if(iter)
{
  Gtk::TreeModel::Row row = *iter;

  //Get the data for the selected row, using our knowledge
  //of the tree model:
  int id = row[m_Columns.m_col_id];
  set_something_id_chosen(id); //Your own function.
}
else
  set_nothing_chosen(); //Your own function.Gtk::TreeModel::iterator iter = m_refListStore-&gt;append();Gtk::TreeModel::iterator iter = m_refModel-&gt;children().begin()
if(iter)
  refTreeSelection-&gt;select(iter);Gtk::TreeModel::iterator iter_child =
    m_refTreeStore-&gt;append(row.children());Gtk::TreeView::Column* pColumn =
  Gtk::manage(new Gtk::TreeView::Column("Icon Name"));

// m_columns.icon and m_columns.iconname are columns in the model.
// pColumn is the column in the TreeView:
pColumn-&gt;pack_start(m_columns.icon, /* expand= */ false);
pColumn-&gt;pack_start(m_columns.iconname);

m_TreeView.append_column(*pColumn);Gtk::TreeView::Column* pColumn = treeview.get_column(0);
if(pColumn)
  pColumn-&gt;set_sort_column(m_columns.m_col_id);Gtk::Widget* pMenubar = m_refUIManager-&gt;get_widget("/MenuBar");
pBox-&gt;add(*pMenuBar, Gtk::PACK_SHRINK);Gtk::Window window;
window.set_default_size(200, 200);Hand-coded source filesHand-coding constructorsHandle the options in <function>main()</function> and hide them from <classname>Gtk::Application</classname> by setting <literal>argc = 1</literal> in the call to <methodname>Gtk::Application::create()</methodname>.Handling <literal>button_press_event</literal>Handling an X event doesn't affect the Widget's other signals. If you handle <literal>button_press_event</literal> for <classname>Gtk::Button</classname>, you'll still be able to get the <literal>clicked</literal> signal. They are emitted at (nearly) the same time.Headers and LinkingHello WorldHello World 2Hello World in <application>gtkmm</application>HelloWorld::HelloWorld()
:
  m_button ("Hello World")
{
  set_border_width(10);
  m_button.signal_clicked().connect(sigc::mem_fun(*this,
    &amp;HelloWorld::on_button_clicked));
  add(m_button);.
  m_button.show();
}Here are some examples of normal C++ memory management:Here is a list of some of these Widgets:Here is a simple example that packs 100 toggle buttons into a ScrolledWindow. Try resizing the window to see the scrollbars react.Here is a small bit of code to tie it all together: (Note that usually you wouldn't load the image every time in the draw signal handler! It's just shown here to keep it all together.)Here is a very simple example, demonstrating a drag and drop <literal>Copy</literal> operation:Here is an example callback method:Here is an example of a program that draws some text, some of it upside-down. The Printing chapter contains another <link linkend="sec-printing-example">example</link> of drawing text.Here is an example of a simple program that draws an image.Here is an excerpt from a <application>gdb</application> session. Only the most interesting parts of the output are shown. <placeholder-1/> You can see that the exception was thrown from <filename>without_signal.cc</filename>, line 6 (<code>throw "Something";</code>).Here is some example code from <filename>gtkmm/demos/gtk-demo/example_icontheme.cc</filename>, which has a pixbuf icon and a text name in the same column:Here is the source code for the example that produced the screenshots above. When you run this example, provide a number between 1 and 3 as a command-line option, to see different packing options in use.Here we define a new class called <classname>OverriddenButton</classname>, which inherits from <classname>Gtk::Button</classname>. The only thing we change is the <methodname>on_clicked()</methodname> method, which is called whenever <classname>Gtk::Button</classname> emits the <literal>clicked</literal> signal. This method prints "Hello World" to <literal>stdout</literal>, and then calls the original, overridden method, to let <classname>Gtk::Button</classname> do what it would have done had we not overridden.Here's a simple example: <placeholder-1/>Here's a slightly larger example of slots in action:Here's an example of a <classname>SpinButton</classname> in action:Here's an example of a signal handler being connected to a signal:Here's an example of a simple program that draws an arc, a circle and an ellipse into a drawing area.Here's an example of this technique:Here's the constructor for the <classname>Box</classname> widget, and methods that set per-container packing options: <placeholder-1/> Passing <literal>true</literal> to <methodname>set_homogeneous()</methodname> will cause all of the contained widgets to be the same size. <parameter>spacing</parameter> is a (minimum) number of pixels to leave between each widget.How gettext worksHow to use Git for GNOME translatorsHowever, care is required when writing programs based on <application>gtkmm</application> using multiple threads of execution, arising from the fact that <application>libsigc++</application>, and in particular <classname>sigc::trackable</classname>, are not thread-safe. That's because none of the complex interactions that occur behind the scenes when using <application>libsigc++</application> are protected by a mutex or other means of synchronization. <placeholder-1/>However, this does not allow you any control of which items can be dragged, and where they can be dropped. If you need that extra control then you might create a derived <literal>Gtk::TreeModel</literal> from <literal>Gtk::TreeStore</literal> or <literal>Gtk::ListStore</literal> and override the <literal>Gtk::TreeDragSource::row_draggable()</literal> and <literal>Gdk::TreeDragDest::row_drop_possible()</literal> virtual methods. You can examine the <literal>Gtk::TreeModel::Path</literal>s provided and allow or disallow dragging or dropping by returning <literal>true</literal> or <literal>false</literal>.However, this is even simpler when using the <function>PKG_CHECK_MODULES()</function> macro in a standard configure.ac file with autoconf and automake. For instance: <placeholder-1/> This checks for the presence of gtkmm and defines MYAPP_LIBS and MYAPP_CFLAGS for use in your Makefile.am files.However, you might not want the new values to be stored immediately. For instance, maybe you want to restrict the input to certain characters or ranges of values.However, you probably already avoid bare char* arrays and pointer arithmetic by using <classname>std::string</classname>, so you just need to start using <classname>Glib::ustring</classname> instead. See the <link linkend="sec-basics-ustring">Basics</link> chapter about <classname>Glib::ustring</classname>.I've been embedded.
A plug was addedINTLTOOL_FILES = intltool-extract.in \
                 intltool-merge.in \
                 intltool-update.inIT_PROG_INTLTOOL([0.35.0])

GETTEXT_PACKAGE=programname
AC_SUBST(GETTEXT_PACKAGE)
AC_DEFINE_UNQUOTED([GETTEXT_PACKAGE], ["$GETTEXT_PACKAGE"],
                   [The domain to use with gettext])
AM_GLIB_GNU_GETTEXT

PROGRAMNAME_LOCALEDIR=[${datadir}/locale]
AC_SUBST(PROGRAMNAME_LOCALEDIR)IdealIdeally, we would like you to <ulink url="http://www.gtkmm.org/bugs.shtml">provide a patch</ulink> to the <filename>docs/tutorial/C/gtkmm-tutorial-in.xml</filename> file. This file is currently in the <literal>gtkmm-documentation</literal> module in GNOME git.Idle FunctionsIf a particular class object derives from <classname>sigc::trackable</classname>, only one thread should create <classname>sigc::slot</classname> objects representing any of the class's non-static methods by calling <function>sigc::mem_fun()</function>. The first thread to create such a slot should be regarded as owning the relevant object for the purpose of creating further slots referencing <emphasis>any</emphasis> of its non-static methods using that function, or nulling those slots by disconnecting them or destroying the trackable object.If a programmer does not need a class scope widget, a function scope widget may also be used. The advantages to function scope over class scope are the increased data hiding and reduced dependencies. <placeholder-1/>If a programmer does not need dynamic memory allocation, automatic widgets in class scope may be used. One advantage of automatic widgets in class scope is that memory management is grouped in one place. The programmer does not risk memory leaks from failing to <literal>delete</literal> a widget.If everything worked correctly, you should be able to build <application>gtkmm</application> and all of its dependencies from git by executing <command>jhbuild build</command> (or, if you didn't specify <application>gtkmm</application> in the <varname>modules</varname> variable, with the command <command>jhbuild build gtkmm</command>).If for some reason the <classname>Socket</classname> couldn't attach the <classname>Plug</classname>, the window would look something like this:If the enum is not a <classname>GType</classname>, you must pass a third parameter NO_GTYPE. This is the case when there is no <function>*_get_type()</function> function for the C enum, but be careful that you don't just need to include an extra header for that function. You should also file a bug against the C API, because all enums should be registered as GTypes.If there are many caught exceptions before the interesting uncaught one, this method can be tedious. It can be automated with the following <application>gdb</application> commands. <placeholder-1/> These commands will print a backtrace from each <code>throw</code> and continue. The backtrace from the last (or possibly the last but one) <code>throw</code> before the program stops, is the interesting one.If this is the first time you're using a program that uses the Recent Files framework, the dialog may be empty at first. Otherwise it should show the list of recently used documents registered by other applications.If you are interested in helping out with the development of <application>gtkmm</application>, or fixing a bug in <application>gtkmm</application>, you'll probably need to build the development version of <application>gtkmm</application>. However, you should not install a development version over your stable version. Instead, you should install it alongside your existing <application>gtkmm</application> installation, in a separate path.If you are using <application>gettext</application> directly, you can only mark strings for translation if they are in source code file. However, if you use <application>intltool</application>, you can mark strings for translation in a variety of other file formats, including <application>Glade</application> UI files, xml, <ulink url="http://standards.freedesktop.org/desktop-entry-spec/latest/">.desktop files</ulink> and several more. So, if you have designed some of the application UI in <application>Glade</application> then also add your <filename>.glade</filename> files to the list in <literal>POTFILES.in</literal>.If you call <methodname>Gtk::TreeView::set_reorderable()</methodname> then your TreeView's items can be moved within the treeview itself. This is demonstrated in the <classname>TreeStore</classname> example.If you copied the skeleton source tree in mm-common and substituted the placeholder text, then you will already have suitable <filename>Makefile.am</filename> and <filename>Doxyfile.in</filename> files. With the mm-common build setup, the list of Doxygen input files is not defined in the Doxygen configuration file, but passed along from <command>make</command> to the standard input of <command>doxygen</command>. The input file list is defined by the <varname>doc_input</varname> variable in the <filename>Makefile.am</filename> file.If you copy a <classname>RefPtr</classname>, for instance <placeholder-1/> , or if you pass it as a method argument or a return type, then <classname>RefPtr</classname> will do any necessary referencing to ensure that the instance will not be destroyed until the last <classname>RefPtr</classname> has gone out of scope.If you do decide to contribute, please post your contribution to the <application>gtkmm</application> mailing list at <ulink url="mailto:gtkmm-list@gnome.org">&lt;gtkmm-list@gnome.org&gt;</ulink>. Also, be aware that the entirety of this document is free, and any addition you provide must also be free. That is, people must be able to use any portion of your examples in their programs, and copies of this document (including your contribution) may be distributed freely.If you don't want to look for a specific URI, but instead want to get a list of all recently used items, <classname>RecentManager</classname> provides the <methodname>get_items()</methodname> function. The return value of this function is a <classname>std::vector</classname> of all recently used files. The following code demonstrates how you might get a list of recently used files:If you have created a <classname>Tag</classname> and added it to the <classname>TagTable</classname>, you may apply that tag to part of the <classname>TextBuffer</classname> so that some of the text is displayed with that formatting. You define the start and end of the range of text by specifying <classname>Gtk::TextBuffer::iterator</classname>s. For instance:If you pass <literal>true</literal> to the <methodname>set_activates_default()</methodname> method, pressing Enter in the <classname>Gtk::Entry</classname> will activate the default widget for the window containing the <classname>Gtk::Entry</classname>. This is especially useful in dialog boxes. The default widget is usually one of the dialog buttons, which e.g. will close the dialog box. To set a widget as the default widget, use <methodname>Gtk::Widget::set_can_default()</methodname> and <methodname>Gtk::Widget::grab_default()</methodname>.If you share an adjustment object between a Scrollbar and a TextView widget, manipulating the scrollbar will automagically adjust the TextView widget. You can set it up like this:If you try to draw one pixel wide lines, you may notice that the line sometimes comes up blurred and wider than it ought to be. This happens because Cairo will try to draw from the selected position, to both sides (half to each), so if you're positioned right on the intersection of the pixels, and want a one pixel wide line, Cairo will try to use half of each adjacent pixel, which isn't possible (a pixel is the smallest unit possible). This happens when the width of the line is an odd number of pixels (not just one pixel).If you use one signal handler to catch the same signal from several widgets, you might like that signal handler to receive some extra information. For instance, you might want to know which button was clicked. You can do this with <function>sigc::bind()</function>. Here's some code from the <link linkend="sec-helloworld2">helloworld2</link> example. <placeholder-1/> This says that we want the signal to send an extra <classname>Glib::ustring</classname> argument to the signal handler, and that the value of that argument should be "button 1". Of course we will need to add that extra argument to the declaration of our signal handler: <placeholder-2/> Of course, a normal "clicked" signal handler would have no arguments.If you want to help develop <application>gtkmm</application> or experiment with new features, you can also install <application>gtkmm</application> from git. Most users will never need to do this, but if you're interested in helping with <application>gtkmm</application> development, see the <link linkend="chapter-working-with-source">Working with gtkmm's Source Code</link> appendix.If you want to register a file with metadata, you can pass a <classname>RecentManager::Data</classname> parameter to <methodname>add_item()</methodname>. The metadata that can be set on a particular file item is as follows:If you want to specify a method that gets called when nothing else is happening, use the following:If you wish to learn more about smartpointers, you might look in these books: <placeholder-1/>If you've drawn a series of lines that form a path, you may want them to join together in a certain way. Cairo offers three different ways to join lines together: Miter, Bevel, and Round. These are show below:If you've never used a packing toolkit before, it can take some getting used to. You'll probably find, however, that you don't need to rely on visual form editors quite as much as you might with other toolkits.If your distribution does not provide a pre-built <application>gtkmm</application> package, or if you want to install a different version than the one provided by your distribution, you can also install <application>gtkmm</application> from source. The source code for <application>gtkmm</application> can be downloaded from <ulink url="http://www.gtkmm.org/"/>.If your program is free software, there is a whole <literal>GNOME</literal> subproject devoted to helping you make translations, the <ulink url="https://wiki.gnome.org/TranslationProject/"><literal>GNOME</literal> Translation Project</ulink>.Implementing custom logic for editable cells.In <filename>configure.ac</filename>, <placeholder-1/>In <filename>skeleton/skeletonmm/Makefile.am</filename> we must mention the correct values for the generic variables that are used elsewhere in the build system:In <filename>skeleton/src/Makefile.am</filename> we must mention the correct values for the generic variables that are used elsewhere in the build system:In addition to adding items to the list, you can also look up items from the list and modify or remove items.In addition to changing a file's URI, you can also remove items from the list, either one at a time or by clearing them all at once. The former is accomplished with <methodname>remove_item()</methodname>, the latter with <methodname>purge_items()</methodname>.In addition to drawing basic straight lines, there are a number of things that you can customize about a line. You've already seen examples of setting a line's color and width, but there are others as well.In addition to drawing straight lines Cairo allows you to easily draw curved lines (technically a cubic Bézier spline) using the <methodname>Cairo::Context::curve_to()</methodname> and <methodname>Cairo::Context::rel_curve_to()</methodname> functions. These functions take coordinates for a destination point as well as coordinates for two 'control' points. This is best explained using an example, so let's dive in.In general, gtkmm-style projects use Doxygen, which reads specially formatted C++ comments and generates HTML documentation. You may write these doxygen comments directly in the header files.In the <classname>Gtk::Window</classname>, we have also the default handler overridden (<methodname>on_key_release_event()</methodname>), and another handler being called before the default handler (<methodname>windowKeyReleaseBefore()</methodname>).In the <link linkend="sec-wrapping-hg-files">.hg and .ccg files</link> section you can learn about the syntax used in these files.In the example above we drew everything using absolute coordinates. You can also draw using relative coordinates. For a straight line, this is done with the function <methodname>Cairo::Context::rel_line_to()</methodname>.In the instructions below we will assume that you will not be using <application>gettext</application> directly, but <application>intltool</application>, which was written specifically for <literal>GNOME</literal>. <application>intltool</application> uses <function>gettext()</function>, which extracts strings from source code, but <application>intltool</application> can also combine strings from other files, for example from desktop menu details, and GUI resource files such as <application>Glade</application> files, into standard <application>gettext</application><filename>.pot/.po</filename> files.In the top-level Makefile.am: <placeholder-1/>In these cases, you should add extra characters to the strings. For instance, use <literal>"jumps[noun]"</literal> and <literal>"jumps[verb]"</literal> instead of just <literal>"jumps"</literal> and strip them again outside the <function>gettext</function> call. If you add extra characters you should also add a comment for the translators before the <function>gettext</function> call. Such comments will be shown in the <filename>.po</filename> files. For instance:In this example there are three event handlers that are called after <classname>Gtk::Window</classname>'s default event handler, one in the <classname>Gtk::Entry</classname>, one in the <classname>Gtk::Grid</classname> and one in the <classname>Gtk::Window</classname>.In this example there are three keyboard shortcuts: <keycap>Alt</keycap>+<keycap>1</keycap> selects the first radio button, <keycap>Alt</keycap>+<keycap>2</keycap> selects the second one, and the <keycap>Esc</keycap> key hides (closes) the window. The default event signal handler is overridden, as described in the <link linkend="sec-overriding-default-signal-handlers">Overriding default signal handlers</link> section in the appendix.In this example, we'll construct a small but fully functional <application>gtkmm</application> program and draw some lines into the window. The lines are drawn by creating a path and then stroking it. A path is created using the functions <methodname>Cairo::Context::move_to()</methodname> and <methodname>Cairo::Context::line_to()</methodname>. The function <methodname>move_to()</methodname> is similar to the act of lifting your pen off of the paper and placing it somewhere else -- no line is drawn between the point you were at and the point you moved to. To draw a line between two points, use the <methodname>line_to()</methodname> function.In this section of the tutorial, we'll cover the basic Cairo drawing model, describe each of the basic drawing elements in some detail (with examples), and then present a simple application that uses Cairo to draw a custom clock widget.In your <literal>src/Makefile.am</literal>, update your <literal>AM_CPPFLAGS</literal> to add the following preprocessor macro definition:In your callback, compare the vector of available targets with those that your application supports for pasting. You could enable or disable a Paste menu item, depending on whether pasting is currently possible. For instance:In your signal handler, you should examine the new value and then store it in the Model if that is appropriate for your application.Includes the other files.Independently sorted views of the same modelInfoBarInheritance can be used to derive new widgets. The derivation of new widgets in GTK+ C code is so complicated and error prone that almost no C coders do it. As a C++ developer you know that derivation is an essential Object Orientated technique.InitializationInstallationInstalling <application>gtkmm</application> with <application>jhbuild</application>Installing From SourceInstalling and Using the git version of <application>gtkmm</application>Instead of laboriously connecting signal handlers to signals, you can simply make a new class which inherits from a widget - say, a Button - and then override the default signal handler, such as Button::on_clicked(). This can be a lot simpler than hooking up signal handlers for everything.Intermediate typesInternationalization and LocalizationIntltool READMEIntroductionIt also takes an optional extra argument: <placeholder-1/>It follows the same form. The number 3 at the end of the type's name indicates that our signal handler will need three arguments. The first type in the type list is <type>void</type>, so that should be our signal handler's return type. The following three types are the argument types, in order. Our signal handler's prototype could look like this:It is common for binding modules to track the version number of the library they are wrapping. So, for instance, if the C library is at version 1.23.4, then the initial version of the binding module would be 1.23.0. However, avoid starting with an even minor version number as that usually indicates a stable release.It is good practice to put all modifications to the graphics state between <methodname>save()</methodname>/<methodname>restore()</methodname> function calls. For example, if you have a function that takes a <classname>Cairo::Context</classname> reference as an argument, you might implement it as follows:It supports pasting of 2 targets - both the custom one and a text one that creates an arbitrary text representation of the custom data.It uses <methodname>request_targets()</methodname> and the <literal>owner_change</literal> signal and disables the Paste button if it can't use anything on the clipboard.It's impossible to predict the amount of space necessary for text after it has been translated to other languages, or displayed in a different font. On Unix it is also impossible to anticipate the effects of every theme and window manager.It's possible that certain strings will be marked as <literal>fuzzy</literal> in the <filename>.po</filename> file. These translations will not substitute the original string. To make them appear, simply remove the <literal>fuzzy</literal> tag.Iterating over Model RowsIteratorsJonathonJongsmaJust call the non-const version of the same function, instead of generating almost duplicate code.Just like normal pointers, you can check whether a <classname>RefPtr</classname> points to anything.Keyboard EventsKeyboard Events - Event PropagationKeyboard Events - SimpleKingKjellL10N Guidelines for DevelopersLabelLabels are the main method of placing non-editable text in windows, for instance to place a title next to a <classname>Entry</classname> widget. You can specify the text in the constructor, or later with the <methodname>set_text()</methodname> or <methodname>set_markup()</methodname> methods.Lack of propertiesLaursenLess C++ code is required.Let's look at an example of overriding:Let's take a look at a slightly improved <literal>helloworld</literal>, showing what we've learnt.Let's take another look at a Signal's <literal>connect</literal> method:Like checkboxes, radio buttons also inherit from <classname>Gtk::ToggleButton</classname>, but these work in groups, and only one RadioButton in a group can be selected at any one time.Like the <classname>TreeView</classname>, you should probably put your <classname>TextView</classname> inside a <classname>ScrolledWindow</classname> to allow the user to see and move around the whole text area with scrollbars.Likewise, replace all instances of <varname>Joe Hacker</varname> by the name of the intended copyright holder, which is probably you. Do the same for the <varname>joe@example.com</varname> email address.Line ends can have different styles as well. The default style is for the line to start and stop exactly at the destination points of the line. This is called a Butt cap. The other options are Round (uses a round ending, with the center of the circle at the end point) or Square (uses a squared ending, with the center of the square at the end point). This setting is set using the function <methodname>Cairo::Context::set_line_cap()</methodname>.Line stylesListStoreListStore, for rowsLoading the .glade fileLooking up Items in the List of Recent FilesLots of people need to implement right-click context menus for <classname>TreeView</classname>'s so we will explain how to do that here to save you some time. Apart from one or two points, it's much the same as a normal context menu, as described in the <link linkend="sec-menus-popup">menus chapter</link>.Main MenuMain Menu exampleMakefile.am filesManaged WidgetsMany Cairo drawing functions have a <methodname>_preserve()</methodname> variant. Normally drawing functions such as <methodname>clip()</methodname>, <methodname>fill()</methodname>, or <methodname>stroke()</methodname> will clear the current path. If you use the <methodname>_preserve()</methodname> variant, the current path will be retained so that you can use the same path with the next drawing function.Many GUI toolkits require you to precisely place widgets in a window, using absolute positioning, often using a visual editor. This leads to several problems:Marking strings for translationMarkoMarksMaybe the user should not be able to select every item in your list or tree. For instance, in the gtk-demo, you can select a demo to see the source code, but it doesn't make any sense to select a demo category.Member instances can be used, simplifying memory management. All GTK+ C widgets are dealt with by use of pointers. As a C++ coder you know that pointers should be avoided where possible.Memory managementMenus and ToolbarsMessageDialogMethod macrosMethodsMicrosoft WindowsMiscellaneous WidgetsMixing C and C++ APIsModel ColumnsModelColumns()
{ add(m_col_id); add(m_col_name); }

  Gtk::TreeModelColumn&lt;int&gt; m_col_id;
  Gtk::TreeModelColumn&lt;Glib::ustring&gt; m_col_name;
};

ModelColumns m_columns;Modifying build filesModifying the List of Recent FilesMonitoring I/OMore information about what lies behind the internationalization and localization process is presented and demonstrated in: <placeholder-1/>More than one Model Column per View ColumnMost applications will have only one <classname>Window</classname>, or only one main window. These applications can use the <methodname>Gtk::Application::run(Gtk::Window&amp;)</methodname> overload. It shows the window and returns when the window has been hidden. This might happen when the user closes the window, or when your code decides to <methodname>hide()</methodname> the window. You can prevent the user from closing the window (for instance, if there are unsaved changes) by overriding <methodname>Gtk::Window::on_delete_event()</methodname>.Most custom widgets need their own <classname>Gdk::Window</classname> to draw on. Then you can call <methodname>Gtk::Widget::set_has_window(true)</methodname> in your constructor. (This is the default value.) If you do not call <methodname>set_has_window(false)</methodname>, you must override <methodname>on_realize()</methodname> and call <methodname>Gtk::Widget::set_realized()</methodname> and <methodname>Gtk::Widget::set_window()</methodname> from there.Most dialogs in this chapter are modal, that is, they freeze the rest of the application while they are shown. It's also possible to create a non-modal dialog, which does not freeze other windows in the application. The following example shows a non-modal <classname>AboutDialog</classname>. This is perhaps not the kind of dialog you would normally make non-modal, but non-modal dialogs can be useful in other cases. E.g. <application>gedit</application>'s search-and-replace dialog is non-modal.Most of our examples use this technique.Most of the chapters in this book deal with specific widgets. See the <link linkend="chapter-container-widgets">Container Widgets</link> section for more details about adding widgets to container widgets.Most of the useful member methods for this class are actually in the <classname>Gtk::FileChooser</classname> base class.Most packing uses boxes as in the above example. These are invisible containers into which we can pack our widgets. When packing widgets into a horizontal box, the objects are inserted horizontally from left to right or right to left depending on whether <methodname>pack_start()</methodname> or <methodname>pack_end()</methodname> is used. In a vertical box, widgets are packed from top to bottom or vice versa. You may use any combination of boxes inside or beside other boxes to create the desired effect.MoveMulti-Threaded ProgramMulti-threaded programsMultiple-item widgetsMultiple-item widgets inherit from <classname>Gtk::Container</classname>; just as with <classname>Gtk::Bin</classname>, you use the <methodname>add()</methodname> and <methodname>remove()</methodname> methods to add and remove contained widgets. Unlike <methodname>Gtk::Bin::remove()</methodname>, however, the <methodname>remove()</methodname> method for <classname>Gtk::Container</classname> takes an argument, specifiying which widget to remove.MurrayMurray CummingNext we call the Window's <methodname>set_border_width()</methodname> method. This sets the amount of space between the sides of the window and the widget it contains.Next we make an object of our <classname>HelloWorld</classname> class, whose constructor takes no arguments, but it isn't visible yet. When we call <methodname>Gtk::Application::run()</methodname>, giving it the helloworld Window, it shows the Window and starts the <application>gtkmm</application><emphasis>event loop</emphasis>. During the event loop <application>gtkmm</application> idles, waiting for actions from the user, and responding appropriately. When the user closes the Window, run() will return, causing the final line of our main() function be to executed. The application will then finish.Next we must adapt the various <filename>Makefile.am</filename> files: <placeholder-1/>Next you should create a <classname>UIManager</classname> and add the <classname>ActionGroup</classname> to the <classname>UIManager</classname> with <methodname>insert_action_group()</methodname> At this point is also a good idea to tell the parent window to respond to the specified keyboard shortcuts, by using <methodname>add_accel_group()</methodname>.Next, we use the Window's <methodname>add()</methodname> method to put <literal>m_button</literal> in the Window. (<methodname>add()</methodname> comes from <classname>Gtk::Container</classname>, which is described in the chapter on container widgets.) The <methodname>add()</methodname> method places the Widget in the Window, but it doesn't display the widget. <application>gtkmm</application> widgets are always invisible when you create them - to display them, you must call their <methodname>show()</methodname> method, which is what we do in the next line.Nicolai M. Josuttis, "The C++ Standard Library" - section 4.2Non-modal AboutDialogNormal C++ memory managementNote also that not all widgets receive all X events by default. To receive additional X events, you can use <methodname>Gtk::Widget::set_events()</methodname> before showing the widget, or <methodname>Gtk::Widget::add_events()</methodname> after showing the widget. However, some widgets must first be placed inside an <classname>EventBox</classname> widget. See the <link linkend="chapter-widgets-without-xwindows">Widgets Without X-Windows</link> chapter.Note that UTF-8 isn't compatible with 8-bit encodings like ISO-8859-1. For instance, German umlauts are not in the ASCII range and need more than 1 byte in the UTF-8 encoding. If your code contains 8-bit string literals, you have to convert them to UTF-8 (e.g. the Bavarian greeting "Grüß Gott" would be "Gr\xC3\xBC\xC3\x9F Gott").Note that files ending in <filename>.in</filename> will be used to generate files with the same name but without the <filename>.in</filename> suffix, by replacing some variables with actual values during the configure stage.Note that if you mention extra modules in addition to gtkmm-3.0, they should be separated by spaces, not commas.Note that in this case, we've expressed nearly everything in terms of the height and width of the window, including the width of the lines. Because of this, when you resize the window, everything scales with the window. Also note that there are three drawing sections in the function and each is wrapped with a <methodname>save()</methodname>/<methodname>restore()</methodname> pair so that we're back at a known state after each drawing.Note that most language teams only consist of 1-3 persons, so if your program contains a lot of strings, it might last a while before anyone has the time to look at it. Also, most translators do not want to waste their time (translating is a very time-consuming task) so if they do not assess your project as being really serious (in the sense that it is polished and being maintained) they may decide to spend their time on some other project.Note that the instance (such as m_Columns here) should usually not be static, because it often needs to be instantiated after glibmm has been instantiated.Note that this is where we specify the names of the actions as they will be seen by users in menus and toolbars. Therefore, this is where you should make strings translatable, by putting them inside the _() macro.Note that to build <application>gtkmm</application> from git, you'll often need to build many of its dependencies from git as well. <application>jhbuild</application> makes this easier than it would normally be, but it will take quite a while to build and install them all. You will probably encounter build problems, though these will usually be corrected quickly if you report them.Note that we don't pass a pointer to <methodname>on_button_clicked()</methodname> directly to the signal's <methodname>connect()</methodname> method. Instead, we call <function>sigc::ptr_fun()</function>, and pass the result to <methodname>connect()</methodname>.Note that you can't just do <placeholder-1/> because the group is modified by <methodname>set_group()</methodname> and therefore non-const.Note that you must specify actions for sub menus as well as menu items.Note that, due to GTK+'s theming system, the appearance of these widgets will vary. In the case of checkboxes and radio buttons, they may vary considerably.Note, however, that the TreeView will provide iterators to the sorted model. You must convert them to iterators to the underlying child model in order to perform actions on that model. For instance:NotebookNotice that the return value is of type <classname>sigc::signal&lt;void,int&gt;::iterator</classname>. This can be implicitly converted into a <classname>sigc::connection</classname> which in turn can be used to control the connection. By keeping a connection object you can disconnect its associated signal handler using the method <methodname>sigc::connection::disconnect()</methodname>.Notice that we provided <command>gmmproc</command> with the path to the .m4 convert files, the path to the .defs file, the name of a .hg file, the source directory, and the destination directory.Notice that we've used an initialiser statement to give the <literal>m_button</literal> object the label "Hello World".Notice, that after canceling an event, no other function will be called (even if it is from the same widget).Now let's look at our program's <function>main()</function> function. Here it is, without comments:Now let's look at the connection again:Now let's see what happens when an exception is thrown from a signal handler. Here's the source code. <placeholder-1/>Now let's take a look at the code that performs the actual drawing. The first section of <methodname>on_draw()</methodname> should be pretty familiar by now. This example again scales the coordinate system to be a unit square so that it's easier to draw the clock as a percentage of window size so that it will automatically scale when the window size is adjusted. Furthermore, the coordinate system is scaled over and down so that the (0, 0) coordinate is in the very center of the window.Now that there is a place to put your translations, you need to initialize <application>intltool</application> and <application>gettext</application>. Add the following code to your <literal>configure.ac</literal>, substituting 'programname' with the name of your program:Now that we understand the basics of the Cairo graphics library, we're almost ready to start drawing. We'll start with the simplest of drawing elements: the straight line. But first you need to know a little bit about Cairo's coordinate system. The origin of the Cairo coordinate system is located in the upper-left corner of the window with positive x values to the right and positive y values going down. <placeholder-1/>Now that we've covered the basics of drawing with Cairo, let's try to put it all together and create a simple application that actually does something. The following example uses Cairo to create a custom <classname>Clock</classname> widget. The clock has a second hand, a minute hand, and an hour hand, and updates itself every second.Now that you've seen signals and signal handlers in <application>gtkmm</application>, you might like to use the same technique to allow interaction between your own classes. That's actually very simple by using the <application>libsigc++</application> library directly.Now we edit the files to adapt them to our needs. You might prefer to use a multiple-file search-replace utility for this, such as <command>regexxer</command>. Note that nearly all of the files provided with the skeleton source tree contain placeholder text. Thus, the substitutions should be performed globally, and not be limited to the Automake and Autoconf files.OK, you say, that's nice, but what if I want to create my own handlers to respond when the user adjusts a <classname>Range</classname> widget or a <classname>SpinButton</classname>. To access the value of a <classname>Gtk::Adjustment</classname>, you can use the <methodname>get_value()</methodname> and <methodname>set_value()</methodname> methods:Objects and functions.Objects such as <classname>Gdk::Pixbuf</classname> can only be instantiated with a <methodname>create()</methodname> function. For instance, <placeholder-1/>Objects used via <classname>RefPtr</classname>: Pass the <classname>RefPtr</classname> as a const reference. For instance, <code>const Glib::RefPtr&lt;Gtk::FileFilter&gt;&amp; filter</code>.Occasionally you might want to make an <classname>Entry</classname> widget read-only. This can be done by passing <literal>false</literal> to the <methodname>set_editable()</methodname> method.Of course this means that you can store <classname>RefPtr</classname>s in standard containers, such as <classname>std::vector</classname> or <classname>std::list</classname>.Of course, a top-level container will not be added to another container. The programmer is responsible for destroying the top-level container using one of the traditional C++ techniques. For instance, your top-level Window might just be an instance in your <function>main()</function> function.Often when wrapping methods, it is desirable to store the return of the C function in what is called an output parameter. In this case, the C++ method returns <type>void</type> but an output parameter in which to store the value of the C function is included in the argument list of the C++ method. gmmproc allows such functionality, but appropriate initialization macros must be included to tell gmmproc how to initialize the C++ parameter from the return of the C function.OleOn Unix, the default preview handler uses an external viewer program. On Windows, the native preview dialog will be shown. If necessary you may override this behaviour and provide a custom preview dialog. See the example located in /examples/book/printing/advanced.Once you've built your software, you'll need to run your program within the jhbuild environment as well. To do this, you can again use the <command>jhbuild shell</command> command to start a new shell with the <application>jhbuild</application> environment set up. Alternatively, you can execute a one-off command in the <application>jhbuild</application> environment using the following command: <command>jhbuild run command-name</command>. In this case, the command will be run with the correct environment variables set, but will return to your previous environment after the program exits.Once you've configured <application>jhbuild</application> as described above, building <application>gtkmm</application> should be relatively straightforward. The first time you run <application>jhbuild</application>, you should run the following sequence of commands to ensure that <application>jhbuild</application> has the required tools and verify that it is set up correctly: <screen>$ jhbuild bootstrap
$ jhbuild sanitycheck</screen>One of the benefits of UTF-8 is that you don't need to use it unless you want to, so you don't need to retrofit all of your code at once. <classname>std::string</classname> will still work for 7-bit ASCII strings. But when you try to localize your application for languages like Chinese, for instance, you will start to see strange errors, and possible crashes. Then all you need to do is start using <classname>Glib::ustring</classname> instead.One of the major advantages of <application>gtkmm</application> is that it is crossplatform. <application>gtkmm</application> programs written on other platforms such as GNU/Linux can generally be transferred to Windows (and vice versa) with few modifications to the source.Openismus has more <ulink url="http://www.openismus.com/documents/linux/automake/automake.shtml">basic help with automake and autoconf</ulink>.Optional Parameter ProcessingOr you could specify the tag when first inserting the text: <placeholder-1/>Other macrosOther macros, such as <function>_WRAP_METHOD()</function> and <function>_WRAP_SIGNAL()</function> may only be used after a call to a <function>_CLASS_*</function> macro.Other than the signal's name (<literal>focus</literal>), two things are important to note here: the number following the word <classname>SignalProxy</classname> at the beginning (1, in this case), and the types in the list (<type>bool</type> and <type>Gtk::DirectionType</type>). The number indicates how many arguments the signal handler should have; the first type, <type>bool</type>, is the type that the signal handler should return; and the next type, <type>Gtk::DirectionType</type>, is the type of this signal's first, and only, argument. By looking at the reference documentation, you can see the names of the arguments too.Our examples all tend to have the same structure. They follow these steps for using a <classname>Widget</classname>:Output Parameter ProcessingOverriding default signal handlersOverviewPKG_CHECK_MODULES([MYAPP], [gtkmm-3.0 &gt;= 3.8.0])Pack the widget into a container using the appropriate call, e.g. <methodname>Gtk::Container::add()</methodname> or <methodname>pack_start()</methodname>.PackingPage setupPanedPanes divide a widget into two halves, separated by a moveable divider. The two halves (panes) can be oriented either horizontally (side by side) or vertically (one above the other).PangoParameter ReorderingParts of chapter on "Internationalization".Parts of the update from gtkmm 2 to gtkmm 3.PastePedroPer-child packing optionsPer-container packing optionsPermission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. You may obtain a copy of the GNU Free Documentation License from the Free Software Foundation by visiting their Web site or by writing to: Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.PitfallsPlease note that when reordering parameters for a <function>_WRAP_SIGNAL()</function> method signature, the C parameter names would always be <literal>p0</literal>, <literal>p1</literal>, etc. because the <filename>generate_extra_defs</filename> utility uses those parameter names no matter what the C API's parameter names may be. It's how the utility is written presently.Please see <ulink url="https://wiki.gnome.org/Projects/gtkmm/MSWindows/BuildingGtkmm"> https://wiki.gnome.org/Projects/gtkmm/MSWindows/BuildingGtkmm</ulink> for instructions on how to build gtkmm on Windows.PlugsPlugs and SocketsPlugs and Sockets ExamplePopup Context MenuPopup MenuPopup Menu examplePopup MenusPrebuilt PackagesPreparing your projectPretty thrilling, eh? Let's examine the code. First, the <classname>HelloWorld</classname> class:Preventing row selectionPreviewPrintOperationPrintingPrinting - SimpleProbably the most common way of creating <classname>Gdk::Pixbuf</classname>s is to use <methodname>Gdk::Pixbuf::create_from_file()</methodname>, which can read an image file, such as a png file into a pixbuf ready for rendering.Problems in the C API.Programming with <application>gtkmm</application> 3Progress bars are used to show the status of an ongoing operation. For instance, a <classname>ProgressBar</classname> can show how much of a task has been completed.ProgressBarPush-ButtonsPuts the generated code in #ifdef blocks.Puts the generated code in #ifdef blocks. Text about the deprecation can be specified as an optional parameter.Radio buttonsRadioButtonRange WidgetsRe. Overriding signal handlers: You can do this in the straight-C world of GTK+ too; that's what GTK's object system is for. But in GTK+, you have to go through some complicated procedures to get object-oriented features like inheritance and overloading. In C++, it's simple, since those features are supported in the language itself; you can let the compiler do the dirty work.Recent versions of <application>gtkmm</application> are packaged by nearly every major Linux distribution these days. So, if you use Linux, you can probably get started with <application>gtkmm</application> by installing the package from the official repository for your distribution. Distributions that include <application>gtkmm</application> in their repositories include Debian, Ubuntu, Red Hat, Fedora, Mandriva, Suse, and many others.RecentChooserRecentManagerRecently Used DocumentsRecommended TechniquesReferenceRemember that on a Unix or Linux operating system, you will probably need to be <literal>root</literal> to install software. The <command>su</command> or <command>sudo</command> command will allow you to enter the <literal>root</literal> password and have <literal>root</literal> status temporarily.Remember that these names are just the identifiers that we used when creating the actions. They are not the text that the user will see in the menus and toolbars. We provided those human-readable names when we created the actions.Remember that you are not instantiating a widget with <methodname>get_widget()</methodname>, you are just obtaining a pointer to one that already exists. You will always receive a pointer to the same instance when you call <methodname>get_widget()</methodname> on the same <classname>Gtk::Builder</classname>, with the same widget name. The widgets are instantiated during <methodname>Gtk::Builder::create_from_file()</methodname>.Rendering textReorderable rowsResourcesResponding to changesReusing C documentationRiederRow childrenSame strings, different semanticsScale WidgetsScrollbar WidgetsScrolled windows have <emphasis>scrollbar policies</emphasis> which determine whether the <classname>Scrollbar</classname>s will be displayed. The policies can be set with the <methodname>set_policy()</methodname> method. The policy may be one of <literal>Gtk::POLICY_AUTOMATIC</literal> or <literal>Gtk::POLICY_ALWAYS</literal>. <literal>Gtk::POLICY_AUTOMATIC</literal> will cause the scrolled window to display the scrollbar only if the contained widget is larger than the visible area. <literal>Gtk::POLICY_ALWAYS</literal> will cause the scrollbar to be displayed always.ScrolledWindowScrollingSecond, check for an error and connect to the <literal>status_changed</literal> signal. For instance: <placeholder-1/>Section "Build Structure" of chapter on "Wrapping C Libraries with gmmproc".Section on Gtk::Grid.See <link linkend="sec-printing-example-simple">an example</link> of exactly how this can be done.See the <link linkend="chapter-draganddrop">Drag and Drop</link> chapter for general advice about Drag and Drop with gtkmm.See the <link linkend="chapter-internationalization">Internationalization</link> section for information about providing the UTF-8 string literals.See the <link linkend="chapter-refptr">appendix</link> for detailed information about RefPtr.See the <link linkend="sec-progressbar">ProgressBar</link> section for another example that uses an <classname>Alignment</classname>.Selecting which C++ types should be used is also important when wrapping C API. Though it's usually obvious what C++ types should be used in the C++ method, here are some hints: <placeholder-1/>Set the attributes of the widget. If the widget has no default constructor, then you will need to initialize the widget in the initalizer list of your container class's constructor.Set the title of the tab via <methodname>PrintOperation::set_custom_tab_label()</methodname>, create a new widget and return it from the <literal>create_custom_widget</literal> signal handler. You'll probably want this to be a container widget, packed with some others.Setting a prefixSetting up jhbuildSetting valuesShared resourcesShown below is a simple example of how to use the <classname>RecentChooserDialog</classname> and the <classname>RecentAction</classname> classes in a program. This simple program has a menubar with a <guimenuitem>Recent Files Dialog</guimenuitem> menu item. When you select this menu item, a dialog pops up showing the list of recently used files.Signal Handler sequenceSignalsSignals and properties.Signals usually have function pointers in the GTK struct, with a corresponding enum value and a <function>g_signal_new()</function> in the .c file.SimpleSimple Entry ExampleSimple ExampleSimple RecentChooserDialog exampleSimple Text ExampleSimple UseSimple text copy-paste functionality is provided for free by widgets such as <classname>Gtk::Entry</classname> and <classname>Gtk::TextView</classname>, but you might need special code to deal with your own data formats. For instance, a drawing program would need special code to allow copy and paste within a view, or between documents.Since a <classname>Plug</classname> is just a special type of <classname>Gtk::Window</classname> class, you can add containers or widgets to it like you would to any other window.Since the Cairo graphics library was written with support for multiple output targets (the X window system, PNG images, OpenGL, etc), there is a distinction between user-space and device-space coordinates. The mapping between these two coordinate systems defaults to one-to-one so that integer values map roughly to pixels on the screen, but this setting can be adjusted if desired. Sometimes it may be useful to scale the coordinates so that the full width and height of a window both range from 0 to 1 (the 'unit square') or some other mapping that works for your application. This can be done with the <methodname>Cairo::Context::scale()</methodname> function.Since this is very similar to the methods above this explanation should be sufficient to understand what's going on. However, here's a little example:Single or multiple selectionSingle-item ContainersSo far we've told you to perform actions in response to button-presses and the like by handling signals. That's certainly a good way to do things, but it's not the only way.So that a user can click on a <classname>TreeView</classname>'s column header to sort the <classname>TreeView</classname>'s contents, call <methodname>Gtk::TreeView::Column::set_sort_column()</methodname>, supplying the model column on which model should be sorted when the header is clicked. For instance:So that applications can react to changes, for instance when a user moves a scrollbar, <classname>Gtk::Adjustment</classname> has a <literal>value_changed</literal> signal. You can then use the <methodname>get_value()</methodname> method to discover the new value.So that the <classname>Entry</classname> can interact with the drop-down list of choices, you must specify which of your model columns is the text column, with <methodname>set_entry_text_column()</methodname>. For instance: <placeholder-1/>So you should either avoid this situation or use <ulink url="http://developer.gnome.org/glibmm/unstable/classGlib_1_1ustring.html"><function>Glib::ustring::compose()</function></ulink> which supports syntax such as: <placeholder-1/>So, for example, if you have a <classname>Scale</classname> widget, and you want to change the rotation of a picture whenever its value changes, you would create a signal handler like this:SocketsSome <application>gtkmm</application> widgets don't have associated X windows; they draw on their parents' windows. Because of this, they cannot receive events. Also, if they are incorrectly sized, they don't clip, so you can get messy overwriting etc. To receive events on one of these widgets, you can place it inside an <classname>EventBox</classname> widget and then call <methodname>Gtk::Widget::set_events()</methodname> on the EventBox before showing it.Some API related to gtkmm uses intermediate data containers, such as <classname>Glib::StringArrayHandle</classname>, instead of a specific Standard C++ container such as <classname>std::vector</classname> or <classname>std::list</classname>, though <application>gtkmm</application> itself now uses just <classname>std::vector</classname> since <application>gtkmm</application> 3.0.Some Widgets do not have an associated X-Window, so they therefore do not receive X events. This means that the signals described in the <link linkend="sec-xeventsignals">X event signals</link> section will not be emitted. If you want to capture events for these widgets you can use a special container called <classname>Gtk::EventBox</classname>, which is described in the <link linkend="sec-eventbox">EventBox</link> section.Some extra macros make this easier and consistent. Look in gtkmm's .m4 files for examples. For instance: <placeholder-1/>Some objects, such as <classname>Gdk::Pixbuf</classname>s and <classname>Pango::Font</classname>s, are obtained from a shared store. Therefore you cannot instantiate your own instances. These classes typically inherit from <classname>Glib::Object</classname>. Rather than requiring you to reference and unreference these objects, <application>gtkmm</application> uses the <classname>Glib::RefPtr&lt;&gt;</classname> smartpointer. Cairomm has its own smartpointer, <classname>Cairo::RefPtr&lt;&gt;</classname>.Some of the basic types that are used in C APIs have better alternatives in C++. For example, there's no need for a <type>gboolean</type> type since C++ has <type>bool</type>. The following list shows some commonly-used types in C APIs and what you might convert them to in a C++ wrapper library.Some thread safety rules on the use of <classname>Glib::Dispatcher</classname> still apply. As mentioned, a <classname>Glib::Dispatcher</classname> object must be constructed in the receiver thread (the thread in whose main loop it will execute its connected slots). By default this is the main program thread, although there is a <classname>Glib::Dispatcher</classname> constructor which can take the <classname>Glib::MainContext</classname> object of any thread which has a main loop. Only the receiver thread should call <methodname>connect()</methodname> on the <classname>Glib::Dispatcher</classname> object, or manipulate any related <classname>sigc::connection</classname> object, unless additional synchronization is employed. However, any worker thread can safely emit on the <classname>Glib::Dispatcher</classname> object without any locking once the receiver thread has connected the slots, provided that it is constructed before the worker thread is started (if it is constructed after the thread has started, additional synchronization will normally be required to ensure visibility).Sometimes two english strings are identical but have different meanings in different contexts, so they would probably not be identical when translated. Since the English strings are used as look-up keys, this causes problems.SortingSorting by clicking on columnsSource CodeSources and DestinationsSpecifies the destination directory for generated sources, and the name of the main .defs file that <command>gmmproc</command> should parse.Specifies the name of the slot parameter of the method, if it has one. This enables <command>gmmproc</command> to generate code to copy the slot and pass the copy on to the C function in its final <literal>gpointer user_data</literal> parameter. The <literal>slot_callback</literal> option must also be used to specify the name of the glue callback function to also pass on to the C function.Specifying CellRenderer detailsSpinButtonStart the <filename>plug</filename> program and send it to the background (or just use a different terminal).Stock items have been recommended for use in buttons. From <application>gtkmm</application>-3.10 they are deprecated. They should not be used in newly-written code. However, the documentation of <ulink url="http://developer.gnome.org/gtkmm/unstable/namespaceGtk_1_1Stock.html">namespace Gtk::Stock</ulink> shows recommended labels and named icons to show in buttons.String literals should be typed in the source code in English, but surrounded by a macro. The <application>gettext</application> (or intltool) utility can then extract the marked strings for translation, and substitute the translated text at runtime.String literals should be typed in the source code in English, but they should be surrounded by a call to the <function>gettext()</function> function. These strings will be extracted for translation and the translations may be used at runtime instead of the original English strings.Subclass Widgets to better organize your code. You should probably subclass your main <classname>Window</classname> at least. Then you can make your child Widgets and signal handlers members of that class.Subclassing isn't always the best way to accomplish things. It is only useful when you want the widget to handle its own signal by itself. If you want some other class to handle the signal then you'll need to connect a separate handler. This is even more true if you want several objects to handle the same signal, or if you want one signal handler to respond to the same signal from different objects.TableTagTableTagsTags and FormattingTargetsTells <command>gmmproc</command> not to pass a copy of the slot to the C function, if the method has one. Instead the slot itself is passed. The slot parameter name and the glue callback function must have been specified with the <literal>slot_name</literal> and <literal>slot_callbback</literal> options respectively.Tells <command>gmmproc</command> to add initialization code for the interface.Tells <command>gmmproc</command> to add some typedefs, constructors, and standard methods to this class, as appropriate when wrapping a widget.Tells <command>gmmproc</command> to include a header in the generated private/button_p.h file.Testing and adding translationsText is drawn via Pango Layouts. The easiest way to create a <classname>Pango::Layout</classname> is to use <methodname>Gtk::Widget::create_pango_layout()</methodname>. Once created, the layout can be manipulated in various ways, including changing the text, font, etc. Finally, the layout can be rendered using the <methodname>Pango::Layout::show_in_cairo_context()</methodname> method.Text rendering is done using Pango. The <classname>Pango::Layout</classname> object for printing should be created by calling the <methodname>PrintContext::create_pango_layout()</methodname> method. The <classname>PrintContext</classname> object also provides the page metrics, via <methodname>get_width()</methodname> and <methodname>get_height()</methodname>. The number of pages can be set with <methodname>PrintOperation::set_n_pages()</methodname>. To actually render the Pango text in <literal>on_draw_page</literal>, get a <classname>Cairo::Context</classname> with <methodname>PrintContext::get_cairo_context()</methodname> and show the <classname>Pango::LayoutLine</classname>s that appear within the requested page number.TextViewThat will create a file named <filename>programname.pot</filename>. Now copy that file to <filename>languagecode.po</filename>, such as <filename>de.po</filename> or <filename>hu.po</filename>. Also add that language code to <literal>LINGUAS</literal>. The <filename>.po</filename> file contains a header and a list of English strings, with space for the translated strings to be entered. Make sure you set the encoding of the <filename>.po</filename> file (specified in the header, but also as content) to <literal>UTF-8</literal>.The "changed" signalThe 'Print to file' option is available in the print dialog, without the need for extra implementation. However, it is sometimes useful to generate a pdf file directly from code. For instance, <placeholder-1/>The .h and .cc files will be generated from the .hg and .ccg files by processing them with <command>gmmproc</command> like so, though this happens automatically when using the above build structure: <placeholder-1/>The .hg and .ccg filesThe .hg and .ccg source files are very much like .h and .cc C++ source files, but they contain extra macros, such as <function>_CLASS_GOBJECT()</function> and <function>_WRAP_METHOD()</function>, from which <command>gmmproc</command> generates appropriate C++ source code, usually at the same position in the header. Any additional C++ source code will be copied verbatim into the corresponding .h or .cc file.The <application>GNU gettext</application> package allows you to mark strings in source code, extract those strings for translation, and use the translated strings in your application.The <application>gtkmm</application> module is defined in the <filename>gnome-suites-core-deps-3.x.modules</filename> moduleset, so edit your <filename>.jhbuildrc</filename> file and set your moduleset setting to the latest version e.g. like so: <placeholder-1/>The <classname>AboutDialog</classname> offers a simple way to display information about a program, like its logo, name, copyright, website and license.The <classname>Alignment</classname> widget allows you to place a widget at a position and size relative to the size of the <classname>Alignment</classname> widget itself. For instance, it might be used to center a widget.The <classname>AspectFrame</classname> widget looks like a <classname>Frame</classname> widget, but it also enforces the <emphasis>aspect ratio</emphasis> (the ratio of the width to the height) of the child widget, adding extra space if necessary. For instance, this would allow you to display a photograph without allowing the user to distort it horizontally or vertically while resizing.The <classname>ColorChooserDialog</classname> allows the user to choose a color. The <classname>ColorButton</classname> opens a color selection dialog when it is clicked.The <classname>ComboBox</classname> widget offers a list (or tree) of choices in a dropdown menu. If appropriate, it can show extra information about each item, such as text, a picture, a checkbox, or a progress bar. The <classname>ComboBox</classname> widget usually restricts the user to the available choices, but it can optionally have an <classname>Entry</classname>, allowing the user to enter arbitrary text if none of the available choices are suitable.The <classname>DrawingArea</classname> widget is a blank window that gives you the freedom to create any graphic you desire. Along with that freedom comes the responsibility to handle draw signals on the widget. When a widget is first shown, or when it is covered and then uncovered again it needs to redraw itself. Most widgets have code to do this, but the DrawingArea does not, allowing you to write your own draw signal handler to determine how the contents of the widget will be drawn. This is most often done by overriding the virtual <methodname>on_draw()</methodname> member function.The <classname>EntryCompletion</classname> may use a <classname>TreeModel</classname> containing possible entries, specified with <methodname>set_model()</methodname>. You should then call <methodname>set_text_column()</methodname> to specify which of your model columns should be used to match possible text entries.The <classname>FileChooserDialog</classname> is suitable for use with "Open" or "Save" menu items.The <classname>FontChooserDialog</classname> allows the user to choose a font. The <classname>FontButton</classname> opens a font chooser dialog when it is clicked.The <classname>Gdk::Pixbuf</classname> can be rendered by setting it as the source pattern of the Cairo context with <methodname>Gdk::Cairo::set_source_pixbuf()</methodname>. Then draw the image with either <methodname>Cairo::Context::paint()</methodname> (to draw the whole image), or <methodname>Cairo::Context::rectangle()</methodname> and <methodname>Cairo::Context::fill()</methodname> (to fill the specified rectangle). <methodname>set_source_pixbuf()</methodname> is not a member of <classname>Cairo::Context</classname>. It takes a <classname>Cairo::Context</classname> as its first parameter.The <classname>Gtk::Adjustment</classname> is created by its <methodname>create()</methodname> method which is as follows:The <classname>Gtk::Button</classname> widget has the following signals, but most of the time you will just handle the <literal>clicked</literal> signal:The <classname>Gtk::TreeView</classname> widget can contain lists or trees of data, in columns.The <classname>ListStore</classname> contains simple rows of data, and each row has no children.The <classname>PrintOperation</classname> class has a method called <methodname>set_default_page_setup()</methodname> which selects the default paper size, orientation and margins. To show a page setup dialog from your application, use the <methodname>Gtk::run_page_setup_dialog()</methodname> method, which returns a <classname>Gtk::PageSetup</classname> object with the chosen settings. Use this object to update a <classname>PrintOperation</classname> and to access the selected <classname>Gtk::PaperSize</classname>, <literal>Gtk::PageOrientation</literal> and printer-specific margins.The <classname>SpinButton</classname> can create a default <classname>Adjustment</classname>, which you can access via the <methodname>get_adjustment()</methodname> method, or you can specify an existing <classname>Adjustment</classname> in the constructor.The <classname>Tag</classname> class has many other properties.The <classname>TextView</classname> creates its own default <classname>TextBuffer</classname>, which you can access via the <methodname>get_buffer()</methodname> method.The <classname>TextView</classname> widget can be used to display and edit large amounts of formatted text. Like the <classname>TreeView</classname>, it has a model/view design. In this case the <classname>TextBuffer</classname> is the model.The <classname>ToolPalette</classname>'s items might be dragged or simply activated. For instance, the user might drag objects to a canvas to create new items there. Or the user might click an item to activate a certain brush size in a drawing application.The <classname>TreeModelColumnRecord</classname> class is used to keep track of the columns and their data types. You add <classname>TreeModelColumn</classname> instances to the <classname>ColumnRecord</classname> and then use those <classname>TreeModelColumns</classname> when getting and setting the data in model rows. You will probably find it convenient to derive a new <classname>TreeModelColumnRecord</classname> which has your <classname>TreeModelColumn</classname> instances as member data.The <classname>TreeStore</classname> contains rows of data, and each row may have child rows.The <classname>TreeView</classname> already allows you to show the same <classname>TreeModel</classname> in two <classname>TreeView</classname> widgets. If you need one of these TreeViews to sort the model differently than the other then you should use a <classname>TreeModelSort</classname> instead of just, for instance, <methodname>Gtk::TreeViewModel::set_sort_column()</methodname>. <classname>TreeModelSort</classname> is a model that contains another model, presenting a sorted version of that model. For instance, you might add a sorted version of a model to a <classname>TreeView</classname> like so:The <classname>Widget</classname> class has some special signals which correspond to the underlying X-Windows events. These are suffixed by <literal>_event</literal>; for instance, <methodname>Widget::signal_button_press_event()</methodname>.The <filename>.defs</filename> files are text files, in a lisp format, that describe the API of a C library, including its <placeholder-1/>The <filename>configure</filename> script will check to make sure all of the required dependencies are already installed. If you are missing any dependencies, it will exit and display an error.The <filename>skeletonmm/codegen/generate_defs_and_docs.sh</filename> script generates all <filename>.defs</filename> files and the <filename>*_docs.xml</filename> file, described in the <link linkend="sec-wrapping-documentation">Documentation</link> section.The <function>AC_CONFIG_FILES()</function> block must mention the correct directory names, as described above.The <function>AC_CONFIG_HEADERS()</function> line is used to generate two or more configuration header files. The first header file in the list contains all configuration macros which are set during the configure run. The remaining headers in the list contain only a subset of configuration macros and their corresponding <filename>config.h.in</filename> file will not be autogenerated. The reason for this separation is that the namespaced configuration headers are installed with your library and define publically visible macros.The <function>AC_CONFIG_SRCDIR()</function> line must mention a file in our source tree. We can edit this later if we don't yet know the names of any of the files that we will create.The <function>AC_SUBST([SOMETHINGMM_MODULES], ['...'])</function> line may need to be modified to check for the correct dependencies.The <function>_CTOR_DEFAULT()</function> and <function>_WRAP_CTOR()</function> macros add constructors, wrapping the specified <function>*_new()</function> C functions. These macros assume that the C object has properties with the same names as the function parameters, as is usually the case, so that it can supply the parameters directly to a <function>g_object_new()</function> call. These constructors never actually call the <function>*_new()</function> C functions, because gtkmm must actually instantiate derived GTypes, and the <function>*_new()</function> C functions are meant only as convenience functions for C programmers.The <link linkend="chapter-draganddrop">Drag and Drop</link> API uses the same mechanism. You should probably use the same data targets and formats for both Clipboard and Drag and Drop operations.The <literal>const ... &amp;</literal> around both is just for efficiency, like using <classname>const std::string&amp;</classname> instead of <classname>std::string</classname> for a method parameter to avoid unnecessary copying.The <literal>ideal</literal> example below can supply more than one clipboard target.The <methodname>PrintOperation::run()</methodname> method starts the print loop, during which various signals are emitted: <placeholder-1/>The <methodname>get_request_mode_vfunc()</methodname>, <methodname>get_preferred_width_vfunc()</methodname>, <methodname>get_preferred_height_vfunc()</methodname>, <methodname>get_preferred_width_for_height_vfunc()</methodname>, <methodname>get_preferred_height_for_width_vfunc()</methodname>, and <methodname>on_size_allocate()</methodname> virtual methods control the layout of the child widgets. For instance, if your container has 2 child widgets, with one below the other, your <methodname>get_request_mode_vfunc()</methodname> might request height-for-width layout. Then your <methodname>get_preferred_width_vfunc()</methodname> might report the maximum of the widths of the child widgets, and <methodname>get_preferred_height_for_width_vfunc()</methodname> might report the sum of their heights. If you want padding between the child widgets then you would add that to the width and height too. Your widget's container will use this result to ensure that your widget gets enough space, and not less. By examining each widget's parent, and its parent, this logic will eventually decide the size of the top-level window.The <methodname>pack_start()</methodname> and <methodname>pack_end()</methodname> methods place widgets inside these containers. The <methodname>pack_start()</methodname> method will start at the top and work its way down in a <classname>Box</classname> with vertical orientation, or pack left to right in a <classname>Box</classname> with horizontal orientation. <methodname>pack_end()</methodname> will do the opposite, packing from bottom to top or from right to left. Using these methods allows us to right justify or left justify our widgets. We will use <methodname>pack_start()</methodname> in most of our examples.The <methodname>run()</methodname> method returns an <literal>int</literal>. This may be a value from the <literal>Gtk::ResponseType</literal> if the user closed the dialog by clicking a standard button, or it could be the custom response value that you specified when using <methodname>add_button()</methodname>.The <methodname>spin()</methodname> method 'spins' the <classname>SpinButton</classname>, as if its increment or decrement button had been clicked. You need to specify a <classname>Gtk::SpinType</classname> to specify the direction or new position.The <parameter>options</parameter> argument can take one of these three options: <placeholder-1/>The <parameter>padding</parameter> argument specifies the width of an extra border area to leave around the packed widget.The <parameter>value</parameter> argument is the initial value of the adjustment, usually corresponding to the topmost or leftmost position of an adjustable widget. The <parameter>lower</parameter> and <parameter>upper</parameter> arguments specify the possible range of values which the adjustment can hold. The <parameter>step_increment</parameter> argument specifies the smaller of the two increments by which the user can change the value, while the <parameter>page_increment</parameter> is the larger one. The <parameter>page_size</parameter> argument usually corresponds somehow to the visible area of a panning widget. The <parameter>upper</parameter> argument is used to represent the bottommost or rightmost coordinate in a panning widget's child.The BufferThe C function (e.g. <function>get_request_mode</function>) is described more fully in the <filename>*_vfuncs.defs</filename> file, and the <filename>convert*.m4</filename> files contain the necessary conversion from the C++ parameter type to the C parameter type.The C function (e.g. <function>gtk_entry_set_text</function>) is described more fully in the .defs file, and the <filename>convert*.m4</filename> files contain the necessary conversion from the C++ parameter type to the C parameter type. This macro also generates doxygen documentation comments based on the <filename>*_docs.xml</filename> and <filename>*_docs_override.xml</filename> files.The Cairo Drawing ModelThe Cairo coordinate system, in the <literal>draw_page</literal> handler, is automatically rotated to the current page orientation. It is normally within the printer margins, but you can change that via the <methodname>PrintOperation::set_use_full_page()</methodname> method. The default measurement unit is device pixels. To select other units, use the <methodname>PrintOperation::set_unit()</methodname> method.The ClipboardThe Drawing Area WidgetThe ModelThe RefPtr smartpointerThe SelectionThe TreeView widgetThe UI layout for a popup menu should use the <literal>popup</literal> node. For instance:The ViewThe View is the actual widget (<classname>Gtk::TreeView</classname>) that displays the model (<classname>Gtk::TreeModel</classname>) data and allows the user to interact with it. The View can show all of the model's columns, or just some, and it can show them in various ways.The adjustable widgets can be roughly divided into those which use and require specific units for these values, and those which treat them as arbitrary numbers.The arguments to <methodname>Action::create()</methodname> specify the action's name and how it will appear in menus and toolbars.The basic concept of drawing in Cairo involves defining 'invisible' paths and then stroking or filling them to make them visible.The build structureThe call to <methodname>Cairo::Context::curve_to()</methodname> should be fairly self-explanatory. The first pair of coordinates define the control point for the beginning of the curve. The second set of coordinates define the control point for the end of the curve, and the last set of coordinates define the destination point. To make the concept of control points a bit easier to visualize, a line has been drawn from each control point to the end-point on the curve that it is associated with. Note that these control point lines are both translucent. This is achieved with a variant of <methodname>set_source_rgb()</methodname> called <methodname>set_source_rgba()</methodname>. This function takes a fourth argument specifying the alpha value of the color (valid values are between 0 and 1).The chosen itemThe class macro declares the class itself and its relationship with the underlying C type. It generates some internal constructors, the member <varname>gobject_</varname>, typedefs, the <function>gobj()</function> accessors, type registration, and the <function>Glib::wrap()</function> method, among other things.The clear callback allows you to free the memory used by your stored data when the clipboard replaces its data with something else.The command line options passed to the C preprocessor.The command line options passed to the C++ compiler.The communication between a <classname>Socket</classname> and a <classname>Plug</classname> follows the XEmbed protocol. This protocol has also been implemented in other toolkits (e.g. Qt), which allows the same level of integration when embedding a Qt widget in GTK+ or vice versa.The compiler will complain if you use an inappropriate type. For instance, this would generate a compiler error:The connect*_once() variants, <methodname>Glib::SignalIdle::connect_once()</methodname>, <methodname>Glib::SignalTimeout::connect_once()</methodname>, <methodname>Glib::SignalTimeout::connect_seconds_once()</methodname>, are thread-safe for any case where the slot is not created by a call to <function>sigc::mem_fun()</function> which represents a method of a class deriving from <classname>sigc::trackable</classname>. This is similar to <methodname>Glib::Threads::Thread::create()</methodname> as mentioned in point 4.The constraintsThe constructor for <classname>ExampleWindow</classname> creates the menu using <classname>UIManager</classname> (see <xref linkend="chapter-menus-and-toolbars"/> for more information). It then adds the menu and the toolbar to the window.The constructor for <classname>Gtk::EventBox</classname> is:The current state of a <classname>Cairo::Context</classname> can be saved to an internal stack of saved states and later be restored to the state it was in when you saved it. To do this, use the <methodname>save()</methodname> method and the <methodname>restore()</methodname> method. This can be useful if you need to temporarily change the line width and color (or any other graphics setting) in order to draw something and then return to the previous settings. In this situation, you could call <methodname>Cairo::Context::save()</methodname>, change the graphics settings, draw the lines, and then call <methodname>Cairo::Context::restore()</methodname> to restore the original graphics state. Multiple calls to <methodname>save()</methodname> and <methodname>restore()</methodname> can be nested; each call to <methodname>restore()</methodname> restores the state from the matching paired <methodname>save()</methodname>. <placeholder-1/>The default <classname>CellRenderers</classname> and their default behaviour will normally suffice, but you might occasionally need finer control. For instance, this example code from <filename>gtkmm/demos/gtk-demo/example_treeview_treestore.cc</filename>, appends a <classname>Gtk::CellRenderer</classname> widget and instructs it to render the data from various model columns through various aspects of its appearance.The destination widget will emit these signals, in this order: <placeholder-1/>The drag and drop signals provide a DragContext, which contains some information about the drag and drop operation and can be used to influence the process. For instance, you can discover the source widget, or change the drag and drop icon, by using the <methodname>set_icon()</methodname> methods. More importantly, you should call the <methodname>drag_finish()</methodname> method from your <literal>drag_data_received</literal> signal handler to indicate whether the drop was successful.The easiest way to do this is using <ulink url="https://wiki.gnome.org/Projects/Jhbuild">jhbuild</ulink>. <application>jhbuild</application> is a program that makes building GNOME software much easier by calculating dependencies and building things in the correct order. This section will give a brief explanation of how to set up <application>jhbuild</application> to build and install <application>gtkmm</application> from the source repository (git). For up-to-date information on <application>jhbuild</application>, please refer to the <ulink url="http://developer.gnome.org/jhbuild/unstable/">jhbuild manual</ulink>. If you need assistance using <application>jhbuild</application>, you should ask for help on the <ulink url="http://mail.gnome.org/mailman/listinfo/gnome-love">gnome-love mailing list</ulink>.The entryThe event is delivered first to the widget the event occurred in. If all signal handlers in that widget return <literal>false</literal> (indicating that the event has not been handled), then the signal will be propagated to the parent widget and emitted there. This continues all the way up to the top-level widget if no one handles the event.The event will propagate until it reaches the top-level widget, or until you stop the propagation by returning <literal>true</literal> from an event handler.The example in examples/book/printing/advanced demonstrates this.The extra typedef allows the struct to be used in a header without including its full definition, simply by predeclaring it, by repeating that typedef. This means that you don't have to include the C library's header in your C++ header, thus keeping it out of your public API. <command>gmmproc</command> assumes that this technique was used, so you will see compiler errors if that is not the case.The first 6 methods in the previous table are also overridden in custom containers. They are briefly described in the <link linkend="sec-custom-containers">Custom Containers</link> section.The first argument is a <classname>slot</classname> you wish to have called when the timeout occurs. The second argument is the number of milliseconds between calls to that method. You receive a <classname>sigc::connection</classname> object that can be used to deactivate the connection using its <methodname>disconnect()</methodname> method:The first argument is a slot you wish to have called when the specified event (see argument 3) occurs on the file descriptor you specify using argument two. Argument three may be one or more (using <literal>|</literal>) of:The first argument is the widget you're packing. In our example these are all <classname>Button</classname>s.The first call to <methodname>connect()</methodname> is just like the one we saw last time; nothing new here.The first line of output is from <filename>plug</filename>, after it has been notified that it has been embedded inside of a <classname>Socket</classname>. The second line was emitted by <filename>socket</filename> in response to its <methodname>plug_added</methodname> signal. If everything was done as described above, the <filename>socket</filename> window should look roughly like the following:The following example demonstrates both uses of an <classname>EventBox</classname> - a label is created that is clipped to a small box, and set up so that a mouse-click on the label causes the program to exit. Resizing the window reveals varying amounts of the label.The following example demonstrates how to print some input from a user interface. It shows how to implement <literal>on_begin_print</literal> and <literal>on_draw_page</literal>, as well as how to track print status and update the print settings.The following example demonstrates the use of <classname>RadioButton</classname>s:The following example program requires a command-line option. The source code shows two ways of handling command-line options in combination with <classname>Gtk::Application</classname>.The following example shows how to set up a Cairo context with a foreground color of red and a width of 2. Any drawing functions that use this context will use these settings.The following is a simple example of using sockets and plugs. The method of communication between processes is deliberately kept very simple: The <classname>Plug</classname> writes its ID out to a text file named <filename>plug.id</filename> and the process with the socket reads the ID from this file. In a real program, you may want to use a more sophisticated method of inter-process communication.The following program uses a <classname>Gtk::AspectFrame</classname> to present a drawing area whose aspect ratio will always be 2:1, no matter how the user resizes the top-level window.The function <methodname>Cairo::Context::arc_negative()</methodname> is exactly the same as <methodname>Cairo::Context::arc()</methodname> but the angles go the opposite direction.The function <methodname>Cairo::Context::paint()</methodname> is used here to set the background color of the window. This function takes no arguments and fills the current surface (or the clipped portion of the surface) with the source color currently active. After setting the background color of the window, we draw a circle for the clock outline, fill it with white, and then stroke the outline in black. Notice that both of these actions use the <methodname>_preserve</methodname> variant to preserve the current path, and then this same path is clipped to make sure that our next lines don't go outside the outline of the clock.The functions <methodname>move_item()</methodname>, <methodname>remove_item()</methodname> and <methodname>purge_items()</methodname> have no effect on the actual files that are referred to by the URIs, they only modify the list of recent files.The group which treats the values as arbitrary numbers includes the <classname>Range</classname> widgets (<classname>Scrollbar</classname> and <classname>Scale</classname>), the <classname>ScaleButton</classname> widget, and the <classname>SpinButton</classname> widget. These widgets are typically "adjusted" directly by the user with the mouse or keyboard. They will treat the <parameter>lower</parameter> and <parameter>upper</parameter> values of an adjustment as a range within which the user can manipulate the adjustment's <parameter>value</parameter>. By default, they will only modify the <parameter>value</parameter> of an adjustment.The implementation of the <function>wrap_init()</function> method in <filename>wrap_init.cc</filename> is generated by <filename>generate_wrap_init.pl</filename>, but the declaration in <filename>wrap_init.h</filename> is hand-coded, so you will need to adjust <filename>wrap_init.h</filename> so that the <function>wrap_init()</function> function appears in the correct C++ namespace.The label text can be justified using the <methodname>set_justify()</methodname> method. The widget is also capable of word-wrapping, which can be activated with <methodname>set_line_wrap()</methodname>.The last line shows the window and enters the <application>gtkmm</application> main processing loop, which will finish when the window is closed. Your <function>main()</function> function will then return with an appropriate success or error code.The line join style is set using the function <methodname>Cairo::Context::set_line_join()</methodname>.The list is provided via a <classname>TreeModel</classname>, and columns from this model are added to the ComboBox's view with the <methodname>ComboBox::pack_start()</methodname> method. This provides flexibility and compile-time type-safety, but the <classname>ComboBoxText</classname> class provides a simpler text-based specialization in case that flexibility is not required.The macros are explained in more detail in the following sections.The macros in this example do the following: <placeholder-1/>The macros that you use in the .hg and .ccg files often need to know how to convert a C++ type to a C type, or vice-versa. gmmproc takes this information from an .m4 file in your <literal>tools/m4/</literal> directory. This allows it to call a C function in the implementation of your C++ method, passing the appropriate parameters to that C functon. For instance, this tells gmmproc how to convert a GtkTreeView pointer to a Gtk::TreeView pointer: <placeholder-1/>The main activity in the internationalization process is finding strings seen by users and marking them for translation. You do not need to do it all at once - if you set up the necessary project infrastructure correctly then your application will work normally regardless of how many strings you've covered.The maximum age of items in the recently used files list can be set with <methodname>Gtk::Settings::property_gtk_recent_files_max_age()</methodname>. Default value: 30 days.The modelThe model for a ComboBox can be defined and filled exactly as for a <classname>TreeView</classname>. For instance, you might derive a ComboBox class with one integer and one text column, like so:The name of the library, such as libsomethingmm.The names of the <application>gtkmm</application> packages vary from distribution to distribution (e.g. <application>libgtkmm-3.0-dev</application> on Debian and Ubuntu or <application>gtkmm30-devel</application> on Red Hat Fedora), so check with your distribution's package management program for the correct package name and install it like you would any other package.The native GTK+ print dialog has a preview button, but you may also start a preview directly from an application: <placeholder-1/>The next is more interesting. <function>sigc::mem_fun()</function> is called with two arguments. The first argument is <parameter>some_object</parameter>, which is the object that our new slot will be pointing at. The second argument is a pointer to one of its methods. This particular version of <function>sigc::mem_fun()</function> creates a slot which will, when "called", call the pointed-to method of the specified object, in this case <methodname>some_object.on_button_clicked()</methodname>.The next statement: <placeholder-1/> creates a <classname>Gtk::Application</classname> object, stored in a <classname>RefPtr</classname> smartpointer. This is needed in all <application>gtkmm</application> applications. The <methodname>create()</methodname> method for this object initializes <application>gtkmm</application>, and checks the arguments passed to your application on the command line, looking for standard options such as <literal>--display</literal>. It takes these from the argument list, leaving anything it does not recognize for your application to parse or ignore. This ensures that all <application>gtkmm</application> applications accept the same set of standard arguments.The next two lines of code create a window and set its default (initial) size:The number of decimal places can be altered using the <methodname>set_digits()</methodname> method.The only difference between this example and the straight line example is in the <methodname>on_draw()</methodname> function, but there are a few new concepts and functions introduced here, so let's examine them briefly.The orientation of a <classname>Gtk::Scrollbar</classname> can be either horizontal or vertical.The other group includes the <classname>Viewport</classname> widget and the <classname>ScrolledWindow</classname> widget. All of these widgets use pixel values for their adjustments. These are also typically adjusted indirectly using scrollbars. While all widgets which use adjustments can either create their own adjustments or use ones you supply, you'll generally want to let this particular category of widgets create its own adjustments.The package names will not change when new API/ABI-compatible versions of <application>gtkmm</application> are released. Otherwise they would not be API/ABI-compatible. So don't be surprised, for instance, to find <application>gtkmm</application> 3.8 supplied by Debian's <application>libgtkmm-3.0-dev</application> package.The primary disadvantage of using class scope widgets is revealing the class implementation rather than the class interface in the class header.The primary object is <classname>Gtk::PrintOperation</classname>, allocated for each print operation. To handle page drawing connect to its signals, or inherit from it and override the default virtual signal handlers. <classname>PrintOperation</classname> automatically handles all the settings affecting the print loop.The process of writing source code that allows for translation is called <literal>internationalization</literal>, often abbreviated to <literal>i18n</literal>. The <literal>Localization</literal> process, sometimes abbreviated as <literal>l10n</literal>, provides translated text for other languages, based on that source code.The progress bar can also display a configurable text string within its trough, using the <methodname>set_text()</methodname> method.The purpose of this example is to show the steps the event takes when it is emitted.The return value is a <classname>sigc::connection</classname> that may be used to stop monitoring this file descriptor using its <methodname>disconnect()</methodname> method. The <parameter>slot</parameter> signal handler should be declared as follows:The rulesThe same principles apply for signals which have more arguments. Here's one with three (taken from <filename>&lt;gtkmm/textbuffer.h&gt;</filename>):The second way to set up radio buttons is to make a group first, and then add radio buttons to it. Here's an example:The section for drawing an arc introduces one new function, <methodname>close_path()</methodname>. This function will in effect draw a straight line from the current point back to the first point in the path. There is a significant difference between calling <methodname>close_path()</methodname> and manually drawing a line back to the starting point, however. If you use <methodname>close_path()</methodname>, the lines will be nicely joined together. If you use <methodname>line_to()</methodname> instead, the lines will end at the same point, but Cairo won't do any special joining.The selected rowsThe signal handler is <methodname>on_button_clicked()</methodname>.The single-item container widgets derive from <classname>Gtk::Bin</classname>, which provides the <methodname>add()</methodname> and <methodname>remove()</methodname> methods for the child widget. Note that <classname>Gtk::Button</classname> and <classname>Gtk::Window</classname> are technically single-item containers, but we have discussed them already elsewhere.The slots connected to <classname>sigc::signal</classname> objects execute in the thread which calls <methodname>emit()</methodname> or <methodname>operator()()</methodname> on the signal. <classname>Glib::Dispatcher</classname> does not behave this way: instead its connected slots execute in the thread in which the <classname>Glib::Dispatcher</classname> object was constructed (which must have a glib main loop). If a <classname>Glib::Dispatcher</classname> object is constructed in the main GUI thread (which will therefore be the receiver thread), any worker thread can emit on it and have the connected slots safely execute <application>gtkmm</application> functions.The source widget will emit these signals, in this order: <placeholder-1/>The standard tree models (<classname>TreeStore</classname> and <classname>ListStore</classname>) derive from <classname>TreeSortable</classname>, so they offer sorting functionality. For instance, call <methodname>set_sort_column()</methodname>, to sort the model by the specified column. Or supply a callback function to <methodname>set_sort_func()</methodname> to implement a more complicated sorting algorithm.The text columnThe trick is to position in the middle of the pixel where you want the line to be drawn, and thus guaranteeing you get the desired results. See <ulink url="http://cairographics.org/FAQ/#sharp_lines">Cairo FAQ</ulink>.The use of the <literal>const</literal> keyword in C++ is not always clear. You might not realise that <type>const Something*</type> declares a pointer to a <type>const Something</type>. The pointer can be changed, but not the <type>Something</type> that it points to.The value can have an adjustable number of decimal places, and the step size is configurable. <classname>SpinButton</classname>s have an 'auto-repeat' feature as well: holding down the increment or decrement button can optionally cause the value to change more quickly the longer the button is held down.The value displayed by a scale widget is rounded to one decimal point by default, as is the <literal>value</literal> field in its <classname>Gtk::Adjustment</classname>. You can change this with the <methodname>set_digits()</methodname> method.The virtual <methodname>on_draw()</methodname> method provides a Cairo context that you shall use for drawing in the <classname>Gtk::DrawingArea</classname> widget. It is not necessary to save and restore this Cairo context in <methodname>on_draw()</methodname>.The way it works is that you upload your source code to a git repository where translators can access it, then contact the gnome-i18n mailing list and ask to have your program added to the <ulink url="http://l10n.gnome.org/module/">list of modules to translate</ulink>.The way that <classname>Sockets</classname> and <classname>Plugs</classname> work together is through their window ids. Both a <classname>Socket</classname> and a <classname>Plug</classname> have IDs that can be retrieved with their <methodname>get_id()</methodname> member functions. The use of these IDs will be explained below in <xref linkend="sec-connecting-plugs-sockets"/>.The widgets don't rearrange themselves when the window is resized. Some widgets are hidden when the window is made smaller, and lots of useless space appears when the window is made larger.The width of the label will be adjusted automatically. You can produce multi-line labels by putting line breaks ("\n") in the label string.The window ID is: 69206019Then edit the <filename>.cc</filename> file to specify the correct types. For instance, your <function>main()</function> function might look like this: <placeholder-1/>Then start the <filename>socket</filename> program:Then use <methodname>append_column()</methodname> to add the view Column to the View. Notice that <methodname>Gtk::TreeView::append_column()</methodname> is overridden to accept either a prebuilt <classname>Gtk::TreeView::Column</classname> widget, or just the <classname>TreeModelColumn</classname> from which it generates an appropriate <classname>Gtk::TreeView::Column</classname> widget.Then you make sure you update the file <filename>POTFILES.in</filename> in the <filename>po/</filename> subdirectory (<command>intltool-update -M</command> can help with this) so that the translators always access updated <filename>myprogram.pot</filename> files, and simply freeze the strings at least a couple of days before you make a new release, announcing it on gnome-i18n. Depending on the number of strings your program contains and how popular it is, the translations will then start to tick in as <filename>languagename.po</filename> files.Then, to add a widget at that position, use <methodname>Gtk::TextView::add_child_at_anchor()</methodname>:Then, you can define the actual visible layout of the menus and toolbars, and add the UI layout to the <classname>UIManager</classname>. This "ui string" uses an XML format, in which you should mention the names of the actions that you have already created. For instance:There are a couple of things to note about this example code. Again, the only real difference between this example and the previous ones is the <methodname>on_draw()</methodname> function, so we'll limit our focus to that function. In addition, the first part of the function is nearly identical to the previous examples, so we'll skip that portion.There are a few common mistakes that you would discover eventually yourself. But this section might help you to avoid them.There are a number of graphics state variables that can be set for a Cairo context. The most common context attributes are color (using <methodname>set_source_rgb()</methodname> or <methodname>set_source_rgba()</methodname> for translucent colors), line width (using <methodname>set_line_width()</methodname>), line dash pattern (using <methodname>set_dash()</methodname>), line cap style (using <methodname>set_line_cap()</methodname>), and line join style (using <methodname>set_line_join()</methodname>), and font styles (using <methodname>set_font_size()</methodname>, <methodname>set_font_face()</methodname> and others). There are many other settings as well, such as transformation matrices, fill rules, whether to perform antialiasing, and others. For further information, see the <ulink url="http://www.cairographics.org/cairomm/">cairomm</ulink> API documentation.There are basically five different styles, as shown in this picture:There are other things you can customize as well, including creating dashed lines and other things. For more information, see the Cairo API documentation.There are several derived <classname>Dialog</classname> classes which you might find useful. <classname>Gtk::MessageDialog</classname> is used for most simple notifications. But at other times you might need to derive your own dialog class to provide more complex functionality.There are several options governing how widgets are to be packed, and this can be confusing at first. If you have difficulties then it is sometimes a good idea to play with the <application>glade</application> GUI designer to see what is possible. You might even decide to use the <application>Gtk::Builder</application> API to load your GUI at runtime.There are several other containers, which we will also discuss.There are some optional extra arguments: <placeholder-1/>There are specific APIs for Menus and toolbars, but you should usually deal with them together, using the <classname>UIManager</classname> to define <classname>Action</classname>s which you can then arrange in menus and toolbars. In this way you can handle activation of the action instead of responding to the menu and toolbar items separately. And you can enable or disable both the menu and toolbar item via the action.There are two basic strategies that can be used: <placeholder-1/>There are two built-in <classname>Mark</classname>s - <literal>insert</literal> and <literal>selection_bound</literal>, which you can access with <classname>TextBuffer</classname>'s <methodname>get_insert()</methodname> and <methodname>get_selection_bound()</methodname> methods.There are two ways to create a Button. You can specify a label string in the <classname>Gtk::Button</classname> constructor, or set it later with <methodname>set_label()</methodname>.There are two ways to set up a group of radio buttons. The first way is to create the buttons, and set up their groups afterwards. Only the first two constructors are used. In the following example, we make a new window class called <classname>RadioButtons</classname>, and then put three radio buttons in it:There is a method for drawing from a <classname>Gdk::Pixbuf</classname> to a <classname>Cairo::Context</classname>. A <classname>Gdk::Pixbuf</classname> buffer is a useful wrapper around a collection of pixels, which can be read from files, and manipulated in various ways.There is a more complex example in examples/others/dnd.There is one optional extra argument: <placeholder-1/>There may be times when you need to modify the list of recent files. For instance, if a file is moved or renamed, you may need to update the file's location in the recent files list so that it doesn't point to an incorrect location. You can update an item's location by using <methodname>move_item()</methodname>.There's rather a lot to think about in this (non-functional) code. First let's identify the parties involved:Therefore, the <classname>RefPtr</classname> equivalent of <type>Something*</type> for a method parameter is <type>const Glib::RefPtr&lt;Something&gt;&amp;</type>, and the equivalent of <type>const Something*</type> is <type>const Glib::RefPtr&lt;const Something&gt;&amp;</type>.These are standard scrollbars. They should be used only to scroll another widget, such as, a <classname>Gtk::Entry</classname>, or a <classname>Gtk::Viewport</classname>, though it's usually easier to use the <classname>Gtk::ScrolledWindow</classname> widget in most cases.These dependencies have their own dependencies, including the following applications and libraries:These interactions arise from the fact that, amongst other things, a class inheriting from <classname>sigc::trackable</classname> will, via that inheritance, have a <classname>std::list</classname> object keeping track of slots created by calls to <function>sigc::mem_fun()</function> representing any of its non-static methods (more particularly it keeps a list of callbacks which will null the connected slots on its destruction). Each <classname>sigc::slot</classname> object also keeps, via <classname>sigc::slot_rep</classname>, its own <classname>sigc::trackable</classname> object to track any <classname>sigc::connection</classname> objects which it needs to inform about its demise, and also has a function to deregister itself from any <classname>sigc::trackable</classname> on disconnection or destruction. <classname>sigc::signal</classname> objects also keep lists of slots, which will be updated by a call to their <methodname>connect()</methodname> method or calls to any <classname>sigc::connection</classname> object relating to such a connection.These signals behave slightly differently. The value returned from the signal handler indicates whether it has fully "handled" the event. If the value is <literal>false</literal> then <application>gtkmm</application> will pass the event on to the next signal handler. If the value is <literal>true</literal> then no other signal handlers will need to be called.These widgets are mainly used for decoration or layout, so you won't often need to capture events on them. They are intended to have no X-Window in order to improve performance.Things are dragged from <literal>sources</literal> to be dropped on <literal>destinations</literal>. Each source and destination has infomation about the data formats that it can send or receive, provided by <classname>Gtk::TargetEntry</classname> items. A drop destination will only accept a dragged item if they both share a compatible <classname>Gtk::TargetEntry</classname> item. Appropriate signals will then be emitted, telling the signal handlers which <classname>Gtk::TargetEntry</classname> was used.This <filename>.defs</filename> file describes enum types and their possible values. It is generated by the <filename>enum.pl</filename> script which you can find in glibmm's <filename>tools</filename> directory. For instance, <placeholder-1/>This <filename>.defs</filename> file describes objects and their functions. It is generated by the <command>h2def.py</command> script which you can find in glibmm's <filename>tools/defs_gen</filename> directory. For instance, <placeholder-1/>This <filename>.defs</filename> file describes signals and properties. It is generated by the special <filename>generate_extra_defs</filename> utility that is in every wrapping project, such as <filename>gtkmm/tools/extra_defs_gen/</filename>. For instance <placeholder-1/>This <filename>.defs</filename> file describes virtual functions (vfuncs). It must be written by hand. There is the skeleton file <filename>skeleton/src/skeleton_vfunc.defs</filename> to start from. You can also look at <application>gtkmm</application>'s <filename>gtk/src/gtk_vfuncs.defs</filename> file.This <varname>PROGRAMNAME_LOCALEDIR</varname> variable will be used later in the <literal>Makefile.am</literal> file, to define a macro that will be used when you initialize <application>gettext</application> in your source code.This allows language bindings to implement their own equivalents (such as C++ constructors), without using the <function>*_new()</function> function. This is often necessary so that they can actually instantiate a derived GType, to add their own hooks for signal handlers and vfuncs.This bookThis book assumes a good understanding of C++, and how to create C++ programs.This book explains key concepts of the <application>gtkmm</application> C++ API for creating user interfaces. It also introduces the main user interface elements ("widgets").This book explains key concepts of the <application>gtkmm</application> C++ API for creating user interfaces. It also introduces the main user interface elements ("widgets"). Although it mentions classes, constructors, and methods, it does not go into great detail. Therefore, for full API information you should follow the links into the reference documentation.This causes <application>gtkmm</application> to call the specified method whenever nothing else is happening. You can add a priority (lower numbers are higher priorities). There are two ways to remove the signal handler: calling <methodname>disconnect()</methodname> on the <classname>sigc::connection</classname> object, or returning <literal>false</literal> in the signal handler, which should be declared as follows:This chapter will introduce some of the most important aspects of <application>gtkmm</application> coding. These will be demonstrated with simple working example code. However, this is just a taster, so you need to look at the other chapters for more substantial information.This class implements the "Hello World" window. It's derived from <classname>Gtk::Window</classname>, and has a single <classname>Gtk::Button</classname> as a member. We've chosen to use the constructor to do all of the initialisation work for the window, including setting up the signals. Here it is, with the comments omitted:This command will build and install a series of modules and will probably take quite a long time the first time through. After the first time, however, it should go quite a bit faster since it only needs to rebuild files that changed since the last build. Alternatively, after you've built and installed <application>gtkmm</application> the first time, you can rebuild <application>gtkmm</application> by itself (without rebuilding all of its dependencies) with the command <command>jhbuild buildone gtkmm</command>.This compiler error might look like this: <placeholder-1/> or this: <placeholder-2/>This document, like so much other great software out there, was created for free by volunteers. If you are at all knowledgeable about any aspect of <application>gtkmm</application> that does not already have documentation, please consider contributing to this document.This example adds a <classname>ToolPalette</classname> and a <classname>DrawingArea</classname> to a window and allows the user to drag icons from the tool palette to the drawing area. The tool palette contains several groups of items. The combo boxes allow the user to change the style and orientation of the tool palette.This example allows copy and pasting of application-specific data, using the standard text target. Although this is simple, it's not ideal because it does not identify the <classname>Clipboard</classname> data as being of a particular type.This example creates a <classname>Gtk::EntryCompletion</classname> and associates it with a <classname>Gtk::Entry</classname> widget. The completion uses a <classname>Gtk::TreeModel</classname> of possible entries, and some additional actions.This example creates a button with a picture and a label.This example creates a window with three buttons in a grid. The first two buttons are in the upper row, from left to right. A third button is attached underneath the first button, in a new lower row, spanning two columns.This example creates two executable programs: <filename>socket</filename> and <filename>plug</filename>. The idea is that <filename>socket</filename> has an application window that will embed a widget from the <filename>plug</filename> program. The way this example is designed, <filename>plug</filename> must be running first before starting <filename>socket</filename>. To see the example in action, execute the following commands in order from within the example directory:This example displays a window with three range widgets all connected to the same adjustment, along with a couple of controls for adjusting some of the parameters mentioned above and in the section on adjustments, so you can see how they affect the way these widgets work for the user.This example has a <classname>Gtk::TreeView</classname> widget, with a <classname>Gtk::ListStore</classname> model.This example implements a container with two child widgets, one above the other. Of course, in this case it would be far simpler just to use a vertical <classname>Gtk::Box</classname>.This example implements a widget which draws a Penrose triangle.This example is identical to the <classname>ListStore</classname> example, but it uses <methodname>TreeView::append_column_editable()</methodname> instead of <methodname>TreeView::append_column()</methodname>.This example is much like the <classname>ListStore</classname> example, but derives a custom <classname>TreeView</classname> in order to override the <literal>button_press_event</literal>, and also to encapsulate the tree model code in our derived class. See the <link linkend="sec-treeview-contextmenu">TreeView Popup Context Menu</link> section.This example is much like the <classname>TreeStore</classname> example, but has 2 extra columns to indicate whether the row can be dragged, and whether it can receive drag-and-dropped rows. It uses a derived <classname>Gtk::TreeStore</classname> which overrides the virtual functions as described in the <link linkend="sec-treeview-draganddrop">TreeView Drag and Drop</link> section.This example is very similar to the <classname>ListStore</classname> example, but uses a <classname>Gtk::TreeStore</classname> model instead, and adds children to the rows.This example points out the difference of idle and timeout methods a little. If you need methods that are called periodically, and speed is not very important, then you want timeout methods. If you want methods that are called as often as possible (like calculating a fractal in background), then use idle methods.This example right-aligns a button in a window by using an <classname>Alignment</classname> widget.This example shows a <classname>Gtk::Entry</classname> widget with a named search icon, and prints text to the terminal when the icon is pressed.This example shows a <classname>Gtk::Entry</classname> widget with a progress bar.This example shows how to load a <application>Glade</application> file at runtime and access the widgets via a derived class.This example uses <classname>Gtk::Entry</classname>. It also has two <classname>CheckButton</classname>s, with which you can toggle the editable and visible flags.This exception can then be thrown by methods which are generated from _WRAP_METHOD() with the errthrow option.This has the following advantages: <placeholder-1/>This involves a variety of tools, some of them crufty, but at least they work, and has been used successfully by several projects.This involves the use of the <classname>Gtk::ActionGroup</classname>, <classname>Gtk::Action</classname>, and <classname>UIManager</classname> classes, all of which should be instantiated via their <methodname>create()</methodname> methods, which return <classname>RefPtr</classname>s.This is a full working example that defines and uses custom signals.This is an example program with two threads, one GUI thread, like in all <application>gtkmm</application> programs, and one worker thread. The worker thread is created when you press the <literal>Start work</literal> button. It is deleted when the work is finished, when you press the <literal>Stop work</literal> button, or when you press the <literal>Quit</literal> button.This is demonstrated in the Popup Context Menu example.This is demonstrated in the drag_and_drop example.This is easy to correct in the C library, so do send a patch to the relevant maintainer.This is like the simple example, but it <placeholder-1/>This is one of the places where the beauty of C++ really comes out. One wouldn't think of subclassing a GTK+ widget simply to override its action method; it's just too much trouble. In GTK+, you almost always use signals to get things done, unless you're writing a new widget. But because overriding methods is so easy in C++, it's entirely practical - and sensible - to subclass a button for that purpose.This is the declaration of the <methodname>pack_start()</methodname> method:This isn't purely a <application>gtkmm</application> or GUI issue. <application>gtkmm</application> uses <application>libsigc++</application> to implement its proxy wrappers for the <application>GTK+</application> signal system, but for new, non-GTK+ signals, you can create pure C++ signals, using the <classname>sigc::signal&lt;&gt;</classname> template.This macro can be used to wrap structs which don't fit into any specialized category.This macro creates a constructor with arguments, equivalent to a <function>*_new()</function> C function. It won't actually call the <function>*_new()</function> function, but will simply create an equivalent constructor with the same argument types. It takes a C++ constructor signature, and a C function name.This macro creates a default constructor with no arguments.This macro declares a wrapper for a non-<classname>GObject</classname> struct, registered with <function>g_boxed_type_register_static()</function>.This macro declares a wrapper for a reference-counted opaque struct. The C++ wrapper cannot be directly instantiated and can only be used with <classname>Glib::RefPtr</classname>.This macro declares a wrapper for a simple assignable struct such as <classname>GdkRectangle</classname>. It is similar to <function>_CLASS_BOXEDTYPE</function>, but the C struct is not allocated dynamically.This macro declares a wrapper for a type that is derived from <classname>GObject</classname>, but whose wrapper is not derived from <classname>Gtk::Object</classname>.This macro declares a wrapper for a type that is derived from <classname>GTypeInterface</classname>.This macro declares a wrapper for a type whose wrapper is derived from <classname>Gtk::Object</classname>, such as a widget or dialog.This macro declares a wrapper for an opaque struct that has copy and free functions. The new, copy and free functions will be used to instantiate the default constructor, copy constructor and destructor.This macro generates a C++ enum to wrap a C enum. You must specify the desired C++ name and the name of the underlying C enum.This macro generates a C++ exception class, derived from Glib::Error, with a Code enum and a code() method. You must specify the desired C++ name, the name of the corresponding C enum, and the prefix for the C enum values.This macro generates initialization code for the interface.This macro generates the C++ libsigc++-style signal to wrap a C GObject signal. It actually generates a public accessor method, such as <function>signal_clicked()</function>, which returns a proxy object. <command>gmmproc</command> uses the .defs file to discover the C parameter types and the .m4 convert files to discover appropriate type conversions.This macro generates the C++ method to wrap a C GObject property. You must specify the property name and the wanted C++ type for the property. <command>gmmproc</command> uses the .defs file to discover the C type and the .m4 convert files to discover appropriate type conversions.This macro generates the C++ method to wrap a C function.This macro generates the C++ method to wrap a virtual C function.This macro is like <function>_WRAP_METHOD()</function>, but it generates only the documentation for a C++ method that wraps a C function. Use this when you must hand-code the method, but you want to use the documentation that would be generated if the method was generated.This macro just generates a Doxygen documentationn block for the enum. This is useful for enums that can't be wrapped with <function>_WRAP_ENUM()</function> because they are complexly defined (maybe using C macros) but including the generated enum documentation is still desired. It is used with the same syntax as <function>_WRAP_ENUM()</function> and also process the same options (though NO_GTYPE is just ignored because it makes no difference when just generating the enum's documentation).This macro will be used when you initialize <literal>gettext</literal> in your source code.This means that any method which takes a <type>const Glib::RefPtr&lt;BaseType&gt;</type> argument can also take a <type>const Glib::RefPtr&lt;DerivedType&gt;</type>. The cast is implicit, just as it would be for a normal pointer.This program contains a single class, <classname>MyArea</classname>, which is a subclass of <classname>Gtk::DrawingArea</classname> and contains an <methodname>on_draw()</methodname> member function. This function is called whenever the image in the drawing area needs to be redrawn. It is passed a <classname>Cairo::RefPtr</classname> pointer to a <classname>Cairo::Context</classname> that we use for the drawing. The actual drawing code sets the color we want to use for drawing by using <methodname>set_source_rgb()</methodname> which takes arguments defining the Red, Green, and Blue components of the desired color (valid values are between 0 and 1). After setting the color, we created a new path using the functions <methodname>move_to()</methodname> and <methodname>line_to()</methodname>, and then stroked this path with <methodname>stroke()</methodname>.This provides a directory structure for the source .hg and .ccg files and the generated .h and .cc files, with <filename>filelist.am</filename> Automake include files that can specify the various files in use, in terms of generic Automake variables. The directory structure usually looks like this, after we have renamed the directories appropriately: <placeholder-1/>This requires a number of rules to be observed when writing multi-threaded programs using <application>gtkmm</application>. These are set out below, but one point to note is that extra care is required when deriving classes from <classname>sigc::trackable</classname>, because the effects are unintuitive (see particularly points 4 and 5 below).This section describes primarily what you can expect on a Linux system, when you use <ulink url="http://www.gnu.org/software/gdb/">the gdb debugger</ulink>.This section is simply a gathering of wisdom, general style guidelines and hints for creating <application>gtkmm</application> applications.This simple application draws a curve with Cairo and displays the control points for each end of the curve.This simple example shows how to load a <application>Glade</application> file at runtime and access the widgets with <application>Gtk::Builder</application>.This tells gmmproc that the C <function>*_new()</function> has a final GError** parameter which should be ignored.This variable must mention the correct library name, and this library name must be used to form the <varname>_SOURCES</varname>, <varname>_LDFLAGS</varname>, and <varname>_LIBADD</varname> variable names. It is permissible to use variables substituted by <filename>configure</filename> like <varname>@SOMETHINGMM_API_VERSION@</varname> as part of the variable names.TimeoutsTimeouts, I/O and Idle FunctionsTo access a widget, for instance to <methodname>show()</methodname> a dialog, use the <methodname>get_widget()</methodname> method, providing the widget's name. This name should be specified in the <application>Glade</application> Properties window. If the widget could not be found, or is of the wrong type, then the pointer will be set to 0. <placeholder-1/>To achieve this, you should use the normal <classname>Gtk::TreeView</classname><methodname>insert_column()</methodname> and <methodname>append_column()</methodname> methods, then use <methodname>get_column_cell_renderer()</methodname> to get the <classname>Gtk::CellRenderer</classname> used by that column.To add a new file to the list of recent documents, in the simplest case, you only need to provide the URI. For example:To add widgets to the action area, use the <methodname>add_action_widget()</methodname> method. They will be packed alongside the default buttons. Use the <methodname>remove_action_widget()</methodname> method to remove widgets.To begin our introduction to <application>gtkmm</application>, we'll start with the simplest program possible. This program will create an empty 200 x 200 pixel window.To change the selection, specify a <classname>Gtk::TreeModel::iterator</classname> or <classname>Gtk::TreeModel::Row</classname>, like so:To change the value shown, use the <methodname>set_fraction()</methodname> method, passing a <type>double</type> between 0.0 and 1.0 to provide the new percentage.To control which rows can be selected, use the <methodname>set_select_function()</methodname> method, providing a <classname>sigc::slot</classname> callback. For instance:To convince yourself that you've done well, you may wish to add a translation for a new locale. In order to do that, go to the <filename>po</filename> subdirectory of your project and execute the following command: <placeholder-1/>To define an accelerator key for keyboard navigation, place an underscore before one of the label's characters and specify <literal>true</literal> for the optional <literal>mnemonic</literal> parameter. For instance:To detect a click of the right mouse button, you need to handle the <literal>button_press_event</literal> signal, and check exactly which button was pressed. Because the <classname>TreeView</classname> normally handles this signal completely, you need to either override the default signal handler in a derived <classname>TreeView</classname> class, or use <methodname>connect_notify()</methodname> instead of <methodname>connect()</methodname>. You probably also want to call the default handler before doing anything else, so that the right-click will cause the row to be selected first.To determine the currently-visible page, use the <methodname>get_current_page()</methodname> method, and pass the result to <methodname>get_nth_page()</methodname>, which returns a pointer to the actual widget. To programmatically change the current page, use the <methodname>set_current_page()</methodname> method.To determine which key was pressed or released, you read the value of <varname>GdkEventKey::keyval</varname> and compare it with a constant in the <filename>&lt;gdk/gdkkeysyms.h&gt;</filename> header file. The states of modifier keys (shift, ctrl, etc.) are available as bit-flags in <varname>GdkEventKey::state</varname>.To discover the currently visible page, use the <methodname>get_current_page()</methodname> method. This returns the page number, and then calling <methodname>get_nth_page()</methodname> with that number will give you a pointer to the actual child widget.To discover what item, if any, the user has chosen from the ComboBox, call <methodname>ComboBox::get_active()</methodname>. This returns a <classname>TreeModel::iterator</classname> that you can dereference to a <classname>Row</classname> in order to read the values in your columns. For instance, you might read an integer ID value from the model, even though you have chosen only to show the human-readable description in the ComboBox. For instance:To do any drawing in <application>gtkmm</application> with Cairo, you must first create a <classname>Cairo::Context</classname> object. This class holds all of the graphics state parameters that describe how drawing is to be done. This includes information such as line width, color, the surface to draw to, and many other things. This allows the actual drawing functions to take fewer arguments to simplify the interface. In <application>gtkmm</application>, a <classname>Cairo::Context</classname> is created by calling the <methodname>Gdk::Window::create_cairo_context()</methodname> function. Since Cairo contexts are reference-counted objects, this function returns a <classname>Cairo::RefPtr&lt;Cairo::Context&gt;</classname> object.To do this, you need to call the <methodname>pulse()</methodname> method at regular intervals. You can also choose the step size, with the <methodname>set_pulse_step()</methodname> method.To draw an ellipse, you can scale the current transformation matrix by different amounts in the X and Y directions. For example, to draw an ellipse with center at <varname>x</varname>, <varname>y</varname> and size <varname>width</varname>, <varname>height</varname>: <placeholder-1/>To enable this functionality, you must create a <classname>EntryCompletion</classname> object, and provide it to the <classname>Entry</classname> widget via the <methodname>set_completion()</methodname> method.To find out what rows the user has selected, get the <classname>Gtk::TreeView::Selection</classname> object from the <classname>TreeView</classname>, like so:To find out what targets are currently available on the <classname>Clipboard</classname> for pasting, call the <methodname>request_targets()</methodname> method, specifying a method to be called with the information. For instance:To find out what type of signal handler you can connect to a signal, you can look it up in the reference documentation or the header file. Here's an example of a signal declaration you might see in the <application>gtkmm</application> headers:To force it to snap to the nearest <literal>step_increment</literal>, use <methodname>set_snap_to_ticks()</methodname>.To instantiate a <classname>Gtk::MenuBar</classname> or <classname>Gtk::Toolbar</classname> which you can actually show, you should use the <methodname>UIManager::get_widget()</methodname> method, and then add the widget to a container. For instance:To instantiate just one window, or just one of the child widgets, you can specify the name of a widget as the second parameter. For instance, <placeholder-1/>To look up recently used files, <classname>RecentManager</classname> provides several functions. To look up a specific item by its URI, you can use the <methodname>lookup_item()</methodname> function, which will return a <classname>RecentInfo</classname> class. If the specified URI did not exist in the list of recent files, <methodname>lookup_item()</methodname> throws a <classname>RecentManagerError</classname> exception. For example:To make the <classname>SpinButton</classname> 'wrap' between its upper and lower bounds, use the <methodname>set_wrap()</methodname> method.To obtain a <application>gtkmm</application> instance from a C GObject instance, use the Glib::wrap() function. For instanceTo pack widgets into a custom dialog, you should pack them into the <classname>Gtk::Box</classname>, available via <methodname>get_content_area()</methodname>. To just add a <classname>Button</classname> to the bottom of the <classname>Dialog</classname>, you could use the <methodname>add_button()</methodname> method.To prevent the user from typing non-numeric characters into the entry box, pass <literal>true</literal> to the <methodname>set_numeric()</methodname> method.To programmatically change the selected page, use the <methodname>set_current_page()</methodname> method.To receive the keyboard events, you must first call the <methodname>Gtk::Widget::add_events()</methodname> function with a bit mask of the events you're interested in. The event signal handler will receive an argument that depends on the type of event. For keyboard events it's a <type>GdkEventKey*</type>. As discribed in the <link linkend="sec-xeventsignals">appendix</link>, the event signal handler returns a <type>bool</type> value, to indicate that the signal is fully handled (<literal>true</literal>) or allow event propagation (<literal>false</literal>).To render more than one model column in a view column, you need to create the <classname>TreeView::Column</classname> widget manually, and use <methodname>pack_start()</methodname> to add the model columns to it.To respond to the user clicking on a row or range of rows, connect to the signal like so:To retrieve the state of the <classname>ToggleButton</classname>, you can use the <methodname>get_active()</methodname> method. This returns <literal>true</literal> if the button is "down". You can also set the toggle button's state, with <methodname>set_active()</methodname>. Note that, if you do this, and the state actually changes, it causes the "clicked" signal to be emitted. This is usually what you want.To see where the exception is thrown, you can use the <application>gdb</application> command <userinput>catch throw</userinput>. <placeholder-1/>To set the title of a page, use the <methodname>set_page_title()</methodname> method. The header and side images of a page can be set with the <methodname>set_page_header_image()</methodname> and <methodname>set_page_side_image()</methodname> methods.To set up <application>jhbuild</application>, follow the basic installation instructions from the <ulink url="http://developer.gnome.org/jhbuild/unstable/">jhbuild manual</ulink>. After you have installed <application>jhbuild</application>, you should copy the sample <application>jhbuild</application> configuration file into your home directory by executing the following command from the <application>jhbuild</application> directory: <screen>$ cp examples/sample.jhbuildrc ~/.jhbuildrc</screen>To show the popup menu, use <classname>Gtk::Menu</classname>'s <methodname>popup()</methodname> method, providing the button identifier and the time of activation, as provided by the <literal>button_press_event</literal> signal, which you will need to handle anyway. For instance:To simplify compilation, we use <literal>pkg-config</literal>, which is present in all (properly installed) <application>gtkmm</application> installations. This program 'knows' what compiler switches are needed to compile programs that use <application>gtkmm</application>. The <literal>--cflags</literal> option causes <literal>pkg-config</literal> to output a list of include directories for the compiler to look in; the <literal>--libs</literal> option requests the list of libraries for the compiler to link with and the directories to find them in. Try running it from your shell-prompt to see the results on your system.To specify that some text in the buffer should have specific formatting, you must define a tag to hold that formatting information, and then apply that tag to the region of text. For instance, to define the tag and its properties:To use a <application>gtkmm</application> instance with a C function that requires a C GObject instance, use the <function>gobj()</function> function to obtain a pointer to the underlying GObject instance. For instanceTo work around this, you could write a comment in the source code just before the string, telling the translators to use the special character if it is available in their languages. For english, you could then make an American English <filename>en_US.po</filename> translation which used that special character.Toggle buttonsToggleButtonToolItem ReferenceToolItemGroup ReferenceToolPaletteToolPalette ExampleToolPalette ReferenceTooltipTooltip ReferenceTooltipsTooltips are the little information windows that pop up when you leave your pointer over a widget for a few seconds. Use <methodname>set_tooltip_text()</methodname> to set a text string as a tooltip on any <classname>Widget</classname>. <classname>Gtk::ToolItem</classname>s are not <classname>Widget</classname>s, but have the same method for convenience. <classname>Gtk::Tooltip</classname> is used for more advanced tooltip usage, such as showing an image as well as text.TreeModel::iterator iter = refTreeSelection-&gt;get_selected();
if(iter) //If anything is selected
{
  TreeModel::Row row = *iter;
  //Do something with the row.
}TreeModelSort ReferenceTreeSortable ReferenceTreeStoreTreeStore, for a hierarchyTreeView - Drag And DropTreeView - Editable CellsTreeView - ListStoreTreeView - Popup Context MenuTreeView - TreeStoreTrolltech's Qt is the closest competition to <application>gtkmm</application>, so it deserves discussion.Try executing the example and increasing the system load. The upper progress bar will increase steadily; the lower one will slow down.Try to compile and run it before going on. You should see something like this:Two extra parameters are optional, for the case that the interface derives from another interface, which should be the case when the GInterface has another GInterface as a prerequisite. For instance, from <filename>loadableicon.hg</filename>: <placeholder-1/>Typically our wrapper library would be called libsomethingmm. We can start by copying the <ulink url="http://git.gnome.org/browse/mm-common/tree/skeletonmm">skeleton source tree</ulink> from the mm-common module. <placeholder-1/>UI changes can be seen more quickly, so UIs are able to improve.UIManagerUnable to predeclare structsUnfortunately, the integration with the standard iostreams is not completely foolproof. <application>gtkmm</application> converts <classname>Glib::ustring</classname>s to a locale-specific encoding (which usually is not UTF-8) if you output them to an <classname>ostream</classname> with <function>operator&lt;&lt;</function>. Likewise, retrieving <classname>Glib::ustrings</classname> from <classname>istream</classname> with <function>operator&gt;&gt;</function> causes a conversion in the opposite direction. But this scheme breaks down if you go through a <classname>std::string</classname>, e.g. by inputting text from a stream to a <classname>std::string</classname> and then implicitly converting it to a <classname>Glib::ustring</classname>. If the string contained non-ASCII characters and the current locale is not UTF-8 encoded, the result is a corrupted <classname>Glib::ustring</classname>. You can work around this with a manual conversion. For instance, to retrieve the <classname>std::string</classname> from a <classname>ostringstream</classname>: <placeholder-1/>Unix and LinuxUnless your container is a top-level window that derives from <classname>Gtk::Window</classname>, you should probably also call <methodname>Gtk::Widget::set_has_window(false)</methodname> in your constructor. This means that your container does not create its own <classname>Gdk::Window</classname>, but uses its parent's window. (Note the difference between <classname>Gtk::Window</classname> and <classname>Gdk::Window</classname>.) If your container does need its own <classname>Gdk::Window</classname>, and does not derive from <classname>Gtk::Window</classname>, you must also override the <methodname>on_realize()</methodname> method as described in the <link linkend="sec-custom-widgets">Custom Widgets</link> section. And unless your container draws directly onto the underlying <classname>Gdk::Window</classname>, you should probably call <methodname>set_redraw_on_allocate(false)</methodname> to improve performance.Unlike the Windows UCS-2 Unicode solution, this does not require any special compiler options to process string literals, and it does not result in Unicode executables and libraries which are incompatible with ASCII ones.Unlike the other widgets in this section, pane widgets contain not one but two child widgets, one in each pane. Therefore, you should use <methodname>add1()</methodname> and <methodname>add2()</methodname> instead of the <methodname>add()</methodname> method.Unusual wordsUpdate your <literal>DISTCLEANFILES</literal>: <placeholder-1/>Use <classname>Glib::Dispatcher</classname> to invoke <application>gtkmm</application> functions from worker threads (this is dealt with in more detail in the next section).Use <methodname>Gtk::Builder::get_widget_derived()</methodname> like so: <placeholder-1/>Use GNU <application>autoconf</application> and <application>automake</application>! They are your friends :) <application>Automake</application> examines C files, determines how they depend on each other, and generates a <filename>Makefile</filename> so the files can be compiled in the correct order. <application>Autoconf</application> permits automatic configuration of software installation, handling a large number of system quirks to increase portability.Use the <methodname>append_page()</methodname>, <methodname>prepend_page()</methodname> and <methodname>insert_page()</methodname> methods to add tabbed pages to the <literal>Notebook</literal>, supplying the child widget and the name for the tab.Use the <methodname>append_page()</methodname>, <methodname>prepend_page</methodname> and <methodname>insert_page()</methodname> methods to add pages to the <classname>Assistant</classname>, supplying the child widget for each page.Use the last GError** parameter of the C function to throw an exception.Use the last GError** parameter of the C virtual function (if there is one) to throw an exception.Use these macros if you're wrapping a simple struct or boxed type that provides direct access to its data members, to create getters and setters for the data members.Use these macros to automatically provide getters and setters for a data member that is a pointer type. For the getter function, it will create two methods, one const and one non-const.Use these macros to provide getters and setters for a data member that is a <classname>GObject</classname> type that must be referenced before being returned.Used in conjunction with the <literal>slot_name</literal> option to specify the name of the glue callback function that handles extracting the slot and then calling it. The address of this callback is also passed on to the C function that the method wraps.Useful methodsUsing Adjustments the Easy WayUsing Glib::DispatcherUsing a <application>gtkmm</application> widgetUsing a ModelUsing derived widgetsUsing non-ASCII characters in stringsUsing the git version of <application>gtkmm</application>VineWe also assume that you are using autotools (e.g. <application>automake</application> and <application>autoconf</application>) to build your project, and that you are using <ulink url="http://git.gnome.org/browse/gnome-common/tree/autogen.sh"><literal>./autogen.sh</literal> from <application>gnome-common</application></ulink>, which, among other things, takes care of some <application>intltool</application> initialization.We also discuss the <classname>Gtk::Paned</classname> widget, which allows you to divide a window into two separate "panes". This widget actually contains two child widgets, but the number is fixed so it seems appropriate.We just told you that the button's <literal>clicked</literal> signal is expecting to call a method with no arguments. All signals have requirements like this - you can't hook a function with two arguments to a signal expecting none (unless you use an adapter, such as <function>sigc::bind()</function>, of course). Therefore, it's important to know what type of signal handler you'll be expected to connect to a given signal.We made a new group by simply declaring a variable, <literal>group</literal>, of type <classname>Gtk::RadioButton::Group</classname>. Then we made three radio buttons, using a constructor to make each of them part of <literal>group</literal>.We make a call to <methodname>Cairo::Context::scale()</methodname>, passing in the width and height of the drawing area. This scales the user-space coordinate system such that the width and height of the widget are both equal to 1.0 'units'. There's no particular reason to scale the coordinate system in this case, but sometimes it can make drawing operations easier.We must mention all of our <filename>.hg</filename> and <filename>.ccg</filename> files in the <filename>skeleton/src/filelist.am</filename> file, typically in the <varname>files_hg</varname> variable.We now use std::vector in several methods instead of the intermediate *Handle types to make the API clearer.We should now create our first <filename>.hg</filename> and <filename>.ccg</filename> files, to wrap one of the objects in the C library. One pair of example source files already exists: <filename>skeleton.ccg</filename> and <filename>skeleton.hg</filename>. Create copies of these files as necessary.We then hook up a signal handler to <literal>m_button</literal>'s <literal>clicked</literal> signal. This prints our friendly greeting to <literal>stdout</literal>.We told <application>gtkmm</application> to put all three <classname>RadioButton</classname>s in the same group by obtaining the group with <methodname>get_group()</methodname> and using <methodname>set_group()</methodname> to tell the other <classname>RadioButton</classname>s to share that group.We will now explain each line of the exampleWe would very much like to hear of any problems you have learning <application>gtkmm</application> with this document, and would appreciate input regarding improvements. Please see the <link linkend="chapter-contributing">Contributing</link> section for further information.We're hooking it up to the <classname>Gtk::Button</classname> object called <varname>button</varname>.We've now learned enough to look at a real example. In accordance with an ancient tradition of computer science, we now introduce Hello World, a la <application>gtkmm</application>:What if a widget reconfigures the <parameter>upper</parameter> or <parameter>lower</parameter> fields of its <classname>Adjustment</classname>, such as when a user adds more text to a text widget? In this case, it emits the <literal>changed</literal> signal.What's the difference between spacing (set when the box is created) and padding (set when elements are packed)? Spacing is added between objects, and padding is added on either side of a widget. The following figure should make it clearer:When <varname>pixbuf</varname> goes out of scope an <methodname>unref()</methodname> will happen in the background and you don't need to worry about it anymore. There's no <literal>new</literal> so there's no <literal>delete</literal>.When a constructor must be partly hand written because, for instance, the <function>*_new()</function> C function's parameters do not correspond directly to object properties, or because the <function>*_new()</function> C function does more than call <function>g_object_new()</function>, the <function>_CONSTRUCT()</function> macro may be used in the .ccg file to save some work. The <function>_CONSTRUCT</function> macro takes a series of property names and values. For instance, from <filename>button.ccg</filename>: <placeholder-1/>When a drop destination has accepted a dragged item, certain signals will be emitted, depending on what action has been selected. For instance, the user might have held down the <keycap>Shift</keycap> key to specify a <literal>move</literal> rather than a <literal>copy</literal>. Remember that the user can only select the actions which you have specified in your calls to <methodname>drag_dest_set()</methodname> and <methodname>drag_source_set()</methodname>.When a program is aborted because of an unhandled C++ exception, it's sometimes possible to use a debugger to find the location where the exception was thrown. This is more difficult than usual if the exception was thrown from a signal handler.When deriving from <classname>Gtk::Container</classname>, you should override the following virtual methods: <placeholder-1/>When deriving from <classname>Gtk::Widget</classname>, you should override the following virtual methods. The methods marked (optional) need not be overridden in all custom widgets. The base class's methods may be appropriate. <placeholder-1/>When the Button emits its <literal>clicked</literal> signal, <methodname>on_button_clicked()</methodname> will be called.When the application runs, the <application>gettext</application> library checks the system-wide directory to see if there is a <filename>.mo</filename> file for the user's locale environment (you can set the locale with, for instance, "export LANG=de_DE.UTF-8" from a bash console). Later, when the program reaches a <literal>gettext</literal> call, it looks for a translation of a particular string. If none is found, the original string is used.When the mouse is over the button and a mouse button is pressed, <methodname>on_button_press()</methodname> will be called.When the user asks to copy some data, you should tell the <classname>Clipboard</classname> what targets are available, and provide the callback methods that it can use to get the data. At this point you should store a copy of the data, to be provided when the clipboard calls your callback method in response to a paste.When the user asks to paste data from the <classname>Clipboard</classname>, you should request a specific format and provide a callback method which will be called with the actual data. For instance:When the user enters arbitrary text, it may not be enough to connect to the <literal>changed</literal> signal, which is emitted for every typed character. It is not emitted when the user presses the Enter key. Pressing the Enter key or moving the keyboard focus to another widget may signal that the user has finished entering text. To be notified of these events, connect to the <classname>Entry</classname>'s <literal>activate</literal> and <literal>focus_out_event</literal> signals, like so <placeholder-1/> The <literal>changed</literal> signals of <classname>ComboBox</classname> and <classname>Entry</classname> are both emitted for every change. It doesn't matter which one you connect to. But only <classname>Entry</classname>'s <literal>focus_out_event</literal> signal is useful here.When using <function>_CLASS_GOBJECT()</function>, the constructors should be protected (rather than public) and each constructor should have a corresponding <function>_WRAP_CREATE()</function> in the public section. This prevents the class from being instantiated without using a <classname>RefPtr</classname>. For instance: <placeholder-1/>When using a <classname>Gtk::TreeStore</classname>, the rows can have child rows, which can have their own children in turn. Use <methodname>Gtk::TreeModel::Row::children()</methodname> to get the container of child <classname>Row</classname>s: <placeholder-1/>When using this simple <methodname>append_column()</methodname> override, the <classname>TreeView</classname> will display the model data with an appropriate <classname>CellRenderer</classname>. For instance, strings and numbers are shown in a simple <classname>Gtk::Entry</classname> widget, and booleans are shown in a <classname>Gtk::CheckButton</classname>. This is usually what you need. For other column types you must either connect a callback that converts your type into a string representation, with <methodname>TreeViewColumn::set_cell_data_func()</methodname>, or derive a custom <classname>CellRenderer</classname>. Note that (unsigned) short is not supported by default - You could use (unsigned) int or (unsigned) long as the column type instead.When you downloaded <application>jhbuild</application> from the git repository, you got a number of <filename>.modules</filename> files, specifying dependencies between modules. By default <application>jhbuild</application> does not use the downloaded versions of these files, but reads the latest versions in the git repository. This is usually what you want. If you don't want it, use the <varname>use_local_modulesets</varname> variable in <filename>.jhbuildrc</filename>.When you select a choice from the drop-down menu, the value from this column will be placed in the <classname>Entry</classname>.When you write in the entry, a key release event will be emitted, which will go first to the toplevel window (<classname>Gtk::Window</classname>), since we have one event handler set to be called before, that's what is called first (<methodname>windowKeyReleaseBefore()</methodname>). Then the default handler is called (which we have overridden), and after that the event is sent to the widget that has focus, the <classname>Entry</classname> in our example and, depending on whether we let it propagate, it can reach the <classname>Grid</classname>'s and the <classname>Window</classname>'s event handlers. If it propagates, the text you're writing will appear in the <classname>Label</classname> above the <classname>Entry</classname>.Whenever you press or release a key, an event is emitted. You can connect a signal handler to handle such events.Why use <application>gtkmm</application> instead of GTK+?Widget ReferenceWidget::on_expose_event() was replaced by Widget::on_draw(), which assumes that cairomm is used for drawing, via the provided <classname>Cairo::Context</classname> and does not require you to call <methodname>Cairo::Context::clip()</methodname>.WidgetsWidgets Without X-WindowsWidgets and ChildAnchorsWidgets are arranged inside container widgets such as frames and notebooks, in a hierarchy of widgets within widgets. Some of these container widgets, such as <classname>Gtk::Grid</classname>, are not visible - they exist only to arrange other widgets. Here is some example code that adds 2 <classname>Gtk::Button</classname> widgets to a <classname>Gtk::Box</classname> container widget: <placeholder-1/> and here is how to add the <classname>Gtk::Box</classname>, containing those buttons, to a <classname>Gtk::Frame</classname>, which has a visible frame and title: <placeholder-2/>With <function>_WRAP_METHOD()</function> it is also possible for the return of the wrapped C function (if it has one) to be placed in an output parameter of the C++ method instead of having the C++ method also return a value like the C function does. To do that, simply include the output parameter in the C++ method parameter list appending a <literal>{OUT}</literal> to the output parameter name. For example, if <function>gtk_widget_get_request_mode()</function> is declared as the following: <placeholder-1/> And having the C++ method set an output parameter is desired instead of returning a <type>SizeRequestMode</type>, something like the following could be used: <placeholder-2/> The <literal>{OUT}</literal> appended to the name of the <parameter>mode</parameter> output parameter tells <command>gmmproc</command> to place the return of the C function in that output parameter. In this case, however, a necessary initialization macro like the following would also have to be specified: <placeholder-3/> Which could also be written as: <placeholder-4/>With Cairo, the same function is used to draw arcs, circles, or ellipses: <methodname>Cairo::Context::arc()</methodname>. This function takes five arguments. The first two are the coordinates of the center point of the arc, the third argument is the radius of the arc, and the final two arguments define the start and end angle of the arc. All angles are defined in radians, so drawing a circle is the same as drawing an arc from 0 to 2 * M_PI radians. An angle of 0 is in the direction of the positive X axis (in user-space). An angle of M_PI/2 radians (90 degrees) is in the direction of the positive Y axis (in user-space). Angles increase in the direction from the positive X axis toward the positive Y axis. So with the default transformation matrix, angles increase in a clockwise direction. (Remember that the positive Y axis points downwards.)Working with gtkmm's Source CodeWrapping <classname>GList*</classname> and <classname>GSList*</classname> parameters: First, you need to discover what objects are contained in the list's data field for each item, usually by reading the documentation for the C function. The list can then be wrapped by a <classname>std::vector</classname> type. For instance, <code>std::vector&lt; Glib::RefPtr&lt;Gdk::Pixbuf&gt; &gt;</code>. You may need to define a Traits type to specify how the C and C++ types should be converted.Wrapping <classname>GList*</classname> and <classname>GSList*</classname> return types: You must discover whether the caller should free the list and whether it should release the items in the list, again by reading the documentation of the C function. With this information you can choose the ownership (none, shallow or deep) for the m4 conversion rule, which you should probably put directly into the .hg file because the ownership depends on the function rather than the type. For instance: <placeholder-1/>Wrapping C Libraries with gmmprocWriting signal handlersWriting the vfuncs .defsX Event signalsX events are described in more detail in the <link linkend="sec-xeventsignals">X Event signals</link> section in the appendix.X events differ in some ways from other signals. These differences are described in the <link linkend="sec-xeventsignals">X Event signals</link> section in the appendix. Here we will use keyboard events to show how X events can be used in a program.Yes, that's correct: a Window can contain at most one widget. How, then, can we use a window for anything useful? By placing a multiple-child container in the window. The most useful container widgets are <classname>Gtk::Grid</classname> and <classname>Gtk::Box</classname>.You are likely to encounter some problems in the library that you are wrapping, particularly if it is a new project. Here are some common problems, with solutions.You are not guaranteed to get the <literal>Gtk::SizeRequestMode</literal> that you request. Therefore all four of the <methodname>get_preferred_xxx_vfunc()</methodname> methods must return sensible values.You can adjust the position of the divider using the <methodname>set_position()</methodname> method, and you will probably need to do so.You can also cast to a derived type, but the syntax is a little different than with a normal pointer.You can also connect to <classname>CellRenderer</classname> signals to detect user actions. For instance:You can also specify a signal handler when calling <methodname>ActionGroup::add()</methodname>. This signal handler will be called when the action is activated via either a menu item or a toolbar button.You can also use <methodname>get_tag_table()</methodname> to get, and maybe modify, the <classname>TextBuffer</classname>'s default <classname>TagTable</classname> instead of creating one explicitly.You can apply more than one <classname>Tag</classname> to the same text, by using <methodname>apply_tag()</methodname> more than once, or by using <methodname>insert_with_tags()</methodname>. The <classname>Tag</classname>s might specify different values for the same properties, but you can resolve these conflicts by using <methodname>Tag::set_priority()</methodname>.You can build several modules by setting the <varname>modules</varname> variable to a meta-package, e.g. <literal>meta-gnome-core</literal>, or listing more than one module name. The <varname>modules</varname> variable specifies which modules will be built when you don't explicitly specify anything on the command line. You can always build a different moduleset later by specifying it on the commandline (e.g. <command>jhbuild build gtkmm</command>).You can cast <classname>RefPtr</classname>s to base types, just like normal pointers.You can copy <classname>RefPtr</classname>s, just like normal pointers. But unlike normal pointers, you don't need to worry about deleting the underlying instance.You can create a new <classname>RecentManager</classname>, but you'll most likely just want to use the default one. You can get a reference to the default <classname>RecentManager</classname> with <methodname>get_default()</methodname>.You can dereference a smartpointer with the -&gt; operator, to call the methods of the underlying instance, just like a normal pointer.You can dereference the iterator to get the Row:You can draw very sophisticated shapes using Cairo, but the methods to do so are quite basic. Cairo provides methods for drawing straight lines, curved lines, and arcs (including circles). These basic shapes can be combined to create more complex shapes and paths which can be filled with solid colors, gradients, patterns, and other things. In addition, Cairo can perform complex transformations, do compositing of images, and render antialiased text.You can embed widgets, such as <classname>Gtk::Button</classname>s, in the text. Each such child widget needs a <classname>ChildAnchor</classname>. ChildAnchors are associated with <classname>iterators</classname>. For instance, to create a child anchor at a particular position, use <methodname>Gtk::TextBuffer::create_child_anchor()</methodname>:You can set the <emphasis>margin</emphasis> and <emphasis>expand</emphasis> properties of the child <classname>Widget</classname>s to control their spacing and their behaviour when the Grid is resized.You can set the spinbutton's value using the <methodname>set_value()</methodname> method, and retrieve it with <methodname>get_value()</methodname>.You can specify a <classname>Gtk::TreeModel</classname> when constructing the <classname>Gtk::TreeView</classname>, or you can use the <methodname>set_model()</methodname> method, like so:You can specify a name for the <classname>Tag</classname> when using the <methodname>create()</methodname> method, but it is not necessary.You can stop the timeout method by returning <literal>false</literal> from your signal handler. Therefore, if you want your method to be called repeatedly, it should return <literal>true</literal>.You can then connect to the appropriate "edited" signal. For instance, connect to <methodname>Gtk::CellRendererText::signal_edited()</methodname>, or <methodname>Gtk::CellRendererToggle::signal_toggled()</methodname>. If the column contains more than one <classname>CellRenderer</classname> then you will need to use <methodname>Gtk::TreeView::get_column()</methodname> and then call <methodname>get_cell_renderers()</methodname> on that view Column.You can then connect to the signal using the same syntax used when connecting to <application>gtkmm</application> signals. For instance, <placeholder-1/>You can then use the <methodname>get_iter()</methodname> method later to create an iterator for the <classname>Mark</classname>'s new position.You can use <application>Glade</application> to layout your own custom widgets derived from <application>gtkmm</application> widget classes. This keeps your code organized and encapsulated. Of course you won't see the exact appearance and properties of your derived widget in <application>Glade</application>, but you can specify its location and child widgets and the properties of its <application>gtkmm</application> base class.You can use C APIs which do not yet have convenient C++ interfaces. It is generally not a problem to use C APIs from C++, and <application>gtkmm</application> helps by providing access to the underlying C object, and providing an easy way to create a C++ wrapper object from a C object, provided that the C API is also based on the GObject system.You can use the <methodname>append_column()</methodname> method to tell the View that it should display certain Model columns, in a certain order, with a certain column title.You can use the <methodname>operator[]</methodname> override to get the data in a particular column in a row, specifiying the <classname>TreeModelColumn</classname> used to create the model.You can use the <methodname>operator[]</methodname> override to set the data for a particular column in the row, specifying the <classname>TreeModelColumn</classname> used to create the model.You can use the <methodname>toggled()</methodname> method to toggle the button, rather than forcing it to be up or down: This switches the button's state, and causes the <literal>toggled</literal> signal to be emitted.You can usually pretend that <classname>Gtk::Clipboard</classname> is a singleton. You can get the default clipboard instance with <methodname>Gtk::Clipboard::get()</methodname>. This is probably the only clipboard you will ever need.You could just declare that signal as a public member variable, but some people find that distasteful and prefer to make it available via an accessor method, like so: <placeholder-1/>You could then encapsulate the manipulation of the child widgets in the constructor of the derived class, maybe using <methodname>get_widget()</methodname> or <methodname>get_widget_derived()</methodname> again. For instance, <placeholder-1/>You don't always need to call the parent's method; there are times when you might not want to. Note that we called the parent method <emphasis>after</emphasis> writing "Hello World", but we could have called it before. In this simple example, it hardly matters much, but there are times when it will. With signals, it's not quite so easy to change details like this, and you can do something here which you can't do at all with connected signal handlers: you can call the parent method in the <emphasis>middle</emphasis> of your custom code.You have no way of getting a bare <classname>Gdk::Pixbuf</classname>. In the example, <varname>pixbuf</varname> is a smart pointer, so you can do this, much like a normal pointer: <placeholder-1/>You may add a custom tab to the print dialog: <placeholder-1/>You may be wondering how to make <application>gtkmm</application> do useful work while it's idling along. Happily, you have several options. Using the following methods you can create a timeout method that will be called every few milliseconds.You might also derive non-widget classes from Gtk::Object so they can be used without <classname>Glib::RefPtr</classname>. For instance, they could then be instantiated with <function>Gtk::manage()</function> or on the stack as a member variable. This is convenient, but you should use this only when you are sure that true reference-counting is not needed. We consider it useful for widgets.You might be surprised to learn that <application>gtkmm</application> doesn't use <classname>std::string</classname> in its interfaces. Instead it uses <classname>Glib::ustring</classname>, which is so similar and unobtrusive that you could actually pretend that each <classname>Glib::ustring</classname> is a <classname>std::string</classname> and ignore the rest of this section. But read on if you want to use languages other than English in your application.You might need to react to every change of selection in the ComboBox, for instance to update other widgets. To do so, you should handle the <literal>changed</literal> signal. For instance:You might not anticipate the need to support additional languages, but you can never rule it out. And it's easier to develop the application properly in the first place rather than retrofitting later.You might occasionally find it useful to handle X events when there's something you can't accomplish with normal signals. <classname>Gtk::Button</classname>, for example, does not send mouse-pointer coordinates with its <literal>clicked</literal> signal, but you could handle <literal>button_press_event</literal> if you needed this information. X events are also often used to handle key-presses.You might then handle the <classname>ToolButton</classname>'s <literal>clicked</literal> signal. Alternatively, you could allow the item to be dragged to another widget, by calling <methodname>Gtk::ToolPalette::add_drag_dest()</methodname> and then using <methodname>Gtk::ToolPalette::get_drag_item()</methodname> in the other widget's <literal>drag_data_received</literal> signal handler.You might want to associate extra data with each row. If so, just add it as a Model column, but don't add it to the View.You might want to be notified whenever the user types in a text entry widget. <classname>Gtk::Entry</classname> provides two signals, <literal>activate</literal> and <literal>changed</literal>, for this purpose. <literal>activate</literal> is emitted when the user presses the Enter key in a text-entry widget; <literal>changed</literal> is emitted when the text in the widget changes. You can use these, for instance, to validate or filter the text the user types. Moving the keyboard focus to another widget may also signal that the user has finished entering text. The <literal>focus_out_event</literal> signal that <classname>Gtk::Entry</classname> inherits from <classname>Gtk::Widget</classname> can notify you when that happens. The <link linkend="sec-comboboxentry">ComboBox with an Entry</link> section contains example programs that use these signals.You might want to include additional source files that will not be generated by <command>gmmproc</command> from <filename>.hg</filename> and <filename>.ccg</filename> files. You can simply place these in your <filename>libsomething/libsomethingmm</filename> directory and mention them in the <filename>Makefile.am</filename> in the <varname>files_extra_h</varname> and <varname>files_extra_cc</varname> variables.You might wish to reuse documentation that exists for the C library that you are wrapping. GTK-style C libraries typically use gtk-doc and therefore have source code comments formatted for gtk-doc and some extra documentation in .sgml and .xml files. The docextract_to_xml.py script, from glibmm's <filename>tools/defs_gen</filename> directory, can read these files and generate an .xml file that <command>gmmproc</command> can use to generate doxygen comments. <command>gmmproc</command> will even try to transform the documentation to make it more appropriate for a C++ API.You must call the base class's constructor in the initialization list, providing the C pointer. For instance, <placeholder-1/>You must edit the source code of your own <filename>generate_extra_defs</filename> tool in order to generate the <filename>.defs</filename> for the GObject C types that you wish to wrap. In the skeleton source tree, the source file is named <filename>codegen/extradefs/generate_extra_defs_skeleton.cc</filename>. If not done so already, the file should be renamed, with the basename of your new binding substituted for the <varname>skeleton</varname> placeholder. The <filename>codegen/Makefile.am</filename> file should also mention the new source filename.You must set the optional parameter <literal>after = false</literal> in the call to <literal>signal_command_line().connect()</literal>, because your signal handler must be called before the default signal handler. You must also call <methodname>Gio::Application::activate()</methodname> in the signal handler, unless you want your application to exit without showing its main window. (<classname>Gio::Application</classname> is a base class of <classname>Gtk::Application</classname>.)You need to specify the <classname>Alignment</classname>'s characteristics to the constructor, or to the <methodname>set()</methodname> method. In particular, you won't notice much effect unless you specify a number other than 1.0 for the <literal>xscale</literal> and <literal>yscale</literal> parameters, because 1.0 simply means that the child widget will expand to fill all available space.You never know how much space a string will take on screen when translated. It might very possibly be twice the size of the original English string. Luckily, most <application>gtkmm</application> widgets will expand at runtime to the required size.You probably won't ever need to attach a handler to this signal, unless you're writing a new type of range widget.You should avoid C-style pointer arithmetic, and functions such as strlen(). In UTF-8, each character might need anywhere from 1 to 6 bytes, so it's not possible to assume that the next byte is another character. <classname>Glib::ustring</classname> worries about the details of this for you so you can use methods such as Glib::ustring::substr() while still thinking in terms of characters instead of bytes.You should avoid cryptic abbreviations, slang, or jargon. They are usually difficult to translate, and are often difficult for even native speakers to understand. For instance, prefer "application" to "app"You should avoid including the C header from your C++ header, to avoid polluting the global namespace, and to avoid exporting unnecessary public API. But you will need to include the necessary C headers from your .ccg file.You should be very careful when installing to standard system prefixes such as <filename>/usr</filename>. Linux distributions install software packages to <filename>/usr</filename>, so installing a source package to this prefix could corrupt or conflict with software installed using your distribution's package-management system. Ideally, you should use a separate prefix for all software you install from source.You should not declare these types yourself. You should instead use whatever Standard C++ container you prefer. glibmm will do the conversion for you. Here are some of these intermediate types: <placeholder-1/>You should save the chosen <classname>Gtk::PageSetup</classname> so you can use it again if the page setup dialog is shown again.You should then cast that <classname>Gtk::CellRenderer*</classname> to the specific <classname>CellRenderer</classname> that you expect, so you can use specific API.You specify the <classname>ColumnRecord</classname> when creating the Model, like so:You still need C++ code to deal with User Interface changes triggered by user actions, but using <application>Gtk::Builder</application> for the widget layout allows you to focus on implementing that functionality.You will typically use this macro when the class already derives from Gtk::Object. For instance, you will use it when wrapping a GTK+ Widget, because Gtk::Widget derives from Gtk::Object.You've probably noticed that <application>gtkmm</application> windows seem "elastic" - they can usually be stretched in many different ways. This is due to the <emphasis>widget packing</emphasis> system.Your application doesn't need to wait for clipboard operations, particularly between the time when the user chooses Copy and then later chooses Paste. Most <classname>Gtk::Clipboard</classname> methods take <classname>sigc::slot</classname>s which specify callback methods. When <classname>Gtk::Clipboard</classname> is ready, it will call these methods, either providing the requested data, or asking for data.Your callback will then provide the stored data when the user chooses to paste the data. For instance:Your derived class must have a constructor that takes a pointer to the underlying C type, and the <classname>Gtk::Builder</classname> instance. All relevant classes of <application>gtkmm</application> typedef their underlying C type as <classname>BaseObjectType</classname> (<classname>Gtk::Dialog</classname> typedefs <classname>BaseObjectType</classname> as <type>GtkDialog</type>, for instance).Your existing knowledge of C++ will help you with <application>gtkmm</application> as it would with any library. Unless we state otherwise, you can expect <application>gtkmm</application> classes to behave like any other C++ class, and you can expect to use your existing C++ techniques with <application>gtkmm</application> classes.Your implementation of the <methodname>child_type_vfunc()</methodname> method should report the type of widget that may be added to your container, if it is not yet full. This is usually <methodname>Gtk::Widget::get_type()</methodname> to indicate that the container may contain any class derived from <classname>Gtk::Widget</classname>. If the container may not contain any more widgets, then this method should return <literal>G_TYPE_NONE</literal>.Your library must be initialized before it can be used, to register the new types that it makes available. Also, the C library that you are wrapping might have its own initialization function that you should call. You can do this in an <function>init()</function> function that you can place in hand-coded <filename>init.h</filename> and <filename>init.cc</filename> files. This function should initialize your dependencies (such as the C function, and <application>gtkmm</application>) and call your generated <function>wrap_init()</function> function. For instance: <placeholder-1/>_CLASS_BOXEDTYPE_CLASS_BOXEDTYPE( C++ class, C class, new function, copy function, free function )_CLASS_BOXEDTYPE_STATIC_CLASS_BOXEDTYPE_STATIC( C++ class, C class )_CLASS_GENERIC_CLASS_GENERIC( C++ class, C class )_CLASS_GOBJECT_CLASS_GOBJECT( C++ class, C class, C casting macro, C++ base class, C base class )_CLASS_GTKOBJECT_CLASS_GTKOBJECT( C++ class, C class, C casting macro, C++ base class, C base class )_CLASS_GTKOBJECT()_CLASS_INTERFACE_CLASS_INTERFACE( C++ class, C class, C casting macro, C interface struct, Base C++ class (optional), Base C class (optional) )_CLASS_OPAQUE_COPYABLE_CLASS_OPAQUE_COPYABLE( C++ class, C class, new function, copy function, free function )_CLASS_OPAQUE_REFCOUNTED_CLASS_OPAQUE_REFCOUNTED( C++ class, C class, new function, ref function, unref function )_CTOR_DEFAULT_DEFS()_IGNORE / _IGNORE_SIGNAL_IGNORE(C function name 1, C function name2, etc)_IGNORE_SIGNAL(C signal name 1, C signal name2, etc)_IMPLEMENTS_INTERFACE_IMPLEMENTS_INTERFACE()_IMPLEMENTS_INTERFACE(C++ interface name)_MEMBER_GET / _MEMBER_SET_MEMBER_GET(C++ name, C name, C++ type, C type)_MEMBER_GET(x, x, int, int)_MEMBER_GET_GOBJECT / _MEMBER_SET_GOBJECT_MEMBER_GET_GOBJECT(C++ name, C name, C++ type, C type)_MEMBER_GET_PTR / _MEMBER_SET_PTR_MEMBER_GET_PTR(C++ name, C name, C++ type, C type)_MEMBER_SET(C++ name, C name, C++ type, C type)_MEMBER_SET_GOBJECT(C++ name, C name, C++ type, C type)_MEMBER_SET_PTR(C++ name, C name, C++ type, C type)_PINCLUDE()_WRAP_CTOR_WRAP_ENUM_WRAP_ENUM_DOCS_ONLY_WRAP_GERROR_WRAP_METHOD_WRAP_METHOD( C++ method signature, C function name)_WRAP_METHOD_DOCS_ONLY_WRAP_METHOD_DOCS_ONLY(C function name)_WRAP_PROPERTY_WRAP_PROPERTY(C property name, C++ type)_WRAP_SIGNAL_WRAP_SIGNAL( C++ signal handler signature, C signal name)_WRAP_VFUNC_WRAP_VFUNC( C++ method signature, C function name)adj-&gt;signal_value_changed().connect(sigc::bind&lt;MyPicture*&gt;(sigc::mem_fun(*this,
    &amp;cb_rotate_picture), picture));adjustment-&gt;signal_changed();and connect it to the scale widget's adjustment like this:and thenatkmmbinding_namebindtextdomain(GETTEXT_PACKAGE, PROGRAMNAME_LOCALEDIR);
bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
textdomain(GETTEXT_PACKAGE);boolbool DemoWindow::select_function(
    const Glib::RefPtr&lt;Gtk::TreeModel&gt;&amp; model,
    const Gtk::TreeModel::Path&amp; path, bool)
{
  const Gtk::TreeModel::iterator iter = model-&gt;get_iter(path);
  return iter-&gt;children().empty(); // only allow leaf nodes to be selected
}bool ExampleWindow::on_button_press_event(GdkEventButton* event)
{
  if( (event-&gt;type == GDK_BUTTON_PRESS) &amp;&amp;
      (event-&gt;button == 3) )
  {
    m_Menu_Popup-&gt;popup(event-&gt;button, event-&gt;time);
    return true; //It has been handled.
  }
  else
    return false;
}bool MyArea::on_draw(const Cairo::RefPtr&lt;Cairo::Context&gt;&amp; cr)
{
  Glib::RefPtr&lt;Gdk::Pixbuf&gt; image = Gdk::Pixbuf::create_from_file("myimage.png");
  // Draw the image at 110, 90, except for the outermost 10 pixels.
  Gdk::Cairo::set_source_pixbuf(cr, image, 100, 80);
  cr-&gt;rectangle(110, 90, image-&gt;get_width()-20, image-&gt;get_height()-20);
  cr-&gt;fill();
  return true;
}buttons examplecairocairommcell.property_editable() = true;class HelloWorld : public Gtk::Window
{

public:
  HelloWorld();
  virtual ~HelloWorld();

protected:
  //Signal handlers:
  virtual void on_button_clicked();

  //Member widgets:
  Gtk::Button m_button;
};class ModelColumns : public Gtk::TreeModelColumnRecord
{
public:

  ModelColumns()
    { add(m_col_text); add(m_col_number); }

  Gtk::TreeModelColumn&lt;Glib::ustring&gt; m_col_text;
  Gtk::TreeModelColumn&lt;int&gt; m_col_number;
};

ModelColumns m_Columns;class RadioButtons : public Gtk::Window
{
public:
    RadioButtons();

protected:
    Gtk::RadioButton m_rb1, m_rb2, m_rb3;
};

RadioButtons::RadioButtons()
  : m_rb1("button1"),
    m_rb2("button2"),
    m_rb3("button3")
{
    Gtk::RadioButton::Group group = m_rb1.get_group();
    m_rb2.set_group(group);
    m_rb3.set_group(group);
}class RadioButtons : public Gtk::Window
{
public:
    RadioButtons();
};

RadioButtons::RadioButtons()
{
    Gtk::RadioButton::Group group;
    Gtk::RadioButton *m_rb1 = Gtk::manage(
      new Gtk::RadioButton(group,"button1"));
    Gtk::RadioButton *m_rb2 = manage(
      new Gtk::RadioButton(group,"button2"));
      Gtk::RadioButton *m_rb3 = manage(
        new Gtk::RadioButton(group,"button3"));
}clickedconfigure.acconstversioncontext-&gt;save();
context-&gt;translate(x, y);
context-&gt;scale(width / 2.0, height / 2.0);
context-&gt;arc(0.0, 0.0, 1.0, 0.0, 2 * M_PI);
context-&gt;restore();custom_c_callbackcustom_default_handlercustom_vfunccustom_vfunc_callbackdeprecateddisplay_message("Getting ready for i18n.");display_message(_("Getting ready for i18n."));doubleenterenumserrthrowevent_box.add(child_widget);flags: Used only for drag and drop, this specifies whether the data may be dragged to other widgets and applications, or only to the same ones.functionsg++ simple.cc -o simple `pkg-config gtkmm-3.0 --cflags --libs`gbooleangchar*gdk-pixbufgdoublegettext manualgintglibglibmmgmmproc Parameter Processinggnomemm_hellogtk.defsgtk_enums.defsgtk_methods.defsgtk_signals.defsgtk_vfuncs.defsgtkmmgtkmm-3.0 is the name of the current stable API. There was an older API called gtkmm-2-4 which installs in parallel when it is available. There were several versions of gtkmm-2.4, such as gtkmm 2.10 and there are several versions of the gtkmm-3.0 API. Note that the API name does not change for every version because that would be an incompatible API and ABI break. Theoretically, there might be a future gtkmm-4.0 API which would install in parallel with gtkmm-3.0 without affecting existing applications.gtkmm_helloguintgunicharifdefinfo: An identifier which will be sent to your signals to tell you which TargetEntry was used.intint cols_count = m_TreeView.append_column_editable("Alex", m_columns.alex);
Gtk::TreeViewColumn* pColumn = m_TreeView.get_column(cols_count-1);
if(pColumn)
{
  Gtk::CellRendererToggle* pRenderer =
    static_cast&lt;Gtk::CellRendererToggle*&gt;(pColumn-&gt;get_first_cell());
  pColumn-&gt;add_attribute(pRenderer-&gt;property_visible(), m_columns.visible);
  pColumn-&gt;add_attribute(pRenderer-&gt;property_activatable(), m_columns.world);int main(int argc, char** argv)
{
  Glib::RefPtr&lt;Gtk::Application&gt; app = Gtk::Application::create(argc, argv, "org.gtkmm.example");

  HelloWorld helloworld;
  return app-&gt;run(helloworld);
}intltool-update --potleavelib_LTLIBRARIESlibsigc++ 2.0m4 Conversionsm4 Initializationsm_TextView.add_child_at_anchor(m_Button, refAnchor);m_TreeView.append_column("Messages", m_Columns.m_col_text);m_TreeView.set_model(m_refListStore);m_box.pack_start(m_Button1);
m_box.pack_start(m_Button2);m_button1.signal_clicked().connect( sigc::mem_fun(*this,
  &amp;HelloWorld::on_button_clicked) );m_combo.set_entry_text_column(m_columns.m_col_name);m_combo.signal_changed().connect( sigc::mem_fun(*this,
      &amp;ExampleWindow::on_combo_changed) );m_frame.add(m_box);m_rb2.set_group(m_rb1.get_group()); //doesn't workm_refActionGroup = Gtk::ActionGroup::create();

m_refActionGroup-&gt;add( Gtk::Action::create("MenuFile", "_File") );
m_refActionGroup-&gt;add( Gtk::Action::create("New", "_New"),
  sigc::mem_fun(*this, &amp;ExampleWindow::on_action_file_new) );
m_refActionGroup-&gt;add( Gtk::Action::create("ExportData", "Export Data"),
  sigc::mem_fun(*this, &amp;ExampleWindow::on_action_file_open) );
m_refActionGroup-&gt;add( Gtk::Action::create("Quit", "_Quit"),
  sigc::mem_fun(*this, &amp;ExampleWindow::on_action_file_quit) );m_refTreeSelection-&gt;set_select_function( sigc::mem_fun(*this,
    &amp;DemoWindow::select_function) );modules = [ 'gtkmm' ]moduleset = 'gnome-suites-core-deps-3.12'no_default_handlerno_slot_copyobjects (GObjects, widgets, interfaces, boxed-types and plain structs)orpangommpkg-configpressedpropertiesrefBuffer-&gt;apply_tag(refTagMatch, iterRangeStart, iterRangeStop);refBuffer-&gt;insert_with_tag(iter, "Some text", refTagMatch);refClipboard-&gt;request_contents("example_custom_target",
    sigc::mem_fun(*this, &amp;ExampleWindow::on_clipboard_received) );refClipboard-&gt;request_targets( sigc::mem_fun(*this,
    &amp;ExampleWindow::on_clipboard_received_targets) );refTreeSelection-&gt;selected_foreach_iter(
    sigc::mem_fun(*this, &amp;TheClass::selected_row_callback) );

void TheClass::selected_row_callback(
    const Gtk::TreeModel::iterator&amp; iter)
{
  TreeModel::Row row = *iter;
  //Do something with the row.
}refTreeSelection-&gt;set_mode(Gtk::SELECTION_MULTIPLE);refTreeSelection-&gt;signal_changed().connect(
    sigc::mem_fun(*this, &amp;Example_IconTheme::on_selection_changed)
);refreturnrefreturn_ctypereleasedreturn app-&gt;run(window);row[m_Columns.m_col_text] = "sometext";signalsslot_callbackslot_namesrc/main.cc
src/other.ccstd::cout &lt;&lt; Glib::ustring::compose(
             _("Current amount: %1 Future: %2"), amount, future) &lt;&lt; std::endl;

label.set_text(Glib::ustring::compose(_("Really delete %1 now?"), filename));std::cout &lt;&lt; _("Current amount: ") &lt;&lt; amount
          &lt;&lt; _(" Future: ") &lt;&lt; future &lt;&lt; std::endl;

label.set_text(_("Really delete ") + filename + _(" now?"));std::ostringstream output;
output.imbue(std::locale("")); // use the user's locale for this stream
output &lt;&lt; percentage &lt;&lt; " % done";
label-&gt;set_text(Glib::locale_to_utf8(output.str()));std::stringstd::string uses 8 bit per character, but 8 bits aren't enough to encode languages such as Arabic, Chinese, and Japanese. Although the encodings for these languages have now been specified by the Unicode Consortium, the C and C++ languages do not yet provide any standardised Unicode support. GTK+ and GNOME chose to implement Unicode using UTF-8, and that's what is wrapped by Glib::ustring. It provides almost exactly the same interface as std::string, along with automatic conversions to and from std::string.std::vector&lt; Glib::RefPtr&lt;Gtk::RecentInfo&gt; &gt; info_list = recent_manager-&gt;get_items();target: A name, such as "STRING"translator-creditstypedef Gtk::TreeModel::Children type_children; //minimise code length.
type_children children = refModel-&gt;children();
for(type_children::iterator iter = children.begin();
    iter != children.end(); ++iter)
{
  Gtk::TreeModel::Row row = *iter;
  //Do something with the row - see above for set/get.
}vfuncsvfuncs (function pointer member fields in structs), written by hand.void ExampleWindow::on_button_delete()
{
  Glib::RefPtr&lt;Gtk::TreeSelection&gt; refTreeSelection =
      m_treeview.get_selection();
  if(refTreeSelection)
  {
    Gtk::TreeModel::iterator sorted_iter =
        m_refTreeSelection-&gt;get_selected();
    if(sorted_iter)
    {
      Gtk::TreeModel::iterator iter =
          m_refModelSort-&gt;convert_iter_to_child_iter(sorted_iter);
      m_refModel-&gt;erase(iter);
    }
  }
}void ExampleWindow::on_clipboard_get(
    Gtk::SelectionData&amp; selection_data, guint /* info */)
{
  const std::string target = selection_data.get_target();

  if(target == "example_custom_target")
    selection_data.set("example_custom_target", m_ClipboardStore);
}void ExampleWindow::on_clipboard_received(
    const Gtk::SelectionData&amp; selection_data)
{
  Glib::ustring clipboard_data = selection_data.get_data_as_string();
  //Do something with the pasted data.
}void ExampleWindow::on_clipboard_received_targets(
  const std::vector&lt;Glib::ustring&gt;&amp; targets)
{
  const bool bPasteIsPossible =
    std::find(targets.begin(), targets.end(),
      example_target_custom) != targets.end();

  // Enable/Disable the Paste button appropriately:
  m_Button_Paste.set_sensitive(bPasteIsPossible);
}void cb_rotate_picture (MyPicture* picture)
{
  picture-&gt;set_rotation(adj-&gt;get_value());
...void doSomething(const Cairo::RefPtr&lt;Cairo::Context&gt;&amp; context, int x)
{
    context-&gt;save();
    // change graphics state
    // perform drawing operations
    context-&gt;restore();
}void drag_dest_set(const std::vector&lt;Gtk::TargetEntry&gt;&amp; targets,
    Gtk::DestDefaults flags, Gdk::DragAction actions);void drag_source_set(const std::vector&lt;Gtk::TargetEntry&gt;&amp; targets,
      Gdk::ModifierType start_button_mask, Gdk::DragAction actions);void pack_start(Gtk::Widget&amp; child,
                Gtk::PackOptions options = Gtk::PACK_EXPAND_WIDGET,
                guint padding = 0);where <parameter>condition</parameter> is as specified above. As usual the slot is created with <function>sigc::mem_fun()</function> (for a member method of an object), or <function>sigc::ptr_fun()</function> (for a function).wrap_init_flagsxgettext -a -o my-strings --omit-header *.cc *.hProject-Id-Version: gtkmm-documentation master
PO-Revision-Date: 2017-10-17 20:58+0200
Last-Translator: Marek Černocký <marek@manet.cz>
Language-Team: čeština <gnome-cs-list@gnome.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Language: cs
Plural-Forms: nplurals=3; plural=(n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2;
X-Generator: Gtranslator 2.91.7

        GtkSizeRequestMode gtk_widget_get_request_mode(GtkWidget* widget);
      
        GtkToolItem* gtk_tool_button_new(GtkWidget* icon_widget, const gchar*
        label);
      
        _INITIALIZATION(`Gdk::Rectangle&amp;',`GdkRectangle', `$3 =
        Glib::wrap(&amp;($4))')
      
        _INITIALIZATION(`SizeRequestMode&amp;',`GtkSizeRequestMode',`$3 =
        ($1)($4)')
      
        _INITIALIZATION(`SizeRequestMode&amp;',`GtkSizeRequestMode',`$3 =
        (SizeRequestMode)($4)')
      
        _WRAP_CTOR(ToolButton(Widget&amp; icon_widget, const Glib::ustring&amp;
        label{?}), gtk_tool_button_new)
      
        _WRAP_METHOD(bool get_cell_rect(const TreeModel::Path&amp; path, const
        CellRenderer&amp; cell, Gdk::Rectangle&amp; rect{&gt;&gt;}) const,
        gtk_icon_view_get_cell_rect)
      
        _WRAP_METHOD(void get_request_mode(SizeRequestMode&amp; mode{OUT})
        const, gtk_widget_get_request_mode)
      
        _WRAP_METHOD(void set_device_events(Gdk::EventMask events{.}, const
        Glib::RefPtr&lt;const Gdk::Device&gt;&amp; device{.}),
        gtk_widget_set_device_events)
      
        _WRAP_METHOD(void set_device_events(Gdk::EventMask events{events},
        const Glib::RefPtr&lt;const Gdk::Device&gt;&amp; device{device}),
        gtk_widget_set_device_events)
      
        gboolean gtk_icon_view_get_cell_rect(GtkIconView* icon_view,
        GtkTreePath* path, GtkCellRenderer* cell, GdkRectangle* rect);
      
        void gtk_widget_set_device_events(GtkWidget* widget, GdkDevice* device,
        GdkEventMask events);
      
    ...
    button.signal_clicked().connect(sigc::ptr_fun(&amp;on_button_clicked));
    ...

  $ git clone git://git.gnome.org/mm-common
  $ cp -a mm-common/skeletonmm libnecomm

# ./configure
# make
# make install

#include &lt;gtkmm/bin.h&gt;
#include &lt;gtkmm/activatable.h&gt;
_DEFS(gtkmm,gtk)
_PINCLUDE(gtkmm/private/bin_p.h)

namespace Gtk
{

class Button
  : public Bin,
    public Activatable
{
  _CLASS_GTKOBJECT(Button,GtkButton,GTK_BUTTON,Gtk::Bin,GtkBin)
  _IMPLEMENTS_INTERFACE(Activatable)
public:

  _CTOR_DEFAULT
  explicit Button(const Glib::ustring&amp; label, bool mnemonic = false);

  _WRAP_METHOD(void set_label(const Glib::ustring&amp; label), gtk_button_set_label)

  ...

  _WRAP_SIGNAL(void clicked(), "clicked")

  ...

  _WRAP_PROPERTY("label", Glib::ustring)
};

} // jmenný prostor Gtk

#include &lt;gtkmm/button.h&gt;

class OverriddenButton : public Gtk::Button
{
protected:
    virtual void on_clicked();
}

void OverriddenButton::on_clicked()
{
    std::cout &lt;&lt; "Hello World" &lt;&lt; std::endl;

    // zavoláme základní verzi metody třídy
    Gtk::Button::on_clicked();
}

#include &lt;gtkmm/button.h&gt;

void on_button_clicked()
{
    std::cout &lt;&lt; "Hello World" &lt;&lt; std::endl;
}

main()
{
    Gtk::Button button("Hello World");
    button.signal_clicked().connect(sigc::ptr_fun(&amp;on_button_clicked));
}

#include &lt;gtkmm/button.h&gt;
#include &lt;gtkmm/window.h&gt;
class Foo : public Gtk::Window
{
private:
  Gtk::Button theButton;
  // bude zlikvidováno, když je zlikvidován objekt Foo
};

#include &lt;libsomething.h&gt;

int main(int, char**)
{
  something_init();

  std::cout &lt;&lt; get_defs(SOME_TYPE_WIDGET)
            &lt;&lt; get_defs(SOME_TYPE_STUFF);
  return 0;
}

$ ./enum.pl /usr/include/gtk-3.0/gtk/*.h &gt; gtk_enums.defs

$ ./h2def.py /usr/include/gtk-3.0/gtk/*.h &gt; gtk_methods.defs

$ cd gtk/src
$ /usr/lib/glibmm-2.4/proc/gmmproc -I ../../tools/m4 --defs . button . ./../gtkmm

$ cd tools/extra_defs_gen
$ ./generate_extra_defs &gt; gtk_signals.defs

$ for f in $(find libnecomm -depth -name '*skeleton*'); do \
    d="${f%/*}"; b="${f##*/}"; mv "$f" "$d/${b//skeleton/libneco}"; \
  done

&gt; gdb with_signal
(gdb) catch throw
Catchpoint 1 (throw)
(gdb) run
Catchpoint 1 (exception thrown), 0x00714ff0 in __cxa_throw ()
(gdb) backtrace
#0  0x00714ff0 in __cxa_throw () from /usr/lib/i386-linux-gnu/libstdc++.so.6
#1  0x08048bd4 in throwSomething () at with_signal.cc:6
(gdb) continue
Continuing.
(with_signal:2375): glibmm-ERROR **
unhandled exception (type unknown) in signal handler

Program received signal SIGTRAP, Trace/breakpoint trap.

&gt; gdb with_signal
(gdb) run
(with_signal:2703): glibmm-ERROR **:
unhandled exception (type unknown) in signal handler

Program received signal SIGTRAP, Trace/breakpoint trap.
(gdb) backtrace
#2  0x0063c6ab in glibmm_unexpected_exception () at exceptionhandler.cc:77
#3  Glib::exception_handlers_invoke () at exceptionhandler.cc:150
#4  0x0063d370 in glibmm_source_callback (data=0x804d620) at main.cc:212
#13 0x002e1b31 in Gtk::Application::run (this=0x804f300) at application.cc:178
#14 0x08048ccc in main (argc=1, argv=0xbfffecd4) at with_signal.cc:16

&gt; gdb without_signal
(gdb) run
terminate called after throwing an instance of 'char const*'

Program received signal SIGABRT, Aborted.
(gdb) backtrace
#7  0x08048864 in throwSomething () at without_signal.cc:6
#8  0x0804887d in main (argc=1, argv=0xbfffecd4) at without_signal.cc:12

(gdb) catch throw
(gdb) commands
(gdb)   backtrace
(gdb)   continue
(gdb)   end
(gdb) set pagination off
(gdb) run

// _MEMBER_GET_PTR(engine_lang, lang_engine, EngineLang*, PangoEngineLang*)
// Je to jen komentáře. Je těžké najít skutečný příklad ze života.

// ve třídě, která je zděděná z Gtk::Window …
Glib::RefPtr&lt;PrintOperation&gt; op = PrintOperation::create();
// … nastavení operace …
op-&gt;run(Gtk::PRINT_OPERATION_ACTION_PREVIEW, *this);

// v metodě třídy ExampleWindow …
Glib::RefPtr&lt;PrintOperation&gt; op = PrintOperation::create();
// … nastavení operace …
op-&gt;signal_done().connect(sigc::bind(sigc::mem_fun(*this, &amp;ExampleWindow::on_printoperation_done), op));
// spuštění operace

// with_signal.cc
#include &lt;gtkmm.h&gt;

bool throwSomething()
{
  throw "Something";
  return true;
}

int main(int argc, char** argv)
{
  Glib::signal_timeout().connect(sigc::ptr_fun(throwSomething), 500);
  Glib::RefPtr&lt;Gtk::Application&gt; app =
    Gtk::Application::create(argc, argv, "org.gtkmm.with_signal");
  app-&gt;hold();
  return app-&gt;run();
}

// without_signal.cc
#include &lt;gtkmm.h&gt;

bool throwSomething()
{
  throw "Something";
  return true;
}

int main(int argc, char** argv)
{
  throwSomething();
  Glib::RefPtr&lt;Gtk::Application&gt; app =
    Gtk::Application::create(argc, argv, "org.gtkmm.without_signal");
  return app-&gt;run();
}

// Ve třídě, která je zděděná z Gtk::Window a pamatuje si jako členy m_refPageSetup a m_refSettings…
Glib::RefPtr&lt;Gtk::PageSetup&gt; new_page_setup = Gtk::run_page_setup_dialog(*this, m_refPageSetup, m_refSettings);
m_refPageSetup = new_page_setup;

Button::Button(const Glib::ustring&amp; label, bool mnemonic)
:
  _CONSTRUCT("label", label.c_str(), "use_underline", gboolean(mnemonic))
{}

DerivedDialog* pDialog = 0;
builder-&gt;get_widget_derived("DialogBasic", pDialog);

DerivedDialog::DerivedDialog(BaseObjectType* cobject, const Glib::RefPtr&lt;Gtk::Builder&gt;&amp; builder)
: Gtk::Dialog(cobject)
{
}

DerivedDialog::DerivedDialog(BaseObjectType* cobject, const Glib::RefPtr&lt;Gtk::Builder&gt;&amp; builder)
: Gtk::Dialog(cobject),
  m_builder(builder),
  m_pButton(0)
{
  // Získat instanci Button z Glade a napojit obsluhu signálu:
  m_builder-&gt;get_widget("quit_button", m_pButton);
  if(m_pButton)
  {
    m_pButton-&gt;signal_clicked().connect( sigc::mem_fun(*this, &amp;DerivedDialog::on_button_quit) );
  }
}

Glib::RefPtr&lt;Gdk::Pixbuf&gt; pixbuf = Gdk::Pixbuf::create_from_file(filename);

Glib::RefPtr&lt;Gdk::Pixbuf&gt; pixbuf2 = pixbuf;

Glib::RefPtr&lt;Gdk::Pixbuf&gt; refPixbuf = Gdk::Pixbuf::create_from_file(filename);
Gdk::Pixbuf&amp; underlying = *refPixbuf; //Syntax error - will not compile.

Glib::RefPtr&lt;Gdk::Pixbuf&gt; refPixbuf = Gdk::Pixbuf::create_from_file(filename);
Glib::RefPtr&lt;Gdk::Pixbuf&gt; refPixbuf2 = refPixbuf;

Glib::RefPtr&lt;Gdk::Pixbuf&gt; refPixbuf = Gdk::Pixbuf::create_from_file(filename);
int width = refPixbuf-&gt;get_width();

Glib::RefPtr&lt;Gtk::Builder&gt; builder = Gtk::Builder::create_from_file("basic.glade");

Glib::RefPtr&lt;Gtk::Builder&gt; builder = Gtk::Builder::create_from_file("basic.glade", "treeview_products");

Glib::RefPtr&lt;Gtk::PrintOperation&gt; op = Gtk::PrintOperation::create();
// … nastavení operace …
op-&gt;set_export_filename("test.pdf");
Gtk::PrintOperationResult res = op-&gt;run(Gtk::PRINT_OPERATION_ACTION_EXPORT);

Glib::RefPtr&lt;Gtk::TreeModel&gt; refModel = m_TreeView.get_model();
if(refModel)
{
  int cols_count = refModel-&gt;get_n_columns();
  ...
}

Glib::RefPtr&lt;Gtk::TreeStore&gt; refStore =
Glib::RefPtr&lt;Gtk::TreeStore&gt;::cast_dynamic(refModel);
Glib::RefPtr&lt;Gtk::TreeStore&gt; refStore2 =
Glib::RefPtr&lt;Gtk::TreeStore&gt;::cast_static(refModel);

Glib::RefPtr&lt;Gtk::TreeStore&gt; refStore = Gtk::TreeStore::create(columns);
Glib::RefPtr&lt;Gtk::TreeModel&gt; refModel = refStore;

Glib::SignalProxy1&lt;bool, Gtk::DirectionType&gt; signal_focus()

Glib::SignalProxy3&lt;void, const TextBuffer::iterator&amp;, const Glib::ustrin&amp;, int&gt; signal_insert();

Gtk::Button* button = new Gtk::Button("example");
gtk_button_do_something_new(button-&gt;gobj());

Gtk::Button* pButton = new Gtk::Button("Test");

// zde se dělá něco užitečného s pButton

delete pButton;

Gtk::Dialog* pDialog = 0;
builder-&gt;get_widget("DialogBasic", pDialog);

Gtk::ToolButton* button = Gtk::manage(new Gtk::ToolButton(icon, "Big"));
button-&gt;set_tooltip_text("Big Brush);
group_brushes-&gt;insert(*button);

Gtk::ToolItemGroup* group_brushes =
  Gtk::manage(new Gtk::ToolItemGroup("Brushes"));
m_ToolPalette.add(*group_brushes);

Gtk::Widget* CustomPrintOperation::on_create_custom_widget()
{
  set_custom_tab_label("My custom tab");

  Gtk::Box* hbox = new Gtk::Box(Gtk::ORIENTATION_HORIZONTAL, 8);
  hbox-&gt;set_border_width(6);

  Gtk::Label* label = Gtk::manage(new Gtk::Label("Enter some text: "));
  hbox-&gt;pack_start(*label, false, false);
  label-&gt;show();

  hbox-&gt;pack_start(m_Entry, false, false);
  m_Entry.show();

  return hbox;
}

void CustomPrintOperation::on_custom_widget_apply(Gtk::Widget* /* widget */)
{
  Glib::ustring user_input = m_Entry.get_text();
  //...
}

GtkButton* cbutton = get_a_button();
Gtk::Button* button = Glib::wrap(cbutton);

GtkWidget* example_widget_new(int something, const char* thing)
{
        ExampleWidget* widget;
        widget = g_object_new (EXAMPLE_TYPE_WIDGET, NULL);
        example_widget_construct(widget, "something", something, "thing", thing);
}

void example_widget_construct(ExampleWidget* widget, int something, const char* thing)
{
        //Do stuff that uses private API:
        widget-&gt;priv-&gt;thing = thing;
        do_something(something);
}

GtkWidget* example_widget_new(int something, const char* thing)
{
        return g_object_new (EXAMPLE_TYPE_WIDGET, "something", something, "thing", thing, NULL);
}

MyContainer::MyContainer()
{
  Gtk::Button* pButton = Gtk::manage(new Gtk::Button("Test"));
  add(*pButton); //add *pButton to MyContainer
}

_CLASS_BOXEDTYPE(RGBA, GdkRGBA, NONE, gdk_rgba_copy, gdk_rgba_free)

_CLASS_BOXEDTYPE_STATIC(Rectangle, GdkRectangle)

_CLASS_GENERIC(AttrIter, PangoAttrIterator)

_CLASS_GOBJECT(AccelGroup, GtkAccelGroup, GTK_ACCEL_GROUP, Glib::Object, GObject)

_CLASS_GTKOBJECT(Button, GtkButton, GTK_BUTTON, Gtk::Bin, GtkBin)

_CLASS_INTERFACE(CellEditable, GtkCellEditable, GTK_CELL_EDITABLE, GtkCellEditableIface)

_CLASS_INTERFACE(LoadableIcon, GLoadableIcon, G_LOADABLE_ICON, GLoadableIconIface, Icon, GIcon)

_CLASS_OPAQUE_COPYABLE(Checksum, GChecksum, NONE, g_checksum_copy, g_checksum_free)

_CLASS_OPAQUE_REFCOUNTED(Coverage, PangoCoverage, pango_coverage_new, pango_coverage_ref, pango_coverage_unref)

_CONVERSION(`GtkTreeView*',`TreeView*',`Glib::wrap($3)')

_CONVERSION(`PrintSettings&amp;',`GtkPrintSettings*',__FR2P)
_CONVERSION(`const PrintSettings&amp;',`GtkPrintSettings*',__FCR2P)
_CONVERSION(`const Glib::RefPtr&lt;Printer&gt;&amp;',`GtkPrinter*',__CONVERT_REFPTR_TO_P($3))

_IGNORE(gtk_button_box_set_spacing, gtk_button_box_get_spacing)

_IMPLEMENTS_INTERFACE(Activatable)

_INITIALIZATION(`Gtk::Widget&amp;',`GtkWidget*',`$3 = Glib::wrap($4)')

_MEMBER_GET_GOBJECT(layout, layout, Pango::Layout, PangoLayout*)

_WRAP_ENUM(IconLookupFlags, GtkIconLookupFlags, NO_GTYPE)

_WRAP_ENUM(WindowType, GtkWindowType)

_WRAP_GERROR(PixbufError, GdkPixbufError, GDK_PIXBUF_ERROR)

_WRAP_METHOD(void set_text(const Glib::ustring&amp; text), gtk_entry_set_text)

_WRAP_METHOD_DOCS_ONLY(gtk_container_remove)

_WRAP_PROPERTY("label", Glib::ustring)

_WRAP_SIGNAL(void clicked(),"clicked")

_WRAP_VFUNC(SizeRequestMode get_request_mode() const, get_request_mode)

bool MyCallback() { std::cout &lt;&lt; "Hello World!\n" &lt;&lt; std::endl; return true; }

bool idleFunc();

bool input_callback(Glib::IOCondition condition);

bool on_button_press(GdkEventButton* event);
Gtk::Button button("label");
button.signal_button_press_event().connect( sigc::ptr_fun(&amp;on_button_press) );

bool on_key_press_or_release_event(GdkEventKey* event)
{
  if (event-&gt;type == GDK_KEY_PRESS &amp;&amp;
    event-&gt;keyval == GDK_KEY_1 &amp;&amp;
    (event-&gt;state &amp; (GDK_SHIFT_MASK | GDK_CONTROL_MASK | GDK_MOD1_MASK)) == GDK_MOD1_MASK)
  {
    handle_alt_1_press(); // GDK_MOD1_MASK je normálně klávesa Alt
    return true;
  }
  return false;
}

Gtk::Entry m_entry; // v definici třídy

// v konstruktoru třídy
m_entry.signal_key_press_event().connect( sigc::ptr_fun(&amp;on_key_press_or_release_event) );
m_entry.signal_key_release_event().connect( sigc::ptr_fun(&amp;on_key_press_or_release_event) );
m_entry.add_events(Gdk::KEY_PRESS_MASK | Gdk::KEY_RELEASE_MASK);

button.signal_button_press_event().connect( sigc::ptr_fun(&amp;on_mywindow_button_press), false );

class Server
{
public:
  // pro přístup k signálu:
  typedef sigc::signal&lt;void, bool, int&gt; type_signal_something;
  type_signal_something signal_something();

protected:
  type_signal_something m_signal_something;
};

Server::type_signal_something Server::signal_something()
{
  return m_signal_something;
}

class TextMark : public Glib::Object
{
  _CLASS_GOBJECT(TextMark, GtkTextMark, GTK_TEXT_MARK, Glib::Object, GObject)

protected:
  _WRAP_CTOR(TextMark(const Glib::ustring&amp; name, bool left_gravity = true), gtk_text_mark_new)

public:
  _WRAP_CREATE(const Glib::ustring&amp; name, bool left_gravity = true)

example-widget.h:56: error: using typedef-name 'ExampleWidget' after 'struct'
../../libexample/libexamplemm/example-widget.h:34: error: 'ExampleWidget' has a previous declaration here
make[4]: *** [example-widget.lo] Error 1

example-widget.h:60: error: '_ExampleWidget ExampleWidget' redeclared as different kind of symbol
../../libexample/libexamplemm/example-widget.h:34: error: previous declaration of 'typedef struct _ExampleWidget ExampleWidget'

int width = 0;
if(pixbuf)
{
  width = pixbuf-&gt;get_width();
}

m_button1.signal_clicked().connect( sigc::bind&lt;Glib::ustring&gt;( sigc::mem_fun(*this, &amp;HelloWorld::on_button_clicked), "button 1") );

my_connection.disconnect();

server.signal_something().connect(
  sigc::mem_fun(client, &amp;Client::on_server_something) );

sigc::connection  Glib::SignalIdle::connect(const sigc::slot&lt;bool&gt;&amp; slot,
                                    int priority = Glib::PRIORITY_DEFAULT_IDLE);

sigc::connection Glib::SignalIO::connect(const sigc::slot&lt;bool,Glib::IOCondition&gt;&amp; slot,
                                 int fd, Glib::IOCondition condition,
                                 int priority = Glib::PRIORITY_DEFAULT);

sigc::connection Glib::SignalTimeout::connect(const sigc::slot&lt;bool&gt;&amp; slot,
                                      unsigned int interval, int priority = Glib::PRIORITY_DEFAULT);

sigc::signal&lt;void, bool, int&gt; signal_neco;

sigc::signal&lt;void,int&gt;::iterator signal&lt;void,int&gt;::connect( const sigc::slot&lt;void,int&gt;&amp; );

std::list&lt; Glib::RefPtr&lt;Gdk::Pixbuf&gt; &gt; listPixbufs;
Glib::RefPtr&lt;Gdk::Pixbuf&gt; refPixbuf = Gdk::Pixbuf::create_from_file(filename);
listPixbufs.push_back(refPixbuf);

typedef struct _ExampleWidget ExampleWidget;

struct _ExampleWidget
{
};

virtual void on_button_clicked(Glib::ustring data);

void ExampleWindow::on_printoperation_done(Gtk::PrintOperationResult result, const Glib::RefPtr&lt;PrintOperation&gt;&amp; op)
{
  if (result == Gtk::PRINT_OPERATION_RESULT_ERROR)
    // upozornění uživatele
  else if (result == Gtk::PRINT_OPERATION_RESULT_APPLY)
    // Aktualizace PrintSettings s tím, co bylo použito v této PrintOperation

  if (! op-&gt;is_finished())
    op-&gt;signal_status_changed().connect(sigc::bind(sigc::mem_fun(*this, &amp;ExampleWindow::on_printoperation_status_changed), op));
}

void ExampleWindow::on_printoperation_status_changed(const Glib::RefPtr&lt;PrintFormOperation&gt;&amp; op)
{
  if (op-&gt;is_finished())
    // tisková úloha je dokončená
  else
    // získat stav pomocí get_status() nebo get_status_string()

  // aktualizovat uživatelské rozhraní
}

void init()
{
  Gtk::Main::init_gtkmm_internals(); // Nastavuje systém typů g_* a tabulku Glib::wrap()
  wrap_init(); // Říká tabulce Glib::wrap() o třídě libnecomm.
}

void on_button_clicked();

class some_class
{
    void on_button_clicked();
};

some_class some_object;

main()
{
    Gtk::Button button;
    button.signal_clicked().connect( sigc::ptr_fun(&amp;on_button_clicked) );
    button.signal_clicked().connect( sigc::mem_fun(some_object, &amp;some_class::on_button_clicked) );
}

void on_insert(const TextBuffer::iterator&amp; pos, const Glib::ustring&amp; text, int bytes)

{
  Gtk::Button aButton;
  aButton.show();
  ...
  app-&gt;run();
}
„Skryté“ sloupce# keep this file sorted alphabetically, one language code per line
cs
ja#include &lt;gtkmm.h&gt;#m4 _CONVERSION(`GSList*',`std::vector&lt;Widget*&gt;',`Glib::SListHandler&lt;Widget*&gt;::slist_to_vector($3, Glib::OWNERSHIP_SHALLOW)')$ ./plug &amp;$ ./socket(Odbočení od tématu: <application>GTK+</application> nazývá toto schéma „signalink“ – „signalizace“. Pozorný čtenář se zkušenostmi s vývojářskou sadou GUI namítne, že ten stejný návrh můžete často vidět pod názvem „broadcaster-listener“ – „hromadné vysílání-naslouchání“ (např. ve frameworku PowerPlant v Mertokworks pro Macintowsh). Funguje to podobně: nastaví se vysílače <literal>broadcaster</literal> a pak se k nim připojí posluchači <literal>listeners</literal>. Vysílače udržují seznam objektů, které je poslouchají, a když někdo vysílači předá zprávu, ten zavolá všechny své objekty ze seznamu a zprávu jim předá. V <application>gtkmm</application> signální objekty hrají roli vysílačů a sloty hrají roli posluchačů. Více se o tom dozvíte dále.(Podle toho pak musíte mít ve složce <literal>po</literal> soubory <literal>cs.po</literal> a <literal>ja.po</literal>, které budou obsahovat český, respektive japonský překlad.)./docextract_to_xml.py -s ~/checkout/gnome/gtk+/gtk/ &gt; gtk_docs.xml
// vytvoří své vlastní přizpůsobení
Gtk::TextView textview;
// použije nově vytvořené přizpůsobení pro posuvník
Gtk::Scrollbar vscrollbar (textview.get_vadjustment(), Gtk::ORIENTATION_VERTICAL);// note to translators: don't translate the "[noun]" part - it is
// just here to distinguish the string from another "jumps" string
text = strip(gettext("jumps[noun]"), "[noun]");//compiler error - no conversion from ustring to int.
int number = row[m_Columns.m_col_text];2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010<application>Gtk::Builder</application> kontroluje widget na prázdný ukazatel a na očekávaný typ a případně o těchto problémech vypíše varování do příkazové řádky.<application>gtkmm</application> poskytuje normální sadu funkcí na spouštění vláken, mutexy, podmíněné proměnné a třídy na zamykání v rozsahu působnosti pro psaní vícevláknových programů pomocí C++.<application>gtkmm</application> 3 přidává některé nové třídy:<application>gtkmm</application> 3 má také několik menších změn v API, na které pravděpodobně narazíte při portování kódu, který používá <application>gtkmm</application> 2.4. Zde je jejich krátký seznam:Knihovna tvořící <application>gtkmm</application> 3.0 se nazývá <literal>libgtkmm-3.0</literal> místo <literal>libgtkmm-2.4</literal> a instaluje své hlavičkové soubory do obdobně verzované složky, takže se pkg-config může doptat na <literal>gtkmm-3.0</literal> i <literal>gtkmm-2.4</literal>.<application>gtkmm</application> dává programům kontrolu nad životností (tj. konstrukcí a destrukcí) kteréhokoliv widgetu stejným způsobme, jako nad kterýmkoliv jiným objektem C++. Díky této flexibilitě můžete použit <literal>new</literal> a <literal>delete</literal> k vytvoření a zničení objektu dynamicky, nebo můžete použít běžného člena třídy (který je zničen automaticky při zničení instance třídy), nebo použít lokální instanci (která zanikne při opuštění jejího rozsahu působnosti). Takovouto flexibilitu nenajdete v každé vývojářské sade GUI v C++, mnohé omezují programátory jen na nějakou podmnožinu funkcí správy paměti v C++.<application>gtkmm</application> umožňuje psát kód pomocí běžných technik C++, jako je zapouzdření, dědičnost a polymorfizmus. Jako programátor v C++ jste již nejspíše zjistili, že to vede k jasnějšímu a přehlednějšímu programovému kódu.<application>gtkmm</application> a Win32Aplikace s <application>gtkmm</application> mohou jednoduše podporovat více jazyků, včetně neevropských, jako je čínština nebo zprava doleva psaná arabština. Správně napsaná a přeložená aplikace s <application>gtkmm</application> použije za běhu správný jazyk podle toho, jaké národní prostředí má uživatel nastavené.Aplikace vytvoření pomocí <application>gtkmm</application> jsou tvořené okny obsahujícími widgety, jako jsou tlačítka nebo textová pole. V některých jiných systémech se widgety nazývají „ovládací prvky“. Ke každému widgetu v oknech aplikace existuje objekt C++ ve vašem aplikačním kódu. Pro dosažení vizuálních projevů widgetu vám stačí volat metody třídy widgetu.<application>gtkmm</application> uspořádává widgety hierarchicky pomocí <emphasis>kontejnerů</emphasis>. Kontejnerový widget obsahuje další widgety. Většina widgetů v <application>gtkmm</application> jsou kontejnerové widgety. Window, Notebook a Button jsou všechno příklady kontejnerových widgetů. Existují dvě varianty kontejnerů: jednopotomkové kontejnery, které jsou všechny odvozené z <classname>Gtk::Bin</classname> a vícepotomkové kontejnery, které jsou odvozené z <classname>Gtk::Container</classname>. Většina widgetů v <application>gtkmm</application> je odvozených z <classname>Gtk::Bin</classname>, včetně <classname>Gtk::Window</classname>.Třídy <application>gtkmm</application> jsou navržené přímo s ohledem na přepisování. Obsahují virtuální členské metody speciálně zamýšlené za účelem přepsání.<application>gtkmm</application> ve srovnání s Qt<application>gtkmm</application> aktuálně funguje s <ulink url="http://mingw.org/">MingW/GCC3.4 compiler</ulink> a Microsoft Visual C++ 2005 nebo novějším (včetně volně dostupné verze express) na platformě Windows. Zde je <ulink url="ftp://ftp.gnome.org/pub/GNOME/binaries/win32/gtkmm">instalátor</ulink> dostupný pro gtkmm na MS Windows. Instrukce, jak jej použít viz <ulink url="https://wiki.gnome.org/Projects/gtkmm/MSWindows/">https://wiki.gnome.org/Projects/gtkmm/MSWindows</ulink>.Vývojáři <application>gtkmm</application> mají tendenci protěžovat <application>gtkmm</application> před Qt, protože <application>gtkmm</application> dělá věci více přirozeně jazyku C++. Qt pochází z dob, kdy C++ a standardní knihovny nebyly plně standardizované, nebo dobře podporované kompilátory. Proto duplikuje plno věcí, které dnes již najdete ve standardních knihovnách, jak třeba kontejnery a typové informace. Nejdůležitější je, že Trolltech upravil jazyk C++, aby poskytovat signály, takže třídy Qt nejde jednoduše používat s jinými třídami než z Qt. <application>gtkmm</application> je schopné používat standardní C++ k poskytování signálů, bez změn v jazyce C++. Další rozdíly najdete popsané na stránce s <ulink url="https://wiki.gnome.org/Projects/gtkmm/FAQ">častými dotazy a odpověďmi</ulink>.<application>gtkmm</application> má řadu widgetů, které mohou vizuálně měnit nějakou hodnotu pomocí myši nebo kalávesnice, např. widgety <classname>Range</classname> (popsané v kapitole <link linkend="chapter-range-widgets">Widgety Range</link>). Existuje také několik widgetů, které zobrazují z velké oblasti jen nějakou zvolenou část, např. widget  <classname>Viewport</classname>. Tyto widgety mají objekty <classname>Gtk::Adjustment</classname>, které jsou vyjádřením této části jejich API.<application>gtkmm</application> vyžaduje méně kódu ve srovnání s GTK+, které používá názvy funkcí s prefixy a spoustu přetypovacích maker.<application>gtkmm</application> je obalení knihovny <ulink url="http://www.gtk.org/">GTK+</ulink> pro jazyk C++. Tato knihovna slouží k vytváření grafického uživatelského rozhraní. <application>gtkmm</application> je licencováno pod LGPL, takže s jeho pomocí můžete vyvíjet otevřený software, svobodný software nebo i komerční nesvobodný software aniž byste museli platit za licence.<application>gtkmm</application> jen obaluje GTK+<application>gtkmm</application> je také typově bezpečnější, takže kompilátor může odhalit chyby, které by při použití C šli odhalit jen za běhu. Používání konkrétnějších typů také zpřehledňuje celé API, protože můžete zjistit, které typy by měly být použity, jednoduše pohledem do deklarace metody.<application>gtkmm</application> není nativní vývojářská sada C++, ale obalení C++ okolo vývojářské sady C. Toto oddělení rozhraní a implementace má jisté výhody. Vývojáři <application>gtkmm</application> tráví většinu času rozpravami o tom, jak by <application>gtkmm</application> mělo podávat nejčistší API, bez obtížných kompromisů kvůli obskurním technickým detailům. Trochu přispíváme i do podkladového kódu GTK+, přestože kvůli tomu musíme programovat v C, v Perlu, V Pythonu atd. GTK+ tak těží z širší základny uživatelů, než vývojářské sady pro jediný konkrétní jazyk – má více implementátorů, více vývojářů, více testerů a více uživatelů.<application>gtkmm</application> velmi usnadňuje odvozování nových widgetů děděním ze stávajících tříd widgetů, buď odvozením z kontejneru a přidáním potomků, nebo odvozením z jednopoložkového widgetu a změnou jeho chování. Občas ale můžete narazit na to, že vhodný výchozí bod neexistuje. V takovém případě můžete implementovat widget od nuly.<application>gtkmm</application> poskytuje jednoduchý způsob, jak spravovat nedávno použité dokumenty. Třídy, které se starají o implementaci této funkcionality, jsou <classname>RecentManager</classname>, <classname>RecentChooserDialog</classname>, <classname>RecentChooserMenu</classname>, <classname>RecentChooserWidget</classname>, <classname>RecentAction</classname> a <classname>RecentFilter</classname>.<application>gtkmm</application> poskytuje čtyři základní typy tlačítek:<application>gtkmm</application> poskytuje funkci <function>manage()</function> a metody <methodname>add()</methodname> pro vytvoření a zničení widgetu. Každý widget vyjma okna nejvyšší úrovně musí být přidán nebo zabalen do kontejneru v pořadí, v jakém se má zobrazit. Funkce <function>manage()</function> widgety označuje, takže když je widget přidán do kontejneru, stane se kontejner zodpovědný za jeho smazání.Obsluhy signálů <application>gtkmm</application> jsou silně typové, kdežto kód <application>GTK+</application> v C umožní napojit zpětné volání s nesprávným počtem a typem argumentů, což vede k selhání segmentace za běhu. A na rozdíl od <application>Qt</application>, <application>gtkmm</application> toho dosáhne beze změn v jazyce C++.<application>gtkmm</application> využívá nástroj <command>gmmproc</command> k vygenerování většiny svých zdrojových kódů pomocí souborů .defs, které definují API knihoven založených na <classname>GObject</classname>. Je tak velmi snadné vytvořit další obalující kód ve stylu gtkmm pro další knihovny založené na glib/GObject.<application>gtkmm</application> používá k implementaci signálů knihovnu libsigc++. Zde je příklad jednořádkového kódu, který napojí signál „clicked“ tlačítka Gtk::Button na obsluhu signálu nazvanou „on_button_clicked“: <placeholder-1/><application>gtkmm</application> používá k řešení tohoto problému systém balení. Místo aby se určila přesná pozice a velikost jednotlivých widgetů v okně, můžete uspořádat své widgety do řádků, sloupců a/nebo mřížek. <application>gtkmm</application> umí automaticky určit velikost okna na základě velikostí widgetů, které obsahuje. A velikost widgetů je naopak dána množstvím textu, který obsahují, nebo minimální a maximální velikostí, které určíte a/nebo jak jste požádali, že se má sdílet dostupné místo navzájem mezi widgety. Doladit své rozložení pak můžete pomocí hodnot odsazení a centrování jednotlivých widgetů. <application>gtkmm</application> použije všechny tyto informace ke změně velikosti a pozice elegantně s ohledem na to, jak uživatel manipuluje s oknem.<application>gtkmm</application> se původně jmenovalo gtk--, protoge + už GTK+ ve svém názvu má. Protože ale s -- je problém ve vyhledávačích, býval balíček většinou pojmenován <application>gtkmm</application>, a u toho nakonec zůstalo.Třídy widgetů v <application>gtkmm</application> mají metody zpřístupňující signály, jako je <methodname>Gtk::Button::signal_clicked()</methodname>, která vám umožňují napojit si svoji obsluhu signálu. Díky pružnosti <application>libsigc++</application>, která je používaná <application>gtkmm</application> jako knihovna pro zpětná volání, může být obsluhou signálu většinou libovolný druh funkce, ale nejspíše budete chtít použít metodu třídy. Mezi programátory <methodname>GTK+</methodname> v C jsou tyto obsluhy signálů často nazývané „zpětná volání“.<application>gtkmm</application> je, obdobně jako jiné vývojářské sady GUI, <emphasis>řízené událostmi</emphasis>. Když se vyskytne událost, jako je zmáčknutí tlačítka myši, je widgetem, který byl zmáčknut, <emphasis>vyslán</emphasis> příslušný signál. Různé widgety mají různé sady signálů, které mohou vyslat. Aby se kliknutí tlačítkem projevilo nějakou činností, je třeba nastavit <emphasis>obsluhu signálu</emphasis> (signal handler), která signál „clicked“ od tlačítka zachytí.<application>gtkmm</application>-3.0 je nová verze API <application>gtkmm</application>, která se instaluje souběžně se starším API <application>gtkmm</application>-2.4. Poslední verzí API <application>gtkmm</application>-2.4 byla <application>gtkmm</application> 2.24. <application>gtkmm</application> 3 nemá žádné hlavní podstatné rozdíly vůči <application>gtkmm</application> 2, ale událo se v ní několik menších změn, které nejsou možné s dodržením binární kompatibility. Pokud jste doposud nikdy nepoužívali API <application>gtkmm</application>-2.4, můžete jej v této kapitole v klidu ignorovat.Skript <application>intltool</application>/<application>xgettext</application> vytáhne řetězce a vloží je do souboru <filename>mujbalicek.pot</filename>. Překladatelé vaší aplikace vytvoří překlady tak, že nejprve zkopírují tento soubor <filename>.pot</filename> do souboru <filename>kod_narodniho_prostredi.po</filename>. Kód národního prostředí udává jazyk a kódování pro tento jazyk, včetně formátu data a čísel. Když později dojde ke změnám ve zdrojovém kódu, skript <literal>msmerge</literal> použije znovu vygenerovaný soubor <filename>.pot</filename> k aktualizaci souboru <filename>kod_narodniho_prostredi.po</filename>.Kontejnery <classname>ButtonBox</classname> pomáhají, aby aplikace vypadaly jednotně, protože používají standardní nastavení, jako je interní rozestup tlačítek a jejich balení.Třída <classname>Gdk::Drawable</classname> byla odstraněn a jeho metody přesunuty do <classname>Gdk::Window</classname>.<classname>Gdk::Pixmap</classname> a <classname>Gdk::Bitmap</classname> byly odstraněny ve prospěch <classname>Gdk::Pixbuf</classname>.<classname>Gdk::RGBA</classname> nahrazuje <classname>Color</classname>, přičemž přidává komponentu alfa pro průhlednost. <classname>Colormap</classname> byla odstraněna, spolu s jejím nevhodným alokováním barev.<classname>Glib::ListHandle&lt;Gtk::Widget*&gt;</classname>: Použijte <classname>std::vector&lt;Gtk::Widget*&gt;</classname>, <classname>std::list&lt;Gtk::Widget*&gt;</classname>, atd.<classname>Glib::RefPtr</classname> je chytrý ukazatel. Konkrétně je to ukazatel s počítáním odkazů. Možná znáte <classname>std::auto_ptr&lt;&gt;</classname>, <classname>std::unique_ptr&lt;&gt;</classname> a <classname>std::shared_ptr&lt;&gt;</classname>, což jsou také chytré ukazatele. <classname>Glib::RefPtr&lt;&gt;</classname> je podobný <classname>std::shared_ptr&lt;&gt;</classname>, který také počítá odkazy. <classname>Glib::RefPtr&lt;&gt;</classname> byl zaveden dlouho před tím, než se objevil chytrý ukazatel s počítáním odkazů ve standardní knihovně C++.<classname>Glib::SListHandle&lt;Gtk::Widget*&gt;</classname>: Použijte <classname>std::vector&lt;Gtk::Widget*&gt;</classname>, <classname>std::list&lt;Gtk::Widget*&gt;</classname>, atd.<classname>Glib::StringArrayHandle</classname> nebo <classname>Glib::ArrayHandle&lt;Glib::ustring&gt;</classname>: Použijte <classname>std::vector&lt;Glib::ustring&gt;</classname>, <classname>std::list&lt;Glib::ustring&gt;</classname>, <type>const char*[]</type>, atd.<classname>Gtk::Adjustment</classname>, <classname>IconSet</classname> a <classname>Gdk::Cursor</classname> se teď používají přes <classname>Glib::RefPtr</classname>.<classname>Gtk::AppChooser</classname>, <classname>Gtk::AppChooserButton</classname> a <classname>Gtk::AppChooserDialog</classname> umožňují uživateli vybrat nainstalovanou aplikaci pro otevření konkrétního typu obsahu.<classname>Gtk::Box</classname> uspořádává své synovské widgety svisle nebo vodorovně. K vložení synovského widgetu použijte metody<methodname>pack_start()</methodname> a <methodname>pack_end()</methodname>.<classname>Gtk::Box</classname>, <classname>Gtk::ButtonBox</classname>, <classname>Gtk::IconView</classname>, <classname>Gtk::Paned</classname>, <classname>Gtk::ProgressBar</classname>, <classname>Gtk::ScaleButton</classname>, <classname>Gtk::Scrollbar</classname> a <classname>Gtk::Separator</classname> jsou nyní odovozené z <classname>Gtk::Orientable</classname>, což umožňuje jejich otočení (svislé nebo vodorovné) určit bez požadavku na použití odvozené třídy, jako je <classname>Gtk::HBox</classname>.<classname>Gtk::Builder</classname> se musí používat přes <classname>Glib::RefPtr</classname>. Podobně jako u všech takovýchto tříd, musíte pro vytvoření instance použít metodu <methodname>create()</methodname>. Například <placeholder-1/> Tím se vytvoří instance oken definovaných v souboru .glade, které se ale hned nezobrazí, pokud to výslovně neřeknete nastavením v okně <guilabel>Vlastnosti</guilabel> a aplikaci <application>Glade</application>.<classname>Gtk::Button</classname> je také kontejner, takže do něj můžete vložit jiný widget, jako třeba <classname>Gtk::Image</classname>.<classname>Gtk::CellLayout</classname> používaná třídami <classname>Gtk::IconView</classname>, <classname>Gtk::TreeView::Column</classname> a <classname>Gtk::ComboBox</classname> má nyní <classname>Gtk::CellArea</classname>, kterou lze použít k přesnějšímu určení, jak jsou objekty <classname>CellRenderer</classname> uspořádané a zarovnané.<classname>Gtk::CheckButton</classname> je zděděné z <classname>Gtk::ToggleButton</classname>. Jediný skutečný rozdíl mezi nim je ve vzhledu <classname>Gtk::CheckButton</classname>. Zaškrtávací políčko můžete kontrolovat, nastavovat a přepínat těmi stejnými členskými metodami, jako <classname>Gtk::ToggleButton</classname>.<classname>Gtk::Grid</classname> uspořádává synovské widgety do řádků a sloupců. K vložení synovského widgetu použijte metody <methodname>attach()</methodname>, <methodname>attach_next_to()</methodname> a <methodname>add()</methodname>.<classname>Gtk::Grid</classname> je nový kontejnerový widget, který může případně nahradit <classname>Gtk::Box</classname> a <classname>Gtk::Table</classname>. Své potomky uspořádává přednostně podle jejich vlastností, místo nějakého svého daného rozvržení.<classname>Gtk::IconView</classname>, <classname>Gtk::TextView</classname>, <classname>Gtk::TreeView</classname> a další widgety odvozují ze Scrollable, místo aby si definovali své vlastní metody, jako je <methodname>get_vadjustment()</methodname>, a místo aby měli svůj vlastní signál set_scroll_adjustments.Widgety <classname>Gtk::Scale</classname> a <classname>Gtk::Scrollbar</classname> jsou odvozené z <classname>Gtk::Range</classname> a sdílí s ním mnoho funkcionality. Obsahují „vodicí dráhu“ a „táhlo“ (v některých grafických prostředích nazývané „posuvné kolečko“). Tažením táhla pomocí ukazatele myši provádí posuv v mezích vodicí dráhy, klikání na vodicí dráhu posouvá táhlo přímo na místo kliku nebo o určenou vzdálenost, v závislosti na použitém tlačítku myši. Tohle by mělo být běžně známé chování posuvníku.Widgety <classname>Gtk::Scale</classname> (nebo „táhla“) umožňují uživateli vizuálně vybrat a měnit hodnotu v rámci určeného rozsahu. Můžete je použít například ke změně úrovně přiblížení náhledu obrázku, nebo k ovládání jasu barvy, nebo k určení počtu minut nečinnosti před zapnutím šetřiče obrazovky.<classname>Gtk::Style</classname> a <classname>Gtk::Rc</classname> byla odstraněny a nahrazují je třída <classname>Gtk::StyleContext</classname> a třídy <classname>Gtk::StyleProvider</classname>, jako je <classname>Gtk::CssProvider</classname>.<classname>Gtk::Switch</classname> zobrazuje stavy zapnuto/vypnuto jasnějším způsobem, než <classname>Gtk::CheckBox</classname>. Může se například hodit, když umožňujete uživateli aktivovat hardware.<classname>Gtk::Table</classname> umožňuje umístit widgety do mřížky, podobně jako <classname>Gtk::Grid</classname>.Widget <classname>Gtk::Table</classname> je od <application>gtkmm</application> verze 3.4 zavržený a neměl by být používán v nově psaném kódu. Místo něj použijte <classname>Gtk::Grid</classname>.Objekty <classname>Gtk::TargetEntry</classname> obsahují tyto informace: <placeholder-1/><classname>Gtk::TextBuffer</classname> je model obsahující data pro <classname>Gtk::TextView</classname>, podobně jako je <classname>Gtk::TreeModel</classname> používán <classname>Gtk::TreeView</classname>. To umožňuje dvěma a více <classname>Gtk::TextView</classname> sdílet stejný <classname>TextBuffer</classname> a při tom to umožňuje zobrazit textový obsah vyrovnávací paměti trochu odlišně. Nebo byste mohli spravovat několik objektů <classname>Gtk::TextBuffer</classname> a v různou dobu volit vždy jeden z nich pro zobrazení ve widgetu <classname>Gtk::TextView</classname>.<classname>Gtk::TextView</classname> má různé metody <methodname>scroll_to_*()</methodname>. Ty dokážou zajistit, aby byla viditelná konkrétní část textové vyrovnávací paměti. Například funkce hledání ve vaší aplikaci může použít <methodname>Gtk::TextView::scroll_to_iter()</methodname> k zobrazení nalezeného textu.<classname>Gtk::ToggleButton</classname> je užitečné především jako základní třída pro třídy <classname>Gtk::CheckButton</classname> a <classname>Gtk::RadioButton</classname>.Položky <classname>Gtk::ToolItem</classname> se dají přidávat do skupin. Například takto:<classname>Gtk::TreeModel</classname> poskytuje přes metodu <methodname>children()</methodname> kontejner ve stylu standardní knihovny C++ s jeho potomky. Pro iteraci můžete použít dobře známé metody <methodname>begin()</methodname> a <methodname>end()</methodname>, nějak takto:Model <classname>Gtk::TreeStore</classname> může mít dceřiné položky. Přidávají se pomocí metody <methodname>append()</methodname>, <methodname>prepend()</methodname> nebo <methodname>insert()</methodname> takto:Pokud <classname>Gtk::TreeView</classname> použijete s modelem <classname>Gtk::ListStore</classname> nebo <classname>Gtk::TreeStore</classname>, bude již sám o sobě umět jednoduché „táhni a upusť“. Jestliže je to nezbytné, umožňuje také implementaci složitějšího chování při přetahování položek pomocí API <link linkend="chapter-draganddrop">Táhni a upusť</link>.<classname>Gtk::Widget</classname> má několik metod a signálů s předponou „drag_“. Používají se k technice „táhni a upusť“.Nabídky <classname>Menu</classname> jsou normálně jen přidané do okna, ale mohou být také jen dočasně zobrazené na základě kliknutí myší. Například kontextová nabídka se může zobrazit, když uživatel klikne druhým tlačítkem myši.<classname>MessageDialog</classname> je užitečná třída používaná k vytváření jednoduchých a standardních dialogových oken se zprávou, ikonou a tlačítky, pomocí kterých může uživatel reagovat. V konstruktoru můžete určit typ zprávy a text a k tomu, pomocí výčtu <literal>Gtk::ButtonsType</literal>, standardní tlačítka.<classname>RadioButtons</classname> jsou po vytvoření „vypnuté“, takže když z nich poprvé vytvoříte skupinu, nebude žádný z nich vybraný. Proto před jejich použitím nezapomeňte jeden znich pomocí <methodname>set_active()</methodname> zapnout:Widgety <classname>Range</classname> typicky napojují obsluhu na tento signál, který mění jejich vzhled s ohledem na změny – například velikost táhla v posuvníku roste, nebo se zmenšuje, v opačném poměru k rozdílu mezi hodnotami <parameter>lower</parameter> a <parameter>upper</parameter> jeho objektu <classname>Adjustment</classname>.<classname>RecentChooser</classname> je rozhraní, které může být implementováno widgety zobrazujícími seznam nedávných souborů. <application>gtkmm</application> poskytuje čtyři vestavěné implementace pro výběr nedávných souborů: <classname>RecentChooserWidget</classname>, <classname>RecentChooserDialog</classname>, <classname>RecentChooserMenu</classname> a <classname>RecentAction</classname>.Třídy <classname>RecentChooserMenu</classname> a <classname>RecentAction</classname> umožňují vypsat nedávno použité soubory v podobě nabídky.<classname>RecentChooserWidget</classname> je jednoduchý widget pro zobrazení seznamu nedávno použitých souborů. <classname>RecentChooserWidget</classname> je základním stavebním kamenem pro <classname>RecentChooserDialog</classname>, ale pokud chcete, můžete jej vestavět do svého uživatelského rozhraní.<classname>RecentManager</classname> funguje jako databáze nedávno použitých souborů. Tuto třídu můžete použít k registraci nových souborů, odstranění souborů ze seznamu a vyhledání nedávno použitých souborů. Každý uživatel má svůj vlastní seznam nedávno použitých souborů.<classname>RecentManager</classname> je model v návrhovém vzoru model-zobrazení. Pro zobrazení slouží třída, která implementuje rozhraní <classname>RecentChooser</classname>.Widgety <classname>Scale</classname> umí zobrazit vedle stupnice aktuální číselnou hodnotu. Výchozí je zobrazení hodnoty, ale můžete to změnit pomocí metody <methodname>set_draw_value()</methodname>.Widgety <classname>ScrolledWindow</classname> vytvoří oblast s posuvníky. Do okna <classname>ScrolledWindow</classname> můžete vložit widget libovolného typu, který bude díky posuvníků dostupný celý bez ohledu na svoji velikost. Pamatujte ale, že <classname>ScrolledWindow</classname> není <classname>Gtk::Window</classname>, i když název k tomu navádí.<classname>SpinButton</classname> používá objekt <link linkend="chapter-adjustment">Adjustment</link> k uchování informací o rozsahu hodnot. Atributy tohoto objektu jsou konkrétně použity takto: <placeholder-1/>Iterátory třídy <classname>TextBuffer</classname> jsou obecně zneplatněny, když dojde ke změně textu, ale v těchto situacích můžete použít <classname>Gtk::TextBuffer::Mark</classname> k zapamatování pozice. Například:<classname>TextView</classname> má různé metody, které umožňují měnit prezentovanou podobu vyrovnávací paměti pro konkrétní zobrazení. Některé jde přepsat pomocí objektů <classname>Gtk::TextTag</classname> ve vyrovnávací paměti, pokud určují ty stejné věci. Například pomocí <methodname>set_left_margin()</methodname>, <methodname>set_right_margin()</methodname>, <methodname>set_indent()</methodname> atd.<classname>ToggleButton</classname> se podobá na normální <classname>Button</classname>, ale když je zmáčknuto, tak zůstane zmáčknuté, dokud na něj znovu nekliknete.<classname>ToolItemGroup</classname> byste měli do palety nástrojů přidávat přes metodu základní třídy <function>Gtk::Container::add()</function>, například takto:<classname>Widget</classname> může být rozpoznán jako zdroj nebo cíl pomocí těchto metod <classname>Gtk::Widget</classname>:<command>gmmproc</command> umožňuje zpracování parametrů v hlavičkách metod různým způsobem pro makra, které zpracovávají hlavičky metod (jako jsou <function>_WRAP_METHOD()</function>, <function>_WRAP_CTOR()</function> and <function>_WRAP_CREATE()</function>):<command>gmmproc</command> vás bude na standardním výstupu varovat o funkcích a signálech, které jste zapomněli obalit, a pomůže vám tím zajistit obalení celého API. Pokud ale některé funkce nebo signály obalit nechcete, nebo když zvolíte ruční napsaní některých metod, můžete použít makro <function>_IGNORE()</function> nebo <function>_IGNORE_SIGNAL()</function>, abyste zastavili stížnosti <command>gmmproc</command>.<filename>libneco</filename>: Obsahuje hlavní soubor pro vložení a soubor <filename>.pc</filename> pro pkg-config.<filename>libnecomm</filename>: Obsahuje vygenerované a ručně napsané soubory .h a .cc.<filename>libnecomm</filename>: Složka nejvyšší úrovně.<filename>private</filename>:Obsahuje vygenerované soubory <filename>*_p.h</filename>.<filename>src</filename>: Obsahuje zdrojové soubory.hg a .ccg.<function>_WRAP_METHOD()</function> podporuje také nastavení výstupních parametrů v C++ z výstupních parametrů v C, pokud obalená funkce v C nějaké má. Předpokládejme například, že chceme obalit následující funkci v C, která vrací hodnotu v jejím výstupním parametru <parameter>rect</parameter>: <placeholder-1/> Aby <command>gmmproc</command> umístil hodnotu vracenou ve výstupním parametru <parameter>rect</parameter> v C++, můžete použít nějak takto direktivu <function>_WRAP_METHOD()</function>: <placeholder-2/> <literal>{&gt;&gt;}</literal> následující za názvem parametru <parameter>rect</parameter> říká, že výstupní parametr v C++ by se měl nastavit z hodnoty vracené v parametru v C z funkce v C. <command>gmmproc</command> vygeneruje deklaraci dočasné proměnné, ve které se uchová hodnota výstupního parametru v C a výraz, který nastaví výstupní parametr v C++ z dočasné proměnné. V tomto případě může být nutné mít nějaké makro <function>_INITIALIZATION()</function> popisující, jak nastavit <classname>Gdk::Rectangle&amp;</classname> z <classname>GdkRectangle*</classname>. Může vypadat třeba takto: <placeholder-3/><function>_WRAP_METHOD()</function>, <function>_WRAP_SIGNAL()</function> a <function>_WRAP_PROPERTY()</function>Funkce <function>sigc::bind()</function> se nepoužívá úplně běžné, ale občas se vám hodit může. Pokud se dobře vyznáte v programování <application>GTK+</application>, pak jste si nejspíše všimli, se je to podobné, jako doplňující argument <literal>gpointer data</literal>, který mají všechna zpětná volání v GTK+. Obecně je v <application>GTK+</application> nadužívaný k předávání informací, které by měly být uložené v členských datech v odvozených widgetech, ale v C je odvozování widgetů velmi složité. V <application>gtkmm</application> máme mnohem menší potřebu takovýchto obezliček.<function>sigc::ptr_fun()</function> generuje <classname>sigc::slot</classname>. Slot je objekt, který vypadá a působí jako funkce. Někdy se můžete setkat i s označením funkční objekt nebo functor. <function>sigc::ptr_fun()</function> generuje slot pro samostatnou funkci nebo statickou metodu. <function>sigc::mem_fun()</function> generuje slot pro členskou metodu konkrétní instance.Když je tato inicializace použita skriptem <command>gmmproc</command>, je <literal>$3</literal> nahrazeno názvem výstupního parametru metody v C++ a <literal>$4</literal> návratovým parametrem funkce v C. Někdy se může hodit i <literal>$1</literal>, které je nahrazeno typem C++ bez amprsandu (&amp;) a <literal>$2</literal>, které je nahrazeno typem C.Když je tento převod použit skriptem <command>gmmproc</command>, je <literal>$3</literal> nahrazeno názvem parametru.<literal>Gtk::PACK_EXPAND_PADDING</literal>: Dodatečné místo je zaplněno odsazením. Widgety budou rozložené rovnoměrně, ale jejich velikost se nezmění – místo toho mezi nimi bude prázdné místo.<literal>Gtk::PACK_EXPAND_WIDGET</literal>: Dodatečné místo je získáno zvětšením velikost synovského widgetu, aniž by se měnilo množství místa mezi widgety.<literal>Gtk::PACK_SHRINK</literal>: Místo je zmenšeno na velikost synovského widgetu. Widget zabere místa tak akorát pro svoji potřebu a nikdy se nezvětší.Soubor <literal>LINGUAS</literal> obsahuje abecedně seřazený seznam kódů identifikujících jazyky, do kterých je aplikace přeložená (řádky začínající # jsou komentáře a jsou ignorovány). Jednotlivé kódy jazyků uvedené v <literal>LINGUAS</literal> musí odpovídat názvům souborů <literal>.po</literal>. Když má například aplikace překlad do češtiny a japonštiny, měl by váš soubor <literal>LINGUAS</literal> vypadat nějak takto:Soubor <literal>POTFILES.in</literal> je seznam cest ke všem souborům, které obsahují řetězce označené k překladu, počínaje kořenovou složkou projektu. Takže když například má váš projekt zdrojové kódy umístěné v podsložce s názvem <literal>src</literal> a v ní jsou dva soubory obsahující řetězce, které chcete přeložit, může váš soubor <literal>POTFILES.in</literal> vypadat nějak takto:<literal>actions</literal> říká, které akce „Táhni a upusť“ může tento cíl přijímat – viz popis výše. 	<literal>begin_print</literal>: Tento signál musíte obsluhovat, protože to je místo, kde vytvoříte a nastavíte <classname>Pango::Layout</classname> používaný k poskytnutí <classname>Gtk::PrintContext</classname> a rozdělíte tiskový výstup na stránky.<literal>done</literal>: Signál je vyslán, když je tisk dokončen, míněno, když jsou tisková data zařazena do tiskové fronty. Pamatujte, že poskytnutý objekt <literal>Gtk::PrintOperationResult</literal> může oznamovat chybu, která se při tisku objevila. V takovém případě nejspíše budete chtít na výsledek upozornit uživatele.<literal>drag_begin</literal>: Poskytuje DragContext.<literal>drag_data_delete</literal>: Poskytuje zdroji příležitost smazat původní data, pokud je to vhodné.<literal>drag_data_get</literal>: Poskytuje <literal>info</literal> o přetahovaném formátu dat a strukturu <literal>Gtk::SelectionData</literal>, do které byste měli vložit požadovaná data.<literal>drag_data_received</literal>: Poskytuje <literal>info</literal> o přetahovaném formátu dat a strukturu <literal>Gtk::SelectionData</literal>, která obsahuje upuštěná data. Měli byste zavolat metodu <methodname>drag_finish()</methodname> z <literal>DragContext</literal>, abyste dali najevo, že operace proběhla úspěšně.<literal>drag_drop</literal>: Poskytuje <classname>DragContext</classname> a souřadnice.. Můžete zavolat metodu <methodname>drag_get_data()</methodname>, která spustí signál <literal>drag_data_get</literal> ve zdrojovém widgetu a signál <literal>drag_data_received</literal> v cílovém widgetu.<literal>drag_end</literal>: Poskytuje DragContext.<literal>drag_motion</literal>: Poskytuje <classname>DragContext</classname> a souřadnice. Můžete zavolat metodu <methodname>drag_status()</methodname> třídy <classname>DragContext</classname>, abyste zjistili, které akce budou přijaty.<literal>draw_page</literal>: Musíte obsluhovat tento signál, který poskytuje <classname>PrintContext</classname> a číslo stránky. <classname>PrintContext</classname> by se měl použít k vytvoření <classname>Cairo::Context</classname> a do něj pak nakreslit požadovanou stránku. Když chcete vykreslit text, použijte iteraci nad <classname>Pango::Layout</classname>, který jste vytvořili v obsluze signálu <literal>begin_print</literal>.<literal>end_print</literal>: Obsluha tohoto signálu je bezpečné místo k uvolnění libovolných prostředků, které se vztahují k objektu <classname>PrintOperation</classname>. Pokud máte vlastní třídu zděděnou z <classname>PrintOperation</classname>, je přirozeně jednodušší to udělat v destruktoru.<literal>flags</literal> jsou hodnoty kombinované pomocí bitového NEBO, které říkají, jak má widget vizuálně reagovat na přetahované položky.<literal>lower</literal>: spodní hranice rozsahu hodnot<literal>page_increment</literal>: hodnota, o kterou se provede zvýšení/snížení při zmáčknutí druhého tlačítka myši na příslušném tlačítku<literal>page_size</literal>: nepoužito<literal>paginate</literal>: Zalomení na stránky může být časově náročná operace, takže jestli ji potřebujete sledovat, můžete zavolat <methodname>PrintOperation::set_show_progress()</methodname> a obsluhovat tento signál.<literal>request_page_setup</literal>: Poskytuje <classname>PrintContext</classname>, číslo stránky a <classname>Gtk::PageSetup</classname>. Obsluhujte tento signál, když potřebujete měnit nastavení stránek jednotlivě.<literal>start_button_mask</literal> jsou hodnoty kombinované bitovým NEBO, které určují, jaké modifikační klávesy nebo tlačítka myši musí být zmáčknuty, aby se začalo přetahovat.<literal>status_changed</literal>: Vyšle se, kdykoliv se změní stav tiskové úlohy. Pro sledování stavu úlohy po zařazení do tiskové fronty použijte metodu <methodname>PrintOperation::set_track_print_status()</methodname>. Když chcete zjistit stav, použijte <methodname>get_status()</methodname> nebo <methodname>get_status_string()</methodname>.<literal>step_increment</literal>: hodnota, o kterou se provede zvýšení/snížení při zmáčknutí prvního tlačítka myši na příslušném tlačítku<literal>targets</literal> je vektor prvků <classname>Gtk::TargetEntry</classname>.<literal>upper</literal>: horní hranice rozsahu hodnot<literal>value</literal>: hodnota do číselníku<methodname>Gtk::Widget::show()</methodname> dává <application>gtkmm</application> najevo, že máme dokončené nastavení vlastností widgetu a widget je připravený k zobrazení. Když jej chcete znovu skrýt, můžete použít <methodname>Gtk::Widget::hide()</methodname>. Pořadí, ve které widgety zobrazíte, není důležité, ale doporučujeme, abyste hlavní okno zobrazili až jako poslední. Tak se celé okno objeví s již vykresleným obsahem. V opačném případě by uživatel nejdříve spatřil prázdné okno, ve kterém by se mu postupně zjevily widgety.<methodname>child_type_vfunc()</methodname>: Vrátí, jaký typ potomka lze přidat.<methodname>forall_vfunc()</methodname>: Zavolá to stejné zpětné volání pro jednotlivé potomky.<methodname>get_preferred_height_for_width_vfunc()</methodname>: Vypočítá minimální a přirozenou výšku kontejneru, když by byla dána konkrétní šířka.<methodname>get_preferred_height_for_width_vfunc()</methodname>: Vypočítá minimální a přirozenou výšku widgetu pro situaci, že by byla určena konkrétní šířka.<methodname>get_preferred_height_vfunc()</methodname>: Vypočítá minimální a přirozenou výšku kontejneru.<methodname>get_preferred_height_vfunc()</methodname>: Vypočítá minimální a přirozenou výšku widgetu.<methodname>get_preferred_width_for_height_vfunc()</methodname>: Vypočítá minimální a přirozenou šířku kontejneru, když by byla dána konkrétní výška.<methodname>get_preferred_width_for_height_vfunc()</methodname>: Vypočítá minimální a přirozenou šířku widgetu pro situaci, že by byla určena konkrétní výška.<methodname>get_preferred_width_vfunc()</methodname>: Vypočítá minimální a přirozenou šířku kontejneru.<methodname>get_preferred_width_vfunc()</methodname>: Vypočítá minimální a přirozenou šířku widgetu.<methodname>get_request_mode_vfunc()</methodname>: (volitelné) Vrátí, který režim <literal>Gtk::SizeRequestMode</literal> je widgetem upřednostňován.<methodname>get_request_mode_vfunc()</methodname>: Vrací, kterému <literal>Gtk::SizeRequestMode</literal> kontejner dává přednost.<methodname>get_widget()</methodname> vrací synovské widgety, které jsou spravované přes <methodname>managed()</methodname> (viz kapitola <link linkend="chapter-memory">Správa paměti</link>), a tím pádem budou smazané, když je smazán jejich rodičovský kontejner. Takže když dostanete jen synovské widgety z <application>Gtk::Builder</application>, místo z celého okna, pak je buď musíte vložit do kontejneru nebo je smazat. Třídy <classname>Windows</classname> (jako je <classname>Dialogs</classname>) nemohou být spravované, protože nemají rodičovský kontejner, a proto je musíte v některém okamžiku smazat sami.<methodname>on_add()</methodname>: Přidá widget jako potomka do kontejneru.<methodname>on_draw()</methodname>: Kreslí na poskytnutý <classname>Cairo::Context</classname>.<methodname>on_map()</methodname>: (volitelné)<methodname>on_realize()</methodname>: Přidruží widget k oknu <classname>Gdk::Window</classname>.<methodname>on_remove()</methodname>: Odstraní synovský widget z kontejneru.<methodname>on_size_allocate()</methodname> obdrží skutečnou výšku a šířku, kterou se rodičovský kontejner rozhodl widgetu dát. Což může být více než minimum, i více než nahlášená přirozená velikost, například v případě roztaženého hlavního okna. Můžete si zvolit, že budete místo navíc ignorovat a necháte oblast prázdnou, nebo můžete zvolit roztažení synovského widgetu, aby místo zaplnil, nebo můžete zvolit roztažení odsazení mezi widgety. Je to váš kontejner, vaše rozhodnutí. Nezapomeňte zavolat <methodname>set_allocation()</methodname> uvnitř implementace <methodname>on_size_allocate()</methodname>, aby se skutečně použilo naalokované místo, které bylo rodičovským kontejnerem nabídnuto.<methodname>on_size_allocate()</methodname>: Umístí synovské widgety s ohledem na výšku a šířku, kterou kontejner skutečně uvedl.<methodname>on_size_allocate()</methodname>: Umístí widget s ohledem na výšku a šířku, které byly skutečně zadány.<methodname>on_unmap()</methodname>: (volitelné)<methodname>on_unrealize()</methodname>: (volitelné) Zruší přidružení k oknu <classname>Gdk::Window</classname>.<methodname>run()</methodname> může vracet <literal>PRINT_OPERATION_RESULT_IN_PROGRESS</literal>. Abyste mohli sledovat stav a reagovat na výsledky nebo chyby, potřebujete implementovat obsluhu signálu pro signály <literal>done</literal> a <literal>status_changed</literal>:<placeholder-1/> (nebo <placeholder-2/> pro názvy souborů)<placeholder-1/> Nyní, když jsou objekty typu <classname>MyContainer</classname> zničené, je smazáné i tlačítko. Není již potřeba mazat <varname>pButton</varname>, aby se uvolnila jeho paměť. Jeho smazání bylo předáno za úkol kontejneru <classname>MyContainer</classname>.balíček s příkladem <placeholder-1/><type>GdkEventButton</type> je struktura, která obsahuje parametry události, jako jsou souřadnice ukazatele myši ve chvíli, kdy bylo tlačítko zmáčknuto. Existuje několik různých typů struktury <type>GdkEvent</type> pro různé události.<ulink url="http://developer.gnome.org/gtkmm/unstable/classGtk_1_1Button.html"><classname>Gtk::Button</classname></ulink>. Standardní tlačítko, obvykle doplnění popiskem nebo obrázkem. Zmáčknutí spustí akci. Viz kapitola <link linkend="sec-pushbuttons">Button</link>.<ulink url="http://developer.gnome.org/gtkmm/unstable/classGtk_1_1CheckButton.html"><classname>Gtk::CheckButton</classname></ulink>. Funguje podobně jako přepínací tlačítko, ale svůj stav zobrazuje v podobě malého čtverečku s popiskem vedle sebe. Mělo by se používat ve většině situací, které požadují nastavení zapnuto/vypnuto. Viz kapitola <link linkend="sec-checkboxes">CheckButton</link>.<ulink url="http://developer.gnome.org/gtkmm/unstable/classGtk_1_1RadioButton.html"><classname>Gtk::RadioButton</classname></ulink>. Anglický název „rádiové tlačítko“ vznikl podle tlačítek na starých autorádiích, kde tlačítka voliče spojená do skupiny a když jste některé zmáčkli, jiné zmáčknuté vyskočilo, takže vždy mohl být zmáčknuté jen jedno. Stejně tak u skupinového přepínače, když zvolení jednoho tlačítka způsobí vypnutí ostatních. Jsou podobná zaškrtávacím políčkům (malý widget s popiskem vedle sebe), ale mají jinou vizuální podobu. Viz kapitola <link linkend="sec-radio-buttons">RadioButton</link>.<ulink url="http://developer.gnome.org/gtkmm/unstable/classGtk_1_1ToggleButton.html"><classname>Gtk::ToggleButton</classname></ulink>. Na rozdíl od normálního tlačítka, které se automaticky vrátí do normálního stavu, přepínací tlačítko zůstane zmáčknuté, dokud jej znovu nezmáčknete. Tím pádem se dá použít jak přepínač stavů zapnuto/vypnuto. Viz kapitola <link linkend="sec-toggle-buttons">ToggleButton</link>.<varname>app_exec</varname>: Příkazový řádek, který bude použitý ke spuštění tohoto prostředku. Tento řetězec může obsahovat ošetřené znaky „f“ a „u“, které se nahradí souborovou cestou prostředku, respektive jeho adresou URI.<varname>app_name</varname>: Název aplikace, která registruje prostředky.<varname>description</varname>: Krátký popis prostředku v podobě řetězce kódovaného v UTF-8.<varname>display_name</varname>: Název prostředku v podobě řetězce kódovaného v UTF-8, který se použije k zobrazení.<varname>groups</varname>: Seznam skupin přidružených k položce. Skupiny jsou v podstatě libovolné řetězce přidružené ke konkrétnímu prostředku. Můžete o nich uvažovat, jako o kategoriích (třeba „e-mail“, „grafika“, atd.) nebo o štítcích pro prostředek.<varname>is_private</varname>:Jestli má být tento prostředek viditelný jen aplikacím, které mají registraci, či nikoliv.<varname>mime_type</varname>: Typ MIME prostředku.Soubor <filename>.hg</filename> má typicky vložené některé hlavičkové soubory a následně deklaruje. Pomocí některých maker se do této třídy přidá API nebo chování. Například <filename>button.hg</filename> z <application>gtkmm</application> vypadá zhruba takto: <placeholder-1/><classname>ComboBox</classname> může obsahovat widget <classname>Entry</classname> pro zadávání libovolného textu. Stačí zadat <literal>true</literal> do parametru <literal>has_entry</literal> v konstruktoru.Widget <classname>Entry</classname> může nabízet rozbalovací seznam s přednastavenými volbami, které vychází z prvních několika znaků, které uživatel napsal. Například vyhledávací pole by mohlo nabízet text, který se hledal již dříve.<classname>Glib::Dispatchet</classname> se používá k zasílání upozornění z pracovního vlákna do vlákna starajícího se o grafické uživatelské rozhraní. Třída <classname>ExampleWorker</classname> obsahuje data, ke kterým je přistupováno z obou vláken. Tato data jsou chráněna pomocí <classname>Glib::Threads::Mutex</classname>. Pouze vlákno starající se o GUI může měnit GUI.Objekt <classname>Glib::Dispatcher</classname> může být vyslán vláknem příjemce i pracovním vláknem, i když by se tak mělo dít v rozumných mezích. V unixových systémech objekty <classname>Glib::Dispatcher</classname> sdílí jednu společnou rouru, která by se teoreticky mohla přeplnit na velmi vytíženém systému ve kterém poběží program používající velké množství objektů <classname>Dispatcher</classname>. Roura by se musela zaplnit před tím, než by hlavní smyčka ve vlákně příjemce měla příležitost z ní číst, a tak ji vyprázdnit, a vlákno příjemce by zkoušelo vysílat, a tím pádem do ní zapisovat. Když by byla v takovém stavu, pak by vlákno příjemce by blokovalo zápis a skončilo by to na mrtvém bodě. V případě, že vlákno příjemce vysílá, lze místo toho samozřejmě použít normální objekt <classname>sigc::signal&lt;void&gt;</classname>.Kontejner <classname>Grid</classname> widgety dynamicky uspořádává do řádků a sloupců. Rozměry mřížky není zapotřebí zadávat v konstruktoru.<classname>Notebook</classname> má sadu navrstvených <literal>karet</literal>, z nichž každá může obsahovat widgety. <literal>Ouška</literal> s popisky umožňují uživateli vybrat požadovanou kartu. Díky objektům <classname>Notebook</classname> můžete umístit několik sad widgetů na malý prostor a v jednu chvíli zobrazit vždy jednu kartu. Často se používají například v dialogových oknech s předvolbami.<classname>Plug</classname> je speciální druh okna, které lze vložit do objektu <classname>Socket</classname>. Mimo běžných vlastností a metod třídy <classname>Gtk::Window</classname> poskytuje <classname>Plug</classname> konstruktor, který přebírá ID objektu <classname>Socket</classname>, čímž se automaticky vloží objekt <classname>Plug</classname> do objektu <classname>Socket</classname> s příslušným ID.Výchozí podoba widgetu <classname>ProgressBar</classname> je vodorovně a zleva doprava, ale můžete to změnit na svislou zavoláním metody <methodname>set_orientation()</methodname>.Objekt <classname>RecentInfo</classname> je v podstatě objekt obsahující všechna metadata o jednom nedávno použitém souboru. Můžete jej využít k vyhledání vlastností uvedených <link linkend="list-file-metadata">v předchozím</link>.Třída <classname>Socket</classname> je speciální druh kontejnerového widgetu, který poskytuje možnost vložit widget z jednoho procesu do jiného procesu způsobem, který je pro uživatele transparentní.<classname>SpinButton</classname> umožňuje uživateli vybrat hodnotu z nějakého rozsahu číselných hodnot. Jedná se o widget <classname>Entry</classname> po stranně s tlačítky pro zvyšování a snižování. Klikání na tlačítka způsobuje zvýšení nebo snížení hodnoty v číselníku v rámci povoleného rozsahu hodnot. Widget <classname>Entry</classname> můžete použít také k přímému zadání hodnoty.Widget <classname>ToolPalette</classname> je podobný widgetu <classname>Toolbar</classname>, ale na rozdíl od něj může obsahovat mřížku položek roztříděných do skupin. Uživatel může jednotlivé skupiny skrývat nebo rozbalovat. Obdobně jako v nástrojové liště, mohou být položky zobrazené jako ikony, texty nebo ikony s textem.Objekt <classname>sigc::signal</classname> by měl být považován za vlastněný vláknem, které jej vytvořilo. Pouze toto vlákno by mělo napojit objekt <classname>sigc::slot</classname> na objekt signálu a pouze toto vlákno by mělo vyslat signál pomocí <methodname>emit()</methodname>, nebo na signál zavolat <methodname>operator()()</methodname>, nebo napojený objekt <classname>sigc::slot</classname> anulovat. Z toho vyplývá (mimo jiné), že objekt signálu poskytovaný widgetem <application>gtkmm</application> by měl operovat jen v hlavním vlákně starajícím se o grafické uživatelské rozhraní a objekt odvozený z <classname>sigc::trackable</classname> mající nestatické metody, na které se odkazuje slot napojený na objekt signálu, by měl být zlikvidován v tomto vlákně.Objekt <classname>sigc::slot</classname> vytvořený zavoláním <function>sigc::mem_fun()</function>, který odkazuje na metodu třídy odvozené z <classname>sigc::trackable</classname> by neměl být kopírován do jiného vlákna, ani zničen jiným vláknem, než tím, které ho vytvořilo. (Jedním důsledkem toho je, že <methodname>Gllib::Thread::create()</methodname> by nemělo být voláno s argumentem se slotem, který byl vytvořený zavoláním <function>sigc::mem_fun()</function>, která představuje metodu takového třídy. Je však bezpečné předat objekt funkce <methodname>Glib::Threads:Thread::create()</methodname> představující takovou metodu třeba pomocí <function>boost::bind()</function> nebo v C++11 pomocí <function>std::bind()</function> nebo lambda výrazem z C++11.)Synovský widget je možné přidat do <classname>EventBox</classname> pomocí:Následuje menší příklad. Pokud jej chcete použít, spusťte jej z terminálu – nevytváří žádné okno. Co ale vytvoří, je pojmenovaná roura <literal>testfifo</literal> v aktuální složce. Pak spusťte další shell a v něm <literal>echo "Hello" &gt; testinfo</literal>. Příklad bude vypisovat jednotlivé řádky, které takto zadáte, až dokud nespustíte <literal>echo "Q" &gt; testfifo</literal>.Šikovnou funkcí knihovny Glib (jedna z knihoven ležících pod <application>gtkmm</application>) je schopnost mít kontrolu nad daty z popisovače souborů pro vaše potřeby. To se hodí hlavně pro síťové aplikace. Následující metoda přesně tohle využívá:Správně internacializovaná aplikace nebude mít žádné předpoklady ohledně počtu bajtů na znak. To znamená, že byste neměli používat ukazatelovou aritmetiku k procházení řetězců po znacích a neměli byste používat <classname>std::string</classname> nebo standardní funkce C, jako je <function>strlen()</function>, protože ty takové předpoklady mají.Pravidlo, ze kterého mohou existovat výjimky: V případě, že virtuální funkce v C vrací ukazatel na objekt odvozený z <classname>GObject</classname>, tj. objekt s počítáním referencí, pak virtuální funkce v C++ vrátí objekt <classname>Glib::RefPtr&lt;&gt;</classname>. Je vyžadován jeden z doplňující argumentů <parameter>refreturn</parameter> nebo <parameter>refreturn_ctype</parameter>.Chytré ukazatele fungují hodně podobně jako normální ukazatele.Zde je pár příkladů.Cíle mohou být v různých binárních formátech. Tato kapitola a příklady operují s 8bitovým textem. To by umožnilo používat pro data ve schránce formát XML. Není to ale nejspíše úplně vhodné pro binární data, jako jsou obrázky. <classname>Gtk::Clipboard</classname> poskytuje přetěžování, které vám v případě potřeby umožňuje určit formát mnohem podrobněji.AM_CPPFLAGSAM_CPPFLAGS = ... -DNAZEVAPLIKACE_LOCALEDIR=\"${NAZEVAPLIKACE_LOCALEDIR}\"AM_CXXFLAGSATKDialogové okno s informacemi o aplikaci (AboutDialog)Přístup k widgetůmAkceRežim aktivityPřidejte <literal>INTLTOOL_FILES</literal> do seznamu souborů <literal>EXTRA_DIST</literal>. Tím se zajistí, že když provedete <command>make dist</command>, budou tyto příkazy zahrnuty do zdrojového balíčku.Přidejte <literal>po</literal> do proměnné <literal>SUBDIRS</literal>. Bez toho se překladu nebudou sestavovat a instalovat spolu s aplikací.Přidá výchozí konstruktor.Přidá metody pro obalení částí API C.Řádky do modelu přidejte pomocí metod <methodname>append()</methodname>, <methodname>prepend()</methodname> nebo <methodname>insert()</methodname>.Přidání položek do seznamu nedávných souborůPřidávání řádkůPřidání sloupců do zobrazeníPřidávání synovský řádkůProvést opravu přidání vlastností a zajištěním, že budou spolu navzájem správně komunikovat, je v knihovně v jazyce C relativně obtížné, ale není to nemožné. Takže vyplňte chybové hlášení a zkuste příslušnému správci poslat záplatu.Přidání widgetůDoplňkové přepínače z příkazové řádky předané skriptu <filename>generate_wrap_init.pl</filename>, jako je jmenný prostor C++ a prefix v podobě rodičovské složky pro vkládané soubory.Navíc se dá použít třetí tlačítko myši ke skokům přímo na hodnoty <literal>upper</literal> nebo <literal>lower</literal>.Objekty Adjustment zevnitřPřizpůsobení (Adjustment)Po té, co je objekt <classname>Socket</classname> nebo <classname>Plug</classname> realizován, můžete získat jeho ID pomocí jeho metody <methodname>get_id()</methodname>. Toto ID pak může být sdíleno s jiným procesy, aby věděly, jak se navzájem připojit.Po přidání řádků do tohoto modelu byste jej měli pomocí metody <methodname>set_model()</methodname> předat do objektu <classname>ComboBox</classname>. Pak použijte metodu <methodname>pack_start()</methodname> nebo <methodname>pack_end()</methodname> k určení, které sloupce se budou v rozbalovacím seznamu zobrazovat. Stejně jako u <classname>TreeView</classname>, můžete buď nastavit výchozí vykreslování buněk předáním <classname>TreeModelColumn</classname> do balicí metody, nebo můžete vytvořit instanci konkrétní třídy <classname>CellRenderer</classname> a určit konkrétní mapování buď pomocí <methodname>add_attribute()</methodname> nebo <methodname>set_cell_data_func()</methodname>. Tyto metody pochází ze základní třídy <classname>CellLayout</classname>.Po sestavení a spuštění tohoto programu zkuste změnit velikost okna, abyste viděli, jak se bude chovat. Zkuste si také pohrát s volbami <methodname>pack_start()</methodname> podle oddílu <link linkend="sec-boxes">Boxy</link>.Po nakreslení obrysu projdeme po ciferníku a nakreslíme značky pro každou hodinu, s výraznějšími značkami pro 3, 6, 9 a 12 hodin. Nyní máme vše připravené k implementaci funkcionality udržování času na hodinách, což představuje získání aktuální hodnoty pro hodiny, minuty a sekundy a vykreslení ručiček v příslušném úhlu.Po zadání zdrojového kódu do <literal>simple.cc</literal> můžete zkompilovat výše uvedený program pomocí <application>gcc</application>: <placeholder-1/> Pamatujte, že musíte volání <literal>pkg-config</literal> uzavřít do zpětných uvozovek. Ty způsobí, že shell provede příkaz v nich uzavřený a výstup tohoto příkazu použije jako součást příkazového řádku. Také pamatujte, že <literal>simple.cc</literal> musí být před zavoláním <literal>pkg-config</literal> v příkazovém řádku.Po vybrání položky <guimenuitem>Recent Files Dialog</guimenuitem> v nabídce byste měli vidět něco podobného následujícímu oknu.Po nastavení správné sady modulů potřebujete říci systému <application>jhbuild</application>, který modul nebo sadu modulů sestavit. Abyste sestavili <application>gtkmm</application> a všechny jeho závislosti, nastavte <varname>modules</varname> takto: <placeholder-1/>Po jeho spuštění byste měli v terminálu vidět následující výstup:Po té byste měli uvidět něco takovéhoto:Po té, co jste vytvořili a nastavili filtr, který vyfiltruje jen ty položky, které chcete, můžete jej použít s widgetem pro výběr pomocí funkce <methodname>RecentChooser::add_filter()</methodname>.Po dokončení tvorby cesty pořád nemáte nakreslené nic viditelného. Aby se cesta zviditelnila, musíte použít funkci <methodname>stroke()</methodname>, která obtáhne cestu čarou s tloušťkou a stylem definovanými v objektu <classname>Cairo::Context</classname>. Po obtažení se aktuální cesta smaže a můžete začít s novou cestou.Po té, co nainstalujete všechny závislosti, si stáhněte zdrojové kódy <application>gtkmm</application>, rozbalte je a přepněte se do nově vytvořené složky. <application>gtkmm</application> můžete sestavit a nainstalovat následující posloupností přikazů:Po té, co jste nainstalovali verzi <application>gtkmm</application> z repozitáře git, jste připraveni začít ji používat a experimentovat s ní. Abyste mohli používat novou verzi <application>gtkmm</application>, kterou jste právě nainstalovali, potřebujete nastavit některé proměnné prostředí, aby váš skript <filename>configure</filename> věděl, kde najít nové knihovny. Naštěstí <application>jhbuild</application> nabízí jednoduché řešení tohoto problému. Spuštěním příkazu <command>jhbuild shell</command> se spustí nový shell se správně nastavenými všemi proměnnými prostředí. Když nyní, stejně jak jste zvyklí, znovu nakonfigurujete a sestavíte svůj projekt, měl by být slinkován vůči nově nainstalovaným knihovnám. Pro návrat do předchozího prostředí stačí prostě opustit shell, který <application>jhbuild</application> spustil.AhlstedtZarovnání (Alignment)Všechny programy používající <application>gtkmm</application> musí mít vložené určité hlavičkové soubory <application>gtkmm</application>. <literal>gtkmm.h</literal> vloží celou sadu <application>gtkmm</application>. To obvykle není dobrý nápad, protože to vloží megabajty hlaviček, ale pro tento jednoduchý program nás to nemusí trápit.Všechny kontejnerové widgety jsou odvozené z <classname>Gtk::Container</classname>, i když ne vždy přímo. Některé kontejnerové widgety, jako třeba <classname>Gtk::Grid</classname>, mohou přechovávat více synovských widgetů, takže mají obvykle složitější rozhraní. Jiné, jako <classname>Gtk::Frame</classname>, obsahují jen jeden synovský widget.Všechna zavržená API byla v <application>gtkmm</application> 3.0 odstraněna, ale v budoucnu se samozřejmě mohou objevit nově zavržená.Všechny výskyty <varname>skeleton</varname> by měly být nahrazeny správným názvem knihovny C, kterou obalujete, např. za „neco“ a „libneco“. Stejně tak všechny výskyty <varname>SKELETON</varname> by měly být nahrazeny za „NECO“ a „LIBNECO“ a všechny výskyty <varname>Skeleton</varname> za „Neco“.Také může, pomocí metody <methodname>set_value_pos()</methodname>, nastavit místo pro vykreslování hodnoty, relativně k vodicí dráze.Případně, když by seznam možných vstupů byl příliš dlouhý, nebo je nevhodné jej přímo vygenerovat, můžete místo toho použít zpětné volání, které zadáte pomocí <methodname>set_match_func()</methodname>. Hodí se to také, když potřebujete porovnávat jinou část řetězce, než začátek.Jinou možností je nechat na kontejnerovém widgetu rozhodování, kdy se má widget zničit. Ve většině případů chcete, aby widget existoval tak dlouho, jako kontejner, ve kterém je. Když chcete přenést správu životnosti widgetu na jeho kontejner, nejprve jej vytvořte pomocí <function>Gtk::manage()</function> a zabalte jej do jeho kontejneru pomocí <methodname>Gtk::Container::add()</methodname>, <methodname>Gtk::Box::pack_start()</methodname> nebo podobné metody. Takto bude widget zničen, kdykoliv bude zničen jeho kontejner.Ačkoliv <application>glib</application> je sama o sobě z hlediska vláken bezpečná, některé obalující funkce z <application>glibmm</application>, které používají <application>libsigc++</application>, bezpečné nebudou. Takže například jen vlákno, ve kterém běží hlavní smyčka by mělo volat <methodname>Glib::SignalIdle::connect()</methodname>, <methodname>Glib::SignalIO::connect()</methodname>, <methodname>Glib::SignalTimeout::connect()</methodname>, <methodname>Glib::SignalTimeout::connect_seconds</methodname> pro hlavní smyčku, nebo manipulovat s objektem <classname>sigc::connection</classname>, který vrací.Ačkoliv instance widgetů <application>gtkmm</application> mají životnost a rozsah působnosti stejné, jako jiné třídy C++, má <application>gtkmm</application> volitelnou vlastnost, která šetří čas a uvidíte ji v některých příkladech. <function>Gtk::manage()</function> vám umožňuje říci, že synovský widget je vlastněný kontejnerem, ve kterém je umístěný. Díky tomu můžete pomocí <function>new</function> vytvořit widget, přidat jej do kontejneru a už se nestarat o jeho smazání. Více se o technikách správy paměti v <application>gtkmm</application> se můžete dozvědět v kapitole <link linkend="chapter-memory">Správa paměti</link>.Ačkoliv Cairo umí vykreslit text, neznamená to, že by mohlo nahradit Pango. Pango je lepší volbou, když potřebujete provádět pokročilejší vykreslování textu, jako je zalamování nebo vypouštění textu. Kreslení textu pomocí Cairo by se mělo dělat je v případě, že je text součástí grafiky.Ačkoliv signál <literal>custom_widget_apply</literal> poskytuje widget, který jste před tím vytvořili, pro zjednodušení věcí si můžete widget, který očekáváte, že obsahuje uživatelův vstup, pamatovat jako člena třídy. Například řekněme, že máme <classname>Gtk::Entry</classname> nazvanou <literal>m_Entry</literal> jako člena vaší třídy <classname>CustomPrintOperation</classname>: <placeholder-1/>Ačkoliv název <classname>EventBox</classname> zdůrazňuje metodu obsluhy událostí, dá se widget používat také k ořezávání (a dalším věcem; viz příklad dále).Ačkoliv jsme si ukázali na jednoduchém příkladu příkaz pro kompilaci, měli byste ve skutečnosti používat nástroje automake a autoconf, jak je to popsáno v „Autoconf, Automake, Libtool“ od G. V. Vaughana a kol. Příklady uváděné v této knize jsou zahrnuté v balíčku <application>gtkmm-documentation</application> včetně příslušných souborů pro sestavení, takže příkazy pro sestavení již nadále nebudeme uvádět. Stačí vám jen najít příslušnou složku s příkladem a napsat <literal>make</literal>.Ačkoliv můžete rozvržení a vzhled okna a widgetů určit přímo v kódu C++, asi shledáte pohodlnějším navrhovat uživatelská rozhraní pomocí aplikace <literal>Glade</literal> a pak je načítat za běhu pomocí <literal>Gtk::Builder</literal>. Viz kapitola <link linkend="chapter-builder">Glade a Gtk::Builder</link>.I když si teoreticky můžete implementovat svůj vlastní Model, normálně budete používat buď třídu <classname>ListStore</classname> nebo <classname>TreeStore</classname>.Ačkoliv můžete k vytváření a uspořádání widgetů používat kód v C++, rychle se to zvrhne v úmornou a opakující se činnost. A kvůli shlédnutí každé změny musíte znovu kompilovat. Aplikace <application>Glade</application> umožňuje rozvrhnout widgety na obrazovce a uložit jejich uspořádání popsané pomocí XML. Vaše aplikace pak může použít API <application>Gtk::Builder</application> k načtení souboru XML za běhu a k získání ukazatele na konkrétně nazvanou instanci widgetu.Ačkoliv váš kontejner může mít svoji vlastní metodu pro nastavení synovských widgetů, měli byste i tak poskytnou implementaci pro virtuální metody <methodname>on_add()</methodname> a <methodname>on_remove()</methodname> ze základní třídy tak, aby obě metody dělali něco vhodného, když jsou zavolány.Ačkoliv ve většině případů programátoři dávají přednost tomu, aby kontejnery automaticky ničily své potomky pomocí <function>Gtk::manage()</function> (viz dále), není po programátorech použití <function>Gtk::manage()</function> vyžadováno. Dají se použít i tradiční operátory <literal>new</literal> a <literal>delete</literal>. <placeholder-1/> Zde programátor smazal <varname>pButton</varname>, aby zabránil úniku paměti.Widget <classname>Assistant</classname> rozděluje složité operace do několika jednodušších kroků. Každý krok je na zvláštní stránce, která obsahuje záhlaví, synovský widget a oblast s akcemi. Oblast akcí obsahuje navigační tlačítka, která se aktualizují automaticky podle typu stránky nastaveného pomocí <methodname>set_page_type()</methodname>.Widget <classname>Entry</classname> umí zobrazovat ukazatel průběhu uvnitř textové oblasti, pod zadávaným textem. Ukazatel průběhu se zobrazí, když je zavolána metoda <methodname>set_progress_fraction()</methodname> nebo <methodname>set_progress_pulse_step()</methodname>.Widget <classname>Entry</classname> umí na začátku a konci textové oblasti zobrazovat ikonu. Ikona se dá určit metodami jako jsou <methodname>set_icon_from_pixbuf()</methodname> nebo <methodname>set_icon_from_icon_name()</methodname>. Aplikace může reagovat na uživatelovo zmáčknutí ikony obsluhou signálu <methodname>signal_icon_press</methodname>.<classname>InfoBar</classname> může zobrazovat menší počet informací nebo stručné dotazy. Na rozdíl od dialogového okna <classname>Dialog</classname> neotevírá nové okno, ale objeví se v horní části aktuálního okna. Jeho API je velmi podobné API <link linkend="chapter-dialogs">Gtk::Dialog</link>.Vylepšené „Hello World“AnastasovA tady je výňatek z práce s <application>gdb</application>. <placeholder-1/> Výjimka je zachycena v <application>glibmm</application> a program končí pomocí volání <function>g_error()</function>. Jiné výjimky mohou vést k jinému chování, ale v každém případě je výjimka z obsluhy signálu zachycena v <application>glibmm</application> nebo v <application>gtkmm</application> a <application>gdb</application> nemůže vidět, kde byla vyhozena.Další věcí, která stojí v tomto příkladu za zmínku, je, že voláme <methodname>connect()</methodname> dvakrát pro ten samý objekt signálu. To je úplně v pořádku – když je na tlačítko kliknuto, jsou zavolány obě obsluhy signálu.Jiným způsobme, jak zlikvidovat připojení, je vaše obsluha signálu. Musí být typu <classname>sigc::slot&lt;bool&gt;</classname>. Jak vidíte z definice, vaše obsluha signálu musí vracet hodnotu typu <literal>bool</literal>. Definice ukázkové metody může vypadat nějak takto: <placeholder-1/>Jiný řešením je přidat funkci <function>*_construct()</function>, kterou konstruktor C++ může zavolat po vytvoření instance jeho vlastního typu. Například <placeholder-1/>Objekt <classname>sigc::connection</classname> by měl být považován za vlastněný vláknem, ve kterém byl metoda vracející objekt <classname>sigc::connection</classname> zavolána. Jen toto vlákno by mělo volat metody <classname>sigc::connection</classname> na objektu.Případné další negenerované zdrojové soubory <filename>.h</filename> a <filename>.cc</filename> mohou být umístěné v <filename>skeleton/skeletonmm/</filename> a vypsané v <filename>skeleton/skeletonmm/filelist.am</filename>, typicky v proměnných <varname>files_extra_h</varname> a <varname>files_extra_cc</varname>.Životnost aplikacePoužití formátovacích značekJako první krok při portování zdrojového kódu do <application>gtkmm</application>-3.0 byste asi měli zajistit, abys se vaše aplikace sestavila se zakázaným zavrženým API <application>gtkmm</application>-2.4 pomocí definice makra GTKMM_DISABLE_DEPRECATED. Existují některá makra v autotools, která vám to mohou usnadnit tím, že je volitelně definujete v době sestavení. Více podrobností viz <ulink url="https://wiki.gnome.org/Projects/gtkmm/PortingToGtkmm3">wikistránka o portování na gtkmm 3</ulink>.Stejně jako před tím, se většina zajímavých věcí děje v obsluze kreslicího signálu <methodname>on_draw()</methodname>. Než se ponoříme do této obsluhy signálu, všimněte si, že konstruktor widgetu <classname>Clock</classname> napojuje obsluhu funkce <methodname>on_timeout()</methodname> na časovač s periodou 1000 milisekund (1 sekunda). To znamená, že <methodname>on_timeout()</methodname> bude voláno jednou za sekundu. Jedinou povinností této funkce je zneplatnit obsah okna, takže <application>gtkmm</application> je nuceno jej znovu překreslit.Jak bylo zmíněno výše, každý <classname>TextView</classname> má <classname>TextBuffer</classname> a jeden nebo více <classname>TextView</classname> může sdílet stejný <classname>TextBuffer</classname>.Jak již byl zmíněno, <classname>Gtk::Adjustment</classname> může vysílat signály. To je samozřejmě ta finta, jak se automaticky dějí aktualizace, když sdílíte objekt <classname>Adjustment</classname> mezi widgetem <classname>Scrollbar</classname> a jiným přizpůsobitelným widgetem. Všechny přizpůsobitelné widgety mohou napojit obsluhy signálů na svůj signál <literal>value_changed</literal>, stejně jako to může váš program.Stejně, jako jsme přejmenovali složky, měli bychom přejmenovat i některé zdrojové soubory. Například: <placeholder-1/> U řady souborů v kostře se také bude muset později vyplnit obsah podle projektu.Jak bylo vysvětleno v kapitole <link linkend="chapter-adjustment">Přizpůsobení (Adjustment)</link>, všechny widgety odvozené z <classname>Range</classname> jsou spřažené s objektem <classname>Adjustment</classname>. Pro změnu hodnot <literal>lower</literal>, <literal>upper</literal> a <literal>current</literal> použitých widgetem musíte použít metody jeho objektu <classname>Adjustment</classname>, který můžete získat pomocí metody <methodname>get_adjustment()</methodname>. Výchozí konstruktor widgetu <classname>Range</classname> vytváří <classname>Adjustment</classname> automaticky, nebo můžete určit některý existující, třeba když jej chcete sdílet s jinými widgety. Další podrobnosti viz kapitola <link linkend="chapter-adjustment">Přizpůsobení (Adjustment)</link>.Stejně, jako u widgetů <classname>Scrollbar</classname>, může být orientace buď vodorovná nebo svislá. Výchozí konstruktor vytvoří objekt <classname>Adjustment</classname> se všemi jeho hodnotami nastavenými na <literal>0.0</literal>. To není použitelné, takže potřebujete nastavit u objektu <classname>Adjustment</classname> některé údaje, abyste získali smysluplné chování.Mimo skutečnosti, že napojené sloty vždy běží ve vlákně příjemce, objekty <classname>Glib::Dispatcher</classname> jsou podobné objektům <classname>sigc::signal&lt;void&gt;</classname>. Nemohou tedy předávat nenavázané argumenty ani návratovou hodnotu. Nejlepším způsobem předání nenavázaných argumentů je pomocí z hlediska vláken bezpečné (asynchronní) fronty. V době psaní <classname>glibmm</classname> žádnou neměl, ale většina lidí píšících vícevláknový kód bude mít nějakou k dispozici (je to relativně snadné na napsání, i když v kombinaci bezpečnosti vláken se silnou bezpečností výjimek vznikají jisté delikatesy).AspectFramePrůvodce (Assistant)Počítejte s dostatečnou šířkou pro zobrazení řetězcůAsynchronní operacePřed instalací jsou soubory <filename>.po</filename> převedeny do binárního formátu (s příponou <filename>.mo</filename>) a při instalaci se nakopírují do systémové složky pro lokalizační soubory, například <filename>/usr/share/locale/</filename>.Z hlediska vývoje aplikací, poskytuje tiskové API v <application>gtkmm</application> dialogová okna, která jsou jednotná napříč aplikacemi a umožňují používat běžné kreslicí API Cairo, spolu s vykreslováním textu pomocí knihovny Pango. V implementaci tohoto společného API se používají výkonné části specifické pro platformu a ovladače specifické pro tiskárnu.Minimálně by funkce <function>_new()</function> neměla používat žádné privátní API (funkce, které jsou jen v souboru .c). Dokonce i v případě, že neexistují žádné funkce, můžeme napsat dva až tři řádky kódu s implementací funkce <function>_new()</function>, pokud tyto řádky kódu používají API, které je pro nás dostupné.V tuto chvíli máme oddělené nástroje pro generování různých částí těchto souborů <filename>.defs</filename>, takže je rozdělíme do samostatných souborů. Například ve složce <filename>gtk/src</filename> se zdrojovými kódy <application>gtkmm</application> můžete najít tyto soubory: <placeholder-1/>Editovatelné buňky s automatickým ukládáním.Rovnocenné základní typyZákladní typyZákladyProtože uživatel může zadat libovolný text, aktivní model řádku není dostačující, abychom zjistili, jaký text uživatel zadal. Proto byste měli za tímto účelem získat widget <classname>Entry</classname> pomocí metody <methodname>ComboBox::get_entry()</methodname> a zavolat <methodname>get_text()</methodname>.Protože automatický převod není vždy zcela správný, můžete chtít pro některé metody poskytnout ručně psaný text. Můžete to udělat zkopírováním uzlu XML pro tuto funkci ze souboru <filename>neco_docs.xml</filename> do <filename>neco_docs_override.xml</filename> a změnou jeho obsahu.Než se pokusíte nainstalovat <application>gtkmm</application> 3.0, budete možná muset nejprve nainstalovat tyto další balíčky.Níže je krátký příklad, který ilustruje tyto funkce. Pro lepší ukázku stylů popisku vyžívá widget Frame. (Widget Frame je vysvětlen v kapitole <link linkend="sec-frame">Rám (Frame)</link>.) Podle nastavení systému je možné, že první znak v <literal>m_Label_Normal</literal> se zobrazí podtržený, jen když zmáčknete klávesu <keycap>Alt</keycap>.BernhardMimo ukazování dosaženého pokroku, který nastal, se dá ukazatel průběhu použít také k prezentaci toho, že probíhá nějaká činnost. Dělá se to přepnutím ukazatele průběhu do <emphasis>režimu aktivity</emphasis>. V tomto režimu ukazatel průběhu zobrazuje malý obdélník, který pobíhá tam a zpět. Hodí se to v situacích, když nelze vypočítat rozsah hodnot, ve kterém bude operace probíhat (např. příjem souboru neznámé délky).Navázání dodatečných argumentůBjarne Stroustrup, „The C++ Programming Language“ čtvrté vydání – kapitola 34.3Balení boxů 1Balení boxů 2BoxySestavování <application>gtkmm</application> na Win32Ale na rozdíl od většiny chytrých ukazatelů nemůžete použít operátor * pro přístup k podkladové instanci.Ale na rozdíl od normálních ukazatelů, <classname>RefPtr</classname> jsou automaticky inicializované na null, takže nemusíte myslet na to, abyste to dělali sami.Tlačítko (Button)Boxy na tlačítka jsou pohodlným způsobem, jak rychle uspořádat skupinu tlačítek. Mohou být vodorovně vedle sebe nebo svisle pod sebou.Boxy na tlačítka podporují několik stylů rozvržení. Styl lze získat a změnit pomocí <methodname>get_layout()</methodname> a <methodname>set_layout()</methodname>.ButtonBoxKontejnery ButtonBoxTlačítkaTlačítka se do <classname>ButtonBox</classname> přidávají pomocí metody <methodname>add()</methodname>.Podle zvyklostí mají objekty ve stylu glib/GTK+ funkce <function>*_new()</function>, jako třeba <function>example_widget_new()</function>, které nedělají nic víc, než že zavolají <function>g_object_new()</function> a vrátí jeho výsledek. Vstupní parametry se předají do <function>g_object_new()</function> spolu s názvy vlastností, pro které tyto hodnoty jsou. Například <placeholder-1/>Podle konvencí se struktury deklarují v hlavičkových souborech ve stylu glib/GTK+ takto: <placeholder-1/>Standardně se <application>gtkmm</application> nainstaluje do složky <filename>/usr/local</filename>. Na některých systémech můžete potřebovat provést instalaci do jiného místa. Například v systému RHEL můžete použít volbu <literal>--prefix</literal> konfiguračního skriptu takto: <screen>
# ./configure --prefix=/usr
</screen>Standardně je <application>jhbuild</application> nakonfigurován pro instalaci veškerého softwaru, který sestaví, do <filename>/opt/gnome</filename>. Můžete zvolit i jinou cestu, ale doporučuje se, aby směřovala jinam, než je ostatní nainstalovaný software (nenastavujte ji do <filename>/usr</filename>!). Jestli jste se drželi instrukcí pro <application>jhbuild</application>, pak tato cesta patří vám, jako uživateli, a není tak potřeba spouštět <application>jhbuild</application> jako uživatel <literal>root</literal>.Standardně se <methodname>PrintOperation::run()</methodname> vrací po té, co je tisková operace dokončená. Pokud potřebujete spustit neblokující tiskovou operaci, zavolejte <methodname>PrintOperation::set_allow_async()</methodname>. Pamatujte ale, že <methodname>set_allow_async()</methodname> není podporováno na všech platformách, ale signál <literal>done</literal> bude i tak vyslán.Standardně lze označit jen jeden řádek, ale můžete povolit i označení více řádků nastavením příslušného režimu: <placeholder-1/>Standardně je vaše obsluha signálu zavolána až po předchozích připojených obsluhách signálu. To ale může dělat problém při obsluze signálů od událostí X. Například stávající obsluhy signálu nebo výchozí obsluha signálu může vrátit <literal>true</literal> a tím zastavit volání další obsluhy. Když chcete určit, že vaše obsluha signálu by měla být zavoláno před ostatními, což znamená, že bude zavolána vždy, můžete zadat <literal>false</literal> do volitelného parametru <literal>after</literal>. Například, <placeholder-1/>Při odvození z <classname>Gtk::Widget</classname> můžete provádět veškeré kreslení pro svůj widget přímo, místo abyste jen uspořádali synovské widgety. Například <classname>Gtk::Label</classname> kreslí text popisku, ale nedělá to to pomocí jiných widgetů.Přepsáním <methodname>forall_vfunc()</methodname> umožníte aplikacím operovat se všemi synovskými widgety v kontejneru. Například <methodname>show_all_children()</methodname> ji používá k vyhledání všech synovských widgetů a jejich zobrazení.Programátoři v jazyce C používají pro skládání a spojování řetězců funkci <function>sprintf()</function>. V C++ dávají přednost datovým proudům, což ale bohužel znesnadňuje překlady, protože jednotlivé útržky textu se překládají samostatně a nedává to překladateli možnost je přeuspořádat podle pravidel gramatiky jeho jazyka.Typ v CTyp v C++Cairo a PangoZavoláním <methodname>add_drag_dest()</methodname> umožníte položkám nebo skupinám jejich přetažení z palety nástrojů na konkrétní cílový widget. Následně můžete použít <methodname>get_drag_item()</methodname> ke zjištění, který objekt <classname>TollItem</classname> nebo <classname>ToolItemGroup</classname> je přetahován. Ke zjištění, jestli jde o položku nebo skupiny, můžete použít <literal>dynamic_cast</literal>. Hodit se vám to bude například ve vaší obsluze signálu <literal>drag_data_received</literal> k přidání upuštěné položky nebo k zobrazení názorné ikony během přetahování.Zavolat <methodname>show()</methodname>, aby se widget zobrazit.PřetypováníBuňky v <classname>TreeView</classname> může uživatel upravovat přímo na místě. Abyste mu to umožnili, použijte z <classname>Gtk::TreeView</classname> na místo metod <methodname>insert_column()</methodname> a <methodname>append_column()</methodname> metody <methodname>insert_column_editable()</methodname> a <methodname>append_column_editable()</methodname>. Když jsou tyto buňky upraveny, je nová hodnota bezprostředně uložena do Modelu. Upozorňujeme ale, že tyto metody jsou šablonami, ze kterých lze vytvořit instanci jen pro jednoduché typy sloupců, jako je <classname>Glib::ustring</classname>, int nebo long.Změny v <application>gtkmm</application> 3Změna rozvržení okna „za běhu“, například kvůli přidání dalšího widgetu, je velmi komplikovaná. Vyžaduje to unavné přepočítání pozice všech widgetů.Změna výběruKapitola „Kreslení s Cairo“Kapitola „Vícevláknové programování“Kapitola „Tisk“Kapitola „Nedávné soubory“Kapitola „Časovače“Kapitola „Práce se zdrojovými kódy gtkmm“Kapitola v Události klávesnice.Zaškrtávací políčko (CheckButton)Zaškrtávací políčka (CheckButton)Kontrola na nullSynovské widgety mohou zabrat více řádků nebo sloupců pomocí <methodname>attach()</methodname> nebo mohou být přidány vedle stávajícího widgetu uvnitř mřížky pomocí <methodname>attach_next_to()</methodname>. Jednotlivé řádky a sloupce mřížky mohou být nastaveny tak, aby měly jednotnou výšku nebo šířku pomocí <methodname>set_row_homogeneous()</methodname> a <methodname>set_column_homogeneous()</methodname>.ChrisWidgety v rozsahu působnosti třídyMakra pro třídySchránka – ideální příkladSchránka – jednoduchý příkladDialogové okno pro výběr barvy (ColorChooserDialog)Rozbalovací seznamy (ComboBox)ComboBoxRozbalovací seznam (ComboBox) se vstupním polem (Entry)ComboBox se vstupním polemKombinované vstupní pole (ComboBoxText)Textový rozbalovací seznam (ComboBoxText) se vstupním polem (Entry)Srovnání s jinými signalizačními systémySkládání řetězcůNapojit případné signály, které si přejete používat s příslušnou obsluhou.Připojení zástrčky do zásuvkyNapojení obsluhy signáluKonstantní objekty předávané přes <classname>RefPtr</classname>: Pokud nemá být objekt měněn funkcí, zajistěte aby byl objekt konstantní, i když je již konstantní <classname>RefPtr</classname>. Například <code>const Glib::RefPtr&lt;const Gtk::FileFilter&gt;&amp; filter</code>.BezkonstantnostMakra pro konstruktoryKonstruktoryKontejnerové widgetyNa rozdíl od jiných událostí, události klávesnice jsou nejprve zaslány do okna nejvyšší úrovně (<classname>Gtk::Window</classname>), kde jsou zkontrolovány vůči případným klávesovým zkratkám (akcelerátory a horké klávesy používané k výběru položek v nabídkách pomocí klávesnice). Po té (za předpokladu, že událost nebyla obsloužena) jsou zaslány do widgetu, který má zaměření a z něj jsou pak propagovány.PřispíváníKopírováníKopírováníKopírování kostry projektuVytvořte objekt <classname>Plug</classname> nezávisle na konkrétním objektu <classname>Socket</classname> a předejte jeho ID do jinému procesu, který jej potřebuje použít. ID objektu <classname>Plug</classname> se dá spřáhnout s konkrétním objektem <classname>Socket</classname> pomocí funkce <classname>Socket::add_id()</classname>. Tohle je přístup použitý v příkladu níže.Vytvořte objekt <classname>Socket</classname> v jednom procesu a předejte jeho ID do jiného procesu, aby mohl vytvořit objekt <classname>Plug</classname> s uvedením daného ID objektu <classname>Socket</classname> ve svém konstruktoru. Neexistuje žádný způsob, jak přiřadit <classname>Plug</classname> konkrétnímu objektu <classname>Socket</classname> později po vytvoření, takže musíte ID opravdu předat do konstruktoru třídy <classname>Plug</classname>.Vytvořte v kořenové složce vašeho projektu podsložku s názvem <literal>po</literal>. V budoucnu bude obsahovat všechny překlady. V ní vytvořte soubory s názvy <literal>LINGUAS</literal> a <literal>POTFILES.in</literal>. Je běžnou praxí v ní vytvořit také soubor <literal>ChangeLog</literal>, aby si překladatelé mohli udržovat přehled o změnách v překladech.Místo předávání ukazatelů všude možně vytvářejte své vlastní signály. Objekty spolu mohou navzájem komunikovat přes signály a obsluhy signálů. Je to mnohem jednodušší, než objekty uchovávající si ukazatele na sebe navzájem a volající si navzájem metody. Třídy z <application>gtkmm</application> používají speciální verze <classname>sigc::signal</classname>, ale vy byste měli používat normální signály <classname>sigc::signal</classname>, jak je popsáno v dokumentaci <application>libsigc++</application>.Vytváření souborů .hg a .ccgVytváření objektů AdjustmentVytváření vlastních signálůCummingV současnosti <application>gettext</application> nepodporuje jiné znaky než ASCII (tj. znaky s kódem vyšším než 127) ve zdrojovém kódu. Například nemůžete použít znak copyright (©).Vlastní kontejnerVlastní kontejneryVlastní widgetVlastní widgetyDISTCLEANFILES = ... intltool-extract \
                 intltool-merge \
                 intltool-update \
                 po/.intltool-merge-cacheDanielDavidDeklarovat proměnnou typu <classname>Widget</classname>, kterou si přejete použit, obecně jako členskou proměnnou odvozené kontejnerové třídy. Mohli byste také deklarovat ukazatel na typ widgetu a pak jej vytvořit pomocí <literal>new</literal> ve svém kódu. Ale i když používáte widget přes ukazatel, je pořád pravděpodobně nejlepší vytvořit ukazatel jako členskou proměnnou v kontejnerové třídě, abyste se k widgetu později dostali.Výchozí formátováníDefinujte <literal>INTLTOOL_FILES</literal> takto: <placeholder-1/>Definuje vlastní cíl schránky, ačkoliv formát cíle zůstává textový.ZávislostiSnižování referencíVytvářet a upravovat uživatelské rozhraní mohou návrháři bez programátorských znalostíDialogová oknaDialogová okna se používají jako podružná okna pro poskytování informací nebo pokládání dotazů. Okna <classname>Gtk::Dialog</classname> obsahují několik předbalených widgetů pro zajištění jednotného vzhledu a fungování a metodu <methodname>run()</methodname>, která blokuje další činnost, dokud dialogové okno nezmizí.Různé aplikace obsahují různé typy dat a ta data mohou zpřístupňovat v různých formátech. <application>gtkmm</application> nazývá takovéto datové typy <literal>cíle</literal> (targets).Různé typy spojů v CairoOdpojení obsluhy signáluVyhledání dostupných cílůV případě, že volání funkce v C očekává, že mu bude poskytnuta reference, proveďte dodatečné zvýšení počitadla referencí pomocí <function>reference()</function> u návratové hodnoty přepsané funkce <function>neco_vfunc()</function> ve funkci zpětného volání v C.Provede pomocí <function>reference()</function> dodatečné zvýšení počitadla referencí u návratové hodnoty z virtuální metody <function>on_neco()</function> v případě, že funkce v C neposkytuje reference.V případě, že virtuální funkce v C neposkytuje reference, proveďte dodatečné zvýšení počitadla referencí pomocí <function>reference()</function> u návratové hodnoty funkce <function>neco_vfunc()</function>.Provede pomocí <function>reference()</function> zvýšení počtu referencí na návratové hodnotě v případě, že funkce v C neposkytuje reference.Negenerovat funkce zpětného volání v C pro signál. Použijte to, když musíte vygenerovat funkci zpětného volání ručně.Negenerujte funkce zpětných volání v C pro virtuální funkce. Tohle použijte, když musíte generovat funkce zpětných volání ručně.Negenerujte definice virtuálních funkcí v souboru <filename>.cc</filename>. Tohle použijte, když musíte generovat virtuální funkce ručně.Negenerovat virtuální metodu <function>on_neco()</function>, která umožňuje snadné přepsání výchozí obsluhy signálu. Použijte, když by přidání signál s výchozí obsluhou signálu rozbilo ABI zvýšením velikosti tabulky virtuálních funkcí pro třídu.DokumentaceStruktura pro sestavení dokumentaceTáhni a upusťKontext přetahování (DragContext)Kreslení oblouků a kružnicKreslicí oblast – obloukyKreslicí oblast – obrázekKreslicí oblast – čáryKreslicí oblast – textKreslicí oblast – tenké čáryKreslení křivekKreslení obrázkůKreslení rovných čarKreslení textuKreslení textu pomocí knihovny PangoKreslení po směru hodinových ručičekKreslení tenkých čarKreslení s relativními souřadnicemiPři <literal>přesouvání</literal> zdrojový widget vyšle také tento signál: <placeholder-1/>Dynamická alokace pomocí manage() a add()Dynamická alokace pomocí new a deleteKaždá instance <classname>Cairo::Context</classname> patří k nějakému konkrétnímu <classname>Gdk::Window</classname>., takže první řádek příkladu výše vytvoří widget <classname>Gtk::DrawingArea</classname> a druhý řádek využije k němu patřící <classname>Gdk::Window</classname> k vytvoření objektu <classname>Cairo::Context</classname>. Poslední dva řádky mění grafický stav kontextu.Každý <classname>Gtk::TextBuffer</classname> používá <classname>Gtk::TextBuffer::TagTable</classname>, který obsahuje objekty <classname>Tag</classname> pro vyrovnávací paměť. Dva nebo více objektů <classname>TextBuffer</classname> může sdílet stejnou instanci <classname>TagTable</classname>. Když vytvoříte objekty <classname>Tag</classname>, měli byste je přidat do <classname>TagTable</classname>. Například:Každý widget <classname>Gtk::TreeView</classname> má přiřazený <classname>Gtk::TreeModel</classname>, který obsahuje data zobrazená v <classname>TreeView</classname>. Každý <classname>Gtk::TreeModel</classname> může být použit i více než jedním <classname>Gtk::TreeView</classname>. Umožňuje to například stejná podkladová data zobrazit a upravovat dvěma různými způsoby naráz. Nebo dvě zobrazení mohou ukazovat různé sloupce ze stejného datového modelu, podobně jako dva dotazy SQL (nebo pohledy) mohou zobrazovat různá pole ze stejné databázové tabulky.Jednotlivé položky v seznamu nedávno použitých souborů jsou identifikovány jejich adresou URI a mohou mít přiřazena metadata. Metadata se dají využít k určení, jak se má soubor zobrazovat, popisu souboru, jeho typu MIME, která aplikace jej má registrovaný, jestli je soukromý jen pro registrující aplikaci a dalším věcí.Každý řádek obsahuje jeden vodorovný <classname>Box</classname> s několika tlačítky. Každé z těchto tlačítek na řádku je sbaleno do <classname>Boxu</classname> pomocí stejných argumentů předanýc metodě <methodname>pack_start()</methodname>.Editovatelné buňkyElstnerVyšle se, když je tlačítko zmáčknuto a uvolněno.Vyšle se, když je tlačítko zmáčknuto.Vyšle se, když je tlačítko uvolněno.Vyšle se, když ukazatel myši opustí okno vlastnící tlačítko.Vyšle se, když ukazatel myši najede nad okno vlastnící tlačítko.Vstupní pole (Entry)Doplňování vstupuPříklad doplňování vstupuPříklad vstupního pole s ikonamiIkony ve vstupním poliVstupní pole s ukazatelem průběhuPříklad ukazatele průběhu ve vstupním poliVstupní pole umožňují uživateli zadat text. Obsah pole můžete měnit pomocí metody <methodname>set_text()</methodname> a aktuální obsah číst pomocí metody <methodname>get_text()</methodname>.Vstupní pole s ikonouVstupní pole s ukazatelem průběhuVýčtyPropagace událostiPropagace událostí znamená, že když je událost vyslána na konkrétní widget, může být předána do rodičovského widgetu (a ten ji může předat do svého rodičovského widgetu atd.) a pokud má rodič obsluhu události, je tato obsluha zavolána.Schránka událostí (EventBox)PříkladUkázková aplikace: Kreslení hodin pomocí knihovny CairoPříkladyVýjimky v obsluze signáluOčekává se UTF-8Export do PDFRozšířené dialogové okno tiskuFerreiraVýběr souboru (FileChooser)Dialogové okno pro výběr souboru (FileChooserDialog)Filtrování nedávných souborůNakonec zkontrolujeme stav. Například <placeholder-1/>Nakonec, aby mohla vaše aplikace používat překlady pro aktuální národní prostředí, přidejte na začátek souboru <filename>main.cc</filename> tento kód, aby inicializovat gettext. <placeholder-1/>Nejprv vytvořte akce <classname>Action</classname> a pak je přidejte do <classname>ActionGroup</classname> pomocí <methodname>ActionGroup::add()</methodname>.Nejprve vytvoříme instanci objektu uchovávaného v chytrém ukazateli <classname>RefPtr</classname> nazývaném <literal>app</literal>. Je typu <classname>Gtk::Application</classname>. Každý program používající <application>gtkmm</application> musí jeden takový mít. Jeho metodě <function>create()</function> předáme argumenty příkazové řádky. Argumenty, které potřebuje, si zpracuje a zpracování ostatních, jak jsme již psali, ponechá na vás.Nejprve se podívejme na jednoduchý příklad, kde je výjimka vyhozena z normální funkce (bez obsluhy signálu). <placeholder-1/>Dialogové okno pro výběr písma (FontChooserDialog)U <classname>CellRendererToggle</classname> byste místo toho mohli nastavit vlastnost <emphasis>activatable</emphasis>.Pro všechna makra zpracovávající hlavičky metod, vyjma maker <function>_WRAP_SIGNAL()</function> a <function>_WRAP_VFUNC()</function>, je také možné určit parametry jako volitelné tak, že se vygenerují další metody v C++ bez určených volitelných parametrů. Například řekněme, že následující funkce <function>*_new()</function> byla obalena jako konstruktor v třídě <classname>Gtk::ToolButton</classname>: <placeholder-1/> Navíc řekněme, že API C umožňuje NULL pro parametr <parameter>label</parameter> v této funkci, takže parametr může být volitelný. Pak by bylo možné přimět <command>gmmproc</command> vygenerovat původní konstruktor (se všemi parametry) souběžně s dalším konstruktorem bez volitelného parametru tak, že k názvu parametru připojí <literal>{?}</literal>: <placeholder-2/> V takovém situaci se vygenerují dva konstruktory: Jeden s volitelným parametrem a jeden bez něj.Pro všechna makra, která zpracovávají hlavičky metod, je možné určit jiné pořadí parametrů C++, než je stávající pořadí ve funkcích, virtuálních funkcích nebo signálech v jazyce C. Například řekněme, že následující funkce C byly obaleny jako metody v C++ pro třídu <classname>Gtk::Widget</classname>: <placeholder-1/> Je však nutné změnit pořadí dvou parametrů metody v C++. Nějak takto by se dala funkce obalit jako metoda v C++ s jiným pořadím pro dva parametry: <placeholder-2/> <literal>{c_param_name}</literal> následující za názvy parametrů metody říká <command>gmmproc</command>, aby mapoval parametr v C++ na daný parametr v C uvedený v <literal>{}</literal>. Vzhledem k tomu, že názvy parametrů v C++ odpovídají těm v C, lze výše uvedené zapsat jako: <placeholder-3/>Pře kteroukoliv z tříd <classname>RecentChooser</classname> platí, že když si nepřejete zobrazit všechny položky v seznam nedávných souborů, můžete seznam vyfiltrovat, aby zobrazoval jen ty, které chcete. Seznam se dá filtrovat s pomocí třídy <classname>RecentFilter</classname>. Tato třída vám umožňuje filtrovat nedávné soubory podle jejich názvu (<methodname>add_pattern()</methodname>), typu MIME (<methodname>add_mime_type()</methodname>), aplikace, která je registruje (<methodname>add_application()</methodname>) nebo pomocí vlastní filtrační funkce (<methodname>add_custom()</methodname>). Poskytuje rovněž schopnost filtrovat na základě toho, před jakou dobou byl soubor změněn a jaké patří skupině.Pro každou stránku, která potřebujete vykreslit, je vyslán následující signál: <placeholder-1/>Například pro <classname>Pango::Analysis</classname> v <filename>item.hg</filename>: <placeholder-1/>Například z <filename>icontheme.hg</filename>: <placeholder-1/>Pokud by například funkce v C vracela <type>GtkWidget*</type> a metoda v C++ z nějakého důvodu místo widgetu vracela něco jiného, je žádoucí, aby metoda v C++ umístila widget do určeného výstupního parametru, k čemuž by bylo nutné následující inicializační makro: <placeholder-1/>Například v <filename>rectangle.hg</filename>: <placeholder-1/>Například v <filename>layoutline.hg</filename> z Pangomm: <placeholder-1/>Pokud byste raději implementovali své vlastní signály, místo napojení těch stávajících v <application>gtkmm</application>, podívejte se do tohoto <link linkend="chapter-custom-signals">dodatku</link>.NapříkladNapříklad <application>gedit</application> může dodávat a přijímat cíl <literal>"UTF8_STRING"</literal>, takže můžete do aplikace <application>gedit</application> vkládat z libovolné aplikace, která dodává takovýto cíl. Nebo dvě různé aplikace pro úpravy obrázků mohou dodávat a přijímat jako cíle různorodé formáty obrázků. Pokud aplikace umí přijímat jeden z cílů, který ostatní aplikace dodávají, může uživatel kopírovat data z jedné do druhé.Například <placeholder-1/>Například pro <classname>Gdk::Rectangle</classname>: <placeholder-1/>Například pro <classname>Pango::AttrIter</classname>: <placeholder-1/>Například pro <classname>Pango::Coverage</classname>: <placeholder-1/>Například, pro <classname>CellRendererText</classname> byste mohli nastavit vlastnost buňky <emphasis>editable</emphasis> na <literal>true</literal> takto:Příklad z <classname>Gdk::RGBA</classname>: <placeholder-1/>Příklad z <classname>Glib::Checksum</classname>: <placeholder-1/>Příklad z <filename>accelgroup.hg</filename>: <placeholder-1/>Příklad z <filename>button.hg</filename>: <placeholder-1/>Příklad z <filename>buttonbox.hg</filename>: <placeholder-1/>Příklad z <filename>celleditable.hg</filename>: <placeholder-1/>Příklad z <filename>container.hg</filename>: <placeholder-1/>Příklad z <filename>entry.hg</filename>: <placeholder-1/>Příklad z <filename>enums.hg</filename>: <placeholder-1/>Příklad z <filename>pixbuf.hg</filename>: <placeholder-1/>Příklad z <filename>widget.hg</filename>: <placeholder-1/>Například si představme, že obalujeme knihovnu C nazvanou libneco a že poskytuje API na základě <classname>GObject</classname> s typy nazvanými například <classname>NecoWidget</classname> a <classname>NecoNejakeho</classname>.Například takovýto kód by mohl přinést problémy:Například, abyste vytvořili signál, který posílá dva parametry, <type>bool</type> a <type>int</type>, jednoduše zadeklarujte <classname>sigc::signal</classname>, nějak takto: <placeholder-1/>Například:Více informací o signálech najdete v <link linkend="chapter-signals">dodatku</link>.Pro vícenásobné označování musíte definovat zpětné volání a předat jej do <methodname>selected_foreach()</methodname>, <methodname>selected_foreach_path()</methodname> nebo <methodname>selected_foreach_iter()</methodname>, zhruba takto:Jen pro srovnání, je možné vygenerovat soubor, který bude obsahovat všechny řetězce, které se objevují ve zdrojovém kódu, bez ohledu na to, že nejsou označené k překladu, včetně názvu zdrojového souboru a čísla řádku. K vygenerování takového souboru, nazvaného <literal>moje-řetězce</literal> spusťte následující příkaz ve složce se zdrojovými kódy: <placeholder-1/>Pro označení jednoho řádku stačí zavolat <methodname>get_selected()</methodname>, takto:Pro zadávání hesel, heslových frází a jiných citlivých informací, u kterých nechcete, aby se při psaní zobrazovaly, zavolejte metodu <methodname>set_visibility()</methodname> s parametrem <literal>false</literal>, což způsobí skrytí textu.Rám (Frame)Rám <classname>Frame</classname> do sebe umí uzavřít jeden widget nebo celou skupinu widgetů a volitelně k nim zobrazit nadpis. Například do něj můžete umístit skupinu zaškrtávacích políček <classname>CheckButton</classname> nebo skupinových přepínačů <classname>RadioButton</classname>.Čas od času by se mohlo hodit mít možnost vložit widget z jiné aplikace do svojí aplikace. <application>gtkmm</application> to umožňuje udělat pomocí tříd <classname>Gtk::Socket</classname> a <classname>Gtk::Plug</classname>. Neočekává se, že by tuto funkcionalitu potřebovalo moc aplikací, ale ve zřídkavých případech můžete potřebovat zobrazit widget, který běží v úplně jiném procesu, a pak se vám tyto třídy mohou hodit.Úplný příkladWidgety v rozsahu působnosti funkceGTK+ 3.0GTK+ a <application>gtkmm</application> byly navrženy s tím, aby dobře fungovaly i s Microsoft Windows a vývojáři pobízejí k jeho použití na platformě win32. Windows ale nemají standardizovaný instalační systém pro vývojářské knihovny. Proto se prosím podívejte na stránku <ulink url="https://wiki.gnome.org/Projects/gtkmm/MSWindows">Windows Installation</ulink> na instalační instrukce a poznámky týkající se výhradně Windows.GTK+ používá kreslicí API <ulink url="http://cairographics.org">Cairo</ulink>. S <application>gtkmm</application> můžete používat <ulink url="http://www.cairographics.org/cairomm/">cairomm</ulink>, což je API C++.Generovat deklaraci virtuální metody <function>on_neco()</function> v souboru <filename>.h</filename>, ale negenerovat definici v souboru <filename>.cc</filename>. Použijte, když musíte generovat definici ručně.Generování souborů .defsGenerování .defs  pro výčtyGenerování .defs  pro metodyGenerování .defs  pro signály a vlastnostiGenerování zdrojových kódů pro obalující API ve stylu gtkmm vyžaduje použití nástrojů, jako jsou <command>gmmproc</command> a <filename>generate_wrap_int.pl</filename>. Teoreticky si můžete napsat vlastní sestavovací soubory pro tentýž účel, ale mnohem lepší volbou je, použít sestavovací infrastrukturu poskytovanou modulem mm-common. Jestli s tím začínáte, výrazně vám pomůže, vzít si existující modul jako příklad na okoukání.Získejte data z widgetů v obsluze signálu <literal>custom_widget_apply</literal>.Získání pomoci s překlademZískání hodnotPředat všechny přepínače příkazové řádky do <methodname>Gtk::Application::create()</methodname> a přidat příznak <literal>Gio::APPLICATION_HANDLES_COMMAND_LINE</literal>. Napojit obsluhu signálu na signál <literal>command_line</literal> a zpracovat přepínače příkazové řádky v obsluze signálu.Glade a Gtk::BuilderGlib::IO_ERR – Zavolat vaši metodu, když se na popisovači souboru vyskytla nějaká chyba.Glib::IO_HUP – Zavolat vaši metodu, když došlo k zaseknutí (připojení bylo porušeno, obvykle kvůli rouře nebo soketu).Glib::IO_IN – Zavolat vaši metodu, když jsou připravena data ke čtení na popisovači vašeho souboru.Glib::IO_OUT – Zavolat vaši metodu, když je popisovač souboru připravený k zápisu.Glib::IO_PRI – Zavolat vaši metodu, když má popisovač souboru neodkladná data k přečtení.Glib::RefPtr&lt;Gtk::Adjustment&gt; Gtk::Adjustment::create(
  double value,
  double lower,
  double upper,
  double step_increment = 1,
  double page_increment = 10,
  double page_size = 0);Glib::RefPtr&lt;Gtk::Application&gt; app = Gtk::Application::create(argc, argv, "org.gtkmm.examples.base");Glib::RefPtr&lt;Gtk::Clipboard&gt; refClipboard = Gtk::Clipboard::get();

// Cíle:
std::vector&lt;Gtk::TargetEntry&gt; targets;
targets.push_back( Gtk::TargetEntry("example_custom_target") );
targets.push_back( Gtk::TargetEntry("UTF8_STRING") );

refClipboard-&gt;set( targets,
    sigc::mem_fun(*this, &amp;ExampleWindow::on_clipboard_get),
    sigc::mem_fun(*this, &amp;ExampleWindow::on_clipboard_clear) );Glib::RefPtr&lt;Gtk::ListStore&gt; refListStore =
    Gtk::ListStore::create(m_Columns);Glib::RefPtr&lt;Gtk::RecentInfo&gt; info;
try
{
  info = recent_manager-&gt;lookup_item(uri);
}
catch(const Gtk::RecentManagerError&amp; ex)
{
  std::cerr &lt;&lt; "RecentManagerError: " &lt;&lt; ex.what() &lt;&lt; std::endl;
}
if (info)
{
  // položka byla nalezena
}Glib::RefPtr&lt;Gtk::RecentManager&gt; recent_manager = Gtk::RecentManager::get_default();
recent_manager-&gt;add_item(uri);Glib::RefPtr&lt;Gtk::TextBuffer::Mark&gt; refMark =
    refBuffer-&gt;create_mark(iter);Glib::RefPtr&lt;Gtk::TextBuffer::Tag&gt; refTagMatch =
    Gtk::TextBuffer::Tag::create();
refTagMatch-&gt;property_background() = "orange";Glib::RefPtr&lt;Gtk::TextBuffer::TagTable&gt; refTagTable =
    Gtk::TextBuffer::TagTable::create();
refTagTable-&gt;add(refTagMatch);
// V budoucích verzích snad bude mít  <application>gtkmm</application> metodu
// set_tag_table() pro použití až po vytvoření vyrovnávací paměti.
Glib::RefPtr&lt;Gtk::TextBuffer&gt; refBuffer =
    Gtk::TextBuffer::create(refTagTable);Glib::RefPtr&lt;Gtk::TextChildAnchor&gt; refAnchor =
    refBuffer-&gt;create_child_anchor(iter);Glib::RefPtr&lt;Gtk::TreeModelSort&gt; sorted_model =
    Gtk::TreeModelSort::create(model);
sorted_model-&gt;set_sort_column(columns.m_col_name, Gtk::SORT_ASCENDING);
treeview.set_model(sorted_model);Glib::RefPtr&lt;Gtk::TreeSelection&gt; refTreeSelection =
    m_TreeView.get_selection();Glib::RefPtr&lt;Gtk::UIManager&gt; m_refUIManager =
    Gtk::UIManager::create();
m_refUIManager-&gt;insert_action_group(m_refActionGroup);
add_accel_group(m_refUIManager-&gt;get_accel_group());Glib::ustringGlib::ustring and std::iostreamsGlib::ustring strText = row[m_Columns.m_col_text];
int number = row[m_Columns.m_col_number];Glib::ustring ui_info =
    "&lt;ui&gt;"
    "  &lt;menubar name='MenuBar'&gt;"
    "    &lt;menu action='MenuFile'&gt;"
    "      &lt;menuitem action='New'/&gt;"
    "      &lt;menuitem action='Open'/&gt;"
    "      &lt;separator/&gt;"
    "      &lt;menuitem action='Quit'/&gt;"
    "    &lt;/menu&gt;"
    "    &lt;menu action='MenuEdit'&gt;"
    "      &lt;menuitem action='Cut'/&gt;"
    "      &lt;menuitem action='Copy'/&gt;"
    "      &lt;menuitem action='Paste'/&gt;"
    "    &lt;/menu&gt;"
    "  &lt;/menubar&gt;"
    "  &lt;toolbar  name='ToolBar'&gt;"
    "    &lt;toolitem action='Open'/&gt;"
    "    &lt;toolitem action='Quit'/&gt;"
    "  &lt;/toolbar&gt;"
    "&lt;/ui&gt;";

m_refUIManager-&gt;add_ui_from_string(ui_info);Glib::ustring ui_info =
    "&lt;ui&gt;"
    "  &lt;popup name='PopupMenu'&gt;"
    "    &lt;menuitem action='ContextEdit'/&gt;"
    "    &lt;menuitem action='ContextProcess'/&gt;"
    "    &lt;menuitem action='ContextRemove'/&gt;"
    "  &lt;/popup&gt;"
    "&lt;/ui&gt;";

m_refUIManager-&gt;add_ui_from_string(ui_info);Mřížka (Grid)SkupinyGtk::Alignment
Gtk::Arrow
Gtk::AspectFrame
Gtk::Bin
Gtk::Box
Gtk::Button
Gtk::CheckButton
Gtk::Fixed
Gtk::Frame
Gtk::Grid
Gtk::Image
Gtk::Label
Gtk::MenuItem
Gtk::Notebook
Gtk::Paned
Gtk::RadioButton
Gtk::Range
Gtk::ScrolledWindow
Gtk::Separator
Gtk::Table (zavrženo od <application>gtkmm</application> verze 3.4)
Gtk::ToolbarGtk::Application a přepínače příkazového řádkuGtk::Box(Gtk::Orientation orientation = Gtk::ORIENTATION_HORIZONTAL, int spacing = 0);
void set_spacing(int spacing);
void set_homogeneous(bool homogeneous = true);Gtk::Button* pButton = new Gtk::Button("_Something", true);Gtk::CellRendererToggle* pRenderer =
    Gtk::manage( new Gtk::CellRendererToggle() );
pRenderer-&gt;signal_toggled().connect(
    sigc::bind( sigc::mem_fun(*this,
        &amp;Example_TreeView_TreeStore::on_cell_toggled), m_columns.dave)
);Gtk::ComboBox nyní odvozuje z CellLayout, díky čemuž je rozvržení a zarovnání jeho instancí <classname>Gtk::CellRenderer</classname> snazší.Gtk::DrawingArea myArea;
Cairo::RefPtr&lt;Cairo::Context&gt; myContext = myArea.get_window()-&gt;create_cairo_context();
myContext-&gt;set_source_rgb(1.0, 0.0, 0.0);
myContext-&gt;set_line_width(2.0);Gtk::Entry* entry = m_Combo.get_entry();
if (entry)
{
  // Entry by měl přijmout událost focus-out.
  entry-&gt;add_events(Gdk::FOCUS_CHANGE_MASK);

  // Případně se můžete napojit k m_Combo.signal_changed().
  entry-&gt;signal_changed().connect(sigc::mem_fun(*this,
    &amp;ExampleWindow::on_entry_changed) );

  entry-&gt;signal_activate().connect(sigc::mem_fun(*this,
    &amp;ExampleWindow::on_entry_activate) );

  entry-&gt;signal_focus_out_event().connect(sigc::mem_fun(*this,
    &amp;ExampleWindow::on_entry_focus_out_event) );
}Gtk::EventBox();Gtk::Label podporuje jednoduché formátování, například pro ztučnění, obarvení nebo zvětšení textu. Docílit toho můžete tím, že metodě <methodname>set_markup()</methodname> předáte řetězec, který používá <ulink url="http://developer.gnome.org/pango/unstable/PangoMarkupFormat.html">syntax Pango Markup</ulink>. Kupříkladu <code>&lt;b&gt;bold text&lt;/b&gt; and &lt;s&gt;strikethrough text&lt;/s&gt;</code> .Gtk::TreeModel::Children children = row.children();Gtk::TreeModel::Row row = *iter;Gtk::TreeModel::Row row = m_refModel-&gt;children()[5]; //The fifth row.
if(row)
  refTreeSelection-&gt;select(row);Gtk::TreeModel::iterator iter = m_Combo.get_active();
if(iter)
{
  Gtk::TreeModel::Row row = *iter;

  // Získáme data pro vybraný řádek s pomocí naší znalosti
  // stromového modelu:
  int id = row[m_Columns.m_col_id];
  set_something_id_chosen(id); // Vaše vlastní funkce
}
else
  set_nothing_chosen(); // Vaše vlastní funkceGtk::TreeModel::iterator iter = m_refListStore-&gt;append();Gtk::TreeModel::iterator iter = m_refModel-&gt;children().begin()
if(iter)
  refTreeSelection-&gt;select(iter);Gtk::TreeModel::iterator iter_child =
    m_refTreeStore-&gt;append(row.children());Gtk::TreeView::Column* pColumn =
  Gtk::manage(new Gtk::TreeView::Column("Icon Name"));

// m_columns.icon a m_columns.iconname jsou sloupce v modelu
// pColumn je sloupec v TreeView:
pColumn-&gt;pack_start(m_columns.icon, /* expand= */ false);
pColumn-&gt;pack_start(m_columns.iconname);

m_TreeView.append_column(*pColumn);Gtk::TreeView::Column* pColumn = treeview.get_column(0);
if(pColumn)
  pColumn-&gt;set_sort_column(m_columns.m_col_id);Gtk::Widget* pMenubar = m_refUIManager-&gt;get_widget("/MenuBar");
pBox-&gt;add(*pMenuBar, Gtk::PACK_SHRINK);Gtk::Window window;
window.set_default_size(200, 200);Ručně psané soubory se zdrojovými kódyRuční psaní konstruktorůZpracovat přepínače v <function>main()</function> a skrýt je v <classname>Gtk::Application</classname> nastavením <literal>argc = 1</literal> ve volání <methodname>Gtk::Application::create()</methodname>.Obsluha <literal>button_press_event</literal>Obsluha událostí X neovlivňuje ostatní signály widgetu. Pokud třeba obsluhujete <literal>button_press_event</literal> pro <classname>Gtk::Button</classname>, stále budete schopni obdržet signál <literal>clicked</literal>. Obojí je vysláno v (téměř) stejnou chvíli.Hlavičkové soubory a linkováníHello World„Hello World“ 2„Ahoj Světe“ v <application>gtkmm</application>HelloWorld::HelloWorld()
:
  m_button ("Hello World")
{
  set_border_width(10);
  m_button.signal_clicked().connect(sigc::mem_fun(*this,
    &amp;HelloWorld::on_button_clicked));
  add(m_button);.
  m_button.show();
}Zde je nějaký příklad normální správy paměti v C++:Zde je seznam některých těchto widgetů:Zde je jednoduchý příklad, který sbalí 100 přepínacích tlačítek do okna s posuvníky. Zkuste měnit velikost okna, abyste viděli, jak posuvníky reagují.Zde je malý kousek kódu, který dává vše dohromady: (Samozřejmě, že obvykle byste obrázek v obsluze kreslicího signálu nenačítali pokaždé! Zde je to jen proto, aby bylo ukázané vše pohromadě.)Zde je velmi jednoduchý příklad předvádějící operaci <literal>kopírování</literal> pomocí tažení a upuštění:Zde je příklad metody zpětného volání:Zde je příklad programu, který vykreslí nějaký text a pak ten stejný vzhůru nohama. Kapitola o tisku obsahuje další <link linkend="sec-printing-example">příklad</link> s kreslením textu.Zde je příklad jednoduchého programu, který kreslí obrázek.Zde je výňatek z práce s <application>gdb</application>. Zobrazené jsou jen nejzajímavější části výstupu. <placeholder-1/> Můžete vidět, že výjimka byla vyhozená z <filename>without_signal.cc</filename>, řádek 6 (<code>throw "Something";</code>).Zde je příklad kódu z <filename>gtkmm/demos/gtk-demo/example_icontheme.cc</filename>, který má ve stejném sloupci ikonu pixbuf i textový název:Zde je zdrojový kód pro příklad, jehož výsledkem je to, co můžete vidět na snímku obrazovky výše. Když příklad spouštíte, zadejte jako volbu příkazového řádku číslo v rozmezí 1 až 3, a uvidíte, jak se použijí různé volby balení.Zde definujeme novou třídu nazvanou <classname>OverriddenButton</classname>, která je zděděná z <classname>Gtk::Button</classname>. Jedinou věcí, kterou měníme, je metoda <methodname>on_clicked()</methodname>, která je zavolaná, kdykoliv <classname>Gtk::Button</classname> vyšle signál <literal>clicked</literal>. Tato metoda vypíše „Hello World“ na <literal>stdout</literal> a pak zavolá původní, přepsanou metodu, aby třída <classname>Gtk::Button</classname> mohla udělat to, co by dělala, kdybychom ji nepřepsali.Zde je jednoduchý příklad: <placeholder-1/>Zde je trochu rozsáhlejší příklad slotů v činnosti:Zde je ukázka widgetu <classname>SpinButton</classname> v akci:Zde je příklad napojení obsluhy signálu na signál:Zde je příklad jednoduchého programu, který kreslí do kreslicí oblasti oblouk, kružnici a elipsu.Zde je příklad této techniky:Zde je konstruktor pro widget <classname>Box</classname> a metody které nastavují volby balení podle pro kontejner: <placeholder-1/> Předání <literal>tru</literal> do <methodname>set_homogeneous</methodname> způsobí, že všechny obsažené widgety budou mít stejnou velikost. <parameter>spacing</parameter> je (minimální) počet pixelů, který se má ponechat mezi jednotlivými widgety.Jak gettext fungujejak používat Git pro překladatele GNOMEPřesto je potřeba při psaní programů založených na <application>gtkmm</application> a používajících spouštění více vláken věnovat některým věcem pozornost. Pramení to z faktu, že <application>libsigc++</application>, a zejména <classname>sigc::trackable</classname>, nejsou bezpečné z hlediska vláken. Je to proto, že žádné složitější interakce, které se vyskytují při použití <application>libsigc++</application>, nejsou chráněné mutexem nebo jiným synchronizačním mechanizmem. <placeholder-1/>Neumožňuje to ale řídit, které položky lze přetáhnout a kam je lze upustit. Pokud potřebujete širší možnosti ovládání, můžete vytvořit odvozený <literal>Gtk::TreeModel</literal> z <literal>Gtk::TreeStore</literal> nebo <literal>Gtk::ListStore</literal> a přepsat virtuální metody <literal>Gtk::TreeDragSource::row_draggable()</literal> a <literal>Gdk::TreeDragDest::row_drop_possible()</literal>. Můžete si prohlédnout poskytovanou cestu <literal>Gtk::TreeModel::Path</literal> a podle ní povolit nebo zakázat přetažení nebo upuštění tím, že vrátíte <literal>true</literal> nebo <literal>false</literal>.Jde to ale i jednodušeji, když použijete makro <function>PKG_CHECK_MODULES()</function> ve standardním souboru configure.ac v spolupráci s autoconf a automake. Například: <placeholder-1/> Tím se zkontroluje přítomnost gtkmm a definují MYAPP_LIBS a MYAPP_CFLAGS pro použití se soubory Makefile.am.Může se stát, že budete chtít, aby se nové hodnoty neukládaly okamžitě. Například můžete chtít omezit vstup na konkrétní znaky nebo rozsah hodnot.Místo obyčejných polí char* a ukazatelové aritmetiky už stejně nejspíše používáte třídu <classname>std::string</classname>, takže stačí, když přejdete místo ní na používání <classname>Glib::ustring</classname>. Viz kapitola <link linkend="sec-basics-ustring">Základy</link> o <classname>Glib::ustring</classname>.I've been embedded.
A plug was addedINTLTOOL_FILES = intltool-extract.in \
                 intltool-merge.in \
                 intltool-update.inIT_PROG_INTLTOOL([0.35.0])

GETTEXT_PACKAGE=nazev_aplikace
AC_SUBST(GETTEXT_PACKAGE)
AC_DEFINE_UNQUOTED([GETTEXT_PACKAGE], ["$GETTEXT_PACKAGE"],
                   [Doména, která se má použít pro gettext])
AM_GLIB_GNU_GETTEXT

NAZEVAPLIKACE_LOCALEDIR=[${datadir}/locale]
AC_SUBST(NAZEVAPLIKACE_LOCALEDIR)IdeálníIdeální by bylo, kdybyste <ulink url="http://www.gtkmm.org/bugs.shtml">poskytli záplatu</ulink> k souboru <filename>docs/tutorial/C/gtkmm-tutorial-in.xml</filename>. Tento soubor se momentálně nachází v modulu <literal>gtkmm-documentation</literal> v repozitáři git projektu GNOME.Funkce při nečinnostiPokud je určitý objekt třídy odvozený z <classname>sigc::trackable</classname>, jen jedno vlákno by mělo vytvářet objekty <classname>sigc::slot</classname> představující některou z nestatických metod třídy volánm <function>sigc::mem_fun()</function>. První vlákno, které má vytvořit takovýto slot, by mělo být považováno za vlastníka příslušného objektu za účelem vytváření dalších slotů odkazujících na <emphasis>kteroukoliv</emphasis> z jeho nestatických metod používajících tuto funkci, nebo anulovat tyto sloty jejich odpojením nebo zničeném sledovacího objektu.Pokud programátor nepotřebuje widgety v rozsahu působnosti třídy, může použít také widgety v rozsahu působnosti funkce. Přínosem oproti rozsahu působnosti třídy jsou zvýšené skrytí dat a omezení závislostí. <placeholder-1/>Pokud programátor nepotřebuje dynamickou alokaci paměti, dají se použít automatické widgety v rozsahu působnosti třídy. Jedním z přínosů automatických widgetů v rozsahu působnosti třídy je, že správa paměti je na jednom místě jako celek. Programátor neriskuje úniky paměti vlivem selhání <literal>delete</literal> u widgetu.Pokud je vše správně, měli byste být schopni sestavit <application>gtkmm</application> a všechny jeho závislosti z repozitáře git pomocí příkazu <command>jhbuild build</command> (nebo, pokud neurčíte <application>gtkmm</application> v proměnné <varname>modules</varname>, pomocí příkazu <command>jhbuild build gtkmm</command>).Pokud by <classname>Socket</classname> z nějakého důvodu nemohl připojit <classname>Plug</classname>, vypadalo by okno nějak takto:Pokud výčet není <classname>GType</classname>, musíte předat třetí parametr NO_GTYPE. To je případ, když neexistuje funkce <function>*_get_type()</function> pro výčet v C, ale dávejte pozor, jestli jenom nepotřebujete vložit další hlavičkový soubor pro onu funkci. Měli byste také vyplnit chybové hlášení vůči API C, protože všechny výčtové typy by měli být zaregistrované jako GType.Pokud se před tím, než není zachycena zajímavá výjimka, zachytává příliš jiných výjimek, může být tento postup poněkud únavný. Dá se ale automatizovat následujícími příkazy <application>gdb</application>. <placeholder-1/> Tyto příkazy vypíší zpětně zásobník volání pro každé <code>throw</code> a pokračuje se. Výpis z posledního (nebo možná předposledního) <code>throw</code> před zastavením programu je ten, který nás zajímá.Když je to poprvé, co používáte program, který využívá nedávné soubory, může být dialogové okno napoprvé prázdné. Jinak v něm uvidíte zobrazený seznam nedávno použitých dokumentů zaregistrovaných jinými aplikacemi.Pokud byste měli zájem pomoci nám s vývojem <application>gtkmm</application> nebo s opravou chyb v <application>gtkmm</application>, budete nejspíše potřebovat sestavit vývojovou verzi <application>gtkmm</application>. Neměli byste ale instalovat vývojovou verzi přes stabilní verzi. Místo toho byste ji měli nainstalovat vedle stávající instalace <application>gtkmm</application> do samostatné cesty.Jestliže používáte <application>gettext</application> přímo, můžete označit k překladu jen řetězce, které jsou přímo ve zdrojových kódech. Pokud ale používáte <application>intltool</application>, můžete označit k překladu i řetězce v různých jiných souborových formátech, včetně souborů <application>Glade</application> s uživatelským rozhraním, souborů ve formátu XML, <ulink url="http://standards.freedesktop.org/desktop-entry-spec/latest/">souborů .desktop</ulink> a několika dalších. Takže pokud máte aplikaci s uživatelským rozhraním navrženým v <application>Glade</application>, přidejte do <literal>POTFILES.in</literal> rovněž své soubory <filename>.glade</filename>.Když zavoláte <methodname>Gtk::TreeView::set_reorderable()</methodname>, bude možné přesouvat položky v rámci stromového zobrazení. Ukázáno je to v příkladu <classname>TreeStore</classname>.Pokud jste zkopírovali kostru zdrojového stromu v mm-common a nahradili zástupné texty, tak budete již mít vhodné soubory <filename>Makefile.am</filename> a <filename>Doxyfile.in</filename>. S nastavení sestavení podle mm-common není seznam vstupních souborů Doxygen definován v konfiguračním souboru Doxygen, ale je předáván z <command>make</command> na standardní vstup příkazu <command>doxygen</command>. Seznam vstupních souborů je definován proměnnou <varname>doc_input</varname> v souboru <filename>Makefile.am</filename>.Když kopírujete <classname>RefPtr</classname>, například <placeholder-1/>, nebo jej předáte jako argument metody, nebo jej vrátíte jako typ, pak <classname>RefPtr</classname> nebude provádět počítání referencí, aby se zajistilo, že instance nebude zničena dříve, než poslední <classname>RefPtr</classname> přejde mimo rozsah působnosti.Pokud se rozhodnete přispět, pošlete prosím příspěvek do poštovní konference <application>gtkmm</application> na adrese <ulink url="mailto:gtkmm-list@gnome.org">&lt;gtkmm-list@gnome.org&gt;</ulink>. Pamatujte ale, že celý dokument je svobodný a zdarma a i příspěvky, se kterými přijdete, musí splňovat tyto podmínky. To mimo jiné znamená, že lidé mohou volně používat části příkladů ve svých programech a volně šířit kopie tohoto dokumentu (včetně příspěvků).Pokud nechcete vyhledávat podle konkrétní URI, ale místo toho chcete získat seznam všech nedávno použitých položek, poskytuje <classname>RecentManager</classname> funkci <methodname>get_items()</methodname>. Návratová hodnota této funkce je <classname>std::vector</classname> se všemi nedávno použitými soubory. Následující kód ukazuje, jak můžete seznam nedávno použitých souborů získat:Když vytvoříte objekt <classname>Tag</classname> a přidáte jej do <classname>TagTable</classname>, můžete použít tuto formátovací značku na část textu v <classname>TextBuffer</classname>, takže tento text se zobrazí s formátováním. Začátek a konec rozsahu definujete pomocí <classname>Gtk::TextBuffer::iterator</classname>. Například:Pokud předáte <literal>true</literal> do metody <methodname>set_activates_default()</methodname>, zmáčknutí klávesy <keymap>Enter</keymap> v <classname>Gtk::Entry</classname> bude aktivovat výchozí widget pro okno, které tento <classname>Gtk::Entry</classname> obsahuje. To je užitečné především v dialogových oknech. Výchozím widgetem je obvykle jedno z tlačítek dialogového okna, které jej například zavře. Pro nastavení widgetu jako výchozího použijte <methodname>Gtk::Widget::set_can_default()</methodname> a <methodname>Gtk::Widget::grab_default()</methodname>.Pokud sdílíte objekt přizpůsobení mezi widgety <classname>Scrollbar</classname> a <classname>TextView</classname>, manipulace s posuvníkem bude automaticky ovlivňovat widget <classname>TextView</classname>. Natavit to můžete takto:Když zkusíte kreslit čáru tlustou jeden pixel, můžete být překvapeni, že místy bude čára rozmazaná a širší, než by měla. To se děje, protože Cairo se snaží kreslit z vybraných souřadnic obě strany (polovinu tloušťky na každou stranu), takže když zadáte umístění přesně mezi pixely a chcete jeden pixel tlustou čáru, pokouší se Cairo použí polovinu z každého pixelu, což není možní (pixel je nejmenší možná jednotka). Děje se to pokaždé, když je tloušťka čáry lichý počet pixelů (ne jen pro jeden pixel).V případě, že použijete obsluhu signálu k zachycení stejného signálu z několika widgetů, byli byste rádi, kdyby obsluha signálu obdržela nějaké doplňující informace. Například můžete chtít vědět, na které tlačítko bylo kliknuto. To můžete udělat pomocí <function>sigc::bind()</function>. Zde je kód z příkladu <link linkend="sec-helloworld2">helloworld2</link>. <placeholder-1/> Říká se v něm, že chceme po signálu, aby poslal do obsluhy signálu doplňující argument <classname>Glib::ustring</classname> a hodnota tohoto argumentu by měla být „button 1“. Samozřejmě potřebujeme přidat tento doplňující argument do deklarace naší obsluhy signálu: <placeholder-2/> A samozřejmě, normální obsluha signálu „clicked“ by neměla mít žádné argumenty.Pokud chcete pomoci s vývojem <application>gtkmm</application> nebo experimentovat s novými funkcemi, můžete nainstalovat <application>gtkmm</application> také ze systému správy verzí Git. Většina uživatelů to nikdy nebude potřebovat, ale jestli máte zájem pomoci s vývojem <application>gtkmm</application>, podívejte se do dodatku <link linkend="chapter-working-with-source">Práce se zdrojovými kódy gtkmm</link>.Když chcete zaregistrovat soubor včetně metadat, můžete předat do <methodname>add_item()</methodname> parametr <classname>RecentManager::Data</classname>. Metadata mohou být nastavena pro konkrétní položku souboru následovně:Když chcete určit metodu, která má být zavolána, když se nic jiného neděje, použijte následující:Jestli se chcete o chytrých ukazatelích dozvědět více, můžete si přečíst tyto knihy: <placeholder-1/>Když kreslíte posloupnost čar ve formě cesty, můžete je chtít spojovat dohromady konkrétním způsobem. Cairo nabízí tři různé způsoby, jak čáry spojit: hranatý spoj – Miter, zkosený spoj – Bevel a zaoblený spoj – Round. Zde jsou ukázané ve zmíněném pořadí:Jestliže jste doposud nepoužívali žádnou vývojářskou sadu pro balení, může vám chvíli trvat, než si na to zvyknete. Nejspíše ale zjistíte, že nejste závislí na vizuální podobě v editoru, stejně jako byste nemuseli u kterékoliv jiné vývojářské sady.V případě, že vaše distribuce neposkytuje sestavený balíček <application>gtkmm</application>, nebo když chcete instalovat jinou verzi, než je ta poskytovaná ve vaší distribuci, můžete <application>gtkmm</application> nainstalovat také ze zdrojových kódů. Zdrojové kódy pro <application>gtkmm</application> můžete stáhnout z <ulink url="http://www.gtkmm.org/"/>.Pokud je vaše aplikace svobodným softwarem, je k dispozici celý dílčí projekt v <literal>GNOME</literal>, který vám pomůže s překlad. Jedná se o <ulink url="https://wiki.gnome.org/TranslationProject/">Překladatelský projekt <literal>GNOME</literal></ulink>.Implementace vlastní logiky pro editovatelné buňky.V souboru <filename>configure.ac</filename> <placeholder-1/>V <filename>skeleton/skeletonmm/Makefile.am</filename> musíme uvést správné hodnoty pro obecné proměnné, které se používají všude možně v sestavovacím systému:V <filename>skeleton/src/Makefile.am</filename> musíme uvést správné hodnoty pro obecné proměnné, které s použijí všude možně v sestavovacím systému.Mimo přidávání položek do seznamu, můžete položky v seznamu také vyhledávat a měnit nebo odebírat.Mimo změny URI souboru můžete také položky ze seznam odstranit, buď po jedné nebo smazat všechny naráz. Prvního zmíněného dosáhnete pomocí <methodname>remove_item()</methodname>, druhého pomocí <methodname>purge_items()</methodname>.Mimo kreslení základních rovných čar, existuje řada věcí, které si u čar můžete přizpůsobit. Již jste viděli příklad nastavení barvy a tloušťky čáry, ale jsou tu i další.Mimo rovných čar umožňuje Cairo kreslit jednoduše i křivky (přesný technický termín je kubické Bézierovy splajny) pomocí funkcí <methodname>Cairo::Context::curve_to()</methodname> a <methodname>Cairo::Context::rel_curve_to()</methodname>. Tyto funkce přebírají souřadnice pro cílový bod a souřadnice dvou „řídících“ bodů. Nejlépe to bude vysvětlit na příkladu, tak pojďme na to.Obecně používají projekty ve stylu gtkmm Doxygen, který čte speciálně formátované komentáře jazyka C++ a generuje z nich dokumentaci v HTML. Tyto komentáře můžete zapisovat přímo do hlavičkových souborů.V <classname>Gtk::Window</classname> máme také přepsanou výchozí obsluhu (<methodname>on_key_release_event()</methodname>) a další obsluha je volaná před výchozí obsluhou (<methodname>windowKeyReleaseBefore()</methodname>).V kapitole <link linkend="sec-wrapping-hg-files">soubory .hg a .ccg</link> se můžete dozvědět více o syntaxi používané v těchto souborech.V příkladu výše jsme všechno nakreslili pomocí absolutních souřadnic. Můžeme kreslit také pomocí relativních souřadnic. Pro přímé čáry se to dělá pomocí funkce <methodname>Cairo::Context::rel_line_to()</methodname>.V následujících instrukcích nepočítáme s přímým použitím nástrojů <application>gettext</application>, ale <application>intltool</application>, které byly napsány speciálně pro projekt <literal>GNOME</literal>. <application>intltool</application> používá <function>gettext()</function>, který vytáhne řetězce ze zdrojového kódu, ale umí je kombinovat s řetězci z dalších souborů, například ze souborů .desktop s detaily o aplikaci a ze souborů <application>Glade</application> s prostředky grafického uživatelského rozhraní. Výsledkem jsou standardní soubory <application>.pot/.po</application> ve formátu <application>gettext</application>.V Makefile.am v nejvyšší úrovni: <placeholder-1/>V takovémto případě byste měli přidat do řetězce nějaké další znaky. Například použít <literal>"jumps[noun]"</literal> a <literal>"jumps[verb]"</literal> místo prostého <literal>"jumps"</literal> a po zavolání funkce <function>gettext</function> je odříznout. Když něco takového provedete, měli byste také přidat komentář pro překladatele před volání <function>gettext</function>. Tyto komentáře se objeví v souborech <filename>.po</filename>. Například:V tomto příkladu jsou tři obsluhy událostí, které se nazývají podle výchozích obsluh událostí v <classname>Gtk::Window</classname>. Jedna je <classname>Gtk::Entry</classname>, druhá <classname>Gtk::Grid</classname> a třetí <classname>Gtk::Window</classname>.V tomto příkladu jsou tři klávesové zkratky: <keycap>Alt</keycap>+<keycap>1</keycap> vybírá první skupinový přepínač, <keycap>Alt</keycap>+<keycap>2</keycap> vybírá druhý a klávesa <keycap>Esc</keycap> skryje (zavře) okno. Výchozí obsluha signálu události je přepsaná tak, jak je popsáno v oddílu <link linkend="sec-overriding-default-signal-handlers">Přepisování výchozí obsluhy signálu</link> v dodatku.V tomto příkladu sestavíme malý, ale plně funkční program používající <application>gtkmm</application> a nakreslíme do okna pár čar. Čáry se kreslí vytvořením cesty a jejím obtažením. Cesta se vytváří pomocí funkcí <methodname>Cairo::Context::move_to()</methodname> a <methodname>Cairo::Context::line_to()</methodname>. Funkce <methodname>move_to()</methodname> funguje podobně, jako když zvednete pero nad papír a posunete ruku jinam a znovu jej přiložíte – během přesunu ruky pero nic nekreslilo. Pro kreslení čáry mezi dvěma body se používá funkce <methodname>line_to()</methodname>.V této části výukového textu pokryjeme základní kreslicí model Cairo, popíšeme podrobně jednotlivé základní kreslicí prvky (včetně příkladů) a ukážeme si jednoduchou aplikaci, která používá Cairo ke kreslení widgetu s hodinami.V souboru <literal>src/Makefile.am</literal> aktualizujte <literal>AM_CPPFLAGS</literal> přidáním následujících definic maker preprocesoru:Ve svém zpětném volání porovnejte vektor dostupných cílů s těmi, které vaše aplikace podporuje pro vložení. Mohli byste i povolit nebo zakázat položku nabídky „Vložit“, v závislosti na tom, jestli je vložení zrovna možné. Například:Ve své obsluze signálu byste měli zkontrolovat novou hodnotu a uložit ji do objektu <classname>Model</classname>, pokud se to vaší aplikaci může hodit.Vložení dalších souborůNezávisle řazená zobrazení téhož modeluInformační lišta (InfoBar)K odvozování nových widgetů můžete použít dědičnost. Odvozování nových widgetů v kódu GTK+ v jazyce C je komplikované a náchylné na chyby, které většina programátorů jiných jazyků při použití C dělá. Jako programátor v C++ víte, že odvozování s pomocí dědičnosti je základní technikou objektového programování.InicializaceInstalaceInstalace <application>gtkmm</application> pomocí programu <application>jhbuild</application>Instalace ze zdrojových kódůInstalace a používání vývojové verze <application>gtkmm</application> z repozitáře gitNamísto pracného napojení obsluhy signálu na signál můžete jednoduše vytvořit novou třídu, která bude zděděná z widgetu – řekněme tlačítka – a přepsat jeho výchozí obsluhu signálu, jako je Button::on_clicked(). To může být mnohem jednodušší, než se zaháčkovat na obsluhu signálu pro všechno.Mezilehlé typyInternacionalizace a lokalizacesoubor README z intltoolÚvodNavíc přebírá dodatečný volitelný argument: <placeholder-1/>Má tu stejnou formu. Číslo 3 na konci názvu typu říká, že naše obsluha signálu potřebuje tři argumenty. Prví typ v seznamu typů je <type>void</type>, protože by měl být návratovým typem naší obsluhy signálu. Následující tři typy jsou postupně typy argumentů. Prototyp naší obsluhy signálu by mohl vypadat nějak takto:Pro vazební moduly je běžné, že sledují číslo verze knihovny, kterou obalují. Takže například, když knihovna C je ve verzi 1.23.4, počáteční verze vazebního modulu by byla 1.23.0. Vyhněte se ale počátku se sudým vedlejším číslem verze, protože obvykle indikuje stabilní vydání.Je dobrou praxí vložit všechny změny do grafického stavu mezi voláním funkcí <methodname>save()</methodname>/<methodname>restore()</methodname>. Například, když máte funkci, která přebírá jako argument ukazatel na <classname>Cairo::Context</classname>, můžete to implementovat nějak takto:Podporuje vložení dvou cílů – jak vlastní, tak textový vytváří reprezentaci libovolného textu z vlastních dat.Používá <methodname>request_targets()</methodname> a signál <literal>owner_change</literal> a zakazuje tlačítko <guilabel>Paste</guilabel>, když není nic k dispozici pro vložení.Není možné odhadnou množství potřebného místa pro texty po jejich přeložení do jiných národních jazyků nebo jejich zobrazení jiným písmem. V Unixu také není možné předvídat, jak se projeví různé motivy a správce oken.Je možné, že některé řetězce budou v souboru <filename>.po</filename> označené jako <literal>fuzzy</literal>. Tyto překlady nenahradí originální řetězce. Aby se objevily, stačí po kontrole, a případné opravě překladu, odstranit značku <literal>fuzzy</literal>.Iterace přes řádky modeluIterátoryJonathonJongsmaProstě zavolá nekonstantní verzi té samé funkce, místo aby se generovalo spousta duplicitního kódu.Stejně jako u normálních ukazatelů můžete kontrolovat, jestli <classname>RefPtr</classname> neukazuje na nic.Události klávesniceUdálosti klávesnice – propagace událostíUdálosti klávesnice – jednoduchý příkladKingKjellpříručka L10N pro vývojářePopisek (Label)Popisky jsou hlavním způsobem, jak umístit neupravitelný text do oken, například název vedle vstupního pole <classname>Entry</classname>. Text můžete zadat v konstruktoru nebo později pomocí metody <methodname>set_text()</methodname> nebo <methodname>set_markup()</methodname>.Chybějící vlastnostiLaursenJe potřeba méně kódu v C++.Pojďme se podívat na příklad s přepsáním:Pojďme se podívat, jak s tím, co jsme si ukázali, trochu vylepšit <literal>helloworld</literal>.Podívejme se ještě jednou na metodu <literal>connect()</literal> signálu:Podobně jako zaškrtávací políčka, i skupinové přepínače jsou zděděné z <classname>Gtk::ToggleButton</classname>, ale pracují ve skupinách, kdy v jednu chvíli jen jedno z nich může být ve skupině vybráno.Obdobně jako u <classname>TreeView</classname>, byste měli svůj <classname>TextView</classname> nejspíše vložit do <classname>ScrolledWindow</classname>, aby uživatelé mohli vidět i přesahující text a mohli se po celém textu pohybovat pomocí posuvníků.Obdobně nahraďte všechny výskyty <varname>Joe Hacker</varname> za zamýšleného držitele práv, což budete nejspíše vy. To stejné proveďte s e-mailovou adresou <varname>joe@example.com</varname>.Stejně tak mohou mít různé styly konce čar. Výchozí styl pro čáru je začínat a končit přesně v koncových bodech čáry. To se nazývá rovný konec – Butt. Dalšími volbami jsou zaoblení – Round (zaoblení má střed v koncovém bodu) a čtvercový konec – Square (rovněž čtverec má střed v koncovém bodu). Tyto volby se nastavují pomocí funkce <methodname>Cairo::Context::set_line_cap()</methodname>.Styly čarListStoreListStore (pro řádky)Načtení souboru .gladeVyhledávání položek v seznamu nedávných souborůSpousta lidí potřebuje pro <classname>TreeView</classname> implementovat kontextovou nabídku pod pravé kliknutí, takže abychom vám ušetřili čas, vysvětlíme vám, jak na to. Krom jedné dvou věcí je to stejné, jako normální kontextová nabídka popsaná v <link linkend="sec-menus-popup">kapitole o nabídkách</link>.Hlavní nabídkaPříklad hlavní nabídkySoubory Makefile.amWidgety pod správouMnoho kreslicích funkcí Cairo má variantu <methodname>_preserve()</methodname>. Normální kreslicí funkce, jako jsou <methodname>clip()</methodname>, <methodname>fill()</methodname> nebo <methodname>stroke()</methodname>, mažou aktuální cestu. Když použijete variantu <methodname>_preserve()</methodname>, bude aktuální cesta ponechána, takže ji můžete použít v následující kreslicí funkci.Řada vývojářských nástrojů pro GUI vyžaduje přesné umístění widgetů v oknech s použitím přesných souřadnic a často je k tomu zapotřebí vizuální editor. To vede k několika problémům:Označení řetězců k překladuMarkoPoziční značky (Mark)Někdy může být zapotřebí, aby uživatel nemohl vybrat všechny položky v seznamu nebo stromu. Například v gtk-demo může vybírat jednotlivé ukázky, aby si prohlédl zdrojový kód, ale na výběr nereagují kategorie ukázek.Pro zjednodušení správy paměti můžete používat členské instance. Všechny widgety GTK+ v C s nimi zachází pomocí ukazatelů. Jako programátor v C++ víte, že ukazatelům byste se měli vyhnout, kdekoliv je to možné.Správa pamětiNabídky a nástrojové lištyDialogové okno se zprávou (MessageDialog)Makra pro metodyMetodyMicrosoft WindowsRůzné widgetyMíchání API z C a C++Sloupce modeluModelColumns()
{ add(m_col_id); add(m_col_name); }

  Gtk::TreeModelColumn&lt;int&gt; m_col_id;
  Gtk::TreeModelColumn&lt;Glib::ustring&gt; m_col_name;
};

ModelColumns m_columns;Úprava souborů řídících sestaveníZměny seznamu nedávných souborůSledování V/VDalší informace o pozadí procesu internacionalizace a lokalizace jsou představeny a ukázány v: <placeholder-1/>Více než jeden sloupec modelu ve sloupci zobrazeníVětšina aplikací bude mít jen jeden objekt <classname>Window</classname>, nebo aspoň jen jedno hlavní okno. Tyto aplikace mohou používat přetížení <methodname>Gtk::Application::run(Gtk::Window&amp;)</methodname>. Tím se zobrazí okno a k návratu z volání dojde, až se okno skryje. To může nastat, když uživatel okno zavře, nebo když se váš kód rozhodne okno skrýt pomocí <methodname>hide()</methodname>. Přepsáním <methodname>Gtk::Window::on_delete_event()</methodname> můžete uživateli zabránit okno zavřít (například, když existuje neuložené změny v jeho datech).Většina widgetů potřebuje své vlastní <classname>Gdk::Window</classname>, aby na něj mohly kreslit. Pak můžete ve svém konstruktoru zavolat <methodname>Gtk::Widget::set_has_window(true)</methodname>. (Jedná se o výchozí hodnotu.) Když <methodname>set_has_window(false)</methodname> nezavoláte, musíte přepsat <methodname>on_realize()</methodname> a zavolat od tam <methodname>Gtk::Widget::set_realized()</methodname> a <methodname>Gtk::Widget::set_window()</methodname>.Většina dialogových oken v této kapitole je modálních, což znamená, že po dobu co jsou zobrazená, zmrazí zbytek aplikace. Je možné vytvářet i nemodální dialogová okna, která ostatní okna v aplikaci nezmrazí. Následující příklad ukazuje nemodální <classname>AboutDialog</classname>. Není to ale druh dialogového okna, které byste běžně dělali jako nemodální, ale nemodální dialogová okna se hodí v různých jiných situacích. Např. dialogové okno pro hledání a nahrazování v aplikaci <application>gedit</application> je nemodální.Většina našich příkladů používá tuto techniku.Většina kapitol v této knize se zabývá konkrétními widgety. Více informací o přidávání widgetů do kontejnerového widgetu najdete v kapitole <link linkend="chapter-container-widgets">Kontejnerové widgety</link>.Většina užitečných členských metod této třídy se ve skutečnosti nachází v rodičovské třídě <classname>Gtk::FileChooser</classname>.Většinou se pro balení používají boxy, stejně jako v předchozím příkladu. Jedná se o neviditelné kontejnery, do kterých můžete balit své widgety. Když balíte widgety do vodorovného boxu, vkládají se vodorovně zleva doprava, nebo zprava doleva, podle toho, jestli použijete <methodname>pack_start()</methodname> nebo <methodname>pack_end()</methodname>. U svislých boxů se widgety balí shora dolů a naopak. Abyste dosáhli kýženého efektu, můžete použít libovolné kombinace boxů uvnitř a vedle dalších boxů.PřesunVícevláknový programVícevláknové programyWidgety s více položkamiWidgety s více položkami jsou odvozené z <classname>Gtk::Container</classname>. Podobně jako <classname>Gtk::Bin</classname> používají metody <methodname>add()</methodname> a <methodname>remove()</methodname> k přidání a odebrání widgetů. Ale na rozdíl od <methodname>Gtk::Bin::remove()</methodname> jejich metoda <methodname>remove()</methodname> přebírá argument, který určuje, který widget se má odebrat.MurrayMurray CummingNásledně voláme metodu <methodname>set_border_width()</methodname> objektu Window. Tím se nastaví množství volného místa mezi okraji okna a widgetem, který je v okně obsažen.Následně vytvoříme objekt naší třídy <classname>HelloWorld</classname>, jejíž konstruktor nemá žádný argument, ale zatím není viditelná. Pak zavoláme <methodname>Gtk::Application::run()</methodname>, čímž aplikace dostane okno, to se zobrazí a spustí se <emphasis>smyčka událostí</emphasis> <application>gtkmm</application>. Ve smyčce událostí je <application>gtkmm</application> nečinné a jen vyčkává na nějakou činnost ze strany uživatele, na níž příslušně zareaguje. Když uživatel zavře okno, dojde k návratu z metody <methodname>run()</methodname> a tím se provede zbývající řádek ve funkci <function>main()</function>. Po té aplikace skončí.Následně musíme přizpůsobit různé soubory <filename>Makefile.am</filename>: <placeholder-1/>Následně byste měli vytvořit <classname>UIManager</classname> a pomocí <methodname>insert_action_group()</methodname> do něj přidat <classname>ActionGroup</classname>. V tento okamžik je také dobré říci rodičovskému oknu pomocí <methodname>add_accel_group()</methodname>, aby reagovalo na patřičné klávesové zkratky.Následně použijeme metodu <methodname>add()</methodname> k vložení <literal>m_button</literal> do okna. (<methodname>add()</methodname> pochází z třídy <classname>Gtk::Container</classname>, která je popsaná v kapitole o kontejnerových třídách.) Metoda <methodname>add()</methodname> umístí widget do okna, ale nezobrazí jej. Widgety jsou v <application>gtkmm</application> po svém vytvoření vždy neviditelné – abyste je zobrazili, musíte zavolat jejich metodu <methodname>show()</methodname>, což je přesně to, co děláme na dalším řádku.Nicolai M. Josuttis, „The C++ Standard Library“ – kapitola 4.2Nemodální dialogové okno s informacemi o aplikaci (AboutDialog)Normální správa paměti v C++Pamatujte také, že ne všechny widgety přijímají ve výchozí podobě všechny události X. K příjmu dalších událostí X můžete použít před zobrazením widgetu jeho metodu <methodname>Gtk::Widget::set_events()</methodname> nebo po jeho zobrazení metodu <methodname>Gtk::Widget::add_events()</methodname>. Některé widgety je však třeba nejprve umístit do widgetu <classname>EventBox</classname>. Viz kapitola <link linkend="chapter-widgets-without-xwindows">Widgety bez X-Windows</link>.Mějte ale na paměti, že UTF-8 není kompatibilní s 8bitovými kódováními, jako je ISO-8859-2. Například ypsilon s čárkou není v ASCII a potřebuje proto v UTF-8 k zakódování víc než jeden bajt. Pokud váš kód obsahuje 8bitové řetězcové literály, musíte je převést do UTF-8 (např. český pozdrav „Dobrý den“ by byl „Dobr\xC3\xBD den“).Soubory končící na <filename>.in</filename> budou použity k vygenerování souborů se stejným názvem, ale bez přípony <filename>.in</filename>. Během konfigurační fáze se v nich nahradí některé proměnné skutečnými hodnotami.Pokud budeme uvádět dodatečné moduly navíc ke gtkmm-3.0, měly by být oddělené mezerami, ne čárkami.Všimněte si, že v tomto případě jsme téměř vše vyjádřili v pojmech výšky a šířky okna, včetně tloušťky čar. Díky tomu vše při změně velikosti okna správně změní měřítko. Navíc si všimněte, že jsou ve funkci tři samostatné celky kreslení, které jsou obalené v páru funkcí <methodname>save()</methodname> a <methodname>restore()</methodname>, takže po každém kreslení se vrátíme zpět do známého stavu.Upozorňujeme, že většina překladatelských týmů se skládá jen z jednoho až tří lidí, takže pokud vaše aplikace obsahuje spoustu řetězců, může to chvíli trvat, něž si někdo najde čas se na ni podívat. Navíc většina překladatelů nechce ztrácet svůj čas (překládání je časově velmi náročné) na nesolidních projektech (ve smyslu, že je dotažený do použitelného stavu a udržovaný) a mohou se věnovat raději jinému projektu.Pamatujte na to, že instance (jako je zde m_Columns) by obvykle neměla být statická, protože je často potřeba ji vytvořit po té, co je inicializována glibmm.Poznamenejme, že tohle je místo, kde definujeme název akce tak, jak jej uživatelé uvidí v nabídkách a v nástrojových lištách. Protože je to zároveň místo, kde byste měli poskytnou řetězce k překladu, vložte je do makra _().Upozorňujeme, že k sestavení <application>gtkmm</application> z repozitáře git je často zapotřebí sestavení také mnoha jeho závislostí. <application>jhbuild</application> to velmi usnadňuje oproti normálnímu postupu, ale sestavení a instalace zabere poměrně hodně času. Pravděpodobně také narazíte na nějaké problémy se sestavováním, ale když je nahlásíte, tak bývají poměrně rychle opravené.Všimněte si, že ukazatel na <methodname>on_button_clicked()</methodname> nepředáváme přímo do metody <methodname>connect()</methodname> patřící signálu. Místo toho zavoláme <function>sigc::ptr_fun()</function> a do <methodname>connect()</methodname> předáme výsledek.Pamatujte, že nemůžete jen prostě provést <placeholder-1/> protože skupina je voláním <methodname>set_group()</methodname> měněna a proto není konstantní.Všimněte si, že musíte definovat akce i pro podnabídky, úplně stejně jako pro položky nabídek.Pamatujte, že díky systému motivů v GTK+ se vzhled těchto widgetů může měnit. V případě zaškrtávacích políček a přepínačů dokonce značně.Všimněte si, že <classname>TreeView</classname> bude poskytovat iterátory řazenému modelu. Abyste mohli provádět akce na daném modelu, musíte je převést na iterátory do podkladového podřízeného modelu. Například:Sešit (Notebook)Všimněte si, že návratová hodnota je typu <classname>sigc::signal&lt;void,int&gt;::iterator</classname>. Ten se dá implicitně převést na <classname>sigc::connection</classname>, který se pak dá použít k řízení napojení. Když si objekt napojení zapamatujete, můžete přidruženou obsluhu signálu odpojit pomocí metody <methodname>sigc::connection::disconnect()</methodname>.Všimněte si, že <command>gmmproc</command> poskytujeme cestu k převodním souborům <filename>.m4</filename>, cestu k souboru <filename>.defs</filename>, název souboru <filename>.hg</filename>, složku se zdrojovými kódy a cílovou složku.Všimněte si, že používáme inicializační výraz k předání popisku „Hello World“ objektu <literal>m_button</literal>.Dejte pozor na to, že po zastavení události nebude už zavolána žádná funkce (i kdyby byla z toho stejného widgetu).Nyní se pojďme podívat na funkci <function>main()</function> našeho programu. Zde je i s komentáři:Nyní se pojďme znovu podívat na přípojení:Nyní se podívejme, co se stane, když je výjimka vyhozena z obsluhy signálu. Zde je zdrojový kód. <placeholder-1/>Nyní se zaměřme na kód, který provádí skutečné vykreslení. První část funkce <methodname>on_draw()</methodname> by vám měla být dobře známá. Tento příklad znovu mění měřítko systému souřadnic na čtvercovou jednotku, takže bude jednodušší vykreslit hodiny jako procentní část velikosti okna a při změně velikosti okna dojde k automatickému přizpůsobení velikosti hodin. Navíc je systém souřadnic posunut vpřed a dolů, takže souřadnice (0, 0) je přímo uprostřed okna.Nyní máte místo, kam dávat překlady, a teď potřebujete inicializovat <application>intltool</application> a <application>gettext</application>. Přidejte následující kód do svého souboru <literal>configure.ac</literal>, přičemž „nazevaplikace“ nahraďte názvem svojí aplikace (platí pro celou kapitolu).Teď, když rozumíme základům grafické knihovny Cairo, jsme více méně připravení začít kreslit. Pojďme začít s nejjednodušším možným útvarem – rovnu čárou. Nejdříve ale musíte něco málo vědět o systému souřadnic v Cairo. Počátek systému souřadnic v Cairo je v levém horním rohu okna s rostoucími kladnými hodnotami x doprava a hodnotami y dolů. <placeholder-1/>Tímto jsme pokryli všechny základy o kreslení pomocí Cairo. Takže to zkusme dát vše dohromady a vytvořit jednoduchou aplikaci, která bude dělat něco reálného. Následující příklad používá Cairo k vytvoření vlastního widgetu s hodinami <classname>Clock</classname>. Hodiny mají sekundovou, minutovou a hodinovou ručičku a aktualizují se po sekundě.Nyní, když jste poznali signály a obsluhu signálů v <application>gtkmm</application>, budete možná chtít používat stejnou techniku ke komunikaci mezi vašimi vlastními třídami. Je to skutečně velmi jednoduché díky přímému použití knihovny <application>libsigc++</application>.Nyní upravíme soubory, abychom je přizpůsobili našim potřebám. Možná dáváte přednost použití nějakého nástroje pro hledání a nahrazování ve více souborech, jako je <command>regexxer</command>. Proto je dobré vědět, že téměř všechny soubory poskytnuté v kostře zdrojového stromu obsahují zástupné texty. Náhrady by tak měly být prováděné globálně a neomezovat se jen na soubory Automake a Autoconf.Bezva, řeknete že je to pěkné, ale co když si chcete vytvořit vlastní obsluhu, abyste reagovali na uživatelovy změny hodnoty ve widgetu <classname>Range</classname> nebo <classname>SpinButton</classname>. Pro přístup k hondote z <classname>Gtk::Adjustment</classname> můžete použít metody <methodname>get_value()</methodname> a <methodname>set_value()</methodname>:Objekty a funkceU objektů, jako je <classname>Gdk::Pixbuf</classname>, lze vytvořit instanci jen pomocí funkce <methodname>create()</methodname>. Například <placeholder-1/>Objekty používané přes <classname>RefPtr</classname>: Předávejte <classname>RefPtr</classname> jako konstantní referenci. Například <code>const Glib::RefPtr&lt;Gtk::FileFilter&gt;&amp; filter</code>.Příležitostně můžete potřebovat, aby byl widget <classname>Entry</classname> jen ke čtení. Toho se dá dosáhnout předáním <literal>false</literal> metodě <methodname>set_editable()</methodname>.To samozřejmě znamená, že můžete uchovávat <classname>RefPtr</classname> ve standardních kontejnerech, jako je <classname>std::vector</classname> nebo <classname>std::list</classname>.Kontejner nejvyšší úrovně samozřejmě nebude přidán do jiného kontejneru. Program je zodpovědný za zničení kontejneru nejvyšší úrovně pomocí jedné z tradičních technik C++. Například vaše okno nejvyšší úrovně může být jen instancí vaší funkce <function>main()</function>.Při balení metod je často žádoucí ukládat návratové hodnoty funkce C v tzv. výstupním parametru. V tomto případě metoda C ++ vrací <type>void</type>, ale výstupní parametr, ve kterém je uložena hodnota z funkce v C, je zahrnut v seznamu argumentů metody v C ++. <command>gmmproc</command> umožňuje tuto funkcionalitu, ale musí být zahrnuta vhodná inicializační makra, které řeknou <command>gmmproc</command>, jak inicializovat parametr C ++ z návratové hodnoty funkce v C.OleV Unixu výchozí obsluha náhledu používá externí prohlížeč. Ve Windows se zobrazí nativní dialogové okno s náhledem. V případě potřeby můžete toto chování přepsat a poskytnout vlastní dialogové okno s náhledem. Viz příklad v /examples/book/printing/advanced.Jakmile máte svůj software sestavený, potřebujete jej spustit ve stejném prostředí systému <application>jhbuild</application>. K tomu můžete znovu spustit příkaz <command>jhbuild shell</command>, aby se spustil nový shell s nastaveným prostředím pro <application>jhbuild</application>. Případně můžete jednorázově spustit příkaz v prostředí systému <application>jhbuild</application> následujícím příkazem: <command>jhbuild run command-name</command>. V tomto případě bude příkaz spuštěn s nastavenými správnými proměnnými prostředí, ale po jeho ukončení dojde návratu do předchozího prostředí.Jakmile nakonfigurujete <application>jhbuild</application> podle popisu uvedeného výše, mělo by být sestavení <application>gtkmm</application> relativně přímočaré. Když spouštíte <application>jhbuild</application> poprvé, měli byste spustit následující posloupnost příkazů, která zajistí, že <application>jhbuild</application> bude mít požadované nástroje, a která ověří, že je vše správně nastavené: <screen>$ jhbuild bootstrap
$ jhbuild sanitycheck</screen>Jednou z východ UTF-8 je, že jej nemusíte používat, když jej nechcete, a nemusíte tak opravovat veškerý kód naráz. <classname>std::string</classname> bude stále fungovat pro řetězce se 7bitovým ASCII. Když se ale rozhodnete lokalizovat své aplikace do jazyků, jako je čeština nebo čínština, začnou se objevovat zvláštní chyby a případně i zhroucení. Potom vše, co musíte udělat, je začít používat místo něj <classname>Glib::ustring</classname>.Jedním z hlavních přínosů <application>gtkmm</application> je, že je multiplatformní. Programy <application>gtkmm</application> napsané na jiných platformách, jako je GNU/Linux, mohou být obecně vzato přenesené do Windows (a naopak) jen s pár změnami ve zdrojových kódech.Na webu Openismus je další <ulink url="http://www.openismus.com/documents/linux/automake/automake.shtml">základní nápověda k automake a autoconf</ulink>.Zpracování volitelných parametrůNebo můžete formátovací značku určit při prvním vložení textu: <placeholder-1/>Ostatní makraOstatní makra, jako je <function>_WRAP_METHOD()</function> a <function>_WRAP_SIGNAL()</function> mohou být použita jen po zavolání makra <function>_CLASS_*</function>.Mimo názvu signálu (<literal>focus</literal>) stojí za zmínku ještě dvě věci: číslo následující za slovem <classname>SignalProxy</classname> na začátku deklarace (v tomto případě 1) a typy v seznamu (<type>bool</type> and <type>Gtk::DirectionType</type>). Číslo říká, kolik argumentů by obsluha signálu měla mít. První typ <type>bool</type> je typ, který by měla obsluha signálu vracet a následující typ <type>Gtk::DirectionType</type> je typ prvního a jediného argumentu signálu. Po nahlédnutí do referenční dokumentace můžete zjistit také názvy argumentů.Všechny naše příklady se snaží mít stejnou strukturu. V použití třídy <classname>Widget</classname> se snaží držet těchto kroků:Zpracování výstupních parametrůPřepisování výchozí obsluhy signáluPřehledPKG_CHECK_MODULES([MYAPP], [gtkmm-3.0 &gt;= 3.8.0])Zabalit widget do kontejneru pomocí příslušného volání, např. <methodname>Gtk::Container::add()</methodname> nebo <methodname>pack_start()</methodname>.BaleníNastavení stránkyDvojitý panel (Paned)Dvojitý panel rozdělí widget na dvě části oddělené rozdělovací čárou. Oba panely mohou být orientované buďto vodorovně (vedle sebe) nebo svisle (nad sebou).PangoZměna pořadí parametrůČásti kapitoly „Internacionalizace“Části v aktualizaci z gtkmm2 na gtkmm 3.VloženíPedroVolby balení pro potomkyVolby balení pro kontejnerJe povoleno kopírovat, šířit a/nebo upravovat tento dokument za podmínek GNU Free Documentation License (GFDL) ve verzi 1.2 nebo v jakékoli novější verzi vydané nadací Free Software Foundation; bez neměnných oddílů, bez textů předních desek a bez textů zadních desek. Znění licence GNU Free Documentation License můžete získat od organizace Free Software Foundation na jejích webových stránkách, nebo si o ni napište na adresu: Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.ÚskalíPamatujte, že při změně pořadí parametrů pro hlavičku metody <function>_WRAP_SIGNAL()</function>, budou názvy parametrů v C vždy <literal>p0</literal>, <literal>p1</literal> atd., protože nástroj <filename>generate_extrac_defs</filename> používá tyto názvy parametrů bez ohledu na názvy parametrů v API C. Takto prostě zmíněný nástroj v současnosti funguje.Na instrukce, jak sestavit gtkmm na Windows se prosím podívejte na <ulink url="https://wiki.gnome.org/Projects/gtkmm/MSWindows/BuildingGtkmm">https://wiki.gnome.org/Projects/gtkmm/MSWindows/BuildingGtkmm</ulink>PlugZástrčky (Plug) a zásuvky (Socket)Příklad s třídami Plug a SocketVyskakovací kontextová nabídkaVyskakovací nabídkaPříklad vyskakovací nabídkyVyskakovací nabídkyPředem sestavené balíčkyPříprava vašeho projektuPěkný výsledek, ne? Pojďme si kód vysvětlit. Nejprve třída <classname>HelloWorld</classname>:Jak zabárnit výběru řádkuNáhledTisková operace (PrintOperation)TiskTisk – jednoduchý příkladPravděpodobně nejčastějším způsobem vytváření objektů <classname>Gdk::Pixbuf</classname> je použití metody <methodname>Gdk::Pixbuf::create_from_file()</methodname>, která načte obrázek ze souboru, jako je soubor <filename>.png</filename>, do pixelové vyrovnávací paměti připravené k vykreslování.Problémy v API v CProgramování s <application>gtkmm</application> 3Ukazatel průběhu zobrazuje stav probíhající operace. Například může <classname>ProgressBar</classname> zobrazovat, jak velká část úlohy je dokončená.Ukazatel průběhu (PrograssBar)Mačkací tlačítko (Button)Vloží vygenerovaný kód do bloků #ifdef.Vloží vygenerovaný kód do bloků #ifdef. Jako volitelný parametr lze uvést vysvětlující text o zavržení.Skupinové přepínače (RadioButton)Skupinový přepínač (RadioButton)Widgety odvozené z RangePřepisování obsluhy signálu: Můžete to dělat i přímo ve světě C v GTK+. Je to to, k čemu objektový systém GTK slouží. V GTK+ ale musíte projít složitými postupy, abyste získali objektově orientované vlastnosti, jako je dědění nebo přetěžování. V C++ je to jednoduché, protože tyto vlastnosti jsou podporované jazykem jako takovým. Necháte na kompilátoru, aby udělal špinavou práci za vás.V současnosti jsou nejnovější verze <application>gtkmm</application> zabaleny v téměř všech hlavních linuxových distribucích. Takže pokud používáte Linux, začnete nejspíše s <application>gtkmm</application> instalací balíčku z oficiálního repozitáře své distribuce. Mezi distribuce, které <application>gtkmm</application> obsahují ve svých repozitářích, patří Debian, Ubuntu, Red Hat, Fedora, Mandriva, Suse a mnohé další.Výběr nedávno použitých (RecentChooser)Správa nedávno použitých (RecentManager)Nedávno použité dokumentyDoporučené technikyOdkazNezapomeňte, že v operačních systémech Unix a Linux budete k instalaci nejspíše potřebovat oprávnění uživatele <literal>root</literal>. Příkaz <command>su</command> nebo <command>sudo</command> vám umožní zadat heslo uživatele <literal>root</literal> a získat dočasně jeho status.Pamatujte, že tyto názvy jsou jen obyčejné identifikátory, které jste použili při vytváření akcí. Nejedná se o text, který by viděl uživatel v nabídkách nebo nástrojových lištách. Názvy čitelné pro lidi jsme poskytli při vytváření akcí.Pamatujte, že instanci widgetu nevytváříte pomocí metody <methodname>get_widget()</methodname>, tou jen získáváte ukazatel na instanci, která již existuje. Pokaždé, když zavoláte <methodname>get_widget()</methodname> na ten samý objekt <classname>Gtk::Builder</classname>, měli byste obdržet ukazatel na tu samou instanci. Instance widgetů se vytváří během <methodname>Gtk::Builder::create_from_file()</methodname>.Vykreslování textuSeřaditelné řádkyZdrojeReagování na změnyRecyklace dokumentace ke knihovnám CRiederPotomci řádkuStejné řetězce, jiný významStupnicové widgetyPosuvníkové widgetyOkna s posuvníky mají <emphasis>pravidla pro posuvníky</emphasis>, která určují, jestli jsou posuvníky <classname>Scrollbar</classname> zobrazené, nebo ne. Pravidla můžete nastavit pomocí metody <methodname>set_policy()</methodname>. Mohou nabývat hodnoty <literal>Gtk::POLICY_AUTOMATIC</literal> nebo <literal>Gtk::POLICY_ALWAYS</literal>. <literal>Gtk::POLICY_AUTOMATIC</literal> způsobí, že okno s posuvníky zobrazí posuvník jen v případě, že vložený widget je větší než viditelná oblast. <literal>Gtk::POLICY_ALWAYS</literal> způsobí, že posuvníky se zobrazí vždy.Okno s posuvníky (ScrolledWindow)PosouváníZa druhé zkontrolujeme chyby a napojíme na signál <literal>status_changed</literal>. Například: <placeholder-1/>Oddíl „Struktura sestavení“ v kapitole „Obalování knihoven C pomocí gmmproc“Oddíl v Gtk::Grid.Viz <link linkend="sec-printing-example-simple">příklad</link>, jak udělat právě toto.Obecné rady k „Táhni a upusť“ pomocí gtkmm najdete v kapitole <link linkend="chapter-draganddrop">Táhni a upusť</link>Více informací o poskytování řetězcových literálů v UTF-8 viz kapitola <link linkend="chapter-internationalization">Internacionalizace</link>.Podrobné informace o RefPtr viz <link linkend="chapter-refptr">dodatek</link>.Na další příklad použití <classname>Alignment</classname> se můžete podívat do oddílu <link linkend="sec-progressbar">ProgressBar</link>.Výběr typů C++, které by se měli použít, je důležitý také při obalování API C. Ačkoliv je většinou zřejmé, jaké typy C++ by se měly použít v metodě C++, máme pro vás pár rad: <placeholder-1/>Nastavit vlastnosti widgetu. Pokud widget nemá výchozí konstruktor, potřebujete jej inicializovat v seznamu inicializací v konstruktoru kontejnerové třídy.Nastavte název karty přes <methodname>PrintOperation::set_custom_tab_label()</methodname>, vytvořte nový widget a vraťte je z obsluhy signálu <literal>create_custom_widget</literal>. Pravděpodobně budete chtít, aby to byl kontejnerový widget, ve kterém budou zabalené další widgety.Nastavení prefixuNastavení systému jhbuildNastavení hodnotSdílené prostředkyNíže je zobrazený jednoduchý příklad, jak použít v programu třídy <classname>RecentChooserDialog</classname> a <classname>RecentAction</classname>. Tento jednoduchý příklad má nabídkovou lištu s položkou <guimenuitem>Recent Files Dialog</guimenuitem>. Když tuto položku vyberete, vyskočí dialogové okno, které zobrazí seznam nedávno použitých souborů.Posloupnost obsluhy signáluSignálySignály a vlastnostiSignály obvykle mají ve struktuře GTK ukazatel na funkci s příslušnou výčtovou hodnotou a <function>g_signal_new()</function> v souboru <filename>.c</filename>.JednoduchýPříklad s jednoduchým vstupním polemJednoduchý příkladJednoduchý příklad s RecentChooserDialogJednoduchý textový příkladJednoduché použitíJednoduchá funkcionalita kopírování/vložení textu je volně poskytována widgety, jako jsou <classname>Gtk::Entry</classname> a <classname>Gtk::TextView</classname>. Pro zacházení se svým vlastním datovým formátem ale budete potřebovat speciální kód. Například kreslicí program by potřeboval speciální kód, který by zprovoznil kopírování a vkládání v rámci zobrazení, nebo mezi dokumenty.Protože je <classname>Plug</classname> jen speciálním typem třídy <classname>Gtk::Window</classname>, můžete do něj přidávat kontejnery nebo widgety úplně stejným způsobem, jako u jiných oken.Vzhledem k tomu, že grafická knihovna Cairo byla napsána s podporou více výstupních cílů (systém X window, obrázky PNG, OpenGL atd.), existuje zde rozdíl mezi souřadnicemi v uživatelském prostoru a v prostoru zařízení. Výchozí mapování mezi těmito dvěma souřadnicovými systémy je jedna ku jedné, takže celočíselné hodnoty se mapují zhruba na jednotlivé pixely na obrazovce, nastavení se ale klidně můžete přizpůsobit svým potřebám. Někdy může být výhodné změnit měřítko, aby souřadnice měly pro celou šířku i výšku rozsah od 0 do 1 („čtvercové jednotky“) nebo nějaké jiné mapování, které bude vaší aplikaci vyhovovat. Provést to můžete pomocí funkce <methodname>Cairo::Context::scale()</methodname>.Protože je tahle metoda velmi podobná metodě rozebrané v předchozím, mělo by tohle vysvětlení k pochopení fungování stačit. Pro jistotu je zde ale příklad:Jednoduchý nebo vícenásobný výběrJednopoložkové kontejneryDoposud jste se dozvěděli, jak provést nějakou činnost na základě zmáčknutí tlačítka a jak obsluhovat signály. To je samozřejmě dobrý způsob, jak dělat věci, ale není jediný.Aby uživatel mohl kliknutím na záhlaví sloupce v <classname>TreeView</classname> seřadit obsah <classname>TreeView</classname>, je potřeba zavolat metodu <methodname>Gtk::TreeView::Column::set_sort_column()</methodname>, které předáte sloupec modelu, na jehož modelu se má řadit, když uživatel na záhlaví klikne. Například:Aby aplikace mohly reagovat na změny, například když uživatel posune posuvníkem, má <classname>Gtk::Adjustment</classname> signál <literal>value_changed</literal>. Vy pak můžete použít metodu <methodname>get_value()</methodname> ke zjištění nové hodnoty.Aby vstupní pole <classname>Entry</classname> mohlo spolupracovat s rozbalovacím seznamem voleb, musíte určit, který z vašich sloupců v modelu je textový, pomocí  <methodname>set_entry_text_column()</methodname>. Například: <placeholder-1/>Proto byste se měli takovýmto situacím vyhnout nebo používat metodu <ulink url="http://developer.gnome.org/glibmm/unstable/classGlib_1_1ustring.html"><function>Glib::ustring::compose()</function></ulink>, která podporuje syntax takto: <placeholder-1/>Takže, když například máte widget <classname>Scale</classname> a chcete změnit otočení obrázku, kdykoliv se změní jeho hodnota, vytvořili byste obsluhu signálu nějak takto:SocketNěkteré widgety <application>gtkmm</application> nemají přidružené okno X a kreslí do oken svých rodičů. Kvůli tomu ale nemohou přijímat události. Navíc, když mají špatně nastavenou velikost, neprovádí ořezání, takže může docházet k různému přepisování obsahuj apod. Když chcete přijímat události v nějakém takovém widgetu, můžete jej umístit dovnitř widgetu <classname>EventBox</classname> a pak před zobrazením zavolat na <classname>EventBox</classname> metodu <methodname>Gtk::Widget::set_events()</methodname>.Některá API vztahující se ke gtkmm používají místo specifických standardních kontejnerů jazyka C++, jako je <classname>std::vector</classname> nebo <classname>std::list</classname>, mezilehlé datové kontejnery, jako je <classname>Glib::StringArrayHandle</classname>, ačkoliv samotné <application>gtkmm</application> nyní od verze 3.0 používá jen <classname>std::vector</classname>.Některé  widget nemají přiřazené X-Window, takže nepřijímají události od X Serveru. Z toho důvodu nejsou vysílány signály popsané v oddíle <link linkend="sec-xeventsignals">Signály událostí X</link>. Jestliže chcete zachytávat události pro tyto widgety, můžete použít speciální kontejner <classname>Gtk::EventBox</classname>, který je popsán v oddíle <link linkend="sec-eventbox">EventBox</link>.Pár doplňujících maker to usnadňuje a zajistí jednotnost. Na příklady se podívejte do souborů <filename>.m4</filename> z gtkmm. Například <placeholder-1/>Některé objekty, jako jsou <classname>Gdk::Pixbuf</classname> a <classname>Pango::Font</classname>, se získávají ze sdíleného úložiště. Proto u nich nemůžete vytvářet své vlastní instance. Tyto třídy bývají typicky zděděné z <classname>Glib::Object</classname>. Místo aby <application>gtkmm</application> vyžadovalo reference a dereference na takovéto objekty, používá chytré ukazatele <classname>Glib::RefPtr&lt;&gt;</classname>. Cairomm má svůj vlastní chytrý ukazatel <classname>Cairo::RefPtr&lt;&gt;</classname>.Některé základní typy, které se používají v API v C mají lepší náhrady v C++. Například, není potřeba používat typ <type>gboolean</type>, protože C++ má <type>bool</type>. Následující seznam uvádí některé běžně používané typy v API v C a na co je můžete převést v obalující knihovně C++.Některá bezpečnostní pravidla pro vlákna při použití <classname>Glib::Dispatcher</classname> stále platí. Jak bylo zmíněno, objekt <classname>Glib::Dispatcher</classname> musí být vytvořen ve vlákně příjemce (vlákno, ve kterém hlavní smyčka spustí jeho napojené sloty). Standardně je to hlavní vlákno programu, ačkoliv existuje konstruktor třídy <classname>Glib::Dispatcher</classname>, který umí převzít objekt <classname>Glib::MainContext</classname> libovolného vlákna, které má hlavní smyčku. Jen vlákno příjemce by mělo volat <methodname>connect()</methodname> na objekt <classname>Glib::Dispatcher</classname>, nebo manipulovat s souvisejícím objektem <classname>sigc::connection</classname>, pokud není zajištěna dodatečná synchronizace. Na druhou stranu, libovolné vlákno může bezpečně vyslat objekt <classname>Glib::Dispatcher</classname> bez zamykání, jakmile má vlákno příjemce napojené sloty, za předpokladu, že je vytvořen před spuštěním pracovního vlákna (jestliže je vytvořen po spuštění vlákna, je pro zajištění viditelnosti vyžadována dodatečná synchronizace).Občas bývají dva texty v angličtině stejné, ale mají různý význam podle kontextu, takže pak budou mít nejspíše i jiné překlady. Protože se ale anglické řetězce používají jako vyhledávací klíče, mám zde problém.ŘazeníŘazení klikáním na sloupceZdrojový kódZdroje a cíleUrčuje cílovou složku pro generované zdrojové soubory a název hlavního souboru <filename>.defs</filename>, který by měl <command>gmmproc</command> zpracovat.Určuje název parametru slot v metodě, pokud existuje. Umožňuje to <command>gmmproc</command> generovat kód pro kopírování slotu a předání kopie do funkce v C v jejím posledním parametru <literal>gpointer user_data</literal>. Musí být také použita volba <literal>slot_callback</literal> pro určení názvu lepicí funkce zpětného volání, aby došlo k předání také do funkce v C.Určení údajů pro CellRendererČíselník (SpinButton)Spusťte program <filename>plug</filename> a pošlete jej do pozadí (nebo stačí použít jiný terminál).Pro tlačítka byly doporučované standardní ikony. Od <application>gtkmm</application>-3.10 jsou zavržené a v nově psaném kódu byste je neměli používat. Místo toho dokumentace ke <ulink url="http://developer.gnome.org/gtkmm/unstable/namespaceGtk_1_1Stock.html">jmennému prostoru Gtk::Stock</ulink> ukazuje doporučené popisky a pojmenované ikony pro zobrazení na tlačítkách.Řetězcové literály byste měli ve zdrojovém kódu psát v angličtině, ale obalené do makra. Nástroj <application>gettext</application> (nebo <application>intltool</application>) umí vytáhnout takto označené řetězce pro překladatele a za běhu je pak nahrazovat překlady.Řetězcové literály by se měly ve zdrojovém kódu psát v angličtině a zároveň by měly být uzavřeny do volání funkce <function>gettext()</function>. Pak budou vytaženy pro překlad a překlad bude použit za běhu místo původního anglického řetězce.Odvozujte podtřídy widgetů kvůli lepší přehlednosti kódu. Pravděpodobně odvodíte minimálně podtřídu z <classname>Window</classname>. Pak můžete ze synovských widgetů a obsluh signálů udělat členy této třídy.Tvorba podtříd není ale vždy nejlepším způsobem, jak dosáhnout kýženého. Je použitelná jen, když widget obsluhuje své vlastní signály. Když chcete, aby signál obsluhovala jiná třída, potřebujete napojit samostatnou obsluhu. Platí to o to víc, když chcete aby stejný signál obsluhovalo několik objektů, nebo chcete, aby jedna obsluha reagovala na stejný signál z více různých objektů.Tabulka (Table)Tabulka formátovacích značek (TagTable)Formátovací značky (Tag)Formátovací značky a formátováníCíleŘíká <command>gmmproc</command> aby nepředával kopii slotu do funkce v C, pokud metoda nějaké má. Místo slotu je předána sama funkce. Název parametru se slotem a lepící funkce zpětného volání musí mít být zadány jako volby <literal>slot_name</literal>, respektive <literal>slot_callback</literal>.Řekne <command>gmmproc</command>, aby přidal inicializační kód pro rozhraní.Řekne <command>gmmproc</command>, aby přidal podle potřeby některé definice typů, konstruktory a standardní metody do této třídy při obalování widgetu.Řekne <command>gmmproc</command>, aby vložil hlavičkové soubory do generovaného souboru <filename>private/button_p.h</filename>.Testování a přidávání překladůText se kreslí pomocí <classname>Layout</classname> z knihovny Pango. Nejjednodušším způsobem, jak vytvořit <classname>Pango::Layout</classname>, je použít <methodname>Gtk::Widget::create_pango_layout()</methodname>. Když je vytvořený, dá se s ním pracovat několika způsoby, včetně změny textu, fontu apod. Nakonec jej můžete vykreslit pomocí metody <methodname>Pango::Layout::show_in_cairo_context()</methodname>.Vykreslování textu se provádí pomocí knihovny Pango. Objekt <classname>Pango::Layout</classname> pro tisk by se měl vytvořit zavoláním metody <methodname>PrintContext::create_pango_layout()</methodname>. Objekt <classname>PrintContext</classname> poskytuje také metriku stránky, přes <methodname>get_width()</methodname> a <methodname>get_height()</methodname>. Počet stránek můžete nastavit pomocí <methodname>PrintOperation::set_n_pages()</methodname>. Abyste mohli v <literal>on_draw_page</literal> provést skutečné vykreslení textu Pango, získejte <classname>Cairo::Context</classname> pomocí <methodname>PrintContext::get_cairo_context()</methodname> a zobrazte objekty <classname>Pango::LayoutLine</classname>, které se tím objeví na příslušné stránce.Zobrazení textu (TextView)Vytvoří se tím soubor <filename>nazevaplikace.pot</filename>. Zkopírujte tento soubor do <filename>kodjazyka.po</filename>, třeba <filename>cs.po</filename> nebo <filename>hu.po</filename>. Příslušný jazyk také přidejte do souboru <literal>LINGUAS</literal>. Soubor <filename>.po</filename> obsahuje hlavičku a seznam anglických řetězců s rezervovaným místem pro zadání přeložených řetězců. Ujistěte se, že je kódování souboru <filename>.po</filename> nastavené na <literal>UTF-8</literal> (je to uvedené v hlavičce a musí být v tomto kódování i řetězce).Signál "changed"Volba „Tisk do souboru“, která je dostupná v dialogovém okně tisku, nepotřebuje žádnou zvláštní implementaci. Někdy ale může být užitečné vygenerovat soubor PDF přímo z kódu. Například <placeholder-1/>Soubory <filename>.h</filename> a <filename>.cc</filename> budou vygenerované ze souborů <filename>.hg</filename> a <filename>.ccg</filename> jejich zpracováním pomocí <command>gmmproc</command>, k čemuž dojde automaticky při použití sestavovací struktury uvedené výše: <placeholder-1/>Soubory .hg a .ccgZdrojové soubory <filename>.hg</filename> a <filename>.ccg</filename> se velmi podobají zdrojovým souborům <filename>.h</filename> a <filename>.cc</filename>, ale mohou obsahovat další makra, jako je <function>_CLASS_GOBJECT()</function> a <function>_WRAP_METHOD()</function>, ze kterých <command>gmmproc</command> generuje příslušný zdrojový kód C++, obvykle na stejném místě v hlavičkovém souboru. Případný doplňující zdrojový kód C++ bude doslovně nakopírován do příslušného souboru <filename>.h</filename> nebo <filename>.cc</filename>.Balíček <application>GNU gettext</application> umožňuje označit řetězce ve zdrojovém kódu k překladu, vytáhnout tyto řetězce pro překlad a použít přeložené řetězce v aplikaci.Modul <application>gtkmm</application> je definován v sadě modulů <filename>gnome-suites-core-deps-3.x.modules</filename>, takže upravte svůj soubor <filename>.jhbuildrc</filename> a nastavte nastavení sady modulů na nejnovější verzi, například takto: <placeholder-1/><classname>AboutDialog</classname> nabízí jednoduchý způsob pro zobrazení informací o programu, jako je jeho logo, název, copyright, webové stránky a licence.Widget <classname>Alignment</classname> umožňuje umístit widget a dát mu velikost relativně k velikosti samotného widgetu <classname>Alignment</classname>. Například jej můžete použít k vystředění widgetu.Widget <classname>AspectFrame</classname> vypadá podobně jako widget <classname>Frame</classname>, ale navíc dodržuje <emphasis>poměr stran</emphasis> (poměr mezi šířkou a výškou) synovského widgetu. Využívá k tomu doplňování prázdného místa okolo widgetu v případě potřeby. Využít se dá například k zobrazení fotografie, aniž by ji uživatel při změně velikosti vodorovně nebo svisle deformoval.<classname>ColorChooserDialog</classname> umožňuje uživateli výběr barvy. Tlačítko <classname>ColorButton</classname> otevře po kliknutí právě toto dialogové okno.Widget <classname>ComboBox</classname> poskytuje seznam (nebo strom) voleb v rozbalovací nabídce. Je-li to vhodné, může u každé položky zobrazovat doplňující informace, jako text, ikonu, zaškrtávací políčko nebo ukazatel průběhu. Widget <classname>ComboBox</classname> obvykle omezuje uživatele v dostupných volbách, ale může mít volitelně textové vstupní pole <classname>Entry</classname>, do kterého může uživatel vložit libovolný text, když se mu nehodí žádná z dostupných voleb.Widget <classname>DrawingArea</classname> je prázdné okno, které vám dává svobodu ve vytváření libovolné grafiky dle přání. Spolu s touto svobodou přichází zodpovědnost za obsluhu kreslicích signálů ve widgetu. Když je widget poprvé zobrazen, nebo když je skryt a pak znovu odkryt, potřebuje se překreslit. Většina widgetů k tomu má kód, ale <classname>DrawingArea</classname> ne, abyste si mohli napsat svoji vlastní obsluhu signálu, která určí, jak se má obsah widgetu nakreslit. Většinou se to dělá přepsáním virtuální členské funkce <methodname>on_draw()</methodname>.Pomocí metody <methodname>set_model()</methodname> můžete pro <classname>EntryCompletion</classname> určit <classname>TreeModel</classname>, který bude obsahovat možné vstupy. Pak byste měli ještě zavolat <methodname>set_text_column()</methodname> k určení sloupce ve vašem modelu, který se má používat k porovnávání možných textových vstupů.Třída <classname>FileChooserDialog</classname> je užitečná ve spojení s funkcemi „Otevřít“ a „Uložit“.<classname>FontChooserDialog</classname> umožňuje uživateli výběr fontu. Tlačítko <classname>FontButton</classname> otevře po kliknutí právě toto dialogové okno.<classname>Gdk::Pixbuf</classname> lze vykreslit jeho nastavením jako zdrojového vzorku v kontextu Cairo pomocí <methodname>Gdk::Cairo::set_source_pixbuf()</methodname>. Pak obrázek nakreslíte pomocí <methodname>Cairo::Context::paint()</methodname> (nakreslí celý obrázek), nebo pomocí <methodname>Cairo::Context::rectangle()</methodname> a <methodname>Cairo::Context::fill()</methodname> (vyplní určený obdélník). <methodname>set_source_pixbuf()</methodname> není členská metoda z <classname>Cairo::Context</classname>. Jako první parametr je vyžadován <classname>Cairo::Context</classname>.<classname>Gtk::Adjustment</classname> se vytváří jeho metodou <methodname>create()</methodname>, která vypadá takto:Widget <classname>Gtk::Button</classname> má následující signály, ale povětšinou budete obsluhovat stejně jen signál <literal>clicked</literal>:Widget <classname>Gtk::TreeView</classname> může obsahovat seznam nebo strom s daty ve sloupcích.<classname>ListStore</classname> obsahuje jen řádková data, řádky nemají žádné potomky.Třída <classname>PrintOperation</classname> má metodu nazvanou <methodname>set_default_page_setup()</methodname>, která vybírá výchozí velikost papíru, jeho otočení a okraje. K zobrazení dialogového okna s nastavením stránky pro svoji aplikaci použijte metodu <methodname>Gtk::run_page_setup_dialog()</methodname>, která vrací objekt <classname>Gtk::PageSetup</classname> se zvolený nastavením. Tento objek použijte k aktualizaci <classname>PrintOperation</classname> a k přístupu k vybrané velikosti papíru <classname>Gtk::PaperSize</classname>, otočení papíru <literal>Gtk::PageOrientation</literal> a okrajům, které se liší podle tiskárny.<classname>SpinButton</classname> si umí vytvořit výchozí objekt <classname>Adjustment</classname>, ke kterému se můžete dostat přes metodu <methodname>get_adjustment()</methodname>, nebo můžete v konstruktoru určit nějaký již existující objekt <classname>Adjustment</classname>.Třída <classname>Tag</classname> má mnoho dalších vlastností.<classname>TextView</classname> vytváří svůj vlastní výchozí <classname>TextBuffer</classname>, ke kterému se můžete dostat přes metodu <methodname>get_buffer()</methodname>.Widget <classname>TextView</classname> se dá použít k zobrazení a úpravám velkého množství formátovaného textu. Podobně jako <classname>TreeView</classname>, má design model/zobrazení. Modelem je v tomto případě <classname>TextBuffer</classname>.Položky z <classname>ToolPalette</classname> se dají přetahovat nebo prostě aktivovat. Například může uživatel přetáhnout položky na plátno, aby na něm vytvořit nové objekty. Nebo může kliknutím na položku aktivovat konkrétní velikost štětce v aplikaci na kreslení.Třída <classname>TreeModelColumnRecord</classname> se používá k udržení přehledu o sloupcích a jejich datových typech. Instance <classname>TreeModelColumn</classname> přidáváte do <classname>ColumnRecord</classname> a pak je používáte k získávání a nastavování dat v řádkovém modelu. Pravděpodobně budete považovat za vhodné odvodit novou třídu <classname>TreeModelColumnRecord</classname>, kterou použije vaše instance <classname>TreeModelColumn</classname> jako členská data.<classname>TreeStore</classname> obsahuje řádková data a každý z řádků může mít potomky v podobě dalších řádků.<classname>TreeView</classname> již umožňuje zobrazit ten samý <classname>TreeModel</classname> ve dvou widgetech <classname>TreeView</classname>. Jestliže potřebujete, aby jeden z nich řadil model jiným způsobem, než ten druhý, měli byste místo toho použít <classname>TreeModelSort</classname>, například <methodname>Gtk::TreeViewModel::set_sort_column()</methodname>. <classname>TreeModelSort</classname> je model, který obsahuje jiný model a podává jeho seřazenou verzi. Například můžete přidat řazenou verzi modelu do <classname>TreeView</classname> takto:Třída <classname>Widget</classname> má speciální signály, které odpovídají událostem systému X-Windows v pozadí. Mají za svým názvem připojeno <literal>_event</literal>, např. <methodname>Widget::signal_button_press_event()</methodname>.Soubory <filename>.defs</filename> jsou textové soubory ve formátu lisp, které popisují API knihovny C, včetně jejích <placeholder-1/>Skript <filename>configure</filename> zkontroluje, jestli jsou již nainstalované všechny závislosti. Pokud bude některá chybět, zobrazí chybu a skončí.Skript <filename>skeletonmm/codegen/generate_defs_and_docs.sh</filename> generuje všechny soubory <filename>.defs</filename> a soubor <filename>*_docs.xml</filename>, popsaný v kapitole <link linkend="sec-wrapping-documentation">Dokumentace</link>.Blok <function>AC_CONFIG_FILES()</function> musí uvádět správné názvy složek, jak bylo popsáno výše.Řádek <function>AC_CONFIG_HEADERS()</function> se používá ke generování dvou nebo více hlavičkových souborů. První hlavičkový soubor v seznamu obsahuje všechna konfigurační makra, která se nastaví při běhu konfigurace. Zbývající hlavičkové soubory v seznamu obsahují jen podmnožinu konfiguračních maker a jejich příslušný soubor <filename>config.h.in</filename> se automaticky nevygeneruje. Důvodem je oddělení těchto věcí, protože konfigurační hlavičkové soubory se jmenným prostorem se instalují spolu s vaší knihovnou a definují veřejně viditelná makra.Na řádku s <function>AC_CONFIG_SRCDIR()</function> musí být zmíněný soubor z naše stromu zdrojových kódů. Pokud zatím nevíme názvy žádných souborů, které vytvoříme, můžeme tento údaj doplnit později.Řádek <function>AC_SUBST([SOMETHINGMM_MODULES], ['…'])</function> může potřebovat upravit, aby kontroloval správné závislosti.Makra <function>_CTOR_DEFAULT()</function> a <function>_WRAP_CTOR()</function> přidávají konstruktory pomocí obalení určených funkcí <function>*_new()</function> v C. Tato makra předpokládají, že objekt C má vlastnosti se stejnými názvy, jako jsou parametry funkce, což tak obvykle je, takže se mohou parametry přímo předat do volání <function>g_object_new()</function>. Tyto konstruktory ve skutečnosti nikdy nevolají funkce <function>*_new()</function> v C, protože gtkmm musí ve skutečnosti vytvořit instance odvozených typů GType a funkce <function>*_new()</function> v C jsou zamýšlené jen pro pohodlí programátorů v jazyce C.API <link linkend="chapter-draganddrop">Táhni a upusť</link> používá ten stejný mechanizmus. Asi byste měli používat stejné datové cíle a formáty jak pro operace se schránkou, tak pro „táhni a upusť“.<literal>const … &amp;</literal> je u obou jen kvůli efektivitě, podobně jako použití <classname>const std::string&amp;</classname> místo <classname>std::string</classname> pro parametr metody, aby se zabránilo zbytečnému kopírování.<literal>Ideální</literal> příklad níže by mohl dodávat více než jeden cíl schránky.Metoda <methodname>PrintOperation::run()</methodname> spouští tiskovou smyčku, během které jsou vyslány různé signály: <placeholder-1/>Virtuální metody <methodname>get_request_mode_vfunc()</methodname>, <methodname>get_preferred_width_vfunc()</methodname>, <methodname>get_preferred_height_vfunc()</methodname>, <methodname>get_preferred_width_for_height_vfunc()</methodname>, <methodname>get_preferred_height_for_width_vfunc()</methodname> a <methodname>on_size_allocate()</methodname> řídí rozvržení synovských widgetů. Například, když má kontejner dva synovské widgety, jeden nad druhým, mohla by metoda <methodname>get_request_mode_vfunc()</methodname> požádat o rozvržení height-for-width (widget si řekne, kolik místa na výšku chce podle toho, kolik ho dostane na šířku). Pak by metoda <methodname>get_preferred_width_vfunc()</methodname> mohla oznámit maximální šířku synovských widgetů a metoda <methodname>get_preferred_height_for_width_vfunc()</methodname> součet jejich výšek. Pokud chcete mezi synovskými widgety odsazení, pak byste jej přidali navíc k šířce a výšce. Kontejner pro widgety použije tyto výsledky, aby zajistil, že widgety budou mít dostatek místa a ne méně. Postupným zkoumáním rodičů widgetů a jejich rodičů a tak dále tato logika nakonec rozhodne o velikosti okna nejvyšší úrovně.Metody <methodname>pack_start()</methodname> a <methodname>pack_end()</methodname> umisťují widgety uvnitř svých kontejnerů. Metoda <methodname>pack_start()</methodname> začíná u objektu <classname>Box</classname> se svislým uspořádáním shora a pokračuje dolů, u objektu <classname>Box</classname> s vodorovným uspořádáním pak vlevo a pokračuje doprava. <methodname>pack_end()</methodname> pracuje přesně opačně, tzn. zdola nahoru nebo zprava doleva. Použití těchto metod dovoluje zarovnání widgetů doprava nebo doleva. Ve většině příkladů budeme používat <methodname>pack_start()</methodname>.Metoda <methodname>run()</methodname> vrací hodnotu typu <literal>int</literal>. Může jít o hodnotu z <literal>Gtk::ResponseType</literal>, když uživatel zavře dialogové okno kliknutím na standardní tlačítko, nebo by mohlo jít o vlastní návratovou hodnotu, kterou jste určili při použití <methodname>add_button()</methodname>.Metoda <methodname>spin</methodname> „pootočí“ číselníkem <classname>SpinButton</classname> stejně, jako když uživatel klikne na tlačítko pro zvýšení nebo snížení. Potřebujete určit <classname>Gtk::SpinType</classname>, podle kterého se řídí směr nebo nová hodnota.Parametr <parameter>options</parameter> může přebírat jednu z následujících tří voleb: <placeholder-1/>Parametr <parameter>padding</parameter> určuje šířku dodatečného volného okraje, který se má ponechat okolo zabaleného widgetu.Argument <parameter>value</parameter> je počáteční hodnota přizpůsobení, obvykle odpovídající nejvyšší nebo nejlevější pozici ve widgetu. Argumenty <parameter>lower</parameter> a <parameter>upper</parameter> určují možný rozsah hodnot, kterých se má přizpůsobení držet. Argument <parameter>step_increment</parameter> určuje menší ze dvou kroků, po kterých uživatel může hodnotu měnit, zatímco <parameter>page_increment</parameter> určuje tu větší. Argument <parameter>page_size</parameter> obvykle nějak koresponduje s viditelnou oblastí pohybovaného widgetu. Argument <parameter>upper</parameter> se používá k reprezentaci nejnižší nebo nejpravější souřadnice v pohybovaném widgetu.Vyrovnávací paměťFunkce v C (např. <function>get_request_mode()</function>) je více popsaná v souboru <filename>*_vfunc.defs</filename> a soubory <filename>convert*.m4</filename> obsahují nutné převody z typu parametru v C++ na typ parametru v C.Funkce v C (např. <function>gtk_entry_set_text</function>) je více popsaná v souboru <filename>.defs</filename> a soubory <filename>convert*.m4</filename> obsahují nutné převody z typů parametrů v C++ na typy parametrů v C. Toto makro také generuje dokumentační komentáře Doxygen na základě souborů <filename>*_docs.xml</filename> a <filename>*_docs_override.xml</filename>.Kreslicí model CairoSystém souřadnic v Cairo, v obsluze <literal>draw_page</literal>, je automaticky otočen podle aktuálního otočení stránky. Normálně je v rozmezí tiskových okrajů, ale to můžete změnit pomocí metody <methodname>PrintOperation::set_use_full_page()</methodname>. Výchozí měrnou jednotkou jsou pixely zařízení. K výběru jiných jednotek použijte metodu <methodname>PrintOperation::set_unit()</methodname>.SchránkaWidget sloužící jako plocha pro kresleníModelChytrý ukazatel RefPtrVýběrWidget TreeViewNávrh uživatelského rozhraní by pro vyskakovací nabídku měl použít uzel <literal>popup</literal>. Například:Zobrazení (View)<classname>View</classname> je skutečný widget (<classname>Gtk::TreeView</classname>), který zobrazuje data modelu (<classname>Gtk::TreeModel</classname>) a umožňuje uživateli s nimi komunikovat. Může zobrazovat všechny sloupce modelu, nebo jen vybrané, a umí je zobrazovat různými způsoby.Widgety přizpůsobení lze zhruba rozdělit na ty, které používají a vyžadují pro hodnoty konkrétní jednotky, a ty, které pracují s libovolnými čísly.Argumenty metody <methodname>Action::create()</methodname> určují název akce a jak bude v nabídkách a nástrojových lištách vypadat.Základní koncept kreslení v Cairo obnáší definici „neviditelných“ cest a jejich následné obtažení a vyplnění, aby byly viditelné.Struktura sestaveníVolání metody <methodname>Cairo::Context::curve_to()</methodname> by mělo být pochopitelné na pohled. První pár souřadnic definuje řídící bod pro začátek křivky. Druhá sada souřadnic definuje řídící bod pro konec křivky a poslední sada souřadnic definuje cílový bod. Abyste si dokázali koncept řídících bodů snáze vizuálně představit, nakreslí se čára z obou řídících bodů do příslušných koncových bodů křivky. Tyto pomocné čáry jsou průsvitné, čehož se dosáhne zavoláním metody <methodname>set_source_rgba()</methodname>, která je jen rozšířenou variantou <methodname>set_source_rgb()</methodname>. Přebírá navíc čtvrtý argument určující alfakanál barvy (platné hodnoty jsou mezi 0 a 1).Vybraná položkaMakro deklaruje samotnou třídu a její vztah k podkladovému typu v C. Generuje některé interní konstruktory, definice členských typů <varname>gobject</varname>, příslušníky <function>gobj()</function>, registraci typu a metodu <function>Glib::wrap()</function>, spolu s dalšími věcmi.Čistící zpětné volání vám ve chvíli, kdy schránka nahradí stávající data jinými, dá prostor k uvolnění paměti, kterou jste použili u chování dat.Volba příkazové řádky předávaná do preprocesoru C.Volba příkazové řádky předávaná do kompilátoru C++.Komunikace mezi objekty <classname>Socket</classname> a <classname>Plug</classname> probíhá podle protokolu XEmbed. Tento protokol je implementován i v jiných vývojářských sadách (např. Qt), které umožňují stejnou úroveň integrace při vkládání widgetu Qt do widgetu GTK+ a naopak.Kompilátor vás upozorní, když použijete nesprávný typ. Například následující ukázka by měla způsobit chybu kompilace:Varianty connect*_once(), <methodname>Glib::SignalIdle::connect_once()</methodname>, <methodname>Glib::SignalTimeout::connect_once()</methodname>, <methodname>Glib::SignalTimeout::connect_seconds_once()</methodname>, jsou bezpečné z hlediska vláken pro libovolný případ, kde slot není vytvořený voláním <function>sigc::mem_fun()</function>, která představuje metodu třídy odvozené z <classname>sigc::trackable</classname>. Je to obdobné jako <methodname>Glib::Threads::Thread::create()</methodname>, která byla zmíněna v bodě 4.OmezeníKonstruktor pro <classname>ExampleWindow</classname> vytvoří nabídku pomocí <classname>UIManager</classname> (více informací viz <xref linkend="chapter-menus-and-toolbars"/>). Pak přidá do okna nabídku a nástrojovou lištu.Konstruktor pro <classname>Gtk::EventBox</classname> je:Aktuální stav <classname>Cairo::Context</classname> se dá uložit do interního zásobníku stavů a později jej obnovit do stejného stavu, jako byl při uložení. K tomu použijte metodu <methodname>save()</methodname> a metodu <methodname>restore()</methodname>. Může se to hodit, když potřebujete dočasně změnit např. tloušťku a barvu čáry (nebo jiné grafické nastavení), abyste něco nakreslili, a pak se vrátit k předchozímu nastavení. V takové situaci byste mohli zavolat <methodname>Cairo::Context::save()</methodname>, změnit grafické nastavení, nakreslit čáru a zavolat <methodname>Cairo::Context::restore()</methodname> pro obnovení původního grafického stavu. Dá se do sebe postupně vložit i více volání metod <methodname>save()</methodname> a <methodname>restore()</methodname>. Každé volání <methodname>restore()</methodname> pak obnoví stav z příslušného páru volání <methodname>save()</methodname>. <placeholder-1/>Výchozí <classname>CellRenderers</classname> a jeho výchozí chování běžně postačují, ale občas může být potřeba preciznější ovládání. Například tento ukázkový kód z <filename>gtkmm/demos/gtk-demo/example_treeview_treestore.cc</filename> připojuje widget <classname>Gtk::CellRenderer</classname> a říká mu, aby vykresloval data z různých sloupců modelu podle různých hledisek jejich podoby.Cílový widget vyšle tyto signály, v tomto pořadí: <placeholder-1/>Signály pro „táhni a upusť“ poskytuje třída <classname>DragContext</classname>, která obsahuje některé informace o operaci tažení a upuštění a může být použita k ovlivnění procesu. Například můžete najít zdrojový widget, nebo změnit ikonu taženého objektu, pomocí metody <methodname>set_icon()</methodname>. Podstatnější je, že byste měli ze své obsluhy signálu <literal>drag_data_received</literal> zavolat metodu <methodname>drag_finish()</methodname>, abyste dali vědět, jestli upuštění bylo úspěšné.Nejjednodušší je na to použít <ulink url="https://wiki.gnome.org/Projects/Jhbuild">jhbuild</ulink>. <application>jhbuild</application> je program, který usnadňuje sestavení veškerého softwaru GNOME díky výpočtům závislostí a sestavením věcí ve správném pořadí. V této části se dozvíte stručně něco o tom, jako ho nastavit, aby sestavil a nainstaloval <application>gtkmm</application> ze zdrojového repozitáře (git). Ohledně aktuálních informací o programu <application>jhbuild</application> se prosím podívejte do <ulink url="http://developer.gnome.org/jhbuild/unstable/">příručky k systému jhbuild</ulink>. Jestli budete potřebovat nějaké rady k použití programu <application>jhbuild</application>, měli byste o pomoc žádat v <ulink url="http://mail.gnome.org/mailman/listinfo/gnome-love">poštovní konferenci gnome-love</ulink>.Vstupní poleUdálost se nejprve doručí do widgetu, ve kterém se objevila. Pokud všechny obsluhy signálu v tomto widgetu vrátí <literal>false</literal> (což značí, že událost nebyl obsloužena), je signál propagován do rodičovského widgetu a vyslán zde. Tak se postupně pokračuje až do widgetu v nejvyšší úrovni, dokud se neobjeví nějaký, který událost obslouží.Událost se bude propagovat, dokud nedosáhne widgetu v nejvyšší úrovni, nebo dokud propagaci nezastavíte vrácením <literal>true</literal> z obsluhy události.Prakticky to předvádí příklad v examples/book/printing/advanced.Doplňující typedef umožňuje použít strukturu v hlavičkovém souboru bez vložení její plné definice, pouze jejím předeklarováním pomocí zopakování tohoto typedef. To znamená, že nemusíte vkládat hlavičkový soubor knihovny v C do svého hlavičkového souboru v C++ a tím ji udržet mimo veřejné API. <command>gmmproc</command> předpokládá, že je tato technika použita, takže pokud tomu tak není, uvidíte chybové hlášení kompilátoru.Prvních šet metod z předchozí tabulky se přepisuje také ve vlastních kontejnerech. Stručně jsou popsány v oddíle <link linkend="sec-custom-containers">Vlastní kontejnery</link>.První argument je <classname>slot</classname>, který si přejete mít zavolaný, když doběhne časový odpočet. Druhý argument je počet milisekund mezi voláními této metody. Obdržíte objekt <classname>sigc::connection</classname>, který můžete použít k deaktivaci napojení pomocí metody <methodname>disconnect()</methodname>:První argument je slot, který si přejete mít volaný, když nastane určená událost (viz třetí argument) na popisovači souboru, který jste určili druhým argumentem. Třetí argument může být jedna nebo více (pomocí <literal>|</literal>) hodnot z:Prvním argumentem je widget, který balíme. V našem příkladu to jsou tlačítka <classname>Button</classname>.První volání <methodname>connect()</methodname> je stejné, jak jsme již viděli minule, nic nového.První řádek výstupu je z programu <filename>plug</filename> po té, co byl informován, že byl vložen do objektu <classname>Socket</classname>. Druhý řádek byl vypsán programem <filename>socket</filename> v reakci na jeho signál <methodname>plug_added</methodname>. Pokud vše proběhne, jak bylo popsáno výše, mělo by okno programu <filename>socket</filename> vypadat zhruba takto:Následující příklad ukazuje obojí využití třídy <classname>EventBox</classname> – popisek je vytvořen tak, že je oříznut do malého boxu a nastaven tak, že kliknutí myší na něm způsobí ukončení programu. Změna velikosti okna odkryje další část popisku.Následující příklad předvádí, jak vytisknout nějaký vstup z uživatelského rozhraní. Ukazuje, jak implementovat <literal>on_begin_print</literal> a <literal>on_draw_page</literal>, a navíc jak sledovat stav tisku a jak aktualizovat nastavení tisku.Následující příklad ukazuje použití skupinových přepínačů <classname>RadioButton</classname>:Program v následujícím příkladu požaduje přepínače na příkazové řádce. Zdrojový kód ukazuje dva způsoby, jak zpracovat přepínače příkazové řádky ve spojení s <classname>Gtk::Application</classname>.Následující příklad ukazuje, jak nastavit kontext Cairo s červenou barvou pozadí a tloušťkou 2. Kterákoliv kreslicí funkce, která použije tento kontext, použije toto nastavení.Následuje jednoduchý příklad použití tříd <classname>Socket</classname> a <filename>Plug</filename>. Metoda komunikace mezi procesy je záměrně udržována velmi jednoduchá: <classname>Plug</classname> zapíše své ID do textového souboru nazvaného <filename>plug.id</filename> a proces s objektem <classname>Socket</classname> přečte ID z tohoto souboru. Ve skutečném programu byste mohli použít mnohem promyšlenější způsob meziprocesové komunikace.Následující program použív <classname>Gtk::AspectFrame</classname> k zobrazení kreslící oblasti, jejíž poměr stran bude vždy 2∶1, bez ohledu na to, jak uživatel mění velikost nadřazeného okna.Funkce <methodname>Cairo::Context::arc_negative()</methodname> je úplně stejná, jako <methodname>Cairo::Context::arc()</methodname>, jen úhly se počítají v opačném směru.Funkce <methodname>Cairo::Context::paint()</methodname> je zde použita k nastavení barvy pozadí okna. Tato funkce nepřebírá žádný argument a vyplní aktuální povrch (nebo oříznutou část povrchu) právě aktivní zdrojovou barvou. Po nastavení barvy pozadí okna nakreslíme kružnici tvořící obrys hodin a následně tu stejnou cestu ořízneme, abychom si zajistili, že naše následující čáry nepůjdou mimo hodiny.Funkce <methodname>move_item()</methodname>, <methodname>remove_item()</methodname> a <methodname>purge_items()</methodname> nemají žádný vliv na skutečné soubory, na které odkazují adresy URI, mění pouze seznam nedávných souborů.Skupina, která zachází s hodnotami jako s libovolnými čísly, zahrnuje widgety <classname>Range</classname> (<classname>Scrollbar</classname> a <classname>Scale</classname>), widget <classname>ScaleButton</classname> a widget <classname>SpinButton</classname>. Tyto widgety typicky „přizpůsobují“ přímo podle uživatelova ovládání myší nebo klávesnicí. S hodnotami přizpůsobení <parameter>lower</parameter> a <parameter>upper</parameter> zachází jako s rozmezími, v rámci kterých uživatel může měnit <parameter>value</parameter> v přizpůsobení. Standardně bude měnit jen údaj <parameter>value</parameter>.Implementace metody <function>wrap_init()</function> ve <filename>wrap_init.cc</filename> je generovaná skriptem <filename>generate_wrap_init.pl</filename>, ale deklarace ve <filename>wrap_init.h</filename> je psaná ručně, takže musíte upravit <filename>wrap_init.h</filename>, aby se funkce <function>wrap_init()</function> vyskytovala ve správném jmenném prostoru C++.Text popisku může být zarovnán pomocí metody <methodname>set_justify()</methodname>. Rovněž zvládá zalamování slov, které se dá aktivovat pomocí <methodname>set_line_wrap()</methodname>.Poslední řádek okno zobrazí a vstoupí do hlavní prováděcí smyčky <application>gtkmm</application>, která skončí, když je okno zavřeno. Vaše funkce <function>main()</function> pak vrátí příslušný úspěšný nebo chybový kód.Styl spojování čar se nastavuje pomocí funkce <methodname>Cairo::Context::set_line_join()</methodname>.Seznam je poskytován přes objekt <classname>TreeModel</classname> a sloupce tohoto modelu se přidávají do objektu <classname>ComboBox</classname>, který provádí zobrazení, pomocí metody <methodname>ComboBox::pack_start()</methodname>. Poskytuje to pružnost a typovou bezpečnost při kompilaci. Pokud ale tyto vymoženosti nejsou zrovna zapotřebí, je k dispozici zjednodušená třída <classname>ComboBoxText</classname> specializovaná čistě na textové položky.V následujících oddílech jsou podrobně rozebrána makra.Makro v následujícím příkladu dělá následující: <placeholder-1/>Makra, která používáte v souborech <filename>.hg</filename> a <filename>.ccg</filename>, často potřebují znát, jak převést typ C++ na typ C a naopak. <command>gmmproc</command> získává tyto informace z souboru <filename>.m4</filename> ve složce <filename>tools/m4/</filename>. Díky tomu se mohou volat funkce v C z implementací vašich metod v C++ se správným předáním parametrů do funkce C. Například takto se řekne <command>gmmproc</command>, jak má převést ukazatel na <classname>GtkTreeView</classname> na ukazatel na <classname>Gtk::TreeView</classname>: <placeholder-1/>Hlavní činností při internacionalizaci je vyhledání řetězců, které uživatele uvidí a jejich označení k překladu. Nemusíte je všechny označit naráz – když správně nastavíte potřebnou infrastrukturu projektu, bude vaše aplikace normálně fungovat bez ohledu na to, kolik řetězců jste internacionalizací pokryli.Maximální stáří položek v seznamu nedávno použitých položek se dá nastavit pomocí <methodname>Gtk::Settings::property_gtk_recent_files_max_age()</methodname>. Výchozí hodnota je 30 dní.ModelModel pro <classname>ComboBox</classname> se dá definovat a vyplnit úplně stejně, jako pro <classname>TreeView</classname>. Například můžete odvodit třídu <classname>ComboBox</classname> s jedním celočíselným a jedním textovým sloupce, nějak takto:Název knihovny, jako libnecomm.Název balíčků <application>gtkmm</application> se liší distribuci od distribuce (např. <application>libgtkmm-3.0-dev</application> v Debianu a Ubuntu nebo <application>gtkmm30-devel</application> ve Fedoře), takže si správný název balíčku budete muset najít ve správě balíčků své distribuce a pak jej nainstalovat, jak jste běžně zvyklí u jiných balíčků.Standardní dialogové okno tisku z GTK+ má tlačítko <guilabel>Náhled</guilabel>, ale náhled můžete spustit i přímo z aplikace: <placeholder-1/>Další už je podstatně zajímavější. <function>sigc::mem_fun()</function> je volaná se dvěma argumenty. První argument je <parameter>some_object</parameter>, což je objekt, na který náš nový slot bude ukazovat. Druhý argument je ukazatel na jednu z jeho metod. Tato konkrétní verze <function>sigc::mem_fun()</function> vytváří slot, který bude, když je „zavolán“, volat metodu určeného objektu, na kterou ukazuje, v tomto případě <methodname>some_object.on_button_clicked()</methodname>.Následující výraz: <placeholder-1/> vytvoří objekt <classname>Gtk::Application</classname> a uchová jej v chytrém ukazateli <classname>RefPtr</classname>. Tohle je zapotřebí ve všech aplikacích založených na <application>gtkmm</application>. Metoda <methodname>create()</methodname> tohoto objektu inicializuje <methodname>create()</methodname> a zkontroluje argumenty předané aplikaci z příkazového řádku, přičemž se dívá po standardních přepínačích, jako je <literal>--display</literal>. Přebírá je ze seznamu argumentů, a co nerozpozná, to ponechá pro další zpracování, nebo případně ignorování, ve vaší aplikaci. Tím se zajistí, že všechny aplikace <application>gtkmm</application> přijímají stejnou množinu standardních argumentů.Následujícídva řádky kódu vytvoří okno a nastaví jeho výchozí (počáteční) velikost:Počet desetinných míst můžete měnit pomocí metody <methodname>set_digits()</methodname>.Jediný rozdíl mezi tímto příkladem a příkladem s rovnými čárami je ve funkci <methodname>on_draw()</methodname>, ale je zde uvedeno pár nových konceptů a funkcí, tak si je pojďme ve stručnosti vysvětlit.Orientace widgetu <classname>Gtk::Scrollbar</classname> může být vodorovná nebo svislá.Do druhé skupiny patří widget <classname>Viewport</classname> a widget <classname>ScrolledWindow</classname>. Všechny tyto widgety používají pro svá přizpůsobení údaje v pixelech. Typicky přizpůsobují nepřímo přes posuvníky. Zatímco všechny widgety, které používají přizpůsobení, mohou buď vytvořit svá vlastní přizpůsobení, nebo použít ta, která dodáte, u této konkrétní skupiny widgetů bude obecně chtít nechat widgety, ať si vytvoří svá vlastní přizpůsobení.Název balíčku se nemění, když je vydána nová verze <application>gtkmm</application> s kompatibilním API/ABI. Jinak by neměla kompatibilní API/ABI. Takže nebuďte překvapeni, když například v Debianu najdete <application>gtkmm</application> 3.8 poskytované v balíčku <application>libgtkmm-3.0-dev</application>.Hlavním přínosem použití widgetů v rozsahu působnosti třídy je odhalení implementace třídy, místo rozhraní třídy v hlavičce třídy.Hlavním objektem je <classname>Gtk::PrintOperation</classname>, který se alokuje zvlášť pro jednotlivé tiskové operace. Abyste mohli obsluhovat kreslení stránky, musíte se napojit na jeho signály, nebo jej zdědit a přepsat jeho výchozí virtuální obsluhy signálů. <classname>PrintOperation</classname> automaticky obsluhuje všechna nastavení ovlivňující tiskovou smyčku.Proces psaní zdrojového kódu, který umožňuje jazykové překlady, se nazývá <literal>internacionalizace</literal>, což je často zkracováno na <literal>i18n</literal>. <literal>Lokalizace</literal>, zkracovaná na <literal>l10n</literal> je pak vlastní překlad textů vycházejících ze zdrojového kódu do jiných jazyků.Ukazatel průběhu umí také v průběhu zobrazovat nastavitelný text. K tomu slouží metoda <methodname>set_text()</methodname>.Účelem tohoto příkladu je ukázat kroky, které událost podstoupí, když je vyslána.Vrácená hodnota je <classname>sigc::connection</classname>, kterou můžete použít k zastavení sledování tohoto popisovače souboru pomocí jeho metody <methodname>disconnect()</methodname>. Obsluha signálu <parameter>slot</parameter> by měla být deklarovaná následovně:PravidlaStejné principy se používají pro signály, které mají více argumentů. Zde je jeden se třemi (pochází z <filename>&lt;gtkmm/textbuffer.h&gt;</filename>):Druhým způsobem, jak vytvořit skupinové přepínače, je nejprve vytvořit skupinu a pak do ní přidávat jednotlivé skupinové přepínače. Zde je příklad:V části kreslící oblouk můžete potkat novou funkci <methodname>close_path()</methodname>. Tato funkce se projevuje nakreslením rovné čáry z aktuálního do prvního bodu cesty. Je ale podstatný rozdíl mezi zavoláním <methodname>close_path()</methodname> a ručním nakreslením čáry zpět k počátečnímu bodu. Když použijete <methodname>close_path()</methodname>, budou čáry spolu pěkně spojené. Když místo toho použijete <methodname>line_to()</methodname>, budou čáry sice končit ve stejném bodě, ale Cairo je nijak speciálně nespojí.Vybrané řádkyObsluha signálu je <methodname>on_button_clicked()</methodname>.Jednopoložkové kontejnery jsou odvozené z třídy <classname>Gtk::Bin</classname>, která poskytuje pro synovský widget metody <methodname>add()</methodname> a <methodname>remove()</methodname>. Pro úplnost, <classname>Gtk::Button</classname> a <classname>Gtk::Window</classname> jsou technicky také jednopoložkové kontejnery, ale probírány jsou na jiném místě.Sloty napojené na objekty <classname>sigc::signal</classname> běží ve vlákně, které volá na signál <methodname>emit()</methodname> nebo <methodname>operator()</methodname>. <classname>Glib::Dispatcher</classname> se takto nechová: místo toho jeho napojené sloty běží ve vlákně, ve kterém byl objekt <classname>Glib::Dispatcher</classname> vytvořen (které musí mít hlavní smyčku glib). Pokud je objekt <classname>Glib::Dispatcher</classname> vytvořen v hlavním vlákně grafického uživatelského rozhraní (který tedy bude mít přijímací vlákno), libovolné pracovním vlákno pro něj může vysílat a mít napojené sloty, které mohou bezpečně spouštět funkce <application>gtkmm</application>. Zdrojový widget vyšle tyto signály, v tomto pořadí: <placeholder-1/>Standardní stromové modely (<classname>TreeStore</classname> a <classname>ListStore</classname>) jsou odvozené z <classname>TreeSortable</classname>, takže nabízejí funkci řazení. Například zavoláním <methodname>set_sort_column()</methodname> seřadíte model podle určeného sloupce. Nebo, když chcete složitější algoritmus řazení, poskytněte funkci zpětného volání do <methodname>set_sort_func()</methodname>.Textový sloupecTrik je v umístění uprostřed pixelu, kde chcete čáru nakreslit, čímž se garantuje, že dostanete požadované výsledky. Viz <ulink url="http://cairographics.org/FAQ/#sharp_lines">Časté dotazy a odpovědi ke knihovně Cairo</ulink>.Použití klíčového slova <literal>const</literal> v jazyce C++ není vždy zcela zřejmé. Možná si neuvědomujete, že <type>const Neco*</type> deklaruje ukazatel na <type>const Neco</type>. Ukazatel lze měnit, ale nelze měnit <type>Neco</type> na které ukazuje.Hodnota má přizpůsobitelný počet desetinných míst a velikost kroku je také nastavitelná. <classname>SpinButton</classname> má rovněž funkci „automatického opakování“: když držíte zmáčknuté tlačítko pro zvyšování nebo snižování hodnoty, může se volitelně hodnota začít měnit rychleji, v závislosti na tom, jak dlouho je tlačítko drženo.Hodnota zobrazená u stupnicových widgetů je ve výchozím stavu zaokrouhlovaná na jedno desetinné místo, stejně jako pole <literal>value</literal> v jejich objektu <classname>Gtk::Adjustment</classname>. Změnit to můžete pomocí metody <methodname>set_digits()</methodname>.Virtuální metoda <methodname>on_draw()</methodname> poskytuje kontext Cairo, který byste měli použít ke kreslení ve widgetu <classname>Gtk::DrawingArea</classname>. V <methodname>on_draw()</methodname> není potřeba si tento kontext Cairo ukládat a obnovovat.Funguje to tak, že nahrajete svoje zdrojové kódy do repozitáře git, kde se k nim mohou dostat překladatelé. Pak kontaktujete poštovní konferenci gnome-i18n a požádáte, aby vaši aplikaci přidali do <ulink url="http://l10n.gnome.org/module/">seznamu modulů k překladu</ulink>.Způsob, jakým <classname>Socket</classname> a <classname>Plug</classname> spolu fungují, je přes ID jejich oken. Jak <classname>Socket</classname>, tak <classname>Plug</classname>, mají ID, která lze získat přes jejich členské funkce <methodname>get_id()</methodname>. Použití těchto ID bude vysvětleno dále v kapitole <xref linkend="sec-connecting-plugs-sockets"/>.Widgety nemohou samy měnit uspořádání, když se změní velikost okna. Když je okno příliš malé, tak některé widgety nejsou vidět, a naopak u příliš velkého okna vzniká spousta nevyužitého místa.Šířka popisku se přizpůsobuje automaticky. Můžete vytvářet i víceřádkové popisky vloženém zalomení ("\n") do textového řetězce popisku.The window ID is: 69206019Pak upravte soubor <filename>.cc</filename>, aby uváděl správné typy. Například vaše funkce <function>main()</function> může vypadat nějak takto: <placeholder-1/>Pak spusťte program <filename>socket</filename>:Pak použijte <methodname>append_column()</methodname> k přidání sloupce zobrazení Column do zobrazení View. Upozorňujeme, že metoda <methodname>Gtk::TreeView::append_column()</methodname> je přepsaná, aby přijímala buď předsestavený widget <classname>Gtk::TreeView::Column</classname> nebo jen prostě <classname>TreeModelColumn</classname>, ze kterého vygeneruje příslušný widget <classname>Gtk::TreeView::Column</classname>.Pak si zkontrolujte, že máte aktualizovaný soubor <filename>POTFILES.in</filename> v podsložce <filename>po/</filename> (s tím vám může pomoci <command>intltool-update -M</command>), aby se překladatelé dostali vždy k aktuálnímu souboru <filename>vase_aplikace.pot</filename> a nejméně několik dní před plánovaným vydáním zmrazte řetězce a proveďte oznámení v konferenci gnome-i18n. V závislosti na množství řetězců ve vaší aplikaci a její popularitě se vám začnou objevovat soubory <filename>kod_jazyka.pro</filename> s překlady.Pro přidání widgetu na tuto pozici použijte <methodname>Gtk::TextView::add_child_at_anchor()</methodname>:Pak můžete definovat skutečné viditelné rozvržení nabídek a nástrojových lišt a přidat je do rozvržení uživatelského rozhraní v instanci <classname>UIManager</classname>. Tyto „řetězce uživatelského rozhraní“ používají formát XML, ve kterém byste měli použít názvy činností, které jste již vytvořili. Například:Je tu pár věcí, které v tomto příkladu stojí za zmínku. Ještě jednou, jediný skutečný rozdíl mezi tímto příkladem a předchozím je ve funkci <methodname>on_draw()</methodname>, takže se zaměříme jen na ni. Navíc, první část této funkce je hodně podobná předchozímu příkladu, takže ji přeskočíme.Existuje několik běžných omylů, na které byste si jistě přišli sami. Tato kapitola vám pomůže se jim vyhnout.Existuje řada proměnných s grafickými stavy, které se dají nastavit pro kontext Cairo. Nejběžnějšími atributy kontextu jsou barvy (použijte <methodname>set_source_rgb()</methodname> nebo <methodname>set_source_rgba()</methodname> pro průsvitné barvy), tloušťka čáry (použijte <methodname>set_line_width()</methodname>), vzorek čáry (použijte <methodname>set_dash()</methodname>), styl zakončení čáry (použijte <methodname>set_line_cap()</methodname>), styl spojení čar (použijte <methodname>set_line_join()</methodname>) a styly fontu (použijte <methodname>set_font_size()</methodname>, <methodname>set_font_face()</methodname> atd). Existují i další nastavení, jako jsou transformační matice, pravidla vyplňování, povolení vyhlazování a další. Více informací najdete v dokumentaci k API <ulink url="http://www.cairographics.org/cairomm/">cairomm</ulink>.V základu existuje pět rozdílných stylů, které můžete vidět na tomto obrázku:Existují i další věci, které si můžete přizpůsobit, včetně vytváření přerušovaných čar a jiného. Více informací najdete v dokumentaci k API Cairo.Od třídy <classname>Dialog</classname> je odvozeno několik dalších tříd, které by se vám mohly hodit. <classname>Gtk::MessageDialog</classname> se používá pro úplně nejjednodušší oznámení. Časem ale můžete potřebovat odvodit svá vlastní dialogová okna, abyste mohli poskytnout ucelenější funkcionalitu.Existuje několik voleb řídících, jak budou widgety balené, a některé z nich mohou být na první pohled matoucí. Pokud s tím budete mít problémy, je někdy dobrý nápad pohrát si s návrhářem grafického uživatelského rozhraní <application>glade</application>, abyste viděli, jak se co chová. Můžete se také rozhodnout používat API <application>Gtk::Builder</application> pro načtení vašeho návrhu GUI za běhu.Existuje ještě několik dalších kontejnerů, které také probereme.Je zde několik dalších volitelných argumentů: <placeholder-1/>Pro nabídky a nástrojové lišty existují speciální API, ale běžně byste s nimi měli zacházet dohromady pomocí třídy <classname>UIManager</classname>, s kterou nadefinujete akce <classname>Action</classname> a ty pak rozmístíte do nabídek a nástrojových lišt. Tímto způsobem můžete obsluhovat aktivaci akce namísto reagování na položky nabídky a nástrojové lišty odděleně. Navíc můžete přes akci naráz povolit nebo zakázat položku jak v nabídce, tak na nástrojové liště.Existují dvě základní strategie, které můžete použít: <placeholder-1/>Existují dvě vestavěné poziční značky <classname>Mark</classname> – <literal>insert</literal> a <literal>selection_bound</literal>, ke kterým se můžete dostat přes metody <methodname>get_insert()</methodname> a <methodname>get_selection_bound()</methodname> třídy <classname>TextBuffer</classname>.Existují dva postupy, jak vytvořit tlačítko. Můžete určit textový popisek v konstruktoru <classname>Gtk::Button</classname> nebo jej nastavit později pomocí <methodname>set_label()</methodname>.Existují dva způsoby, jak nastavit skupinovým přepínačům skupinu. První způsob je vytvořit tlačítka a později jim nastavit skupinu. Používají se jen první dva konstruktory. V následujícím příkladu vytvoříme novou třídu okna nazvanou <classname>RadioButtons</classname> a pak do ní vložíme tři skupinové přepínače:Existuje metoda pro kreslení z <classname>Gdk::Pixbuf</classname> do <classname>Cairo::Context</classname>. Vyrovnávací paměť <classname>Gdk::Pixbuf</classname> je užitečná jako obal okolo množiny pixelů tvořících obrázek, které můžete načíst ze souboru a pak s nimi různým způsobem pracovat.V <filename>examples/others/dnd</filename> najdete ucelenější příklad.Existuje jeden další volitelný argument: <placeholder-1/>Mohou nastat situace, kdy budete chtít seznam nedávných souborů změnit. Například, když je soubor přesunut nebo přejmenován, můžete potřebovat aktualizovat umístění souboru v seznamu nedávných souborů, aby neodkazoval na nesprávné místo. Aktualizovat umístění položky můžete pomocí <methodname>move_item()</methodname>.V tomto (nefunkčním) kódu je toho hodně k zamyšlení. Nejdříve pojďme pojmenovat zúčastněné věci:Proto <classname>RefPtr</classname> stejné jako <type>Neco*</type> pro parametr metody je <type>const Glib::RefPtr&lt;Neco&gt;&amp;</type> a stejné jako <type>const Neco*</type> je <type>const Glib::RefPtr&lt;const Neco&gt;&amp;</type>.K dispozici jsou standardní posuvníky. Měly by se používat jen k posunu v jiných widgetech, jako třeba v <classname>Gtk::Entry</classname> nebo <classname>Gtk::Viewport</classname>, ale většinou je stejně jednodušší použít widget <classname>Gtk::ScrolledWindow</classname>.Tyto závislosti mají zase své vlastní závislosti, včetně následujících aplikací a knihoven:Tyto interakce vyplývají ze skutečnosti, že, mimo jiné, třída dědící z <classname>sigc::trackable</classname> bude mít, prostřednictvím rozhraní, objekt <classname>std::list</classname> sledující sloty vytvořené voláním <function>sigc::mem_fun()</function> představující jejich nestatické metody (lépe řečeno, sleduje seznam zpětných volání, která nastavují na null napojené sloty při jejich destrukci). Jednotlivé objekty <classname>sigc::slot</classname> také udržují, přes <classname>sigc::slot_rep</classname>, svůj vlastní objekt <classname>sigc::trackable</classname> pro sledování objektů <classname>sigc::connection</classname>, které potřebuje kvůli informacím o jejich zániku, a také má funkci k odregistrování sebe sama z <classname>sigc::trackable</classname> pro odpojení nebo destrukci. Objekty <classname>sigc::signal</classname> také uchovávají seznam slotů, které budou aktualizovány voláním jejich metody <methodname>connect()</methodname> nebo voláním objektu <classname>sigc::connection</classname> vztahujícího se k takovému napojení.Tyto signály se chovají lehce jinak. Hodnota vrácená z obsluhy signálu říká, jestli událost byla „plně“ obsloužena. Pokud je hodnota <literal>false</literal>, pak <application>gtkmm</application> předá událost následující obsluze signálu v hierarchii. Pokud je hodnota <literal>true</literal>, není potřeba volat žádnou další obsluhu signálu.Tyto widgety se používají hlavně k dekoracím a rozvržení, takže u nich často nepotřebujete zachytávat události. Jsou předurčené k tomu, nemít žádné vlastní okno X, aby se dosáhlo lepší výkonnosti.Věci se přetahují ze <literal>zdrojů</literal> a upouští na <literal>cílech</literal>. Jednotlivé zdroje a cíle musí informovat o datových formátech, které umí odesílat a přijímat pomocí položek <classname>Gtk::TargetEntry</classname>. Cíl pro upuštění přijímá přetahovanou položku jen, když oba sdílejí kompatibilní položku <classname>Gtk::TargetEntry</classname>. Pak je vyslán příslušný signál, které říká obsluze signálu, která položka <classname>Gtk::TargetEntry</classname> byla použita.Soubor <filename>.defs</filename> popisuje výčtové typy a jejich možné hodnoty. Je generovaný pomocí skriptu <filename>enum.pl</filename>, který můžete najít ve složce <filename>tools</filename> knihovny glibmm. Například <placeholder-1/>Soubor <filename>.defs</filename> popisuje objekty a jejich funkce. Je generovaný pomocí skriptu <command>h2def.py</command>, který můžete najít ve složce <filename>tools/defs_gen</filename> knihovny glibmm. Například <placeholder-1/>Tento soubor <filename>.defs</filename> popisuje signály a vlastnosti. Je generovaný pomocí speciálního nástroje <filename>generate_extra_defs</filename>, která je v každém obalujicím projektu, jako je <filename>gtkmm/tools/extra_defs_gen/</filename>. Například <placeholder-1/>Tento soubor <filename>.defs</filename> popisuje virtuální funkce. Musíte jej napsat ručně. Existuje k tomu připravená kostra <filename>skeleton/src/skeleton_vfunc.defs</filename>, ze které můžete vyjít. Můžete se také podívat na soubor <filename>gtk/src/gtk_vfuncs.defs</filename> z <application>gtkmm</application>.Proměnná <varname>NAZEVAPLIKACE_LOCALEDIR</varname> bude použita později v souboru <literal>Makefile.am</literal> k definici makra, které se použije až budeme ve zdrojovém kódu inicializovat <application>gettext</application>.To umožňuje vazbám mezi různými programovacími jazyky implementovat jejich vlastní ekvivalenty (jako jsou konstruktory v C++), bez použití funkce <function>*_new()</function>. Často je to nutné, protože mohou ve skutečnosti vytvářet instanci odvozenin GType, do kterých přidají vlastní háčky pro obsluhu signálů a virtuálních funkcí.O této knizePro čtení této knihy se předpokládá dobrá znalost jazyka C++, včetně znalosti jak v C++ vytvořit program.Tato kniha vysvětluje klíčové koncepty <application>gtkmm</application>, což je API C++ pro vytváření uživatelského rozhraní. Seznamuje také v hlavními prvky uživatelského rozhraní, tzv. widgety.Tato kniha vysvětluje klíčové koncepty <application>gtkmm</application>, což je API C++ pro vytváření uživatelského rozhraní. Seznamuje také v hlavními prvky uživatelského rozhraní, tzv. widgety. I když jsou zmíněny třídy, konstruktory a metody, nezachází do přílišných podrobností. Je to proto, že úplné informace o API byste měli hledat v odkazované referenční dokumentaci.Způsobí to, že <application>gtkmm</application> zavolá určenou metodu kdykoliv, když se nic neděje. Můžete přidat prioritu (nižší čísla znamenají vyšší prioritu). Jsou dva způsoby, jak obsluhu signálu odstranit: zavolat <methodname>disconnect()</methodname> na objektu <classname>sigc::connection</classname>, nebo vrátit <literal>false</literal> z obsluhy signálu, která byla deklarována následovně:Tato kapitola vám představí některé z nejdůležitějších aspektů programování s <application>gtkmm</application>. Budou předvedeny na jednoduchém funkčním ukázkovém kódu. Nicméně se jedná jen o takovou ochutnávku, na podstatné věci se budete muset podívat do dalších kapitol.Tato třída implementuje okno „Hello World“. Je odvozená z <classname>Gtk::Window</classname> a má jako člena jeden widget <classname>Gtk::Button</classname>. Rozhodli jsme se využít konstruktor k provedené veškerých instalačních prácí s oknem, včetně nastavení signálů. Zde je s vynechanými komentáři:Tento příkaz sestaví a nainstaluje sérii modulů a bude pravděpodobně napoprvé trvat dosti dlouho. Při následujících spuštění by už ale měl být o něco rychlejší, protože bude potřebovat sestavit jen soubory, které se změnily od předchozího sestavení. Jinou variantou je, že po té co napoprvé sestavíte a nainstalujete <application>gtkmm</application>, můžete <application>gtkmm</application> znovu sestavit sebou samým (bez opětovného sestavování všech jeho závislostí) pomocí příkazu <command>jhbuild buildone gtkmm</command>.Tato chyba kompilátoru může vypadat nějak takto: <placeholder-1/> nebo takto: <placeholder-2/>Tento dokument, stejně jako mnoho dalšího skvělého softwaru, byl vytvořen zdarma dobrovolníky. Pokud víte o čemkoliv z <application>gtkmm</application>, co není ještě zdokumentováno, pouvažujte prosím o přispění do tohoto dokumentu.Tento příklad přidává do okna <classname>ToolPalette</classname> a <classname>DrawingArea</classname> a umožňuje uživateli přetáhnout ikony z palety nástrojů do kreslící oblasti. Paleta nástrojů obsahuje několik skupin položek. Rozbalovací seznamy umožňují uživateli měnit styl a otočení palety nástrojů.Tento příklad umožňuje kopírovat a vkládat data specifická pro aplikaci pomocí standardního textového cíle. I když je příklad jednoduchý, není ideální, protože nezjišťuje, jestli jsou dat v objektu <classname>Clipboard</classname> konkrétního typu.Tento příklad vytvoří <classname>Gtk::EntryCompletion</classname> a přidruží jej k widgetu <classname>Gtk::Entry</classname>. Doplňování využívá <classname>Gtk::TreeModel</classname> s možnými vstupy a některé doplňující činnosti.Tento příklad vytvoří tlačítko s obrázkem a popiskem.Tento příklad vytvoří okno se třemi tlačítky v mřížce. První dvě tlačítka jsou v horním řádku, zleva doprava. Třetí tlačítko je připojeno pod prvním, v novém nižším řádku a zabírá dva sloupce.V příkladu se vytvoří dva spustitelné programy: <filename>socket</filename> a <filename>plug</filename>. Myšlenka je taková, že <filename>socket</filename> má aplikační okno, které vloží widget z programu <filename>plug</filename>. Příklad je navržený tak, že než spustíte <filename>socket</filename>, musíte jako první spustit <filename>plug</filename>. Abyste viděli příklad v činnosti, spusťte následující příkazy v uvedeném pořadí ze složky z příklady:Tento příklad zobrazuje okno se třemi widgety pro určení rozmezí, které jsou všechny napojené na ten stejný widget přizpůsobení, spolu s párem ovládacích prvků pro přizpůsobení některých parametrů zmíněných výše a v kapitole o třídě <classname>Adjustment</classname>, takže nyní můžete vidět, jak ovlivňují fungování z pohledu uživatele.Tento příklad obsahuje widget <classname>Gtk::TreeView</classname> s modelem <classname>Gtk::ListStore</classname>.Tento příklad implementuje kontejner, který má dva synovské widgety nad sebou. Samozřejmě v praxi by v tomto případě bylo jednodušší prostě použít svislý <classname>Gtk::Box</classname>.Tento příklad implementuje widget, který kreslí Penroseův trojúhelník.Tento příklad je stejný jako příklad s <classname>ListStore</classname>, ale používá <methodname>TreeView::append_column_editable()</methodname> místo <methodname>TreeView::append_column()</methodname>.Tento příklad se velmi podobá příkladu <classname>ListStore</classname>, akorát odvozuje vlastní <classname>TreeView</classname>, aby se mohla přepsat  <literal>button_press_event</literal> a zapouzdřit kód stromového modelu do naší odvozené třídy. Viz kapitola <link linkend="sec-treeview-contextmenu">Vyskakovací kontextová nabídka v TreeView</link>.Tento příklad je hodně podobný příkladu pro <classname>TreeStore</classname>, ale má navíc dva sloupce, které ukazují, jestli se dá řádek přesunout a jestli může řádek přijmout jiný přetahovaný řádek. Příklad používá <classname>Gtk::TreeStore</classname>, ve které přepisuje virtuální funkce, jak bylo ukázáno v kapitole <link linkend="sec-treeview-draganddrop">Táhni a upusť ve stromovém zobrazení</link>.Tento příklad je velmi podobný příkladu s <classname>ListStore</classname>, ale místo něj používá <classname>Gtk::TreeStore</classname> a přidává potomky do řádků.Tento příklad ukazuje malý rozdíl mezi metodou <methodname>idle</methodname> a <methodname>timeout</methodname>. Když potřebujete metodu, která je volána pravidelně a rychlost není důležitá, pak budete chtít metodu <methodname>timeout</methodname>. Pokud potřebujete takovou, která je volána tak často, jak je to možné (např. výpočet fraktálu na pozadí), pak použijte metodu <methodname>idle</methodname>.Tento příklad ukazuje zarovnání tlačítko v okně doprava pomocí widgetu <classname>Alignment</classname>.Tento příklad ukazuje widget <classname>Gtk::Entry</classname> s pojmenovanou vyhledávací ikonou, při jejímž zmáčknutí vypíše text do terminálu.Tento příklad ukazuje widget <classname>Gtk::Entry</classname> s ukazatelem průběhu.Tento příklad ukazuje, jak načíst soubor <application>Glade</application> za běhu a jak přistupovat k widgetům přes odvozenou třídu.Tento příklad používá <classname>Gtk::Entry</classname>. Má také dvě zaškrtávací políčka <classname>CheckButton</classname>, kterými můžete přepínat příznaky editovatelnosti a viditelnosti.Tato výjimka může být vyhozená metodou, která je vygenerovaná pomocí _WRAP_METOD() s volbou errthrow.Má to následující výhody: <placeholder-1/>Ve skutečnosti se jedná o několik nástrojů, z nichž některé jsou záludnější, ale určitě fungují a byly použité v několika projektech.J k tomu zapotřebí použití tříd <classname>Gtk::ActionGroup</classname>, <classname>Gtk::Action</classname> a <classname>UIManager</classname>. U všech by se měla vytvářet instance pomocí jejich metody <methodname>create()</methodname>, která vrací <classname>RefPtr</classname>.Jedná se o úplný funkční příklad, který definuje a používá vlastní signály.Jedná se o příklad programu se dvěma vlákny, jedním vláknem pro grafické uživatelské rozhraní, podobně jako ve všech programech <application>gtkmm</application>, a jedním pracovním vláknem. Pracovní vlákno se vytvoří, když zmáčknete tlačítko <literal>Start work</literal>. Smaže se, když je práce dokončena, když zmáčknete tlačítko <literal>Stop work</literal>, nebo když zmáčknete tlačítko <literal>Quit</literal>.Ukázáné je to v příkladu s vyskakovací kontextovou nabídkou.Ukázané to je v příkladu drag_and_drop.Takovéto věci se v knihovně v jazyce C opravují snadno, tak neváhejte poslat příslušnému správci záplatu.Je to hodně podobné jednoduchému příkladu, aleJe to jedna z věcí, na které se ukazuje krása C++. Neměli byste přemýšlet o podtřídách widgetů GTK+ kvůli přepsání jeho akčních metod, to vám akorát přinese potíže. V GTK+ se k udělání věcí většinou vždy používají signály, vyjma situací, kdy píšete nový widget. Protože ale v C++ je přepisování metod tak snadné, je pro tento účel praktické a rozumné, vytvořit podtřídu tlačítka.Deklarace metody <methodname>pack_start()</methodname> vypadá takto:Není to záležitostí jen <application>gtkmm</application> nebo grafického uživatelského rozhraní. <application>gtkmm</application> používá <application>libsigc++</application> k implementaci vlastního zástupného obalení pro systém signálu <application>GTK+</application>, ale pro nové signály nepocházející z GTK+ můžete vytvářet signály čistě z C++, pomocí šablony <classname>sigc::signal&lt;&gt;</classname>.Toto makro se dá použít k obalení struktur, které nezapadají do žádné speciální kategorie.Toto makro vytvoří konstruktor s argumenty ekvivalentní funkci <function>*_new()</function> v C. Ve skutečnosti se nebude volat funkce <function>*_new()</function>, ale jednoduše vytvoří ekvivalentní konstruktor se stejnými typy argumentů. Vyžadována je hlavička konstruktoru v C++ a název funkce v C.Toto makro vytváří výchozí konstruktor bez argumentů.Toto makro deklaruje obalení pro jinou strukturu než <classname>GObject</classname> registrovanou pomocí <function>g_boxed_type_register_static()</function>.Toto makro deklaruje obalení pro neprůhlednou strukturu s počítáním referencí. Pro obalení v C++ nelze přímo vytvářet instance a lze je použít jen pomocí <classname>Glib::RefPtr</classname>.Toto makro deklaruje obalení pro jednoduchou přiřaditelnou strukturu, jako je <classname>GdkRectangle</classname>. Je to podobné, jako u <function>_CLASS_BOXEDTYPE</function>, jen struktura v C se nealokuje dynamicky.Toto makro deklaruje obalení pro typ, který je odvozený z <classname>GObject</classname>, ale jeho obalení není odvozené z <classname>Gtk::Object</classname>.Toto makro deklaruje obalení pro typ, který je odvozený z <classname>GTypeInterface</classname>.Toto makro deklaruje obalení pro typ, jehož obalení je odvozené z <classname>Gtk::Object</classname>, jako je widget nebo dialog.Toto makro deklaruje obalení pro neprůhlednou strukturu, která má funkce copy a free. Funkce new, copy a free se použijí pro vytváření instancí pomocí výchozího konstruktoru, pro kopírovací konstruktor a pro destruktor.Toto makro generuje výčet v C++ pro obalení výčtu v C. Musíte uvést požadovaný název v C++ a název podkladového výčtu v C.Toto makro generuje třídu výjimky v C++ odvozenou z Glib::Error, s výčtem Code a metodou code(). Musíte uvést požadovaný název v C++, název příslušného výčtu v C a prefix pro hodnoty výčtu v C.Toto makro generuje inicializační kód pro rozhraní.Toto makro generuje signál v C++ ve stylu libsigc++ pro obalení signálu objektu GObject v C. Ve skutečnosti generuje veřejně přístupnou metodu, jako je <function>signal_clicked()</function>, která vrací zástupný objekt. <command>gmmproc</command> používá soubor <filename>.defs</filename> k vyhledání typů parametrů C a převodní soubory <filename>.m4</filename> k vyhledání příslušných typů převodů.Toto makro generuje metodu C++ pro obalení vlastnosti objektu GObject v C. Musíte správně uvést název vlastnosti a typ C++, který chcete. <command>gmmproc</command> používá soubor <filename>.defs</filename> k vyhledání typu C a převodní soubory <filename>.m4</filename> k vyhledání příslušného typu převodů.Toto makro generuje metodu v C++ pro obalení funkce v C.Toto makro generuje metodu v C++ pro obalení virtuální funkce v C.Toto makro je podobné jako <function>_WRAP_METHOD()</function>, ale generuje jen dokumentaci pro metodu v C++, která obaluje funkci v C. Použijte v situaci, kdy musíte ručně napsat metodu, ale chcete použít dokumentaci, která by byla vygenerovaná, kdyby se generovala metoda.Toto makro jen vygeneruje pro výčet blok s dokumentací Doxygen. To se hodí pro výčty, které nemohou být obalené pomocí <function>_WRAP_ENUM()</function>, protože jsou definované komplexně (možná pomocí maker v C), ale přejete si, aby vygenerovaná dokumentace k výčtu byl součástí. Používá se se stejnou syntaxí, jako <function>_WRAP_ENUM()</function> a zpracovává ty samé volby (a však NO_GTYPE je jednoduše ignorováno, protože nezpůsobuje žádný rozdíl, když se generuje dokumentace k výčtu).Toto makro se použije, když inicializujete <literal>gettext</literal> ve svém zdrojovém kódu.To znamená, že kterákoliv metoda, která přebírá argument <type>const Glib::RefPtr&lt;BaseType&gt;</type>, může přebírat také <type>const Glib::RefPtr&lt;DerivedType&gt;</type>. Přetypování je implicitní, jako by to bylo pro normální ukazatel.Tento program obsahuje jednu třídu, <classname>MyArea</classname>, která je podtřídou <classname>Gtk::DrawingArea</classname> a obsahuje členskou funkci <methodname>on_draw()</methodname>. Tato funkce je zavolána vždy, když se má překreslit obrázek v kreslicí oblasti. Je jí předán ukazatel <classname>Cairo::RefPtr</classname> na <classname>Cairo::Context</classname>, který použijeme ke kreslení. Skutečný kreslicí kód nastavuje barvu, kterou chceme použít ke kreslení pomocí <methodname>set_source_rgb()</methodname>, která má argumenty definující červenou, zelenou a modrou složku požadované barvy (platné jsou hodnoty mezi 0 a 1). Po nastavení barvy vytvoříme novou cestu pomocí funkcí <methodname>move_to()</methodname> a <methodname>line_to()</methodname> a obtáhneme ji pomocí <methodname>stroke()</methodname>.Tím se poskytne struktura složek pro zdrojové soubory <filename>.hg</filename> a <filename>.ccg</filename> a generované soubory <filename>.h</filename> a <filename>.cc</filename>, se souborem <filename>filelist.amd</filename> pro Automake, který obsahuje soubory, kterými mohou být různé soubory používané ve významu obecných proměnných Automake. Struktura složek, po příslušném přejmenování složek, obvykle vypadá nějak takto: <placeholder-1/>Celé to vyžaduje řadu pravidel, kterých je třeba se držet při psaní vícevláknových aplikací pomocí <application>gtkmm</application>. Jsou uvedena níže, ale jedna věc stojí zvlášť za pozornost, a to, že je potřeba věnovat speciální péči odvozování tříd z <classname>sigc::trackable</classname>, protože efekty jsou nepředvidatelné (viz hlavně body 4 a 5 níže).Tento oddíl popisuje hlavně, co můžete očekávat v systému Linux, když použijete <ulink url="http://www.gnu.org/software/gdb/">ladicí program gdb</ulink>.V této kapitole je taková všehochuť mouder, obecných pokynů a rad k vytváření aplikací s <application>gtkmm</application>.Tato jednoduchá aplikace kreslí pomocí Cairo křivku a zobrazuje řídící body pro její jednotlivé konce.Tento příklad ukazuje, jak načíst soubor <application>Glade</application> za běhu a jak přistupovat k widgetům pomocí <application>Gtk::Builder</application>.Tímto se říká <command>gmmproc</command>, že <function>*_new()</function> v C má poslední parametr GError**, který by se měl ignorovat.Tato proměnná musí uvádět správný název knihovny a název této knihovny musí být použitý k vytvoření názvů proměnných <varname>_SOURCES</varname>, <varname>_LDFLAGS</varname> a <varname>_LIBADD</varname>. Je zcela legitimní použít jako součást názvů proměnných proměnné nahrazované skriptem <filename>configure</filename>, jako <varname>@NECOMM_API_VERSION@</varname>.Časové limityČasové limity, V/V a funkce při nečinnostiPro přístup k widgetu, například kvůli zavolání <methodname>show()</methodname> dialogového okna, použijte metodu <methodname>get_widget()</methodname>, které poskytnete název widgetu. Tento název by měl být zadaný v okně vlastností v <application>Glade</application>. Když se widget nepodaří najít, nebo je nesprávného typu, bude ukazatel nastaven na NULL. <placeholder-1/>Abyste toho dosáhli, měli byste použít normální metody <methodname>insert_column()</methodname> a <methodname>append_column()</methodname> z <classname>Gtk::TreeView</classname> a pak použít <methodname>get_column_cell_renderer()</methodname> pro získání objektu <classname>Gtk::CellRenderer</classname>, který sloupec používá.Když chcete do seznamu nedávných dokumentů přidat novou položku, v nejjednodušším případě stačí poskytnou adresu URI. Například:Pro přidání widgetů do oblasti akcí použijte metodu <methodname>add_action_widget()</methodname>. Budou baleny vedle výchozích tlačítek. Naopak, k jejich odebrání použijte metodu <methodname>remove_action_widget()</methodname>.Abychom vás uvedli do <application>gtkmm</application>, začneme s nejjednodušším možným programem. Tento program vytvoří okno o rozměrech 200 × 200 pixelů.Pro změnu výběru určete <classname>Gtk::TreeModel::iterator</classname> nebo <classname>Gtk::TreeModel::Row</classname>, takto:Když chcete změnit zobrazenou hodnotu, použijte metodu <methodname>set_fraction()</methodname>, které předáte číselnou hodnotu typu <type>double</type> v rozmezí 0,0 až 1,0, která se přepočítá na procenta.K řízení, které řádky mohou být vybrány, použijte metodu <methodname>set_select_function()</methodname> poskytující zpětné volání <classname>sigc::slot</classname>. Například:Chcete-li se přesvědčit, že jste vše udělali dobře, budete možná chtít přidat překlad do nového jazyka. K tomu je potřeba přejít do podsložky <filename>po</filename> ve vašem projektu a spustit následující příkaz: <placeholder-1/>K definici horké klávesy pro ovládání z klávesnice umístěte před jeden ze znaků popisku podtržítko a volitelný parametr <literal>mnemonic</literal> nastavte na <literal>true</literal>. Například:Abyste mohli detekovat kliknutí pravým tlačítkem myši, potřebujete obsluhovat signál <literal>button_press_event</literal> a kontrolovat, které přesně tlačítko bylo zmáčknuto. Protože <classname>TreeView</classname> normálně tento signál obsluhuje zcela sám, musíte buď přepsat výchozí obsluhu signálu v odvozené třídě <classname>TreeView</classname>, nebo použít místo metody <methodname>connect()</methodname> metodu <methodname>connect_notify()</methodname>. Než provedete cokoliv dalšího, bude nejspíše chtít zavolat výchozí obsluhu, takže kliknutí pravým tlačítkem způsobí nejprve vybrání řádku.K určení právě viditelné stránky použijte metodu <methodname>get_current_page()</methodname> a výsledek předejte metodě <methodname>get_nth_page()</methodname>, která vrátí ukazatel na aktuální widget. K programové změně aktuální stránky použijte metodu <methodname>set_current_page()</methodname>.Pro určení, která klávesa byl zmáčknuta nebo uvolněna, můžete číst hodnotu <varname>GdkEventKey::keyval</varname> a porovnat ji s konstantou v hlavičkovém souboru <filename>&lt;gdk/gdkkeysyms.h&gt;</filename>. Stav modifikačních kláves (Shift, Ctrl, atd.) je dostupný v podobě bitových příznaků v <varname>GdkEventKey::state</varname>.Ke zjištění, která stránka je právě viditelná, použijte metodu <methodname>get_current_page()</methodname>. Vrátí vám číslo stránky a s tímto číslem zavolejte <methodname>get_nth_page()</methodname>, abyste získali ukazatel na aktuální synovský widget.Chcete-li zjistit, kterou položku uživatel v rozbalovacím seznamu zvolil, pokud vůbec nějakou, zavolejte metodu <methodname>ComboBox::get_active()</methodname>. Ta vrací <classname>TreeModel::iterator</classname>, který můžete použít jako zpětný odkaz na objekt <classname>Row</classname>, abyste mohli číst hodnoty ve vašich sloupcích. Třeba můžete číst celočíselnou hodnotu ID z modelu, zatímco uživateli jste v rozbalovacím seznamu zobrazili pouze pro člověka čitelný textový popis. Například:Abyste mohli v <application>gtkmm</application> kreslit pomocí Cairo, musíte nejprve vytvořit objekt <classname>Cairo::Context</classname>. Tato třída udržuje všechny parametry s grafickými stavy, které popisují, jak se kreslení provádí. Patří k nim takové informace, jako je tloušťka čáry, barva, plocha, která se má kreslit a mnoho dalších věcí. Díky tomu může aktuální kreslicí funkce přebírat méně parametrů a rozhraní je tak jednodušší. V <application>gtkmm</application> se <classname>Cairo::Context</classname> vytváří voláním funkce <methodname>Gdk::Window::create_cairo_context()</methodname>. Protože kontext Cairo je objekt s počítáním referencí, vrací tato funkce objekt <classname>Cairo::RefPtr&lt;Cairo::Context&gt;</classname>.Abyste to mohli provést, musíte volat v pravidelných intervalech metodu <methodname>pulse()</methodname>. Můžete také pomocí metody <methodname>set_pulse_step()</methodname> zvolit velikost kroku.Abyste nakreslili elipsu, můžete změnit měřítko na různé hodnoty ve směru X a Y v transformační matici. Například, když chcete nakreslit elipsu se středem v <varname>x</varname>, <varname>y</varname> a s šířkou <varname>width</varname> a výškou <varname>height</varname>: <placeholder-1/>Jestli chcete tuto funkcionalitu zprovoznit, musíte vytvořit objekt <classname>EntryCompletion</classname> a poskytnout jej widgetu <classname>Entry</classname> přes metodu <methodname>set_completion()</methodname>.Když potřebujete vědět, které řádky uživatel označil, získejte z <classname>TreeView</classname> objekt <classname>Gtk::TreeView::Selection</classname>, takto:Když chcete najít, jaké cíle jsou aktuálně v objektu <classname>Clipboard</classname> dostupné pro vkládání, zavolejte metodu <methodname>request_targets()</methodname> a určete jí svoji metodu, která se má zavolat s informacemi. Například:Když chcete zjistit, které typy obsluhy signálu můžete na signál napojit, podívejte se do referenční dokumentace nebo do hlavičkového souboru. Zde je příklad deklarace signálu, která můžete vidět v hlavičkových souborech <application>gtkmm</application>:Když jej chcete přinutit, aby se automaticky dorovnával na nejbližší násobek <literal>step_increment</literal>, použijte <methodname>set_snap_to_ticks()</methodname>.K vytvoření instance <classname>Gtk::MenuBar</classname> nebo <classname>Gtk::Toolbar</classname>, které chcete skutečně zobrazit, byste měli použít metodu <methodname>UIManager::get_widget()</methodname> a pak přidat widget do kontejneru. Například:Když chcete vytvořit instanci jen jednoho okna, nebo jen jednoho synovského widgetu, můžete určit název widgetu jako druhý parametr. Například <placeholder-1/>Pro vyhledání nedávno použitých souborů <classname>RecentManager</classname> poskytuje několik funkcí. K vyhledání konkrétní položky podle její URI můžete použít funkci <methodname>lookup_item()</methodname>, která vrací třídu <classname>RecentInfo</classname>. Pokud zadaná adresa URI v seznamu nedávných souborů neexistuje <methodname>lookup_item()</methodname> vyhodí výjimku <classname>RecentManagerError</classname>. Například:Aby číselník <classname>SpinButton</classname> cyklicky přecházel mezi horní a dolní hranicí, použijte metodu <methodname>set_wrap()</methodname>.Když chcete získat instanci <application>gtkmm</application> z instance GObject v C, použijte <methodname>Glib::wrap()</methodname>. NapříkladKdyž chcete do vlastního dialogového okna zabalit widgety, měli byste je balit do instance <classname>Gtk::Box</classname> dostupné přes <methodname>get_content_area()</methodname>. Když chcete jen přidat tlačítko do dolní části dialogového okna, můžete použít metodu <methodname>add_button()</methodname>.Abyste uživateli zabránili v psaní nečíselných znaků do vstupního pole, předejte metodě <methodname>set_numeric()</methodname> hodnotu <literal>true</literal>.K programové změně vybrané stránky použijte metodu <methodname>set_current_page()</methodname>.Abyste přijímali události klávesnice, musíte nejprve zavolat funkci <methodname>Gtk::Widget::add_events()</methodname> s bitovou maskou událostí, které vás zajímají. Obsluha signálu události obdrží argument, který závisí na typu události. Pro události klávesnice je to <type>GdkEventKey*</type>. Jak je popsáno v <link linkend="sec-xeventsignals">dodatku</link>, obsluha signálu události vrací hodnotu <type>bool</type>, kterou říká, že signál byl plně obsloužen (<literal>true</literal>) nebo povolí propagaci události (<literal>false</literal>).Když chcete v jednom sloupci zobrazení vykreslit více než jeden sloupec z modelu, musíte vytvořit widget <classname>TreeView::Column</classname> ručně a k přidání sloupce modelu do něj použít <methodname>pack_start()</methodname>.Když chcete reagovat na uživatelovo kliknutí na řádek nebo rozsah řádků, připojte nějak takto signál:Pro získání stavu widgetu <classname>ToggleButton</classname> můžete použít metodu <methodname>get_active()</methodname>. Ta vrací <literal>true</literal>, když je tlačítko „dole“. Můžete také stav tlačítka nastavit pomocí <methodname>set_active()</methodname>. Všimněte si, že když to uděláte a aktuální stav se tím změní, způsobí to vyslání signálu „clicked“, což je přesně to, co obvykle chcete.Když chcete vidět, kde je výjimka vyhozena, můžete použít v <application>gdb</application> příkaz <userinput>catch throw</userinput>. <placeholder-1/>K nastavení záhlaví stránky použijte metodu <methodname>set_page_title()</methodname>. Nadpis a postranní obrázeki stránky mohou být nastaveny pomocí metod <methodname>set_page_header_image()</methodname> a <methodname>set_page_side_image()</methodname>.Ohledně nastavení systému <application>jhbuild</application> se řiďte základními instalačními instrukcemi z <ulink url="http://developer.gnome.org/jhbuild/unstable/">příručky k systému jhbuild</ulink>. Po té, co <application>jhbuild</application> nainstalujete, měli byste nakopírovat ukázkový konfigurační soubor <application>jhbuild</application> do své domovské složky spuštěním následujícího příkazu ve složce, kde se nachází <application>jhbuild</application>: <screen>$ cp examples/sample.jhbuildrc ~/.jhbuildrc</screen>K zobrazení vyskakovací nabídky použijte metodu <methodname>popup()</methodname> třídy <classname>Gtk::Menu</classname>, poskytněte ji identifikátor tlačítka a čas aktivace tak, jak to dělá signál <literal>button_press_event</literal>, který stejně budete muset obsluhovat. Například:Pro zjednodušení kompilace používáme <literal>pkg-config</literal>, který najdete ve všech (správně nainstalovaných) instalacích <application>gtkmm</application>. Tento program „zná“ přepínače, které jsou zapotřebí ke kompilaci programu, který používá <application>gtkmm</application>. Přepínač <literal>--cflags</literal> způsobí, že <literal>pkg-config</literal> vypíše seznam složek, ve kterých kompilátor hledá hlavičkové soubory, a přepínač <literal>--libs</literal> zažádá o seznam knihoven, které má kompilátor přilinkovat, a o složky, ve kterých je má hledat. Zkuste si to spustit ručně v shellu, abyste viděli výsledky pro váš systém.K určení, že nějaký text ve vyrovnávací paměti by měl být nějak naformátován, musíte definovat formátovací značku, která si drží informaci o formátování, a pak ji použít na část textu. Příklad definice formátovací značky a jejích vlastností:Pro použití instance <application>gtkmm</application> s funkcí C, které požaduje instanci GObject v C, použijte funkci <function>gobj()</function>, přes kterou získáte ukazatel na podkladovou instanci GObject. NapříkladPro částečné obejití byste mohli napsat do zdrojového kódu těsně před řetězec komentář, ve kterém řeknete překladatelům, aby použili speciální znak, pokud je v jejich jazyce dostupný. Pro angličtinu pak můžete vytvořit překlad do americké angličtiny <filename>en_US.po</filename>, ve kterém použijete speciální znak.Přepínací tlačítka (ToggleButton)Přepínací tlačítko (ToggleButton)Referenční příručka třídy ToolItemReferenční příručka třídy ToolItemGroupPaleta nástrojů (ToolPalette)Příklad s ToolPaletteReferenční příručka třídy ToolPaletteVysvětlivka (Tooltip)Dokumentace k objektu TooltipVysvětlivkyVysvětlivky jsou jednoduchá informační okna, která vyskočí, když nad widgetem postojíte pár vteřin ukazatelem. K nastavení vysvětlivky libovolného <classname>Widgetu</classname> použijte <methodname>set_tooltip_text()</methodname>. Objekty <classname>Gtk::ToolItem</classname> nejsou <classname>Widgety</classname>, ale kvůli snadnému používání mají stejnou metodu. Pro pokročilé vysvětlivky, které například zobrazují k textu i obrázek, slouží <classname>Gtk::Tooltip</classname>.TreeModel::iterator iter = refTreeSelection-&gt;get_selected();
if(iter) // Když je něco vybráno
{
  TreeModel::Row row = *iter;
  // udělat něco s řádkem
}Referenční příručka k TreeModelSortReferenční příručka k TreeSortableTreeStoreTreeStore (pro hierarchii)TreeView – táhni a upusťTreeView – editovatelné buňkyTreeView – ListStoreTreeView – vyskakovací kontextová nabídkaTreeView – TreeStoreNejbližší konkurencí <application>gtkmm</application> je Qt od Trolltechu, takže se na něj pojďme podívat blíže.Zkuste příklad spustit a zvýšit zátěž systému. Horní ukazatel průběhu bude nabývat rovnoměrně, dolní se zpomalí.Než budeme pokračovat, zkuste si ji přeložit a spustit. Měli byste vidět něco takového:Dva doplňující parametry jsou volitelné, pro případ kdy je rozhraní odvozeno z jiného rozhraní, což by mělo být, když GInterface má jako předpoklad jiný GInterface. Příklad z <filename>loadableicon.hg</filename>: <placeholder-1/>Typicky by se naše obalujíc knihovna nazývala libnecomm. Můžeme začít zkopírováním <ulink url="http://git.gnome.org/browse/mm-common/tree/skeletonmm">kostry zdrojového stromu</ulink> z modulu mm-common. <placeholder-1/>Změny v uživatelském rozhraní jsou rychleji viditelné, takže se dobře vylepšuje.UIManagerNejde předeklarovat strukturyIntegrace se standardními iostream není bohužel úplně bezbolestná. Když provádíte výstup do <classname>ostream</classname> pomocí <function>operátoru &lt;&lt;</function>, <application>gtkmm</application> převádí řetězce <classname>Glib::ustring</classname> na kódování podle národního prostředí (které nemusí být UTF-8). Obdobně, získání řětězců <classname>Glib::ustring</classname> z <classname>istream</classname> pomocí <function>operátoru &gt;&gt;</function> způsobí převod opačným směrem. Tohle schéma se ale naruší, když půjdete skrz <classname>std::string</classname>, např. vložením textu z datového proudu do <classname>std::string</classname> a jeho implicitním převodem na <classname>Glib::ustring</classname>. Pokud řetězec obsahuje jiné znaky, než jen ASCII, a aktuální národní prostředí není kódované v UTF-8, ve výsledkem poškozený řetězec <classname>Glib::ustring</classname>. Můžete to obejít ručním převodem. Například když chcete získat <classname>std::string</classname> z <classname>ostringstream</classname>: <placeholder-1/>Unix a LinuxVyjma situace, kdy je kontejner oknem nejvyšší úrovně odvozeným z <classname>Gtk::Window</classname>, měli byste pravděpodobně ve svém konstruktoru také volat <methodname>Gtk::Widget::set_has_window(false)</methodname>. Znamená to, že váš kontejner nevytváří své vlastní okno <classname>Gdk::Window</classname>, ale používá okno rodiče. (Všimněte si rozdílu mezi <classname>Gtk::Window</classname> and <classname>Gdk::Window</classname>.) Pokud váš kontejner nepotřebuje svůj vlastní objekt <classname>Gdk::Window</classname> a není odvozený z <classname>Gtk::Window</classname>, musíte rovněž přepsat metodu <methodname>on_realize()</methodname>, jak bylo popsáno v oddíle <link linkend="sec-custom-widgets">Vlastní widgety</link>. A pokud váš kontejner nekreslí přímo do podkladového <classname>Gdk::Window</classname>, budete muset kvůli vylepšení výkonu pravděpodobně volat <methodname>set_redraw_on_allocate(false)</methodname>.Na rozdíl od řešení Unikódu v podobě UCS-2 ve Windows, nejsou zapotřebí žádné speciální volby kompilátoru pro zpracování řetězcových literálů a nevznikají tak spustitelné programy a knihovny s podporou Unikódu, které by byly nekompatibilní s ASCII.Na rozdíl od jiných widgetů v tomto oddíle, obsahuje widget <classname>Paned</classname> ne jeden, ale dva synovské widgety, po jednom v každém z panelů. Proto musíte místo metody <methodname>add()</methodname> použít <methodname>add1()</methodname> a <methodname>add2()</methodname>.Neobvyklá slovaAktualizujte svůj <literal>DISTCLEANFILES</literal>: <placeholder-1/>Použijte <classname>Glib::Dispatcher</classname> k vyvolání funkcí <application>gtkmm</application> z pracovních vláken (podrobněji bude rozebráno dále).Použijte <methodname>Gtk::Builder::get_widget_derived()</methodname> nějak takto: <placeholder-1/>Používejte GNU <application>autoconf</application> a <application>automake</application>! Jsou to vaši přátelé :-) <application>Automake</application> prozkoumá soubory v C, určí, jak na sobě navzájem závisí, a vygeneruje <filename>Makefile</filename>, takže lze soubory zkompilovat ve správném pořadí. <application>Autoconf</application> umožňuje automatickou konfiguraci instalace softwaru, která se vyrovná se spoustou specialit jednotlivých systémů, takž dosáhnete lepší přenositelnosti.Pro přidání karet do objektu <literal>Notebook</literal> použijte metody <methodname>append_page()</methodname>, <methodname>prepend_page()</methodname> a <methodname>insert_page()</methodname>, kterým poskytnete synovský widget a název karty.K přidání stránek do widgetu <classname>Assistant</classname> použijte metody <methodname>append_page()</methodname>, <methodname>prepend_page</methodname> a <methodname>insert_page()</methodname>. Ke každé stránce poskytněte synovský widget.Použijte poslední parametr GError** funkce v C k vyhození výjimky.Použijte poslední parametr GError** virtuální funkce v C (pokud existuje) k vyhození výjimky.Tato makra použijte, když obalujete jednoduchou strukturu nebo boxovyný typ, který poskytuje přímý přístup ke svým datovým členům, aby se vytvořily funkce pro získávání a nastavování datových členů.Tato makra použijte k poskytnutí funkcí pro získávání a nastavování datového člena, který je typu ukazatel. Pro funkci na získávání to vytvoří dvě metody, jednu konstantní a jednu nekonstantní.Tato makra použijte k poskytnutí funkcí pro získávání a nastavování datového člena typu <classname>GObject</classname>, u kterého musí být před jeho vrácením zvýšeno počitadlo referencí.Používá se ve spojení s volbou <literal>slot_name</literal> k určení názvu lepicí funkce zpětného volání, která se stará o získání slotu a jeho zavolání. Adresa tohoto zpětného volání je rovněž předaná do funkce C, kterou metoda obaluje.Užitečné metodySnadné použití objektů AdjustmentPoužívání Glib::DispatcherPoužívání widgetů <application>gtkmm</application>Použití modeluPoužívání odvozených widgetůPoužívání jiných znaků než ASCII v řetězcíchPoužívání vývojové verze <application>gtkmm</application> z repozitáře gitVineRovněž předpokládáme použití nástrojů autotools (napří. <application>automake</application> a <application>autoconf</application>) pro sestavení vašeho projektu a tím pádem i použití <ulink url="http://git.gnome.org/browse/gnome-common/tree/autogen.sh"><literal>./autogen.sh</literal> z <application>gnome-common</application></ulink>, který se mimo jiné věci stará o inicializaci <application>intltool</application>.Probírán je také widget <classname>Gtk::Paned</classname>, který umožňuje rozdělit okno do dvou oddělených „panelů“. Tento widget ve skutečnosti obsahuje dva synovské widgety, ale tento počet je pevně dán, takže je správné jej zařadit sem.Právě jsme vám řekli, že signál <literal>clicked</literal> tlačítka očekává volání metody bez argumentu. Všechny signály mají obdobné požadavky – nemůžete zaháčkovat funkci se dvěma argumenty na signál, který neočekává žádný (ledaže použijete adaptér, jako je <function>sigc::bind()</function>). Proto je důležité znát, jaký typ obsluhy signálu byste měli očekávat, že se k danému signálu napojí.Jednoduchou deklarací <literal>group</literal> typu <classname>Gtk::RadioButton::Group</classname> vytvoříme novou skupinu. Následně vytvoříme tři skupinové přepínače pomocí konstruktoru, který z nich udělá členy skupiny <literal>group</literal>.Voláme metodu <methodname>Cairo::Context::scale()</methodname> a předáváme jí šířku a výšku kreslicí oblasti. Tím se přepočítá systém souřadnic v uživatelském prostoru, jako by tato šířka a výška widgetu byly obojí rovny 1,0 „jednotek“. K tomuto systému přepočítání není žádný konkrétní důvod, ale občas to může kreslení zjednodušit.Všechny naše soubory <filename>.hg</filename> a <filename>.ccg</filename> musíme uvést v <filename>skeleton/src/filelist.am</filename>, typicky v proměnné <varname>files_hg</varname>.Nyní v několika metodách používáme std::vector místo mezilehlého typu *Handle, aby bylo API čistší.Měli bychom vytvořit své první soubory <filename>.hg</filename> a <filename>.ccg</filename> pro obalení některého z objektů v knihovně C. Jeden pár ukázkových zdrojových souborů již existuje: <filename>skeleton.ccg</filename> a <filename>skeleton.hg</filename>. Podle potřeby si vytvořte kopie těchto souborů.Potom zaháčkujeme obsluhu signálu na signál <literal>clicked</literal> widgetu <literal>m_button</literal>. V ní vypisujeme přátelské uvítání do <literal>stdout</literal>.Řekli jsme <application>gtkmm</application>, aby vložil tři widgety <classname>RadioButton</classname> do stejné skupiny tak, že jsme získali skupinu pomocí <methodname>get_group()</methodname> a použili <methodname>set_group()</methodname>, abychom ostatním widgetům <classname>RadioButton</classname> řekli, že mají tuto skupinu sdílet.Nyní si vysvětlíme jednotlivé řádky příkladu.Rádi bychom se dozvěděli, když budete mít problém se studiem <application>gtkmm</application> podle tohoto dokumentu a odměnou za to vám bude jeho vylepšení. Na více informací se prosím podívejte do kapitoly <link linkend="chapter-contributing">Přispívání</link>.Zaháčkovali jsme ji k objektu <classname>Gtk::Button</classname> nazvanému <varname>button</varname>.Nyní už toho víme dost na to, abychom se mohli podívat na nějaký funkční příklad. A jak už je v programování tradicí, začneme aplikací „Ahoj Světe“ a lá <application>gtkmm</application>:Co když widget změní nastavení polí <parameter>upper</parameter> nebo <parameter>lower</parameter> ve svém objektu <classname>Adjustment</classname>, třeba když uživatel přidá další text do textového widgetu? V tomto případě vyšle signál <literal>changed</literal>.Jaký je rozdíl mezi rozestupy (nastavují se při vytváření boxu) a odsazením (nastavuje se při balení)? Rozestupy se přidávají mezi objekty a odsazení se přidává na některé strany widgetu. Následující obrázek by to měl názorně objasnit:Kdy <varname>pixbuf</varname> přejde mimo rozsah působnosti, provede se na pozadí <methodname>unref()</methodname> a dále se o něj již nemusíte starat. Nebylo zde žádné <literal>new</literal>, tak není ani žádné <literal>delete</literal>.Pokud musí být konstruktor částečně napsán ručně, protože například parametry funkce <function>*_new()</function> v C neodpovídají přímo vlastnostem objektu, nebo protože funkce <function>*_new()</function> v C toho dělá více, než že jen zavolá <function>g_object_new()</function>, pak se může pro ušetření práce použít v souboru <filename>.ccg</filename> makro <function>_CONSTRUCT()</function>. To vyžaduje sérii názvů vlastností a hodnoty. Příklad z <filename>button.ccg</filename>: <placeholder-1/>Když cíl pro upuštění přijme přetahovanou položku, jsou vyslány některé signály, podle toho, jaká akce byla vybrána. Například, uživatel může držet zmáčknutou klávesu <keycap>Shift</keycap>, aby řekl že chce <literal>přesouvat</literal> a ne <literal>kopírovat</literal>. Pamatujte, že uživatel může vybrat jen akci, kterou jste určili ve svém volání metod <methodname>drag_dest_set()</methodname> a <methodname>drag_source_set()</methodname>.Když je program přerušen kvůli neobsloužené výjimce C++, je občas možné použít ladicí program k nalezení místa, kde byla výjimka vyhozena. Pokud je výjimka vyhozena v obsluze signálu, je to náročnější, než obvykle.Když odvozujete z třídy <classname>Gtk::Container</classname>, měli byste přepsat následující virtuální metody: <placeholder-1/>Když odvozujete z třídy <classname>Gtk::Widget</classname>, měli byste přepsat následující virtuální metody. Metody označené „(volitelné)“ není potřeba přepsat ve všech vlastních widgetech. U základních metod třídy to může být vhodné. <placeholder-1/>Když <classname>Button</classname> vyšle svůj signál <literal>clicked</literal>, zavolá se <methodname>on_button_clicked()</methodname>.Když je aplikace spuštěna, knihovna <application>gettext</application> zkontroluje systémovou složku, jestli v ní je soubor <filename>.mo</filename> pro národní prostředí uživatele (národní prostředí můžete nastavit například příkazem „export LANG=cs_CZ.UTF-8“ z příkazové řádky). Až později běžící aplikace narazí na volání <literal>gettext</literal>, podívá se po překladu konkrétního řetězce. Pokud jej nenajde, použije se řetězec původní.Když je ukazatel myši nad tlačítkem a zmáčknete tlačítko myši, je zavoláno <methodname>on_button_press()</methodname>.Když uživatel žádá o zkopírování nějakých dat, měli byste objektu <classname>Clipboard</classname> říci, jaké cíle jsou k dispozici a poskytnout metodu zpětného volání, kterou může použít k získání dat. V tuto chvíli byste si měli uložit kopii dat, abyste je mohli poskytnout, až schránka zavolá vaše zpětné volání v reakci na uživatelovo vložení.Když uživatel požádá o vložení dat ze schránky, tj. z objektu <classname>Clipboard</classname>, měli byste si požádat o konkrétní formát a poskytnout metodu zpětného volání, která bude zavolána na skutečná data. Například:Když uživatel zadává libovolný text, nemusí být dostačující napojit se na signál <literal>changed</literal>, který se vysílá po napsání každého znaku. Nevyšle se totiž při zmáčknutí klávesy <keycap>Enter</keycap> uživatelem. Zmáčknutí klávesy <keycap>Enter</keycap> nebo přesun zaměření na jiný widget může znamenat, že uživatel dokončil zadávání textu. Abyste byli o této události informováni, napojte se takto na signály <classname>activate</classname> a <literal>focus_out_event</literal> z třídy <literal>Entry</literal> <placeholder-1/> Signály <literal>changed</literal> třídy <classname>ComboBox</classname> i <classname>Entry</classname> jsou vysílány při každé změně. Je tak jedno, na který z nich se napojíte. Ale signál <literal>focus_out_event</literal> je zde použitelný pouze z třídy <classname>Entry</classname>.Při použití <function>_CLASS_GOBJECT()</function> by konstruktor měl být chráněný (místo veřejný) a jednotlivé konstruktory by měly mít příslušná makra <function>_WRAP_CREATE()</function> ve veřejné části. Tím se zabrání vytváření instancí třídy bez použití <classname>RefPtr</classname>. Například: <placeholder-1/>Když používáte <classname>Gtk::TreeStore</classname>, mohou mít řádky potomky v podobě řádků a ty zase další potomky a tak dál. K přístupu do kontejneru těchto synovských řádků <classname>Row</classname> použijte <methodname>Gtk::TreeModel::Row::children()</methodname>: <placeholder-1/>Když se použije toto jednoduché přepsání metody <methodname>append_column()</methodname>, bude <classname>TreeView</classname> zobrazovat data z modelu pomocí příslušné třídy <classname>CellRenderer</classname>. Například řetězce a čísla se zobrazují v jednoduchém widgetu <classname>Gtk::Entry</classname> a pravdivostní hodnoty se zobrazují pomocí widgetu <classname>Gtk::CheckButton</classname>. Obvykle je to to, co chcete. Pro další typy sloupců musíte buď pomocí <methodname>TreeViewColumn::set_cell_data_func()</methodname> napojit zpětné volání, které převádí váš typ na řetězcovou reprezentaci, nebo odvodit vlastní <classname>CellRenderer</classname>. Upozorňujeme, že typ <literal>(unsigned) short</literal> není standardně podporován – musíte místo toho použít sloupec <literal>(unsigned) int</literal> nebo <literal>(unsigned) long</literal>.Když stáhnete <application>jhbuild</application> z repozitáře git, máte spoustu souborů <filename>.modules</filename>, které specifikují závislosti mezi moduly. Standardně <application>jhbuild</application> nepoužívá stažené verze těchto souborů, ale čte si nejnovější verze přímo z repozitáře. Obvykle to je to, co chcete. Pokut to tak ale nechcete, použijte proměnnou <varname>use_local_modulesets</varname> v <filename>.jhbuildrc</filename>.Když vyberete položku z robalovací nabídky, umístí se hodnota z tohoto sloupce do <classname>Entry</classname>.Když píšete do vstupního pole, vyšle se událost o uvolnění klávesy, která jde nejprve do okna nejvyšší úrovně (<classname>Gtk::Window</classname>), protože máme nastavenou jednu obsluhu události, aby byla zavolaná napřed, bude to ona, co bude zavolána první (<methodname>windowKeyReleaseBefore()</methodname>). Pak je zavolána výchozí obsluha (kterou máme přepsanou) a následně je událost zaslána widgetu, který má zaměření, což je v našem příkladu <classname>Entry</classname>. Podle toho, jak budeme událost propagovat, může dorazit až k obsluhám událostí objektů <classname>Grid</classname> a <classname>Window</classname>. Pokud bude propagována, bude se text, který píšete objevovat v popisku <classname>Label</classname> nad vstupním polem <classname>Entry</classname>.Kdykoliv zmáčknete nebo uvolníte klávesu, je vyslána událost. Můžete se napojit na obsluhu signálu a takovéto události zpracovávat.Proč používat <application>gtkmm</application> místo GTK+?Dokumentace k obejktu WidgetMetoda Widget::on_expose_event() byla nahrazena pomocí Widget::on_draw(), která předpokládá, že pro kreslení je použita knihovna cairomm přes poskytovaný <classname>Cairo::Context</classname> a nevyžaduje volání <methodname>Cairo::Context::clip()</methodname>.WidgetyWidgety bez X-WindowsWidgety a kotvy potomků (ChildAnchors)Widgety se uspořádávají do kontejnerových widgetů, jako jsou rámy a sešity, v hierarchii widgetů ve widgetech. Některé z těchto kontejnerových widgetů, jako třeba <classname>Gtk::Grid</classname>, nejsou viditelné – existují jen pro potřeby uspořádání ostatních widgetů. Zde je příklad kódu, který přidává dva widgety <classname>Gtk::Button</classname> do kontejnerového widgetu <classname>Gtk::Box</classname>: <placeholder-1/> a zde je, jak přidat <classname>Gtk::Box</classname> obsahující tato dvě tlačítka do <classname>Gtk::Frame</classname>, který má viditelný rámeček a název: <placeholder-2/>Pomocí <function>_WRAP_METHOD()</function> je pro návratovou hodnotu obalené funkce v C (pokud nějakou mát) také možné umístit ji do některého výstupního parametru metody v C++, místo aby byla návratovou hodnotou metody v C++ stejně jako u funkce v C. Když to chcete takto, stačí vložit výstupní parametr do seznamu parametrů metody v C++ a přidat za jeho název <literal>{OUT}</literal>. Například, když je <function>gtk_widget_get_request_mode()</function> deklarována následovně: <placeholder-1/> a máme metodu v C++, která nastavuje výstupní parametr, jak je požadováno, místo aby vracela <type>SizeRequestMode</type>, mohli bychom použít něco takového: <placeholder-2/> <literal>{OUT}</literal> připojené k názvu výstupního parametru <parameter>mode</parameter> říká skriptu <command>gmmproc</command>, aby umístil návratovou hodnotu funkce v C do tohoto výstupního parametru. V tomto případě byla ale navíc nutné určit inicializační makro: <placeholder-3/> Což by šlo zapsat i jako: <placeholder-4/>Ke kreslení oblouků, kružnic a elips se v Cairo používá ta samá funkce: <methodname>Cairo::Context::arc()</methodname>. Tato funkce má pět argumentů. První dva jsou souřadnice středu oblouku, třetí je poloměr oblouku a konečně poslední dva argumenty definují počáteční a koncový úhel oblouku. Všechny úhly se určují v radiánech, takže nakreslení kružnice je to stejné, jako nakreslení oblouku od 0 do 2 * M_PI radiánů. Úhel 0 leží na kladné ose X (v uživatelském prostoru). Úhel M_PI/2 radiánů (90 stupňů) je v kladném směru osy Y (v uživatelském prostoru). Úhel se zvyšuje ve směru z kladné osy X ke kladné ose Y. Takže s výchozí transformační maticí se úhel zvyšuje po směru hodinových ručiček. (Vzpomeňte, že kladná osa Y jde směrem dolů.)Práce se zdrojovým kódem gtkmmObaluje parametry<classname>GList*</classname> a <classname>GSList*</classname>: Za prvé, potřebujete vyhledat, které objekty se nachází v datových polích seznamu pro jednotlivé položky. Obvykle si k tomu stačí přečíst dokumentaci pro funkci v C. Seznam je pak možné obalit typem <classname>std::vector</classname>. Například <code>std::vector&lt; Glib::RefPtr&lt;Gdk::Pixbuf&gt; &gt;</code>. Možná budete potřebovat definovat typ Traits pro určení, jak se typy C a C++ mají převádět.Obalení návratových typů <classname>GList*</classname> a <classname>GSList*</classname>: Musíte vyhledat, jestli má volající seznam uvolnit a jestli má uvolnit položky v seznamu. Opět k tomu stačí přečíst si dokumentaci funkce v C. S touto informací můžete zvolit vlastnictví (žádné, mělké nebo hluboké) pro převodní pravidlo m4, které byste pravděpodobně měli vložit přímo do souboru <filename>.hg</filename>, protože vlastnictví závisí spíše na funkci, než na typu. Například: <placeholder-1/>Obalení knihoven C pomocí gmmprocPsaní obsluhy signálůPsaní .defs pro virtuální funkceSignály událostí XUdálosti X jsou podrobněji popsané v dodatku v oddílu <link linkend="sec-xeventsignals">Signály událostí X</link>.Události X se v některých věcech liší od ostatních signálů. Tyto rozdíly jsou popsané v oddílu <link linkend="sec-xeventsignals">Signály událostí X</link> v dodatku. Zde použijeme události klávesnice k předvedení, jak se dají události X použít v programu.Ano, to je správně: Okno nemůže obsahovat více jak jeden widget. Jak jej pak ale můžeme využít nějakým použitelným způsobem? Umístěním kontejneru pro více potomku do okna. Nejpoužívanější kontejnery na widgety jsou <classname>Gtk::Grid</classname> a <classname>Gtk::Box</classname>.Nejspíše se setkáte s některými problémy v knihovně, kterou balíte, zejména pokud jde o nový projekt. Zde jsou některé běžné problémy včetně řešení.Není zaručeno, že dostanete velikost <literal>Gtk::SizeRequestMode</literal>, kterou požadujete. Proto všechny čtyři metody <methodname>get_preferred_xxx_vfunc()</methodname> musí vracet proměnlivé hodnoty.Rozdělovací čáru můžete umístit pomocí metody <methodname>set_position()</methodname>, a nejspíše to budete potřebovat udělat.Můžete také přetypovat na zděděné typy, ale syntax je trochu rozdílná, než s normálním ukazatelem.Můžete také napojit signál <classname>CellRenderer</classname>, abyste odhalili uživatelské činnosti. Například:Při volání <methodname>ActionGroup::add()</methodname> můžete také určit obsluhu signálu. Ta pak bude vyvolána, kdykoliv bude akce aktivována přes svojí položku nabídky nebo tlačítko na nástrojové liště.Můžete také použít <methodname>get_tag_table()</methodname> pro získání, a případné změny, výchozího objektu <classname>TagTable</classname> z objektu <classname>TextBuffer</classname>, místo abyste jej přímo vytvářeli.Na ten samý text můžete použít i více formátovacích značek použitím metody <methodname>apply_tag()</methodname> vícekrát, nebo pomocí <methodname>insert_with_tags()</methodname>. Více objektů <classname>Tag</classname> může určit pro tu samou vlastnost různé hodnoty, ale tyto konflikty se dají řešit pomocí <methodname>Tag::set_priority()</methodname>.Můžete sestavit několik modulů nastavením proměnné <varname>modules</varname> na metabalíček, např. <literal>meta-gnome-core</literal>, nebo vypsáním více než jednoho názvu modulu. Proměnná <varname>modules</varname> určuje, které moduly budou sestavené, když žádný výslovně neuvedete na příkazové řádce. Vždy můžete sestavit jinou sadu modulů později jejich zadáním na příkazové řádce (např. <command>jhbuild build gtkmm</command>).<classname>RefPtr</classname> můžete přetypovat na základní typy, stejně jako normální ukazatele.<classname>RefPtr</classname> můžete kopírovat stejně jako normální ukazatele. Ale na rozdíl od nich se nemusíte starat o smazání podkladové instance.Můžete vytvořit nový <classname>RecentManager</classname>, ale nejspíše budete chtít používat výchozí. Ukazatel na výchozí <classname>RecentManager</classname> získáte pomocí metody <methodname>get_default()</methodname>.Počitadlo referencí chytrého ukazatele můžete snížit (dereference) pomocí operátoru -&gt;, který zavolá metodu podkladové instance, jako u normálního ukazatele.Pro získání řádku <classname>Row</classname> můžete použít dereferenci iterátoru:Pomocí Cairo můžete kreslit i velmi složité tvary, ale metody k tomu používané jsou vcelku základní. Cairo poskytuje metody pro kreslení rovných čar, křivek a oblouků (včetně celých kružnic). Tyto základní tvary můžete kombinovat, abyste vytvořili složitější tvary a cesty, které můžete vyplnit plnou barvou, přechody, vzory a dalšími věcmi. Navíc Cairo zvládá komplexní transformace, skládání obrázků a vykreslování vyhlazeného textu.Widgety, jako je <classname>Gtk::Button</classname>, můžete vkládat do textu. Každý takový synovský widget potřebuje objekt <classname>ChildAnchor</classname>. Tyto objekty jsou propojené s iterátory. Například, abyste vytvořili kotvu pro potomka na konkrétní pozici v textu, použijte <methodname>Gtk::TextBuffer::create_child_anchor()</methodname>:Pro synovské <classname>Widgety</classname> můžete zadat vlastnosti <emphasis>margin</emphasis> a <emphasis>expand</emphasis>, abyste určili jejich rozestupy a chování při změně rozměrů mřížky.Hodnotu číselníku můžete nastavit pomocí metody <methodname>set_value()</methodname> a naopak ji získat pomocí <methodname>get_value()</methodname>.<classname>Gtk::TreeModel</classname> můžete určit, když konstruhujete <classname>Gtk::TreeView</classname>, nebo můžete použít metodu <methodname>set_model()</methodname>, nějak takto:Při použití metody <methodname>create()</methodname> můžete určit pro objekt <classname>Tag</classname> název, ale není to nutné.Metodu <methodname>timetout</methodname> můžete zastavit vrácením <literal>false</literal> z vaší obsluhy signálu. Pokud chcete, aby vaše metoda byla volána pravidelně, měli byste vrátit <literal>true</literal>.Můžete provést napojení na příslušný signál „edited“, například na <methodname>Gtk::CellRendererText::signal_edited()</methodname> nebo <methodname>Gtk::CellRendererToggle::signal_toggled()</methodname>. Pokud sloupec obsahuje víc než jeden <classname>CellRenderer</classname> budete potřebovat použít <methodname>Gtk::TreeView::get_column()</methodname> a zavolat na zobrazení tohoto sloupce <methodname>get_cell_renderers()</methodname>.Na signál se můžete napojit pomocí stejné syntaxe, jako se používá při napojení k signálům <application>gtkmm</application>. Například <placeholder-1/>Později můžete použít metodu <methodname>get_iter()</methodname> k vytvoření iterátoru pro novou pozici v objektu <classname>Mark</classname>.<application>Glade</application> můžete použít k umístění svého vlastního widgetu odvozeného z třídy widgetu z <application>gtkmm</application>. Tím udržíte v kódu pořádek a zapouzdřenost. Samozřejmě nemůžete v <application>Glade</application> vidět přesný vzhled a vlastnosti odvozeného widgetu, ale můžete určit jeho pozici a potomky a vlastnosti jeho podkladové třídy z <application>gtkmm</application>.Můžete používat API v C, která zatím nemají vhodné rozhraní v C++. Obecně není problém s používáním API v C z C++ a <application>gtkmm</application> v tom pomáhá poskytováním přístupu k podkladovým objektům C a poskytováním jednoduchého způsobu, jak vytvořit objekt v C++ obalující objekt v C za předpokladu, že API v C je také založené na systému GObject.Můžete použít metodu <methodname>append_column()</methodname>, abyste řekli widgetu <classname>View</classname>, že má použít konkrétní sloupce objektu <classname>Modelu</classname>, v konkrétním pořadí, s konkrétními záhlavími sloupců.S <classname>TreeModelColumn</classname>, použitým k vytvoření modelu, a <methodname>operatorem []</methodname> můžete získat data z konkrétního sloupce v řádku.S <classname>TreeModelColumn</classname>, použitým k vytvoření modelu, a <methodname>operatorem []</methodname> můžete přepsat data nastavená v konkrétním sloupci v řádku.Můžete používat metodu <methodname>toggled()</methodname> k přepnutí tlačítka a určitě ji dejte přednost pro vynucením zmáčknutí nebo vyskočení: Přepne stav tlačítka a způsobí vyslání signálu <literal>toggled</literal>.Obvykle můžete předstírat, že je <classname>Gtk::Clipboard</classname> jedináček. Výchozí instanci schránky můžete získat pomocí <methodname>Gtk::Clipboard::get()</methodname>. Je to pravděpodobně jediná schránka, kterou kdy budete potřebovat.Stačilo by jen deklarovat signál, jako veřejnou členskou proměnnou, ale někteří to nepovažují za vhodné a dávají přednost jeho zpřístupnění přes metodu, nějak takto: <placeholder-1/>Manipulaci se synovskými widgety v konstruktoru odvozené třidy byste mohli zapouzdřit, třeba znovu pomocí <methodname>get_widget()</methodname> nebo <methodname>get_widget_derived()</methodname>. Například <placeholder-1/>Ne vždy je potřeba volat metodu rodiče. Jsou situace, kdy to možná chtít nebudete. Všimněte si, že rodičovskou metodu voláme <emphasis>až po</emphasis> vypsání „Hello World“, ale mohli bychom ji volat i před tím. V tomto jednoduchém příkladu je to jedno, ale jsou případy, kdy to jedno není. Se signály to není tak jednoduché měnit detaily, jak to bylo zde, a zde můžete dělat něco, co obecně v obsluze signálů dělat není možné: můžete zavolat rodičovskou metodu <emphasis>uprostřed</emphasis> svého vlastního kódu.Nemáte žádnou možnost, jak získat holý <classname>Gdk::Pixbuf</classname>. V příkladu je <varname>pixbuf</varname> chytrý ukazatel, takže to můžete udělat podobně, jako u normálního ukazatele: <placeholder-1/>Do tiskového dialogového okna můžete přidat vlastní kartu: <placeholder-1/>Možná vás zajímá, jak to udělat, aby <application>gtkmm</application> dělalo něco užitečného, když je v nečinném stavu. Máte štěstí, protože máte dokonce hned několik možností, jak to udělat. Pomocí následujících metod můžete vytvořit časovanou metodu, která bude zavolaná každých pár milisekund.Mohli byste také odvodit z <classname>Gtk::Object</classname> jinou třídu než widget, takže by šla používat bez <classname>Glib::RefPtr</classname>. Například by její instance mohly být vytvářeny pomocí <function>Gtk::manage()</function> nebo na zásobníku jako členské proměnné. Pro některé účely je to vhodné, ale musíte to použít jen v případě, kdy máte jistotu, že počítání referencí není zapotřebí. Za užitečné to považujeme pro widgety.Možná budete překvapeni, že <application>gtkmm</application> nepoužívá ve svých rozhraních <classname>std::string</classname>. Místo toho používá <classname>Glib::ustring</classname>, který je ale  natolik podobný a nenápadný, že klidně můžete předstírat, že <classname>Glib::ustring</classname> je <classname>std::string</classname> a zbytek kapitoly ignorovat. Přečtěte si ji ale, pokud chcete ve svých aplikacích používat jiné jazyky, než jen angličtinu.Můžete chtít reagovat na všechny změny výběru v rozbalovacím seznamu, například kvůli aktualizaci ostatních widgetů. K tomu byste měli obsluhovat signál <literal>changed</literal>. Například:Možná nebudete předpokládat potřebu podpory dalších jazyků, ale nikdy neříkejte nikdy. A je jednodušší aplikace hned ze začátku napsat správně, než ji později celou opravovat.Občas, když něčeho nejde dosáhnout s normálními signály, můžete shledat užitečným obsluhovat události X. <classname>Gtk::Button</classname> například neposílá v jeho signálu <literal>clicked</literal> souřadnice ukazatele myši, ale pokud tuto informaci potřebujete, mohli byste obsluhovat <literal>button_press_event</literal>. Události X jsou také často využívány k obsluze zmačknutí kláves.Pak můžete obsluhovat signál <literal>clicked</literal> objektu <classname>ToolButton</classname>. Případně byste mohli umožnit položce její přetažení do jiného widgetu pomocí volání <methodname>Gtk::ToolPalette::add_drag_dest()</methodname> a následného použití <methodname>Gtk::ToolPalette::get_drag_item()</methodname> v obsluze signálu <literal>drag_data_received</literal> v onom jiném widgetu.Můžete potřebovat mít v řádcích zadaná nějaká doplňující data. V takovém případě stačí, když je přidáte do Modelu jako další sloupec, ale ten nebudete přidávat do zobrazení View.Můžete chtít být informováni, kdykoliv uživatel něco do textového vstupního pole napíše. <classname>Gtk::Entry</classname> poskytuje za tímto účelem dva signály, <literal>activate</literal> a <literal>changed</literal>. Signál <literal>activate</literal> je vyslán, když uživatel zmáčkne v textovém poli klávesu <keymap>Enter</keymap>. Signál <literal>changed</literal> je vyslán, když se text ve widgetu změní. To můžete například využít k ověřování nebo filtrování textu, který uživatel píše. Přesunutí zaměření klávesnice do jiného widgetu rovněž vyšle signál, který signalizuje, že uživatel dokončil zadávání textu. Jedná se o signál <literal>focus_out_event</literal>, který <classname>Gtk::Entry</classname> dědí z <classname>Gtk::Widget</classname>. Kapitola <link linkend="sec-comboboxentry">Kombinované vstupní pole (ComboBoxEntry)</link> obsahuje ukázkový program, který tyto signály používá.Můžete chtít vložit další zdrojové soubory, které se nebudou generovat pomocí <command>gmmproc</command> ze souborů <filename>.hg</filename> a <filename>ccg</filename>. Stačí je prostě umístit do vaší složky <filename>libneco/libnecomm</filename> a uvést je v <filename>Makefile.am</filename> v proměnných <varname>files_extra_h</varname> and <varname>files_extra_cc</varname>.Můžete si přát využít dokumentaci, která již existuje pro knihovny jazyka C, které jsou pro C++ obalené. Tyto knihovny ve stylu GTK typicky používají gtk-doc a proto mají komentáře ve zdrojovém kódu formátované pro gtk-doc a k tomu nějakou doplňující dokumentaci v souborech .sgml a .xml. Skript <filename>docextract_to_xml.py</filename> ze složky <filename>tools/defs_gen</filename> umí tyto soubory číst a vygenerovat soubor .xml, který může <command>gmmproc</command> použít k vygenerování komentářů pro doxygen. <command>gmmproc</command> se navíc pokusí provést v dokumentaci nějaké změny, aby lépe odpovídala API C++.V seznamu inicializací musíte zavolat konstruktor základní třídy, abyste získali ukazatel C. Například <placeholder-1/>Aby se vygeneroval soubor <filename>.defs</filename> pro typy GObject v C, které si přejete obalit, musíte upravit zdrojový kód svého vlastního nástroje <filename>generate_extra_defs</filename>. Ve stromu zdrojových kódů kostry je soubor s názvem <filename>codegen/extradefs/generate_extra_defs_skeleton.cc</filename>. Pokud jste to zatím neudělali, měli byste jej přejmenovat. Základní název by měla tvořit nová vazba nahrazující zástupný název <varname>skeleton</varname>. Nový název zdrojového souboru by měl být také uveden v <filename>codegen/Makefile.am</filename>.Při volání <literal>signal_command_line().connect()</literal> musíte nastavit volitelný parametr <literal>after = false</literal>, protože vaše obsluha signálu musí být zavolána před výchozí obsluhou signálu. Také musíte v obsluze signálu zavolat <methodname>Gio::Application::activate()</methodname>, pokud tedy nechcete, aby vaše aplikace skončila dříve, než zobrazí hlavní okno. (<classname>Gio::Application</classname> je základem pro třídu <classname>Gtk::Application</classname>.)Potřebujete zadat vlastnosti objektu <classname>Alignment</classname>, buď do konstruktoru nebo do metody <methodname>set()</methodname>. Nutno podotknout, že při pokud nezadáte u parametrů <literal>xscale</literal> a <literal>yscale</literal> jiné hodnoty než 1,0, nezaznamenáte žádný efekt, protože 1,0 jednoduše znamená, že synovský widget se roztáhne, aby zaplnil všechno dostupné místo.Nemůžete dopředu vědět, kolik místa na obrazovce řetězec zabere po překladu. Je klidně možné, že bude dvakrát delší, než anglický originál. Naštěstí se většina widgetů <application>gtkmm</application> za běhu roztáhne na velikost, která se po nich chce.Pravděpodobně nebudete muset pokaždé napojit obsluhu k tomuto signálu, vyjma případů, kdy používáte nový typ widgetu <classname>Range</classname>.Měli byste se vyvarovat ukazatelové aritmetiky ve stylu C a funkcí jako je strlen(). V UTF-8 mohou znaky zabírat od 1 do 6 bajtů, takže se nedá automaticky předpokládat, že následující bajt je jiný znak. <classname>Glib::ustring</classname> se o tyto věci postará, takže můžete používat metody jako je Glib::ustring::substr() a přitom stále uvažovat v intencích znaků, ale ne bajtů.Měli byste se vyhnout tajuplným zkratkám, slangu a nářečím. Většinou bývá nesnadné je přeložit a někdy jim nerozumí ani rodilý mluvčí. Například raději používejte „application“ než „app“.Měli byste se vyhnout vložení hlavičkového souboru C z vašeho hlavičkového souboru C++, aby se předešlo šíření globálního jmenného prostoru a exportu nepotřebného veřejného API. Budete ale potřebovat vložit nutné hlavičkové soubory C ze souboru <filename>.ccg</filename>.Měli byste být opatrní, když instalujete do standardních systémových složek, jako je <filename>/usr</filename>. Linuxové distribuce instalují do <filename>/usr</filename> softwarové balíčky, takže instalace ze zdrojových kódů do této cesty by mohla poškodit software nainstalovaný správou balíčků vaší distribuce, nebo s ním být v konfliktu. Nejlépe, když použijete oddělenou složku pro všechen software instalovaný ze zdrojových kódů.Tyto typy byste si neměli deklarovat sami. Místo toho byste měli použít kterýkoliv standardní kontejner jazyka C++, který vám vyhovuje. glibmm za vás provede převod. Zde jsou některé z mezilehlých typů: <placeholder-1/> Zvolený <classname>Gtk::PageSetup</classname> byste si měli uložit, abyste jej mohli opětovně použít, když se znovu zobrazí dialogové okno nastavení stránky.Měli byste pak <classname>Gtk::CellRenderer*</classname> přetypovat na konkrétní <classname>CellRenderer</classname>, který očekáváte, abyste mohli použít jeho API.Když vytváříte Model, určíte <classname>ColumnRecord</classname> takto:Stále budete potřebovat nějaký kód v C++ k obsluze změn v uživatelském rozhraní spouštěných uživatelovou činností, ale použití <application>Gtk::Builder</application> pro rozvržení vám uvolní ruce pro práci na funkcionalitě.Toto makro typicky použijete, když třída již existuje a je odvozená z <classname>Gtk::Object</classname>. Například jej použijete, když obalujete Widget z GTK+, protože <classname>Gtk::Widget</classname> je zděděný z <classname>Gtk::Object</classname>.Nejspíše jste si všimli, že okna <application>gtkmm</application> jsou „elastická“ – můžete je různě roztahovat a zase zmenšovat. Je to díky systému <emphasis>balení widgetů</emphasis> (packing).Vaše aplikace nepotřebuje na operace se schránkou čekat, zejména v čase mezi tím, co uživatel použil „Kopírovat“ a chystá se použít „Vložit“. Většina metod <classname>Gtk::Clipboard</classname> přebírá objekty <classname>sigc::slot</classname>, které specifikují metody zpětného volání. Když je <classname>Gtk::Clipboard</classname> připravený, zavolá tyto metody a buď jim poskytne požadovaná data nebo si o data požádá.Až uživatel zvolí vložení dat, vaše zpětné volání poskytne uložená data. Například:Vaše odvozená třída musí mít konstruktor, který přebírá ukazatel na podkladový typ C a instanci <classname>Gtk::Builder</classname>. Všechny související třídy v <application>gtkmm</application> definují svůj podkladový typ C jako <classname>BaseObjectType</classname> (například <classname>Gtk::Dialog</classname> definuje typ <classname>BaseObjectType</classname> jako <type>GtkDialog</type>).Vaše stávající znalosti C++ vám budou s <application>gtkmm</application> ku prospěchu, stejně jako u jakékoliv jiné knihovny. Pokud neuvedeme jinak, očekávejte od tříd <application>gtkmm</application> chování jako u jakékoliv jiné třídy C++ a můžete očekávat, že třídy <application>gtkmm</application> používají běžné techniky C++.Vaše implementace metody <methodname>child_type_vfunc()</methodname> by měla hlásit typ widgetu, který je možné přidat do vašeho kontejneru za předpokladu, že ještě není plný. Obvykle to je <methodname>Gtk::Widget::get_type()</methodname>, abyste dali najevo, že kontejner může obsahovat libovolnou třídu zděděnou z <classname>Gtk::Widget</classname>. Pokud kontejner již nemůže pojmou žádný další widget, měla by tato metoda vráti <literal>G_TYPE_NONE</literal>.Než můžete svoji knihovnu použít, je potřeba ji inicializovat, aby se zaregistrovaly nové typy, které zpřístupňuje. Také knihovny v C, které obalujete, mohou mít své vlastní inicializační funkce, které byste měli zavolat. Můžete to udělat ve funkci <function>init()</function>, kterou můžete umístit do ručně napsaných souborů <filename>init.h</filename> a <filename>init.cc</filename>. Tato funkce by měla inicializovat vaše závislosti (např. funkci v C a <application>gtkmm</application>) a zavolat vaši vygenerovanou funkci <function>wrap_init()</function>. Například: <placeholder-1/>_CLASS_BOXEDTYPE_CLASS_BOXEDTYPE( C++ class, C class, new function, copy function, free function )_CLASS_BOXEDTYPE_STATIC_CLASS_BOXEDTYPE_STATIC( C++ class, C class )_CLASS_GENERIC_CLASS_GENERIC( C++ class, C class )_CLASS_GOBJECT_CLASS_GOBJECT( C++ class, C class, C casting macro, C++ base class, C base class )_CLASS_GTKOBJECT_CLASS_GTKOBJECT( C++ class, C class, C casting macro, C++ base class, C base class )_CLASS_GTKOBJECT()_CLASS_INTERFACE_CLASS_INTERFACE( C++ class, C class, C casting macro, C interface struct, Base C++ class (optional), Base C class (optional) )_CLASS_OPAQUE_COPYABLE_CLASS_OPAQUE_COPYABLE( C++ class, C class, new function, copy function, free function )_CLASS_OPAQUE_REFCOUNTED_CLASS_OPAQUE_REFCOUNTED( C++ class, C class, new function, ref function, unref function )_CTOR_DEFAULT_DEFS()_IGNORE / _IGNORE_SIGNAL_IGNORE(C function name 1, C function name2, etc)_IGNORE_SIGNAL(C signal name 1, C signal name2, etc)_IMPLEMENTS_INTERFACE_IMPLEMENTS_INTERFACE()_IMPLEMENTS_INTERFACE(C++ interface name)_MEMBER_GET / _MEMBER_SET_MEMBER_GET(C++ name, C name, C++ type, C type)_MEMBER_GET(x, x, int, int)_MEMBER_GET_GOBJECT / _MEMBER_SET_GOBJECT_MEMBER_GET_GOBJECT(C++ name, C name, C++ type, C type)_MEMBER_GET_PTR / _MEMBER_SET_PTR_MEMBER_GET_PTR(C++ name, C name, C++ type, C type)_MEMBER_SET(C++ name, C name, C++ type, C type)_MEMBER_SET_GOBJECT(C++ name, C name, C++ type, C type)_MEMBER_SET_PTR(C++ name, C name, C++ type, C type)_PINCLUDE()_WRAP_CTOR_WRAP_ENUM_WRAP_ENUM_DOCS_ONLY_WRAP_GERROR_WRAP_METHOD_WRAP_METHOD( C++ method signature, C function name)_WRAP_METHOD_DOCS_ONLY_WRAP_METHOD_DOCS_ONLY(C function name)_WRAP_PROPERTY_WRAP_PROPERTY(C property name, C++ type)_WRAP_SIGNAL_WRAP_SIGNAL( C++ signal handler signature, C signal name)_WRAP_VFUNC_WRAP_VFUNC( C++ method signature, C function name)adj-&gt;signal_value_changed().connect(sigc::bind&lt;MyPicture*&gt;(sigc::mem_fun(*this,
    &amp;cb_rotate_picture), picture));adjustment-&gt;signal_changed();a napojili byste jej na přizpůsobení widgetu <classname>Scale</classname> nějak takto:a pakatkmmbinding_namebindtextdomain(GETTEXT_PACKAGE, PROGRAMNAME_LOCALEDIR);
bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
textdomain(GETTEXT_PACKAGE);boolbool DemoWindow::select_function(
    const Glib::RefPtr&lt;Gtk::TreeModel&gt;&amp; model,
    const Gtk::TreeModel::Path&amp; path, bool)
{
  const Gtk::TreeModel::iterator iter = model-&gt;get_iter(path);
  return iter-&gt;children().empty(); // only allow leaf nodes to be selected
}bool ExampleWindow::on_button_press_event(GdkEventButton* event)
{
  if( (event-&gt;type == GDK_BUTTON_PRESS) &amp;&amp;
      (event-&gt;button == 3) )
  {
    m_Menu_Popup-&gt;popup(event-&gt;button, event-&gt;time);
    return true; // Bylo obslouženo
  }
  else
    return false;
}bool MyArea::on_draw(const Cairo::RefPtr&lt;Cairo::Context&gt;&amp; cr)
{
  Glib::RefPtr&lt;Gdk::Pixbuf&gt; image = Gdk::Pixbuf::create_from_file("myimage.png");
  // Vykreslíme obrázek na 110, 90, vyjma úplně krajních 10 pixelů.
  Gdk::Cairo::set_source_pixbuf(cr, image, 100, 80);
  cr-&gt;rectangle(110, 90, image-&gt;get_width()-20, image-&gt;get_height()-20);
  cr-&gt;fill();
  return true;
}Příklad tlačítkacairocairommcell.property_editable() = true;class HelloWorld : public Gtk::Window
{

public:
  HelloWorld();
  virtual ~HelloWorld();

protected:
  // Obsluha signálu:
  virtual void on_button_clicked();

  // Členské widgety:
  Gtk::Button m_button;
};class ModelColumns : public Gtk::TreeModelColumnRecord
{
public:

  ModelColumns()
    { add(m_col_text); add(m_col_number); }

  Gtk::TreeModelColumn&lt;Glib::ustring&gt; m_col_text;
  Gtk::TreeModelColumn&lt;int&gt; m_col_number;
};

ModelColumns m_Columns;class RadioButtons : public Gtk::Window
{
public:
    RadioButtons();

protected:
    Gtk::RadioButton m_rb1, m_rb2, m_rb3;
};

RadioButtons::RadioButtons()
  : m_rb1("button1"),
    m_rb2("button2"),
    m_rb3("button3")
{
    Gtk::RadioButton::Group group = m_rb1.get_group();
    m_rb2.set_group(group);
    m_rb3.set_group(group);
}class RadioButtons : public Gtk::Window
{
public:
    RadioButtons();
};

RadioButtons::RadioButtons()
{
    Gtk::RadioButton::Group group;
    Gtk::RadioButton *m_rb1 = Gtk::manage(
      new Gtk::RadioButton(group,"button1"));
    Gtk::RadioButton *m_rb2 = manage(
      new Gtk::RadioButton(group,"button2"));
      Gtk::RadioButton *m_rb3 = manage(
        new Gtk::RadioButton(group,"button3"));
}clickedconfigure.acconstversioncontext-&gt;save();
context-&gt;translate(x, y);
context-&gt;scale(width / 2.0, height / 2.0);
context-&gt;arc(0.0, 0.0, 1.0, 0.0, 2 * M_PI);
context-&gt;restore();custom_c_callbackcustom_default_handlercustom_vfunccustom_vfunc_callbackdeprecateddisplay_message("Getting ready for i18n.");display_message(_("Getting ready for i18n."));doubleentervýčtových typůerrthrowevent_box.add(child_widget);flags: Příznaky, používané jen pro táhni a upusť, které určují, zda se data smí přetáhnout do jiného widgetu a aplikace, nebo jen do toho stejného.funkcíg++ simple.cc -o simple `pkg-config gtkmm-3.0 --cflags --libs`gbooleangchar*gdk-pixbufgdoublepříručka gettextgintglibglibmmZpracování parametrů gmmprocgnomemm_hellogtk.defsgtk_enums.defsgtk_methods.defsgtk_signals.defsgtk_vfuncs.defsgtkmmgtkmm-3.0 je název aktuálního stabilního API. Existuje i starší API nazývané gtkmm-2.4, které, pokud je dostupné, se instaluje souběžně. Existovalo postupně několik verzí gtkmm-2.4, jako třeba gtkmm 2.10 a existuje i několik verzí API gtkmm-3.0. Je třeba si uvědomit, že název API se nemění s každou verzí, protože by došlo k narušení kompatibility API a ABI. Teoreticky může v budoucnu vzniknout API gtkmm-4.0, které by se instalovalo souběžně s gtkmm-3.0 bez vlivu na stávající aplikace.gtkmm_helloguintgunicharifdefinfo: Identifikátor, který bude vyslán do vašeho signálu, aby sdělil, který <classname>TargetEntry</classname> byl použitintint cols_count = m_TreeView.append_column_editable("Alex", m_columns.alex);
Gtk::TreeViewColumn* pColumn = m_TreeView.get_column(cols_count-1);
if(pColumn)
{
  Gtk::CellRendererToggle* pRenderer =
    static_cast&lt;Gtk::CellRendererToggle*&gt;(pColumn-&gt;get_first_cell());
  pColumn-&gt;add_attribute(pRenderer-&gt;property_visible(), m_columns.visible);
  pColumn-&gt;add_attribute(pRenderer-&gt;property_activatable(), m_columns.world);int main(int argc, char** argv)
{
  Glib::RefPtr&lt;Gtk::Application&gt; app = Gtk::Application::create(argc, argv, "org.gtkmm.example");

  HelloWorld helloworld;
  return app-&gt;run(helloworld);
}intltool-update --potleavelib_LTLIBRARIESlibsigc++ 2.0Konverze m4Inicializace m4m_TextView.add_child_at_anchor(m_Button, refAnchor);m_TreeView.append_column("Messages", m_Columns.m_col_text);m_TreeView.set_model(m_refListStore);m_box.pack_start(m_Button1);
m_box.pack_start(m_Button2);m_button1.signal_clicked().connect( sigc::mem_fun(*this,
  &amp;HelloWorld::on_button_clicked) );m_combo.set_entry_text_column(m_columns.m_col_name);m_combo.signal_changed().connect( sigc::mem_fun(*this,
      &amp;ExampleWindow::on_combo_changed) );m_frame.add(m_box);m_rb2.set_group(m_rb1.get_group()); // nefungujem_refActionGroup = Gtk::ActionGroup::create();

m_refActionGroup-&gt;add( Gtk::Action::create("MenuFile", "_File") );
m_refActionGroup-&gt;add( Gtk::Action::create("New", "_New"),
  sigc::mem_fun(*this, &amp;ExampleWindow::on_action_file_new) );
m_refActionGroup-&gt;add( Gtk::Action::create("ExportData", "Export Data"),
  sigc::mem_fun(*this, &amp;ExampleWindow::on_action_file_open) );
m_refActionGroup-&gt;add( Gtk::Action::create("Quit", "_Quit"),
  sigc::mem_fun(*this, &amp;ExampleWindow::on_action_file_quit) );m_refTreeSelection-&gt;set_select_function( sigc::mem_fun(*this,
    &amp;DemoWindow::select_function) );modules = [ 'gtkmm' ]moduleset = 'gnome-suites-core-deps-3.12'no_default_handlerno_slot_copyobjektů (GObject, widgety, rozhraní, boxované typy a obyčejné struktury)nebopangommpkg-configpressedvlastnostírefBuffer-&gt;apply_tag(refTagMatch, iterRangeStart, iterRangeStop);refBuffer-&gt;insert_with_tag(iter, "Some text", refTagMatch);refClipboard-&gt;request_contents("example_custom_target",
    sigc::mem_fun(*this, &amp;ExampleWindow::on_clipboard_received) );refClipboard-&gt;request_targets( sigc::mem_fun(*this,
    &amp;ExampleWindow::on_clipboard_received_targets) );refTreeSelection-&gt;selected_foreach_iter(
    sigc::mem_fun(*this, &amp;TheClass::selected_row_callback) );

void TheClass::selected_row_callback(
    const Gtk::TreeModel::iterator&amp; iter)
{
  TreeModel::Row row = *iter;
  // Udělat něco s řádkem
}refTreeSelection-&gt;set_mode(Gtk::SELECTION_MULTIPLE);refTreeSelection-&gt;signal_changed().connect(
    sigc::mem_fun(*this, &amp;Example_IconTheme::on_selection_changed)
);refreturnrefreturn_ctypereleasedreturn app-&gt;run(window);row[m_Columns.m_col_text] = "sometext";signálůslot_callbackslot_namesrc/main.cc
src/other.ccstd::cout &lt;&lt; Glib::ustring::compose(
             _("Current amount: %1 Future: %2"), amount, future) &lt;&lt; std::endl;

label.set_text(Glib::ustring::compose(_("Really delete %1 now?"), filename));std::cout &lt;&lt; _("Current amount: ") &lt;&lt; amount
          &lt;&lt; _(" Future: ") &lt;&lt; future &lt;&lt; std::endl;

label.set_text(_("Really delete ") + filename + _(" now?"));std::ostringstream output;
output.imbue(std::locale("")); // pro tento textový proud použít uživatelův jazyk
output &lt;&lt; percentage &lt;&lt; " % done";
label-&gt;set_text(Glib::locale_to_utf8(output.str()));std::stringstd::string používá 8 bitů na znak, ale to není dostačující pro kódování jazyků, jako je arabština, čínština nebo japonština. Ačkoliv kódování pro tyto jazyky je nyní standardizováno organizací Unicode Consortium, programovací jazyky C a C++ neposkytují pro Unikód standardizovanou podporu. GTK+ a GNOME se vydalo cestou implementace Unikódu pomocí UTF-8 a to je přesně to, co obaluje Glib::ustring. Z větší části poskytuje přesně to stejné rozhraní, jako std:string, včetně automatického převodu na a z std::string.std::vector&lt; Glib::RefPtr&lt;Gtk::RecentInfo&gt; &gt; info_list = recent_manager-&gt;get_items();target: Název cíle, jako třeba „STRING“Marek Černocký <marek@manet.cz>typedef Gtk::TreeModel::Children type_children; // zmenší délku kódu
type_children children = refModel-&gt;children();
for(type_children::iterator iter = children.begin();
    iter != children.end(); ++iter)
{
  Gtk::TreeModel::Row row = *iter;
  // Udělat něco s řádkem - viz set/get výše
}virtuálních funkcíVirtuální funkce (ukazatel na funkci jako členské pole v struktuře), psané ručně.void ExampleWindow::on_button_delete()
{
  Glib::RefPtr&lt;Gtk::TreeSelection&gt; refTreeSelection =
      m_treeview.get_selection();
  if(refTreeSelection)
  {
    Gtk::TreeModel::iterator sorted_iter =
        m_refTreeSelection-&gt;get_selected();
    if(sorted_iter)
    {
      Gtk::TreeModel::iterator iter =
          m_refModelSort-&gt;convert_iter_to_child_iter(sorted_iter);
      m_refModel-&gt;erase(iter);
    }
  }
}void ExampleWindow::on_clipboard_get(
    Gtk::SelectionData&amp; selection_data, guint /* info */)
{
  const std::string target = selection_data.get_target();

  if(target == "example_custom_target")
    selection_data.set("example_custom_target", m_ClipboardStore);
}void ExampleWindow::on_clipboard_received(
    const Gtk::SelectionData&amp; selection_data)
{
  Glib::ustring clipboard_data = selection_data.get_data_as_string();
  // Udělat něco s vloženými daty
}void ExampleWindow::on_clipboard_received_targets(
  const std::vector&lt;Glib::ustring&gt;&amp; targets)
{
  const bool bPasteIsPossible =
    std::find(targets.begin(), targets.end(),
      example_target_custom) != targets.end();

  // Příslušně povolí/zakáže tlačítko pro vložení:
  m_Button_Paste.set_sensitive(bPasteIsPossible);
}void cb_rotate_picture (MyPicture* picture)
{
  picture-&gt;set_rotation(adj-&gt;get_value());
…void doSomething(const Cairo::RefPtr&lt;Cairo::Context&gt;&amp; context, int x)
{
    context-&gt;save();
    // změna grafického stavu
    // provedení kreslící operace
    context-&gt;restore();
}void drag_dest_set(const std::vector&lt;Gtk::TargetEntry&gt;&amp; targets,
    Gtk::DestDefaults flags, Gdk::DragAction actions);void drag_source_set(const std::vector&lt;Gtk::TargetEntry&gt;&amp; targets,
      Gdk::ModifierType start_button_mask, Gdk::DragAction actions);void pack_start(Gtk::Widget&amp; child,
                Gtk::PackOptions options = Gtk::PACK_EXPAND_WIDGET,
                guint padding = 0);kde argument <parameter>condition</parameter> je takový, jak byl určen ve funkci zmíněné výše. Jako obvykle je slot vytvořen pomocí <function>sigc::mem_fun()</function> (pro členské metody objektu), nebo pomocí <function>sigc::ptr_fun()</function> (pro funkce).wrap_init_flagsxgettext -a -o moje-řetězce --omit-header *.cc *.h